From c23a457e72abe608715ac76f076f47dc42af07a5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 20:31:44 +0200 Subject: Merging upstream version 1.74.1+dfsg1. Signed-off-by: Daniel Baumann --- src/tools/clippy/tests/compile-test.rs | 333 ++++------- src/tools/clippy/tests/headers.rs | 2 +- .../cargo_common_metadata/fail/Cargo.stderr | 1 + .../fail_publish/Cargo.stderr | 1 + .../fail_publish_true/Cargo.stderr | 1 + .../tests/ui-cargo/duplicate_mod/fail/Cargo.stderr | 1 + .../tests/ui-cargo/feature_name/fail/Cargo.stderr | 2 + .../ui-cargo/module_style/fail_mod/Cargo.stderr | 1 + .../module_style/fail_mod_remap/Cargo.stderr | 1 + .../ui-cargo/module_style/fail_no_mod/Cargo.stderr | 1 + .../multiple_crate_versions/fail/Cargo.stderr | 1 + .../wildcard_dependencies/fail/Cargo.stderr | 1 + .../tests/ui-internal/check_formulation.stderr | 1 + .../ui-internal/collapsible_span_lint_calls.fixed | 1 - .../ui-internal/collapsible_span_lint_calls.rs | 1 - .../ui-internal/collapsible_span_lint_calls.stderr | 12 +- .../clippy/tests/ui-internal/if_chain_style.stderr | 1 + .../ui-internal/interning_defined_symbol.fixed | 1 - .../tests/ui-internal/interning_defined_symbol.rs | 1 - .../ui-internal/interning_defined_symbol.stderr | 10 +- .../tests/ui-internal/invalid_msrv_attr_impl.fixed | 2 - .../tests/ui-internal/invalid_msrv_attr_impl.rs | 2 - .../ui-internal/invalid_msrv_attr_impl.stderr | 6 +- .../clippy/tests/ui-internal/invalid_paths.stderr | 1 + .../clippy/tests/ui-internal/outer_expn_data.fixed | 2 - .../clippy/tests/ui-internal/outer_expn_data.rs | 2 - .../tests/ui-internal/outer_expn_data.stderr | 4 +- .../tests/ui-internal/unnecessary_def_path.fixed | 1 - .../tests/ui-internal/unnecessary_def_path.rs | 1 - .../tests/ui-internal/unnecessary_def_path.stderr | 32 +- .../unnecessary_def_path_hardcoded_path.stderr | 1 + .../tests/ui-internal/unnecessary_symbol_str.fixed | 1 - .../tests/ui-internal/unnecessary_symbol_str.rs | 1 - .../ui-internal/unnecessary_symbol_str.stderr | 12 +- .../absolute_paths.allow_crates.stderr | 1 + .../absolute_paths.disallow_crates.stderr | 1 + .../tests/ui-toml/absolute_paths/absolute_paths.rs | 2 +- .../uninlined_format_args.fixed | 1 - .../uninlined_format_args.rs | 1 - .../uninlined_format_args.stderr | 14 +- .../arithmetic_side_effects_allowed.stderr | 1 + .../array_size_threshold/array_size_threshold.rs | 2 +- .../array_size_threshold.stderr | 2 + .../await_holding_invalid_type.rs | 6 +- .../await_holding_invalid_type.stderr | 7 +- .../conf_deprecated_key/conf_deprecated_key.stderr | 1 + .../clippy/tests/ui-toml/dbg_macro/dbg_macro.rs | 2 +- .../tests/ui-toml/dbg_macro/dbg_macro.stderr | 1 + .../decimal_literal_representation/clippy.toml | 1 + .../decimal_literal_representation.fixed | 6 + .../decimal_literal_representation.rs | 6 + .../decimal_literal_representation.stderr | 11 + .../ui-toml/disallowed_macros/auxiliary/macros.rs | 15 + .../tests/ui-toml/disallowed_macros/clippy.toml | 2 + .../ui-toml/disallowed_macros/disallowed_macros.rs | 5 +- .../disallowed_macros/disallowed_macros.stderr | 23 +- .../disallowed_names.stderr | 1 + .../disallowed_names.stderr | 1 + .../ui-toml/disallowed_script_idents/clippy.toml | 1 + .../disallowed_script_idents.rs | 6 + .../disallowed_script_idents.stderr | 11 + .../doc_valid_idents_append/doc_markdown.fixed | 12 + .../doc_valid_idents_append/doc_markdown.stderr | 1 + .../doc_valid_idents_replace/doc_markdown.fixed | 12 + .../doc_valid_idents_replace/doc_markdown.stderr | 1 + .../tests/ui-toml/enum_variant_names/clippy.toml | 1 + .../enum_variant_names/enum_variant_names.rs | 16 + .../enum_variant_names/enum_variant_names.stderr | 18 + .../tests/ui-toml/enum_variant_size/clippy.toml | 1 + .../enum_variant_size/enum_variant_size.fixed | 11 + .../ui-toml/enum_variant_size/enum_variant_size.rs | 11 + .../enum_variant_size/enum_variant_size.stderr | 21 + .../ui-toml/enum_variants_threshold0/clippy.toml | 1 + .../enum_variants_name_threshold.rs | 3 + .../excessive_nesting/auxiliary/proc_macros.rs | 469 --------------- .../ui-toml/excessive_nesting/excessive_nesting.rs | 4 +- .../excessive_nesting/excessive_nesting.stderr | 1 + .../tests/ui-toml/expect_used/expect_used.stderr | 1 + .../tests/ui-toml/explicit_iter_loop/clippy.toml | 1 + .../explicit_iter_loop/explicit_iter_loop.fixed | 10 + .../explicit_iter_loop/explicit_iter_loop.rs | 10 + .../explicit_iter_loop/explicit_iter_loop.stderr | 17 + .../ui-toml/fn_params_excessive_bools/test.stderr | 1 + .../tests/ui-toml/functions_maxlines/test.stderr | 1 + .../ui-toml/ifs_same_cond/ifs_same_cond.stderr | 1 + .../ui-toml/large_futures/large_futures.fixed | 27 + .../ui-toml/large_futures/large_futures.stderr | 1 + .../large_include_file/large_include_file.stderr | 1 + .../tests/ui-toml/large_stack_frames/clippy.toml | 1 + .../large_stack_frames/large_stack_frames.rs | 17 + .../large_stack_frames/large_stack_frames.stderr | 15 + .../large_types_passed_by_value/clippy.toml | 1 + .../large_types_passed_by_value.fixed | 7 + .../large_types_passed_by_value.rs | 7 + .../large_types_passed_by_value.stderr | 11 + .../ui-toml/lint_decimal_readability/test.fixed | 23 + .../ui-toml/lint_decimal_readability/test.stderr | 2 + .../tests/ui-toml/manual_let_else/clippy.toml | 1 + .../ui-toml/manual_let_else/manual_let_else.fixed | 10 + .../ui-toml/manual_let_else/manual_let_else.rs | 14 + .../ui-toml/manual_let_else/manual_let_else.stderr | 15 + .../index_refutable_slice.fixed | 24 + .../ui-toml/min_ident_chars/min_ident_chars.stderr | 1 + .../min_rust_version/min_rust_version.fixed | 98 ++++ .../min_rust_version/min_rust_version.stderr | 1 + .../conf_missing_enforced_import_rename.fixed | 16 + .../conf_missing_enforced_import_rename.stderr | 1 + .../module_inception/module_inception.stderr | 1 + .../conf_nonstandard_macro_braces.fixed | 3 +- .../conf_nonstandard_macro_braces.rs | 3 +- .../conf_nonstandard_macro_braces.stderr | 17 +- .../tests/ui-toml/path_ends_with_ext/clippy.toml | 1 + .../path_ends_with_ext/path_ends_with_ext.rs | 9 + .../tests/ui-toml/print_macro/print_macro.stderr | 2 + .../pub_crate_missing_doc.stderr | 1 + .../tests/ui-toml/result_large_err/clippy.toml | 1 + .../ui-toml/result_large_err/result_large_err.rs | 10 + .../result_large_err/result_large_err.stderr | 12 + .../tests/ui-toml/semicolon_block/both.fixed | 1 - .../clippy/tests/ui-toml/semicolon_block/both.rs | 1 - .../tests/ui-toml/semicolon_block/both.stderr | 10 +- .../semicolon_block/semicolon_inside_block.fixed | 1 - .../semicolon_block/semicolon_inside_block.rs | 1 - .../semicolon_block/semicolon_inside_block.stderr | 3 +- .../semicolon_block/semicolon_outside_block.fixed | 1 - .../semicolon_block/semicolon_outside_block.rs | 1 - .../semicolon_block/semicolon_outside_block.stderr | 7 +- .../strict_non_send_fields_in_send_ty/test.stderr | 1 + .../ui-toml/struct_excessive_bools/test.stderr | 1 + .../ui-toml/suppress_lint_in_const/test.stderr | 3 +- .../conf_french_disallowed_name.stderr | 1 + .../conf_disallowed_methods.stderr | 1 + .../conf_disallowed_types.stderr | 1 + .../tests/ui-toml/toml_trivially_copy/test.rs | 2 +- .../tests/ui-toml/toml_trivially_copy/test.stderr | 1 + .../toml_unknown_key/conf_unknown_key.stderr | 4 + .../ui-toml/too_large_for_stack/boxed_local.rs | 5 + .../ui-toml/too_large_for_stack/boxed_local.stderr | 11 + .../tests/ui-toml/too_large_for_stack/clippy.toml | 1 + .../ui-toml/too_large_for_stack/useless_vec.fixed | 9 + .../ui-toml/too_large_for_stack/useless_vec.rs | 9 + .../ui-toml/too_large_for_stack/useless_vec.stderr | 11 + .../tests/ui-toml/too_many_arguments/clippy.toml | 1 + .../too_many_arguments/too_many_arguments.rs | 7 + .../too_many_arguments/too_many_arguments.stderr | 11 + .../tests/ui-toml/type_complexity/clippy.toml | 1 + .../ui-toml/type_complexity/type_complexity.rs | 7 + .../ui-toml/type_complexity/type_complexity.stderr | 11 + .../ui-toml/type_repetition_in_bounds/clippy.toml | 1 + .../ui-toml/type_repetition_in_bounds/main.rs | 18 + .../ui-toml/type_repetition_in_bounds/main.stderr | 12 + .../auxiliary/proc_macro_unsafe.rs | 13 - .../ui-toml/undocumented_unsafe_blocks/clippy.toml | 2 - .../undocumented_unsafe_blocks/default/clippy.toml | 2 + .../disabled/clippy.toml | 3 + .../undocumented_unsafe_blocks.default.stderr | 316 +++++++++++ .../undocumented_unsafe_blocks.disabled.stderr | 396 +++++++++++++ .../undocumented_unsafe_blocks.rs | 46 +- .../undocumented_unsafe_blocks.stderr | 314 ----------- .../ui-toml/unnecessary_box_returns/clippy.toml | 1 + .../unnecessary_box_returns.fixed | 11 + .../unnecessary_box_returns.rs | 11 + .../unnecessary_box_returns.stderr | 12 + .../tests/ui-toml/unwrap_used/unwrap_used.fixed | 95 ++++ .../tests/ui-toml/unwrap_used/unwrap_used.stderr | 2 + .../upper_case_acronyms.fixed | 44 ++ .../upper_case_acronyms.stderr | 1 + .../clippy/tests/ui-toml/vec_box_sized/test.fixed | 16 + .../clippy/tests/ui-toml/vec_box_sized/test.stderr | 1 + .../tests/ui-toml/verbose_bit_mask/clippy.toml | 1 + .../verbose_bit_mask/verbose_bit_mask.fixed | 7 + .../ui-toml/verbose_bit_mask/verbose_bit_mask.rs | 7 + .../verbose_bit_mask/verbose_bit_mask.stderr | 11 + .../tests/ui-toml/wildcard_imports/clippy.toml | 1 + .../wildcard_imports/wildcard_imports.fixed | 11 + .../ui-toml/wildcard_imports/wildcard_imports.rs | 11 + .../wildcard_imports/wildcard_imports.stderr | 11 + .../clippy/tests/ui/absurd-extreme-comparisons.rs | 19 + .../tests/ui/absurd-extreme-comparisons.stderr | 35 +- src/tools/clippy/tests/ui/allow_attributes.fixed | 10 +- src/tools/clippy/tests/ui/allow_attributes.rs | 10 +- src/tools/clippy/tests/ui/allow_attributes.stderr | 5 +- .../tests/ui/allow_attributes_without_reason.rs | 2 +- .../clippy/tests/ui/almost_complete_range.fixed | 3 +- src/tools/clippy/tests/ui/almost_complete_range.rs | 3 +- .../clippy/tests/ui/almost_complete_range.stderr | 55 +- src/tools/clippy/tests/ui/approx_const.rs | 23 + src/tools/clippy/tests/ui/approx_const.stderr | 45 +- .../clippy/tests/ui/arc_with_non_send_sync.rs | 2 +- .../clippy/tests/ui/arc_with_non_send_sync.stderr | 1 + .../clippy/tests/ui/arithmetic_side_effects.rs | 34 +- .../clippy/tests/ui/arithmetic_side_effects.stderr | 15 +- src/tools/clippy/tests/ui/as_conversions.rs | 2 +- src/tools/clippy/tests/ui/as_conversions.stderr | 1 + src/tools/clippy/tests/ui/as_ptr_cast_mut.rs | 4 + src/tools/clippy/tests/ui/as_ptr_cast_mut.stderr | 5 +- src/tools/clippy/tests/ui/as_underscore.fixed | 2 - src/tools/clippy/tests/ui/as_underscore.rs | 2 - src/tools/clippy/tests/ui/as_underscore.stderr | 5 +- src/tools/clippy/tests/ui/asm_syntax.rs | 5 + src/tools/clippy/tests/ui/asm_syntax.stderr | 10 +- .../clippy/tests/ui/assertions_on_constants.rs | 9 + .../clippy/tests/ui/assertions_on_constants.stderr | 17 +- .../tests/ui/assertions_on_result_states.fixed | 1 - .../clippy/tests/ui/assertions_on_result_states.rs | 1 - .../tests/ui/assertions_on_result_states.stderr | 15 +- src/tools/clippy/tests/ui/assign_ops.fixed | 2 - src/tools/clippy/tests/ui/assign_ops.rs | 2 - src/tools/clippy/tests/ui/assign_ops.stderr | 23 +- src/tools/clippy/tests/ui/assign_ops2.rs | 13 + src/tools/clippy/tests/ui/assign_ops2.stderr | 22 +- src/tools/clippy/tests/ui/async_yields_async.fixed | 1 - src/tools/clippy/tests/ui/async_yields_async.rs | 1 - .../clippy/tests/ui/async_yields_async.stderr | 13 +- src/tools/clippy/tests/ui/attrs.rs | 5 + src/tools/clippy/tests/ui/attrs.stderr | 6 +- src/tools/clippy/tests/ui/await_holding_lock.rs | 13 + .../clippy/tests/ui/await_holding_lock.stderr | 151 ++--- .../clippy/tests/ui/await_holding_refcell_ref.rs | 6 + .../tests/ui/await_holding_refcell_ref.stderr | 74 +-- .../clippy/tests/ui/bind_instead_of_map.fixed | 1 - src/tools/clippy/tests/ui/bind_instead_of_map.rs | 1 - .../clippy/tests/ui/bind_instead_of_map.stderr | 8 +- .../tests/ui/bind_instead_of_map_multipart.fixed | 1 - .../tests/ui/bind_instead_of_map_multipart.rs | 1 - .../tests/ui/bind_instead_of_map_multipart.stderr | 12 +- src/tools/clippy/tests/ui/bit_masks.rs | 20 + src/tools/clippy/tests/ui/bit_masks.stderr | 32 +- .../tests/ui/blanket_clippy_restriction_lints.rs | 3 + .../ui/blanket_clippy_restriction_lints.stderr | 17 +- .../clippy/tests/ui/blocks_in_if_conditions.fixed | 1 - .../clippy/tests/ui/blocks_in_if_conditions.rs | 1 - .../clippy/tests/ui/blocks_in_if_conditions.stderr | 8 +- .../tests/ui/blocks_in_if_conditions_closure.rs | 3 + .../ui/blocks_in_if_conditions_closure.stderr | 6 +- .../clippy/tests/ui/bool_assert_comparison.fixed | 2 - .../clippy/tests/ui/bool_assert_comparison.rs | 2 - .../clippy/tests/ui/bool_assert_comparison.stderr | 67 +-- src/tools/clippy/tests/ui/bool_comparison.fixed | 4 +- src/tools/clippy/tests/ui/bool_comparison.rs | 4 +- src/tools/clippy/tests/ui/bool_comparison.stderr | 45 +- .../clippy/tests/ui/bool_to_int_with_if.fixed | 2 - src/tools/clippy/tests/ui/bool_to_int_with_if.rs | 2 - .../clippy/tests/ui/bool_to_int_with_if.stderr | 19 +- src/tools/clippy/tests/ui/borrow_as_ptr.fixed | 1 - src/tools/clippy/tests/ui/borrow_as_ptr.rs | 1 - src/tools/clippy/tests/ui/borrow_as_ptr.stderr | 5 +- .../clippy/tests/ui/borrow_as_ptr_no_std.fixed | 1 - src/tools/clippy/tests/ui/borrow_as_ptr_no_std.rs | 1 - .../clippy/tests/ui/borrow_as_ptr_no_std.stderr | 5 +- src/tools/clippy/tests/ui/borrow_box.rs | 11 + src/tools/clippy/tests/ui/borrow_box.stderr | 20 +- src/tools/clippy/tests/ui/borrow_deref_ref.fixed | 3 +- src/tools/clippy/tests/ui/borrow_deref_ref.rs | 3 +- src/tools/clippy/tests/ui/borrow_deref_ref.stderr | 7 +- .../clippy/tests/ui/borrow_deref_ref_unfixable.rs | 3 + .../tests/ui/borrow_deref_ref_unfixable.stderr | 3 +- src/tools/clippy/tests/ui/box_collection.rs | 9 + src/tools/clippy/tests/ui/box_collection.stderr | 17 +- src/tools/clippy/tests/ui/box_default.fixed | 3 +- src/tools/clippy/tests/ui/box_default.rs | 3 +- src/tools/clippy/tests/ui/box_default.stderr | 33 +- src/tools/clippy/tests/ui/boxed_local.rs | 5 + src/tools/clippy/tests/ui/boxed_local.stderr | 7 +- .../ui/branches_sharing_code/shared_at_bottom.rs | 14 +- .../branches_sharing_code/shared_at_bottom.stderr | 32 +- .../ui/branches_sharing_code/shared_at_top.rs | 9 +- .../ui/branches_sharing_code/shared_at_top.stderr | 21 +- .../shared_at_top_and_bottom.rs | 7 +- .../shared_at_top_and_bottom.stderr | 23 +- .../ui/branches_sharing_code/valid_if_blocks.rs | 5 + .../branches_sharing_code/valid_if_blocks.stderr | 22 +- .../clippy/tests/ui/builtin_type_shadow.stderr | 1 + src/tools/clippy/tests/ui/bytecount.rs | 29 +- src/tools/clippy/tests/ui/bytecount.stderr | 14 +- src/tools/clippy/tests/ui/bytes_count_to_len.fixed | 1 - src/tools/clippy/tests/ui/bytes_count_to_len.rs | 1 - .../clippy/tests/ui/bytes_count_to_len.stderr | 9 +- src/tools/clippy/tests/ui/bytes_nth.fixed | 2 - src/tools/clippy/tests/ui/bytes_nth.rs | 2 - src/tools/clippy/tests/ui/bytes_nth.stderr | 7 +- ...case_sensitive_file_extension_comparisons.fixed | 1 - .../case_sensitive_file_extension_comparisons.rs | 1 - ...ase_sensitive_file_extension_comparisons.stderr | 13 +- src/tools/clippy/tests/ui/cast.rs | 144 ++++- src/tools/clippy/tests/ui/cast.stderr | 143 ++--- .../clippy/tests/ui/cast_abs_to_unsigned.fixed | 2 - src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs | 2 - .../clippy/tests/ui/cast_abs_to_unsigned.stderr | 37 +- src/tools/clippy/tests/ui/cast_alignment.rs | 5 + src/tools/clippy/tests/ui/cast_alignment.stderr | 7 +- src/tools/clippy/tests/ui/cast_enum_constructor.rs | 3 + .../clippy/tests/ui/cast_enum_constructor.stderr | 3 +- src/tools/clippy/tests/ui/cast_lossless_bool.fixed | 2 - src/tools/clippy/tests/ui/cast_lossless_bool.rs | 2 - .../clippy/tests/ui/cast_lossless_bool.stderr | 29 +- .../clippy/tests/ui/cast_lossless_float.fixed | 2 - src/tools/clippy/tests/ui/cast_lossless_float.rs | 2 - .../clippy/tests/ui/cast_lossless_float.stderr | 23 +- .../clippy/tests/ui/cast_lossless_integer.fixed | 13 +- src/tools/clippy/tests/ui/cast_lossless_integer.rs | 13 +- .../clippy/tests/ui/cast_lossless_integer.stderr | 53 +- src/tools/clippy/tests/ui/cast_nan_to_int.rs | 12 + src/tools/clippy/tests/ui/cast_nan_to_int.stderr | 11 +- .../tests/ui/cast_raw_slice_pointer_cast.fixed | 1 - .../clippy/tests/ui/cast_raw_slice_pointer_cast.rs | 1 - .../tests/ui/cast_raw_slice_pointer_cast.stderr | 15 +- src/tools/clippy/tests/ui/cast_size.32bit.stderr | 181 ++++++ src/tools/clippy/tests/ui/cast_size.64bit.stderr | 172 ++++++ src/tools/clippy/tests/ui/cast_size.rs | 10 +- src/tools/clippy/tests/ui/cast_size.stderr | 169 ------ src/tools/clippy/tests/ui/cast_size_32bit.rs | 35 -- src/tools/clippy/tests/ui/cast_size_32bit.stderr | 171 ------ .../clippy/tests/ui/cast_slice_different_sizes.rs | 16 + .../tests/ui/cast_slice_different_sizes.stderr | 38 +- src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed | 2 +- src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs | 2 +- src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr | 1 + src/tools/clippy/tests/ui/cfg_features.fixed | 17 + src/tools/clippy/tests/ui/cfg_features.rs | 5 + src/tools/clippy/tests/ui/cfg_features.stderr | 7 +- src/tools/clippy/tests/ui/char_lit_as_u8.rs | 5 +- src/tools/clippy/tests/ui/char_lit_as_u8.stderr | 5 +- .../tests/ui/char_lit_as_u8_suggestions.fixed | 2 - .../clippy/tests/ui/char_lit_as_u8_suggestions.rs | 2 - .../tests/ui/char_lit_as_u8_suggestions.stderr | 21 +- .../clippy/tests/ui/checked_conversions.fixed | 2 - src/tools/clippy/tests/ui/checked_conversions.rs | 2 - .../clippy/tests/ui/checked_conversions.stderr | 35 +- .../ui/checked_unwrap/complex_conditionals.rs | 80 ++- .../ui/checked_unwrap/complex_conditionals.stderr | 86 +-- .../checked_unwrap/complex_conditionals_nested.rs | 10 +- .../complex_conditionals_nested.stderr | 9 +- .../tests/ui/checked_unwrap/simple_conditionals.rs | 143 ++++- .../ui/checked_unwrap/simple_conditionals.stderr | 153 +++-- src/tools/clippy/tests/ui/clear_with_drain.fixed | 1 - src/tools/clippy/tests/ui/clear_with_drain.rs | 1 - src/tools/clippy/tests/ui/clear_with_drain.stderr | 43 +- src/tools/clippy/tests/ui/clone_on_copy.fixed | 2 - src/tools/clippy/tests/ui/clone_on_copy.rs | 2 - src/tools/clippy/tests/ui/clone_on_copy.stderr | 19 +- src/tools/clippy/tests/ui/clone_on_copy_impl.rs | 2 +- .../clippy/tests/ui/cloned_instead_of_copied.fixed | 2 - .../clippy/tests/ui/cloned_instead_of_copied.rs | 2 - .../tests/ui/cloned_instead_of_copied.stderr | 17 +- src/tools/clippy/tests/ui/cmp_null.rs | 3 + src/tools/clippy/tests/ui/cmp_null.stderr | 3 +- .../tests/ui/cmp_owned/asymmetric_partial_eq.fixed | 1 - .../tests/ui/cmp_owned/asymmetric_partial_eq.rs | 1 - .../ui/cmp_owned/asymmetric_partial_eq.stderr | 13 +- .../tests/ui/cmp_owned/comparison_flip.fixed | 2 - .../clippy/tests/ui/cmp_owned/comparison_flip.rs | 2 - .../tests/ui/cmp_owned/comparison_flip.stderr | 5 +- .../tests/ui/cmp_owned/with_suggestion.fixed | 2 - .../clippy/tests/ui/cmp_owned/with_suggestion.rs | 2 - .../tests/ui/cmp_owned/with_suggestion.stderr | 13 +- .../tests/ui/cmp_owned/without_suggestion.rs | 4 + .../tests/ui/cmp_owned/without_suggestion.stderr | 5 +- src/tools/clippy/tests/ui/cognitive_complexity.rs | 20 + .../clippy/tests/ui/cognitive_complexity.stderr | 39 +- .../tests/ui/cognitive_complexity_attr_used.rs | 1 + .../tests/ui/cognitive_complexity_attr_used.stderr | 1 + .../clippy/tests/ui/collapsible_else_if.fixed | 1 - src/tools/clippy/tests/ui/collapsible_else_if.rs | 1 - .../clippy/tests/ui/collapsible_else_if.stderr | 17 +- src/tools/clippy/tests/ui/collapsible_if.fixed | 1 - src/tools/clippy/tests/ui/collapsible_if.rs | 1 - src/tools/clippy/tests/ui/collapsible_if.stderr | 19 +- src/tools/clippy/tests/ui/collapsible_match.rs | 12 + src/tools/clippy/tests/ui/collapsible_match.stderr | 65 ++- src/tools/clippy/tests/ui/collapsible_match2.rs | 4 + .../clippy/tests/ui/collapsible_match2.stderr | 25 +- .../clippy/tests/ui/collapsible_str_replace.fixed | 2 - .../clippy/tests/ui/collapsible_str_replace.rs | 2 - .../clippy/tests/ui/collapsible_str_replace.stderr | 29 +- .../clippy/tests/ui/collection_is_never_read.rs | 61 +- .../tests/ui/collection_is_never_read.stderr | 79 +-- src/tools/clippy/tests/ui/comparison_chain.rs | 7 + src/tools/clippy/tests/ui/comparison_chain.stderr | 35 +- .../clippy/tests/ui/comparison_to_empty.fixed | 2 - src/tools/clippy/tests/ui/comparison_to_empty.rs | 2 - .../clippy/tests/ui/comparison_to_empty.stderr | 19 +- src/tools/clippy/tests/ui/const_comparisons.rs | 85 ++- src/tools/clippy/tests/ui/const_comparisons.stderr | 88 +-- src/tools/clippy/tests/ui/copy_iterator.rs | 2 + src/tools/clippy/tests/ui/copy_iterator.stderr | 5 +- .../tests/ui/crashes/auxiliary/ice-7868-aux.rs | 2 + src/tools/clippy/tests/ui/crashes/ice-10148.rs | 4 +- src/tools/clippy/tests/ui/crashes/ice-10148.stderr | 1 + src/tools/clippy/tests/ui/crashes/ice-10645.stderr | 1 + src/tools/clippy/tests/ui/crashes/ice-10912.rs | 4 + src/tools/clippy/tests/ui/crashes/ice-10912.stderr | 5 +- src/tools/clippy/tests/ui/crashes/ice-11337.rs | 9 + src/tools/clippy/tests/ui/crashes/ice-11422.fixed | 25 + src/tools/clippy/tests/ui/crashes/ice-11422.rs | 25 + src/tools/clippy/tests/ui/crashes/ice-11422.stderr | 16 + src/tools/clippy/tests/ui/crashes/ice-2774.fixed | 29 + src/tools/clippy/tests/ui/crashes/ice-2774.rs | 2 + src/tools/clippy/tests/ui/crashes/ice-2774.stderr | 1 + src/tools/clippy/tests/ui/crashes/ice-360.rs | 6 +- src/tools/clippy/tests/ui/crashes/ice-360.stderr | 30 +- src/tools/clippy/tests/ui/crashes/ice-3717.fixed | 11 + src/tools/clippy/tests/ui/crashes/ice-3717.rs | 1 + src/tools/clippy/tests/ui/crashes/ice-3741.rs | 2 +- src/tools/clippy/tests/ui/crashes/ice-3891.rs | 1 + src/tools/clippy/tests/ui/crashes/ice-3969.rs | 6 + src/tools/clippy/tests/ui/crashes/ice-3969.stderr | 9 +- src/tools/clippy/tests/ui/crashes/ice-5835.fixed | 11 + src/tools/clippy/tests/ui/crashes/ice-5835.rs | 2 + src/tools/clippy/tests/ui/crashes/ice-5835.stderr | 1 + src/tools/clippy/tests/ui/crashes/ice-5872.fixed | 7 + src/tools/clippy/tests/ui/crashes/ice-5872.rs | 2 + src/tools/clippy/tests/ui/crashes/ice-5872.stderr | 1 + src/tools/clippy/tests/ui/crashes/ice-6250.rs | 2 +- src/tools/clippy/tests/ui/crashes/ice-6251.rs | 2 +- src/tools/clippy/tests/ui/crashes/ice-6251.stderr | 2 +- src/tools/clippy/tests/ui/crashes/ice-6252.rs | 1 + src/tools/clippy/tests/ui/crashes/ice-6252.stderr | 6 +- src/tools/clippy/tests/ui/crashes/ice-6254.rs | 2 + src/tools/clippy/tests/ui/crashes/ice-6254.stderr | 1 + src/tools/clippy/tests/ui/crashes/ice-7169.fixed | 13 + src/tools/clippy/tests/ui/crashes/ice-7169.rs | 2 + src/tools/clippy/tests/ui/crashes/ice-7169.stderr | 1 + src/tools/clippy/tests/ui/crashes/ice-7868.stderr | 1 + src/tools/clippy/tests/ui/crashes/ice-7869.rs | 1 + src/tools/clippy/tests/ui/crashes/ice-7869.stderr | 2 + src/tools/clippy/tests/ui/crashes/ice-8250.fixed | 8 + src/tools/clippy/tests/ui/crashes/ice-8250.rs | 2 + src/tools/clippy/tests/ui/crashes/ice-8250.stderr | 1 + src/tools/clippy/tests/ui/crashes/ice-8821.fixed | 10 + src/tools/clippy/tests/ui/crashes/ice-8821.rs | 2 + src/tools/clippy/tests/ui/crashes/ice-8821.stderr | 1 + src/tools/clippy/tests/ui/crashes/ice-8850.fixed | 31 + src/tools/clippy/tests/ui/crashes/ice-8850.rs | 4 + src/tools/clippy/tests/ui/crashes/ice-8850.stderr | 5 +- src/tools/clippy/tests/ui/crashes/ice-9041.rs | 4 +- src/tools/clippy/tests/ui/crashes/ice-9041.stderr | 1 + src/tools/clippy/tests/ui/crashes/ice-9405.stderr | 2 +- src/tools/clippy/tests/ui/crashes/ice-9445.rs | 2 + src/tools/clippy/tests/ui/crashes/ice-9445.stderr | 1 + src/tools/clippy/tests/ui/crashes/ice-9463.rs | 4 + src/tools/clippy/tests/ui/crashes/ice-9463.stderr | 4 +- src/tools/clippy/tests/ui/crashes/ice-96721.fixed | 10 + .../ui/crashes/needless_lifetimes_impl_trait.fixed | 21 + .../ui/crashes/needless_lifetimes_impl_trait.rs | 1 + .../needless_pass_by_value-w-late-bound.fixed | 10 + .../crashes/needless_pass_by_value-w-late-bound.rs | 1 + .../needless_pass_by_value-w-late-bound.stderr | 1 + src/tools/clippy/tests/ui/crate_in_macro_def.fixed | 1 - src/tools/clippy/tests/ui/crate_in_macro_def.rs | 1 - .../clippy/tests/ui/crate_in_macro_def.stderr | 3 +- .../tests/ui/crate_level_checks/no_std_swap.fixed | 13 + .../tests/ui/crate_level_checks/no_std_swap.rs | 2 + .../tests/ui/crate_level_checks/no_std_swap.stderr | 3 + .../ui/crate_level_checks/std_main_recursion.rs | 1 + .../crate_level_checks/std_main_recursion.stderr | 1 + src/tools/clippy/tests/ui/create_dir.fixed | 1 - src/tools/clippy/tests/ui/create_dir.rs | 1 - src/tools/clippy/tests/ui/create_dir.stderr | 5 +- src/tools/clippy/tests/ui/dbg_macro.rs | 21 + src/tools/clippy/tests/ui/dbg_macro.stderr | 37 +- .../clippy/tests/ui/debug_assert_with_mut_call.rs | 29 + .../tests/ui/debug_assert_with_mut_call.stderr | 55 +- .../tests/ui/decimal_literal_representation.fixed | 2 - .../tests/ui/decimal_literal_representation.rs | 2 - .../tests/ui/decimal_literal_representation.stderr | 15 +- .../ui/declare_interior_mutable_const/enums.stderr | 1 + .../declare_interior_mutable_const/others.stderr | 1 + .../declare_interior_mutable_const/traits.stderr | 1 + src/tools/clippy/tests/ui/def_id_nocore.rs | 1 + src/tools/clippy/tests/ui/def_id_nocore.stderr | 1 + .../ui/default_constructed_unit_structs.fixed | 2 - .../tests/ui/default_constructed_unit_structs.rs | 2 - .../ui/default_constructed_unit_structs.stderr | 13 +- .../tests/ui/default_instead_of_iter_empty.fixed | 1 - .../tests/ui/default_instead_of_iter_empty.rs | 1 - .../tests/ui/default_instead_of_iter_empty.stderr | 7 +- .../tests/ui/default_numeric_fallback_f64.fixed | 3 +- .../tests/ui/default_numeric_fallback_f64.rs | 3 +- .../tests/ui/default_numeric_fallback_f64.stderr | 49 +- .../tests/ui/default_numeric_fallback_i32.fixed | 3 +- .../tests/ui/default_numeric_fallback_i32.rs | 3 +- .../tests/ui/default_numeric_fallback_i32.stderr | 53 +- .../clippy/tests/ui/default_trait_access.fixed | 3 +- src/tools/clippy/tests/ui/default_trait_access.rs | 3 +- .../clippy/tests/ui/default_trait_access.stderr | 18 +- .../tests/ui/default_union_representation.rs | 4 + .../tests/ui/default_union_representation.stderr | 11 +- src/tools/clippy/tests/ui/deprecated.stderr | 1 + src/tools/clippy/tests/ui/deprecated_old.rs | 4 + src/tools/clippy/tests/ui/deprecated_old.stderr | 5 +- src/tools/clippy/tests/ui/deref_addrof.fixed | 3 +- src/tools/clippy/tests/ui/deref_addrof.rs | 3 +- src/tools/clippy/tests/ui/deref_addrof.stderr | 21 +- .../clippy/tests/ui/deref_addrof_double_trigger.rs | 6 +- .../tests/ui/deref_addrof_double_trigger.stderr | 5 +- src/tools/clippy/tests/ui/deref_addrof_macro.rs | 2 +- src/tools/clippy/tests/ui/deref_by_slicing.fixed | 2 - src/tools/clippy/tests/ui/deref_by_slicing.rs | 2 - src/tools/clippy/tests/ui/deref_by_slicing.stderr | 19 +- src/tools/clippy/tests/ui/derivable_impls.fixed | 15 +- src/tools/clippy/tests/ui/derivable_impls.rs | 15 +- src/tools/clippy/tests/ui/derivable_impls.stderr | 17 +- src/tools/clippy/tests/ui/derive.rs | 11 +- src/tools/clippy/tests/ui/derive.stderr | 27 +- .../clippy/tests/ui/derive_ord_xor_partial_ord.rs | 6 +- .../tests/ui/derive_ord_xor_partial_ord.stderr | 17 +- .../tests/ui/derive_partial_eq_without_eq.fixed | 2 - .../tests/ui/derive_partial_eq_without_eq.rs | 2 - .../tests/ui/derive_partial_eq_without_eq.stderr | 23 +- .../clippy/tests/ui/derived_hash_with_manual_eq.rs | 2 + .../tests/ui/derived_hash_with_manual_eq.stderr | 6 +- src/tools/clippy/tests/ui/disallowed_names.rs | 15 + src/tools/clippy/tests/ui/disallowed_names.stderr | 27 +- .../clippy/tests/ui/disallowed_script_idents.rs | 14 +- .../tests/ui/disallowed_script_idents.stderr | 8 +- .../clippy/tests/ui/diverging_sub_expression.rs | 12 + .../tests/ui/diverging_sub_expression.stderr | 21 +- src/tools/clippy/tests/ui/doc/doc-fixable.fixed | 12 +- src/tools/clippy/tests/ui/doc/doc-fixable.rs | 12 +- src/tools/clippy/tests/ui/doc/doc-fixable.stderr | 18 +- src/tools/clippy/tests/ui/doc/unbalanced_ticks.rs | 12 +- .../clippy/tests/ui/doc/unbalanced_ticks.stderr | 29 +- src/tools/clippy/tests/ui/doc_errors.rs | 39 ++ src/tools/clippy/tests/ui/doc_errors.stderr | 13 +- src/tools/clippy/tests/ui/doc_link_with_quotes.rs | 2 + .../clippy/tests/ui/doc_link_with_quotes.stderr | 1 + src/tools/clippy/tests/ui/doc_unsafe.rs | 2 +- src/tools/clippy/tests/ui/doc_unsafe.stderr | 1 + src/tools/clippy/tests/ui/double_comparison.fixed | 1 - src/tools/clippy/tests/ui/double_comparison.rs | 1 - src/tools/clippy/tests/ui/double_comparison.stderr | 17 +- src/tools/clippy/tests/ui/double_must_use.rs | 4 + src/tools/clippy/tests/ui/double_must_use.stderr | 7 +- src/tools/clippy/tests/ui/double_neg.rs | 2 + src/tools/clippy/tests/ui/double_neg.stderr | 1 + src/tools/clippy/tests/ui/double_parens.rs | 7 + src/tools/clippy/tests/ui/double_parens.stderr | 11 +- src/tools/clippy/tests/ui/drain_collect.fixed | 2 - src/tools/clippy/tests/ui/drain_collect.rs | 2 - src/tools/clippy/tests/ui/drain_collect.stderr | 22 +- src/tools/clippy/tests/ui/drop_non_drop.rs | 2 + src/tools/clippy/tests/ui/drop_non_drop.stderr | 5 +- .../tests/ui/duplicate_underscore_argument.rs | 2 + .../tests/ui/duplicate_underscore_argument.stderr | 1 + src/tools/clippy/tests/ui/duration_subsec.fixed | 1 - src/tools/clippy/tests/ui/duration_subsec.rs | 1 - src/tools/clippy/tests/ui/duration_subsec.stderr | 11 +- .../clippy/tests/ui/else_if_without_else.stderr | 1 + src/tools/clippy/tests/ui/empty_drop.fixed | 1 - src/tools/clippy/tests/ui/empty_drop.rs | 1 - src/tools/clippy/tests/ui/empty_drop.stderr | 5 +- src/tools/clippy/tests/ui/empty_enum.rs | 1 + src/tools/clippy/tests/ui/empty_enum.stderr | 1 + .../tests/ui/empty_line_after_doc_comments.rs | 5 +- .../tests/ui/empty_line_after_doc_comments.stderr | 1 + .../tests/ui/empty_line_after_outer_attribute.rs | 5 +- .../ui/empty_line_after_outer_attribute.stderr | 1 + src/tools/clippy/tests/ui/empty_loop.rs | 5 +- src/tools/clippy/tests/ui/empty_loop.stderr | 5 +- src/tools/clippy/tests/ui/empty_loop_no_std.rs | 2 + src/tools/clippy/tests/ui/empty_loop_no_std.stderr | 3 +- .../tests/ui/empty_structs_with_brackets.fixed | 1 - .../clippy/tests/ui/empty_structs_with_brackets.rs | 1 - .../tests/ui/empty_structs_with_brackets.stderr | 5 +- src/tools/clippy/tests/ui/endian_bytes.stderr | 3 + src/tools/clippy/tests/ui/entry.fixed | 1 - src/tools/clippy/tests/ui/entry.rs | 1 - src/tools/clippy/tests/ui/entry.stderr | 21 +- src/tools/clippy/tests/ui/entry_btree.fixed | 2 - src/tools/clippy/tests/ui/entry_btree.rs | 2 - src/tools/clippy/tests/ui/entry_btree.stderr | 3 +- src/tools/clippy/tests/ui/entry_with_else.fixed | 2 - src/tools/clippy/tests/ui/entry_with_else.rs | 2 - src/tools/clippy/tests/ui/entry_with_else.stderr | 15 +- .../tests/ui/enum_clike_unportable_variant.rs | 12 +- .../tests/ui/enum_clike_unportable_variant.stderr | 17 +- src/tools/clippy/tests/ui/enum_glob_use.fixed | 2 - src/tools/clippy/tests/ui/enum_glob_use.rs | 2 - src/tools/clippy/tests/ui/enum_glob_use.stderr | 7 +- src/tools/clippy/tests/ui/enum_variants.rs | 15 + src/tools/clippy/tests/ui/enum_variants.stderr | 45 +- .../clippy/tests/ui/eprint_with_newline.fixed | 69 +++ src/tools/clippy/tests/ui/eprint_with_newline.rs | 24 +- .../clippy/tests/ui/eprint_with_newline.stderr | 53 +- src/tools/clippy/tests/ui/eq_op.rs | 31 + src/tools/clippy/tests/ui/eq_op.stderr | 57 +- src/tools/clippy/tests/ui/eq_op_macros.rs | 8 + src/tools/clippy/tests/ui/eq_op_macros.stderr | 15 +- src/tools/clippy/tests/ui/equatable_if_let.fixed | 3 +- src/tools/clippy/tests/ui/equatable_if_let.rs | 3 +- src/tools/clippy/tests/ui/equatable_if_let.stderr | 29 +- src/tools/clippy/tests/ui/erasing_op.rs | 6 + src/tools/clippy/tests/ui/erasing_op.stderr | 9 +- src/tools/clippy/tests/ui/err_expect.fixed | 2 - src/tools/clippy/tests/ui/err_expect.rs | 2 - src/tools/clippy/tests/ui/err_expect.stderr | 5 +- src/tools/clippy/tests/ui/error_impl_error.rs | 4 + src/tools/clippy/tests/ui/error_impl_error.stderr | 13 +- src/tools/clippy/tests/ui/eta.fixed | 4 +- src/tools/clippy/tests/ui/eta.rs | 4 +- src/tools/clippy/tests/ui/eta.stderr | 2 + .../clippy/tests/ui/excessive_precision.fixed | 1 - src/tools/clippy/tests/ui/excessive_precision.rs | 1 - .../clippy/tests/ui/excessive_precision.stderr | 31 +- src/tools/clippy/tests/ui/exhaustive_items.fixed | 2 - src/tools/clippy/tests/ui/exhaustive_items.rs | 2 - src/tools/clippy/tests/ui/exhaustive_items.stderr | 10 +- src/tools/clippy/tests/ui/exit1.rs | 2 + src/tools/clippy/tests/ui/exit1.stderr | 1 + src/tools/clippy/tests/ui/exit2.rs | 2 + src/tools/clippy/tests/ui/exit2.stderr | 1 + src/tools/clippy/tests/ui/expect.rs | 3 + src/tools/clippy/tests/ui/expect.stderr | 5 +- src/tools/clippy/tests/ui/expect_fun_call.fixed | 1 - src/tools/clippy/tests/ui/expect_fun_call.rs | 1 - src/tools/clippy/tests/ui/expect_fun_call.stderr | 31 +- .../clippy/tests/ui/expect_tool_lint_rfc_2383.rs | 7 + .../tests/ui/expect_tool_lint_rfc_2383.stderr | 11 +- .../clippy/tests/ui/explicit_auto_deref.fixed | 32 +- src/tools/clippy/tests/ui/explicit_auto_deref.rs | 30 +- .../clippy/tests/ui/explicit_auto_deref.stderr | 89 +-- src/tools/clippy/tests/ui/explicit_counter_loop.rs | 13 +- .../clippy/tests/ui/explicit_counter_loop.stderr | 17 +- .../clippy/tests/ui/explicit_deref_methods.fixed | 1 - .../clippy/tests/ui/explicit_deref_methods.rs | 1 - .../clippy/tests/ui/explicit_deref_methods.stderr | 25 +- .../clippy/tests/ui/explicit_into_iter_loop.fixed | 1 - .../clippy/tests/ui/explicit_into_iter_loop.rs | 1 - .../clippy/tests/ui/explicit_into_iter_loop.stderr | 13 +- src/tools/clippy/tests/ui/explicit_iter_loop.fixed | 8 +- src/tools/clippy/tests/ui/explicit_iter_loop.rs | 2 +- .../clippy/tests/ui/explicit_iter_loop.stderr | 30 +- src/tools/clippy/tests/ui/explicit_write.fixed | 1 - src/tools/clippy/tests/ui/explicit_write.rs | 1 - src/tools/clippy/tests/ui/explicit_write.stderr | 35 +- src/tools/clippy/tests/ui/extend_with_drain.fixed | 1 - src/tools/clippy/tests/ui/extend_with_drain.rs | 1 - src/tools/clippy/tests/ui/extend_with_drain.stderr | 9 +- .../clippy/tests/ui/extra_unused_lifetimes.rs | 2 +- .../clippy/tests/ui/extra_unused_lifetimes.stderr | 1 + .../tests/ui/extra_unused_type_parameters.fixed | 18 +- .../tests/ui/extra_unused_type_parameters.rs | 18 +- .../tests/ui/extra_unused_type_parameters.stderr | 17 +- .../ui/extra_unused_type_parameters_unfixable.rs | 3 + .../extra_unused_type_parameters_unfixable.stderr | 5 +- src/tools/clippy/tests/ui/fallible_impl_from.rs | 4 + .../clippy/tests/ui/fallible_impl_from.stderr | 21 +- .../clippy/tests/ui/field_reassign_with_default.rs | 4 +- .../tests/ui/field_reassign_with_default.stderr | 1 + src/tools/clippy/tests/ui/filetype_is_file.rs | 3 + src/tools/clippy/tests/ui/filetype_is_file.stderr | 5 +- .../clippy/tests/ui/filter_map_bool_then.fixed | 27 +- src/tools/clippy/tests/ui/filter_map_bool_then.rs | 27 +- .../clippy/tests/ui/filter_map_bool_then.stderr | 39 +- .../clippy/tests/ui/filter_map_identity.fixed | 2 - src/tools/clippy/tests/ui/filter_map_identity.rs | 2 - .../clippy/tests/ui/filter_map_identity.stderr | 9 +- src/tools/clippy/tests/ui/filter_map_next.rs | 2 + src/tools/clippy/tests/ui/filter_map_next.stderr | 5 +- .../clippy/tests/ui/filter_map_next_fixable.fixed | 2 - .../clippy/tests/ui/filter_map_next_fixable.rs | 2 - .../clippy/tests/ui/filter_map_next_fixable.stderr | 5 +- src/tools/clippy/tests/ui/flat_map_identity.fixed | 2 - src/tools/clippy/tests/ui/flat_map_identity.rs | 2 - src/tools/clippy/tests/ui/flat_map_identity.stderr | 7 +- src/tools/clippy/tests/ui/flat_map_option.fixed | 1 - src/tools/clippy/tests/ui/flat_map_option.rs | 1 - src/tools/clippy/tests/ui/flat_map_option.stderr | 5 +- src/tools/clippy/tests/ui/float_arithmetic.rs | 18 + src/tools/clippy/tests/ui/float_arithmetic.stderr | 33 +- src/tools/clippy/tests/ui/float_cmp.rs | 27 +- src/tools/clippy/tests/ui/float_cmp.stderr | 13 +- src/tools/clippy/tests/ui/float_cmp_const.rs | 18 +- src/tools/clippy/tests/ui/float_cmp_const.stderr | 15 +- .../clippy/tests/ui/float_equality_without_abs.rs | 14 +- .../tests/ui/float_equality_without_abs.stderr | 21 +- src/tools/clippy/tests/ui/floating_point_abs.fixed | 1 - src/tools/clippy/tests/ui/floating_point_abs.rs | 1 - .../clippy/tests/ui/floating_point_abs.stderr | 17 +- src/tools/clippy/tests/ui/floating_point_exp.fixed | 1 - src/tools/clippy/tests/ui/floating_point_exp.rs | 1 - .../clippy/tests/ui/floating_point_exp.stderr | 11 +- .../clippy/tests/ui/floating_point_hypot.fixed | 1 - src/tools/clippy/tests/ui/floating_point_hypot.rs | 1 - .../clippy/tests/ui/floating_point_hypot.stderr | 7 +- src/tools/clippy/tests/ui/floating_point_log.fixed | 1 - src/tools/clippy/tests/ui/floating_point_log.rs | 1 - .../clippy/tests/ui/floating_point_log.stderr | 60 +- .../clippy/tests/ui/floating_point_logbase.fixed | 1 - .../clippy/tests/ui/floating_point_logbase.rs | 1 - .../clippy/tests/ui/floating_point_logbase.stderr | 11 +- .../clippy/tests/ui/floating_point_mul_add.fixed | 1 - .../clippy/tests/ui/floating_point_mul_add.rs | 1 - .../clippy/tests/ui/floating_point_mul_add.stderr | 25 +- .../clippy/tests/ui/floating_point_powf.fixed | 1 - src/tools/clippy/tests/ui/floating_point_powf.rs | 1 - .../clippy/tests/ui/floating_point_powf.stderr | 64 ++- .../clippy/tests/ui/floating_point_powi.fixed | 1 - src/tools/clippy/tests/ui/floating_point_powi.rs | 1 - .../clippy/tests/ui/floating_point_powi.stderr | 29 +- src/tools/clippy/tests/ui/floating_point_rad.fixed | 1 - src/tools/clippy/tests/ui/floating_point_rad.rs | 1 - .../clippy/tests/ui/floating_point_rad.stderr | 17 +- .../clippy/tests/ui/fn_address_comparisons.rs | 3 + .../clippy/tests/ui/fn_address_comparisons.stderr | 3 +- .../clippy/tests/ui/fn_params_excessive_bools.rs | 7 + .../tests/ui/fn_params_excessive_bools.stderr | 15 +- .../tests/ui/fn_to_numeric_cast.32bit.stderr | 146 +++++ .../tests/ui/fn_to_numeric_cast.64bit.stderr | 146 +++++ src/tools/clippy/tests/ui/fn_to_numeric_cast.rs | 4 +- .../clippy/tests/ui/fn_to_numeric_cast.stderr | 144 ----- .../clippy/tests/ui/fn_to_numeric_cast_32bit.rs | 55 -- .../tests/ui/fn_to_numeric_cast_32bit.stderr | 144 ----- .../clippy/tests/ui/fn_to_numeric_cast_any.rs | 20 +- .../clippy/tests/ui/fn_to_numeric_cast_any.stderr | 33 +- src/tools/clippy/tests/ui/for_kv_map.fixed | 56 ++ src/tools/clippy/tests/ui/for_kv_map.rs | 6 + src/tools/clippy/tests/ui/for_kv_map.stderr | 9 +- src/tools/clippy/tests/ui/forget_non_drop.rs | 2 + src/tools/clippy/tests/ui/forget_non_drop.stderr | 5 +- src/tools/clippy/tests/ui/format.fixed | 1 - src/tools/clippy/tests/ui/format.rs | 1 - src/tools/clippy/tests/ui/format.stderr | 35 +- src/tools/clippy/tests/ui/format_args.fixed | 1 - src/tools/clippy/tests/ui/format_args.rs | 1 - src/tools/clippy/tests/ui/format_args.stderr | 51 +- src/tools/clippy/tests/ui/format_args_unfixable.rs | 18 + .../clippy/tests/ui/format_args_unfixable.stderr | 37 +- src/tools/clippy/tests/ui/format_collect.rs | 3 + src/tools/clippy/tests/ui/format_collect.stderr | 14 +- src/tools/clippy/tests/ui/format_push_string.rs | 5 + .../clippy/tests/ui/format_push_string.stderr | 12 +- src/tools/clippy/tests/ui/formatting.rs | 12 + src/tools/clippy/tests/ui/formatting.stderr | 12 +- .../clippy/tests/ui/four_forward_slashes.fixed | 4 +- src/tools/clippy/tests/ui/four_forward_slashes.rs | 4 +- .../clippy/tests/ui/four_forward_slashes.stderr | 1 + .../tests/ui/four_forward_slashes_first_line.fixed | 1 - .../tests/ui/four_forward_slashes_first_line.rs | 1 - .../ui/four_forward_slashes_first_line.stderr | 1 + .../tests/ui/from_iter_instead_of_collect.fixed | 2 - .../tests/ui/from_iter_instead_of_collect.rs | 2 - .../tests/ui/from_iter_instead_of_collect.stderr | 31 +- src/tools/clippy/tests/ui/from_over_into.fixed | 2 - src/tools/clippy/tests/ui/from_over_into.rs | 2 - src/tools/clippy/tests/ui/from_over_into.stderr | 13 +- .../clippy/tests/ui/from_over_into_unfixable.rs | 4 + .../tests/ui/from_over_into_unfixable.stderr | 7 +- .../clippy/tests/ui/from_raw_with_void_ptr.rs | 5 + .../clippy/tests/ui/from_raw_with_void_ptr.stderr | 17 +- src/tools/clippy/tests/ui/from_str_radix_10.fixed | 61 ++ src/tools/clippy/tests/ui/from_str_radix_10.rs | 9 + src/tools/clippy/tests/ui/from_str_radix_10.stderr | 15 +- src/tools/clippy/tests/ui/functions.rs | 18 + src/tools/clippy/tests/ui/functions.stderr | 34 +- src/tools/clippy/tests/ui/functions_maxlines.rs | 2 + .../clippy/tests/ui/functions_maxlines.stderr | 5 +- src/tools/clippy/tests/ui/future_not_send.rs | 9 + src/tools/clippy/tests/ui/future_not_send.stderr | 64 +-- src/tools/clippy/tests/ui/get_first.fixed | 1 - src/tools/clippy/tests/ui/get_first.rs | 1 - src/tools/clippy/tests/ui/get_first.stderr | 7 +- src/tools/clippy/tests/ui/get_last_with_len.fixed | 2 - src/tools/clippy/tests/ui/get_last_with_len.rs | 2 - src/tools/clippy/tests/ui/get_last_with_len.stderr | 13 +- src/tools/clippy/tests/ui/get_unwrap.fixed | 2 - src/tools/clippy/tests/ui/get_unwrap.rs | 2 - src/tools/clippy/tests/ui/get_unwrap.stderr | 63 ++- src/tools/clippy/tests/ui/identity_op.fixed | 1 - src/tools/clippy/tests/ui/identity_op.rs | 1 - src/tools/clippy/tests/ui/identity_op.stderr | 81 +-- src/tools/clippy/tests/ui/if_let_mutex.rs | 3 + src/tools/clippy/tests/ui/if_let_mutex.stderr | 8 +- src/tools/clippy/tests/ui/if_not_else.rs | 2 + src/tools/clippy/tests/ui/if_not_else.stderr | 5 +- src/tools/clippy/tests/ui/if_same_then_else.stderr | 1 + src/tools/clippy/tests/ui/if_same_then_else2.rs | 2 +- .../clippy/tests/ui/if_same_then_else2.stderr | 22 +- .../clippy/tests/ui/if_then_some_else_none.rs | 17 + .../clippy/tests/ui/if_then_some_else_none.stderr | 12 +- src/tools/clippy/tests/ui/ifs_same_cond.stderr | 1 + .../clippy/tests/ui/ignored_unit_patterns.fixed | 18 +- src/tools/clippy/tests/ui/ignored_unit_patterns.rs | 18 +- .../clippy/tests/ui/ignored_unit_patterns.stderr | 17 +- src/tools/clippy/tests/ui/impl.rs | 4 + src/tools/clippy/tests/ui/impl.stderr | 14 +- src/tools/clippy/tests/ui/impl_trait_in_params.rs | 5 +- .../clippy/tests/ui/impl_trait_in_params.stderr | 3 +- src/tools/clippy/tests/ui/implicit_clone.fixed | 3 +- src/tools/clippy/tests/ui/implicit_clone.rs | 1 - src/tools/clippy/tests/ui/implicit_clone.stderr | 31 +- src/tools/clippy/tests/ui/implicit_hasher.rs | 4 +- src/tools/clippy/tests/ui/implicit_hasher.stderr | 163 +----- src/tools/clippy/tests/ui/implicit_return.fixed | 1 - src/tools/clippy/tests/ui/implicit_return.rs | 1 - src/tools/clippy/tests/ui/implicit_return.stderr | 33 +- .../clippy/tests/ui/implicit_saturating_add.fixed | 2 - .../clippy/tests/ui/implicit_saturating_add.rs | 2 - .../clippy/tests/ui/implicit_saturating_add.stderr | 49 +- .../clippy/tests/ui/implicit_saturating_sub.fixed | 1 - .../clippy/tests/ui/implicit_saturating_sub.rs | 1 - .../clippy/tests/ui/implicit_saturating_sub.stderr | 47 +- .../clippy/tests/ui/implied_bounds_in_impls.fixed | 125 ++++ .../clippy/tests/ui/implied_bounds_in_impls.rs | 125 ++++ .../clippy/tests/ui/implied_bounds_in_impls.stderr | 196 +++++++ .../tests/ui/inconsistent_digit_grouping.fixed | 1 - .../clippy/tests/ui/inconsistent_digit_grouping.rs | 1 - .../tests/ui/inconsistent_digit_grouping.stderr | 23 +- .../tests/ui/inconsistent_struct_constructor.fixed | 3 +- .../tests/ui/inconsistent_struct_constructor.rs | 3 +- .../ui/inconsistent_struct_constructor.stderr | 5 +- .../ui/incorrect_clone_impl_on_copy_type.fixed | 97 ---- .../tests/ui/incorrect_clone_impl_on_copy_type.rs | 107 ---- .../ui/incorrect_clone_impl_on_copy_type.stderr | 40 -- .../incorrect_partial_ord_impl_on_ord_type.fixed | 145 ----- .../ui/incorrect_partial_ord_impl_on_ord_type.rs | 149 ----- .../incorrect_partial_ord_impl_on_ord_type.stderr | 31 - ...rect_partial_ord_impl_on_ord_type_fully_qual.rs | 51 -- ..._partial_ord_impl_on_ord_type_fully_qual.stderr | 31 - .../if_let_slice_binding.fixed | 177 ++++++ .../index_refutable_slice/if_let_slice_binding.rs | 10 + .../if_let_slice_binding.stderr | 18 +- .../slice_indexing_in_macro.fixed | 29 + .../slice_indexing_in_macro.rs | 1 + .../clippy/tests/ui/indexing_slicing_index.rs | 52 +- .../clippy/tests/ui/indexing_slicing_index.stderr | 35 +- .../clippy/tests/ui/indexing_slicing_slice.rs | 23 +- .../clippy/tests/ui/indexing_slicing_slice.stderr | 44 +- .../clippy/tests/ui/inefficient_to_string.fixed | 1 - src/tools/clippy/tests/ui/inefficient_to_string.rs | 1 - .../clippy/tests/ui/inefficient_to_string.stderr | 14 +- .../tests/ui/infallible_destructuring_match.fixed | 1 - .../tests/ui/infallible_destructuring_match.rs | 1 - .../tests/ui/infallible_destructuring_match.stderr | 9 +- src/tools/clippy/tests/ui/infinite_iter.rs | 74 ++- src/tools/clippy/tests/ui/infinite_iter.stderr | 58 +- src/tools/clippy/tests/ui/infinite_loop.rs | 24 + src/tools/clippy/tests/ui/infinite_loop.stderr | 22 +- src/tools/clippy/tests/ui/inherent_to_string.rs | 2 + .../clippy/tests/ui/inherent_to_string.stderr | 5 +- .../clippy/tests/ui/inline_fn_without_body.fixed | 2 - .../clippy/tests/ui/inline_fn_without_body.rs | 2 - .../clippy/tests/ui/inline_fn_without_body.stderr | 7 +- src/tools/clippy/tests/ui/inspect_for_each.rs | 1 + src/tools/clippy/tests/ui/inspect_for_each.stderr | 2 + src/tools/clippy/tests/ui/int_plus_one.fixed | 2 - src/tools/clippy/tests/ui/int_plus_one.rs | 2 - src/tools/clippy/tests/ui/int_plus_one.stderr | 9 +- src/tools/clippy/tests/ui/integer_division.rs | 3 + src/tools/clippy/tests/ui/integer_division.stderr | 5 +- src/tools/clippy/tests/ui/into_iter_on_ref.fixed | 1 - src/tools/clippy/tests/ui/into_iter_on_ref.rs | 1 - src/tools/clippy/tests/ui/into_iter_on_ref.stderr | 55 +- .../clippy/tests/ui/invalid_null_ptr_usage.fixed | 2 - .../clippy/tests/ui/invalid_null_ptr_usage.rs | 2 - .../clippy/tests/ui/invalid_null_ptr_usage.stderr | 50 +- .../clippy/tests/ui/invalid_upcast_comparisons.rs | 28 + .../tests/ui/invalid_upcast_comparisons.stderr | 53 +- .../clippy/tests/ui/is_digit_ascii_radix.fixed | 2 - src/tools/clippy/tests/ui/is_digit_ascii_radix.rs | 2 - .../clippy/tests/ui/is_digit_ascii_radix.stderr | 7 +- src/tools/clippy/tests/ui/issue-7447.rs | 3 + src/tools/clippy/tests/ui/issue-7447.stderr | 3 +- src/tools/clippy/tests/ui/issue_2356.fixed | 1 - src/tools/clippy/tests/ui/issue_2356.rs | 1 - src/tools/clippy/tests/ui/issue_2356.stderr | 4 +- src/tools/clippy/tests/ui/issue_4266.rs | 4 + src/tools/clippy/tests/ui/issue_4266.stderr | 6 +- src/tools/clippy/tests/ui/items_after_statement.rs | 3 + .../clippy/tests/ui/items_after_statement.stderr | 8 +- .../clippy/tests/ui/iter_cloned_collect.fixed | 2 - src/tools/clippy/tests/ui/iter_cloned_collect.rs | 2 - .../clippy/tests/ui/iter_cloned_collect.stderr | 11 +- src/tools/clippy/tests/ui/iter_count.fixed | 1 - src/tools/clippy/tests/ui/iter_count.rs | 1 - src/tools/clippy/tests/ui/iter_count.stderr | 51 +- src/tools/clippy/tests/ui/iter_kv_map.fixed | 2 - src/tools/clippy/tests/ui/iter_kv_map.rs | 2 - src/tools/clippy/tests/ui/iter_kv_map.stderr | 57 +- src/tools/clippy/tests/ui/iter_next_slice.fixed | 1 - src/tools/clippy/tests/ui/iter_next_slice.rs | 1 - src/tools/clippy/tests/ui/iter_next_slice.stderr | 9 +- .../clippy/tests/ui/iter_not_returning_iterator.rs | 4 + .../tests/ui/iter_not_returning_iterator.stderr | 5 +- src/tools/clippy/tests/ui/iter_nth.stderr | 1 + src/tools/clippy/tests/ui/iter_nth_zero.fixed | 2 - src/tools/clippy/tests/ui/iter_nth_zero.rs | 2 - src/tools/clippy/tests/ui/iter_nth_zero.stderr | 7 +- .../tests/ui/iter_on_empty_collections.fixed | 1 - .../clippy/tests/ui/iter_on_empty_collections.rs | 1 - .../tests/ui/iter_on_empty_collections.stderr | 13 +- .../clippy/tests/ui/iter_on_single_items.fixed | 1 - src/tools/clippy/tests/ui/iter_on_single_items.rs | 1 - .../clippy/tests/ui/iter_on_single_items.stderr | 13 +- src/tools/clippy/tests/ui/iter_out_of_bounds.rs | 71 +++ .../clippy/tests/ui/iter_out_of_bounds.stderr | 119 ++++ .../clippy/tests/ui/iter_overeager_cloned.fixed | 53 +- src/tools/clippy/tests/ui/iter_overeager_cloned.rs | 43 +- .../clippy/tests/ui/iter_overeager_cloned.stderr | 114 +++- src/tools/clippy/tests/ui/iter_skip_next.fixed | 2 +- src/tools/clippy/tests/ui/iter_skip_next.rs | 2 +- src/tools/clippy/tests/ui/iter_skip_next.stderr | 1 + .../clippy/tests/ui/iter_skip_next_unfixable.rs | 7 +- .../tests/ui/iter_skip_next_unfixable.stderr | 9 +- src/tools/clippy/tests/ui/iter_skip_zero.fixed | 5 +- src/tools/clippy/tests/ui/iter_skip_zero.rs | 5 +- src/tools/clippy/tests/ui/iter_skip_zero.stderr | 11 +- src/tools/clippy/tests/ui/iter_with_drain.fixed | 1 - src/tools/clippy/tests/ui/iter_with_drain.rs | 1 - src/tools/clippy/tests/ui/iter_with_drain.stderr | 13 +- src/tools/clippy/tests/ui/iterator_step_by_zero.rs | 8 + .../clippy/tests/ui/iterator_step_by_zero.stderr | 13 +- src/tools/clippy/tests/ui/large_const_arrays.fixed | 2 - src/tools/clippy/tests/ui/large_const_arrays.rs | 2 - .../clippy/tests/ui/large_const_arrays.stderr | 19 +- src/tools/clippy/tests/ui/large_digit_groups.fixed | 1 - src/tools/clippy/tests/ui/large_digit_groups.rs | 1 - .../clippy/tests/ui/large_digit_groups.stderr | 12 +- .../tests/ui/large_enum_variant.32bit.stderr | 280 +++++++++ .../tests/ui/large_enum_variant.64bit.stderr | 280 +++++++++ src/tools/clippy/tests/ui/large_enum_variant.rs | 5 +- .../clippy/tests/ui/large_enum_variant.stderr | 279 --------- src/tools/clippy/tests/ui/large_futures.fixed | 70 +++ src/tools/clippy/tests/ui/large_futures.rs | 8 + src/tools/clippy/tests/ui/large_futures.stderr | 17 +- src/tools/clippy/tests/ui/large_stack_arrays.rs | 7 + .../clippy/tests/ui/large_stack_arrays.stderr | 13 +- src/tools/clippy/tests/ui/large_stack_frames.rs | 6 + .../clippy/tests/ui/large_stack_frames.stderr | 13 +- .../clippy/tests/ui/large_types_passed_by_value.rs | 2 +- .../tests/ui/large_types_passed_by_value.stderr | 1 + src/tools/clippy/tests/ui/len_without_is_empty.rs | 39 ++ .../clippy/tests/ui/len_without_is_empty.stderr | 50 +- src/tools/clippy/tests/ui/len_zero.fixed | 2 - src/tools/clippy/tests/ui/len_zero.rs | 2 - src/tools/clippy/tests/ui/len_zero.stderr | 48 +- src/tools/clippy/tests/ui/len_zero_ranges.fixed | 2 - src/tools/clippy/tests/ui/len_zero_ranges.rs | 2 - src/tools/clippy/tests/ui/len_zero_ranges.stderr | 5 +- src/tools/clippy/tests/ui/let_and_return.fixed | 187 ++++++ src/tools/clippy/tests/ui/let_and_return.rs | 5 + src/tools/clippy/tests/ui/let_and_return.stderr | 7 +- src/tools/clippy/tests/ui/let_if_seq.rs | 9 +- src/tools/clippy/tests/ui/let_if_seq.stderr | 18 +- src/tools/clippy/tests/ui/let_underscore_future.rs | 5 +- .../clippy/tests/ui/let_underscore_future.stderr | 5 +- src/tools/clippy/tests/ui/let_underscore_lock.rs | 4 + .../clippy/tests/ui/let_underscore_lock.stderr | 7 +- .../clippy/tests/ui/let_underscore_must_use.rs | 12 + .../clippy/tests/ui/let_underscore_must_use.stderr | 23 +- .../clippy/tests/ui/let_underscore_untyped.rs | 2 +- .../clippy/tests/ui/let_underscore_untyped.stderr | 1 + src/tools/clippy/tests/ui/let_unit.fixed | 4 +- src/tools/clippy/tests/ui/let_unit.rs | 4 +- src/tools/clippy/tests/ui/let_unit.stderr | 21 +- .../clippy/tests/ui/let_with_type_underscore.rs | 2 +- .../tests/ui/let_with_type_underscore.stderr | 1 + .../clippy/tests/ui/lines_filter_map_ok.fixed | 2 - src/tools/clippy/tests/ui/lines_filter_map_ok.rs | 2 - .../clippy/tests/ui/lines_filter_map_ok.stderr | 17 +- src/tools/clippy/tests/ui/linkedlist.rs | 9 + src/tools/clippy/tests/ui/linkedlist.stderr | 17 +- src/tools/clippy/tests/ui/literals.rs | 27 + src/tools/clippy/tests/ui/literals.stderr | 46 +- .../clippy/tests/ui/lossy_float_literal.fixed | 1 - src/tools/clippy/tests/ui/lossy_float_literal.rs | 1 - .../clippy/tests/ui/lossy_float_literal.stderr | 23 +- src/tools/clippy/tests/ui/macro_use_imports.fixed | 4 +- src/tools/clippy/tests/ui/macro_use_imports.rs | 4 +- src/tools/clippy/tests/ui/macro_use_imports.stderr | 13 +- .../clippy/tests/ui/macro_use_imports_expect.rs | 2 +- .../tests/ui/manual_assert.edition2018.fixed | 1 - .../tests/ui/manual_assert.edition2018.stderr | 19 +- .../tests/ui/manual_assert.edition2021.fixed | 1 - .../tests/ui/manual_assert.edition2021.stderr | 19 +- src/tools/clippy/tests/ui/manual_assert.rs | 1 - src/tools/clippy/tests/ui/manual_async_fn.fixed | 1 - src/tools/clippy/tests/ui/manual_async_fn.rs | 1 - src/tools/clippy/tests/ui/manual_async_fn.stderr | 27 +- src/tools/clippy/tests/ui/manual_bits.fixed | 2 - src/tools/clippy/tests/ui/manual_bits.rs | 2 - src/tools/clippy/tests/ui/manual_bits.stderr | 59 +- src/tools/clippy/tests/ui/manual_clamp.fixed | 296 ++++++++++ src/tools/clippy/tests/ui/manual_clamp.rs | 70 +++ src/tools/clippy/tests/ui/manual_clamp.stderr | 146 ++--- src/tools/clippy/tests/ui/manual_filter.fixed | 2 - src/tools/clippy/tests/ui/manual_filter.rs | 2 - src/tools/clippy/tests/ui/manual_filter.stderr | 31 +- src/tools/clippy/tests/ui/manual_filter_map.fixed | 1 - src/tools/clippy/tests/ui/manual_filter_map.rs | 1 - src/tools/clippy/tests/ui/manual_filter_map.stderr | 78 +-- src/tools/clippy/tests/ui/manual_find.rs | 6 +- src/tools/clippy/tests/ui/manual_find.stderr | 13 +- .../clippy/tests/ui/manual_find_fixable.fixed | 1 - src/tools/clippy/tests/ui/manual_find_fixable.rs | 1 - .../clippy/tests/ui/manual_find_fixable.stderr | 25 +- src/tools/clippy/tests/ui/manual_find_map.fixed | 1 - src/tools/clippy/tests/ui/manual_find_map.rs | 1 - src/tools/clippy/tests/ui/manual_find_map.stderr | 79 +-- src/tools/clippy/tests/ui/manual_flatten.rs | 11 +- src/tools/clippy/tests/ui/manual_flatten.stderr | 46 +- src/tools/clippy/tests/ui/manual_float_methods.rs | 3 +- .../clippy/tests/ui/manual_float_methods.stderr | 14 +- .../clippy/tests/ui/manual_instant_elapsed.fixed | 1 - .../clippy/tests/ui/manual_instant_elapsed.rs | 1 - .../clippy/tests/ui/manual_instant_elapsed.stderr | 5 +- .../clippy/tests/ui/manual_is_ascii_check.fixed | 2 - src/tools/clippy/tests/ui/manual_is_ascii_check.rs | 2 - .../clippy/tests/ui/manual_is_ascii_check.stderr | 41 +- src/tools/clippy/tests/ui/manual_let_else.rs | 28 +- src/tools/clippy/tests/ui/manual_let_else.stderr | 76 +-- .../clippy/tests/ui/manual_let_else_match.fixed | 135 +++++ src/tools/clippy/tests/ui/manual_let_else_match.rs | 10 + .../clippy/tests/ui/manual_let_else_match.stderr | 27 +- .../tests/ui/manual_let_else_question_mark.fixed | 1 - .../tests/ui/manual_let_else_question_mark.rs | 1 - .../tests/ui/manual_let_else_question_mark.stderr | 14 +- .../tests/ui/manual_main_separator_str.fixed | 2 - .../clippy/tests/ui/manual_main_separator_str.rs | 2 - .../tests/ui/manual_main_separator_str.stderr | 9 +- src/tools/clippy/tests/ui/manual_map_option.fixed | 3 +- src/tools/clippy/tests/ui/manual_map_option.rs | 3 +- src/tools/clippy/tests/ui/manual_map_option.stderr | 43 +- .../clippy/tests/ui/manual_map_option_2.fixed | 2 - src/tools/clippy/tests/ui/manual_map_option_2.rs | 2 - .../clippy/tests/ui/manual_map_option_2.stderr | 11 +- .../tests/ui/manual_memcpy/with_loop_counters.rs | 14 +- .../ui/manual_memcpy/with_loop_counters.stderr | 33 +- .../ui/manual_memcpy/without_loop_counters.rs | 16 +- .../ui/manual_memcpy/without_loop_counters.stderr | 39 +- src/tools/clippy/tests/ui/manual_next_back.fixed | 2 - src/tools/clippy/tests/ui/manual_next_back.rs | 2 - src/tools/clippy/tests/ui/manual_next_back.stderr | 5 +- .../clippy/tests/ui/manual_non_exhaustive_enum.rs | 4 +- .../tests/ui/manual_non_exhaustive_enum.stderr | 9 +- .../tests/ui/manual_non_exhaustive_struct.rs | 6 +- .../tests/ui/manual_non_exhaustive_struct.stderr | 17 +- src/tools/clippy/tests/ui/manual_ok_or.fixed | 1 - src/tools/clippy/tests/ui/manual_ok_or.rs | 1 - src/tools/clippy/tests/ui/manual_ok_or.stderr | 9 +- .../clippy/tests/ui/manual_range_patterns.fixed | 19 +- src/tools/clippy/tests/ui/manual_range_patterns.rs | 13 +- .../clippy/tests/ui/manual_range_patterns.stderr | 83 ++- src/tools/clippy/tests/ui/manual_rem_euclid.fixed | 3 +- src/tools/clippy/tests/ui/manual_rem_euclid.rs | 3 +- src/tools/clippy/tests/ui/manual_rem_euclid.stderr | 21 +- src/tools/clippy/tests/ui/manual_retain.fixed | 40 +- src/tools/clippy/tests/ui/manual_retain.rs | 40 +- src/tools/clippy/tests/ui/manual_retain.stderr | 63 ++- .../tests/ui/manual_saturating_arithmetic.fixed | 2 - .../tests/ui/manual_saturating_arithmetic.rs | 2 - .../tests/ui/manual_saturating_arithmetic.stderr | 49 +- .../tests/ui/manual_slice_size_calculation.fixed | 3 +- .../tests/ui/manual_slice_size_calculation.rs | 3 +- .../tests/ui/manual_slice_size_calculation.stderr | 15 +- src/tools/clippy/tests/ui/manual_split_once.fixed | 2 - src/tools/clippy/tests/ui/manual_split_once.rs | 2 - src/tools/clippy/tests/ui/manual_split_once.stderr | 39 +- src/tools/clippy/tests/ui/manual_str_repeat.fixed | 2 - src/tools/clippy/tests/ui/manual_str_repeat.rs | 2 - src/tools/clippy/tests/ui/manual_str_repeat.stderr | 25 +- src/tools/clippy/tests/ui/manual_string_new.fixed | 2 - src/tools/clippy/tests/ui/manual_string_new.rs | 2 - src/tools/clippy/tests/ui/manual_string_new.stderr | 19 +- src/tools/clippy/tests/ui/manual_strip.rs | 10 +- src/tools/clippy/tests/ui/manual_strip.stderr | 33 +- src/tools/clippy/tests/ui/manual_try_fold.rs | 4 +- src/tools/clippy/tests/ui/manual_try_fold.stderr | 1 + src/tools/clippy/tests/ui/manual_unwrap_or.fixed | 1 - src/tools/clippy/tests/ui/manual_unwrap_or.rs | 1 - src/tools/clippy/tests/ui/manual_unwrap_or.stderr | 29 +- .../clippy/tests/ui/manual_while_let_some.fixed | 2 - src/tools/clippy/tests/ui/manual_while_let_some.rs | 2 - .../clippy/tests/ui/manual_while_let_some.stderr | 15 +- .../clippy/tests/ui/many_single_char_names.rs | 6 + .../clippy/tests/ui/many_single_char_names.stderr | 8 +- src/tools/clippy/tests/ui/map_clone.fixed | 1 - src/tools/clippy/tests/ui/map_clone.rs | 1 - src/tools/clippy/tests/ui/map_clone.stderr | 13 +- .../clippy/tests/ui/map_collect_result_unit.fixed | 1 - .../clippy/tests/ui/map_collect_result_unit.rs | 1 - .../clippy/tests/ui/map_collect_result_unit.stderr | 5 +- src/tools/clippy/tests/ui/map_err.rs | 1 + src/tools/clippy/tests/ui/map_err.stderr | 1 + src/tools/clippy/tests/ui/map_flatten.rs | 7 +- src/tools/clippy/tests/ui/map_flatten.stderr | 22 +- .../clippy/tests/ui/map_flatten_fixable.fixed | 2 - src/tools/clippy/tests/ui/map_flatten_fixable.rs | 2 - .../clippy/tests/ui/map_flatten_fixable.stderr | 19 +- src/tools/clippy/tests/ui/map_identity.fixed | 1 - src/tools/clippy/tests/ui/map_identity.rs | 1 - src/tools/clippy/tests/ui/map_identity.stderr | 13 +- src/tools/clippy/tests/ui/map_unwrap_or.rs | 2 +- src/tools/clippy/tests/ui/map_unwrap_or.stderr | 1 + .../clippy/tests/ui/map_unwrap_or_fixable.fixed | 1 - src/tools/clippy/tests/ui/map_unwrap_or_fixable.rs | 1 - .../clippy/tests/ui/map_unwrap_or_fixable.stderr | 5 +- src/tools/clippy/tests/ui/match_as_ref.fixed | 2 - src/tools/clippy/tests/ui/match_as_ref.rs | 2 - src/tools/clippy/tests/ui/match_as_ref.stderr | 7 +- src/tools/clippy/tests/ui/match_bool.rs | 11 + src/tools/clippy/tests/ui/match_bool.stderr | 32 +- .../tests/ui/match_expr_like_matches_macro.fixed | 2 - .../tests/ui/match_expr_like_matches_macro.rs | 2 - .../tests/ui/match_expr_like_matches_macro.stderr | 30 +- src/tools/clippy/tests/ui/match_on_vec_items.rs | 11 +- .../clippy/tests/ui/match_on_vec_items.stderr | 15 +- src/tools/clippy/tests/ui/match_overlapping_arm.rs | 8 + .../clippy/tests/ui/match_overlapping_arm.stderr | 31 +- src/tools/clippy/tests/ui/match_ref_pats.fixed | 1 - src/tools/clippy/tests/ui/match_ref_pats.rs | 1 - src/tools/clippy/tests/ui/match_ref_pats.stderr | 12 +- src/tools/clippy/tests/ui/match_result_ok.fixed | 1 - src/tools/clippy/tests/ui/match_result_ok.rs | 1 - src/tools/clippy/tests/ui/match_result_ok.stderr | 7 +- src/tools/clippy/tests/ui/match_same_arms.rs | 1 + src/tools/clippy/tests/ui/match_same_arms.stderr | 33 +- src/tools/clippy/tests/ui/match_same_arms2.rs | 2 +- src/tools/clippy/tests/ui/match_same_arms2.stderr | 2 + .../tests/ui/match_same_arms_non_exhaustive.rs | 4 +- .../tests/ui/match_same_arms_non_exhaustive.stderr | 7 +- .../clippy/tests/ui/match_single_binding.fixed | 1 - src/tools/clippy/tests/ui/match_single_binding.rs | 1 - .../clippy/tests/ui/match_single_binding.stderr | 49 +- .../clippy/tests/ui/match_single_binding2.fixed | 1 - src/tools/clippy/tests/ui/match_single_binding2.rs | 1 - .../clippy/tests/ui/match_single_binding2.stderr | 9 +- .../clippy/tests/ui/match_str_case_mismatch.fixed | 1 - .../clippy/tests/ui/match_str_case_mismatch.rs | 1 - .../clippy/tests/ui/match_str_case_mismatch.stderr | 15 +- src/tools/clippy/tests/ui/match_wild_err_arm.rs | 8 + .../clippy/tests/ui/match_wild_err_arm.stderr | 7 +- .../ui/match_wildcard_for_single_variants.fixed | 2 - .../tests/ui/match_wildcard_for_single_variants.rs | 2 - .../ui/match_wildcard_for_single_variants.stderr | 21 +- src/tools/clippy/tests/ui/mem_forget.rs | 8 + src/tools/clippy/tests/ui/mem_forget.stderr | 7 +- src/tools/clippy/tests/ui/mem_replace.fixed | 2 - src/tools/clippy/tests/ui/mem_replace.rs | 2 - src/tools/clippy/tests/ui/mem_replace.stderr | 50 +- src/tools/clippy/tests/ui/mem_replace_macro.rs | 2 +- src/tools/clippy/tests/ui/mem_replace_macro.stderr | 1 + src/tools/clippy/tests/ui/methods.stderr | 2 + src/tools/clippy/tests/ui/methods_fixable.fixed | 2 - src/tools/clippy/tests/ui/methods_fixable.rs | 2 - src/tools/clippy/tests/ui/methods_fixable.stderr | 3 +- src/tools/clippy/tests/ui/methods_unfixable.rs | 3 +- src/tools/clippy/tests/ui/methods_unfixable.stderr | 1 + src/tools/clippy/tests/ui/min_ident_chars.rs | 2 +- src/tools/clippy/tests/ui/min_ident_chars.stderr | 1 + src/tools/clippy/tests/ui/min_max.rs | 14 + src/tools/clippy/tests/ui/min_max.stderr | 25 +- src/tools/clippy/tests/ui/min_rust_version_attr.rs | 6 + .../clippy/tests/ui/min_rust_version_attr.stderr | 10 +- .../tests/ui/min_rust_version_invalid_attr.rs | 5 + .../tests/ui/min_rust_version_invalid_attr.stderr | 14 +- .../tests/ui/mismatched_target_os_non_unix.fixed | 2 - .../tests/ui/mismatched_target_os_non_unix.rs | 2 - .../tests/ui/mismatched_target_os_non_unix.stderr | 9 +- .../tests/ui/mismatched_target_os_unix.fixed | 2 - .../clippy/tests/ui/mismatched_target_os_unix.rs | 2 - .../tests/ui/mismatched_target_os_unix.stderr | 35 +- .../tests/ui/mismatching_type_param_order.rs | 10 + .../tests/ui/mismatching_type_param_order.stderr | 17 +- src/tools/clippy/tests/ui/misnamed_getters.fixed | 143 +++++ src/tools/clippy/tests/ui/misnamed_getters.rs | 19 + src/tools/clippy/tests/ui/misnamed_getters.stderr | 54 +- .../clippy/tests/ui/missing_assert_message.rs | 16 + .../clippy/tests/ui/missing_assert_message.stderr | 31 +- .../tests/ui/missing_asserts_for_indexing.fixed | 121 ++++ .../tests/ui/missing_asserts_for_indexing.rs | 121 ++++ .../tests/ui/missing_asserts_for_indexing.stderr | 253 +++++++++ .../ui/missing_asserts_for_indexing_unfixable.rs | 49 ++ .../missing_asserts_for_indexing_unfixable.stderr | 164 ++++++ .../tests/ui/missing_const_for_fn/cant_be_const.rs | 2 +- .../ui/missing_const_for_fn/could_be_const.rs | 12 + .../ui/missing_const_for_fn/could_be_const.stderr | 33 +- src/tools/clippy/tests/ui/missing_doc.rs | 2 +- src/tools/clippy/tests/ui/missing_doc.stderr | 1 + .../clippy/tests/ui/missing_doc_crate_missing.rs | 2 + .../tests/ui/missing_doc_crate_missing.stderr | 3 + src/tools/clippy/tests/ui/missing_doc_impl.rs | 2 +- src/tools/clippy/tests/ui/missing_doc_impl.stderr | 1 + .../clippy/tests/ui/missing_fields_in_debug.rs | 3 + .../clippy/tests/ui/missing_fields_in_debug.stderr | 21 +- src/tools/clippy/tests/ui/missing_inline.rs | 25 +- src/tools/clippy/tests/ui/missing_inline.stderr | 25 +- .../clippy/tests/ui/missing_panics_doc.stderr | 1 + src/tools/clippy/tests/ui/missing_spin_loop.fixed | 1 - src/tools/clippy/tests/ui/missing_spin_loop.rs | 1 - src/tools/clippy/tests/ui/missing_spin_loop.stderr | 13 +- .../clippy/tests/ui/missing_spin_loop_no_std.fixed | 1 - .../clippy/tests/ui/missing_spin_loop_no_std.rs | 1 - .../tests/ui/missing_spin_loop_no_std.stderr | 3 +- src/tools/clippy/tests/ui/missing_trait_methods.rs | 2 + .../clippy/tests/ui/missing_trait_methods.stderr | 3 +- .../clippy/tests/ui/mistyped_literal_suffix.fixed | 3 +- .../clippy/tests/ui/mistyped_literal_suffix.rs | 3 +- .../clippy/tests/ui/mistyped_literal_suffix.stderr | 32 +- .../tests/ui/mixed_read_write_in_expression.rs | 4 + .../tests/ui/mixed_read_write_in_expression.stderr | 13 +- src/tools/clippy/tests/ui/module_inception.rs | 5 + src/tools/clippy/tests/ui/module_inception.stderr | 12 +- .../clippy/tests/ui/module_name_repetitions.rs | 6 + .../clippy/tests/ui/module_name_repetitions.stderr | 9 +- .../clippy/tests/ui/modulo_arithmetic_float.rs | 20 + .../clippy/tests/ui/modulo_arithmetic_float.stderr | 19 +- .../clippy/tests/ui/modulo_arithmetic_integral.rs | 34 ++ .../tests/ui/modulo_arithmetic_integral.stderr | 33 +- .../tests/ui/modulo_arithmetic_integral_const.rs | 34 ++ .../ui/modulo_arithmetic_integral_const.stderr | 33 +- src/tools/clippy/tests/ui/modulo_one.rs | 26 +- src/tools/clippy/tests/ui/modulo_one.stderr | 27 +- src/tools/clippy/tests/ui/multi_assignments.rs | 7 + src/tools/clippy/tests/ui/multi_assignments.stderr | 11 +- .../tests/ui/multiple_unsafe_ops_per_block.rs | 2 +- .../tests/ui/multiple_unsafe_ops_per_block.stderr | 1 + .../clippy/tests/ui/must_use_candidates.fixed | 1 - src/tools/clippy/tests/ui/must_use_candidates.rs | 1 - .../clippy/tests/ui/must_use_candidates.stderr | 11 +- src/tools/clippy/tests/ui/must_use_unit.fixed | 3 +- src/tools/clippy/tests/ui/must_use_unit.rs | 3 +- src/tools/clippy/tests/ui/must_use_unit.stderr | 7 +- src/tools/clippy/tests/ui/mut_from_ref.rs | 6 + src/tools/clippy/tests/ui/mut_from_ref.stderr | 21 +- src/tools/clippy/tests/ui/mut_key.rs | 20 +- src/tools/clippy/tests/ui/mut_key.stderr | 31 +- src/tools/clippy/tests/ui/mut_mut.rs | 2 +- src/tools/clippy/tests/ui/mut_mut.stderr | 1 + src/tools/clippy/tests/ui/mut_mutex_lock.fixed | 1 - src/tools/clippy/tests/ui/mut_mutex_lock.rs | 1 - src/tools/clippy/tests/ui/mut_mutex_lock.stderr | 3 +- src/tools/clippy/tests/ui/mut_range_bound.rs | 30 +- src/tools/clippy/tests/ui/mut_range_bound.stderr | 19 +- src/tools/clippy/tests/ui/mut_reference.rs | 6 +- src/tools/clippy/tests/ui/mut_reference.stderr | 5 +- src/tools/clippy/tests/ui/mutex_atomic.rs | 9 + src/tools/clippy/tests/ui/mutex_atomic.stderr | 14 +- .../tests/ui/needless_arbitrary_self_type.fixed | 2 - .../tests/ui/needless_arbitrary_self_type.rs | 2 - .../tests/ui/needless_arbitrary_self_type.stderr | 13 +- .../needless_arbitrary_self_type_unfixable.fixed | 46 ++ .../ui/needless_arbitrary_self_type_unfixable.rs | 5 +- .../needless_arbitrary_self_type_unfixable.stderr | 1 + .../clippy/tests/ui/needless_bitwise_bool.fixed | 2 - src/tools/clippy/tests/ui/needless_bitwise_bool.rs | 2 - .../clippy/tests/ui/needless_bitwise_bool.stderr | 3 +- .../clippy/tests/ui/needless_bool/fixable.fixed | 2 - src/tools/clippy/tests/ui/needless_bool/fixable.rs | 2 - .../clippy/tests/ui/needless_bool/fixable.stderr | 44 +- .../clippy/tests/ui/needless_bool/simple.stderr | 1 + .../clippy/tests/ui/needless_bool_assign.fixed | 2 - src/tools/clippy/tests/ui/needless_bool_assign.rs | 2 - .../clippy/tests/ui/needless_bool_assign.stderr | 11 +- src/tools/clippy/tests/ui/needless_borrow.fixed | 292 +--------- src/tools/clippy/tests/ui/needless_borrow.rs | 292 +--------- src/tools/clippy/tests/ui/needless_borrow.stderr | 131 +---- .../clippy/tests/ui/needless_borrow_pat.fixed | 163 ++++++ src/tools/clippy/tests/ui/needless_borrow_pat.rs | 13 + .../clippy/tests/ui/needless_borrow_pat.stderr | 27 +- .../clippy/tests/ui/needless_borrowed_ref.fixed | 2 - src/tools/clippy/tests/ui/needless_borrowed_ref.rs | 2 - .../clippy/tests/ui/needless_borrowed_ref.stderr | 35 +- .../ui/needless_borrows_for_generic_args.fixed | 287 ++++++++++ .../tests/ui/needless_borrows_for_generic_args.rs | 287 ++++++++++ .../ui/needless_borrows_for_generic_args.stderr | 77 +++ src/tools/clippy/tests/ui/needless_collect.fixed | 2 - src/tools/clippy/tests/ui/needless_collect.rs | 2 - src/tools/clippy/tests/ui/needless_collect.stderr | 39 +- .../clippy/tests/ui/needless_collect_indirect.rs | 19 +- .../tests/ui/needless_collect_indirect.stderr | 66 ++- src/tools/clippy/tests/ui/needless_continue.rs | 20 +- src/tools/clippy/tests/ui/needless_continue.stderr | 39 +- src/tools/clippy/tests/ui/needless_doc_main.rs | 6 + src/tools/clippy/tests/ui/needless_doc_main.stderr | 43 +- src/tools/clippy/tests/ui/needless_else.fixed | 1 - src/tools/clippy/tests/ui/needless_else.rs | 1 - src/tools/clippy/tests/ui/needless_else.stderr | 3 +- .../tests/ui/needless_for_each_fixable.fixed | 1 - .../clippy/tests/ui/needless_for_each_fixable.rs | 1 - .../tests/ui/needless_for_each_fixable.stderr | 17 +- .../clippy/tests/ui/needless_for_each_unfixable.rs | 3 + .../tests/ui/needless_for_each_unfixable.stderr | 11 +- src/tools/clippy/tests/ui/needless_if.fixed | 3 +- src/tools/clippy/tests/ui/needless_if.rs | 3 +- src/tools/clippy/tests/ui/needless_if.stderr | 15 +- src/tools/clippy/tests/ui/needless_late_init.fixed | 3 +- src/tools/clippy/tests/ui/needless_late_init.rs | 3 +- .../clippy/tests/ui/needless_late_init.stderr | 33 +- src/tools/clippy/tests/ui/needless_lifetimes.fixed | 3 +- src/tools/clippy/tests/ui/needless_lifetimes.rs | 3 +- .../clippy/tests/ui/needless_lifetimes.stderr | 93 +-- src/tools/clippy/tests/ui/needless_match.fixed | 1 - src/tools/clippy/tests/ui/needless_match.rs | 1 - src/tools/clippy/tests/ui/needless_match.stderr | 27 +- .../clippy/tests/ui/needless_option_as_deref.fixed | 2 - .../clippy/tests/ui/needless_option_as_deref.rs | 2 - .../tests/ui/needless_option_as_deref.stderr | 7 +- .../clippy/tests/ui/needless_option_take.fixed | 2 - src/tools/clippy/tests/ui/needless_option_take.rs | 2 - .../clippy/tests/ui/needless_option_take.stderr | 3 +- .../ui/needless_parens_on_range_literals.fixed | 1 - .../tests/ui/needless_parens_on_range_literals.rs | 1 - .../ui/needless_parens_on_range_literals.stderr | 13 +- .../clippy/tests/ui/needless_pass_by_ref_mut.rs | 47 +- .../tests/ui/needless_pass_by_ref_mut.stderr | 69 ++- .../clippy/tests/ui/needless_pass_by_value.rs | 25 +- .../clippy/tests/ui/needless_pass_by_value.stderr | 51 +- src/tools/clippy/tests/ui/needless_pub_self.fixed | 4 +- src/tools/clippy/tests/ui/needless_pub_self.rs | 4 +- src/tools/clippy/tests/ui/needless_pub_self.stderr | 1 + .../clippy/tests/ui/needless_question_mark.fixed | 2 - .../clippy/tests/ui/needless_question_mark.rs | 2 - .../clippy/tests/ui/needless_question_mark.stderr | 29 +- src/tools/clippy/tests/ui/needless_range_loop.rs | 17 +- .../clippy/tests/ui/needless_range_loop.stderr | 27 +- src/tools/clippy/tests/ui/needless_range_loop2.rs | 11 +- .../clippy/tests/ui/needless_range_loop2.stderr | 15 +- .../clippy/tests/ui/needless_raw_string.fixed | 14 +- src/tools/clippy/tests/ui/needless_raw_string.rs | 14 +- .../clippy/tests/ui/needless_raw_string.stderr | 53 +- .../tests/ui/needless_raw_string_hashes.fixed | 23 +- .../clippy/tests/ui/needless_raw_string_hashes.rs | 23 +- .../tests/ui/needless_raw_string_hashes.stderr | 179 +++++- src/tools/clippy/tests/ui/needless_return.fixed | 2 - src/tools/clippy/tests/ui/needless_return.rs | 2 - src/tools/clippy/tests/ui/needless_return.stderr | 105 ++-- .../ui/needless_return_with_question_mark.fixed | 3 +- .../tests/ui/needless_return_with_question_mark.rs | 3 +- .../ui/needless_return_with_question_mark.stderr | 3 +- src/tools/clippy/tests/ui/needless_splitn.fixed | 1 - src/tools/clippy/tests/ui/needless_splitn.rs | 1 - src/tools/clippy/tests/ui/needless_splitn.stderr | 27 +- src/tools/clippy/tests/ui/needless_update.rs | 2 + src/tools/clippy/tests/ui/needless_update.stderr | 1 + .../clippy/tests/ui/neg_cmp_op_on_partial_ord.rs | 5 + .../tests/ui/neg_cmp_op_on_partial_ord.stderr | 7 +- src/tools/clippy/tests/ui/neg_multiply.fixed | 1 - src/tools/clippy/tests/ui/neg_multiply.rs | 1 - src/tools/clippy/tests/ui/neg_multiply.stderr | 17 +- src/tools/clippy/tests/ui/never_loop.rs | 71 ++- src/tools/clippy/tests/ui/never_loop.stderr | 83 ++- src/tools/clippy/tests/ui/new_ret_no_self.rs | 13 + src/tools/clippy/tests/ui/new_ret_no_self.stderr | 34 +- .../clippy/tests/ui/new_without_default.fixed | 309 ++++++++++ src/tools/clippy/tests/ui/new_without_default.rs | 27 +- .../clippy/tests/ui/new_without_default.stderr | 43 +- src/tools/clippy/tests/ui/no_effect.rs | 31 + src/tools/clippy/tests/ui/no_effect.stderr | 58 +- src/tools/clippy/tests/ui/no_effect_replace.rs | 9 + src/tools/clippy/tests/ui/no_effect_replace.stderr | 15 +- src/tools/clippy/tests/ui/no_effect_return.rs | 12 + src/tools/clippy/tests/ui/no_effect_return.stderr | 23 +- .../clippy/tests/ui/no_mangle_with_rust_abi.rs | 7 + .../clippy/tests/ui/no_mangle_with_rust_abi.stderr | 12 +- .../clippy/tests/ui/non_canonical_clone_impl.fixed | 96 ++++ .../clippy/tests/ui/non_canonical_clone_impl.rs | 106 ++++ .../tests/ui/non_canonical_clone_impl.stderr | 41 ++ .../tests/ui/non_canonical_partial_ord_impl.fixed | 144 +++++ .../tests/ui/non_canonical_partial_ord_impl.rs | 148 +++++ .../tests/ui/non_canonical_partial_ord_impl.stderr | 32 ++ .../non_canonical_partial_ord_impl_fully_qual.rs | 51 ++ ...on_canonical_partial_ord_impl_fully_qual.stderr | 32 ++ .../clippy/tests/ui/non_expressive_names.stderr | 1 + src/tools/clippy/tests/ui/non_minimal_cfg.fixed | 2 - src/tools/clippy/tests/ui/non_minimal_cfg.rs | 2 - src/tools/clippy/tests/ui/non_minimal_cfg.stderr | 9 +- src/tools/clippy/tests/ui/non_minimal_cfg2.rs | 2 + src/tools/clippy/tests/ui/non_minimal_cfg2.stderr | 1 + .../tests/ui/non_octal_unix_permissions.fixed | 2 +- .../clippy/tests/ui/non_octal_unix_permissions.rs | 2 +- .../tests/ui/non_octal_unix_permissions.stderr | 1 + .../clippy/tests/ui/non_send_fields_in_send_ty.rs | 12 + .../tests/ui/non_send_fields_in_send_ty.stderr | 49 +- src/tools/clippy/tests/ui/nonminimal_bool.rs | 15 + src/tools/clippy/tests/ui/nonminimal_bool.stderr | 27 +- .../clippy/tests/ui/nonminimal_bool_methods.fixed | 1 - .../clippy/tests/ui/nonminimal_bool_methods.rs | 1 - .../clippy/tests/ui/nonminimal_bool_methods.stderr | 27 +- src/tools/clippy/tests/ui/numbered_fields.fixed | 1 - src/tools/clippy/tests/ui/numbered_fields.rs | 1 - src/tools/clippy/tests/ui/numbered_fields.stderr | 5 +- src/tools/clippy/tests/ui/obfuscated_if_else.fixed | 2 - src/tools/clippy/tests/ui/obfuscated_if_else.rs | 2 - .../clippy/tests/ui/obfuscated_if_else.stderr | 3 +- src/tools/clippy/tests/ui/octal_escapes.rs | 10 + src/tools/clippy/tests/ui/octal_escapes.stderr | 91 +-- src/tools/clippy/tests/ui/ok_expect.rs | 5 + src/tools/clippy/tests/ui/ok_expect.stderr | 9 +- .../clippy/tests/ui/only_used_in_recursion.rs | 18 +- .../clippy/tests/ui/only_used_in_recursion.stderr | 63 ++- .../clippy/tests/ui/only_used_in_recursion2.rs | 7 +- .../clippy/tests/ui/only_used_in_recursion2.stderr | 19 +- src/tools/clippy/tests/ui/op_ref.fixed | 99 ++++ src/tools/clippy/tests/ui/op_ref.rs | 5 + src/tools/clippy/tests/ui/op_ref.stderr | 7 +- src/tools/clippy/tests/ui/open_options.rs | 8 + src/tools/clippy/tests/ui/open_options.stderr | 13 +- .../clippy/tests/ui/option_as_ref_deref.fixed | 2 - src/tools/clippy/tests/ui/option_as_ref_deref.rs | 2 - .../clippy/tests/ui/option_as_ref_deref.stderr | 37 +- src/tools/clippy/tests/ui/option_env_unwrap.rs | 2 +- src/tools/clippy/tests/ui/option_env_unwrap.stderr | 1 + src/tools/clippy/tests/ui/option_filter_map.fixed | 3 +- src/tools/clippy/tests/ui/option_filter_map.rs | 3 +- src/tools/clippy/tests/ui/option_filter_map.stderr | 17 +- src/tools/clippy/tests/ui/option_if_let_else.fixed | 1 - src/tools/clippy/tests/ui/option_if_let_else.rs | 1 - .../clippy/tests/ui/option_if_let_else.stderr | 47 +- src/tools/clippy/tests/ui/option_map_or_none.fixed | 2 - src/tools/clippy/tests/ui/option_map_or_none.rs | 2 - .../clippy/tests/ui/option_map_or_none.stderr | 12 +- .../tests/ui/option_map_unit_fn_fixable.fixed | 1 - .../clippy/tests/ui/option_map_unit_fn_fixable.rs | 1 - .../tests/ui/option_map_unit_fn_fixable.stderr | 39 +- src/tools/clippy/tests/ui/option_option.rs | 12 + src/tools/clippy/tests/ui/option_option.stderr | 22 +- src/tools/clippy/tests/ui/or_fun_call.fixed | 1 - src/tools/clippy/tests/ui/or_fun_call.rs | 1 - src/tools/clippy/tests/ui/or_fun_call.stderr | 64 ++- src/tools/clippy/tests/ui/or_then_unwrap.fixed | 2 - src/tools/clippy/tests/ui/or_then_unwrap.rs | 2 - src/tools/clippy/tests/ui/or_then_unwrap.stderr | 7 +- .../tests/ui/out_of_bounds_indexing/issue-3102.rs | 7 +- .../ui/out_of_bounds_indexing/issue-3102.stderr | 7 +- .../tests/ui/out_of_bounds_indexing/simple.rs | 7 + .../tests/ui/out_of_bounds_indexing/simple.stderr | 11 +- .../clippy/tests/ui/overflow_check_conditional.rs | 9 + .../tests/ui/overflow_check_conditional.stderr | 15 +- .../clippy/tests/ui/overly_complex_bool_expr.fixed | 39 ++ .../clippy/tests/ui/overly_complex_bool_expr.rs | 5 + .../tests/ui/overly_complex_bool_expr.stderr | 17 +- src/tools/clippy/tests/ui/panic_in_result_fn.rs | 2 + .../clippy/tests/ui/panic_in_result_fn.stderr | 9 +- .../tests/ui/panic_in_result_fn_assertions.rs | 3 + .../tests/ui/panic_in_result_fn_assertions.stderr | 14 +- src/tools/clippy/tests/ui/panicking_macros.rs | 20 + src/tools/clippy/tests/ui/panicking_macros.stderr | 34 +- src/tools/clippy/tests/ui/partial_pub_fields.rs | 4 + .../clippy/tests/ui/partial_pub_fields.stderr | 7 +- src/tools/clippy/tests/ui/partialeq_ne_impl.rs | 2 + src/tools/clippy/tests/ui/partialeq_ne_impl.stderr | 3 + src/tools/clippy/tests/ui/partialeq_to_none.fixed | 1 - src/tools/clippy/tests/ui/partialeq_to_none.rs | 1 - src/tools/clippy/tests/ui/partialeq_to_none.stderr | 31 +- .../clippy/tests/ui/path_buf_push_overwrite.fixed | 1 - .../clippy/tests/ui/path_buf_push_overwrite.rs | 1 - .../clippy/tests/ui/path_buf_push_overwrite.stderr | 5 +- src/tools/clippy/tests/ui/path_ends_with_ext.fixed | 36 ++ src/tools/clippy/tests/ui/path_ends_with_ext.rs | 36 ++ .../clippy/tests/ui/path_ends_with_ext.stderr | 17 + .../tests/ui/pattern_type_mismatch/mutability.rs | 2 + .../ui/pattern_type_mismatch/mutability.stderr | 3 +- .../pattern_type_mismatch/pattern_alternatives.rs | 3 + .../pattern_alternatives.stderr | 5 +- .../ui/pattern_type_mismatch/pattern_structs.rs | 8 + .../pattern_type_mismatch/pattern_structs.stderr | 15 +- .../ui/pattern_type_mismatch/pattern_tuples.rs | 10 + .../ui/pattern_type_mismatch/pattern_tuples.stderr | 19 +- .../tests/ui/pattern_type_mismatch/syntax.rs | 8 + .../tests/ui/pattern_type_mismatch/syntax.stderr | 17 +- src/tools/clippy/tests/ui/patterns.fixed | 3 +- src/tools/clippy/tests/ui/patterns.rs | 3 +- src/tools/clippy/tests/ui/patterns.stderr | 7 +- .../tests/ui/permissions_set_readonly_false.rs | 2 + .../tests/ui/permissions_set_readonly_false.stderr | 1 + src/tools/clippy/tests/ui/precedence.fixed | 1 - src/tools/clippy/tests/ui/precedence.rs | 1 - src/tools/clippy/tests/ui/precedence.stderr | 25 +- src/tools/clippy/tests/ui/print.rs | 10 + src/tools/clippy/tests/ui/print.stderr | 16 +- src/tools/clippy/tests/ui/print_in_format_impl.rs | 10 +- .../clippy/tests/ui/print_in_format_impl.stderr | 13 +- src/tools/clippy/tests/ui/print_literal.fixed | 58 ++ src/tools/clippy/tests/ui/print_literal.rs | 13 + src/tools/clippy/tests/ui/print_literal.stderr | 23 +- src/tools/clippy/tests/ui/print_stderr.rs | 3 + src/tools/clippy/tests/ui/print_stderr.stderr | 3 +- src/tools/clippy/tests/ui/print_with_newline.fixed | 28 +- src/tools/clippy/tests/ui/print_with_newline.rs | 28 +- .../clippy/tests/ui/print_with_newline.stderr | 55 +- .../clippy/tests/ui/println_empty_string.fixed | 1 - src/tools/clippy/tests/ui/println_empty_string.rs | 1 - .../clippy/tests/ui/println_empty_string.stderr | 9 +- src/tools/clippy/tests/ui/proc_macro.rs | 1 + src/tools/clippy/tests/ui/ptr_arg.rs | 26 +- src/tools/clippy/tests/ui/ptr_arg.stderr | 52 +- src/tools/clippy/tests/ui/ptr_as_ptr.fixed | 3 +- src/tools/clippy/tests/ui/ptr_as_ptr.rs | 3 +- src/tools/clippy/tests/ui/ptr_as_ptr.stderr | 19 +- src/tools/clippy/tests/ui/ptr_cast_constness.fixed | 3 +- src/tools/clippy/tests/ui/ptr_cast_constness.rs | 3 +- .../clippy/tests/ui/ptr_cast_constness.stderr | 15 +- src/tools/clippy/tests/ui/ptr_eq.fixed | 1 - src/tools/clippy/tests/ui/ptr_eq.rs | 1 - src/tools/clippy/tests/ui/ptr_eq.stderr | 5 +- .../clippy/tests/ui/ptr_offset_with_cast.fixed | 1 - src/tools/clippy/tests/ui/ptr_offset_with_cast.rs | 1 - .../clippy/tests/ui/ptr_offset_with_cast.stderr | 5 +- src/tools/clippy/tests/ui/pub_use.rs | 1 + src/tools/clippy/tests/ui/pub_use.stderr | 1 + src/tools/clippy/tests/ui/pub_with_shorthand.fixed | 4 +- src/tools/clippy/tests/ui/pub_with_shorthand.rs | 4 +- .../clippy/tests/ui/pub_with_shorthand.stderr | 1 + .../clippy/tests/ui/pub_without_shorthand.fixed | 4 +- src/tools/clippy/tests/ui/pub_without_shorthand.rs | 4 +- .../clippy/tests/ui/pub_without_shorthand.stderr | 1 + src/tools/clippy/tests/ui/question_mark.fixed | 1 - src/tools/clippy/tests/ui/question_mark.rs | 1 - src/tools/clippy/tests/ui/question_mark.stderr | 33 +- src/tools/clippy/tests/ui/question_mark_used.rs | 1 + .../clippy/tests/ui/question_mark_used.stderr | 1 + src/tools/clippy/tests/ui/range.rs | 2 + src/tools/clippy/tests/ui/range.stderr | 1 + src/tools/clippy/tests/ui/range_contains.fixed | 2 - src/tools/clippy/tests/ui/range_contains.rs | 2 - src/tools/clippy/tests/ui/range_contains.stderr | 43 +- .../clippy/tests/ui/range_plus_minus_one.fixed | 2 - src/tools/clippy/tests/ui/range_plus_minus_one.rs | 2 - .../clippy/tests/ui/range_plus_minus_one.stderr | 20 +- src/tools/clippy/tests/ui/rc_buffer.fixed | 1 - src/tools/clippy/tests/ui/rc_buffer.rs | 1 - src/tools/clippy/tests/ui/rc_buffer.stderr | 17 +- src/tools/clippy/tests/ui/rc_buffer_arc.fixed | 1 - src/tools/clippy/tests/ui/rc_buffer_arc.rs | 1 - src/tools/clippy/tests/ui/rc_buffer_arc.stderr | 17 +- .../clippy/tests/ui/rc_clone_in_vec_init/arc.rs | 9 + .../tests/ui/rc_clone_in_vec_init/arc.stderr | 17 +- .../clippy/tests/ui/rc_clone_in_vec_init/rc.rs | 9 + .../clippy/tests/ui/rc_clone_in_vec_init/rc.stderr | 17 +- .../clippy/tests/ui/rc_clone_in_vec_init/weak.rs | 17 + .../tests/ui/rc_clone_in_vec_init/weak.stderr | 25 +- src/tools/clippy/tests/ui/rc_mutex.rs | 4 + src/tools/clippy/tests/ui/rc_mutex.stderr | 7 +- .../clippy/tests/ui/read_line_without_trim.fixed | 2 - .../clippy/tests/ui/read_line_without_trim.rs | 2 - .../clippy/tests/ui/read_line_without_trim.stderr | 21 +- src/tools/clippy/tests/ui/read_zero_byte_vec.rs | 13 +- .../clippy/tests/ui/read_zero_byte_vec.stderr | 19 +- .../clippy/tests/ui/readonly_write_lock.fixed | 45 ++ src/tools/clippy/tests/ui/readonly_write_lock.rs | 3 + .../clippy/tests/ui/readonly_write_lock.stderr | 3 +- src/tools/clippy/tests/ui/recursive_format_impl.rs | 11 + .../clippy/tests/ui/recursive_format_impl.stderr | 19 +- src/tools/clippy/tests/ui/redundant_allocation.rs | 45 ++ .../clippy/tests/ui/redundant_allocation.stderr | 39 +- .../tests/ui/redundant_allocation_fixable.fixed | 1 - .../tests/ui/redundant_allocation_fixable.rs | 1 - .../tests/ui/redundant_allocation_fixable.stderr | 25 +- src/tools/clippy/tests/ui/redundant_as_str.fixed | 24 + src/tools/clippy/tests/ui/redundant_as_str.rs | 24 + src/tools/clippy/tests/ui/redundant_as_str.stderr | 17 + .../clippy/tests/ui/redundant_async_block.fixed | 2 - src/tools/clippy/tests/ui/redundant_async_block.rs | 2 - .../clippy/tests/ui/redundant_async_block.stderr | 21 +- .../tests/ui/redundant_at_rest_pattern.fixed | 3 +- .../clippy/tests/ui/redundant_at_rest_pattern.rs | 3 +- .../tests/ui/redundant_at_rest_pattern.stderr | 13 +- src/tools/clippy/tests/ui/redundant_clone.fixed | 1 - src/tools/clippy/tests/ui/redundant_clone.rs | 1 - src/tools/clippy/tests/ui/redundant_clone.stderr | 61 +- .../tests/ui/redundant_closure_call_early.rs | 3 + .../tests/ui/redundant_closure_call_early.stderr | 3 +- .../tests/ui/redundant_closure_call_fixable.fixed | 2 - .../tests/ui/redundant_closure_call_fixable.rs | 2 - .../tests/ui/redundant_closure_call_fixable.stderr | 29 +- .../clippy/tests/ui/redundant_closure_call_late.rs | 4 + .../tests/ui/redundant_closure_call_late.stderr | 5 +- src/tools/clippy/tests/ui/redundant_else.rs | 7 + src/tools/clippy/tests/ui/redundant_else.stderr | 20 +- .../clippy/tests/ui/redundant_field_names.fixed | 13 +- src/tools/clippy/tests/ui/redundant_field_names.rs | 13 +- .../clippy/tests/ui/redundant_field_names.stderr | 17 +- src/tools/clippy/tests/ui/redundant_guards.fixed | 53 +- src/tools/clippy/tests/ui/redundant_guards.rs | 53 +- src/tools/clippy/tests/ui/redundant_guards.stderr | 127 ++++- src/tools/clippy/tests/ui/redundant_locals.rs | 2 +- src/tools/clippy/tests/ui/redundant_locals.stderr | 1 + .../ui/redundant_pattern_matching_drop_order.fixed | 2 - .../ui/redundant_pattern_matching_drop_order.rs | 2 - .../redundant_pattern_matching_drop_order.stderr | 45 +- .../ui/redundant_pattern_matching_ipaddr.fixed | 1 - .../tests/ui/redundant_pattern_matching_ipaddr.rs | 1 - .../ui/redundant_pattern_matching_ipaddr.stderr | 37 +- .../ui/redundant_pattern_matching_option.fixed | 2 - .../tests/ui/redundant_pattern_matching_option.rs | 2 - .../ui/redundant_pattern_matching_option.stderr | 61 +- .../tests/ui/redundant_pattern_matching_poll.fixed | 2 - .../tests/ui/redundant_pattern_matching_poll.rs | 2 - .../ui/redundant_pattern_matching_poll.stderr | 37 +- .../ui/redundant_pattern_matching_result.fixed | 1 - .../tests/ui/redundant_pattern_matching_result.rs | 1 - .../ui/redundant_pattern_matching_result.stderr | 57 +- .../clippy/tests/ui/redundant_pub_crate.fixed | 1 - src/tools/clippy/tests/ui/redundant_pub_crate.rs | 1 - .../clippy/tests/ui/redundant_pub_crate.stderr | 33 +- src/tools/clippy/tests/ui/redundant_slicing.fixed | 2 - src/tools/clippy/tests/ui/redundant_slicing.rs | 2 - src/tools/clippy/tests/ui/redundant_slicing.stderr | 7 +- .../tests/ui/redundant_static_lifetimes.fixed | 2 - .../clippy/tests/ui/redundant_static_lifetimes.rs | 2 - .../tests/ui/redundant_static_lifetimes.stderr | 37 +- .../ui/redundant_static_lifetimes_multiple.rs | 12 + .../ui/redundant_static_lifetimes_multiple.stderr | 21 +- .../clippy/tests/ui/redundant_type_annotations.rs | 18 + .../tests/ui/redundant_type_annotations.stderr | 33 +- .../clippy/tests/ui/ref_binding_to_reference.rs | 10 +- .../tests/ui/ref_binding_to_reference.stderr | 18 +- src/tools/clippy/tests/ui/ref_option_ref.rs | 14 +- src/tools/clippy/tests/ui/ref_option_ref.stderr | 21 +- src/tools/clippy/tests/ui/ref_patterns.rs | 3 + src/tools/clippy/tests/ui/ref_patterns.stderr | 5 +- src/tools/clippy/tests/ui/regex.rs | 22 +- src/tools/clippy/tests/ui/regex.stderr | 60 +- src/tools/clippy/tests/ui/rename.fixed | 10 +- src/tools/clippy/tests/ui/rename.rs | 10 +- src/tools/clippy/tests/ui/rename.stderr | 107 ++-- .../clippy/tests/ui/renamed_builtin_attr.fixed | 2 - src/tools/clippy/tests/ui/renamed_builtin_attr.rs | 2 - .../clippy/tests/ui/renamed_builtin_attr.stderr | 2 +- src/tools/clippy/tests/ui/repeat_once.fixed | 1 - src/tools/clippy/tests/ui/repeat_once.rs | 1 - src/tools/clippy/tests/ui/repeat_once.stderr | 13 +- src/tools/clippy/tests/ui/repl_uninit.rs | 7 +- src/tools/clippy/tests/ui/repl_uninit.stderr | 7 +- .../tests/ui/reserve_after_initialization.fixed | 48 ++ .../tests/ui/reserve_after_initialization.rs | 51 ++ .../tests/ui/reserve_after_initialization.stderr | 26 + .../tests/ui/rest_pat_in_fully_bound_structs.rs | 5 +- .../ui/rest_pat_in_fully_bound_structs.stderr | 7 +- src/tools/clippy/tests/ui/result_large_err.rs | 14 + src/tools/clippy/tests/ui/result_large_err.stderr | 25 +- .../tests/ui/result_map_or_into_option.fixed | 2 - .../clippy/tests/ui/result_map_or_into_option.rs | 2 - .../tests/ui/result_map_or_into_option.stderr | 3 +- .../tests/ui/result_map_unit_fn_fixable.fixed | 1 - .../clippy/tests/ui/result_map_unit_fn_fixable.rs | 1 - .../tests/ui/result_map_unit_fn_fixable.stderr | 37 +- .../tests/ui/result_map_unit_fn_unfixable.rs | 11 +- .../tests/ui/result_map_unit_fn_unfixable.stderr | 12 +- src/tools/clippy/tests/ui/result_unit_error.rs | 5 + src/tools/clippy/tests/ui/result_unit_error.stderr | 9 +- .../clippy/tests/ui/return_self_not_must_use.rs | 3 + .../tests/ui/return_self_not_must_use.stderr | 7 +- .../tests/ui/reversed_empty_ranges_fixable.fixed | 1 - .../tests/ui/reversed_empty_ranges_fixable.rs | 1 - .../tests/ui/reversed_empty_ranges_fixable.stderr | 9 +- .../ui/reversed_empty_ranges_loops_fixable.fixed | 1 - .../ui/reversed_empty_ranges_loops_fixable.rs | 1 - .../ui/reversed_empty_ranges_loops_fixable.stderr | 13 +- .../ui/reversed_empty_ranges_loops_unfixable.rs | 3 + .../reversed_empty_ranges_loops_unfixable.stderr | 3 +- .../tests/ui/reversed_empty_ranges_unfixable.rs | 4 + .../ui/reversed_empty_ranges_unfixable.stderr | 5 +- src/tools/clippy/tests/ui/same_item_push.rs | 5 + src/tools/clippy/tests/ui/same_item_push.stderr | 9 +- src/tools/clippy/tests/ui/same_name_method.rs | 5 + src/tools/clippy/tests/ui/same_name_method.stderr | 19 +- src/tools/clippy/tests/ui/search_is_some.rs | 2 +- src/tools/clippy/tests/ui/search_is_some.stderr | 1 + .../tests/ui/search_is_some_fixable_none.fixed | 1 - .../clippy/tests/ui/search_is_some_fixable_none.rs | 1 - .../tests/ui/search_is_some_fixable_none.stderr | 87 +-- .../tests/ui/search_is_some_fixable_some.fixed | 1 - .../clippy/tests/ui/search_is_some_fixable_some.rs | 1 - .../tests/ui/search_is_some_fixable_some.stderr | 95 ++-- src/tools/clippy/tests/ui/seek_from_current.fixed | 1 - src/tools/clippy/tests/ui/seek_from_current.rs | 1 - src/tools/clippy/tests/ui/seek_from_current.stderr | 3 +- .../tests/ui/seek_to_start_instead_of_rewind.fixed | 1 - .../tests/ui/seek_to_start_instead_of_rewind.rs | 1 - .../ui/seek_to_start_instead_of_rewind.stderr | 7 +- src/tools/clippy/tests/ui/self_assignment.rs | 12 + src/tools/clippy/tests/ui/self_assignment.stderr | 21 +- .../clippy/tests/ui/self_named_constructors.rs | 2 + .../clippy/tests/ui/self_named_constructors.stderr | 3 + .../tests/ui/semicolon_if_nothing_returned.fixed | 1 - .../tests/ui/semicolon_if_nothing_returned.rs | 1 - .../tests/ui/semicolon_if_nothing_returned.stderr | 11 +- .../clippy/tests/ui/semicolon_inside_block.fixed | 1 - .../clippy/tests/ui/semicolon_inside_block.rs | 1 - .../clippy/tests/ui/semicolon_inside_block.stderr | 9 +- .../clippy/tests/ui/semicolon_outside_block.fixed | 1 - .../clippy/tests/ui/semicolon_outside_block.rs | 1 - .../clippy/tests/ui/semicolon_outside_block.stderr | 9 +- src/tools/clippy/tests/ui/serde.rs | 2 + src/tools/clippy/tests/ui/serde.stderr | 6 +- src/tools/clippy/tests/ui/shadow.rs | 2 +- src/tools/clippy/tests/ui/shadow.stderr | 3 + .../clippy/tests/ui/short_circuit_statement.fixed | 2 - .../clippy/tests/ui/short_circuit_statement.rs | 2 - .../clippy/tests/ui/short_circuit_statement.stderr | 7 +- .../tests/ui/should_impl_trait/method_list_1.rs | 15 + .../ui/should_impl_trait/method_list_1.stderr | 44 +- .../tests/ui/should_impl_trait/method_list_2.rs | 17 +- .../ui/should_impl_trait/method_list_2.stderr | 44 +- .../clippy/tests/ui/should_panic_without_expect.rs | 21 + .../tests/ui/should_panic_without_expect.stderr | 14 + .../tests/ui/significant_drop_in_scrutinee.fixed | 627 --------------------- .../tests/ui/significant_drop_in_scrutinee.rs | 54 +- .../tests/ui/significant_drop_in_scrutinee.stderr | 86 +-- .../tests/ui/significant_drop_tightening.fixed | 2 - .../clippy/tests/ui/significant_drop_tightening.rs | 2 - .../tests/ui/significant_drop_tightening.stderr | 9 +- src/tools/clippy/tests/ui/similar_names.rs | 8 + src/tools/clippy/tests/ui/similar_names.stderr | 29 +- src/tools/clippy/tests/ui/single_call_fn.rs | 3 +- src/tools/clippy/tests/ui/single_call_fn.stderr | 17 +- .../clippy/tests/ui/single_char_add_str.fixed | 1 - src/tools/clippy/tests/ui/single_char_add_str.rs | 1 - .../clippy/tests/ui/single_char_add_str.stderr | 53 +- .../clippy/tests/ui/single_char_lifetime_names.rs | 5 + .../tests/ui/single_char_lifetime_names.stderr | 7 +- .../clippy/tests/ui/single_char_pattern.fixed | 2 - src/tools/clippy/tests/ui/single_char_pattern.rs | 2 - .../clippy/tests/ui/single_char_pattern.stderr | 103 ++-- .../tests/ui/single_component_path_imports.fixed | 1 - .../tests/ui/single_component_path_imports.rs | 1 - .../tests/ui/single_component_path_imports.stderr | 5 +- .../single_component_path_imports_nested_first.rs | 6 +- ...ngle_component_path_imports_nested_first.stderr | 5 +- .../clippy/tests/ui/single_element_loop.fixed | 1 - src/tools/clippy/tests/ui/single_element_loop.rs | 1 - .../clippy/tests/ui/single_element_loop.stderr | 15 +- src/tools/clippy/tests/ui/single_match.fixed | 1 - src/tools/clippy/tests/ui/single_match.rs | 1 - src/tools/clippy/tests/ui/single_match.stderr | 37 +- src/tools/clippy/tests/ui/single_match_else.fixed | 3 +- src/tools/clippy/tests/ui/single_match_else.rs | 3 +- src/tools/clippy/tests/ui/single_match_else.stderr | 19 +- .../clippy/tests/ui/single_range_in_vec_init.rs | 3 +- .../tests/ui/single_range_in_vec_init.stderr | 21 +- .../ui/size_of_in_element_count/expressions.rs | 4 + .../ui/size_of_in_element_count/expressions.stderr | 7 +- .../tests/ui/size_of_in_element_count/functions.rs | 21 + .../ui/size_of_in_element_count/functions.stderr | 41 +- src/tools/clippy/tests/ui/size_of_ref.rs | 3 + src/tools/clippy/tests/ui/size_of_ref.stderr | 5 +- src/tools/clippy/tests/ui/skip_while_next.stderr | 1 + .../clippy/tests/ui/slow_vector_initialization.rs | 29 +- .../tests/ui/slow_vector_initialization.stderr | 33 +- .../clippy/tests/ui/stable_sort_primitive.fixed | 1 - src/tools/clippy/tests/ui/stable_sort_primitive.rs | 1 - .../clippy/tests/ui/stable_sort_primitive.stderr | 15 +- src/tools/clippy/tests/ui/starts_ends_with.fixed | 1 - src/tools/clippy/tests/ui/starts_ends_with.rs | 1 - src/tools/clippy/tests/ui/starts_ends_with.stderr | 54 +- .../clippy/tests/ui/std_instead_of_core.fixed | 62 ++ src/tools/clippy/tests/ui/std_instead_of_core.rs | 11 + .../clippy/tests/ui/std_instead_of_core.stderr | 74 +-- src/tools/clippy/tests/ui/str_to_string.rs | 2 + src/tools/clippy/tests/ui/str_to_string.stderr | 3 +- src/tools/clippy/tests/ui/string_add.rs | 4 +- src/tools/clippy/tests/ui/string_add.stderr | 2 + src/tools/clippy/tests/ui/string_add_assign.fixed | 2 - src/tools/clippy/tests/ui/string_add_assign.rs | 2 - src/tools/clippy/tests/ui/string_add_assign.stderr | 8 +- src/tools/clippy/tests/ui/string_extend.fixed | 2 - src/tools/clippy/tests/ui/string_extend.rs | 2 - src/tools/clippy/tests/ui/string_extend.stderr | 9 +- .../tests/ui/string_from_utf8_as_bytes.fixed | 1 - .../clippy/tests/ui/string_from_utf8_as_bytes.rs | 1 - .../tests/ui/string_from_utf8_as_bytes.stderr | 3 +- .../clippy/tests/ui/string_lit_as_bytes.fixed | 1 - src/tools/clippy/tests/ui/string_lit_as_bytes.rs | 1 - .../clippy/tests/ui/string_lit_as_bytes.stderr | 19 +- .../clippy/tests/ui/string_lit_chars_any.fixed | 3 +- src/tools/clippy/tests/ui/string_lit_chars_any.rs | 3 +- .../clippy/tests/ui/string_lit_chars_any.stderr | 31 +- src/tools/clippy/tests/ui/string_slice.rs | 4 + src/tools/clippy/tests/ui/string_slice.stderr | 5 +- src/tools/clippy/tests/ui/string_to_string.rs | 1 + src/tools/clippy/tests/ui/string_to_string.stderr | 1 + .../clippy/tests/ui/strlen_on_c_strings.fixed | 2 - src/tools/clippy/tests/ui/strlen_on_c_strings.rs | 2 - .../clippy/tests/ui/strlen_on_c_strings.stderr | 15 +- .../clippy/tests/ui/struct_excessive_bools.rs | 2 + .../clippy/tests/ui/struct_excessive_bools.stderr | 5 +- .../clippy/tests/ui/suspicious_arithmetic_impl.rs | 11 + .../tests/ui/suspicious_arithmetic_impl.stderr | 18 +- .../tests/ui/suspicious_command_arg_space.fixed | 13 + .../tests/ui/suspicious_command_arg_space.rs | 3 + .../tests/ui/suspicious_command_arg_space.stderr | 3 +- .../clippy/tests/ui/suspicious_doc_comments.fixed | 1 - .../clippy/tests/ui/suspicious_doc_comments.rs | 1 - .../clippy/tests/ui/suspicious_doc_comments.stderr | 19 +- .../tests/ui/suspicious_doc_comments_unfixable.rs | 5 +- .../ui/suspicious_doc_comments_unfixable.stderr | 9 +- .../clippy/tests/ui/suspicious_else_formatting.rs | 2 +- .../tests/ui/suspicious_else_formatting.stderr | 1 + src/tools/clippy/tests/ui/suspicious_map.rs | 2 + src/tools/clippy/tests/ui/suspicious_map.stderr | 3 +- .../tests/ui/suspicious_operation_groupings.fixed | 1 - .../tests/ui/suspicious_operation_groupings.rs | 1 - .../tests/ui/suspicious_operation_groupings.stderr | 53 +- src/tools/clippy/tests/ui/suspicious_splitn.rs | 18 + src/tools/clippy/tests/ui/suspicious_splitn.stderr | 17 +- src/tools/clippy/tests/ui/suspicious_to_owned.rs | 9 + .../clippy/tests/ui/suspicious_to_owned.stderr | 14 +- .../tests/ui/suspicious_unary_op_formatting.rs | 4 + .../tests/ui/suspicious_unary_op_formatting.stderr | 7 +- .../clippy/tests/ui/suspicious_xor_used_as_pow.rs | 9 +- .../tests/ui/suspicious_xor_used_as_pow.stderr | 11 +- src/tools/clippy/tests/ui/swap.fixed | 1 - src/tools/clippy/tests/ui/swap.rs | 1 - src/tools/clippy/tests/ui/swap.stderr | 36 +- src/tools/clippy/tests/ui/swap_ptr_to_ref.fixed | 2 - src/tools/clippy/tests/ui/swap_ptr_to_ref.rs | 2 - src/tools/clippy/tests/ui/swap_ptr_to_ref.stderr | 9 +- .../clippy/tests/ui/swap_ptr_to_ref_unfixable.rs | 4 + .../tests/ui/swap_ptr_to_ref_unfixable.stderr | 5 +- .../clippy/tests/ui/tabs_in_doc_comments.fixed | 2 - src/tools/clippy/tests/ui/tabs_in_doc_comments.rs | 2 - .../clippy/tests/ui/tabs_in_doc_comments.stderr | 17 +- src/tools/clippy/tests/ui/temporary_assignment.rs | 5 + .../clippy/tests/ui/temporary_assignment.stderr | 8 +- .../clippy/tests/ui/tests_outside_test_module.rs | 2 + .../tests/ui/tests_outside_test_module.stderr | 1 + src/tools/clippy/tests/ui/to_digit_is_some.fixed | 2 - src/tools/clippy/tests/ui/to_digit_is_some.rs | 2 - src/tools/clippy/tests/ui/to_digit_is_some.stderr | 5 +- .../ui/to_string_in_format_args_incremental.fixed | 1 - src/tools/clippy/tests/ui/toplevel_ref_arg.fixed | 3 +- src/tools/clippy/tests/ui/toplevel_ref_arg.rs | 3 +- src/tools/clippy/tests/ui/toplevel_ref_arg.stderr | 13 +- .../tests/ui/toplevel_ref_arg_non_rustfix.rs | 2 +- .../tests/ui/toplevel_ref_arg_non_rustfix.stderr | 1 + src/tools/clippy/tests/ui/trailing_empty_array.rs | 11 + .../clippy/tests/ui/trailing_empty_array.stderr | 31 +- src/tools/clippy/tests/ui/trailing_zeros.fixed | 13 + src/tools/clippy/tests/ui/trailing_zeros.rs | 7 +- src/tools/clippy/tests/ui/trailing_zeros.stderr | 7 +- .../tests/ui/trait_duplication_in_bounds.fixed | 1 - .../clippy/tests/ui/trait_duplication_in_bounds.rs | 1 - .../tests/ui/trait_duplication_in_bounds.stderr | 20 +- .../ui/trait_duplication_in_bounds_unfixable.rs | 8 + .../trait_duplication_in_bounds_unfixable.stderr | 12 +- src/tools/clippy/tests/ui/transmute.rs | 47 +- src/tools/clippy/tests/ui/transmute.stderr | 81 +-- src/tools/clippy/tests/ui/transmute_32bit.stderr | 30 +- src/tools/clippy/tests/ui/transmute_64bit.rs | 3 + src/tools/clippy/tests/ui/transmute_64bit.stderr | 3 +- src/tools/clippy/tests/ui/transmute_collection.rs | 19 + .../clippy/tests/ui/transmute_collection.stderr | 35 +- .../clippy/tests/ui/transmute_float_to_int.fixed | 32 ++ .../clippy/tests/ui/transmute_float_to_int.rs | 7 + .../clippy/tests/ui/transmute_float_to_int.stderr | 11 +- .../tests/ui/transmute_int_to_non_zero.fixed | 52 ++ .../clippy/tests/ui/transmute_int_to_non_zero.rs | 11 + .../tests/ui/transmute_int_to_non_zero.stderr | 19 +- src/tools/clippy/tests/ui/transmute_null_to_fn.rs | 14 + .../clippy/tests/ui/transmute_null_to_fn.stderr | 31 +- .../clippy/tests/ui/transmute_ptr_to_ptr.fixed | 70 +++ src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs | 7 + .../clippy/tests/ui/transmute_ptr_to_ptr.stderr | 11 +- .../clippy/tests/ui/transmute_ptr_to_ref.fixed | 2 - src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs | 2 - .../clippy/tests/ui/transmute_ptr_to_ref.stderr | 45 +- .../clippy/tests/ui/transmute_undefined_repr.rs | 305 ++++++---- .../tests/ui/transmute_undefined_repr.stderr | 49 +- .../ui/transmutes_expressible_as_ptr_casts.fixed | 1 - .../ui/transmutes_expressible_as_ptr_casts.rs | 1 - .../ui/transmutes_expressible_as_ptr_casts.stderr | 23 +- src/tools/clippy/tests/ui/transmuting_null.rs | 4 + src/tools/clippy/tests/ui/transmuting_null.stderr | 5 +- .../clippy/tests/ui/trim_split_whitespace.fixed | 1 - src/tools/clippy/tests/ui/trim_split_whitespace.rs | 1 - .../clippy/tests/ui/trim_split_whitespace.stderr | 17 +- .../clippy/tests/ui/trivially_copy_pass_by_ref.rs | 21 +- .../tests/ui/trivially_copy_pass_by_ref.stderr | 66 +-- src/tools/clippy/tests/ui/try_err.fixed | 3 +- src/tools/clippy/tests/ui/try_err.rs | 3 +- src/tools/clippy/tests/ui/try_err.stderr | 24 +- .../clippy/tests/ui/tuple_array_conversions.rs | 7 +- .../clippy/tests/ui/tuple_array_conversions.stderr | 5 +- src/tools/clippy/tests/ui/type_complexity.rs | 16 + src/tools/clippy/tests/ui/type_complexity.stderr | 29 +- src/tools/clippy/tests/ui/type_id_on_box.fixed | 2 - src/tools/clippy/tests/ui/type_id_on_box.rs | 2 - src/tools/clippy/tests/ui/type_id_on_box.stderr | 7 +- .../clippy/tests/ui/type_repetition_in_bounds.rs | 5 + .../tests/ui/type_repetition_in_bounds.stderr | 8 +- src/tools/clippy/tests/ui/types.fixed | 2 - src/tools/clippy/tests/ui/types.rs | 2 - src/tools/clippy/tests/ui/types.stderr | 3 +- .../tests/ui/unchecked_duration_subtraction.fixed | 1 - .../tests/ui/unchecked_duration_subtraction.rs | 1 - .../tests/ui/unchecked_duration_subtraction.stderr | 9 +- .../clippy/tests/ui/undocumented_unsafe_blocks.rs | 534 ------------------ .../tests/ui/undocumented_unsafe_blocks.stderr | 346 ------------ src/tools/clippy/tests/ui/unicode.fixed | 1 - src/tools/clippy/tests/ui/unicode.rs | 1 - src/tools/clippy/tests/ui/unicode.stderr | 36 +- src/tools/clippy/tests/ui/uninit.rs | 4 + src/tools/clippy/tests/ui/uninit.stderr | 4 +- src/tools/clippy/tests/ui/uninit_vec.rs | 11 + src/tools/clippy/tests/ui/uninit_vec.stderr | 39 +- .../clippy/tests/ui/uninlined_format_args.fixed | 4 +- src/tools/clippy/tests/ui/uninlined_format_args.rs | 4 +- .../clippy/tests/ui/uninlined_format_args.stderr | 9 +- .../uninlined_format_args_panic.edition2018.fixed | 1 - .../uninlined_format_args_panic.edition2018.stderr | 3 +- .../uninlined_format_args_panic.edition2021.fixed | 1 - .../uninlined_format_args_panic.edition2021.stderr | 13 +- .../clippy/tests/ui/uninlined_format_args_panic.rs | 1 - src/tools/clippy/tests/ui/unit_arg.rs | 3 +- src/tools/clippy/tests/ui/unit_arg.stderr | 21 +- .../clippy/tests/ui/unit_arg_empty_blocks.fixed | 1 - src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs | 1 - .../clippy/tests/ui/unit_arg_empty_blocks.stderr | 9 +- src/tools/clippy/tests/ui/unit_cmp.rs | 7 + src/tools/clippy/tests/ui/unit_cmp.stderr | 22 +- src/tools/clippy/tests/ui/unit_hash.fixed | 34 ++ src/tools/clippy/tests/ui/unit_hash.rs | 6 + src/tools/clippy/tests/ui/unit_hash.stderr | 5 +- .../clippy/tests/ui/unit_return_expecting_ord.rs | 4 + .../tests/ui/unit_return_expecting_ord.stderr | 11 +- src/tools/clippy/tests/ui/unknown_attribute.rs | 1 + .../clippy/tests/ui/unknown_clippy_lints.fixed | 2 - src/tools/clippy/tests/ui/unknown_clippy_lints.rs | 2 - .../clippy/tests/ui/unknown_clippy_lints.stderr | 17 +- .../clippy/tests/ui/unnecessary_box_returns.rs | 6 +- .../clippy/tests/ui/unnecessary_box_returns.stderr | 7 +- src/tools/clippy/tests/ui/unnecessary_cast.fixed | 1 - src/tools/clippy/tests/ui/unnecessary_cast.rs | 1 - src/tools/clippy/tests/ui/unnecessary_cast.stderr | 81 +-- .../clippy/tests/ui/unnecessary_cast_unfixable.rs | 5 +- .../tests/ui/unnecessary_cast_unfixable.stderr | 3 +- src/tools/clippy/tests/ui/unnecessary_clone.rs | 13 +- src/tools/clippy/tests/ui/unnecessary_clone.stderr | 18 +- .../clippy/tests/ui/unnecessary_filter_map.rs | 5 + .../clippy/tests/ui/unnecessary_filter_map.stderr | 11 +- src/tools/clippy/tests/ui/unnecessary_find_map.rs | 5 + .../clippy/tests/ui/unnecessary_find_map.stderr | 11 +- src/tools/clippy/tests/ui/unnecessary_fold.fixed | 2 - src/tools/clippy/tests/ui/unnecessary_fold.rs | 2 - src/tools/clippy/tests/ui/unnecessary_fold.stderr | 31 +- .../clippy/tests/ui/unnecessary_iter_cloned.fixed | 2 - .../clippy/tests/ui/unnecessary_iter_cloned.rs | 2 - .../clippy/tests/ui/unnecessary_iter_cloned.stderr | 5 +- src/tools/clippy/tests/ui/unnecessary_join.fixed | 1 - src/tools/clippy/tests/ui/unnecessary_join.rs | 1 - src/tools/clippy/tests/ui/unnecessary_join.stderr | 5 +- .../clippy/tests/ui/unnecessary_lazy_eval.fixed | 3 +- src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs | 3 +- .../clippy/tests/ui/unnecessary_lazy_eval.stderr | 77 +-- .../tests/ui/unnecessary_lazy_eval_unfixable.rs | 6 +- .../ui/unnecessary_lazy_eval_unfixable.stderr | 5 +- .../tests/ui/unnecessary_literal_unwrap.fixed | 1 - .../clippy/tests/ui/unnecessary_literal_unwrap.rs | 1 - .../tests/ui/unnecessary_literal_unwrap.stderr | 107 ++-- .../ui/unnecessary_literal_unwrap_unfixable.rs | 54 +- .../ui/unnecessary_literal_unwrap_unfixable.stderr | 199 +++---- .../tests/ui/unnecessary_map_on_constructor.fixed | 56 ++ .../tests/ui/unnecessary_map_on_constructor.rs | 56 ++ .../tests/ui/unnecessary_map_on_constructor.stderr | 53 ++ .../clippy/tests/ui/unnecessary_operation.fixed | 2 - src/tools/clippy/tests/ui/unnecessary_operation.rs | 2 - .../clippy/tests/ui/unnecessary_operation.stderr | 39 +- .../tests/ui/unnecessary_owned_empty_strings.fixed | 2 - .../tests/ui/unnecessary_owned_empty_strings.rs | 2 - .../ui/unnecessary_owned_empty_strings.stderr | 5 +- .../clippy/tests/ui/unnecessary_safety_comment.rs | 8 + .../tests/ui/unnecessary_safety_comment.stderr | 33 +- .../clippy/tests/ui/unnecessary_self_imports.fixed | 1 - .../clippy/tests/ui/unnecessary_self_imports.rs | 1 - .../tests/ui/unnecessary_self_imports.stderr | 5 +- .../clippy/tests/ui/unnecessary_sort_by.fixed | 2 - src/tools/clippy/tests/ui/unnecessary_sort_by.rs | 2 - .../clippy/tests/ui/unnecessary_sort_by.stderr | 25 +- .../ui/unnecessary_struct_initialization.fixed | 4 +- .../tests/ui/unnecessary_struct_initialization.rs | 4 +- .../ui/unnecessary_struct_initialization.stderr | 13 +- .../clippy/tests/ui/unnecessary_to_owned.fixed | 4 +- src/tools/clippy/tests/ui/unnecessary_to_owned.rs | 4 +- .../clippy/tests/ui/unnecessary_to_owned.stderr | 170 +++--- .../clippy/tests/ui/unnecessary_unsafety_doc.rs | 2 +- .../tests/ui/unnecessary_unsafety_doc.stderr | 1 + src/tools/clippy/tests/ui/unnecessary_wraps.rs | 9 + src/tools/clippy/tests/ui/unnecessary_wraps.stderr | 27 +- .../clippy/tests/ui/unneeded_field_pattern.rs | 2 +- .../clippy/tests/ui/unneeded_field_pattern.stderr | 1 + .../tests/ui/unneeded_wildcard_pattern.fixed | 3 +- .../clippy/tests/ui/unneeded_wildcard_pattern.rs | 3 +- .../tests/ui/unneeded_wildcard_pattern.stderr | 30 +- .../clippy/tests/ui/unnested_or_patterns.fixed | 2 - src/tools/clippy/tests/ui/unnested_or_patterns.rs | 2 - .../clippy/tests/ui/unnested_or_patterns.stderr | 35 +- .../clippy/tests/ui/unnested_or_patterns2.fixed | 2 - src/tools/clippy/tests/ui/unnested_or_patterns2.rs | 2 - .../clippy/tests/ui/unnested_or_patterns2.stderr | 17 +- src/tools/clippy/tests/ui/unreadable_literal.fixed | 2 - src/tools/clippy/tests/ui/unreadable_literal.rs | 2 - .../clippy/tests/ui/unreadable_literal.stderr | 21 +- .../clippy/tests/ui/unsafe_derive_deserialize.rs | 4 + .../tests/ui/unsafe_derive_deserialize.stderr | 7 +- .../clippy/tests/ui/unsafe_removed_from_name.rs | 6 + .../tests/ui/unsafe_removed_from_name.stderr | 9 +- .../tests/ui/unseparated_prefix_literals.fixed | 3 +- .../clippy/tests/ui/unseparated_prefix_literals.rs | 3 +- .../tests/ui/unseparated_prefix_literals.stderr | 19 +- src/tools/clippy/tests/ui/unused_async.rs | 4 + src/tools/clippy/tests/ui/unused_async.stderr | 12 +- .../tests/ui/unused_format_specs_unfixable.rs | 7 +- .../tests/ui/unused_format_specs_unfixable.stderr | 7 +- src/tools/clippy/tests/ui/unused_io_amount.rs | 20 + src/tools/clippy/tests/ui/unused_io_amount.stderr | 40 +- src/tools/clippy/tests/ui/unused_peekable.rs | 8 + src/tools/clippy/tests/ui/unused_peekable.stderr | 15 +- src/tools/clippy/tests/ui/unused_rounding.fixed | 1 - src/tools/clippy/tests/ui/unused_rounding.rs | 1 - src/tools/clippy/tests/ui/unused_rounding.stderr | 11 +- src/tools/clippy/tests/ui/unused_self.rs | 9 + src/tools/clippy/tests/ui/unused_self.stderr | 17 +- src/tools/clippy/tests/ui/unused_unit.fixed | 2 +- src/tools/clippy/tests/ui/unused_unit.rs | 2 +- src/tools/clippy/tests/ui/unwrap.rs | 3 + src/tools/clippy/tests/ui/unwrap.stderr | 5 +- src/tools/clippy/tests/ui/unwrap_expect_used.rs | 6 + .../clippy/tests/ui/unwrap_expect_used.stderr | 12 +- src/tools/clippy/tests/ui/unwrap_in_result.rs | 2 + src/tools/clippy/tests/ui/unwrap_in_result.stderr | 13 +- src/tools/clippy/tests/ui/unwrap_or.fixed | 13 + src/tools/clippy/tests/ui/unwrap_or.rs | 3 + src/tools/clippy/tests/ui/unwrap_or.stderr | 3 +- .../clippy/tests/ui/unwrap_or_else_default.fixed | 32 +- .../clippy/tests/ui/unwrap_or_else_default.rs | 32 +- .../clippy/tests/ui/unwrap_or_else_default.stderr | 33 +- .../clippy/tests/ui/upper_case_acronyms.fixed | 62 ++ src/tools/clippy/tests/ui/upper_case_acronyms.rs | 12 + .../clippy/tests/ui/upper_case_acronyms.stderr | 21 +- src/tools/clippy/tests/ui/use_self.fixed | 3 +- src/tools/clippy/tests/ui/use_self.rs | 3 +- src/tools/clippy/tests/ui/use_self.stderr | 85 +-- src/tools/clippy/tests/ui/use_self_trait.fixed | 2 - src/tools/clippy/tests/ui/use_self_trait.rs | 2 - src/tools/clippy/tests/ui/use_self_trait.stderr | 33 +- .../clippy/tests/ui/used_underscore_binding.rs | 30 +- .../clippy/tests/ui/used_underscore_binding.stderr | 48 +- src/tools/clippy/tests/ui/useless_asref.fixed | 1 - src/tools/clippy/tests/ui/useless_asref.rs | 1 - src/tools/clippy/tests/ui/useless_asref.stderr | 24 +- src/tools/clippy/tests/ui/useless_attribute.fixed | 3 +- src/tools/clippy/tests/ui/useless_attribute.rs | 3 +- src/tools/clippy/tests/ui/useless_attribute.stderr | 7 +- src/tools/clippy/tests/ui/useless_conversion.fixed | 93 ++- src/tools/clippy/tests/ui/useless_conversion.rs | 93 ++- .../clippy/tests/ui/useless_conversion.stderr | 90 ++- .../clippy/tests/ui/useless_conversion_try.rs | 9 + .../clippy/tests/ui/useless_conversion_try.stderr | 16 +- src/tools/clippy/tests/ui/vec.fixed | 2 +- src/tools/clippy/tests/ui/vec.rs | 2 +- src/tools/clippy/tests/ui/vec.stderr | 29 +- src/tools/clippy/tests/ui/vec_box_sized.fixed | 7 +- src/tools/clippy/tests/ui/vec_box_sized.rs | 7 +- src/tools/clippy/tests/ui/vec_box_sized.stderr | 13 +- src/tools/clippy/tests/ui/vec_init_then_push.rs | 11 +- .../clippy/tests/ui/vec_init_then_push.stderr | 26 +- src/tools/clippy/tests/ui/vec_resize_to_zero.fixed | 20 + src/tools/clippy/tests/ui/vec_resize_to_zero.rs | 1 + .../clippy/tests/ui/vec_resize_to_zero.stderr | 1 + src/tools/clippy/tests/ui/verbose_file_reads.rs | 2 + .../clippy/tests/ui/verbose_file_reads.stderr | 3 +- .../clippy/tests/ui/vtable_address_comparisons.rs | 8 + .../tests/ui/vtable_address_comparisons.stderr | 15 +- src/tools/clippy/tests/ui/while_let_loop.rs | 8 +- src/tools/clippy/tests/ui/while_let_loop.stderr | 22 +- .../clippy/tests/ui/while_let_on_iterator.fixed | 1 - src/tools/clippy/tests/ui/while_let_on_iterator.rs | 1 - .../clippy/tests/ui/while_let_on_iterator.stderr | 53 +- src/tools/clippy/tests/ui/wild_in_or_pats.rs | 4 + src/tools/clippy/tests/ui/wild_in_or_pats.stderr | 7 +- .../clippy/tests/ui/wildcard_enum_match_arm.fixed | 1 - .../clippy/tests/ui/wildcard_enum_match_arm.rs | 1 - .../clippy/tests/ui/wildcard_enum_match_arm.stderr | 14 +- src/tools/clippy/tests/ui/wildcard_imports.fixed | 2 +- src/tools/clippy/tests/ui/wildcard_imports.rs | 2 +- src/tools/clippy/tests/ui/wildcard_imports.stderr | 1 + .../ui/wildcard_imports_2021.edition2018.fixed | 2 +- .../ui/wildcard_imports_2021.edition2018.stderr | 1 + .../ui/wildcard_imports_2021.edition2021.fixed | 2 +- .../ui/wildcard_imports_2021.edition2021.stderr | 1 + src/tools/clippy/tests/ui/wildcard_imports_2021.rs | 2 +- src/tools/clippy/tests/ui/write_literal.fixed | 58 ++ src/tools/clippy/tests/ui/write_literal.rs | 13 + src/tools/clippy/tests/ui/write_literal.stderr | 23 +- src/tools/clippy/tests/ui/write_literal_2.rs | 29 +- src/tools/clippy/tests/ui/write_literal_2.stderr | 115 ++-- src/tools/clippy/tests/ui/write_with_newline.fixed | 27 +- src/tools/clippy/tests/ui/write_with_newline.rs | 25 +- .../clippy/tests/ui/write_with_newline.stderr | 55 +- .../clippy/tests/ui/writeln_empty_string.fixed | 2 - src/tools/clippy/tests/ui/writeln_empty_string.rs | 2 - .../clippy/tests/ui/writeln_empty_string.stderr | 5 +- src/tools/clippy/tests/ui/wrong_self_convention.rs | 24 + .../clippy/tests/ui/wrong_self_convention.stderr | 47 +- .../clippy/tests/ui/wrong_self_convention2.rs | 2 + .../clippy/tests/ui/wrong_self_convention2.stderr | 3 +- .../clippy/tests/ui/wrong_self_conventions_mut.rs | 2 + .../tests/ui/wrong_self_conventions_mut.stderr | 3 +- src/tools/clippy/tests/ui/zero_div_zero.rs | 4 + src/tools/clippy/tests/ui/zero_div_zero.stderr | 7 +- src/tools/clippy/tests/ui/zero_offset.rs | 9 + src/tools/clippy/tests/ui/zero_offset.stderr | 14 +- src/tools/clippy/tests/ui/zero_ptr.fixed | 1 - src/tools/clippy/tests/ui/zero_ptr.rs | 1 - src/tools/clippy/tests/ui/zero_ptr.stderr | 11 +- src/tools/clippy/tests/ui/zero_ptr_no_std.fixed | 2 - src/tools/clippy/tests/ui/zero_ptr_no_std.rs | 2 - src/tools/clippy/tests/ui/zero_ptr_no_std.stderr | 8 +- .../clippy/tests/ui/zero_sized_btreemap_values.rs | 14 +- .../tests/ui/zero_sized_btreemap_values.stderr | 25 +- .../clippy/tests/ui/zero_sized_hashmap_values.rs | 14 +- .../tests/ui/zero_sized_hashmap_values.stderr | 25 +- 2115 files changed, 23247 insertions(+), 13779 deletions(-) create mode 100644 src/tools/clippy/tests/ui-toml/decimal_literal_representation/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.fixed create mode 100644 src/tools/clippy/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.rs create mode 100644 src/tools/clippy/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.stderr create mode 100644 src/tools/clippy/tests/ui-toml/disallowed_script_idents/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/disallowed_script_idents/disallowed_script_idents.rs create mode 100644 src/tools/clippy/tests/ui-toml/disallowed_script_idents/disallowed_script_idents.stderr create mode 100644 src/tools/clippy/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed create mode 100644 src/tools/clippy/tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed create mode 100644 src/tools/clippy/tests/ui-toml/enum_variant_names/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/enum_variant_names/enum_variant_names.rs create mode 100644 src/tools/clippy/tests/ui-toml/enum_variant_names/enum_variant_names.stderr create mode 100644 src/tools/clippy/tests/ui-toml/enum_variant_size/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/enum_variant_size/enum_variant_size.fixed create mode 100644 src/tools/clippy/tests/ui-toml/enum_variant_size/enum_variant_size.rs create mode 100644 src/tools/clippy/tests/ui-toml/enum_variant_size/enum_variant_size.stderr create mode 100644 src/tools/clippy/tests/ui-toml/enum_variants_threshold0/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/enum_variants_threshold0/enum_variants_name_threshold.rs delete mode 100644 src/tools/clippy/tests/ui-toml/excessive_nesting/auxiliary/proc_macros.rs create mode 100644 src/tools/clippy/tests/ui-toml/explicit_iter_loop/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/explicit_iter_loop/explicit_iter_loop.fixed create mode 100644 src/tools/clippy/tests/ui-toml/explicit_iter_loop/explicit_iter_loop.rs create mode 100644 src/tools/clippy/tests/ui-toml/explicit_iter_loop/explicit_iter_loop.stderr create mode 100644 src/tools/clippy/tests/ui-toml/large_futures/large_futures.fixed create mode 100644 src/tools/clippy/tests/ui-toml/large_stack_frames/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.rs create mode 100644 src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.stderr create mode 100644 src/tools/clippy/tests/ui-toml/large_types_passed_by_value/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.fixed create mode 100644 src/tools/clippy/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.rs create mode 100644 src/tools/clippy/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.stderr create mode 100644 src/tools/clippy/tests/ui-toml/lint_decimal_readability/test.fixed create mode 100644 src/tools/clippy/tests/ui-toml/manual_let_else/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/manual_let_else/manual_let_else.fixed create mode 100644 src/tools/clippy/tests/ui-toml/manual_let_else/manual_let_else.rs create mode 100644 src/tools/clippy/tests/ui-toml/manual_let_else/manual_let_else.stderr create mode 100644 src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.fixed create mode 100644 src/tools/clippy/tests/ui-toml/min_rust_version/min_rust_version.fixed create mode 100644 src/tools/clippy/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.fixed create mode 100644 src/tools/clippy/tests/ui-toml/path_ends_with_ext/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/path_ends_with_ext/path_ends_with_ext.rs create mode 100644 src/tools/clippy/tests/ui-toml/result_large_err/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/result_large_err/result_large_err.rs create mode 100644 src/tools/clippy/tests/ui-toml/result_large_err/result_large_err.stderr create mode 100644 src/tools/clippy/tests/ui-toml/too_large_for_stack/boxed_local.rs create mode 100644 src/tools/clippy/tests/ui-toml/too_large_for_stack/boxed_local.stderr create mode 100644 src/tools/clippy/tests/ui-toml/too_large_for_stack/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/too_large_for_stack/useless_vec.fixed create mode 100644 src/tools/clippy/tests/ui-toml/too_large_for_stack/useless_vec.rs create mode 100644 src/tools/clippy/tests/ui-toml/too_large_for_stack/useless_vec.stderr create mode 100644 src/tools/clippy/tests/ui-toml/too_many_arguments/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/too_many_arguments/too_many_arguments.rs create mode 100644 src/tools/clippy/tests/ui-toml/too_many_arguments/too_many_arguments.stderr create mode 100644 src/tools/clippy/tests/ui-toml/type_complexity/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/type_complexity/type_complexity.rs create mode 100644 src/tools/clippy/tests/ui-toml/type_complexity/type_complexity.stderr create mode 100644 src/tools/clippy/tests/ui-toml/type_repetition_in_bounds/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/type_repetition_in_bounds/main.rs create mode 100644 src/tools/clippy/tests/ui-toml/type_repetition_in_bounds/main.stderr delete mode 100644 src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/auxiliary/proc_macro_unsafe.rs delete mode 100644 src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/default/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/disabled/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr create mode 100644 src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr delete mode 100644 src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.stderr create mode 100644 src/tools/clippy/tests/ui-toml/unnecessary_box_returns/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.fixed create mode 100644 src/tools/clippy/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.rs create mode 100644 src/tools/clippy/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.stderr create mode 100644 src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.fixed create mode 100644 src/tools/clippy/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed create mode 100644 src/tools/clippy/tests/ui-toml/vec_box_sized/test.fixed create mode 100644 src/tools/clippy/tests/ui-toml/verbose_bit_mask/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.fixed create mode 100644 src/tools/clippy/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.rs create mode 100644 src/tools/clippy/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.stderr create mode 100644 src/tools/clippy/tests/ui-toml/wildcard_imports/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/wildcard_imports/wildcard_imports.fixed create mode 100644 src/tools/clippy/tests/ui-toml/wildcard_imports/wildcard_imports.rs create mode 100644 src/tools/clippy/tests/ui-toml/wildcard_imports/wildcard_imports.stderr create mode 100644 src/tools/clippy/tests/ui/cast_size.32bit.stderr create mode 100644 src/tools/clippy/tests/ui/cast_size.64bit.stderr delete mode 100644 src/tools/clippy/tests/ui/cast_size.stderr delete mode 100644 src/tools/clippy/tests/ui/cast_size_32bit.rs delete mode 100644 src/tools/clippy/tests/ui/cast_size_32bit.stderr create mode 100644 src/tools/clippy/tests/ui/cfg_features.fixed create mode 100644 src/tools/clippy/tests/ui/crashes/ice-11337.rs create mode 100644 src/tools/clippy/tests/ui/crashes/ice-11422.fixed create mode 100644 src/tools/clippy/tests/ui/crashes/ice-11422.rs create mode 100644 src/tools/clippy/tests/ui/crashes/ice-11422.stderr create mode 100644 src/tools/clippy/tests/ui/crashes/ice-2774.fixed create mode 100644 src/tools/clippy/tests/ui/crashes/ice-3717.fixed create mode 100644 src/tools/clippy/tests/ui/crashes/ice-5835.fixed create mode 100644 src/tools/clippy/tests/ui/crashes/ice-5872.fixed create mode 100644 src/tools/clippy/tests/ui/crashes/ice-7169.fixed create mode 100644 src/tools/clippy/tests/ui/crashes/ice-8250.fixed create mode 100644 src/tools/clippy/tests/ui/crashes/ice-8821.fixed create mode 100644 src/tools/clippy/tests/ui/crashes/ice-8850.fixed create mode 100644 src/tools/clippy/tests/ui/crashes/ice-96721.fixed create mode 100644 src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.fixed create mode 100644 src/tools/clippy/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed create mode 100644 src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.fixed create mode 100644 src/tools/clippy/tests/ui/eprint_with_newline.fixed create mode 100644 src/tools/clippy/tests/ui/fn_to_numeric_cast.32bit.stderr create mode 100644 src/tools/clippy/tests/ui/fn_to_numeric_cast.64bit.stderr delete mode 100644 src/tools/clippy/tests/ui/fn_to_numeric_cast.stderr delete mode 100644 src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs delete mode 100644 src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.stderr create mode 100644 src/tools/clippy/tests/ui/for_kv_map.fixed create mode 100644 src/tools/clippy/tests/ui/from_str_radix_10.fixed create mode 100644 src/tools/clippy/tests/ui/implied_bounds_in_impls.fixed create mode 100644 src/tools/clippy/tests/ui/implied_bounds_in_impls.rs create mode 100644 src/tools/clippy/tests/ui/implied_bounds_in_impls.stderr delete mode 100644 src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.fixed delete mode 100644 src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.rs delete mode 100644 src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.stderr delete mode 100644 src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.fixed delete mode 100644 src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.rs delete mode 100644 src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.stderr delete mode 100644 src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs delete mode 100644 src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr create mode 100644 src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.fixed create mode 100644 src/tools/clippy/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed create mode 100644 src/tools/clippy/tests/ui/iter_out_of_bounds.rs create mode 100644 src/tools/clippy/tests/ui/iter_out_of_bounds.stderr create mode 100644 src/tools/clippy/tests/ui/large_enum_variant.32bit.stderr create mode 100644 src/tools/clippy/tests/ui/large_enum_variant.64bit.stderr delete mode 100644 src/tools/clippy/tests/ui/large_enum_variant.stderr create mode 100644 src/tools/clippy/tests/ui/large_futures.fixed create mode 100644 src/tools/clippy/tests/ui/let_and_return.fixed create mode 100644 src/tools/clippy/tests/ui/manual_clamp.fixed create mode 100644 src/tools/clippy/tests/ui/manual_let_else_match.fixed create mode 100644 src/tools/clippy/tests/ui/misnamed_getters.fixed create mode 100644 src/tools/clippy/tests/ui/missing_asserts_for_indexing.fixed create mode 100644 src/tools/clippy/tests/ui/missing_asserts_for_indexing.rs create mode 100644 src/tools/clippy/tests/ui/missing_asserts_for_indexing.stderr create mode 100644 src/tools/clippy/tests/ui/missing_asserts_for_indexing_unfixable.rs create mode 100644 src/tools/clippy/tests/ui/missing_asserts_for_indexing_unfixable.stderr create mode 100644 src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.fixed create mode 100644 src/tools/clippy/tests/ui/needless_borrow_pat.fixed create mode 100644 src/tools/clippy/tests/ui/needless_borrows_for_generic_args.fixed create mode 100644 src/tools/clippy/tests/ui/needless_borrows_for_generic_args.rs create mode 100644 src/tools/clippy/tests/ui/needless_borrows_for_generic_args.stderr create mode 100644 src/tools/clippy/tests/ui/new_without_default.fixed create mode 100644 src/tools/clippy/tests/ui/non_canonical_clone_impl.fixed create mode 100644 src/tools/clippy/tests/ui/non_canonical_clone_impl.rs create mode 100644 src/tools/clippy/tests/ui/non_canonical_clone_impl.stderr create mode 100644 src/tools/clippy/tests/ui/non_canonical_partial_ord_impl.fixed create mode 100644 src/tools/clippy/tests/ui/non_canonical_partial_ord_impl.rs create mode 100644 src/tools/clippy/tests/ui/non_canonical_partial_ord_impl.stderr create mode 100644 src/tools/clippy/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs create mode 100644 src/tools/clippy/tests/ui/non_canonical_partial_ord_impl_fully_qual.stderr create mode 100644 src/tools/clippy/tests/ui/op_ref.fixed create mode 100644 src/tools/clippy/tests/ui/overly_complex_bool_expr.fixed create mode 100644 src/tools/clippy/tests/ui/path_ends_with_ext.fixed create mode 100644 src/tools/clippy/tests/ui/path_ends_with_ext.rs create mode 100644 src/tools/clippy/tests/ui/path_ends_with_ext.stderr create mode 100644 src/tools/clippy/tests/ui/print_literal.fixed create mode 100644 src/tools/clippy/tests/ui/readonly_write_lock.fixed create mode 100644 src/tools/clippy/tests/ui/redundant_as_str.fixed create mode 100644 src/tools/clippy/tests/ui/redundant_as_str.rs create mode 100644 src/tools/clippy/tests/ui/redundant_as_str.stderr create mode 100644 src/tools/clippy/tests/ui/reserve_after_initialization.fixed create mode 100644 src/tools/clippy/tests/ui/reserve_after_initialization.rs create mode 100644 src/tools/clippy/tests/ui/reserve_after_initialization.stderr create mode 100644 src/tools/clippy/tests/ui/should_panic_without_expect.rs create mode 100644 src/tools/clippy/tests/ui/should_panic_without_expect.stderr delete mode 100644 src/tools/clippy/tests/ui/significant_drop_in_scrutinee.fixed create mode 100644 src/tools/clippy/tests/ui/std_instead_of_core.fixed create mode 100644 src/tools/clippy/tests/ui/suspicious_command_arg_space.fixed create mode 100644 src/tools/clippy/tests/ui/trailing_zeros.fixed create mode 100644 src/tools/clippy/tests/ui/transmute_float_to_int.fixed create mode 100644 src/tools/clippy/tests/ui/transmute_int_to_non_zero.fixed create mode 100644 src/tools/clippy/tests/ui/transmute_ptr_to_ptr.fixed delete mode 100644 src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs delete mode 100644 src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr create mode 100644 src/tools/clippy/tests/ui/unit_hash.fixed create mode 100644 src/tools/clippy/tests/ui/unnecessary_map_on_constructor.fixed create mode 100644 src/tools/clippy/tests/ui/unnecessary_map_on_constructor.rs create mode 100644 src/tools/clippy/tests/ui/unnecessary_map_on_constructor.stderr create mode 100644 src/tools/clippy/tests/ui/unwrap_or.fixed create mode 100644 src/tools/clippy/tests/ui/upper_case_acronyms.fixed create mode 100644 src/tools/clippy/tests/ui/vec_resize_to_zero.fixed create mode 100644 src/tools/clippy/tests/ui/write_literal.fixed (limited to 'src/tools/clippy/tests') diff --git a/src/tools/clippy/tests/compile-test.rs b/src/tools/clippy/tests/compile-test.rs index e46f8bf6f..f340cf593 100644 --- a/src/tools/clippy/tests/compile-test.rs +++ b/src/tools/clippy/tests/compile-test.rs @@ -1,16 +1,13 @@ -#![feature(test)] // compiletest_rs requires this attribute #![feature(lazy_cell)] #![feature(is_sorted)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] #![warn(rust_2018_idioms, unused_lifetimes)] #![allow(unused_extern_crates)] -use compiletest::{status_emitter, CommandBuilder, OutputConflictHandling}; -use ui_test as compiletest; -use ui_test::Mode as TestMode; +use ui_test::{status_emitter, Args, CommandBuilder, Config, Match, Mode, OutputConflictHandling}; use std::collections::BTreeMap; -use std::env::{self, remove_var, set_var, var_os}; +use std::env::{self, set_var, var_os}; use std::ffi::{OsStr, OsString}; use std::fs; use std::path::{Path, PathBuf}; @@ -21,7 +18,6 @@ use test_utils::IS_RUSTC_TEST_SUITE; // in the depinfo file (otherwise cargo thinks they are unused) extern crate clippy_lints; extern crate clippy_utils; -extern crate derive_new; extern crate futures; extern crate if_chain; extern crate itertools; @@ -30,11 +26,12 @@ extern crate quote; extern crate syn; extern crate tokio; +mod test_utils; + /// All crates used in UI tests are listed here static TEST_DEPENDENCIES: &[&str] = &[ "clippy_lints", "clippy_utils", - "derive_new", "futures", "if_chain", "itertools", @@ -105,32 +102,35 @@ static EXTERN_FLAGS: LazyLock> = LazyLock::new(|| { .collect() }); -mod test_utils; - // whether to run internal tests or not const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal"); -fn base_config(test_dir: &str) -> compiletest::Config { - let mut config = compiletest::Config { - mode: TestMode::Yolo, - stderr_filters: vec![], - stdout_filters: vec![], - output_conflict_handling: if var_os("RUSTC_BLESS").is_some_and(|v| v != "0") - || env::args().any(|arg| arg == "--bless") - { - OutputConflictHandling::Bless - } else { - OutputConflictHandling::Error("cargo uibless".into()) +fn canonicalize(path: impl AsRef) -> PathBuf { + let path = path.as_ref(); + fs::create_dir_all(path).unwrap(); + fs::canonicalize(path).unwrap_or_else(|err| panic!("{} cannot be canonicalized: {err}", path.display())) +} + +fn base_config(test_dir: &str) -> (Config, Args) { + let mut args = Args::test().unwrap(); + args.bless |= var_os("RUSTC_BLESS").is_some_and(|v| v != "0"); + + let mut config = Config { + mode: Mode::Yolo { + rustfix: ui_test::RustfixMode::Everything, }, + stderr_filters: vec![(Match::PathBackslash, b"/")], + stdout_filters: vec![], + filter_files: env::var("TESTNAME") + .map(|filters| filters.split(',').map(str::to_string).collect()) + .unwrap_or_default(), target: None, - out_dir: PathBuf::from(std::env::var_os("CARGO_TARGET_DIR").unwrap_or("target".into())).join("ui_test"), - ..compiletest::Config::rustc(Path::new("tests").join(test_dir)) + out_dir: canonicalize(var_os("CARGO_TARGET_DIR").unwrap_or_else(|| "target".into())).join("ui_test"), + ..Config::rustc(Path::new("tests").join(test_dir)) }; - - if let Some(_path) = option_env!("RUSTC_LIB_PATH") { - //let path = PathBuf::from(path); - //config.run_lib_path = path.clone(); - //config.compile_lib_path = path; + config.with_args(&args, /* bless by default */ false); + if let OutputConflictHandling::Error(err) = &mut config.output_conflict_handling { + *err = "cargo uibless".into(); } let current_exe_path = env::current_exe().unwrap(); let deps_path = current_exe_path.parent().unwrap(); @@ -155,52 +155,34 @@ fn base_config(test_dir: &str) -> compiletest::Config { config.program.args.push(dep.into()); } - // Normalize away slashes in windows paths. - config.stderr_filter(r"\\", "/"); - - //config.build_base = profile_path.join("test").join(test_dir); config.program.program = profile_path.join(if cfg!(windows) { "clippy-driver.exe" } else { "clippy-driver" }); - config -} - -fn test_filter() -> Box bool> { - if let Ok(filters) = env::var("TESTNAME") { - let filters: Vec<_> = filters.split(',').map(ToString::to_string).collect(); - Box::new(move |path| filters.iter().any(|f| path.to_string_lossy().contains(f))) - } else { - Box::new(|_| true) - } + (config, args) } fn run_ui() { - let config = base_config("ui"); - //config.rustfix_coverage = true; - // use tests/clippy.toml - let _g = VarGuard::set("CARGO_MANIFEST_DIR", fs::canonicalize("tests").unwrap()); - let _threads = VarGuard::set( - "RUST_TEST_THREADS", - // if RUST_TEST_THREADS is set, adhere to it, otherwise override it - env::var("RUST_TEST_THREADS").unwrap_or_else(|_| { - std::thread::available_parallelism() - .map_or(1, std::num::NonZeroUsize::get) - .to_string() - }), - ); + let (mut config, args) = base_config("ui"); + config + .program + .envs + .push(("CLIPPY_CONF_DIR".into(), Some(canonicalize("tests").into()))); - let test_filter = test_filter(); + let quiet = args.quiet; - compiletest::run_tests_generic( - config, - move |path| compiletest::default_file_filter(path) && test_filter(path), - compiletest::default_per_file_config, - status_emitter::Text, + ui_test::run_tests_generic( + vec![config], + ui_test::default_file_filter, + ui_test::default_per_file_config, + if quiet { + status_emitter::Text::quiet() + } else { + status_emitter::Text::verbose() + }, ) .unwrap(); - check_rustfix_coverage(); } fn run_internal_tests() { @@ -208,51 +190,59 @@ fn run_internal_tests() { if !RUN_INTERNAL_TESTS { return; } - let mut config = base_config("ui-internal"); + let (mut config, args) = base_config("ui-internal"); if let OutputConflictHandling::Error(err) = &mut config.output_conflict_handling { *err = "cargo uitest --features internal -- -- --bless".into(); } - let test_filter = test_filter(); + let quiet = args.quiet; - compiletest::run_tests_generic( - config, - move |path| compiletest::default_file_filter(path) && test_filter(path), - compiletest::default_per_file_config, - status_emitter::Text, + ui_test::run_tests_generic( + vec![config], + ui_test::default_file_filter, + ui_test::default_per_file_config, + if quiet { + status_emitter::Text::quiet() + } else { + status_emitter::Text::verbose() + }, ) .unwrap(); } fn run_ui_toml() { - let mut config = base_config("ui-toml"); - - config.stderr_filter( - ®ex::escape( - &fs::canonicalize("tests") - .unwrap() - .parent() - .unwrap() - .display() - .to_string() - .replace('\\', "/"), + let (mut config, args) = base_config("ui-toml"); + + config.stderr_filters = vec![ + ( + Match::Exact( + canonicalize("tests") + .parent() + .unwrap() + .to_string_lossy() + .as_bytes() + .to_vec(), + ), + b"$DIR", ), - "$$DIR", - ); + (Match::Exact(b"\\".to_vec()), b"/"), + ]; - let test_filter = test_filter(); + let quiet = args.quiet; ui_test::run_tests_generic( - config, - |path| compiletest::default_file_filter(path) && test_filter(path), - |config, path| { - let mut config = config.clone(); + vec![config], + ui_test::default_file_filter, + |config, path, _file_contents| { config .program .envs .push(("CLIPPY_CONF_DIR".into(), Some(path.parent().unwrap().into()))); - Some(config) }, - status_emitter::Text, + if quiet { + status_emitter::Text::quiet() + } else { + status_emitter::Text::verbose() + }, ) .unwrap(); } @@ -262,7 +252,7 @@ fn run_ui_cargo() { return; } - let mut config = base_config("ui-cargo"); + let (mut config, args) = base_config("ui-cargo"); config.program.input_file_flag = CommandBuilder::cargo().input_file_flag; config.program.out_dir_flag = CommandBuilder::cargo().out_dir_flag; config.program.args = vec!["clippy".into(), "--color".into(), "never".into(), "--quiet".into()]; @@ -280,30 +270,47 @@ fn run_ui_cargo() { }); config.edition = None; - config.stderr_filter( - ®ex::escape( - &fs::canonicalize("tests") - .unwrap() - .parent() - .unwrap() - .display() - .to_string() - .replace('\\', "/"), + config.stderr_filters = vec![ + ( + Match::Exact( + canonicalize("tests") + .parent() + .unwrap() + .to_string_lossy() + .as_bytes() + .to_vec(), + ), + b"$DIR", ), - "$$DIR", - ); + (Match::Exact(b"\\".to_vec()), b"/"), + ]; - let test_filter = test_filter(); + let quiet = args.quiet; + + let ignored_32bit = |path: &Path| { + // FIXME: for some reason the modules are linted in a different order for this test + cfg!(target_pointer_width = "32") && path.ends_with("tests/ui-cargo/module_style/fail_mod/Cargo.toml") + }; ui_test::run_tests_generic( - config, - |path| test_filter(path) && path.ends_with("Cargo.toml"), - |config, path| { - let mut config = config.clone(); - config.out_dir = PathBuf::from("target/ui_test_cargo/").join(path.parent().unwrap()); - Some(config) + vec![config], + |path, config| { + path.ends_with("Cargo.toml") && ui_test::default_any_file_filter(path, config) && !ignored_32bit(path) + }, + |config, path, _file_contents| { + config.out_dir = canonicalize( + std::env::current_dir() + .unwrap() + .join("target") + .join("ui_test_cargo/") + .join(path.parent().unwrap()), + ); + }, + if quiet { + status_emitter::Text::quiet() + } else { + status_emitter::Text::verbose() }, - status_emitter::Text, ) .unwrap(); } @@ -328,7 +335,6 @@ fn main() { "cargo" => run_ui_cargo as fn(), "toml" => run_ui_toml as fn(), "internal" => run_internal_tests as fn(), - "rustfix-coverage-known-exceptions-accuracy" => rustfix_coverage_known_exceptions_accuracy as fn(), "ui-cargo-toml-metadata" => ui_cargo_toml_metadata as fn(), _ => panic!("unknown speedtest: {speedtest} || accepted speedtests are: [ui, cargo, toml, internal]"), @@ -349,95 +355,20 @@ fn main() { f(); sum += start.elapsed().as_millis(); } - println!("average {} time: {} millis.", speedtest.to_uppercase(), sum / 1000); + println!( + "average {} time: {} millis.", + speedtest.to_uppercase(), + sum / u128::from(iterations) + ); } else { run_ui(); run_ui_toml(); run_ui_cargo(); run_internal_tests(); - rustfix_coverage_known_exceptions_accuracy(); ui_cargo_toml_metadata(); } } -const RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS: &[&str] = &[ - "assign_ops2.rs", - "borrow_deref_ref_unfixable.rs", - "cast_size_32bit.rs", - "char_lit_as_u8.rs", - "cmp_owned/without_suggestion.rs", - "dbg_macro.rs", - "deref_addrof_double_trigger.rs", - "doc/unbalanced_ticks.rs", - "eprint_with_newline.rs", - "explicit_counter_loop.rs", - "iter_skip_next_unfixable.rs", - "let_and_return.rs", - "literals.rs", - "map_flatten.rs", - "map_unwrap_or.rs", - "match_bool.rs", - "mem_replace_macro.rs", - "needless_arbitrary_self_type_unfixable.rs", - "needless_borrow_pat.rs", - "needless_for_each_unfixable.rs", - "nonminimal_bool.rs", - "print_literal.rs", - "redundant_static_lifetimes_multiple.rs", - "ref_binding_to_reference.rs", - "repl_uninit.rs", - "result_map_unit_fn_unfixable.rs", - "search_is_some.rs", - "single_component_path_imports_nested_first.rs", - "string_add.rs", - "suspicious_to_owned.rs", - "toplevel_ref_arg_non_rustfix.rs", - "unit_arg.rs", - "unnecessary_clone.rs", - "unnecessary_lazy_eval_unfixable.rs", - "write_literal.rs", - "write_literal_2.rs", -]; - -fn check_rustfix_coverage() { - let missing_coverage_path = Path::new("debug/test/ui/rustfix_missing_coverage.txt"); - let missing_coverage_path = if let Ok(target_dir) = std::env::var("CARGO_TARGET_DIR") { - PathBuf::from(target_dir).join(missing_coverage_path) - } else { - missing_coverage_path.to_path_buf() - }; - - if let Ok(missing_coverage_contents) = std::fs::read_to_string(missing_coverage_path) { - assert!(RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS.iter().is_sorted_by_key(Path::new)); - - for rs_file in missing_coverage_contents.lines() { - let rs_path = Path::new(rs_file); - if rs_path.starts_with("tests/ui/crashes") { - continue; - } - assert!(rs_path.starts_with("tests/ui/"), "{rs_file:?}"); - let filename = rs_path.strip_prefix("tests/ui/").unwrap(); - assert!( - RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS - .binary_search_by_key(&filename, Path::new) - .is_ok(), - "`{rs_file}` runs `MachineApplicable` diagnostics but is missing a `run-rustfix` annotation. \ - Please either add `//@run-rustfix` at the top of the file or add the file to \ - `RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS` in `tests/compile-test.rs`.", - ); - } - } -} - -fn rustfix_coverage_known_exceptions_accuracy() { - for filename in RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS { - let rs_path = Path::new("tests/ui").join(filename); - assert!(rs_path.exists(), "`{}` does not exist", rs_path.display()); - let fixed_path = rs_path.with_extension("fixed"); - assert!(!fixed_path.exists(), "`{}` exists", fixed_path.display()); - } -} - fn ui_cargo_toml_metadata() { let ui_cargo_path = Path::new("tests/ui-cargo"); let cargo_common_metadata_path = ui_cargo_path.join("cargo_common_metadata"); @@ -473,27 +404,3 @@ fn ui_cargo_toml_metadata() { ); } } - -/// Restores an env var on drop -#[must_use] -struct VarGuard { - key: &'static str, - value: Option, -} - -impl VarGuard { - fn set(key: &'static str, val: impl AsRef) -> Self { - let value = var_os(key); - set_var(key, val); - Self { key, value } - } -} - -impl Drop for VarGuard { - fn drop(&mut self) { - match self.value.as_deref() { - None => remove_var(self.key), - Some(value) => set_var(self.key, value), - } - } -} diff --git a/src/tools/clippy/tests/headers.rs b/src/tools/clippy/tests/headers.rs index 1d1e566cb..7eec9a9cd 100644 --- a/src/tools/clippy/tests/headers.rs +++ b/src/tools/clippy/tests/headers.rs @@ -16,7 +16,7 @@ fn old_test_headers() { continue; } - let file = fs::read_to_string(entry.path()).unwrap(); + let file = fs::read_to_string(entry.path()).unwrap_or_else(|err| panic!("{}: {err}", entry.path().display())); if let Some(header) = old_headers.find(&file) { println!("Found header `{}` in {}", header.as_str(), entry.path().display()); diff --git a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail/Cargo.stderr b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail/Cargo.stderr index e161507b5..4d97d5496 100644 --- a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail/Cargo.stderr +++ b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail/Cargo.stderr @@ -1,6 +1,7 @@ error: package `cargo_common_metadata_fail` is missing `package.description` metadata | = note: `-D clippy::cargo-common-metadata` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cargo_common_metadata)]` error: package `cargo_common_metadata_fail` is missing `either package.license or package.license_file` metadata diff --git a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish/Cargo.stderr b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish/Cargo.stderr index dbf494cc3..9eb884f08 100644 --- a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish/Cargo.stderr +++ b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish/Cargo.stderr @@ -1,6 +1,7 @@ error: package `cargo_common_metadata_fail_publish` is missing `package.description` metadata | = note: `-D clippy::cargo-common-metadata` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cargo_common_metadata)]` error: package `cargo_common_metadata_fail_publish` is missing `either package.license or package.license_file` metadata diff --git a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish_true/Cargo.stderr b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish_true/Cargo.stderr index ae5967406..f9685a784 100644 --- a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish_true/Cargo.stderr +++ b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish_true/Cargo.stderr @@ -1,6 +1,7 @@ error: package `cargo_common_metadata_fail_publish_true` is missing `package.description` metadata | = note: `-D clippy::cargo-common-metadata` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cargo_common_metadata)]` error: package `cargo_common_metadata_fail_publish_true` is missing `either package.license or package.license_file` metadata diff --git a/src/tools/clippy/tests/ui-cargo/duplicate_mod/fail/Cargo.stderr b/src/tools/clippy/tests/ui-cargo/duplicate_mod/fail/Cargo.stderr index fde3a1e65..912ea9bb4 100644 --- a/src/tools/clippy/tests/ui-cargo/duplicate_mod/fail/Cargo.stderr +++ b/src/tools/clippy/tests/ui-cargo/duplicate_mod/fail/Cargo.stderr @@ -9,6 +9,7 @@ error: file is loaded as a module multiple times: `src/b.rs` | = help: replace all but one `mod` item with `use` items = note: `-D clippy::duplicate-mod` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::duplicate_mod)]` error: file is loaded as a module multiple times: `src/c.rs` --> src/main.rs:9:1 diff --git a/src/tools/clippy/tests/ui-cargo/feature_name/fail/Cargo.stderr b/src/tools/clippy/tests/ui-cargo/feature_name/fail/Cargo.stderr index da2db45d3..388f49fb2 100644 --- a/src/tools/clippy/tests/ui-cargo/feature_name/fail/Cargo.stderr +++ b/src/tools/clippy/tests/ui-cargo/feature_name/fail/Cargo.stderr @@ -2,6 +2,7 @@ error: the "no-" prefix in the feature name "no-qaq" is negative | = help: consider renaming the feature to "qaq", but make sure the feature adds functionality = note: `-D clippy::negative-feature-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::negative_feature_names)]` error: the "no_" prefix in the feature name "no_qaq" is negative | @@ -19,6 +20,7 @@ error: the "-support" suffix in the feature name "qvq-support" is redundant | = help: consider renaming the feature to "qvq" = note: `-D clippy::redundant-feature-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_feature_names)]` error: the "_support" suffix in the feature name "qvq_support" is redundant | diff --git a/src/tools/clippy/tests/ui-cargo/module_style/fail_mod/Cargo.stderr b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod/Cargo.stderr index c2907f319..902330e17 100644 --- a/src/tools/clippy/tests/ui-cargo/module_style/fail_mod/Cargo.stderr +++ b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod/Cargo.stderr @@ -6,6 +6,7 @@ error: `mod.rs` files are required, found `src/bad/inner.rs` | = help: move `src/bad/inner.rs` to `src/bad/inner/mod.rs` = note: `-D clippy::self-named-module-files` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::self_named_module_files)]` error: `mod.rs` files are required, found `src/bad/inner/stuff.rs` --> src/bad/inner/stuff.rs:1:1 diff --git a/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/Cargo.stderr b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/Cargo.stderr index fcf1a3c5e..d776feb7f 100644 --- a/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/Cargo.stderr +++ b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/Cargo.stderr @@ -6,5 +6,6 @@ error: `mod.rs` files are required, found `src/bad.rs` | = help: move `src/bad.rs` to `src/bad/mod.rs` = note: `-D clippy::self-named-module-files` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::self_named_module_files)]` error: could not compile `fail-mod-remap` (bin "fail-mod-remap") due to previous error diff --git a/src/tools/clippy/tests/ui-cargo/module_style/fail_no_mod/Cargo.stderr b/src/tools/clippy/tests/ui-cargo/module_style/fail_no_mod/Cargo.stderr index f61642ca2..22558bc4c 100644 --- a/src/tools/clippy/tests/ui-cargo/module_style/fail_no_mod/Cargo.stderr +++ b/src/tools/clippy/tests/ui-cargo/module_style/fail_no_mod/Cargo.stderr @@ -6,5 +6,6 @@ error: `mod.rs` files are not allowed, found `src/bad/mod.rs` | = help: move `src/bad/mod.rs` to `src/bad.rs` = note: `-D clippy::mod-module-files` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mod_module_files)]` error: could not compile `fail-no-mod` (bin "fail-no-mod") due to previous error diff --git a/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/fail/Cargo.stderr b/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/fail/Cargo.stderr index 5bcce9204..4beedc108 100644 --- a/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/fail/Cargo.stderr +++ b/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/fail/Cargo.stderr @@ -1,5 +1,6 @@ error: multiple versions for dependency `winapi`: 0.2.8, 0.3.9 | = note: `-D clippy::multiple-crate-versions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::multiple_crate_versions)]` error: could not compile `multiple_crate_versions` (bin "multiple_crate_versions") due to previous error diff --git a/src/tools/clippy/tests/ui-cargo/wildcard_dependencies/fail/Cargo.stderr b/src/tools/clippy/tests/ui-cargo/wildcard_dependencies/fail/Cargo.stderr index b1578c9f3..65a19bb07 100644 --- a/src/tools/clippy/tests/ui-cargo/wildcard_dependencies/fail/Cargo.stderr +++ b/src/tools/clippy/tests/ui-cargo/wildcard_dependencies/fail/Cargo.stderr @@ -1,5 +1,6 @@ error: wildcard dependency for `regex` | = note: `-D clippy::wildcard-dependencies` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wildcard_dependencies)]` error: could not compile `wildcard_dependencies` (bin "wildcard_dependencies") due to previous error diff --git a/src/tools/clippy/tests/ui-internal/check_formulation.stderr b/src/tools/clippy/tests/ui-internal/check_formulation.stderr index 10eabca4b..96fa61760 100644 --- a/src/tools/clippy/tests/ui-internal/check_formulation.stderr +++ b/src/tools/clippy/tests/ui-internal/check_formulation.stderr @@ -6,6 +6,7 @@ LL | /// Check for lint formulations that are correct | = help: try using `Checks for` instead = note: `-D clippy::almost-standard-lint-formulation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::almost_standard_lint_formulation)]` error: non-standard lint formulation --> $DIR/check_formulation.rs:33:5 diff --git a/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.fixed b/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.fixed index 72c04bf80..918e33345 100644 --- a/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.fixed +++ b/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] #![feature(rustc_private)] diff --git a/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.rs b/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.rs index 76f7c3ce9..1baf6142b 100644 --- a/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.rs +++ b/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] #![feature(rustc_private)] diff --git a/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.stderr b/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.stderr index 0852fe65a..dce2daad6 100644 --- a/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.stderr +++ b/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.stderr @@ -1,5 +1,5 @@ error: this call is collapsible - --> $DIR/collapsible_span_lint_calls.rs:36:9 + --> $DIR/collapsible_span_lint_calls.rs:35:9 | LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| { LL | | db.span_suggestion(expr.span, help_msg, sugg.to_string(), Applicability::MachineApplicable); @@ -7,14 +7,14 @@ LL | | }); | |__________^ help: collapse into: `span_lint_and_sugg(cx, TEST_LINT, expr.span, lint_msg, help_msg, sugg.to_string(), Applicability::MachineApplicable)` | note: the lint level is defined here - --> $DIR/collapsible_span_lint_calls.rs:2:9 + --> $DIR/collapsible_span_lint_calls.rs:1:9 | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ = note: `#[deny(clippy::collapsible_span_lint_calls)]` implied by `#[deny(clippy::internal)]` error: this call is collapsible - --> $DIR/collapsible_span_lint_calls.rs:39:9 + --> $DIR/collapsible_span_lint_calls.rs:38:9 | LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| { LL | | db.span_help(expr.span, help_msg); @@ -22,7 +22,7 @@ LL | | }); | |__________^ help: collapse into: `span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), help_msg)` error: this call is collapsible - --> $DIR/collapsible_span_lint_calls.rs:42:9 + --> $DIR/collapsible_span_lint_calls.rs:41:9 | LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| { LL | | db.help(help_msg); @@ -30,7 +30,7 @@ LL | | }); | |__________^ help: collapse into: `span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, None, help_msg)` error: this call is collapsible - --> $DIR/collapsible_span_lint_calls.rs:45:9 + --> $DIR/collapsible_span_lint_calls.rs:44:9 | LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| { LL | | db.span_note(expr.span, note_msg); @@ -38,7 +38,7 @@ LL | | }); | |__________^ help: collapse into: `span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg)` error: this call is collapsible - --> $DIR/collapsible_span_lint_calls.rs:48:9 + --> $DIR/collapsible_span_lint_calls.rs:47:9 | LL | / span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |db| { LL | | db.note(note_msg); diff --git a/src/tools/clippy/tests/ui-internal/if_chain_style.stderr b/src/tools/clippy/tests/ui-internal/if_chain_style.stderr index b12df2786..ea0495532 100644 --- a/src/tools/clippy/tests/ui-internal/if_chain_style.stderr +++ b/src/tools/clippy/tests/ui-internal/if_chain_style.stderr @@ -16,6 +16,7 @@ help: this `let` statement can also be in the `if_chain!` LL | let x = ""; | ^^^^^^^^^^^ = note: `-D clippy::if-chain-style` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::if_chain_style)]` error: `if a && b;` should be `if a; if b;` --> $DIR/if_chain_style.rs:24:12 diff --git a/src/tools/clippy/tests/ui-internal/interning_defined_symbol.fixed b/src/tools/clippy/tests/ui-internal/interning_defined_symbol.fixed index a1a10c079..98591e15b 100644 --- a/src/tools/clippy/tests/ui-internal/interning_defined_symbol.fixed +++ b/src/tools/clippy/tests/ui-internal/interning_defined_symbol.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute, clippy::let_unit_value)] #![feature(rustc_private)] diff --git a/src/tools/clippy/tests/ui-internal/interning_defined_symbol.rs b/src/tools/clippy/tests/ui-internal/interning_defined_symbol.rs index 32dbfe5dc..92e92d4fb 100644 --- a/src/tools/clippy/tests/ui-internal/interning_defined_symbol.rs +++ b/src/tools/clippy/tests/ui-internal/interning_defined_symbol.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute, clippy::let_unit_value)] #![feature(rustc_private)] diff --git a/src/tools/clippy/tests/ui-internal/interning_defined_symbol.stderr b/src/tools/clippy/tests/ui-internal/interning_defined_symbol.stderr index 4e99636e6..b8d9721ee 100644 --- a/src/tools/clippy/tests/ui-internal/interning_defined_symbol.stderr +++ b/src/tools/clippy/tests/ui-internal/interning_defined_symbol.stderr @@ -1,30 +1,30 @@ error: interning a defined symbol - --> $DIR/interning_defined_symbol.rs:18:13 + --> $DIR/interning_defined_symbol.rs:17:13 | LL | let _ = Symbol::intern("f32"); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::f32` | note: the lint level is defined here - --> $DIR/interning_defined_symbol.rs:2:9 + --> $DIR/interning_defined_symbol.rs:1:9 | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ = note: `#[deny(clippy::interning_defined_symbol)]` implied by `#[deny(clippy::internal)]` error: interning a defined symbol - --> $DIR/interning_defined_symbol.rs:21:13 + --> $DIR/interning_defined_symbol.rs:20:13 | LL | let _ = sym!(f32); | ^^^^^^^^^ help: try: `rustc_span::sym::f32` error: interning a defined symbol - --> $DIR/interning_defined_symbol.rs:24:13 + --> $DIR/interning_defined_symbol.rs:23:13 | LL | let _ = Symbol::intern("proc-macro"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::proc_dash_macro` error: interning a defined symbol - --> $DIR/interning_defined_symbol.rs:27:13 + --> $DIR/interning_defined_symbol.rs:26:13 | LL | let _ = Symbol::intern("self"); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::symbol::kw::SelfLower` diff --git a/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.fixed b/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.fixed index ac0752774..928596d08 100644 --- a/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.fixed +++ b/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] #![feature(rustc_private)] diff --git a/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.rs b/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.rs index 56f778621..50b28648c 100644 --- a/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.rs +++ b/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] #![feature(rustc_private)] diff --git a/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.stderr b/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.stderr index ddc06f0be..e97f6aea7 100644 --- a/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.stderr +++ b/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.stderr @@ -1,11 +1,11 @@ error: `extract_msrv_attr!` macro missing from `LateLintPass` implementation - --> $DIR/invalid_msrv_attr_impl.rs:30:1 + --> $DIR/invalid_msrv_attr_impl.rs:28:1 | LL | impl LateLintPass<'_> for Pass { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/invalid_msrv_attr_impl.rs:3:9 + --> $DIR/invalid_msrv_attr_impl.rs:1:9 | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ @@ -17,7 +17,7 @@ LL + extract_msrv_attr!(LateContext); | error: `extract_msrv_attr!` macro missing from `EarlyLintPass` implementation - --> $DIR/invalid_msrv_attr_impl.rs:34:1 + --> $DIR/invalid_msrv_attr_impl.rs:32:1 | LL | impl EarlyLintPass for Pass { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui-internal/invalid_paths.stderr b/src/tools/clippy/tests/ui-internal/invalid_paths.stderr index 0e8508869..988d32d52 100644 --- a/src/tools/clippy/tests/ui-internal/invalid_paths.stderr +++ b/src/tools/clippy/tests/ui-internal/invalid_paths.stderr @@ -5,6 +5,7 @@ LL | pub const TRANSMUTE: [&str; 4] = ["core", "intrinsics", "", "transmute" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::invalid-paths` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::invalid_paths)]` error: invalid path --> $DIR/invalid_paths.rs:18:5 diff --git a/src/tools/clippy/tests/ui-internal/outer_expn_data.fixed b/src/tools/clippy/tests/ui-internal/outer_expn_data.fixed index d8a08bc99..cef16cf6c 100644 --- a/src/tools/clippy/tests/ui-internal/outer_expn_data.fixed +++ b/src/tools/clippy/tests/ui-internal/outer_expn_data.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] #![feature(rustc_private)] diff --git a/src/tools/clippy/tests/ui-internal/outer_expn_data.rs b/src/tools/clippy/tests/ui-internal/outer_expn_data.rs index f7af0e9d8..fb453be66 100644 --- a/src/tools/clippy/tests/ui-internal/outer_expn_data.rs +++ b/src/tools/clippy/tests/ui-internal/outer_expn_data.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::internal)] #![allow(clippy::missing_clippy_version_attribute)] #![feature(rustc_private)] diff --git a/src/tools/clippy/tests/ui-internal/outer_expn_data.stderr b/src/tools/clippy/tests/ui-internal/outer_expn_data.stderr index afef69678..e41ace472 100644 --- a/src/tools/clippy/tests/ui-internal/outer_expn_data.stderr +++ b/src/tools/clippy/tests/ui-internal/outer_expn_data.stderr @@ -1,11 +1,11 @@ error: usage of `outer_expn().expn_data()` - --> $DIR/outer_expn_data.rs:25:34 + --> $DIR/outer_expn_data.rs:23:34 | LL | let _ = expr.span.ctxt().outer_expn().expn_data(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `outer_expn_data()` | note: the lint level is defined here - --> $DIR/outer_expn_data.rs:3:9 + --> $DIR/outer_expn_data.rs:1:9 | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed index fce24412f..3908411da 100644 --- a/src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed +++ b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:paths.rs #![deny(clippy::internal)] #![feature(rustc_private)] diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_def_path.rs b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.rs index b10bc9e46..632e26215 100644 --- a/src/tools/clippy/tests/ui-internal/unnecessary_def_path.rs +++ b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:paths.rs #![deny(clippy::internal)] #![feature(rustc_private)] diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_def_path.stderr b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.stderr index 3ca29f099..dd963d24c 100644 --- a/src/tools/clippy/tests/ui-internal/unnecessary_def_path.stderr +++ b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.stderr @@ -1,72 +1,72 @@ error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:37:13 + --> $DIR/unnecessary_def_path.rs:36:13 | LL | let _ = match_type(cx, ty, &OPTION); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Option)` | note: the lint level is defined here - --> $DIR/unnecessary_def_path.rs:3:9 + --> $DIR/unnecessary_def_path.rs:2:9 | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ = note: `#[deny(clippy::unnecessary_def_path)]` implied by `#[deny(clippy::internal)]` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:38:13 + --> $DIR/unnecessary_def_path.rs:37:13 | LL | let _ = match_type(cx, ty, RESULT); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:39:13 + --> $DIR/unnecessary_def_path.rs:38:13 | LL | let _ = match_type(cx, ty, &["core", "result", "Result"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:43:13 + --> $DIR/unnecessary_def_path.rs:42:13 | LL | let _ = clippy_utils::ty::match_type(cx, ty, rc_path); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Rc)` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:45:13 + --> $DIR/unnecessary_def_path.rs:44:13 | LL | let _ = match_type(cx, ty, &paths::OPTION); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Option)` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:46:13 + --> $DIR/unnecessary_def_path.rs:45:13 | LL | let _ = match_type(cx, ty, paths::RESULT); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)` error: use of a def path to a `LangItem` - --> $DIR/unnecessary_def_path.rs:48:13 + --> $DIR/unnecessary_def_path.rs:47:13 | LL | let _ = match_type(cx, ty, &["alloc", "boxed", "Box"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_lang_item(cx, ty, LangItem::OwnedBox)` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:49:13 + --> $DIR/unnecessary_def_path.rs:48:13 | LL | let _ = match_type(cx, ty, &["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::maybe_uninit_uninit)` error: use of a def path to a `LangItem` - --> $DIR/unnecessary_def_path.rs:51:13 + --> $DIR/unnecessary_def_path.rs:50:13 | LL | let _ = match_def_path(cx, did, &["alloc", "boxed", "Box"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().get(LangItem::OwnedBox) == Some(did)` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:52:13 + --> $DIR/unnecessary_def_path.rs:51:13 | LL | let _ = match_def_path(cx, did, &["core", "option", "Option"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.is_diagnostic_item(sym::Option, did)` error: use of a def path to a `LangItem` - --> $DIR/unnecessary_def_path.rs:53:13 + --> $DIR/unnecessary_def_path.rs:52:13 | LL | let _ = match_def_path(cx, did, &["core", "option", "Option", "Some"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().get(LangItem::OptionSome) == Some(did)` @@ -74,25 +74,25 @@ LL | let _ = match_def_path(cx, did, &["core", "option", "Option", "Some"]); = help: if this `DefId` came from a constructor expression or pattern then the parent `DefId` should be used instead error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:55:13 + --> $DIR/unnecessary_def_path.rs:54:13 | LL | let _ = match_trait_method(cx, expr, &["core", "convert", "AsRef"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_trait_method(cx, expr, sym::AsRef)` error: use of a def path to a diagnostic item - --> $DIR/unnecessary_def_path.rs:57:13 + --> $DIR/unnecessary_def_path.rs:56:13 | LL | let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_path_diagnostic_item(cx, expr, sym::Option)` error: use of a def path to a `LangItem` - --> $DIR/unnecessary_def_path.rs:58:13 + --> $DIR/unnecessary_def_path.rs:57:13 | LL | let _ = is_expr_path_def_path(cx, expr, &["core", "iter", "traits", "Iterator", "next"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().get(LangItem::IteratorNext) == Some(id))` error: use of a def path to a `LangItem` - --> $DIR/unnecessary_def_path.rs:59:13 + --> $DIR/unnecessary_def_path.rs:58:13 | LL | let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option", "Some"]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_res_lang_ctor(cx, path_res(cx, expr), LangItem::OptionSome)` diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr b/src/tools/clippy/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr index 3ca45404e..58b1fd92b 100644 --- a/src/tools/clippy/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr +++ b/src/tools/clippy/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr @@ -6,6 +6,7 @@ LL | const DEREF_TRAIT: [&str; 4] = ["core", "ops", "deref", "Deref"]; | = help: convert all references to use `sym::Deref` = note: `-D clippy::unnecessary-def-path` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_def_path)]` error: hardcoded path to a language item --> $DIR/unnecessary_def_path_hardcoded_path.rs:11:40 diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.fixed b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.fixed index b802de1cb..eb79fdbc4 100644 --- a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.fixed +++ b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(rustc_private)] #![deny(clippy::internal)] #![allow( diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.rs b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.rs index c1bead5bd..bbea13af9 100644 --- a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.rs +++ b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(rustc_private)] #![deny(clippy::internal)] #![allow( diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.stderr b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.stderr index a1f507f33..8e2aa5953 100644 --- a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.stderr +++ b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.stderr @@ -1,36 +1,36 @@ error: unnecessary `Symbol` to string conversion - --> $DIR/unnecessary_symbol_str.rs:16:5 + --> $DIR/unnecessary_symbol_str.rs:15:5 | LL | Symbol::intern("foo").as_str() == "clippy"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Symbol::intern("foo") == rustc_span::sym::clippy` | note: the lint level is defined here - --> $DIR/unnecessary_symbol_str.rs:3:9 + --> $DIR/unnecessary_symbol_str.rs:2:9 | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ = note: `#[deny(clippy::unnecessary_symbol_str)]` implied by `#[deny(clippy::internal)]` error: unnecessary `Symbol` to string conversion - --> $DIR/unnecessary_symbol_str.rs:17:5 + --> $DIR/unnecessary_symbol_str.rs:16:5 | LL | Symbol::intern("foo").to_string() == "self"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Symbol::intern("foo") == rustc_span::symbol::kw::SelfLower` error: unnecessary `Symbol` to string conversion - --> $DIR/unnecessary_symbol_str.rs:18:5 + --> $DIR/unnecessary_symbol_str.rs:17:5 | LL | Symbol::intern("foo").to_ident_string() != "Self"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Symbol::intern("foo") != rustc_span::symbol::kw::SelfUpper` error: unnecessary `Symbol` to string conversion - --> $DIR/unnecessary_symbol_str.rs:19:5 + --> $DIR/unnecessary_symbol_str.rs:18:5 | LL | &*Ident::empty().as_str() == "clippy"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ident::empty().name == rustc_span::sym::clippy` error: unnecessary `Symbol` to string conversion - --> $DIR/unnecessary_symbol_str.rs:20:5 + --> $DIR/unnecessary_symbol_str.rs:19:5 | LL | "clippy" == Ident::empty().to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::clippy == Ident::empty().name` diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr index a8900da4e..99f08d947 100644 --- a/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr +++ b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr @@ -5,6 +5,7 @@ LL | std::f32::MAX; | ^^^^^^^^^^^^^ | = note: `-D clippy::absolute-paths` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::absolute_paths)]` error: consider bringing this path into scope with the `use` keyword --> $DIR/absolute_paths.rs:41:5 diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr index 41b70644b..017ba4cc2 100644 --- a/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr +++ b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr @@ -5,6 +5,7 @@ LL | std::f32::MAX; | ^^^^^^^^^^^^^ | = note: `-D clippy::absolute-paths` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::absolute_paths)]` error: consider bringing this path into scope with the `use` keyword --> $DIR/absolute_paths.rs:41:5 diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.rs b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.rs index d4c250a8f..0e6a54452 100644 --- a/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.rs +++ b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.rs @@ -1,4 +1,4 @@ -//@aux-build:../../ui/auxiliary/proc_macros.rs:proc-macro +//@aux-build:../../ui/auxiliary/proc_macros.rs //@aux-build:helper.rs //@revisions: allow_crates disallow_crates //@[allow_crates] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/absolute_paths/allow_crates diff --git a/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed b/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed index c90856845..c04543da9 100644 --- a/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed +++ b/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::uninlined_format_args)] #![allow(clippy::unnecessary_literal_unwrap)] diff --git a/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs b/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs index 661350c5c..813830d80 100644 --- a/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs +++ b/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::uninlined_format_args)] #![allow(clippy::unnecessary_literal_unwrap)] diff --git a/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr b/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr index eb1180e60..b754f67ed 100644 --- a/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr +++ b/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr @@ -1,10 +1,11 @@ error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:10:5 + --> $DIR/uninlined_format_args.rs:9:5 | LL | println!("val='{}'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::uninlined-format-args` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::uninlined_format_args)]` help: change this to | LL - println!("val='{}'", local_i32); @@ -12,7 +13,7 @@ LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:11:5 + --> $DIR/uninlined_format_args.rs:10:5 | LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,12 +25,13 @@ LL + println!("Hello {} is {local_f64:.local_i32$}", "x"); | error: literal with an empty format string - --> $DIR/uninlined_format_args.rs:11:35 + --> $DIR/uninlined_format_args.rs:10:35 | LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64); | ^^^ | = note: `-D clippy::print-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_literal)]` help: try | LL - println!("Hello {} is {:.*}", "x", local_i32, local_f64); @@ -37,7 +39,7 @@ LL + println!("Hello x is {:.*}", local_i32, local_f64); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:12:5 + --> $DIR/uninlined_format_args.rs:11:5 | LL | println!("Hello {} is {:.*}", local_i32, 5, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +51,7 @@ LL + println!("Hello {local_i32} is {local_f64:.*}", 5); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:13:5 + --> $DIR/uninlined_format_args.rs:12:5 | LL | println!("Hello {} is {2:.*}", local_i32, 5, local_f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +63,7 @@ LL + println!("Hello {local_i32} is {local_f64:.*}", 5); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args.rs:14:5 + --> $DIR/uninlined_format_args.rs:13:5 | LL | println!("{}, {}", local_i32, local_opt.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr b/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr index 4f98ca192..5e8d26e07 100644 --- a/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr +++ b/src/tools/clippy/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr @@ -5,6 +5,7 @@ LL | let _ = Baz + Baz; | ^^^^^^^^^ | = note: `-D clippy::arithmetic-side-effects` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]` error: arithmetic operation that can potentially result in unexpected side-effects --> $DIR/arithmetic_side_effects_allowed.rs:80:13 diff --git a/src/tools/clippy/tests/ui-toml/array_size_threshold/array_size_threshold.rs b/src/tools/clippy/tests/ui-toml/array_size_threshold/array_size_threshold.rs index 7f623c7a9..d36159e12 100644 --- a/src/tools/clippy/tests/ui-toml/array_size_threshold/array_size_threshold.rs +++ b/src/tools/clippy/tests/ui-toml/array_size_threshold/array_size_threshold.rs @@ -1,6 +1,6 @@ #![allow(unused)] #![warn(clippy::large_const_arrays, clippy::large_stack_arrays)] - +//@no-rustfix const ABOVE: [u8; 11] = [0; 11]; const BELOW: [u8; 10] = [0; 10]; diff --git a/src/tools/clippy/tests/ui-toml/array_size_threshold/array_size_threshold.stderr b/src/tools/clippy/tests/ui-toml/array_size_threshold/array_size_threshold.stderr index ac017b209..cf70b3c5c 100644 --- a/src/tools/clippy/tests/ui-toml/array_size_threshold/array_size_threshold.stderr +++ b/src/tools/clippy/tests/ui-toml/array_size_threshold/array_size_threshold.stderr @@ -7,6 +7,7 @@ LL | const ABOVE: [u8; 11] = [0; 11]; | help: make this a static item: `static` | = note: `-D clippy::large-const-arrays` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_const_arrays)]` error: allocating a local array larger than 10 bytes --> $DIR/array_size_threshold.rs:4:25 @@ -16,6 +17,7 @@ LL | const ABOVE: [u8; 11] = [0; 11]; | = help: consider allocating on the heap with `vec![0; 11].into_boxed_slice()` = note: `-D clippy::large-stack-arrays` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_stack_arrays)]` error: allocating a local array larger than 10 bytes --> $DIR/array_size_threshold.rs:8:17 diff --git a/src/tools/clippy/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs b/src/tools/clippy/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs index fbef5c456..868cf00a8 100644 --- a/src/tools/clippy/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs +++ b/src/tools/clippy/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.rs @@ -7,8 +7,10 @@ async fn bad() -> u32 { } async fn bad_reason() -> u32 { - let _x = Ipv4Addr::new(127, 0, 0, 1); - baz().await + let x = Ipv4Addr::new(127, 0, 0, 1); + let y = baz().await; + let _x = x; + y } async fn good() -> u32 { diff --git a/src/tools/clippy/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr b/src/tools/clippy/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr index 825aa1487..ddcd1940d 100644 --- a/src/tools/clippy/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr +++ b/src/tools/clippy/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr @@ -6,15 +6,16 @@ LL | let _x = String::from("hello"); | = note: strings are bad (from clippy.toml) = note: `-D clippy::await-holding-invalid-type` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::await_holding_invalid_type)]` error: `std::net::Ipv4Addr` may not be held across an `await` point per `clippy.toml` --> $DIR/await_holding_invalid_type.rs:10:9 | -LL | let _x = Ipv4Addr::new(127, 0, 0, 1); - | ^^ +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.rs:31:13 + --> $DIR/await_holding_invalid_type.rs:33:13 | LL | let _x = String::from("hi!"); | ^^ diff --git a/src/tools/clippy/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr b/src/tools/clippy/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr index 89d84eb24..a21952c0e 100644 --- a/src/tools/clippy/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr +++ b/src/tools/clippy/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr @@ -18,6 +18,7 @@ LL | fn cognitive_complexity() { | = help: you could split it up into multiple smaller functions = note: `-D clippy::cognitive-complexity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cognitive_complexity)]` error: aborting due to previous error; 2 warnings emitted diff --git a/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.rs b/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.rs index 21e4fce26..67129e624 100644 --- a/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.rs +++ b/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.rs @@ -1,6 +1,6 @@ //@compile-flags: --test #![warn(clippy::dbg_macro)] - +//@no-rustfix fn foo(n: u32) -> u32 { if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } } diff --git a/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.stderr b/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.stderr index 859383a71..3a66f701e 100644 --- a/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.stderr +++ b/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.stderr @@ -5,6 +5,7 @@ LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } | ^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::dbg-macro` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]` help: remove the invocation before committing it to a version control system | LL | if let Some(n) = n.checked_sub(4) { n } else { n } diff --git a/src/tools/clippy/tests/ui-toml/decimal_literal_representation/clippy.toml b/src/tools/clippy/tests/ui-toml/decimal_literal_representation/clippy.toml new file mode 100644 index 000000000..74fc5d249 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/decimal_literal_representation/clippy.toml @@ -0,0 +1 @@ +literal-representation-threshold = 0xFFFFFF diff --git a/src/tools/clippy/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.fixed b/src/tools/clippy/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.fixed new file mode 100644 index 000000000..750f3be84 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.fixed @@ -0,0 +1,6 @@ +#![warn(clippy::decimal_literal_representation)] +fn main() { + let _ = 8388608; + let _ = 0x00FF_FFFF; + //~^ ERROR: integer literal has a better hexadecimal representation +} diff --git a/src/tools/clippy/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.rs b/src/tools/clippy/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.rs new file mode 100644 index 000000000..26b3354d1 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.rs @@ -0,0 +1,6 @@ +#![warn(clippy::decimal_literal_representation)] +fn main() { + let _ = 8388608; + let _ = 16777215; + //~^ ERROR: integer literal has a better hexadecimal representation +} diff --git a/src/tools/clippy/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.stderr b/src/tools/clippy/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.stderr new file mode 100644 index 000000000..6f817a3fd --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/decimal_literal_representation/decimal_literal_representation.stderr @@ -0,0 +1,11 @@ +error: integer literal has a better hexadecimal representation + --> $DIR/decimal_literal_representation.rs:4:13 + | +LL | let _ = 16777215; + | ^^^^^^^^ help: consider: `0x00FF_FFFF` + | + = note: `-D clippy::decimal-literal-representation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::decimal_literal_representation)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/disallowed_macros/auxiliary/macros.rs b/src/tools/clippy/tests/ui-toml/disallowed_macros/auxiliary/macros.rs index fcaeace0e..f4166b227 100644 --- a/src/tools/clippy/tests/ui-toml/disallowed_macros/auxiliary/macros.rs +++ b/src/tools/clippy/tests/ui-toml/disallowed_macros/auxiliary/macros.rs @@ -30,3 +30,18 @@ macro_rules! item { const ITEM: usize = 1; }; } + +#[macro_export] +macro_rules! binop { + ($t:tt) => { + $t + $t + }; +} + +#[macro_export] +macro_rules! attr { + ($i:item) => { + #[repr(C)] + $i + }; +} diff --git a/src/tools/clippy/tests/ui-toml/disallowed_macros/clippy.toml b/src/tools/clippy/tests/ui-toml/disallowed_macros/clippy.toml index c8fe8be9a..85f1b71eb 100644 --- a/src/tools/clippy/tests/ui-toml/disallowed_macros/clippy.toml +++ b/src/tools/clippy/tests/ui-toml/disallowed_macros/clippy.toml @@ -8,4 +8,6 @@ disallowed-macros = [ "macros::ty", "macros::pat", "macros::item", + "macros::binop", + "macros::attr", ] diff --git a/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.rs b/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.rs index ba919b487..4a3d55e13 100644 --- a/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.rs +++ b/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.rs @@ -20,11 +20,14 @@ fn main() { let macros::pat!() = 1; let _: macros::ty!() = ""; macros::item!(); + let _ = macros::binop!(1); eprintln!("allowed"); } -struct S; +macros::attr! { + struct S; +} impl S { macros::item!(); diff --git a/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.stderr b/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.stderr index aed9feb6f..3c6f59b16 100644 --- a/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.stderr +++ b/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.stderr @@ -5,6 +5,7 @@ LL | println!("one"); | ^^^^^^^^^^^^^^^ | = note: `-D clippy::disallowed-macros` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_macros)]` error: use of a disallowed macro `std::println` --> $DIR/disallowed_macros.rs:11:5 @@ -62,23 +63,37 @@ error: use of a disallowed macro `macros::item` LL | macros::item!(); | ^^^^^^^^^^^^^^^ +error: use of a disallowed macro `macros::binop` + --> $DIR/disallowed_macros.rs:23:13 + | +LL | let _ = macros::binop!(1); + | ^^^^^^^^^^^^^^^^^ + +error: use of a disallowed macro `macros::attr` + --> $DIR/disallowed_macros.rs:28:1 + | +LL | / macros::attr! { +LL | | struct S; +LL | | } + | |_^ + error: use of a disallowed macro `macros::item` - --> $DIR/disallowed_macros.rs:30:5 + --> $DIR/disallowed_macros.rs:33:5 | LL | macros::item!(); | ^^^^^^^^^^^^^^^ error: use of a disallowed macro `macros::item` - --> $DIR/disallowed_macros.rs:34:5 + --> $DIR/disallowed_macros.rs:37:5 | LL | macros::item!(); | ^^^^^^^^^^^^^^^ error: use of a disallowed macro `macros::item` - --> $DIR/disallowed_macros.rs:38:5 + --> $DIR/disallowed_macros.rs:41:5 | LL | macros::item!(); | ^^^^^^^^^^^^^^^ -error: aborting due to 13 previous errors +error: aborting due to 15 previous errors diff --git a/src/tools/clippy/tests/ui-toml/disallowed_names_append/disallowed_names.stderr b/src/tools/clippy/tests/ui-toml/disallowed_names_append/disallowed_names.stderr index 23c3e96a8..51cbe1abf 100644 --- a/src/tools/clippy/tests/ui-toml/disallowed_names_append/disallowed_names.stderr +++ b/src/tools/clippy/tests/ui-toml/disallowed_names_append/disallowed_names.stderr @@ -5,6 +5,7 @@ LL | let foo = "bar"; | ^^^ | = note: `-D clippy::disallowed-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]` error: use of a disallowed/placeholder name `ducks` --> $DIR/disallowed_names.rs:7:9 diff --git a/src/tools/clippy/tests/ui-toml/disallowed_names_replace/disallowed_names.stderr b/src/tools/clippy/tests/ui-toml/disallowed_names_replace/disallowed_names.stderr index d961fa340..d9f25a3ee 100644 --- a/src/tools/clippy/tests/ui-toml/disallowed_names_replace/disallowed_names.stderr +++ b/src/tools/clippy/tests/ui-toml/disallowed_names_replace/disallowed_names.stderr @@ -5,6 +5,7 @@ LL | let ducks = ["quack", "quack"]; | ^^^^^ | = note: `-D clippy::disallowed-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui-toml/disallowed_script_idents/clippy.toml b/src/tools/clippy/tests/ui-toml/disallowed_script_idents/clippy.toml new file mode 100644 index 000000000..26cb2d77b --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/disallowed_script_idents/clippy.toml @@ -0,0 +1 @@ +allowed-scripts = ["Cyrillic"] diff --git a/src/tools/clippy/tests/ui-toml/disallowed_script_idents/disallowed_script_idents.rs b/src/tools/clippy/tests/ui-toml/disallowed_script_idents/disallowed_script_idents.rs new file mode 100644 index 000000000..9df1ec6fa --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/disallowed_script_idents/disallowed_script_idents.rs @@ -0,0 +1,6 @@ +#![warn(clippy::disallowed_script_idents)] +fn main() { + let счётчик = 10; + let カウンタ = 10; + //~^ ERROR: identifier `カウンタ` has a Unicode script that is not allowed by configuration +} diff --git a/src/tools/clippy/tests/ui-toml/disallowed_script_idents/disallowed_script_idents.stderr b/src/tools/clippy/tests/ui-toml/disallowed_script_idents/disallowed_script_idents.stderr new file mode 100644 index 000000000..31bb5ee35 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/disallowed_script_idents/disallowed_script_idents.stderr @@ -0,0 +1,11 @@ +error: identifier `カウンタ` has a Unicode script that is not allowed by configuration: Katakana + --> $DIR/disallowed_script_idents.rs:4:9 + | +LL | let カウンタ = 10; + | ^^^^^^^^ + | + = note: `-D clippy::disallowed-script-idents` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_script_idents)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed b/src/tools/clippy/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed new file mode 100644 index 000000000..f16e138da --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/doc_valid_idents_append/doc_markdown.fixed @@ -0,0 +1,12 @@ +#![warn(clippy::doc_markdown)] + +/// This is a special interface for ClipPy which doesn't require backticks +fn allowed_name() {} + +/// OAuth and LaTeX are inside Clippy's default list. +fn default_name() {} + +/// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. +fn unknown_name() {} + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr b/src/tools/clippy/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr index 0f767c9b8..92b035058 100644 --- a/src/tools/clippy/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr +++ b/src/tools/clippy/tests/ui-toml/doc_valid_idents_append/doc_markdown.stderr @@ -5,6 +5,7 @@ LL | /// TestItemThingyOfCoolness might sound cool but is not on the list and sh | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::doc-markdown` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | LL | /// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. diff --git a/src/tools/clippy/tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed b/src/tools/clippy/tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed new file mode 100644 index 000000000..af6ec675e --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/doc_valid_idents_replace/doc_markdown.fixed @@ -0,0 +1,12 @@ +#![warn(clippy::doc_markdown)] + +/// This is a special interface for ClipPy which doesn't require backticks +fn allowed_name() {} + +/// `OAuth` and `LaTeX` are inside Clippy's default list. +fn default_name() {} + +/// `TestItemThingyOfCoolness` might sound cool but is not on the list and should be linted. +fn unknown_name() {} + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr b/src/tools/clippy/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr index e0613eb86..6567b5f12 100644 --- a/src/tools/clippy/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr +++ b/src/tools/clippy/tests/ui-toml/doc_valid_idents_replace/doc_markdown.stderr @@ -5,6 +5,7 @@ LL | /// OAuth and LaTeX are inside Clippy's default list. | ^^^^^ | = note: `-D clippy::doc-markdown` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | LL | /// `OAuth` and LaTeX are inside Clippy's default list. diff --git a/src/tools/clippy/tests/ui-toml/enum_variant_names/clippy.toml b/src/tools/clippy/tests/ui-toml/enum_variant_names/clippy.toml new file mode 100644 index 000000000..0ad7a9799 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/enum_variant_names/clippy.toml @@ -0,0 +1 @@ +enum-variant-name-threshold = 5 diff --git a/src/tools/clippy/tests/ui-toml/enum_variant_names/enum_variant_names.rs b/src/tools/clippy/tests/ui-toml/enum_variant_names/enum_variant_names.rs new file mode 100644 index 000000000..8f4e178cc --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/enum_variant_names/enum_variant_names.rs @@ -0,0 +1,16 @@ +enum Foo { + AFoo, + BFoo, + CFoo, + DFoo, +} +enum Foo2 { + //~^ ERROR: all variants have the same postfix + AFoo, + BFoo, + CFoo, + DFoo, + EFoo, +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/enum_variant_names/enum_variant_names.stderr b/src/tools/clippy/tests/ui-toml/enum_variant_names/enum_variant_names.stderr new file mode 100644 index 000000000..11039b1db --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/enum_variant_names/enum_variant_names.stderr @@ -0,0 +1,18 @@ +error: all variants have the same postfix: `Foo` + --> $DIR/enum_variant_names.rs:7:1 + | +LL | / enum Foo2 { +LL | | +LL | | AFoo, +LL | | BFoo, +... | +LL | | EFoo, +LL | | } + | |_^ + | + = help: remove the postfixes and use full paths to the variants instead of glob imports + = note: `-D clippy::enum-variant-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::enum_variant_names)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/enum_variant_size/clippy.toml b/src/tools/clippy/tests/ui-toml/enum_variant_size/clippy.toml new file mode 100644 index 000000000..64a8017fe --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/enum_variant_size/clippy.toml @@ -0,0 +1 @@ +enum-variant-size-threshold = 500 diff --git a/src/tools/clippy/tests/ui-toml/enum_variant_size/enum_variant_size.fixed b/src/tools/clippy/tests/ui-toml/enum_variant_size/enum_variant_size.fixed new file mode 100644 index 000000000..9ae760ae4 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/enum_variant_size/enum_variant_size.fixed @@ -0,0 +1,11 @@ +enum Fine { + A(()), + B([u8; 500]), +} +enum Bad { + //~^ ERROR: large size difference between variants + A(()), + B(Box<[u8; 501]>), +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/enum_variant_size/enum_variant_size.rs b/src/tools/clippy/tests/ui-toml/enum_variant_size/enum_variant_size.rs new file mode 100644 index 000000000..cf7f432bf --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/enum_variant_size/enum_variant_size.rs @@ -0,0 +1,11 @@ +enum Fine { + A(()), + B([u8; 500]), +} +enum Bad { + //~^ ERROR: large size difference between variants + A(()), + B([u8; 501]), +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/enum_variant_size/enum_variant_size.stderr b/src/tools/clippy/tests/ui-toml/enum_variant_size/enum_variant_size.stderr new file mode 100644 index 000000000..4d9bc9d48 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/enum_variant_size/enum_variant_size.stderr @@ -0,0 +1,21 @@ +error: large size difference between variants + --> $DIR/enum_variant_size.rs:5:1 + | +LL | / enum Bad { +LL | | +LL | | A(()), + | | ----- the second-largest variant contains at least 0 bytes +LL | | B([u8; 501]), + | | ------------ the largest variant contains at least 501 bytes +LL | | } + | |_^ the entire enum is at least 502 bytes + | + = note: `-D clippy::large-enum-variant` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]` +help: consider boxing the large fields to reduce the total size of the enum + | +LL | B(Box<[u8; 501]>), + | ~~~~~~~~~~~~~~ + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/enum_variants_threshold0/clippy.toml b/src/tools/clippy/tests/ui-toml/enum_variants_threshold0/clippy.toml new file mode 100644 index 000000000..f85aade6a --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/enum_variants_threshold0/clippy.toml @@ -0,0 +1 @@ +enum-variant-name-threshold = 0 diff --git a/src/tools/clippy/tests/ui-toml/enum_variants_threshold0/enum_variants_name_threshold.rs b/src/tools/clippy/tests/ui-toml/enum_variants_threshold0/enum_variants_name_threshold.rs new file mode 100644 index 000000000..6918d7528 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/enum_variants_threshold0/enum_variants_name_threshold.rs @@ -0,0 +1,3 @@ +enum Actions {} + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/excessive_nesting/auxiliary/proc_macros.rs b/src/tools/clippy/tests/ui-toml/excessive_nesting/auxiliary/proc_macros.rs deleted file mode 100644 index 60fbaaea3..000000000 --- a/src/tools/clippy/tests/ui-toml/excessive_nesting/auxiliary/proc_macros.rs +++ /dev/null @@ -1,469 +0,0 @@ -// NOTE: Copied from `ui/auxiliary/proc_macros.rs`, couldn't get `../` to work for some reason - -#![feature(let_chains)] -#![feature(proc_macro_span)] -#![allow(clippy::excessive_nesting, dead_code)] - -extern crate proc_macro; - -use core::mem; -use proc_macro::token_stream::IntoIter; -use proc_macro::Delimiter::{self, Brace, Parenthesis}; -use proc_macro::Spacing::{self, Alone, Joint}; -use proc_macro::{Group, Ident, Literal, Punct, Span, TokenStream, TokenTree as TT}; - -type Result = core::result::Result; - -/// Make a `compile_error!` pointing to the given span. -fn make_error(msg: &str, span: Span) -> TokenStream { - TokenStream::from_iter([ - TT::Ident(Ident::new("compile_error", span)), - TT::Punct(punct_with_span('!', Alone, span)), - TT::Group({ - let mut msg = Literal::string(msg); - msg.set_span(span); - group_with_span(Parenthesis, TokenStream::from_iter([TT::Literal(msg)]), span) - }), - ]) -} - -fn expect_tt(tt: Option, f: impl FnOnce(TT) -> Option, expected: &str, span: Span) -> Result { - match tt { - None => Err(make_error( - &format!("unexpected end of input, expected {expected}"), - span, - )), - Some(tt) => { - let span = tt.span(); - match f(tt) { - Some(x) => Ok(x), - None => Err(make_error(&format!("unexpected token, expected {expected}"), span)), - } - }, - } -} - -fn punct_with_span(c: char, spacing: Spacing, span: Span) -> Punct { - let mut p = Punct::new(c, spacing); - p.set_span(span); - p -} - -fn group_with_span(delimiter: Delimiter, stream: TokenStream, span: Span) -> Group { - let mut g = Group::new(delimiter, stream); - g.set_span(span); - g -} - -/// Token used to escape the following token from the macro's span rules. -const ESCAPE_CHAR: char = '$'; - -/// Takes a single token followed by a sequence of tokens. Returns the sequence of tokens with their -/// span set to that of the first token. Tokens may be escaped with either `#ident` or `#(tokens)`. -#[proc_macro] -pub fn with_span(input: TokenStream) -> TokenStream { - let mut iter = input.into_iter(); - let span = iter.next().unwrap().span(); - let mut res = TokenStream::new(); - if let Err(e) = write_with_span(span, iter, &mut res) { - e - } else { - res - } -} - -/// Takes a sequence of tokens and return the tokens with the span set such that they appear to be -/// from an external macro. Tokens may be escaped with either `#ident` or `#(tokens)`. -#[proc_macro] -pub fn external(input: TokenStream) -> TokenStream { - let mut res = TokenStream::new(); - if let Err(e) = write_with_span(Span::mixed_site(), input.into_iter(), &mut res) { - e - } else { - res - } -} - -/// Copies all the tokens, replacing all their spans with the given span. Tokens can be escaped -/// either by `#ident` or `#(tokens)`. -fn write_with_span(s: Span, mut input: IntoIter, out: &mut TokenStream) -> Result<()> { - while let Some(tt) = input.next() { - match tt { - TT::Punct(p) if p.as_char() == ESCAPE_CHAR => { - expect_tt( - input.next(), - |tt| match tt { - tt @ (TT::Ident(_) | TT::Literal(_)) => { - out.extend([tt]); - Some(()) - }, - TT::Punct(mut p) if p.as_char() == ESCAPE_CHAR => { - p.set_span(s); - out.extend([TT::Punct(p)]); - Some(()) - }, - TT::Group(g) if g.delimiter() == Parenthesis => { - out.extend([TT::Group(group_with_span(Delimiter::None, g.stream(), g.span()))]); - Some(()) - }, - _ => None, - }, - "an ident, a literal, or parenthesized tokens", - p.span(), - )?; - }, - TT::Group(g) => { - let mut stream = TokenStream::new(); - write_with_span(s, g.stream().into_iter(), &mut stream)?; - out.extend([TT::Group(group_with_span(g.delimiter(), stream, s))]); - }, - mut tt => { - tt.set_span(s); - out.extend([tt]); - }, - } - } - Ok(()) -} - -/// Within the item this attribute is attached to, an `inline!` macro is available which expands the -/// contained tokens as though they came from a macro expansion. -/// -/// Within the `inline!` macro, any token preceded by `$` is passed as though it were an argument -/// with an automatically chosen fragment specifier. `$ident` will be passed as `ident`, `$1` or -/// `$"literal"` will be passed as `literal`, `$'lt` will be passed as `lifetime`, and `$(...)` will -/// pass the contained tokens as a `tt` sequence (the wrapping parenthesis are removed). If another -/// specifier is required it can be specified within parenthesis like `$(@expr ...)`. This will -/// expand the remaining tokens as a single argument. -/// -/// Multiple `inline!` macros may be nested within each other. This will expand as nested macro -/// calls. However, any arguments will be passed as though they came from the outermost context. -#[proc_macro_attribute] -pub fn inline_macros(args: TokenStream, input: TokenStream) -> TokenStream { - let mut args = args.into_iter(); - let mac_name = match args.next() { - Some(TT::Ident(name)) => Some(name), - Some(tt) => { - return make_error( - "unexpected argument, expected either an ident or no arguments", - tt.span(), - ); - }, - None => None, - }; - if let Some(tt) = args.next() { - return make_error( - "unexpected argument, expected either an ident or no arguments", - tt.span(), - ); - }; - - let mac_name = if let Some(mac_name) = mac_name { - Ident::new(&format!("__inline_mac_{mac_name}"), Span::call_site()) - } else { - let mut input = match LookaheadIter::new(input.clone().into_iter()) { - Some(x) => x, - None => return input, - }; - loop { - match input.next() { - None => break Ident::new("__inline_mac", Span::call_site()), - Some(TT::Ident(kind)) => match &*kind.to_string() { - "impl" => break Ident::new("__inline_mac_impl", Span::call_site()), - kind @ ("struct" | "enum" | "union" | "fn" | "mod" | "trait" | "type" | "const" | "static") => { - if let TT::Ident(name) = &input.tt { - break Ident::new(&format!("__inline_mac_{kind}_{name}"), Span::call_site()); - } else { - break Ident::new(&format!("__inline_mac_{kind}"), Span::call_site()); - } - }, - _ => {}, - }, - _ => {}, - } - } - }; - - let mut expander = Expander::default(); - let mut mac = MacWriter::new(mac_name); - if let Err(e) = expander.expand(input.into_iter(), &mut mac) { - return e; - } - let mut out = TokenStream::new(); - mac.finish(&mut out); - out.extend(expander.expn); - out -} - -/// Wraps a `TokenStream` iterator with a single token lookahead. -struct LookaheadIter { - tt: TT, - iter: IntoIter, -} -impl LookaheadIter { - fn new(mut iter: IntoIter) -> Option { - iter.next().map(|tt| Self { tt, iter }) - } - - /// Get's the lookahead token, replacing it with the next token in the stream. - /// Note: If there isn't a next token, this will not return the lookahead token. - fn next(&mut self) -> Option { - self.iter.next().map(|tt| mem::replace(&mut self.tt, tt)) - } -} - -/// Builds the macro used to implement all the `inline!` macro calls. -struct MacWriter { - name: Ident, - macros: TokenStream, - next_idx: usize, -} -impl MacWriter { - fn new(name: Ident) -> Self { - Self { - name, - macros: TokenStream::new(), - next_idx: 0, - } - } - - /// Inserts a new `inline!` call. - fn insert(&mut self, name_span: Span, bang_span: Span, body: Group, expander: &mut Expander) -> Result<()> { - let idx = self.next_idx; - self.next_idx += 1; - - let mut inner = Expander::for_arm(idx); - inner.expand(body.stream().into_iter(), self)?; - let new_arm = inner.arm.unwrap(); - - self.macros.extend([ - TT::Group(Group::new(Parenthesis, new_arm.args_def)), - TT::Punct(Punct::new('=', Joint)), - TT::Punct(Punct::new('>', Alone)), - TT::Group(Group::new(Parenthesis, inner.expn)), - TT::Punct(Punct::new(';', Alone)), - ]); - - expander.expn.extend([ - TT::Ident({ - let mut name = self.name.clone(); - name.set_span(name_span); - name - }), - TT::Punct(punct_with_span('!', Alone, bang_span)), - ]); - let mut call_body = TokenStream::from_iter([TT::Literal(Literal::usize_unsuffixed(idx))]); - if let Some(arm) = expander.arm.as_mut() { - if !new_arm.args.is_empty() { - arm.add_sub_args(new_arm.args, &mut call_body); - } - } else { - call_body.extend(new_arm.args); - } - let mut g = Group::new(body.delimiter(), call_body); - g.set_span(body.span()); - expander.expn.extend([TT::Group(g)]); - Ok(()) - } - - /// Creates the macro definition. - fn finish(self, out: &mut TokenStream) { - if self.next_idx != 0 { - out.extend([ - TT::Ident(Ident::new("macro_rules", Span::call_site())), - TT::Punct(Punct::new('!', Alone)), - TT::Ident(self.name), - TT::Group(Group::new(Brace, self.macros)), - ]) - } - } -} - -struct MacroArm { - args_def: TokenStream, - args: Vec, -} -impl MacroArm { - fn add_single_arg_def(&mut self, kind: &str, dollar_span: Span, arg_span: Span, out: &mut TokenStream) { - let mut name = Ident::new(&format!("_{}", self.args.len()), Span::call_site()); - self.args_def.extend([ - TT::Punct(Punct::new('$', Alone)), - TT::Ident(name.clone()), - TT::Punct(Punct::new(':', Alone)), - TT::Ident(Ident::new(kind, Span::call_site())), - ]); - name.set_span(arg_span); - out.extend([TT::Punct(punct_with_span('$', Alone, dollar_span)), TT::Ident(name)]); - } - - fn add_parenthesized_arg_def(&mut self, kind: Ident, dollar_span: Span, arg_span: Span, out: &mut TokenStream) { - let mut name = Ident::new(&format!("_{}", self.args.len()), Span::call_site()); - self.args_def.extend([TT::Group(Group::new( - Parenthesis, - TokenStream::from_iter([ - TT::Punct(Punct::new('$', Alone)), - TT::Ident(name.clone()), - TT::Punct(Punct::new(':', Alone)), - TT::Ident(kind), - ]), - ))]); - name.set_span(arg_span); - out.extend([TT::Punct(punct_with_span('$', Alone, dollar_span)), TT::Ident(name)]); - } - - fn add_multi_arg_def(&mut self, dollar_span: Span, arg_span: Span, out: &mut TokenStream) { - let mut name = Ident::new(&format!("_{}", self.args.len()), Span::call_site()); - self.args_def.extend([TT::Group(Group::new( - Parenthesis, - TokenStream::from_iter([ - TT::Punct(Punct::new('$', Alone)), - TT::Group(Group::new( - Parenthesis, - TokenStream::from_iter([ - TT::Punct(Punct::new('$', Alone)), - TT::Ident(name.clone()), - TT::Punct(Punct::new(':', Alone)), - TT::Ident(Ident::new("tt", Span::call_site())), - ]), - )), - TT::Punct(Punct::new('*', Alone)), - ]), - ))]); - name.set_span(arg_span); - out.extend([ - TT::Punct(punct_with_span('$', Alone, dollar_span)), - TT::Group(group_with_span( - Parenthesis, - TokenStream::from_iter([TT::Punct(punct_with_span('$', Alone, dollar_span)), TT::Ident(name)]), - dollar_span, - )), - TT::Punct(punct_with_span('*', Alone, dollar_span)), - ]); - } - - fn add_arg(&mut self, dollar_span: Span, tt: TT, input: &mut IntoIter, out: &mut TokenStream) -> Result<()> { - match tt { - TT::Punct(p) if p.as_char() == ESCAPE_CHAR => out.extend([TT::Punct(p)]), - TT::Punct(p) if p.as_char() == '\'' && p.spacing() == Joint => { - let lt_name = expect_tt( - input.next(), - |tt| match tt { - TT::Ident(x) => Some(x), - _ => None, - }, - "lifetime name", - p.span(), - )?; - let arg_span = p.span().join(lt_name.span()).unwrap_or(p.span()); - self.add_single_arg_def("lifetime", dollar_span, arg_span, out); - self.args.extend([TT::Punct(p), TT::Ident(lt_name)]); - }, - TT::Ident(x) => { - self.add_single_arg_def("ident", dollar_span, x.span(), out); - self.args.push(TT::Ident(x)); - }, - TT::Literal(x) => { - self.add_single_arg_def("literal", dollar_span, x.span(), out); - self.args.push(TT::Literal(x)); - }, - TT::Group(g) if g.delimiter() == Parenthesis => { - let mut inner = g.stream().into_iter(); - if let Some(TT::Punct(p)) = inner.next() - && p.as_char() == '@' - { - let kind = expect_tt( - inner.next(), - |tt| match tt { - TT::Ident(kind) => Some(kind), - _ => None, - }, - "a macro fragment specifier", - p.span(), - )?; - self.add_parenthesized_arg_def(kind, dollar_span, g.span(), out); - self.args.push(TT::Group(group_with_span(Parenthesis, inner.collect(), g.span()))) - } else { - self.add_multi_arg_def(dollar_span, g.span(), out); - self.args.push(TT::Group(g)); - } - }, - tt => return Err(make_error("unsupported escape", tt.span())), - }; - Ok(()) - } - - fn add_sub_args(&mut self, args: Vec, out: &mut TokenStream) { - self.add_multi_arg_def(Span::call_site(), Span::call_site(), out); - self.args - .extend([TT::Group(Group::new(Parenthesis, TokenStream::from_iter(args)))]); - } -} - -#[derive(Default)] -struct Expander { - arm: Option, - expn: TokenStream, -} -impl Expander { - fn for_arm(idx: usize) -> Self { - Self { - arm: Some(MacroArm { - args_def: TokenStream::from_iter([TT::Literal(Literal::usize_unsuffixed(idx))]), - args: Vec::new(), - }), - expn: TokenStream::new(), - } - } - - fn write_tt(&mut self, tt: TT, mac: &mut MacWriter) -> Result<()> { - match tt { - TT::Group(g) => { - let outer = mem::take(&mut self.expn); - self.expand(g.stream().into_iter(), mac)?; - let inner = mem::replace(&mut self.expn, outer); - self.expn - .extend([TT::Group(group_with_span(g.delimiter(), inner, g.span()))]); - }, - tt => self.expn.extend([tt]), - } - Ok(()) - } - - fn expand(&mut self, input: IntoIter, mac: &mut MacWriter) -> Result<()> { - let Some(mut input) = LookaheadIter::new(input) else { - return Ok(()); - }; - while let Some(tt) = input.next() { - if let TT::Punct(p) = &tt - && p.as_char() == ESCAPE_CHAR - && let Some(arm) = self.arm.as_mut() - { - arm.add_arg(p.span(), mem::replace(&mut input.tt, tt), &mut input.iter, &mut self.expn)?; - if input.next().is_none() { - return Ok(()); - } - } else if let TT::Punct(p) = &input.tt - && p.as_char() == '!' - && let TT::Ident(name) = &tt - && name.to_string() == "inline" - { - let g = expect_tt( - input.iter.next(), - |tt| match tt { - TT::Group(g) => Some(g), - _ => None, - }, - "macro arguments", - p.span(), - )?; - mac.insert(name.span(), p.span(), g, self)?; - if input.next().is_none() { - return Ok(()); - } - } else { - self.write_tt(tt, mac)?; - } - } - self.write_tt(input.tt, mac) - } -} diff --git a/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.rs b/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.rs index c28220b97..d737a832d 100644 --- a/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.rs +++ b/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:../../ui/auxiliary/proc_macros.rs #![rustfmt::skip] #![feature(custom_inner_attributes)] #![allow(unused)] @@ -156,7 +156,7 @@ fn main() { for i in {{{{xx}}}} {{{{{{{{}}}}}}}} while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} - + while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} let d = D { d: {{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}} }; diff --git a/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.stderr b/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.stderr index 1a7311b33..74be5b2e2 100644 --- a/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.stderr +++ b/src/tools/clippy/tests/ui-toml/excessive_nesting/excessive_nesting.stderr @@ -6,6 +6,7 @@ LL | let w = { 3 }; | = help: try refactoring your code to minimize nesting = note: `-D clippy::excessive-nesting` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::excessive_nesting)]` error: this block is too nested --> $DIR/excessive_nesting.rs:67:17 diff --git a/src/tools/clippy/tests/ui-toml/expect_used/expect_used.stderr b/src/tools/clippy/tests/ui-toml/expect_used/expect_used.stderr index 815d00935..13b6d7ff9 100644 --- a/src/tools/clippy/tests/ui-toml/expect_used/expect_used.stderr +++ b/src/tools/clippy/tests/ui-toml/expect_used/expect_used.stderr @@ -6,6 +6,7 @@ LL | let _ = opt.expect(""); | = note: if this value is `None`, it will panic = note: `-D clippy::expect-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::expect_used)]` error: used `expect()` on a `Result` value --> $DIR/expect_used.rs:12:13 diff --git a/src/tools/clippy/tests/ui-toml/explicit_iter_loop/clippy.toml b/src/tools/clippy/tests/ui-toml/explicit_iter_loop/clippy.toml new file mode 100644 index 000000000..15d175ef1 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/explicit_iter_loop/clippy.toml @@ -0,0 +1 @@ +enforce-iter-loop-reborrow = true diff --git a/src/tools/clippy/tests/ui-toml/explicit_iter_loop/explicit_iter_loop.fixed b/src/tools/clippy/tests/ui-toml/explicit_iter_loop/explicit_iter_loop.fixed new file mode 100644 index 000000000..468da22a9 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/explicit_iter_loop/explicit_iter_loop.fixed @@ -0,0 +1,10 @@ +#![warn(clippy::explicit_iter_loop)] + +fn main() { + let mut vec = vec![1, 2, 3]; + let rmvec = &mut vec; + for _ in &*rmvec {} + //~^ ERROR: it is more concise to loop over references to containers + for _ in &mut *rmvec {} + //~^ ERROR: it is more concise to loop over references to containers +} diff --git a/src/tools/clippy/tests/ui-toml/explicit_iter_loop/explicit_iter_loop.rs b/src/tools/clippy/tests/ui-toml/explicit_iter_loop/explicit_iter_loop.rs new file mode 100644 index 000000000..a93464860 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/explicit_iter_loop/explicit_iter_loop.rs @@ -0,0 +1,10 @@ +#![warn(clippy::explicit_iter_loop)] + +fn main() { + let mut vec = vec![1, 2, 3]; + let rmvec = &mut vec; + for _ in rmvec.iter() {} + //~^ ERROR: it is more concise to loop over references to containers + for _ in rmvec.iter_mut() {} + //~^ ERROR: it is more concise to loop over references to containers +} diff --git a/src/tools/clippy/tests/ui-toml/explicit_iter_loop/explicit_iter_loop.stderr b/src/tools/clippy/tests/ui-toml/explicit_iter_loop/explicit_iter_loop.stderr new file mode 100644 index 000000000..587d4f9b3 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/explicit_iter_loop/explicit_iter_loop.stderr @@ -0,0 +1,17 @@ +error: it is more concise to loop over references to containers instead of using explicit iteration methods + --> $DIR/explicit_iter_loop.rs:6:14 + | +LL | for _ in rmvec.iter() {} + | ^^^^^^^^^^^^ help: to write this more concisely, try: `&*rmvec` + | + = note: `-D clippy::explicit-iter-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::explicit_iter_loop)]` + +error: it is more concise to loop over references to containers instead of using explicit iteration methods + --> $DIR/explicit_iter_loop.rs:8:14 + | +LL | for _ in rmvec.iter_mut() {} + | ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut *rmvec` + +error: aborting due to 2 previous errors + diff --git a/src/tools/clippy/tests/ui-toml/fn_params_excessive_bools/test.stderr b/src/tools/clippy/tests/ui-toml/fn_params_excessive_bools/test.stderr index 87bdb61c6..717a4bbfb 100644 --- a/src/tools/clippy/tests/ui-toml/fn_params_excessive_bools/test.stderr +++ b/src/tools/clippy/tests/ui-toml/fn_params_excessive_bools/test.stderr @@ -6,6 +6,7 @@ LL | fn g(_: bool, _: bool) {} | = help: consider refactoring bools into two-variant enums = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::fn_params_excessive_bools)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui-toml/functions_maxlines/test.stderr b/src/tools/clippy/tests/ui-toml/functions_maxlines/test.stderr index dc255bdca..a2ca623e9 100644 --- a/src/tools/clippy/tests/ui-toml/functions_maxlines/test.stderr +++ b/src/tools/clippy/tests/ui-toml/functions_maxlines/test.stderr @@ -8,6 +8,7 @@ LL | | } | |_^ | = note: `-D clippy::too-many-lines` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::too_many_lines)]` error: this function has too many lines (4/1) --> $DIR/test.rs:25:1 diff --git a/src/tools/clippy/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr b/src/tools/clippy/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr index 2841f62bc..305e00af2 100644 --- a/src/tools/clippy/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr +++ b/src/tools/clippy/tests/ui-toml/ifs_same_cond/ifs_same_cond.stderr @@ -10,6 +10,7 @@ note: same as this LL | if x.get() { | ^^^^^^^ = note: `-D clippy::ifs-same-cond` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ifs_same_cond)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui-toml/large_futures/large_futures.fixed b/src/tools/clippy/tests/ui-toml/large_futures/large_futures.fixed new file mode 100644 index 000000000..7dea9fb95 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/large_futures/large_futures.fixed @@ -0,0 +1,27 @@ +#![warn(clippy::large_futures)] + +fn main() {} + +pub async fn should_warn() { + let x = [0u8; 1024]; + async {}.await; + dbg!(x); +} + +pub async fn should_not_warn() { + let x = [0u8; 1020]; + async {}.await; + dbg!(x); +} + +pub async fn bar() { + Box::pin(should_warn()).await; + + async { + let x = [0u8; 1024]; + dbg!(x); + } + .await; + + should_not_warn().await; +} diff --git a/src/tools/clippy/tests/ui-toml/large_futures/large_futures.stderr b/src/tools/clippy/tests/ui-toml/large_futures/large_futures.stderr index b92734de2..7a02fcdbd 100644 --- a/src/tools/clippy/tests/ui-toml/large_futures/large_futures.stderr +++ b/src/tools/clippy/tests/ui-toml/large_futures/large_futures.stderr @@ -5,6 +5,7 @@ LL | should_warn().await; | ^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(should_warn())` | = note: `-D clippy::large-futures` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_futures)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.stderr b/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.stderr index 7b5fb9e87..7508cd6c4 100644 --- a/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.stderr +++ b/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.stderr @@ -6,6 +6,7 @@ LL | const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = 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` + = help: to override `-D warnings` add `#[allow(clippy::large_include_file)]` = 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 diff --git a/src/tools/clippy/tests/ui-toml/large_stack_frames/clippy.toml b/src/tools/clippy/tests/ui-toml/large_stack_frames/clippy.toml new file mode 100644 index 000000000..584335dc2 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/large_stack_frames/clippy.toml @@ -0,0 +1 @@ +stack-size-threshold = 1000 diff --git a/src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.rs b/src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.rs new file mode 100644 index 000000000..39798ffea --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.rs @@ -0,0 +1,17 @@ +#![warn(clippy::large_stack_frames)] + +// We use this helper function instead of writing [0; 4294967297] directly to represent a +// case that large_stack_arrays can't catch +fn create_array() -> [u8; N] { + [0; N] +} + +fn f() { + let _x = create_array::<1000>(); +} +fn f2() { + //~^ ERROR: this function allocates a large amount of stack space + let _x = create_array::<1001>(); +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.stderr b/src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.stderr new file mode 100644 index 000000000..67ee57ab6 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/large_stack_frames/large_stack_frames.stderr @@ -0,0 +1,15 @@ +error: this function allocates a large amount of stack space + --> $DIR/large_stack_frames.rs:12:1 + | +LL | / fn f2() { +LL | | +LL | | let _x = create_array::<1001>(); +LL | | } + | |_^ + | + = note: allocating large amounts of stack space can overflow the stack + = note: `-D clippy::large-stack-frames` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_stack_frames)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/large_types_passed_by_value/clippy.toml b/src/tools/clippy/tests/ui-toml/large_types_passed_by_value/clippy.toml new file mode 100644 index 000000000..45bcbce1e --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/large_types_passed_by_value/clippy.toml @@ -0,0 +1 @@ +pass-by-value-size-limit = 512 diff --git a/src/tools/clippy/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.fixed b/src/tools/clippy/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.fixed new file mode 100644 index 000000000..3c87c79cf --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.fixed @@ -0,0 +1,7 @@ +#![warn(clippy::large_types_passed_by_value)] + +fn f(_v: [u8; 512]) {} +fn f2(_v: &[u8; 513]) {} +//~^ ERROR: this argument (513 byte) is passed by value + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.rs b/src/tools/clippy/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.rs new file mode 100644 index 000000000..0572373a6 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.rs @@ -0,0 +1,7 @@ +#![warn(clippy::large_types_passed_by_value)] + +fn f(_v: [u8; 512]) {} +fn f2(_v: [u8; 513]) {} +//~^ ERROR: this argument (513 byte) is passed by value + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.stderr b/src/tools/clippy/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.stderr new file mode 100644 index 000000000..6678a2b47 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/large_types_passed_by_value/large_types_passed_by_value.stderr @@ -0,0 +1,11 @@ +error: this argument (513 byte) is passed by value, but might be more efficient if passed by reference (limit: 512 byte) + --> $DIR/large_types_passed_by_value.rs:4:11 + | +LL | fn f2(_v: [u8; 513]) {} + | ^^^^^^^^^ help: consider passing by reference instead: `&[u8; 513]` + | + = note: `-D clippy::large-types-passed-by-value` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_types_passed_by_value)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/lint_decimal_readability/test.fixed b/src/tools/clippy/tests/ui-toml/lint_decimal_readability/test.fixed new file mode 100644 index 000000000..f013153f5 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/lint_decimal_readability/test.fixed @@ -0,0 +1,23 @@ +#![allow(clippy::excessive_precision)] +#![warn(clippy::unreadable_literal)] + +fn allow_inconsistent_digit_grouping() { + #![allow(clippy::inconsistent_digit_grouping)] + let _pass1 = 100_200_300.123456789; +} + +fn main() { + allow_inconsistent_digit_grouping(); + + let _pass1 = 100_200_300.100_200_300; + let _pass2 = 1.123456789; + let _pass3 = 1.0; + let _pass4 = 10000.00001; + let _pass5 = 1.123456789e1; + + // due to clippy::inconsistent-digit-grouping + let _fail1 = 100_200_300.123_456_789; + + // fail due to the integer part + let _fail2 = 100_200_300.300_200_100; +} diff --git a/src/tools/clippy/tests/ui-toml/lint_decimal_readability/test.stderr b/src/tools/clippy/tests/ui-toml/lint_decimal_readability/test.stderr index ac9d89d0c..ef97e5d3f 100644 --- a/src/tools/clippy/tests/ui-toml/lint_decimal_readability/test.stderr +++ b/src/tools/clippy/tests/ui-toml/lint_decimal_readability/test.stderr @@ -5,6 +5,7 @@ LL | let _fail1 = 100_200_300.123456789; | ^^^^^^^^^^^^^^^^^^^^^ help: consider: `100_200_300.123_456_789` | = note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inconsistent_digit_grouping)]` error: long literal lacking separators --> $DIR/test.rs:22:18 @@ -13,6 +14,7 @@ LL | let _fail2 = 100200300.300200100; | ^^^^^^^^^^^^^^^^^^^ help: consider: `100_200_300.300_200_100` | = note: `-D clippy::unreadable-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unreadable_literal)]` error: aborting due to 2 previous errors diff --git a/src/tools/clippy/tests/ui-toml/manual_let_else/clippy.toml b/src/tools/clippy/tests/ui-toml/manual_let_else/clippy.toml new file mode 100644 index 000000000..cdae1da01 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/manual_let_else/clippy.toml @@ -0,0 +1 @@ +matches-for-let-else = "AllTypes" diff --git a/src/tools/clippy/tests/ui-toml/manual_let_else/manual_let_else.fixed b/src/tools/clippy/tests/ui-toml/manual_let_else/manual_let_else.fixed new file mode 100644 index 000000000..972f6aa40 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/manual_let_else/manual_let_else.fixed @@ -0,0 +1,10 @@ +#![warn(clippy::manual_let_else)] + +enum Foo { + A(u8), + B, +} + +fn main() { + let Foo::A(x) = Foo::A(1) else { return }; +} diff --git a/src/tools/clippy/tests/ui-toml/manual_let_else/manual_let_else.rs b/src/tools/clippy/tests/ui-toml/manual_let_else/manual_let_else.rs new file mode 100644 index 000000000..fdaba4ad2 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/manual_let_else/manual_let_else.rs @@ -0,0 +1,14 @@ +#![warn(clippy::manual_let_else)] + +enum Foo { + A(u8), + B, +} + +fn main() { + let x = match Foo::A(1) { + //~^ ERROR: this could be rewritten as `let...else` + Foo::A(x) => x, + Foo::B => return, + }; +} diff --git a/src/tools/clippy/tests/ui-toml/manual_let_else/manual_let_else.stderr b/src/tools/clippy/tests/ui-toml/manual_let_else/manual_let_else.stderr new file mode 100644 index 000000000..5c2c86c37 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/manual_let_else/manual_let_else.stderr @@ -0,0 +1,15 @@ +error: this could be rewritten as `let...else` + --> $DIR/manual_let_else.rs:9:5 + | +LL | / let x = match Foo::A(1) { +LL | | +LL | | Foo::A(x) => x, +LL | | Foo::B => return, +LL | | }; + | |______^ help: consider writing: `let Foo::A(x) = Foo::A(1) else { return };` + | + = note: `-D clippy::manual-let-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.fixed b/src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.fixed new file mode 100644 index 000000000..36540bf1d --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.fixed @@ -0,0 +1,24 @@ +#![deny(clippy::index_refutable_slice)] + +fn below_limit() { + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some([_, _, _, _, _, _, _, slice_7, ..]) = slice { + //~^ ERROR: binding can be a slice pattern + // This would usually not be linted but is included now due to the + // index limit in the config file + println!("{}", slice_7); + } +} + +fn above_limit() { + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some(slice) = slice { + // This will not be linted as 8 is above the limit + println!("{}", slice[8]); + } +} + +fn main() { + below_limit(); + above_limit(); +} diff --git a/src/tools/clippy/tests/ui-toml/min_ident_chars/min_ident_chars.stderr b/src/tools/clippy/tests/ui-toml/min_ident_chars/min_ident_chars.stderr index d9a27628d..7f00fac49 100644 --- a/src/tools/clippy/tests/ui-toml/min_ident_chars/min_ident_chars.stderr +++ b/src/tools/clippy/tests/ui-toml/min_ident_chars/min_ident_chars.stderr @@ -5,6 +5,7 @@ LL | use extern_types::Aaa; | ^^^ | = note: `-D clippy::min-ident-chars` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::min_ident_chars)]` error: this ident is too short (3 <= 3) --> $DIR/min_ident_chars.rs:10:5 diff --git a/src/tools/clippy/tests/ui-toml/min_rust_version/min_rust_version.fixed b/src/tools/clippy/tests/ui-toml/min_rust_version/min_rust_version.fixed new file mode 100644 index 000000000..6c58e07d8 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/min_rust_version/min_rust_version.fixed @@ -0,0 +1,98 @@ +#![allow(clippy::redundant_clone, clippy::unnecessary_operation)] +#![warn(clippy::manual_non_exhaustive, clippy::borrow_as_ptr, clippy::manual_bits)] + +use std::mem::{size_of, size_of_val}; +use std::ops::Deref; + +mod enums { + enum E { + A, + B, + #[doc(hidden)] + _C, + } + + // user forgot to remove the marker + #[non_exhaustive] + enum Ep { + A, + B, + #[doc(hidden)] + _C, + } +} + +fn option_as_ref_deref() { + let mut opt = Some(String::from("123")); + + let _ = opt.as_ref().map(String::as_str); + let _ = opt.as_ref().map(|x| x.as_str()); + let _ = opt.as_mut().map(String::as_mut_str); + let _ = opt.as_mut().map(|x| x.as_mut_str()); +} + +fn match_like_matches() { + let _y = match Some(5) { + Some(0) => true, + _ => false, + }; +} + +fn match_same_arms() { + match (1, 2, 3) { + (1, .., 3) => 42, + (.., 3) => 42, + _ => 0, + }; +} + +fn match_same_arms2() { + let _ = match Some(42) { + Some(_) => 24, + None => 24, + }; +} + +fn manual_strip_msrv() { + let s = "hello, world!"; + if s.starts_with("hello, ") { + assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!"); + } +} + +fn check_index_refutable_slice() { + // This shouldn't trigger `clippy::index_refutable_slice` as the suggestion + // would only be valid from 1.42.0 onward + let slice: Option<&[u32]> = Some(&[1]); + if let Some(slice) = slice { + println!("{}", slice[0]); + } +} + +fn map_clone_suggest_copied() { + // This should still trigger the lint but suggest `cloned()` instead of `copied()` + let _: Option = Some(&16).cloned(); +} + +fn borrow_as_ptr() { + let val = 1; + let _p = &val as *const i32; + + let mut val_mut = 1; + let _p_mut = &mut val_mut as *mut i32; +} + +fn manual_bits() { + size_of::() * 8; + size_of_val(&0u32) * 8; +} + +fn main() { + option_as_ref_deref(); + match_like_matches(); + match_same_arms(); + match_same_arms2(); + manual_strip_msrv(); + check_index_refutable_slice(); + borrow_as_ptr(); +} diff --git a/src/tools/clippy/tests/ui-toml/min_rust_version/min_rust_version.stderr b/src/tools/clippy/tests/ui-toml/min_rust_version/min_rust_version.stderr index 5dae5af7e..5b1f8dbd3 100644 --- a/src/tools/clippy/tests/ui-toml/min_rust_version/min_rust_version.stderr +++ b/src/tools/clippy/tests/ui-toml/min_rust_version/min_rust_version.stderr @@ -5,6 +5,7 @@ LL | let _: Option = Some(&16).map(|b| *b); | ^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `Some(&16).cloned()` | = note: `-D clippy::map-clone` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_clone)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.fixed b/src/tools/clippy/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.fixed new file mode 100644 index 000000000..5f4f007cf --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.fixed @@ -0,0 +1,16 @@ +#![warn(clippy::missing_enforced_import_renames)] + +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; +#[rustfmt::skip] +use std::{ + any::{type_name as ident, Any}, + clone as foo, + sync :: Mutex as StdMutie, +}; + +fn main() { + use std::collections::BTreeMap as Map; +} diff --git a/src/tools/clippy/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr b/src/tools/clippy/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr index 45de8fdff..0aea330d4 100644 --- a/src/tools/clippy/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr +++ b/src/tools/clippy/tests/ui-toml/missing_enforced_import_rename/conf_missing_enforced_import_rename.stderr @@ -5,6 +5,7 @@ LL | use std::process::{exit as wrong_exit, Child as Kid}; | ^^^^^^^^^^^^^^^^^^ help: try: `exit as goodbye` | = note: `-D clippy::missing-enforced-import-renames` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_enforced_import_renames)]` error: this import should be renamed --> $DIR/conf_missing_enforced_import_rename.rs:6:1 diff --git a/src/tools/clippy/tests/ui-toml/module_inception/module_inception.stderr b/src/tools/clippy/tests/ui-toml/module_inception/module_inception.stderr index a5a09c322..0eb25453b 100644 --- a/src/tools/clippy/tests/ui-toml/module_inception/module_inception.stderr +++ b/src/tools/clippy/tests/ui-toml/module_inception/module_inception.stderr @@ -7,6 +7,7 @@ LL | | } | |_________^ | = note: `-D clippy::module-inception` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::module_inception)]` error: module has the same name as its containing module --> $DIR/module_inception.rs:11:5 diff --git a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed index 054db5d93..673106f0b 100644 --- a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed +++ b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed @@ -1,5 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro -//@run-rustfix +//@aux-build:proc_macro_derive.rs #![warn(clippy::nonstandard_macro_braces)] diff --git a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs index 95d1a2297..b9c69037b 100644 --- a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs +++ b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs @@ -1,5 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro -//@run-rustfix +//@aux-build:proc_macro_derive.rs #![warn(clippy::nonstandard_macro_braces)] diff --git a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr index 7ae381597..483941d3c 100644 --- a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr +++ b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr @@ -1,37 +1,38 @@ error: use of irregular braces for `vec!` macro - --> $DIR/conf_nonstandard_macro_braces.rs:44:13 + --> $DIR/conf_nonstandard_macro_braces.rs:43:13 | LL | let _ = vec! {1, 2, 3}; | ^^^^^^^^^^^^^^ help: consider writing: `vec![1, 2, 3]` | = note: `-D clippy::nonstandard-macro-braces` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::nonstandard_macro_braces)]` error: use of irregular braces for `format!` macro - --> $DIR/conf_nonstandard_macro_braces.rs:45:13 + --> $DIR/conf_nonstandard_macro_braces.rs:44:13 | 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/conf_nonstandard_macro_braces.rs:46:13 + --> $DIR/conf_nonstandard_macro_braces.rs:45:13 | LL | let _ = matches!{{}, ()}; | ^^^^^^^^^^^^^^^^ help: consider writing: `matches!({}, ())` error: use of irregular braces for `quote!` macro - --> $DIR/conf_nonstandard_macro_braces.rs:47:13 + --> $DIR/conf_nonstandard_macro_braces.rs:46:13 | LL | let _ = quote!(let x = 1;); | ^^^^^^^^^^^^^^^^^^ help: consider writing: `quote!{let x = 1;}` error: use of irregular braces for `quote::quote!` macro - --> $DIR/conf_nonstandard_macro_braces.rs:48:13 + --> $DIR/conf_nonstandard_macro_braces.rs:47:13 | LL | let _ = quote::quote!(match match match); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `quote::quote!{match match match}` error: use of irregular braces for `vec!` macro - --> $DIR/conf_nonstandard_macro_braces.rs:19:9 + --> $DIR/conf_nonstandard_macro_braces.rs:18:9 | LL | vec!{0, 0, 0} | ^^^^^^^^^^^^^ help: consider writing: `vec![0, 0, 0]` @@ -42,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/conf_nonstandard_macro_braces.rs:57:12 + --> $DIR/conf_nonstandard_macro_braces.rs:56:12 | LL | let _: type_pos!(usize) = vec![]; | ^^^^^^^^^^^^^^^^ help: consider writing: `type_pos![usize]` error: use of irregular braces for `eprint!` macro - --> $DIR/conf_nonstandard_macro_braces.rs:59:5 + --> $DIR/conf_nonstandard_macro_braces.rs:58:5 | LL | eprint!("test if user config overrides defaults"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `eprint!["test if user config overrides defaults"]` diff --git a/src/tools/clippy/tests/ui-toml/path_ends_with_ext/clippy.toml b/src/tools/clippy/tests/ui-toml/path_ends_with_ext/clippy.toml new file mode 100644 index 000000000..40d7dfd93 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/path_ends_with_ext/clippy.toml @@ -0,0 +1 @@ +allowed-dotfiles = ["dot"] diff --git a/src/tools/clippy/tests/ui-toml/path_ends_with_ext/path_ends_with_ext.rs b/src/tools/clippy/tests/ui-toml/path_ends_with_ext/path_ends_with_ext.rs new file mode 100644 index 000000000..a34b15f4a --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/path_ends_with_ext/path_ends_with_ext.rs @@ -0,0 +1,9 @@ +#![warn(clippy::path_ends_with_ext)] + +use std::path::Path; + +fn f(p: &Path) { + p.ends_with(".dot"); +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/print_macro/print_macro.stderr b/src/tools/clippy/tests/ui-toml/print_macro/print_macro.stderr index d4b1ae84f..fe2d5afc6 100644 --- a/src/tools/clippy/tests/ui-toml/print_macro/print_macro.stderr +++ b/src/tools/clippy/tests/ui-toml/print_macro/print_macro.stderr @@ -5,6 +5,7 @@ LL | print!("{n}"); | ^^^^^^^^^^^^^ | = note: `-D clippy::print-stdout` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_stdout)]` error: use of `eprint!` --> $DIR/print_macro.rs:7:5 @@ -13,6 +14,7 @@ LL | eprint!("{n}"); | ^^^^^^^^^^^^^^ | = note: `-D clippy::print-stderr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_stderr)]` error: aborting due to 2 previous errors diff --git a/src/tools/clippy/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr b/src/tools/clippy/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr index a47418705..1ecdabbc0 100644 --- a/src/tools/clippy/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr +++ b/src/tools/clippy/tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.stderr @@ -5,6 +5,7 @@ LL | pub(crate) fn crate_no_docs() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]` error: missing documentation for a function --> $DIR/pub_crate_missing_doc.rs:15:5 diff --git a/src/tools/clippy/tests/ui-toml/result_large_err/clippy.toml b/src/tools/clippy/tests/ui-toml/result_large_err/clippy.toml new file mode 100644 index 000000000..df505ed96 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/result_large_err/clippy.toml @@ -0,0 +1 @@ +large-error-threshold = 512 diff --git a/src/tools/clippy/tests/ui-toml/result_large_err/result_large_err.rs b/src/tools/clippy/tests/ui-toml/result_large_err/result_large_err.rs new file mode 100644 index 000000000..dea4d61a9 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/result_large_err/result_large_err.rs @@ -0,0 +1,10 @@ +#![warn(clippy::result_large_err)] + +fn f() -> Result<(), [u8; 511]> { + todo!() +} +fn f2() -> Result<(), [u8; 512]> { + //~^ ERROR: the `Err`-variant returned from this function is very large + todo!() +} +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/result_large_err/result_large_err.stderr b/src/tools/clippy/tests/ui-toml/result_large_err/result_large_err.stderr new file mode 100644 index 000000000..b0936319d --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/result_large_err/result_large_err.stderr @@ -0,0 +1,12 @@ +error: the `Err`-variant returned from this function is very large + --> $DIR/result_large_err.rs:6:12 + | +LL | fn f2() -> Result<(), [u8; 512]> { + | ^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes + | + = help: try reducing the size of `[u8; 512]`, for example by boxing large elements or replacing it with `Box<[u8; 512]>` + = note: `-D clippy::result-large-err` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_large_err)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/both.fixed b/src/tools/clippy/tests/ui-toml/semicolon_block/both.fixed index fc8038a09..306cd23c8 100644 --- a/src/tools/clippy/tests/ui-toml/semicolon_block/both.fixed +++ b/src/tools/clippy/tests/ui-toml/semicolon_block/both.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/both.rs b/src/tools/clippy/tests/ui-toml/semicolon_block/both.rs index 52ce1f038..b9f012cfb 100644 --- a/src/tools/clippy/tests/ui-toml/semicolon_block/both.rs +++ b/src/tools/clippy/tests/ui-toml/semicolon_block/both.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/both.stderr b/src/tools/clippy/tests/ui-toml/semicolon_block/both.stderr index 2f58842ea..ca6a7475c 100644 --- a/src/tools/clippy/tests/ui-toml/semicolon_block/both.stderr +++ b/src/tools/clippy/tests/ui-toml/semicolon_block/both.stderr @@ -1,10 +1,11 @@ error: consider moving the `;` outside the block for consistent formatting - --> $DIR/both.rs:43:5 + --> $DIR/both.rs:42:5 | LL | { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::semicolon-outside-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::semicolon_outside_block)]` help: put the `;` here | LL - { unit_fn_block(); } @@ -12,7 +13,7 @@ LL + { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/both.rs:44:5 + --> $DIR/both.rs:43:5 | LL | unsafe { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL + unsafe { unit_fn_block() }; | error: consider moving the `;` inside the block for consistent formatting - --> $DIR/both.rs:49:5 + --> $DIR/both.rs:48:5 | LL | / { LL | | unit_fn_block(); @@ -33,6 +34,7 @@ LL | | }; | |______^ | = note: `-D clippy::semicolon-inside-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::semicolon_inside_block)]` help: put the `;` here | LL ~ unit_fn_block(); @@ -40,7 +42,7 @@ LL ~ } | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/both.rs:63:5 + --> $DIR/both.rs:62:5 | LL | { m!(()); } | ^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed index 23df98301..5b7f8e00c 100644 --- a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed +++ b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.rs b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.rs index e8516f79b..3a81661cd 100644 --- a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.rs +++ b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr index 2569dc4b4..ce03d7d75 100644 --- a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr +++ b/src/tools/clippy/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_inside_block.rs:48:5 + --> $DIR/semicolon_inside_block.rs:47:5 | LL | / { LL | | unit_fn_block(); @@ -8,6 +8,7 @@ LL | | }; | |______^ | = note: `-D clippy::semicolon-inside-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::semicolon_inside_block)]` help: put the `;` here | LL ~ unit_fn_block(); diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed index 7e9055e71..14604eaea 100644 --- a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed +++ b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.rs b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.rs index 4dc956d8a..c76720146 100644 --- a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.rs +++ b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr index 6dd3577dd..fcc409796 100644 --- a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr +++ b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr @@ -1,10 +1,11 @@ error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:42:5 + --> $DIR/semicolon_outside_block.rs:41:5 | LL | { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::semicolon-outside-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::semicolon_outside_block)]` help: put the `;` here | LL - { unit_fn_block(); } @@ -12,7 +13,7 @@ LL + { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:43:5 + --> $DIR/semicolon_outside_block.rs:42:5 | LL | unsafe { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL + unsafe { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:62:5 + --> $DIR/semicolon_outside_block.rs:61:5 | LL | { m!(()); } | ^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr b/src/tools/clippy/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr index c72f8c648..6df11cc1f 100644 --- a/src/tools/clippy/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr +++ b/src/tools/clippy/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr @@ -11,6 +11,7 @@ LL | rc_is_not_send: Rc, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::non_send_fields_in_send_ty)]` error: some fields in `MultiField` are not safe to be sent to another thread --> $DIR/test.rs:19:1 diff --git a/src/tools/clippy/tests/ui-toml/struct_excessive_bools/test.stderr b/src/tools/clippy/tests/ui-toml/struct_excessive_bools/test.stderr index 4e7c70d18..9237c9c9d 100644 --- a/src/tools/clippy/tests/ui-toml/struct_excessive_bools/test.stderr +++ b/src/tools/clippy/tests/ui-toml/struct_excessive_bools/test.stderr @@ -8,6 +8,7 @@ LL | | } | = help: consider using a state machine or refactoring bools into two-variant enums = note: `-D clippy::struct-excessive-bools` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::struct_excessive_bools)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui-toml/suppress_lint_in_const/test.stderr b/src/tools/clippy/tests/ui-toml/suppress_lint_in_const/test.stderr index 14e131944..f8ace7995 100644 --- a/src/tools/clippy/tests/ui-toml/suppress_lint_in_const/test.stderr +++ b/src/tools/clippy/tests/ui-toml/suppress_lint_in_const/test.stderr @@ -4,7 +4,7 @@ error[E0080]: evaluation of `main::{constant#3}` failed LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 -note: erroneous constant used +note: erroneous constant encountered --> $DIR/test.rs:37:5 | LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. @@ -18,6 +18,7 @@ LL | x[index]; | = help: consider using `.get(n)` or `.get_mut(n)` instead = note: `-D clippy::indexing-slicing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` error: indexing may panic --> $DIR/test.rs:46:5 diff --git a/src/tools/clippy/tests/ui-toml/toml_disallow/conf_french_disallowed_name.stderr b/src/tools/clippy/tests/ui-toml/toml_disallow/conf_french_disallowed_name.stderr index 9082c1c54..621328292 100644 --- a/src/tools/clippy/tests/ui-toml/toml_disallow/conf_french_disallowed_name.stderr +++ b/src/tools/clippy/tests/ui-toml/toml_disallow/conf_french_disallowed_name.stderr @@ -5,6 +5,7 @@ LL | fn test(toto: ()) {} | ^^^^ | = note: `-D clippy::disallowed-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]` error: use of a disallowed/placeholder name `toto` --> $DIR/conf_french_disallowed_name.rs:9:9 diff --git a/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr index fc137c225..d9b70e3b7 100644 --- a/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr +++ b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr @@ -5,6 +5,7 @@ LL | let re = Regex::new(r"ab.*c").unwrap(); | ^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::disallowed-methods` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]` error: use of a disallowed method `regex::Regex::is_match` --> $DIR/conf_disallowed_methods.rs:36:5 diff --git a/src/tools/clippy/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr b/src/tools/clippy/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr index e3ece799c..4ac96deb4 100644 --- a/src/tools/clippy/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr +++ b/src/tools/clippy/tests/ui-toml/toml_disallowed_types/conf_disallowed_types.stderr @@ -5,6 +5,7 @@ LL | use std::sync::atomic::AtomicU32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::disallowed-types` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_types)]` error: `std::time::Instant` is not allowed according to config --> $DIR/conf_disallowed_types.rs:8:1 diff --git a/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.rs b/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.rs index 78784bfff..145a2ce44 100644 --- a/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.rs +++ b/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.rs @@ -1,6 +1,6 @@ //@normalize-stderr-test: "\(\d+ byte\)" -> "(N byte)" //@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)" - +//@no-rustfix #![warn(clippy::trivially_copy_pass_by_ref)] #![allow(clippy::needless_pass_by_ref_mut)] diff --git a/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.stderr b/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.stderr index db5d68053..262d302e7 100644 --- a/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.stderr +++ b/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.stderr @@ -5,6 +5,7 @@ LL | fn bad(x: &u16, y: &Foo) {} | ^^^^ help: consider passing by value instead: `u16` | = note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::trivially_copy_pass_by_ref)]` error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) --> $DIR/test.rs:15:20 diff --git a/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr index cdabe6460..4bed5c149 100644 --- a/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr +++ b/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr @@ -10,6 +10,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect allow-print-in-tests allow-private-module-inception allow-unwrap-in-tests + allowed-dotfiles allowed-idents-below-min-chars allowed-scripts arithmetic-side-effects-allowed @@ -28,6 +29,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect disallowed-types doc-valid-idents enable-raw-pointer-heuristic-for-send + enforce-iter-loop-reborrow enforced-import-renames enum-variant-name-threshold enum-variant-size-threshold @@ -81,6 +83,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect allow-print-in-tests allow-private-module-inception allow-unwrap-in-tests + allowed-dotfiles allowed-idents-below-min-chars allowed-scripts arithmetic-side-effects-allowed @@ -99,6 +102,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect disallowed-types doc-valid-idents enable-raw-pointer-heuristic-for-send + enforce-iter-loop-reborrow enforced-import-renames enum-variant-name-threshold enum-variant-size-threshold diff --git a/src/tools/clippy/tests/ui-toml/too_large_for_stack/boxed_local.rs b/src/tools/clippy/tests/ui-toml/too_large_for_stack/boxed_local.rs new file mode 100644 index 000000000..2f0236122 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/too_large_for_stack/boxed_local.rs @@ -0,0 +1,5 @@ +fn f(x: Box<[u8; 500]>) {} +//~^ ERROR: local variable doesn't need to be boxed here +fn f2(x: Box<[u8; 501]>) {} + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/too_large_for_stack/boxed_local.stderr b/src/tools/clippy/tests/ui-toml/too_large_for_stack/boxed_local.stderr new file mode 100644 index 000000000..2859a29f1 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/too_large_for_stack/boxed_local.stderr @@ -0,0 +1,11 @@ +error: local variable doesn't need to be boxed here + --> $DIR/boxed_local.rs:1:6 + | +LL | fn f(x: Box<[u8; 500]>) {} + | ^ + | + = note: `-D clippy::boxed-local` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::boxed_local)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/too_large_for_stack/clippy.toml b/src/tools/clippy/tests/ui-toml/too_large_for_stack/clippy.toml new file mode 100644 index 000000000..a9c42fca4 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/too_large_for_stack/clippy.toml @@ -0,0 +1 @@ +too-large-for-stack = 500 diff --git a/src/tools/clippy/tests/ui-toml/too_large_for_stack/useless_vec.fixed b/src/tools/clippy/tests/ui-toml/too_large_for_stack/useless_vec.fixed new file mode 100644 index 000000000..ebe92d9b5 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/too_large_for_stack/useless_vec.fixed @@ -0,0 +1,9 @@ +#![warn(clippy::useless_vec)] + +fn main() { + let x = [0u8; 500]; + //~^ ERROR: useless use of `vec!` + x.contains(&1); + let y = vec![0u8; 501]; + y.contains(&1); +} diff --git a/src/tools/clippy/tests/ui-toml/too_large_for_stack/useless_vec.rs b/src/tools/clippy/tests/ui-toml/too_large_for_stack/useless_vec.rs new file mode 100644 index 000000000..e2886a8cc --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/too_large_for_stack/useless_vec.rs @@ -0,0 +1,9 @@ +#![warn(clippy::useless_vec)] + +fn main() { + let x = vec![0u8; 500]; + //~^ ERROR: useless use of `vec!` + x.contains(&1); + let y = vec![0u8; 501]; + y.contains(&1); +} diff --git a/src/tools/clippy/tests/ui-toml/too_large_for_stack/useless_vec.stderr b/src/tools/clippy/tests/ui-toml/too_large_for_stack/useless_vec.stderr new file mode 100644 index 000000000..923cded5e --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/too_large_for_stack/useless_vec.stderr @@ -0,0 +1,11 @@ +error: useless use of `vec!` + --> $DIR/useless_vec.rs:4:13 + | +LL | let x = vec![0u8; 500]; + | ^^^^^^^^^^^^^^ help: you can use an array directly: `[0u8; 500]` + | + = note: `-D clippy::useless-vec` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::useless_vec)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/too_many_arguments/clippy.toml b/src/tools/clippy/tests/ui-toml/too_many_arguments/clippy.toml new file mode 100644 index 000000000..15906305c --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/too_many_arguments/clippy.toml @@ -0,0 +1 @@ +too-many-arguments-threshold = 10 diff --git a/src/tools/clippy/tests/ui-toml/too_many_arguments/too_many_arguments.rs b/src/tools/clippy/tests/ui-toml/too_many_arguments/too_many_arguments.rs new file mode 100644 index 000000000..7b2d6897d --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/too_many_arguments/too_many_arguments.rs @@ -0,0 +1,7 @@ +#![warn(clippy::too_many_arguments)] + +fn not_too_many(p1: u8, p2: u8, p3: u8, p4: u8, p5: u8, p6: u8, p7: u8, p8: u8, p9: u8, p10: u8) {} +fn too_many(p1: u8, p2: u8, p3: u8, p4: u8, p5: u8, p6: u8, p7: u8, p8: u8, p9: u8, p10: u8, p11: u8) {} +//~^ ERROR: this function has too many arguments + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/too_many_arguments/too_many_arguments.stderr b/src/tools/clippy/tests/ui-toml/too_many_arguments/too_many_arguments.stderr new file mode 100644 index 000000000..a52e1fcb9 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/too_many_arguments/too_many_arguments.stderr @@ -0,0 +1,11 @@ +error: this function has too many arguments (11/10) + --> $DIR/too_many_arguments.rs:4:1 + | +LL | fn too_many(p1: u8, p2: u8, p3: u8, p4: u8, p5: u8, p6: u8, p7: u8, p8: u8, p9: u8, p10: u8, p11: u8) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::too-many-arguments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::too_many_arguments)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/type_complexity/clippy.toml b/src/tools/clippy/tests/ui-toml/type_complexity/clippy.toml new file mode 100644 index 000000000..bf2ffdd0e --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/type_complexity/clippy.toml @@ -0,0 +1 @@ +type-complexity-threshold = 500 diff --git a/src/tools/clippy/tests/ui-toml/type_complexity/type_complexity.rs b/src/tools/clippy/tests/ui-toml/type_complexity/type_complexity.rs new file mode 100644 index 000000000..b95f51343 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/type_complexity/type_complexity.rs @@ -0,0 +1,7 @@ +// 480 +fn f(_: (u8, (u8, (u8, (u8, (u8, (u8,))))))) {} +// 550 +fn f2(_: (u8, (u8, (u8, (u8, (u8, (u8, u8))))))) {} +//~^ ERROR: very complex type used + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/type_complexity/type_complexity.stderr b/src/tools/clippy/tests/ui-toml/type_complexity/type_complexity.stderr new file mode 100644 index 000000000..8ca637f72 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/type_complexity/type_complexity.stderr @@ -0,0 +1,11 @@ +error: very complex type used. Consider factoring parts into `type` definitions + --> $DIR/type_complexity.rs:4:10 + | +LL | fn f2(_: (u8, (u8, (u8, (u8, (u8, (u8, u8))))))) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::type-complexity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::type_complexity)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/type_repetition_in_bounds/clippy.toml b/src/tools/clippy/tests/ui-toml/type_repetition_in_bounds/clippy.toml new file mode 100644 index 000000000..2f91866aa --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/type_repetition_in_bounds/clippy.toml @@ -0,0 +1 @@ +max-trait-bounds = 5 diff --git a/src/tools/clippy/tests/ui-toml/type_repetition_in_bounds/main.rs b/src/tools/clippy/tests/ui-toml/type_repetition_in_bounds/main.rs new file mode 100644 index 000000000..2454c1038 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/type_repetition_in_bounds/main.rs @@ -0,0 +1,18 @@ +#![warn(clippy::type_repetition_in_bounds)] + +fn f() +where + T: Copy + Clone + Sync + Send + ?Sized + Unpin, + T: PartialEq, +{ +} + +fn f2() +where + T: Copy + Clone + Sync + Send + ?Sized, + T: Unpin + PartialEq, + //~^ ERROR: this type has already been used as a bound predicate +{ +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/type_repetition_in_bounds/main.stderr b/src/tools/clippy/tests/ui-toml/type_repetition_in_bounds/main.stderr new file mode 100644 index 000000000..2ae298497 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/type_repetition_in_bounds/main.stderr @@ -0,0 +1,12 @@ +error: this type has already been used as a bound predicate + --> $DIR/main.rs:13:5 + | +LL | T: Unpin + PartialEq, + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: consider combining the bounds: `T: Copy + Clone + Sync + Send + ?Sized + Unpin + PartialEq` + = note: `-D clippy::type-repetition-in-bounds` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::type_repetition_in_bounds)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/auxiliary/proc_macro_unsafe.rs b/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/auxiliary/proc_macro_unsafe.rs deleted file mode 100644 index 1c591fc76..000000000 --- a/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/auxiliary/proc_macro_unsafe.rs +++ /dev/null @@ -1,13 +0,0 @@ -extern crate proc_macro; - -use proc_macro::{Delimiter, Group, Ident, TokenStream, TokenTree}; - -#[proc_macro] -pub fn unsafe_block(input: TokenStream) -> TokenStream { - let span = input.into_iter().next().unwrap().span(); - TokenStream::from_iter([TokenTree::Ident(Ident::new("unsafe", span)), { - let mut group = Group::new(Delimiter::Brace, TokenStream::new()); - group.set_span(span); - TokenTree::Group(group) - }]) -} diff --git a/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/clippy.toml b/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/clippy.toml deleted file mode 100644 index e6dbb3d37..000000000 --- a/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/clippy.toml +++ /dev/null @@ -1,2 +0,0 @@ -accept-comment-above-statement = true -accept-comment-above-attributes = true diff --git a/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/default/clippy.toml b/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/default/clippy.toml new file mode 100644 index 000000000..3b205d536 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/default/clippy.toml @@ -0,0 +1,2 @@ +# default configuration has `accept-comment-above-statement` and +# `accept-comment-above-attributes` true diff --git a/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/disabled/clippy.toml b/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/disabled/clippy.toml new file mode 100644 index 000000000..57ecb902d --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/disabled/clippy.toml @@ -0,0 +1,3 @@ +# test with these options disabled +accept-comment-above-statement = false +accept-comment-above-attributes = false diff --git a/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr b/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr new file mode 100644 index 000000000..15edf2a7d --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr @@ -0,0 +1,316 @@ +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:266:19 + | +LL | /* Safety: */ unsafe {} + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]` + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:270:5 + | +LL | unsafe {} + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:274:14 + | +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.rs:274:29 + | +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.rs:274:48 + | +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.rs:278:18 + | +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.rs:278:37 + | +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.rs:282:14 + | +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.rs:287:19 + | +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.rs:293:14 + | +LL | let _ = &unsafe {}; + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:297:14 + | +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.rs:301:13 + | +LL | let _ = unsafe {}; + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:311:8 + | +LL | t!(unsafe {}); + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:317:13 + | +LL | unsafe {} + | ^^^^^^^^^ +... +LL | t!(); + | ---- in this macro invocation + | + = help: consider adding a safety comment on the preceding line + = 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.rs:325:5 + | +LL | unsafe {} // SAFETY: + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:329:5 + | +LL | unsafe { + | ^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:339:5 + | +LL | unsafe {}; + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:343:20 + | +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.rs:350:5 + | +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.rs:357:9 + | +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.rs:378:13 + | +LL | unsafe impl T for $t {} + | ^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | no_safety_comment!(()); + | ---------------------- in this macro invocation + | + = help: consider adding a safety comment on the preceding line + = 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.rs:403:13 + | +LL | unsafe impl T for $t {} + | ^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | no_safety_comment!(()); + | ---------------------- in this macro invocation + | + = help: consider adding a safety comment on the preceding line + = 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.rs:411:5 + | +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.rs:403:13 + | +LL | unsafe impl T for $t {} + | ^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | no_safety_comment!(u32); + | ----------------------- in this macro invocation + | + = help: consider adding a safety comment on the preceding line + = 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.rs:417:5 + | +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.rs:463:5 + | +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.rs:467:19 + | +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.rs:471:5 + | +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.rs:475:5 + | +LL | const BIG_NUMBER: i32 = 1000000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider removing the safety comment + --> $DIR/undocumented_unsafe_blocks.rs:474:5 + | +LL | // SAFETY: + | ^^^^^^^^^^ + = note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]` + +error: unsafe impl missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:476:5 + | +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.rs:483:5 + | +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.rs:492:1 + | +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.rs:505:5 + | +LL | / let _ = { +LL | | if unsafe { true } { +LL | | todo!(); +LL | | } else { +... | +LL | | } +LL | | }; + | |______^ + | +help: consider removing the safety comment + --> $DIR/undocumented_unsafe_blocks.rs:504: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.rs:506:12 + | +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.rs:509:23 + | +LL | let bar = unsafe {}; + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: aborting due to 35 previous errors + diff --git a/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr b/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr new file mode 100644 index 000000000..cc9530f79 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr @@ -0,0 +1,396 @@ +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:266:19 + | +LL | /* Safety: */ unsafe {} + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]` + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:270:5 + | +LL | unsafe {} + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:274:14 + | +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.rs:274:29 + | +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.rs:274:48 + | +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.rs:278:18 + | +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.rs:278:37 + | +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.rs:282:14 + | +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.rs:287:19 + | +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.rs:293:14 + | +LL | let _ = &unsafe {}; + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:297:14 + | +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.rs:301:13 + | +LL | let _ = unsafe {}; + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:311:8 + | +LL | t!(unsafe {}); + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:317:13 + | +LL | unsafe {} + | ^^^^^^^^^ +... +LL | t!(); + | ---- in this macro invocation + | + = help: consider adding a safety comment on the preceding line + = 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.rs:325:5 + | +LL | unsafe {} // SAFETY: + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:329:5 + | +LL | unsafe { + | ^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:339:5 + | +LL | unsafe {}; + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:343:20 + | +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.rs:350:5 + | +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.rs:357:9 + | +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.rs:378:13 + | +LL | unsafe impl T for $t {} + | ^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | no_safety_comment!(()); + | ---------------------- in this macro invocation + | + = help: consider adding a safety comment on the preceding line + = 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.rs:403:13 + | +LL | unsafe impl T for $t {} + | ^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | no_safety_comment!(()); + | ---------------------- in this macro invocation + | + = help: consider adding a safety comment on the preceding line + = 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.rs:411:5 + | +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.rs:403:13 + | +LL | unsafe impl T for $t {} + | ^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | no_safety_comment!(u32); + | ----------------------- in this macro invocation + | + = help: consider adding a safety comment on the preceding line + = 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.rs:417:5 + | +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.rs:463:5 + | +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.rs:467:19 + | +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.rs:471:5 + | +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.rs:475:5 + | +LL | const BIG_NUMBER: i32 = 1000000; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider removing the safety comment + --> $DIR/undocumented_unsafe_blocks.rs:474:5 + | +LL | // SAFETY: + | ^^^^^^^^^^ + = note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]` + +error: unsafe impl missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:476:5 + | +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.rs:483:5 + | +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.rs:492:1 + | +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.rs:502:9 + | +LL | unsafe {}; + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: statement has unnecessary safety comment + --> $DIR/undocumented_unsafe_blocks.rs:505:5 + | +LL | / let _ = { +LL | | if unsafe { true } { +LL | | todo!(); +LL | | } else { +... | +LL | | } +LL | | }; + | |______^ + | +help: consider removing the safety comment + --> $DIR/undocumented_unsafe_blocks.rs:504: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.rs:506:12 + | +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.rs:509:23 + | +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.rs:527:9 + | +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.rs:531:9 + | +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.rs:535:9 + | +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.rs:541:5 + | +LL | unsafe {} + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:545:5 + | +LL | unsafe { + | ^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: unsafe block missing a safety comment + --> $DIR/undocumented_unsafe_blocks.rs:552:9 + | +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.rs:557:9 + | +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.rs:563:9 + | +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.rs:568:5 + | +LL | unsafe {} + | ^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: aborting due to 45 previous errors + diff --git a/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs b/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs index 33d636709..a27813987 100644 --- a/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs +++ b/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs @@ -1,4 +1,7 @@ -//@aux-build:proc_macro_unsafe.rs:proc-macro +//@aux-build:../../ui/auxiliary/proc_macro_unsafe.rs +//@revisions: default disabled +//@[default] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/undocumented_unsafe_blocks/default +//@[disabled] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/undocumented_unsafe_blocks/disabled #![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)] #![allow(deref_nullptr, clippy::let_unit_value, clippy::missing_safety_doc)] @@ -491,7 +494,7 @@ unsafe impl CrateRoot for () {} // SAFETY: ok unsafe impl CrateRoot for (i32) {} -fn issue_9142() { +fn nested_block_separation_issue_9142() { // SAFETY: ok let _ = // we need this comment to avoid rustfmt putting @@ -518,50 +521,65 @@ pub const unsafe fn a_const_function_with_a_very_long_name_to_break_the_line() - 2 } -fn issue_10832() { - // Safety: A safety comment +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() }; - // Safety: Another safety comment + // 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() }; - // Safety: Yet another safety comment + // 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() }; } -fn issue_8679() { - // SAFETY: +fn above_expr_attribute_issue_8679() { + // SAFETY: fail ONLY if `accept-comment-above-attribute = false` #[allow(unsafe_code)] unsafe {} - // SAFETY: + // SAFETY: fail ONLY if `accept-comment-above-attribute = false` #[expect(unsafe_code, reason = "totally safe")] unsafe { *std::ptr::null::() }; - // Safety: A safety comment + // SAFETY: fail ONLY if `accept-comment-above-attribute = false` #[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() }; - // Safety: Another safety comment + // 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() }; - // Safety: Yet another safety comment + // SAFETY: fail ONLY if `accept-comment-above-attribute = false` #[allow(unsafe_code)] - static _SOME_STATIC_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 = + #[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() }; // SAFETY: #[allow(unsafe_code)] - // This also works I guess + // This shouldn't work either unsafe {} } +mod issue_11246 { + // Safety: foo + const _: () = unsafe {}; + + // Safety: A safety comment + const FOO: () = unsafe {}; + + // Safety: bar + static BAR: u8 = unsafe { 0 }; +} + +// Safety: Another safety comment +const FOO: () = unsafe {}; + fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.stderr b/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.stderr deleted file mode 100644 index 9a0fd0593..000000000 --- a/src/tools/clippy/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.stderr +++ /dev/null @@ -1,314 +0,0 @@ -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:263:19 - | -LL | /* Safety: */ unsafe {} - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:267:5 - | -LL | unsafe {} - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:271:14 - | -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.rs:271:29 - | -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.rs:271:48 - | -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.rs:275:18 - | -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.rs:275:37 - | -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.rs:279:14 - | -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.rs:284:19 - | -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.rs:290:14 - | -LL | let _ = &unsafe {}; - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:294:14 - | -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.rs:298:13 - | -LL | let _ = unsafe {}; - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:308:8 - | -LL | t!(unsafe {}); - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:314:13 - | -LL | unsafe {} - | ^^^^^^^^^ -... -LL | t!(); - | ---- in this macro invocation - | - = help: consider adding a safety comment on the preceding line - = 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.rs:322:5 - | -LL | unsafe {} // SAFETY: - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:326:5 - | -LL | unsafe { - | ^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:336:5 - | -LL | unsafe {}; - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:340:20 - | -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.rs:347:5 - | -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.rs:354:9 - | -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.rs:375:13 - | -LL | unsafe impl T for $t {} - | ^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | no_safety_comment!(()); - | ---------------------- in this macro invocation - | - = help: consider adding a safety comment on the preceding line - = 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.rs:400:13 - | -LL | unsafe impl T for $t {} - | ^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | no_safety_comment!(()); - | ---------------------- in this macro invocation - | - = help: consider adding a safety comment on the preceding line - = 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.rs:408:5 - | -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.rs:400:13 - | -LL | unsafe impl T for $t {} - | ^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | no_safety_comment!(u32); - | ----------------------- in this macro invocation - | - = help: consider adding a safety comment on the preceding line - = 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.rs:414:5 - | -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.rs:460:5 - | -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.rs:464:19 - | -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.rs:468:5 - | -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.rs:472:5 - | -LL | const BIG_NUMBER: i32 = 1000000; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider removing the safety comment - --> $DIR/undocumented_unsafe_blocks.rs:471:5 - | -LL | // SAFETY: - | ^^^^^^^^^^ - = note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings` - -error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:473:5 - | -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.rs:480:5 - | -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.rs:489:1 - | -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.rs:502:5 - | -LL | / let _ = { -LL | | if unsafe { true } { -LL | | todo!(); -LL | | } else { -... | -LL | | } -LL | | }; - | |______^ - | -help: consider removing the safety comment - --> $DIR/undocumented_unsafe_blocks.rs:501: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.rs:503:12 - | -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.rs:506:23 - | -LL | let bar = unsafe {}; - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: aborting due to 35 previous errors - diff --git a/src/tools/clippy/tests/ui-toml/unnecessary_box_returns/clippy.toml b/src/tools/clippy/tests/ui-toml/unnecessary_box_returns/clippy.toml new file mode 100644 index 000000000..7c3ffc290 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/unnecessary_box_returns/clippy.toml @@ -0,0 +1 @@ +unnecessary-box-size = 64 diff --git a/src/tools/clippy/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.fixed b/src/tools/clippy/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.fixed new file mode 100644 index 000000000..413bc0bf1 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.fixed @@ -0,0 +1,11 @@ +#![warn(clippy::unnecessary_box_returns)] + +fn f() -> [u8; 64] { + //~^ ERROR: boxed return of the sized type `[u8; 64]` + todo!() +} +fn f2() -> Box<[u8; 65]> { + todo!() +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.rs b/src/tools/clippy/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.rs new file mode 100644 index 000000000..b44fbb554 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.rs @@ -0,0 +1,11 @@ +#![warn(clippy::unnecessary_box_returns)] + +fn f() -> Box<[u8; 64]> { + //~^ ERROR: boxed return of the sized type `[u8; 64]` + todo!() +} +fn f2() -> Box<[u8; 65]> { + todo!() +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.stderr b/src/tools/clippy/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.stderr new file mode 100644 index 000000000..df9aa37ac --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/unnecessary_box_returns/unnecessary_box_returns.stderr @@ -0,0 +1,12 @@ +error: boxed return of the sized type `[u8; 64]` + --> $DIR/unnecessary_box_returns.rs:3:11 + | +LL | fn f() -> Box<[u8; 64]> { + | ^^^^^^^^^^^^^ help: try: `[u8; 64]` + | + = help: changing this also requires a change to the return expressions in this function + = note: `-D clippy::unnecessary-box-returns` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_box_returns)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.fixed b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.fixed new file mode 100644 index 000000000..baf939af2 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.fixed @@ -0,0 +1,95 @@ +//@compile-flags: --test + +#![allow( + unused_mut, + clippy::get_first, + clippy::from_iter_instead_of_collect, + clippy::useless_vec +)] +#![warn(clippy::unwrap_used)] +#![warn(clippy::get_unwrap)] + +use std::collections::{BTreeMap, HashMap, VecDeque}; + +struct GetFalsePositive { + arr: [u32; 3], +} + +impl GetFalsePositive { + fn get(&self, pos: usize) -> Option<&u32> { + self.arr.get(pos) + } + fn get_mut(&mut self, pos: usize) -> Option<&mut u32> { + self.arr.get_mut(pos) + } +} + +fn main() { + let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); + let mut some_slice = &mut [0, 1, 2, 3]; + let mut some_vec = vec![0, 1, 2, 3]; + let mut some_vecdeque: VecDeque<_> = some_vec.iter().cloned().collect(); + let mut some_hashmap: HashMap = HashMap::from_iter(vec![(1, 'a'), (2, 'b')]); + let mut some_btreemap: BTreeMap = BTreeMap::from_iter(vec![(1, 'a'), (2, 'b')]); + let mut false_positive = GetFalsePositive { arr: [0, 1, 2] }; + + { + // Test `get().unwrap()` + let _ = &boxed_slice[1]; + let _ = &some_slice[0]; + let _ = &some_vec[0]; + let _ = &some_vecdeque[0]; + let _ = &some_hashmap[&1]; + let _ = &some_btreemap[&1]; + #[allow(clippy::unwrap_used)] + let _ = false_positive.get(0).unwrap(); + // Test with deref + let _: u8 = boxed_slice[1]; + } + + { + // Test `get_mut().unwrap()` + boxed_slice[0] = 1; + some_slice[0] = 1; + some_vec[0] = 1; + some_vecdeque[0] = 1; + // Check false positives + #[allow(clippy::unwrap_used)] + { + *some_hashmap.get_mut(&1).unwrap() = 'b'; + *some_btreemap.get_mut(&1).unwrap() = 'b'; + *false_positive.get_mut(0).unwrap() = 1; + } + } + + { + // Test `get().unwrap().foo()` and `get_mut().unwrap().bar()` + let _ = some_vec[0..1].to_vec(); + let _ = some_vec[0..1].to_vec(); + } +} + +#[test] +fn test() { + let boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); + let _ = &boxed_slice[1]; +} + +#[cfg(test)] +mod issue9612 { + // should not lint in `#[cfg(test)]` modules + #[test] + fn test_fn() { + let _a: u8 = 2.try_into().unwrap(); + let _a: u8 = 3.try_into().expect(""); + + util(); + } + + fn util() { + let _a: u8 = 4.try_into().unwrap(); + let _a: u8 = 5.try_into().expect(""); + // should still warn + let _ = &Box::new([0])[1]; + } +} diff --git a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr index 10219beaf..cc22ea273 100644 --- a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr +++ b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr @@ -5,6 +5,7 @@ LL | let _ = boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&boxed_slice[1]` | = note: `-D clippy::get-unwrap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::get_unwrap)]` error: used `unwrap()` on an `Option` value --> $DIR/unwrap_used.rs:38:17 @@ -15,6 +16,7 @@ LL | let _ = boxed_slice.get(1).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message = note: `-D clippy::unwrap-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise --> $DIR/unwrap_used.rs:39:17 diff --git a/src/tools/clippy/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed b/src/tools/clippy/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed new file mode 100644 index 000000000..afb889f15 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.fixed @@ -0,0 +1,44 @@ +#![warn(clippy::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, +} + +// linted with cfg option, beware that lint suggests `GccllvmSomething` instead of +// `GccLlvmSomething` +struct GccllvmSomething; + +// don't warn on public items +pub struct MIXEDCapital; + +pub struct FULLCAPITAL; + +// enum variants should not be linted if the num is pub +pub enum ParseError { + FULLCAPITAL(u8), + MIXEDCapital(String), + Utf8(std::string::FromUtf8Error), + Parse(T, String), +} + +// private, do lint here +enum ParseErrorPrivate { + Wasd(u8), + WasdMixed(String), + Utf8(std::string::FromUtf8Error), + Parse(T, String), +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr b/src/tools/clippy/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr index 02f29bbef..3fad561b1 100644 --- a/src/tools/clippy/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr +++ b/src/tools/clippy/tests/ui-toml/upper_case_acronyms_aggressive/upper_case_acronyms.stderr @@ -5,6 +5,7 @@ LL | struct HTTPResponse; // not linted by default, but with cfg option | ^^^^^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `HttpResponse` | = note: `-D clippy::upper-case-acronyms` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::upper_case_acronyms)]` error: name `NS` contains a capitalized acronym --> $DIR/upper_case_acronyms.rs:8:5 diff --git a/src/tools/clippy/tests/ui-toml/vec_box_sized/test.fixed b/src/tools/clippy/tests/ui-toml/vec_box_sized/test.fixed new file mode 100644 index 000000000..bb4936401 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/vec_box_sized/test.fixed @@ -0,0 +1,16 @@ +struct S { + x: u64, +} + +struct C { + y: u16, +} + +struct Foo(Vec); +struct Bar(Vec); +struct Quux(Vec>); +struct Baz(Vec>); +struct BarBaz(Vec>); +struct FooBarBaz(Vec); + +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/vec_box_sized/test.stderr b/src/tools/clippy/tests/ui-toml/vec_box_sized/test.stderr index 55de68f8e..c88860ea8 100644 --- a/src/tools/clippy/tests/ui-toml/vec_box_sized/test.stderr +++ b/src/tools/clippy/tests/ui-toml/vec_box_sized/test.stderr @@ -5,6 +5,7 @@ LL | struct Foo(Vec>); | ^^^^^^^^^^^^ help: try: `Vec` | = note: `-D clippy::vec-box` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::vec_box)]` error: `Vec` is already on the heap, the boxing is unnecessary --> $DIR/test.rs:10:12 diff --git a/src/tools/clippy/tests/ui-toml/verbose_bit_mask/clippy.toml b/src/tools/clippy/tests/ui-toml/verbose_bit_mask/clippy.toml new file mode 100644 index 000000000..55a202eef --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/verbose_bit_mask/clippy.toml @@ -0,0 +1 @@ +verbose-bit-mask-threshold = 31 diff --git a/src/tools/clippy/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.fixed b/src/tools/clippy/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.fixed new file mode 100644 index 000000000..437692a4d --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.fixed @@ -0,0 +1,7 @@ +#![warn(clippy::verbose_bit_mask)] +fn main() { + let v: i32 = 0; + let _ = v & 0b11111 == 0; + let _ = v.trailing_zeros() >= 6; + //~^ ERROR: bit mask could be simplified +} diff --git a/src/tools/clippy/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.rs b/src/tools/clippy/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.rs new file mode 100644 index 000000000..ce1027080 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.rs @@ -0,0 +1,7 @@ +#![warn(clippy::verbose_bit_mask)] +fn main() { + let v: i32 = 0; + let _ = v & 0b11111 == 0; + let _ = v & 0b111111 == 0; + //~^ ERROR: bit mask could be simplified +} diff --git a/src/tools/clippy/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.stderr b/src/tools/clippy/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.stderr new file mode 100644 index 000000000..7377921b4 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/verbose_bit_mask/verbose_bit_mask.stderr @@ -0,0 +1,11 @@ +error: bit mask could be simplified with a call to `trailing_zeros` + --> $DIR/verbose_bit_mask.rs:5:13 + | +LL | let _ = v & 0b111111 == 0; + | ^^^^^^^^^^^^^^^^^ help: try: `v.trailing_zeros() >= 6` + | + = note: `-D clippy::verbose-bit-mask` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::verbose_bit_mask)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui-toml/wildcard_imports/clippy.toml b/src/tools/clippy/tests/ui-toml/wildcard_imports/clippy.toml new file mode 100644 index 000000000..875aaeef6 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/wildcard_imports/clippy.toml @@ -0,0 +1 @@ +warn-on-all-wildcard-imports = true diff --git a/src/tools/clippy/tests/ui-toml/wildcard_imports/wildcard_imports.fixed b/src/tools/clippy/tests/ui-toml/wildcard_imports/wildcard_imports.fixed new file mode 100644 index 000000000..1752f4885 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/wildcard_imports/wildcard_imports.fixed @@ -0,0 +1,11 @@ +#![warn(clippy::wildcard_imports)] + +mod prelude { + pub const FOO: u8 = 1; +} +use prelude::FOO; +//~^ ERROR: usage of wildcard import + +fn main() { + let _ = FOO; +} diff --git a/src/tools/clippy/tests/ui-toml/wildcard_imports/wildcard_imports.rs b/src/tools/clippy/tests/ui-toml/wildcard_imports/wildcard_imports.rs new file mode 100644 index 000000000..331c2c59c --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/wildcard_imports/wildcard_imports.rs @@ -0,0 +1,11 @@ +#![warn(clippy::wildcard_imports)] + +mod prelude { + pub const FOO: u8 = 1; +} +use prelude::*; +//~^ ERROR: usage of wildcard import + +fn main() { + let _ = FOO; +} diff --git a/src/tools/clippy/tests/ui-toml/wildcard_imports/wildcard_imports.stderr b/src/tools/clippy/tests/ui-toml/wildcard_imports/wildcard_imports.stderr new file mode 100644 index 000000000..13ec3a229 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/wildcard_imports/wildcard_imports.stderr @@ -0,0 +1,11 @@ +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:6:5 + | +LL | use prelude::*; + | ^^^^^^^^^^ help: try: `prelude::FOO` + | + = note: `-D clippy::wildcard-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]` + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/absurd-extreme-comparisons.rs b/src/tools/clippy/tests/ui/absurd-extreme-comparisons.rs index f682b280c..60f2ba4ab 100644 --- a/src/tools/clippy/tests/ui/absurd-extreme-comparisons.rs +++ b/src/tools/clippy/tests/ui/absurd-extreme-comparisons.rs @@ -12,27 +12,46 @@ fn main() { const Z: u32 = 0; let u: u32 = 42; u <= 0; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u <= Z; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u < Z; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con Z >= u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con Z > u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u > u32::MAX; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u >= u32::MAX; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u32::MAX < u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u32::MAX <= u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con 1-1 > u; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u >= !0; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u <= 12 - 2*6; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con let i: i8 = 0; i < -127 - 1; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con i8::MAX >= i; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con 3-7 < i32::MIN; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con let b = false; b >= true; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con false > b; + //~^ ERROR: this comparison involving the minimum or maximum element for this type con u > 0; // ok // this is handled by clippy::unit_cmp () < {}; + //~^ ERROR: <-comparison of unit values detected. This will always be false + //~| NOTE: `#[deny(clippy::unit_cmp)]` on by default } use std::cmp::{Ordering, PartialEq, PartialOrd}; diff --git a/src/tools/clippy/tests/ui/absurd-extreme-comparisons.stderr b/src/tools/clippy/tests/ui/absurd-extreme-comparisons.stderr index 21cb11fa1..64d38e60d 100644 --- a/src/tools/clippy/tests/ui/absurd-extreme-comparisons.stderr +++ b/src/tools/clippy/tests/ui/absurd-extreme-comparisons.stderr @@ -6,9 +6,10 @@ LL | u <= 0; | = help: because `0` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == 0` instead = note: `-D clippy::absurd-extreme-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::absurd_extreme_comparisons)]` error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:15:5 + --> $DIR/absurd-extreme-comparisons.rs:16:5 | LL | u <= Z; | ^^^^^^ @@ -16,7 +17,7 @@ LL | u <= Z; = help: because `Z` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == Z` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:16:5 + --> $DIR/absurd-extreme-comparisons.rs:18:5 | LL | u < Z; | ^^^^^ @@ -24,7 +25,7 @@ LL | u < Z; = help: because `Z` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:17:5 + --> $DIR/absurd-extreme-comparisons.rs:20:5 | LL | Z >= u; | ^^^^^^ @@ -32,7 +33,7 @@ LL | Z >= u; = help: because `Z` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `Z == u` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:18:5 + --> $DIR/absurd-extreme-comparisons.rs:22:5 | LL | Z > u; | ^^^^^ @@ -40,7 +41,7 @@ LL | Z > u; = help: because `Z` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:19:5 + --> $DIR/absurd-extreme-comparisons.rs:24:5 | LL | u > u32::MAX; | ^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | u > u32::MAX; = help: because `u32::MAX` is the maximum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:20:5 + --> $DIR/absurd-extreme-comparisons.rs:26:5 | LL | u >= u32::MAX; | ^^^^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | u >= u32::MAX; = help: because `u32::MAX` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u == u32::MAX` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:21:5 + --> $DIR/absurd-extreme-comparisons.rs:28:5 | LL | u32::MAX < u; | ^^^^^^^^^^^^ @@ -64,7 +65,7 @@ LL | u32::MAX < u; = help: because `u32::MAX` is the maximum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:22:5 + --> $DIR/absurd-extreme-comparisons.rs:30:5 | LL | u32::MAX <= u; | ^^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL | u32::MAX <= u; = help: because `u32::MAX` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u32::MAX == u` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:23:5 + --> $DIR/absurd-extreme-comparisons.rs:32:5 | LL | 1-1 > u; | ^^^^^^^ @@ -80,7 +81,7 @@ LL | 1-1 > u; = help: because `1-1` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:24:5 + --> $DIR/absurd-extreme-comparisons.rs:34:5 | LL | u >= !0; | ^^^^^^^ @@ -88,7 +89,7 @@ LL | u >= !0; = help: because `!0` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u == !0` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:25:5 + --> $DIR/absurd-extreme-comparisons.rs:36:5 | LL | u <= 12 - 2*6; | ^^^^^^^^^^^^^ @@ -96,7 +97,7 @@ LL | u <= 12 - 2*6; = help: because `12 - 2*6` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == 12 - 2*6` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:27:5 + --> $DIR/absurd-extreme-comparisons.rs:39:5 | LL | i < -127 - 1; | ^^^^^^^^^^^^ @@ -104,7 +105,7 @@ LL | i < -127 - 1; = help: because `-127 - 1` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:28:5 + --> $DIR/absurd-extreme-comparisons.rs:41:5 | LL | i8::MAX >= i; | ^^^^^^^^^^^^ @@ -112,7 +113,7 @@ LL | i8::MAX >= i; = help: because `i8::MAX` is the maximum value for this type, this comparison is always true error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:29:5 + --> $DIR/absurd-extreme-comparisons.rs:43:5 | LL | 3-7 < i32::MIN; | ^^^^^^^^^^^^^^ @@ -120,7 +121,7 @@ LL | 3-7 < i32::MIN; = help: because `i32::MIN` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:31:5 + --> $DIR/absurd-extreme-comparisons.rs:46:5 | LL | b >= true; | ^^^^^^^^^ @@ -128,7 +129,7 @@ LL | b >= true; = help: because `true` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `b == true` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> $DIR/absurd-extreme-comparisons.rs:32:5 + --> $DIR/absurd-extreme-comparisons.rs:48:5 | LL | false > b; | ^^^^^^^^^ @@ -136,7 +137,7 @@ LL | false > b; = help: because `false` is the minimum value for this type, this comparison is always false error: <-comparison of unit values detected. This will always be false - --> $DIR/absurd-extreme-comparisons.rs:35:5 + --> $DIR/absurd-extreme-comparisons.rs:52:5 | LL | () < {}; | ^^^^^^^ diff --git a/src/tools/clippy/tests/ui/allow_attributes.fixed b/src/tools/clippy/tests/ui/allow_attributes.fixed index cc95a0681..b506a9890 100644 --- a/src/tools/clippy/tests/ui/allow_attributes.fixed +++ b/src/tools/clippy/tests/ui/allow_attributes.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused)] #![warn(clippy::allow_attributes)] #![feature(lint_reasons)] @@ -23,6 +22,13 @@ struct T4; #[cfg_attr(panic = "unwind", expect(dead_code))] struct CfgT; +#[allow(clippy::allow_attributes, unused)] +struct Allowed; + +#[expect(clippy::allow_attributes)] +#[allow(unused)] +struct Expected; + fn ignore_external() { external! { #[allow(clippy::needless_borrow)] // Should not lint diff --git a/src/tools/clippy/tests/ui/allow_attributes.rs b/src/tools/clippy/tests/ui/allow_attributes.rs index 2eb6ad304..c7daa7abd 100644 --- a/src/tools/clippy/tests/ui/allow_attributes.rs +++ b/src/tools/clippy/tests/ui/allow_attributes.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused)] #![warn(clippy::allow_attributes)] #![feature(lint_reasons)] @@ -23,6 +22,13 @@ struct T4; #[cfg_attr(panic = "unwind", allow(dead_code))] struct CfgT; +#[allow(clippy::allow_attributes, unused)] +struct Allowed; + +#[expect(clippy::allow_attributes)] +#[allow(unused)] +struct Expected; + fn ignore_external() { external! { #[allow(clippy::needless_borrow)] // Should not lint diff --git a/src/tools/clippy/tests/ui/allow_attributes.stderr b/src/tools/clippy/tests/ui/allow_attributes.stderr index d17fd86cb..7ac0bd456 100644 --- a/src/tools/clippy/tests/ui/allow_attributes.stderr +++ b/src/tools/clippy/tests/ui/allow_attributes.stderr @@ -1,13 +1,14 @@ error: #[allow] attribute found - --> $DIR/allow_attributes.rs:14:3 + --> $DIR/allow_attributes.rs:13:3 | LL | #[allow(dead_code)] | ^^^^^ help: replace it with: `expect` | = note: `-D clippy::allow-attributes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::allow_attributes)]` error: #[allow] attribute found - --> $DIR/allow_attributes.rs:23:30 + --> $DIR/allow_attributes.rs:22:30 | LL | #[cfg_attr(panic = "unwind", allow(dead_code))] | ^^^^^ help: replace it with: `expect` diff --git a/src/tools/clippy/tests/ui/allow_attributes_without_reason.rs b/src/tools/clippy/tests/ui/allow_attributes_without_reason.rs index d223d5642..663c2eb2c 100644 --- a/src/tools/clippy/tests/ui/allow_attributes_without_reason.rs +++ b/src/tools/clippy/tests/ui/allow_attributes_without_reason.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(lint_reasons)] #![deny(clippy::allow_attributes_without_reason)] #![allow(unfulfilled_lint_expectations)] diff --git a/src/tools/clippy/tests/ui/almost_complete_range.fixed b/src/tools/clippy/tests/ui/almost_complete_range.fixed index 50a13f16b..21caeb153 100644 --- a/src/tools/clippy/tests/ui/almost_complete_range.fixed +++ b/src/tools/clippy/tests/ui/almost_complete_range.fixed @@ -1,6 +1,5 @@ -//@run-rustfix //@edition:2018 -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(exclusive_range_pattern)] #![feature(stmt_expr_attributes)] diff --git a/src/tools/clippy/tests/ui/almost_complete_range.rs b/src/tools/clippy/tests/ui/almost_complete_range.rs index fd8223a23..556110a5c 100644 --- a/src/tools/clippy/tests/ui/almost_complete_range.rs +++ b/src/tools/clippy/tests/ui/almost_complete_range.rs @@ -1,6 +1,5 @@ -//@run-rustfix //@edition:2018 -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(exclusive_range_pattern)] #![feature(stmt_expr_attributes)] diff --git a/src/tools/clippy/tests/ui/almost_complete_range.stderr b/src/tools/clippy/tests/ui/almost_complete_range.stderr index 34521c13a..054a02c9c 100644 --- a/src/tools/clippy/tests/ui/almost_complete_range.stderr +++ b/src/tools/clippy/tests/ui/almost_complete_range.stderr @@ -1,5 +1,5 @@ error: almost complete ascii range - --> $DIR/almost_complete_range.rs:19:17 + --> $DIR/almost_complete_range.rs:18:17 | LL | let _ = ('a') ..'z'; | ^^^^^^--^^^ @@ -7,9 +7,10 @@ LL | let _ = ('a') ..'z'; | help: use an inclusive range: `..=` | = note: `-D clippy::almost-complete-range` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::almost_complete_range)]` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:20:17 + --> $DIR/almost_complete_range.rs:19:17 | LL | let _ = 'A' .. ('Z'); | ^^^^--^^^^^^ @@ -17,7 +18,7 @@ LL | let _ = 'A' .. ('Z'); | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:21:17 + --> $DIR/almost_complete_range.rs:20:17 | LL | let _ = ((('0'))) .. ('9'); | ^^^^^^^^^^--^^^^^^ @@ -25,7 +26,7 @@ LL | let _ = ((('0'))) .. ('9'); | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:28:13 + --> $DIR/almost_complete_range.rs:27:13 | LL | let _ = (b'a')..(b'z'); | ^^^^^^--^^^^^^ @@ -33,7 +34,7 @@ LL | let _ = (b'a')..(b'z'); | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:29:13 + --> $DIR/almost_complete_range.rs:28:13 | LL | let _ = b'A'..b'Z'; | ^^^^--^^^^ @@ -41,7 +42,7 @@ LL | let _ = b'A'..b'Z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:30:13 + --> $DIR/almost_complete_range.rs:29:13 | LL | let _ = b'0'..b'9'; | ^^^^--^^^^ @@ -49,7 +50,7 @@ LL | let _ = b'0'..b'9'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:36:13 + --> $DIR/almost_complete_range.rs:35:13 | LL | let _ = inline!('a')..'z'; | ^^^^^^^^^^^^--^^^ @@ -57,7 +58,7 @@ LL | let _ = inline!('a')..'z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:37:13 + --> $DIR/almost_complete_range.rs:36:13 | LL | let _ = inline!('A')..'Z'; | ^^^^^^^^^^^^--^^^ @@ -65,7 +66,7 @@ LL | let _ = inline!('A')..'Z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:38:13 + --> $DIR/almost_complete_range.rs:37:13 | LL | let _ = inline!('0')..'9'; | ^^^^^^^^^^^^--^^^ @@ -73,7 +74,7 @@ LL | let _ = inline!('0')..'9'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:41:9 + --> $DIR/almost_complete_range.rs:40:9 | LL | b'a'..b'z' if true => 1, | ^^^^--^^^^ @@ -81,7 +82,7 @@ LL | b'a'..b'z' if true => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:42:9 + --> $DIR/almost_complete_range.rs:41:9 | LL | b'A'..b'Z' if true => 2, | ^^^^--^^^^ @@ -89,7 +90,7 @@ LL | b'A'..b'Z' if true => 2, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:43:9 + --> $DIR/almost_complete_range.rs:42:9 | LL | b'0'..b'9' if true => 3, | ^^^^--^^^^ @@ -97,7 +98,7 @@ LL | b'0'..b'9' if true => 3, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:51:9 + --> $DIR/almost_complete_range.rs:50:9 | LL | 'a'..'z' if true => 1, | ^^^--^^^ @@ -105,7 +106,7 @@ LL | 'a'..'z' if true => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:52:9 + --> $DIR/almost_complete_range.rs:51:9 | LL | 'A'..'Z' if true => 2, | ^^^--^^^ @@ -113,7 +114,7 @@ LL | 'A'..'Z' if true => 2, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:53:9 + --> $DIR/almost_complete_range.rs:52:9 | LL | '0'..'9' if true => 3, | ^^^--^^^ @@ -121,7 +122,7 @@ LL | '0'..'9' if true => 3, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:66:17 + --> $DIR/almost_complete_range.rs:65:17 | LL | let _ = 'a'..'z'; | ^^^--^^^ @@ -131,7 +132,7 @@ LL | let _ = 'a'..'z'; = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: almost complete ascii range - --> $DIR/almost_complete_range.rs:67:17 + --> $DIR/almost_complete_range.rs:66:17 | LL | let _ = 'A'..'Z'; | ^^^--^^^ @@ -141,7 +142,7 @@ LL | let _ = 'A'..'Z'; = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: almost complete ascii range - --> $DIR/almost_complete_range.rs:68:17 + --> $DIR/almost_complete_range.rs:67:17 | LL | let _ = '0'..'9'; | ^^^--^^^ @@ -151,7 +152,7 @@ LL | let _ = '0'..'9'; = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: almost complete ascii range - --> $DIR/almost_complete_range.rs:75:9 + --> $DIR/almost_complete_range.rs:74:9 | LL | 'a'..'z' => 1, | ^^^--^^^ @@ -159,7 +160,7 @@ LL | 'a'..'z' => 1, | help: use an inclusive range: `...` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:76:9 + --> $DIR/almost_complete_range.rs:75:9 | LL | 'A'..'Z' => 2, | ^^^--^^^ @@ -167,7 +168,7 @@ LL | 'A'..'Z' => 2, | help: use an inclusive range: `...` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:77:9 + --> $DIR/almost_complete_range.rs:76:9 | LL | '0'..'9' => 3, | ^^^--^^^ @@ -175,7 +176,7 @@ LL | '0'..'9' => 3, | help: use an inclusive range: `...` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:84:13 + --> $DIR/almost_complete_range.rs:83:13 | LL | let _ = 'a'..'z'; | ^^^--^^^ @@ -183,7 +184,7 @@ LL | let _ = 'a'..'z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:85:13 + --> $DIR/almost_complete_range.rs:84:13 | LL | let _ = 'A'..'Z'; | ^^^--^^^ @@ -191,7 +192,7 @@ LL | let _ = 'A'..'Z'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:86:13 + --> $DIR/almost_complete_range.rs:85:13 | LL | let _ = '0'..'9'; | ^^^--^^^ @@ -199,7 +200,7 @@ LL | let _ = '0'..'9'; | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:88:9 + --> $DIR/almost_complete_range.rs:87:9 | LL | 'a'..'z' => 1, | ^^^--^^^ @@ -207,7 +208,7 @@ LL | 'a'..'z' => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:89:9 + --> $DIR/almost_complete_range.rs:88:9 | LL | 'A'..'Z' => 1, | ^^^--^^^ @@ -215,7 +216,7 @@ LL | 'A'..'Z' => 1, | help: use an inclusive range: `..=` error: almost complete ascii range - --> $DIR/almost_complete_range.rs:90:9 + --> $DIR/almost_complete_range.rs:89:9 | LL | '0'..'9' => 3, | ^^^--^^^ diff --git a/src/tools/clippy/tests/ui/approx_const.rs b/src/tools/clippy/tests/ui/approx_const.rs index ccdbd34f7..2c3e0978c 100644 --- a/src/tools/clippy/tests/ui/approx_const.rs +++ b/src/tools/clippy/tests/ui/approx_const.rs @@ -2,63 +2,86 @@ #[allow(clippy::similar_names)] fn main() { let my_e = 2.7182; + //~^ ERROR: approximate value of `f{32, 64}::consts::E` found let almost_e = 2.718; + //~^ ERROR: approximate value of `f{32, 64}::consts::E` found let no_e = 2.71; let my_1_frac_pi = 0.3183; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_1_PI` found let no_1_frac_pi = 0.31; let my_frac_1_sqrt_2 = 0.70710678; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found let almost_frac_1_sqrt_2 = 0.70711; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found let my_frac_1_sqrt_2 = 0.707; let my_frac_2_pi = 0.63661977; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_2_PI` found let no_frac_2_pi = 0.636; let my_frac_2_sq_pi = 1.128379; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_2_SQRT_PI` found let no_frac_2_sq_pi = 1.128; let my_frac_pi_2 = 1.57079632679; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_2` found let no_frac_pi_2 = 1.5705; let my_frac_pi_3 = 1.04719755119; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_3` found let no_frac_pi_3 = 1.047; let my_frac_pi_4 = 0.785398163397; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_4` found let no_frac_pi_4 = 0.785; let my_frac_pi_6 = 0.523598775598; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_6` found let no_frac_pi_6 = 0.523; let my_frac_pi_8 = 0.3926990816987; + //~^ ERROR: approximate value of `f{32, 64}::consts::FRAC_PI_8` found let no_frac_pi_8 = 0.392; let my_ln_10 = 2.302585092994046; + //~^ ERROR: approximate value of `f{32, 64}::consts::LN_10` found let no_ln_10 = 2.303; let my_ln_2 = 0.6931471805599453; + //~^ ERROR: approximate value of `f{32, 64}::consts::LN_2` found let no_ln_2 = 0.693; let my_log10_e = 0.4342944819032518; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG10_E` found let no_log10_e = 0.434; let my_log2_e = 1.4426950408889634; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_E` found let no_log2_e = 1.442; let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found let no_log2_10 = 3.321; let log10_2 = 0.301029995663981; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG10_2` found let no_log10_2 = 0.301; let my_pi = 3.1415; + //~^ ERROR: approximate value of `f{32, 64}::consts::PI` found let almost_pi = 3.14; + //~^ ERROR: approximate value of `f{32, 64}::consts::PI` found let no_pi = 3.15; let my_sq2 = 1.4142; + //~^ ERROR: approximate value of `f{32, 64}::consts::SQRT_2` found let no_sq2 = 1.414; let my_tau = 6.2832; + //~^ ERROR: approximate value of `f{32, 64}::consts::TAU` found let almost_tau = 6.28; + //~^ ERROR: approximate value of `f{32, 64}::consts::TAU` found let no_tau = 6.3; } diff --git a/src/tools/clippy/tests/ui/approx_const.stderr b/src/tools/clippy/tests/ui/approx_const.stderr index 0932a2eec..4b5cd2a7a 100644 --- a/src/tools/clippy/tests/ui/approx_const.stderr +++ b/src/tools/clippy/tests/ui/approx_const.stderr @@ -6,9 +6,10 @@ LL | let my_e = 2.7182; | = help: consider using the constant directly = note: `-D clippy::approx-constant` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::approx_constant)]` error: approximate value of `f{32, 64}::consts::E` found - --> $DIR/approx_const.rs:5:20 + --> $DIR/approx_const.rs:6:20 | LL | let almost_e = 2.718; | ^^^^^ @@ -16,7 +17,7 @@ LL | let almost_e = 2.718; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_1_PI` found - --> $DIR/approx_const.rs:8:24 + --> $DIR/approx_const.rs:10:24 | LL | let my_1_frac_pi = 0.3183; | ^^^^^^ @@ -24,7 +25,7 @@ LL | let my_1_frac_pi = 0.3183; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found - --> $DIR/approx_const.rs:11:28 + --> $DIR/approx_const.rs:14:28 | LL | let my_frac_1_sqrt_2 = 0.70710678; | ^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | let my_frac_1_sqrt_2 = 0.70710678; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found - --> $DIR/approx_const.rs:12:32 + --> $DIR/approx_const.rs:16:32 | LL | let almost_frac_1_sqrt_2 = 0.70711; | ^^^^^^^ @@ -40,7 +41,7 @@ LL | let almost_frac_1_sqrt_2 = 0.70711; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_2_PI` found - --> $DIR/approx_const.rs:15:24 + --> $DIR/approx_const.rs:20:24 | LL | let my_frac_2_pi = 0.63661977; | ^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | let my_frac_2_pi = 0.63661977; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_2_SQRT_PI` found - --> $DIR/approx_const.rs:18:27 + --> $DIR/approx_const.rs:24:27 | LL | let my_frac_2_sq_pi = 1.128379; | ^^^^^^^^ @@ -56,7 +57,7 @@ LL | let my_frac_2_sq_pi = 1.128379; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_2` found - --> $DIR/approx_const.rs:21:24 + --> $DIR/approx_const.rs:28:24 | LL | let my_frac_pi_2 = 1.57079632679; | ^^^^^^^^^^^^^ @@ -64,7 +65,7 @@ LL | let my_frac_pi_2 = 1.57079632679; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_3` found - --> $DIR/approx_const.rs:24:24 + --> $DIR/approx_const.rs:32:24 | LL | let my_frac_pi_3 = 1.04719755119; | ^^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL | let my_frac_pi_3 = 1.04719755119; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_4` found - --> $DIR/approx_const.rs:27:24 + --> $DIR/approx_const.rs:36:24 | LL | let my_frac_pi_4 = 0.785398163397; | ^^^^^^^^^^^^^^ @@ -80,7 +81,7 @@ LL | let my_frac_pi_4 = 0.785398163397; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_6` found - --> $DIR/approx_const.rs:30:24 + --> $DIR/approx_const.rs:40:24 | LL | let my_frac_pi_6 = 0.523598775598; | ^^^^^^^^^^^^^^ @@ -88,7 +89,7 @@ LL | let my_frac_pi_6 = 0.523598775598; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::FRAC_PI_8` found - --> $DIR/approx_const.rs:33:24 + --> $DIR/approx_const.rs:44:24 | LL | let my_frac_pi_8 = 0.3926990816987; | ^^^^^^^^^^^^^^^ @@ -96,7 +97,7 @@ LL | let my_frac_pi_8 = 0.3926990816987; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LN_10` found - --> $DIR/approx_const.rs:36:20 + --> $DIR/approx_const.rs:48:20 | LL | let my_ln_10 = 2.302585092994046; | ^^^^^^^^^^^^^^^^^ @@ -104,7 +105,7 @@ LL | let my_ln_10 = 2.302585092994046; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LN_2` found - --> $DIR/approx_const.rs:39:19 + --> $DIR/approx_const.rs:52:19 | LL | let my_ln_2 = 0.6931471805599453; | ^^^^^^^^^^^^^^^^^^ @@ -112,7 +113,7 @@ LL | let my_ln_2 = 0.6931471805599453; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG10_E` found - --> $DIR/approx_const.rs:42:22 + --> $DIR/approx_const.rs:56:22 | LL | let my_log10_e = 0.4342944819032518; | ^^^^^^^^^^^^^^^^^^ @@ -120,7 +121,7 @@ LL | let my_log10_e = 0.4342944819032518; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_E` found - --> $DIR/approx_const.rs:45:21 + --> $DIR/approx_const.rs:60:21 | LL | let my_log2_e = 1.4426950408889634; | ^^^^^^^^^^^^^^^^^^ @@ -128,7 +129,7 @@ LL | let my_log2_e = 1.4426950408889634; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/approx_const.rs:48:19 + --> $DIR/approx_const.rs:64:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -136,7 +137,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG10_2` found - --> $DIR/approx_const.rs:51:19 + --> $DIR/approx_const.rs:68:19 | LL | let log10_2 = 0.301029995663981; | ^^^^^^^^^^^^^^^^^ @@ -144,7 +145,7 @@ LL | let log10_2 = 0.301029995663981; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::PI` found - --> $DIR/approx_const.rs:54:17 + --> $DIR/approx_const.rs:72:17 | LL | let my_pi = 3.1415; | ^^^^^^ @@ -152,7 +153,7 @@ LL | let my_pi = 3.1415; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::PI` found - --> $DIR/approx_const.rs:55:21 + --> $DIR/approx_const.rs:74:21 | LL | let almost_pi = 3.14; | ^^^^ @@ -160,7 +161,7 @@ LL | let almost_pi = 3.14; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::SQRT_2` found - --> $DIR/approx_const.rs:58:18 + --> $DIR/approx_const.rs:78:18 | LL | let my_sq2 = 1.4142; | ^^^^^^ @@ -168,7 +169,7 @@ LL | let my_sq2 = 1.4142; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::TAU` found - --> $DIR/approx_const.rs:61:18 + --> $DIR/approx_const.rs:82:18 | LL | let my_tau = 6.2832; | ^^^^^^ @@ -176,7 +177,7 @@ LL | let my_tau = 6.2832; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::TAU` found - --> $DIR/approx_const.rs:62:22 + --> $DIR/approx_const.rs:84:22 | LL | let almost_tau = 6.28; | ^^^^ diff --git a/src/tools/clippy/tests/ui/arc_with_non_send_sync.rs b/src/tools/clippy/tests/ui/arc_with_non_send_sync.rs index 2940c2732..d03a577c4 100644 --- a/src/tools/clippy/tests/ui/arc_with_non_send_sync.rs +++ b/src/tools/clippy/tests/ui/arc_with_non_send_sync.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::arc_with_non_send_sync)] #![allow(unused_variables)] diff --git a/src/tools/clippy/tests/ui/arc_with_non_send_sync.stderr b/src/tools/clippy/tests/ui/arc_with_non_send_sync.stderr index de3f2fb9e..fd239580d 100644 --- a/src/tools/clippy/tests/ui/arc_with_non_send_sync.stderr +++ b/src/tools/clippy/tests/ui/arc_with_non_send_sync.stderr @@ -8,6 +8,7 @@ LL | let _ = Arc::new(RefCell::new(42)); = note: required for `Arc>` to implement `Send` and `Sync` = help: consider using an `Rc` instead or wrapping the inner type with a `Mutex` = note: `-D clippy::arc-with-non-send-sync` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::arc_with_non_send_sync)]` error: usage of an `Arc` that is not `Send` or `Sync` --> $DIR/arc_with_non_send_sync.rs:40:13 diff --git a/src/tools/clippy/tests/ui/arithmetic_side_effects.rs b/src/tools/clippy/tests/ui/arithmetic_side_effects.rs index 2ac2fa220..b454c29ae 100644 --- a/src/tools/clippy/tests/ui/arithmetic_side_effects.rs +++ b/src/tools/clippy/tests/ui/arithmetic_side_effects.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![allow( clippy::assign_op_pattern, @@ -10,12 +10,12 @@ arithmetic_overflow, unconditional_panic )] -#![feature(const_mut_refs, inline_const, saturating_int_impl)] +#![feature(const_mut_refs, inline_const)] #![warn(clippy::arithmetic_side_effects)] extern crate proc_macro_derive; -use core::num::{Saturating, Wrapping}; +use core::num::{NonZeroUsize, Saturating, Wrapping}; const ONE: i32 = 1; const ZERO: i32 = 0; @@ -493,4 +493,32 @@ pub fn issue_11262() { let _ = 2 / zero; } +pub fn issue_11392() { + fn example_div(unsigned: usize, nonzero_unsigned: NonZeroUsize) -> usize { + unsigned / nonzero_unsigned + } + + fn example_rem(unsigned: usize, nonzero_unsigned: NonZeroUsize) -> usize { + unsigned % nonzero_unsigned + } + + let (unsigned, nonzero_unsigned) = (0, NonZeroUsize::new(1).unwrap()); + example_div(unsigned, nonzero_unsigned); + example_rem(unsigned, nonzero_unsigned); +} + +pub fn issue_11393() { + fn example_div(x: Wrapping, maybe_zero: Wrapping) -> Wrapping { + x / maybe_zero + } + + fn example_rem(x: Wrapping, maybe_zero: Wrapping) -> Wrapping { + x % maybe_zero + } + + let [x, maybe_zero] = [1, 0].map(Wrapping); + example_div(x, maybe_zero); + example_rem(x, maybe_zero); +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr b/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr index e9a626643..13729a6c5 100644 --- a/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr +++ b/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr @@ -5,6 +5,7 @@ LL | _n += 1; | ^^^^^^^ | = note: `-D clippy::arithmetic-side-effects` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]` error: arithmetic operation that can potentially result in unexpected side-effects --> $DIR/arithmetic_side_effects.rs:305:5 @@ -702,5 +703,17 @@ error: arithmetic operation that can potentially result in unexpected side-effec LL | 10 / a | ^^^^^^ -error: aborting due to 117 previous errors +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:512:9 + | +LL | x / maybe_zero + | ^^^^^^^^^^^^^^ + +error: arithmetic operation that can potentially result in unexpected side-effects + --> $DIR/arithmetic_side_effects.rs:516:9 + | +LL | x % maybe_zero + | ^^^^^^^^^^^^^^ + +error: aborting due to 119 previous errors diff --git a/src/tools/clippy/tests/ui/as_conversions.rs b/src/tools/clippy/tests/ui/as_conversions.rs index 69f1c541c..192eb51ea 100644 --- a/src/tools/clippy/tests/ui/as_conversions.rs +++ b/src/tools/clippy/tests/ui/as_conversions.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::as_conversions)] #![allow(clippy::borrow_as_ptr, unused)] diff --git a/src/tools/clippy/tests/ui/as_conversions.stderr b/src/tools/clippy/tests/ui/as_conversions.stderr index 54037a649..4bb964399 100644 --- a/src/tools/clippy/tests/ui/as_conversions.stderr +++ b/src/tools/clippy/tests/ui/as_conversions.stderr @@ -6,6 +6,7 @@ LL | let i = 0u32 as u64; | = help: consider using a safe wrapper for this conversion = note: `-D clippy::as-conversions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::as_conversions)]` error: using a potentially dangerous silent `as` conversion --> $DIR/as_conversions.rs:12:13 diff --git a/src/tools/clippy/tests/ui/as_ptr_cast_mut.rs b/src/tools/clippy/tests/ui/as_ptr_cast_mut.rs index 7d71947e4..297a53b1b 100644 --- a/src/tools/clippy/tests/ui/as_ptr_cast_mut.rs +++ b/src/tools/clippy/tests/ui/as_ptr_cast_mut.rs @@ -1,6 +1,7 @@ #![allow(unused)] #![warn(clippy::as_ptr_cast_mut)] #![allow(clippy::wrong_self_convention, clippy::unnecessary_cast)] +//@no-rustfix struct MutPtrWrapper(Vec); impl MutPtrWrapper { @@ -19,7 +20,10 @@ impl Covariant { fn main() { let mut string = String::new(); let _ = string.as_ptr() as *mut u8; + //~^ ERROR: casting the result of `as_ptr` to *mut u8 + //~| NOTE: `-D clippy::as-ptr-cast-mut` implied by `-D warnings` let _: *mut i8 = string.as_ptr() as *mut _; + //~^ ERROR: casting the result of `as_ptr` to *mut i8 let _ = string.as_ptr() as *const i8; let _ = string.as_mut_ptr(); let _ = string.as_mut_ptr() as *mut u8; diff --git a/src/tools/clippy/tests/ui/as_ptr_cast_mut.stderr b/src/tools/clippy/tests/ui/as_ptr_cast_mut.stderr index 2189c3d2f..92cdf9115 100644 --- a/src/tools/clippy/tests/ui/as_ptr_cast_mut.stderr +++ b/src/tools/clippy/tests/ui/as_ptr_cast_mut.stderr @@ -1,13 +1,14 @@ error: casting the result of `as_ptr` to *mut u8 - --> $DIR/as_ptr_cast_mut.rs:21:13 + --> $DIR/as_ptr_cast_mut.rs:22:13 | LL | let _ = string.as_ptr() as *mut u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `string.as_mut_ptr()` | = note: `-D clippy::as-ptr-cast-mut` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::as_ptr_cast_mut)]` error: casting the result of `as_ptr` to *mut i8 - --> $DIR/as_ptr_cast_mut.rs:22:22 + --> $DIR/as_ptr_cast_mut.rs:25:22 | LL | let _: *mut i8 = string.as_ptr() as *mut _; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `string.as_mut_ptr()` diff --git a/src/tools/clippy/tests/ui/as_underscore.fixed b/src/tools/clippy/tests/ui/as_underscore.fixed index 69af84a0e..c7f26e64c 100644 --- a/src/tools/clippy/tests/ui/as_underscore.fixed +++ b/src/tools/clippy/tests/ui/as_underscore.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::as_underscore)] fn foo(_n: usize) {} diff --git a/src/tools/clippy/tests/ui/as_underscore.rs b/src/tools/clippy/tests/ui/as_underscore.rs index a8cfb81d9..70f3b3866 100644 --- a/src/tools/clippy/tests/ui/as_underscore.rs +++ b/src/tools/clippy/tests/ui/as_underscore.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::as_underscore)] fn foo(_n: usize) {} diff --git a/src/tools/clippy/tests/ui/as_underscore.stderr b/src/tools/clippy/tests/ui/as_underscore.stderr index d7cd58d96..1842eeeac 100644 --- a/src/tools/clippy/tests/ui/as_underscore.stderr +++ b/src/tools/clippy/tests/ui/as_underscore.stderr @@ -1,5 +1,5 @@ error: using `as _` conversion - --> $DIR/as_underscore.rs:9:9 + --> $DIR/as_underscore.rs:7:9 | LL | foo(n as _); | ^^^^^- @@ -7,9 +7,10 @@ LL | foo(n as _); | help: consider giving the type explicitly: `usize` | = note: `-D clippy::as-underscore` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::as_underscore)]` error: using `as _` conversion - --> $DIR/as_underscore.rs:12:18 + --> $DIR/as_underscore.rs:10:18 | LL | let _n: u8 = n as _; | ^^^^^- diff --git a/src/tools/clippy/tests/ui/asm_syntax.rs b/src/tools/clippy/tests/ui/asm_syntax.rs index af02e202b..0a7eb86bc 100644 --- a/src/tools/clippy/tests/ui/asm_syntax.rs +++ b/src/tools/clippy/tests/ui/asm_syntax.rs @@ -6,8 +6,11 @@ mod warn_intel { pub(super) unsafe fn use_asm() { use std::arch::asm; asm!(""); + //~^ ERROR: Intel x86 assembly syntax used asm!("", options()); + //~^ ERROR: Intel x86 assembly syntax used asm!("", options(nostack)); + //~^ ERROR: Intel x86 assembly syntax used asm!("", options(att_syntax)); asm!("", options(nostack, att_syntax)); } @@ -21,7 +24,9 @@ mod warn_att { asm!("", options()); asm!("", options(nostack)); asm!("", options(att_syntax)); + //~^ ERROR: AT&T x86 assembly syntax used asm!("", options(nostack, att_syntax)); + //~^ ERROR: AT&T x86 assembly syntax used } } diff --git a/src/tools/clippy/tests/ui/asm_syntax.stderr b/src/tools/clippy/tests/ui/asm_syntax.stderr index 9c7c3ba7d..537ea8c57 100644 --- a/src/tools/clippy/tests/ui/asm_syntax.stderr +++ b/src/tools/clippy/tests/ui/asm_syntax.stderr @@ -6,9 +6,10 @@ LL | asm!(""); | = help: use AT&T x86 assembly syntax = note: `-D clippy::inline-asm-x86-intel-syntax` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inline_asm_x86_intel_syntax)]` error: Intel x86 assembly syntax used - --> $DIR/asm_syntax.rs:9:9 + --> $DIR/asm_syntax.rs:10:9 | LL | asm!("", options()); | ^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | asm!("", options()); = help: use AT&T x86 assembly syntax error: Intel x86 assembly syntax used - --> $DIR/asm_syntax.rs:10:9 + --> $DIR/asm_syntax.rs:12:9 | LL | asm!("", options(nostack)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,16 +25,17 @@ LL | asm!("", options(nostack)); = help: use AT&T x86 assembly syntax error: AT&T x86 assembly syntax used - --> $DIR/asm_syntax.rs:23:9 + --> $DIR/asm_syntax.rs:26:9 | LL | asm!("", options(att_syntax)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use Intel x86 assembly syntax = note: `-D clippy::inline-asm-x86-att-syntax` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inline_asm_x86_att_syntax)]` error: AT&T x86 assembly syntax used - --> $DIR/asm_syntax.rs:24:9 + --> $DIR/asm_syntax.rs:28:9 | LL | asm!("", options(nostack, att_syntax)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/assertions_on_constants.rs b/src/tools/clippy/tests/ui/assertions_on_constants.rs index 7bea9563d..10809a6d2 100644 --- a/src/tools/clippy/tests/ui/assertions_on_constants.rs +++ b/src/tools/clippy/tests/ui/assertions_on_constants.rs @@ -8,21 +8,30 @@ macro_rules! assert_const { } fn main() { assert!(true); + //~^ ERROR: `assert!(true)` will be optimized out by the compiler assert!(false); + //~^ ERROR: `assert!(false)` should probably be replaced assert!(true, "true message"); + //~^ ERROR: `assert!(true)` will be optimized out by the compiler assert!(false, "false message"); + //~^ ERROR: `assert!(false, ..)` should probably be replaced let msg = "panic message"; assert!(false, "{}", msg.to_uppercase()); + //~^ ERROR: `assert!(false, ..)` should probably be replaced const B: bool = true; assert!(B); + //~^ ERROR: `assert!(true)` will be optimized out by the compiler const C: bool = false; assert!(C); + //~^ ERROR: `assert!(false)` should probably be replaced assert!(C, "C message"); + //~^ ERROR: `assert!(false, ..)` should probably be replaced debug_assert!(true); + //~^ ERROR: `debug_assert!(true)` will be optimized out by the compiler // Don't lint this, since there is no better way for expressing "Only panic in debug mode". debug_assert!(false); // #3948 assert_const!(3); diff --git a/src/tools/clippy/tests/ui/assertions_on_constants.stderr b/src/tools/clippy/tests/ui/assertions_on_constants.stderr index 29fe00903..780d1fe1c 100644 --- a/src/tools/clippy/tests/ui/assertions_on_constants.stderr +++ b/src/tools/clippy/tests/ui/assertions_on_constants.stderr @@ -6,9 +6,10 @@ LL | assert!(true); | = help: remove it = note: `-D clippy::assertions-on-constants` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::assertions_on_constants)]` error: `assert!(false)` should probably be replaced - --> $DIR/assertions_on_constants.rs:11:5 + --> $DIR/assertions_on_constants.rs:12:5 | LL | assert!(false); | ^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | assert!(false); = help: use `panic!()` or `unreachable!()` error: `assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:12:5 + --> $DIR/assertions_on_constants.rs:14:5 | LL | assert!(true, "true message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | assert!(true, "true message"); = help: remove it error: `assert!(false, ..)` should probably be replaced - --> $DIR/assertions_on_constants.rs:13:5 + --> $DIR/assertions_on_constants.rs:16:5 | LL | assert!(false, "false message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | assert!(false, "false message"); = help: use `panic!(..)` or `unreachable!(..)` error: `assert!(false, ..)` should probably be replaced - --> $DIR/assertions_on_constants.rs:16:5 + --> $DIR/assertions_on_constants.rs:20:5 | LL | assert!(false, "{}", msg.to_uppercase()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | assert!(false, "{}", msg.to_uppercase()); = help: use `panic!(..)` or `unreachable!(..)` error: `assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:19:5 + --> $DIR/assertions_on_constants.rs:24:5 | LL | assert!(B); | ^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | assert!(B); = help: remove it error: `assert!(false)` should probably be replaced - --> $DIR/assertions_on_constants.rs:22:5 + --> $DIR/assertions_on_constants.rs:28:5 | LL | assert!(C); | ^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | assert!(C); = help: use `panic!()` or `unreachable!()` error: `assert!(false, ..)` should probably be replaced - --> $DIR/assertions_on_constants.rs:23:5 + --> $DIR/assertions_on_constants.rs:30:5 | LL | assert!(C, "C message"); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +65,7 @@ LL | assert!(C, "C message"); = help: use `panic!(..)` or `unreachable!(..)` error: `debug_assert!(true)` will be optimized out by the compiler - --> $DIR/assertions_on_constants.rs:25:5 + --> $DIR/assertions_on_constants.rs:33:5 | LL | debug_assert!(true); | ^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/assertions_on_result_states.fixed b/src/tools/clippy/tests/ui/assertions_on_result_states.fixed index 3152bd3ca..14d9b8b99 100644 --- a/src/tools/clippy/tests/ui/assertions_on_result_states.fixed +++ b/src/tools/clippy/tests/ui/assertions_on_result_states.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::assertions_on_result_states)] #![allow(clippy::unnecessary_literal_unwrap)] diff --git a/src/tools/clippy/tests/ui/assertions_on_result_states.rs b/src/tools/clippy/tests/ui/assertions_on_result_states.rs index 42755e935..ac1911d87 100644 --- a/src/tools/clippy/tests/ui/assertions_on_result_states.rs +++ b/src/tools/clippy/tests/ui/assertions_on_result_states.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::assertions_on_result_states)] #![allow(clippy::unnecessary_literal_unwrap)] diff --git a/src/tools/clippy/tests/ui/assertions_on_result_states.stderr b/src/tools/clippy/tests/ui/assertions_on_result_states.stderr index be581030c..23af51cfe 100644 --- a/src/tools/clippy/tests/ui/assertions_on_result_states.stderr +++ b/src/tools/clippy/tests/ui/assertions_on_result_states.stderr @@ -1,43 +1,44 @@ error: called `assert!` with `Result::is_ok` - --> $DIR/assertions_on_result_states.rs:25:5 + --> $DIR/assertions_on_result_states.rs:24:5 | LL | assert!(r.is_ok()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()` | = note: `-D clippy::assertions-on-result-states` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::assertions_on_result_states)]` error: called `assert!` with `Result::is_ok` - --> $DIR/assertions_on_result_states.rs:43:5 + --> $DIR/assertions_on_result_states.rs:42:5 | LL | assert!(get_ok().is_ok()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `get_ok().unwrap()` error: called `assert!` with `Result::is_ok` - --> $DIR/assertions_on_result_states.rs:46:5 + --> $DIR/assertions_on_result_states.rs:45:5 | 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:59:5 + --> $DIR/assertions_on_result_states.rs:58:5 | LL | assert!(r.is_ok()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()` error: called `assert!` with `Result::is_ok` - --> $DIR/assertions_on_result_states.rs:65:9 + --> $DIR/assertions_on_result_states.rs:64:9 | LL | assert!(r.is_ok()); | ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()` error: called `assert!` with `Result::is_err` - --> $DIR/assertions_on_result_states.rs:73:5 + --> $DIR/assertions_on_result_states.rs:72: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:83:5 + --> $DIR/assertions_on_result_states.rs:82:5 | LL | assert!(res.is_err()) | ^^^^^^^^^^^^^^^^^^^^^ help: replace with: `res.unwrap_err();` diff --git a/src/tools/clippy/tests/ui/assign_ops.fixed b/src/tools/clippy/tests/ui/assign_ops.fixed index ef45e97d1..2bd0807f4 100644 --- a/src/tools/clippy/tests/ui/assign_ops.fixed +++ b/src/tools/clippy/tests/ui/assign_ops.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - use core::num::Wrapping; #[allow(dead_code, unused_assignments, clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/assign_ops.rs b/src/tools/clippy/tests/ui/assign_ops.rs index ae87afc48..be3491a44 100644 --- a/src/tools/clippy/tests/ui/assign_ops.rs +++ b/src/tools/clippy/tests/ui/assign_ops.rs @@ -1,5 +1,3 @@ -//@run-rustfix - use core::num::Wrapping; #[allow(dead_code, unused_assignments, clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/assign_ops.stderr b/src/tools/clippy/tests/ui/assign_ops.stderr index 63a938ab4..e021e1bab 100644 --- a/src/tools/clippy/tests/ui/assign_ops.stderr +++ b/src/tools/clippy/tests/ui/assign_ops.stderr @@ -1,67 +1,68 @@ error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:9:5 + --> $DIR/assign_ops.rs:7:5 | LL | a = a + 1; | ^^^^^^^^^ help: replace it with: `a += 1` | = note: `-D clippy::assign-op-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:10:5 + --> $DIR/assign_ops.rs:8:5 | LL | a = 1 + a; | ^^^^^^^^^ help: replace it with: `a += 1` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:11:5 + --> $DIR/assign_ops.rs:9:5 | LL | a = a - 1; | ^^^^^^^^^ help: replace it with: `a -= 1` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:12:5 + --> $DIR/assign_ops.rs:10:5 | LL | a = a * 99; | ^^^^^^^^^^ help: replace it with: `a *= 99` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:13:5 + --> $DIR/assign_ops.rs:11:5 | LL | a = 42 * a; | ^^^^^^^^^^ help: replace it with: `a *= 42` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:14:5 + --> $DIR/assign_ops.rs:12:5 | LL | a = a / 2; | ^^^^^^^^^ help: replace it with: `a /= 2` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:15:5 + --> $DIR/assign_ops.rs:13:5 | LL | a = a % 5; | ^^^^^^^^^ help: replace it with: `a %= 5` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:16:5 + --> $DIR/assign_ops.rs:14:5 | LL | a = a & 1; | ^^^^^^^^^ help: replace it with: `a &= 1` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:22:5 + --> $DIR/assign_ops.rs:20:5 | LL | s = s + "bla"; | ^^^^^^^^^^^^^ help: replace it with: `s += "bla"` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:26:5 + --> $DIR/assign_ops.rs:24:5 | LL | a = a + Wrapping(1u32); | ^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a += Wrapping(1u32)` error: manual implementation of an assign operation - --> $DIR/assign_ops.rs:28:5 + --> $DIR/assign_ops.rs:26:5 | LL | v[0] = v[0] + v[1]; | ^^^^^^^^^^^^^^^^^^ help: replace it with: `v[0] += v[1]` diff --git a/src/tools/clippy/tests/ui/assign_ops2.rs b/src/tools/clippy/tests/ui/assign_ops2.rs index 2c876a96c..a53556425 100644 --- a/src/tools/clippy/tests/ui/assign_ops2.rs +++ b/src/tools/clippy/tests/ui/assign_ops2.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![allow(clippy::uninlined_format_args)] #[allow(unused_assignments)] @@ -5,14 +6,24 @@ fn main() { let mut a = 5; a += a + 1; + //~^ ERROR: variable appears on both sides of an assignment operation + //~| NOTE: `-D clippy::misrefactored-assign-op` implied by `-D warnings` a += 1 + a; + //~^ ERROR: variable appears on both sides of an assignment operation a -= a - 1; + //~^ ERROR: variable appears on both sides of an assignment operation a *= a * 99; + //~^ ERROR: variable appears on both sides of an assignment operation a *= 42 * a; + //~^ ERROR: variable appears on both sides of an assignment operation a /= a / 2; + //~^ ERROR: variable appears on both sides of an assignment operation a %= a % 5; + //~^ ERROR: variable appears on both sides of an assignment operation a &= a & 1; + //~^ ERROR: variable appears on both sides of an assignment operation a *= a * a; + //~^ ERROR: variable appears on both sides of an assignment operation a = a * a * a; a = a * 42 * a; a = a * 2 + a; @@ -50,6 +61,8 @@ fn cow_add_assign() { // this can be linted buf = buf + cows.clone(); + //~^ ERROR: manual implementation of an assign operation + //~| NOTE: `-D clippy::assign-op-pattern` implied by `-D warnings` // this should not as cow Add is not commutative buf = cows + buf; diff --git a/src/tools/clippy/tests/ui/assign_ops2.stderr b/src/tools/clippy/tests/ui/assign_ops2.stderr index 25e746022..6e9b96c0a 100644 --- a/src/tools/clippy/tests/ui/assign_ops2.stderr +++ b/src/tools/clippy/tests/ui/assign_ops2.stderr @@ -1,10 +1,11 @@ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:7:5 + --> $DIR/assign_ops2.rs:8:5 | LL | a += a + 1; | ^^^^^^^^^^ | = note: `-D clippy::misrefactored-assign-op` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::misrefactored_assign_op)]` help: did you mean `a = a + 1` or `a = a + a + 1`? Consider replacing it with | LL | a += 1; @@ -15,7 +16,7 @@ LL | a = a + a + 1; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:8:5 + --> $DIR/assign_ops2.rs:11:5 | LL | a += 1 + a; | ^^^^^^^^^^ @@ -30,7 +31,7 @@ LL | a = a + 1 + a; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:9:5 + --> $DIR/assign_ops2.rs:13:5 | LL | a -= a - 1; | ^^^^^^^^^^ @@ -45,7 +46,7 @@ LL | a = a - (a - 1); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:10:5 + --> $DIR/assign_ops2.rs:15:5 | LL | a *= a * 99; | ^^^^^^^^^^^ @@ -60,7 +61,7 @@ LL | a = a * a * 99; | ~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:11:5 + --> $DIR/assign_ops2.rs:17:5 | LL | a *= 42 * a; | ^^^^^^^^^^^ @@ -75,7 +76,7 @@ LL | a = a * 42 * a; | ~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:12:5 + --> $DIR/assign_ops2.rs:19:5 | LL | a /= a / 2; | ^^^^^^^^^^ @@ -90,7 +91,7 @@ LL | a = a / (a / 2); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:13:5 + --> $DIR/assign_ops2.rs:21:5 | LL | a %= a % 5; | ^^^^^^^^^^ @@ -105,7 +106,7 @@ LL | a = a % (a % 5); | ~~~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:14:5 + --> $DIR/assign_ops2.rs:23:5 | LL | a &= a & 1; | ^^^^^^^^^^ @@ -120,7 +121,7 @@ LL | a = a & a & 1; | ~~~~~~~~~~~~~ error: variable appears on both sides of an assignment operation - --> $DIR/assign_ops2.rs:15:5 + --> $DIR/assign_ops2.rs:25:5 | LL | a *= a * a; | ^^^^^^^^^^ @@ -135,12 +136,13 @@ LL | a = a * a * a; | ~~~~~~~~~~~~~ error: manual implementation of an assign operation - --> $DIR/assign_ops2.rs:52:5 + --> $DIR/assign_ops2.rs:63:5 | LL | buf = buf + cows.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()` | = note: `-D clippy::assign-op-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]` error: aborting due to 10 previous errors diff --git a/src/tools/clippy/tests/ui/async_yields_async.fixed b/src/tools/clippy/tests/ui/async_yields_async.fixed index 8d9b02389..cfad78138 100644 --- a/src/tools/clippy/tests/ui/async_yields_async.fixed +++ b/src/tools/clippy/tests/ui/async_yields_async.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(lint_reasons)] #![feature(async_closure)] #![warn(clippy::async_yields_async)] diff --git a/src/tools/clippy/tests/ui/async_yields_async.rs b/src/tools/clippy/tests/ui/async_yields_async.rs index bed79062f..7bc266479 100644 --- a/src/tools/clippy/tests/ui/async_yields_async.rs +++ b/src/tools/clippy/tests/ui/async_yields_async.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(lint_reasons)] #![feature(async_closure)] #![warn(clippy::async_yields_async)] diff --git a/src/tools/clippy/tests/ui/async_yields_async.stderr b/src/tools/clippy/tests/ui/async_yields_async.stderr index 7f7253483..c29e3c734 100644 --- a/src/tools/clippy/tests/ui/async_yields_async.stderr +++ b/src/tools/clippy/tests/ui/async_yields_async.stderr @@ -1,5 +1,5 @@ error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:40:9 + --> $DIR/async_yields_async.rs:39:9 | LL | let _h = async { | _____________________- @@ -11,6 +11,7 @@ LL | | }; | |______- outer async construct | = note: `-D clippy::async-yields-async` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::async_yields_async)]` help: consider awaiting this value | LL ~ async { @@ -19,7 +20,7 @@ LL + }.await | error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:45:9 + --> $DIR/async_yields_async.rs:44:9 | LL | let _i = async { | ____________________- @@ -32,7 +33,7 @@ LL | | }; | |_____- outer async construct error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:51:9 + --> $DIR/async_yields_async.rs:50:9 | LL | let _j = async || { | ________________________- @@ -51,7 +52,7 @@ LL + }.await | error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:56:9 + --> $DIR/async_yields_async.rs:55:9 | LL | let _k = async || { | _______________________- @@ -64,7 +65,7 @@ LL | | }; | |_____- outer async construct error: an async construct yields a type which is itself awaitable - --> $DIR/async_yields_async.rs:58:23 + --> $DIR/async_yields_async.rs:57:23 | LL | let _l = async || CustomFutureType; | ^^^^^^^^^^^^^^^^ @@ -74,7 +75,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:64:9 + --> $DIR/async_yields_async.rs:63:9 | LL | let _m = async || { | _______________________- diff --git a/src/tools/clippy/tests/ui/attrs.rs b/src/tools/clippy/tests/ui/attrs.rs index 8df6e1942..05ee48d17 100644 --- a/src/tools/clippy/tests/ui/attrs.rs +++ b/src/tools/clippy/tests/ui/attrs.rs @@ -3,6 +3,8 @@ #![allow(clippy::missing_docs_in_private_items, clippy::panic, clippy::unreachable)] #[inline(always)] +//~^ ERROR: you have declared `#[inline(always)]` on `test_attr_lint`. This is usually a b +//~| NOTE: `-D clippy::inline-always` implied by `-D warnings` fn test_attr_lint() { assert!(true) } @@ -23,9 +25,12 @@ fn empty_and_false_positive_stmt() { } #[deprecated(since = "forever")] +//~^ ERROR: the since field must contain a semver-compliant version +//~| NOTE: `-D clippy::deprecated-semver` implied by `-D warnings` pub const SOME_CONST: u8 = 42; #[deprecated(since = "1")] +//~^ ERROR: the since field must contain a semver-compliant version pub const ANOTHER_CONST: u8 = 23; #[deprecated(since = "0.1.1")] diff --git a/src/tools/clippy/tests/ui/attrs.stderr b/src/tools/clippy/tests/ui/attrs.stderr index df4e9e20b..16402a4dd 100644 --- a/src/tools/clippy/tests/ui/attrs.stderr +++ b/src/tools/clippy/tests/ui/attrs.stderr @@ -5,17 +5,19 @@ LL | #[inline(always)] | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::inline-always` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inline_always)]` error: the since field must contain a semver-compliant version - --> $DIR/attrs.rs:25:14 + --> $DIR/attrs.rs:27:14 | LL | #[deprecated(since = "forever")] | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::deprecated-semver` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::deprecated_semver)]` error: the since field must contain a semver-compliant version - --> $DIR/attrs.rs:28:14 + --> $DIR/attrs.rs:32:14 | LL | #[deprecated(since = "1")] | ^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/await_holding_lock.rs b/src/tools/clippy/tests/ui/await_holding_lock.rs index 57e5b5504..27b57b648 100644 --- a/src/tools/clippy/tests/ui/await_holding_lock.rs +++ b/src/tools/clippy/tests/ui/await_holding_lock.rs @@ -7,6 +7,7 @@ mod std_mutex { pub async fn bad(x: &Mutex) -> u32 { let guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } @@ -22,11 +23,13 @@ mod std_mutex { pub async fn bad_rw(x: &RwLock) -> u32 { let guard = x.read().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } pub async fn bad_rw_write(x: &RwLock) -> u32 { let mut guard = x.write().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } @@ -48,6 +51,7 @@ mod std_mutex { let first = baz().await; let guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point let second = baz().await; @@ -61,6 +65,7 @@ mod std_mutex { let second = { let guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await }; @@ -73,6 +78,7 @@ mod std_mutex { pub fn block_bad(x: &Mutex) -> impl std::future::Future + '_ { async move { let guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } } @@ -85,6 +91,7 @@ mod parking_lot_mutex { pub async fn bad(x: &Mutex) -> u32 { let guard = x.lock(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } @@ -100,11 +107,13 @@ mod parking_lot_mutex { pub async fn bad_rw(x: &RwLock) -> u32 { let guard = x.read(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } pub async fn bad_rw_write(x: &RwLock) -> u32 { let mut guard = x.write(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } @@ -126,6 +135,7 @@ mod parking_lot_mutex { let first = baz().await; let guard = x.lock(); + //~^ ERROR: this `MutexGuard` is held across an `await` point let second = baz().await; @@ -139,6 +149,7 @@ mod parking_lot_mutex { let second = { let guard = x.lock(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await }; @@ -151,6 +162,7 @@ mod parking_lot_mutex { pub fn block_bad(x: &Mutex) -> impl std::future::Future + '_ { async move { let guard = x.lock(); + //~^ ERROR: this `MutexGuard` is held across an `await` point baz().await } } @@ -171,6 +183,7 @@ async fn no_await(x: std::sync::Mutex) { // `*guard += 1` is removed it is picked up. async fn dropped_before_await(x: std::sync::Mutex) { let mut guard = x.lock().unwrap(); + //~^ ERROR: this `MutexGuard` is held across an `await` point *guard += 1; drop(guard); baz().await; diff --git a/src/tools/clippy/tests/ui/await_holding_lock.stderr b/src/tools/clippy/tests/ui/await_holding_lock.stderr index 81a2d0524..478210400 100644 --- a/src/tools/clippy/tests/ui/await_holding_lock.stderr +++ b/src/tools/clippy/tests/ui/await_holding_lock.stderr @@ -6,203 +6,174 @@ LL | let guard = x.lock().unwrap(); | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:9:9 + --> $DIR/await_holding_lock.rs:11:15 | -LL | / let guard = x.lock().unwrap(); -LL | | baz().await -LL | | } - | |_____^ +LL | baz().await + | ^^^^^ = note: `-D clippy::await-holding-lock` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::await_holding_lock)]` error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:24:13 + --> $DIR/await_holding_lock.rs:25:13 | LL | let guard = x.read().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:24:9 + --> $DIR/await_holding_lock.rs:27:15 | -LL | / let guard = x.read().unwrap(); -LL | | baz().await -LL | | } - | |_____^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:29:13 + --> $DIR/await_holding_lock.rs:31:13 | LL | let mut guard = x.write().unwrap(); | ^^^^^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:29:9 + --> $DIR/await_holding_lock.rs:33:15 | -LL | / let mut guard = x.write().unwrap(); -LL | | baz().await -LL | | } - | |_____^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:50:13 + --> $DIR/await_holding_lock.rs:53:13 | LL | let guard = x.lock().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:50:9 - | -LL | / let guard = x.lock().unwrap(); -LL | | -LL | | let second = baz().await; -LL | | -... | -LL | | first + second + third -LL | | } - | |_____^ + --> $DIR/await_holding_lock.rs:56:28 + | +LL | let second = baz().await; + | ^^^^^ +LL | +LL | let third = baz().await; + | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:63:17 + --> $DIR/await_holding_lock.rs:67:17 | LL | let guard = x.lock().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:63:13 + --> $DIR/await_holding_lock.rs:69:19 | -LL | / let guard = x.lock().unwrap(); -LL | | baz().await -LL | | }; - | |_________^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:75:17 + --> $DIR/await_holding_lock.rs:80:17 | LL | let guard = x.lock().unwrap(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:75:13 + --> $DIR/await_holding_lock.rs:82:19 | -LL | / let guard = x.lock().unwrap(); -LL | | baz().await -LL | | } - | |_________^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:87:13 + --> $DIR/await_holding_lock.rs:93:13 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:87:9 + --> $DIR/await_holding_lock.rs:95:15 | -LL | / let guard = x.lock(); -LL | | baz().await -LL | | } - | |_____^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:102:13 + --> $DIR/await_holding_lock.rs:109:13 | LL | let guard = x.read(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:102:9 + --> $DIR/await_holding_lock.rs:111:15 | -LL | / let guard = x.read(); -LL | | baz().await -LL | | } - | |_____^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:107:13 + --> $DIR/await_holding_lock.rs:115:13 | LL | let mut guard = x.write(); | ^^^^^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:107:9 + --> $DIR/await_holding_lock.rs:117:15 | -LL | / let mut guard = x.write(); -LL | | baz().await -LL | | } - | |_____^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:128:13 + --> $DIR/await_holding_lock.rs:137:13 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:128:9 - | -LL | / let guard = x.lock(); -LL | | -LL | | let second = baz().await; -LL | | -... | -LL | | first + second + third -LL | | } - | |_____^ + --> $DIR/await_holding_lock.rs:140:28 + | +LL | let second = baz().await; + | ^^^^^ +LL | +LL | let third = baz().await; + | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:141:17 + --> $DIR/await_holding_lock.rs:151:17 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:141:13 + --> $DIR/await_holding_lock.rs:153:19 | -LL | / let guard = x.lock(); -LL | | baz().await -LL | | }; - | |_________^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:153:17 + --> $DIR/await_holding_lock.rs:164:17 | LL | let guard = x.lock(); | ^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:153:13 + --> $DIR/await_holding_lock.rs:166:19 | -LL | / let guard = x.lock(); -LL | | baz().await -LL | | } - | |_________^ +LL | baz().await + | ^^^^^ error: this `MutexGuard` is held across an `await` point - --> $DIR/await_holding_lock.rs:173:9 + --> $DIR/await_holding_lock.rs:185:9 | LL | let mut guard = x.lock().unwrap(); | ^^^^^^^^^ | = help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await note: these are all the `await` points this lock is held through - --> $DIR/await_holding_lock.rs:173:5 - | -LL | / let mut guard = x.lock().unwrap(); -LL | | *guard += 1; -LL | | drop(guard); -LL | | baz().await; -LL | | } - | |_^ + --> $DIR/await_holding_lock.rs:189:11 + | +LL | baz().await; + | ^^^^^ error: aborting due to 13 previous errors diff --git a/src/tools/clippy/tests/ui/await_holding_refcell_ref.rs b/src/tools/clippy/tests/ui/await_holding_refcell_ref.rs index 23b7095de..5bd26c628 100644 --- a/src/tools/clippy/tests/ui/await_holding_refcell_ref.rs +++ b/src/tools/clippy/tests/ui/await_holding_refcell_ref.rs @@ -4,11 +4,13 @@ use std::cell::RefCell; async fn bad(x: &RefCell) -> u32 { let b = x.borrow(); + //~^ ERROR: this `RefCell` reference is held across an `await` point baz().await } async fn bad_mut(x: &RefCell) -> u32 { let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point baz().await } @@ -30,6 +32,7 @@ async fn also_bad(x: &RefCell) -> u32 { let first = baz().await; let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point let second = baz().await; @@ -42,6 +45,7 @@ async fn less_bad(x: &RefCell) -> u32 { let first = baz().await; let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point let second = baz().await; @@ -57,6 +61,7 @@ async fn not_good(x: &RefCell) -> u32 { let second = { let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point baz().await }; @@ -69,6 +74,7 @@ async fn not_good(x: &RefCell) -> u32 { fn block_bad(x: &RefCell) -> impl std::future::Future + '_ { async move { let b = x.borrow_mut(); + //~^ ERROR: this `RefCell` reference is held across an `await` point baz().await } } diff --git a/src/tools/clippy/tests/ui/await_holding_refcell_ref.stderr b/src/tools/clippy/tests/ui/await_holding_refcell_ref.stderr index 25c15ab80..9264af93d 100644 --- a/src/tools/clippy/tests/ui/await_holding_refcell_ref.stderr +++ b/src/tools/clippy/tests/ui/await_holding_refcell_ref.stderr @@ -6,96 +6,80 @@ LL | let b = x.borrow(); | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:6:5 + --> $DIR/await_holding_refcell_ref.rs:8:11 | -LL | / let b = x.borrow(); -LL | | baz().await -LL | | } - | |_^ +LL | baz().await + | ^^^^^ = note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::await_holding_refcell_ref)]` error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:11:9 + --> $DIR/await_holding_refcell_ref.rs:12:9 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:11:5 + --> $DIR/await_holding_refcell_ref.rs:14:11 | -LL | / let b = x.borrow_mut(); -LL | | baz().await -LL | | } - | |_^ +LL | baz().await + | ^^^^^ error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:32:9 + --> $DIR/await_holding_refcell_ref.rs:34:9 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:32:5 - | -LL | / let b = x.borrow_mut(); -LL | | -LL | | let second = baz().await; -LL | | -... | -LL | | first + second + third -LL | | } - | |_^ + --> $DIR/await_holding_refcell_ref.rs:37:24 + | +LL | let second = baz().await; + | ^^^^^ +LL | +LL | let third = baz().await; + | ^^^^^ error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:44:9 + --> $DIR/await_holding_refcell_ref.rs:47:9 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:44:5 - | -LL | / let b = x.borrow_mut(); -LL | | -LL | | let second = baz().await; -LL | | -... | -LL | | first + second + third -LL | | } - | |_^ + --> $DIR/await_holding_refcell_ref.rs:50:24 + | +LL | let second = baz().await; + | ^^^^^ error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:59:13 + --> $DIR/await_holding_refcell_ref.rs:63:13 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:59:9 + --> $DIR/await_holding_refcell_ref.rs:65:15 | -LL | / let b = x.borrow_mut(); -LL | | baz().await -LL | | }; - | |_____^ +LL | baz().await + | ^^^^^ error: this `RefCell` reference is held across an `await` point - --> $DIR/await_holding_refcell_ref.rs:71:13 + --> $DIR/await_holding_refcell_ref.rs:76:13 | LL | let b = x.borrow_mut(); | ^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through - --> $DIR/await_holding_refcell_ref.rs:71:9 + --> $DIR/await_holding_refcell_ref.rs:78:15 | -LL | / let b = x.borrow_mut(); -LL | | baz().await -LL | | } - | |_____^ +LL | baz().await + | ^^^^^ error: aborting due to 6 previous errors diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map.fixed b/src/tools/clippy/tests/ui/bind_instead_of_map.fixed index ea2dc2e22..910cec2f2 100644 --- a/src/tools/clippy/tests/ui/bind_instead_of_map.fixed +++ b/src/tools/clippy/tests/ui/bind_instead_of_map.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::bind_instead_of_map)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map.rs b/src/tools/clippy/tests/ui/bind_instead_of_map.rs index 1db58dae5..6d66f659b 100644 --- a/src/tools/clippy/tests/ui/bind_instead_of_map.rs +++ b/src/tools/clippy/tests/ui/bind_instead_of_map.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::bind_instead_of_map)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map.stderr b/src/tools/clippy/tests/ui/bind_instead_of_map.stderr index f17fee746..3af61e6d4 100644 --- a/src/tools/clippy/tests/ui/bind_instead_of_map.stderr +++ b/src/tools/clippy/tests/ui/bind_instead_of_map.stderr @@ -1,23 +1,23 @@ error: using `Option.and_then(Some)`, which is a no-op - --> $DIR/bind_instead_of_map.rs:9:13 + --> $DIR/bind_instead_of_map.rs:8:13 | LL | let _ = x.and_then(Some); | ^^^^^^^^^^^^^^^^ help: use the expression directly: `x` | note: the lint level is defined here - --> $DIR/bind_instead_of_map.rs:2:9 + --> $DIR/bind_instead_of_map.rs:1:9 | LL | #![deny(clippy::bind_instead_of_map)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` - --> $DIR/bind_instead_of_map.rs:10:13 + --> $DIR/bind_instead_of_map.rs:9:13 | LL | let _ = x.and_then(|o| Some(o + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.map(|o| o + 1)` error: using `Result.and_then(Ok)`, which is a no-op - --> $DIR/bind_instead_of_map.rs:16:13 + --> $DIR/bind_instead_of_map.rs:15:13 | LL | let _ = x.and_then(Ok); | ^^^^^^^^^^^^^^ help: use the expression directly: `x` diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.fixed b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.fixed index 63c7aafcd..8cbadc67d 100644 --- a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.fixed +++ b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::bind_instead_of_map)] #![allow(clippy::blocks_in_if_conditions)] diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.rs b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.rs index 69b982fa8..91d9d11e3 100644 --- a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.rs +++ b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::bind_instead_of_map)] #![allow(clippy::blocks_in_if_conditions)] diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.stderr b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.stderr index cedbca785..63f25f26f 100644 --- a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.stderr +++ b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.stderr @@ -1,11 +1,11 @@ error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` - --> $DIR/bind_instead_of_map_multipart.rs:6:13 + --> $DIR/bind_instead_of_map_multipart.rs:5:13 | LL | let _ = Some("42").and_then(|s| if s.len() < 42 { Some(0) } else { Some(s.len()) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/bind_instead_of_map_multipart.rs:2:9 + --> $DIR/bind_instead_of_map_multipart.rs:1:9 | LL | #![deny(clippy::bind_instead_of_map)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -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:9:13 + --> $DIR/bind_instead_of_map_multipart.rs:8: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:12:13 + --> $DIR/bind_instead_of_map_multipart.rs:11: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:20:5 + --> $DIR/bind_instead_of_map_multipart.rs:19: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:61:13 + --> $DIR/bind_instead_of_map_multipart.rs:60:13 | LL | let _ = Some("").and_then(|s| if s.len() == 20 { Some(m!()) } else { Some(Some(20)) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/bit_masks.rs b/src/tools/clippy/tests/ui/bit_masks.rs index cfb493fb5..8e1d066c2 100644 --- a/src/tools/clippy/tests/ui/bit_masks.rs +++ b/src/tools/clippy/tests/ui/bit_masks.rs @@ -12,19 +12,27 @@ fn main() { let x = 5; x & 0 == 0; + //~^ ERROR: &-masking with zero + //~| NOTE: `-D clippy::bad-bit-mask` implied by `-D warnings` + //~| ERROR: this operation will always return zero. This is likely not the intended ou + //~| NOTE: `#[deny(clippy::erasing_op)]` on by default x & 1 == 1; //ok, distinguishes bit 0 x & 1 == 0; //ok, compared with zero x & 2 == 1; + //~^ ERROR: incompatible bit mask: `_ & 2` can never be equal to `1` x | 0 == 0; //ok, equals x == 0 (maybe warn?) x | 1 == 3; //ok, equals x == 2 || x == 3 x | 3 == 3; //ok, equals x <= 3 x | 3 == 2; + //~^ ERROR: incompatible bit mask: `_ | 3` can never be equal to `2` x & 1 > 1; + //~^ ERROR: incompatible bit mask: `_ & 1` will never be higher than `1` x & 2 > 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0 x & 2 < 1; // ok, distinguishes x & 2 == 2 from x & 2 == 0 x | 1 > 1; // ok (if a bit silly), equals x > 1 x | 2 > 1; + //~^ ERROR: incompatible bit mask: `_ | 2` will always be higher than `1` x | 2 <= 2; // ok (if a bit silly), equals x <= 2 x & 192 == 128; // ok, tests for bit 7 and not bit 6 @@ -32,15 +40,22 @@ fn main() { // this also now works with constants x & THREE_BITS == 8; + //~^ ERROR: incompatible bit mask: `_ & 7` can never be equal to `8` x | EVEN_MORE_REDIRECTION < 7; + //~^ ERROR: incompatible bit mask: `_ | 7` will never be lower than `7` 0 & x == 0; + //~^ ERROR: &-masking with zero + //~| ERROR: this operation will always return zero. This is likely not the intended ou 1 | x > 1; // and should now also match uncommon usage 1 < 2 | x; + //~^ ERROR: incompatible bit mask: `_ | 2` will always be higher than `1` 2 == 3 | x; + //~^ ERROR: incompatible bit mask: `_ | 3` can never be equal to `2` 1 == x & 2; + //~^ ERROR: incompatible bit mask: `_ & 2` can never be equal to `1` x | 1 > 2; // no error, because we allowed ineffective bit masks ineffective(); @@ -52,9 +67,14 @@ fn ineffective() { let x = 5; x | 1 > 3; + //~^ ERROR: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared d + //~| NOTE: `-D clippy::ineffective-bit-mask` implied by `-D warnings` x | 1 < 4; + //~^ ERROR: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared d x | 1 <= 3; + //~^ ERROR: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared d x | 1 >= 8; + //~^ ERROR: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared d x | 1 > 2; // not an error (yet), better written as x >= 2 x | 1 >= 7; // not an error (yet), better written as x >= 6 diff --git a/src/tools/clippy/tests/ui/bit_masks.stderr b/src/tools/clippy/tests/ui/bit_masks.stderr index dc5ad6dfb..4423d15d7 100644 --- a/src/tools/clippy/tests/ui/bit_masks.stderr +++ b/src/tools/clippy/tests/ui/bit_masks.stderr @@ -5,6 +5,7 @@ LL | x & 0 == 0; | ^^^^^^^^^^ | = note: `-D clippy::bad-bit-mask` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::bad_bit_mask)]` error: this operation will always return zero. This is likely not the intended outcome --> $DIR/bit_masks.rs:14:5 @@ -15,93 +16,94 @@ LL | x & 0 == 0; = note: `#[deny(clippy::erasing_op)]` on by default error: incompatible bit mask: `_ & 2` can never be equal to `1` - --> $DIR/bit_masks.rs:17:5 + --> $DIR/bit_masks.rs:21:5 | LL | x & 2 == 1; | ^^^^^^^^^^ error: incompatible bit mask: `_ | 3` can never be equal to `2` - --> $DIR/bit_masks.rs:21:5 + --> $DIR/bit_masks.rs:26:5 | LL | x | 3 == 2; | ^^^^^^^^^^ error: incompatible bit mask: `_ & 1` will never be higher than `1` - --> $DIR/bit_masks.rs:23:5 + --> $DIR/bit_masks.rs:29:5 | LL | x & 1 > 1; | ^^^^^^^^^ error: incompatible bit mask: `_ | 2` will always be higher than `1` - --> $DIR/bit_masks.rs:27:5 + --> $DIR/bit_masks.rs:34:5 | LL | x | 2 > 1; | ^^^^^^^^^ error: incompatible bit mask: `_ & 7` can never be equal to `8` - --> $DIR/bit_masks.rs:34:5 + --> $DIR/bit_masks.rs:42:5 | LL | x & THREE_BITS == 8; | ^^^^^^^^^^^^^^^^^^^ error: incompatible bit mask: `_ | 7` will never be lower than `7` - --> $DIR/bit_masks.rs:35:5 + --> $DIR/bit_masks.rs:44:5 | LL | x | EVEN_MORE_REDIRECTION < 7; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: &-masking with zero - --> $DIR/bit_masks.rs:37:5 + --> $DIR/bit_masks.rs:47:5 | LL | 0 & x == 0; | ^^^^^^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/bit_masks.rs:37:5 + --> $DIR/bit_masks.rs:47:5 | LL | 0 & x == 0; | ^^^^^ error: incompatible bit mask: `_ | 2` will always be higher than `1` - --> $DIR/bit_masks.rs:41:5 + --> $DIR/bit_masks.rs:53:5 | LL | 1 < 2 | x; | ^^^^^^^^^ error: incompatible bit mask: `_ | 3` can never be equal to `2` - --> $DIR/bit_masks.rs:42:5 + --> $DIR/bit_masks.rs:55:5 | LL | 2 == 3 | x; | ^^^^^^^^^^ error: incompatible bit mask: `_ & 2` can never be equal to `1` - --> $DIR/bit_masks.rs:43:5 + --> $DIR/bit_masks.rs:57:5 | LL | 1 == x & 2; | ^^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly - --> $DIR/bit_masks.rs:54:5 + --> $DIR/bit_masks.rs:69:5 | LL | x | 1 > 3; | ^^^^^^^^^ | = note: `-D clippy::ineffective-bit-mask` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ineffective_bit_mask)]` error: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared directly - --> $DIR/bit_masks.rs:55:5 + --> $DIR/bit_masks.rs:72:5 | LL | x | 1 < 4; | ^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly - --> $DIR/bit_masks.rs:56:5 + --> $DIR/bit_masks.rs:74:5 | LL | x | 1 <= 3; | ^^^^^^^^^^ error: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared directly - --> $DIR/bit_masks.rs:57:5 + --> $DIR/bit_masks.rs:76:5 | LL | x | 1 >= 8; | ^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.rs b/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.rs index e1ff25c54..2bfaadf8d 100644 --- a/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.rs +++ b/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.rs @@ -4,7 +4,10 @@ //! Test that the whole restriction group is not enabled #![warn(clippy::restriction)] +//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group #![deny(clippy::restriction)] +//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group #![forbid(clippy::restriction)] +//~^ ERROR: `clippy::restriction` is not meant to be enabled as a group fn main() {} diff --git a/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr b/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr index 2bf89ab69..afb634f34 100644 --- a/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr +++ b/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr @@ -1,9 +1,3 @@ -error: `clippy::restriction` is not meant to be enabled as a group - | - = note: because of the command line `--warn clippy::restriction` - = help: enable the restriction lints you need individually - = note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings` - error: `clippy::restriction` is not meant to be enabled as a group --> $DIR/blanket_clippy_restriction_lints.rs:6:9 | @@ -11,9 +5,11 @@ LL | #![warn(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ | = help: enable the restriction lints you need individually + = note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::blanket_clippy_restriction_lints)]` error: `clippy::restriction` is not meant to be enabled as a group - --> $DIR/blanket_clippy_restriction_lints.rs:7:9 + --> $DIR/blanket_clippy_restriction_lints.rs:8:9 | LL | #![deny(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ @@ -21,12 +17,17 @@ LL | #![deny(clippy::restriction)] = help: enable the restriction lints you need individually error: `clippy::restriction` is not meant to be enabled as a group - --> $DIR/blanket_clippy_restriction_lints.rs:8:11 + --> $DIR/blanket_clippy_restriction_lints.rs:10:11 | LL | #![forbid(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ | = help: enable the restriction lints you need individually +error: `clippy::restriction` is not meant to be enabled as a group + | + = note: because of the command line `--warn clippy::restriction` + = help: enable the restriction lints you need individually + error: aborting due to 4 previous errors diff --git a/src/tools/clippy/tests/ui/blocks_in_if_conditions.fixed b/src/tools/clippy/tests/ui/blocks_in_if_conditions.fixed index 2a3867ac8..f89c46504 100644 --- a/src/tools/clippy/tests/ui/blocks_in_if_conditions.fixed +++ b/src/tools/clippy/tests/ui/blocks_in_if_conditions.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::blocks_in_if_conditions)] #![allow(unused, clippy::let_and_return, clippy::needless_if)] #![warn(clippy::nonminimal_bool)] diff --git a/src/tools/clippy/tests/ui/blocks_in_if_conditions.rs b/src/tools/clippy/tests/ui/blocks_in_if_conditions.rs index 704d09fba..34febc5fa 100644 --- a/src/tools/clippy/tests/ui/blocks_in_if_conditions.rs +++ b/src/tools/clippy/tests/ui/blocks_in_if_conditions.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::blocks_in_if_conditions)] #![allow(unused, clippy::let_and_return, clippy::needless_if)] #![warn(clippy::nonminimal_bool)] diff --git a/src/tools/clippy/tests/ui/blocks_in_if_conditions.stderr b/src/tools/clippy/tests/ui/blocks_in_if_conditions.stderr index 079f2feb5..d80ef9c0f 100644 --- a/src/tools/clippy/tests/ui/blocks_in_if_conditions.stderr +++ b/src/tools/clippy/tests/ui/blocks_in_if_conditions.stderr @@ -1,5 +1,5 @@ error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let` - --> $DIR/blocks_in_if_conditions.rs:24:5 + --> $DIR/blocks_in_if_conditions.rs:23:5 | LL | / if { LL | | let x = 3; @@ -8,6 +8,7 @@ LL | | } { | |_____^ | = note: `-D clippy::blocks-in-if-conditions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::blocks_in_if_conditions)]` help: try | LL ~ let res = { @@ -17,18 +18,19 @@ LL ~ }; if res { | error: omit braces around single expression condition - --> $DIR/blocks_in_if_conditions.rs:35:8 + --> $DIR/blocks_in_if_conditions.rs:34:8 | LL | if { true } { 6 } else { 10 } | ^^^^^^^^ help: try: `true` error: this boolean expression can be simplified - --> $DIR/blocks_in_if_conditions.rs:40:8 + --> $DIR/blocks_in_if_conditions.rs:39:8 | LL | if true && x == 3 { 6 } else { 10 } | ^^^^^^^^^^^^^^ help: try: `x == 3` | = note: `-D clippy::nonminimal-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: aborting due to 3 previous errors diff --git a/src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.rs b/src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.rs index d6d085d7f..539f2df15 100644 --- a/src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.rs +++ b/src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.rs @@ -21,6 +21,8 @@ fn pred_test() { && sky == "blue" && predicate( |x| { + //~^ ERROR: in an `if` condition, avoid complex blocks or closures with blocks + //~| NOTE: `-D clippy::blocks-in-if-conditions` implied by `-D warnings` let target = 3; x == target }, @@ -30,6 +32,7 @@ fn pred_test() { if predicate( |x| { + //~^ ERROR: in an `if` condition, avoid complex blocks or closures with blocks; in let target = 3; x == target }, diff --git a/src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.stderr b/src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.stderr index 5ac02e750..ab68997d4 100644 --- a/src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.stderr +++ b/src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.stderr @@ -3,18 +3,22 @@ error: in an `if` condition, avoid complex blocks or closures with blocks; inste | LL | |x| { | _________________^ +LL | | +LL | | LL | | let target = 3; LL | | x == target LL | | }, | |_____________^ | = note: `-D clippy::blocks-in-if-conditions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::blocks_in_if_conditions)]` error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let` - --> $DIR/blocks_in_if_conditions_closure.rs:32:13 + --> $DIR/blocks_in_if_conditions_closure.rs:34:13 | LL | |x| { | _____________^ +LL | | LL | | let target = 3; LL | | x == target LL | | }, diff --git a/src/tools/clippy/tests/ui/bool_assert_comparison.fixed b/src/tools/clippy/tests/ui/bool_assert_comparison.fixed index 53f63444a..63b8e27e1 100644 --- a/src/tools/clippy/tests/ui/bool_assert_comparison.fixed +++ b/src/tools/clippy/tests/ui/bool_assert_comparison.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::assertions_on_constants)] #![warn(clippy::bool_assert_comparison)] diff --git a/src/tools/clippy/tests/ui/bool_assert_comparison.rs b/src/tools/clippy/tests/ui/bool_assert_comparison.rs index 151d93a92..58f81fedb 100644 --- a/src/tools/clippy/tests/ui/bool_assert_comparison.rs +++ b/src/tools/clippy/tests/ui/bool_assert_comparison.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::assertions_on_constants)] #![warn(clippy::bool_assert_comparison)] diff --git a/src/tools/clippy/tests/ui/bool_assert_comparison.stderr b/src/tools/clippy/tests/ui/bool_assert_comparison.stderr index 89cefc95a..5969e4faa 100644 --- a/src/tools/clippy/tests/ui/bool_assert_comparison.stderr +++ b/src/tools/clippy/tests/ui/bool_assert_comparison.stderr @@ -1,10 +1,11 @@ error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:89:5 + --> $DIR/bool_assert_comparison.rs:87:5 | LL | assert_eq!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::bool-assert-comparison` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::bool_assert_comparison)]` help: replace it with `assert!(..)` | LL - assert_eq!("a".is_empty(), false); @@ -12,7 +13,7 @@ LL + assert!(!"a".is_empty()); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:90:5 + --> $DIR/bool_assert_comparison.rs:88:5 | LL | assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL + assert!("".is_empty()); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:91:5 + --> $DIR/bool_assert_comparison.rs:89:5 | LL | assert_eq!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +37,7 @@ LL + assert!("".is_empty()); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:96:5 + --> $DIR/bool_assert_comparison.rs:94:5 | LL | assert_eq!(b, true); | ^^^^^^^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL + assert!(b); | error: used `assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:99:5 + --> $DIR/bool_assert_comparison.rs:97:5 | LL | assert_ne!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +61,7 @@ LL + assert!("a".is_empty()); | error: used `assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:100:5 + --> $DIR/bool_assert_comparison.rs:98:5 | LL | assert_ne!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL + assert!(!"".is_empty()); | error: used `assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:101:5 + --> $DIR/bool_assert_comparison.rs:99:5 | LL | assert_ne!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -84,7 +85,7 @@ LL + assert!(!"".is_empty()); | error: used `assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:106:5 + --> $DIR/bool_assert_comparison.rs:104:5 | LL | assert_ne!(b, true); | ^^^^^^^^^^^^^^^^^^^ @@ -96,7 +97,7 @@ LL + assert!(!b); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:109:5 + --> $DIR/bool_assert_comparison.rs:107:5 | LL | debug_assert_eq!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +109,7 @@ LL + debug_assert!(!"a".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:110:5 + --> $DIR/bool_assert_comparison.rs:108:5 | LL | debug_assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +121,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:111:5 + --> $DIR/bool_assert_comparison.rs:109:5 | LL | debug_assert_eq!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +133,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:116:5 + --> $DIR/bool_assert_comparison.rs:114:5 | LL | debug_assert_eq!(b, true); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +145,7 @@ LL + debug_assert!(b); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:119:5 + --> $DIR/bool_assert_comparison.rs:117:5 | LL | debug_assert_ne!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -156,7 +157,7 @@ LL + debug_assert!("a".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:120:5 + --> $DIR/bool_assert_comparison.rs:118:5 | LL | debug_assert_ne!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -168,7 +169,7 @@ LL + debug_assert!(!"".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:121:5 + --> $DIR/bool_assert_comparison.rs:119:5 | LL | debug_assert_ne!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -180,7 +181,7 @@ LL + debug_assert!(!"".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:126:5 + --> $DIR/bool_assert_comparison.rs:124:5 | LL | debug_assert_ne!(b, true); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -192,7 +193,7 @@ LL + debug_assert!(!b); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:131:5 + --> $DIR/bool_assert_comparison.rs:129:5 | LL | assert_eq!("a".is_empty(), false, "tadam {}", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -204,7 +205,7 @@ LL + assert!(!"a".is_empty(), "tadam {}", 1); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:132:5 + --> $DIR/bool_assert_comparison.rs:130:5 | LL | assert_eq!("a".is_empty(), false, "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -216,7 +217,7 @@ LL + assert!(!"a".is_empty(), "tadam {}", true); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:133:5 + --> $DIR/bool_assert_comparison.rs:131:5 | LL | assert_eq!(false, "a".is_empty(), "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -228,7 +229,7 @@ LL + 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:136:5 | LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -240,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:139:5 + --> $DIR/bool_assert_comparison.rs:137:5 | LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -252,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:140:5 + --> $DIR/bool_assert_comparison.rs:138:5 | LL | debug_assert_eq!(false, "a".is_empty(), "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -264,7 +265,7 @@ LL + debug_assert!(!"a".is_empty(), "tadam {}", true); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:143:5 + --> $DIR/bool_assert_comparison.rs:141:5 | LL | assert_eq!(a!(), true); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -276,7 +277,7 @@ LL + assert!(a!()); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:144:5 + --> $DIR/bool_assert_comparison.rs:142:5 | LL | assert_eq!(true, b!()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -288,7 +289,7 @@ LL + assert!(b!()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:148:5 + --> $DIR/bool_assert_comparison.rs:146:5 | LL | renamed!(b, true); | ^^^^^^^^^^^^^^^^^ @@ -300,7 +301,7 @@ LL + debug_assert!(b); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:162:5 + --> $DIR/bool_assert_comparison.rs:160:5 | LL | assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -312,7 +313,7 @@ LL + assert!("".is_empty()); | error: used `assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:163:5 + --> $DIR/bool_assert_comparison.rs:161:5 | LL | assert_ne!("".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -324,7 +325,7 @@ LL + assert!("".is_empty()); | error: used `assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:164:5 + --> $DIR/bool_assert_comparison.rs:162:5 | LL | assert_ne!("requires negation".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -336,7 +337,7 @@ LL + assert!(!"requires negation".is_empty()); | error: used `assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:165:5 + --> $DIR/bool_assert_comparison.rs:163:5 | LL | assert_eq!("requires negation".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -348,7 +349,7 @@ LL + assert!(!"requires negation".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:167:5 + --> $DIR/bool_assert_comparison.rs:165:5 | LL | debug_assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -360,7 +361,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:168:5 + --> $DIR/bool_assert_comparison.rs:166:5 | LL | debug_assert_ne!("".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -372,7 +373,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> $DIR/bool_assert_comparison.rs:169:5 + --> $DIR/bool_assert_comparison.rs:167:5 | LL | debug_assert_ne!("requires negation".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -384,7 +385,7 @@ LL + debug_assert!(!"requires negation".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> $DIR/bool_assert_comparison.rs:170:5 + --> $DIR/bool_assert_comparison.rs:168:5 | LL | debug_assert_eq!("requires negation".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/bool_comparison.fixed b/src/tools/clippy/tests/ui/bool_comparison.fixed index 8689f89d2..e3f2ca72d 100644 --- a/src/tools/clippy/tests/ui/bool_comparison.fixed +++ b/src/tools/clippy/tests/ui/bool_comparison.fixed @@ -1,8 +1,6 @@ -//@run-rustfix - #![allow(clippy::needless_if)] #![warn(clippy::bool_comparison)] -#![allow(clippy::incorrect_partial_ord_impl_on_ord_type)] +#![allow(clippy::non_canonical_partial_ord_impl)] fn main() { let x = true; diff --git a/src/tools/clippy/tests/ui/bool_comparison.rs b/src/tools/clippy/tests/ui/bool_comparison.rs index a1c94aff9..d1bc20d68 100644 --- a/src/tools/clippy/tests/ui/bool_comparison.rs +++ b/src/tools/clippy/tests/ui/bool_comparison.rs @@ -1,8 +1,6 @@ -//@run-rustfix - #![allow(clippy::needless_if)] #![warn(clippy::bool_comparison)] -#![allow(clippy::incorrect_partial_ord_impl_on_ord_type)] +#![allow(clippy::non_canonical_partial_ord_impl)] fn main() { let x = true; diff --git a/src/tools/clippy/tests/ui/bool_comparison.stderr b/src/tools/clippy/tests/ui/bool_comparison.stderr index 19bdf3013..4560df6d4 100644 --- a/src/tools/clippy/tests/ui/bool_comparison.stderr +++ b/src/tools/clippy/tests/ui/bool_comparison.stderr @@ -1,133 +1,134 @@ error: equality checks against true are unnecessary - --> $DIR/bool_comparison.rs:9:8 + --> $DIR/bool_comparison.rs:7:8 | LL | if x == true { | ^^^^^^^^^ help: try simplifying it as shown: `x` | = note: `-D clippy::bool-comparison` implied by `-D warnings` + = 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:14:8 + --> $DIR/bool_comparison.rs:12:8 | LL | if x == false { | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: equality checks against true are unnecessary - --> $DIR/bool_comparison.rs:19:8 + --> $DIR/bool_comparison.rs:17: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:24:8 + --> $DIR/bool_comparison.rs:22: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:29:8 + --> $DIR/bool_comparison.rs:27:8 | LL | if x != true { | ^^^^^^^^^ help: try simplifying it as shown: `!x` error: inequality checks against false are unnecessary - --> $DIR/bool_comparison.rs:34:8 + --> $DIR/bool_comparison.rs:32: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:39:8 + --> $DIR/bool_comparison.rs:37:8 | LL | if true != x { | ^^^^^^^^^ help: try simplifying it as shown: `!x` error: inequality checks against false are unnecessary - --> $DIR/bool_comparison.rs:44:8 + --> $DIR/bool_comparison.rs:42: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:49:8 + --> $DIR/bool_comparison.rs:47:8 | LL | if x < true { | ^^^^^^^^ help: try simplifying it as shown: `!x` error: greater than checks against false are unnecessary - --> $DIR/bool_comparison.rs:54:8 + --> $DIR/bool_comparison.rs:52:8 | LL | if false < x { | ^^^^^^^^^ help: try simplifying it as shown: `x` error: greater than checks against false are unnecessary - --> $DIR/bool_comparison.rs:59:8 + --> $DIR/bool_comparison.rs:57: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:64:8 + --> $DIR/bool_comparison.rs:62:8 | LL | if true > x { | ^^^^^^^^ help: try simplifying it as shown: `!x` error: order comparisons between booleans can be simplified - --> $DIR/bool_comparison.rs:70:8 + --> $DIR/bool_comparison.rs:68: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:75:8 + --> $DIR/bool_comparison.rs:73: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:123:8 + --> $DIR/bool_comparison.rs:121: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:124:8 + --> $DIR/bool_comparison.rs:122: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:128:8 + --> $DIR/bool_comparison.rs:126: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:129:8 + --> $DIR/bool_comparison.rs:127: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:153:8 + --> $DIR/bool_comparison.rs:151: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:154:8 + --> $DIR/bool_comparison.rs:152: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:155:8 + --> $DIR/bool_comparison.rs:153: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:156:8 + --> $DIR/bool_comparison.rs:154:8 | LL | if m!(func) == true {} | ^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `m!(func)` diff --git a/src/tools/clippy/tests/ui/bool_to_int_with_if.fixed b/src/tools/clippy/tests/ui/bool_to_int_with_if.fixed index fbb10a133..44d7f6e6d 100644 --- a/src/tools/clippy/tests/ui/bool_to_int_with_if.fixed +++ b/src/tools/clippy/tests/ui/bool_to_int_with_if.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(let_chains, inline_const)] #![warn(clippy::bool_to_int_with_if)] #![allow(unused, dead_code, clippy::unnecessary_operation, clippy::no_effect)] diff --git a/src/tools/clippy/tests/ui/bool_to_int_with_if.rs b/src/tools/clippy/tests/ui/bool_to_int_with_if.rs index 709a18d63..7d989ae4b 100644 --- a/src/tools/clippy/tests/ui/bool_to_int_with_if.rs +++ b/src/tools/clippy/tests/ui/bool_to_int_with_if.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(let_chains, inline_const)] #![warn(clippy::bool_to_int_with_if)] #![allow(unused, dead_code, clippy::unnecessary_operation, clippy::no_effect)] diff --git a/src/tools/clippy/tests/ui/bool_to_int_with_if.stderr b/src/tools/clippy/tests/ui/bool_to_int_with_if.stderr index 3bdae75ca..837ed05d3 100644 --- a/src/tools/clippy/tests/ui/bool_to_int_with_if.stderr +++ b/src/tools/clippy/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:16:5 + --> $DIR/bool_to_int_with_if.rs:14:5 | LL | / if a { LL | | 1 @@ -10,9 +10,10 @@ LL | | }; | = note: `a as i32` or `a.into()` can also be valid options = note: `-D clippy::bool-to-int-with-if` implied by `-D warnings` + = 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:21:5 + --> $DIR/bool_to_int_with_if.rs:19:5 | LL | / if a { LL | | 0 @@ -24,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:26:5 + --> $DIR/bool_to_int_with_if.rs:24:5 | LL | / if !a { LL | | 1 @@ -36,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:31:5 + --> $DIR/bool_to_int_with_if.rs:29:5 | LL | / if a || b { LL | | 1 @@ -48,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:36:5 + --> $DIR/bool_to_int_with_if.rs:34:5 | LL | / if cond(a, b) { LL | | 1 @@ -60,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:41:5 + --> $DIR/bool_to_int_with_if.rs:39:5 | LL | / if x + y < 4 { LL | | 1 @@ -72,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:50:12 + --> $DIR/bool_to_int_with_if.rs:48:12 | LL | } else if b { | ____________^ @@ -85,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:59:12 + --> $DIR/bool_to_int_with_if.rs:57:12 | LL | } else if b { | ____________^ @@ -98,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:126:5 + --> $DIR/bool_to_int_with_if.rs:124:5 | LL | if a { 1 } else { 0 } | ^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `u8::from(a)` diff --git a/src/tools/clippy/tests/ui/borrow_as_ptr.fixed b/src/tools/clippy/tests/ui/borrow_as_ptr.fixed index 996cc3650..6c0de96d6 100644 --- a/src/tools/clippy/tests/ui/borrow_as_ptr.fixed +++ b/src/tools/clippy/tests/ui/borrow_as_ptr.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::borrow_as_ptr)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/borrow_as_ptr.rs b/src/tools/clippy/tests/ui/borrow_as_ptr.rs index 5eafaeb2f..c37c5357c 100644 --- a/src/tools/clippy/tests/ui/borrow_as_ptr.rs +++ b/src/tools/clippy/tests/ui/borrow_as_ptr.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::borrow_as_ptr)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/borrow_as_ptr.stderr b/src/tools/clippy/tests/ui/borrow_as_ptr.stderr index c9990bb6f..43a7a6bf5 100644 --- a/src/tools/clippy/tests/ui/borrow_as_ptr.stderr +++ b/src/tools/clippy/tests/ui/borrow_as_ptr.stderr @@ -1,13 +1,14 @@ error: borrow as raw pointer - --> $DIR/borrow_as_ptr.rs:11:14 + --> $DIR/borrow_as_ptr.rs:10:14 | LL | let _p = &val as *const i32; | ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::addr_of!(val)` | = note: `-D clippy::borrow-as-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::borrow_as_ptr)]` error: borrow as raw pointer - --> $DIR/borrow_as_ptr.rs:18:18 + --> $DIR/borrow_as_ptr.rs:17:18 | LL | let _p_mut = &mut val_mut as *mut i32; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::addr_of_mut!(val_mut)` diff --git a/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.fixed b/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.fixed index 10f2727c7..a361a3647 100644 --- a/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.fixed +++ b/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::borrow_as_ptr)] #![feature(lang_items, start, libc)] #![no_std] diff --git a/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.rs b/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.rs index 311e9341a..b3fe01442 100644 --- a/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.rs +++ b/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::borrow_as_ptr)] #![feature(lang_items, start, libc)] #![no_std] diff --git a/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.stderr b/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.stderr index 84c8ba7d0..2f258bcf9 100644 --- a/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.stderr +++ b/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.stderr @@ -1,13 +1,14 @@ error: borrow as raw pointer - --> $DIR/borrow_as_ptr_no_std.rs:9:14 + --> $DIR/borrow_as_ptr_no_std.rs:8:14 | LL | let _p = &val as *const i32; | ^^^^^^^^^^^^^^^^^^ help: try: `core::ptr::addr_of!(val)` | = note: `-D clippy::borrow-as-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::borrow_as_ptr)]` error: borrow as raw pointer - --> $DIR/borrow_as_ptr_no_std.rs:12:18 + --> $DIR/borrow_as_ptr_no_std.rs:11:18 | LL | let _p_mut = &mut val_mut as *mut i32; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `core::ptr::addr_of_mut!(val_mut)` diff --git a/src/tools/clippy/tests/ui/borrow_box.rs b/src/tools/clippy/tests/ui/borrow_box.rs index 95b6b0f50..e9994aac8 100644 --- a/src/tools/clippy/tests/ui/borrow_box.rs +++ b/src/tools/clippy/tests/ui/borrow_box.rs @@ -5,6 +5,7 @@ clippy::disallowed_names, clippy::needless_pass_by_ref_mut )] +//@no-rustfix use std::fmt::Display; @@ -22,14 +23,17 @@ pub fn test1(foo: &mut Box) { pub fn test2() { let foo: &Box; + //~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` } struct Test3<'a> { foo: &'a Box, + //~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` } trait Test4 { fn test4(a: &Box); + //~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` } impl<'a> Test4 for Test3<'a> { @@ -96,17 +100,24 @@ pub fn test13(boxed_slice: &mut Box<[i32]>) { // The suggestion should include proper parentheses to avoid a syntax error. pub fn test14(_display: &Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test15(_display: &Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test16<'a>(_display: &'a Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test17(_display: &Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test18(_display: &Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` pub fn test19<'a>(_display: &'a Box) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` // This exists only to check what happens when parentheses are already present. // Even though the current implementation doesn't put extra parentheses, // it's fine that unnecessary parentheses appear in the future for some reason. pub fn test20(_display: &Box<(dyn Display + Send)>) {} +//~^ ERROR: you seem to be trying to use `&Box`. Consider using just `&T` fn main() { test1(&mut Box::new(false)); diff --git a/src/tools/clippy/tests/ui/borrow_box.stderr b/src/tools/clippy/tests/ui/borrow_box.stderr index 90e752211..a9773958a 100644 --- a/src/tools/clippy/tests/ui/borrow_box.stderr +++ b/src/tools/clippy/tests/ui/borrow_box.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:24:14 + --> $DIR/borrow_box.rs:25:14 | LL | let foo: &Box; | ^^^^^^^^^^ help: try: `&bool` @@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)] | ^^^^^^^^^^^^^^^^^^^^ error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:28:10 + --> $DIR/borrow_box.rs:30:10 | LL | foo: &'a Box, | ^^^^^^^^^^^^^ help: try: `&'a bool` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:32:17 + --> $DIR/borrow_box.rs:35:17 | LL | fn test4(a: &Box); | ^^^^^^^^^^ help: try: `&bool` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:98:25 + --> $DIR/borrow_box.rs:102:25 | LL | pub fn test14(_display: &Box) {} | ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:99:25 + --> $DIR/borrow_box.rs:104:25 | LL | pub fn test15(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:100:29 + --> $DIR/borrow_box.rs:106:29 | LL | pub fn test16<'a>(_display: &'a Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:102:25 + --> $DIR/borrow_box.rs:109:25 | LL | pub fn test17(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:103:25 + --> $DIR/borrow_box.rs:111:25 | LL | pub fn test18(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:104:29 + --> $DIR/borrow_box.rs:113:29 | LL | pub fn test19<'a>(_display: &'a Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> $DIR/borrow_box.rs:109:25 + --> $DIR/borrow_box.rs:119:25 | LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` diff --git a/src/tools/clippy/tests/ui/borrow_deref_ref.fixed b/src/tools/clippy/tests/ui/borrow_deref_ref.fixed index b951ba04c..ea5e983de 100644 --- a/src/tools/clippy/tests/ui/borrow_deref_ref.fixed +++ b/src/tools/clippy/tests/ui/borrow_deref_ref.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![allow(dead_code, unused_variables)] diff --git a/src/tools/clippy/tests/ui/borrow_deref_ref.rs b/src/tools/clippy/tests/ui/borrow_deref_ref.rs index 52980e55f..8c8905b15 100644 --- a/src/tools/clippy/tests/ui/borrow_deref_ref.rs +++ b/src/tools/clippy/tests/ui/borrow_deref_ref.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![allow(dead_code, unused_variables)] diff --git a/src/tools/clippy/tests/ui/borrow_deref_ref.stderr b/src/tools/clippy/tests/ui/borrow_deref_ref.stderr index 1e47cda67..c389d6797 100644 --- a/src/tools/clippy/tests/ui/borrow_deref_ref.stderr +++ b/src/tools/clippy/tests/ui/borrow_deref_ref.stderr @@ -1,19 +1,20 @@ error: deref on an immutable reference - --> $DIR/borrow_deref_ref.rs:14:17 + --> $DIR/borrow_deref_ref.rs:13:17 | LL | let b = &*a; | ^^^ help: if you would like to reborrow, try removing `&*`: `a` | = note: `-D clippy::borrow-deref-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::borrow_deref_ref)]` error: deref on an immutable reference - --> $DIR/borrow_deref_ref.rs:16:22 + --> $DIR/borrow_deref_ref.rs:15:22 | 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:70:23 + --> $DIR/borrow_deref_ref.rs:69: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/src/tools/clippy/tests/ui/borrow_deref_ref_unfixable.rs b/src/tools/clippy/tests/ui/borrow_deref_ref_unfixable.rs index a8e2bbfef..be9887339 100644 --- a/src/tools/clippy/tests/ui/borrow_deref_ref_unfixable.rs +++ b/src/tools/clippy/tests/ui/borrow_deref_ref_unfixable.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![allow(dead_code, unused_variables)] fn main() {} @@ -6,5 +7,7 @@ mod should_lint { fn two_helps() { let s = &String::new(); let x: &str = &*s; + //~^ ERROR: deref on an immutable reference + //~| NOTE: `-D clippy::borrow-deref-ref` implied by `-D warnings` } } diff --git a/src/tools/clippy/tests/ui/borrow_deref_ref_unfixable.stderr b/src/tools/clippy/tests/ui/borrow_deref_ref_unfixable.stderr index 738b01e7e..2a21f5ca2 100644 --- a/src/tools/clippy/tests/ui/borrow_deref_ref_unfixable.stderr +++ b/src/tools/clippy/tests/ui/borrow_deref_ref_unfixable.stderr @@ -1,10 +1,11 @@ error: deref on an immutable reference - --> $DIR/borrow_deref_ref_unfixable.rs:8:23 + --> $DIR/borrow_deref_ref_unfixable.rs:9:23 | LL | let x: &str = &*s; | ^^^ | = note: `-D clippy::borrow-deref-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::borrow_deref_ref)]` help: if you would like to reborrow, try removing `&*` | LL | let x: &str = s; diff --git a/src/tools/clippy/tests/ui/box_collection.rs b/src/tools/clippy/tests/ui/box_collection.rs index 4c9947b9a..499625ea9 100644 --- a/src/tools/clippy/tests/ui/box_collection.rs +++ b/src/tools/clippy/tests/ui/box_collection.rs @@ -19,6 +19,7 @@ fn test_macro() { } fn test1(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `Vec<..>` fn test2(foo: Box)>) { // pass if #31 is fixed @@ -26,20 +27,28 @@ fn test2(foo: Box)>) { } fn test3(foo: Box) {} +//~^ ERROR: you seem to be trying to use `Box`. Consider using just `String` fn test4(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `HashMap< fn test5(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `HashSet< fn test6(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `VecDequ fn test7(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `Linke fn test8(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `BTreeMa fn test9(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `BTreeSe fn test10(foo: Box>) {} +//~^ ERROR: you seem to be trying to use `Box>`. Consider using just `Binar fn test_local_not_linted() { let _: Box>; diff --git a/src/tools/clippy/tests/ui/box_collection.stderr b/src/tools/clippy/tests/ui/box_collection.stderr index 40b6f9be6..1ae7c2a05 100644 --- a/src/tools/clippy/tests/ui/box_collection.stderr +++ b/src/tools/clippy/tests/ui/box_collection.stderr @@ -6,9 +6,10 @@ LL | fn test1(foo: Box>) {} | = help: `Vec<..>` is already on the heap, `Box>` makes an extra allocation = note: `-D clippy::box-collection` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::box_collection)]` error: you seem to be trying to use `Box`. Consider using just `String` - --> $DIR/box_collection.rs:28:15 + --> $DIR/box_collection.rs:29:15 | LL | fn test3(foo: Box) {} | ^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | fn test3(foo: Box) {} = help: `String` is already on the heap, `Box` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `HashMap<..>` - --> $DIR/box_collection.rs:30:15 + --> $DIR/box_collection.rs:32:15 | LL | fn test4(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | fn test4(foo: Box>) {} = help: `HashMap<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `HashSet<..>` - --> $DIR/box_collection.rs:32:15 + --> $DIR/box_collection.rs:35:15 | LL | fn test5(foo: Box>) {} | ^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | fn test5(foo: Box>) {} = help: `HashSet<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `VecDeque<..>` - --> $DIR/box_collection.rs:34:15 + --> $DIR/box_collection.rs:38:15 | LL | fn test6(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | fn test6(foo: Box>) {} = help: `VecDeque<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `LinkedList<..>` - --> $DIR/box_collection.rs:36:15 + --> $DIR/box_collection.rs:41:15 | LL | fn test7(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | fn test7(foo: Box>) {} = help: `LinkedList<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `BTreeMap<..>` - --> $DIR/box_collection.rs:38:15 + --> $DIR/box_collection.rs:44:15 | LL | fn test8(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | fn test8(foo: Box>) {} = help: `BTreeMap<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `BTreeSet<..>` - --> $DIR/box_collection.rs:40:15 + --> $DIR/box_collection.rs:47:15 | LL | fn test9(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^ @@ -64,7 +65,7 @@ LL | fn test9(foo: Box>) {} = help: `BTreeSet<..>` is already on the heap, `Box>` makes an extra allocation error: you seem to be trying to use `Box>`. Consider using just `BinaryHeap<..>` - --> $DIR/box_collection.rs:42:16 + --> $DIR/box_collection.rs:50:16 | LL | fn test10(foo: Box>) {} | ^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/box_default.fixed b/src/tools/clippy/tests/ui/box_default.fixed index 840902b53..69cabcb32 100644 --- a/src/tools/clippy/tests/ui/box_default.fixed +++ b/src/tools/clippy/tests/ui/box_default.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::box_default)] #![allow(clippy::default_constructed_unit_structs)] @@ -37,7 +36,7 @@ fn main() { issue_10381(); // `Box::>::default()` would be valid here, but not `Box::default()` or - // `Box::::default()` + // `Box::::default()` // // Would have a suggestion after https://github.com/rust-lang/rust/blob/fdd030127cc68afec44a8d3f6341525dd34e50ae/compiler/rustc_middle/src/ty/diagnostics.rs#L554-L563 let mut unnameable = Box::new(Option::default()); diff --git a/src/tools/clippy/tests/ui/box_default.rs b/src/tools/clippy/tests/ui/box_default.rs index 3618486a4..48fa8bc33 100644 --- a/src/tools/clippy/tests/ui/box_default.rs +++ b/src/tools/clippy/tests/ui/box_default.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::box_default)] #![allow(clippy::default_constructed_unit_structs)] @@ -37,7 +36,7 @@ fn main() { issue_10381(); // `Box::>::default()` would be valid here, but not `Box::default()` or - // `Box::::default()` + // `Box::::default()` // // Would have a suggestion after https://github.com/rust-lang/rust/blob/fdd030127cc68afec44a8d3f6341525dd34e50ae/compiler/rustc_middle/src/ty/diagnostics.rs#L554-L563 let mut unnameable = Box::new(Option::default()); diff --git a/src/tools/clippy/tests/ui/box_default.stderr b/src/tools/clippy/tests/ui/box_default.stderr index 13dfc5ae4..004550c6c 100644 --- a/src/tools/clippy/tests/ui/box_default.stderr +++ b/src/tools/clippy/tests/ui/box_default.stderr @@ -1,97 +1,98 @@ error: `Box::new(_)` of default value - --> $DIR/box_default.rs:23:32 + --> $DIR/box_default.rs:22:32 | LL | let _string: Box = Box::new(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` | = note: `-D clippy::box-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::box_default)]` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:24:17 + --> $DIR/box_default.rs:23:17 | LL | let _byte = Box::new(u8::default()); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:25:16 + --> $DIR/box_default.rs:24:16 | LL | let _vec = Box::new(Vec::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::>::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:26:17 + --> $DIR/box_default.rs:25:17 | LL | let _impl = Box::new(ImplementsDefault::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:27:18 + --> $DIR/box_default.rs:26:18 | LL | let _impl2 = Box::new(::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:28:42 + --> $DIR/box_default.rs:27:42 | LL | let _impl3: Box = Box::new(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:30:28 + --> $DIR/box_default.rs:29:28 | LL | let _in_macro = outer!(Box::new(String::new())); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:31:34 + --> $DIR/box_default.rs:30:34 | LL | let _string_default = outer!(Box::new(String::from(""))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:32:46 + --> $DIR/box_default.rs:31:46 | LL | let _vec2: Box> = Box::new(vec![]); | ^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:33:33 + --> $DIR/box_default.rs:32:33 | LL | let _vec3: Box> = Box::new(Vec::from([])); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:34:25 + --> $DIR/box_default.rs:33: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:36:16 + --> $DIR/box_default.rs:35:16 | LL | call_ty_fn(Box::new(u8::default())); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:48:5 + --> $DIR/box_default.rs:47:5 | LL | Box::new(bool::default()) | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:65:28 + --> $DIR/box_default.rs:64:28 | LL | let _: Box = Box::new(ImplementsDefault::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:74:17 + --> $DIR/box_default.rs:73:17 | LL | let _ = Box::new(WeirdPathed::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` error: `Box::new(_)` of default value - --> $DIR/box_default.rs:86:18 + --> $DIR/box_default.rs:85:18 | LL | Some(Box::new(Foo::default())) | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::::default()` diff --git a/src/tools/clippy/tests/ui/boxed_local.rs b/src/tools/clippy/tests/ui/boxed_local.rs index 79b6d33fc..e888154c4 100644 --- a/src/tools/clippy/tests/ui/boxed_local.rs +++ b/src/tools/clippy/tests/ui/boxed_local.rs @@ -38,6 +38,8 @@ fn warn_call() { } fn warn_arg(x: Box) { + //~^ ERROR: local variable doesn't need to be boxed here + //~| NOTE: `-D clippy::boxed-local` implied by `-D warnings` x.foo(); } @@ -119,6 +121,7 @@ pub struct PeekableSeekable { } pub fn new(_needs_name: Box>) -> () {} +//~^ ERROR: local variable doesn't need to be boxed here /// Regression for #916, #1123 /// @@ -183,6 +186,7 @@ mod issue4804 { // warn on `x: Box` fn default_impl_x(self: Box, x: Box) -> u32 { + //~^ ERROR: local variable doesn't need to be boxed here 4 } } @@ -190,6 +194,7 @@ mod issue4804 { trait WarnTrait { // warn on `x: Box` fn foo(x: Box) {} + //~^ ERROR: local variable doesn't need to be boxed here } } diff --git a/src/tools/clippy/tests/ui/boxed_local.stderr b/src/tools/clippy/tests/ui/boxed_local.stderr index 10d78fbc0..187cc8fa1 100644 --- a/src/tools/clippy/tests/ui/boxed_local.stderr +++ b/src/tools/clippy/tests/ui/boxed_local.stderr @@ -5,21 +5,22 @@ LL | fn warn_arg(x: Box) { | ^ | = note: `-D clippy::boxed-local` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::boxed_local)]` error: local variable doesn't need to be boxed here - --> $DIR/boxed_local.rs:121:12 + --> $DIR/boxed_local.rs:123:12 | LL | pub fn new(_needs_name: Box>) -> () {} | ^^^^^^^^^^^ error: local variable doesn't need to be boxed here - --> $DIR/boxed_local.rs:185:44 + --> $DIR/boxed_local.rs:188:44 | LL | fn default_impl_x(self: Box, x: Box) -> u32 { | ^ error: local variable doesn't need to be boxed here - --> $DIR/boxed_local.rs:192:16 + --> $DIR/boxed_local.rs:196:16 | LL | fn foo(x: Box) {} | ^ diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.rs b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.rs index 6a63008b5..d102efa7a 100644 --- a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.rs +++ b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.rs @@ -1,7 +1,7 @@ #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)] #![allow(dead_code)] #![allow(clippy::equatable_if_let, clippy::uninlined_format_args)] - +//@no-rustfix // This tests the branches_sharing_code lint at the end of blocks fn simple_examples() { @@ -29,6 +29,8 @@ fn simple_examples() { // The rest is self contained and moveable => Only lint the rest let result = false; + //~^ ERROR: all if blocks contain the same code at the end + //~| NOTE: the end suggestion probably needs some adjustments to use the expressio println!("Block end!"); result }; @@ -47,6 +49,7 @@ fn simple_examples() { } else { println!("This is also eq with the else block"); println!("Same end of block"); + //~^ ERROR: all if blocks contain the same code at the end } // Use of outer scope value @@ -64,6 +67,7 @@ fn simple_examples() { println!("I'm a local because I use the value `z`: `{}`", z); println!( + //~^ ERROR: all if blocks contain the same code at the end "I'm moveable because I know: `outer_scope_value`: '{}'", outer_scope_value ); @@ -76,6 +80,7 @@ fn simple_examples() { println!("Hello World"); } else { println!("Hello World"); + //~^ ERROR: all if blocks contain the same code at the end } } } @@ -92,6 +97,7 @@ fn simple_but_suggestion_is_invalid() { println!("{}", later_used_value); } else { let later_used_value = "A string value"; + //~^ ERROR: all if blocks contain the same code at the end println!("{}", later_used_value); // I'm expecting a note about this } @@ -105,6 +111,7 @@ fn simple_but_suggestion_is_invalid() { println!("Separator print statement"); let simple_examples = "I now identify as a &str :)"; + //~^ ERROR: all if blocks contain the same code at the end println!("This is the new simple_example: {}", simple_examples); } simple_examples(); @@ -170,6 +177,8 @@ fn added_note_for_expression_use() -> u32 { } else { let _ = 6; x << 2 + //~^ ERROR: all if blocks contain the same code at the end + //~| NOTE: the end suggestion probably needs some adjustments to use the expressio }; if x == 9 { @@ -177,6 +186,8 @@ fn added_note_for_expression_use() -> u32 { } else { let _ = 17; x * 4 + //~^ ERROR: all if blocks contain the same code at the end + //~| NOTE: the end suggestion probably needs some adjustments to use the expressio } } @@ -189,6 +200,7 @@ fn test_suggestion_with_weird_formatting() { // The error message still looks weird tbh but this is the best I can do // for weird formatting if x == 17 { b = 1; a = 0x99; } else { a = 0x99; } + //~^ ERROR: all if blocks contain the same code at the end } fn fp_test() { diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.stderr b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.stderr index b9b113dc0..d00717bef 100644 --- a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.stderr +++ b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.stderr @@ -2,6 +2,8 @@ error: all if blocks contain the same code at the end --> $DIR/shared_at_bottom.rs:31:5 | LL | / let result = false; +LL | | +LL | | LL | | println!("Block end!"); LL | | result LL | | }; @@ -17,14 +19,17 @@ help: consider moving these statements after the if | LL ~ } LL + let result = false; +LL + +LL + LL + println!("Block end!"); LL ~ result; | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:49:5 + --> $DIR/shared_at_bottom.rs:51:5 | LL | / println!("Same end of block"); +LL | | LL | | } | |_____^ | @@ -35,9 +40,10 @@ LL + println!("Same end of block"); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:66:5 + --> $DIR/shared_at_bottom.rs:69:5 | LL | / println!( +LL | | LL | | "I'm moveable because I know: `outer_scope_value`: '{}'", LL | | outer_scope_value LL | | ); @@ -48,15 +54,17 @@ help: consider moving these statements after the if | LL ~ } LL + println!( +LL + LL + "I'm moveable because I know: `outer_scope_value`: '{}'", LL + outer_scope_value LL + ); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:78:9 + --> $DIR/shared_at_bottom.rs:82:9 | LL | / println!("Hello World"); +LL | | LL | | } | |_________^ | @@ -67,9 +75,10 @@ LL + println!("Hello World"); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:94:5 + --> $DIR/shared_at_bottom.rs:99:5 | LL | / let later_used_value = "A string value"; +LL | | LL | | println!("{}", later_used_value); LL | | // I'm expecting a note about this LL | | } @@ -80,13 +89,15 @@ help: consider moving these statements after the if | LL ~ } LL + let later_used_value = "A string value"; +LL + LL + println!("{}", later_used_value); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:107:5 + --> $DIR/shared_at_bottom.rs:113:5 | LL | / let simple_examples = "I now identify as a &str :)"; +LL | | LL | | println!("This is the new simple_example: {}", simple_examples); LL | | } | |_____^ @@ -96,13 +107,16 @@ help: consider moving these statements after the if | LL ~ } LL + let simple_examples = "I now identify as a &str :)"; +LL + LL + println!("This is the new simple_example: {}", simple_examples); | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:172:5 + --> $DIR/shared_at_bottom.rs:179:5 | LL | / x << 2 +LL | | +LL | | LL | | }; | |_____^ | @@ -114,9 +128,11 @@ LL ~ x << 2; | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:179:5 + --> $DIR/shared_at_bottom.rs:188:5 | LL | / x * 4 +LL | | +LL | | LL | | } | |_____^ | @@ -128,7 +144,7 @@ LL + x * 4 | error: all if blocks contain the same code at the end - --> $DIR/shared_at_bottom.rs:191:44 + --> $DIR/shared_at_bottom.rs:202:44 | LL | if x == 17 { b = 1; a = 0x99; } else { a = 0x99; } | ^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.rs b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.rs index 9e0b99f16..44f8b2eab 100644 --- a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.rs +++ b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.rs @@ -1,7 +1,7 @@ #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)] #![allow(dead_code)] #![allow(clippy::mixed_read_write_in_expression, clippy::uninlined_format_args)] - +//@no-rustfix // This tests the branches_sharing_code lint at the start of blocks fn simple_examples() { @@ -9,6 +9,7 @@ fn simple_examples() { // Simple if true { + //~^ ERROR: all if blocks contain the same code at the start println!("Hello World!"); println!("I'm branch nr: 1"); } else { @@ -18,6 +19,7 @@ fn simple_examples() { // Else if if x == 0 { + //~^ ERROR: all if blocks contain the same code at the start let y = 9; println!("The value y was set to: `{}`", y); let _z = y; @@ -39,6 +41,7 @@ fn simple_examples() { // Return a value let _ = if x == 7 { + //~^ ERROR: all if blocks contain the same code at the start let y = 16; println!("What can I say except: \"you're welcome?\""); let _ = y; @@ -57,6 +60,7 @@ fn simple_but_suggestion_is_invalid() { // Can't be automatically moved because used_value_name is getting used again let used_value_name = 19; if x == 10 { + //~^ ERROR: all if blocks contain the same code at the start let used_value_name = "Different type"; println!("Str: {}", used_value_name); let _ = 1; @@ -71,6 +75,7 @@ fn simple_but_suggestion_is_invalid() { let can_be_overridden = 8; let _ = can_be_overridden; if x == 11 { + //~^ ERROR: all if blocks contain the same code at the start let can_be_overridden = "Move me"; println!("I'm also moveable"); let _ = 111; @@ -87,6 +92,7 @@ fn check_if_same_than_else_mask() { #[allow(clippy::if_same_then_else)] if x == 2020 { + //~^ ERROR: all if blocks contain the same code at the start println!("This should trigger the `SHARED_CODE_IN_IF_BLOCKS` lint."); println!("Because `IF_SAME_THEN_ELSE` is allowed here"); } else { @@ -95,6 +101,7 @@ fn check_if_same_than_else_mask() { } if x == 2019 { + //~^ ERROR: this `if` has identical blocks println!("This should trigger `IS_SAME_THAN_ELSE` as usual"); } else { println!("This should trigger `IS_SAME_THAN_ELSE` as usual"); diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.stderr b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.stderr index 3e3242a75..9d4d42fb6 100644 --- a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.stderr +++ b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.stderr @@ -2,6 +2,7 @@ error: all if blocks contain the same code at the start --> $DIR/shared_at_top.rs:11:5 | LL | / if true { +LL | | LL | | println!("Hello World!"); | |_________________________________^ | @@ -17,9 +18,10 @@ LL + if true { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:20:5 + --> $DIR/shared_at_top.rs:21:5 | LL | / if x == 0 { +LL | | LL | | let y = 9; LL | | println!("The value y was set to: `{}`", y); LL | | let _z = y; @@ -35,9 +37,10 @@ LL + if x == 0 { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:41:5 + --> $DIR/shared_at_top.rs:43:5 | LL | / let _ = if x == 7 { +LL | | LL | | let y = 16; | |___________________^ | @@ -48,9 +51,10 @@ LL + let _ = if x == 7 { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:59:5 + --> $DIR/shared_at_top.rs:62:5 | LL | / if x == 10 { +LL | | LL | | let used_value_name = "Different type"; LL | | println!("Str: {}", used_value_name); | |_____________________________________________^ @@ -64,9 +68,10 @@ LL + if x == 10 { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:73:5 + --> $DIR/shared_at_top.rs:77:5 | LL | / if x == 11 { +LL | | LL | | let can_be_overridden = "Move me"; LL | | println!("I'm also moveable"); | |______________________________________^ @@ -80,9 +85,10 @@ LL + if x == 11 { | error: all if blocks contain the same code at the start - --> $DIR/shared_at_top.rs:89:5 + --> $DIR/shared_at_top.rs:94:5 | LL | / if x == 2020 { +LL | | LL | | println!("This should trigger the `SHARED_CODE_IN_IF_BLOCKS` lint."); LL | | println!("Because `IF_SAME_THEN_ELSE` is allowed here"); | |________________________________________________________________^ @@ -95,16 +101,17 @@ LL + if x == 2020 { | error: this `if` has identical blocks - --> $DIR/shared_at_top.rs:97:18 + --> $DIR/shared_at_top.rs:103:18 | LL | if x == 2019 { | __________________^ +LL | | LL | | println!("This should trigger `IS_SAME_THAN_ELSE` as usual"); LL | | } else { | |_____^ | note: same as this - --> $DIR/shared_at_top.rs:99:12 + --> $DIR/shared_at_top.rs:106:12 | LL | } else { | ____________^ diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs index 93b8c6e10..36620ee1a 100644 --- a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs +++ b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs @@ -1,7 +1,7 @@ #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)] #![allow(dead_code)] #![allow(clippy::uninlined_format_args)] - +//@no-rustfix // branches_sharing_code at the top and bottom of the if blocks struct DataPack { @@ -15,6 +15,7 @@ fn overlapping_eq_regions() { // Overlap with separator if x == 7 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let t = 7; let _overlap_start = t * 2; let _overlap_end = 2 * t; @@ -31,6 +32,7 @@ fn overlapping_eq_regions() { // Overlap with separator if x == 99 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let r = 7; let _overlap_start = r; let _overlap_middle = r * r; @@ -60,6 +62,7 @@ fn complexer_example() { let x = 8; let y = 9; if (x > 7 && y < 13) || (x + y) % 2 == 1 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let a = 0xcafe; let b = 0xffff00ff; let e_id = gen_id(a, b); @@ -93,6 +96,7 @@ fn added_note_for_expression_use() -> u32 { let x = 9; let _ = if x == 7 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let _ = 19; let _splitter = 6; @@ -105,6 +109,7 @@ fn added_note_for_expression_use() -> u32 { }; if x == 9 { + //~^ ERROR: all if blocks contain the same code at both the start and the end let _ = 17; let _splitter = 6; diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr index ccd697a42..74495fca8 100644 --- a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr +++ b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr @@ -2,13 +2,14 @@ error: all if blocks contain the same code at both the start and the end --> $DIR/shared_at_top_and_bottom.rs:17:5 | LL | / if x == 7 { +LL | | LL | | let t = 7; LL | | let _overlap_start = t * 2; LL | | let _overlap_end = 2 * t; | |_________________________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:29:5 + --> $DIR/shared_at_top_and_bottom.rs:30:5 | LL | / let _u = 9; LL | | } @@ -32,16 +33,17 @@ LL + let _u = 9; | error: all if blocks contain the same code at both the start and the end - --> $DIR/shared_at_top_and_bottom.rs:33:5 + --> $DIR/shared_at_top_and_bottom.rs:34:5 | LL | / if x == 99 { +LL | | LL | | let r = 7; LL | | let _overlap_start = r; LL | | let _overlap_middle = r * r; | |____________________________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:44:5 + --> $DIR/shared_at_top_and_bottom.rs:46:5 | LL | / let _overlap_end = r * r * r; LL | | let z = "end"; @@ -63,16 +65,17 @@ LL + let z = "end"; | error: all if blocks contain the same code at both the start and the end - --> $DIR/shared_at_top_and_bottom.rs:62:5 + --> $DIR/shared_at_top_and_bottom.rs:64:5 | LL | / if (x > 7 && y < 13) || (x + y) % 2 == 1 { +LL | | LL | | let a = 0xcafe; LL | | let b = 0xffff00ff; LL | | let e_id = gen_id(a, b); | |________________________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:82:5 + --> $DIR/shared_at_top_and_bottom.rs:85:5 | LL | / let pack = DataPack { LL | | id: e_id, @@ -102,14 +105,15 @@ LL + process_data(pack); | error: all if blocks contain the same code at both the start and the end - --> $DIR/shared_at_top_and_bottom.rs:95:5 + --> $DIR/shared_at_top_and_bottom.rs:98:5 | LL | / let _ = if x == 7 { +LL | | LL | | let _ = 19; | |___________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:104:5 + --> $DIR/shared_at_top_and_bottom.rs:108:5 | LL | / x << 2 LL | | }; @@ -127,14 +131,15 @@ LL ~ x << 2; | error: all if blocks contain the same code at both the start and the end - --> $DIR/shared_at_top_and_bottom.rs:107:5 + --> $DIR/shared_at_top_and_bottom.rs:111:5 | LL | / if x == 9 { +LL | | LL | | let _ = 17; | |___________________^ | note: this code is shared at the end - --> $DIR/shared_at_top_and_bottom.rs:116:5 + --> $DIR/shared_at_top_and_bottom.rs:121:5 | LL | / x * 4 LL | | } diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.rs b/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.rs index 5780ea089..2aeacb89c 100644 --- a/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.rs +++ b/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.rs @@ -107,6 +107,7 @@ fn valid_examples() { // Let's test empty blocks if false { + //~^ ERROR: this `if` has identical blocks } else { } } @@ -118,6 +119,7 @@ fn trigger_other_lint() { // Same block if x == 0 { + //~^ ERROR: this `if` has identical blocks let u = 19; println!("How are u today?"); let _ = "This is a string"; @@ -129,12 +131,14 @@ fn trigger_other_lint() { // Only same expression let _ = if x == 6 { 7 } else { 7 }; + //~^ ERROR: this `if` has identical blocks // Same in else if block let _ = if x == 67 { println!("Well I'm the most important block"); "I'm a pretty string" } else if x == 68 { + //~^ ERROR: this `if` has identical blocks println!("I'm a doppelgänger"); // Don't listen to my clone below @@ -149,6 +153,7 @@ fn trigger_other_lint() { if x == 0 { println!("I'm single"); } else if x == 68 { + //~^ ERROR: this `if` has identical blocks println!("I'm a doppelgänger"); // Don't listen to my clone below } else { diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.stderr b/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.stderr index a7e72b780..fcbf12235 100644 --- a/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.stderr +++ b/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.stderr @@ -3,11 +3,12 @@ error: this `if` has identical blocks | LL | if false { | ______________^ +LL | | LL | | } else { | |_____^ | note: same as this - --> $DIR/valid_if_blocks.rs:110:12 + --> $DIR/valid_if_blocks.rs:111:12 | LL | } else { | ____________^ @@ -20,10 +21,11 @@ LL | #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `if` has identical blocks - --> $DIR/valid_if_blocks.rs:120:15 + --> $DIR/valid_if_blocks.rs:121:15 | LL | if x == 0 { | _______________^ +LL | | LL | | let u = 19; LL | | println!("How are u today?"); LL | | let _ = "This is a string"; @@ -31,7 +33,7 @@ LL | | } else { | |_____^ | note: same as this - --> $DIR/valid_if_blocks.rs:124:12 + --> $DIR/valid_if_blocks.rs:126:12 | LL | } else { | ____________^ @@ -42,22 +44,23 @@ LL | | } | |_____^ error: this `if` has identical blocks - --> $DIR/valid_if_blocks.rs:131:23 + --> $DIR/valid_if_blocks.rs:133:23 | LL | let _ = if x == 6 { 7 } else { 7 }; | ^^^^^ | note: same as this - --> $DIR/valid_if_blocks.rs:131:34 + --> $DIR/valid_if_blocks.rs:133:34 | LL | let _ = if x == 6 { 7 } else { 7 }; | ^^^^^ error: this `if` has identical blocks - --> $DIR/valid_if_blocks.rs:137:23 + --> $DIR/valid_if_blocks.rs:140:23 | LL | } else if x == 68 { | _______________________^ +LL | | LL | | println!("I'm a doppelgänger"); LL | | // Don't listen to my clone below LL | | @@ -66,7 +69,7 @@ LL | | } else { | |_____^ | note: same as this - --> $DIR/valid_if_blocks.rs:142:12 + --> $DIR/valid_if_blocks.rs:146:12 | LL | } else { | ____________^ @@ -78,17 +81,18 @@ LL | | }; | |_____^ error: this `if` has identical blocks - --> $DIR/valid_if_blocks.rs:151:23 + --> $DIR/valid_if_blocks.rs:155:23 | LL | } else if x == 68 { | _______________________^ +LL | | LL | | println!("I'm a doppelgänger"); LL | | // Don't listen to my clone below LL | | } else { | |_____^ | note: same as this - --> $DIR/valid_if_blocks.rs:154:12 + --> $DIR/valid_if_blocks.rs:159:12 | LL | } else { | ____________^ diff --git a/src/tools/clippy/tests/ui/builtin_type_shadow.stderr b/src/tools/clippy/tests/ui/builtin_type_shadow.stderr index 47a8a1e62..cb8462182 100644 --- a/src/tools/clippy/tests/ui/builtin_type_shadow.stderr +++ b/src/tools/clippy/tests/ui/builtin_type_shadow.stderr @@ -5,6 +5,7 @@ LL | fn foo(a: u32) -> u32 { | ^^^ | = note: `-D clippy::builtin-type-shadow` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::builtin_type_shadow)]` error[E0308]: mismatched types --> $DIR/builtin_type_shadow.rs:5:5 diff --git a/src/tools/clippy/tests/ui/bytecount.rs b/src/tools/clippy/tests/ui/bytecount.rs index 4d168bfea..3794fc5d4 100644 --- a/src/tools/clippy/tests/ui/bytecount.rs +++ b/src/tools/clippy/tests/ui/bytecount.rs @@ -1,26 +1,39 @@ +//@no-rustfix + #![allow(clippy::needless_borrow, clippy::useless_vec)] #[deny(clippy::naive_bytecount)] fn main() { let x = vec![0_u8; 16]; - let _ = x.iter().filter(|&&a| a == 0).count(); // naive byte count + // naive byte count + let _ = x.iter().filter(|&&a| a == 0).count(); + //~^ ERROR: you appear to be counting bytes the naive way - let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); // naive byte count + // naive byte count + let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); + //~^ ERROR: you appear to be counting bytes the naive way - let _ = x.iter().filter(|a| **a > 0).count(); // not an equality count, OK. + // not an equality count, OK. + let _ = x.iter().filter(|a| **a > 0).count(); - let _ = x.iter().map(|a| a + 1).filter(|&a| a < 15).count(); // not a slice + // not a slice + let _ = x.iter().map(|a| a + 1).filter(|&a| a < 15).count(); let b = 0; - let _ = x.iter().filter(|_| b > 0).count(); // woah there + // woah there + let _ = x.iter().filter(|_| b > 0).count(); - let _ = x.iter().filter(|_a| b == b + 1).count(); // nothing to see here, move along + // nothing to see here, move along + let _ = x.iter().filter(|_a| b == b + 1).count(); - let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count + // naive byte count + let _ = x.iter().filter(|a| b + 1 == **a).count(); + //~^ ERROR: you appear to be counting bytes the naive way let y = vec![0_u16; 3]; - let _ = y.iter().filter(|&&a| a == 0).count(); // naive count, but not bytes + // naive count, but not bytes + let _ = y.iter().filter(|&&a| a == 0).count(); } diff --git a/src/tools/clippy/tests/ui/bytecount.stderr b/src/tools/clippy/tests/ui/bytecount.stderr index 68d838c1f..39007f9d1 100644 --- a/src/tools/clippy/tests/ui/bytecount.stderr +++ b/src/tools/clippy/tests/ui/bytecount.stderr @@ -1,25 +1,25 @@ error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:7:13 + --> $DIR/bytecount.rs:10:13 | -LL | let _ = x.iter().filter(|&&a| a == 0).count(); // naive byte count +LL | let _ = x.iter().filter(|&&a| a == 0).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, 0)` | note: the lint level is defined here - --> $DIR/bytecount.rs:3:8 + --> $DIR/bytecount.rs:5:8 | LL | #[deny(clippy::naive_bytecount)] | ^^^^^^^^^^^^^^^^^^^^^^^ error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:9:13 + --> $DIR/bytecount.rs:14:13 | -LL | let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); // naive byte count +LL | let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count((&x[..]), 0)` error: you appear to be counting bytes the naive way - --> $DIR/bytecount.rs:21:13 + --> $DIR/bytecount.rs:32:13 | -LL | let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count +LL | let _ = x.iter().filter(|a| b + 1 == **a).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the bytecount crate: `bytecount::count(x, b + 1)` error: aborting due to 3 previous errors diff --git a/src/tools/clippy/tests/ui/bytes_count_to_len.fixed b/src/tools/clippy/tests/ui/bytes_count_to_len.fixed index fb3d521ba..d20af2253 100644 --- a/src/tools/clippy/tests/ui/bytes_count_to_len.fixed +++ b/src/tools/clippy/tests/ui/bytes_count_to_len.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::bytes_count_to_len)] use std::fs::File; use std::io::Read; diff --git a/src/tools/clippy/tests/ui/bytes_count_to_len.rs b/src/tools/clippy/tests/ui/bytes_count_to_len.rs index 8e256b8f0..340e6b412 100644 --- a/src/tools/clippy/tests/ui/bytes_count_to_len.rs +++ b/src/tools/clippy/tests/ui/bytes_count_to_len.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::bytes_count_to_len)] use std::fs::File; use std::io::Read; diff --git a/src/tools/clippy/tests/ui/bytes_count_to_len.stderr b/src/tools/clippy/tests/ui/bytes_count_to_len.stderr index 224deb779..db0bb4099 100644 --- a/src/tools/clippy/tests/ui/bytes_count_to_len.stderr +++ b/src/tools/clippy/tests/ui/bytes_count_to_len.stderr @@ -1,25 +1,26 @@ error: using long and hard to read `.bytes().count()` - --> $DIR/bytes_count_to_len.rs:8:13 + --> $DIR/bytes_count_to_len.rs:7:13 | LL | let _ = String::from("foo").bytes().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `String::from("foo").len()` | = note: `-D clippy::bytes-count-to-len` implied by `-D warnings` + = 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:11:13 + --> $DIR/bytes_count_to_len.rs:10: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:14:13 + --> $DIR/bytes_count_to_len.rs:13: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:17:13 + --> $DIR/bytes_count_to_len.rs:16:13 | LL | let _ = s2.bytes().count(); | ^^^^^^^^^^^^^^^^^^ help: consider calling `.len()` instead: `s2.len()` diff --git a/src/tools/clippy/tests/ui/bytes_nth.fixed b/src/tools/clippy/tests/ui/bytes_nth.fixed index d3e0f676b..11deb2390 100644 --- a/src/tools/clippy/tests/ui/bytes_nth.fixed +++ b/src/tools/clippy/tests/ui/bytes_nth.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::unnecessary_operation)] #![warn(clippy::bytes_nth)] diff --git a/src/tools/clippy/tests/ui/bytes_nth.rs b/src/tools/clippy/tests/ui/bytes_nth.rs index b7d813fe2..62d9c7a5e 100644 --- a/src/tools/clippy/tests/ui/bytes_nth.rs +++ b/src/tools/clippy/tests/ui/bytes_nth.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::unnecessary_operation)] #![warn(clippy::bytes_nth)] diff --git a/src/tools/clippy/tests/ui/bytes_nth.stderr b/src/tools/clippy/tests/ui/bytes_nth.stderr index e8b150278..574bfaac1 100644 --- a/src/tools/clippy/tests/ui/bytes_nth.stderr +++ b/src/tools/clippy/tests/ui/bytes_nth.stderr @@ -1,19 +1,20 @@ error: called `.bytes().nth()` on a `String` - --> $DIR/bytes_nth.rs:8:13 + --> $DIR/bytes_nth.rs:6:13 | LL | let _ = s.bytes().nth(3); | ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3).copied()` | = note: `-D clippy::bytes-nth` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::bytes_nth)]` error: called `.bytes().nth().unwrap()` on a `String` - --> $DIR/bytes_nth.rs:9:14 + --> $DIR/bytes_nth.rs:7:14 | LL | let _ = &s.bytes().nth(3).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.as_bytes()[3]` error: called `.bytes().nth()` on a `str` - --> $DIR/bytes_nth.rs:10:13 + --> $DIR/bytes_nth.rs:8:13 | LL | let _ = s[..].bytes().nth(3); | ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3).copied()` diff --git a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed index d5af22aef..a816224c9 100644 --- a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed +++ b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::case_sensitive_file_extension_comparisons)] use std::string::String; diff --git a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs index f5f0a0022..994de2805 100644 --- a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs +++ b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::case_sensitive_file_extension_comparisons)] use std::string::String; diff --git a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.stderr b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.stderr index 44c8e3fdf..49c840bd7 100644 --- a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.stderr +++ b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.stderr @@ -1,11 +1,12 @@ error: case-sensitive file extension comparison - --> $DIR/case_sensitive_file_extension_comparisons.rs:14:5 + --> $DIR/case_sensitive_file_extension_comparisons.rs:13:5 | LL | filename.ends_with(".rs") | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using a case-insensitive comparison instead = note: `-D clippy::case-sensitive-file-extension-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::case_sensitive_file_extension_comparisons)]` help: use std::path::Path | LL ~ std::path::Path::new(filename) @@ -14,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:19:13 + --> $DIR/case_sensitive_file_extension_comparisons.rs:18:13 | LL | let _ = String::new().ends_with(".ext12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,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:20:13 + --> $DIR/case_sensitive_file_extension_comparisons.rs:19:13 | LL | let _ = "str".ends_with(".ext12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -42,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:24:17 + --> $DIR/case_sensitive_file_extension_comparisons.rs:23:17 | LL | let _ = "str".ends_with(".ext12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,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:31:13 + --> $DIR/case_sensitive_file_extension_comparisons.rs:30:13 | LL | let _ = String::new().ends_with(".EXT12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,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:32:13 + --> $DIR/case_sensitive_file_extension_comparisons.rs:31:13 | LL | let _ = "str".ends_with(".EXT12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/cast.rs b/src/tools/clippy/tests/ui/cast.rs index 60a0eabf5..1ca18170f 100644 --- a/src/tools/clippy/tests/ui/cast.rs +++ b/src/tools/clippy/tests/ui/cast.rs @@ -1,3 +1,5 @@ +//@no-rustfix + #![feature(repr128)] #![allow(incomplete_features)] #![warn( @@ -12,48 +14,101 @@ fn main() { // Test clippy::cast_precision_loss let x0 = 1i32; x0 as f32; + //~^ ERROR: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, + //~| NOTE: `-D clippy::cast-precision-loss` implied by `-D warnings` let x1 = 1i64; x1 as f32; + //~^ ERROR: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, x1 as f64; + //~^ ERROR: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide, let x2 = 1u32; x2 as f32; + //~^ ERROR: casting `u32` to `f32` causes a loss of precision (`u32` is 32 bits wide, let x3 = 1u64; x3 as f32; + //~^ ERROR: casting `u64` to `f32` causes a loss of precision (`u64` is 64 bits wide, x3 as f64; + //~^ ERROR: casting `u64` to `f64` causes a loss of precision (`u64` is 64 bits wide, // Test clippy::cast_possible_truncation 1f32 as i32; + //~^ ERROR: casting `f32` to `i32` may truncate the value 1f32 as u32; + //~^ ERROR: casting `f32` to `u32` may truncate the value + //~| ERROR: casting `f32` to `u32` may lose the sign of the value + //~| NOTE: `-D clippy::cast-sign-loss` implied by `-D warnings` 1f64 as f32; + //~^ ERROR: casting `f64` to `f32` may truncate the value 1i32 as i8; + //~^ ERROR: casting `i32` to `i8` may truncate the value 1i32 as u8; + //~^ ERROR: casting `i32` to `u8` may truncate the value 1f64 as isize; + //~^ ERROR: casting `f64` to `isize` may truncate the value 1f64 as usize; + //~^ ERROR: casting `f64` to `usize` may truncate the value + //~| ERROR: casting `f64` to `usize` may lose the sign of the value 1f32 as u32 as u16; + //~^ ERROR: casting `u32` to `u16` may truncate the value + //~| ERROR: casting `f32` to `u32` may truncate the value + //~| ERROR: casting `f32` to `u32` may lose the sign of the value { let _x: i8 = 1i32 as _; + //~^ ERROR: casting `i32` to `i8` may truncate the value 1f32 as i32; + //~^ ERROR: casting `f32` to `i32` may truncate the value 1f64 as i32; + //~^ ERROR: casting `f64` to `i32` may truncate the value 1f32 as u8; + //~^ ERROR: casting `f32` to `u8` may truncate the value + //~| ERROR: casting `f32` to `u8` may lose the sign of the value } // Test clippy::cast_possible_wrap 1u8 as i8; + //~^ ERROR: casting `u8` to `i8` may wrap around the value + //~| NOTE: `-D clippy::cast-possible-wrap` implied by `-D warnings` 1u16 as i16; + //~^ ERROR: casting `u16` to `i16` may wrap around the value 1u32 as i32; + //~^ ERROR: casting `u32` to `i32` may wrap around the value 1u64 as i64; + //~^ ERROR: casting `u64` to `i64` may wrap around the value 1usize as isize; - 1usize as i8; // should not wrap, usize is never 8 bits - 1usize as i16; // wraps on 16 bit ptr size - 1usize as i32; // wraps on 32 bit ptr size - 1usize as i64; // wraps on 64 bit ptr size - 1u8 as isize; // should not wrap, isize is never 8 bits - 1u16 as isize; // wraps on 16 bit ptr size - 1u32 as isize; // wraps on 32 bit ptr size - 1u64 as isize; // wraps on 64 bit ptr size + //~^ ERROR: casting `usize` to `isize` may wrap around the value + // should not wrap, usize is never 8 bits + 1usize as i8; + //~^ ERROR: casting `usize` to `i8` may truncate the value + // wraps on 16 bit ptr size + 1usize as i16; + //~^ ERROR: casting `usize` to `i16` may truncate the value + //~| ERROR: casting `usize` to `i16` may wrap around the value on targets with 16-bit + //~| NOTE: `usize` and `isize` may be as small as 16 bits on some platforms + // wraps on 32 bit ptr size + 1usize as i32; + //~^ ERROR: casting `usize` to `i32` may truncate the value on targets with 64-bit wid + //~| ERROR: casting `usize` to `i32` may wrap around the value on targets with 32-bit + // wraps on 64 bit ptr size + 1usize as i64; + //~^ ERROR: casting `usize` to `i64` may wrap around the value on targets with 64-bit + // should not wrap, isize is never 8 bits + 1u8 as isize; + // wraps on 16 bit ptr size + 1u16 as isize; + //~^ ERROR: casting `u16` to `isize` may wrap around the value on targets with 16-bit + //~| NOTE: `usize` and `isize` may be as small as 16 bits on some platforms + // wraps on 32 bit ptr size + 1u32 as isize; + //~^ ERROR: casting `u32` to `isize` may wrap around the value on targets with 32-bit + // wraps on 64 bit ptr size + 1u64 as isize; + //~^ ERROR: casting `u64` to `isize` may truncate the value on targets with 32-bit wid + //~| ERROR: casting `u64` to `isize` may wrap around the value on targets with 64-bit // Test clippy::cast_sign_loss 1i32 as u32; -1i32 as u32; + //~^ ERROR: casting `i32` to `u32` may lose the sign of the value 1isize as usize; -1isize as usize; + //~^ ERROR: casting `isize` to `usize` may lose the sign of the value 0i8 as u8; i8::MAX as u8; i16::MAX as u16; @@ -120,7 +175,9 @@ fn main() { let _ = s as i32; // Test for signed min - (-99999999999i64).min(1) as i8; // should be linted because signed + // should be linted because signed + (-99999999999i64).min(1) as i8; + //~^ ERROR: casting `i64` to `i8` may truncate the value // Test for various operations that remove enough bits for the result to fit (999999u64 & 1) as u8; @@ -132,7 +189,9 @@ fn main() { x.min(1) }) as u8; 999999u64.clamp(0, 255) as u8; - 999999u64.clamp(0, 256) as u8; // should still be linted + // should still be linted + 999999u64.clamp(0, 256) as u8; + //~^ ERROR: casting `u64` to `u8` may truncate the value #[derive(Clone, Copy)] enum E1 { @@ -142,7 +201,8 @@ fn main() { } impl E1 { fn test(self) { - let _ = self as u8; // Don't lint. `0..=2` fits in u8 + // Don't lint. `0..=2` fits in u8 + let _ = self as u8; } } @@ -154,9 +214,14 @@ fn main() { impl E2 { fn test(self) { let _ = self as u8; + //~^ ERROR: casting `main::E2` to `u8` may truncate the value let _ = Self::B as u8; - let _ = self as i16; // Don't lint. `255..=256` fits in i16 - let _ = Self::A as u8; // Don't lint. + //~^ ERROR: casting `main::E2::B` to `u8` will truncate the value + //~| NOTE: `-D clippy::cast-enum-truncation` implied by `-D warnings` + // Don't lint. `255..=256` fits in i16 + let _ = self as i16; + // Don't lint. + let _ = Self::A as u8; } } @@ -168,7 +233,8 @@ fn main() { } impl E3 { fn test(self) { - let _ = self as i8; // Don't lint. `-1..=50` fits in i8 + // Don't lint. `-1..=50` fits in i8 + let _ = self as i8; } } @@ -179,7 +245,8 @@ fn main() { } impl E4 { fn test(self) { - let _ = self as i8; // Don't lint. `-128..=-127` fits in i8 + // Don't lint. `-128..=-127` fits in i8 + let _ = self as i8; } } @@ -191,9 +258,13 @@ fn main() { impl E5 { fn test(self) { let _ = self as i8; + //~^ ERROR: casting `main::E5` to `i8` may truncate the value let _ = Self::A as i8; - let _ = self as i16; // Don't lint. `-129..=127` fits in i16 - let _ = Self::B as u8; // Don't lint. + //~^ ERROR: casting `main::E5::A` to `i8` will truncate the value + // Don't lint. `-129..=127` fits in i16 + let _ = self as i16; + // Don't lint. + let _ = Self::B as u8; } } @@ -206,9 +277,13 @@ fn main() { impl E6 { fn test(self) { let _ = self as i16; - let _ = Self::A as u16; // Don't lint. `2^16-1` fits in u16 - let _ = self as u32; // Don't lint. `2^16-1..=2^16` fits in u32 - let _ = Self::A as u16; // Don't lint. + //~^ ERROR: casting `main::E6` to `i16` may truncate the value + // Don't lint. `2^16-1` fits in u16 + let _ = Self::A as u16; + // Don't lint. `2^16-1..=2^16` fits in u32 + let _ = self as u32; + // Don't lint. + let _ = Self::A as u16; } } @@ -221,8 +296,11 @@ fn main() { impl E7 { fn test(self) { let _ = self as usize; - let _ = Self::A as usize; // Don't lint. - let _ = self as u64; // Don't lint. `2^32-1..=2^32` fits in u64 + //~^ ERROR: casting `main::E7` to `usize` may truncate the value on targets wi + // Don't lint. + let _ = Self::A as usize; + // Don't lint. `2^32-1..=2^32` fits in u64 + let _ = self as u64; } } @@ -236,7 +314,8 @@ fn main() { } impl E8 { fn test(self) { - let _ = self as i128; // Don't lint. `-(2^127)..=2^127-1` fits it i128 + // Don't lint. `-(2^127)..=2^127-1` fits it i128 + let _ = self as i128; } } @@ -248,8 +327,10 @@ fn main() { } impl E9 { fn test(self) { - let _ = Self::A as u8; // Don't lint. - let _ = self as u128; // Don't lint. `0..=2^128-1` fits in u128 + // Don't lint. + let _ = Self::A as u8; + // Don't lint. `0..=2^128-1` fits in u128 + let _ = self as u128; } } @@ -262,16 +343,25 @@ fn main() { impl E10 { fn test(self) { let _ = self as u16; - let _ = Self::B as u32; // Don't lint. - let _ = self as u64; // Don't lint. + //~^ ERROR: casting `main::E10` to `u16` may truncate the value + // Don't lint. + let _ = Self::B as u32; + // Don't lint. + let _ = self as u64; } } } fn avoid_subtract_overflow(q: u32) { let c = (q >> 16) as u8; + //~^ ERROR: casting `u32` to `u8` may truncate the value c as usize; let c = (q / 1000) as u8; + //~^ ERROR: casting `u32` to `u8` may truncate the value c as usize; } + +fn issue11426() { + (&42u8 >> 0xa9008fb6c9d81e42_0e25730562a601c8_u128) as usize; +} diff --git a/src/tools/clippy/tests/ui/cast.stderr b/src/tools/clippy/tests/ui/cast.stderr index de29af78e..bc74f7b72 100644 --- a/src/tools/clippy/tests/ui/cast.stderr +++ b/src/tools/clippy/tests/ui/cast.stderr @@ -1,52 +1,54 @@ 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.rs:14:5 + --> $DIR/cast.rs:16:5 | LL | x0 as f32; | ^^^^^^^^^ | = note: `-D clippy::cast-precision-loss` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_precision_loss)]` error: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast.rs:16:5 + --> $DIR/cast.rs:20:5 | LL | x1 as f32; | ^^^^^^^^^ error: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast.rs:17:5 + --> $DIR/cast.rs:22:5 | LL | x1 as f64; | ^^^^^^^^^ error: casting `u32` to `f32` causes a loss of precision (`u32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast.rs:19:5 + --> $DIR/cast.rs:25:5 | LL | x2 as f32; | ^^^^^^^^^ error: casting `u64` to `f32` causes a loss of precision (`u64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast.rs:21:5 + --> $DIR/cast.rs:28:5 | LL | x3 as f32; | ^^^^^^^^^ error: casting `u64` to `f64` causes a loss of precision (`u64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast.rs:22:5 + --> $DIR/cast.rs:30:5 | LL | x3 as f64; | ^^^^^^^^^ error: casting `f32` to `i32` may truncate the value - --> $DIR/cast.rs:24:5 + --> $DIR/cast.rs:33:5 | LL | 1f32 as i32; | ^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_possible_truncation)]` error: casting `f32` to `u32` may truncate the value - --> $DIR/cast.rs:25:5 + --> $DIR/cast.rs:35:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ @@ -54,15 +56,16 @@ LL | 1f32 as u32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u32` may lose the sign of the value - --> $DIR/cast.rs:25:5 + --> $DIR/cast.rs:35:5 | LL | 1f32 as u32; | ^^^^^^^^^^^ | = note: `-D clippy::cast-sign-loss` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_sign_loss)]` error: casting `f64` to `f32` may truncate the value - --> $DIR/cast.rs:26:5 + --> $DIR/cast.rs:39:5 | LL | 1f64 as f32; | ^^^^^^^^^^^ @@ -70,7 +73,7 @@ LL | 1f64 as f32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `i32` to `i8` may truncate the value - --> $DIR/cast.rs:27:5 + --> $DIR/cast.rs:41:5 | LL | 1i32 as i8; | ^^^^^^^^^^ @@ -82,7 +85,7 @@ LL | i8::try_from(1i32); | ~~~~~~~~~~~~~~~~~~ error: casting `i32` to `u8` may truncate the value - --> $DIR/cast.rs:28:5 + --> $DIR/cast.rs:43:5 | LL | 1i32 as u8; | ^^^^^^^^^^ @@ -94,7 +97,7 @@ LL | u8::try_from(1i32); | ~~~~~~~~~~~~~~~~~~ error: casting `f64` to `isize` may truncate the value - --> $DIR/cast.rs:29:5 + --> $DIR/cast.rs:45:5 | LL | 1f64 as isize; | ^^^^^^^^^^^^^ @@ -102,7 +105,7 @@ LL | 1f64 as isize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `usize` may truncate the value - --> $DIR/cast.rs:30:5 + --> $DIR/cast.rs:47:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ @@ -110,13 +113,13 @@ LL | 1f64 as usize; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `usize` may lose the sign of the value - --> $DIR/cast.rs:30:5 + --> $DIR/cast.rs:47:5 | LL | 1f64 as usize; | ^^^^^^^^^^^^^ error: casting `u32` to `u16` may truncate the value - --> $DIR/cast.rs:31:5 + --> $DIR/cast.rs:50:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^^^^^^^^ @@ -128,7 +131,7 @@ LL | u16::try_from(1f32 as u32); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `f32` to `u32` may truncate the value - --> $DIR/cast.rs:31:5 + --> $DIR/cast.rs:50:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^ @@ -136,13 +139,13 @@ LL | 1f32 as u32 as u16; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u32` may lose the sign of the value - --> $DIR/cast.rs:31:5 + --> $DIR/cast.rs:50:5 | LL | 1f32 as u32 as u16; | ^^^^^^^^^^^ error: casting `i32` to `i8` may truncate the value - --> $DIR/cast.rs:33:22 + --> $DIR/cast.rs:55:22 | LL | let _x: i8 = 1i32 as _; | ^^^^^^^^^ @@ -154,7 +157,7 @@ LL | let _x: i8 = 1i32.try_into(); | ~~~~~~~~~~~~~~~ error: casting `f32` to `i32` may truncate the value - --> $DIR/cast.rs:34:9 + --> $DIR/cast.rs:57:9 | LL | 1f32 as i32; | ^^^^^^^^^^^ @@ -162,7 +165,7 @@ LL | 1f32 as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f64` to `i32` may truncate the value - --> $DIR/cast.rs:35:9 + --> $DIR/cast.rs:59:9 | LL | 1f64 as i32; | ^^^^^^^^^^^ @@ -170,7 +173,7 @@ LL | 1f64 as i32; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u8` may truncate the value - --> $DIR/cast.rs:36:9 + --> $DIR/cast.rs:61:9 | LL | 1f32 as u8; | ^^^^^^^^^^ @@ -178,171 +181,172 @@ LL | 1f32 as u8; = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... error: casting `f32` to `u8` may lose the sign of the value - --> $DIR/cast.rs:36:9 + --> $DIR/cast.rs:61:9 | LL | 1f32 as u8; | ^^^^^^^^^^ error: casting `u8` to `i8` may wrap around the value - --> $DIR/cast.rs:39:5 + --> $DIR/cast.rs:66:5 | LL | 1u8 as i8; | ^^^^^^^^^ | = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_possible_wrap)]` error: casting `u16` to `i16` may wrap around the value - --> $DIR/cast.rs:40:5 + --> $DIR/cast.rs:69:5 | LL | 1u16 as i16; | ^^^^^^^^^^^ error: casting `u32` to `i32` may wrap around the value - --> $DIR/cast.rs:41:5 + --> $DIR/cast.rs:71:5 | LL | 1u32 as i32; | ^^^^^^^^^^^ error: casting `u64` to `i64` may wrap around the value - --> $DIR/cast.rs:42:5 + --> $DIR/cast.rs:73:5 | LL | 1u64 as i64; | ^^^^^^^^^^^ error: casting `usize` to `isize` may wrap around the value - --> $DIR/cast.rs:43:5 + --> $DIR/cast.rs:75:5 | LL | 1usize as isize; | ^^^^^^^^^^^^^^^ error: casting `usize` to `i8` may truncate the value - --> $DIR/cast.rs:44:5 + --> $DIR/cast.rs:78:5 | -LL | 1usize as i8; // should not wrap, usize is never 8 bits +LL | 1usize as i8; | ^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i8::try_from(1usize); // should not wrap, usize is never 8 bits +LL | i8::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may truncate the value - --> $DIR/cast.rs:45:5 + --> $DIR/cast.rs:81:5 | -LL | 1usize as i16; // wraps on 16 bit ptr size +LL | 1usize as i16; | ^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i16::try_from(1usize); // wraps on 16 bit ptr size +LL | i16::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i16` may wrap around the value on targets with 16-bit wide pointers - --> $DIR/cast.rs:45:5 + --> $DIR/cast.rs:81:5 | -LL | 1usize as i16; // wraps on 16 bit ptr size +LL | 1usize as i16; | ^^^^^^^^^^^^^ | = note: `usize` and `isize` may be as small as 16 bits on some platforms = note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:46:5 + --> $DIR/cast.rs:86:5 | -LL | 1usize as i32; // wraps on 32 bit ptr size +LL | 1usize as i32; | ^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i32::try_from(1usize); // wraps on 32 bit ptr size +LL | i32::try_from(1usize); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:46:5 + --> $DIR/cast.rs:86:5 | -LL | 1usize as i32; // wraps on 32 bit ptr size +LL | 1usize as i32; | ^^^^^^^^^^^^^ error: casting `usize` to `i64` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:47:5 + --> $DIR/cast.rs:90:5 | -LL | 1usize as i64; // wraps on 64 bit ptr size +LL | 1usize as i64; | ^^^^^^^^^^^^^ error: casting `u16` to `isize` may wrap around the value on targets with 16-bit wide pointers - --> $DIR/cast.rs:49:5 + --> $DIR/cast.rs:95:5 | -LL | 1u16 as isize; // wraps on 16 bit ptr size +LL | 1u16 as isize; | ^^^^^^^^^^^^^ | = note: `usize` and `isize` may be as small as 16 bits on some platforms = note: for more information see https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:50:5 + --> $DIR/cast.rs:99:5 | -LL | 1u32 as isize; // wraps on 32 bit ptr size +LL | 1u32 as isize; | ^^^^^^^^^^^^^ error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:51:5 + --> $DIR/cast.rs:102:5 | -LL | 1u64 as isize; // wraps on 64 bit ptr size +LL | 1u64 as isize; | ^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | isize::try_from(1u64); // wraps on 64 bit ptr size +LL | isize::try_from(1u64); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers - --> $DIR/cast.rs:51:5 + --> $DIR/cast.rs:102:5 | -LL | 1u64 as isize; // wraps on 64 bit ptr size +LL | 1u64 as isize; | ^^^^^^^^^^^^^ error: casting `i32` to `u32` may lose the sign of the value - --> $DIR/cast.rs:54:5 + --> $DIR/cast.rs:107:5 | LL | -1i32 as u32; | ^^^^^^^^^^^^ error: casting `isize` to `usize` may lose the sign of the value - --> $DIR/cast.rs:56:5 + --> $DIR/cast.rs:110:5 | LL | -1isize as usize; | ^^^^^^^^^^^^^^^^ error: casting `i64` to `i8` may truncate the value - --> $DIR/cast.rs:123:5 + --> $DIR/cast.rs:179:5 | -LL | (-99999999999i64).min(1) as i8; // should be linted because signed +LL | (-99999999999i64).min(1) as i8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | i8::try_from((-99999999999i64).min(1)); // should be linted because signed +LL | i8::try_from((-99999999999i64).min(1)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `u64` to `u8` may truncate the value - --> $DIR/cast.rs:135:5 + --> $DIR/cast.rs:193:5 | -LL | 999999u64.clamp(0, 256) as u8; // should still be linted +LL | 999999u64.clamp(0, 256) as u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... help: ... or use `try_from` and handle the error accordingly | -LL | u8::try_from(999999u64.clamp(0, 256)); // should still be linted +LL | u8::try_from(999999u64.clamp(0, 256)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E2` to `u8` may truncate the value - --> $DIR/cast.rs:156:21 + --> $DIR/cast.rs:216:21 | LL | let _ = self as u8; | ^^^^^^^^^^ @@ -354,15 +358,16 @@ LL | let _ = u8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E2::B` to `u8` will truncate the value - --> $DIR/cast.rs:157:21 + --> $DIR/cast.rs:218:21 | LL | let _ = Self::B as u8; | ^^^^^^^^^^^^^ | = note: `-D clippy::cast-enum-truncation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_enum_truncation)]` error: casting `main::E5` to `i8` may truncate the value - --> $DIR/cast.rs:193:21 + --> $DIR/cast.rs:260:21 | LL | let _ = self as i8; | ^^^^^^^^^^ @@ -374,13 +379,13 @@ LL | let _ = i8::try_from(self); | ~~~~~~~~~~~~~~~~~~ error: casting `main::E5::A` to `i8` will truncate the value - --> $DIR/cast.rs:194:21 + --> $DIR/cast.rs:262:21 | LL | let _ = Self::A as i8; | ^^^^^^^^^^^^^ error: casting `main::E6` to `i16` may truncate the value - --> $DIR/cast.rs:208:21 + --> $DIR/cast.rs:279:21 | LL | let _ = self as i16; | ^^^^^^^^^^^ @@ -392,7 +397,7 @@ LL | let _ = i16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `main::E7` to `usize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast.rs:223:21 + --> $DIR/cast.rs:298:21 | LL | let _ = self as usize; | ^^^^^^^^^^^^^ @@ -404,7 +409,7 @@ LL | let _ = usize::try_from(self); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `main::E10` to `u16` may truncate the value - --> $DIR/cast.rs:264:21 + --> $DIR/cast.rs:345:21 | LL | let _ = self as u16; | ^^^^^^^^^^^ @@ -416,7 +421,7 @@ LL | let _ = u16::try_from(self); | ~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> $DIR/cast.rs:272:13 + --> $DIR/cast.rs:356:13 | LL | let c = (q >> 16) as u8; | ^^^^^^^^^^^^^^^ @@ -428,7 +433,7 @@ LL | let c = u8::try_from(q >> 16); | ~~~~~~~~~~~~~~~~~~~~~ error: casting `u32` to `u8` may truncate the value - --> $DIR/cast.rs:275:13 + --> $DIR/cast.rs:360:13 | LL | let c = (q / 1000) as u8; | ^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed index ef0a93b01..6ca01b7cc 100644 --- a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed +++ b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::cast_abs_to_unsigned)] #![allow(clippy::uninlined_format_args, unused)] diff --git a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs index 96ced670a..190a77c10 100644 --- a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs +++ b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::cast_abs_to_unsigned)] #![allow(clippy::uninlined_format_args, unused)] diff --git a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.stderr b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.stderr index 4668554f4..fbdb559fc 100644 --- a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.stderr +++ b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.stderr @@ -1,109 +1,110 @@ error: casting the result of `i32::abs()` to u32 - --> $DIR/cast_abs_to_unsigned.rs:8:18 + --> $DIR/cast_abs_to_unsigned.rs:6:18 | LL | let y: u32 = x.abs() as u32; | ^^^^^^^^^^^^^^ help: replace with: `x.unsigned_abs()` | = note: `-D clippy::cast-abs-to-unsigned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_abs_to_unsigned)]` error: casting the result of `i32::abs()` to usize - --> $DIR/cast_abs_to_unsigned.rs:12:20 + --> $DIR/cast_abs_to_unsigned.rs:10:20 | LL | let _: usize = a.abs() as usize; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i32::abs()` to usize - --> $DIR/cast_abs_to_unsigned.rs:13:20 + --> $DIR/cast_abs_to_unsigned.rs:11:20 | LL | let _: usize = a.abs() as _; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i32::abs()` to usize - --> $DIR/cast_abs_to_unsigned.rs:14:13 + --> $DIR/cast_abs_to_unsigned.rs:12:13 | LL | let _ = a.abs() as usize; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to usize - --> $DIR/cast_abs_to_unsigned.rs:17:13 + --> $DIR/cast_abs_to_unsigned.rs:15:13 | LL | let _ = a.abs() as usize; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u8 - --> $DIR/cast_abs_to_unsigned.rs:18:13 + --> $DIR/cast_abs_to_unsigned.rs:16:13 | LL | let _ = a.abs() as u8; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u16 - --> $DIR/cast_abs_to_unsigned.rs:19:13 + --> $DIR/cast_abs_to_unsigned.rs:17:13 | LL | let _ = a.abs() as u16; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u32 - --> $DIR/cast_abs_to_unsigned.rs:20:13 + --> $DIR/cast_abs_to_unsigned.rs:18:13 | LL | let _ = a.abs() as u32; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u64 - --> $DIR/cast_abs_to_unsigned.rs:21:13 + --> $DIR/cast_abs_to_unsigned.rs:19:13 | LL | let _ = a.abs() as u64; | ^^^^^^^^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u128 - --> $DIR/cast_abs_to_unsigned.rs:22:13 + --> $DIR/cast_abs_to_unsigned.rs:20:13 | LL | let _ = a.abs() as u128; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to usize - --> $DIR/cast_abs_to_unsigned.rs:25:13 + --> $DIR/cast_abs_to_unsigned.rs:23:13 | LL | let _ = a.abs() as usize; | ^^^^^^^^^^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u8 - --> $DIR/cast_abs_to_unsigned.rs:26:13 + --> $DIR/cast_abs_to_unsigned.rs:24:13 | LL | let _ = a.abs() as u8; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u16 - --> $DIR/cast_abs_to_unsigned.rs:27:13 + --> $DIR/cast_abs_to_unsigned.rs:25:13 | LL | let _ = a.abs() as u16; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u32 - --> $DIR/cast_abs_to_unsigned.rs:28:13 + --> $DIR/cast_abs_to_unsigned.rs:26:13 | LL | let _ = a.abs() as u32; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u64 - --> $DIR/cast_abs_to_unsigned.rs:29:13 + --> $DIR/cast_abs_to_unsigned.rs:27:13 | LL | let _ = a.abs() as u64; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `isize::abs()` to u128 - --> $DIR/cast_abs_to_unsigned.rs:30:13 + --> $DIR/cast_abs_to_unsigned.rs:28:13 | LL | let _ = a.abs() as u128; | ^^^^^^^ help: replace with: `a.unsigned_abs()` error: casting the result of `i64::abs()` to u32 - --> $DIR/cast_abs_to_unsigned.rs:32:13 + --> $DIR/cast_abs_to_unsigned.rs:30:13 | 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:44:23 + --> $DIR/cast_abs_to_unsigned.rs:42:23 | LL | assert_eq!(10u32, x.abs() as u32); | ^^^^^^^^^^^^^^ help: replace with: `x.unsigned_abs()` diff --git a/src/tools/clippy/tests/ui/cast_alignment.rs b/src/tools/clippy/tests/ui/cast_alignment.rs index 95bb883df..98ef5e36f 100644 --- a/src/tools/clippy/tests/ui/cast_alignment.rs +++ b/src/tools/clippy/tests/ui/cast_alignment.rs @@ -17,11 +17,16 @@ fn main() { // cast to more-strictly-aligned type (&1u8 as *const u8) as *const u16; + //~^ ERROR: casting from `*const u8` to a more-strictly-aligned pointer (`*const u16`) + //~| NOTE: `-D clippy::cast-ptr-alignment` implied by `-D warnings` (&mut 1u8 as *mut u8) as *mut u16; + //~^ ERROR: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 // cast to more-strictly-aligned type, but with the `pointer::cast` function. (&1u8 as *const u8).cast::(); + //~^ ERROR: casting from `*const u8` to a more-strictly-aligned pointer (`*const u16`) (&mut 1u8 as *mut u8).cast::(); + //~^ ERROR: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 /* These should be ok */ diff --git a/src/tools/clippy/tests/ui/cast_alignment.stderr b/src/tools/clippy/tests/ui/cast_alignment.stderr index 5df2b5b10..49bd8dad9 100644 --- a/src/tools/clippy/tests/ui/cast_alignment.stderr +++ b/src/tools/clippy/tests/ui/cast_alignment.stderr @@ -5,21 +5,22 @@ LL | (&1u8 as *const u8) as *const u16; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::cast-ptr-alignment` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_ptr_alignment)]` error: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 < 2 bytes) - --> $DIR/cast_alignment.rs:20:5 + --> $DIR/cast_alignment.rs:22:5 | LL | (&mut 1u8 as *mut u8) as *mut u16; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting from `*const u8` to a more-strictly-aligned pointer (`*const u16`) (1 < 2 bytes) - --> $DIR/cast_alignment.rs:23:5 + --> $DIR/cast_alignment.rs:26:5 | LL | (&1u8 as *const u8).cast::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`) (1 < 2 bytes) - --> $DIR/cast_alignment.rs:24:5 + --> $DIR/cast_alignment.rs:28:5 | LL | (&mut 1u8 as *mut u8).cast::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/cast_enum_constructor.rs b/src/tools/clippy/tests/ui/cast_enum_constructor.rs index 0193454ad..3226f487b 100644 --- a/src/tools/clippy/tests/ui/cast_enum_constructor.rs +++ b/src/tools/clippy/tests/ui/cast_enum_constructor.rs @@ -11,7 +11,10 @@ fn main() { } let _ = Foo::Y as usize; + //~^ ERROR: cast of an enum tuple constructor to an integer + //~| NOTE: `-D clippy::cast-enum-constructor` implied by `-D warnings` let _ = Foo::Y as isize; + //~^ ERROR: cast of an enum tuple constructor to an integer let _ = Foo::Y as fn(u32) -> Foo; let _ = Bar::X as usize; } diff --git a/src/tools/clippy/tests/ui/cast_enum_constructor.stderr b/src/tools/clippy/tests/ui/cast_enum_constructor.stderr index 710909dd2..b1bf61ede 100644 --- a/src/tools/clippy/tests/ui/cast_enum_constructor.stderr +++ b/src/tools/clippy/tests/ui/cast_enum_constructor.stderr @@ -5,9 +5,10 @@ LL | let _ = Foo::Y as usize; | ^^^^^^^^^^^^^^^ | = note: `-D clippy::cast-enum-constructor` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_enum_constructor)]` error: cast of an enum tuple constructor to an integer - --> $DIR/cast_enum_constructor.rs:14:13 + --> $DIR/cast_enum_constructor.rs:16:13 | LL | let _ = Foo::Y as isize; | ^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/cast_lossless_bool.fixed b/src/tools/clippy/tests/ui/cast_lossless_bool.fixed index c321cc644..a4ce1c6f9 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_bool.fixed +++ b/src/tools/clippy/tests/ui/cast_lossless_bool.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] #![warn(clippy::cast_lossless)] diff --git a/src/tools/clippy/tests/ui/cast_lossless_bool.rs b/src/tools/clippy/tests/ui/cast_lossless_bool.rs index 632a71892..e5b1c30c1 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_bool.rs +++ b/src/tools/clippy/tests/ui/cast_lossless_bool.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] #![warn(clippy::cast_lossless)] diff --git a/src/tools/clippy/tests/ui/cast_lossless_bool.stderr b/src/tools/clippy/tests/ui/cast_lossless_bool.stderr index ce240b70f..e4a5b2e80 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_bool.stderr +++ b/src/tools/clippy/tests/ui/cast_lossless_bool.stderr @@ -1,85 +1,86 @@ error: casting `bool` to `u8` is more cleanly stated with `u8::from(_)` - --> $DIR/cast_lossless_bool.rs:8:13 + --> $DIR/cast_lossless_bool.rs:6:13 | LL | let _ = true as u8; | ^^^^^^^^^^ help: try: `u8::from(true)` | = note: `-D clippy::cast-lossless` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` error: casting `bool` to `u16` is more cleanly stated with `u16::from(_)` - --> $DIR/cast_lossless_bool.rs:9:13 + --> $DIR/cast_lossless_bool.rs:7:13 | LL | let _ = true as u16; | ^^^^^^^^^^^ help: try: `u16::from(true)` error: casting `bool` to `u32` is more cleanly stated with `u32::from(_)` - --> $DIR/cast_lossless_bool.rs:10:13 + --> $DIR/cast_lossless_bool.rs:8:13 | LL | let _ = true as u32; | ^^^^^^^^^^^ help: try: `u32::from(true)` error: casting `bool` to `u64` is more cleanly stated with `u64::from(_)` - --> $DIR/cast_lossless_bool.rs:11:13 + --> $DIR/cast_lossless_bool.rs:9:13 | LL | let _ = true as u64; | ^^^^^^^^^^^ help: try: `u64::from(true)` error: casting `bool` to `u128` is more cleanly stated with `u128::from(_)` - --> $DIR/cast_lossless_bool.rs:12:13 + --> $DIR/cast_lossless_bool.rs:10:13 | LL | let _ = true as u128; | ^^^^^^^^^^^^ help: try: `u128::from(true)` error: casting `bool` to `usize` is more cleanly stated with `usize::from(_)` - --> $DIR/cast_lossless_bool.rs:13:13 + --> $DIR/cast_lossless_bool.rs:11:13 | LL | let _ = true as usize; | ^^^^^^^^^^^^^ help: try: `usize::from(true)` error: casting `bool` to `i8` is more cleanly stated with `i8::from(_)` - --> $DIR/cast_lossless_bool.rs:15:13 + --> $DIR/cast_lossless_bool.rs:13:13 | LL | let _ = true as i8; | ^^^^^^^^^^ help: try: `i8::from(true)` error: casting `bool` to `i16` is more cleanly stated with `i16::from(_)` - --> $DIR/cast_lossless_bool.rs:16:13 + --> $DIR/cast_lossless_bool.rs:14:13 | LL | let _ = true as i16; | ^^^^^^^^^^^ help: try: `i16::from(true)` error: casting `bool` to `i32` is more cleanly stated with `i32::from(_)` - --> $DIR/cast_lossless_bool.rs:17:13 + --> $DIR/cast_lossless_bool.rs:15:13 | LL | let _ = true as i32; | ^^^^^^^^^^^ help: try: `i32::from(true)` error: casting `bool` to `i64` is more cleanly stated with `i64::from(_)` - --> $DIR/cast_lossless_bool.rs:18:13 + --> $DIR/cast_lossless_bool.rs:16:13 | LL | let _ = true as i64; | ^^^^^^^^^^^ help: try: `i64::from(true)` error: casting `bool` to `i128` is more cleanly stated with `i128::from(_)` - --> $DIR/cast_lossless_bool.rs:19:13 + --> $DIR/cast_lossless_bool.rs:17:13 | LL | let _ = true as i128; | ^^^^^^^^^^^^ help: try: `i128::from(true)` error: casting `bool` to `isize` is more cleanly stated with `isize::from(_)` - --> $DIR/cast_lossless_bool.rs:20:13 + --> $DIR/cast_lossless_bool.rs:18:13 | LL | let _ = true as isize; | ^^^^^^^^^^^^^ help: try: `isize::from(true)` error: casting `bool` to `u16` is more cleanly stated with `u16::from(_)` - --> $DIR/cast_lossless_bool.rs:23:13 + --> $DIR/cast_lossless_bool.rs:21:13 | LL | let _ = (true | false) as u16; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::from(true | false)` error: casting `bool` to `u8` is more cleanly stated with `u8::from(_)` - --> $DIR/cast_lossless_bool.rs:51:13 + --> $DIR/cast_lossless_bool.rs:49:13 | LL | let _ = true as u8; | ^^^^^^^^^^ help: try: `u8::from(true)` diff --git a/src/tools/clippy/tests/ui/cast_lossless_float.fixed b/src/tools/clippy/tests/ui/cast_lossless_float.fixed index e72a0096a..f4f2e4773 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_float.fixed +++ b/src/tools/clippy/tests/ui/cast_lossless_float.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)] #![warn(clippy::cast_lossless)] diff --git a/src/tools/clippy/tests/ui/cast_lossless_float.rs b/src/tools/clippy/tests/ui/cast_lossless_float.rs index dbcbaa9b8..fdd88ed36 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_float.rs +++ b/src/tools/clippy/tests/ui/cast_lossless_float.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)] #![warn(clippy::cast_lossless)] diff --git a/src/tools/clippy/tests/ui/cast_lossless_float.stderr b/src/tools/clippy/tests/ui/cast_lossless_float.stderr index 8326d40be..95e80b4e4 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_float.stderr +++ b/src/tools/clippy/tests/ui/cast_lossless_float.stderr @@ -1,67 +1,68 @@ error: casting `i8` to `f32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:9:13 + --> $DIR/cast_lossless_float.rs:7:13 | LL | let _ = x0 as f32; | ^^^^^^^^^ help: try: `f32::from(x0)` | = note: `-D clippy::cast-lossless` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` error: casting `i8` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:10:13 + --> $DIR/cast_lossless_float.rs:8:13 | LL | let _ = x0 as f64; | ^^^^^^^^^ help: try: `f64::from(x0)` error: casting `u8` to `f32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:12:13 + --> $DIR/cast_lossless_float.rs:10:13 | LL | let _ = x1 as f32; | ^^^^^^^^^ help: try: `f32::from(x1)` error: casting `u8` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:13:13 + --> $DIR/cast_lossless_float.rs:11:13 | LL | let _ = x1 as f64; | ^^^^^^^^^ help: try: `f64::from(x1)` error: casting `i16` to `f32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:15:13 + --> $DIR/cast_lossless_float.rs:13:13 | LL | let _ = x2 as f32; | ^^^^^^^^^ help: try: `f32::from(x2)` error: casting `i16` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:16:13 + --> $DIR/cast_lossless_float.rs:14:13 | LL | let _ = x2 as f64; | ^^^^^^^^^ help: try: `f64::from(x2)` error: casting `u16` to `f32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:18:13 + --> $DIR/cast_lossless_float.rs:16:13 | LL | let _ = x3 as f32; | ^^^^^^^^^ help: try: `f32::from(x3)` error: casting `u16` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:19:13 + --> $DIR/cast_lossless_float.rs:17:13 | LL | let _ = x3 as f64; | ^^^^^^^^^ help: try: `f64::from(x3)` error: casting `i32` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:21:13 + --> $DIR/cast_lossless_float.rs:19:13 | LL | let _ = x4 as f64; | ^^^^^^^^^ help: try: `f64::from(x4)` error: casting `u32` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:23:13 + --> $DIR/cast_lossless_float.rs:21:13 | LL | let _ = x5 as f64; | ^^^^^^^^^ help: try: `f64::from(x5)` error: casting `f32` to `f64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_float.rs:26:13 + --> $DIR/cast_lossless_float.rs:24:13 | LL | let _ = 1.0f32 as f64; | ^^^^^^^^^^^^^ help: try: `f64::from(1.0f32)` diff --git a/src/tools/clippy/tests/ui/cast_lossless_integer.fixed b/src/tools/clippy/tests/ui/cast_lossless_integer.fixed index 7dab02084..5e7e545e7 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_integer.fixed +++ b/src/tools/clippy/tests/ui/cast_lossless_integer.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)] #![warn(clippy::cast_lossless)] @@ -51,3 +49,14 @@ mod cast_lossless_in_impl { enum Test { A = u32::MAX as i64 + 1, } + +fn issue11458() { + macro_rules! sign_cast { + ($var: ident, $src: ty, $dest: ty) => { + <$dest>::from_ne_bytes(($var as $src).to_ne_bytes()) + }; + } + let x = 10_u128; + let _ = i32::from(sign_cast!(x, u8, i8)); + let _ = i32::from(sign_cast!(x, u8, i8) + 1); +} diff --git a/src/tools/clippy/tests/ui/cast_lossless_integer.rs b/src/tools/clippy/tests/ui/cast_lossless_integer.rs index c24f73960..0d69ddbd5 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_integer.rs +++ b/src/tools/clippy/tests/ui/cast_lossless_integer.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)] #![warn(clippy::cast_lossless)] @@ -51,3 +49,14 @@ mod cast_lossless_in_impl { enum Test { A = u32::MAX as i64 + 1, } + +fn issue11458() { + macro_rules! sign_cast { + ($var: ident, $src: ty, $dest: ty) => { + <$dest>::from_ne_bytes(($var as $src).to_ne_bytes()) + }; + } + let x = 10_u128; + let _ = sign_cast!(x, u8, i8) as i32; + let _ = (sign_cast!(x, u8, i8) + 1) as i32; +} diff --git a/src/tools/clippy/tests/ui/cast_lossless_integer.stderr b/src/tools/clippy/tests/ui/cast_lossless_integer.stderr index 721b94876..f9f111a7c 100644 --- a/src/tools/clippy/tests/ui/cast_lossless_integer.stderr +++ b/src/tools/clippy/tests/ui/cast_lossless_integer.stderr @@ -1,118 +1,131 @@ error: casting `i8` to `i16` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:8:13 + --> $DIR/cast_lossless_integer.rs:6:13 | LL | let _ = 1i8 as i16; | ^^^^^^^^^^ help: try: `i16::from(1i8)` | = note: `-D clippy::cast-lossless` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` error: casting `i8` to `i32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:9:13 + --> $DIR/cast_lossless_integer.rs:7:13 | LL | let _ = 1i8 as i32; | ^^^^^^^^^^ help: try: `i32::from(1i8)` error: casting `i8` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:10:13 + --> $DIR/cast_lossless_integer.rs:8:13 | LL | let _ = 1i8 as i64; | ^^^^^^^^^^ help: try: `i64::from(1i8)` error: casting `u8` to `i16` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:11:13 + --> $DIR/cast_lossless_integer.rs:9:13 | LL | let _ = 1u8 as i16; | ^^^^^^^^^^ help: try: `i16::from(1u8)` error: casting `u8` to `i32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:12:13 + --> $DIR/cast_lossless_integer.rs:10:13 | LL | let _ = 1u8 as i32; | ^^^^^^^^^^ help: try: `i32::from(1u8)` error: casting `u8` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:13:13 + --> $DIR/cast_lossless_integer.rs:11:13 | LL | let _ = 1u8 as i64; | ^^^^^^^^^^ help: try: `i64::from(1u8)` error: casting `u8` to `u16` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:14:13 + --> $DIR/cast_lossless_integer.rs:12:13 | LL | let _ = 1u8 as u16; | ^^^^^^^^^^ help: try: `u16::from(1u8)` error: casting `u8` to `u32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:15:13 + --> $DIR/cast_lossless_integer.rs:13:13 | LL | let _ = 1u8 as u32; | ^^^^^^^^^^ help: try: `u32::from(1u8)` error: casting `u8` to `u64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:16:13 + --> $DIR/cast_lossless_integer.rs:14:13 | LL | let _ = 1u8 as u64; | ^^^^^^^^^^ help: try: `u64::from(1u8)` error: casting `i16` to `i32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:17:13 + --> $DIR/cast_lossless_integer.rs:15:13 | LL | let _ = 1i16 as i32; | ^^^^^^^^^^^ help: try: `i32::from(1i16)` error: casting `i16` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:18:13 + --> $DIR/cast_lossless_integer.rs:16:13 | LL | let _ = 1i16 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1i16)` error: casting `u16` to `i32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:19:13 + --> $DIR/cast_lossless_integer.rs:17:13 | LL | let _ = 1u16 as i32; | ^^^^^^^^^^^ help: try: `i32::from(1u16)` error: casting `u16` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:20:13 + --> $DIR/cast_lossless_integer.rs:18:13 | LL | let _ = 1u16 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1u16)` error: casting `u16` to `u32` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:21:13 + --> $DIR/cast_lossless_integer.rs:19:13 | LL | let _ = 1u16 as u32; | ^^^^^^^^^^^ help: try: `u32::from(1u16)` error: casting `u16` to `u64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:22:13 + --> $DIR/cast_lossless_integer.rs:20:13 | LL | let _ = 1u16 as u64; | ^^^^^^^^^^^ help: try: `u64::from(1u16)` error: casting `i32` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:23:13 + --> $DIR/cast_lossless_integer.rs:21:13 | LL | let _ = 1i32 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1i32)` error: casting `u32` to `i64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:24:13 + --> $DIR/cast_lossless_integer.rs:22:13 | LL | let _ = 1u32 as i64; | ^^^^^^^^^^^ help: try: `i64::from(1u32)` error: casting `u32` to `u64` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:25:13 + --> $DIR/cast_lossless_integer.rs:23:13 | LL | let _ = 1u32 as u64; | ^^^^^^^^^^^ help: try: `u64::from(1u32)` error: casting `u8` to `u16` may become silently lossy if you later change the type - --> $DIR/cast_lossless_integer.rs:28:13 + --> $DIR/cast_lossless_integer.rs:26:13 | LL | let _ = (1u8 + 1u8) as u16; | ^^^^^^^^^^^^^^^^^^ help: try: `u16::from(1u8 + 1u8)` -error: aborting due to 19 previous errors +error: casting `i8` to `i32` may become silently lossy if you later change the type + --> $DIR/cast_lossless_integer.rs:60:13 + | +LL | let _ = sign_cast!(x, u8, i8) as i32; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::from(sign_cast!(x, u8, i8))` + +error: casting `i8` to `i32` may become silently lossy if you later change the type + --> $DIR/cast_lossless_integer.rs:61:13 + | +LL | let _ = (sign_cast!(x, u8, i8) + 1) as i32; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::from(sign_cast!(x, u8, i8) + 1)` + +error: aborting due to 21 previous errors diff --git a/src/tools/clippy/tests/ui/cast_nan_to_int.rs b/src/tools/clippy/tests/ui/cast_nan_to_int.rs index 287c5aa21..2d7467ff0 100644 --- a/src/tools/clippy/tests/ui/cast_nan_to_int.rs +++ b/src/tools/clippy/tests/ui/cast_nan_to_int.rs @@ -3,12 +3,24 @@ fn main() { let _ = (0.0_f32 / -0.0) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (f64::INFINITY * -0.0) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (0.0 * f32::INFINITY) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (f32::INFINITY - f32::INFINITY) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize; + //~^ ERROR: casting a known NaN to usize + //~| NOTE: this always evaluates to 0 // those won't be linted: let _ = (1.0_f32 / 0.0) as usize; diff --git a/src/tools/clippy/tests/ui/cast_nan_to_int.stderr b/src/tools/clippy/tests/ui/cast_nan_to_int.stderr index 3539be75a..c0bb29448 100644 --- a/src/tools/clippy/tests/ui/cast_nan_to_int.stderr +++ b/src/tools/clippy/tests/ui/cast_nan_to_int.stderr @@ -6,9 +6,10 @@ LL | let _ = (0.0_f32 / -0.0) as usize; | = note: this always evaluates to 0 = note: `-D clippy::cast-nan-to-int` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_nan_to_int)]` error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:6:13 + --> $DIR/cast_nan_to_int.rs:8:13 | LL | let _ = (f64::INFINITY * -0.0) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | let _ = (f64::INFINITY * -0.0) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:7:13 + --> $DIR/cast_nan_to_int.rs:11:13 | LL | let _ = (0.0 * f32::INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | let _ = (0.0 * f32::INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:9:13 + --> $DIR/cast_nan_to_int.rs:15:13 | LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:10:13 + --> $DIR/cast_nan_to_int.rs:18:13 | LL | let _ = (f32::INFINITY - f32::INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | let _ = (f32::INFINITY - f32::INFINITY) as usize; = note: this always evaluates to 0 error: casting a known NaN to usize - --> $DIR/cast_nan_to_int.rs:11:13 + --> $DIR/cast_nan_to_int.rs:21:13 | LL | let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.fixed b/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.fixed index 9b6fee270..e78bd66c3 100644 --- a/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.fixed +++ b/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::cast_slice_from_raw_parts)] #[allow(unused_imports, unused_unsafe)] diff --git a/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs b/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs index c0bb81379..c3d8c7bee 100644 --- a/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs +++ b/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::cast_slice_from_raw_parts)] #[allow(unused_imports, unused_unsafe)] diff --git a/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.stderr b/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.stderr index f07801c19..47dc39a30 100644 --- a/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.stderr +++ b/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.stderr @@ -1,43 +1,44 @@ error: casting the result of `from_raw_parts` to *const [u8] - --> $DIR/cast_raw_slice_pointer_cast.rs:9:35 + --> $DIR/cast_raw_slice_pointer_cast.rs:8:35 | 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)` | = note: `-D clippy::cast-slice-from-raw-parts` implied by `-D warnings` + = 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:10:35 + --> $DIR/cast_raw_slice_pointer_cast.rs:9: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:11:26 + --> $DIR/cast_raw_slice_pointer_cast.rs:10: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:14:30 + --> $DIR/cast_raw_slice_pointer_cast.rs:13: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:16:30 + --> $DIR/cast_raw_slice_pointer_cast.rs:15: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:20:30 + --> $DIR/cast_raw_slice_pointer_cast.rs:19: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:22:30 + --> $DIR/cast_raw_slice_pointer_cast.rs:21: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/src/tools/clippy/tests/ui/cast_size.32bit.stderr b/src/tools/clippy/tests/ui/cast_size.32bit.stderr new file mode 100644 index 000000000..379ca6086 --- /dev/null +++ b/src/tools/clippy/tests/ui/cast_size.32bit.stderr @@ -0,0 +1,181 @@ +error: casting `isize` to `i8` may truncate the value + --> $DIR/cast_size.rs:15:5 + | +LL | 1isize as i8; + | ^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... + = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_possible_truncation)]` +help: ... or use `try_from` and handle the error accordingly + | +LL | i8::try_from(1isize); + | ~~~~~~~~~~~~~~~~~~~~ + +error: casting `isize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`isize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) + --> $DIR/cast_size.rs:18:5 + | +LL | x0 as f64; + | ^^^^^^^^^ + | + = note: `-D clippy::cast-precision-loss` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_precision_loss)]` + +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:19:5 + | +LL | x1 as f64; + | ^^^^^^^^^ + +error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) + --> $DIR/cast_size.rs:20:5 + | +LL | x0 as f32; + | ^^^^^^^^^ + +error: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) + --> $DIR/cast_size.rs:21:5 + | +LL | x1 as f32; + | ^^^^^^^^^ + +error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast_size.rs:22:5 + | +LL | 1isize as i32; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +LL | i32::try_from(1isize); + | ~~~~~~~~~~~~~~~~~~~~~ + +error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast_size.rs:23:5 + | +LL | 1isize as u32; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +LL | u32::try_from(1isize); + | ~~~~~~~~~~~~~~~~~~~~~ + +error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast_size.rs:24:5 + | +LL | 1usize as u32; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +LL | u32::try_from(1usize); + | ~~~~~~~~~~~~~~~~~~~~~ + +error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast_size.rs:25:5 + | +LL | 1usize as i32; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +LL | i32::try_from(1usize); + | ~~~~~~~~~~~~~~~~~~~~~ + +error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers + --> $DIR/cast_size.rs:25:5 + | +LL | 1usize as i32; + | ^^^^^^^^^^^^^ + | + = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` + = 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 + | +LL | 1i64 as isize; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +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 + | +LL | 1i64 as usize; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +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 + | +LL | 1u64 as isize; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +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 + | +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 + | +LL | 1u64 as usize; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +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 + | +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 + | +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 + | +LL | 9_999_999_999_999_999usize as f64; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: literal out of range for `usize` + --> $DIR/cast_size.rs:36:5 + | +LL | 9_999_999_999_999_999usize as f64; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the literal `9_999_999_999_999_999usize` does not fit into the type `usize` whose range is `0..=4294967295` + = note: `#[deny(overflowing_literals)]` on by default + +error: aborting due to 19 previous errors + diff --git a/src/tools/clippy/tests/ui/cast_size.64bit.stderr b/src/tools/clippy/tests/ui/cast_size.64bit.stderr new file mode 100644 index 000000000..7fae92b12 --- /dev/null +++ b/src/tools/clippy/tests/ui/cast_size.64bit.stderr @@ -0,0 +1,172 @@ +error: casting `isize` to `i8` may truncate the value + --> $DIR/cast_size.rs:15:5 + | +LL | 1isize as i8; + | ^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... + = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_possible_truncation)]` +help: ... or use `try_from` and handle the error accordingly + | +LL | i8::try_from(1isize); + | ~~~~~~~~~~~~~~~~~~~~ + +error: casting `isize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`isize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) + --> $DIR/cast_size.rs:18:5 + | +LL | x0 as f64; + | ^^^^^^^^^ + | + = note: `-D clippy::cast-precision-loss` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_precision_loss)]` + +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:19:5 + | +LL | x1 as f64; + | ^^^^^^^^^ + +error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) + --> $DIR/cast_size.rs:20:5 + | +LL | x0 as f32; + | ^^^^^^^^^ + +error: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) + --> $DIR/cast_size.rs:21:5 + | +LL | x1 as f32; + | ^^^^^^^^^ + +error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast_size.rs:22:5 + | +LL | 1isize as i32; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +LL | i32::try_from(1isize); + | ~~~~~~~~~~~~~~~~~~~~~ + +error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast_size.rs:23:5 + | +LL | 1isize as u32; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +LL | u32::try_from(1isize); + | ~~~~~~~~~~~~~~~~~~~~~ + +error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast_size.rs:24:5 + | +LL | 1usize as u32; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +LL | u32::try_from(1usize); + | ~~~~~~~~~~~~~~~~~~~~~ + +error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers + --> $DIR/cast_size.rs:25:5 + | +LL | 1usize as i32; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +LL | i32::try_from(1usize); + | ~~~~~~~~~~~~~~~~~~~~~ + +error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers + --> $DIR/cast_size.rs:25:5 + | +LL | 1usize as i32; + | ^^^^^^^^^^^^^ + | + = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` + = 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 + | +LL | 1i64 as isize; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +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 + | +LL | 1i64 as usize; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +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 + | +LL | 1u64 as isize; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +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 + | +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 + | +LL | 1u64 as usize; + | ^^^^^^^^^^^^^ + | + = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... +help: ... or use `try_from` and handle the error accordingly + | +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 + | +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 + | +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 + | +LL | 9_999_999_999_999_999usize as f64; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 18 previous errors + diff --git a/src/tools/clippy/tests/ui/cast_size.rs b/src/tools/clippy/tests/ui/cast_size.rs index cd2184aea..d063a70cc 100644 --- a/src/tools/clippy/tests/ui/cast_size.rs +++ b/src/tools/clippy/tests/ui/cast_size.rs @@ -1,12 +1,15 @@ -//@ignore-32bit -#[warn( +//@stderr-per-bitwidth +//@no-rustfix + +#![warn( clippy::cast_precision_loss, clippy::cast_possible_truncation, clippy::cast_sign_loss, clippy::cast_possible_wrap, clippy::cast_lossless )] -#[allow(clippy::no_effect, clippy::unnecessary_operation)] +#![allow(clippy::no_effect, clippy::unnecessary_operation)] + fn main() { // Casting from *size 1isize as i8; @@ -20,7 +23,6 @@ fn main() { 1isize as u32; 1usize as u32; 1usize as i32; - // Casting to *size 1i64 as isize; 1i64 as usize; 1u64 as isize; diff --git a/src/tools/clippy/tests/ui/cast_size.stderr b/src/tools/clippy/tests/ui/cast_size.stderr deleted file mode 100644 index 6d2d49d9e..000000000 --- a/src/tools/clippy/tests/ui/cast_size.stderr +++ /dev/null @@ -1,169 +0,0 @@ -error: casting `isize` to `i8` may truncate the value - --> $DIR/cast_size.rs:12:5 - | -LL | 1isize as i8; - | ^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... - = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` -help: ... or use `try_from` and handle the error accordingly - | -LL | i8::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~ - -error: casting `isize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`isize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast_size.rs:15:5 - | -LL | x0 as f64; - | ^^^^^^^^^ - | - = note: `-D clippy::cast-precision-loss` implied by `-D warnings` - -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:16:5 - | -LL | x1 as f64; - | ^^^^^^^^^ - -error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast_size.rs:17:5 - | -LL | x0 as f32; - | ^^^^^^^^^ - -error: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast_size.rs:18:5 - | -LL | x1 as f32; - | ^^^^^^^^^ - -error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:19:5 - | -LL | 1isize as i32; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -LL | i32::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~~ - -error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:20:5 - | -LL | 1isize as u32; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -LL | u32::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~~ - -error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:21:5 - | -LL | 1usize as u32; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -LL | u32::try_from(1usize); - | ~~~~~~~~~~~~~~~~~~~~~ - -error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size.rs:22:5 - | -LL | 1usize as i32; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -LL | i32::try_from(1usize); - | ~~~~~~~~~~~~~~~~~~~~~ - -error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:22:5 - | -LL | 1usize as i32; - | ^^^^^^^^^^^^^ - | - = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` - -error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size.rs:24:5 - | -LL | 1i64 as isize; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -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:25:5 - | -LL | 1i64 as usize; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -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:26:5 - | -LL | 1u64 as isize; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -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:26: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:27:5 - | -LL | 1u64 as usize; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -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:28: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:33: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:34:5 - | -LL | 9_999_999_999_999_999usize as f64; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 18 previous errors - diff --git a/src/tools/clippy/tests/ui/cast_size_32bit.rs b/src/tools/clippy/tests/ui/cast_size_32bit.rs deleted file mode 100644 index 7ca20d3ca..000000000 --- a/src/tools/clippy/tests/ui/cast_size_32bit.rs +++ /dev/null @@ -1,35 +0,0 @@ -//@ignore-64bit -#[warn( - clippy::cast_precision_loss, - clippy::cast_possible_truncation, - clippy::cast_sign_loss, - clippy::cast_possible_wrap, - clippy::cast_lossless -)] -#[allow(clippy::no_effect, clippy::unnecessary_operation)] -fn main() { - // Casting from *size - 1isize as i8; - 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; - 1usize as i32; - // Casting to *size - 1i64 as isize; - 1i64 as usize; - 1u64 as isize; - 1u64 as usize; - 1u32 as isize; - 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; - 3_999_999_999usize as f64; -} diff --git a/src/tools/clippy/tests/ui/cast_size_32bit.stderr b/src/tools/clippy/tests/ui/cast_size_32bit.stderr deleted file mode 100644 index fb51783a4..000000000 --- a/src/tools/clippy/tests/ui/cast_size_32bit.stderr +++ /dev/null @@ -1,171 +0,0 @@ -error: casting `isize` to `i8` may truncate the value - --> $DIR/cast_size_32bit.rs:12:5 - | -LL | 1isize as i8; - | ^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... - = note: `-D clippy::cast-possible-truncation` implied by `-D warnings` -help: ... or use `try_from` and handle the error accordingly - | -LL | i8::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~ - -error: casting `isize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`isize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide) - --> $DIR/cast_size_32bit.rs:15:5 - | -LL | x0 as f64; - | ^^^^^^^^^ - | - = note: `-D clippy::cast-precision-loss` implied by `-D warnings` - -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_32bit.rs:16:5 - | -LL | x1 as f64; - | ^^^^^^^^^ - -error: casting `isize` to `f32` causes a loss of precision (`isize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast_size_32bit.rs:17:5 - | -LL | x0 as f32; - | ^^^^^^^^^ - -error: casting `usize` to `f32` causes a loss of precision (`usize` is 32 or 64 bits wide, but `f32`'s mantissa is only 23 bits wide) - --> $DIR/cast_size_32bit.rs:18:5 - | -LL | x1 as f32; - | ^^^^^^^^^ - -error: casting `isize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size_32bit.rs:19:5 - | -LL | 1isize as i32; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -LL | i32::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~~ - -error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size_32bit.rs:20:5 - | -LL | 1isize as u32; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -LL | u32::try_from(1isize); - | ~~~~~~~~~~~~~~~~~~~~~ - -error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size_32bit.rs:21:5 - | -LL | 1usize as u32; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -LL | u32::try_from(1usize); - | ~~~~~~~~~~~~~~~~~~~~~ - -error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers - --> $DIR/cast_size_32bit.rs:22:5 - | -LL | 1usize as i32; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -LL | i32::try_from(1usize); - | ~~~~~~~~~~~~~~~~~~~~~ - -error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers - --> $DIR/cast_size_32bit.rs:22:5 - | -LL | 1usize as i32; - | ^^^^^^^^^^^^^ - | - = note: `-D clippy::cast-possible-wrap` implied by `-D warnings` - -error: casting `i64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size_32bit.rs:24:5 - | -LL | 1i64 as isize; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -LL | isize::try_from(1i64); - | ~~~~~~~~~~~~~~~~~~~~~ - -error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size_32bit.rs:25:5 - | -LL | 1i64 as usize; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -LL | usize::try_from(1i64); - | ~~~~~~~~~~~~~~~~~~~~~ - -error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size_32bit.rs:26:5 - | -LL | 1u64 as isize; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -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_32bit.rs:26:5 - | -LL | 1u64 as isize; - | ^^^^^^^^^^^^^ - -error: casting `u64` to `usize` may truncate the value on targets with 32-bit wide pointers - --> $DIR/cast_size_32bit.rs:27:5 - | -LL | 1u64 as usize; - | ^^^^^^^^^^^^^ - | - = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... -help: ... or use `try_from` and handle the error accordingly - | -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_32bit.rs:28: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_32bit.rs:33:5 - | -LL | 999_999_999 as f32; - | ^^^^^^^^^^^^^^^^^^ - -error: casting integer literal to `f64` is unnecessary - --> $DIR/cast_size_32bit.rs:34:5 - | -LL | 3_999_999_999usize as f64; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `3_999_999_999_f64` - | - = note: `-D clippy::unnecessary-cast` implied by `-D warnings` - -error: aborting due to 18 previous errors - diff --git a/src/tools/clippy/tests/ui/cast_slice_different_sizes.rs b/src/tools/clippy/tests/ui/cast_slice_different_sizes.rs index 27e03ebb7..d8101030a 100644 --- a/src/tools/clippy/tests/ui/cast_slice_different_sizes.rs +++ b/src/tools/clippy/tests/ui/cast_slice_different_sizes.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![allow(clippy::let_unit_value, clippy::unnecessary_cast)] fn main() { @@ -7,10 +8,14 @@ fn main() { // Because it's separate, it does not check the cast back to something of the same size let a = r_x as *const [i32]; let b = a as *const [u8]; + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme + //~| NOTE: `#[deny(clippy::cast_slice_different_sizes)]` on by default let c = b as *const [u32]; + //~^ ERROR: casting between raw pointers to `[u8]` (element size 1) and `[u32]` (eleme // loses data let loss = r_x as *const [i32] as *const [u8]; + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme // Cast back to same size but different type loses no data, just type conversion // This is weird code but there's no reason for this lint specifically to fire *twice* on it @@ -18,7 +23,9 @@ fn main() { // Check casting through blocks is detected let loss_block_1 = { r_x as *const [i32] } as *const [u8]; + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme let loss_block_2 = { + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme let _ = (); r_x as *const [i32] } as *const [u8]; @@ -36,6 +43,7 @@ fn main() { // Check that the result of a long chain of casts is detected let long_chain_loss = r_x as *const [i32] as *const [u32] as *const [u16] as *const [i8] as *const [u8]; + //~^ ERROR: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (eleme let long_chain_restore = r_x as *const [i32] as *const [u32] as *const [u16] as *const [i8] as *const [u8] as *const [u32]; } @@ -51,32 +59,40 @@ fn foo2(x: *mut [u8]) -> *mut [u8] { // Test that casts as part of function returns work fn bar(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as *mut [u8] } fn uwu(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as *mut _ } fn bar2(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as _ } // constify fn bar3(x: *mut [u16]) -> *const [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as _ } // unconstify fn bar4(x: *const [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s x as _ } // function returns plus blocks fn blocks(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s ({ x }) as _ } fn more_blocks(x: *mut [u16]) -> *mut [u8] { + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element s { ({ x }) as _ } + //~^ ERROR: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (eleme } diff --git a/src/tools/clippy/tests/ui/cast_slice_different_sizes.stderr b/src/tools/clippy/tests/ui/cast_slice_different_sizes.stderr index 40721dcd0..a5c38e310 100644 --- a/src/tools/clippy/tests/ui/cast_slice_different_sizes.stderr +++ b/src/tools/clippy/tests/ui/cast_slice_different_sizes.stderr @@ -1,5 +1,5 @@ error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:9:13 + --> $DIR/cast_slice_different_sizes.rs:10:13 | LL | let b = a as *const [u8]; | ^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(a as *const u8, ..)` @@ -7,28 +7,29 @@ LL | let b = a as *const [u8]; = note: `#[deny(clippy::cast_slice_different_sizes)]` on by default error: casting between raw pointers to `[u8]` (element size 1) and `[u32]` (element size 4) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:10:13 + --> $DIR/cast_slice_different_sizes.rs:13:13 | LL | let c = b as *const [u32]; | ^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(b as *const u32, ..)` error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:13:16 + --> $DIR/cast_slice_different_sizes.rs:17:16 | LL | let loss = r_x as *const [i32] as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(r_x as *const [i32] as *const u8, ..)` error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:20:24 + --> $DIR/cast_slice_different_sizes.rs:25:24 | LL | let loss_block_1 = { r_x as *const [i32] } as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts({ r_x as *const [i32] } as *const u8, ..)` error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:21:24 + --> $DIR/cast_slice_different_sizes.rs:27:24 | LL | let loss_block_2 = { | ________________________^ +LL | | LL | | let _ = (); LL | | r_x as *const [i32] LL | | } as *const [u8]; @@ -37,82 +38,91 @@ LL | | } as *const [u8]; help: replace with `ptr::slice_from_raw_parts` | LL ~ let loss_block_2 = core::ptr::slice_from_raw_parts({ +LL + LL + let _ = (); LL + r_x as *const [i32] LL ~ } as *const u8, ..); | error: casting between raw pointers to `[i32]` (element size 4) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:38:27 + --> $DIR/cast_slice_different_sizes.rs:45:27 | LL | let long_chain_loss = r_x as *const [i32] as *const [u32] as *const [u16] as *const [i8] as *const [u8]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(r_x as *const [i32] as *const u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:53:36 + --> $DIR/cast_slice_different_sizes.rs:61:36 | LL | fn bar(x: *mut [u16]) -> *mut [u8] { | ____________________________________^ +LL | | LL | | x as *mut [u8] LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:57:36 + --> $DIR/cast_slice_different_sizes.rs:66:36 | LL | fn uwu(x: *mut [u16]) -> *mut [u8] { | ____________________________________^ +LL | | LL | | x as *mut _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:61:37 + --> $DIR/cast_slice_different_sizes.rs:71:37 | LL | fn bar2(x: *mut [u16]) -> *mut [u8] { | _____________________________________^ +LL | | LL | | x as _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:66:39 + --> $DIR/cast_slice_different_sizes.rs:77:39 | LL | fn bar3(x: *mut [u16]) -> *const [u8] { | _______________________________________^ +LL | | LL | | x as _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts`: `core::ptr::slice_from_raw_parts(x as *const u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:71:39 + --> $DIR/cast_slice_different_sizes.rs:83:39 | LL | fn bar4(x: *const [u16]) -> *mut [u8] { | _______________________________________^ +LL | | LL | | x as _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(x as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:76:39 + --> $DIR/cast_slice_different_sizes.rs:89:39 | LL | fn blocks(x: *mut [u16]) -> *mut [u8] { | _______________________________________^ +LL | | LL | | ({ x }) as _ LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:80:44 + --> $DIR/cast_slice_different_sizes.rs:94:44 | LL | fn more_blocks(x: *mut [u16]) -> *mut [u8] { | ____________________________________________^ +LL | | LL | | { ({ x }) as _ } +LL | | LL | | } | |_^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)` error: casting between raw pointers to `[u16]` (element size 2) and `[u8]` (element size 1) does not adjust the count - --> $DIR/cast_slice_different_sizes.rs:81:5 + --> $DIR/cast_slice_different_sizes.rs:96:5 | LL | { ({ x }) as _ } | ^^^^^^^^^^^^^^^^ help: replace with `ptr::slice_from_raw_parts_mut`: `core::ptr::slice_from_raw_parts_mut(({ x }) as *mut u8, ..)` diff --git a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed index 13aadb7d3..05d5b3d10 100644 --- a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed +++ b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + #![feature(stmt_expr_attributes)] #![allow(unused, clippy::no_effect, clippy::unnecessary_operation)] diff --git a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs index 769c5d22b..bc29e2021 100644 --- a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs +++ b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs @@ -1,4 +1,4 @@ -//@run-rustfix + #![feature(stmt_expr_attributes)] #![allow(unused, clippy::no_effect, clippy::unnecessary_operation)] diff --git a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr index 524a2bf72..8816ce2d8 100644 --- a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr +++ b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr @@ -5,6 +5,7 @@ LL | #[cfg_attr(rustfmt, rustfmt::skip)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]` | = note: `-D clippy::deprecated-cfg-attr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::deprecated_cfg_attr)]` error: `cfg_attr` is deprecated for rustfmt and got replaced by tool attributes --> $DIR/cfg_attr_rustfmt.rs:22:1 diff --git a/src/tools/clippy/tests/ui/cfg_features.fixed b/src/tools/clippy/tests/ui/cfg_features.fixed new file mode 100644 index 000000000..3d52f2382 --- /dev/null +++ b/src/tools/clippy/tests/ui/cfg_features.fixed @@ -0,0 +1,17 @@ +#![warn(clippy::maybe_misused_cfg)] + +fn main() { + #[cfg(feature = "not-really-a-feature")] + //~^ ERROR: feature may misspelled as features + //~| NOTE: `-D clippy::maybe-misused-cfg` implied by `-D warnings` + let _ = 1 + 2; + + #[cfg(all(feature = "right", feature = "wrong"))] + //~^ ERROR: feature may misspelled as features + let _ = 1 + 2; + + #[cfg(all(feature = "wrong1", any(feature = "right", feature = "wrong2", feature, features)))] + //~^ ERROR: feature may misspelled as features + //~| ERROR: feature may misspelled as features + let _ = 1 + 2; +} diff --git a/src/tools/clippy/tests/ui/cfg_features.rs b/src/tools/clippy/tests/ui/cfg_features.rs index bc4109c2c..a0344a004 100644 --- a/src/tools/clippy/tests/ui/cfg_features.rs +++ b/src/tools/clippy/tests/ui/cfg_features.rs @@ -2,11 +2,16 @@ fn main() { #[cfg(features = "not-really-a-feature")] + //~^ ERROR: feature may misspelled as features + //~| NOTE: `-D clippy::maybe-misused-cfg` implied by `-D warnings` let _ = 1 + 2; #[cfg(all(feature = "right", features = "wrong"))] + //~^ ERROR: feature may misspelled as features let _ = 1 + 2; #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))] + //~^ ERROR: feature may misspelled as features + //~| ERROR: feature may misspelled as features let _ = 1 + 2; } diff --git a/src/tools/clippy/tests/ui/cfg_features.stderr b/src/tools/clippy/tests/ui/cfg_features.stderr index 00405985d..401c3e92e 100644 --- a/src/tools/clippy/tests/ui/cfg_features.stderr +++ b/src/tools/clippy/tests/ui/cfg_features.stderr @@ -5,21 +5,22 @@ LL | #[cfg(features = "not-really-a-feature")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `feature = "not-really-a-feature"` | = note: `-D clippy::maybe-misused-cfg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::maybe_misused_cfg)]` error: feature may misspelled as features - --> $DIR/cfg_features.rs:7:34 + --> $DIR/cfg_features.rs:9:34 | LL | #[cfg(all(feature = "right", features = "wrong"))] | ^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong"` error: feature may misspelled as features - --> $DIR/cfg_features.rs:10:15 + --> $DIR/cfg_features.rs:13:15 | LL | #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))] | ^^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong1"` error: feature may misspelled as features - --> $DIR/cfg_features.rs:10:59 + --> $DIR/cfg_features.rs:13:59 | LL | #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))] | ^^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong2"` diff --git a/src/tools/clippy/tests/ui/char_lit_as_u8.rs b/src/tools/clippy/tests/ui/char_lit_as_u8.rs index 0a53a3d64..7bb3daf0f 100644 --- a/src/tools/clippy/tests/ui/char_lit_as_u8.rs +++ b/src/tools/clippy/tests/ui/char_lit_as_u8.rs @@ -1,5 +1,8 @@ #![warn(clippy::char_lit_as_u8)] fn main() { - let _ = '❤' as u8; // no suggestion, since a byte literal won't work. + // no suggestion, since a byte literal won't work. + let _ = '❤' as u8; + //~^ ERROR: casting a character literal to `u8` truncates + //~| NOTE: `char` is four bytes wide, but `u8` is a single byte } diff --git a/src/tools/clippy/tests/ui/char_lit_as_u8.stderr b/src/tools/clippy/tests/ui/char_lit_as_u8.stderr index 39fc9d6dd..ce1f2f829 100644 --- a/src/tools/clippy/tests/ui/char_lit_as_u8.stderr +++ b/src/tools/clippy/tests/ui/char_lit_as_u8.stderr @@ -1,11 +1,12 @@ error: casting a character literal to `u8` truncates - --> $DIR/char_lit_as_u8.rs:4:13 + --> $DIR/char_lit_as_u8.rs:5:13 | -LL | let _ = '❤' as u8; // no suggestion, since a byte literal won't work. +LL | let _ = '❤' as u8; | ^^^^^^^^^ | = note: `char` is four bytes wide, but `u8` is a single byte = note: `-D clippy::char-lit-as-u8` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::char_lit_as_u8)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.fixed b/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.fixed index ce2f149dc..6f13078a3 100644 --- a/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.fixed +++ b/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::char_lit_as_u8)] fn main() { diff --git a/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.rs b/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.rs index ffad12fc6..7737eb513 100644 --- a/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.rs +++ b/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::char_lit_as_u8)] fn main() { diff --git a/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.stderr b/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.stderr index 586174c50..359857119 100644 --- a/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.stderr +++ b/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.stderr @@ -1,33 +1,34 @@ error: casting a character literal to `u8` truncates - --> $DIR/char_lit_as_u8_suggestions.rs:6:13 + --> $DIR/char_lit_as_u8_suggestions.rs:4:13 | LL | let _ = 'a' as u8; | ^^^^^^^^^ help: use a byte literal instead: `b'a'` | = note: `char` is four bytes wide, but `u8` is a single byte = note: `-D clippy::char-lit-as-u8` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::char_lit_as_u8)]` error: casting a character literal to `u8` truncates - --> $DIR/char_lit_as_u8_suggestions.rs:7:13 + --> $DIR/char_lit_as_u8_suggestions.rs:5:13 | -LL | let _ = '/n' as u8; - | ^^^^^^^^^^ help: use a byte literal instead: `b'/n'` +LL | let _ = '\n' as u8; + | ^^^^^^^^^^ help: use a byte literal instead: `b'\n'` | = note: `char` is four bytes wide, but `u8` is a single byte error: casting a character literal to `u8` truncates - --> $DIR/char_lit_as_u8_suggestions.rs:8:13 + --> $DIR/char_lit_as_u8_suggestions.rs:6:13 | -LL | let _ = '/0' as u8; - | ^^^^^^^^^^ help: use a byte literal instead: `b'/0'` +LL | let _ = '\0' as u8; + | ^^^^^^^^^^ help: use a byte literal instead: `b'\0'` | = note: `char` is four bytes wide, but `u8` is a single byte error: casting a character literal to `u8` truncates - --> $DIR/char_lit_as_u8_suggestions.rs:9:13 + --> $DIR/char_lit_as_u8_suggestions.rs:7:13 | -LL | let _ = '/x01' as u8; - | ^^^^^^^^^^^^ help: use a byte literal instead: `b'/x01'` +LL | let _ = '\x01' as u8; + | ^^^^^^^^^^^^ help: use a byte literal instead: `b'\x01'` | = note: `char` is four bytes wide, but `u8` is a single byte diff --git a/src/tools/clippy/tests/ui/checked_conversions.fixed b/src/tools/clippy/tests/ui/checked_conversions.fixed index 188e6d975..0e05a2742 100644 --- a/src/tools/clippy/tests/ui/checked_conversions.fixed +++ b/src/tools/clippy/tests/ui/checked_conversions.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( clippy::cast_lossless, unused, diff --git a/src/tools/clippy/tests/ui/checked_conversions.rs b/src/tools/clippy/tests/ui/checked_conversions.rs index 70f0f0975..ac7826992 100644 --- a/src/tools/clippy/tests/ui/checked_conversions.rs +++ b/src/tools/clippy/tests/ui/checked_conversions.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( clippy::cast_lossless, unused, diff --git a/src/tools/clippy/tests/ui/checked_conversions.stderr b/src/tools/clippy/tests/ui/checked_conversions.stderr index 273ead73b..3e0169b74 100644 --- a/src/tools/clippy/tests/ui/checked_conversions.stderr +++ b/src/tools/clippy/tests/ui/checked_conversions.stderr @@ -1,103 +1,104 @@ error: checked cast can be simplified - --> $DIR/checked_conversions.rs:16:13 + --> $DIR/checked_conversions.rs:14:13 | LL | let _ = value <= (u32::max_value() as i64) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()` | = note: `-D clippy::checked-conversions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::checked_conversions)]` error: checked cast can be simplified - --> $DIR/checked_conversions.rs:17:13 + --> $DIR/checked_conversions.rs:15: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:21:13 + --> $DIR/checked_conversions.rs:19: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:22:13 + --> $DIR/checked_conversions.rs:20: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:26:13 + --> $DIR/checked_conversions.rs:24: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:27:13 + --> $DIR/checked_conversions.rs:25: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:33:13 + --> $DIR/checked_conversions.rs:31: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:34:13 + --> $DIR/checked_conversions.rs:32: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:38:13 + --> $DIR/checked_conversions.rs:36: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:39:13 + --> $DIR/checked_conversions.rs:37: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:45:13 + --> $DIR/checked_conversions.rs:43: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:46:13 + --> $DIR/checked_conversions.rs:44: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:50:13 + --> $DIR/checked_conversions.rs:48: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:51:13 + --> $DIR/checked_conversions.rs:49: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:55:13 + --> $DIR/checked_conversions.rs:53: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:56:13 + --> $DIR/checked_conversions.rs:54: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:89:13 + --> $DIR/checked_conversions.rs:87:13 | LL | let _ = value <= (u32::MAX as i64) && value >= 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()` diff --git a/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.rs b/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.rs index 16e54a7d9..323dae380 100644 --- a/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.rs +++ b/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.rs @@ -9,10 +9,18 @@ fn test_complex_conditions() { let x: Result<(), ()> = Ok(()); let y: Result<(), ()> = Ok(()); if x.is_ok() && y.is_err() { - x.unwrap(); // unnecessary - x.unwrap_err(); // will panic - y.unwrap(); // will panic - y.unwrap_err(); // unnecessary + // unnecessary + x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok` + // will panic + x.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic + // will panic + y.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic + // unnecessary + y.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_err` } else { // not statically determinable whether any of the following will always succeed or always fail: x.unwrap(); @@ -26,19 +34,39 @@ fn test_complex_conditions() { x.unwrap(); y.unwrap(); } else { - x.unwrap(); // will panic - x.unwrap_err(); // unnecessary - y.unwrap(); // will panic - y.unwrap_err(); // unnecessary + // will panic + x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic + // unnecessary + x.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok` + // will panic + y.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic + // unnecessary + y.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_ok` } let z: Result<(), ()> = Ok(()); if x.is_ok() && !(y.is_ok() || z.is_err()) { - x.unwrap(); // unnecessary - x.unwrap_err(); // will panic - y.unwrap(); // will panic - y.unwrap_err(); // unnecessary - z.unwrap(); // unnecessary - z.unwrap_err(); // will panic + // unnecessary + x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok` + // will panic + x.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic + // will panic + y.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic + // unnecessary + y.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_ok` + // unnecessary + z.unwrap(); + //~^ ERROR: called `unwrap` on `z` after checking its variant with `is_err` + // will panic + z.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic } if x.is_ok() || !(y.is_ok() && z.is_err()) { // not statically determinable whether any of the following will always succeed or always fail: @@ -46,12 +74,24 @@ fn test_complex_conditions() { y.unwrap(); z.unwrap(); } else { - x.unwrap(); // will panic - x.unwrap_err(); // unnecessary - y.unwrap(); // unnecessary - y.unwrap_err(); // will panic - z.unwrap(); // will panic - z.unwrap_err(); // unnecessary + // will panic + x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic + // unnecessary + x.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok` + // unnecessary + y.unwrap(); + //~^ ERROR: called `unwrap` on `y` after checking its variant with `is_ok` + // will panic + y.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic + // will panic + z.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic + // unnecessary + z.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `z` after checking its variant with `is_err` } } diff --git a/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.stderr b/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.stderr index c395c5ba0..73c074a93 100644 --- a/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.stderr +++ b/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.stderr @@ -1,9 +1,10 @@ error: called `unwrap` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:12:9 + --> $DIR/complex_conditionals.rs:13:9 | LL | if x.is_ok() && y.is_err() { | --------- the check is happening here -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ | = help: try using `if let` or `match` @@ -14,12 +15,12 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:13:9 + --> $DIR/complex_conditionals.rs:16:9 | LL | if x.is_ok() && y.is_err() { | --------- because of this check -LL | x.unwrap(); // unnecessary -LL | x.unwrap_err(); // will panic +... +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ | note: the lint level is defined here @@ -29,180 +30,181 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:14:9 + --> $DIR/complex_conditionals.rs:19:9 | LL | if x.is_ok() && y.is_err() { | ---------- because of this check ... -LL | y.unwrap(); // will panic +LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:15:9 + --> $DIR/complex_conditionals.rs:22:9 | LL | if x.is_ok() && y.is_err() { | ---------- the check is happening here ... -LL | y.unwrap_err(); // unnecessary +LL | y.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:29:9 + --> $DIR/complex_conditionals.rs:38:9 | LL | if x.is_ok() || y.is_ok() { | --------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:30:9 + --> $DIR/complex_conditionals.rs:41:9 | LL | if x.is_ok() || y.is_ok() { | --------- the check is happening here ... -LL | x.unwrap_err(); // unnecessary +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:31:9 + --> $DIR/complex_conditionals.rs:44:9 | LL | if x.is_ok() || y.is_ok() { | --------- because of this check ... -LL | y.unwrap(); // will panic +LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:32:9 + --> $DIR/complex_conditionals.rs:47:9 | LL | if x.is_ok() || y.is_ok() { | --------- the check is happening here ... -LL | y.unwrap_err(); // unnecessary +LL | y.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: called `unwrap` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:36:9 + --> $DIR/complex_conditionals.rs:53:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- the check is happening here -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:37:9 + --> $DIR/complex_conditionals.rs:56:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- because of this check -LL | x.unwrap(); // unnecessary -LL | x.unwrap_err(); // will panic +... +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:38:9 + --> $DIR/complex_conditionals.rs:59:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- because of this check ... -LL | y.unwrap(); // will panic +LL | y.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:39:9 + --> $DIR/complex_conditionals.rs:62:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- the check is happening here ... -LL | y.unwrap_err(); // unnecessary +LL | y.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: called `unwrap` on `z` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:40:9 + --> $DIR/complex_conditionals.rs:65:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | ---------- the check is happening here ... -LL | z.unwrap(); // unnecessary +LL | z.unwrap(); | ^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:41:9 + --> $DIR/complex_conditionals.rs:68:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | ---------- because of this check ... -LL | z.unwrap_err(); // will panic +LL | z.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:49:9 + --> $DIR/complex_conditionals.rs:78:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:50:9 + --> $DIR/complex_conditionals.rs:81:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- the check is happening here ... -LL | x.unwrap_err(); // unnecessary +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` error: called `unwrap` on `y` after checking its variant with `is_ok` - --> $DIR/complex_conditionals.rs:51:9 + --> $DIR/complex_conditionals.rs:84:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- the check is happening here ... -LL | y.unwrap(); // unnecessary +LL | y.unwrap(); | ^^^^^^^^^^ | = help: try using `if let` or `match` error: this call to `unwrap_err()` will always panic - --> $DIR/complex_conditionals.rs:52:9 + --> $DIR/complex_conditionals.rs:87:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- because of this check ... -LL | y.unwrap_err(); // will panic +LL | y.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals.rs:53:9 + --> $DIR/complex_conditionals.rs:90:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | ---------- because of this check ... -LL | z.unwrap(); // will panic +LL | z.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `z` after checking its variant with `is_err` - --> $DIR/complex_conditionals.rs:54:9 + --> $DIR/complex_conditionals.rs:93:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | ---------- the check is happening here ... -LL | z.unwrap_err(); // unnecessary +LL | z.unwrap_err(); | ^^^^^^^^^^^^^^ | = help: try using `if let` or `match` diff --git a/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals_nested.rs b/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals_nested.rs index e417cf833..68923793d 100644 --- a/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals_nested.rs +++ b/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals_nested.rs @@ -4,14 +4,18 @@ clippy::branches_sharing_code, clippy::unnecessary_literal_unwrap )] - +//@no-rustfix fn test_nested() { fn nested() { let x = Some(()); if x.is_some() { - x.unwrap(); // unnecessary + // unnecessary + x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_some` } else { - x.unwrap(); // will panic + // will panic + x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic } } } diff --git a/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals_nested.stderr b/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals_nested.stderr index 049a69d93..d9f701a5b 100644 --- a/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals_nested.stderr +++ b/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals_nested.stderr @@ -1,9 +1,10 @@ error: called `unwrap` on `x` after checking its variant with `is_some` - --> $DIR/complex_conditionals_nested.rs:12:13 + --> $DIR/complex_conditionals_nested.rs:13:13 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ | note: the lint level is defined here @@ -13,12 +14,12 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/complex_conditionals_nested.rs:14:13 + --> $DIR/complex_conditionals_nested.rs:17:13 | LL | if x.is_some() { | ----------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ | note: the lint level is defined here diff --git a/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.rs b/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.rs index 61042bb90..02f80cc52 100644 --- a/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.rs +++ b/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![feature(lint_reasons)] #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] #![allow( @@ -9,7 +10,8 @@ macro_rules! m { ($a:expr) => { if $a.is_some() { - $a.unwrap(); // unnecessary + // unnecessary + $a.unwrap(); } }; } @@ -41,37 +43,72 @@ macro_rules! checks_some { fn main() { let x = Some(()); if x.is_some() { - x.unwrap(); // unnecessary - x.expect("an error message"); // unnecessary + // unnecessary + x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_some` + // unnecessary + x.expect("an error message"); + //~^ ERROR: called `expect` on `x` after checking its variant with `is_some` } else { - x.unwrap(); // will panic - x.expect("an error message"); // will panic + // will panic + x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic + // will panic + x.expect("an error message"); + //~^ ERROR: this call to `expect()` will always panic } if x.is_none() { - x.unwrap(); // will panic + // will panic + x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic } else { - x.unwrap(); // unnecessary + // unnecessary + x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_none` } m!(x); - checks_in_param!(x.is_some(), x.unwrap()); // ok - checks_unwrap!(x, x.unwrap()); // ok - checks_some!(x.is_some(), x); // ok + // ok + checks_in_param!(x.is_some(), x.unwrap()); + // ok + checks_unwrap!(x, x.unwrap()); + // ok + checks_some!(x.is_some(), x); let mut x: Result<(), ()> = Ok(()); if x.is_ok() { - x.unwrap(); // unnecessary - x.expect("an error message"); // unnecessary - x.unwrap_err(); // will panic + // unnecessary + x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok` + // unnecessary + x.expect("an error message"); + //~^ ERROR: called `expect` on `x` after checking its variant with `is_ok` + // will panic + x.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic } else { - x.unwrap(); // will panic - x.expect("an error message"); // will panic - x.unwrap_err(); // unnecessary + // will panic + x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic + // will panic + x.expect("an error message"); + //~^ ERROR: this call to `expect()` will always panic + // unnecessary + x.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok` } if x.is_err() { - x.unwrap(); // will panic - x.unwrap_err(); // unnecessary + // will panic + x.unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic + // unnecessary + x.unwrap_err(); + //~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_err` } else { - x.unwrap(); // unnecessary - x.unwrap_err(); // will panic + // unnecessary + x.unwrap(); + //~^ ERROR: called `unwrap` on `x` after checking its variant with `is_err` + // will panic + x.unwrap_err(); + //~^ ERROR: this call to `unwrap_err()` will always panic } if x.is_ok() { x = Err(()); @@ -87,20 +124,76 @@ fn main() { x.unwrap_err(); } - assert!(x.is_ok(), "{:?}", x.unwrap_err()); // ok, it's a common test pattern + // ok, it's a common test pattern + assert!(x.is_ok(), "{:?}", x.unwrap_err()); +} + +fn issue11371() { + let option = Some(()); + + if option.is_some() { + option.as_ref().unwrap(); + //~^ ERROR: called `unwrap` on `option` after checking its variant with `is_some` + } else { + option.as_ref().unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic + } + + let result = Ok::<(), ()>(()); + + if result.is_ok() { + result.as_ref().unwrap(); + //~^ ERROR: called `unwrap` on `result` after checking its variant with `is_ok` + } else { + result.as_ref().unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic + } + + let mut option = Some(()); + if option.is_some() { + option.as_mut().unwrap(); + //~^ ERROR: called `unwrap` on `option` after checking its variant with `is_some` + } else { + option.as_mut().unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic + } + + let mut result = Ok::<(), ()>(()); + if result.is_ok() { + result.as_mut().unwrap(); + //~^ ERROR: called `unwrap` on `result` after checking its variant with `is_ok` + } else { + result.as_mut().unwrap(); + //~^ ERROR: this call to `unwrap()` will always panic + } + + // This should not lint. Statics are, at the time of writing, not linted on anyway, + // but if at some point they are supported by this lint, it should correctly see that + // `X` is being mutated and not suggest `if let Some(..) = X {}` + static mut X: Option = Some(123); + unsafe { + if X.is_some() { + X = None; + X.unwrap(); + } + } } fn check_expect() { let x = Some(()); if x.is_some() { #[expect(clippy::unnecessary_unwrap)] - x.unwrap(); // unnecessary + // unnecessary + x.unwrap(); #[expect(clippy::unnecessary_unwrap)] - x.expect("an error message"); // unnecessary + // unnecessary + x.expect("an error message"); } else { #[expect(clippy::panicking_unwrap)] - x.unwrap(); // will panic + // will panic + x.unwrap(); #[expect(clippy::panicking_unwrap)] - x.expect("an error message"); // will panic + // will panic + x.expect("an error message"); } } diff --git a/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.stderr b/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.stderr index 93809f655..a5afbba73 100644 --- a/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.stderr +++ b/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.stderr @@ -1,73 +1,76 @@ error: called `unwrap` on `x` after checking its variant with `is_some` - --> $DIR/simple_conditionals.rs:44:9 + --> $DIR/simple_conditionals.rs:47:9 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/simple_conditionals.rs:2:35 + --> $DIR/simple_conditionals.rs:3:35 | LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_some` - --> $DIR/simple_conditionals.rs:45:9 + --> $DIR/simple_conditionals.rs:50:9 | LL | if x.is_some() { | -------------- help: try: `if let Some(..) = x` -LL | x.unwrap(); // unnecessary -LL | x.expect("an error message"); // unnecessary +... +LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:47:9 + --> $DIR/simple_conditionals.rs:54:9 | LL | if x.is_some() { | ----------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/simple_conditionals.rs:2:9 + --> $DIR/simple_conditionals.rs:3:9 | LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `expect()` will always panic - --> $DIR/simple_conditionals.rs:48:9 + --> $DIR/simple_conditionals.rs:57:9 | LL | if x.is_some() { | ----------- because of this check ... -LL | x.expect("an error message"); // will panic +LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:51:9 + --> $DIR/simple_conditionals.rs:62:9 | LL | if x.is_none() { | ----------- because of this check -LL | x.unwrap(); // will panic +LL | // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_none` - --> $DIR/simple_conditionals.rs:53:9 + --> $DIR/simple_conditionals.rs:66:9 | LL | if x.is_none() { | -------------- help: try: `if let Some(..) = x` ... -LL | x.unwrap(); // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_some` - --> $DIR/simple_conditionals.rs:12:13 + --> $DIR/simple_conditionals.rs:14:13 | LL | if $a.is_some() { | --------------- help: try: `if let Some(..) = x` -LL | $a.unwrap(); // unnecessary +LL | // unnecessary +LL | $a.unwrap(); | ^^^^^^^^^^^ ... LL | m!(x); @@ -76,92 +79,162 @@ LL | m!(x); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: called `unwrap` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:61:9 + --> $DIR/simple_conditionals.rs:79:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok(..) = x` -LL | x.unwrap(); // unnecessary +LL | // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ error: called `expect` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:62:9 + --> $DIR/simple_conditionals.rs:82:9 | LL | if x.is_ok() { | ------------ help: try: `if let Ok(..) = x` -LL | x.unwrap(); // unnecessary -LL | x.expect("an error message"); // unnecessary +... +LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/simple_conditionals.rs:63:9 + --> $DIR/simple_conditionals.rs:85:9 | LL | if x.is_ok() { | --------- because of this check ... -LL | x.unwrap_err(); // will panic +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:65:9 + --> $DIR/simple_conditionals.rs:89:9 | LL | if x.is_ok() { | --------- because of this check ... -LL | x.unwrap(); // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: this call to `expect()` will always panic - --> $DIR/simple_conditionals.rs:66:9 + --> $DIR/simple_conditionals.rs:92:9 | LL | if x.is_ok() { | --------- because of this check ... -LL | x.expect("an error message"); // will panic +LL | x.expect("an error message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_ok` - --> $DIR/simple_conditionals.rs:67:9 + --> $DIR/simple_conditionals.rs:95:9 | LL | if x.is_ok() { | ------------ help: try: `if let Err(..) = x` ... -LL | x.unwrap_err(); // unnecessary +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: this call to `unwrap()` will always panic - --> $DIR/simple_conditionals.rs:70:9 + --> $DIR/simple_conditionals.rs:100:9 | LL | if x.is_err() { | ---------- because of this check -LL | x.unwrap(); // will panic +LL | // will panic +LL | x.unwrap(); | ^^^^^^^^^^ error: called `unwrap_err` on `x` after checking its variant with `is_err` - --> $DIR/simple_conditionals.rs:71:9 + --> $DIR/simple_conditionals.rs:103:9 | LL | if x.is_err() { | ------------- help: try: `if let Err(..) = x` -LL | x.unwrap(); // will panic -LL | x.unwrap_err(); // unnecessary +... +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ error: called `unwrap` on `x` after checking its variant with `is_err` - --> $DIR/simple_conditionals.rs:73:9 + --> $DIR/simple_conditionals.rs:107:9 | LL | if x.is_err() { | ------------- help: try: `if let Ok(..) = x` ... -LL | x.unwrap(); // unnecessary +LL | x.unwrap(); | ^^^^^^^^^^ error: this call to `unwrap_err()` will always panic - --> $DIR/simple_conditionals.rs:74:9 + --> $DIR/simple_conditionals.rs:110:9 | LL | if x.is_err() { | ---------- because of this check ... -LL | x.unwrap_err(); // will panic +LL | x.unwrap_err(); | ^^^^^^^^^^^^^^ -error: aborting due to 17 previous errors +error: called `unwrap` on `option` after checking its variant with `is_some` + --> $DIR/simple_conditionals.rs:135:9 + | +LL | if option.is_some() { + | ------------------- help: try: `if let Some(..) = &option` +LL | option.as_ref().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this call to `unwrap()` will always panic + --> $DIR/simple_conditionals.rs:138:9 + | +LL | if option.is_some() { + | ---------------- because of this check +... +LL | option.as_ref().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: called `unwrap` on `result` after checking its variant with `is_ok` + --> $DIR/simple_conditionals.rs:145:9 + | +LL | if result.is_ok() { + | ----------------- help: try: `if let Ok(..) = &result` +LL | result.as_ref().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this call to `unwrap()` will always panic + --> $DIR/simple_conditionals.rs:148:9 + | +LL | if result.is_ok() { + | -------------- because of this check +... +LL | result.as_ref().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: called `unwrap` on `option` after checking its variant with `is_some` + --> $DIR/simple_conditionals.rs:154:9 + | +LL | if option.is_some() { + | ------------------- help: try: `if let Some(..) = &mut option` +LL | option.as_mut().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this call to `unwrap()` will always panic + --> $DIR/simple_conditionals.rs:157:9 + | +LL | if option.is_some() { + | ---------------- because of this check +... +LL | option.as_mut().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: called `unwrap` on `result` after checking its variant with `is_ok` + --> $DIR/simple_conditionals.rs:163:9 + | +LL | if result.is_ok() { + | ----------------- help: try: `if let Ok(..) = &mut result` +LL | result.as_mut().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this call to `unwrap()` will always panic + --> $DIR/simple_conditionals.rs:166:9 + | +LL | if result.is_ok() { + | -------------- because of this check +... +LL | result.as_mut().unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 25 previous errors diff --git a/src/tools/clippy/tests/ui/clear_with_drain.fixed b/src/tools/clippy/tests/ui/clear_with_drain.fixed index b68c7d867..15777a4ea 100644 --- a/src/tools/clippy/tests/ui/clear_with_drain.fixed +++ b/src/tools/clippy/tests/ui/clear_with_drain.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::clear_with_drain)] diff --git a/src/tools/clippy/tests/ui/clear_with_drain.rs b/src/tools/clippy/tests/ui/clear_with_drain.rs index 0f6562eca..1dea7235e 100644 --- a/src/tools/clippy/tests/ui/clear_with_drain.rs +++ b/src/tools/clippy/tests/ui/clear_with_drain.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::clear_with_drain)] diff --git a/src/tools/clippy/tests/ui/clear_with_drain.stderr b/src/tools/clippy/tests/ui/clear_with_drain.stderr index 20158da11..b1a381256 100644 --- a/src/tools/clippy/tests/ui/clear_with_drain.stderr +++ b/src/tools/clippy/tests/ui/clear_with_drain.stderr @@ -1,127 +1,128 @@ error: `drain` used to clear a `Vec` - --> $DIR/clear_with_drain.rs:23:7 + --> $DIR/clear_with_drain.rs:22:7 | LL | v.drain(0..v.len()); | ^^^^^^^^^^^^^^^^^ help: try: `clear()` | = note: `-D clippy::clear-with-drain` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::clear_with_drain)]` error: `drain` used to clear a `Vec` - --> $DIR/clear_with_drain.rs:27:7 + --> $DIR/clear_with_drain.rs:26:7 | LL | v.drain(usize::MIN..v.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `Vec` - --> $DIR/clear_with_drain.rs:46:7 + --> $DIR/clear_with_drain.rs:45:7 | LL | v.drain(0..); | ^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `Vec` - --> $DIR/clear_with_drain.rs:50:7 + --> $DIR/clear_with_drain.rs:49:7 | LL | v.drain(usize::MIN..); | ^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `Vec` - --> $DIR/clear_with_drain.rs:66:7 + --> $DIR/clear_with_drain.rs:65:7 | LL | v.drain(..); | ^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `Vec` - --> $DIR/clear_with_drain.rs:83:7 + --> $DIR/clear_with_drain.rs:82:7 | LL | v.drain(..v.len()); | ^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> $DIR/clear_with_drain.rs:121:11 + --> $DIR/clear_with_drain.rs:120:11 | LL | deque.drain(0..deque.len()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> $DIR/clear_with_drain.rs:125:11 + --> $DIR/clear_with_drain.rs:124:11 | LL | deque.drain(usize::MIN..deque.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> $DIR/clear_with_drain.rs:144:11 + --> $DIR/clear_with_drain.rs:143:11 | LL | deque.drain(0..); | ^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> $DIR/clear_with_drain.rs:148:11 + --> $DIR/clear_with_drain.rs:147:11 | LL | deque.drain(usize::MIN..); | ^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> $DIR/clear_with_drain.rs:164:11 + --> $DIR/clear_with_drain.rs:163:11 | LL | deque.drain(..); | ^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `VecDeque` - --> $DIR/clear_with_drain.rs:181:11 + --> $DIR/clear_with_drain.rs:180:11 | LL | deque.drain(..deque.len()); | ^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> $DIR/clear_with_drain.rs:219:7 + --> $DIR/clear_with_drain.rs:218:7 | LL | s.drain(0..s.len()); | ^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> $DIR/clear_with_drain.rs:223:7 + --> $DIR/clear_with_drain.rs:222:7 | LL | s.drain(usize::MIN..s.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> $DIR/clear_with_drain.rs:242:7 + --> $DIR/clear_with_drain.rs:241:7 | LL | s.drain(0..); | ^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> $DIR/clear_with_drain.rs:246:7 + --> $DIR/clear_with_drain.rs:245:7 | LL | s.drain(usize::MIN..); | ^^^^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> $DIR/clear_with_drain.rs:262:7 + --> $DIR/clear_with_drain.rs:261:7 | LL | s.drain(..); | ^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `String` - --> $DIR/clear_with_drain.rs:279:7 + --> $DIR/clear_with_drain.rs:278:7 | LL | s.drain(..s.len()); | ^^^^^^^^^^^^^^^^ help: try: `clear()` error: `drain` used to clear a `HashSet` - --> $DIR/clear_with_drain.rs:317:9 + --> $DIR/clear_with_drain.rs:316:9 | LL | set.drain(); | ^^^^^^^ help: try: `clear()` error: `drain` used to clear a `HashMap` - --> $DIR/clear_with_drain.rs:336:9 + --> $DIR/clear_with_drain.rs:335:9 | LL | map.drain(); | ^^^^^^^ help: try: `clear()` error: `drain` used to clear a `BinaryHeap` - --> $DIR/clear_with_drain.rs:355:10 + --> $DIR/clear_with_drain.rs:354:10 | LL | heap.drain(); | ^^^^^^^ help: try: `clear()` diff --git a/src/tools/clippy/tests/ui/clone_on_copy.fixed b/src/tools/clippy/tests/ui/clone_on_copy.fixed index a72071158..9d9a5bf20 100644 --- a/src/tools/clippy/tests/ui/clone_on_copy.fixed +++ b/src/tools/clippy/tests/ui/clone_on_copy.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( unused, clippy::redundant_clone, diff --git a/src/tools/clippy/tests/ui/clone_on_copy.rs b/src/tools/clippy/tests/ui/clone_on_copy.rs index 2c5fac8fa..305bc6816 100644 --- a/src/tools/clippy/tests/ui/clone_on_copy.rs +++ b/src/tools/clippy/tests/ui/clone_on_copy.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( unused, clippy::redundant_clone, diff --git a/src/tools/clippy/tests/ui/clone_on_copy.stderr b/src/tools/clippy/tests/ui/clone_on_copy.stderr index 862234d20..0526c2f5a 100644 --- a/src/tools/clippy/tests/ui/clone_on_copy.stderr +++ b/src/tools/clippy/tests/ui/clone_on_copy.stderr @@ -1,55 +1,56 @@ error: using `clone` on type `i32` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:25:5 + --> $DIR/clone_on_copy.rs:23:5 | LL | 42.clone(); | ^^^^^^^^^^ help: try removing the `clone` call: `42` | = note: `-D clippy::clone-on-copy` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::clone_on_copy)]` error: using `clone` on type `i32` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:29:5 + --> $DIR/clone_on_copy.rs:27:5 | LL | (&42).clone(); | ^^^^^^^^^^^^^ help: try dereferencing it: `*(&42)` error: using `clone` on type `i32` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:32:5 + --> $DIR/clone_on_copy.rs:30:5 | LL | rc.borrow().clone(); | ^^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*rc.borrow()` error: using `clone` on type `u32` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:35:5 + --> $DIR/clone_on_copy.rs:33:5 | LL | x.clone().rotate_left(1); | ^^^^^^^^^ help: try removing the `clone` call: `x` error: using `clone` on type `i32` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:49:5 + --> $DIR/clone_on_copy.rs:47:5 | LL | m!(42).clone(); | ^^^^^^^^^^^^^^ help: try removing the `clone` call: `m!(42)` error: using `clone` on type `[u32; 2]` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:59:5 + --> $DIR/clone_on_copy.rs:57:5 | LL | x.clone()[0]; | ^^^^^^^^^ help: try dereferencing it: `(*x)` error: using `clone` on type `char` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:69:14 + --> $DIR/clone_on_copy.rs:67:14 | LL | is_ascii('z'.clone()); | ^^^^^^^^^^^ help: try removing the `clone` call: `'z'` error: using `clone` on type `i32` which implements the `Copy` trait - --> $DIR/clone_on_copy.rs:73:14 + --> $DIR/clone_on_copy.rs:71:14 | 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:77:17 + --> $DIR/clone_on_copy.rs:75:17 | LL | let value = opt.clone()?; // operator precedence needed (*opt)? | ^^^^^^^^^^^ help: try dereferencing it: `(*opt)` diff --git a/src/tools/clippy/tests/ui/clone_on_copy_impl.rs b/src/tools/clippy/tests/ui/clone_on_copy_impl.rs index b7c186bef..2d03544ad 100644 --- a/src/tools/clippy/tests/ui/clone_on_copy_impl.rs +++ b/src/tools/clippy/tests/ui/clone_on_copy_impl.rs @@ -1,4 +1,4 @@ -#![allow(clippy::incorrect_clone_impl_on_copy_type)] +#![allow(clippy::non_canonical_clone_impl)] use std::fmt; use std::marker::PhantomData; diff --git a/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed b/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed index 34bd22334..bc939bb3d 100644 --- a/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed +++ b/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::cloned_instead_of_copied)] #![allow(unused)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs b/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs index fa8444937..27346adbf 100644 --- a/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs +++ b/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::cloned_instead_of_copied)] #![allow(unused)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr b/src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr index 3ce482006..69a3738dd 100644 --- a/src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr +++ b/src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr @@ -1,49 +1,50 @@ error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:9:24 + --> $DIR/cloned_instead_of_copied.rs:7:24 | LL | let _ = [1].iter().cloned(); | ^^^^^^ help: try: `copied` | = note: `-D clippy::cloned-instead-of-copied` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cloned_instead_of_copied)]` error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:10:31 + --> $DIR/cloned_instead_of_copied.rs:8:31 | LL | let _ = vec!["hi"].iter().cloned(); | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:11:22 + --> $DIR/cloned_instead_of_copied.rs:9:22 | LL | let _ = Some(&1).cloned(); | ^^^^^^ help: try: `copied` error: used `cloned` where `copied` could be used instead - --> $DIR/cloned_instead_of_copied.rs:12:34 + --> $DIR/cloned_instead_of_copied.rs:10:34 | 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:13:32 + --> $DIR/cloned_instead_of_copied.rs:11: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:29:22 + --> $DIR/cloned_instead_of_copied.rs:27: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:34:24 + --> $DIR/cloned_instead_of_copied.rs:32: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:35:22 + --> $DIR/cloned_instead_of_copied.rs:33:22 | LL | let _ = Some(&1).cloned(); | ^^^^^^ help: try: `copied` diff --git a/src/tools/clippy/tests/ui/cmp_null.rs b/src/tools/clippy/tests/ui/cmp_null.rs index 2d2d04178..ef1d93940 100644 --- a/src/tools/clippy/tests/ui/cmp_null.rs +++ b/src/tools/clippy/tests/ui/cmp_null.rs @@ -7,11 +7,14 @@ fn main() { let x = 0; let p: *const usize = &x; if p == ptr::null() { + //~^ ERROR: comparing with null is better expressed by the `.is_null()` method + //~| NOTE: `-D clippy::cmp-null` implied by `-D warnings` println!("This is surprising!"); } let mut y = 0; let mut m: *mut usize = &mut y; if m == ptr::null_mut() { + //~^ ERROR: comparing with null is better expressed by the `.is_null()` method println!("This is surprising, too!"); } } diff --git a/src/tools/clippy/tests/ui/cmp_null.stderr b/src/tools/clippy/tests/ui/cmp_null.stderr index a1f4c70fb..d3b7c85b2 100644 --- a/src/tools/clippy/tests/ui/cmp_null.stderr +++ b/src/tools/clippy/tests/ui/cmp_null.stderr @@ -5,9 +5,10 @@ LL | if p == ptr::null() { | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::cmp-null` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cmp_null)]` error: comparing with null is better expressed by the `.is_null()` method - --> $DIR/cmp_null.rs:14:8 + --> $DIR/cmp_null.rs:16:8 | LL | if m == ptr::null_mut() { | ^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.fixed b/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.fixed index 118346348..9fc70ab6f 100644 --- a/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.fixed +++ b/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::needless_if, diff --git a/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.rs b/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.rs index 3a25d53a5..5cd43ea1d 100644 --- a/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.rs +++ b/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::needless_if, diff --git a/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.stderr b/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.stderr index 4714a0daa..6431b3619 100644 --- a/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.stderr +++ b/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.stderr @@ -1,13 +1,14 @@ error: this creates an owned instance just for comparison - --> $DIR/asymmetric_partial_eq.rs:47:12 + --> $DIR/asymmetric_partial_eq.rs:46:12 | LL | if borrowed.to_owned() == owned {} | ^^^^^^^^^^^^^^^^^^^ help: try: `borrowed` | = note: `-D clippy::cmp-owned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cmp_owned)]` error: this creates an owned instance just for comparison - --> $DIR/asymmetric_partial_eq.rs:48:21 + --> $DIR/asymmetric_partial_eq.rs:47:21 | LL | if owned == borrowed.to_owned() {} | ---------^^^^^^^^^^^^^^^^^^^ @@ -15,13 +16,13 @@ LL | if owned == borrowed.to_owned() {} | help: try: `borrowed == owned` error: this creates an owned instance just for comparison - --> $DIR/asymmetric_partial_eq.rs:66:21 + --> $DIR/asymmetric_partial_eq.rs:65:21 | LL | if owned == borrowed.to_owned() {} | ^^^^^^^^^^^^^^^^^^^ help: try: `borrowed` error: this creates an owned instance just for comparison - --> $DIR/asymmetric_partial_eq.rs:67:12 + --> $DIR/asymmetric_partial_eq.rs:66:12 | LL | if borrowed.to_owned() == owned {} | ^^^^^^^^^^^^^^^^^^^--------- @@ -29,7 +30,7 @@ LL | if borrowed.to_owned() == owned {} | help: try: `owned == borrowed` error: this creates an owned instance just for comparison - --> $DIR/asymmetric_partial_eq.rs:93:20 + --> $DIR/asymmetric_partial_eq.rs:92:20 | LL | if "Hi" == borrowed.to_string() {} | --------^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +38,7 @@ LL | if "Hi" == borrowed.to_string() {} | help: try: `borrowed == "Hi"` error: this creates an owned instance just for comparison - --> $DIR/asymmetric_partial_eq.rs:94:12 + --> $DIR/asymmetric_partial_eq.rs:93:12 | LL | if borrowed.to_string() == "Hi" {} | ^^^^^^^^^^^^^^^^^^^^ help: try: `borrowed` diff --git a/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.fixed b/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.fixed index b1133f2a5..40d7b5e49 100644 --- a/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.fixed +++ b/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - use std::fmt::{self, Display}; fn main() { diff --git a/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.rs b/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.rs index 091a9aa65..59a945668 100644 --- a/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.rs +++ b/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.rs @@ -1,5 +1,3 @@ -//@run-rustfix - use std::fmt::{self, Display}; fn main() { diff --git a/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.stderr b/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.stderr index e4d0d822b..09a495996 100644 --- a/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.stderr +++ b/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.stderr @@ -1,13 +1,14 @@ error: this creates an owned instance just for comparison - --> $DIR/comparison_flip.rs:8:8 + --> $DIR/comparison_flip.rs:6:8 | LL | if a.to_string() != "bar" { | ^^^^^^^^^^^^^ help: try: `a` | = note: `-D clippy::cmp-owned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cmp_owned)]` error: this creates an owned instance just for comparison - --> $DIR/comparison_flip.rs:12:17 + --> $DIR/comparison_flip.rs:10:17 | LL | if "bar" != a.to_string() { | ---------^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.fixed b/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.fixed index bf1a58588..8846092fe 100644 --- a/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.fixed +++ b/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #[warn(clippy::cmp_owned)] #[allow(clippy::unnecessary_operation, clippy::no_effect, unused_must_use, clippy::eq_op)] fn main() { diff --git a/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.rs b/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.rs index f3f663670..cb5268734 100644 --- a/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.rs +++ b/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #[warn(clippy::cmp_owned)] #[allow(clippy::unnecessary_operation, clippy::no_effect, unused_must_use, clippy::eq_op)] fn main() { diff --git a/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.stderr b/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.stderr index 2f333e6ea..0b1127c1a 100644 --- a/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.stderr +++ b/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.stderr @@ -1,37 +1,38 @@ error: this creates an owned instance just for comparison - --> $DIR/with_suggestion.rs:7:14 + --> $DIR/with_suggestion.rs:5:14 | LL | x != "foo".to_string(); | ^^^^^^^^^^^^^^^^^ help: try: `"foo"` | = note: `-D clippy::cmp-owned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cmp_owned)]` error: this creates an owned instance just for comparison - --> $DIR/with_suggestion.rs:9:9 + --> $DIR/with_suggestion.rs:7:9 | LL | "foo".to_string() != x; | ^^^^^^^^^^^^^^^^^ help: try: `"foo"` error: this creates an owned instance just for comparison - --> $DIR/with_suggestion.rs:16:10 + --> $DIR/with_suggestion.rs:14:10 | LL | x != "foo".to_owned(); | ^^^^^^^^^^^^^^^^ help: try: `"foo"` error: this creates an owned instance just for comparison - --> $DIR/with_suggestion.rs:18:10 + --> $DIR/with_suggestion.rs:16:10 | LL | x != String::from("foo"); | ^^^^^^^^^^^^^^^^^^^ help: try: `"foo"` error: this creates an owned instance just for comparison - --> $DIR/with_suggestion.rs:22:5 + --> $DIR/with_suggestion.rs:20:5 | LL | Foo.to_owned() == Foo; | ^^^^^^^^^^^^^^ help: try: `Foo` error: this creates an owned instance just for comparison - --> $DIR/with_suggestion.rs:24:30 + --> $DIR/with_suggestion.rs:22:30 | LL | "abc".chars().filter(|c| c.to_owned() != 'X'); | ^^^^^^^^^^^^ help: try: `*c` diff --git a/src/tools/clippy/tests/ui/cmp_owned/without_suggestion.rs b/src/tools/clippy/tests/ui/cmp_owned/without_suggestion.rs index d8a202cb6..ec45d635c 100644 --- a/src/tools/clippy/tests/ui/cmp_owned/without_suggestion.rs +++ b/src/tools/clippy/tests/ui/cmp_owned/without_suggestion.rs @@ -5,10 +5,13 @@ fn main() { let x = &Baz; let y = &Baz; y.to_owned() == *x; + //~^ ERROR: this creates an owned instance just for comparison + //~| NOTE: `-D clippy::cmp-owned` implied by `-D warnings` let x = &&Baz; let y = &Baz; y.to_owned() == **x; + //~^ ERROR: this creates an owned instance just for comparison let x = 0u32; let y = U32Wrapper(x); @@ -20,6 +23,7 @@ struct Foo; impl PartialEq for Foo { fn eq(&self, other: &Self) -> bool { self.to_owned() == *other + //~^ ERROR: this creates an owned instance just for comparison } } diff --git a/src/tools/clippy/tests/ui/cmp_owned/without_suggestion.stderr b/src/tools/clippy/tests/ui/cmp_owned/without_suggestion.stderr index d2dd14d8e..c4f63bd09 100644 --- a/src/tools/clippy/tests/ui/cmp_owned/without_suggestion.stderr +++ b/src/tools/clippy/tests/ui/cmp_owned/without_suggestion.stderr @@ -5,15 +5,16 @@ LL | y.to_owned() == *x; | ^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating | = note: `-D clippy::cmp-owned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cmp_owned)]` error: this creates an owned instance just for comparison - --> $DIR/without_suggestion.rs:11:5 + --> $DIR/without_suggestion.rs:13:5 | LL | y.to_owned() == **x; | ^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating error: this creates an owned instance just for comparison - --> $DIR/without_suggestion.rs:22:9 + --> $DIR/without_suggestion.rs:25:9 | LL | self.to_owned() == *other | ^^^^^^^^^^^^^^^^^^^^^^^^^ try implementing the comparison without allocating diff --git a/src/tools/clippy/tests/ui/cognitive_complexity.rs b/src/tools/clippy/tests/ui/cognitive_complexity.rs index 07bdaff00..e8fd063a9 100644 --- a/src/tools/clippy/tests/ui/cognitive_complexity.rs +++ b/src/tools/clippy/tests/ui/cognitive_complexity.rs @@ -4,6 +4,7 @@ #[rustfmt::skip] fn main() { +//~^ ERROR: the function has a cognitive complexity of (28/25) if true { println!("a"); } @@ -89,6 +90,7 @@ fn main() { #[clippy::cognitive_complexity = "1"] fn kaboom() { + //~^ ERROR: the function has a cognitive complexity of (7/1) let n = 0; 'a: for i in 0..20 { 'b: for j in i..20 { @@ -147,7 +149,9 @@ fn lots_of_short_circuits2() -> bool { #[clippy::cognitive_complexity = "1"] fn baa() { + //~^ ERROR: the function has a cognitive complexity of (2/1) let x = || match 99 { + //~^ ERROR: the function has a cognitive complexity of (2/1) 0 => 0, 1 => 1, 2 => 2, @@ -165,6 +169,7 @@ fn baa() { #[clippy::cognitive_complexity = "1"] fn bar() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), _ => println!("bye"), @@ -176,6 +181,7 @@ fn bar() { /// Tests are usually complex but simple at the same time. `clippy::cognitive_complexity` used to /// give lots of false-positives in tests. fn dont_warn_on_tests() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), _ => println!("bye"), @@ -184,6 +190,7 @@ fn dont_warn_on_tests() { #[clippy::cognitive_complexity = "1"] fn barr() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -194,6 +201,7 @@ fn barr() { #[clippy::cognitive_complexity = "1"] fn barr2() { + //~^ ERROR: the function has a cognitive complexity of (3/1) match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -210,6 +218,7 @@ fn barr2() { #[clippy::cognitive_complexity = "1"] fn barrr() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), 1 => panic!("bla"), @@ -220,6 +229,7 @@ fn barrr() { #[clippy::cognitive_complexity = "1"] fn barrr2() { + //~^ ERROR: the function has a cognitive complexity of (3/1) match 99 { 0 => println!("hi"), 1 => panic!("bla"), @@ -236,6 +246,7 @@ fn barrr2() { #[clippy::cognitive_complexity = "1"] fn barrrr() { + //~^ ERROR: the function has a cognitive complexity of (2/1) match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -246,6 +257,7 @@ fn barrrr() { #[clippy::cognitive_complexity = "1"] fn barrrr2() { + //~^ ERROR: the function has a cognitive complexity of (3/1) match 99 { 0 => println!("hi"), 1 => println!("bla"), @@ -262,6 +274,7 @@ fn barrrr2() { #[clippy::cognitive_complexity = "1"] fn cake() { + //~^ ERROR: the function has a cognitive complexity of (2/1) if 4 == 5 { println!("yea"); } else { @@ -272,6 +285,7 @@ fn cake() { #[clippy::cognitive_complexity = "1"] pub fn read_file(input_path: &str) -> String { + //~^ ERROR: the function has a cognitive complexity of (4/1) use std::fs::File; use std::io::{Read, Write}; use std::path::Path; @@ -303,6 +317,7 @@ enum Void {} #[clippy::cognitive_complexity = "1"] fn void(void: Void) { + //~^ ERROR: the function has a cognitive complexity of (2/1) if true { match void {} } @@ -354,6 +369,7 @@ fn early() -> Result { #[rustfmt::skip] #[clippy::cognitive_complexity = "1"] fn early_ret() -> i32 { +//~^ ERROR: the function has a cognitive complexity of (8/1) let a = if true { 42 } else { return 0; }; let a = if a < 99 { 42 } else { return 0; }; let a = if a < 99 { 42 } else { return 0; }; @@ -375,6 +391,7 @@ fn early_ret() -> i32 { #[clippy::cognitive_complexity = "1"] fn closures() { let x = |a: i32, b: i32| -> i32 { + //~^ ERROR: the function has a cognitive complexity of (2/1) if true { println!("moo"); } @@ -388,6 +405,7 @@ struct Moo; #[clippy::cognitive_complexity = "1"] impl Moo { fn moo(&self) { + //~^ ERROR: the function has a cognitive complexity of (2/1) if true { println!("moo"); } @@ -397,6 +415,7 @@ impl Moo { #[clippy::cognitive_complexity = "1"] mod issue9300 { async fn a() { + //~^ ERROR: the function has a cognitive complexity of (2/1) let a = 0; if a == 0 {} } @@ -404,6 +423,7 @@ mod issue9300 { pub struct S; impl S { pub async fn async_method() { + //~^ ERROR: the function has a cognitive complexity of (2/1) let a = 0; if a == 0 {} } diff --git a/src/tools/clippy/tests/ui/cognitive_complexity.stderr b/src/tools/clippy/tests/ui/cognitive_complexity.stderr index d86724630..58c7455d1 100644 --- a/src/tools/clippy/tests/ui/cognitive_complexity.stderr +++ b/src/tools/clippy/tests/ui/cognitive_complexity.stderr @@ -6,9 +6,10 @@ LL | fn main() { | = help: you could split it up into multiple smaller functions = note: `-D clippy::cognitive-complexity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cognitive_complexity)]` error: the function has a cognitive complexity of (7/1) - --> $DIR/cognitive_complexity.rs:91:4 + --> $DIR/cognitive_complexity.rs:92:4 | LL | fn kaboom() { | ^^^^^^ @@ -16,7 +17,7 @@ LL | fn kaboom() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:149:4 + --> $DIR/cognitive_complexity.rs:151:4 | LL | fn baa() { | ^^^ @@ -24,7 +25,7 @@ LL | fn baa() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:150:13 + --> $DIR/cognitive_complexity.rs:153:13 | LL | let x = || match 99 { | ^^ @@ -32,7 +33,7 @@ LL | let x = || match 99 { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:167:4 + --> $DIR/cognitive_complexity.rs:171:4 | LL | fn bar() { | ^^^ @@ -40,7 +41,7 @@ LL | fn bar() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:178:4 + --> $DIR/cognitive_complexity.rs:183:4 | LL | fn dont_warn_on_tests() { | ^^^^^^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | fn dont_warn_on_tests() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:186:4 + --> $DIR/cognitive_complexity.rs:192:4 | LL | fn barr() { | ^^^^ @@ -56,7 +57,7 @@ LL | fn barr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> $DIR/cognitive_complexity.rs:196:4 + --> $DIR/cognitive_complexity.rs:203:4 | LL | fn barr2() { | ^^^^^ @@ -64,7 +65,7 @@ LL | fn barr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:212:4 + --> $DIR/cognitive_complexity.rs:220:4 | LL | fn barrr() { | ^^^^^ @@ -72,7 +73,7 @@ LL | fn barrr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> $DIR/cognitive_complexity.rs:222:4 + --> $DIR/cognitive_complexity.rs:231:4 | LL | fn barrr2() { | ^^^^^^ @@ -80,7 +81,7 @@ LL | fn barrr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:238:4 + --> $DIR/cognitive_complexity.rs:248:4 | LL | fn barrrr() { | ^^^^^^ @@ -88,7 +89,7 @@ LL | fn barrrr() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (3/1) - --> $DIR/cognitive_complexity.rs:248:4 + --> $DIR/cognitive_complexity.rs:259:4 | LL | fn barrrr2() { | ^^^^^^^ @@ -96,7 +97,7 @@ LL | fn barrrr2() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:264:4 + --> $DIR/cognitive_complexity.rs:276:4 | LL | fn cake() { | ^^^^ @@ -104,7 +105,7 @@ LL | fn cake() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (4/1) - --> $DIR/cognitive_complexity.rs:274:8 + --> $DIR/cognitive_complexity.rs:287:8 | LL | pub fn read_file(input_path: &str) -> String { | ^^^^^^^^^ @@ -112,7 +113,7 @@ LL | pub fn read_file(input_path: &str) -> String { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:305:4 + --> $DIR/cognitive_complexity.rs:319:4 | LL | fn void(void: Void) { | ^^^^ @@ -120,7 +121,7 @@ LL | fn void(void: Void) { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (8/1) - --> $DIR/cognitive_complexity.rs:356:4 + --> $DIR/cognitive_complexity.rs:371:4 | LL | fn early_ret() -> i32 { | ^^^^^^^^^ @@ -128,7 +129,7 @@ LL | fn early_ret() -> i32 { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:377:13 + --> $DIR/cognitive_complexity.rs:393:13 | LL | let x = |a: i32, b: i32| -> i32 { | ^^^^^^^^^^^^^^^^ @@ -136,7 +137,7 @@ LL | let x = |a: i32, b: i32| -> i32 { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:390:8 + --> $DIR/cognitive_complexity.rs:407:8 | LL | fn moo(&self) { | ^^^ @@ -144,7 +145,7 @@ LL | fn moo(&self) { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:399:14 + --> $DIR/cognitive_complexity.rs:417:14 | LL | async fn a() { | ^ @@ -152,7 +153,7 @@ LL | async fn a() { = help: you could split it up into multiple smaller functions error: the function has a cognitive complexity of (2/1) - --> $DIR/cognitive_complexity.rs:406:22 + --> $DIR/cognitive_complexity.rs:425:22 | LL | pub async fn async_method() { | ^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/cognitive_complexity_attr_used.rs b/src/tools/clippy/tests/ui/cognitive_complexity_attr_used.rs index 771a26fc9..6f6e89983 100644 --- a/src/tools/clippy/tests/ui/cognitive_complexity_attr_used.rs +++ b/src/tools/clippy/tests/ui/cognitive_complexity_attr_used.rs @@ -7,6 +7,7 @@ fn main() { #[clippy::cognitive_complexity = "0"] fn kaboom() { + //~^ ERROR: the function has a cognitive complexity of (3/0) if 42 == 43 { panic!(); } else if "cake" == "lie" { diff --git a/src/tools/clippy/tests/ui/cognitive_complexity_attr_used.stderr b/src/tools/clippy/tests/ui/cognitive_complexity_attr_used.stderr index bb48f3297..9cd25f6fd 100644 --- a/src/tools/clippy/tests/ui/cognitive_complexity_attr_used.stderr +++ b/src/tools/clippy/tests/ui/cognitive_complexity_attr_used.stderr @@ -6,6 +6,7 @@ LL | fn kaboom() { | = help: you could split it up into multiple smaller functions = note: `-D clippy::cognitive-complexity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cognitive_complexity)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/collapsible_else_if.fixed b/src/tools/clippy/tests/ui/collapsible_else_if.fixed index c4116cd85..3b410b2f1 100644 --- a/src/tools/clippy/tests/ui/collapsible_else_if.fixed +++ b/src/tools/clippy/tests/ui/collapsible_else_if.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::assertions_on_constants, clippy::equatable_if_let, clippy::needless_if)] #[rustfmt::skip] diff --git a/src/tools/clippy/tests/ui/collapsible_else_if.rs b/src/tools/clippy/tests/ui/collapsible_else_if.rs index 8f51d0ee5..772ef6f9f 100644 --- a/src/tools/clippy/tests/ui/collapsible_else_if.rs +++ b/src/tools/clippy/tests/ui/collapsible_else_if.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::assertions_on_constants, clippy::equatable_if_let, clippy::needless_if)] #[rustfmt::skip] diff --git a/src/tools/clippy/tests/ui/collapsible_else_if.stderr b/src/tools/clippy/tests/ui/collapsible_else_if.stderr index 45b2094c9..f0f840653 100644 --- a/src/tools/clippy/tests/ui/collapsible_else_if.stderr +++ b/src/tools/clippy/tests/ui/collapsible_else_if.stderr @@ -1,5 +1,5 @@ error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:14:12 + --> $DIR/collapsible_else_if.rs:13:12 | LL | } else { | ____________^ @@ -10,6 +10,7 @@ LL | | } | |_____^ | = note: `-D clippy::collapsible-else-if` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::collapsible_else_if)]` help: collapse nested if block | LL ~ } else if y == "world" { @@ -18,7 +19,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:22:12 + --> $DIR/collapsible_else_if.rs:21:12 | LL | } else { | ____________^ @@ -36,7 +37,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:30:12 + --> $DIR/collapsible_else_if.rs:29:12 | LL | } else { | ____________^ @@ -59,7 +60,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:41:12 + --> $DIR/collapsible_else_if.rs:40:12 | LL | } else { | ____________^ @@ -82,7 +83,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:52:12 + --> $DIR/collapsible_else_if.rs:51:12 | LL | } else { | ____________^ @@ -105,7 +106,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:63:12 + --> $DIR/collapsible_else_if.rs:62:12 | LL | } else { | ____________^ @@ -128,7 +129,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:74:12 + --> $DIR/collapsible_else_if.rs:73:12 | LL | } else { | ____________^ @@ -151,7 +152,7 @@ LL + } | error: this `else { if .. }` block can be collapsed - --> $DIR/collapsible_else_if.rs:97:10 + --> $DIR/collapsible_else_if.rs:96:10 | LL | }else{ | __________^ diff --git a/src/tools/clippy/tests/ui/collapsible_if.fixed b/src/tools/clippy/tests/ui/collapsible_if.fixed index e305e1d7a..fff6bfcc7 100644 --- a/src/tools/clippy/tests/ui/collapsible_if.fixed +++ b/src/tools/clippy/tests/ui/collapsible_if.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( clippy::assertions_on_constants, clippy::equatable_if_let, diff --git a/src/tools/clippy/tests/ui/collapsible_if.rs b/src/tools/clippy/tests/ui/collapsible_if.rs index 7c52959d3..70bfea231 100644 --- a/src/tools/clippy/tests/ui/collapsible_if.rs +++ b/src/tools/clippy/tests/ui/collapsible_if.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( clippy::assertions_on_constants, clippy::equatable_if_let, diff --git a/src/tools/clippy/tests/ui/collapsible_if.stderr b/src/tools/clippy/tests/ui/collapsible_if.stderr index 4a1a9e8a6..e8a36bf48 100644 --- a/src/tools/clippy/tests/ui/collapsible_if.stderr +++ b/src/tools/clippy/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:14:5 | LL | / if x == "hello" { LL | | if y == "world" { @@ -9,6 +9,7 @@ LL | | } | |_____^ | = note: `-D clippy::collapsible-if` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]` help: collapse nested if block | LL ~ if x == "hello" && y == "world" { @@ -17,7 +18,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:21:5 + --> $DIR/collapsible_if.rs:20:5 | LL | / if x == "hello" || x == "world" { LL | | if y == "world" || y == "hello" { @@ -34,7 +35,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:27:5 + --> $DIR/collapsible_if.rs:26:5 | LL | / if x == "hello" && x == "world" { LL | | if y == "world" || y == "hello" { @@ -51,7 +52,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:33:5 + --> $DIR/collapsible_if.rs:32:5 | LL | / if x == "hello" || x == "world" { LL | | if y == "world" && y == "hello" { @@ -68,7 +69,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:39:5 + --> $DIR/collapsible_if.rs:38:5 | LL | / if x == "hello" && x == "world" { LL | | if y == "world" && y == "hello" { @@ -85,7 +86,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:45:5 + --> $DIR/collapsible_if.rs:44:5 | LL | / if 42 == 1337 { LL | | if 'a' != 'A' { @@ -102,7 +103,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:101:5 + --> $DIR/collapsible_if.rs:100:5 | LL | / if x == "hello" { LL | | if y == "world" { // Collapsible @@ -119,7 +120,7 @@ LL + } | error: this `if` statement can be collapsed - --> $DIR/collapsible_if.rs:160:5 + --> $DIR/collapsible_if.rs:159:5 | LL | / if matches!(true, true) { LL | | if matches!(true, true) {} @@ -127,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:164:5 | LL | / if matches!(true, true) && truth() { LL | | if matches!(true, true) {} diff --git a/src/tools/clippy/tests/ui/collapsible_match.rs b/src/tools/clippy/tests/ui/collapsible_match.rs index 1d7a72846..7501fd2b0 100644 --- a/src/tools/clippy/tests/ui/collapsible_match.rs +++ b/src/tools/clippy/tests/ui/collapsible_match.rs @@ -11,6 +11,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // match without block match res_opt { Ok(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -20,6 +21,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // match with block match res_opt { Ok(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -29,6 +31,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // if let, if let if let Ok(val) = res_opt { if let Some(n) = val { + //~^ ERROR: this `if let` can be collapsed into the outer `if let` take(n); } } @@ -36,6 +39,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // if let else, if let else if let Ok(val) = res_opt { if let Some(n) = val { + //~^ ERROR: this `if let` can be collapsed into the outer `if let` take(n); } else { return; @@ -47,6 +51,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // if let, match if let Ok(val) = res_opt { match val { + //~^ ERROR: this `match` can be collapsed into the outer `if let` Some(n) => foo(n), _ => (), } @@ -56,6 +61,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> match res_opt { Ok(val) => { if let Some(n) = val { + //~^ ERROR: this `if let` can be collapsed into the outer `match` take(n); } }, @@ -65,6 +71,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // if let else, match if let Ok(val) = res_opt { match val { + //~^ ERROR: this `match` can be collapsed into the outer `if let` Some(n) => foo(n), _ => return, } @@ -76,6 +83,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> match res_opt { Ok(val) => { if let Some(n) = val { + //~^ ERROR: this `if let` can be collapsed into the outer `match` take(n); } else { return; @@ -87,6 +95,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // None in inner match same as outer wild branch match res_opt { Ok(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), None => return, }, @@ -96,6 +105,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // None in outer match same as inner wild branch match opt_opt { Some(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -261,6 +271,7 @@ pub enum Issue9647 { pub fn test_1(x: Issue9647) { if let Issue9647::A { a, .. } = x { if let Some(u) = a { + //~^ ERROR: this `if let` can be collapsed into the outer `if let` println!("{u:?}") } } @@ -269,6 +280,7 @@ pub fn test_1(x: Issue9647) { pub fn test_2(x: Issue9647) { if let Issue9647::A { a: Some(a), .. } = x { if let Some(u) = a { + //~^ ERROR: this `if let` can be collapsed into the outer `if let` println!("{u}") } } diff --git a/src/tools/clippy/tests/ui/collapsible_match.stderr b/src/tools/clippy/tests/ui/collapsible_match.stderr index 0294be60b..ce7da1c16 100644 --- a/src/tools/clippy/tests/ui/collapsible_match.stderr +++ b/src/tools/clippy/tests/ui/collapsible_match.stderr @@ -3,6 +3,7 @@ error: this `match` can be collapsed into the outer `match` | LL | Ok(val) => match val { | ____________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, @@ -13,38 +14,43 @@ help: the outer pattern can be modified to include the inner pattern | LL | Ok(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern = note: `-D clippy::collapsible-match` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::collapsible_match)]` error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:22:20 + --> $DIR/collapsible_match.rs:23:20 | LL | Ok(val) => match val { | ____________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:22:12 + --> $DIR/collapsible_match.rs:23:12 | LL | Ok(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:31:9 + --> $DIR/collapsible_match.rs:33:9 | LL | / if let Some(n) = val { +LL | | LL | | take(n); LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:30:15 + --> $DIR/collapsible_match.rs:32:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding @@ -52,9 +58,10 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:38:9 + --> $DIR/collapsible_match.rs:41:9 | LL | / if let Some(n) = val { +LL | | LL | | take(n); LL | | } else { LL | | return; @@ -62,7 +69,7 @@ LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:37:15 + --> $DIR/collapsible_match.rs:40:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding @@ -70,33 +77,35 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:49:9 + --> $DIR/collapsible_match.rs:53:9 | LL | / match val { +LL | | LL | | Some(n) => foo(n), LL | | _ => (), LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:48:15 + --> $DIR/collapsible_match.rs:52:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding -LL | match val { +... LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:58:13 + --> $DIR/collapsible_match.rs:63:13 | LL | / if let Some(n) = val { +LL | | LL | | take(n); LL | | } | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:57:12 + --> $DIR/collapsible_match.rs:62:12 | LL | Ok(val) => { | ^^^ replace this binding @@ -104,27 +113,29 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:67:9 + --> $DIR/collapsible_match.rs:73:9 | LL | / match val { +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:66:15 + --> $DIR/collapsible_match.rs:72:15 | LL | if let Ok(val) = res_opt { | ^^^ replace this binding -LL | match val { +... LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:78:13 + --> $DIR/collapsible_match.rs:85:13 | LL | / if let Some(n) = val { +LL | | LL | | take(n); LL | | } else { LL | | return; @@ -132,7 +143,7 @@ LL | | } | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:77:12 + --> $DIR/collapsible_match.rs:84:12 | LL | Ok(val) => { | ^^^ replace this binding @@ -140,51 +151,56 @@ LL | if let Some(n) = val { | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:89:20 + --> $DIR/collapsible_match.rs:97:20 | LL | Ok(val) => match val { | ____________________^ +LL | | LL | | Some(n) => foo(n), LL | | None => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:89:12 + --> $DIR/collapsible_match.rs:97:12 | LL | Ok(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match.rs:98:22 + --> $DIR/collapsible_match.rs:107:22 | LL | Some(val) => match val { | ______________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:98:14 + --> $DIR/collapsible_match.rs:107:14 | LL | Some(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `if let` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:263:9 + --> $DIR/collapsible_match.rs:273:9 | LL | / if let Some(u) = a { +LL | | LL | | println!("{u:?}") LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:262:27 + --> $DIR/collapsible_match.rs:272:27 | LL | if let Issue9647::A { a, .. } = x { | ^ replace this binding @@ -192,15 +208,16 @@ LL | if let Some(u) = a { | ^^^^^^^ with this pattern, prefixed by a: error: this `if let` can be collapsed into the outer `if let` - --> $DIR/collapsible_match.rs:271:9 + --> $DIR/collapsible_match.rs:282:9 | LL | / if let Some(u) = a { +LL | | LL | | println!("{u}") LL | | } | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match.rs:270:35 + --> $DIR/collapsible_match.rs:281:35 | LL | if let Issue9647::A { a: Some(a), .. } = x { | ^ replace this binding diff --git a/src/tools/clippy/tests/ui/collapsible_match2.rs b/src/tools/clippy/tests/ui/collapsible_match2.rs index c8fb0a39e..56801f99e 100644 --- a/src/tools/clippy/tests/ui/collapsible_match2.rs +++ b/src/tools/clippy/tests/ui/collapsible_match2.rs @@ -11,6 +11,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> { match res_opt { Ok(val) if make() => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -18,6 +19,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> } match res_opt { Ok(val) => match val { + //~^ ERROR: this `match` can be collapsed into the outer `match` Some(n) => foo(n), _ => return, }, @@ -49,6 +51,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // deref reference value match Some(&[1]) { Some(s) => match *s { + //~^ ERROR: this `match` can be collapsed into the outer `match` [n] => foo(n), _ => (), }, @@ -58,6 +61,7 @@ fn lint_cases(opt_opt: Option>, res_opt: Result, String> // ref pattern and deref match Some(&[1]) { Some(ref s) => match s { + //~^ ERROR: this `match` can be collapsed into the outer `match` [n] => foo(n), _ => (), }, diff --git a/src/tools/clippy/tests/ui/collapsible_match2.stderr b/src/tools/clippy/tests/ui/collapsible_match2.stderr index 144dbe40a..e008355be 100644 --- a/src/tools/clippy/tests/ui/collapsible_match2.stderr +++ b/src/tools/clippy/tests/ui/collapsible_match2.stderr @@ -3,6 +3,7 @@ error: this `match` can be collapsed into the outer `match` | LL | Ok(val) if make() => match val { | __________________________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, @@ -13,30 +14,34 @@ help: the outer pattern can be modified to include the inner pattern | LL | Ok(val) if make() => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern = note: `-D clippy::collapsible-match` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::collapsible_match)]` error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match2.rs:20:24 + --> $DIR/collapsible_match2.rs:21:24 | LL | Ok(val) => match val { | ________________________^ +LL | | LL | | Some(n) => foo(n), LL | | _ => return, LL | | }, | |_____________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match2.rs:20:16 + --> $DIR/collapsible_match2.rs:21:16 | LL | Ok(val) => match val { | ^^^ replace this binding +LL | LL | Some(n) => foo(n), | ^^^^^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match2.rs:34:29 + --> $DIR/collapsible_match2.rs:36:29 | LL | $pat => match $e { | _____________________________^ @@ -49,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:46:28 + --> $DIR/collapsible_match2.rs:48:28 | LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); | ^^^ ^^^^^^^ with this pattern @@ -58,38 +63,42 @@ 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:51:20 + --> $DIR/collapsible_match2.rs:53:20 | LL | Some(s) => match *s { | ____________________^ +LL | | LL | | [n] => foo(n), LL | | _ => (), LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match2.rs:51:14 + --> $DIR/collapsible_match2.rs:53:14 | LL | Some(s) => match *s { | ^ replace this binding +LL | LL | [n] => foo(n), | ^^^ with this pattern error: this `match` can be collapsed into the outer `match` - --> $DIR/collapsible_match2.rs:60:24 + --> $DIR/collapsible_match2.rs:63:24 | LL | Some(ref s) => match s { | ________________________^ +LL | | LL | | [n] => foo(n), LL | | _ => (), LL | | }, | |_________^ | help: the outer pattern can be modified to include the inner pattern - --> $DIR/collapsible_match2.rs:60:14 + --> $DIR/collapsible_match2.rs:63:14 | LL | Some(ref s) => match s { | ^^^^^ replace this binding +LL | LL | [n] => foo(n), | ^^^ with this pattern diff --git a/src/tools/clippy/tests/ui/collapsible_str_replace.fixed b/src/tools/clippy/tests/ui/collapsible_str_replace.fixed index ba6c1769a..03b393d5a 100644 --- a/src/tools/clippy/tests/ui/collapsible_str_replace.fixed +++ b/src/tools/clippy/tests/ui/collapsible_str_replace.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::collapsible_str_replace)] diff --git a/src/tools/clippy/tests/ui/collapsible_str_replace.rs b/src/tools/clippy/tests/ui/collapsible_str_replace.rs index f5871be65..364e5493b 100644 --- a/src/tools/clippy/tests/ui/collapsible_str_replace.rs +++ b/src/tools/clippy/tests/ui/collapsible_str_replace.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::collapsible_str_replace)] diff --git a/src/tools/clippy/tests/ui/collapsible_str_replace.stderr b/src/tools/clippy/tests/ui/collapsible_str_replace.stderr index 223358cf5..4b0bd818d 100644 --- a/src/tools/clippy/tests/ui/collapsible_str_replace.stderr +++ b/src/tools/clippy/tests/ui/collapsible_str_replace.stderr @@ -1,25 +1,26 @@ error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:20:27 + --> $DIR/collapsible_str_replace.rs:18:27 | LL | let _ = "hesuo worpd".replace('s', "l").replace('u', "l"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['s', 'u'], "l")` | = note: `-D clippy::collapsible-str-replace` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::collapsible_str_replace)]` error: used consecutive `str::replace` call - --> $DIR/collapsible_str_replace.rs:22:27 + --> $DIR/collapsible_str_replace.rs:20: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:24:27 + --> $DIR/collapsible_str_replace.rs:22: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:27:10 + --> $DIR/collapsible_str_replace.rs:25:10 | LL | .replace('s', "l") | __________^ @@ -29,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:32:27 + --> $DIR/collapsible_str_replace.rs:30: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:34:27 + --> $DIR/collapsible_str_replace.rs:32: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:34: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:36: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:40:27 + --> $DIR/collapsible_str_replace.rs:38: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:42:45 + --> $DIR/collapsible_str_replace.rs:40: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:45:47 + --> $DIR/collapsible_str_replace.rs:43: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:47:28 + --> $DIR/collapsible_str_replace.rs:45: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:49:27 + --> $DIR/collapsible_str_replace.rs:47: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:86:16 + --> $DIR/collapsible_str_replace.rs:84:16 | LL | let _ = "".replace('a', "1.58").replace('b', "1.58"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['a', 'b'], "1.58")` diff --git a/src/tools/clippy/tests/ui/collection_is_never_read.rs b/src/tools/clippy/tests/ui/collection_is_never_read.rs index e02c1c572..bd281f787 100644 --- a/src/tools/clippy/tests/ui/collection_is_never_read.rs +++ b/src/tools/clippy/tests/ui/collection_is_never_read.rs @@ -18,7 +18,9 @@ fn no_access_at_all() { fn write_without_read() { // The main use case for `collection_is_never_read`. - let mut x = HashMap::new(); // WARNING + let mut x = HashMap::new(); + //~^ ERROR: collection is never read + //~| NOTE: `-D clippy::collection-is-never-read` implied by `-D warnings` x.insert(1, 2); } @@ -57,7 +59,8 @@ fn read_in_closure() { } fn write_in_closure() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read let _ = || { x.push(4); }; @@ -72,12 +75,14 @@ fn read_in_format() { fn shadowing_1() { let x = HashMap::::new(); // Ok let _ = x.len(); - let mut x = HashMap::new(); // WARNING + let mut x = HashMap::new(); + //~^ ERROR: collection is never read x.insert(1, 2); } fn shadowing_2() { - let mut x = HashMap::new(); // WARNING + let mut x = HashMap::new(); + //~^ ERROR: collection is never read x.insert(1, 2); let x = HashMap::::new(); // Ok let _ = x.len(); @@ -85,26 +90,30 @@ fn shadowing_2() { #[allow(clippy::let_unit_value)] fn fake_read_1() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read x.reverse(); let _: () = x.clear(); } fn fake_read_2() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read x.reverse(); println!("{:?}", x.push(5)); } fn assignment() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read let y = vec![4, 5, 6]; // Ok x = y; } #[allow(clippy::self_assignment)] fn self_assignment() { - let mut x = vec![1, 2, 3]; // WARNING + let mut x = vec![1, 2, 3]; + //~^ ERROR: collection is never read x = x; } @@ -121,7 +130,8 @@ fn method_argument_but_not_target() { } fn insert_is_not_a_read() { - let mut x = HashSet::new(); // WARNING + let mut x = HashSet::new(); + //~^ ERROR: collection is never read x.insert(5); } @@ -135,7 +145,8 @@ fn insert_is_a_read() { fn not_read_if_return_value_not_used() { // `is_empty` does not modify the set, so it's a query. But since the return value is not used, the // lint does not consider it a read here. - let x = vec![1, 2, 3]; // WARNING + let x = vec![1, 2, 3]; + //~^ ERROR: collection is never read x.is_empty(); } @@ -170,34 +181,44 @@ fn function_argument() { } fn supported_types() { - let mut x = std::collections::BTreeMap::new(); // WARNING + let mut x = std::collections::BTreeMap::new(); + //~^ ERROR: collection is never read x.insert(true, 1); - let mut x = std::collections::BTreeSet::new(); // WARNING + let mut x = std::collections::BTreeSet::new(); + //~^ ERROR: collection is never read x.insert(1); - let mut x = std::collections::BinaryHeap::new(); // WARNING + let mut x = std::collections::BinaryHeap::new(); + //~^ ERROR: collection is never read x.push(1); - let mut x = std::collections::HashMap::new(); // WARNING + let mut x = std::collections::HashMap::new(); + //~^ ERROR: collection is never read x.insert(1, 2); - let mut x = std::collections::HashSet::new(); // WARNING + let mut x = std::collections::HashSet::new(); + //~^ ERROR: collection is never read x.insert(1); - let mut x = std::collections::LinkedList::new(); // WARNING + let mut x = std::collections::LinkedList::new(); + //~^ ERROR: collection is never read x.push_front(1); - let mut x = Some(true); // WARNING + let mut x = Some(true); + //~^ ERROR: collection is never read x.insert(false); - let mut x = String::from("hello"); // WARNING + let mut x = String::from("hello"); + //~^ ERROR: collection is never read x.push('!'); - let mut x = Vec::new(); // WARNING + let mut x = Vec::new(); + //~^ ERROR: collection is never read x.clear(); x.push(1); - let mut x = std::collections::VecDeque::new(); // WARNING + let mut x = std::collections::VecDeque::new(); + //~^ ERROR: collection is never read x.push_front(1); } diff --git a/src/tools/clippy/tests/ui/collection_is_never_read.stderr b/src/tools/clippy/tests/ui/collection_is_never_read.stderr index 982cb4455..acb9abff6 100644 --- a/src/tools/clippy/tests/ui/collection_is_never_read.stderr +++ b/src/tools/clippy/tests/ui/collection_is_never_read.stderr @@ -1,123 +1,124 @@ error: collection is never read --> $DIR/collection_is_never_read.rs:21:5 | -LL | let mut x = HashMap::new(); // WARNING +LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::collection-is-never-read` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::collection_is_never_read)]` error: collection is never read - --> $DIR/collection_is_never_read.rs:60:5 + --> $DIR/collection_is_never_read.rs:62:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:75:5 + --> $DIR/collection_is_never_read.rs:78:5 | -LL | let mut x = HashMap::new(); // WARNING +LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:80:5 + --> $DIR/collection_is_never_read.rs:84:5 | -LL | let mut x = HashMap::new(); // WARNING +LL | let mut x = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:88:5 + --> $DIR/collection_is_never_read.rs:93:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:94:5 + --> $DIR/collection_is_never_read.rs:100:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:100:5 + --> $DIR/collection_is_never_read.rs:107:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:107:5 + --> $DIR/collection_is_never_read.rs:115:5 | -LL | let mut x = vec![1, 2, 3]; // WARNING +LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:124:5 + --> $DIR/collection_is_never_read.rs:133:5 | -LL | let mut x = HashSet::new(); // WARNING +LL | let mut x = HashSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:138:5 + --> $DIR/collection_is_never_read.rs:148:5 | -LL | let x = vec![1, 2, 3]; // WARNING +LL | let x = vec![1, 2, 3]; | ^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:173:5 + --> $DIR/collection_is_never_read.rs:184:5 | -LL | let mut x = std::collections::BTreeMap::new(); // WARNING +LL | let mut x = std::collections::BTreeMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:176:5 + --> $DIR/collection_is_never_read.rs:188:5 | -LL | let mut x = std::collections::BTreeSet::new(); // WARNING +LL | let mut x = std::collections::BTreeSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:179:5 + --> $DIR/collection_is_never_read.rs:192:5 | -LL | let mut x = std::collections::BinaryHeap::new(); // WARNING +LL | let mut x = std::collections::BinaryHeap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:182:5 + --> $DIR/collection_is_never_read.rs:196:5 | -LL | let mut x = std::collections::HashMap::new(); // WARNING +LL | let mut x = std::collections::HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:185:5 + --> $DIR/collection_is_never_read.rs:200:5 | -LL | let mut x = std::collections::HashSet::new(); // WARNING +LL | let mut x = std::collections::HashSet::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:188:5 + --> $DIR/collection_is_never_read.rs:204:5 | -LL | let mut x = std::collections::LinkedList::new(); // WARNING +LL | let mut x = std::collections::LinkedList::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:191:5 + --> $DIR/collection_is_never_read.rs:208:5 | -LL | let mut x = Some(true); // WARNING +LL | let mut x = Some(true); | ^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:194:5 + --> $DIR/collection_is_never_read.rs:212:5 | -LL | let mut x = String::from("hello"); // WARNING +LL | let mut x = String::from("hello"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:197:5 + --> $DIR/collection_is_never_read.rs:216:5 | -LL | let mut x = Vec::new(); // WARNING +LL | let mut x = Vec::new(); | ^^^^^^^^^^^^^^^^^^^^^^^ error: collection is never read - --> $DIR/collection_is_never_read.rs:201:5 + --> $DIR/collection_is_never_read.rs:221:5 | -LL | let mut x = std::collections::VecDeque::new(); // WARNING +LL | let mut x = std::collections::VecDeque::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 20 previous errors diff --git a/src/tools/clippy/tests/ui/comparison_chain.rs b/src/tools/clippy/tests/ui/comparison_chain.rs index c12c6a310..266cee4c3 100644 --- a/src/tools/clippy/tests/ui/comparison_chain.rs +++ b/src/tools/clippy/tests/ui/comparison_chain.rs @@ -12,6 +12,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < y { b() @@ -25,6 +26,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < y { b() @@ -33,6 +35,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if y > x { b() @@ -41,6 +44,7 @@ fn f(x: u8, y: u8, z: u8) { } if x > 1 { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < 1 { b() @@ -115,12 +119,14 @@ fn g(x: f64, y: f64, z: f64) { fn h(x: T, y: T, z: T) { if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < y { b() } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if x < y { b() @@ -129,6 +135,7 @@ fn h(x: T, y: T, z: T) { } if x > y { + //~^ ERROR: `if` chain can be rewritten with `match` a() } else if y > x { b() diff --git a/src/tools/clippy/tests/ui/comparison_chain.stderr b/src/tools/clippy/tests/ui/comparison_chain.stderr index 2eeb50202..3b41dcf55 100644 --- a/src/tools/clippy/tests/ui/comparison_chain.stderr +++ b/src/tools/clippy/tests/ui/comparison_chain.stderr @@ -2,6 +2,7 @@ error: `if` chain can be rewritten with `match` --> $DIR/comparison_chain.rs:14:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if x < y { LL | | b() @@ -10,15 +11,16 @@ LL | | } | = help: consider rewriting the `if` chain to use `cmp` and `match` = note: `-D clippy::comparison-chain` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::comparison_chain)]` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:27:5 + --> $DIR/comparison_chain.rs:28:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if x < y { -LL | | b() -LL | | } else { +... | LL | | c() LL | | } | |_____^ @@ -26,13 +28,13 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:35:5 + --> $DIR/comparison_chain.rs:37:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if y > x { -LL | | b() -LL | | } else { +... | LL | | c() LL | | } | |_____^ @@ -40,13 +42,13 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:43:5 + --> $DIR/comparison_chain.rs:46:5 | LL | / if x > 1 { +LL | | LL | | a() LL | | } else if x < 1 { -LL | | b() -LL | | } else if x == 1 { +... | LL | | c() LL | | } | |_____^ @@ -54,9 +56,10 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:117:5 + --> $DIR/comparison_chain.rs:121:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if x < y { LL | | b() @@ -66,13 +69,13 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:123:5 + --> $DIR/comparison_chain.rs:128:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if x < y { -LL | | b() -LL | | } else { +... | LL | | c() LL | | } | |_____^ @@ -80,13 +83,13 @@ LL | | } = help: consider rewriting the `if` chain to use `cmp` and `match` error: `if` chain can be rewritten with `match` - --> $DIR/comparison_chain.rs:131:5 + --> $DIR/comparison_chain.rs:137:5 | LL | / if x > y { +LL | | LL | | a() LL | | } else if y > x { -LL | | b() -LL | | } else { +... | LL | | c() LL | | } | |_____^ diff --git a/src/tools/clippy/tests/ui/comparison_to_empty.fixed b/src/tools/clippy/tests/ui/comparison_to_empty.fixed index af219eed0..90eb50715 100644 --- a/src/tools/clippy/tests/ui/comparison_to_empty.fixed +++ b/src/tools/clippy/tests/ui/comparison_to_empty.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::comparison_to_empty)] #![allow(clippy::borrow_deref_ref, clippy::needless_if, clippy::useless_vec)] #![feature(let_chains)] diff --git a/src/tools/clippy/tests/ui/comparison_to_empty.rs b/src/tools/clippy/tests/ui/comparison_to_empty.rs index 21e65184d..0964c4a20 100644 --- a/src/tools/clippy/tests/ui/comparison_to_empty.rs +++ b/src/tools/clippy/tests/ui/comparison_to_empty.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::comparison_to_empty)] #![allow(clippy::borrow_deref_ref, clippy::needless_if, clippy::useless_vec)] #![feature(let_chains)] diff --git a/src/tools/clippy/tests/ui/comparison_to_empty.stderr b/src/tools/clippy/tests/ui/comparison_to_empty.stderr index f29782ed8..b97ab4c3c 100644 --- a/src/tools/clippy/tests/ui/comparison_to_empty.stderr +++ b/src/tools/clippy/tests/ui/comparison_to_empty.stderr @@ -1,55 +1,56 @@ error: comparison to empty slice - --> $DIR/comparison_to_empty.rs:10:13 + --> $DIR/comparison_to_empty.rs:8:13 | LL | let _ = s == ""; | ^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` | = note: `-D clippy::comparison-to-empty` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::comparison_to_empty)]` error: comparison to empty slice - --> $DIR/comparison_to_empty.rs:11:13 + --> $DIR/comparison_to_empty.rs:9:13 | LL | let _ = s != ""; | ^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!s.is_empty()` error: comparison to empty slice - --> $DIR/comparison_to_empty.rs:14:13 + --> $DIR/comparison_to_empty.rs:12:13 | LL | let _ = v == []; | ^^^^^^^ help: using `is_empty` is clearer and more explicit: `v.is_empty()` error: comparison to empty slice - --> $DIR/comparison_to_empty.rs:15:13 + --> $DIR/comparison_to_empty.rs:13:13 | LL | let _ = v != []; | ^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!v.is_empty()` error: comparison to empty slice using `if let` - --> $DIR/comparison_to_empty.rs:16:8 + --> $DIR/comparison_to_empty.rs:14:8 | LL | if let [] = &*v {} | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(*v).is_empty()` error: comparison to empty slice using `if let` - --> $DIR/comparison_to_empty.rs:18:8 + --> $DIR/comparison_to_empty.rs:16:8 | LL | if let [] = s {} | ^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` error: comparison to empty slice using `if let` - --> $DIR/comparison_to_empty.rs:19:8 + --> $DIR/comparison_to_empty.rs:17:8 | LL | if let [] = &*s {} | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` error: comparison to empty slice using `if let` - --> $DIR/comparison_to_empty.rs:20:8 + --> $DIR/comparison_to_empty.rs:18:8 | LL | if let [] = &*s && s == [] {} | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` error: comparison to empty slice - --> $DIR/comparison_to_empty.rs:20:24 + --> $DIR/comparison_to_empty.rs:18:24 | LL | if let [] = &*s && s == [] {} | ^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()` diff --git a/src/tools/clippy/tests/ui/const_comparisons.rs b/src/tools/clippy/tests/ui/const_comparisons.rs index 8e265c914..0898b4ebd 100644 --- a/src/tools/clippy/tests/ui/const_comparisons.rs +++ b/src/tools/clippy/tests/ui/const_comparisons.rs @@ -40,54 +40,111 @@ fn main() { let status_code = 500; // Value doesn't matter for the lint let status = Status { code: status_code }; - status_code >= 400 && status_code < 500; // Correct + // Correct + status_code >= 400 && status_code < 500; status_code <= 400 && status_code > 500; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `400` < `500`, the expression evaluates to false for any value of `st status_code > 500 && status_code < 400; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` > `400`, the expression evaluates to false for any value of `st status_code < 500 && status_code > 500; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: `status_code` cannot simultaneously be greater than and less than `500` // More complex expressions status_code < { 400 } && status_code > { 500 }; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any valu status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluate status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to f status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: `status_code` cannot simultaneously be greater than and less than `STATUS_S // Comparing two different types, via the `impl PartialOrd for Status` status < { 400 } && status > { 500 }; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any valu status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluate status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to f status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: `status` cannot simultaneously be greater than and less than `STATUS_SERVER // Yoda conditions - 500 <= status_code && 600 > status_code; // Correct - 500 <= status_code && status_code <= 600; // Correct - 500 >= status_code && 600 < status_code; // Incorrect - 500 >= status_code && status_code > 600; // Incorrect + // Correct + 500 <= status_code && 600 > status_code; + // Correct + 500 <= status_code && status_code <= 600; + // Incorrect + 500 >= status_code && 600 < status_code; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st + // Incorrect + 500 >= status_code && status_code > 600; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st // Yoda conditions, comparing two different types - 500 <= status && 600 > status; // Correct - 500 <= status && status <= 600; // Correct - 500 >= status && 600 < status; // Incorrect - 500 >= status && status > 600; // Incorrect + // Correct + 500 <= status && 600 > status; + // Correct + 500 <= status && status <= 600; + // Incorrect + 500 >= status && 600 < status; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st + // Incorrect + 500 >= status && status > 600; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `500` < `600`, the expression evaluates to false for any value of `st // Expressions where one of the sides has no effect status_code < 200 && status_code <= 299; + //~^ ERROR: right-hand side of `&&` operator has no effect status_code > 200 && status_code >= 299; - - status_code >= 500 && status_code > 500; // Useless left - status_code > 500 && status_code >= 500; // Useless right - status_code <= 500 && status_code < 500; // Useless left - status_code < 500 && status_code <= 500; // Useless right + //~^ ERROR: left-hand side of `&&` operator has no effect + + // Useless left + status_code >= 500 && status_code > 500; + //~^ ERROR: left-hand side of `&&` operator has no effect + // Useless right + status_code > 500 && status_code >= 500; + //~^ ERROR: right-hand side of `&&` operator has no effect + // Useless left + status_code <= 500 && status_code < 500; + //~^ ERROR: left-hand side of `&&` operator has no effect + // Useless right + status_code < 500 && status_code <= 500; + //~^ ERROR: right-hand side of `&&` operator has no effect // Other types let name = "Steve"; name < "Jennifer" && name > "Shannon"; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `"Jennifer"` < `"Shannon"`, the expression evaluates to false for any let numbers = [1, 2]; numbers < [3, 4] && numbers > [5, 6]; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `[3, 4]` < `[5, 6]`, the expression evaluates to false for any value let letter = 'a'; letter < 'b' && letter > 'c'; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `'b'` < `'c'`, the expression evaluates to false for any value of `le let area = 42.0; area < std::f32::consts::E && area > std::f32::consts::PI; + //~^ ERROR: boolean expression will never evaluate to 'true' + //~| NOTE: since `std::f32::consts::E` < `std::f32::consts::PI`, the expression evalua } diff --git a/src/tools/clippy/tests/ui/const_comparisons.stderr b/src/tools/clippy/tests/ui/const_comparisons.stderr index 90e6db647..f773ccbc7 100644 --- a/src/tools/clippy/tests/ui/const_comparisons.stderr +++ b/src/tools/clippy/tests/ui/const_comparisons.stderr @@ -1,14 +1,15 @@ error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:44:5 + --> $DIR/const_comparisons.rs:45:5 | LL | status_code <= 400 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: since `400` < `500`, the expression evaluates to false for any value of `status_code` = note: `-D clippy::impossible-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::impossible_comparisons)]` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:45:5 + --> $DIR/const_comparisons.rs:48:5 | LL | status_code > 500 && status_code < 400; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | status_code > 500 && status_code < 400; = note: since `500` > `400`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:46:5 + --> $DIR/const_comparisons.rs:51:5 | LL | status_code < 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | status_code < 500 && status_code > 500; = note: `status_code` cannot simultaneously be greater than and less than `500` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:49:5 + --> $DIR/const_comparisons.rs:56:5 | LL | status_code < { 400 } && status_code > { 500 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | status_code < { 400 } && status_code > { 500 }; = note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:50:5 + --> $DIR/const_comparisons.rs:59:5 | LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR; = note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:51:5 + --> $DIR/const_comparisons.rs:62:5 | LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR; = note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:52:5 + --> $DIR/const_comparisons.rs:65:5 | LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR; = note: `status_code` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:55:5 + --> $DIR/const_comparisons.rs:70:5 | LL | status < { 400 } && status > { 500 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +65,7 @@ LL | status < { 400 } && status > { 500 }; = note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:56:5 + --> $DIR/const_comparisons.rs:73:5 | LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR; = note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:57:5 + --> $DIR/const_comparisons.rs:76:5 | LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +81,7 @@ LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR; = note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:58:5 + --> $DIR/const_comparisons.rs:79:5 | LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -88,112 +89,113 @@ LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR; = note: `status` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:63:5 + --> $DIR/const_comparisons.rs:89:5 | -LL | 500 >= status_code && 600 < status_code; // Incorrect +LL | 500 >= status_code && 600 < status_code; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: since `500` < `600`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:64:5 + --> $DIR/const_comparisons.rs:93:5 | -LL | 500 >= status_code && status_code > 600; // Incorrect +LL | 500 >= status_code && status_code > 600; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: since `500` < `600`, the expression evaluates to false for any value of `status_code` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:69:5 + --> $DIR/const_comparisons.rs:103:5 | -LL | 500 >= status && 600 < status; // Incorrect +LL | 500 >= status && 600 < status; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: since `500` < `600`, the expression evaluates to false for any value of `status` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:70:5 + --> $DIR/const_comparisons.rs:107:5 | -LL | 500 >= status && status > 600; // Incorrect +LL | 500 >= status && status > 600; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: since `500` < `600`, the expression evaluates to false for any value of `status` error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:73:5 + --> $DIR/const_comparisons.rs:112:5 | LL | status_code < 200 && status_code <= 299; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 200` evaluates to true, status_code <= 299` will always evaluate to true as well - --> $DIR/const_comparisons.rs:73:23 + --> $DIR/const_comparisons.rs:112:23 | LL | status_code < 200 && status_code <= 299; | ^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::redundant-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_comparisons)]` error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:74:5 + --> $DIR/const_comparisons.rs:114:5 | LL | status_code > 200 && status_code >= 299; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code >= 299` evaluates to true, status_code > 200` will always evaluate to true as well - --> $DIR/const_comparisons.rs:74:5 + --> $DIR/const_comparisons.rs:114:5 | LL | status_code > 200 && status_code >= 299; | ^^^^^^^^^^^^^^^^^^^^^ error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:76:5 + --> $DIR/const_comparisons.rs:118:5 | -LL | status_code >= 500 && status_code > 500; // Useless left +LL | status_code >= 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:76:5 + --> $DIR/const_comparisons.rs:118:5 | -LL | status_code >= 500 && status_code > 500; // Useless left +LL | status_code >= 500 && status_code > 500; | ^^^^^^^^^^^^^^^^^^^^^^ error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:77:5 + --> $DIR/const_comparisons.rs:121:5 | -LL | status_code > 500 && status_code >= 500; // Useless right +LL | status_code > 500 && status_code >= 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:77:23 + --> $DIR/const_comparisons.rs:121:23 | -LL | status_code > 500 && status_code >= 500; // Useless right +LL | status_code > 500 && status_code >= 500; | ^^^^^^^^^^^^^^^^^^^^^ error: left-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:78:5 + --> $DIR/const_comparisons.rs:124:5 | -LL | status_code <= 500 && status_code < 500; // Useless left +LL | status_code <= 500 && status_code < 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:78:5 + --> $DIR/const_comparisons.rs:124:5 | -LL | status_code <= 500 && status_code < 500; // Useless left +LL | status_code <= 500 && status_code < 500; | ^^^^^^^^^^^^^^^^^^^^^^ error: right-hand side of `&&` operator has no effect - --> $DIR/const_comparisons.rs:79:5 + --> $DIR/const_comparisons.rs:127:5 | -LL | status_code < 500 && status_code <= 500; // Useless right +LL | status_code < 500 && status_code <= 500; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well - --> $DIR/const_comparisons.rs:79:23 + --> $DIR/const_comparisons.rs:127:23 | -LL | status_code < 500 && status_code <= 500; // Useless right +LL | status_code < 500 && status_code <= 500; | ^^^^^^^^^^^^^^^^^^^^^ error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:83:5 + --> $DIR/const_comparisons.rs:132:5 | LL | name < "Jennifer" && name > "Shannon"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -201,7 +203,7 @@ LL | name < "Jennifer" && name > "Shannon"; = note: since `"Jennifer"` < `"Shannon"`, the expression evaluates to false for any value of `name` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:86:5 + --> $DIR/const_comparisons.rs:137:5 | LL | numbers < [3, 4] && numbers > [5, 6]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,7 +211,7 @@ LL | numbers < [3, 4] && numbers > [5, 6]; = note: since `[3, 4]` < `[5, 6]`, the expression evaluates to false for any value of `numbers` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:89:5 + --> $DIR/const_comparisons.rs:142:5 | LL | letter < 'b' && letter > 'c'; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +219,7 @@ LL | letter < 'b' && letter > 'c'; = note: since `'b'` < `'c'`, the expression evaluates to false for any value of `letter` error: boolean expression will never evaluate to 'true' - --> $DIR/const_comparisons.rs:92:5 + --> $DIR/const_comparisons.rs:147:5 | LL | area < std::f32::consts::E && area > std::f32::consts::PI; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/copy_iterator.rs b/src/tools/clippy/tests/ui/copy_iterator.rs index ae67ebded..c0e5fc3e4 100644 --- a/src/tools/clippy/tests/ui/copy_iterator.rs +++ b/src/tools/clippy/tests/ui/copy_iterator.rs @@ -4,6 +4,8 @@ struct Countdown(u8); impl Iterator for Countdown { + //~^ ERROR: you are implementing `Iterator` on a `Copy` type + //~| NOTE: consider implementing `IntoIterator` instead type Item = u8; fn next(&mut self) -> Option { diff --git a/src/tools/clippy/tests/ui/copy_iterator.stderr b/src/tools/clippy/tests/ui/copy_iterator.stderr index 6bc6fd6b6..48c3385b6 100644 --- a/src/tools/clippy/tests/ui/copy_iterator.stderr +++ b/src/tools/clippy/tests/ui/copy_iterator.stderr @@ -2,9 +2,9 @@ error: you are implementing `Iterator` on a `Copy` type --> $DIR/copy_iterator.rs:6:1 | LL | / impl Iterator for Countdown { -LL | | type Item = u8; LL | | -LL | | fn next(&mut self) -> Option { +LL | | +LL | | type Item = u8; ... | LL | | } LL | | } @@ -12,6 +12,7 @@ LL | | } | = note: consider implementing `IntoIterator` instead = note: `-D clippy::copy-iterator` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::copy_iterator)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crashes/auxiliary/ice-7868-aux.rs b/src/tools/clippy/tests/ui/crashes/auxiliary/ice-7868-aux.rs index bee29894b..882b66d67 100644 --- a/src/tools/clippy/tests/ui/crashes/auxiliary/ice-7868-aux.rs +++ b/src/tools/clippy/tests/ui/crashes/auxiliary/ice-7868-aux.rs @@ -1,3 +1,5 @@ fn zero() { unsafe { 0 }; + //~^ ERROR: unsafe block missing a safety comment + //~| NOTE: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` } diff --git a/src/tools/clippy/tests/ui/crashes/ice-10148.rs b/src/tools/clippy/tests/ui/crashes/ice-10148.rs index 0df22f413..d89d94edb 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-10148.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-10148.rs @@ -1,5 +1,5 @@ -//@aux-build:../auxiliary/proc_macros.rs:proc-macro - +//@aux-build:../auxiliary/proc_macros.rs +//@no-rustfix extern crate proc_macros; use proc_macros::with_span; diff --git a/src/tools/clippy/tests/ui/crashes/ice-10148.stderr b/src/tools/clippy/tests/ui/crashes/ice-10148.stderr index f23e4433f..4d436e3aa 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-10148.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-10148.stderr @@ -7,6 +7,7 @@ LL | println!(with_span!(""something "")); | help: remove the empty string | = note: `-D clippy::println-empty-string` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::println_empty_string)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crashes/ice-10645.stderr b/src/tools/clippy/tests/ui/crashes/ice-10645.stderr index 0055fe061..fc5347c86 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-10645.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-10645.stderr @@ -11,6 +11,7 @@ LL | pub async fn bar<'a, T: 'a>(_: T) {} | ^ has type `T` which is not `Send` = note: `T` doesn't implement `std::marker::Send` = note: `-D clippy::future-not-send` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::future_not_send)]` warning: 1 warning emitted diff --git a/src/tools/clippy/tests/ui/crashes/ice-10912.rs b/src/tools/clippy/tests/ui/crashes/ice-10912.rs index 69d7f2f39..8dfce1942 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-10912.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-10912.rs @@ -1,4 +1,8 @@ #![warn(clippy::unreadable_literal)] +//@no-rustfix fn f2() -> impl Sized { && 3.14159265358979323846E } +//~^ ERROR: expected at least one digit in exponent +//~| ERROR: long literal lacking separators +//~| NOTE: `-D clippy::unreadable-literal` implied by `-D warnings` fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-10912.stderr b/src/tools/clippy/tests/ui/crashes/ice-10912.stderr index a74ce7315..2be297b56 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-10912.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-10912.stderr @@ -1,16 +1,17 @@ error: expected at least one digit in exponent - --> $DIR/ice-10912.rs:2:28 + --> $DIR/ice-10912.rs:3:28 | LL | fn f2() -> impl Sized { && 3.14159265358979323846E } | ^^^^^^^^^^^^^^^^^^^^^^^ error: long literal lacking separators - --> $DIR/ice-10912.rs:2:28 + --> $DIR/ice-10912.rs:3:28 | LL | fn f2() -> impl Sized { && 3.14159265358979323846E } | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider: `3.141_592_653_589_793_238_46` | = note: `-D clippy::unreadable-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unreadable_literal)]` error: aborting due to 2 previous errors diff --git a/src/tools/clippy/tests/ui/crashes/ice-11337.rs b/src/tools/clippy/tests/ui/crashes/ice-11337.rs new file mode 100644 index 000000000..0bed4035f --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-11337.rs @@ -0,0 +1,9 @@ +#![feature(trait_alias)] + +trait Confusing = Fn(i32) where F: Fn(u32); + +fn alias, F>(_: T, _: F) {} + +fn main() { + alias(|_| {}, |_| {}); +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-11422.fixed b/src/tools/clippy/tests/ui/crashes/ice-11422.fixed new file mode 100644 index 000000000..ca5721cbb --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-11422.fixed @@ -0,0 +1,25 @@ +#![warn(clippy::implied_bounds_in_impls)] + +use std::fmt::Debug; +use std::ops::*; + +fn gen() -> impl PartialOrd + Debug {} + +struct Bar {} +trait Foo {} +trait FooNested> {} +impl Foo for Bar {} +impl FooNested for Bar {} + +fn foo() -> impl Foo + FooNested { + Bar {} +} + +fn test_impl_ops() -> impl Add + Sub + Mul + Div { + 1 +} +fn test_impl_assign_ops() -> impl AddAssign + SubAssign + MulAssign + DivAssign { + 1 +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-11422.rs b/src/tools/clippy/tests/ui/crashes/ice-11422.rs new file mode 100644 index 000000000..355ec2480 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-11422.rs @@ -0,0 +1,25 @@ +#![warn(clippy::implied_bounds_in_impls)] + +use std::fmt::Debug; +use std::ops::*; + +fn gen() -> impl PartialOrd + PartialEq + Debug {} + +struct Bar {} +trait Foo {} +trait FooNested> {} +impl Foo for Bar {} +impl FooNested for Bar {} + +fn foo() -> impl Foo + FooNested { + Bar {} +} + +fn test_impl_ops() -> impl Add + Sub + Mul + Div { + 1 +} +fn test_impl_assign_ops() -> impl AddAssign + SubAssign + MulAssign + DivAssign { + 1 +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-11422.stderr b/src/tools/clippy/tests/ui/crashes/ice-11422.stderr new file mode 100644 index 000000000..fb80b5b14 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-11422.stderr @@ -0,0 +1,16 @@ +error: this bound is already specified as the supertrait of `PartialOrd` + --> $DIR/ice-11422.rs:6:31 + | +LL | fn gen() -> impl PartialOrd + PartialEq + Debug {} + | ^^^^^^^^^ + | + = note: `-D clippy::implied-bounds-in-impls` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::implied_bounds_in_impls)]` +help: try removing this bound + | +LL - fn gen() -> impl PartialOrd + PartialEq + Debug {} +LL + fn gen() -> impl PartialOrd + Debug {} + | + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/crashes/ice-2774.fixed b/src/tools/clippy/tests/ui/crashes/ice-2774.fixed new file mode 100644 index 000000000..96cf0d854 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-2774.fixed @@ -0,0 +1,29 @@ +use std::collections::HashSet; + +// See rust-lang/rust-clippy#2774. + +#[derive(Eq, PartialEq, Debug, Hash)] +pub struct Bar { + foo: Foo, +} + +#[derive(Eq, PartialEq, Debug, Hash)] +pub struct Foo; + +#[allow(clippy::implicit_hasher)] +// This should not cause a "cannot relate bound region" ICE. +pub fn add_barfoos_to_foos(bars: &HashSet<&Bar>) { + //~^ ERROR: the following explicit lifetimes could be elided: 'a + //~| NOTE: `-D clippy::needless-lifetimes` implied by `-D warnings` + let mut foos = HashSet::new(); + foos.extend(bars.iter().map(|b| &b.foo)); +} + +#[allow(clippy::implicit_hasher)] +// Also, this should not cause a "cannot relate bound region" ICE. +pub fn add_barfoos_to_foos2(bars: &HashSet<&Bar>) { + let mut foos = HashSet::new(); + foos.extend(bars.iter().map(|b| &b.foo)); +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-2774.rs b/src/tools/clippy/tests/ui/crashes/ice-2774.rs index 88cfa1f92..464d7891c 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-2774.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-2774.rs @@ -13,6 +13,8 @@ pub struct Foo; #[allow(clippy::implicit_hasher)] // This should not cause a "cannot relate bound region" ICE. pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) { + //~^ ERROR: the following explicit lifetimes could be elided: 'a + //~| NOTE: `-D clippy::needless-lifetimes` implied by `-D warnings` let mut foos = HashSet::new(); foos.extend(bars.iter().map(|b| &b.foo)); } diff --git a/src/tools/clippy/tests/ui/crashes/ice-2774.stderr b/src/tools/clippy/tests/ui/crashes/ice-2774.stderr index a166ccb3e..ae9610c9a 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-2774.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-2774.stderr @@ -5,6 +5,7 @@ LL | pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) { | ^^ ^^ | = note: `-D clippy::needless-lifetimes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_lifetimes)]` help: elide the lifetimes | LL - pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) { diff --git a/src/tools/clippy/tests/ui/crashes/ice-360.rs b/src/tools/clippy/tests/ui/crashes/ice-360.rs index 6555c19ca..0d10932b0 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-360.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-360.rs @@ -1,12 +1,16 @@ fn main() {} - +//@no-rustfix fn no_panic(slice: &[T]) { let mut iter = slice.iter(); loop { + //~^ ERROR: this loop never actually loops + //~| ERROR: this loop could be written as a `while let` loop + //~| NOTE: `-D clippy::while-let-loop` implied by `-D warnings` let _ = match iter.next() { Some(ele) => ele, None => break, }; loop {} + //~^ ERROR: empty `loop {}` wastes CPU cycles } } diff --git a/src/tools/clippy/tests/ui/crashes/ice-360.stderr b/src/tools/clippy/tests/ui/crashes/ice-360.stderr index a2e2ab8fd..a84697a9f 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-360.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-360.stderr @@ -1,25 +1,41 @@ +error: this loop never actually loops + --> $DIR/ice-360.rs:5:5 + | +LL | / loop { +LL | | +LL | | +LL | | +... | +LL | | +LL | | } + | |_____^ + | + = note: `#[deny(clippy::never_loop)]` on by default + error: this loop could be written as a `while let` loop --> $DIR/ice-360.rs:5:5 | LL | / loop { -LL | | let _ = match iter.next() { -LL | | Some(ele) => ele, -LL | | None => break, -LL | | }; -LL | | loop {} +LL | | +LL | | +LL | | +... | +LL | | LL | | } | |_____^ help: try: `while let Some(ele) = iter.next() { .. }` | = note: `-D clippy::while-let-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::while_let_loop)]` error: empty `loop {}` wastes CPU cycles - --> $DIR/ice-360.rs:10:9 + --> $DIR/ice-360.rs:13:9 | LL | loop {} | ^^^^^^^ | = help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body = note: `-D clippy::empty-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_loop)]` -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors diff --git a/src/tools/clippy/tests/ui/crashes/ice-3717.fixed b/src/tools/clippy/tests/ui/crashes/ice-3717.fixed new file mode 100644 index 000000000..3f54b3269 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-3717.fixed @@ -0,0 +1,11 @@ +#![deny(clippy::implicit_hasher)] + +use std::collections::HashSet; + +fn main() {} + +pub fn ice_3717(_: &HashSet) { + //~^ ERROR: parameter of type `HashSet` should be generalized over different hashers + let _ = [0u8; 0]; + let _: HashSet = HashSet::default(); +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-3717.rs b/src/tools/clippy/tests/ui/crashes/ice-3717.rs index f50714643..2890a9277 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-3717.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-3717.rs @@ -5,6 +5,7 @@ use std::collections::HashSet; fn main() {} pub fn ice_3717(_: &HashSet) { + //~^ ERROR: parameter of type `HashSet` should be generalized over different hashers let _ = [0u8; 0]; let _: HashSet = HashSet::new(); } diff --git a/src/tools/clippy/tests/ui/crashes/ice-3741.rs b/src/tools/clippy/tests/ui/crashes/ice-3741.rs index 268c5ba0a..3106a2e72 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-3741.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-3741.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_crash.rs:proc-macro +//@aux-build:proc_macro_crash.rs #![warn(clippy::suspicious_else_formatting)] diff --git a/src/tools/clippy/tests/ui/crashes/ice-3891.rs b/src/tools/clippy/tests/ui/crashes/ice-3891.rs index 05c5134c8..a3f1ccad7 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-3891.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-3891.rs @@ -1,3 +1,4 @@ fn main() { 1x; + //~^ ERROR: invalid suffix `x` for number literal } diff --git a/src/tools/clippy/tests/ui/crashes/ice-3969.rs b/src/tools/clippy/tests/ui/crashes/ice-3969.rs index 9b68cac7f..d5676cbd9 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-3969.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-3969.rs @@ -18,10 +18,13 @@ struct Dst { struct TwoStrs(str, str) where str: Sized; +//~^ ERROR: trait bound str: std::marker::Sized does not depend on any type or lifetim +//~| NOTE: `-D trivial-bounds` implied by `-D warnings` fn unsized_local() where for<'a> Dst: Sized, + //~^ ERROR: trait bound for<'a> Dst<(dyn A + 'a)>: std::marker::Sized does not depend { let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); } @@ -29,6 +32,7 @@ where fn return_str() -> str where str: Sized, + //~^ ERROR: trait bound str: std::marker::Sized does not depend on any type or lifetim { *"Sized".to_string().into_boxed_str() } @@ -36,6 +40,7 @@ where fn use_op(s: String) -> String where String: ::std::ops::Neg, + //~^ ERROR: trait bound std::string::String: std::ops::Neg does not depend on any type { -s } @@ -43,6 +48,7 @@ where fn use_for() where i32: Iterator, + //~^ ERROR: trait bound i32: std::iter::Iterator does not depend on any type or lifeti { for _ in 2i32 {} } diff --git a/src/tools/clippy/tests/ui/crashes/ice-3969.stderr b/src/tools/clippy/tests/ui/crashes/ice-3969.stderr index 790180808..c6bef3004 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-3969.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-3969.stderr @@ -5,27 +5,28 @@ LL | str: Sized; | ^^^^^ | = note: `-D trivial-bounds` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(trivial_bounds)]` error: trait bound for<'a> Dst<(dyn A + 'a)>: std::marker::Sized does not depend on any type or lifetime parameters - --> $DIR/ice-3969.rs:24:30 + --> $DIR/ice-3969.rs:26:30 | LL | for<'a> Dst: Sized, | ^^^^^ error: trait bound str: std::marker::Sized does not depend on any type or lifetime parameters - --> $DIR/ice-3969.rs:31:10 + --> $DIR/ice-3969.rs:34:10 | LL | str: Sized, | ^^^^^ error: trait bound std::string::String: std::ops::Neg does not depend on any type or lifetime parameters - --> $DIR/ice-3969.rs:38:13 + --> $DIR/ice-3969.rs:42:13 | LL | String: ::std::ops::Neg, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: trait bound i32: std::iter::Iterator does not depend on any type or lifetime parameters - --> $DIR/ice-3969.rs:45:10 + --> $DIR/ice-3969.rs:50:10 | LL | i32: Iterator, | ^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/crashes/ice-5835.fixed b/src/tools/clippy/tests/ui/crashes/ice-5835.fixed new file mode 100644 index 000000000..c0532d685 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5835.fixed @@ -0,0 +1,11 @@ +#[rustfmt::skip] +pub struct Foo { + /// 位 + //~^ ERROR: using tabs in doc comments is not recommended + //~| NOTE: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` + /// ^ Do not remove this tab character. + /// It was required to trigger the ICE. + pub bar: u8, +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-5835.rs b/src/tools/clippy/tests/ui/crashes/ice-5835.rs index 5e99cb432..122bddd6a 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-5835.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-5835.rs @@ -1,6 +1,8 @@ #[rustfmt::skip] pub struct Foo { /// 位 + //~^ ERROR: using tabs in doc comments is not recommended + //~| NOTE: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` /// ^ Do not remove this tab character. /// It was required to trigger the ICE. pub bar: u8, diff --git a/src/tools/clippy/tests/ui/crashes/ice-5835.stderr b/src/tools/clippy/tests/ui/crashes/ice-5835.stderr index c972bcb60..74d99a348 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-5835.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-5835.stderr @@ -5,6 +5,7 @@ LL | /// 位 | ^^^^ help: consider using four spaces per tab | = note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crashes/ice-5872.fixed b/src/tools/clippy/tests/ui/crashes/ice-5872.fixed new file mode 100644 index 000000000..c8e870c62 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-5872.fixed @@ -0,0 +1,7 @@ +#![warn(clippy::needless_collect)] + +fn main() { + let _ = vec![1, 2, 3].into_iter().next().is_none(); + //~^ ERROR: avoid using `collect()` when not needed + //~| NOTE: `-D clippy::needless-collect` implied by `-D warnings` +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-5872.rs b/src/tools/clippy/tests/ui/crashes/ice-5872.rs index 68afa8f8c..c6ed31365 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-5872.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-5872.rs @@ -2,4 +2,6 @@ fn main() { let _ = vec![1, 2, 3].into_iter().collect::>().is_empty(); + //~^ ERROR: avoid using `collect()` when not needed + //~| NOTE: `-D clippy::needless-collect` implied by `-D warnings` } diff --git a/src/tools/clippy/tests/ui/crashes/ice-5872.stderr b/src/tools/clippy/tests/ui/crashes/ice-5872.stderr index a60ca345c..75a26ee31 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-5872.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-5872.stderr @@ -5,6 +5,7 @@ LL | let _ = vec![1, 2, 3].into_iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` | = note: `-D clippy::needless-collect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_collect)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crashes/ice-6250.rs b/src/tools/clippy/tests/ui/crashes/ice-6250.rs index c33580ff6..32849f2ca 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-6250.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-6250.rs @@ -1,6 +1,6 @@ // originally from glacier/fixed/77218.rs // ice while adjusting... - +//@no-rustfix pub struct Cache { data: Vec, } diff --git a/src/tools/clippy/tests/ui/crashes/ice-6251.rs b/src/tools/clippy/tests/ui/crashes/ice-6251.rs index 6aa779aae..a81137a64 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-6251.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-6251.rs @@ -1,6 +1,6 @@ // originally from glacier/fixed/77329.rs // assertion failed: `(left == right) ; different DefIds - +//@no-rustfix fn bug() -> impl Iterator { std::iter::empty() } diff --git a/src/tools/clippy/tests/ui/crashes/ice-6251.stderr b/src/tools/clippy/tests/ui/crashes/ice-6251.stderr index 68a5766c9..11081dc80 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-6251.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-6251.stderr @@ -27,7 +27,7 @@ LL | fn bug() -> impl Iterator { | ^^^^^^^^^^^ expected `usize`, found closure | = note: expected type `usize` - found closure `[closure@$DIR/ice-6251.rs:4:44: 4:53]` + found closure `{closure@$DIR/ice-6251.rs:4:44: 4:53}` error: aborting due to 3 previous errors diff --git a/src/tools/clippy/tests/ui/crashes/ice-6252.rs b/src/tools/clippy/tests/ui/crashes/ice-6252.rs index 0ccf0aae9..67fbb0ff6 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-6252.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-6252.rs @@ -1,5 +1,6 @@ // originally from glacier fixed/77919.rs // encountered errors resolving bounds after type-checking +//@no-rustfix trait TypeVal { const VAL: T; } diff --git a/src/tools/clippy/tests/ui/crashes/ice-6252.stderr b/src/tools/clippy/tests/ui/crashes/ice-6252.stderr index 4787282f5..cb65360d1 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-6252.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-6252.stderr @@ -1,5 +1,5 @@ error[E0412]: cannot find type `PhantomData` in this scope - --> $DIR/ice-6252.rs:8:9 + --> $DIR/ice-6252.rs:9:9 | LL | _n: PhantomData, | ^^^^^^^^^^^ not found in this scope @@ -14,7 +14,7 @@ LL + use std::marker::PhantomData; | error[E0412]: cannot find type `VAL` in this scope - --> $DIR/ice-6252.rs:10:63 + --> $DIR/ice-6252.rs:11:63 | LL | impl TypeVal for Multiply where N: TypeVal {} | ^^^ not found in this scope @@ -25,7 +25,7 @@ LL | impl TypeVal for Multiply where N: TypeVal {} | +++++ error[E0046]: not all trait items implemented, missing: `VAL` - --> $DIR/ice-6252.rs:10:1 + --> $DIR/ice-6252.rs:11:1 | LL | const VAL: T; | ------------ `VAL` from trait diff --git a/src/tools/clippy/tests/ui/crashes/ice-6254.rs b/src/tools/clippy/tests/ui/crashes/ice-6254.rs index 8af608903..2ae426cf7 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-6254.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-6254.rs @@ -11,6 +11,8 @@ fn main() { // This used to cause an ICE (https://github.com/rust-lang/rust/issues/78071) match FOO_REF_REF { FOO_REF_REF => {}, + //~^ ERROR: to use a constant of type `Foo` in a pattern, `Foo` must be annotated + //~| NOTE: for more information, see issue #62411 {}, } } diff --git a/src/tools/clippy/tests/ui/crashes/ice-6254.stderr b/src/tools/clippy/tests/ui/crashes/ice-6254.stderr index 263c27d3d..6ace7dae8 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-6254.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-6254.stderr @@ -9,6 +9,7 @@ LL | FOO_REF_REF => {}, = note: the traits must be derived, manual `impl`s are not sufficient = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details = note: `-D indirect-structural-match` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(indirect_structural_match)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crashes/ice-7169.fixed b/src/tools/clippy/tests/ui/crashes/ice-7169.fixed new file mode 100644 index 000000000..cf4077e4d --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-7169.fixed @@ -0,0 +1,13 @@ +#![allow(clippy::needless_if)] + +#[derive(Default)] +struct A { + a: Vec>, + b: T, +} + +fn main() { + if Ok::<_, ()>(A::::default()).is_ok() {} + //~^ ERROR: redundant pattern matching, consider using `is_ok()` + //~| NOTE: `-D clippy::redundant-pattern-matching` implied by `-D warnings` +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-7169.rs b/src/tools/clippy/tests/ui/crashes/ice-7169.rs index b203252f0..b09e6f384 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-7169.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-7169.rs @@ -8,4 +8,6 @@ struct A { fn main() { if let Ok(_) = Ok::<_, ()>(A::::default()) {} + //~^ ERROR: redundant pattern matching, consider using `is_ok()` + //~| NOTE: `-D clippy::redundant-pattern-matching` implied by `-D warnings` } diff --git a/src/tools/clippy/tests/ui/crashes/ice-7169.stderr b/src/tools/clippy/tests/ui/crashes/ice-7169.stderr index 0cd028516..47947f89b 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-7169.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-7169.stderr @@ -5,6 +5,7 @@ LL | if let Ok(_) = Ok::<_, ()>(A::::default()) {} | -------^^^^^-------------------------------------- help: try: `if Ok::<_, ()>(A::::default()).is_ok()` | = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crashes/ice-7868.stderr b/src/tools/clippy/tests/ui/crashes/ice-7868.stderr index 1d8314e88..e5f14f221 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-7868.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-7868.stderr @@ -6,6 +6,7 @@ LL | unsafe { 0 }; | = help: consider adding a safety comment on the preceding line = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crashes/ice-7869.rs b/src/tools/clippy/tests/ui/crashes/ice-7869.rs index 8f97a063a..774e22f6b 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-7869.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-7869.rs @@ -1,4 +1,5 @@ enum Tila { + //~^ ERROR: all variants have the same prefix: `Työ` TyöAlkoi, TyöKeskeytyi, TyöValmis, diff --git a/src/tools/clippy/tests/ui/crashes/ice-7869.stderr b/src/tools/clippy/tests/ui/crashes/ice-7869.stderr index 35d1e8fd2..7acace78a 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-7869.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-7869.stderr @@ -2,6 +2,7 @@ error: all variants have the same prefix: `Työ` --> $DIR/ice-7869.rs:1:1 | LL | / enum Tila { +LL | | LL | | TyöAlkoi, LL | | TyöKeskeytyi, LL | | TyöValmis, @@ -10,6 +11,7 @@ LL | | } | = help: remove the prefixes and use full paths to the variants instead of glob imports = note: `-D clippy::enum-variant-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::enum_variant_names)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crashes/ice-8250.fixed b/src/tools/clippy/tests/ui/crashes/ice-8250.fixed new file mode 100644 index 000000000..984b61258 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-8250.fixed @@ -0,0 +1,8 @@ +fn _f(s: &str) -> Option<()> { + let _ = s[1..].split('.').next()?; + //~^ ERROR: unnecessary use of `splitn` + //~| NOTE: `-D clippy::needless-splitn` implied by `-D warnings` + Some(()) +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-8250.rs b/src/tools/clippy/tests/ui/crashes/ice-8250.rs index d9a5ee116..c1b2e48ba 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-8250.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-8250.rs @@ -1,5 +1,7 @@ fn _f(s: &str) -> Option<()> { let _ = s[1..].splitn(2, '.').next()?; + //~^ ERROR: unnecessary use of `splitn` + //~| NOTE: `-D clippy::needless-splitn` implied by `-D warnings` Some(()) } diff --git a/src/tools/clippy/tests/ui/crashes/ice-8250.stderr b/src/tools/clippy/tests/ui/crashes/ice-8250.stderr index e6f3644ef..9c57f3345 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-8250.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-8250.stderr @@ -5,6 +5,7 @@ LL | let _ = s[1..].splitn(2, '.').next()?; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `s[1..].split('.')` | = note: `-D clippy::needless-splitn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_splitn)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crashes/ice-8821.fixed b/src/tools/clippy/tests/ui/crashes/ice-8821.fixed new file mode 100644 index 000000000..a25bb46f9 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-8821.fixed @@ -0,0 +1,10 @@ +#![warn(clippy::let_unit_value)] + +fn f() {} +static FN: fn() = f; + +fn main() { + FN(); + //~^ ERROR: this let-binding has unit value + //~| NOTE: `-D clippy::let-unit-value` implied by `-D warnings` +} diff --git a/src/tools/clippy/tests/ui/crashes/ice-8821.rs b/src/tools/clippy/tests/ui/crashes/ice-8821.rs index fb87b79ae..082f7c926 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-8821.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-8821.rs @@ -5,4 +5,6 @@ static FN: fn() = f; fn main() { let _: () = FN(); + //~^ ERROR: this let-binding has unit value + //~| NOTE: `-D clippy::let-unit-value` implied by `-D warnings` } diff --git a/src/tools/clippy/tests/ui/crashes/ice-8821.stderr b/src/tools/clippy/tests/ui/crashes/ice-8821.stderr index 486096e0a..c8bd01fb1 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-8821.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-8821.stderr @@ -5,6 +5,7 @@ LL | let _: () = FN(); | ^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `FN();` | = note: `-D clippy::let-unit-value` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_unit_value)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crashes/ice-8850.fixed b/src/tools/clippy/tests/ui/crashes/ice-8850.fixed new file mode 100644 index 000000000..4569b9e87 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-8850.fixed @@ -0,0 +1,31 @@ +fn fn_pointer_static() -> usize { + static FN: fn() -> usize = || 1; + + FN() + 1 + //~^ ERROR: returning the result of a `let` binding from a block + //~| NOTE: `-D clippy::let-and-return` implied by `-D warnings` +} + +fn fn_pointer_const() -> usize { + const FN: fn() -> usize = || 1; + + FN() + 1 + //~^ ERROR: returning the result of a `let` binding from a block +} + +fn deref_to_dyn_fn() -> usize { + struct Derefs; + impl std::ops::Deref for Derefs { + type Target = dyn Fn() -> usize; + + fn deref(&self) -> &Self::Target { + &|| 2 + } + } + static FN: Derefs = Derefs; + + FN() + 1 + //~^ ERROR: returning the result of a `let` binding from a block +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-8850.rs b/src/tools/clippy/tests/ui/crashes/ice-8850.rs index f2747ab22..499756ece 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-8850.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-8850.rs @@ -2,12 +2,15 @@ fn fn_pointer_static() -> usize { static FN: fn() -> usize = || 1; let res = FN() + 1; res + //~^ ERROR: returning the result of a `let` binding from a block + //~| NOTE: `-D clippy::let-and-return` implied by `-D warnings` } fn fn_pointer_const() -> usize { const FN: fn() -> usize = || 1; let res = FN() + 1; res + //~^ ERROR: returning the result of a `let` binding from a block } fn deref_to_dyn_fn() -> usize { @@ -22,6 +25,7 @@ fn deref_to_dyn_fn() -> usize { static FN: Derefs = Derefs; let res = FN() + 1; res + //~^ ERROR: returning the result of a `let` binding from a block } fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-8850.stderr b/src/tools/clippy/tests/ui/crashes/ice-8850.stderr index 620fd1eda..aa140f305 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-8850.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-8850.stderr @@ -7,6 +7,7 @@ LL | res | ^^^ | = note: `-D clippy::let-and-return` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_and_return)]` help: return the expression directly | LL ~ @@ -14,7 +15,7 @@ LL ~ FN() + 1 | error: returning the result of a `let` binding from a block - --> $DIR/ice-8850.rs:10:5 + --> $DIR/ice-8850.rs:12:5 | LL | let res = FN() + 1; | ------------------- unnecessary `let` binding @@ -28,7 +29,7 @@ LL ~ FN() + 1 | error: returning the result of a `let` binding from a block - --> $DIR/ice-8850.rs:24:5 + --> $DIR/ice-8850.rs:27:5 | LL | let res = FN() + 1; | ------------------- unnecessary `let` binding diff --git a/src/tools/clippy/tests/ui/crashes/ice-9041.rs b/src/tools/clippy/tests/ui/crashes/ice-9041.rs index 55cc9bc99..727d88f7f 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-9041.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-9041.rs @@ -1,8 +1,10 @@ pub struct Thing; - +//@no-rustfix pub fn has_thing(things: &[Thing]) -> bool { let is_thing_ready = |_peer: &Thing| -> bool { todo!() }; things.iter().find(|p| is_thing_ready(p)).is_some() + //~^ ERROR: called `is_some()` after searching an `Iterator` with `find` + //~| NOTE: `-D clippy::search-is-some` implied by `-D warnings` } fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-9041.stderr b/src/tools/clippy/tests/ui/crashes/ice-9041.stderr index f5038f0a8..49c9bdc30 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-9041.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-9041.stderr @@ -5,6 +5,7 @@ LL | things.iter().find(|p| is_thing_ready(p)).is_some() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|p| is_thing_ready(&p))` | = note: `-D clippy::search-is-some` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::search_is_some)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crashes/ice-9405.stderr b/src/tools/clippy/tests/ui/crashes/ice-9405.stderr index 9a6e410f2..56649a2bd 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-9405.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-9405.stderr @@ -1,7 +1,7 @@ warning: multiple lines skipped by escaped newline --> $DIR/ice-9405.rs:6:10 | -LL | "/ +LL | "\ | __________^ LL | | LL | | {}", diff --git a/src/tools/clippy/tests/ui/crashes/ice-9445.rs b/src/tools/clippy/tests/ui/crashes/ice-9445.rs index c67b22f6f..b6afbd33c 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-9445.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-9445.rs @@ -1,3 +1,5 @@ const UNINIT: core::mem::MaybeUninit> = core::mem::MaybeUninit::uninit(); +//~^ ERROR: a `const` item should never be interior mutable +//~| NOTE: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/ice-9445.stderr b/src/tools/clippy/tests/ui/crashes/ice-9445.stderr index a59d098e5..9307409ba 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-9445.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-9445.stderr @@ -7,6 +7,7 @@ LL | const UNINIT: core::mem::MaybeUninit> = core: | make this a static item (maybe with lazy_static) | = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::declare_interior_mutable_const)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crashes/ice-9463.rs b/src/tools/clippy/tests/ui/crashes/ice-9463.rs index 9564e77c2..fa83d25b3 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-9463.rs +++ b/src/tools/clippy/tests/ui/crashes/ice-9463.rs @@ -1,5 +1,9 @@ #![deny(arithmetic_overflow)] fn main() { let _x = -1_i32 >> -1; + //~^ ERROR: this arithmetic operation will overflow let _y = 1u32 >> 10000000000000u32; + //~^ ERROR: this arithmetic operation will overflow + //~| ERROR: literal out of range for `u32` + //~| NOTE: the literal `10000000000000u32` does not fit into the type `u32` whose rang } diff --git a/src/tools/clippy/tests/ui/crashes/ice-9463.stderr b/src/tools/clippy/tests/ui/crashes/ice-9463.stderr index 2b425e85a..911795694 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-9463.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-9463.stderr @@ -11,13 +11,13 @@ LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ error: this arithmetic operation will overflow - --> $DIR/ice-9463.rs:4:14 + --> $DIR/ice-9463.rs:5:14 | LL | let _y = 1u32 >> 10000000000000u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to shift right by `1316134912_u32`, which would overflow error: literal out of range for `u32` - --> $DIR/ice-9463.rs:4:22 + --> $DIR/ice-9463.rs:5:22 | LL | let _y = 1u32 >> 10000000000000u32; | ^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/crashes/ice-96721.fixed b/src/tools/clippy/tests/ui/crashes/ice-96721.fixed new file mode 100644 index 000000000..976189d0b --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-96721.fixed @@ -0,0 +1,10 @@ +macro_rules! foo { + () => { + "bar.rs" + }; +} + +#[path = "file"] //~ ERROR: malformed `path` attribute +mod abc {} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.fixed b/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.fixed new file mode 100644 index 000000000..8bd9eea75 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.fixed @@ -0,0 +1,21 @@ +#![deny(clippy::needless_lifetimes)] +#![allow(dead_code)] + +trait Foo {} + +struct Bar; + +struct Baz<'a> { + bar: &'a Bar, +} + +impl<'a> Foo for Baz<'a> {} + +impl Bar { + fn baz(&self) -> impl Foo + '_ { + //~^ ERROR: the following explicit lifetimes could be elided: 'a + Baz { bar: self } + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.rs b/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.rs index 376ff97ba..06947e3a3 100644 --- a/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.rs +++ b/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.rs @@ -13,6 +13,7 @@ impl<'a> Foo for Baz<'a> {} impl Bar { fn baz<'a>(&'a self) -> impl Foo + 'a { + //~^ ERROR: the following explicit lifetimes could be elided: 'a Baz { bar: self } } } diff --git a/src/tools/clippy/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed b/src/tools/clippy/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed new file mode 100644 index 000000000..774dea391 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/needless_pass_by_value-w-late-bound.fixed @@ -0,0 +1,10 @@ +// https://github.com/rust-lang/rust/issues/107147 + +#![warn(clippy::needless_pass_by_value)] + +struct Foo<'a>(&'a [(); 100]); + +fn test(x: &Foo<'_>) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body + +fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs b/src/tools/clippy/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs index dd3d8b8b6..f3d887192 100644 --- a/src/tools/clippy/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs +++ b/src/tools/clippy/tests/ui/crashes/needless_pass_by_value-w-late-bound.rs @@ -5,5 +5,6 @@ struct Foo<'a>(&'a [(); 100]); fn test(x: Foo<'_>) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body fn main() {} diff --git a/src/tools/clippy/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr b/src/tools/clippy/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr index 7a0a64897..6d4539399 100644 --- a/src/tools/clippy/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr +++ b/src/tools/clippy/tests/ui/crashes/needless_pass_by_value-w-late-bound.stderr @@ -10,6 +10,7 @@ help: consider marking this type as `Copy` LL | struct Foo<'a>(&'a [(); 100]); | ^^^^^^^^^^^^^^ = note: `-D clippy::needless-pass-by-value` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_value)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crate_in_macro_def.fixed b/src/tools/clippy/tests/ui/crate_in_macro_def.fixed index 12a7b9470..bd91389c8 100644 --- a/src/tools/clippy/tests/ui/crate_in_macro_def.fixed +++ b/src/tools/clippy/tests/ui/crate_in_macro_def.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::crate_in_macro_def)] mod hygienic { diff --git a/src/tools/clippy/tests/ui/crate_in_macro_def.rs b/src/tools/clippy/tests/ui/crate_in_macro_def.rs index a1a9eabf6..f6fa338ee 100644 --- a/src/tools/clippy/tests/ui/crate_in_macro_def.rs +++ b/src/tools/clippy/tests/ui/crate_in_macro_def.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::crate_in_macro_def)] mod hygienic { diff --git a/src/tools/clippy/tests/ui/crate_in_macro_def.stderr b/src/tools/clippy/tests/ui/crate_in_macro_def.stderr index 9ac5937dc..3e6246182 100644 --- a/src/tools/clippy/tests/ui/crate_in_macro_def.stderr +++ b/src/tools/clippy/tests/ui/crate_in_macro_def.stderr @@ -1,10 +1,11 @@ error: `crate` references the macro call's crate - --> $DIR/crate_in_macro_def.rs:19:28 + --> $DIR/crate_in_macro_def.rs:18:28 | LL | println!("{}", crate::unhygienic::MESSAGE); | ^^^^^ help: to reference the macro definition's crate, use: `$crate` | = note: `-D clippy::crate-in-macro-def` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::crate_in_macro_def)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.fixed b/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.fixed new file mode 100644 index 000000000..32bccd3a0 --- /dev/null +++ b/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.fixed @@ -0,0 +1,13 @@ +#![no_std] +#![feature(lang_items, start, libc)] +#![crate_type = "lib"] + +use core::panic::PanicInfo; + +#[warn(clippy::all)] +fn main() { + let mut a = 42; + let mut b = 1337; + + core::mem::swap(&mut a, &mut b); +} diff --git a/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.rs b/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.rs index d3571eaf0..8ed45a334 100644 --- a/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.rs +++ b/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.rs @@ -10,5 +10,7 @@ fn main() { let mut b = 1337; a = b; + //~^ ERROR: this looks like you are trying to swap `a` and `b` + //~| NOTE: or maybe you should use `core::mem::replace`? b = a; } diff --git a/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.stderr b/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.stderr index 7d8ea3f76..01033246d 100644 --- a/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.stderr +++ b/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.stderr @@ -2,11 +2,14 @@ error: this looks like you are trying to swap `a` and `b` --> $DIR/no_std_swap.rs:12:5 | LL | / a = b; +LL | | +LL | | LL | | b = a; | |_________^ help: try: `core::mem::swap(&mut a, &mut b)` | = note: or maybe you should use `core::mem::replace`? = note: `-D clippy::almost-swapped` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::almost_swapped)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/crate_level_checks/std_main_recursion.rs b/src/tools/clippy/tests/ui/crate_level_checks/std_main_recursion.rs index 89ff66099..c2c3e0958 100644 --- a/src/tools/clippy/tests/ui/crate_level_checks/std_main_recursion.rs +++ b/src/tools/clippy/tests/ui/crate_level_checks/std_main_recursion.rs @@ -3,4 +3,5 @@ fn main() { println!("Hello, World!"); main(); + //~^ ERROR: recursing into entrypoint `main` } diff --git a/src/tools/clippy/tests/ui/crate_level_checks/std_main_recursion.stderr b/src/tools/clippy/tests/ui/crate_level_checks/std_main_recursion.stderr index 82c68bd1c..f3ffd6a10 100644 --- a/src/tools/clippy/tests/ui/crate_level_checks/std_main_recursion.stderr +++ b/src/tools/clippy/tests/ui/crate_level_checks/std_main_recursion.stderr @@ -6,6 +6,7 @@ LL | main(); | = help: consider using another function for this recursion = note: `-D clippy::main-recursion` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::main_recursion)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/create_dir.fixed b/src/tools/clippy/tests/ui/create_dir.fixed index 5de3e9fea..8fbf7dd19 100644 --- a/src/tools/clippy/tests/ui/create_dir.fixed +++ b/src/tools/clippy/tests/ui/create_dir.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused_must_use)] #![warn(clippy::create_dir)] diff --git a/src/tools/clippy/tests/ui/create_dir.rs b/src/tools/clippy/tests/ui/create_dir.rs index d375bfb4a..af2c326ec 100644 --- a/src/tools/clippy/tests/ui/create_dir.rs +++ b/src/tools/clippy/tests/ui/create_dir.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused_must_use)] #![warn(clippy::create_dir)] diff --git a/src/tools/clippy/tests/ui/create_dir.stderr b/src/tools/clippy/tests/ui/create_dir.stderr index 67298fc47..037e6ff17 100644 --- a/src/tools/clippy/tests/ui/create_dir.stderr +++ b/src/tools/clippy/tests/ui/create_dir.stderr @@ -1,13 +1,14 @@ error: calling `std::fs::create_dir` where there may be a better way - --> $DIR/create_dir.rs:11:5 + --> $DIR/create_dir.rs:10:5 | LL | std::fs::create_dir("foo"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `create_dir_all("foo")` | = note: `-D clippy::create-dir` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::create_dir)]` error: calling `std::fs::create_dir` where there may be a better way - --> $DIR/create_dir.rs:12:5 + --> $DIR/create_dir.rs:11:5 | LL | std::fs::create_dir("bar").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `std::fs::create_dir_all` instead: `create_dir_all("bar")` diff --git a/src/tools/clippy/tests/ui/dbg_macro.rs b/src/tools/clippy/tests/ui/dbg_macro.rs index 6c63c0989..149b08476 100644 --- a/src/tools/clippy/tests/ui/dbg_macro.rs +++ b/src/tools/clippy/tests/ui/dbg_macro.rs @@ -1,24 +1,36 @@ +//@no-rustfix + #![warn(clippy::dbg_macro)] fn foo(n: u32) -> u32 { if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } + //~^ ERROR: the `dbg!` macro is intended as a debugging tool + //~| NOTE: `-D clippy::dbg-macro` implied by `-D warnings` } fn bar(_: ()) {} fn factorial(n: u32) -> u32 { if dbg!(n <= 1) { + //~^ ERROR: the `dbg!` macro is intended as a debugging tool dbg!(1) + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } else { dbg!(n * factorial(n - 1)) + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } } fn main() { dbg!(42); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool dbg!(dbg!(dbg!(42))); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool foo(3) + dbg!(factorial(4)); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool dbg!(1, 2, dbg!(3, 4)); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool dbg!(1, 2, 3, 4, 5); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } fn issue9914() { @@ -39,11 +51,16 @@ fn issue9914() { } dbg!(); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool #[allow(clippy::let_unit_value)] let _ = dbg!(); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool bar(dbg!()); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool foo!(dbg!()); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool foo2!(foo!(dbg!())); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool expand_to_dbg!(); } @@ -65,22 +82,26 @@ mod issue7274 { struct MyThing; define_thing!(MyThing, { dbg!(2); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool }); } #[test] pub fn issue8481() { dbg!(1); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } #[cfg(test)] fn foo2() { dbg!(1); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } #[cfg(test)] mod mod1 { fn func() { dbg!(1); + //~^ ERROR: the `dbg!` macro is intended as a debugging tool } } diff --git a/src/tools/clippy/tests/ui/dbg_macro.stderr b/src/tools/clippy/tests/ui/dbg_macro.stderr index 3d2926259..f45a7ba1f 100644 --- a/src/tools/clippy/tests/ui/dbg_macro.stderr +++ b/src/tools/clippy/tests/ui/dbg_macro.stderr @@ -1,17 +1,18 @@ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:4:22 + --> $DIR/dbg_macro.rs:6:22 | LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } | ^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::dbg-macro` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::dbg_macro)]` help: remove the invocation before committing it to a version control system | 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.rs:9:8 + --> $DIR/dbg_macro.rs:13:8 | LL | if dbg!(n <= 1) { | ^^^^^^^^^^^^ @@ -22,7 +23,7 @@ LL | if n <= 1 { | ~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:10:9 + --> $DIR/dbg_macro.rs:15:9 | LL | dbg!(1) | ^^^^^^^ @@ -33,7 +34,7 @@ LL | 1 | error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:12:9 + --> $DIR/dbg_macro.rs:18:9 | LL | dbg!(n * factorial(n - 1)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +45,7 @@ LL | n * factorial(n - 1) | error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:17:5 + --> $DIR/dbg_macro.rs:24:5 | LL | dbg!(42); | ^^^^^^^^ @@ -55,7 +56,7 @@ LL | 42; | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:18:5 + --> $DIR/dbg_macro.rs:26:5 | LL | dbg!(dbg!(dbg!(42))); | ^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +67,7 @@ LL | dbg!(dbg!(42)); | ~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:19:14 + --> $DIR/dbg_macro.rs:28:14 | LL | foo(3) + dbg!(factorial(4)); | ^^^^^^^^^^^^^^^^^^ @@ -77,7 +78,7 @@ LL | foo(3) + factorial(4); | ~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:20:5 + --> $DIR/dbg_macro.rs:30:5 | LL | dbg!(1, 2, dbg!(3, 4)); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +89,7 @@ LL | (1, 2, dbg!(3, 4)); | ~~~~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:21:5 + --> $DIR/dbg_macro.rs:32:5 | LL | dbg!(1, 2, 3, 4, 5); | ^^^^^^^^^^^^^^^^^^^ @@ -99,7 +100,7 @@ LL | (1, 2, 3, 4, 5); | ~~~~~~~~~~~~~~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:41:5 + --> $DIR/dbg_macro.rs:53:5 | LL | dbg!(); | ^^^^^^^ @@ -111,7 +112,7 @@ LL + | error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:43:13 + --> $DIR/dbg_macro.rs:56:13 | LL | let _ = dbg!(); | ^^^^^^ @@ -122,7 +123,7 @@ LL | let _ = (); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:44:9 + --> $DIR/dbg_macro.rs:58:9 | LL | bar(dbg!()); | ^^^^^^ @@ -133,7 +134,7 @@ LL | bar(()); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:45:10 + --> $DIR/dbg_macro.rs:60:10 | LL | foo!(dbg!()); | ^^^^^^ @@ -144,7 +145,7 @@ LL | foo!(()); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:46:16 + --> $DIR/dbg_macro.rs:62:16 | LL | foo2!(foo!(dbg!())); | ^^^^^^ @@ -155,7 +156,7 @@ LL | foo2!(foo!(())); | ~~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:67:9 + --> $DIR/dbg_macro.rs:84:9 | LL | dbg!(2); | ^^^^^^^ @@ -166,7 +167,7 @@ LL | 2; | ~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:73:5 + --> $DIR/dbg_macro.rs:91:5 | LL | dbg!(1); | ^^^^^^^ @@ -177,7 +178,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:78:5 + --> $DIR/dbg_macro.rs:97:5 | LL | dbg!(1); | ^^^^^^^ @@ -188,7 +189,7 @@ LL | 1; | ~ error: the `dbg!` macro is intended as a debugging tool - --> $DIR/dbg_macro.rs:84:9 + --> $DIR/dbg_macro.rs:104:9 | LL | dbg!(1); | ^^^^^^^ diff --git a/src/tools/clippy/tests/ui/debug_assert_with_mut_call.rs b/src/tools/clippy/tests/ui/debug_assert_with_mut_call.rs index 46faa0a7b..8d04be777 100644 --- a/src/tools/clippy/tests/ui/debug_assert_with_mut_call.rs +++ b/src/tools/clippy/tests/ui/debug_assert_with_mut_call.rs @@ -40,13 +40,20 @@ fn func_non_mutable() { fn func_mutable() { debug_assert!(bool_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` + //~| NOTE: `-D clippy::debug-assert-with-mut-call` implied by `-D warnings` debug_assert!(!bool_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert_eq!(0, u32_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_eq!(u32_mut(&mut 3), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_ne!(1, u32_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` debug_assert_ne!(u32_mut(&mut 3), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` } fn method_non_mutable() { @@ -62,20 +69,33 @@ fn method_non_mutable() { fn method_mutable() { debug_assert!(S.bool_self_mut()); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(!S.bool_self_mut()); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(S.bool_self_ref_arg_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(S.bool_self_mut_arg_ref(&3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(S.bool_self_mut_arg_mut(&mut 3)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert_eq!(S.u32_self_mut(), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_eq!(S.u32_self_mut_arg_ref(&3), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_eq!(S.u32_self_ref_arg_mut(&mut 3), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_eq!(S.u32_self_mut_arg_mut(&mut 3), 0); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_ne!(S.u32_self_mut(), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` debug_assert_ne!(S.u32_self_mut_arg_ref(&3), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` debug_assert_ne!(S.u32_self_ref_arg_mut(&mut 3), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` debug_assert_ne!(S.u32_self_mut_arg_mut(&mut 3), 1); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` } fn misc() { @@ -84,27 +104,35 @@ fn misc() { debug_assert_eq!(v.get(0), Some(&1)); debug_assert_ne!(v[0], 2); debug_assert_eq!(v.pop(), Some(1)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` debug_assert_ne!(Some(3), v.pop()); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_ne!` let a = &mut 3; debug_assert!(bool_mut(a)); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` // nested debug_assert!(!(bool_ref(&u32_mut(&mut 3)))); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` // chained debug_assert_eq!(v.pop().unwrap(), 3); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert_eq!` // format args debug_assert!(bool_ref(&3), "w/o format"); debug_assert!(bool_mut(&mut 3), "w/o format"); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` debug_assert!(bool_ref(&3), "{} format", "w/"); debug_assert!(bool_mut(&mut 3), "{} format", "w/"); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert!` // sub block let mut x = 42_u32; debug_assert!({ bool_mut(&mut x); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert! x > 10 }); @@ -112,6 +140,7 @@ fn misc() { debug_assert!((|| { let mut x = 42; bool_mut(&mut x); + //~^ ERROR: do not call a function with mutable arguments inside of `debug_assert! x > 10 })()); } diff --git a/src/tools/clippy/tests/ui/debug_assert_with_mut_call.stderr b/src/tools/clippy/tests/ui/debug_assert_with_mut_call.stderr index a2ca71b57..b993bbf55 100644 --- a/src/tools/clippy/tests/ui/debug_assert_with_mut_call.stderr +++ b/src/tools/clippy/tests/ui/debug_assert_with_mut_call.stderr @@ -5,165 +5,166 @@ LL | debug_assert!(bool_mut(&mut 3)); | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::debug-assert-with-mut-call` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::debug_assert_with_mut_call)]` error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:43:20 + --> $DIR/debug_assert_with_mut_call.rs:45:20 | LL | debug_assert!(!bool_mut(&mut 3)); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:45:25 + --> $DIR/debug_assert_with_mut_call.rs:48:25 | LL | debug_assert_eq!(0, u32_mut(&mut 3)); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:46:22 + --> $DIR/debug_assert_with_mut_call.rs:50:22 | LL | debug_assert_eq!(u32_mut(&mut 3), 0); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:48:25 + --> $DIR/debug_assert_with_mut_call.rs:53:25 | LL | debug_assert_ne!(1, u32_mut(&mut 3)); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:49:22 + --> $DIR/debug_assert_with_mut_call.rs:55:22 | LL | debug_assert_ne!(u32_mut(&mut 3), 1); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:64:19 + --> $DIR/debug_assert_with_mut_call.rs:71:19 | LL | debug_assert!(S.bool_self_mut()); | ^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:65:20 + --> $DIR/debug_assert_with_mut_call.rs:73:20 | LL | debug_assert!(!S.bool_self_mut()); | ^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:66:19 + --> $DIR/debug_assert_with_mut_call.rs:75:19 | LL | debug_assert!(S.bool_self_ref_arg_mut(&mut 3)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:67:19 + --> $DIR/debug_assert_with_mut_call.rs:77:19 | LL | debug_assert!(S.bool_self_mut_arg_ref(&3)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:68:19 + --> $DIR/debug_assert_with_mut_call.rs:79:19 | LL | debug_assert!(S.bool_self_mut_arg_mut(&mut 3)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:70:22 + --> $DIR/debug_assert_with_mut_call.rs:82:22 | LL | debug_assert_eq!(S.u32_self_mut(), 0); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:71:22 + --> $DIR/debug_assert_with_mut_call.rs:84:22 | LL | debug_assert_eq!(S.u32_self_mut_arg_ref(&3), 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:72:22 + --> $DIR/debug_assert_with_mut_call.rs:86:22 | LL | debug_assert_eq!(S.u32_self_ref_arg_mut(&mut 3), 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:73:22 + --> $DIR/debug_assert_with_mut_call.rs:88:22 | LL | debug_assert_eq!(S.u32_self_mut_arg_mut(&mut 3), 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:75:22 + --> $DIR/debug_assert_with_mut_call.rs:91:22 | LL | debug_assert_ne!(S.u32_self_mut(), 1); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:76:22 + --> $DIR/debug_assert_with_mut_call.rs:93:22 | LL | debug_assert_ne!(S.u32_self_mut_arg_ref(&3), 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:77:22 + --> $DIR/debug_assert_with_mut_call.rs:95:22 | LL | debug_assert_ne!(S.u32_self_ref_arg_mut(&mut 3), 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:78:22 + --> $DIR/debug_assert_with_mut_call.rs:97:22 | LL | debug_assert_ne!(S.u32_self_mut_arg_mut(&mut 3), 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:86:22 + --> $DIR/debug_assert_with_mut_call.rs:106:22 | LL | debug_assert_eq!(v.pop(), Some(1)); | ^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_ne!` - --> $DIR/debug_assert_with_mut_call.rs:87:31 + --> $DIR/debug_assert_with_mut_call.rs:108:31 | LL | debug_assert_ne!(Some(3), v.pop()); | ^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:90:19 + --> $DIR/debug_assert_with_mut_call.rs:112:19 | LL | debug_assert!(bool_mut(a)); | ^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:93:31 + --> $DIR/debug_assert_with_mut_call.rs:116:31 | LL | debug_assert!(!(bool_ref(&u32_mut(&mut 3)))); | ^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert_eq!` - --> $DIR/debug_assert_with_mut_call.rs:96:22 + --> $DIR/debug_assert_with_mut_call.rs:120:22 | LL | debug_assert_eq!(v.pop().unwrap(), 3); | ^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:100:19 + --> $DIR/debug_assert_with_mut_call.rs:125:19 | LL | debug_assert!(bool_mut(&mut 3), "w/o format"); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:102:19 + --> $DIR/debug_assert_with_mut_call.rs:128:19 | LL | debug_assert!(bool_mut(&mut 3), "{} format", "w/"); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:107:9 + --> $DIR/debug_assert_with_mut_call.rs:134:9 | LL | bool_mut(&mut x); | ^^^^^^^^^^^^^^^^ error: do not call a function with mutable arguments inside of `debug_assert!` - --> $DIR/debug_assert_with_mut_call.rs:114:9 + --> $DIR/debug_assert_with_mut_call.rs:142:9 | LL | bool_mut(&mut x); | ^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/decimal_literal_representation.fixed b/src/tools/clippy/tests/ui/decimal_literal_representation.fixed index a6eb8c214..e34f48b65 100644 --- a/src/tools/clippy/tests/ui/decimal_literal_representation.fixed +++ b/src/tools/clippy/tests/ui/decimal_literal_representation.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #[warn(clippy::decimal_literal_representation)] #[allow(unused_variables)] #[rustfmt::skip] diff --git a/src/tools/clippy/tests/ui/decimal_literal_representation.rs b/src/tools/clippy/tests/ui/decimal_literal_representation.rs index 7c666d6d7..bcc4d0df9 100644 --- a/src/tools/clippy/tests/ui/decimal_literal_representation.rs +++ b/src/tools/clippy/tests/ui/decimal_literal_representation.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #[warn(clippy::decimal_literal_representation)] #[allow(unused_variables)] #[rustfmt::skip] diff --git a/src/tools/clippy/tests/ui/decimal_literal_representation.stderr b/src/tools/clippy/tests/ui/decimal_literal_representation.stderr index 8d50c8f83..f1d4d744e 100644 --- a/src/tools/clippy/tests/ui/decimal_literal_representation.stderr +++ b/src/tools/clippy/tests/ui/decimal_literal_representation.stderr @@ -1,43 +1,44 @@ error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:18:9 + --> $DIR/decimal_literal_representation.rs:16:9 | LL | 32_773, // 0x8005 | ^^^^^^ help: consider: `0x8005` | = note: `-D clippy::decimal-literal-representation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::decimal_literal_representation)]` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:19:9 + --> $DIR/decimal_literal_representation.rs:17:9 | LL | 65_280, // 0xFF00 | ^^^^^^ help: consider: `0xFF00` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:20:9 + --> $DIR/decimal_literal_representation.rs:18: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:21:9 + --> $DIR/decimal_literal_representation.rs:19: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:23:9 + --> $DIR/decimal_literal_representation.rs:21: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:24:9 + --> $DIR/decimal_literal_representation.rs:22:9 | LL | 32_773usize, // 0x8005_usize | ^^^^^^^^^^^ help: consider: `0x8005_usize` error: integer literal has a better hexadecimal representation - --> $DIR/decimal_literal_representation.rs:25:9 + --> $DIR/decimal_literal_representation.rs:23:9 | LL | 2_131_750_927isize, // 0x7F0F_F00F_isize | ^^^^^^^^^^^^^^^^^^ help: consider: `0x7F0F_F00F_isize` diff --git a/src/tools/clippy/tests/ui/declare_interior_mutable_const/enums.stderr b/src/tools/clippy/tests/ui/declare_interior_mutable_const/enums.stderr index 6070df749..6d3437388 100644 --- a/src/tools/clippy/tests/ui/declare_interior_mutable_const/enums.stderr +++ b/src/tools/clippy/tests/ui/declare_interior_mutable_const/enums.stderr @@ -7,6 +7,7 @@ LL | const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(tru | make this a static item (maybe with lazy_static) | = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::declare_interior_mutable_const)]` error: a `const` item should never be interior mutable --> $DIR/enums.rs:23:1 diff --git a/src/tools/clippy/tests/ui/declare_interior_mutable_const/others.stderr b/src/tools/clippy/tests/ui/declare_interior_mutable_const/others.stderr index 0259f6a4a..cc286b9f7 100644 --- a/src/tools/clippy/tests/ui/declare_interior_mutable_const/others.stderr +++ b/src/tools/clippy/tests/ui/declare_interior_mutable_const/others.stderr @@ -7,6 +7,7 @@ LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); | make this a static item (maybe with lazy_static) | = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::declare_interior_mutable_const)]` error: a `const` item should never be interior mutable --> $DIR/others.rs:10:1 diff --git a/src/tools/clippy/tests/ui/declare_interior_mutable_const/traits.stderr b/src/tools/clippy/tests/ui/declare_interior_mutable_const/traits.stderr index ef62919df..7647cd96f 100644 --- a/src/tools/clippy/tests/ui/declare_interior_mutable_const/traits.stderr +++ b/src/tools/clippy/tests/ui/declare_interior_mutable_const/traits.stderr @@ -5,6 +5,7 @@ LL | const ATOMIC: AtomicUsize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::declare_interior_mutable_const)]` error: a `const` item should never be interior mutable --> $DIR/traits.rs:9:9 diff --git a/src/tools/clippy/tests/ui/def_id_nocore.rs b/src/tools/clippy/tests/ui/def_id_nocore.rs index da0816830..190d636eb 100644 --- a/src/tools/clippy/tests/ui/def_id_nocore.rs +++ b/src/tools/clippy/tests/ui/def_id_nocore.rs @@ -25,6 +25,7 @@ struct A; impl A { pub fn as_ref(self) -> &'static str { + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mutabl "A" } } diff --git a/src/tools/clippy/tests/ui/def_id_nocore.stderr b/src/tools/clippy/tests/ui/def_id_nocore.stderr index f8fc17e87..bfd0de4e1 100644 --- a/src/tools/clippy/tests/ui/def_id_nocore.stderr +++ b/src/tools/clippy/tests/ui/def_id_nocore.stderr @@ -6,6 +6,7 @@ LL | pub fn as_ref(self) -> &'static str { | = help: consider choosing a less ambiguous name = note: `-D clippy::wrong-self-convention` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/default_constructed_unit_structs.fixed b/src/tools/clippy/tests/ui/default_constructed_unit_structs.fixed index ac5fe38ff..3047c221d 100644 --- a/src/tools/clippy/tests/ui/default_constructed_unit_structs.fixed +++ b/src/tools/clippy/tests/ui/default_constructed_unit_structs.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::default_constructed_unit_structs)] use std::marker::PhantomData; diff --git a/src/tools/clippy/tests/ui/default_constructed_unit_structs.rs b/src/tools/clippy/tests/ui/default_constructed_unit_structs.rs index de7f14ffb..66afedb23 100644 --- a/src/tools/clippy/tests/ui/default_constructed_unit_structs.rs +++ b/src/tools/clippy/tests/ui/default_constructed_unit_structs.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::default_constructed_unit_structs)] use std::marker::PhantomData; diff --git a/src/tools/clippy/tests/ui/default_constructed_unit_structs.stderr b/src/tools/clippy/tests/ui/default_constructed_unit_structs.stderr index 13abb9149..434c72aa9 100644 --- a/src/tools/clippy/tests/ui/default_constructed_unit_structs.stderr +++ b/src/tools/clippy/tests/ui/default_constructed_unit_structs.stderr @@ -1,37 +1,38 @@ error: use of `default` to create a unit struct - --> $DIR/default_constructed_unit_structs.rs:13:13 + --> $DIR/default_constructed_unit_structs.rs:11:13 | LL | Self::default() | ^^^^^^^^^^^ help: remove this call to `default` | = note: `-D clippy::default-constructed-unit-structs` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::default_constructed_unit_structs)]` error: use of `default` to create a unit struct - --> $DIR/default_constructed_unit_structs.rs:55:31 + --> $DIR/default_constructed_unit_structs.rs:53:31 | 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:128:33 + --> $DIR/default_constructed_unit_structs.rs:126: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:129:42 + --> $DIR/default_constructed_unit_structs.rs:127: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:130:55 + --> $DIR/default_constructed_unit_structs.rs:128: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:131:23 + --> $DIR/default_constructed_unit_structs.rs:129:23 | LL | let _ = UnitStruct::default(); | ^^^^^^^^^^^ help: remove this call to `default` diff --git a/src/tools/clippy/tests/ui/default_instead_of_iter_empty.fixed b/src/tools/clippy/tests/ui/default_instead_of_iter_empty.fixed index f44d34576..3298a222b 100644 --- a/src/tools/clippy/tests/ui/default_instead_of_iter_empty.fixed +++ b/src/tools/clippy/tests/ui/default_instead_of_iter_empty.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::default_instead_of_iter_empty)] #![allow(dead_code)] use std::collections::HashMap; diff --git a/src/tools/clippy/tests/ui/default_instead_of_iter_empty.rs b/src/tools/clippy/tests/ui/default_instead_of_iter_empty.rs index 1c649df25..75b088a99 100644 --- a/src/tools/clippy/tests/ui/default_instead_of_iter_empty.rs +++ b/src/tools/clippy/tests/ui/default_instead_of_iter_empty.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::default_instead_of_iter_empty)] #![allow(dead_code)] use std::collections::HashMap; diff --git a/src/tools/clippy/tests/ui/default_instead_of_iter_empty.stderr b/src/tools/clippy/tests/ui/default_instead_of_iter_empty.stderr index 460fc84de..48d6c02d1 100644 --- a/src/tools/clippy/tests/ui/default_instead_of_iter_empty.stderr +++ b/src/tools/clippy/tests/ui/default_instead_of_iter_empty.stderr @@ -1,19 +1,20 @@ 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:12:13 | LL | let _ = std::iter::Empty::::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::empty::()` | = note: `-D clippy::default-instead-of-iter-empty` implied by `-D warnings` + = 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:14:13 + --> $DIR/default_instead_of_iter_empty.rs:13: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:15:41 + --> $DIR/default_instead_of_iter_empty.rs:14:41 | LL | let _foo: std::iter::Empty = std::iter::Empty::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::iter::empty()` diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed index 02eb78060..9072d2335 100644 --- a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed +++ b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::default_numeric_fallback)] #![allow( diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs index 79a966983..256b94f6c 100644 --- a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs +++ b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::default_numeric_fallback)] #![allow( diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.stderr b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.stderr index b949cd1d5..7ea2e3e68 100644 --- a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.stderr +++ b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.stderr @@ -1,145 +1,146 @@ error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:22:17 + --> $DIR/default_numeric_fallback_f64.rs:21:17 | LL | let x = 0.12; | ^^^^ help: consider adding suffix: `0.12_f64` | = note: `-D clippy::default-numeric-fallback` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::default_numeric_fallback)]` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:23:18 + --> $DIR/default_numeric_fallback_f64.rs:22:18 | LL | let x = [1., 2., 3.]; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:23:22 + --> $DIR/default_numeric_fallback_f64.rs:22:22 | LL | let x = [1., 2., 3.]; | ^^ help: consider adding suffix: `2.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:23:26 + --> $DIR/default_numeric_fallback_f64.rs:22:26 | 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:24:28 + --> $DIR/default_numeric_fallback_f64.rs:23: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:24:32 + --> $DIR/default_numeric_fallback_f64.rs:23: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:24:46 + --> $DIR/default_numeric_fallback_f64.rs:23: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:24:50 + --> $DIR/default_numeric_fallback_f64.rs:23: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:25:23 + --> $DIR/default_numeric_fallback_f64.rs:24: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:26:18 + --> $DIR/default_numeric_fallback_f64.rs:25:18 | LL | _ => 1., | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:45:21 + --> $DIR/default_numeric_fallback_f64.rs:44:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:53:21 + --> $DIR/default_numeric_fallback_f64.rs:52:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:59:21 + --> $DIR/default_numeric_fallback_f64.rs:58:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:67:21 + --> $DIR/default_numeric_fallback_f64.rs:66:21 | LL | let y = 1.; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:79:9 + --> $DIR/default_numeric_fallback_f64.rs:78:9 | LL | 1. | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:85:27 + --> $DIR/default_numeric_fallback_f64.rs:84:27 | LL | let f = || -> _ { 1. }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:89:29 + --> $DIR/default_numeric_fallback_f64.rs:88: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:103:21 + --> $DIR/default_numeric_fallback_f64.rs:102:21 | LL | generic_arg(1.); | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:106:32 + --> $DIR/default_numeric_fallback_f64.rs:105: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:124:28 + --> $DIR/default_numeric_fallback_f64.rs:123:28 | LL | GenericStruct { x: 1. }; | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:127:36 + --> $DIR/default_numeric_fallback_f64.rs:126: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:145:24 + --> $DIR/default_numeric_fallback_f64.rs:144:24 | LL | GenericEnum::X(1.); | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_f64.rs:165:23 + --> $DIR/default_numeric_fallback_f64.rs:164: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:175:25 + --> $DIR/default_numeric_fallback_f64.rs:174:25 | LL | inline!(let x = 22.;); | ^^^ help: consider adding suffix: `22.0_f64` diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed index 23272d07e..920cd9f8f 100644 --- a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed +++ b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(lint_reasons)] #![warn(clippy::default_numeric_fallback)] diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs index fb1491416..bdb7b5f47 100644 --- a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs +++ b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(lint_reasons)] #![warn(clippy::default_numeric_fallback)] diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.stderr b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.stderr index 48cd28102..b03b8b84c 100644 --- a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.stderr +++ b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.stderr @@ -1,157 +1,158 @@ error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:22:17 + --> $DIR/default_numeric_fallback_i32.rs:21:17 | LL | let x = 22; | ^^ help: consider adding suffix: `22_i32` | = note: `-D clippy::default-numeric-fallback` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::default_numeric_fallback)]` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:23:18 + --> $DIR/default_numeric_fallback_i32.rs:22:18 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:23:21 + --> $DIR/default_numeric_fallback_i32.rs:22:21 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:23:24 + --> $DIR/default_numeric_fallback_i32.rs:22:24 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `3_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:24:28 + --> $DIR/default_numeric_fallback_i32.rs:23: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:24:31 + --> $DIR/default_numeric_fallback_i32.rs:23: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:24:44 + --> $DIR/default_numeric_fallback_i32.rs:23: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:24:47 + --> $DIR/default_numeric_fallback_i32.rs:23: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:25:23 + --> $DIR/default_numeric_fallback_i32.rs:24:23 | LL | let x = match 1 { | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:26:13 + --> $DIR/default_numeric_fallback_i32.rs:25:13 | 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:25:18 | LL | 1 => 1, | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:27:18 + --> $DIR/default_numeric_fallback_i32.rs:26:18 | LL | _ => 2, | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:46:21 + --> $DIR/default_numeric_fallback_i32.rs:45:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:54:21 + --> $DIR/default_numeric_fallback_i32.rs:53:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:60:21 + --> $DIR/default_numeric_fallback_i32.rs:59:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:68:21 + --> $DIR/default_numeric_fallback_i32.rs:67:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:80:9 + --> $DIR/default_numeric_fallback_i32.rs:79:9 | LL | 1 | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:86:27 + --> $DIR/default_numeric_fallback_i32.rs:85:27 | LL | let f = || -> _ { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:90:29 + --> $DIR/default_numeric_fallback_i32.rs:89:29 | LL | let f = || -> i32 { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:104:21 + --> $DIR/default_numeric_fallback_i32.rs:103:21 | LL | generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:107:32 + --> $DIR/default_numeric_fallback_i32.rs:106: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:125:28 + --> $DIR/default_numeric_fallback_i32.rs:124:28 | LL | GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:128:36 + --> $DIR/default_numeric_fallback_i32.rs:127:36 | LL | let _ = GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:146:24 + --> $DIR/default_numeric_fallback_i32.rs:145:24 | LL | GenericEnum::X(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:166:23 + --> $DIR/default_numeric_fallback_i32.rs:165:23 | LL | s.generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:176:25 + --> $DIR/default_numeric_fallback_i32.rs:175:25 | LL | inline!(let x = 22;); | ^^ help: consider adding suffix: `22_i32` diff --git a/src/tools/clippy/tests/ui/default_trait_access.fixed b/src/tools/clippy/tests/ui/default_trait_access.fixed index 6e541473c..6f1e72c5a 100644 --- a/src/tools/clippy/tests/ui/default_trait_access.fixed +++ b/src/tools/clippy/tests/ui/default_trait_access.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![deny(clippy::default_trait_access)] #![allow(dead_code, unused_imports)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/default_trait_access.rs b/src/tools/clippy/tests/ui/default_trait_access.rs index 2ffeb32fb..5528ca8b7 100644 --- a/src/tools/clippy/tests/ui/default_trait_access.rs +++ b/src/tools/clippy/tests/ui/default_trait_access.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![deny(clippy::default_trait_access)] #![allow(dead_code, unused_imports)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/default_trait_access.stderr b/src/tools/clippy/tests/ui/default_trait_access.stderr index 103fccf6a..e53c8e2c7 100644 --- a/src/tools/clippy/tests/ui/default_trait_access.stderr +++ b/src/tools/clippy/tests/ui/default_trait_access.stderr @@ -1,53 +1,53 @@ error: calling `String::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:14:22 + --> $DIR/default_trait_access.rs:13:22 | LL | let s1: String = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `String::default()` | note: the lint level is defined here - --> $DIR/default_trait_access.rs:3:9 + --> $DIR/default_trait_access.rs:2:9 | LL | #![deny(clippy::default_trait_access)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `String::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:18:22 + --> $DIR/default_trait_access.rs:17:22 | LL | let s3: String = D2::default(); | ^^^^^^^^^^^^^ help: try: `String::default()` error: calling `String::default()` is more clear than this expression - --> $DIR/default_trait_access.rs:20:22 + --> $DIR/default_trait_access.rs:19:22 | 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:24:22 + --> $DIR/default_trait_access.rs:23: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:34:46 + --> $DIR/default_trait_access.rs:33: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:40:36 + --> $DIR/default_trait_access.rs:39: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:42:36 + --> $DIR/default_trait_access.rs:41: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:46:42 + --> $DIR/default_trait_access.rs:45:42 | LL | let s17: TupleStructDerivedDefault = Default::default(); | ^^^^^^^^^^^^^^^^^^ help: try: `TupleStructDerivedDefault::default()` diff --git a/src/tools/clippy/tests/ui/default_union_representation.rs b/src/tools/clippy/tests/ui/default_union_representation.rs index 93b2d33da..41308b077 100644 --- a/src/tools/clippy/tests/ui/default_union_representation.rs +++ b/src/tools/clippy/tests/ui/default_union_representation.rs @@ -2,6 +2,7 @@ #![warn(clippy::default_union_representation)] union NoAttribute { + //~^ ERROR: this union has the default representation a: i32, b: u32, } @@ -14,6 +15,7 @@ union ReprC { #[repr(packed)] union ReprPacked { + //~^ ERROR: this union has the default representation a: i32, b: u32, } @@ -32,6 +34,7 @@ union ReprCAlign { #[repr(align(32))] union ReprAlign { + //~^ ERROR: this union has the default representation a: i32, b: u32, } @@ -52,6 +55,7 @@ union ZSTsAndField2 { f3: (), } union ZSTAndTwoFields { + //~^ ERROR: this union has the default representation f0: u32, f1: u64, f2: (), diff --git a/src/tools/clippy/tests/ui/default_union_representation.stderr b/src/tools/clippy/tests/ui/default_union_representation.stderr index 8b7ed94cb..82f69ffee 100644 --- a/src/tools/clippy/tests/ui/default_union_representation.stderr +++ b/src/tools/clippy/tests/ui/default_union_representation.stderr @@ -2,6 +2,7 @@ error: this union has the default representation --> $DIR/default_union_representation.rs:4:1 | LL | / union NoAttribute { +LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -9,11 +10,13 @@ LL | | } | = help: consider annotating `NoAttribute` with `#[repr(C)]` to explicitly specify memory layout = note: `-D clippy::default-union-representation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::default_union_representation)]` error: this union has the default representation - --> $DIR/default_union_representation.rs:16:1 + --> $DIR/default_union_representation.rs:17:1 | LL | / union ReprPacked { +LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -22,9 +25,10 @@ LL | | } = help: consider annotating `ReprPacked` with `#[repr(C)]` to explicitly specify memory layout error: this union has the default representation - --> $DIR/default_union_representation.rs:34:1 + --> $DIR/default_union_representation.rs:36:1 | LL | / union ReprAlign { +LL | | LL | | a: i32, LL | | b: u32, LL | | } @@ -33,9 +37,10 @@ LL | | } = help: consider annotating `ReprAlign` with `#[repr(C)]` to explicitly specify memory layout error: this union has the default representation - --> $DIR/default_union_representation.rs:54:1 + --> $DIR/default_union_representation.rs:57:1 | LL | / union ZSTAndTwoFields { +LL | | LL | | f0: u32, LL | | f1: u64, LL | | f2: (), diff --git a/src/tools/clippy/tests/ui/deprecated.stderr b/src/tools/clippy/tests/ui/deprecated.stderr index 0e142ac8f..388fcc238 100644 --- a/src/tools/clippy/tests/ui/deprecated.stderr +++ b/src/tools/clippy/tests/ui/deprecated.stderr @@ -5,6 +5,7 @@ LL | #![warn(clippy::should_assert_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D renamed-and-removed-lints` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(renamed_and_removed_lints)]` error: lint `clippy::extend_from_slice` has been removed: `.extend_from_slice(_)` is a faster way to extend a Vec by a slice --> $DIR/deprecated.rs:6:9 diff --git a/src/tools/clippy/tests/ui/deprecated_old.rs b/src/tools/clippy/tests/ui/deprecated_old.rs index e89dca4fc..356ad5f06 100644 --- a/src/tools/clippy/tests/ui/deprecated_old.rs +++ b/src/tools/clippy/tests/ui/deprecated_old.rs @@ -1,5 +1,9 @@ #[warn(unstable_as_slice)] +//~^ ERROR: lint `unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized +//~| NOTE: `-D renamed-and-removed-lints` implied by `-D warnings` #[warn(unstable_as_mut_slice)] +//~^ ERROR: lint `unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` has been st #[warn(misaligned_transmute)] +//~^ ERROR: lint `misaligned_transmute` has been removed: this lint has been split into ca fn main() {} diff --git a/src/tools/clippy/tests/ui/deprecated_old.stderr b/src/tools/clippy/tests/ui/deprecated_old.stderr index 8043ab005..d27ad852f 100644 --- a/src/tools/clippy/tests/ui/deprecated_old.stderr +++ b/src/tools/clippy/tests/ui/deprecated_old.stderr @@ -5,15 +5,16 @@ LL | #[warn(unstable_as_slice)] | ^^^^^^^^^^^^^^^^^ | = note: `-D renamed-and-removed-lints` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(renamed_and_removed_lints)]` error: lint `unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` has been stabilized in 1.7 - --> $DIR/deprecated_old.rs:2:8 + --> $DIR/deprecated_old.rs:4:8 | LL | #[warn(unstable_as_mut_slice)] | ^^^^^^^^^^^^^^^^^^^^^ error: lint `misaligned_transmute` has been removed: this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr - --> $DIR/deprecated_old.rs:3:8 + --> $DIR/deprecated_old.rs:6:8 | LL | #[warn(misaligned_transmute)] | ^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/deref_addrof.fixed b/src/tools/clippy/tests/ui/deref_addrof.fixed index 0ecca1b8f..aa1cf19b7 100644 --- a/src/tools/clippy/tests/ui/deref_addrof.fixed +++ b/src/tools/clippy/tests/ui/deref_addrof.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::return_self_not_must_use, clippy::useless_vec)] #![warn(clippy::deref_addrof)] diff --git a/src/tools/clippy/tests/ui/deref_addrof.rs b/src/tools/clippy/tests/ui/deref_addrof.rs index 9f91310e6..38796aef3 100644 --- a/src/tools/clippy/tests/ui/deref_addrof.rs +++ b/src/tools/clippy/tests/ui/deref_addrof.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::return_self_not_must_use, clippy::useless_vec)] #![warn(clippy::deref_addrof)] diff --git a/src/tools/clippy/tests/ui/deref_addrof.stderr b/src/tools/clippy/tests/ui/deref_addrof.stderr index 9dd1e246b..b01fa4df6 100644 --- a/src/tools/clippy/tests/ui/deref_addrof.stderr +++ b/src/tools/clippy/tests/ui/deref_addrof.stderr @@ -1,55 +1,56 @@ error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:24:13 + --> $DIR/deref_addrof.rs:23:13 | LL | let b = *&a; | ^^^ help: try: `a` | = note: `-D clippy::deref-addrof` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::deref_addrof)]` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:26:13 + --> $DIR/deref_addrof.rs:25:13 | LL | let b = *&get_number(); | ^^^^^^^^^^^^^^ help: try: `get_number()` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:31:13 + --> $DIR/deref_addrof.rs:30:13 | LL | let b = *&bytes[1..2][0]; | ^^^^^^^^^^^^^^^^ help: try: `bytes[1..2][0]` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:35:13 + --> $DIR/deref_addrof.rs:34:13 | LL | let b = *&(a); | ^^^^^ help: try: `(a)` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:37:13 + --> $DIR/deref_addrof.rs:36:13 | LL | let b = *(&a); | ^^^^^ help: try: `a` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:40:13 + --> $DIR/deref_addrof.rs:39:13 | LL | let b = *((&a)); | ^^^^^^^ help: try: `a` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:42:13 + --> $DIR/deref_addrof.rs:41:13 | LL | let b = *&&a; | ^^^^ help: try: `&a` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:44:14 + --> $DIR/deref_addrof.rs:43:14 | LL | let b = **&aref; | ^^^^^^ help: try: `aref` error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:54:17 + --> $DIR/deref_addrof.rs:53:17 | LL | inline!(*& $(@expr self)) | ^^^^^^^^^^^^^^^^ help: try: `$(@expr self)` @@ -57,7 +58,7 @@ LL | inline!(*& $(@expr self)) = note: this error originates in the macro `__inline_mac_impl` (in Nightly builds, run with -Z macro-backtrace for more info) error: immediately dereferencing a reference - --> $DIR/deref_addrof.rs:58:17 + --> $DIR/deref_addrof.rs:57:17 | LL | inline!(*&mut $(@expr self)) | ^^^^^^^^^^^^^^^^^^^ help: try: `$(@expr self)` diff --git a/src/tools/clippy/tests/ui/deref_addrof_double_trigger.rs b/src/tools/clippy/tests/ui/deref_addrof_double_trigger.rs index 453194329..32582a3a8 100644 --- a/src/tools/clippy/tests/ui/deref_addrof_double_trigger.rs +++ b/src/tools/clippy/tests/ui/deref_addrof_double_trigger.rs @@ -1,5 +1,5 @@ // This test can't work with run-rustfix because it needs two passes of test+fix - +//@no-rustfix #[warn(clippy::deref_addrof)] #[allow(unused_variables, unused_mut)] fn main() { @@ -8,10 +8,13 @@ fn main() { //This produces a suggestion of 'let b = *&a;' which //will trigger the 'clippy::deref_addrof' lint again let b = **&&a; + //~^ ERROR: immediately dereferencing a reference + //~| NOTE: `-D clippy::deref-addrof` implied by `-D warnings` { let mut x = 10; let y = *&mut x; + //~^ ERROR: immediately dereferencing a reference } { @@ -19,5 +22,6 @@ fn main() { //will trigger the 'clippy::deref_addrof' lint again let mut x = 10; let y = **&mut &mut x; + //~^ ERROR: immediately dereferencing a reference } } diff --git a/src/tools/clippy/tests/ui/deref_addrof_double_trigger.stderr b/src/tools/clippy/tests/ui/deref_addrof_double_trigger.stderr index 6fa5069b6..78ec73400 100644 --- a/src/tools/clippy/tests/ui/deref_addrof_double_trigger.stderr +++ b/src/tools/clippy/tests/ui/deref_addrof_double_trigger.stderr @@ -5,15 +5,16 @@ LL | let b = **&&a; | ^^^^ help: try: `&a` | = note: `-D clippy::deref-addrof` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::deref_addrof)]` error: immediately dereferencing a reference - --> $DIR/deref_addrof_double_trigger.rs:14:17 + --> $DIR/deref_addrof_double_trigger.rs:16:17 | LL | let y = *&mut x; | ^^^^^^^ help: try: `x` error: immediately dereferencing a reference - --> $DIR/deref_addrof_double_trigger.rs:21:18 + --> $DIR/deref_addrof_double_trigger.rs:24:18 | LL | let y = **&mut &mut x; | ^^^^^^^^^^^^ help: try: `&mut x` diff --git a/src/tools/clippy/tests/ui/deref_addrof_macro.rs b/src/tools/clippy/tests/ui/deref_addrof_macro.rs index ce4b94a73..c7e60f365 100644 --- a/src/tools/clippy/tests/ui/deref_addrof_macro.rs +++ b/src/tools/clippy/tests/ui/deref_addrof_macro.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::deref_addrof)] diff --git a/src/tools/clippy/tests/ui/deref_by_slicing.fixed b/src/tools/clippy/tests/ui/deref_by_slicing.fixed index f91a425c6..a3c2e8456 100644 --- a/src/tools/clippy/tests/ui/deref_by_slicing.fixed +++ b/src/tools/clippy/tests/ui/deref_by_slicing.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::deref_by_slicing)] #![allow(clippy::borrow_deref_ref)] diff --git a/src/tools/clippy/tests/ui/deref_by_slicing.rs b/src/tools/clippy/tests/ui/deref_by_slicing.rs index 1bfdd0a98..5b4a73712 100644 --- a/src/tools/clippy/tests/ui/deref_by_slicing.rs +++ b/src/tools/clippy/tests/ui/deref_by_slicing.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::deref_by_slicing)] #![allow(clippy::borrow_deref_ref)] diff --git a/src/tools/clippy/tests/ui/deref_by_slicing.stderr b/src/tools/clippy/tests/ui/deref_by_slicing.stderr index 8f042ef47..7b8144a9a 100644 --- a/src/tools/clippy/tests/ui/deref_by_slicing.stderr +++ b/src/tools/clippy/tests/ui/deref_by_slicing.stderr @@ -1,55 +1,56 @@ error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:10:13 + --> $DIR/deref_by_slicing.rs:8:13 | LL | let _ = &vec[..]; | ^^^^^^^^ help: dereference the original value instead: `&*vec` | = note: `-D clippy::deref-by-slicing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::deref_by_slicing)]` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:11:13 + --> $DIR/deref_by_slicing.rs:9:13 | LL | let _ = &mut vec[..]; | ^^^^^^^^^^^^ help: dereference the original value instead: `&mut *vec` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:14:13 + --> $DIR/deref_by_slicing.rs:12:13 | LL | let _ = &ref_vec[..]; | ^^^^^^^^^^^^ help: dereference the original value instead: `&**ref_vec` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:15:21 + --> $DIR/deref_by_slicing.rs:13:21 | 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:16:13 + --> $DIR/deref_by_slicing.rs:14: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:19:13 + --> $DIR/deref_by_slicing.rs:17:13 | LL | let _ = &s[..]; | ^^^^^^ help: dereference the original value instead: `&*s` error: slicing when dereferencing would work - --> $DIR/deref_by_slicing.rs:22:18 + --> $DIR/deref_by_slicing.rs:20: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:26:13 + --> $DIR/deref_by_slicing.rs:24: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:29:13 + --> $DIR/deref_by_slicing.rs:27:13 | LL | let _ = (&bytes[..]).read_to_end(&mut vec![]).unwrap(); // Err, re-borrows slice | ^^^^^^^^^^^^ help: reborrow the original value instead: `(&*bytes)` diff --git a/src/tools/clippy/tests/ui/derivable_impls.fixed b/src/tools/clippy/tests/ui/derivable_impls.fixed index a10f3d010..68c5a5c5c 100644 --- a/src/tools/clippy/tests/ui/derivable_impls.fixed +++ b/src/tools/clippy/tests/ui/derivable_impls.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] use std::collections::HashMap; @@ -289,4 +287,17 @@ mod issue10158 { } } +mod issue11368 { + pub struct A { + a: u32, + } + + impl Default for A { + #[track_caller] + fn default() -> Self { + Self { a: 0 } + } + } +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/derivable_impls.rs b/src/tools/clippy/tests/ui/derivable_impls.rs index 18cef1c5b..21d73ba8b 100644 --- a/src/tools/clippy/tests/ui/derivable_impls.rs +++ b/src/tools/clippy/tests/ui/derivable_impls.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] use std::collections::HashMap; @@ -325,4 +323,17 @@ mod issue10158 { } } +mod issue11368 { + pub struct A { + a: u32, + } + + impl Default for A { + #[track_caller] + fn default() -> Self { + Self { a: 0 } + } + } +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/derivable_impls.stderr b/src/tools/clippy/tests/ui/derivable_impls.stderr index 8089f5ea0..98e2f3612 100644 --- a/src/tools/clippy/tests/ui/derivable_impls.stderr +++ b/src/tools/clippy/tests/ui/derivable_impls.stderr @@ -1,5 +1,5 @@ error: this `impl` can be derived - --> $DIR/derivable_impls.rs:22:1 + --> $DIR/derivable_impls.rs:20:1 | LL | / impl std::default::Default for FooDefault<'_> { LL | | fn default() -> Self { @@ -11,6 +11,7 @@ LL | | } | |_^ | = note: `-D clippy::derivable-impls` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::derivable_impls)]` = help: remove the manual implementation... help: ...and instead derive it | @@ -19,7 +20,7 @@ LL | struct FooDefault<'a> { | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:43:1 + --> $DIR/derivable_impls.rs:41:1 | LL | / impl std::default::Default for TupleDefault { LL | | fn default() -> Self { @@ -36,7 +37,7 @@ LL | struct TupleDefault(bool, i32, u64); | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:95:1 + --> $DIR/derivable_impls.rs:93:1 | LL | / impl Default for StrDefault<'_> { LL | | fn default() -> Self { @@ -53,7 +54,7 @@ LL | struct StrDefault<'a>(&'a str); | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:121:1 + --> $DIR/derivable_impls.rs:119:1 | LL | / impl Default for Y { LL | | fn default() -> Self { @@ -70,7 +71,7 @@ LL | struct Y(u32); | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:160:1 + --> $DIR/derivable_impls.rs:158:1 | LL | / impl Default for WithoutSelfCurly { LL | | fn default() -> Self { @@ -87,7 +88,7 @@ LL | struct WithoutSelfCurly { | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:168:1 + --> $DIR/derivable_impls.rs:166:1 | LL | / impl Default for WithoutSelfParan { LL | | fn default() -> Self { @@ -104,7 +105,7 @@ LL | struct WithoutSelfParan(bool); | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:218:1 + --> $DIR/derivable_impls.rs:216:1 | LL | / impl Default for RepeatDefault1 { LL | | fn default() -> Self { @@ -121,7 +122,7 @@ LL | pub struct RepeatDefault1 { | error: this `impl` can be derived - --> $DIR/derivable_impls.rs:252:1 + --> $DIR/derivable_impls.rs:250:1 | LL | / impl Default for SimpleEnum { LL | | fn default() -> Self { diff --git a/src/tools/clippy/tests/ui/derive.rs b/src/tools/clippy/tests/ui/derive.rs index c76711312..20ac8a6e6 100644 --- a/src/tools/clippy/tests/ui/derive.rs +++ b/src/tools/clippy/tests/ui/derive.rs @@ -1,8 +1,4 @@ -#![allow( - clippy::incorrect_clone_impl_on_copy_type, - clippy::incorrect_partial_ord_impl_on_ord_type, - dead_code -)] +#![allow(clippy::non_canonical_clone_impl, clippy::non_canonical_partial_ord_impl, dead_code)] #![warn(clippy::expl_impl_clone_on_copy)] @@ -10,6 +6,7 @@ struct Qux; impl Clone for Qux { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { Qux } @@ -34,6 +31,7 @@ struct Lt<'a> { } impl<'a> Clone for Lt<'a> { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { unimplemented!() } @@ -45,6 +43,7 @@ struct BigArray { } impl Clone for BigArray { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { unimplemented!() } @@ -56,6 +55,7 @@ struct FnPtr { } impl Clone for FnPtr { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { unimplemented!() } @@ -76,6 +76,7 @@ impl Clone for Generic { #[derive(Copy)] struct Generic2(T); impl Clone for Generic2 { + //~^ ERROR: you are implementing `Clone` explicitly on a `Copy` type fn clone(&self) -> Self { Self(self.0.clone()) } diff --git a/src/tools/clippy/tests/ui/derive.stderr b/src/tools/clippy/tests/ui/derive.stderr index 5d7ed0918..88942d954 100644 --- a/src/tools/clippy/tests/ui/derive.stderr +++ b/src/tools/clippy/tests/ui/derive.stderr @@ -1,7 +1,8 @@ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:12:1 + --> $DIR/derive.rs:8:1 | LL | / impl Clone for Qux { +LL | | LL | | fn clone(&self) -> Self { LL | | Qux LL | | } @@ -9,20 +10,23 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:12:1 + --> $DIR/derive.rs:8:1 | LL | / impl Clone for Qux { +LL | | LL | | fn clone(&self) -> Self { LL | | Qux LL | | } LL | | } | |_^ = note: `-D clippy::expl-impl-clone-on-copy` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::expl_impl_clone_on_copy)]` error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:36:1 + --> $DIR/derive.rs:33:1 | LL | / impl<'a> Clone for Lt<'a> { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -30,9 +34,10 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:36:1 + --> $DIR/derive.rs:33:1 | LL | / impl<'a> Clone for Lt<'a> { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -40,9 +45,10 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:47:1 + --> $DIR/derive.rs:45:1 | LL | / impl Clone for BigArray { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -50,9 +56,10 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:47:1 + --> $DIR/derive.rs:45:1 | LL | / impl Clone for BigArray { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -60,9 +67,10 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> $DIR/derive.rs:58:1 + --> $DIR/derive.rs:57:1 | LL | / impl Clone for FnPtr { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -70,9 +78,10 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> $DIR/derive.rs:58:1 + --> $DIR/derive.rs:57:1 | LL | / impl Clone for FnPtr { +LL | | LL | | fn clone(&self) -> Self { LL | | unimplemented!() LL | | } @@ -83,6 +92,7 @@ error: you are implementing `Clone` explicitly on a `Copy` type --> $DIR/derive.rs:78:1 | LL | / impl Clone for Generic2 { +LL | | LL | | fn clone(&self) -> Self { LL | | Self(self.0.clone()) LL | | } @@ -93,6 +103,7 @@ note: consider deriving `Clone` or removing `Copy` --> $DIR/derive.rs:78:1 | LL | / impl Clone for Generic2 { +LL | | LL | | fn clone(&self) -> Self { LL | | Self(self.0.clone()) LL | | } diff --git a/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.rs b/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.rs index 1fb3d51c4..1c7e6d1c2 100644 --- a/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.rs +++ b/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.rs @@ -1,6 +1,6 @@ #![warn(clippy::derive_ord_xor_partial_ord)] #![allow(clippy::unnecessary_wraps)] -#![allow(clippy::incorrect_partial_ord_impl_on_ord_type)] +#![allow(clippy::non_canonical_partial_ord_impl)] use std::cmp::Ordering; @@ -20,6 +20,7 @@ impl PartialOrd for DeriveBoth { } #[derive(Ord, PartialEq, Eq)] +//~^ ERROR: you are deriving `Ord` but have implemented `PartialOrd` explicitly struct DeriveOrd; impl PartialOrd for DeriveOrd { @@ -29,6 +30,7 @@ impl PartialOrd for DeriveOrd { } #[derive(Ord, PartialEq, Eq)] +//~^ ERROR: you are deriving `Ord` but have implemented `PartialOrd` explicitly struct DeriveOrdWithExplicitTypeVariable; impl PartialOrd for DeriveOrdWithExplicitTypeVariable { @@ -41,6 +43,7 @@ impl PartialOrd for DeriveOrdWithExplicitType struct DerivePartialOrd; impl std::cmp::Ord for DerivePartialOrd { + //~^ ERROR: you are implementing `Ord` explicitly but have derived `PartialOrd` fn cmp(&self, other: &Self) -> Ordering { Ordering::Less } @@ -61,6 +64,7 @@ mod use_ord { struct DerivePartialOrdInUseOrd; impl Ord for DerivePartialOrdInUseOrd { + //~^ ERROR: you are implementing `Ord` explicitly but have derived `PartialOrd` fn cmp(&self, other: &Self) -> Ordering { Ordering::Less } diff --git a/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr b/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr index bd1488348..7555c12b1 100644 --- a/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr +++ b/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr @@ -5,30 +5,32 @@ LL | #[derive(Ord, PartialEq, Eq)] | ^^^ | note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:25:1 + --> $DIR/derive_ord_xor_partial_ord.rs:26:1 | LL | impl PartialOrd for DeriveOrd { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::derive-ord-xor-partial-ord` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::derive_ord_xor_partial_ord)]` = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `Ord` but have implemented `PartialOrd` explicitly - --> $DIR/derive_ord_xor_partial_ord.rs:31:10 + --> $DIR/derive_ord_xor_partial_ord.rs:32:10 | LL | #[derive(Ord, PartialEq, Eq)] | ^^^ | note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:34:1 + --> $DIR/derive_ord_xor_partial_ord.rs:36:1 | LL | impl PartialOrd for DeriveOrdWithExplicitTypeVariable { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are implementing `Ord` explicitly but have derived `PartialOrd` - --> $DIR/derive_ord_xor_partial_ord.rs:43:1 + --> $DIR/derive_ord_xor_partial_ord.rs:45:1 | LL | / impl std::cmp::Ord for DerivePartialOrd { +LL | | LL | | fn cmp(&self, other: &Self) -> Ordering { LL | | Ordering::Less LL | | } @@ -36,16 +38,17 @@ LL | | } | |_^ | note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:40:10 + --> $DIR/derive_ord_xor_partial_ord.rs:42:10 | LL | #[derive(PartialOrd, PartialEq, Eq)] | ^^^^^^^^^^ = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are implementing `Ord` explicitly but have derived `PartialOrd` - --> $DIR/derive_ord_xor_partial_ord.rs:63:5 + --> $DIR/derive_ord_xor_partial_ord.rs:66:5 | LL | / impl Ord for DerivePartialOrdInUseOrd { +LL | | LL | | fn cmp(&self, other: &Self) -> Ordering { LL | | Ordering::Less LL | | } @@ -53,7 +56,7 @@ LL | | } | |_____^ | note: `PartialOrd` implemented here - --> $DIR/derive_ord_xor_partial_ord.rs:60:14 + --> $DIR/derive_ord_xor_partial_ord.rs:63:14 | LL | #[derive(PartialOrd, PartialEq, Eq)] | ^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.fixed b/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.fixed index a1f29430c..a7f5d3ec7 100644 --- a/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.fixed +++ b/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::derive_partial_eq_without_eq)] diff --git a/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.rs b/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.rs index ff4d88855..476d2aee2 100644 --- a/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.rs +++ b/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::derive_partial_eq_without_eq)] diff --git a/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.stderr b/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.stderr index 794c5dab8..abfd70e8c 100644 --- a/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.stderr +++ b/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.stderr @@ -1,67 +1,68 @@ error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:13:17 + --> $DIR/derive_partial_eq_without_eq.rs:11:17 | LL | #[derive(Debug, PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` | = note: `-D clippy::derive-partial-eq-without-eq` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::derive_partial_eq_without_eq)]` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:55:10 + --> $DIR/derive_partial_eq_without_eq.rs:53:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:61:10 + --> $DIR/derive_partial_eq_without_eq.rs:59:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:67:10 + --> $DIR/derive_partial_eq_without_eq.rs:65:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:70:10 + --> $DIR/derive_partial_eq_without_eq.rs:68:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:76:10 + --> $DIR/derive_partial_eq_without_eq.rs:74:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:82:10 + --> $DIR/derive_partial_eq_without_eq.rs:80:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:95:17 + --> $DIR/derive_partial_eq_without_eq.rs:93:17 | LL | #[derive(Debug, PartialEq, Clone)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:98:10 + --> $DIR/derive_partial_eq_without_eq.rs:96:10 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:105:14 + --> $DIR/derive_partial_eq_without_eq.rs:103:14 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` error: you are deriving `PartialEq` and can implement `Eq` - --> $DIR/derive_partial_eq_without_eq.rs:108:14 + --> $DIR/derive_partial_eq_without_eq.rs:106:14 | LL | #[derive(PartialEq)] | ^^^^^^^^^ help: consider deriving `Eq` as well: `PartialEq, Eq` diff --git a/src/tools/clippy/tests/ui/derived_hash_with_manual_eq.rs b/src/tools/clippy/tests/ui/derived_hash_with_manual_eq.rs index 8ad09a8de..8423699d9 100644 --- a/src/tools/clippy/tests/ui/derived_hash_with_manual_eq.rs +++ b/src/tools/clippy/tests/ui/derived_hash_with_manual_eq.rs @@ -10,6 +10,7 @@ impl PartialEq for Foo { } #[derive(Hash)] +//~^ ERROR: you are deriving `Hash` but have implemented `PartialEq` explicitly struct Bar; impl PartialEq for Bar { @@ -19,6 +20,7 @@ impl PartialEq for Bar { } #[derive(Hash)] +//~^ ERROR: you are deriving `Hash` but have implemented `PartialEq` explicitly struct Baz; impl PartialEq for Baz { diff --git a/src/tools/clippy/tests/ui/derived_hash_with_manual_eq.stderr b/src/tools/clippy/tests/ui/derived_hash_with_manual_eq.stderr index 230940f25..8ef08f9fa 100644 --- a/src/tools/clippy/tests/ui/derived_hash_with_manual_eq.stderr +++ b/src/tools/clippy/tests/ui/derived_hash_with_manual_eq.stderr @@ -5,7 +5,7 @@ LL | #[derive(Hash)] | ^^^^ | note: `PartialEq` implemented here - --> $DIR/derived_hash_with_manual_eq.rs:15:1 + --> $DIR/derived_hash_with_manual_eq.rs:16:1 | LL | impl PartialEq for Bar { | ^^^^^^^^^^^^^^^^^^^^^^ @@ -13,13 +13,13 @@ LL | impl PartialEq for Bar { = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `Hash` but have implemented `PartialEq` explicitly - --> $DIR/derived_hash_with_manual_eq.rs:21:10 + --> $DIR/derived_hash_with_manual_eq.rs:22:10 | LL | #[derive(Hash)] | ^^^^ | note: `PartialEq` implemented here - --> $DIR/derived_hash_with_manual_eq.rs:24:1 + --> $DIR/derived_hash_with_manual_eq.rs:26:1 | LL | impl PartialEq for Baz { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/disallowed_names.rs b/src/tools/clippy/tests/ui/disallowed_names.rs index 5889f0443..9a701a2cb 100644 --- a/src/tools/clippy/tests/ui/disallowed_names.rs +++ b/src/tools/clippy/tests/ui/disallowed_names.rs @@ -10,11 +10,16 @@ #![warn(clippy::disallowed_names)] fn test(foo: ()) {} +//~^ ERROR: use of a disallowed/placeholder name `foo` +//~| NOTE: `-D clippy::disallowed-names` implied by `-D warnings` fn main() { let foo = 42; + //~^ ERROR: use of a disallowed/placeholder name `foo` let baz = 42; + //~^ ERROR: use of a disallowed/placeholder name `baz` let quux = 42; + //~^ ERROR: use of a disallowed/placeholder name `quux` // Unlike these others, `bar` is actually considered an acceptable name. // Among many other legitimate uses, bar commonly refers to a period of time in music. // See https://github.com/rust-lang/rust-clippy/issues/5225. @@ -26,23 +31,33 @@ fn main() { match (42, Some(1337), Some(0)) { (foo, Some(baz), quux @ Some(_)) => (), + //~^ ERROR: use of a disallowed/placeholder name `foo` + //~| ERROR: use of a disallowed/placeholder name `baz` + //~| ERROR: use of a disallowed/placeholder name `quux` _ => (), } } fn issue_1647(mut foo: u8) { + //~^ ERROR: use of a disallowed/placeholder name `foo` let mut baz = 0; + //~^ ERROR: use of a disallowed/placeholder name `baz` if let Some(mut quux) = Some(42) {} + //~^ ERROR: use of a disallowed/placeholder name `quux` } fn issue_1647_ref() { let ref baz = 0; + //~^ ERROR: use of a disallowed/placeholder name `baz` if let Some(ref quux) = Some(42) {} + //~^ ERROR: use of a disallowed/placeholder name `quux` } fn issue_1647_ref_mut() { let ref mut baz = 0; + //~^ ERROR: use of a disallowed/placeholder name `baz` if let Some(ref mut quux) = Some(42) {} + //~^ ERROR: use of a disallowed/placeholder name `quux` } mod tests { diff --git a/src/tools/clippy/tests/ui/disallowed_names.stderr b/src/tools/clippy/tests/ui/disallowed_names.stderr index 9ab68b641..3387906a0 100644 --- a/src/tools/clippy/tests/ui/disallowed_names.stderr +++ b/src/tools/clippy/tests/ui/disallowed_names.stderr @@ -5,81 +5,82 @@ LL | fn test(foo: ()) {} | ^^^ | = note: `-D clippy::disallowed-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_names)]` error: use of a disallowed/placeholder name `foo` - --> $DIR/disallowed_names.rs:15:9 + --> $DIR/disallowed_names.rs:17:9 | LL | let foo = 42; | ^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:16:9 + --> $DIR/disallowed_names.rs:19:9 | LL | let baz = 42; | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:17:9 + --> $DIR/disallowed_names.rs:21:9 | LL | let quux = 42; | ^^^^ error: use of a disallowed/placeholder name `foo` - --> $DIR/disallowed_names.rs:28:10 + --> $DIR/disallowed_names.rs:33:10 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:28:20 + --> $DIR/disallowed_names.rs:33:20 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:28:26 + --> $DIR/disallowed_names.rs:33:26 | LL | (foo, Some(baz), quux @ Some(_)) => (), | ^^^^ error: use of a disallowed/placeholder name `foo` - --> $DIR/disallowed_names.rs:33:19 + --> $DIR/disallowed_names.rs:41:19 | LL | fn issue_1647(mut foo: u8) { | ^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:34:13 + --> $DIR/disallowed_names.rs:43:13 | LL | let mut baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:35:21 + --> $DIR/disallowed_names.rs:45:21 | LL | if let Some(mut quux) = Some(42) {} | ^^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:39:13 + --> $DIR/disallowed_names.rs:50:13 | LL | let ref baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:40:21 + --> $DIR/disallowed_names.rs:52:21 | LL | if let Some(ref quux) = Some(42) {} | ^^^^ error: use of a disallowed/placeholder name `baz` - --> $DIR/disallowed_names.rs:44:17 + --> $DIR/disallowed_names.rs:57:17 | LL | let ref mut baz = 0; | ^^^ error: use of a disallowed/placeholder name `quux` - --> $DIR/disallowed_names.rs:45:25 + --> $DIR/disallowed_names.rs:59:25 | LL | if let Some(ref mut quux) = Some(42) {} | ^^^^ diff --git a/src/tools/clippy/tests/ui/disallowed_script_idents.rs b/src/tools/clippy/tests/ui/disallowed_script_idents.rs index cfdda3597..6b68fae31 100644 --- a/src/tools/clippy/tests/ui/disallowed_script_idents.rs +++ b/src/tools/clippy/tests/ui/disallowed_script_idents.rs @@ -2,9 +2,15 @@ #![allow(dead_code)] fn main() { - let counter = 10; // OK, latin is allowed. - let zähler = 10; // OK, it's still latin. + // OK, latin is allowed. + let counter = 10; + // OK, it's still latin. + let zähler = 10; - let счётчик = 10; // Cyrillic is not allowed by default. - let カウンタ = 10; // Same for japanese. + // Cyrillic is not allowed by default. + let счётчик = 10; + //~^ ERROR: identifier `счётчик` has a Unicode script that is not allowed by configura + // Same for japanese. + let カウンタ = 10; + //~^ ERROR: identifier `カウンタ` has a Unicode script that is not allowed by configuratio } diff --git a/src/tools/clippy/tests/ui/disallowed_script_idents.stderr b/src/tools/clippy/tests/ui/disallowed_script_idents.stderr index cc84dc1d4..bf5cbe306 100644 --- a/src/tools/clippy/tests/ui/disallowed_script_idents.stderr +++ b/src/tools/clippy/tests/ui/disallowed_script_idents.stderr @@ -1,7 +1,7 @@ error: identifier `счётчик` has a Unicode script that is not allowed by configuration: Cyrillic - --> $DIR/disallowed_script_idents.rs:8:9 + --> $DIR/disallowed_script_idents.rs:11:9 | -LL | let счётчик = 10; // Cyrillic is not allowed by default. +LL | let счётчик = 10; | ^^^^^^^ | note: the lint level is defined here @@ -11,9 +11,9 @@ LL | #![deny(clippy::disallowed_script_idents)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: identifier `カウンタ` has a Unicode script that is not allowed by configuration: Katakana - --> $DIR/disallowed_script_idents.rs:9:9 + --> $DIR/disallowed_script_idents.rs:14:9 | -LL | let カウンタ = 10; // Same for japanese. +LL | let カウンタ = 10; | ^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/tools/clippy/tests/ui/diverging_sub_expression.rs b/src/tools/clippy/tests/ui/diverging_sub_expression.rs index 9b1619baf..e0acf0509 100644 --- a/src/tools/clippy/tests/ui/diverging_sub_expression.rs +++ b/src/tools/clippy/tests/ui/diverging_sub_expression.rs @@ -18,7 +18,10 @@ impl A { fn main() { let b = true; b || diverge(); + //~^ ERROR: sub-expression diverges + //~| NOTE: `-D clippy::diverging-sub-expression` implied by `-D warnings` b || A.foo(); + //~^ ERROR: sub-expression diverges } #[allow(dead_code, unused_variables)] @@ -29,20 +32,28 @@ fn foobar() { 4 => return, 5 => continue, 6 => true || return, + //~^ ERROR: sub-expression diverges 7 => true || continue, + //~^ ERROR: sub-expression diverges 8 => break, 9 => diverge(), 3 => true || diverge(), + //~^ ERROR: sub-expression diverges 10 => match 42 { 99 => return, _ => true || panic!("boo"), + //~^ ERROR: sub-expression diverges }, // lint blocks as well 15 => true || { return; }, + //~^ ERROR: sub-expression diverges 16 => false || { return; }, + //~^ ERROR: sub-expression diverges // ... and when it's a single expression 17 => true || { return }, + //~^ ERROR: sub-expression diverges 18 => false || { return }, + //~^ ERROR: sub-expression diverges // ... but not when there's both an expression and a statement 19 => true || { _ = 1; return }, 20 => false || { _ = 1; return }, @@ -52,6 +63,7 @@ fn foobar() { 23 => true || { return; true }, 24 => true || { return; true }, _ => true || break, + //~^ ERROR: sub-expression diverges }; } } diff --git a/src/tools/clippy/tests/ui/diverging_sub_expression.stderr b/src/tools/clippy/tests/ui/diverging_sub_expression.stderr index 243a5cf53..d8021c5d7 100644 --- a/src/tools/clippy/tests/ui/diverging_sub_expression.stderr +++ b/src/tools/clippy/tests/ui/diverging_sub_expression.stderr @@ -5,33 +5,34 @@ LL | b || diverge(); | ^^^^^^^^^ | = note: `-D clippy::diverging-sub-expression` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::diverging_sub_expression)]` error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:21:10 + --> $DIR/diverging_sub_expression.rs:23:10 | LL | b || A.foo(); | ^^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:31:26 + --> $DIR/diverging_sub_expression.rs:34:26 | LL | 6 => true || return, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:32:26 + --> $DIR/diverging_sub_expression.rs:36:26 | LL | 7 => true || continue, | ^^^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:35:26 + --> $DIR/diverging_sub_expression.rs:40:26 | LL | 3 => true || diverge(), | ^^^^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:38:30 + --> $DIR/diverging_sub_expression.rs:44:30 | LL | _ => true || panic!("boo"), | ^^^^^^^^^^^^^ @@ -39,31 +40,31 @@ LL | _ => true || panic!("boo"), = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:41:29 + --> $DIR/diverging_sub_expression.rs:48:29 | LL | 15 => true || { return; }, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:42:30 + --> $DIR/diverging_sub_expression.rs:50:30 | LL | 16 => false || { return; }, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:44:29 + --> $DIR/diverging_sub_expression.rs:53:29 | LL | 17 => true || { return }, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:45:30 + --> $DIR/diverging_sub_expression.rs:55:30 | LL | 18 => false || { return }, | ^^^^^^ error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:54:26 + --> $DIR/diverging_sub_expression.rs:65:26 | LL | _ => true || break, | ^^^^^ diff --git a/src/tools/clippy/tests/ui/doc/doc-fixable.fixed b/src/tools/clippy/tests/ui/doc/doc-fixable.fixed index 14444df4c..47b56960a 100644 --- a/src/tools/clippy/tests/ui/doc/doc-fixable.fixed +++ b/src/tools/clippy/tests/ui/doc/doc-fixable.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + //! This file tests for the `DOC_MARKDOWN` lint. #![allow(dead_code, incomplete_features)] @@ -198,6 +198,16 @@ fn pulldown_cmark_crash() {} /// [plain text][path::to::item] fn intra_doc_link() {} +/// Ignore escaped\_underscores +/// +/// \\[ +/// \\prod\_{x\\in X} p\_x +/// \\] +fn issue_2581() {} + +/// Foo \[bar\] \[baz\] \[qux\]. `DocMarkdownLint` +fn lint_after_escaped_chars() {} + // issue #7033 - generic_const_exprs ICE struct S where [(); N.checked_next_power_of_two().unwrap()]: { diff --git a/src/tools/clippy/tests/ui/doc/doc-fixable.rs b/src/tools/clippy/tests/ui/doc/doc-fixable.rs index 542d33b13..4d9a4eafa 100644 --- a/src/tools/clippy/tests/ui/doc/doc-fixable.rs +++ b/src/tools/clippy/tests/ui/doc/doc-fixable.rs @@ -1,4 +1,4 @@ -//@run-rustfix + //! This file tests for the `DOC_MARKDOWN` lint. #![allow(dead_code, incomplete_features)] @@ -198,6 +198,16 @@ fn pulldown_cmark_crash() {} /// [plain text][path::to::item] fn intra_doc_link() {} +/// Ignore escaped\_underscores +/// +/// \\[ +/// \\prod\_{x\\in X} p\_x +/// \\] +fn issue_2581() {} + +/// Foo \[bar\] \[baz\] \[qux\]. DocMarkdownLint +fn lint_after_escaped_chars() {} + // issue #7033 - generic_const_exprs ICE struct S where [(); N.checked_next_power_of_two().unwrap()]: { diff --git a/src/tools/clippy/tests/ui/doc/doc-fixable.stderr b/src/tools/clippy/tests/ui/doc/doc-fixable.stderr index 94ef43afc..4c9ff41d9 100644 --- a/src/tools/clippy/tests/ui/doc/doc-fixable.stderr +++ b/src/tools/clippy/tests/ui/doc/doc-fixable.stderr @@ -5,6 +5,7 @@ LL | /// The foo_bar function does _nothing_. See also foo::bar. (note the dot t | ^^^^^^^ | = note: `-D clippy::doc-markdown` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` help: try | LL | /// The `foo_bar` function does _nothing_. See also foo::bar. (note the dot there) @@ -24,12 +25,12 @@ LL | /// The foo_bar function does _nothing_. See also `foo::bar`. (note the dot error: item in documentation is missing backticks --> $DIR/doc-fixable.rs:10:83 | -LL | /// Markdown is _weird_. I mean _really weird_. This /_ is ok. So is `_`. But not Foo::some_fun +LL | /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not Foo::some_fun | ^^^^^^^^^^^^^ | help: try | -LL | /// Markdown is _weird_. I mean _really weird_. This /_ is ok. So is `_`. But not `Foo::some_fun` +LL | /// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not `Foo::some_fun` | ~~~~~~~~~~~~~~~ error: item in documentation is missing backticks @@ -307,5 +308,16 @@ help: try LL | /// An iterator over `mycrate::Collection`'s values. | ~~~~~~~~~~~~~~~~~~~~~ -error: aborting due to 28 previous errors +error: item in documentation is missing backticks + --> $DIR/doc-fixable.rs:208:34 + | +LL | /// Foo \[bar\] \[baz\] \[qux\]. DocMarkdownLint + | ^^^^^^^^^^^^^^^ + | +help: try + | +LL | /// Foo \[bar\] \[baz\] \[qux\]. `DocMarkdownLint` + | ~~~~~~~~~~~~~~~~~ + +error: aborting due to 29 previous errors diff --git a/src/tools/clippy/tests/ui/doc/unbalanced_ticks.rs b/src/tools/clippy/tests/ui/doc/unbalanced_ticks.rs index 8e8324b30..6f7bab720 100644 --- a/src/tools/clippy/tests/ui/doc/unbalanced_ticks.rs +++ b/src/tools/clippy/tests/ui/doc/unbalanced_ticks.rs @@ -1,20 +1,24 @@ //! This file tests for the `DOC_MARKDOWN` lint, specifically cases //! where ticks are unbalanced (see issue #6753). - +//@no-rustfix #![allow(dead_code)] #![warn(clippy::doc_markdown)] /// This is a doc comment with `unbalanced_tick marks and several words that +//~^ ERROR: backticks are unbalanced /// should be `encompassed_by` tick marks because they `contain_underscores`. /// Because of the initial `unbalanced_tick` pair, the error message is /// very `confusing_and_misleading`. fn main() {} /// This paragraph has `unbalanced_tick marks and should stop_linting. +//~^ ERROR: backticks are unbalanced /// /// This paragraph is fine and should_be linted normally. +//~^ ERROR: item in documentation is missing backticks /// /// Double unbalanced backtick from ``here to here` should lint. +//~^ ERROR: backticks are unbalanced /// /// Double balanced back ticks ``start end`` is fine. fn multiple_paragraphs() {} @@ -28,11 +32,15 @@ fn in_code_block() {} /// # `Fine` /// /// ## not_fine +//~^ ERROR: item in documentation is missing backticks /// /// ### `unbalanced +//~^ ERROR: backticks are unbalanced /// /// - This `item has unbalanced tick marks +//~^ ERROR: backticks are unbalanced /// - This item needs backticks_here +//~^ ERROR: item in documentation is missing backticks fn other_markdown() {} #[rustfmt::skip] @@ -40,4 +48,4 @@ fn other_markdown() {} /// /// `lol` /// pub struct Struct; /// ``` -fn iss_7421() {} +fn issue_7421() {} diff --git a/src/tools/clippy/tests/ui/doc/unbalanced_ticks.stderr b/src/tools/clippy/tests/ui/doc/unbalanced_ticks.stderr index f2ac6bc32..89ad8db39 100644 --- a/src/tools/clippy/tests/ui/doc/unbalanced_ticks.stderr +++ b/src/tools/clippy/tests/ui/doc/unbalanced_ticks.stderr @@ -1,7 +1,9 @@ error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:7:1 + --> $DIR/unbalanced_ticks.rs:7:5 | -LL | / /// This is a doc comment with `unbalanced_tick marks and several words that +LL | /// This is a doc comment with `unbalanced_tick marks and several words that + | _____^ +LL | | LL | | /// should be `encompassed_by` tick marks because they `contain_underscores`. LL | | /// Because of the initial `unbalanced_tick` pair, the error message is LL | | /// very `confusing_and_misleading`. @@ -9,17 +11,18 @@ LL | | /// very `confusing_and_misleading`. | = help: a backtick may be missing a pair = note: `-D clippy::doc-markdown` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]` error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:13:1 + --> $DIR/unbalanced_ticks.rs:14:5 | LL | /// This paragraph has `unbalanced_tick marks and should stop_linting. - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: a backtick may be missing a pair error: item in documentation is missing backticks - --> $DIR/unbalanced_ticks.rs:15:32 + --> $DIR/unbalanced_ticks.rs:17:32 | LL | /// This paragraph is fine and should_be linted normally. | ^^^^^^^^^ @@ -30,15 +33,15 @@ LL | /// This paragraph is fine and `should_be` linted normally. | ~~~~~~~~~~~ error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:17:1 + --> $DIR/unbalanced_ticks.rs:20:5 | LL | /// Double unbalanced backtick from ``here to here` should lint. - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: a backtick may be missing a pair error: item in documentation is missing backticks - --> $DIR/unbalanced_ticks.rs:30:8 + --> $DIR/unbalanced_ticks.rs:34:8 | LL | /// ## not_fine | ^^^^^^^^ @@ -49,23 +52,23 @@ LL | /// ## `not_fine` | ~~~~~~~~~~ error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:32:1 + --> $DIR/unbalanced_ticks.rs:37:5 | LL | /// ### `unbalanced - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ | = help: a backtick may be missing a pair error: backticks are unbalanced - --> $DIR/unbalanced_ticks.rs:34:1 + --> $DIR/unbalanced_ticks.rs:40:5 | LL | /// - This `item has unbalanced tick marks - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: a backtick may be missing a pair error: item in documentation is missing backticks - --> $DIR/unbalanced_ticks.rs:35:23 + --> $DIR/unbalanced_ticks.rs:42:23 | LL | /// - This item needs backticks_here | ^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/doc_errors.rs b/src/tools/clippy/tests/ui/doc_errors.rs index 30fdd3b08..9b3783aaf 100644 --- a/src/tools/clippy/tests/ui/doc_errors.rs +++ b/src/tools/clippy/tests/ui/doc_errors.rs @@ -5,20 +5,25 @@ use std::io; pub fn pub_fn_missing_errors_header() -> Result<(), ()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section + //~| NOTE: `-D clippy::missing-errors-doc` implied by `-D warnings` unimplemented!(); } pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } /// This is not sufficiently documented. pub fn pub_fn_returning_io_result() -> io::Result<()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } /// This is not sufficiently documented. pub async fn async_pub_fn_returning_io_result() -> io::Result<()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } @@ -49,11 +54,13 @@ pub struct Struct1; impl Struct1 { /// This is not sufficiently documented. pub fn pub_method_missing_errors_header() -> Result<(), ()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } /// This is not sufficiently documented. pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> { + //~^ ERROR: docs for function returning `Result` missing `# Errors` section unimplemented!(); } @@ -78,15 +85,42 @@ impl Struct1 { async fn async_priv_method_missing_errors_header() -> Result<(), ()> { unimplemented!(); } + + /** + # Errors + A description of the errors goes here. + */ + fn block_comment() -> Result<(), ()> { + unimplemented!(); + } + + /** + * # Errors + * A description of the errors goes here. + */ + fn block_comment_leading_asterisks() -> Result<(), ()> { + unimplemented!(); + } + + #[doc(hidden)] + fn doc_hidden() -> Result<(), ()> { + unimplemented!(); + } } pub trait Trait1 { /// This is not sufficiently documented. fn trait_method_missing_errors_header() -> Result<(), ()>; + //~^ ERROR: docs for function returning `Result` missing `# Errors` section /// # Errors /// A description of the errors goes here. fn trait_method_with_errors_header() -> Result<(), ()>; + + #[doc(hidden)] + fn doc_hidden() -> Result<(), ()> { + unimplemented!(); + } } impl Trait1 for Struct1 { @@ -99,6 +133,11 @@ impl Trait1 for Struct1 { } } +#[doc(hidden)] +pub trait DocHidden { + fn f() -> Result<(), ()>; +} + fn main() -> Result<(), ()> { Ok(()) } diff --git a/src/tools/clippy/tests/ui/doc_errors.stderr b/src/tools/clippy/tests/ui/doc_errors.stderr index d74f2dbfe..dc59675b9 100644 --- a/src/tools/clippy/tests/ui/doc_errors.stderr +++ b/src/tools/clippy/tests/ui/doc_errors.stderr @@ -5,39 +5,40 @@ LL | pub fn pub_fn_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::missing-errors-doc` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_errors_doc)]` error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:11:1 + --> $DIR/doc_errors.rs:13:1 | LL | pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:16:1 + --> $DIR/doc_errors.rs:19:1 | LL | pub fn pub_fn_returning_io_result() -> io::Result<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:21:1 + --> $DIR/doc_errors.rs:25:1 | LL | pub async fn async_pub_fn_returning_io_result() -> io::Result<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:51:5 + --> $DIR/doc_errors.rs:56:5 | LL | pub fn pub_method_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:56:5 + --> $DIR/doc_errors.rs:62:5 | LL | pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function returning `Result` missing `# Errors` section - --> $DIR/doc_errors.rs:85:5 + --> $DIR/doc_errors.rs:113:5 | LL | fn trait_method_missing_errors_header() -> Result<(), ()>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/doc_link_with_quotes.rs b/src/tools/clippy/tests/ui/doc_link_with_quotes.rs index 17c04c34e..37d0d1359 100644 --- a/src/tools/clippy/tests/ui/doc_link_with_quotes.rs +++ b/src/tools/clippy/tests/ui/doc_link_with_quotes.rs @@ -5,6 +5,8 @@ fn main() { } /// Calls ['bar'] uselessly +//~^ ERROR: possible intra-doc link using quotes instead of backticks +//~| NOTE: `-D clippy::doc-link-with-quotes` implied by `-D warnings` pub fn foo() { bar() } diff --git a/src/tools/clippy/tests/ui/doc_link_with_quotes.stderr b/src/tools/clippy/tests/ui/doc_link_with_quotes.stderr index ea730e667..2db1bc092 100644 --- a/src/tools/clippy/tests/ui/doc_link_with_quotes.stderr +++ b/src/tools/clippy/tests/ui/doc_link_with_quotes.stderr @@ -5,6 +5,7 @@ LL | /// Calls ['bar'] uselessly | ^^^^^ | = note: `-D clippy::doc-link-with-quotes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::doc_link_with_quotes)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/doc_unsafe.rs b/src/tools/clippy/tests/ui/doc_unsafe.rs index d21b046f1..0c8eac5cc 100644 --- a/src/tools/clippy/tests/ui/doc_unsafe.rs +++ b/src/tools/clippy/tests/ui/doc_unsafe.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::let_unit_value)] diff --git a/src/tools/clippy/tests/ui/doc_unsafe.stderr b/src/tools/clippy/tests/ui/doc_unsafe.stderr index a86e19137..ab3fb3c02 100644 --- a/src/tools/clippy/tests/ui/doc_unsafe.stderr +++ b/src/tools/clippy/tests/ui/doc_unsafe.stderr @@ -5,6 +5,7 @@ LL | pub unsafe fn destroy_the_planet() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::missing-safety-doc` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/double_comparison.fixed b/src/tools/clippy/tests/ui/double_comparison.fixed index f8ca92ef0..788f3224b 100644 --- a/src/tools/clippy/tests/ui/double_comparison.fixed +++ b/src/tools/clippy/tests/ui/double_comparison.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::needless_if)] fn main() { diff --git a/src/tools/clippy/tests/ui/double_comparison.rs b/src/tools/clippy/tests/ui/double_comparison.rs index 47ff87bea..245a83d57 100644 --- a/src/tools/clippy/tests/ui/double_comparison.rs +++ b/src/tools/clippy/tests/ui/double_comparison.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::needless_if)] fn main() { diff --git a/src/tools/clippy/tests/ui/double_comparison.stderr b/src/tools/clippy/tests/ui/double_comparison.stderr index 4df1c28ac..02f0a9609 100644 --- a/src/tools/clippy/tests/ui/double_comparison.stderr +++ b/src/tools/clippy/tests/ui/double_comparison.stderr @@ -1,49 +1,50 @@ error: this binary expression can be simplified - --> $DIR/double_comparison.rs:7:8 + --> $DIR/double_comparison.rs:6:8 | LL | if x == y || x < y { | ^^^^^^^^^^^^^^^ help: try: `x <= y` | = note: `-D clippy::double-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::double_comparisons)]` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:10:8 + --> $DIR/double_comparison.rs:9:8 | LL | if x < y || x == y { | ^^^^^^^^^^^^^^^ help: try: `x <= y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:13:8 + --> $DIR/double_comparison.rs:12:8 | LL | if x == y || x > y { | ^^^^^^^^^^^^^^^ help: try: `x >= y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:16: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:19:8 + --> $DIR/double_comparison.rs:18:8 | LL | if x < y || x > y { | ^^^^^^^^^^^^^^ help: try: `x != y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:22:8 + --> $DIR/double_comparison.rs:21:8 | LL | if x > y || x < y { | ^^^^^^^^^^^^^^ help: try: `x != y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:25:8 + --> $DIR/double_comparison.rs:24:8 | LL | if x <= y && x >= y { | ^^^^^^^^^^^^^^^^ help: try: `x == y` error: this binary expression can be simplified - --> $DIR/double_comparison.rs:28:8 + --> $DIR/double_comparison.rs:27:8 | LL | if x >= y && x <= y { | ^^^^^^^^^^^^^^^^ help: try: `x == y` diff --git a/src/tools/clippy/tests/ui/double_must_use.rs b/src/tools/clippy/tests/ui/double_must_use.rs index 26a387b3c..615de3e24 100644 --- a/src/tools/clippy/tests/ui/double_must_use.rs +++ b/src/tools/clippy/tests/ui/double_must_use.rs @@ -3,16 +3,19 @@ #[must_use] pub fn must_use_result() -> Result<(), ()> { + //~^ ERROR: this function has an empty `#[must_use]` attribute, but returns a type already unimplemented!(); } #[must_use] pub fn must_use_tuple() -> (Result<(), ()>, u8) { + //~^ ERROR: this function has an empty `#[must_use]` attribute, but returns a type already unimplemented!(); } #[must_use] pub fn must_use_array() -> [Result<(), ()>; 1] { + //~^ ERROR: this function has an empty `#[must_use]` attribute, but returns a type already unimplemented!(); } @@ -29,6 +32,7 @@ async fn async_must_use() -> usize { #[must_use] async fn async_must_use_result() -> Result<(), ()> { + //~^ ERROR: this function has an empty `#[must_use]` attribute, but returns a type already Ok(()) } diff --git a/src/tools/clippy/tests/ui/double_must_use.stderr b/src/tools/clippy/tests/ui/double_must_use.stderr index 49ab2ea3e..a2d87c59e 100644 --- a/src/tools/clippy/tests/ui/double_must_use.stderr +++ b/src/tools/clippy/tests/ui/double_must_use.stderr @@ -6,9 +6,10 @@ LL | pub fn must_use_result() -> Result<(), ()> { | = help: either add some descriptive text or remove the attribute = note: `-D clippy::double-must-use` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::double_must_use)]` error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` - --> $DIR/double_must_use.rs:10:1 + --> $DIR/double_must_use.rs:11:1 | LL | pub fn must_use_tuple() -> (Result<(), ()>, u8) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | pub fn must_use_tuple() -> (Result<(), ()>, u8) { = help: either add some descriptive text or remove the attribute error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` - --> $DIR/double_must_use.rs:15:1 + --> $DIR/double_must_use.rs:17:1 | LL | pub fn must_use_array() -> [Result<(), ()>; 1] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | pub fn must_use_array() -> [Result<(), ()>; 1] { = help: either add some descriptive text or remove the attribute error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` - --> $DIR/double_must_use.rs:31:1 + --> $DIR/double_must_use.rs:34:1 | LL | async fn async_must_use_result() -> Result<(), ()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/double_neg.rs b/src/tools/clippy/tests/ui/double_neg.rs index 38a8fbd74..da8289044 100644 --- a/src/tools/clippy/tests/ui/double_neg.rs +++ b/src/tools/clippy/tests/ui/double_neg.rs @@ -5,4 +5,6 @@ fn main() { -x; -(-x); --x; + //~^ ERROR: `--x` could be misinterpreted as pre-decrement by C programmers, is usuall + //~| NOTE: `-D clippy::double-neg` implied by `-D warnings` } diff --git a/src/tools/clippy/tests/ui/double_neg.stderr b/src/tools/clippy/tests/ui/double_neg.stderr index 7cdb040b6..a6241c786 100644 --- a/src/tools/clippy/tests/ui/double_neg.stderr +++ b/src/tools/clippy/tests/ui/double_neg.stderr @@ -5,6 +5,7 @@ LL | --x; | ^^^ | = note: `-D clippy::double-neg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::double_neg)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/double_parens.rs b/src/tools/clippy/tests/ui/double_parens.rs index ff1dc76ab..ab1459eed 100644 --- a/src/tools/clippy/tests/ui/double_parens.rs +++ b/src/tools/clippy/tests/ui/double_parens.rs @@ -13,22 +13,28 @@ impl DummyStruct { fn simple_double_parens() -> i32 { ((0)) + //~^ ERROR: consider removing unnecessary double parentheses + //~| NOTE: `-D clippy::double-parens` implied by `-D warnings` } fn fn_double_parens() { dummy_fn((0)); + //~^ ERROR: consider removing unnecessary double parentheses } fn method_double_parens(x: DummyStruct) { x.dummy_method((0)); + //~^ ERROR: consider removing unnecessary double parentheses } fn tuple_double_parens() -> (i32, i32) { ((1, 2)) + //~^ ERROR: consider removing unnecessary double parentheses } fn unit_double_parens() { (()) + //~^ ERROR: consider removing unnecessary double parentheses } fn fn_tuple_ok() { @@ -51,6 +57,7 @@ fn method_unit_ok(x: DummyStruct) { fn inside_macro() { assert_eq!((1, 2), (1, 2), "Error"); assert_eq!(((1, 2)), (1, 2), "Error"); + //~^ ERROR: consider removing unnecessary double parentheses } fn main() {} diff --git a/src/tools/clippy/tests/ui/double_parens.stderr b/src/tools/clippy/tests/ui/double_parens.stderr index 40fcad2ab..8a010d8cc 100644 --- a/src/tools/clippy/tests/ui/double_parens.stderr +++ b/src/tools/clippy/tests/ui/double_parens.stderr @@ -5,33 +5,34 @@ LL | ((0)) | ^^^^^ | = note: `-D clippy::double-parens` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::double_parens)]` error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:19:14 + --> $DIR/double_parens.rs:21:14 | LL | dummy_fn((0)); | ^^^ error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:23:20 + --> $DIR/double_parens.rs:26:20 | LL | x.dummy_method((0)); | ^^^ error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:27:5 + --> $DIR/double_parens.rs:31:5 | LL | ((1, 2)) | ^^^^^^^^ error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:31:5 + --> $DIR/double_parens.rs:36:5 | LL | (()) | ^^^^ error: consider removing unnecessary double parentheses - --> $DIR/double_parens.rs:53:16 + --> $DIR/double_parens.rs:59:16 | LL | assert_eq!(((1, 2)), (1, 2), "Error"); | ^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/drain_collect.fixed b/src/tools/clippy/tests/ui/drain_collect.fixed index 11001bd31..6f597243f 100644 --- a/src/tools/clippy/tests/ui/drain_collect.fixed +++ b/src/tools/clippy/tests/ui/drain_collect.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::drain_collect)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/drain_collect.rs b/src/tools/clippy/tests/ui/drain_collect.rs index 373a3ca35..353aac4da 100644 --- a/src/tools/clippy/tests/ui/drain_collect.rs +++ b/src/tools/clippy/tests/ui/drain_collect.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::drain_collect)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/drain_collect.stderr b/src/tools/clippy/tests/ui/drain_collect.stderr index 0792f0254..3364466ec 100644 --- a/src/tools/clippy/tests/ui/drain_collect.stderr +++ b/src/tools/clippy/tests/ui/drain_collect.stderr @@ -1,65 +1,65 @@ error: you seem to be trying to move all elements into a new `BinaryHeap` - --> $DIR/drain_collect.rs:9:5 + --> $DIR/drain_collect.rs:7:5 | LL | b.drain().collect() | ^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` | note: the lint level is defined here - --> $DIR/drain_collect.rs:3:9 + --> $DIR/drain_collect.rs:1:9 | LL | #![deny(clippy::drain_collect)] | ^^^^^^^^^^^^^^^^^^^^^ error: you seem to be trying to move all elements into a new `HashMap` - --> $DIR/drain_collect.rs:17:5 + --> $DIR/drain_collect.rs:15:5 | LL | b.drain().collect() | ^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` error: you seem to be trying to move all elements into a new `HashSet` - --> $DIR/drain_collect.rs:25:5 + --> $DIR/drain_collect.rs:23:5 | LL | b.drain().collect() | ^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` error: you seem to be trying to move all elements into a new `Vec` - --> $DIR/drain_collect.rs:33:5 + --> $DIR/drain_collect.rs:31:5 | LL | b.drain(..).collect() | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` error: you seem to be trying to move all elements into a new `Vec` - --> $DIR/drain_collect.rs:41:5 + --> $DIR/drain_collect.rs:39:5 | LL | b.drain(..).collect() | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` error: you seem to be trying to move all elements into a new `Vec` - --> $DIR/drain_collect.rs:45:5 + --> $DIR/drain_collect.rs:43:5 | LL | b.drain(0..).collect() | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` error: you seem to be trying to move all elements into a new `Vec` - --> $DIR/drain_collect.rs:49:5 + --> $DIR/drain_collect.rs:47:5 | LL | b.drain(..b.len()).collect() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` error: you seem to be trying to move all elements into a new `Vec` - --> $DIR/drain_collect.rs:53:5 + --> $DIR/drain_collect.rs:51:5 | LL | b.drain(0..b.len()).collect() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` error: you seem to be trying to move all elements into a new `Vec` - --> $DIR/drain_collect.rs:58:5 + --> $DIR/drain_collect.rs:56:5 | LL | b.drain(..).collect() | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(&mut b)` error: you seem to be trying to move all elements into a new `String` - --> $DIR/drain_collect.rs:66:5 + --> $DIR/drain_collect.rs:64:5 | LL | b.drain(..).collect() | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)` diff --git a/src/tools/clippy/tests/ui/drop_non_drop.rs b/src/tools/clippy/tests/ui/drop_non_drop.rs index 5a0ebde82..6dbcb7777 100644 --- a/src/tools/clippy/tests/ui/drop_non_drop.rs +++ b/src/tools/clippy/tests/ui/drop_non_drop.rs @@ -20,6 +20,7 @@ fn main() { struct Foo; // Lint drop(Foo); + //~^ ERROR: call to `std::mem::drop` with a value that does not implement `Drop`. Drop // Don't lint drop(make_result(Foo)); // Don't lint @@ -35,6 +36,7 @@ fn main() { struct Baz(T); // Lint drop(Baz(Foo)); + //~^ ERROR: call to `std::mem::drop` with a value that does not implement `Drop`. Drop // Don't lint drop(Baz(Bar)); } diff --git a/src/tools/clippy/tests/ui/drop_non_drop.stderr b/src/tools/clippy/tests/ui/drop_non_drop.stderr index b86057c0c..a571076f6 100644 --- a/src/tools/clippy/tests/ui/drop_non_drop.stderr +++ b/src/tools/clippy/tests/ui/drop_non_drop.stderr @@ -10,15 +10,16 @@ note: argument has type `main::Foo` LL | drop(Foo); | ^^^ = note: `-D clippy::drop-non-drop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::drop_non_drop)]` error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes - --> $DIR/drop_non_drop.rs:37:5 + --> $DIR/drop_non_drop.rs:38:5 | LL | drop(Baz(Foo)); | ^^^^^^^^^^^^^^ | note: argument has type `main::Baz` - --> $DIR/drop_non_drop.rs:37:10 + --> $DIR/drop_non_drop.rs:38:10 | LL | drop(Baz(Foo)); | ^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/duplicate_underscore_argument.rs b/src/tools/clippy/tests/ui/duplicate_underscore_argument.rs index 54d748c7c..118f6e4a3 100644 --- a/src/tools/clippy/tests/ui/duplicate_underscore_argument.rs +++ b/src/tools/clippy/tests/ui/duplicate_underscore_argument.rs @@ -2,6 +2,8 @@ #[allow(dead_code, unused)] fn join_the_dark_side(darth: i32, _darth: i32) {} +//~^ ERROR: `darth` already exists, having another argument having almost the same name ma +//~| NOTE: `-D clippy::duplicate-underscore-argument` implied by `-D warnings` fn join_the_light_side(knight: i32, _master: i32) {} // the Force is strong with this one fn main() { diff --git a/src/tools/clippy/tests/ui/duplicate_underscore_argument.stderr b/src/tools/clippy/tests/ui/duplicate_underscore_argument.stderr index f71614a5f..f47f6c896 100644 --- a/src/tools/clippy/tests/ui/duplicate_underscore_argument.stderr +++ b/src/tools/clippy/tests/ui/duplicate_underscore_argument.stderr @@ -5,6 +5,7 @@ LL | fn join_the_dark_side(darth: i32, _darth: i32) {} | ^^^^^ | = note: `-D clippy::duplicate-underscore-argument` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::duplicate_underscore_argument)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/duration_subsec.fixed b/src/tools/clippy/tests/ui/duration_subsec.fixed index bfd30f004..114c516ed 100644 --- a/src/tools/clippy/tests/ui/duration_subsec.fixed +++ b/src/tools/clippy/tests/ui/duration_subsec.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::needless_borrow)] #![warn(clippy::duration_subsec)] diff --git a/src/tools/clippy/tests/ui/duration_subsec.rs b/src/tools/clippy/tests/ui/duration_subsec.rs index 860233f08..8469fe086 100644 --- a/src/tools/clippy/tests/ui/duration_subsec.rs +++ b/src/tools/clippy/tests/ui/duration_subsec.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::needless_borrow)] #![warn(clippy::duration_subsec)] diff --git a/src/tools/clippy/tests/ui/duration_subsec.stderr b/src/tools/clippy/tests/ui/duration_subsec.stderr index cdbeff6a0..705683837 100644 --- a/src/tools/clippy/tests/ui/duration_subsec.stderr +++ b/src/tools/clippy/tests/ui/duration_subsec.stderr @@ -1,31 +1,32 @@ error: calling `subsec_millis()` is more concise than this calculation - --> $DIR/duration_subsec.rs:10:24 + --> $DIR/duration_subsec.rs:9:24 | LL | let bad_millis_1 = dur.subsec_micros() / 1_000; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_millis()` | = note: `-D clippy::duration-subsec` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::duration_subsec)]` error: calling `subsec_millis()` is more concise than this calculation - --> $DIR/duration_subsec.rs:11:24 + --> $DIR/duration_subsec.rs:10: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:16:22 + --> $DIR/duration_subsec.rs:15: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:21:13 + --> $DIR/duration_subsec.rs:20: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:25:13 + --> $DIR/duration_subsec.rs:24:13 | LL | let _ = dur.subsec_nanos() / NANOS_IN_MICRO; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `dur.subsec_micros()` diff --git a/src/tools/clippy/tests/ui/else_if_without_else.stderr b/src/tools/clippy/tests/ui/else_if_without_else.stderr index 11baf7544..b2bf4ac4d 100644 --- a/src/tools/clippy/tests/ui/else_if_without_else.stderr +++ b/src/tools/clippy/tests/ui/else_if_without_else.stderr @@ -10,6 +10,7 @@ LL | | } | = help: add an `else` block here = note: `-D clippy::else-if-without-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::else_if_without_else)]` error: `if` expression with an `else if`, but without a final `else` --> $DIR/else_if_without_else.rs:54:12 diff --git a/src/tools/clippy/tests/ui/empty_drop.fixed b/src/tools/clippy/tests/ui/empty_drop.fixed index fd0a9a708..949d0d8b3 100644 --- a/src/tools/clippy/tests/ui/empty_drop.fixed +++ b/src/tools/clippy/tests/ui/empty_drop.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::empty_drop)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/empty_drop.rs b/src/tools/clippy/tests/ui/empty_drop.rs index 6c15cb933..74822ea50 100644 --- a/src/tools/clippy/tests/ui/empty_drop.rs +++ b/src/tools/clippy/tests/ui/empty_drop.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::empty_drop)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/empty_drop.stderr b/src/tools/clippy/tests/ui/empty_drop.stderr index 70f7880d0..5848eab74 100644 --- a/src/tools/clippy/tests/ui/empty_drop.stderr +++ b/src/tools/clippy/tests/ui/empty_drop.stderr @@ -1,5 +1,5 @@ error: empty drop implementation - --> $DIR/empty_drop.rs:8:1 + --> $DIR/empty_drop.rs:7:1 | LL | / impl Drop for Foo { LL | | fn drop(&mut self) {} @@ -7,9 +7,10 @@ LL | | } | |_^ help: try removing this impl | = note: `-D clippy::empty-drop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_drop)]` error: empty drop implementation - --> $DIR/empty_drop.rs:24:1 + --> $DIR/empty_drop.rs:23:1 | LL | / impl Drop for Baz { LL | | fn drop(&mut self) { diff --git a/src/tools/clippy/tests/ui/empty_enum.rs b/src/tools/clippy/tests/ui/empty_enum.rs index a2e5c13c4..77357c15d 100644 --- a/src/tools/clippy/tests/ui/empty_enum.rs +++ b/src/tools/clippy/tests/ui/empty_enum.rs @@ -3,5 +3,6 @@ // Enable never type to test empty enum lint #![feature(never_type)] enum Empty {} +//~^ ERROR: enum with no variants fn main() {} diff --git a/src/tools/clippy/tests/ui/empty_enum.stderr b/src/tools/clippy/tests/ui/empty_enum.stderr index 0d9aa5818..92d81c726 100644 --- a/src/tools/clippy/tests/ui/empty_enum.stderr +++ b/src/tools/clippy/tests/ui/empty_enum.stderr @@ -6,6 +6,7 @@ LL | enum Empty {} | = help: consider using the uninhabited type `!` (never type) or a wrapper around it to introduce a type which can't be instantiated = note: `-D clippy::empty-enum` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_enum)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/empty_line_after_doc_comments.rs b/src/tools/clippy/tests/ui/empty_line_after_doc_comments.rs index cc36ce5f4..e843770f5 100644 --- a/src/tools/clippy/tests/ui/empty_line_after_doc_comments.rs +++ b/src/tools/clippy/tests/ui/empty_line_after_doc_comments.rs @@ -1,7 +1,4 @@ -//@aux-build:proc_macro_attr.rs:proc-macro -// Flaky test, see https://github.com/rust-lang/rust/issues/113585. -//@ignore-32bit -//@ignore-64bit +//@aux-build:proc_macro_attr.rs #![warn(clippy::empty_line_after_doc_comments)] #![allow(clippy::assertions_on_constants)] #![feature(custom_inner_attributes)] diff --git a/src/tools/clippy/tests/ui/empty_line_after_doc_comments.stderr b/src/tools/clippy/tests/ui/empty_line_after_doc_comments.stderr index 2ca1b5167..2cf5b5b0f 100644 --- a/src/tools/clippy/tests/ui/empty_line_after_doc_comments.stderr +++ b/src/tools/clippy/tests/ui/empty_line_after_doc_comments.stderr @@ -7,6 +7,7 @@ LL | | fn with_doc_and_newline() { assert!(true)} | |_ | = note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs b/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs index bc54e0fd2..269e66ea0 100644 --- a/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs +++ b/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs @@ -1,7 +1,4 @@ -//@aux-build:proc_macro_attr.rs:proc-macro -// Flaky test, see https://github.com/rust-lang/rust/issues/113585. -//@ignore-32bit -//@ignore-64bit +//@aux-build:proc_macro_attr.rs #![warn(clippy::empty_line_after_outer_attr)] #![allow(clippy::assertions_on_constants)] #![feature(custom_inner_attributes)] diff --git a/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.stderr b/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.stderr index 594fca44a..0cb848c20 100644 --- a/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.stderr +++ b/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.stderr @@ -8,6 +8,7 @@ LL | | fn with_one_newline_and_comment() { assert!(true) } | |_ | = note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/empty_loop.rs b/src/tools/clippy/tests/ui/empty_loop.rs index f1a55415c..be3475631 100644 --- a/src/tools/clippy/tests/ui/empty_loop.rs +++ b/src/tools/clippy/tests/ui/empty_loop.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::empty_loop)] @@ -7,10 +7,12 @@ use proc_macros::{external, inline_macros}; fn should_trigger() { loop {} + #[allow(clippy::never_loop)] loop { loop {} } + #[allow(clippy::never_loop)] 'outer: loop { 'inner: loop {} } @@ -18,6 +20,7 @@ fn should_trigger() { #[inline_macros] fn should_not_trigger() { + #[allow(clippy::never_loop)] loop { panic!("This is fine") } diff --git a/src/tools/clippy/tests/ui/empty_loop.stderr b/src/tools/clippy/tests/ui/empty_loop.stderr index 760241233..113556f67 100644 --- a/src/tools/clippy/tests/ui/empty_loop.stderr +++ b/src/tools/clippy/tests/ui/empty_loop.stderr @@ -6,9 +6,10 @@ LL | loop {} | = help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body = note: `-D clippy::empty-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_loop)]` error: empty `loop {}` wastes CPU cycles - --> $DIR/empty_loop.rs:11:9 + --> $DIR/empty_loop.rs:12:9 | LL | loop {} | ^^^^^^^ @@ -16,7 +17,7 @@ LL | loop {} = help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body error: empty `loop {}` wastes CPU cycles - --> $DIR/empty_loop.rs:15:9 + --> $DIR/empty_loop.rs:17:9 | LL | 'inner: loop {} | ^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/empty_loop_no_std.rs b/src/tools/clippy/tests/ui/empty_loop_no_std.rs index f9ab443df..5fe32351e 100644 --- a/src/tools/clippy/tests/ui/empty_loop_no_std.rs +++ b/src/tools/clippy/tests/ui/empty_loop_no_std.rs @@ -11,6 +11,7 @@ use core::panic::PanicInfo; fn main(argc: isize, argv: *const *const u8) -> isize { // This should trigger the lint loop {} + //~^ ERROR: empty `loop {}` wastes CPU cycles } #[panic_handler] @@ -23,4 +24,5 @@ fn panic(_info: &PanicInfo) -> ! { extern "C" fn eh_personality() { // This should also trigger the lint loop {} + //~^ ERROR: empty `loop {}` wastes CPU cycles } diff --git a/src/tools/clippy/tests/ui/empty_loop_no_std.stderr b/src/tools/clippy/tests/ui/empty_loop_no_std.stderr index 71af64f49..902008264 100644 --- a/src/tools/clippy/tests/ui/empty_loop_no_std.stderr +++ b/src/tools/clippy/tests/ui/empty_loop_no_std.stderr @@ -6,9 +6,10 @@ LL | loop {} | = help: you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body = note: `-D clippy::empty-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_loop)]` error: empty `loop {}` wastes CPU cycles - --> $DIR/empty_loop_no_std.rs:25:5 + --> $DIR/empty_loop_no_std.rs:26:5 | LL | loop {} | ^^^^^^^ diff --git a/src/tools/clippy/tests/ui/empty_structs_with_brackets.fixed b/src/tools/clippy/tests/ui/empty_structs_with_brackets.fixed index 6fab30208..80572645f 100644 --- a/src/tools/clippy/tests/ui/empty_structs_with_brackets.fixed +++ b/src/tools/clippy/tests/ui/empty_structs_with_brackets.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::empty_structs_with_brackets)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/empty_structs_with_brackets.rs b/src/tools/clippy/tests/ui/empty_structs_with_brackets.rs index 0caa3c49c..8fb3e247a 100644 --- a/src/tools/clippy/tests/ui/empty_structs_with_brackets.rs +++ b/src/tools/clippy/tests/ui/empty_structs_with_brackets.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::empty_structs_with_brackets)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/empty_structs_with_brackets.stderr b/src/tools/clippy/tests/ui/empty_structs_with_brackets.stderr index 0308cb557..4b8572d5c 100644 --- a/src/tools/clippy/tests/ui/empty_structs_with_brackets.stderr +++ b/src/tools/clippy/tests/ui/empty_structs_with_brackets.stderr @@ -1,14 +1,15 @@ error: found empty brackets on struct declaration - --> $DIR/empty_structs_with_brackets.rs:5:25 + --> $DIR/empty_structs_with_brackets.rs:4:25 | LL | pub struct MyEmptyStruct {} // should trigger lint | ^^^ | = note: `-D clippy::empty-structs-with-brackets` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::empty_structs_with_brackets)]` = help: remove the brackets error: found empty brackets on struct declaration - --> $DIR/empty_structs_with_brackets.rs:6:26 + --> $DIR/empty_structs_with_brackets.rs:5:26 | LL | struct MyEmptyTupleStruct(); // should trigger lint | ^^^ diff --git a/src/tools/clippy/tests/ui/endian_bytes.stderr b/src/tools/clippy/tests/ui/endian_bytes.stderr index 5e64ea5b5..a458c46fa 100644 --- a/src/tools/clippy/tests/ui/endian_bytes.stderr +++ b/src/tools/clippy/tests/ui/endian_bytes.stderr @@ -9,6 +9,7 @@ LL | fn host() { fn_body!(); } | = help: specify the desired endianness explicitly = note: `-D clippy::host-endian-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::host_endian_bytes)]` = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i8::to_ne_bytes` method @@ -346,6 +347,7 @@ LL | fn little() { fn_body!(); } | = help: use the native endianness instead = note: `-D clippy::little-endian-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::little_endian_bytes)]` = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) error: usage of the `i8::to_le_bytes` method @@ -707,6 +709,7 @@ LL | fn host_encourage_little() { fn_body_smol!(); } | = help: use `u8::to_le_bytes` instead = note: `-D clippy::big-endian-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::big_endian_bytes)]` = 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` diff --git a/src/tools/clippy/tests/ui/entry.fixed b/src/tools/clippy/tests/ui/entry.fixed index 7e8239060..4099fe7e1 100644 --- a/src/tools/clippy/tests/ui/entry.fixed +++ b/src/tools/clippy/tests/ui/entry.fixed @@ -1,5 +1,4 @@ //@needs-asm-support -//@run-rustfix #![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)] #![warn(clippy::map_entry)] diff --git a/src/tools/clippy/tests/ui/entry.rs b/src/tools/clippy/tests/ui/entry.rs index 742c93225..409be0aa0 100644 --- a/src/tools/clippy/tests/ui/entry.rs +++ b/src/tools/clippy/tests/ui/entry.rs @@ -1,5 +1,4 @@ //@needs-asm-support -//@run-rustfix #![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)] #![warn(clippy::map_entry)] diff --git a/src/tools/clippy/tests/ui/entry.stderr b/src/tools/clippy/tests/ui/entry.stderr index e8a003e9c..b01f0a9a0 100644 --- a/src/tools/clippy/tests/ui/entry.stderr +++ b/src/tools/clippy/tests/ui/entry.stderr @@ -1,5 +1,5 @@ error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:25:5 + --> $DIR/entry.rs:24:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); @@ -7,9 +7,10 @@ LL | | } | |_____^ help: try: `m.entry(k).or_insert(v);` | = note: `-D clippy::map-entry` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_entry)]` error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:30:5 + --> $DIR/entry.rs:29:5 | LL | / if !m.contains_key(&k) { LL | | if true { @@ -32,7 +33,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:39:5 + --> $DIR/entry.rs:38:5 | LL | / if !m.contains_key(&k) { LL | | if true { @@ -55,7 +56,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:48:5 + --> $DIR/entry.rs:47:5 | LL | / if !m.contains_key(&k) { LL | | if true { @@ -79,7 +80,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:58:5 + --> $DIR/entry.rs:57:5 | LL | / if !m.contains_key(&k) { LL | | foo(); @@ -96,7 +97,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:64:5 + --> $DIR/entry.rs:63:5 | LL | / if !m.contains_key(&k) { LL | | match 0 { @@ -122,7 +123,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:76:5 + --> $DIR/entry.rs:75:5 | LL | / if !m.contains_key(&k) { LL | | match 0 { @@ -146,7 +147,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:86:5 + --> $DIR/entry.rs:85:5 | LL | / if !m.contains_key(&k) { LL | | foo(); @@ -187,7 +188,7 @@ LL + }); | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry.rs:120:5 + --> $DIR/entry.rs:119:5 | LL | / if !m.contains_key(&m!(k)) { LL | | m.insert(m!(k), m!(v)); @@ -195,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:152:5 + --> $DIR/entry.rs:151:5 | LL | / if !m.contains_key(&k) { LL | | let x = (String::new(), String::new()); diff --git a/src/tools/clippy/tests/ui/entry_btree.fixed b/src/tools/clippy/tests/ui/entry_btree.fixed index 3baaacffd..228212c79 100644 --- a/src/tools/clippy/tests/ui/entry_btree.fixed +++ b/src/tools/clippy/tests/ui/entry_btree.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::map_entry)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/entry_btree.rs b/src/tools/clippy/tests/ui/entry_btree.rs index 770e8e91d..44703c567 100644 --- a/src/tools/clippy/tests/ui/entry_btree.rs +++ b/src/tools/clippy/tests/ui/entry_btree.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::map_entry)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/entry_btree.stderr b/src/tools/clippy/tests/ui/entry_btree.stderr index 8f41581d6..cc0e951d9 100644 --- a/src/tools/clippy/tests/ui/entry_btree.stderr +++ b/src/tools/clippy/tests/ui/entry_btree.stderr @@ -1,5 +1,5 @@ error: usage of `contains_key` followed by `insert` on a `BTreeMap` - --> $DIR/entry_btree.rs:12:5 + --> $DIR/entry_btree.rs:10:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); @@ -8,6 +8,7 @@ LL | | } | |_____^ | = note: `-D clippy::map-entry` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_entry)]` help: try | LL ~ if let std::collections::btree_map::Entry::Vacant(e) = m.entry(k) { diff --git a/src/tools/clippy/tests/ui/entry_with_else.fixed b/src/tools/clippy/tests/ui/entry_with_else.fixed index 71fe04fd6..34804b9ee 100644 --- a/src/tools/clippy/tests/ui/entry_with_else.fixed +++ b/src/tools/clippy/tests/ui/entry_with_else.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)] #![warn(clippy::map_entry)] diff --git a/src/tools/clippy/tests/ui/entry_with_else.rs b/src/tools/clippy/tests/ui/entry_with_else.rs index 80f74649a..0515748fd 100644 --- a/src/tools/clippy/tests/ui/entry_with_else.rs +++ b/src/tools/clippy/tests/ui/entry_with_else.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)] #![warn(clippy::map_entry)] diff --git a/src/tools/clippy/tests/ui/entry_with_else.stderr b/src/tools/clippy/tests/ui/entry_with_else.stderr index 0d0eb9649..425e87122 100644 --- a/src/tools/clippy/tests/ui/entry_with_else.stderr +++ b/src/tools/clippy/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:16:5 + --> $DIR/entry_with_else.rs:14:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); @@ -9,6 +9,7 @@ LL | | } | |_____^ | = note: `-D clippy::map-entry` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_entry)]` help: try | LL ~ match m.entry(k) { @@ -22,7 +23,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:22:5 + --> $DIR/entry_with_else.rs:20:5 | LL | / if m.contains_key(&k) { LL | | m.insert(k, v); @@ -44,7 +45,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:28:5 + --> $DIR/entry_with_else.rs:26:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); @@ -63,7 +64,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:34:5 + --> $DIR/entry_with_else.rs:32:5 | LL | / if !m.contains_key(&k) { LL | | foo(); @@ -82,7 +83,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:40:5 + --> $DIR/entry_with_else.rs:38:5 | LL | / if !m.contains_key(&k) { LL | | m.insert(k, v); @@ -104,7 +105,7 @@ LL + } | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:46:5 + --> $DIR/entry_with_else.rs:44:5 | LL | / if m.contains_key(&k) { LL | | if true { m.insert(k, v) } else { m.insert(k, v2) } @@ -127,7 +128,7 @@ LL ~ }; | error: usage of `contains_key` followed by `insert` on a `HashMap` - --> $DIR/entry_with_else.rs:52:5 + --> $DIR/entry_with_else.rs:50:5 | LL | / if m.contains_key(&k) { LL | | foo(); diff --git a/src/tools/clippy/tests/ui/enum_clike_unportable_variant.rs b/src/tools/clippy/tests/ui/enum_clike_unportable_variant.rs index abe42a230..c50404c50 100644 --- a/src/tools/clippy/tests/ui/enum_clike_unportable_variant.rs +++ b/src/tools/clippy/tests/ui/enum_clike_unportable_variant.rs @@ -1,4 +1,4 @@ -//@ignore-target-x86 +//@ignore-32bit #![warn(clippy::enum_clike_unportable_variant)] #![allow(unused, non_upper_case_globals)] @@ -6,6 +6,8 @@ #[repr(usize)] enum NonPortable { X = 0x1_0000_0000, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets + //~| NOTE: `-D clippy::enum-clike-unportable-variant` implied by `-D warnings` Y = 0, Z = 0x7FFF_FFFF, A = 0xFFFF_FFFF, @@ -13,9 +15,11 @@ enum NonPortable { enum NonPortableNoHint { X = 0x1_0000_0000, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets Y = 0, Z = 0x7FFF_FFFF, A = 0xFFFF_FFFF, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets } #[repr(isize)] @@ -23,21 +27,27 @@ enum NonPortableSigned { X = -1, Y = 0x7FFF_FFFF, Z = 0xFFFF_FFFF, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets A = 0x1_0000_0000, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets B = i32::MIN as isize, C = (i32::MIN as isize) - 1, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets } enum NonPortableSignedNoHint { X = -1, Y = 0x7FFF_FFFF, Z = 0xFFFF_FFFF, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets A = 0x1_0000_0000, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets } #[repr(usize)] enum NonPortable2 { X = ::Number, + //~^ ERROR: C-like enum variant discriminant is not portable to 32-bit targets Y = 0, } diff --git a/src/tools/clippy/tests/ui/enum_clike_unportable_variant.stderr b/src/tools/clippy/tests/ui/enum_clike_unportable_variant.stderr index 5935eea5e..93ad4daa9 100644 --- a/src/tools/clippy/tests/ui/enum_clike_unportable_variant.stderr +++ b/src/tools/clippy/tests/ui/enum_clike_unportable_variant.stderr @@ -5,51 +5,52 @@ LL | X = 0x1_0000_0000, | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::enum-clike-unportable-variant` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::enum_clike_unportable_variant)]` error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:15:5 + --> $DIR/enum_clike_unportable_variant.rs:17:5 | LL | X = 0x1_0000_0000, | ^^^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:18:5 + --> $DIR/enum_clike_unportable_variant.rs:21:5 | LL | A = 0xFFFF_FFFF, | ^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:25:5 + --> $DIR/enum_clike_unportable_variant.rs:29:5 | LL | Z = 0xFFFF_FFFF, | ^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:26:5 + --> $DIR/enum_clike_unportable_variant.rs:31:5 | LL | A = 0x1_0000_0000, | ^^^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:28:5 + --> $DIR/enum_clike_unportable_variant.rs:34:5 | LL | C = (i32::MIN as isize) - 1, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:34:5 + --> $DIR/enum_clike_unportable_variant.rs:41:5 | LL | Z = 0xFFFF_FFFF, | ^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:35:5 + --> $DIR/enum_clike_unportable_variant.rs:43:5 | LL | A = 0x1_0000_0000, | ^^^^^^^^^^^^^^^^^ error: C-like enum variant discriminant is not portable to 32-bit targets - --> $DIR/enum_clike_unportable_variant.rs:40:5 + --> $DIR/enum_clike_unportable_variant.rs:49:5 | LL | X = ::Number, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/enum_glob_use.fixed b/src/tools/clippy/tests/ui/enum_glob_use.fixed index 419370ffb..9044e8026 100644 --- a/src/tools/clippy/tests/ui/enum_glob_use.fixed +++ b/src/tools/clippy/tests/ui/enum_glob_use.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::enum_glob_use)] #![allow(unused)] #![warn(unused_imports)] diff --git a/src/tools/clippy/tests/ui/enum_glob_use.rs b/src/tools/clippy/tests/ui/enum_glob_use.rs index 645ed9832..4f157a97c 100644 --- a/src/tools/clippy/tests/ui/enum_glob_use.rs +++ b/src/tools/clippy/tests/ui/enum_glob_use.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::enum_glob_use)] #![allow(unused)] #![warn(unused_imports)] diff --git a/src/tools/clippy/tests/ui/enum_glob_use.stderr b/src/tools/clippy/tests/ui/enum_glob_use.stderr index 69531aed3..8b94e67f8 100644 --- a/src/tools/clippy/tests/ui/enum_glob_use.stderr +++ b/src/tools/clippy/tests/ui/enum_glob_use.stderr @@ -1,19 +1,20 @@ error: usage of wildcard import for enum variants - --> $DIR/enum_glob_use.rs:7:5 + --> $DIR/enum_glob_use.rs:5:5 | LL | use std::cmp::Ordering::*; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::cmp::Ordering::Less` | = note: `-D clippy::enum-glob-use` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::enum_glob_use)]` error: usage of wildcard import for enum variants - --> $DIR/enum_glob_use.rs:13:5 + --> $DIR/enum_glob_use.rs:11:5 | LL | use self::Enum::*; | ^^^^^^^^^^^^^ help: try: `self::Enum::Foo` error: usage of wildcard import for enum variants - --> $DIR/enum_glob_use.rs:17:13 + --> $DIR/enum_glob_use.rs:15:13 | LL | use crate::Enum::*; | ^^^^^^^^^^^^^^ help: try: `crate::Enum::Foo` diff --git a/src/tools/clippy/tests/ui/enum_variants.rs b/src/tools/clippy/tests/ui/enum_variants.rs index 531652a0e..85df852f7 100644 --- a/src/tools/clippy/tests/ui/enum_variants.rs +++ b/src/tools/clippy/tests/ui/enum_variants.rs @@ -12,7 +12,10 @@ enum FakeCallType2 { } enum Foo { + //~^ ERROR: all variants have the same prefix: `c` cFoo, + //~^ ERROR: variant name ends with the enum's name + //~| NOTE: `-D clippy::enum-variant-names` implied by `-D warnings` cBar, cBaz, } @@ -23,9 +26,13 @@ enum Fooo { } enum Food { + //~^ ERROR: all variants have the same prefix: `Food` FoodGood, + //~^ ERROR: variant name starts with the enum's name FoodMiddle, + //~^ ERROR: variant name starts with the enum's name FoodBad, + //~^ ERROR: variant name starts with the enum's name } enum Stuff { @@ -33,6 +40,7 @@ enum Stuff { } enum BadCallType { + //~^ ERROR: all variants have the same prefix: `CallType` CallTypeCall, CallTypeCreate, CallTypeDestroy, @@ -45,6 +53,7 @@ enum TwoCallType { } enum Consts { + //~^ ERROR: all variants have the same prefix: `Constant` ConstantInt, ConstantCake, ConstantLie, @@ -57,6 +66,7 @@ enum Two { } enum Something { + //~^ ERROR: all variants have the same prefix: `C` CCall, CCreate, CCryogenize, @@ -79,6 +89,7 @@ enum Sealll { } enum Seallll { + //~^ ERROR: all variants have the same prefix: `WithOut` WithOutCake, WithOutTea, WithOut, @@ -134,12 +145,14 @@ pub enum NetworkLayer { // should lint suggesting `IData`, not only `Data` (see #4639) enum IDataRequest { + //~^ ERROR: all variants have the same postfix: `IData` PutIData(String), GetIData(String), DeleteUnpubIData(String), } enum HIDataRequest { + //~^ ERROR: all variants have the same postfix: `HIData` PutHIData(String), GetHIData(String), DeleteUnpubHIData(String), @@ -160,6 +173,7 @@ enum Phase { mod issue9018 { enum DoLint { + //~^ ERROR: all variants have the same prefix: `_Type` _TypeCreate, _TypeRead, _TypeUpdate, @@ -167,6 +181,7 @@ mod issue9018 { } enum DoLintToo { + //~^ ERROR: all variants have the same postfix: `Type` _CreateType, _UpdateType, _DeleteType, diff --git a/src/tools/clippy/tests/ui/enum_variants.stderr b/src/tools/clippy/tests/ui/enum_variants.stderr index 7342aff80..9ea80b635 100644 --- a/src/tools/clippy/tests/ui/enum_variants.stderr +++ b/src/tools/clippy/tests/ui/enum_variants.stderr @@ -1,17 +1,20 @@ error: variant name ends with the enum's name - --> $DIR/enum_variants.rs:15:5 + --> $DIR/enum_variants.rs:16:5 | LL | cFoo, | ^^^^ | = note: `-D clippy::enum-variant-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::enum_variant_names)]` error: all variants have the same prefix: `c` --> $DIR/enum_variants.rs:14:1 | LL | / enum Foo { +LL | | LL | | cFoo, -LL | | cBar, +LL | | +... | LL | | cBaz, LL | | } | |_^ @@ -19,39 +22,42 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: variant name starts with the enum's name - --> $DIR/enum_variants.rs:26:5 + --> $DIR/enum_variants.rs:30:5 | LL | FoodGood, | ^^^^^^^^ error: variant name starts with the enum's name - --> $DIR/enum_variants.rs:27:5 + --> $DIR/enum_variants.rs:32:5 | LL | FoodMiddle, | ^^^^^^^^^^ error: variant name starts with the enum's name - --> $DIR/enum_variants.rs:28:5 + --> $DIR/enum_variants.rs:34:5 | LL | FoodBad, | ^^^^^^^ error: all variants have the same prefix: `Food` - --> $DIR/enum_variants.rs:25:1 + --> $DIR/enum_variants.rs:28:1 | LL | / enum Food { +LL | | LL | | FoodGood, -LL | | FoodMiddle, -LL | | FoodBad, +LL | | +... | +LL | | LL | | } | |_^ | = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `CallType` - --> $DIR/enum_variants.rs:35:1 + --> $DIR/enum_variants.rs:42:1 | LL | / enum BadCallType { +LL | | LL | | CallTypeCall, LL | | CallTypeCreate, LL | | CallTypeDestroy, @@ -61,9 +67,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `Constant` - --> $DIR/enum_variants.rs:47:1 + --> $DIR/enum_variants.rs:55:1 | LL | / enum Consts { +LL | | LL | | ConstantInt, LL | | ConstantCake, LL | | ConstantLie, @@ -73,9 +80,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `C` - --> $DIR/enum_variants.rs:59:1 + --> $DIR/enum_variants.rs:68:1 | LL | / enum Something { +LL | | LL | | CCall, LL | | CCreate, LL | | CCryogenize, @@ -85,9 +93,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `WithOut` - --> $DIR/enum_variants.rs:81:1 + --> $DIR/enum_variants.rs:91:1 | LL | / enum Seallll { +LL | | LL | | WithOutCake, LL | | WithOutTea, LL | | WithOut, @@ -97,9 +106,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same postfix: `IData` - --> $DIR/enum_variants.rs:136:1 + --> $DIR/enum_variants.rs:147:1 | LL | / enum IDataRequest { +LL | | LL | | PutIData(String), LL | | GetIData(String), LL | | DeleteUnpubIData(String), @@ -109,9 +119,10 @@ LL | | } = help: remove the postfixes and use full paths to the variants instead of glob imports error: all variants have the same postfix: `HIData` - --> $DIR/enum_variants.rs:142:1 + --> $DIR/enum_variants.rs:154:1 | LL | / enum HIDataRequest { +LL | | LL | | PutHIData(String), LL | | GetHIData(String), LL | | DeleteUnpubHIData(String), @@ -121,9 +132,10 @@ LL | | } = help: remove the postfixes and use full paths to the variants instead of glob imports error: all variants have the same prefix: `_Type` - --> $DIR/enum_variants.rs:162:5 + --> $DIR/enum_variants.rs:175:5 | LL | / enum DoLint { +LL | | LL | | _TypeCreate, LL | | _TypeRead, LL | | _TypeUpdate, @@ -134,9 +146,10 @@ LL | | } = help: remove the prefixes and use full paths to the variants instead of glob imports error: all variants have the same postfix: `Type` - --> $DIR/enum_variants.rs:169:5 + --> $DIR/enum_variants.rs:183:5 | LL | / enum DoLintToo { +LL | | LL | | _CreateType, LL | | _UpdateType, LL | | _DeleteType, diff --git a/src/tools/clippy/tests/ui/eprint_with_newline.fixed b/src/tools/clippy/tests/ui/eprint_with_newline.fixed new file mode 100644 index 000000000..7383d784c --- /dev/null +++ b/src/tools/clippy/tests/ui/eprint_with_newline.fixed @@ -0,0 +1,69 @@ +#![allow(clippy::print_literal)] +#![warn(clippy::print_with_newline)] + +fn main() { + eprintln!("Hello"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::print-with-newline` implied by `-D warnings` + eprintln!("Hello {}", "world"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + eprintln!("Hello {} {}", "world", "#2"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + eprintln!("{}", 1265); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + eprintln!(); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + + // these are all fine + eprint!(""); + eprint!("Hello"); + eprintln!("Hello"); + eprintln!("Hello\n"); + eprintln!("Hello {}\n", "world"); + eprint!("Issue\n{}", 1265); + eprint!("{}", 1265); + eprint!("\n{}", 1275); + eprint!("\n\n"); + eprint!("like eof\n\n"); + eprint!("Hello {} {}\n\n", "world", "#2"); + // #3126 + eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + eprintln!("\nbla\n\n"); + + // Escaping + // #3514 + eprint!("\\n"); + eprintln!("\\"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + eprint!("\\\\n"); + + // Raw strings + // #3778 + eprint!(r"\n"); + + // Literal newlines should also fail + eprintln!( + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + + ); + eprintln!( + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + + ); + + // Don't warn on CRLF (#4208) + eprint!("\r\n"); + eprint!("foo\r\n"); + eprintln!("\\r"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + eprint!("foo\rbar\n"); + + // Ignore expanded format strings + macro_rules! newline { + () => { + "\n" + }; + } + eprint!(newline!()); +} diff --git a/src/tools/clippy/tests/ui/eprint_with_newline.rs b/src/tools/clippy/tests/ui/eprint_with_newline.rs index 8389806c8..5b1140564 100644 --- a/src/tools/clippy/tests/ui/eprint_with_newline.rs +++ b/src/tools/clippy/tests/ui/eprint_with_newline.rs @@ -3,10 +3,16 @@ fn main() { eprint!("Hello\n"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::print-with-newline` implied by `-D warnings` eprint!("Hello {}\n", "world"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("Hello {} {}\n", "world", "#2"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("{}\n", 1265); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("\n"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline // these are all fine eprint!(""); @@ -20,23 +26,30 @@ fn main() { eprint!("\n\n"); eprint!("like eof\n\n"); eprint!("Hello {} {}\n\n", "world", "#2"); - eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - eprintln!("\nbla\n\n"); // #3126 + // #3126 + eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + eprintln!("\nbla\n\n"); // Escaping - eprint!("\\n"); // #3514 - eprint!("\\\n"); // should fail + // #3514 + eprint!("\\n"); + eprint!("\\\n"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("\\\\n"); // Raw strings - eprint!(r"\n"); // #3778 + // #3778 + eprint!(r"\n"); // Literal newlines should also fail eprint!( + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline " " ); eprint!( + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline r" " ); @@ -45,6 +58,7 @@ fn main() { eprint!("\r\n"); eprint!("foo\r\n"); eprint!("\\r\n"); + //~^ ERROR: using `eprint!()` with a format string that ends in a single newline eprint!("foo\rbar\n"); // Ignore expanded format strings diff --git a/src/tools/clippy/tests/ui/eprint_with_newline.stderr b/src/tools/clippy/tests/ui/eprint_with_newline.stderr index 0a6bdf15d..674b4fdae 100644 --- a/src/tools/clippy/tests/ui/eprint_with_newline.stderr +++ b/src/tools/clippy/tests/ui/eprint_with_newline.stderr @@ -1,80 +1,82 @@ error: using `eprint!()` with a format string that ends in a single newline --> $DIR/eprint_with_newline.rs:5:5 | -LL | eprint!("Hello/n"); +LL | eprint!("Hello\n"); | ^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::print-with-newline` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_with_newline)]` help: use `eprintln!` instead | -LL - eprint!("Hello/n"); +LL - eprint!("Hello\n"); LL + eprintln!("Hello"); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:6:5 + --> $DIR/eprint_with_newline.rs:8:5 | -LL | eprint!("Hello {}/n", "world"); +LL | eprint!("Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `eprintln!` instead | -LL - eprint!("Hello {}/n", "world"); +LL - eprint!("Hello {}\n", "world"); LL + eprintln!("Hello {}", "world"); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:7:5 + --> $DIR/eprint_with_newline.rs:10:5 | -LL | eprint!("Hello {} {}/n", "world", "#2"); +LL | eprint!("Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `eprintln!` instead | -LL - eprint!("Hello {} {}/n", "world", "#2"); +LL - eprint!("Hello {} {}\n", "world", "#2"); LL + eprintln!("Hello {} {}", "world", "#2"); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:8:5 + --> $DIR/eprint_with_newline.rs:12:5 | -LL | eprint!("{}/n", 1265); +LL | eprint!("{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^^ | help: use `eprintln!` instead | -LL - eprint!("{}/n", 1265); +LL - eprint!("{}\n", 1265); LL + eprintln!("{}", 1265); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:9:5 + --> $DIR/eprint_with_newline.rs:14:5 | -LL | eprint!("/n"); +LL | eprint!("\n"); | ^^^^^^^^^^^^^ | help: use `eprintln!` instead | -LL - eprint!("/n"); +LL - eprint!("\n"); LL + eprintln!(); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:28:5 + --> $DIR/eprint_with_newline.rs:37:5 | -LL | eprint!("///n"); // should fail +LL | eprint!("\\\n"); | ^^^^^^^^^^^^^^^ | help: use `eprintln!` instead | -LL - eprint!("///n"); // should fail -LL + eprintln!("//"); // should fail +LL - eprint!("\\\n"); +LL + eprintln!("\\"); | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:35:5 + --> $DIR/eprint_with_newline.rs:46:5 | LL | / eprint!( +LL | | LL | | " LL | | " LL | | ); @@ -83,13 +85,15 @@ LL | | ); help: use `eprintln!` instead | LL ~ eprintln!( +LL | LL ~ | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:39:5 + --> $DIR/eprint_with_newline.rs:51:5 | LL | / eprint!( +LL | | LL | | r" LL | | " LL | | ); @@ -98,19 +102,20 @@ LL | | ); help: use `eprintln!` instead | LL ~ eprintln!( +LL | LL ~ | error: using `eprint!()` with a format string that ends in a single newline - --> $DIR/eprint_with_newline.rs:47:5 + --> $DIR/eprint_with_newline.rs:60:5 | -LL | eprint!("//r/n"); +LL | eprint!("\\r\n"); | ^^^^^^^^^^^^^^^^ | help: use `eprintln!` instead | -LL - eprint!("//r/n"); -LL + eprintln!("//r"); +LL - eprint!("\\r\n"); +LL + eprintln!("\\r"); | error: aborting due to 9 previous errors diff --git a/src/tools/clippy/tests/ui/eq_op.rs b/src/tools/clippy/tests/ui/eq_op.rs index e973e5ba2..7c2c13187 100644 --- a/src/tools/clippy/tests/ui/eq_op.rs +++ b/src/tools/clippy/tests/ui/eq_op.rs @@ -5,51 +5,80 @@ fn main() { // simple values and comparisons let _ = 1 == 1; + //~^ ERROR: equal expressions as operands to `==` + //~| NOTE: `-D clippy::eq-op` implied by `-D warnings` let _ = "no" == "no"; + //~^ ERROR: equal expressions as operands to `==` // even though I agree that no means no ;-) let _ = false != false; + //~^ ERROR: equal expressions as operands to `!=` let _ = 1.5 < 1.5; + //~^ ERROR: equal expressions as operands to `<` let _ = 1u64 >= 1u64; + //~^ ERROR: equal expressions as operands to `>=` let x = f32::NAN; let _ = x != x; + //~^ ERROR: equal expressions as operands to `!=` + //~| NOTE: if you intended to check if the operand is NaN, use `.is_nan()` instead // casts, methods, parentheses let _ = (1u32 as u64) & (1u32 as u64); + //~^ ERROR: equal expressions as operands to `&` #[rustfmt::skip] { let _ = 1 ^ ((((((1)))))); + //~^ ERROR: equal expressions as operands to `^` }; // unary and binary operators let _ = (-(2) < -(2)); + //~^ ERROR: equal expressions as operands to `<` let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); + //~^ ERROR: equal expressions as operands to `==` + //~| ERROR: equal expressions as operands to `&` + //~| ERROR: equal expressions as operands to `&` let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; + //~^ ERROR: equal expressions as operands to `==` // various other things let _ = ([1] != [1]); + //~^ ERROR: equal expressions as operands to `!=` let _ = ((1, 2) != (1, 2)); + //~^ ERROR: equal expressions as operands to `!=` let _ = vec![1, 2, 3] == vec![1, 2, 3]; //no error yet, as we don't match macros // const folding let _ = 1 + 1 == 2; + //~^ ERROR: equal expressions as operands to `==` let _ = 1 - 1 == 0; + //~^ ERROR: equal expressions as operands to `==` + //~| ERROR: equal expressions as operands to `-` let _ = 1 - 1; + //~^ ERROR: equal expressions as operands to `-` let _ = 1 / 1; + //~^ ERROR: equal expressions as operands to `/` let _ = true && true; + //~^ ERROR: equal expressions as operands to `&&` let _ = true || true; + //~^ ERROR: equal expressions as operands to `||` let a: u32 = 0; let b: u32 = 0; let _ = a == b && b == a; + //~^ ERROR: equal expressions as operands to `&&` let _ = a != b && b != a; + //~^ ERROR: equal expressions as operands to `&&` let _ = a < b && b > a; + //~^ ERROR: equal expressions as operands to `&&` let _ = a <= b && b >= a; + //~^ ERROR: equal expressions as operands to `&&` let mut a = vec![1]; let _ = a == a; + //~^ ERROR: equal expressions as operands to `==` let _ = 2 * a.len() == 2 * a.len(); // ok, functions let _ = a.pop() == a.pop(); // ok, functions @@ -60,6 +89,7 @@ fn main() { const B: u32 = 10; const C: u32 = A / B; // ok, different named constants const D: u32 = A / A; + //~^ ERROR: equal expressions as operands to `/` } macro_rules! check_if_named_foo { @@ -91,6 +121,7 @@ struct Nested { fn check_nested(n1: &Nested, n2: &Nested) -> bool { // `n2.inner.0.0` mistyped as `n1.inner.0.0` (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0 + //~^ ERROR: equal expressions as operands to `==` } #[test] diff --git a/src/tools/clippy/tests/ui/eq_op.stderr b/src/tools/clippy/tests/ui/eq_op.stderr index c7fa253bd..2427ac0dd 100644 --- a/src/tools/clippy/tests/ui/eq_op.stderr +++ b/src/tools/clippy/tests/ui/eq_op.stderr @@ -5,33 +5,34 @@ LL | let _ = 1 == 1; | ^^^^^^ | = note: `-D clippy::eq-op` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::eq_op)]` error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:8:13 + --> $DIR/eq_op.rs:10:13 | LL | let _ = "no" == "no"; | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:10:13 + --> $DIR/eq_op.rs:13:13 | LL | let _ = false != false; | ^^^^^^^^^^^^^^ error: equal expressions as operands to `<` - --> $DIR/eq_op.rs:11:13 + --> $DIR/eq_op.rs:15:13 | LL | let _ = 1.5 < 1.5; | ^^^^^^^^^ error: equal expressions as operands to `>=` - --> $DIR/eq_op.rs:12:13 + --> $DIR/eq_op.rs:17:13 | LL | let _ = 1u64 >= 1u64; | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:14:13 + --> $DIR/eq_op.rs:20:13 | LL | let _ = x != x; | ^^^^^^ @@ -39,139 +40,139 @@ LL | let _ = x != x; = note: if you intended to check if the operand is NaN, use `.is_nan()` instead error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:17:13 + --> $DIR/eq_op.rs:25:13 | LL | let _ = (1u32 as u64) & (1u32 as u64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `^` - --> $DIR/eq_op.rs:20:17 + --> $DIR/eq_op.rs:29:17 | LL | let _ = 1 ^ ((((((1)))))); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `<` - --> $DIR/eq_op.rs:24:13 + --> $DIR/eq_op.rs:34:13 | LL | let _ = (-(2) < -(2)); | ^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:25:13 + --> $DIR/eq_op.rs:36:13 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:25:14 + --> $DIR/eq_op.rs:36:14 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&` - --> $DIR/eq_op.rs:25:35 + --> $DIR/eq_op.rs:36:35 | LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1)); | ^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:26:13 + --> $DIR/eq_op.rs:40:13 | LL | let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:29:13 + --> $DIR/eq_op.rs:44:13 | LL | let _ = ([1] != [1]); | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> $DIR/eq_op.rs:30:13 + --> $DIR/eq_op.rs:46:13 | LL | let _ = ((1, 2) != (1, 2)); | ^^^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:34:13 + --> $DIR/eq_op.rs:51:13 | LL | let _ = 1 + 1 == 2; | ^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:35:13 + --> $DIR/eq_op.rs:53:13 | LL | let _ = 1 - 1 == 0; | ^^^^^^^^^^ error: equal expressions as operands to `-` - --> $DIR/eq_op.rs:35:13 + --> $DIR/eq_op.rs:53:13 | LL | let _ = 1 - 1 == 0; | ^^^^^ error: equal expressions as operands to `-` - --> $DIR/eq_op.rs:37:13 + --> $DIR/eq_op.rs:57:13 | LL | let _ = 1 - 1; | ^^^^^ error: equal expressions as operands to `/` - --> $DIR/eq_op.rs:38:13 + --> $DIR/eq_op.rs:59:13 | LL | let _ = 1 / 1; | ^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:39:13 + --> $DIR/eq_op.rs:61:13 | LL | let _ = true && true; | ^^^^^^^^^^^^ error: equal expressions as operands to `||` - --> $DIR/eq_op.rs:41:13 + --> $DIR/eq_op.rs:64:13 | LL | let _ = true || true; | ^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:46:13 + --> $DIR/eq_op.rs:70:13 | LL | let _ = a == b && b == a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:47:13 + --> $DIR/eq_op.rs:72:13 | LL | let _ = a != b && b != a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:48:13 + --> $DIR/eq_op.rs:74:13 | LL | let _ = a < b && b > a; | ^^^^^^^^^^^^^^ error: equal expressions as operands to `&&` - --> $DIR/eq_op.rs:49:13 + --> $DIR/eq_op.rs:76:13 | LL | let _ = a <= b && b >= a; | ^^^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:52:13 + --> $DIR/eq_op.rs:80:13 | LL | let _ = a == a; | ^^^^^^ error: equal expressions as operands to `/` - --> $DIR/eq_op.rs:62:20 + --> $DIR/eq_op.rs:91:20 | LL | const D: u32 = A / A; | ^^^^^ error: equal expressions as operands to `==` - --> $DIR/eq_op.rs:93:5 + --> $DIR/eq_op.rs:123:5 | LL | (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/eq_op_macros.rs b/src/tools/clippy/tests/ui/eq_op_macros.rs index 482406772..a511af4a3 100644 --- a/src/tools/clippy/tests/ui/eq_op_macros.rs +++ b/src/tools/clippy/tests/ui/eq_op_macros.rs @@ -21,7 +21,9 @@ fn main() { // lint identical args in `assert_eq!` assert_eq!(a, a); + //~^ ERROR: identical args used in this `assert_eq!` macro call assert_eq!(a + 1, a + 1); + //~^ ERROR: identical args used in this `assert_eq!` macro call // ok assert_eq!(a, b); assert_eq!(a, a + 1); @@ -29,7 +31,9 @@ fn main() { // lint identical args in `assert_ne!` assert_ne!(a, a); + //~^ ERROR: identical args used in this `assert_ne!` macro call assert_ne!(a + 1, a + 1); + //~^ ERROR: identical args used in this `assert_ne!` macro call // ok assert_ne!(a, b); assert_ne!(a, a + 1); @@ -37,7 +41,9 @@ fn main() { // lint identical args in `debug_assert_eq!` debug_assert_eq!(a, a); + //~^ ERROR: identical args used in this `debug_assert_eq!` macro call debug_assert_eq!(a + 1, a + 1); + //~^ ERROR: identical args used in this `debug_assert_eq!` macro call // ok debug_assert_eq!(a, b); debug_assert_eq!(a, a + 1); @@ -45,7 +51,9 @@ fn main() { // lint identical args in `debug_assert_ne!` debug_assert_ne!(a, a); + //~^ ERROR: identical args used in this `debug_assert_ne!` macro call debug_assert_ne!(a + 1, a + 1); + //~^ ERROR: identical args used in this `debug_assert_ne!` macro call // ok debug_assert_ne!(a, b); debug_assert_ne!(a, a + 1); diff --git a/src/tools/clippy/tests/ui/eq_op_macros.stderr b/src/tools/clippy/tests/ui/eq_op_macros.stderr index cb9b0c018..0df26607a 100644 --- a/src/tools/clippy/tests/ui/eq_op_macros.stderr +++ b/src/tools/clippy/tests/ui/eq_op_macros.stderr @@ -8,6 +8,7 @@ LL | assert_in_macro_def!(); | ---------------------- in this macro invocation | = note: `-D clippy::eq-op` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::eq_op)]` = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) error: identical args used in this `assert_ne!` macro call @@ -50,43 +51,43 @@ LL | assert_eq!(a, a); | ^^^^ error: identical args used in this `assert_eq!` macro call - --> $DIR/eq_op_macros.rs:24:16 + --> $DIR/eq_op_macros.rs:25:16 | LL | assert_eq!(a + 1, a + 1); | ^^^^^^^^^^^^ error: identical args used in this `assert_ne!` macro call - --> $DIR/eq_op_macros.rs:31:16 + --> $DIR/eq_op_macros.rs:33:16 | LL | assert_ne!(a, a); | ^^^^ error: identical args used in this `assert_ne!` macro call - --> $DIR/eq_op_macros.rs:32:16 + --> $DIR/eq_op_macros.rs:35:16 | LL | assert_ne!(a + 1, a + 1); | ^^^^^^^^^^^^ error: identical args used in this `debug_assert_eq!` macro call - --> $DIR/eq_op_macros.rs:39:22 + --> $DIR/eq_op_macros.rs:43:22 | LL | debug_assert_eq!(a, a); | ^^^^ error: identical args used in this `debug_assert_eq!` macro call - --> $DIR/eq_op_macros.rs:40:22 + --> $DIR/eq_op_macros.rs:45:22 | LL | debug_assert_eq!(a + 1, a + 1); | ^^^^^^^^^^^^ error: identical args used in this `debug_assert_ne!` macro call - --> $DIR/eq_op_macros.rs:47:22 + --> $DIR/eq_op_macros.rs:53:22 | LL | debug_assert_ne!(a, a); | ^^^^ error: identical args used in this `debug_assert_ne!` macro call - --> $DIR/eq_op_macros.rs:48:22 + --> $DIR/eq_op_macros.rs:55:22 | LL | debug_assert_ne!(a + 1, a + 1); | ^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/equatable_if_let.fixed b/src/tools/clippy/tests/ui/equatable_if_let.fixed index 6cc070fb5..2b523e1e1 100644 --- a/src/tools/clippy/tests/ui/equatable_if_let.fixed +++ b/src/tools/clippy/tests/ui/equatable_if_let.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow( unused_variables, diff --git a/src/tools/clippy/tests/ui/equatable_if_let.rs b/src/tools/clippy/tests/ui/equatable_if_let.rs index f00a129be..f7e3bb296 100644 --- a/src/tools/clippy/tests/ui/equatable_if_let.rs +++ b/src/tools/clippy/tests/ui/equatable_if_let.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow( unused_variables, diff --git a/src/tools/clippy/tests/ui/equatable_if_let.stderr b/src/tools/clippy/tests/ui/equatable_if_let.stderr index 649495dde..6cc19d829 100644 --- a/src/tools/clippy/tests/ui/equatable_if_let.stderr +++ b/src/tools/clippy/tests/ui/equatable_if_let.stderr @@ -1,85 +1,86 @@ error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:65:8 + --> $DIR/equatable_if_let.rs:64:8 | LL | if let 2 = a {} | ^^^^^^^^^ help: try: `a == 2` | = note: `-D clippy::equatable-if-let` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::equatable_if_let)]` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:66:8 + --> $DIR/equatable_if_let.rs:65:8 | LL | if let Ordering::Greater = a.cmp(&b) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.cmp(&b) == Ordering::Greater` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:67:8 + --> $DIR/equatable_if_let.rs:66:8 | LL | if let Some(2) = c {} | ^^^^^^^^^^^^^^^ help: try: `c == Some(2)` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:68:8 + --> $DIR/equatable_if_let.rs:67:8 | LL | if let Struct { a: 2, b: false } = d {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `d == (Struct { a: 2, b: false })` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:69:8 + --> $DIR/equatable_if_let.rs:68:8 | LL | if let Enum::TupleVariant(32, 64) = e {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == Enum::TupleVariant(32, 64)` error: this pattern matching can be expressed using equality - --> $DIR/equatable_if_let.rs:70:8 + --> $DIR/equatable_if_let.rs:69:8 | 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:71:8 + --> $DIR/equatable_if_let.rs:70: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:72:8 + --> $DIR/equatable_if_let.rs:71: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:81:8 + --> $DIR/equatable_if_let.rs:80: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:82:8 + --> $DIR/equatable_if_let.rs:81: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:83:8 + --> $DIR/equatable_if_let.rs:82: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:84:8 + --> $DIR/equatable_if_let.rs:83: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:85:8 + --> $DIR/equatable_if_let.rs:84: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:87:8 + --> $DIR/equatable_if_let.rs:86:8 | LL | if let inline!("abc") = "abc" { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"abc" == inline!("abc")` diff --git a/src/tools/clippy/tests/ui/erasing_op.rs b/src/tools/clippy/tests/ui/erasing_op.rs index 74985029e..00c74f23f 100644 --- a/src/tools/clippy/tests/ui/erasing_op.rs +++ b/src/tools/clippy/tests/ui/erasing_op.rs @@ -33,11 +33,17 @@ impl core::ops::Mul for Vec1 { #[warn(clippy::erasing_op)] fn test(x: u8) { x * 0; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou + //~| NOTE: `-D clippy::erasing-op` implied by `-D warnings` 0 & x; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou 0 / x; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou 0 * Meter; // no error: Output type is different from the non-zero argument 0 * Vec1 { x: 5 }; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou Vec1 { x: 5 } * 0; + //~^ ERROR: this operation will always return zero. This is likely not the intended ou } fn main() { diff --git a/src/tools/clippy/tests/ui/erasing_op.stderr b/src/tools/clippy/tests/ui/erasing_op.stderr index 979412523..1b50a05cd 100644 --- a/src/tools/clippy/tests/ui/erasing_op.stderr +++ b/src/tools/clippy/tests/ui/erasing_op.stderr @@ -5,27 +5,28 @@ LL | x * 0; | ^^^^^ | = note: `-D clippy::erasing-op` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::erasing_op)]` error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:36:5 + --> $DIR/erasing_op.rs:38:5 | LL | 0 & x; | ^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:37:5 + --> $DIR/erasing_op.rs:40:5 | LL | 0 / x; | ^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:39:5 + --> $DIR/erasing_op.rs:43:5 | LL | 0 * Vec1 { x: 5 }; | ^^^^^^^^^^^^^^^^^ error: this operation will always return zero. This is likely not the intended outcome - --> $DIR/erasing_op.rs:40:5 + --> $DIR/erasing_op.rs:45:5 | LL | Vec1 { x: 5 } * 0; | ^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/err_expect.fixed b/src/tools/clippy/tests/ui/err_expect.fixed index 46e2816da..abbc6dbeb 100644 --- a/src/tools/clippy/tests/ui/err_expect.fixed +++ b/src/tools/clippy/tests/ui/err_expect.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::unnecessary_literal_unwrap)] struct MyTypeNonDebug; diff --git a/src/tools/clippy/tests/ui/err_expect.rs b/src/tools/clippy/tests/ui/err_expect.rs index b9446034d..0c7ad185d 100644 --- a/src/tools/clippy/tests/ui/err_expect.rs +++ b/src/tools/clippy/tests/ui/err_expect.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::unnecessary_literal_unwrap)] struct MyTypeNonDebug; diff --git a/src/tools/clippy/tests/ui/err_expect.stderr b/src/tools/clippy/tests/ui/err_expect.stderr index 82c0754cf..da7cd47f0 100644 --- a/src/tools/clippy/tests/ui/err_expect.stderr +++ b/src/tools/clippy/tests/ui/err_expect.stderr @@ -1,13 +1,14 @@ error: called `.err().expect()` on a `Result` value - --> $DIR/err_expect.rs:12:16 + --> $DIR/err_expect.rs:10:16 | LL | test_debug.err().expect("Testing debug type"); | ^^^^^^^^^^^^ help: try: `expect_err` | = note: `-D clippy::err-expect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::err_expect)]` error: called `.err().expect()` on a `Result` value - --> $DIR/err_expect.rs:27:7 + --> $DIR/err_expect.rs:25:7 | LL | x.err().expect("17"); | ^^^^^^^^^^^^ help: try: `expect_err` diff --git a/src/tools/clippy/tests/ui/error_impl_error.rs b/src/tools/clippy/tests/ui/error_impl_error.rs index 40ce4181b..05003f7d0 100644 --- a/src/tools/clippy/tests/ui/error_impl_error.rs +++ b/src/tools/clippy/tests/ui/error_impl_error.rs @@ -5,6 +5,7 @@ pub mod a { #[derive(Debug)] pub struct Error; + //~^ ERROR: exported type named `Error` that implements `Error` impl std::fmt::Display for Error { fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -18,6 +19,7 @@ pub mod a { mod b { #[derive(Debug)] pub(super) enum Error {} + //~^ ERROR: exported type named `Error` that implements `Error` impl std::fmt::Display for Error { fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -30,6 +32,7 @@ mod b { pub mod c { pub union Error { + //~^ ERROR: exported type named `Error` that implements `Error` a: u32, b: u32, } @@ -51,6 +54,7 @@ pub mod c { pub mod d { pub type Error = std::fmt::Error; + //~^ ERROR: exported type alias named `Error` that implements `Error` } mod e { diff --git a/src/tools/clippy/tests/ui/error_impl_error.stderr b/src/tools/clippy/tests/ui/error_impl_error.stderr index f3e04b641..d7a1aa829 100644 --- a/src/tools/clippy/tests/ui/error_impl_error.stderr +++ b/src/tools/clippy/tests/ui/error_impl_error.stderr @@ -5,38 +5,39 @@ LL | pub struct Error; | ^^^^^ | note: `Error` was implemented here - --> $DIR/error_impl_error.rs:15:5 + --> $DIR/error_impl_error.rs:16:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::error-impl-error` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::error_impl_error)]` error: exported type named `Error` that implements `Error` - --> $DIR/error_impl_error.rs:20:21 + --> $DIR/error_impl_error.rs:21:21 | LL | pub(super) enum Error {} | ^^^^^ | note: `Error` was implemented here - --> $DIR/error_impl_error.rs:28:5 + --> $DIR/error_impl_error.rs:30:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: exported type named `Error` that implements `Error` - --> $DIR/error_impl_error.rs:32:15 + --> $DIR/error_impl_error.rs:34:15 | LL | pub union Error { | ^^^^^ | note: `Error` was implemented here - --> $DIR/error_impl_error.rs:49:5 + --> $DIR/error_impl_error.rs:52:5 | LL | impl std::error::Error for Error {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: exported type alias named `Error` that implements `Error` - --> $DIR/error_impl_error.rs:53:14 + --> $DIR/error_impl_error.rs:56:14 | LL | pub type Error = std::fmt::Error; | ^^^^^ diff --git a/src/tools/clippy/tests/ui/eta.fixed b/src/tools/clippy/tests/ui/eta.fixed index ddabe7616..32c7499bf 100644 --- a/src/tools/clippy/tests/ui/eta.fixed +++ b/src/tools/clippy/tests/ui/eta.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::redundant_closure, clippy::redundant_closure_for_method_calls)] #![allow(unused)] #![allow( @@ -8,7 +7,8 @@ clippy::option_map_unit_fn, clippy::redundant_closure_call, clippy::uninlined_format_args, - clippy::useless_vec + clippy::useless_vec, + clippy::unnecessary_map_on_constructor )] use std::path::{Path, PathBuf}; diff --git a/src/tools/clippy/tests/ui/eta.rs b/src/tools/clippy/tests/ui/eta.rs index 92ecff6eb..25b7431ba 100644 --- a/src/tools/clippy/tests/ui/eta.rs +++ b/src/tools/clippy/tests/ui/eta.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::redundant_closure, clippy::redundant_closure_for_method_calls)] #![allow(unused)] #![allow( @@ -8,7 +7,8 @@ clippy::option_map_unit_fn, clippy::redundant_closure_call, clippy::uninlined_format_args, - clippy::useless_vec + clippy::useless_vec, + clippy::unnecessary_map_on_constructor )] use std::path::{Path, PathBuf}; diff --git a/src/tools/clippy/tests/ui/eta.stderr b/src/tools/clippy/tests/ui/eta.stderr index ff40a2074..951e4ac74 100644 --- a/src/tools/clippy/tests/ui/eta.stderr +++ b/src/tools/clippy/tests/ui/eta.stderr @@ -5,6 +5,7 @@ LL | let a = Some(1u8).map(|a| foo(a)); | ^^^^^^^^^^ help: replace the closure with the function itself: `foo` | = note: `-D clippy::redundant-closure` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]` error: redundant closure --> $DIR/eta.rs:33:40 @@ -37,6 +38,7 @@ LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo` | = note: `-D clippy::redundant-closure-for-method-calls` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_for_method_calls)]` error: redundant closure --> $DIR/eta.rs:95:51 diff --git a/src/tools/clippy/tests/ui/excessive_precision.fixed b/src/tools/clippy/tests/ui/excessive_precision.fixed index 7bb4da453..cc5531035 100644 --- a/src/tools/clippy/tests/ui/excessive_precision.fixed +++ b/src/tools/clippy/tests/ui/excessive_precision.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::excessive_precision)] #![allow( dead_code, diff --git a/src/tools/clippy/tests/ui/excessive_precision.rs b/src/tools/clippy/tests/ui/excessive_precision.rs index e8d6ab687..fff986a82 100644 --- a/src/tools/clippy/tests/ui/excessive_precision.rs +++ b/src/tools/clippy/tests/ui/excessive_precision.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::excessive_precision)] #![allow( dead_code, diff --git a/src/tools/clippy/tests/ui/excessive_precision.stderr b/src/tools/clippy/tests/ui/excessive_precision.stderr index 348ad183d..5e7672e18 100644 --- a/src/tools/clippy/tests/ui/excessive_precision.stderr +++ b/src/tools/clippy/tests/ui/excessive_precision.stderr @@ -1,91 +1,92 @@ error: float has excessive precision - --> $DIR/excessive_precision.rs:21:26 + --> $DIR/excessive_precision.rs:20:26 | LL | const BAD32_1: f32 = 0.123_456_789_f32; | ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79_f32` | = note: `-D clippy::excessive-precision` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::excessive_precision)]` error: float has excessive precision - --> $DIR/excessive_precision.rs:22:26 + --> $DIR/excessive_precision.rs:21:26 | LL | const BAD32_2: f32 = 0.123_456_789; | ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79` error: float has excessive precision - --> $DIR/excessive_precision.rs:23:26 + --> $DIR/excessive_precision.rs:22:26 | LL | const BAD32_3: f32 = 0.100_000_000_000_1; | ^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.1` error: float has excessive precision - --> $DIR/excessive_precision.rs:24:29 + --> $DIR/excessive_precision.rs:23:29 | LL | const BAD32_EDGE: f32 = 1.000_000_9; | ^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.000_001` error: float has excessive precision - --> $DIR/excessive_precision.rs:28:26 + --> $DIR/excessive_precision.rs:27:26 | LL | const BAD64_3: f64 = 0.100_000_000_000_000_000_1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.1` error: float has excessive precision - --> $DIR/excessive_precision.rs:31:22 + --> $DIR/excessive_precision.rs:30:22 | LL | println!("{:?}", 8.888_888_888_888_888_888_888); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `8.888_888_888_888_89` error: float has excessive precision - --> $DIR/excessive_precision.rs:42:22 + --> $DIR/excessive_precision.rs:41:22 | LL | let bad32: f32 = 1.123_456_789; | ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8` error: float has excessive precision - --> $DIR/excessive_precision.rs:43:26 + --> $DIR/excessive_precision.rs:42:26 | LL | let bad32_suf: f32 = 1.123_456_789_f32; | ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8_f32` error: float has excessive precision - --> $DIR/excessive_precision.rs:44:21 + --> $DIR/excessive_precision.rs:43:21 | LL | let bad32_inf = 1.123_456_789_f32; | ^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8_f32` error: float has excessive precision - --> $DIR/excessive_precision.rs:54:36 + --> $DIR/excessive_precision.rs:53: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:55:36 + --> $DIR/excessive_precision.rs:54: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:59:24 + --> $DIR/excessive_precision.rs:58:24 | LL | let bad_e32: f32 = 1.123_456_788_888e-10; | ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8e-10` error: float has excessive precision - --> $DIR/excessive_precision.rs:62:27 + --> $DIR/excessive_precision.rs:61:27 | LL | let bad_bige32: f32 = 1.123_456_788_888E-10; | ^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.123_456_8E-10` error: float has excessive precision - --> $DIR/excessive_precision.rs:71:13 + --> $DIR/excessive_precision.rs:70:13 | LL | let _ = 2.225_073_858_507_201_1e-308_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `2.225_073_858_507_201e-308_f64` error: float has excessive precision - --> $DIR/excessive_precision.rs:74:13 + --> $DIR/excessive_precision.rs:73:13 | LL | let _ = 1.000_000_000_000_001e-324_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0_f64` diff --git a/src/tools/clippy/tests/ui/exhaustive_items.fixed b/src/tools/clippy/tests/ui/exhaustive_items.fixed index 6c7b1cab6..1bf33a5f2 100644 --- a/src/tools/clippy/tests/ui/exhaustive_items.fixed +++ b/src/tools/clippy/tests/ui/exhaustive_items.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/exhaustive_items.rs b/src/tools/clippy/tests/ui/exhaustive_items.rs index d205bac2d..1328791e1 100644 --- a/src/tools/clippy/tests/ui/exhaustive_items.rs +++ b/src/tools/clippy/tests/ui/exhaustive_items.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/exhaustive_items.stderr b/src/tools/clippy/tests/ui/exhaustive_items.stderr index f46ebd477..ae43e81c0 100644 --- a/src/tools/clippy/tests/ui/exhaustive_items.stderr +++ b/src/tools/clippy/tests/ui/exhaustive_items.stderr @@ -1,5 +1,5 @@ error: exported enums should not be exhaustive - --> $DIR/exhaustive_items.rs:11:5 + --> $DIR/exhaustive_items.rs:9:5 | LL | / pub enum Exhaustive { LL | | Foo, @@ -10,7 +10,7 @@ LL | | } | |_____^ | note: the lint level is defined here - --> $DIR/exhaustive_items.rs:3:9 + --> $DIR/exhaustive_items.rs:1:9 | LL | #![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)] | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -21,7 +21,7 @@ LL ~ pub enum Exhaustive { | error: exported enums should not be exhaustive - --> $DIR/exhaustive_items.rs:20:5 + --> $DIR/exhaustive_items.rs:18: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:55:5 + --> $DIR/exhaustive_items.rs:53:5 | LL | / pub struct Exhaustive { LL | | pub foo: u8, @@ -47,7 +47,7 @@ LL | | } | |_____^ | note: the lint level is defined here - --> $DIR/exhaustive_items.rs:3:35 + --> $DIR/exhaustive_items.rs:1:35 | LL | #![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/exit1.rs b/src/tools/clippy/tests/ui/exit1.rs index 4eac6eb74..a89f6dd4c 100644 --- a/src/tools/clippy/tests/ui/exit1.rs +++ b/src/tools/clippy/tests/ui/exit1.rs @@ -3,6 +3,8 @@ fn not_main() { if true { std::process::exit(4); + //~^ ERROR: usage of `process::exit` + //~| NOTE: `-D clippy::exit` implied by `-D warnings` } } diff --git a/src/tools/clippy/tests/ui/exit1.stderr b/src/tools/clippy/tests/ui/exit1.stderr index a8d3956aa..94d8f1e32 100644 --- a/src/tools/clippy/tests/ui/exit1.stderr +++ b/src/tools/clippy/tests/ui/exit1.stderr @@ -5,6 +5,7 @@ LL | std::process::exit(4); | ^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::exit` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::exit)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/exit2.rs b/src/tools/clippy/tests/ui/exit2.rs index 4b693ed70..d5ff93fb9 100644 --- a/src/tools/clippy/tests/ui/exit2.rs +++ b/src/tools/clippy/tests/ui/exit2.rs @@ -2,6 +2,8 @@ fn also_not_main() { std::process::exit(3); + //~^ ERROR: usage of `process::exit` + //~| NOTE: `-D clippy::exit` implied by `-D warnings` } fn main() { diff --git a/src/tools/clippy/tests/ui/exit2.stderr b/src/tools/clippy/tests/ui/exit2.stderr index 7263e156a..cd324f182 100644 --- a/src/tools/clippy/tests/ui/exit2.stderr +++ b/src/tools/clippy/tests/ui/exit2.stderr @@ -5,6 +5,7 @@ LL | std::process::exit(3); | ^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::exit` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::exit)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/expect.rs b/src/tools/clippy/tests/ui/expect.rs index 1588579bb..f15b3d37e 100644 --- a/src/tools/clippy/tests/ui/expect.rs +++ b/src/tools/clippy/tests/ui/expect.rs @@ -4,12 +4,15 @@ fn expect_option() { let opt = Some(0); let _ = opt.expect(""); + //~^ ERROR: used `expect()` on an `Option` value } fn expect_result() { let res: Result = Ok(0); let _ = res.expect(""); + //~^ ERROR: used `expect()` on a `Result` value let _ = res.expect_err(""); + //~^ ERROR: used `expect_err()` on a `Result` value } fn main() { diff --git a/src/tools/clippy/tests/ui/expect.stderr b/src/tools/clippy/tests/ui/expect.stderr index f787fa973..35a258a85 100644 --- a/src/tools/clippy/tests/ui/expect.stderr +++ b/src/tools/clippy/tests/ui/expect.stderr @@ -6,9 +6,10 @@ LL | let _ = opt.expect(""); | = note: if this value is `None`, it will panic = note: `-D clippy::expect-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::expect_used)]` error: used `expect()` on a `Result` value - --> $DIR/expect.rs:11:13 + --> $DIR/expect.rs:12:13 | LL | let _ = res.expect(""); | ^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | let _ = res.expect(""); = note: if this value is an `Err`, it will panic error: used `expect_err()` on a `Result` value - --> $DIR/expect.rs:12:13 + --> $DIR/expect.rs:14:13 | LL | let _ = res.expect_err(""); | ^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/expect_fun_call.fixed b/src/tools/clippy/tests/ui/expect_fun_call.fixed index 73c6c97de..6ac3c43ad 100644 --- a/src/tools/clippy/tests/ui/expect_fun_call.fixed +++ b/src/tools/clippy/tests/ui/expect_fun_call.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::expect_fun_call)] #![allow( clippy::to_string_in_format_args, diff --git a/src/tools/clippy/tests/ui/expect_fun_call.rs b/src/tools/clippy/tests/ui/expect_fun_call.rs index a78613863..22ea2db50 100644 --- a/src/tools/clippy/tests/ui/expect_fun_call.rs +++ b/src/tools/clippy/tests/ui/expect_fun_call.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::expect_fun_call)] #![allow( clippy::to_string_in_format_args, diff --git a/src/tools/clippy/tests/ui/expect_fun_call.stderr b/src/tools/clippy/tests/ui/expect_fun_call.stderr index a621f681d..dd3976f36 100644 --- a/src/tools/clippy/tests/ui/expect_fun_call.stderr +++ b/src/tools/clippy/tests/ui/expect_fun_call.stderr @@ -1,91 +1,92 @@ error: use of `expect` followed by a function call - --> $DIR/expect_fun_call.rs:38:26 + --> $DIR/expect_fun_call.rs:37:26 | LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))` | = note: `-D clippy::expect-fun-call` implied by `-D warnings` + = 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:41:26 + --> $DIR/expect_fun_call.rs:40: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:44:37 + --> $DIR/expect_fun_call.rs:43: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:54:25 + --> $DIR/expect_fun_call.rs:53: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:57:25 + --> $DIR/expect_fun_call.rs:56: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:69:17 + --> $DIR/expect_fun_call.rs:68: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:90:21 + --> $DIR/expect_fun_call.rs:89: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:91:21 + --> $DIR/expect_fun_call.rs:90: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:92:21 + --> $DIR/expect_fun_call.rs:91: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:94:21 + --> $DIR/expect_fun_call.rs:93: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:95:21 + --> $DIR/expect_fun_call.rs:94: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:99:16 + --> $DIR/expect_fun_call.rs:98: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:105:17 + --> $DIR/expect_fun_call.rs:104: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:109:20 + --> $DIR/expect_fun_call.rs:108: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:112:30 + --> $DIR/expect_fun_call.rs:111:30 | LL | format_capture_and_value.expect(&format!("{error_code}, {}", 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{error_code}, {}", 1))` diff --git a/src/tools/clippy/tests/ui/expect_tool_lint_rfc_2383.rs b/src/tools/clippy/tests/ui/expect_tool_lint_rfc_2383.rs index 2460f3343..3811421dc 100644 --- a/src/tools/clippy/tests/ui/expect_tool_lint_rfc_2383.rs +++ b/src/tools/clippy/tests/ui/expect_tool_lint_rfc_2383.rs @@ -33,10 +33,13 @@ mod rustc_warn { //! See #[expect(dead_code)] + //~^ ERROR: this lint expectation is unfulfilled + //~| NOTE: `-D unfulfilled-lint-expectations` implied by `-D warnings` pub fn rustc_lints() { let x = 42; #[expect(illegal_floating_point_literal_pattern)] + //~^ ERROR: this lint expectation is unfulfilled match x { 5 => {} 6 => {} @@ -111,6 +114,7 @@ mod clippy_warn { //! See #[expect(clippy::almost_swapped)] + //~^ ERROR: this lint expectation is unfulfilled fn foo() { let mut a = 0; let mut b = 9; @@ -118,16 +122,19 @@ mod clippy_warn { } #[expect(clippy::bytes_nth)] + //~^ ERROR: this lint expectation is unfulfilled fn bar() { let _ = "Hello".as_bytes().get(3); } #[expect(clippy::if_same_then_else)] + //~^ ERROR: this lint expectation is unfulfilled fn baz() { let _ = if true { 33 } else { 42 }; } #[expect(clippy::overly_complex_bool_expr)] + //~^ ERROR: this lint expectation is unfulfilled fn burger() { let a = false; let b = true; diff --git a/src/tools/clippy/tests/ui/expect_tool_lint_rfc_2383.stderr b/src/tools/clippy/tests/ui/expect_tool_lint_rfc_2383.stderr index 7ce9e855b..3f8d0b724 100644 --- a/src/tools/clippy/tests/ui/expect_tool_lint_rfc_2383.stderr +++ b/src/tools/clippy/tests/ui/expect_tool_lint_rfc_2383.stderr @@ -5,33 +5,34 @@ LL | #[expect(dead_code)] | ^^^^^^^^^ | = note: `-D unfulfilled-lint-expectations` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(unfulfilled_lint_expectations)]` error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:39:18 + --> $DIR/expect_tool_lint_rfc_2383.rs:41:18 | LL | #[expect(illegal_floating_point_literal_pattern)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:113:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:116:14 | LL | #[expect(clippy::almost_swapped)] | ^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:120:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:124:14 | LL | #[expect(clippy::bytes_nth)] | ^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:125:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:130:14 | LL | #[expect(clippy::if_same_then_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this lint expectation is unfulfilled - --> $DIR/expect_tool_lint_rfc_2383.rs:130:14 + --> $DIR/expect_tool_lint_rfc_2383.rs:136:14 | LL | #[expect(clippy::overly_complex_bool_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/explicit_auto_deref.fixed b/src/tools/clippy/tests/ui/explicit_auto_deref.fixed index 71a5ed96d..12158d0d1 100644 --- a/src/tools/clippy/tests/ui/explicit_auto_deref.fixed +++ b/src/tools/clippy/tests/ui/explicit_auto_deref.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(closure_lifetime_binder)] #![warn(clippy::explicit_auto_deref)] #![allow( @@ -207,7 +205,7 @@ fn main() { } } - f_str(&&ref_str); // `needless_borrow` will suggest removing both references + f_str(&ref_str); // `needless_borrow` will suggest removing both references f_str(&ref_str); // `needless_borrow` will suggest removing only one reference let x = &&40; @@ -295,4 +293,32 @@ fn main() { fn return_dyn_assoc<'a>(x: &'a &'a u32) -> &'a <&'a u32 as WithAssoc>::Assoc { *x } + + // Issue #11366 + let _: &mut u32 = match &mut Some(&mut 0u32) { + Some(x) => x, + None => panic!(), + }; + + // Issue #11474 + pub struct Variant { + pub anonymous: Variant0, + } + + pub union Variant0 { + pub anonymous: std::mem::ManuallyDrop, + } + + pub struct Variant00 { + pub anonymous: Variant000, + } + + pub union Variant000 { + pub val: i32, + } + + unsafe { + let mut p = core::mem::zeroed::(); + (*p.anonymous.anonymous).anonymous.val = 1; + } } diff --git a/src/tools/clippy/tests/ui/explicit_auto_deref.rs b/src/tools/clippy/tests/ui/explicit_auto_deref.rs index 9d0cafa15..dec021c18 100644 --- a/src/tools/clippy/tests/ui/explicit_auto_deref.rs +++ b/src/tools/clippy/tests/ui/explicit_auto_deref.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(closure_lifetime_binder)] #![warn(clippy::explicit_auto_deref)] #![allow( @@ -295,4 +293,32 @@ fn main() { fn return_dyn_assoc<'a>(x: &'a &'a u32) -> &'a <&'a u32 as WithAssoc>::Assoc { *x } + + // Issue #11366 + let _: &mut u32 = match &mut Some(&mut 0u32) { + Some(x) => &mut *x, + None => panic!(), + }; + + // Issue #11474 + pub struct Variant { + pub anonymous: Variant0, + } + + pub union Variant0 { + pub anonymous: std::mem::ManuallyDrop, + } + + pub struct Variant00 { + pub anonymous: Variant000, + } + + pub union Variant000 { + pub val: i32, + } + + unsafe { + let mut p = core::mem::zeroed::(); + (*p.anonymous.anonymous).anonymous.val = 1; + } } diff --git a/src/tools/clippy/tests/ui/explicit_auto_deref.stderr b/src/tools/clippy/tests/ui/explicit_auto_deref.stderr index afc311e3f..3d2a7b0d9 100644 --- a/src/tools/clippy/tests/ui/explicit_auto_deref.stderr +++ b/src/tools/clippy/tests/ui/explicit_auto_deref.stderr @@ -1,238 +1,245 @@ error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:70:19 + --> $DIR/explicit_auto_deref.rs:68:19 | LL | let _: &str = &*s; | ^^^ help: try: `&s` | = note: `-D clippy::explicit-auto-deref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::explicit_auto_deref)]` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:71:19 + --> $DIR/explicit_auto_deref.rs:69:19 | LL | let _: &str = &*{ String::new() }; | ^^^^^^^^^^^^^^^^^^^ help: try: `&{ String::new() }` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:72:19 + --> $DIR/explicit_auto_deref.rs:70:19 | LL | let _: &str = &mut *{ String::new() }; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut { String::new() }` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:76:11 + --> $DIR/explicit_auto_deref.rs:74:11 | LL | f_str(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:80:13 + --> $DIR/explicit_auto_deref.rs:78: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:83:24 + --> $DIR/explicit_auto_deref.rs:81:24 | LL | let _: &Box = &**b; | ^^^^ help: try: `&b` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:89:7 + --> $DIR/explicit_auto_deref.rs:87:7 | LL | c(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:95:9 + --> $DIR/explicit_auto_deref.rs:93:9 | LL | &**x | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:99:11 + --> $DIR/explicit_auto_deref.rs:97:11 | LL | { &**x } | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:103:9 + --> $DIR/explicit_auto_deref.rs:101:9 | LL | &**{ x } | ^^^^^^^^ help: try: `{ x }` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:107:9 + --> $DIR/explicit_auto_deref.rs:105:9 | LL | &***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:122:12 | LL | f1(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:125:12 + --> $DIR/explicit_auto_deref.rs:123:12 | LL | f2(&*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:124:12 | LL | f3(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:127:27 + --> $DIR/explicit_auto_deref.rs:125:27 | LL | f4.callable_str()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:128:12 + --> $DIR/explicit_auto_deref.rs:126:12 | LL | f5(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:129:12 + --> $DIR/explicit_auto_deref.rs:127:12 | LL | f6(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:130:27 + --> $DIR/explicit_auto_deref.rs:128:27 | LL | f7.callable_str()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:131:25 + --> $DIR/explicit_auto_deref.rs:129:25 | LL | f8.callable_t()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:132:12 + --> $DIR/explicit_auto_deref.rs:130:12 | LL | f9(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:133:13 + --> $DIR/explicit_auto_deref.rs:131:13 | LL | f10(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:134:26 + --> $DIR/explicit_auto_deref.rs:132:26 | LL | f11.callable_t()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:138:16 + --> $DIR/explicit_auto_deref.rs:136:16 | LL | let _ = S1(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:143:21 + --> $DIR/explicit_auto_deref.rs:141:21 | LL | let _ = S2 { s: &*s }; | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:159:30 + --> $DIR/explicit_auto_deref.rs:157:30 | LL | let _ = Self::S1(&**s); | ^^^^ help: try: `s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:160:35 + --> $DIR/explicit_auto_deref.rs:158:35 | LL | let _ = Self::S2 { s: &**s }; | ^^^^ help: try: `s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:163:20 + --> $DIR/explicit_auto_deref.rs:161:20 | LL | let _ = E1::S1(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:164:25 + --> $DIR/explicit_auto_deref.rs:162:25 | LL | let _ = E1::S2 { s: &*s }; | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:182:13 + --> $DIR/explicit_auto_deref.rs:180:13 | LL | let _ = (*b).foo; | ^^^^ help: try: `b` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:183: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:198:19 + --> $DIR/explicit_auto_deref.rs:196: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:200:19 + --> $DIR/explicit_auto_deref.rs:198: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:210:13 + --> $DIR/explicit_auto_deref.rs:208:12 | LL | f_str(&&*ref_str); // `needless_borrow` will suggest removing both references - | ^^^^^^^^ help: try: `ref_str` + | ^^^^^^^^^ help: try: `ref_str` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:211:12 + --> $DIR/explicit_auto_deref.rs:209: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:220:41 + --> $DIR/explicit_auto_deref.rs:218:41 | LL | let _ = || -> &'static str { return *s }; | ^^ help: try: `s` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:239:9 + --> $DIR/explicit_auto_deref.rs:237:9 | LL | &**x | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:262:8 + --> $DIR/explicit_auto_deref.rs:260:8 | LL | c1(*x); | ^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:265:20 + --> $DIR/explicit_auto_deref.rs:263:20 | LL | return *x; | ^^ help: try: `x` error: deref which would be done by auto-deref - --> $DIR/explicit_auto_deref.rs:267:9 + --> $DIR/explicit_auto_deref.rs:265:9 | LL | *x | ^^ help: try: `x` -error: aborting due to 39 previous errors +error: deref which would be done by auto-deref + --> $DIR/explicit_auto_deref.rs:299:20 + | +LL | Some(x) => &mut *x, + | ^^^^^^^ help: try: `x` + +error: aborting due to 40 previous errors diff --git a/src/tools/clippy/tests/ui/explicit_counter_loop.rs b/src/tools/clippy/tests/ui/explicit_counter_loop.rs index e02b8f62b..c25e79a36 100644 --- a/src/tools/clippy/tests/ui/explicit_counter_loop.rs +++ b/src/tools/clippy/tests/ui/explicit_counter_loop.rs @@ -1,26 +1,31 @@ #![warn(clippy::explicit_counter_loop)] #![allow(clippy::uninlined_format_args, clippy::useless_vec)] - +//@no-rustfix fn main() { let mut vec = vec![1, 2, 3, 4]; let mut _index = 0; for _v in &vec { + //~^ ERROR: the variable `_index` is used as a loop counter + //~| NOTE: `-D clippy::explicit-counter-loop` implied by `-D warnings` _index += 1 } let mut _index = 1; _index = 0; for _v in &vec { + //~^ ERROR: the variable `_index` is used as a loop counter _index += 1 } let mut _index = 0; for _v in &mut vec { + //~^ ERROR: the variable `_index` is used as a loop counter _index += 1; } let mut _index = 0; for _v in vec { + //~^ ERROR: the variable `_index` is used as a loop counter _index += 1; } @@ -108,6 +113,7 @@ mod issue_1219 { let text = "banana"; let mut count = 0; for ch in text.chars() { + //~^ ERROR: the variable `count` is used as a loop counter println!("{}", count); count += 1; if ch == 'a' { @@ -119,6 +125,7 @@ mod issue_1219 { let text = "banana"; let mut count = 0; for ch in text.chars() { + //~^ ERROR: the variable `count` is used as a loop counter println!("{}", count); count += 1; for i in 0..2 { @@ -177,6 +184,7 @@ mod issue_1670 { pub fn test() { let mut count = 0; for _i in 3..10 { + //~^ ERROR: the variable `count` is used as a loop counter count += 1; } } @@ -217,6 +225,7 @@ mod issue_7920 { // should suggest `enumerate` for _item in slice { + //~^ ERROR: the variable `idx_usize` is used as a loop counter if idx_usize == index_usize { break; } @@ -229,6 +238,8 @@ mod issue_7920 { // should suggest `zip` for _item in slice { + //~^ ERROR: the variable `idx_u32` is used as a loop counter + //~| NOTE: `idx_u32` is of type `u32`, making it ineligible for `Iterator::enumera if idx_u32 == index_u32 { break; } diff --git a/src/tools/clippy/tests/ui/explicit_counter_loop.stderr b/src/tools/clippy/tests/ui/explicit_counter_loop.stderr index 0677e4d78..aef979072 100644 --- a/src/tools/clippy/tests/ui/explicit_counter_loop.stderr +++ b/src/tools/clippy/tests/ui/explicit_counter_loop.stderr @@ -5,51 +5,52 @@ LL | for _v in &vec { | ^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter().enumerate()` | = note: `-D clippy::explicit-counter-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::explicit_counter_loop)]` error: the variable `_index` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:13:5 + --> $DIR/explicit_counter_loop.rs:15:5 | LL | for _v in &vec { | ^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter().enumerate()` error: the variable `_index` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:18:5 + --> $DIR/explicit_counter_loop.rs:21:5 | LL | for _v in &mut vec { | ^^^^^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter_mut().enumerate()` error: the variable `_index` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:23:5 + --> $DIR/explicit_counter_loop.rs:27:5 | LL | for _v in vec { | ^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.into_iter().enumerate()` error: the variable `count` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:110:9 + --> $DIR/explicit_counter_loop.rs:115:9 | LL | for ch in text.chars() { | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()` error: the variable `count` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:121:9 + --> $DIR/explicit_counter_loop.rs:127:9 | LL | for ch in text.chars() { | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()` error: the variable `count` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:179:9 + --> $DIR/explicit_counter_loop.rs:186:9 | LL | for _i in 3..10 { | ^^^^^^^^^^^^^^^ help: consider using: `for (count, _i) in (3..10).enumerate()` error: the variable `idx_usize` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:219:9 + --> $DIR/explicit_counter_loop.rs:227:9 | LL | for _item in slice { | ^^^^^^^^^^^^^^^^^^ help: consider using: `for (idx_usize, _item) in slice.iter().enumerate()` error: the variable `idx_u32` is used as a loop counter - --> $DIR/explicit_counter_loop.rs:231:9 + --> $DIR/explicit_counter_loop.rs:240:9 | LL | for _item in slice { | ^^^^^^^^^^^^^^^^^^ help: consider using: `for (idx_u32, _item) in (0_u32..).zip(slice.iter())` diff --git a/src/tools/clippy/tests/ui/explicit_deref_methods.fixed b/src/tools/clippy/tests/ui/explicit_deref_methods.fixed index 4c0b0d8f2..7b2dd2fe6 100644 --- a/src/tools/clippy/tests/ui/explicit_deref_methods.fixed +++ b/src/tools/clippy/tests/ui/explicit_deref_methods.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::explicit_deref_methods)] #![allow(unused_variables, unused_must_use)] #![allow( diff --git a/src/tools/clippy/tests/ui/explicit_deref_methods.rs b/src/tools/clippy/tests/ui/explicit_deref_methods.rs index bc5da35e5..eb52cfb0d 100644 --- a/src/tools/clippy/tests/ui/explicit_deref_methods.rs +++ b/src/tools/clippy/tests/ui/explicit_deref_methods.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::explicit_deref_methods)] #![allow(unused_variables, unused_must_use)] #![allow( diff --git a/src/tools/clippy/tests/ui/explicit_deref_methods.stderr b/src/tools/clippy/tests/ui/explicit_deref_methods.stderr index e4d2fe3a1..eb7059367 100644 --- a/src/tools/clippy/tests/ui/explicit_deref_methods.stderr +++ b/src/tools/clippy/tests/ui/explicit_deref_methods.stderr @@ -1,73 +1,74 @@ error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:55:19 + --> $DIR/explicit_deref_methods.rs:54:19 | LL | let b: &str = a.deref(); | ^^^^^^^^^ help: try: `&*a` | = note: `-D clippy::explicit-deref-methods` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::explicit_deref_methods)]` error: explicit `deref_mut` method call - --> $DIR/explicit_deref_methods.rs:57:23 + --> $DIR/explicit_deref_methods.rs:56:23 | LL | let b: &mut str = a.deref_mut(); | ^^^^^^^^^^^^^ help: try: `&mut **a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:60:39 + --> $DIR/explicit_deref_methods.rs:59:39 | LL | let b: String = format!("{}, {}", a.deref(), a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:60:50 + --> $DIR/explicit_deref_methods.rs:59:50 | LL | let b: String = format!("{}, {}", a.deref(), a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:62:20 + --> $DIR/explicit_deref_methods.rs:61:20 | LL | println!("{}", a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:65:11 + --> $DIR/explicit_deref_methods.rs:64:11 | LL | match a.deref() { | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:69:28 + --> $DIR/explicit_deref_methods.rs:68:28 | LL | let b: String = concat(a.deref()); | ^^^^^^^^^ help: try: `&*a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:71:13 + --> $DIR/explicit_deref_methods.rs:70:13 | LL | let b = just_return(a).deref(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `just_return(a)` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:73:28 + --> $DIR/explicit_deref_methods.rs:72: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:75:19 + --> $DIR/explicit_deref_methods.rs:74:19 | LL | let b: &str = a.deref().deref(); | ^^^^^^^^^^^^^^^^^ help: try: `&**a` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:78:13 + --> $DIR/explicit_deref_methods.rs:77:13 | LL | let b = opt_a.unwrap().deref(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*opt_a.unwrap()` error: explicit `deref` method call - --> $DIR/explicit_deref_methods.rs:115:31 + --> $DIR/explicit_deref_methods.rs:114:31 | LL | let b: &str = expr_deref!(a.deref()); | ^^^^^^^^^ help: try: `&*a` diff --git a/src/tools/clippy/tests/ui/explicit_into_iter_loop.fixed b/src/tools/clippy/tests/ui/explicit_into_iter_loop.fixed index dcef63403..2521bce6a 100644 --- a/src/tools/clippy/tests/ui/explicit_into_iter_loop.fixed +++ b/src/tools/clippy/tests/ui/explicit_into_iter_loop.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::explicit_into_iter_loop)] fn main() { diff --git a/src/tools/clippy/tests/ui/explicit_into_iter_loop.rs b/src/tools/clippy/tests/ui/explicit_into_iter_loop.rs index bc048ed30..9eac96d18 100644 --- a/src/tools/clippy/tests/ui/explicit_into_iter_loop.rs +++ b/src/tools/clippy/tests/ui/explicit_into_iter_loop.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::explicit_into_iter_loop)] fn main() { diff --git a/src/tools/clippy/tests/ui/explicit_into_iter_loop.stderr b/src/tools/clippy/tests/ui/explicit_into_iter_loop.stderr index fa89b884f..c03647ab4 100644 --- a/src/tools/clippy/tests/ui/explicit_into_iter_loop.stderr +++ b/src/tools/clippy/tests/ui/explicit_into_iter_loop.stderr @@ -1,37 +1,38 @@ error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:10:18 + --> $DIR/explicit_into_iter_loop.rs:9:18 | LL | for _ in iterator.into_iter() {} | ^^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `iterator` | = note: `-D clippy::explicit-into-iter-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::explicit_into_iter_loop)]` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:23:14 + --> $DIR/explicit_into_iter_loop.rs:22:14 | LL | for _ in t.into_iter() {} | ^^^^^^^^^^^^^ help: to write this more concisely, try: `&t` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:26:14 + --> $DIR/explicit_into_iter_loop.rs:25:14 | LL | for _ in r.into_iter() {} | ^^^^^^^^^^^^^ help: to write this more concisely, try: `r` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:34:14 + --> $DIR/explicit_into_iter_loop.rs:33:14 | LL | for _ in mr.into_iter() {} | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&*mr` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:46:14 + --> $DIR/explicit_into_iter_loop.rs:45:14 | LL | for _ in u.into_iter() {} | ^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut u` error: it is more concise to loop over containers instead of using explicit iteration methods - --> $DIR/explicit_into_iter_loop.rs:49:14 + --> $DIR/explicit_into_iter_loop.rs:48:14 | LL | for _ in mr.into_iter() {} | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut *mr` diff --git a/src/tools/clippy/tests/ui/explicit_iter_loop.fixed b/src/tools/clippy/tests/ui/explicit_iter_loop.fixed index 746ef813c..f08397def 100644 --- a/src/tools/clippy/tests/ui/explicit_iter_loop.fixed +++ b/src/tools/clippy/tests/ui/explicit_iter_loop.fixed @@ -1,10 +1,10 @@ -//@run-rustfix #![deny(clippy::explicit_iter_loop)] #![allow( clippy::linkedlist, clippy::similar_names, clippy::needless_borrow, clippy::deref_addrof, + clippy::unnecessary_mut_passed, dead_code )] @@ -21,15 +21,15 @@ fn main() { for _ in rvec {} let rmvec = &mut vec; - for _ in &*rmvec {} - for _ in &mut *rmvec {} + for _ in rmvec.iter() {} + for _ in rmvec.iter_mut() {} for _ in &vec {} // these are fine for _ in &mut vec {} // these are fine for _ in &[1, 2, 3] {} - for _ in &*(&mut [1, 2, 3]) {} + for _ in (&mut [1, 2, 3]).iter() {} for _ in &[0; 32] {} for _ in &[0; 33] {} diff --git a/src/tools/clippy/tests/ui/explicit_iter_loop.rs b/src/tools/clippy/tests/ui/explicit_iter_loop.rs index fba230ee0..2ee6825d4 100644 --- a/src/tools/clippy/tests/ui/explicit_iter_loop.rs +++ b/src/tools/clippy/tests/ui/explicit_iter_loop.rs @@ -1,10 +1,10 @@ -//@run-rustfix #![deny(clippy::explicit_iter_loop)] #![allow( clippy::linkedlist, clippy::similar_names, clippy::needless_borrow, clippy::deref_addrof, + clippy::unnecessary_mut_passed, dead_code )] diff --git a/src/tools/clippy/tests/ui/explicit_iter_loop.stderr b/src/tools/clippy/tests/ui/explicit_iter_loop.stderr index 94a264dce..725d9b63c 100644 --- a/src/tools/clippy/tests/ui/explicit_iter_loop.stderr +++ b/src/tools/clippy/tests/ui/explicit_iter_loop.stderr @@ -5,7 +5,7 @@ LL | for _ in vec.iter() {} | ^^^^^^^^^^ help: to write this more concisely, try: `&vec` | note: the lint level is defined here - --> $DIR/explicit_iter_loop.rs:2:9 + --> $DIR/explicit_iter_loop.rs:1:9 | LL | #![deny(clippy::explicit_iter_loop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,38 +22,12 @@ error: it is more concise to loop over references to containers instead of using LL | for _ in rvec.iter() {} | ^^^^^^^^^^^ help: to write this more concisely, try: `rvec` -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:24:14 - | -LL | for _ in rmvec.iter() {} - | ^^^^^^^^^^^^ help: to write this more concisely, try: `&*rmvec` - -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:25:14 - | -LL | for _ in rmvec.iter_mut() {} - | ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut *rmvec` - error: it is more concise to loop over references to containers instead of using explicit iteration methods --> $DIR/explicit_iter_loop.rs:30:14 | LL | for _ in [1, 2, 3].iter() {} | ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]` -error: it is more concise to loop over references to containers instead of using explicit iteration methods - --> $DIR/explicit_iter_loop.rs:32:14 - | -LL | for _ in (&mut [1, 2, 3]).iter() {} - | ^^^^^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&*(&mut [1, 2, 3])` - -error: the method `iter` doesn't need a mutable reference - --> $DIR/explicit_iter_loop.rs:32:14 - | -LL | for _ in (&mut [1, 2, 3]).iter() {} - | ^^^^^^^^^^^^^^^^ - | - = note: `-D clippy::unnecessary-mut-passed` implied by `-D warnings` - error: it is more concise to loop over references to containers instead of using explicit iteration methods --> $DIR/explicit_iter_loop.rs:34:14 | @@ -138,5 +112,5 @@ error: it is more concise to loop over references to containers instead of using LL | for _ in r.iter() {} | ^^^^^^^^ help: to write this more concisely, try: `r` -error: aborting due to 22 previous errors +error: aborting due to 18 previous errors diff --git a/src/tools/clippy/tests/ui/explicit_write.fixed b/src/tools/clippy/tests/ui/explicit_write.fixed index 213485bc2..77a910dc1 100644 --- a/src/tools/clippy/tests/ui/explicit_write.fixed +++ b/src/tools/clippy/tests/ui/explicit_write.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::explicit_write)] #![allow(unused_imports)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/explicit_write.rs b/src/tools/clippy/tests/ui/explicit_write.rs index 64acd7108..c77956264 100644 --- a/src/tools/clippy/tests/ui/explicit_write.rs +++ b/src/tools/clippy/tests/ui/explicit_write.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::explicit_write)] #![allow(unused_imports)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/explicit_write.stderr b/src/tools/clippy/tests/ui/explicit_write.stderr index b3aa7274c..26aad266b 100644 --- a/src/tools/clippy/tests/ui/explicit_write.stderr +++ b/src/tools/clippy/tests/ui/explicit_write.stderr @@ -1,79 +1,80 @@ error: use of `write!(stdout(), ...).unwrap()` - --> $DIR/explicit_write.rs:24:9 + --> $DIR/explicit_write.rs:23:9 | LL | write!(std::io::stdout(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `print!("test")` | = note: `-D clippy::explicit-write` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::explicit_write)]` error: use of `write!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:25:9 + --> $DIR/explicit_write.rs:24:9 | LL | write!(std::io::stderr(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprint!("test")` error: use of `writeln!(stdout(), ...).unwrap()` - --> $DIR/explicit_write.rs:26:9 + --> $DIR/explicit_write.rs:25:9 | LL | writeln!(std::io::stdout(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `println!("test")` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:27:9 + --> $DIR/explicit_write.rs:26:9 | LL | writeln!(std::io::stderr(), "test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("test")` error: use of `stdout().write_fmt(...).unwrap()` - --> $DIR/explicit_write.rs:28:9 + --> $DIR/explicit_write.rs:27: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:29:9 + --> $DIR/explicit_write.rs:28: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:32:9 + --> $DIR/explicit_write.rs:31:9 | -LL | writeln!(std::io::stdout(), "test/ntest").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `println!("test/ntest")` +LL | writeln!(std::io::stdout(), "test\ntest").unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `println!("test\ntest")` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:33:9 + --> $DIR/explicit_write.rs:32:9 | -LL | writeln!(std::io::stderr(), "test/ntest").unwrap(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("test/ntest")` +LL | writeln!(std::io::stderr(), "test\ntest").unwrap(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("test\ntest")` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:36:9 + --> $DIR/explicit_write.rs:35:9 | LL | writeln!(std::io::stderr(), "with {}", value).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("with {}", value)` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:37:9 + --> $DIR/explicit_write.rs:36: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:38:9 + --> $DIR/explicit_write.rs:37:9 | LL | writeln!(std::io::stderr(), "with {value}").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("with {value}")` error: use of `writeln!(stderr(), ...).unwrap()` - --> $DIR/explicit_write.rs:39:9 + --> $DIR/explicit_write.rs:38: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:41:9 + --> $DIR/explicit_write.rs:40:9 | LL | writeln!(std::io::stderr(), "{:w$}", value, w = width).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("{:w$}", value, w = width)` diff --git a/src/tools/clippy/tests/ui/extend_with_drain.fixed b/src/tools/clippy/tests/ui/extend_with_drain.fixed index 594f2f6d4..856c1a42d 100644 --- a/src/tools/clippy/tests/ui/extend_with_drain.fixed +++ b/src/tools/clippy/tests/ui/extend_with_drain.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::extend_with_drain)] #![allow(clippy::iter_with_drain)] use std::collections::BinaryHeap; diff --git a/src/tools/clippy/tests/ui/extend_with_drain.rs b/src/tools/clippy/tests/ui/extend_with_drain.rs index 3e2ad0205..7d5380976 100644 --- a/src/tools/clippy/tests/ui/extend_with_drain.rs +++ b/src/tools/clippy/tests/ui/extend_with_drain.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::extend_with_drain)] #![allow(clippy::iter_with_drain)] use std::collections::BinaryHeap; diff --git a/src/tools/clippy/tests/ui/extend_with_drain.stderr b/src/tools/clippy/tests/ui/extend_with_drain.stderr index eb2dd304d..e0bd5a620 100644 --- a/src/tools/clippy/tests/ui/extend_with_drain.stderr +++ b/src/tools/clippy/tests/ui/extend_with_drain.stderr @@ -1,25 +1,26 @@ error: use of `extend` instead of `append` for adding the full range of a second vector - --> $DIR/extend_with_drain.rs:9:5 + --> $DIR/extend_with_drain.rs:8:5 | LL | vec2.extend(vec1.drain(..)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec2.append(&mut vec1)` | = note: `-D clippy::extend-with-drain` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::extend_with_drain)]` error: use of `extend` instead of `append` for adding the full range of a second vector - --> $DIR/extend_with_drain.rs:14:5 + --> $DIR/extend_with_drain.rs:13:5 | LL | vec4.extend(vec3.drain(..)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec4.append(&mut vec3)` error: use of `extend` instead of `append` for adding the full range of a second vector - --> $DIR/extend_with_drain.rs:18:5 + --> $DIR/extend_with_drain.rs:17:5 | LL | vec11.extend(return_vector().drain(..)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec11.append(&mut return_vector())` error: use of `extend` instead of `append` for adding the full range of a second vector - --> $DIR/extend_with_drain.rs:49:5 + --> $DIR/extend_with_drain.rs:48:5 | LL | y.extend(ref_x.drain(..)); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `y.append(ref_x)` diff --git a/src/tools/clippy/tests/ui/extra_unused_lifetimes.rs b/src/tools/clippy/tests/ui/extra_unused_lifetimes.rs index 50abe89da..cdfaf8d3a 100644 --- a/src/tools/clippy/tests/ui/extra_unused_lifetimes.rs +++ b/src/tools/clippy/tests/ui/extra_unused_lifetimes.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![allow( unused, diff --git a/src/tools/clippy/tests/ui/extra_unused_lifetimes.stderr b/src/tools/clippy/tests/ui/extra_unused_lifetimes.stderr index 26ebc3976..8790fe5a5 100644 --- a/src/tools/clippy/tests/ui/extra_unused_lifetimes.stderr +++ b/src/tools/clippy/tests/ui/extra_unused_lifetimes.stderr @@ -5,6 +5,7 @@ LL | fn unused_lt<'a>(x: u8) {} | ^^ | = note: `-D clippy::extra-unused-lifetimes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::extra_unused_lifetimes)]` error: this lifetime isn't used in the function definition --> $DIR/extra_unused_lifetimes.rs:46:10 diff --git a/src/tools/clippy/tests/ui/extra_unused_type_parameters.fixed b/src/tools/clippy/tests/ui/extra_unused_type_parameters.fixed index 8420df663..c9bebabdf 100644 --- a/src/tools/clippy/tests/ui/extra_unused_type_parameters.fixed +++ b/src/tools/clippy/tests/ui/extra_unused_type_parameters.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused, clippy::needless_lifetimes)] #![warn(clippy::extra_unused_type_parameters)] @@ -114,4 +113,19 @@ with_span!( } ); +mod issue11302 { + use std::fmt::Debug; + use std::marker::PhantomData; + + #[derive(Debug)] + struct Wrapper(PhantomData); + + fn store(v: &mut Vec>) + where + Wrapper: Debug, + { + v.push(Box::new(Wrapper(PhantomData))); + } +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/extra_unused_type_parameters.rs b/src/tools/clippy/tests/ui/extra_unused_type_parameters.rs index f63535d7a..1bc0047ad 100644 --- a/src/tools/clippy/tests/ui/extra_unused_type_parameters.rs +++ b/src/tools/clippy/tests/ui/extra_unused_type_parameters.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused, clippy::needless_lifetimes)] #![warn(clippy::extra_unused_type_parameters)] @@ -114,4 +113,19 @@ with_span!( } ); +mod issue11302 { + use std::fmt::Debug; + use std::marker::PhantomData; + + #[derive(Debug)] + struct Wrapper(PhantomData); + + fn store(v: &mut Vec>) + where + Wrapper: Debug, + { + v.push(Box::new(Wrapper(PhantomData))); + } +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/extra_unused_type_parameters.stderr b/src/tools/clippy/tests/ui/extra_unused_type_parameters.stderr index b5277d498..9a179076c 100644 --- a/src/tools/clippy/tests/ui/extra_unused_type_parameters.stderr +++ b/src/tools/clippy/tests/ui/extra_unused_type_parameters.stderr @@ -1,25 +1,26 @@ error: type parameter `T` goes unused in function definition - --> $DIR/extra_unused_type_parameters.rs:10:13 + --> $DIR/extra_unused_type_parameters.rs:9:13 | LL | fn unused_ty(x: u8) { | ^^^ help: consider removing the parameter | = note: `-D clippy::extra-unused-type-parameters` implied by `-D warnings` + = 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:14:16 + --> $DIR/extra_unused_type_parameters.rs:13: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:18:21 + --> $DIR/extra_unused_type_parameters.rs:17: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:30:19 + --> $DIR/extra_unused_type_parameters.rs:29:19 | LL | fn unused_bounded(x: U) { | ^^^^^^^^^^^^ ^^^^^^^^^^^^ @@ -31,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:34:16 + --> $DIR/extra_unused_type_parameters.rs:33:16 | LL | fn some_unused, E>(b: B, c: C) { | ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -43,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:59:22 + --> $DIR/extra_unused_type_parameters.rs:58: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:81:17 + --> $DIR/extra_unused_type_parameters.rs:80: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:94:56 + --> $DIR/extra_unused_type_parameters.rs:93:56 | LL | fn unused_with_priv_trait_bound() { | ^^^ help: consider removing the parameter diff --git a/src/tools/clippy/tests/ui/extra_unused_type_parameters_unfixable.rs b/src/tools/clippy/tests/ui/extra_unused_type_parameters_unfixable.rs index 10b39aa8f..65b53eb2e 100644 --- a/src/tools/clippy/tests/ui/extra_unused_type_parameters_unfixable.rs +++ b/src/tools/clippy/tests/ui/extra_unused_type_parameters_unfixable.rs @@ -1,6 +1,7 @@ #![warn(clippy::extra_unused_type_parameters)] fn unused_where_clause(x: U) +//~^ ERROR: type parameter `T` goes unused in function definition where T: Default, { @@ -8,6 +9,7 @@ where } fn unused_multi_where_clause(x: U) +//~^ ERROR: type parameters go unused in function definition: T, V where T: Default, { @@ -15,6 +17,7 @@ where } fn unused_all_where_clause() +//~^ ERROR: type parameters go unused in function definition: T, U, V where T: Default, { diff --git a/src/tools/clippy/tests/ui/extra_unused_type_parameters_unfixable.stderr b/src/tools/clippy/tests/ui/extra_unused_type_parameters_unfixable.stderr index a9580cc89..a216c4363 100644 --- a/src/tools/clippy/tests/ui/extra_unused_type_parameters_unfixable.stderr +++ b/src/tools/clippy/tests/ui/extra_unused_type_parameters_unfixable.stderr @@ -6,9 +6,10 @@ LL | fn unused_where_clause(x: U) | = help: consider removing the parameter = note: `-D clippy::extra-unused-type-parameters` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::extra_unused_type_parameters)]` error: type parameters go unused in function definition: T, V - --> $DIR/extra_unused_type_parameters_unfixable.rs:10:30 + --> $DIR/extra_unused_type_parameters_unfixable.rs:11:30 | LL | fn unused_multi_where_clause(x: U) | ^ ^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | fn unused_multi_where_clause(x: U) = help: consider removing the parameters error: type parameters go unused in function definition: T, U, V - --> $DIR/extra_unused_type_parameters_unfixable.rs:17:28 + --> $DIR/extra_unused_type_parameters_unfixable.rs:19:28 | LL | fn unused_all_where_clause() | ^ ^^^^^^^^^^ ^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/fallible_impl_from.rs b/src/tools/clippy/tests/ui/fallible_impl_from.rs index fb6e8ec70..a81e51fca 100644 --- a/src/tools/clippy/tests/ui/fallible_impl_from.rs +++ b/src/tools/clippy/tests/ui/fallible_impl_from.rs @@ -4,6 +4,7 @@ // docs example struct Foo(i32); impl From for Foo { + //~^ ERROR: consider implementing `TryFrom` instead fn from(s: String) -> Self { Foo(s.parse().unwrap()) } @@ -25,6 +26,7 @@ impl From for Valid { struct Invalid; impl From for Invalid { + //~^ ERROR: consider implementing `TryFrom` instead fn from(i: usize) -> Invalid { if i != 42 { panic!(); @@ -34,6 +36,7 @@ impl From for Invalid { } impl From> for Invalid { + //~^ ERROR: consider implementing `TryFrom` instead fn from(s: Option) -> Invalid { let s = s.unwrap(); if !s.is_empty() { @@ -52,6 +55,7 @@ impl ProjStrTrait for Box { type ProjString = String; } impl<'a> From<&'a mut as ProjStrTrait>::ProjString> for Invalid { + //~^ ERROR: consider implementing `TryFrom` instead fn from(s: &'a mut as ProjStrTrait>::ProjString) -> Invalid { if s.parse::().ok().unwrap() != 42 { panic!("{:?}", s); diff --git a/src/tools/clippy/tests/ui/fallible_impl_from.stderr b/src/tools/clippy/tests/ui/fallible_impl_from.stderr index 21761484f..96074ca89 100644 --- a/src/tools/clippy/tests/ui/fallible_impl_from.stderr +++ b/src/tools/clippy/tests/ui/fallible_impl_from.stderr @@ -2,6 +2,7 @@ error: consider implementing `TryFrom` instead --> $DIR/fallible_impl_from.rs:6:1 | LL | / impl From for Foo { +LL | | LL | | fn from(s: String) -> Self { LL | | Foo(s.parse().unwrap()) LL | | } @@ -10,7 +11,7 @@ LL | | } | = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail note: potential failure(s) - --> $DIR/fallible_impl_from.rs:8:13 + --> $DIR/fallible_impl_from.rs:9:13 | LL | Foo(s.parse().unwrap()) | ^^^^^^^^^^^^^^^^^^ @@ -21,12 +22,12 @@ LL | #![deny(clippy::fallible_impl_from)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider implementing `TryFrom` instead - --> $DIR/fallible_impl_from.rs:27:1 + --> $DIR/fallible_impl_from.rs:28:1 | LL | / impl From for Invalid { +LL | | LL | | fn from(i: usize) -> Invalid { LL | | if i != 42 { -LL | | panic!(); ... | LL | | } LL | | } @@ -34,19 +35,19 @@ LL | | } | = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail note: potential failure(s) - --> $DIR/fallible_impl_from.rs:30:13 + --> $DIR/fallible_impl_from.rs:32:13 | LL | panic!(); | ^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: consider implementing `TryFrom` instead - --> $DIR/fallible_impl_from.rs:36:1 + --> $DIR/fallible_impl_from.rs:38:1 | LL | / impl From> for Invalid { +LL | | LL | | fn from(s: Option) -> Invalid { LL | | let s = s.unwrap(); -LL | | if !s.is_empty() { ... | LL | | } LL | | } @@ -54,7 +55,7 @@ LL | | } | = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail note: potential failure(s) - --> $DIR/fallible_impl_from.rs:38:17 + --> $DIR/fallible_impl_from.rs:41:17 | LL | let s = s.unwrap(); | ^^^^^^^^^^ @@ -68,12 +69,12 @@ LL | panic!("{:?}", s); = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: consider implementing `TryFrom` instead - --> $DIR/fallible_impl_from.rs:54:1 + --> $DIR/fallible_impl_from.rs:57:1 | LL | / impl<'a> From<&'a mut as ProjStrTrait>::ProjString> for Invalid { +LL | | LL | | fn from(s: &'a mut as ProjStrTrait>::ProjString) -> Invalid { LL | | if s.parse::().ok().unwrap() != 42 { -LL | | panic!("{:?}", s); ... | LL | | } LL | | } @@ -81,7 +82,7 @@ LL | | } | = help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail note: potential failure(s) - --> $DIR/fallible_impl_from.rs:56:12 + --> $DIR/fallible_impl_from.rs:60:12 | LL | if s.parse::().ok().unwrap() != 42 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/field_reassign_with_default.rs b/src/tools/clippy/tests/ui/field_reassign_with_default.rs index d6df114b8..2045b1eeb 100644 --- a/src/tools/clippy/tests/ui/field_reassign_with_default.rs +++ b/src/tools/clippy/tests/ui/field_reassign_with_default.rs @@ -1,5 +1,5 @@ -//@aux-build:proc_macro_derive.rs:proc-macro -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macro_derive.rs +//@aux-build:proc_macros.rs #![warn(clippy::field_reassign_with_default)] diff --git a/src/tools/clippy/tests/ui/field_reassign_with_default.stderr b/src/tools/clippy/tests/ui/field_reassign_with_default.stderr index da74f9ef9..a8cf84bd4 100644 --- a/src/tools/clippy/tests/ui/field_reassign_with_default.stderr +++ b/src/tools/clippy/tests/ui/field_reassign_with_default.stderr @@ -10,6 +10,7 @@ note: consider initializing the variable with `main::A { i: 42, ..Default::defau LL | let mut a: A = Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::field-reassign-with-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::field_reassign_with_default)]` error: field assignment outside of initializer for an instance created with Default::default() --> $DIR/field_reassign_with_default.rs:96:5 diff --git a/src/tools/clippy/tests/ui/filetype_is_file.rs b/src/tools/clippy/tests/ui/filetype_is_file.rs index d3ad36e40..9e8a4c043 100644 --- a/src/tools/clippy/tests/ui/filetype_is_file.rs +++ b/src/tools/clippy/tests/ui/filetype_is_file.rs @@ -7,16 +7,19 @@ fn main() -> std::io::Result<()> { // !filetype.is_dir() if fs::metadata("foo.txt")?.file_type().is_file() { + //~^ ERROR: `FileType::is_file()` only covers regular files // read file } // positive of filetype.is_dir() if !fs::metadata("foo.txt")?.file_type().is_file() { + //~^ ERROR: `!FileType::is_file()` only denies regular files // handle dir } // false positive of filetype.is_dir() if !fs::metadata("foo.txt")?.file_type().is_file().bitor(true) { + //~^ ERROR: `FileType::is_file()` only covers regular files // ... } diff --git a/src/tools/clippy/tests/ui/filetype_is_file.stderr b/src/tools/clippy/tests/ui/filetype_is_file.stderr index 36142deb3..8876ad5c9 100644 --- a/src/tools/clippy/tests/ui/filetype_is_file.stderr +++ b/src/tools/clippy/tests/ui/filetype_is_file.stderr @@ -6,9 +6,10 @@ LL | if fs::metadata("foo.txt")?.file_type().is_file() { | = help: use `!FileType::is_dir()` instead = note: `-D clippy::filetype-is-file` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filetype_is_file)]` error: `!FileType::is_file()` only denies regular files - --> $DIR/filetype_is_file.rs:14:8 + --> $DIR/filetype_is_file.rs:15:8 | LL | if !fs::metadata("foo.txt")?.file_type().is_file() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | if !fs::metadata("foo.txt")?.file_type().is_file() { = help: use `FileType::is_dir()` instead error: `FileType::is_file()` only covers regular files - --> $DIR/filetype_is_file.rs:19:9 + --> $DIR/filetype_is_file.rs:21:9 | LL | if !fs::metadata("foo.txt")?.file_type().is_file().bitor(true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/filter_map_bool_then.fixed b/src/tools/clippy/tests/ui/filter_map_bool_then.fixed index e5c9f783f..6a1b81fdb 100644 --- a/src/tools/clippy/tests/ui/filter_map_bool_then.fixed +++ b/src/tools/clippy/tests/ui/filter_map_bool_then.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow( clippy::clone_on_copy, clippy::map_identity, @@ -56,3 +55,27 @@ fn main() { fn issue11309<'a>(iter: impl Iterator) -> Vec<&'a str> { iter.filter_map(|(_, s): (&str, _)| Some(s)).collect() } + +fn issue11503() { + let bools: &[bool] = &[true, false, false, true]; + let _: Vec = bools.iter().enumerate().filter(|&(i, b)| *b).map(|(i, b)| i).collect(); + + // 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(); + + // 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(); + + // Should also suggest derefs when going through a custom deref + struct DerefToBool; + impl std::ops::Deref for DerefToBool { + type Target = bool; + fn deref(&self) -> &Self::Target { + &true + } + } + let bools: &[&&DerefToBool] = &[&&DerefToBool]; + let _: Vec = bools.iter().enumerate().filter(|&(i, b)| ****b).map(|(i, b)| i).collect(); +} diff --git a/src/tools/clippy/tests/ui/filter_map_bool_then.rs b/src/tools/clippy/tests/ui/filter_map_bool_then.rs index 7c9b99df7..a41e88f88 100644 --- a/src/tools/clippy/tests/ui/filter_map_bool_then.rs +++ b/src/tools/clippy/tests/ui/filter_map_bool_then.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow( clippy::clone_on_copy, clippy::map_identity, @@ -56,3 +55,27 @@ fn main() { fn issue11309<'a>(iter: impl Iterator) -> Vec<&'a str> { iter.filter_map(|(_, s): (&str, _)| Some(s)).collect() } + +fn issue11503() { + let bools: &[bool] = &[true, false, false, true]; + let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); + + // 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(); + + // 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(); + + // Should also suggest derefs when going through a custom deref + struct DerefToBool; + impl std::ops::Deref for DerefToBool { + type Target = bool; + fn deref(&self) -> &Self::Target { + &true + } + } + let bools: &[&&DerefToBool] = &[&&DerefToBool]; + let _: Vec = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect(); +} diff --git a/src/tools/clippy/tests/ui/filter_map_bool_then.stderr b/src/tools/clippy/tests/ui/filter_map_bool_then.stderr index fffa5252e..fab698791 100644 --- a/src/tools/clippy/tests/ui/filter_map_bool_then.stderr +++ b/src/tools/clippy/tests/ui/filter_map_bool_then.stderr @@ -1,40 +1,65 @@ error: usage of `bool::then` in `filter_map` - --> $DIR/filter_map_bool_then.rs:20:22 + --> $DIR/filter_map_bool_then.rs:19:22 | LL | v.clone().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)` | = note: `-D clippy::filter-map-bool-then` implied by `-D warnings` + = 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:21:27 + --> $DIR/filter_map_bool_then.rs:20: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:24:10 + --> $DIR/filter_map_bool_then.rs:23: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:28:10 + --> $DIR/filter_map_bool_then.rs:27: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:32:10 + --> $DIR/filter_map_bool_then.rs:31: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:38:22 + --> $DIR/filter_map_bool_then.rs:37: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: aborting due to 6 previous errors +error: usage of `bool::then` in `filter_map` + --> $DIR/filter_map_bool_then.rs:61: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 + | +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 + | +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 + | +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: aborting due to 10 previous errors diff --git a/src/tools/clippy/tests/ui/filter_map_identity.fixed b/src/tools/clippy/tests/ui/filter_map_identity.fixed index 44665b451..ad438afac 100644 --- a/src/tools/clippy/tests/ui/filter_map_identity.fixed +++ b/src/tools/clippy/tests/ui/filter_map_identity.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_imports, clippy::needless_return)] #![warn(clippy::filter_map_identity)] diff --git a/src/tools/clippy/tests/ui/filter_map_identity.rs b/src/tools/clippy/tests/ui/filter_map_identity.rs index 9832acb01..d74232768 100644 --- a/src/tools/clippy/tests/ui/filter_map_identity.rs +++ b/src/tools/clippy/tests/ui/filter_map_identity.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_imports, clippy::needless_return)] #![warn(clippy::filter_map_identity)] diff --git a/src/tools/clippy/tests/ui/filter_map_identity.stderr b/src/tools/clippy/tests/ui/filter_map_identity.stderr index 43c9fdca4..a08477695 100644 --- a/src/tools/clippy/tests/ui/filter_map_identity.stderr +++ b/src/tools/clippy/tests/ui/filter_map_identity.stderr @@ -1,25 +1,26 @@ error: use of `filter_map` with an identity function - --> $DIR/filter_map_identity.rs:8:22 + --> $DIR/filter_map_identity.rs:6:22 | LL | let _ = iterator.filter_map(|x| x); | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` | = note: `-D clippy::filter-map-identity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filter_map_identity)]` error: use of `filter_map` with an identity function - --> $DIR/filter_map_identity.rs:11:22 + --> $DIR/filter_map_identity.rs:9:22 | 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:15:22 + --> $DIR/filter_map_identity.rs:13:22 | LL | let _ = iterator.filter_map(identity); | ^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> $DIR/filter_map_identity.rs:18:22 + --> $DIR/filter_map_identity.rs:16:22 | LL | let _ = iterator.filter_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` diff --git a/src/tools/clippy/tests/ui/filter_map_next.rs b/src/tools/clippy/tests/ui/filter_map_next.rs index dbeb23543..9077b8fca 100644 --- a/src/tools/clippy/tests/ui/filter_map_next.rs +++ b/src/tools/clippy/tests/ui/filter_map_next.rs @@ -5,6 +5,8 @@ fn main() { #[rustfmt::skip] let _: Option = vec![1, 2, 3, 4, 5, 6] + //~^ ERROR: called `filter_map(..).next()` on an `Iterator`. This is more succinctly e + //~| NOTE: `-D clippy::filter-map-next` implied by `-D warnings` .into_iter() .filter_map(|x| { if x == 2 { diff --git a/src/tools/clippy/tests/ui/filter_map_next.stderr b/src/tools/clippy/tests/ui/filter_map_next.stderr index ddc982c93..184155391 100644 --- a/src/tools/clippy/tests/ui/filter_map_next.stderr +++ b/src/tools/clippy/tests/ui/filter_map_next.stderr @@ -3,15 +3,16 @@ error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly | LL | let _: Option = vec![1, 2, 3, 4, 5, 6] | __________________________^ +LL | | +LL | | LL | | .into_iter() -LL | | .filter_map(|x| { -LL | | if x == 2 { ... | LL | | }) LL | | .next(); | |_______________^ | = note: `-D clippy::filter-map-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filter_map_next)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/filter_map_next_fixable.fixed b/src/tools/clippy/tests/ui/filter_map_next_fixable.fixed index efb37f8b1..193ac3aea 100644 --- a/src/tools/clippy/tests/ui/filter_map_next_fixable.fixed +++ b/src/tools/clippy/tests/ui/filter_map_next_fixable.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all, clippy::pedantic)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/filter_map_next_fixable.rs b/src/tools/clippy/tests/ui/filter_map_next_fixable.rs index b10e20d35..dab8d2898 100644 --- a/src/tools/clippy/tests/ui/filter_map_next_fixable.rs +++ b/src/tools/clippy/tests/ui/filter_map_next_fixable.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all, clippy::pedantic)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr b/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr index 26d9c5e19..0edf4e6e0 100644 --- a/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr +++ b/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr @@ -1,13 +1,14 @@ error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead - --> $DIR/filter_map_next_fixable.rs:9:32 + --> $DIR/filter_map_next_fixable.rs:7:32 | LL | let element: Option = a.iter().filter_map(|s| s.parse().ok()).next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.iter().find_map(|s| s.parse().ok())` | = note: `-D clippy::filter-map-next` implied by `-D warnings` + = 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:22:26 + --> $DIR/filter_map_next_fixable.rs:20: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/src/tools/clippy/tests/ui/flat_map_identity.fixed b/src/tools/clippy/tests/ui/flat_map_identity.fixed index 97091d6f1..c142cf719 100644 --- a/src/tools/clippy/tests/ui/flat_map_identity.fixed +++ b/src/tools/clippy/tests/ui/flat_map_identity.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_imports, clippy::needless_return)] #![warn(clippy::flat_map_identity)] diff --git a/src/tools/clippy/tests/ui/flat_map_identity.rs b/src/tools/clippy/tests/ui/flat_map_identity.rs index 5607683a5..8505ba900 100644 --- a/src/tools/clippy/tests/ui/flat_map_identity.rs +++ b/src/tools/clippy/tests/ui/flat_map_identity.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_imports, clippy::needless_return)] #![warn(clippy::flat_map_identity)] diff --git a/src/tools/clippy/tests/ui/flat_map_identity.stderr b/src/tools/clippy/tests/ui/flat_map_identity.stderr index e776c9fdf..d6fcc14fc 100644 --- a/src/tools/clippy/tests/ui/flat_map_identity.stderr +++ b/src/tools/clippy/tests/ui/flat_map_identity.stderr @@ -1,19 +1,20 @@ error: use of `flat_map` with an identity function - --> $DIR/flat_map_identity.rs:10:22 + --> $DIR/flat_map_identity.rs:8:22 | LL | let _ = iterator.flat_map(|x| x); | ^^^^^^^^^^^^^^^ help: try: `flatten()` | = note: `-D clippy::flat-map-identity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::flat_map_identity)]` error: use of `flat_map` with an identity function - --> $DIR/flat_map_identity.rs:13:22 + --> $DIR/flat_map_identity.rs:11:22 | LL | let _ = iterator.flat_map(convert::identity); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `flat_map` with an identity function - --> $DIR/flat_map_identity.rs:16:22 + --> $DIR/flat_map_identity.rs:14:22 | LL | let _ = iterator.flat_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` diff --git a/src/tools/clippy/tests/ui/flat_map_option.fixed b/src/tools/clippy/tests/ui/flat_map_option.fixed index eeab864c4..e08d9a145 100644 --- a/src/tools/clippy/tests/ui/flat_map_option.fixed +++ b/src/tools/clippy/tests/ui/flat_map_option.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::flat_map_option)] #![allow(clippy::redundant_closure, clippy::unnecessary_filter_map)] diff --git a/src/tools/clippy/tests/ui/flat_map_option.rs b/src/tools/clippy/tests/ui/flat_map_option.rs index ebc389f7f..4d0f32ac0 100644 --- a/src/tools/clippy/tests/ui/flat_map_option.rs +++ b/src/tools/clippy/tests/ui/flat_map_option.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::flat_map_option)] #![allow(clippy::redundant_closure, clippy::unnecessary_filter_map)] diff --git a/src/tools/clippy/tests/ui/flat_map_option.stderr b/src/tools/clippy/tests/ui/flat_map_option.stderr index a9d8056de..e0a59daf6 100644 --- a/src/tools/clippy/tests/ui/flat_map_option.stderr +++ b/src/tools/clippy/tests/ui/flat_map_option.stderr @@ -1,13 +1,14 @@ error: used `flat_map` where `filter_map` could be used instead - --> $DIR/flat_map_option.rs:8:24 + --> $DIR/flat_map_option.rs:7:24 | LL | let _ = [1].iter().flat_map(c); | ^^^^^^^^ help: try: `filter_map` | = note: `-D clippy::flat-map-option` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::flat_map_option)]` error: used `flat_map` where `filter_map` could be used instead - --> $DIR/flat_map_option.rs:9:24 + --> $DIR/flat_map_option.rs:8:24 | LL | let _ = [1].iter().flat_map(Some); | ^^^^^^^^ help: try: `filter_map` diff --git a/src/tools/clippy/tests/ui/float_arithmetic.rs b/src/tools/clippy/tests/ui/float_arithmetic.rs index a928c35e8..1647273c4 100644 --- a/src/tools/clippy/tests/ui/float_arithmetic.rs +++ b/src/tools/clippy/tests/ui/float_arithmetic.rs @@ -13,40 +13,58 @@ fn main() { let mut f = 1.0f32; f * 2.0; + //~^ ERROR: floating-point arithmetic detected + //~| NOTE: `-D clippy::float-arithmetic` implied by `-D warnings` 1.0 + f; + //~^ ERROR: floating-point arithmetic detected f * 2.0; + //~^ ERROR: floating-point arithmetic detected f / 2.0; + //~^ ERROR: floating-point arithmetic detected f - 2.0 * 4.2; + //~^ ERROR: floating-point arithmetic detected -f; + //~^ ERROR: floating-point arithmetic detected f += 1.0; + //~^ ERROR: floating-point arithmetic detected f -= 1.0; + //~^ ERROR: floating-point arithmetic detected f *= 2.0; + //~^ ERROR: floating-point arithmetic detected f /= 2.0; + //~^ ERROR: floating-point arithmetic detected } // also warn about floating point arith with references involved pub fn float_arith_ref() { 3.1_f32 + &1.2_f32; + //~^ ERROR: floating-point arithmetic detected &3.4_f32 + 1.5_f32; + //~^ ERROR: floating-point arithmetic detected &3.5_f32 + &1.3_f32; + //~^ ERROR: floating-point arithmetic detected } pub fn float_foo(f: &f32) -> f32 { let a = 5.1; a + f + //~^ ERROR: floating-point arithmetic detected } pub fn float_bar(f1: &f32, f2: &f32) -> f32 { f1 + f2 + //~^ ERROR: floating-point arithmetic detected } pub fn float_baz(f1: f32, f2: &f32) -> f32 { f1 + f2 + //~^ ERROR: floating-point arithmetic detected } pub fn float_qux(f1: f32, f2: f32) -> f32 { (&f1 + &f2) + //~^ ERROR: floating-point arithmetic detected } diff --git a/src/tools/clippy/tests/ui/float_arithmetic.stderr b/src/tools/clippy/tests/ui/float_arithmetic.stderr index 1ceffb35b..da4ca9767 100644 --- a/src/tools/clippy/tests/ui/float_arithmetic.stderr +++ b/src/tools/clippy/tests/ui/float_arithmetic.stderr @@ -5,99 +5,100 @@ LL | f * 2.0; | ^^^^^^^ | = note: `-D clippy::float-arithmetic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::float_arithmetic)]` error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:17:5 + --> $DIR/float_arithmetic.rs:19:5 | LL | 1.0 + f; | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:18:5 + --> $DIR/float_arithmetic.rs:21:5 | LL | f * 2.0; | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:19:5 + --> $DIR/float_arithmetic.rs:23:5 | LL | f / 2.0; | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:20:5 + --> $DIR/float_arithmetic.rs:25:5 | LL | f - 2.0 * 4.2; | ^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:21:5 + --> $DIR/float_arithmetic.rs:27:5 | LL | -f; | ^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:23:5 + --> $DIR/float_arithmetic.rs:30:5 | LL | f += 1.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:24:5 + --> $DIR/float_arithmetic.rs:32:5 | LL | f -= 1.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:25:5 + --> $DIR/float_arithmetic.rs:34:5 | LL | f *= 2.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:26:5 + --> $DIR/float_arithmetic.rs:36:5 | LL | f /= 2.0; | ^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:32:5 + --> $DIR/float_arithmetic.rs:43:5 | LL | 3.1_f32 + &1.2_f32; | ^^^^^^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:33:5 + --> $DIR/float_arithmetic.rs:45:5 | LL | &3.4_f32 + 1.5_f32; | ^^^^^^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:34:5 + --> $DIR/float_arithmetic.rs:47:5 | LL | &3.5_f32 + &1.3_f32; | ^^^^^^^^^^^^^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:39:5 + --> $DIR/float_arithmetic.rs:53:5 | LL | a + f | ^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:43:5 + --> $DIR/float_arithmetic.rs:58:5 | LL | f1 + f2 | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:47:5 + --> $DIR/float_arithmetic.rs:63:5 | LL | f1 + f2 | ^^^^^^^ error: floating-point arithmetic detected - --> $DIR/float_arithmetic.rs:51:5 + --> $DIR/float_arithmetic.rs:68:5 | LL | (&f1 + &f2) | ^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/float_cmp.rs b/src/tools/clippy/tests/ui/float_cmp.rs index a34458b94..5057c6437 100644 --- a/src/tools/clippy/tests/ui/float_cmp.rs +++ b/src/tools/clippy/tests/ui/float_cmp.rs @@ -6,7 +6,7 @@ clippy::unnecessary_operation, clippy::cast_lossless )] - +//@no-rustfix use std::ops::Add; const ZERO: f32 = 0.0; @@ -41,6 +41,16 @@ impl PartialEq for X { } } +impl PartialEq for X { + fn eq(&self, o: &f32) -> bool { + if self.val.is_nan() { + o.is_nan() + } else { + self.val == *o // no error, inside "eq" fn + } + } +} + fn main() { ZERO == 0f32; //no error, comparison with zero is ok 1.0f32 != f32::INFINITY; // also comparison with infinity @@ -48,6 +58,9 @@ fn main() { ZERO == 0.0; //no error, comparison with zero is ok ZERO + ZERO != 1.0; //no error, comparison with zero is ok + let x = X { val: 1.0 }; + x == 1.0; // no error, custom type that implement PartialOrder for float is not checked + ONE == 1f32; ONE == 1.0 + 0.0; ONE + ONE == ZERO + ONE + ONE; @@ -55,14 +68,20 @@ fn main() { ONE != 0.0; // no error, comparison with zero is ok twice(ONE) != ONE; ONE as f64 != 2.0; + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` ONE as f64 != 0.0; // no error, comparison with zero is ok let x: f64 = 1.0; x == 1.0; + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` x != 0f64; // no error, comparison with zero is ok twice(x) != twice(ONE as f64); + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` x < 0.0; // no errors, lower or greater comparisons need no fuzzyness x > 0.0; @@ -83,12 +102,18 @@ fn main() { ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; // ok, because lhs is zero regardless of i NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` let a1: [f32; 1] = [0.0]; let a2: [f32; 1] = [1.1]; a1 == a2; + //~^ ERROR: strict comparison of `f32` or `f64` arrays + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` a1[0] == a2[0]; + //~^ ERROR: strict comparison of `f32` or `f64` + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` // no errors - comparing signums is ok let x32 = 3.21f32; diff --git a/src/tools/clippy/tests/ui/float_cmp.stderr b/src/tools/clippy/tests/ui/float_cmp.stderr index e3e9f3949..217e29879 100644 --- a/src/tools/clippy/tests/ui/float_cmp.stderr +++ b/src/tools/clippy/tests/ui/float_cmp.stderr @@ -1,14 +1,15 @@ error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:57:5 + --> $DIR/float_cmp.rs:70:5 | LL | ONE as f64 != 2.0; | ^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE as f64 - 2.0).abs() > error_margin` | = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` = note: `-D clippy::float-cmp` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::float_cmp)]` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:62:5 + --> $DIR/float_cmp.rs:77:5 | LL | x == 1.0; | ^^^^^^^^ help: consider comparing them within some margin of error: `(x - 1.0).abs() < error_margin` @@ -16,7 +17,7 @@ LL | x == 1.0; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:65:5 + --> $DIR/float_cmp.rs:82:5 | LL | twice(x) != twice(ONE as f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(twice(x) - twice(ONE as f64)).abs() > error_margin` @@ -24,7 +25,7 @@ LL | twice(x) != twice(ONE as f64); = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:85:5 + --> $DIR/float_cmp.rs:104:5 | LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(NON_ZERO_ARRAY[i] - NON_ZERO_ARRAY[j]).abs() < error_margin` @@ -32,7 +33,7 @@ LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` arrays - --> $DIR/float_cmp.rs:90:5 + --> $DIR/float_cmp.rs:111:5 | LL | a1 == a2; | ^^^^^^^^ @@ -40,7 +41,7 @@ LL | a1 == a2; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` - --> $DIR/float_cmp.rs:91:5 + --> $DIR/float_cmp.rs:114:5 | LL | a1[0] == a2[0]; | ^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(a1[0] - a2[0]).abs() < error_margin` diff --git a/src/tools/clippy/tests/ui/float_cmp_const.rs b/src/tools/clippy/tests/ui/float_cmp_const.rs index 86ce3bf3b..47ea0e19c 100644 --- a/src/tools/clippy/tests/ui/float_cmp_const.rs +++ b/src/tools/clippy/tests/ui/float_cmp_const.rs @@ -1,5 +1,5 @@ // does not test any rustfixable lints - +//@no-rustfix #![warn(clippy::float_cmp_const)] #![allow(clippy::float_cmp)] #![allow(unused, clippy::no_effect, clippy::unnecessary_operation)] @@ -14,15 +14,29 @@ fn eq_one(x: f32) -> bool { fn main() { // has errors 1f32 == ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` TWO == ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` TWO != ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` ONE + ONE == TWO; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` let x = 1; x as f32 == ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` let v = 0.9; v == ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` v != ONE; + //~^ ERROR: strict comparison of `f32` or `f64` constant + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` // no errors, lower than or greater than comparisons v < ONE; @@ -55,4 +69,6 @@ fn main() { // has errors NON_ZERO_ARRAY == NON_ZERO_ARRAY2; + //~^ ERROR: strict comparison of `f32` or `f64` constant arrays + //~| NOTE: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` } diff --git a/src/tools/clippy/tests/ui/float_cmp_const.stderr b/src/tools/clippy/tests/ui/float_cmp_const.stderr index 65c45648a..856aaa2ea 100644 --- a/src/tools/clippy/tests/ui/float_cmp_const.stderr +++ b/src/tools/clippy/tests/ui/float_cmp_const.stderr @@ -6,9 +6,10 @@ LL | 1f32 == ONE; | = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` = note: `-D clippy::float-cmp-const` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::float_cmp_const)]` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:17:5 + --> $DIR/float_cmp_const.rs:19:5 | LL | TWO == ONE; | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() < error_margin` @@ -16,7 +17,7 @@ LL | TWO == ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:18:5 + --> $DIR/float_cmp_const.rs:22:5 | LL | TWO != ONE; | ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() > error_margin` @@ -24,7 +25,7 @@ LL | TWO != ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:19:5 + --> $DIR/float_cmp_const.rs:25:5 | LL | ONE + ONE == TWO; | ^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE + ONE - TWO).abs() < error_margin` @@ -32,7 +33,7 @@ LL | ONE + ONE == TWO; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:21:5 + --> $DIR/float_cmp_const.rs:29:5 | LL | x as f32 == ONE; | ^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(x as f32 - ONE).abs() < error_margin` @@ -40,7 +41,7 @@ LL | x as f32 == ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:24:5 + --> $DIR/float_cmp_const.rs:34:5 | LL | v == ONE; | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() < error_margin` @@ -48,7 +49,7 @@ LL | v == ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant - --> $DIR/float_cmp_const.rs:25:5 + --> $DIR/float_cmp_const.rs:37:5 | LL | v != ONE; | ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() > error_margin` @@ -56,7 +57,7 @@ LL | v != ONE; = note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin` error: strict comparison of `f32` or `f64` constant arrays - --> $DIR/float_cmp_const.rs:57:5 + --> $DIR/float_cmp_const.rs:71:5 | LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/float_equality_without_abs.rs b/src/tools/clippy/tests/ui/float_equality_without_abs.rs index d40fa00c3..6363472d8 100644 --- a/src/tools/clippy/tests/ui/float_equality_without_abs.rs +++ b/src/tools/clippy/tests/ui/float_equality_without_abs.rs @@ -1,7 +1,9 @@ #![warn(clippy::float_equality_without_abs)] - +//@no-rustfix pub fn is_roughly_equal(a: f32, b: f32) -> bool { (a - b) < f32::EPSILON + //~^ ERROR: float equality check without `.abs()` + //~| NOTE: `-D clippy::float-equality-without-abs` implied by `-D warnings` } pub fn main() { @@ -11,16 +13,26 @@ pub fn main() { let b = 0.0500001; let _ = (a - b) < f32::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = a - b < f32::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = a - b.abs() < f32::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = (a as f64 - b as f64) < f64::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = 1.0 - 2.0 < f32::EPSILON; + //~^ ERROR: float equality check without `.abs()` let _ = f32::EPSILON > (a - b); + //~^ ERROR: float equality check without `.abs()` let _ = f32::EPSILON > a - b; + //~^ ERROR: float equality check without `.abs()` let _ = f32::EPSILON > a - b.abs(); + //~^ ERROR: float equality check without `.abs()` let _ = f64::EPSILON > (a as f64 - b as f64); + //~^ ERROR: float equality check without `.abs()` let _ = f32::EPSILON > 1.0 - 2.0; + //~^ ERROR: float equality check without `.abs()` // those are correct let _ = (a - b).abs() < f32::EPSILON; diff --git a/src/tools/clippy/tests/ui/float_equality_without_abs.stderr b/src/tools/clippy/tests/ui/float_equality_without_abs.stderr index b34c8159d..155699f6f 100644 --- a/src/tools/clippy/tests/ui/float_equality_without_abs.stderr +++ b/src/tools/clippy/tests/ui/float_equality_without_abs.stderr @@ -7,9 +7,10 @@ LL | (a - b) < f32::EPSILON | help: add `.abs()`: `(a - b).abs()` | = note: `-D clippy::float-equality-without-abs` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::float_equality_without_abs)]` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:13:13 + --> $DIR/float_equality_without_abs.rs:15:13 | LL | let _ = (a - b) < f32::EPSILON; | -------^^^^^^^^^^^^^^^ @@ -17,7 +18,7 @@ LL | let _ = (a - b) < f32::EPSILON; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:14:13 + --> $DIR/float_equality_without_abs.rs:17:13 | LL | let _ = a - b < f32::EPSILON; | -----^^^^^^^^^^^^^^^ @@ -25,7 +26,7 @@ LL | let _ = a - b < f32::EPSILON; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:15:13 + --> $DIR/float_equality_without_abs.rs:19:13 | LL | let _ = a - b.abs() < f32::EPSILON; | -----------^^^^^^^^^^^^^^^ @@ -33,7 +34,7 @@ LL | let _ = a - b.abs() < f32::EPSILON; | help: add `.abs()`: `(a - b.abs()).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:16:13 + --> $DIR/float_equality_without_abs.rs:21:13 | LL | let _ = (a as f64 - b as f64) < f64::EPSILON; | ---------------------^^^^^^^^^^^^^^^ @@ -41,7 +42,7 @@ LL | let _ = (a as f64 - b as f64) < f64::EPSILON; | help: add `.abs()`: `(a as f64 - b as f64).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:17:13 + --> $DIR/float_equality_without_abs.rs:23:13 | LL | let _ = 1.0 - 2.0 < f32::EPSILON; | ---------^^^^^^^^^^^^^^^ @@ -49,7 +50,7 @@ LL | let _ = 1.0 - 2.0 < f32::EPSILON; | help: add `.abs()`: `(1.0 - 2.0).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:19:13 + --> $DIR/float_equality_without_abs.rs:26:13 | LL | let _ = f32::EPSILON > (a - b); | ^^^^^^^^^^^^^^^------- @@ -57,7 +58,7 @@ LL | let _ = f32::EPSILON > (a - b); | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:20:13 + --> $DIR/float_equality_without_abs.rs:28:13 | LL | let _ = f32::EPSILON > a - b; | ^^^^^^^^^^^^^^^----- @@ -65,7 +66,7 @@ LL | let _ = f32::EPSILON > a - b; | help: add `.abs()`: `(a - b).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:21:13 + --> $DIR/float_equality_without_abs.rs:30:13 | LL | let _ = f32::EPSILON > a - b.abs(); | ^^^^^^^^^^^^^^^----------- @@ -73,7 +74,7 @@ LL | let _ = f32::EPSILON > a - b.abs(); | help: add `.abs()`: `(a - b.abs()).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:22:13 + --> $DIR/float_equality_without_abs.rs:32:13 | LL | let _ = f64::EPSILON > (a as f64 - b as f64); | ^^^^^^^^^^^^^^^--------------------- @@ -81,7 +82,7 @@ LL | let _ = f64::EPSILON > (a as f64 - b as f64); | help: add `.abs()`: `(a as f64 - b as f64).abs()` error: float equality check without `.abs()` - --> $DIR/float_equality_without_abs.rs:23:13 + --> $DIR/float_equality_without_abs.rs:34:13 | LL | let _ = f32::EPSILON > 1.0 - 2.0; | ^^^^^^^^^^^^^^^--------- diff --git a/src/tools/clippy/tests/ui/floating_point_abs.fixed b/src/tools/clippy/tests/ui/floating_point_abs.fixed index 0cc572822..5312a8b29 100644 --- a/src/tools/clippy/tests/ui/floating_point_abs.fixed +++ b/src/tools/clippy/tests/ui/floating_point_abs.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(const_fn_floating_point_arithmetic)] #![warn(clippy::suboptimal_flops)] diff --git a/src/tools/clippy/tests/ui/floating_point_abs.rs b/src/tools/clippy/tests/ui/floating_point_abs.rs index 6c732d398..861917713 100644 --- a/src/tools/clippy/tests/ui/floating_point_abs.rs +++ b/src/tools/clippy/tests/ui/floating_point_abs.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(const_fn_floating_point_arithmetic)] #![warn(clippy::suboptimal_flops)] diff --git a/src/tools/clippy/tests/ui/floating_point_abs.stderr b/src/tools/clippy/tests/ui/floating_point_abs.stderr index db8290423..fbc578382 100644 --- a/src/tools/clippy/tests/ui/floating_point_abs.stderr +++ b/src/tools/clippy/tests/ui/floating_point_abs.stderr @@ -1,49 +1,50 @@ error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:16:5 + --> $DIR/floating_point_abs.rs:15:5 | LL | if num >= 0.0 { num } else { -num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:20:5 + --> $DIR/floating_point_abs.rs:19:5 | LL | if 0.0 < num { num } else { -num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:24:5 + --> $DIR/floating_point_abs.rs:23:5 | LL | if a.a > 0.0 { a.a } else { -a.a } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()` error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:28:5 + --> $DIR/floating_point_abs.rs:27:5 | LL | if 0.0 >= num { -num } else { num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()` error: manual implementation of `abs` method - --> $DIR/floating_point_abs.rs:32:5 + --> $DIR/floating_point_abs.rs:31:5 | LL | if a.a < 0.0 { -a.a } else { a.a } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()` error: manual implementation of negation of `abs` method - --> $DIR/floating_point_abs.rs:36:5 + --> $DIR/floating_point_abs.rs:35:5 | LL | if num < 0.0 { num } else { -num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()` error: manual implementation of negation of `abs` method - --> $DIR/floating_point_abs.rs:40:5 + --> $DIR/floating_point_abs.rs:39:5 | LL | if 0.0 >= num { num } else { -num } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()` error: manual implementation of negation of `abs` method - --> $DIR/floating_point_abs.rs:45:12 + --> $DIR/floating_point_abs.rs:44:12 | LL | a: if a.a >= 0.0 { -a.a } else { a.a }, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-a.a.abs()` diff --git a/src/tools/clippy/tests/ui/floating_point_exp.fixed b/src/tools/clippy/tests/ui/floating_point_exp.fixed index 1a33b8153..15072bb1e 100644 --- a/src/tools/clippy/tests/ui/floating_point_exp.fixed +++ b/src/tools/clippy/tests/ui/floating_point_exp.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::imprecise_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/src/tools/clippy/tests/ui/floating_point_exp.rs b/src/tools/clippy/tests/ui/floating_point_exp.rs index 4f4a5ec81..7d8b17946 100644 --- a/src/tools/clippy/tests/ui/floating_point_exp.rs +++ b/src/tools/clippy/tests/ui/floating_point_exp.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::imprecise_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/src/tools/clippy/tests/ui/floating_point_exp.stderr b/src/tools/clippy/tests/ui/floating_point_exp.stderr index b92fae56e..6b64b9b60 100644 --- a/src/tools/clippy/tests/ui/floating_point_exp.stderr +++ b/src/tools/clippy/tests/ui/floating_point_exp.stderr @@ -1,31 +1,32 @@ error: (e.pow(x) - 1) can be computed more accurately - --> $DIR/floating_point_exp.rs:7:13 + --> $DIR/floating_point_exp.rs:6:13 | LL | let _ = x.exp() - 1.0; | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` | = note: `-D clippy::imprecise-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: (e.pow(x) - 1) can be computed more accurately - --> $DIR/floating_point_exp.rs:8:13 + --> $DIR/floating_point_exp.rs:7:13 | LL | let _ = x.exp() - 1.0 + 2.0; | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` error: (e.pow(x) - 1) can be computed more accurately - --> $DIR/floating_point_exp.rs:9:13 + --> $DIR/floating_point_exp.rs:8:13 | LL | let _ = (x as f32).exp() - 1.0 + 2.0; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).exp_m1()` error: (e.pow(x) - 1) can be computed more accurately - --> $DIR/floating_point_exp.rs:15:13 + --> $DIR/floating_point_exp.rs:14:13 | LL | let _ = x.exp() - 1.0; | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` error: (e.pow(x) - 1) can be computed more accurately - --> $DIR/floating_point_exp.rs:16:13 + --> $DIR/floating_point_exp.rs:15:13 | LL | let _ = x.exp() - 1.0 + 2.0; | ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()` diff --git a/src/tools/clippy/tests/ui/floating_point_hypot.fixed b/src/tools/clippy/tests/ui/floating_point_hypot.fixed index 431cb2709..75a224440 100644 --- a/src/tools/clippy/tests/ui/floating_point_hypot.fixed +++ b/src/tools/clippy/tests/ui/floating_point_hypot.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::imprecise_flops)] fn main() { diff --git a/src/tools/clippy/tests/ui/floating_point_hypot.rs b/src/tools/clippy/tests/ui/floating_point_hypot.rs index e5506ed39..ed4dbf638 100644 --- a/src/tools/clippy/tests/ui/floating_point_hypot.rs +++ b/src/tools/clippy/tests/ui/floating_point_hypot.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::imprecise_flops)] fn main() { diff --git a/src/tools/clippy/tests/ui/floating_point_hypot.stderr b/src/tools/clippy/tests/ui/floating_point_hypot.stderr index 42069d9ee..21e0bd8b5 100644 --- a/src/tools/clippy/tests/ui/floating_point_hypot.stderr +++ b/src/tools/clippy/tests/ui/floating_point_hypot.stderr @@ -1,19 +1,20 @@ error: hypotenuse can be computed more accurately - --> $DIR/floating_point_hypot.rs:7:13 + --> $DIR/floating_point_hypot.rs:6:13 | LL | let _ = (x * x + y * y).sqrt(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.hypot(y)` | = note: `-D clippy::imprecise-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: hypotenuse can be computed more accurately - --> $DIR/floating_point_hypot.rs:8:13 + --> $DIR/floating_point_hypot.rs:7:13 | 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:9:13 + --> $DIR/floating_point_hypot.rs:8:13 | LL | let _ = (x.powi(2) + y.powi(2)).sqrt(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.hypot(y)` diff --git a/src/tools/clippy/tests/ui/floating_point_log.fixed b/src/tools/clippy/tests/ui/floating_point_log.fixed index 6582c0a0f..01f0fc5c6 100644 --- a/src/tools/clippy/tests/ui/floating_point_log.fixed +++ b/src/tools/clippy/tests/ui/floating_point_log.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::double_parens, clippy::unnecessary_cast)] #![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] diff --git a/src/tools/clippy/tests/ui/floating_point_log.rs b/src/tools/clippy/tests/ui/floating_point_log.rs index 854d269ff..197e3e1ff 100644 --- a/src/tools/clippy/tests/ui/floating_point_log.rs +++ b/src/tools/clippy/tests/ui/floating_point_log.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::double_parens, clippy::unnecessary_cast)] #![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] diff --git a/src/tools/clippy/tests/ui/floating_point_log.stderr b/src/tools/clippy/tests/ui/floating_point_log.stderr index 89800a13a..a426f4c3d 100644 --- a/src/tools/clippy/tests/ui/floating_point_log.stderr +++ b/src/tools/clippy/tests/ui/floating_point_log.stderr @@ -1,177 +1,179 @@ error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:10:13 + --> $DIR/floating_point_log.rs:9:13 | LL | let _ = x.log(2f32); | ^^^^^^^^^^^ help: consider using: `x.log2()` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:11:13 + --> $DIR/floating_point_log.rs:10:13 | LL | let _ = x.log(10f32); | ^^^^^^^^^^^^ help: consider using: `x.log10()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:12:13 + --> $DIR/floating_point_log.rs:11:13 | LL | let _ = x.log(std::f32::consts::E); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:13:13 + --> $DIR/floating_point_log.rs:12:13 | LL | let _ = x.log(TWO); | ^^^^^^^^^^ help: consider using: `x.log2()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:14:13 + --> $DIR/floating_point_log.rs:13:13 | LL | let _ = x.log(E); | ^^^^^^^^ help: consider using: `x.ln()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:15:13 + --> $DIR/floating_point_log.rs:14:13 | LL | let _ = (x as f32).log(2f32); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).log2()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:18:13 + --> $DIR/floating_point_log.rs:17:13 | LL | let _ = x.log(2f64); | ^^^^^^^^^^^ help: consider using: `x.log2()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:19:13 + --> $DIR/floating_point_log.rs:18:13 | LL | let _ = x.log(10f64); | ^^^^^^^^^^^^ help: consider using: `x.log10()` error: logarithm for bases 2, 10 and e can be computed more accurately - --> $DIR/floating_point_log.rs:20:13 + --> $DIR/floating_point_log.rs:19:13 | LL | let _ = x.log(std::f64::consts::E); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.ln()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:25:13 + --> $DIR/floating_point_log.rs:24:13 | LL | let _ = (1f32 + 2.).ln(); | ^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()` | = note: `-D clippy::imprecise-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:26:13 + --> $DIR/floating_point_log.rs:25:13 | LL | let _ = (1f32 + 2.0).ln(); | ^^^^^^^^^^^^^^^^^ help: consider using: `2.0f32.ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:27:13 + --> $DIR/floating_point_log.rs:26: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:28:13 + --> $DIR/floating_point_log.rs:27: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:29:13 + --> $DIR/floating_point_log.rs:28: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:30:13 + --> $DIR/floating_point_log.rs:29:13 | LL | let _ = (1.0 + x.powi(3) / 2.0).ln(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x.powi(3) / 2.0).ln_1p()` error: ln(1 + x) can be computed more accurately - --> $DIR/floating_point_log.rs:31:13 + --> $DIR/floating_point_log.rs:30:13 | 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:32:13 + --> $DIR/floating_point_log.rs:31: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:33:13 + --> $DIR/floating_point_log.rs:32: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:34:13 + --> $DIR/floating_point_log.rs:33: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:35: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:43:13 + --> $DIR/floating_point_log.rs:42: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:44:13 + --> $DIR/floating_point_log.rs:43: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:45:13 + --> $DIR/floating_point_log.rs:44: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:46:13 + --> $DIR/floating_point_log.rs:45: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:47:13 + --> $DIR/floating_point_log.rs:46: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:48:13 + --> $DIR/floating_point_log.rs:47: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:49:13 + --> $DIR/floating_point_log.rs:48: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:50:13 + --> $DIR/floating_point_log.rs:49: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:51:13 + --> $DIR/floating_point_log.rs:50:13 | LL | let _ = (x / 2.0 + 1.0).ln(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x / 2.0).ln_1p()` diff --git a/src/tools/clippy/tests/ui/floating_point_logbase.fixed b/src/tools/clippy/tests/ui/floating_point_logbase.fixed index 0783ecee1..451673d10 100644 --- a/src/tools/clippy/tests/ui/floating_point_logbase.fixed +++ b/src/tools/clippy/tests/ui/floating_point_logbase.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suboptimal_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/src/tools/clippy/tests/ui/floating_point_logbase.rs b/src/tools/clippy/tests/ui/floating_point_logbase.rs index 80fcfab68..c30911459 100644 --- a/src/tools/clippy/tests/ui/floating_point_logbase.rs +++ b/src/tools/clippy/tests/ui/floating_point_logbase.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suboptimal_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/src/tools/clippy/tests/ui/floating_point_logbase.stderr b/src/tools/clippy/tests/ui/floating_point_logbase.stderr index 9d736b5e1..463bdb84c 100644 --- a/src/tools/clippy/tests/ui/floating_point_logbase.stderr +++ b/src/tools/clippy/tests/ui/floating_point_logbase.stderr @@ -1,31 +1,32 @@ error: log base can be expressed more clearly - --> $DIR/floating_point_logbase.rs:8:13 + --> $DIR/floating_point_logbase.rs:7:13 | LL | let _ = x.ln() / y.ln(); | ^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: log base can be expressed more clearly - --> $DIR/floating_point_logbase.rs:9:13 + --> $DIR/floating_point_logbase.rs:8:13 | LL | let _ = (x as f32).ln() / y.ln(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).log(y)` error: log base can be expressed more clearly - --> $DIR/floating_point_logbase.rs:10:13 + --> $DIR/floating_point_logbase.rs:9:13 | LL | let _ = x.log2() / y.log2(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` error: log base can be expressed more clearly - --> $DIR/floating_point_logbase.rs:11:13 + --> $DIR/floating_point_logbase.rs:10:13 | LL | let _ = x.log10() / y.log10(); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` error: log base can be expressed more clearly - --> $DIR/floating_point_logbase.rs:12:13 + --> $DIR/floating_point_logbase.rs:11:13 | LL | let _ = x.log(5f32) / y.log(5f32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)` diff --git a/src/tools/clippy/tests/ui/floating_point_mul_add.fixed b/src/tools/clippy/tests/ui/floating_point_mul_add.fixed index 8848981a1..c23f4d7c4 100644 --- a/src/tools/clippy/tests/ui/floating_point_mul_add.fixed +++ b/src/tools/clippy/tests/ui/floating_point_mul_add.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(const_fn_floating_point_arithmetic)] #![warn(clippy::suboptimal_flops)] diff --git a/src/tools/clippy/tests/ui/floating_point_mul_add.rs b/src/tools/clippy/tests/ui/floating_point_mul_add.rs index b0edf5cb2..431badc8d 100644 --- a/src/tools/clippy/tests/ui/floating_point_mul_add.rs +++ b/src/tools/clippy/tests/ui/floating_point_mul_add.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(const_fn_floating_point_arithmetic)] #![warn(clippy::suboptimal_flops)] diff --git a/src/tools/clippy/tests/ui/floating_point_mul_add.stderr b/src/tools/clippy/tests/ui/floating_point_mul_add.stderr index a79ae94e8..81b7126db 100644 --- a/src/tools/clippy/tests/ui/floating_point_mul_add.stderr +++ b/src/tools/clippy/tests/ui/floating_point_mul_add.stderr @@ -1,73 +1,74 @@ error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:21:13 + --> $DIR/floating_point_mul_add.rs:20:13 | LL | let _ = a * b + c; | ^^^^^^^^^ help: consider using: `a.mul_add(b, c)` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:22:13 + --> $DIR/floating_point_mul_add.rs:21:13 | LL | let _ = a * b - c; | ^^^^^^^^^ help: consider using: `a.mul_add(b, -c)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:23:13 + --> $DIR/floating_point_mul_add.rs:22:13 | LL | let _ = c + a * b; | ^^^^^^^^^ help: consider using: `a.mul_add(b, c)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:24:13 + --> $DIR/floating_point_mul_add.rs:23:13 | LL | let _ = c - a * b; | ^^^^^^^^^ help: consider using: `a.mul_add(-b, c)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:25:13 + --> $DIR/floating_point_mul_add.rs:24:13 | LL | let _ = a + 2.0 * 4.0; | ^^^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4.0, a)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:26:13 + --> $DIR/floating_point_mul_add.rs:25:13 | LL | let _ = a + 2. * 4.; | ^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4., a)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:28:13 + --> $DIR/floating_point_mul_add.rs:27:13 | LL | let _ = (a * b) + c; | ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:29:13 + --> $DIR/floating_point_mul_add.rs:28:13 | LL | let _ = c + (a * b); | ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_mul_add.rs:30:13 + --> $DIR/floating_point_mul_add.rs:29:13 | LL | let _ = a * b * c + d; | ^^^^^^^^^^^^^ help: consider using: `(a * b).mul_add(c, d)` 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:31:13 | 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:33:13 + --> $DIR/floating_point_mul_add.rs:32: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:35:13 + --> $DIR/floating_point_mul_add.rs:34:13 | LL | let _ = (a * a + b).sqrt(); | ^^^^^^^^^^^ help: consider using: `a.mul_add(a, b)` diff --git a/src/tools/clippy/tests/ui/floating_point_powf.fixed b/src/tools/clippy/tests/ui/floating_point_powf.fixed index 1e660b140..c2884ca31 100644 --- a/src/tools/clippy/tests/ui/floating_point_powf.fixed +++ b/src/tools/clippy/tests/ui/floating_point_powf.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/src/tools/clippy/tests/ui/floating_point_powf.rs b/src/tools/clippy/tests/ui/floating_point_powf.rs index 71c2f5292..37d58af05 100644 --- a/src/tools/clippy/tests/ui/floating_point_powf.rs +++ b/src/tools/clippy/tests/ui/floating_point_powf.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suboptimal_flops, clippy::imprecise_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/src/tools/clippy/tests/ui/floating_point_powf.stderr b/src/tools/clippy/tests/ui/floating_point_powf.stderr index 7c9d50db2..0ff8f82d9 100644 --- a/src/tools/clippy/tests/ui/floating_point_powf.stderr +++ b/src/tools/clippy/tests/ui/floating_point_powf.stderr @@ -1,189 +1,191 @@ error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:7:13 + --> $DIR/floating_point_powf.rs:6:13 | LL | let _ = 2f32.powf(x); | ^^^^^^^^^^^^ help: consider using: `x.exp2()` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:8:13 + --> $DIR/floating_point_powf.rs:7:13 | LL | let _ = 2f32.powf(3.1); | ^^^^^^^^^^^^^^ help: consider using: `3.1f32.exp2()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:9:13 + --> $DIR/floating_point_powf.rs:8:13 | LL | let _ = 2f32.powf(-3.1); | ^^^^^^^^^^^^^^^ help: consider using: `(-3.1f32).exp2()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:10:13 + --> $DIR/floating_point_powf.rs:9:13 | LL | let _ = std::f32::consts::E.powf(x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:11:13 + --> $DIR/floating_point_powf.rs:10:13 | LL | let _ = std::f32::consts::E.powf(3.1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `3.1f32.exp()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:12:13 + --> $DIR/floating_point_powf.rs:11:13 | LL | let _ = std::f32::consts::E.powf(-3.1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-3.1f32).exp()` error: square-root of a number can be computed more efficiently and accurately - --> $DIR/floating_point_powf.rs:13:13 + --> $DIR/floating_point_powf.rs:12:13 | LL | let _ = x.powf(1.0 / 2.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()` error: cube-root of a number can be computed more accurately - --> $DIR/floating_point_powf.rs:14:13 + --> $DIR/floating_point_powf.rs:13:13 | LL | let _ = x.powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()` | = note: `-D clippy::imprecise-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::imprecise_flops)]` error: cube-root of a number can be computed more accurately - --> $DIR/floating_point_powf.rs:15:13 + --> $DIR/floating_point_powf.rs:14:13 | LL | let _ = (x as f32).powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).cbrt()` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:16:13 + --> $DIR/floating_point_powf.rs:15:13 | LL | let _ = x.powf(3.0); | ^^^^^^^^^^^ help: consider using: `x.powi(3)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:17:13 + --> $DIR/floating_point_powf.rs:16:13 | LL | let _ = x.powf(-2.0); | ^^^^^^^^^^^^ help: consider using: `x.powi(-2)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:18:13 + --> $DIR/floating_point_powf.rs:17:13 | LL | let _ = x.powf(16_777_215.0); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(16_777_215)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:19:13 + --> $DIR/floating_point_powf.rs:18:13 | LL | let _ = x.powf(-16_777_215.0); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(-16_777_215)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:20:13 + --> $DIR/floating_point_powf.rs:19:13 | LL | let _ = (x as f32).powf(-16_777_215.0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).powi(-16_777_215)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:21:13 + --> $DIR/floating_point_powf.rs:20:13 | LL | let _ = (x as f32).powf(3.0); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).powi(3)` error: cube-root of a number can be computed more accurately - --> $DIR/floating_point_powf.rs:22:13 + --> $DIR/floating_point_powf.rs:21:13 | LL | let _ = (1.5_f32 + 1.0).powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(1.5_f32 + 1.0).cbrt()` error: cube-root of a number can be computed more accurately - --> $DIR/floating_point_powf.rs:23:13 + --> $DIR/floating_point_powf.rs:22:13 | LL | let _ = 1.5_f64.powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.5_f64.cbrt()` error: square-root of a number can be computed more efficiently and accurately - --> $DIR/floating_point_powf.rs:24:13 + --> $DIR/floating_point_powf.rs:23:13 | LL | let _ = 1.5_f64.powf(1.0 / 2.0); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.5_f64.sqrt()` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:25:13 + --> $DIR/floating_point_powf.rs:24:13 | LL | let _ = 1.5_f64.powf(3.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `1.5_f64.powi(3)` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:34:13 + --> $DIR/floating_point_powf.rs:33:13 | LL | let _ = 2f64.powf(x); | ^^^^^^^^^^^^ help: consider using: `x.exp2()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:35:13 + --> $DIR/floating_point_powf.rs:34:13 | LL | let _ = 2f64.powf(3.1); | ^^^^^^^^^^^^^^ help: consider using: `3.1f64.exp2()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:36:13 + --> $DIR/floating_point_powf.rs:35:13 | LL | let _ = 2f64.powf(-3.1); | ^^^^^^^^^^^^^^^ help: consider using: `(-3.1f64).exp2()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:37:13 + --> $DIR/floating_point_powf.rs:36:13 | LL | let _ = std::f64::consts::E.powf(x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:38:13 + --> $DIR/floating_point_powf.rs:37:13 | LL | let _ = std::f64::consts::E.powf(3.1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `3.1f64.exp()` error: exponent for bases 2 and e can be computed more accurately - --> $DIR/floating_point_powf.rs:39:13 + --> $DIR/floating_point_powf.rs:38:13 | LL | let _ = std::f64::consts::E.powf(-3.1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-3.1f64).exp()` error: square-root of a number can be computed more efficiently and accurately - --> $DIR/floating_point_powf.rs:40:13 + --> $DIR/floating_point_powf.rs:39:13 | LL | let _ = x.powf(1.0 / 2.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()` error: cube-root of a number can be computed more accurately - --> $DIR/floating_point_powf.rs:41:13 + --> $DIR/floating_point_powf.rs:40:13 | LL | let _ = x.powf(1.0 / 3.0); | ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:42:13 + --> $DIR/floating_point_powf.rs:41:13 | LL | let _ = x.powf(3.0); | ^^^^^^^^^^^ help: consider using: `x.powi(3)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:43:13 + --> $DIR/floating_point_powf.rs:42:13 | LL | let _ = x.powf(-2.0); | ^^^^^^^^^^^^ help: consider using: `x.powi(-2)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:44:13 + --> $DIR/floating_point_powf.rs:43:13 | LL | let _ = x.powf(-2_147_483_648.0); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(-2_147_483_648)` error: exponentiation with integer powers can be computed more efficiently - --> $DIR/floating_point_powf.rs:45:13 + --> $DIR/floating_point_powf.rs:44:13 | LL | let _ = x.powf(2_147_483_647.0); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2_147_483_647)` diff --git a/src/tools/clippy/tests/ui/floating_point_powi.fixed b/src/tools/clippy/tests/ui/floating_point_powi.fixed index 41d5288d6..cb033c899 100644 --- a/src/tools/clippy/tests/ui/floating_point_powi.fixed +++ b/src/tools/clippy/tests/ui/floating_point_powi.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suboptimal_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/src/tools/clippy/tests/ui/floating_point_powi.rs b/src/tools/clippy/tests/ui/floating_point_powi.rs index 7951aab31..f02e0e8dd 100644 --- a/src/tools/clippy/tests/ui/floating_point_powi.rs +++ b/src/tools/clippy/tests/ui/floating_point_powi.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suboptimal_flops)] #![allow(clippy::unnecessary_cast)] diff --git a/src/tools/clippy/tests/ui/floating_point_powi.stderr b/src/tools/clippy/tests/ui/floating_point_powi.stderr index fdf6d0880..ddf20ff40 100644 --- a/src/tools/clippy/tests/ui/floating_point_powi.stderr +++ b/src/tools/clippy/tests/ui/floating_point_powi.stderr @@ -1,85 +1,86 @@ error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:10:13 + --> $DIR/floating_point_powi.rs:9:13 | LL | let _ = x.powi(2) + y; | ^^^^^^^^^^^^^ help: consider using: `x.mul_add(x, y)` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:11:13 + --> $DIR/floating_point_powi.rs:10:13 | LL | let _ = x.powi(2) - y; | ^^^^^^^^^^^^^ help: consider using: `x.mul_add(x, -y)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:12:13 + --> $DIR/floating_point_powi.rs:11:13 | LL | let _ = x + y.powi(2); | ^^^^^^^^^^^^^ help: consider using: `y.mul_add(y, x)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:13:13 + --> $DIR/floating_point_powi.rs:12:13 | LL | let _ = x - y.powi(2); | ^^^^^^^^^^^^^ help: consider using: `y.mul_add(-y, x)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:14:13 + --> $DIR/floating_point_powi.rs:13:13 | LL | let _ = x + (y as f32).powi(2); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(y as f32).mul_add(y as f32, x)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:15:13 + --> $DIR/floating_point_powi.rs:14:13 | LL | let _ = (x.powi(2) + y).sqrt(); | ^^^^^^^^^^^^^^^ help: consider using: `x.mul_add(x, y)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:16:13 + --> $DIR/floating_point_powi.rs:15:13 | LL | let _ = (x + y.powi(2)).sqrt(); | ^^^^^^^^^^^^^^^ help: consider using: `y.mul_add(y, x)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:18:13 + --> $DIR/floating_point_powi.rs:17:13 | LL | let _ = (x - 1.0).powi(2) - y; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x - 1.0).mul_add(x - 1.0, -y)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:19:13 + --> $DIR/floating_point_powi.rs:18:13 | LL | let _ = (x - 1.0).powi(2) - y + 3.0; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x - 1.0).mul_add(x - 1.0, -y)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:20:13 + --> $DIR/floating_point_powi.rs:19:13 | LL | let _ = (x - 1.0).powi(2) - (y + 3.0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x - 1.0).mul_add(x - 1.0, -(y + 3.0))` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:21:13 + --> $DIR/floating_point_powi.rs:20:13 | LL | let _ = x - (y + 1.0).powi(2); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(y + 1.0).mul_add(-(y + 1.0), x)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:22:13 + --> $DIR/floating_point_powi.rs:21:13 | LL | let _ = x - (3.0 * y).powi(2); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(3.0 * y).mul_add(-(3.0 * y), x)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:23:13 + --> $DIR/floating_point_powi.rs:22:13 | LL | let _ = x - (y + 1.0 + x).powi(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(y + 1.0 + x).mul_add(-(y + 1.0 + x), x)` error: multiply and add expressions can be calculated more efficiently and accurately - --> $DIR/floating_point_powi.rs:24:13 + --> $DIR/floating_point_powi.rs:23:13 | LL | let _ = x - (y + 1.0 + 2.0).powi(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(y + 1.0 + 2.0).mul_add(-(y + 1.0 + 2.0), x)` diff --git a/src/tools/clippy/tests/ui/floating_point_rad.fixed b/src/tools/clippy/tests/ui/floating_point_rad.fixed index af2364527..a710bd9bd 100644 --- a/src/tools/clippy/tests/ui/floating_point_rad.fixed +++ b/src/tools/clippy/tests/ui/floating_point_rad.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(const_fn_floating_point_arithmetic)] #![warn(clippy::suboptimal_flops)] diff --git a/src/tools/clippy/tests/ui/floating_point_rad.rs b/src/tools/clippy/tests/ui/floating_point_rad.rs index d7612c56a..14656f021 100644 --- a/src/tools/clippy/tests/ui/floating_point_rad.rs +++ b/src/tools/clippy/tests/ui/floating_point_rad.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(const_fn_floating_point_arithmetic)] #![warn(clippy::suboptimal_flops)] diff --git a/src/tools/clippy/tests/ui/floating_point_rad.stderr b/src/tools/clippy/tests/ui/floating_point_rad.stderr index 979442f2c..e7b42de04 100644 --- a/src/tools/clippy/tests/ui/floating_point_rad.stderr +++ b/src/tools/clippy/tests/ui/floating_point_rad.stderr @@ -1,49 +1,50 @@ error: conversion to radians can be done more accurately - --> $DIR/floating_point_rad.rs:12:13 + --> $DIR/floating_point_rad.rs:11:13 | LL | let _ = degrees as f64 * std::f64::consts::PI / 180.0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(degrees as f64).to_radians()` | = note: `-D clippy::suboptimal-flops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suboptimal_flops)]` error: conversion to degrees can be done more accurately - --> $DIR/floating_point_rad.rs:13:13 + --> $DIR/floating_point_rad.rs:12: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:18:13 + --> $DIR/floating_point_rad.rs:17: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:19:13 + --> $DIR/floating_point_rad.rs:18: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:20:13 + --> $DIR/floating_point_rad.rs:19: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:21:13 + --> $DIR/floating_point_rad.rs:20: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:22:13 + --> $DIR/floating_point_rad.rs:21: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:23:13 + --> $DIR/floating_point_rad.rs:22:13 | LL | let _ = 90.5 * std::f32::consts::PI / 180f32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `90.5_f64.to_radians()` diff --git a/src/tools/clippy/tests/ui/fn_address_comparisons.rs b/src/tools/clippy/tests/ui/fn_address_comparisons.rs index 362dcb4fd..35535bd4f 100644 --- a/src/tools/clippy/tests/ui/fn_address_comparisons.rs +++ b/src/tools/clippy/tests/ui/fn_address_comparisons.rs @@ -13,7 +13,10 @@ fn main() { // These should fail: let _ = f == a; + //~^ ERROR: comparing with a non-unique address of a function item + //~| NOTE: `-D clippy::fn-address-comparisons` implied by `-D warnings` let _ = f != a; + //~^ ERROR: comparing with a non-unique address of a function item // These should be fine: let _ = f == g; diff --git a/src/tools/clippy/tests/ui/fn_address_comparisons.stderr b/src/tools/clippy/tests/ui/fn_address_comparisons.stderr index 9c1b5419a..be7fa62f1 100644 --- a/src/tools/clippy/tests/ui/fn_address_comparisons.stderr +++ b/src/tools/clippy/tests/ui/fn_address_comparisons.stderr @@ -5,9 +5,10 @@ LL | let _ = f == a; | ^^^^^^ | = note: `-D clippy::fn-address-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::fn_address_comparisons)]` error: comparing with a non-unique address of a function item - --> $DIR/fn_address_comparisons.rs:16:13 + --> $DIR/fn_address_comparisons.rs:18:13 | LL | let _ = f != a; | ^^^^^^ diff --git a/src/tools/clippy/tests/ui/fn_params_excessive_bools.rs b/src/tools/clippy/tests/ui/fn_params_excessive_bools.rs index f53e53162..cc18708d2 100644 --- a/src/tools/clippy/tests/ui/fn_params_excessive_bools.rs +++ b/src/tools/clippy/tests/ui/fn_params_excessive_bools.rs @@ -17,22 +17,27 @@ foo!(); #[no_mangle] extern "C" fn k(_: bool, _: bool, _: bool, _: bool) {} fn g(_: bool, _: bool, _: bool, _: bool) {} +//~^ ERROR: more than 3 bools in function parameters fn h(_: bool, _: bool, _: bool) {} fn e(_: S, _: S, _: Box, _: Vec) {} fn t(_: S, _: S, _: Box, _: Vec, _: bool, _: bool, _: bool, _: bool) {} +//~^ ERROR: more than 3 bools in function parameters struct S; trait Trait { // should warn for trait functions with and without body fn f(_: bool, _: bool, _: bool, _: bool); + //~^ ERROR: more than 3 bools in function parameters fn g(_: bool, _: bool, _: bool, _: Vec); #[allow(clippy::fn_params_excessive_bools)] fn h(_: bool, _: bool, _: bool, _: bool, _: bool, _: bool); fn i(_: bool, _: bool, _: bool, _: bool) {} + //~^ ERROR: more than 3 bools in function parameters } impl S { fn f(&self, _: bool, _: bool, _: bool, _: bool) {} + //~^ ERROR: more than 3 bools in function parameters fn g(&self, _: bool, _: bool, _: bool) {} #[no_mangle] extern "C" fn h(_: bool, _: bool, _: bool, _: bool) {} @@ -48,6 +53,8 @@ impl Trait for S { fn main() { fn n(_: bool, _: u32, _: bool, _: Box, _: bool, _: bool) { + //~^ ERROR: more than 3 bools in function parameters fn nn(_: bool, _: bool, _: bool, _: bool) {} + //~^ ERROR: more than 3 bools in function parameters } } diff --git a/src/tools/clippy/tests/ui/fn_params_excessive_bools.stderr b/src/tools/clippy/tests/ui/fn_params_excessive_bools.stderr index 43363b469..f529d8cc4 100644 --- a/src/tools/clippy/tests/ui/fn_params_excessive_bools.stderr +++ b/src/tools/clippy/tests/ui/fn_params_excessive_bools.stderr @@ -6,9 +6,10 @@ LL | fn g(_: bool, _: bool, _: bool, _: bool) {} | = help: consider refactoring bools into two-variant enums = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::fn_params_excessive_bools)]` error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:22:1 + --> $DIR/fn_params_excessive_bools.rs:23:1 | LL | fn t(_: S, _: S, _: Box, _: Vec, _: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | fn t(_: S, _: S, _: Box, _: Vec, _: bool, _: bool, _: bool, _: bool = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:27:5 + --> $DIR/fn_params_excessive_bools.rs:29:5 | LL | fn f(_: bool, _: bool, _: bool, _: bool); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | fn f(_: bool, _: bool, _: bool, _: bool); = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:31:5 + --> $DIR/fn_params_excessive_bools.rs:34:5 | LL | fn i(_: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | fn i(_: bool, _: bool, _: bool, _: bool) {} = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:35:5 + --> $DIR/fn_params_excessive_bools.rs:39:5 | LL | fn f(&self, _: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,17 +41,19 @@ LL | fn f(&self, _: bool, _: bool, _: bool, _: bool) {} = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:50:5 + --> $DIR/fn_params_excessive_bools.rs:55:5 | LL | / fn n(_: bool, _: u32, _: bool, _: Box, _: bool, _: bool) { +LL | | LL | | fn nn(_: bool, _: bool, _: bool, _: bool) {} +LL | | LL | | } | |_____^ | = help: consider refactoring bools into two-variant enums error: more than 3 bools in function parameters - --> $DIR/fn_params_excessive_bools.rs:51:9 + --> $DIR/fn_params_excessive_bools.rs:57:9 | LL | fn nn(_: bool, _: bool, _: bool, _: bool) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast.32bit.stderr b/src/tools/clippy/tests/ui/fn_to_numeric_cast.32bit.stderr new file mode 100644 index 000000000..ea08d8c9c --- /dev/null +++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast.32bit.stderr @@ -0,0 +1,146 @@ +error: casting function pointer `foo` to `i8`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:10:13 + | +LL | let _ = foo as i8; + | ^^^^^^^^^ help: try: `foo as usize` + | + = note: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_with_truncation)]` + +error: casting function pointer `foo` to `i16`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:11:13 + | +LL | let _ = foo as i16; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `i32` + --> $DIR/fn_to_numeric_cast.rs:12:13 + | +LL | let _ = foo as i32; + | ^^^^^^^^^^ help: try: `foo as usize` + | + = note: `-D clippy::fn-to-numeric-cast` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast)]` + +error: casting function pointer `foo` to `i64` + --> $DIR/fn_to_numeric_cast.rs:13:13 + | +LL | let _ = foo as i64; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `i128` + --> $DIR/fn_to_numeric_cast.rs:14:13 + | +LL | let _ = foo as i128; + | ^^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `isize` + --> $DIR/fn_to_numeric_cast.rs:15:13 + | +LL | let _ = foo as isize; + | ^^^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u8`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:17:13 + | +LL | let _ = foo as u8; + | ^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u16`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:18:13 + | +LL | let _ = foo as u16; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u32` + --> $DIR/fn_to_numeric_cast.rs:19:13 + | +LL | let _ = foo as u32; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u64` + --> $DIR/fn_to_numeric_cast.rs:20:13 + | +LL | let _ = foo as u64; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u128` + --> $DIR/fn_to_numeric_cast.rs:21:13 + | +LL | let _ = foo as u128; + | ^^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `abc` to `i8`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:34:13 + | +LL | let _ = abc as i8; + | ^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `i16`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:35:13 + | +LL | let _ = abc as i16; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `i32` + --> $DIR/fn_to_numeric_cast.rs:36:13 + | +LL | let _ = abc as i32; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `i64` + --> $DIR/fn_to_numeric_cast.rs:37:13 + | +LL | let _ = abc as i64; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `i128` + --> $DIR/fn_to_numeric_cast.rs:38:13 + | +LL | let _ = abc as i128; + | ^^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `isize` + --> $DIR/fn_to_numeric_cast.rs:39:13 + | +LL | let _ = abc as isize; + | ^^^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u8`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:41:13 + | +LL | let _ = abc as u8; + | ^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u16`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:42:13 + | +LL | let _ = abc as u16; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u32` + --> $DIR/fn_to_numeric_cast.rs:43:13 + | +LL | let _ = abc as u32; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u64` + --> $DIR/fn_to_numeric_cast.rs:44:13 + | +LL | let _ = abc as u64; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u128` + --> $DIR/fn_to_numeric_cast.rs:45:13 + | +LL | let _ = abc as u128; + | ^^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `f` to `i32` + --> $DIR/fn_to_numeric_cast.rs:52:5 + | +LL | f as i32 + | ^^^^^^^^ help: try: `f as usize` + +error: aborting due to 23 previous errors + diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast.64bit.stderr b/src/tools/clippy/tests/ui/fn_to_numeric_cast.64bit.stderr new file mode 100644 index 000000000..62f3bfa70 --- /dev/null +++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast.64bit.stderr @@ -0,0 +1,146 @@ +error: casting function pointer `foo` to `i8`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:10:13 + | +LL | let _ = foo as i8; + | ^^^^^^^^^ help: try: `foo as usize` + | + = note: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_with_truncation)]` + +error: casting function pointer `foo` to `i16`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:11:13 + | +LL | let _ = foo as i16; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `i32`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:12:13 + | +LL | let _ = foo as i32; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `i64` + --> $DIR/fn_to_numeric_cast.rs:13:13 + | +LL | let _ = foo as i64; + | ^^^^^^^^^^ help: try: `foo as usize` + | + = note: `-D clippy::fn-to-numeric-cast` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast)]` + +error: casting function pointer `foo` to `i128` + --> $DIR/fn_to_numeric_cast.rs:14:13 + | +LL | let _ = foo as i128; + | ^^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `isize` + --> $DIR/fn_to_numeric_cast.rs:15:13 + | +LL | let _ = foo as isize; + | ^^^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u8`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:17:13 + | +LL | let _ = foo as u8; + | ^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u16`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:18:13 + | +LL | let _ = foo as u16; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u32`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:19:13 + | +LL | let _ = foo as u32; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u64` + --> $DIR/fn_to_numeric_cast.rs:20:13 + | +LL | let _ = foo as u64; + | ^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `foo` to `u128` + --> $DIR/fn_to_numeric_cast.rs:21:13 + | +LL | let _ = foo as u128; + | ^^^^^^^^^^^ help: try: `foo as usize` + +error: casting function pointer `abc` to `i8`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:34:13 + | +LL | let _ = abc as i8; + | ^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `i16`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:35:13 + | +LL | let _ = abc as i16; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `i32`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:36:13 + | +LL | let _ = abc as i32; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `i64` + --> $DIR/fn_to_numeric_cast.rs:37:13 + | +LL | let _ = abc as i64; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `i128` + --> $DIR/fn_to_numeric_cast.rs:38:13 + | +LL | let _ = abc as i128; + | ^^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `isize` + --> $DIR/fn_to_numeric_cast.rs:39:13 + | +LL | let _ = abc as isize; + | ^^^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u8`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:41:13 + | +LL | let _ = abc as u8; + | ^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u16`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:42:13 + | +LL | let _ = abc as u16; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u32`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:43:13 + | +LL | let _ = abc as u32; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u64` + --> $DIR/fn_to_numeric_cast.rs:44:13 + | +LL | let _ = abc as u64; + | ^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `abc` to `u128` + --> $DIR/fn_to_numeric_cast.rs:45:13 + | +LL | let _ = abc as u128; + | ^^^^^^^^^^^ help: try: `abc as usize` + +error: casting function pointer `f` to `i32`, which truncates the value + --> $DIR/fn_to_numeric_cast.rs:52:5 + | +LL | f as i32 + | ^^^^^^^^ help: try: `f as usize` + +error: aborting due to 23 previous errors + diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs b/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs index 4f6af8708..9501eb5da 100644 --- a/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs +++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs @@ -1,5 +1,5 @@ -//@ignore-32bit - +//@stderr-per-bitwidth +//@no-rustfix #![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)] fn foo() -> String { diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast.stderr b/src/tools/clippy/tests/ui/fn_to_numeric_cast.stderr deleted file mode 100644 index e9549e157..000000000 --- a/src/tools/clippy/tests/ui/fn_to_numeric_cast.stderr +++ /dev/null @@ -1,144 +0,0 @@ -error: casting function pointer `foo` to `i8`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:10:13 - | -LL | let _ = foo as i8; - | ^^^^^^^^^ help: try: `foo as usize` - | - = note: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings` - -error: casting function pointer `foo` to `i16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:11:13 - | -LL | let _ = foo as i16; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:12:13 - | -LL | let _ = foo as i32; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `i64` - --> $DIR/fn_to_numeric_cast.rs:13:13 - | -LL | let _ = foo as i64; - | ^^^^^^^^^^ help: try: `foo as usize` - | - = note: `-D clippy::fn-to-numeric-cast` implied by `-D warnings` - -error: casting function pointer `foo` to `i128` - --> $DIR/fn_to_numeric_cast.rs:14:13 - | -LL | let _ = foo as i128; - | ^^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `isize` - --> $DIR/fn_to_numeric_cast.rs:15:13 - | -LL | let _ = foo as isize; - | ^^^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u8`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:17:13 - | -LL | let _ = foo as u8; - | ^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:18:13 - | -LL | let _ = foo as u16; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:19:13 - | -LL | let _ = foo as u32; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u64` - --> $DIR/fn_to_numeric_cast.rs:20:13 - | -LL | let _ = foo as u64; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u128` - --> $DIR/fn_to_numeric_cast.rs:21:13 - | -LL | let _ = foo as u128; - | ^^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `abc` to `i8`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:34:13 - | -LL | let _ = abc as i8; - | ^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:35:13 - | -LL | let _ = abc as i16; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:36:13 - | -LL | let _ = abc as i32; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i64` - --> $DIR/fn_to_numeric_cast.rs:37:13 - | -LL | let _ = abc as i64; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i128` - --> $DIR/fn_to_numeric_cast.rs:38:13 - | -LL | let _ = abc as i128; - | ^^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `isize` - --> $DIR/fn_to_numeric_cast.rs:39:13 - | -LL | let _ = abc as isize; - | ^^^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u8`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:41:13 - | -LL | let _ = abc as u8; - | ^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u16`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:42:13 - | -LL | let _ = abc as u16; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:43:13 - | -LL | let _ = abc as u32; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u64` - --> $DIR/fn_to_numeric_cast.rs:44:13 - | -LL | let _ = abc as u64; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u128` - --> $DIR/fn_to_numeric_cast.rs:45:13 - | -LL | let _ = abc as u128; - | ^^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `f` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast.rs:52:5 - | -LL | f as i32 - | ^^^^^^^^ help: try: `f as usize` - -error: aborting due to 23 previous errors - diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs b/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs deleted file mode 100644 index 62ce97f09..000000000 --- a/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs +++ /dev/null @@ -1,55 +0,0 @@ -//@ignore-64bit - -#![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)] - -fn foo() -> String { - String::new() -} - -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; - - // Casting to usize is OK and should not warn - let _ = foo as usize; - - // Cast `f` (a `FnDef`) to `fn()` should not warn - fn f() {} - let _ = f as fn(); -} - -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 u8; - let _ = abc as u16; - let _ = abc as u32; - let _ = abc as u64; - let _ = abc as u128; - - // 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 -} - -fn main() {} diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.stderr b/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.stderr deleted file mode 100644 index 671347d2b..000000000 --- a/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.stderr +++ /dev/null @@ -1,144 +0,0 @@ -error: casting function pointer `foo` to `i8`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:10:13 - | -LL | let _ = foo as i8; - | ^^^^^^^^^ help: try: `foo as usize` - | - = note: `-D clippy::fn-to-numeric-cast-with-truncation` implied by `-D warnings` - -error: casting function pointer `foo` to `i16`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:11:13 - | -LL | let _ = foo as i16; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:12:13 - | -LL | let _ = foo as i32; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `i64` - --> $DIR/fn_to_numeric_cast_32bit.rs:13:13 - | -LL | let _ = foo as i64; - | ^^^^^^^^^^ help: try: `foo as usize` - | - = note: `-D clippy::fn-to-numeric-cast` implied by `-D warnings` - -error: casting function pointer `foo` to `i128` - --> $DIR/fn_to_numeric_cast_32bit.rs:14:13 - | -LL | let _ = foo as i128; - | ^^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `isize` - --> $DIR/fn_to_numeric_cast_32bit.rs:15:13 - | -LL | let _ = foo as isize; - | ^^^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u8`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:17:13 - | -LL | let _ = foo as u8; - | ^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u16`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:18:13 - | -LL | let _ = foo as u16; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u32`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:19:13 - | -LL | let _ = foo as u32; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u64` - --> $DIR/fn_to_numeric_cast_32bit.rs:20:13 - | -LL | let _ = foo as u64; - | ^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `foo` to `u128` - --> $DIR/fn_to_numeric_cast_32bit.rs:21:13 - | -LL | let _ = foo as u128; - | ^^^^^^^^^^^ help: try: `foo as usize` - -error: casting function pointer `abc` to `i8`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:34:13 - | -LL | let _ = abc as i8; - | ^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i16`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:35:13 - | -LL | let _ = abc as i16; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:36:13 - | -LL | let _ = abc as i32; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i64` - --> $DIR/fn_to_numeric_cast_32bit.rs:37:13 - | -LL | let _ = abc as i64; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `i128` - --> $DIR/fn_to_numeric_cast_32bit.rs:38:13 - | -LL | let _ = abc as i128; - | ^^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `isize` - --> $DIR/fn_to_numeric_cast_32bit.rs:39:13 - | -LL | let _ = abc as isize; - | ^^^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u8`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:41:13 - | -LL | let _ = abc as u8; - | ^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u16`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:42:13 - | -LL | let _ = abc as u16; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u32`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:43:13 - | -LL | let _ = abc as u32; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u64` - --> $DIR/fn_to_numeric_cast_32bit.rs:44:13 - | -LL | let _ = abc as u64; - | ^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `abc` to `u128` - --> $DIR/fn_to_numeric_cast_32bit.rs:45:13 - | -LL | let _ = abc as u128; - | ^^^^^^^^^^^ help: try: `abc as usize` - -error: casting function pointer `f` to `i32`, which truncates the value - --> $DIR/fn_to_numeric_cast_32bit.rs:52:5 - | -LL | f as i32 - | ^^^^^^^^ help: try: `f as usize` - -error: aborting due to 23 previous errors - diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.rs b/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.rs index 467046839..95abc0ac6 100644 --- a/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.rs +++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.rs @@ -1,6 +1,6 @@ #![warn(clippy::fn_to_numeric_cast_any)] #![allow(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)] - +//@no-rustfix fn foo() -> u8 { 0 } @@ -21,40 +21,58 @@ impl Trait for Struct {} fn fn_pointer_to_integer() { let _ = foo as i8; + //~^ ERROR: casting function pointer `foo` to `i8` + //~| NOTE: `-D clippy::fn-to-numeric-cast-any` implied by `-D warnings` let _ = foo as i16; + //~^ ERROR: casting function pointer `foo` to `i16` let _ = foo as i32; + //~^ ERROR: casting function pointer `foo` to `i32` let _ = foo as i64; + //~^ ERROR: casting function pointer `foo` to `i64` let _ = foo as i128; + //~^ ERROR: casting function pointer `foo` to `i128` let _ = foo as isize; + //~^ ERROR: casting function pointer `foo` to `isize` let _ = foo as u8; + //~^ ERROR: casting function pointer `foo` to `u8` let _ = foo as u16; + //~^ ERROR: casting function pointer `foo` to `u16` let _ = foo as u32; + //~^ ERROR: casting function pointer `foo` to `u32` let _ = foo as u64; + //~^ ERROR: casting function pointer `foo` to `u64` let _ = foo as u128; + //~^ ERROR: casting function pointer `foo` to `u128` let _ = foo as usize; + //~^ ERROR: casting function pointer `foo` to `usize` } fn static_method_to_integer() { let _ = Struct::static_method as usize; + //~^ ERROR: casting function pointer `Struct::static_method` to `usize` } fn fn_with_fn_arg(f: fn(i32) -> u32) -> usize { f as usize + //~^ ERROR: casting function pointer `f` to `usize` } fn fn_with_generic_static_trait_method() -> usize { T::static_method as usize + //~^ ERROR: casting function pointer `T::static_method` to `usize` } fn closure_to_fn_to_integer() { let clos = |x| x * 2_u32; let _ = (clos as fn(u32) -> u32) as usize; + //~^ ERROR: casting function pointer `(clos as fn(u32) -> u32)` to `usize` } fn fn_to_raw_ptr() { let _ = foo as *const (); + //~^ ERROR: casting function pointer `foo` to `*const ()` } fn cast_fn_to_self() { diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.stderr b/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.stderr index a6c4a7767..a1514c87b 100644 --- a/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.stderr +++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast_any.stderr @@ -5,99 +5,100 @@ LL | let _ = foo as i8; | ^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i8` | = note: `-D clippy::fn-to-numeric-cast-any` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::fn_to_numeric_cast_any)]` error: casting function pointer `foo` to `i16` - --> $DIR/fn_to_numeric_cast_any.rs:24:13 + --> $DIR/fn_to_numeric_cast_any.rs:26:13 | LL | let _ = foo as i16; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i16` error: casting function pointer `foo` to `i32` - --> $DIR/fn_to_numeric_cast_any.rs:25:13 + --> $DIR/fn_to_numeric_cast_any.rs:28:13 | LL | let _ = foo as i32; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i32` error: casting function pointer `foo` to `i64` - --> $DIR/fn_to_numeric_cast_any.rs:26:13 + --> $DIR/fn_to_numeric_cast_any.rs:30:13 | LL | let _ = foo as i64; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i64` error: casting function pointer `foo` to `i128` - --> $DIR/fn_to_numeric_cast_any.rs:27:13 + --> $DIR/fn_to_numeric_cast_any.rs:32:13 | LL | let _ = foo as i128; | ^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as i128` error: casting function pointer `foo` to `isize` - --> $DIR/fn_to_numeric_cast_any.rs:28:13 + --> $DIR/fn_to_numeric_cast_any.rs:34:13 | LL | let _ = foo as isize; | ^^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as isize` error: casting function pointer `foo` to `u8` - --> $DIR/fn_to_numeric_cast_any.rs:30:13 + --> $DIR/fn_to_numeric_cast_any.rs:37:13 | LL | let _ = foo as u8; | ^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u8` error: casting function pointer `foo` to `u16` - --> $DIR/fn_to_numeric_cast_any.rs:31:13 + --> $DIR/fn_to_numeric_cast_any.rs:39:13 | LL | let _ = foo as u16; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u16` error: casting function pointer `foo` to `u32` - --> $DIR/fn_to_numeric_cast_any.rs:32:13 + --> $DIR/fn_to_numeric_cast_any.rs:41:13 | LL | let _ = foo as u32; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u32` error: casting function pointer `foo` to `u64` - --> $DIR/fn_to_numeric_cast_any.rs:33:13 + --> $DIR/fn_to_numeric_cast_any.rs:43:13 | LL | let _ = foo as u64; | ^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u64` error: casting function pointer `foo` to `u128` - --> $DIR/fn_to_numeric_cast_any.rs:34:13 + --> $DIR/fn_to_numeric_cast_any.rs:45:13 | LL | let _ = foo as u128; | ^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as u128` error: casting function pointer `foo` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:35:13 + --> $DIR/fn_to_numeric_cast_any.rs:47:13 | LL | let _ = foo as usize; | ^^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as usize` error: casting function pointer `Struct::static_method` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:39:13 + --> $DIR/fn_to_numeric_cast_any.rs:52:13 | LL | let _ = Struct::static_method as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `Struct::static_method() as usize` error: casting function pointer `f` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:43:5 + --> $DIR/fn_to_numeric_cast_any.rs:57:5 | LL | f as usize | ^^^^^^^^^^ help: did you mean to invoke the function?: `f() as usize` error: casting function pointer `T::static_method` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:47:5 + --> $DIR/fn_to_numeric_cast_any.rs:62:5 | LL | T::static_method as usize | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `T::static_method() as usize` error: casting function pointer `(clos as fn(u32) -> u32)` to `usize` - --> $DIR/fn_to_numeric_cast_any.rs:53:13 + --> $DIR/fn_to_numeric_cast_any.rs:69:13 | LL | let _ = (clos as fn(u32) -> u32) as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `(clos as fn(u32) -> u32)() as usize` error: casting function pointer `foo` to `*const ()` - --> $DIR/fn_to_numeric_cast_any.rs:57:13 + --> $DIR/fn_to_numeric_cast_any.rs:74:13 | LL | let _ = foo as *const (); | ^^^^^^^^^^^^^^^^ help: did you mean to invoke the function?: `foo() as *const ()` diff --git a/src/tools/clippy/tests/ui/for_kv_map.fixed b/src/tools/clippy/tests/ui/for_kv_map.fixed new file mode 100644 index 000000000..a2112d7b7 --- /dev/null +++ b/src/tools/clippy/tests/ui/for_kv_map.fixed @@ -0,0 +1,56 @@ +#![warn(clippy::for_kv_map)] +#![allow(clippy::used_underscore_binding)] + +use std::collections::*; +use std::rc::Rc; + +fn main() { + let m: HashMap = HashMap::new(); + for v in m.values() { + //~^ ERROR: you seem to want to iterate on a map's values + //~| NOTE: `-D clippy::for-kv-map` implied by `-D warnings` + let _v = v; + } + + let m: Rc> = Rc::new(HashMap::new()); + for v in (*m).values() { + //~^ ERROR: you seem to want to iterate on a map's values + let _v = v; + // Here the `*` is not actually necessary, but the test tests that we don't + // suggest + // `in *m.values()` as we used to + } + + let mut m: HashMap = HashMap::new(); + for v in m.values_mut() { + //~^ ERROR: you seem to want to iterate on a map's values + let _v = v; + } + + let m: &mut HashMap = &mut HashMap::new(); + for v in (*m).values_mut() { + //~^ ERROR: you seem to want to iterate on a map's values + let _v = v; + } + + let m: HashMap = HashMap::new(); + let rm = &m; + for k in rm.keys() { + //~^ ERROR: you seem to want to iterate on a map's keys + let _k = k; + } + + // The following should not produce warnings. + + let m: HashMap = HashMap::new(); + // No error, _value is actually used + for (k, _value) in &m { + let _ = _value; + let _k = k; + } + + let m: HashMap = Default::default(); + for (_, v) in m { + let _v = v; + } +} diff --git a/src/tools/clippy/tests/ui/for_kv_map.rs b/src/tools/clippy/tests/ui/for_kv_map.rs index 39a8d960a..1b7959b8f 100644 --- a/src/tools/clippy/tests/ui/for_kv_map.rs +++ b/src/tools/clippy/tests/ui/for_kv_map.rs @@ -7,11 +7,14 @@ use std::rc::Rc; fn main() { let m: HashMap = HashMap::new(); for (_, v) in &m { + //~^ ERROR: you seem to want to iterate on a map's values + //~| NOTE: `-D clippy::for-kv-map` implied by `-D warnings` let _v = v; } let m: Rc> = Rc::new(HashMap::new()); for (_, v) in &*m { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; // Here the `*` is not actually necessary, but the test tests that we don't // suggest @@ -20,17 +23,20 @@ fn main() { let mut m: HashMap = HashMap::new(); for (_, v) in &mut m { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; } let m: &mut HashMap = &mut HashMap::new(); for (_, v) in &mut *m { + //~^ ERROR: you seem to want to iterate on a map's values let _v = v; } let m: HashMap = HashMap::new(); let rm = &m; for (k, _value) in rm { + //~^ ERROR: you seem to want to iterate on a map's keys let _k = k; } diff --git a/src/tools/clippy/tests/ui/for_kv_map.stderr b/src/tools/clippy/tests/ui/for_kv_map.stderr index e5cc7c146..d29617e24 100644 --- a/src/tools/clippy/tests/ui/for_kv_map.stderr +++ b/src/tools/clippy/tests/ui/for_kv_map.stderr @@ -5,13 +5,14 @@ LL | for (_, v) in &m { | ^^ | = note: `-D clippy::for-kv-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::for_kv_map)]` help: use the corresponding method | LL | for v in m.values() { | ~ ~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> $DIR/for_kv_map.rs:14:19 + --> $DIR/for_kv_map.rs:16:19 | LL | for (_, v) in &*m { | ^^^ @@ -22,7 +23,7 @@ LL | for v in (*m).values() { | ~ ~~~~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> $DIR/for_kv_map.rs:22:19 + --> $DIR/for_kv_map.rs:25:19 | LL | for (_, v) in &mut m { | ^^^^^^ @@ -33,7 +34,7 @@ LL | for v in m.values_mut() { | ~ ~~~~~~~~~~~~~~ error: you seem to want to iterate on a map's values - --> $DIR/for_kv_map.rs:27:19 + --> $DIR/for_kv_map.rs:31:19 | LL | for (_, v) in &mut *m { | ^^^^^^^ @@ -44,7 +45,7 @@ LL | for v in (*m).values_mut() { | ~ ~~~~~~~~~~~~~~~~~ error: you seem to want to iterate on a map's keys - --> $DIR/for_kv_map.rs:33:24 + --> $DIR/for_kv_map.rs:38:24 | LL | for (k, _value) in rm { | ^^ diff --git a/src/tools/clippy/tests/ui/forget_non_drop.rs b/src/tools/clippy/tests/ui/forget_non_drop.rs index 7580cf95e..2459f51a3 100644 --- a/src/tools/clippy/tests/ui/forget_non_drop.rs +++ b/src/tools/clippy/tests/ui/forget_non_drop.rs @@ -11,6 +11,7 @@ fn main() { struct Foo; // Lint forget(Foo); + //~^ ERROR: call to `std::mem::forget` with a value that does not implement `Drop`. Fo struct Bar; impl Drop for Bar { @@ -22,6 +23,7 @@ fn main() { struct Baz(T); // Lint forget(Baz(Foo)); + //~^ ERROR: call to `std::mem::forget` with a value that does not implement `Drop`. Fo // Don't lint forget(Baz(Bar)); } diff --git a/src/tools/clippy/tests/ui/forget_non_drop.stderr b/src/tools/clippy/tests/ui/forget_non_drop.stderr index 194e37c8b..c0fa433c4 100644 --- a/src/tools/clippy/tests/ui/forget_non_drop.stderr +++ b/src/tools/clippy/tests/ui/forget_non_drop.stderr @@ -10,15 +10,16 @@ note: argument has type `main::Foo` LL | forget(Foo); | ^^^ = note: `-D clippy::forget-non-drop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::forget_non_drop)]` error: call to `std::mem::forget` with a value that does not implement `Drop`. Forgetting such a type is the same as dropping it - --> $DIR/forget_non_drop.rs:24:5 + --> $DIR/forget_non_drop.rs:25:5 | LL | forget(Baz(Foo)); | ^^^^^^^^^^^^^^^^ | note: argument has type `main::Baz` - --> $DIR/forget_non_drop.rs:24:12 + --> $DIR/forget_non_drop.rs:25:12 | LL | forget(Baz(Foo)); | ^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/format.fixed b/src/tools/clippy/tests/ui/format.fixed index 2e24e07ea..36679a9c8 100644 --- a/src/tools/clippy/tests/ui/format.fixed +++ b/src/tools/clippy/tests/ui/format.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::useless_format)] #![allow( unused_tuple_struct_fields, diff --git a/src/tools/clippy/tests/ui/format.rs b/src/tools/clippy/tests/ui/format.rs index 0e64a310b..b0920daf0 100644 --- a/src/tools/clippy/tests/ui/format.rs +++ b/src/tools/clippy/tests/ui/format.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::useless_format)] #![allow( unused_tuple_struct_fields, diff --git a/src/tools/clippy/tests/ui/format.stderr b/src/tools/clippy/tests/ui/format.stderr index 78a11a335..d4630a8f1 100644 --- a/src/tools/clippy/tests/ui/format.stderr +++ b/src/tools/clippy/tests/ui/format.stderr @@ -1,25 +1,26 @@ error: useless use of `format!` - --> $DIR/format.rs:21:5 + --> $DIR/format.rs:20:5 | LL | format!("foo"); | ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` | = note: `-D clippy::useless-format` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::useless_format)]` error: useless use of `format!` - --> $DIR/format.rs:22:5 + --> $DIR/format.rs:21:5 | LL | format!("{{}}"); | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string()` error: useless use of `format!` - --> $DIR/format.rs:23:5 + --> $DIR/format.rs:22:5 | LL | format!("{{}} abc {{}}"); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string()` error: useless use of `format!` - --> $DIR/format.rs:24:5 + --> $DIR/format.rs:23:5 | LL | / format!( LL | | r##"foo {{}} @@ -34,67 +35,67 @@ LL ~ " bar"##.to_string(); | error: useless use of `format!` - --> $DIR/format.rs:29:13 + --> $DIR/format.rs:28:13 | LL | let _ = format!(""); | ^^^^^^^^^^^ help: consider using `String::new()`: `String::new()` error: useless use of `format!` - --> $DIR/format.rs:31:5 + --> $DIR/format.rs:30:5 | LL | format!("{}", "foo"); | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` error: useless use of `format!` - --> $DIR/format.rs:39:5 + --> $DIR/format.rs:38:5 | LL | format!("{}", arg); | ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()` error: useless use of `format!` - --> $DIR/format.rs:69:5 + --> $DIR/format.rs:68:5 | LL | format!("{}", 42.to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()` error: useless use of `format!` - --> $DIR/format.rs:71:5 + --> $DIR/format.rs:70:5 | LL | format!("{}", x.display().to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()` error: useless use of `format!` - --> $DIR/format.rs:75:18 + --> $DIR/format.rs:74:18 | LL | let _ = Some(format!("{}", a + "bar")); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"` error: useless use of `format!` - --> $DIR/format.rs:79:22 + --> $DIR/format.rs:78:22 | -LL | let _s: String = format!("{}", &*v.join("/n")); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("/n")).to_string()` +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:85:13 + --> $DIR/format.rs:84:13 | LL | let _ = format!("{x}"); | ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()` error: useless use of `format!` - --> $DIR/format.rs:87:13 + --> $DIR/format.rs:86:13 | LL | let _ = format!("{y}", y = x); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()` error: useless use of `format!` - --> $DIR/format.rs:91:13 + --> $DIR/format.rs:90:13 | LL | let _ = format!("{abc}"); | ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `abc.to_string()` error: useless use of `format!` - --> $DIR/format.rs:93:13 + --> $DIR/format.rs:92:13 | LL | let _ = format!("{xx}"); | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `xx.to_string()` diff --git a/src/tools/clippy/tests/ui/format_args.fixed b/src/tools/clippy/tests/ui/format_args.fixed index ea3836861..ddd5976c4 100644 --- a/src/tools/clippy/tests/ui/format_args.fixed +++ b/src/tools/clippy/tests/ui/format_args.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::to_string_in_format_args)] #![allow(unused)] #![allow( diff --git a/src/tools/clippy/tests/ui/format_args.rs b/src/tools/clippy/tests/ui/format_args.rs index bfb324492..18e1bc1af 100644 --- a/src/tools/clippy/tests/ui/format_args.rs +++ b/src/tools/clippy/tests/ui/format_args.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::to_string_in_format_args)] #![allow(unused)] #![allow( diff --git a/src/tools/clippy/tests/ui/format_args.stderr b/src/tools/clippy/tests/ui/format_args.stderr index f1832b970..dcdfa668a 100644 --- a/src/tools/clippy/tests/ui/format_args.stderr +++ b/src/tools/clippy/tests/ui/format_args.stderr @@ -1,151 +1,152 @@ error: `to_string` applied to a type that implements `Display` in `format!` args - --> $DIR/format_args.rs:77:72 + --> $DIR/format_args.rs:76:72 | LL | let _ = format!("error: something failed at {}", Location::caller().to_string()); | ^^^^^^^^^^^^ help: remove this | = note: `-D clippy::to-string-in-format-args` implied by `-D warnings` + = 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:80: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:85: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:87: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:88: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:89: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:90: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:91: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:92: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:93: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:94: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:95: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:96: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:97: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:98: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:99: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:100: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:102: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:103: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:104: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:105: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:117: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:118: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:146: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:160:24 | LL | println!("{}", original[..10].to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use this: `&original[..10]` diff --git a/src/tools/clippy/tests/ui/format_args_unfixable.rs b/src/tools/clippy/tests/ui/format_args_unfixable.rs index 423bfaf97..b7492e38b 100644 --- a/src/tools/clippy/tests/ui/format_args_unfixable.rs +++ b/src/tools/clippy/tests/ui/format_args_unfixable.rs @@ -24,31 +24,49 @@ fn main() { let x = 'x'; println!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("{}: {}", error, format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("{:?}: {}", error, format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("{{}}: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!(r#"error: "{}""#, format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("error: {}", format!(r#"something failed at "{}""#, Location::caller())); + //~^ ERROR: `format!` in `println!` args println!("error: {}", format!("something failed at {} {0}", Location::caller())); + //~^ ERROR: `format!` in `println!` args let _ = format!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `format!` args let _ = write!( + //~^ ERROR: `format!` in `write!` args stdout(), "error: {}", format!("something failed at {}", Location::caller()) ); let _ = writeln!( + //~^ ERROR: `format!` in `writeln!` args stdout(), "error: {}", format!("something failed at {}", Location::caller()) ); print!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `print!` args eprint!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `eprint!` args eprintln!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `eprintln!` args let _ = format_args!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `format_args!` args assert!(true, "error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `assert!` args assert_eq!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `assert_eq!` args assert_ne!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `assert_ne!` args panic!("error: {}", format!("something failed at {}", Location::caller())); + //~^ ERROR: `format!` in `panic!` args // negative tests println!("error: {}", format_args!("something failed at {}", Location::caller())); diff --git a/src/tools/clippy/tests/ui/format_args_unfixable.stderr b/src/tools/clippy/tests/ui/format_args_unfixable.stderr index c1be48c3b..3ffe2f6c8 100644 --- a/src/tools/clippy/tests/ui/format_args_unfixable.stderr +++ b/src/tools/clippy/tests/ui/format_args_unfixable.stderr @@ -7,9 +7,10 @@ LL | println!("error: {}", format!("something failed at {}", Location::calle = help: combine the `format!(..)` arguments with the outer `println!(..)` call = help: or consider changing `format!` to `format_args!` = note: `-D clippy::format-in-format-args` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::format_in_format_args)]` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:27:5 + --> $DIR/format_args_unfixable.rs:28:5 | LL | println!("{}: {}", error, format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -18,7 +19,7 @@ LL | println!("{}: {}", error, format!("something failed at {}", Location::c = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:28:5 + --> $DIR/format_args_unfixable.rs:30:5 | LL | println!("{:?}: {}", error, format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +28,7 @@ LL | println!("{:?}: {}", error, format!("something failed at {}", Location: = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:29:5 + --> $DIR/format_args_unfixable.rs:32:5 | LL | println!("{{}}: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +37,7 @@ LL | println!("{{}}: {}", format!("something failed at {}", Location::caller = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:30:5 + --> $DIR/format_args_unfixable.rs:34:5 | LL | println!(r#"error: "{}""#, format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +46,7 @@ LL | println!(r#"error: "{}""#, format!("something failed at {}", Location:: = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:31:5 + --> $DIR/format_args_unfixable.rs:36:5 | LL | println!("error: {}", format!(r#"something failed at "{}""#, Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,7 +55,7 @@ LL | println!("error: {}", format!(r#"something failed at "{}""#, Location:: = help: or consider changing `format!` to `format_args!` error: `format!` in `println!` args - --> $DIR/format_args_unfixable.rs:32:5 + --> $DIR/format_args_unfixable.rs:38:5 | LL | println!("error: {}", format!("something failed at {} {0}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -63,7 +64,7 @@ LL | println!("error: {}", format!("something failed at {} {0}", Location::c = help: or consider changing `format!` to `format_args!` error: `format!` in `format!` args - --> $DIR/format_args_unfixable.rs:33:13 + --> $DIR/format_args_unfixable.rs:40:13 | LL | let _ = format!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,10 +73,11 @@ LL | let _ = format!("error: {}", format!("something failed at {}", Location = help: or consider changing `format!` to `format_args!` error: `format!` in `write!` args - --> $DIR/format_args_unfixable.rs:34:13 + --> $DIR/format_args_unfixable.rs:42:13 | LL | let _ = write!( | _____________^ +LL | | LL | | stdout(), LL | | "error: {}", LL | | format!("something failed at {}", Location::caller()) @@ -86,10 +88,11 @@ LL | | ); = help: or consider changing `format!` to `format_args!` error: `format!` in `writeln!` args - --> $DIR/format_args_unfixable.rs:39:13 + --> $DIR/format_args_unfixable.rs:48:13 | LL | let _ = writeln!( | _____________^ +LL | | LL | | stdout(), LL | | "error: {}", LL | | format!("something failed at {}", Location::caller()) @@ -100,7 +103,7 @@ LL | | ); = help: or consider changing `format!` to `format_args!` error: `format!` in `print!` args - --> $DIR/format_args_unfixable.rs:44:5 + --> $DIR/format_args_unfixable.rs:54:5 | LL | print!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +112,7 @@ LL | print!("error: {}", format!("something failed at {}", Location::caller( = help: or consider changing `format!` to `format_args!` error: `format!` in `eprint!` args - --> $DIR/format_args_unfixable.rs:45:5 + --> $DIR/format_args_unfixable.rs:56:5 | LL | eprint!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -118,7 +121,7 @@ LL | eprint!("error: {}", format!("something failed at {}", Location::caller = help: or consider changing `format!` to `format_args!` error: `format!` in `eprintln!` args - --> $DIR/format_args_unfixable.rs:46:5 + --> $DIR/format_args_unfixable.rs:58:5 | LL | eprintln!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -127,7 +130,7 @@ LL | eprintln!("error: {}", format!("something failed at {}", Location::call = help: or consider changing `format!` to `format_args!` error: `format!` in `format_args!` args - --> $DIR/format_args_unfixable.rs:47:13 + --> $DIR/format_args_unfixable.rs:60:13 | LL | let _ = format_args!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -136,7 +139,7 @@ LL | let _ = format_args!("error: {}", format!("something failed at {}", Loc = help: or consider changing `format!` to `format_args!` error: `format!` in `assert!` args - --> $DIR/format_args_unfixable.rs:48:5 + --> $DIR/format_args_unfixable.rs:62:5 | LL | assert!(true, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -145,7 +148,7 @@ LL | assert!(true, "error: {}", format!("something failed at {}", Location:: = help: or consider changing `format!` to `format_args!` error: `format!` in `assert_eq!` args - --> $DIR/format_args_unfixable.rs:49:5 + --> $DIR/format_args_unfixable.rs:64:5 | LL | assert_eq!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +157,7 @@ LL | assert_eq!(0, 0, "error: {}", format!("something failed at {}", Locatio = help: or consider changing `format!` to `format_args!` error: `format!` in `assert_ne!` args - --> $DIR/format_args_unfixable.rs:50:5 + --> $DIR/format_args_unfixable.rs:66:5 | LL | assert_ne!(0, 0, "error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -163,7 +166,7 @@ LL | assert_ne!(0, 0, "error: {}", format!("something failed at {}", Locatio = help: or consider changing `format!` to `format_args!` error: `format!` in `panic!` args - --> $DIR/format_args_unfixable.rs:51:5 + --> $DIR/format_args_unfixable.rs:68:5 | LL | panic!("error: {}", format!("something failed at {}", Location::caller())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/format_collect.rs b/src/tools/clippy/tests/ui/format_collect.rs index c7f2b7b69..26ebdc6c0 100644 --- a/src/tools/clippy/tests/ui/format_collect.rs +++ b/src/tools/clippy/tests/ui/format_collect.rs @@ -3,11 +3,13 @@ fn hex_encode(bytes: &[u8]) -> String { bytes.iter().map(|b| format!("{b:02X}")).collect() + //~^ ERROR: use of `format!` to build up a string from an iterator } #[rustfmt::skip] fn hex_encode_deep(bytes: &[u8]) -> String { bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() + //~^ ERROR: use of `format!` to build up a string from an iterator } macro_rules! fmt { @@ -22,6 +24,7 @@ fn from_macro(bytes: &[u8]) -> String { fn with_block() -> String { (1..10) + //~^ ERROR: use of `format!` to build up a string from an iterator .map(|s| { let y = 1; format!("{s} {y}") diff --git a/src/tools/clippy/tests/ui/format_collect.stderr b/src/tools/clippy/tests/ui/format_collect.stderr index d918f1ed4..340218ccf 100644 --- a/src/tools/clippy/tests/ui/format_collect.stderr +++ b/src/tools/clippy/tests/ui/format_collect.stderr @@ -16,29 +16,31 @@ LL | bytes.iter().map(|b| format!("{b:02X}")).collect() | ^^^^^^^^^^^^^^^^^^ = note: this can be written more efficiently by appending to a `String` directly = note: `-D clippy::format-collect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::format_collect)]` error: use of `format!` to build up a string from an iterator - --> $DIR/format_collect.rs:10:5 + --> $DIR/format_collect.rs:11:5 | LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: call `fold` instead - --> $DIR/format_collect.rs:10:18 + --> $DIR/format_collect.rs:11:18 | LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() | ^^^ help: ... and use the `write!` macro here - --> $DIR/format_collect.rs:10:32 + --> $DIR/format_collect.rs:11:32 | LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect() | ^^^^^^^^^^^^^^^^^^ = note: this can be written more efficiently by appending to a `String` directly error: use of `format!` to build up a string from an iterator - --> $DIR/format_collect.rs:24:5 + --> $DIR/format_collect.rs:26:5 | LL | / (1..10) +LL | | LL | | .map(|s| { LL | | let y = 1; LL | | format!("{s} {y}") @@ -47,12 +49,12 @@ LL | | .collect() | |__________________^ | help: call `fold` instead - --> $DIR/format_collect.rs:25:10 + --> $DIR/format_collect.rs:28:10 | LL | .map(|s| { | ^^^ help: ... and use the `write!` macro here - --> $DIR/format_collect.rs:27:13 + --> $DIR/format_collect.rs:30:13 | LL | format!("{s} {y}") | ^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/format_push_string.rs b/src/tools/clippy/tests/ui/format_push_string.rs index 89423ffe1..735ae3393 100644 --- a/src/tools/clippy/tests/ui/format_push_string.rs +++ b/src/tools/clippy/tests/ui/format_push_string.rs @@ -3,7 +3,9 @@ fn main() { let mut string = String::new(); string += &format!("{:?}", 1234); + //~^ ERROR: `format!(..)` appended to existing `String` string.push_str(&format!("{:?}", 5678)); + //~^ ERROR: `format!(..)` appended to existing `String` } mod issue9493 { @@ -11,6 +13,7 @@ mod issue9493 { let mut hex = String::with_capacity(vector.len() * 2); for byte in vector { hex += &(if upper { + //~^ ERROR: `format!(..)` appended to existing `String` format!("{byte:02X}") } else { format!("{byte:02x}") @@ -23,12 +26,14 @@ mod issue9493 { let mut s = String::new(); // if let s += &(if let Some(_a) = Some(1234) { + //~^ ERROR: `format!(..)` appended to existing `String` format!("{}", 1234) } else { format!("{}", 1234) }); // match s += &(match Some(1234) { + //~^ ERROR: `format!(..)` appended to existing `String` Some(_) => format!("{}", 1234), None => format!("{}", 1234), }); diff --git a/src/tools/clippy/tests/ui/format_push_string.stderr b/src/tools/clippy/tests/ui/format_push_string.stderr index 76762c4a1..545915b56 100644 --- a/src/tools/clippy/tests/ui/format_push_string.stderr +++ b/src/tools/clippy/tests/ui/format_push_string.stderr @@ -6,9 +6,10 @@ LL | string += &format!("{:?}", 1234); | = help: consider using `write!` to avoid the extra allocation = note: `-D clippy::format-push-string` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::format_push_string)]` error: `format!(..)` appended to existing `String` - --> $DIR/format_push_string.rs:6:5 + --> $DIR/format_push_string.rs:7:5 | LL | string.push_str(&format!("{:?}", 5678)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,9 +17,10 @@ LL | string.push_str(&format!("{:?}", 5678)); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> $DIR/format_push_string.rs:13:13 + --> $DIR/format_push_string.rs:15:13 | LL | / hex += &(if upper { +LL | | LL | | format!("{byte:02X}") LL | | } else { LL | | format!("{byte:02x}") @@ -28,9 +30,10 @@ LL | | }); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> $DIR/format_push_string.rs:25:9 + --> $DIR/format_push_string.rs:28:9 | LL | / s += &(if let Some(_a) = Some(1234) { +LL | | LL | | format!("{}", 1234) LL | | } else { LL | | format!("{}", 1234) @@ -40,9 +43,10 @@ LL | | }); = help: consider using `write!` to avoid the extra allocation error: `format!(..)` appended to existing `String` - --> $DIR/format_push_string.rs:31:9 + --> $DIR/format_push_string.rs:35:9 | LL | / s += &(match Some(1234) { +LL | | LL | | Some(_) => format!("{}", 1234), LL | | None => format!("{}", 1234), LL | | }); diff --git a/src/tools/clippy/tests/ui/formatting.rs b/src/tools/clippy/tests/ui/formatting.rs index 471a8e0de..312fa2aa4 100644 --- a/src/tools/clippy/tests/ui/formatting.rs +++ b/src/tools/clippy/tests/ui/formatting.rs @@ -14,10 +14,16 @@ fn main() { // weird op_eq formatting: let mut a = 42; a =- 35; + //~^ ERROR: this looks like you are trying to use `.. -= ..`, but you really are doing + //~| NOTE: to remove this lint, use either `-=` or `= -` a =* &191; + //~^ ERROR: this looks like you are trying to use `.. *= ..`, but you really are doing + //~| NOTE: to remove this lint, use either `*=` or `= *` let mut b = true; b =! false; + //~^ ERROR: this looks like you are trying to use `.. != ..`, but you really are doing + //~| NOTE: to remove this lint, use either `!=` or `= !` // those are ok: a = -35; @@ -27,10 +33,14 @@ fn main() { // possible missing comma in an array let _ = &[ -1, -2, -3 // <= no comma here + //~^ ERROR: possibly missing a comma here + //~| NOTE: to remove this lint, add a comma or write the expr in a single line -4, -5, -6 ]; let _ = &[ -1, -2, -3 // <= no comma here + //~^ ERROR: possibly missing a comma here + //~| NOTE: to remove this lint, add a comma or write the expr in a single line *4, -5, -6 ]; @@ -68,6 +78,8 @@ fn main() { // lint if it doesn't let _ = &[ -1 + //~^ ERROR: possibly missing a comma here + //~| NOTE: to remove this lint, add a comma or write the expr in a single line -4, ]; } diff --git a/src/tools/clippy/tests/ui/formatting.stderr b/src/tools/clippy/tests/ui/formatting.stderr index caccd5cba..d4eb8e511 100644 --- a/src/tools/clippy/tests/ui/formatting.stderr +++ b/src/tools/clippy/tests/ui/formatting.stderr @@ -6,9 +6,10 @@ LL | a =- 35; | = note: to remove this lint, use either `-=` or `= -` = note: `-D clippy::suspicious-assignment-formatting` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_assignment_formatting)]` error: this looks like you are trying to use `.. *= ..`, but you really are doing `.. = (* ..)` - --> $DIR/formatting.rs:17:6 + --> $DIR/formatting.rs:19:6 | LL | a =* &191; | ^^^^ @@ -16,7 +17,7 @@ LL | a =* &191; = note: to remove this lint, use either `*=` or `= *` error: this looks like you are trying to use `.. != ..`, but you really are doing `.. = (! ..)` - --> $DIR/formatting.rs:20:6 + --> $DIR/formatting.rs:24:6 | LL | b =! false; | ^^^^ @@ -24,16 +25,17 @@ LL | b =! false; = note: to remove this lint, use either `!=` or `= !` error: possibly missing a comma here - --> $DIR/formatting.rs:29:19 + --> $DIR/formatting.rs:35:19 | LL | -1, -2, -3 // <= no comma here | ^ | = note: to remove this lint, add a comma or write the expr in a single line = note: `-D clippy::possible-missing-comma` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::possible_missing_comma)]` error: possibly missing a comma here - --> $DIR/formatting.rs:33:19 + --> $DIR/formatting.rs:41:19 | LL | -1, -2, -3 // <= no comma here | ^ @@ -41,7 +43,7 @@ LL | -1, -2, -3 // <= no comma here = note: to remove this lint, add a comma or write the expr in a single line error: possibly missing a comma here - --> $DIR/formatting.rs:70:11 + --> $DIR/formatting.rs:80:11 | LL | -1 | ^ diff --git a/src/tools/clippy/tests/ui/four_forward_slashes.fixed b/src/tools/clippy/tests/ui/four_forward_slashes.fixed index 54b2c414b..6d31c543d 100644 --- a/src/tools/clippy/tests/ui/four_forward_slashes.fixed +++ b/src/tools/clippy/tests/ui/four_forward_slashes.fixed @@ -1,5 +1,5 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro + +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(unused)] #![warn(clippy::four_forward_slashes)] diff --git a/src/tools/clippy/tests/ui/four_forward_slashes.rs b/src/tools/clippy/tests/ui/four_forward_slashes.rs index facdc8cb1..458b8de53 100644 --- a/src/tools/clippy/tests/ui/four_forward_slashes.rs +++ b/src/tools/clippy/tests/ui/four_forward_slashes.rs @@ -1,5 +1,5 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro + +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(unused)] #![warn(clippy::four_forward_slashes)] diff --git a/src/tools/clippy/tests/ui/four_forward_slashes.stderr b/src/tools/clippy/tests/ui/four_forward_slashes.stderr index 89162e6b0..6450c5f94 100644 --- a/src/tools/clippy/tests/ui/four_forward_slashes.stderr +++ b/src/tools/clippy/tests/ui/four_forward_slashes.stderr @@ -6,6 +6,7 @@ LL | | fn a() {} | |_ | = note: `-D clippy::four-forward-slashes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::four_forward_slashes)]` help: make this a doc comment by removing one `/` | LL + /// whoops diff --git a/src/tools/clippy/tests/ui/four_forward_slashes_first_line.fixed b/src/tools/clippy/tests/ui/four_forward_slashes_first_line.fixed index ce272b4c6..5ef40015d 100644 --- a/src/tools/clippy/tests/ui/four_forward_slashes_first_line.fixed +++ b/src/tools/clippy/tests/ui/four_forward_slashes_first_line.fixed @@ -1,7 +1,6 @@ /// borked doc comment on the first line. doesn't combust! fn a() {} -//@run-rustfix // This test's entire purpose is to make sure we don't panic if the comment with four slashes // extends to the first line of the file. This is likely pretty rare in production, but an ICE is an // ICE. diff --git a/src/tools/clippy/tests/ui/four_forward_slashes_first_line.rs b/src/tools/clippy/tests/ui/four_forward_slashes_first_line.rs index d8f82d441..9c835e745 100644 --- a/src/tools/clippy/tests/ui/four_forward_slashes_first_line.rs +++ b/src/tools/clippy/tests/ui/four_forward_slashes_first_line.rs @@ -1,7 +1,6 @@ //// borked doc comment on the first line. doesn't combust! fn a() {} -//@run-rustfix // This test's entire purpose is to make sure we don't panic if the comment with four slashes // extends to the first line of the file. This is likely pretty rare in production, but an ICE is an // ICE. diff --git a/src/tools/clippy/tests/ui/four_forward_slashes_first_line.stderr b/src/tools/clippy/tests/ui/four_forward_slashes_first_line.stderr index 7944da14f..afb7c6b4d 100644 --- a/src/tools/clippy/tests/ui/four_forward_slashes_first_line.stderr +++ b/src/tools/clippy/tests/ui/four_forward_slashes_first_line.stderr @@ -6,6 +6,7 @@ LL | | fn a() {} | |_ | = note: `-D clippy::four-forward-slashes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::four_forward_slashes)]` help: make this a doc comment by removing one `/` | LL + /// borked doc comment on the first line. doesn't combust! diff --git a/src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed b/src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed index 1671987cb..82c8e1d8a 100644 --- a/src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed +++ b/src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::from_iter_instead_of_collect)] #![allow(unused_imports, unused_tuple_struct_fields)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/from_iter_instead_of_collect.rs b/src/tools/clippy/tests/ui/from_iter_instead_of_collect.rs index 48509b32f..2aed6b14b 100644 --- a/src/tools/clippy/tests/ui/from_iter_instead_of_collect.rs +++ b/src/tools/clippy/tests/ui/from_iter_instead_of_collect.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::from_iter_instead_of_collect)] #![allow(unused_imports, unused_tuple_struct_fields)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/from_iter_instead_of_collect.stderr b/src/tools/clippy/tests/ui/from_iter_instead_of_collect.stderr index 8f08ac8c3..6e86341d1 100644 --- a/src/tools/clippy/tests/ui/from_iter_instead_of_collect.stderr +++ b/src/tools/clippy/tests/ui/from_iter_instead_of_collect.stderr @@ -1,91 +1,92 @@ error: usage of `FromIterator::from_iter` - --> $DIR/from_iter_instead_of_collect.rs:19:9 + --> $DIR/from_iter_instead_of_collect.rs:17:9 | LL | >::from_iter(iter.into_iter().copied()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `iter.into_iter().copied().collect::()` | = note: `-D clippy::from-iter-instead-of-collect` implied by `-D warnings` + = 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:25:13 + --> $DIR/from_iter_instead_of_collect.rs:23: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:27:13 + --> $DIR/from_iter_instead_of_collect.rs:25: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:32:19 + --> $DIR/from_iter_instead_of_collect.rs:30: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:19 + --> $DIR/from_iter_instead_of_collect.rs:31: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:35:17 + --> $DIR/from_iter_instead_of_collect.rs:33: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:38:17 + --> $DIR/from_iter_instead_of_collect.rs:36: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:43:21 + --> $DIR/from_iter_instead_of_collect.rs:41: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:48:14 + --> $DIR/from_iter_instead_of_collect.rs:46: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:49:19 + --> $DIR/from_iter_instead_of_collect.rs:47: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:52:19 + --> $DIR/from_iter_instead_of_collect.rs:50: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:56:17 + --> $DIR/from_iter_instead_of_collect.rs:54: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:57:17 + --> $DIR/from_iter_instead_of_collect.rs:55: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:60:15 + --> $DIR/from_iter_instead_of_collect.rs:58: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:61:15 + --> $DIR/from_iter_instead_of_collect.rs:59: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/src/tools/clippy/tests/ui/from_over_into.fixed b/src/tools/clippy/tests/ui/from_over_into.fixed index d96b68a91..18d285693 100644 --- a/src/tools/clippy/tests/ui/from_over_into.fixed +++ b/src/tools/clippy/tests/ui/from_over_into.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(type_alias_impl_trait)] #![warn(clippy::from_over_into)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/from_over_into.rs b/src/tools/clippy/tests/ui/from_over_into.rs index da8fe04f4..779ef709e 100644 --- a/src/tools/clippy/tests/ui/from_over_into.rs +++ b/src/tools/clippy/tests/ui/from_over_into.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(type_alias_impl_trait)] #![warn(clippy::from_over_into)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/from_over_into.stderr b/src/tools/clippy/tests/ui/from_over_into.stderr index 498b00de5..784843ce5 100644 --- a/src/tools/clippy/tests/ui/from_over_into.stderr +++ b/src/tools/clippy/tests/ui/from_over_into.stderr @@ -1,10 +1,11 @@ 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:10:1 + --> $DIR/from_over_into.rs:8:1 | LL | impl Into for String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::from-over-into` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::from_over_into)]` help: replace the `Into` implementation with `From` | LL ~ impl From for StringWrapper { @@ -13,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:18:1 + --> $DIR/from_over_into.rs:16:1 | LL | impl Into for String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -26,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:33:1 + --> $DIR/from_over_into.rs:31:1 | LL | impl Into for X { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,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:45:1 + --> $DIR/from_over_into.rs:43:1 | LL | impl core::convert::Into for crate::ExplicitPaths { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -59,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:65:1 + --> $DIR/from_over_into.rs:63:1 | LL | impl Into for PathInExpansion { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,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:87:5 + --> $DIR/from_over_into.rs:85:5 | LL | impl Into> for Vec { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/from_over_into_unfixable.rs b/src/tools/clippy/tests/ui/from_over_into_unfixable.rs index c769e38eb..0c1f39f93 100644 --- a/src/tools/clippy/tests/ui/from_over_into_unfixable.rs +++ b/src/tools/clippy/tests/ui/from_over_into_unfixable.rs @@ -9,6 +9,7 @@ macro_rules! in_macro { } impl Into for String { + //~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free fn into(self) -> InMacro { InMacro(in_macro!()) } @@ -17,6 +18,7 @@ impl Into for String { struct WeirdUpperSelf; impl Into for &'static [u8] { + //~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free fn into(self) -> WeirdUpperSelf { let _ = Self::default(); WeirdUpperSelf @@ -26,6 +28,7 @@ impl Into for &'static [u8] { struct ContainsVal; impl Into for ContainsVal { + //~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free fn into(self) -> u8 { let val = 1; val + 1 @@ -37,6 +40,7 @@ pub struct Lval(T); pub struct Rval(T); impl Into> for Lval { + //~^ ERROR: an implementation of `From` is preferred since it gives you `Into<_>` for free fn into(self) -> Rval { Rval(self) } diff --git a/src/tools/clippy/tests/ui/from_over_into_unfixable.stderr b/src/tools/clippy/tests/ui/from_over_into_unfixable.stderr index 2ab9b9d6b..8ef36f082 100644 --- a/src/tools/clippy/tests/ui/from_over_into_unfixable.stderr +++ b/src/tools/clippy/tests/ui/from_over_into_unfixable.stderr @@ -6,9 +6,10 @@ LL | impl Into for String { | = help: replace the `Into` implementation with `From` = note: `-D clippy::from-over-into` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::from_over_into)]` error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into_unfixable.rs:19:1 + --> $DIR/from_over_into_unfixable.rs:20:1 | LL | impl Into for &'static [u8] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | impl Into for &'static [u8] { = help: replace the `Into` implementation with `From<&'static [u8]>` error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into_unfixable.rs:28:1 + --> $DIR/from_over_into_unfixable.rs:30:1 | LL | impl Into for ContainsVal { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -26,7 +27,7 @@ LL | impl Into for ContainsVal { = help: replace the `Into` implementation with `From` error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true - --> $DIR/from_over_into_unfixable.rs:39:1 + --> $DIR/from_over_into_unfixable.rs:42:1 | LL | impl Into> for Lval { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/from_raw_with_void_ptr.rs b/src/tools/clippy/tests/ui/from_raw_with_void_ptr.rs index 95ef6425f..81472070e 100644 --- a/src/tools/clippy/tests/ui/from_raw_with_void_ptr.rs +++ b/src/tools/clippy/tests/ui/from_raw_with_void_ptr.rs @@ -9,6 +9,7 @@ fn main() { // must lint let ptr = Box::into_raw(Box::new(42usize)) as *mut c_void; let _ = unsafe { Box::from_raw(ptr) }; + //~^ ERROR: creating a `Box` from a void raw pointer // shouldn't be linted let _ = unsafe { Box::from_raw(ptr as *mut usize) }; @@ -20,16 +21,20 @@ fn main() { // must lint let ptr = Rc::into_raw(Rc::new(42usize)) as *mut c_void; let _ = unsafe { Rc::from_raw(ptr) }; + //~^ ERROR: creating a `Rc` from a void raw pointer // must lint let ptr = Arc::into_raw(Arc::new(42usize)) as *mut c_void; let _ = unsafe { Arc::from_raw(ptr) }; + //~^ ERROR: creating a `Arc` from a void raw pointer // must lint let ptr = std::rc::Weak::into_raw(Rc::downgrade(&Rc::new(42usize))) as *mut c_void; let _ = unsafe { std::rc::Weak::from_raw(ptr) }; + //~^ ERROR: creating a `Weak` from a void raw pointer // must lint let ptr = std::sync::Weak::into_raw(Arc::downgrade(&Arc::new(42usize))) as *mut c_void; let _ = unsafe { std::sync::Weak::from_raw(ptr) }; + //~^ ERROR: creating a `Weak` from a void raw pointer } diff --git a/src/tools/clippy/tests/ui/from_raw_with_void_ptr.stderr b/src/tools/clippy/tests/ui/from_raw_with_void_ptr.stderr index 1963d0801..6e1ad0d99 100644 --- a/src/tools/clippy/tests/ui/from_raw_with_void_ptr.stderr +++ b/src/tools/clippy/tests/ui/from_raw_with_void_ptr.stderr @@ -10,51 +10,52 @@ help: cast this to a pointer of the appropriate type LL | let _ = unsafe { Box::from_raw(ptr) }; | ^^^ = note: `-D clippy::from-raw-with-void-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::from_raw_with_void_ptr)]` error: creating a `Rc` from a void raw pointer - --> $DIR/from_raw_with_void_ptr.rs:22:22 + --> $DIR/from_raw_with_void_ptr.rs:23:22 | LL | let _ = unsafe { Rc::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> $DIR/from_raw_with_void_ptr.rs:22:35 + --> $DIR/from_raw_with_void_ptr.rs:23:35 | LL | let _ = unsafe { Rc::from_raw(ptr) }; | ^^^ error: creating a `Arc` from a void raw pointer - --> $DIR/from_raw_with_void_ptr.rs:26:22 + --> $DIR/from_raw_with_void_ptr.rs:28:22 | LL | let _ = unsafe { Arc::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> $DIR/from_raw_with_void_ptr.rs:26:36 + --> $DIR/from_raw_with_void_ptr.rs:28:36 | LL | let _ = unsafe { Arc::from_raw(ptr) }; | ^^^ error: creating a `Weak` from a void raw pointer - --> $DIR/from_raw_with_void_ptr.rs:30:22 + --> $DIR/from_raw_with_void_ptr.rs:33:22 | LL | let _ = unsafe { std::rc::Weak::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> $DIR/from_raw_with_void_ptr.rs:30:46 + --> $DIR/from_raw_with_void_ptr.rs:33:46 | LL | let _ = unsafe { std::rc::Weak::from_raw(ptr) }; | ^^^ error: creating a `Weak` from a void raw pointer - --> $DIR/from_raw_with_void_ptr.rs:34:22 + --> $DIR/from_raw_with_void_ptr.rs:38:22 | LL | let _ = unsafe { std::sync::Weak::from_raw(ptr) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: cast this to a pointer of the appropriate type - --> $DIR/from_raw_with_void_ptr.rs:34:48 + --> $DIR/from_raw_with_void_ptr.rs:38:48 | LL | let _ = unsafe { std::sync::Weak::from_raw(ptr) }; | ^^^ diff --git a/src/tools/clippy/tests/ui/from_str_radix_10.fixed b/src/tools/clippy/tests/ui/from_str_radix_10.fixed new file mode 100644 index 000000000..8c253bfd9 --- /dev/null +++ b/src/tools/clippy/tests/ui/from_str_radix_10.fixed @@ -0,0 +1,61 @@ +#![warn(clippy::from_str_radix_10)] + +mod some_mod { + // fake function that shouldn't trigger the lint + pub fn from_str_radix(_: &str, _: u32) -> Result<(), std::num::ParseIntError> { + unimplemented!() + } +} + +// fake function that shouldn't trigger the lint +fn from_str_radix(_: &str, _: u32) -> Result<(), std::num::ParseIntError> { + unimplemented!() +} + +// to test parenthesis addition +struct Test; + +impl std::ops::Add for Test { + type Output = &'static str; + + fn add(self, _: Self) -> Self::Output { + "304" + } +} + +fn main() -> Result<(), Box> { + // all of these should trigger the lint + "30".parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~| NOTE: `-D clippy::from-str-radix-10` implied by `-D warnings` + "24".parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + "100".parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + "7".parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + ("10".to_owned() + "5").parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + (Test + Test).parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + + let string = "300"; + string.parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + + let stringier = "400".to_string(); + stringier.parse::()?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + + // none of these should trigger the lint + u16::from_str_radix("20", 3)?; + i32::from_str_radix("45", 12)?; + usize::from_str_radix("10", 16)?; + i128::from_str_radix("10", 13)?; + some_mod::from_str_radix("50", 10)?; + some_mod::from_str_radix("50", 6)?; + from_str_radix("50", 10)?; + from_str_radix("50", 6)?; + + Ok(()) +} diff --git a/src/tools/clippy/tests/ui/from_str_radix_10.rs b/src/tools/clippy/tests/ui/from_str_radix_10.rs index 2f2ea0484..e9d022157 100644 --- a/src/tools/clippy/tests/ui/from_str_radix_10.rs +++ b/src/tools/clippy/tests/ui/from_str_radix_10.rs @@ -26,17 +26,26 @@ impl std::ops::Add for Test { fn main() -> Result<(), Box> { // all of these should trigger the lint u32::from_str_radix("30", 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` + //~| NOTE: `-D clippy::from-str-radix-10` implied by `-D warnings` i64::from_str_radix("24", 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` isize::from_str_radix("100", 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` u8::from_str_radix("7", 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` u16::from_str_radix(&("10".to_owned() + "5"), 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` i128::from_str_radix(Test + Test, 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` let string = "300"; i32::from_str_radix(string, 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` let stringier = "400".to_string(); i32::from_str_radix(&stringier, 10)?; + //~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse` // none of these should trigger the lint u16::from_str_radix("20", 3)?; diff --git a/src/tools/clippy/tests/ui/from_str_radix_10.stderr b/src/tools/clippy/tests/ui/from_str_radix_10.stderr index da5c16f8d..439dcff74 100644 --- a/src/tools/clippy/tests/ui/from_str_radix_10.stderr +++ b/src/tools/clippy/tests/ui/from_str_radix_10.stderr @@ -5,45 +5,46 @@ LL | u32::from_str_radix("30", 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"30".parse::()` | = note: `-D clippy::from-str-radix-10` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::from_str_radix_10)]` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:29:5 + --> $DIR/from_str_radix_10.rs:31:5 | LL | i64::from_str_radix("24", 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"24".parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:30:5 + --> $DIR/from_str_radix_10.rs:33:5 | LL | isize::from_str_radix("100", 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"100".parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:31:5 + --> $DIR/from_str_radix_10.rs:35:5 | LL | u8::from_str_radix("7", 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"7".parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:32:5 + --> $DIR/from_str_radix_10.rs:37:5 | LL | u16::from_str_radix(&("10".to_owned() + "5"), 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `("10".to_owned() + "5").parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:33:5 + --> $DIR/from_str_radix_10.rs:39:5 | LL | i128::from_str_radix(Test + Test, 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(Test + Test).parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:36:5 + --> $DIR/from_str_radix_10.rs:43:5 | LL | i32::from_str_radix(string, 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.parse::()` error: this call to `from_str_radix` can be replaced with a call to `str::parse` - --> $DIR/from_str_radix_10.rs:39:5 + --> $DIR/from_str_radix_10.rs:47:5 | LL | i32::from_str_radix(&stringier, 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `stringier.parse::()` diff --git a/src/tools/clippy/tests/ui/functions.rs b/src/tools/clippy/tests/ui/functions.rs index 18149bfbc..0aef60959 100644 --- a/src/tools/clippy/tests/ui/functions.rs +++ b/src/tools/clippy/tests/ui/functions.rs @@ -6,9 +6,12 @@ fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {} fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} +//~^ ERROR: this function has too many arguments (8/7) +//~| NOTE: `-D clippy::too-many-arguments` implied by `-D warnings` #[rustfmt::skip] fn bad_multiline( +//~^ ERROR: this function has too many arguments (8/7) one: u32, two: u32, three: &str, @@ -43,6 +46,7 @@ extern "C" fn extern_fn( pub trait Foo { fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool); fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()); + //~^ ERROR: this function has too many arguments (8/7) fn ptr(p: *const u8); } @@ -52,6 +56,7 @@ pub struct Bar; impl Bar { fn good_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {} fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} + //~^ ERROR: this function has too many arguments (8/7) } // ok, we don’t want to warn implementations @@ -61,8 +66,12 @@ impl Foo for Bar { fn ptr(p: *const u8) { println!("{}", unsafe { *p }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked + //~| NOTE: `-D clippy::not-unsafe-ptr-arg-deref` implied by `-D warnings` println!("{:?}", unsafe { p.as_ref() }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked unsafe { std::ptr::read(p) }; + //~^ ERROR: this public function might dereference a raw pointer but is not marked } } @@ -74,16 +83,22 @@ fn private(p: *const u8) { pub fn public(p: *const u8) { println!("{}", unsafe { *p }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un println!("{:?}", unsafe { p.as_ref() }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un unsafe { std::ptr::read(p) }; + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un } type Alias = *const u8; pub fn type_alias(p: Alias) { println!("{}", unsafe { *p }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un println!("{:?}", unsafe { p.as_ref() }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un unsafe { std::ptr::read(p) }; + //~^ ERROR: this public function might dereference a raw pointer but is not marked `un } impl Bar { @@ -93,8 +108,11 @@ impl Bar { pub fn public(self, p: *const u8) { println!("{}", unsafe { *p }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked println!("{:?}", unsafe { p.as_ref() }); + //~^ ERROR: this public function might dereference a raw pointer but is not marked unsafe { std::ptr::read(p) }; + //~^ ERROR: this public function might dereference a raw pointer but is not marked } pub fn public_ok(self, p: *const u8) { diff --git a/src/tools/clippy/tests/ui/functions.stderr b/src/tools/clippy/tests/ui/functions.stderr index 8ebd4997f..371ea1612 100644 --- a/src/tools/clippy/tests/ui/functions.stderr +++ b/src/tools/clippy/tests/ui/functions.stderr @@ -5,101 +5,103 @@ LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::too-many-arguments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::too_many_arguments)]` error: this function has too many arguments (8/7) - --> $DIR/functions.rs:11:1 + --> $DIR/functions.rs:13:1 | LL | / fn bad_multiline( +LL | | LL | | one: u32, LL | | two: u32, -LL | | three: &str, ... | LL | | eight: () LL | | ) { | |__^ error: this function has too many arguments (8/7) - --> $DIR/functions.rs:45:5 + --> $DIR/functions.rs:48:5 | LL | fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this function has too many arguments (8/7) - --> $DIR/functions.rs:54:5 + --> $DIR/functions.rs:58:5 | LL | fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:63:34 + --> $DIR/functions.rs:68:34 | LL | println!("{}", unsafe { *p }); | ^ | = note: `-D clippy::not-unsafe-ptr-arg-deref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::not_unsafe_ptr_arg_deref)]` error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:64:35 + --> $DIR/functions.rs:71:35 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:65:33 + --> $DIR/functions.rs:73:33 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:76:30 + --> $DIR/functions.rs:85:30 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:77:31 + --> $DIR/functions.rs:87:31 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:78:29 + --> $DIR/functions.rs:89:29 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:84:30 + --> $DIR/functions.rs:96:30 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:85:31 + --> $DIR/functions.rs:98:31 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:86:29 + --> $DIR/functions.rs:100:29 | LL | unsafe { std::ptr::read(p) }; | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:95:34 + --> $DIR/functions.rs:110:34 | LL | println!("{}", unsafe { *p }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:96:35 + --> $DIR/functions.rs:112:35 | LL | println!("{:?}", unsafe { p.as_ref() }); | ^ error: this public function might dereference a raw pointer but is not marked `unsafe` - --> $DIR/functions.rs:97:33 + --> $DIR/functions.rs:114:33 | LL | unsafe { std::ptr::read(p) }; | ^ diff --git a/src/tools/clippy/tests/ui/functions_maxlines.rs b/src/tools/clippy/tests/ui/functions_maxlines.rs index 5e1ee55e0..a3496f56d 100644 --- a/src/tools/clippy/tests/ui/functions_maxlines.rs +++ b/src/tools/clippy/tests/ui/functions_maxlines.rs @@ -56,6 +56,8 @@ fn good_lines() { } fn bad_lines() { + //~^ ERROR: this function has too many lines (102/100) + //~| NOTE: `-D clippy::too-many-lines` implied by `-D warnings` println!("Dont get confused by braces: {{}}"); println!("This is bad."); println!("This is bad."); diff --git a/src/tools/clippy/tests/ui/functions_maxlines.stderr b/src/tools/clippy/tests/ui/functions_maxlines.stderr index dc6c8ba2f..1d6ddad79 100644 --- a/src/tools/clippy/tests/ui/functions_maxlines.stderr +++ b/src/tools/clippy/tests/ui/functions_maxlines.stderr @@ -2,15 +2,16 @@ error: this function has too many lines (102/100) --> $DIR/functions_maxlines.rs:58:1 | LL | / fn bad_lines() { +LL | | +LL | | LL | | println!("Dont get confused by braces: {{}}"); -LL | | println!("This is bad."); -LL | | println!("This is bad."); ... | LL | | println!("This is bad."); LL | | } | |_^ | = note: `-D clippy::too-many-lines` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::too_many_lines)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/future_not_send.rs b/src/tools/clippy/tests/ui/future_not_send.rs index 858036692..9274340b5 100644 --- a/src/tools/clippy/tests/ui/future_not_send.rs +++ b/src/tools/clippy/tests/ui/future_not_send.rs @@ -5,10 +5,12 @@ use std::rc::Rc; use std::sync::Arc; async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { + //~^ ERROR: future cannot be sent between threads safely async { true }.await } pub async fn public_future(rc: Rc<[u8]>) { + //~^ ERROR: future cannot be sent between threads safely async { true }.await; } @@ -17,10 +19,12 @@ pub async fn public_send(arc: Arc<[u8]>) -> bool { } async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { + //~^ ERROR: future cannot be sent between threads safely true } pub async fn public_future2(rc: Rc<[u8]>) {} +//~^ ERROR: future cannot be sent between threads safely pub async fn public_send2(arc: Arc<[u8]>) -> bool { false @@ -32,11 +36,13 @@ struct Dummy { impl Dummy { async fn private_future(&self) -> usize { + //~^ ERROR: future cannot be sent between threads safely async { true }.await; self.rc.len() } pub async fn public_future(&self) { + //~^ ERROR: future cannot be sent between threads safely self.private_future().await; } @@ -47,11 +53,13 @@ impl Dummy { } async fn generic_future(t: T) -> T +//~^ ERROR: future cannot be sent between threads safely where T: Send, { let rt = &t; async { true }.await; + let _ = rt; t } @@ -63,6 +71,7 @@ where } async fn unclear_future(t: T) {} +//~^ ERROR: future cannot be sent between threads safely fn main() { let rc = Rc::new([1, 2, 3]); diff --git a/src/tools/clippy/tests/ui/future_not_send.stderr b/src/tools/clippy/tests/ui/future_not_send.stderr index 5c6348962..f43e3c8ff 100644 --- a/src/tools/clippy/tests/ui/future_not_send.stderr +++ b/src/tools/clippy/tests/ui/future_not_send.stderr @@ -5,137 +5,123 @@ LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^^^ future returned by `private_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:8:20 + --> $DIR/future_not_send.rs:9:20 | LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { | -- has type `std::rc::Rc<[u8]>` which is not `Send` +LL | LL | async { true }.await | ^^^^^ await occurs here, with `rc` maybe used later -LL | } - | - `rc` is later dropped here = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` -note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:8:20 +note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` + --> $DIR/future_not_send.rs:7:39 | LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell) -> bool { - | ---- has type `&std::cell::Cell` which is not `Send` -LL | async { true }.await - | ^^^^^ await occurs here, with `cell` maybe used later -LL | } - | - `cell` is later dropped here + | ^^^^ has type `&std::cell::Cell` which is not `Send`, because `std::cell::Cell` is not `Sync` = note: `std::cell::Cell` doesn't implement `std::marker::Sync` = note: `-D clippy::future-not-send` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::future_not_send)]` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:11:42 + --> $DIR/future_not_send.rs:12:42 | LL | pub async fn public_future(rc: Rc<[u8]>) { | ^ future returned by `public_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:12:20 + --> $DIR/future_not_send.rs:14:20 | LL | pub async fn public_future(rc: Rc<[u8]>) { | -- has type `std::rc::Rc<[u8]>` which is not `Send` +LL | LL | async { true }.await; | ^^^^^ await occurs here, with `rc` maybe used later -LL | } - | - `rc` is later dropped here = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:19:63 + --> $DIR/future_not_send.rs:21:63 | LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^^^ future returned by `private_future2` is not `Send` | note: captured value is not `Send` - --> $DIR/future_not_send.rs:19:26 + --> $DIR/future_not_send.rs:21:26 | LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^ has type `std::rc::Rc<[u8]>` which is not `Send` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` - --> $DIR/future_not_send.rs:19:40 + --> $DIR/future_not_send.rs:21:40 | LL | async fn private_future2(rc: Rc<[u8]>, cell: &Cell) -> bool { | ^^^^ has type `&std::cell::Cell` which is not `Send`, because `std::cell::Cell` is not `Sync` = note: `std::cell::Cell` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:23:43 + --> $DIR/future_not_send.rs:26:43 | LL | pub async fn public_future2(rc: Rc<[u8]>) {} | ^ future returned by `public_future2` is not `Send` | note: captured value is not `Send` - --> $DIR/future_not_send.rs:23:29 + --> $DIR/future_not_send.rs:26:29 | LL | pub async fn public_future2(rc: Rc<[u8]>) {} | ^^ has type `std::rc::Rc<[u8]>` which is not `Send` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:34:39 + --> $DIR/future_not_send.rs:38:39 | LL | async fn private_future(&self) -> usize { | ^^^^^ future returned by `private_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:35:24 + --> $DIR/future_not_send.rs:40:24 | LL | async fn private_future(&self) -> usize { | ----- has type `&Dummy` which is not `Send` +LL | LL | async { true }.await; | ^^^^^ await occurs here, with `&self` maybe used later -LL | self.rc.len() -LL | } - | - `&self` is later dropped here = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:39:39 + --> $DIR/future_not_send.rs:44:39 | LL | pub async fn public_future(&self) { | ^ future returned by `public_future` is not `Send` | -note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:40:31 +note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` + --> $DIR/future_not_send.rs:44:32 | LL | pub async fn public_future(&self) { - | ----- has type `&Dummy` which is not `Send` -LL | self.private_future().await; - | ^^^^^ await occurs here, with `&self` maybe used later -LL | } - | - `&self` is later dropped here + | ^^^^^ has type `&Dummy` which is not `Send`, because `Dummy` is not `Sync` = note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:49:37 + --> $DIR/future_not_send.rs:55:37 | LL | async fn generic_future(t: T) -> T | ^ future returned by `generic_future` is not `Send` | note: future is not `Send` as this value is used across an await - --> $DIR/future_not_send.rs:54:20 + --> $DIR/future_not_send.rs:61:20 | LL | let rt = &t; | -- has type `&T` which is not `Send` LL | async { true }.await; | ^^^^^ await occurs here, with `rt` maybe used later -LL | t -LL | } - | - `rt` is later dropped here = note: `T` doesn't implement `std::marker::Sync` error: future cannot be sent between threads safely - --> $DIR/future_not_send.rs:65:34 + --> $DIR/future_not_send.rs:73:34 | LL | async fn unclear_future(t: T) {} | ^ future returned by `unclear_future` is not `Send` | note: captured value is not `Send` - --> $DIR/future_not_send.rs:65:28 + --> $DIR/future_not_send.rs:73:28 | LL | async fn unclear_future(t: T) {} | ^ has type `T` which is not `Send` diff --git a/src/tools/clippy/tests/ui/get_first.fixed b/src/tools/clippy/tests/ui/get_first.fixed index bc2f86566..b1a597fc4 100644 --- a/src/tools/clippy/tests/ui/get_first.fixed +++ b/src/tools/clippy/tests/ui/get_first.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::get_first)] #![allow(clippy::useless_vec)] use std::collections::{BTreeMap, HashMap, VecDeque}; diff --git a/src/tools/clippy/tests/ui/get_first.rs b/src/tools/clippy/tests/ui/get_first.rs index bc0e233fd..e27ee4be8 100644 --- a/src/tools/clippy/tests/ui/get_first.rs +++ b/src/tools/clippy/tests/ui/get_first.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::get_first)] #![allow(clippy::useless_vec)] use std::collections::{BTreeMap, HashMap, VecDeque}; diff --git a/src/tools/clippy/tests/ui/get_first.stderr b/src/tools/clippy/tests/ui/get_first.stderr index 0899a5905..56b4c29a3 100644 --- a/src/tools/clippy/tests/ui/get_first.stderr +++ b/src/tools/clippy/tests/ui/get_first.stderr @@ -1,19 +1,20 @@ error: accessing first element with `x.get(0)` - --> $DIR/get_first.rs:18:13 + --> $DIR/get_first.rs:17:13 | LL | let _ = x.get(0); // Use x.first() | ^^^^^^^^ help: try: `x.first()` | = note: `-D clippy::get-first` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::get_first)]` error: accessing first element with `y.get(0)` - --> $DIR/get_first.rs:23:13 + --> $DIR/get_first.rs:22:13 | LL | let _ = y.get(0); // Use y.first() | ^^^^^^^^ help: try: `y.first()` error: accessing first element with `z.get(0)` - --> $DIR/get_first.rs:28:13 + --> $DIR/get_first.rs:27:13 | LL | let _ = z.get(0); // Use z.first() | ^^^^^^^^ help: try: `z.first()` diff --git a/src/tools/clippy/tests/ui/get_last_with_len.fixed b/src/tools/clippy/tests/ui/get_last_with_len.fixed index 01a83e5bf..377906cb2 100644 --- a/src/tools/clippy/tests/ui/get_last_with_len.fixed +++ b/src/tools/clippy/tests/ui/get_last_with_len.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::get_last_with_len)] #![allow(unused, clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/get_last_with_len.rs b/src/tools/clippy/tests/ui/get_last_with_len.rs index d82484b46..273593204 100644 --- a/src/tools/clippy/tests/ui/get_last_with_len.rs +++ b/src/tools/clippy/tests/ui/get_last_with_len.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::get_last_with_len)] #![allow(unused, clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/get_last_with_len.stderr b/src/tools/clippy/tests/ui/get_last_with_len.stderr index ac8dd6c2e..0056adc57 100644 --- a/src/tools/clippy/tests/ui/get_last_with_len.stderr +++ b/src/tools/clippy/tests/ui/get_last_with_len.stderr @@ -1,37 +1,38 @@ error: accessing last element with `x.get(x.len() - 1)` - --> $DIR/get_last_with_len.rs:10:13 + --> $DIR/get_last_with_len.rs:8:13 | LL | let _ = x.get(x.len() - 1); | ^^^^^^^^^^^^^^^^^^ help: try: `x.last()` | = note: `-D clippy::get-last-with-len` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::get_last_with_len)]` error: accessing last element with `s.field.get(s.field.len() - 1)` - --> $DIR/get_last_with_len.rs:34:13 + --> $DIR/get_last_with_len.rs:32:13 | LL | let _ = s.field.get(s.field.len() - 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.field.last()` error: accessing last element with `slice.get(slice.len() - 1)` - --> $DIR/get_last_with_len.rs:39:13 + --> $DIR/get_last_with_len.rs:37:13 | LL | let _ = slice.get(slice.len() - 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `slice.last()` error: accessing last element with `array.get(array.len() - 1)` - --> $DIR/get_last_with_len.rs:42:13 + --> $DIR/get_last_with_len.rs:40:13 | LL | let _ = array.get(array.len() - 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `array.last()` error: accessing last element with `deq.get(deq.len() - 1)` - --> $DIR/get_last_with_len.rs:45:13 + --> $DIR/get_last_with_len.rs:43:13 | LL | let _ = deq.get(deq.len() - 1); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `deq.back()` error: accessing last element with `nested[0].get(nested[0].len() - 1)` - --> $DIR/get_last_with_len.rs:48:13 + --> $DIR/get_last_with_len.rs:46:13 | LL | let _ = nested[0].get(nested[0].len() - 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `nested[0].last()` diff --git a/src/tools/clippy/tests/ui/get_unwrap.fixed b/src/tools/clippy/tests/ui/get_unwrap.fixed index fda334407..d5a4309db 100644 --- a/src/tools/clippy/tests/ui/get_unwrap.fixed +++ b/src/tools/clippy/tests/ui/get_unwrap.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( unused_mut, clippy::from_iter_instead_of_collect, diff --git a/src/tools/clippy/tests/ui/get_unwrap.rs b/src/tools/clippy/tests/ui/get_unwrap.rs index eaf6b005a..5a9ad204f 100644 --- a/src/tools/clippy/tests/ui/get_unwrap.rs +++ b/src/tools/clippy/tests/ui/get_unwrap.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( unused_mut, clippy::from_iter_instead_of_collect, diff --git a/src/tools/clippy/tests/ui/get_unwrap.stderr b/src/tools/clippy/tests/ui/get_unwrap.stderr index 19dc9071f..384860ea1 100644 --- a/src/tools/clippy/tests/ui/get_unwrap.stderr +++ b/src/tools/clippy/tests/ui/get_unwrap.stderr @@ -1,17 +1,17 @@ error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:38:17 + --> $DIR/get_unwrap.rs:36:17 | LL | let _ = boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&boxed_slice[1]` | note: the lint level is defined here - --> $DIR/get_unwrap.rs:10:9 + --> $DIR/get_unwrap.rs:8:9 | LL | #![deny(clippy::get_unwrap)] | ^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:38:17 + --> $DIR/get_unwrap.rs:36:17 | LL | let _ = boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -19,15 +19,16 @@ LL | let _ = boxed_slice.get(1).unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message = note: `-D clippy::unwrap-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise - --> $DIR/get_unwrap.rs:39:17 + --> $DIR/get_unwrap.rs:37:17 | LL | let _ = some_slice.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_slice[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:39:17 + --> $DIR/get_unwrap.rs:37:17 | LL | let _ = some_slice.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,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:40:17 + --> $DIR/get_unwrap.rs:38:17 | LL | let _ = some_vec.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vec[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:40:17 + --> $DIR/get_unwrap.rs:38:17 | LL | let _ = some_vec.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -51,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:41:17 + --> $DIR/get_unwrap.rs:39:17 | LL | let _ = some_vecdeque.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vecdeque[0]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:41:17 + --> $DIR/get_unwrap.rs:39:17 | LL | let _ = some_vecdeque.get(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,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:42:17 + --> $DIR/get_unwrap.rs:40:17 | LL | let _ = some_hashmap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_hashmap[&1]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:42:17 + --> $DIR/get_unwrap.rs:40:17 | LL | let _ = some_hashmap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -81,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:43:17 + --> $DIR/get_unwrap.rs:41:17 | LL | let _ = some_btreemap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_btreemap[&1]` error: used `unwrap()` on an `Option` value - --> $DIR/get_unwrap.rs:43:17 + --> $DIR/get_unwrap.rs:41:17 | LL | let _ = some_btreemap.get(&1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,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:47:21 + --> $DIR/get_unwrap.rs:45: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:47:22 + --> $DIR/get_unwrap.rs:45:22 | LL | let _: u8 = *boxed_slice.get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,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:52:9 + --> $DIR/get_unwrap.rs:50: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:52:10 + --> $DIR/get_unwrap.rs:50:10 | LL | *boxed_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -126,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:53:9 + --> $DIR/get_unwrap.rs:51: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:53:10 + --> $DIR/get_unwrap.rs:51:10 | LL | *some_slice.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -141,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:54:9 + --> $DIR/get_unwrap.rs:52: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:54:10 + --> $DIR/get_unwrap.rs:52:10 | LL | *some_vec.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -156,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:55:9 + --> $DIR/get_unwrap.rs:53: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:55:10 + --> $DIR/get_unwrap.rs:53:10 | LL | *some_vecdeque.get_mut(0).unwrap() = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -171,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:67:17 + --> $DIR/get_unwrap.rs:65: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:67:17 + --> $DIR/get_unwrap.rs:65:17 | LL | let _ = some_vec.get(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -186,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:68:17 + --> $DIR/get_unwrap.rs:66: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:68:17 + --> $DIR/get_unwrap.rs:66:17 | LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -201,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:78:24 + --> $DIR/get_unwrap.rs:76: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:81:18 + --> $DIR/get_unwrap.rs:79: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:84:18 + --> $DIR/get_unwrap.rs:82: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:101:33 + --> $DIR/get_unwrap.rs:99: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/src/tools/clippy/tests/ui/identity_op.fixed b/src/tools/clippy/tests/ui/identity_op.fixed index beb16000e..f3b4b1fff 100644 --- a/src/tools/clippy/tests/ui/identity_op.fixed +++ b/src/tools/clippy/tests/ui/identity_op.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::identity_op)] #![allow(unused)] #![allow( diff --git a/src/tools/clippy/tests/ui/identity_op.rs b/src/tools/clippy/tests/ui/identity_op.rs index 072e00c00..631aa3b02 100644 --- a/src/tools/clippy/tests/ui/identity_op.rs +++ b/src/tools/clippy/tests/ui/identity_op.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::identity_op)] #![allow(unused)] #![allow( diff --git a/src/tools/clippy/tests/ui/identity_op.stderr b/src/tools/clippy/tests/ui/identity_op.stderr index 3ba557d18..2a61327f1 100644 --- a/src/tools/clippy/tests/ui/identity_op.stderr +++ b/src/tools/clippy/tests/ui/identity_op.stderr @@ -1,241 +1,242 @@ error: this operation has no effect - --> $DIR/identity_op.rs:43:5 + --> $DIR/identity_op.rs:42:5 | LL | x + 0; | ^^^^^ help: consider reducing it to: `x` | = note: `-D clippy::identity-op` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::identity_op)]` error: this operation has no effect - --> $DIR/identity_op.rs:44:5 + --> $DIR/identity_op.rs:43:5 | LL | x + (1 - 1); | ^^^^^^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:46:5 + --> $DIR/identity_op.rs:45:5 | LL | 0 + x; | ^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:49:5 + --> $DIR/identity_op.rs:48:5 | LL | x | (0); | ^^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:52:5 + --> $DIR/identity_op.rs:51:5 | LL | x * 1; | ^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:53:5 + --> $DIR/identity_op.rs:52:5 | LL | 1 * x; | ^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:59:5 + --> $DIR/identity_op.rs:58:5 | LL | -1 & x; | ^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:62:5 + --> $DIR/identity_op.rs:61:5 | LL | u & 255; | ^^^^^^^ help: consider reducing it to: `u` error: this operation has no effect - --> $DIR/identity_op.rs:65:5 + --> $DIR/identity_op.rs:64:5 | LL | 42 << 0; | ^^^^^^^ help: consider reducing it to: `42` error: this operation has no effect - --> $DIR/identity_op.rs:66:5 + --> $DIR/identity_op.rs:65:5 | LL | 1 >> 0; | ^^^^^^ help: consider reducing it to: `1` error: this operation has no effect - --> $DIR/identity_op.rs:67:5 + --> $DIR/identity_op.rs:66:5 | LL | 42 >> 0; | ^^^^^^^ help: consider reducing it to: `42` error: this operation has no effect - --> $DIR/identity_op.rs:68:5 + --> $DIR/identity_op.rs:67:5 | LL | &x >> 0; | ^^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:69:5 + --> $DIR/identity_op.rs:68:5 | LL | x >> &0; | ^^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:76:5 + --> $DIR/identity_op.rs:75:5 | LL | 2 % 3; | ^^^^^ help: consider reducing it to: `2` error: this operation has no effect - --> $DIR/identity_op.rs:77:5 + --> $DIR/identity_op.rs:76:5 | LL | -2 % 3; | ^^^^^^ help: consider reducing it to: `-2` error: this operation has no effect - --> $DIR/identity_op.rs:78:5 + --> $DIR/identity_op.rs:77:5 | LL | 2 % -3 + x; | ^^^^^^ help: consider reducing it to: `2` error: this operation has no effect - --> $DIR/identity_op.rs:79:5 + --> $DIR/identity_op.rs:78:5 | LL | -2 % -3 + x; | ^^^^^^^ help: consider reducing it to: `-2` error: this operation has no effect - --> $DIR/identity_op.rs:80:9 + --> $DIR/identity_op.rs:79:9 | LL | x + 1 % 3; | ^^^^^ help: consider reducing it to: `1` error: this operation has no effect - --> $DIR/identity_op.rs:88:5 + --> $DIR/identity_op.rs:87:5 | LL | 0 + if b { 1 } else { 2 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(if b { 1 } else { 2 })` error: this operation has no effect - --> $DIR/identity_op.rs:89:5 + --> $DIR/identity_op.rs:88:5 | LL | 0 + if b { 1 } else { 2 } + if b { 3 } else { 4 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(if b { 1 } else { 2 })` error: this operation has no effect - --> $DIR/identity_op.rs:90:5 + --> $DIR/identity_op.rs:89:5 | LL | 0 + match a { 0 => 10, _ => 20 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(match a { 0 => 10, _ => 20 })` error: this operation has no effect - --> $DIR/identity_op.rs:91:5 + --> $DIR/identity_op.rs:90:5 | LL | 0 + match a { 0 => 10, _ => 20 } + match a { 0 => 30, _ => 40 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(match a { 0 => 10, _ => 20 })` error: this operation has no effect - --> $DIR/identity_op.rs:92:5 + --> $DIR/identity_op.rs:91:5 | LL | 0 + if b { 1 } else { 2 } + match a { 0 => 30, _ => 40 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(if b { 1 } else { 2 })` error: this operation has no effect - --> $DIR/identity_op.rs:93:5 + --> $DIR/identity_op.rs:92:5 | LL | 0 + match a { 0 => 10, _ => 20 } + if b { 3 } else { 4 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(match a { 0 => 10, _ => 20 })` error: this operation has no effect - --> $DIR/identity_op.rs:94:5 + --> $DIR/identity_op.rs:93:5 | LL | (if b { 1 } else { 2 }) + 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(if b { 1 } else { 2 })` error: this operation has no effect - --> $DIR/identity_op.rs:96:5 + --> $DIR/identity_op.rs:95:5 | LL | 0 + { a } + 3; | ^^^^^^^^^ help: consider reducing it to: `({ a })` error: this operation has no effect - --> $DIR/identity_op.rs:97:5 + --> $DIR/identity_op.rs:96:5 | LL | 0 + { a } * 2; | ^^^^^^^^^^^^^ help: consider reducing it to: `({ a } * 2)` error: this operation has no effect - --> $DIR/identity_op.rs:98:5 + --> $DIR/identity_op.rs:97:5 | LL | 0 + loop { let mut c = 0; if c == 10 { break c; } c += 1; } + { a * 2 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(loop { let mut c = 0; if c == 10 { break c; } c += 1; })` error: this operation has no effect - --> $DIR/identity_op.rs:103:7 + --> $DIR/identity_op.rs:102:7 | LL | f(1 * a + { 8 * 5 }); | ^^^^^ help: consider reducing it to: `a` error: this operation has no effect - --> $DIR/identity_op.rs:104:7 + --> $DIR/identity_op.rs:103:7 | LL | f(0 + if b { 1 } else { 2 } + 3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `if b { 1 } else { 2 }` error: this operation has no effect - --> $DIR/identity_op.rs:105:20 + --> $DIR/identity_op.rs:104:20 | LL | const _: i32 = { 2 * 4 } + 0 + 3; | ^^^^^^^^^^^^^ help: consider reducing it to: `{ 2 * 4 }` error: this operation has no effect - --> $DIR/identity_op.rs:106:20 + --> $DIR/identity_op.rs:105:20 | LL | const _: i32 = 0 + { 1 + 2 * 3 } + 3; | ^^^^^^^^^^^^^^^^^ help: consider reducing it to: `{ 1 + 2 * 3 }` error: this operation has no effect - --> $DIR/identity_op.rs:108:5 + --> $DIR/identity_op.rs:107:5 | LL | 0 + a as usize; | ^^^^^^^^^^^^^^ help: consider reducing it to: `a as usize` error: this operation has no effect - --> $DIR/identity_op.rs:109:13 + --> $DIR/identity_op.rs:108:13 | LL | let _ = 0 + a as usize; | ^^^^^^^^^^^^^^ help: consider reducing it to: `a as usize` error: this operation has no effect - --> $DIR/identity_op.rs:110:5 + --> $DIR/identity_op.rs:109:5 | LL | 0 + { a } as usize; | ^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `({ a } as usize)` error: this operation has no effect - --> $DIR/identity_op.rs:112:9 + --> $DIR/identity_op.rs:111:9 | LL | 2 * (0 + { a }); | ^^^^^^^^^^^ help: consider reducing it to: `{ a }` error: this operation has no effect - --> $DIR/identity_op.rs:113:5 + --> $DIR/identity_op.rs:112:5 | LL | 1 * ({ a } + 4); | ^^^^^^^^^^^^^^^ help: consider reducing it to: `(({ a } + 4))` error: this operation has no effect - --> $DIR/identity_op.rs:114:5 + --> $DIR/identity_op.rs:113:5 | LL | 1 * 1; | ^^^^^ help: consider reducing it to: `1` error: this operation has no effect - --> $DIR/identity_op.rs:118:18 + --> $DIR/identity_op.rs:117:18 | LL | let _: i32 = &x + 0; | ^^^^^^ help: consider reducing it to: `x` error: this operation has no effect - --> $DIR/identity_op.rs:122:5 + --> $DIR/identity_op.rs:121:5 | LL | 0 + if a { 1 } else { 2 } + if b { 3 } else { 5 } | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(if a { 1 } else { 2 })` diff --git a/src/tools/clippy/tests/ui/if_let_mutex.rs b/src/tools/clippy/tests/ui/if_let_mutex.rs index 321feb022..cb6915e0e 100644 --- a/src/tools/clippy/tests/ui/if_let_mutex.rs +++ b/src/tools/clippy/tests/ui/if_let_mutex.rs @@ -8,6 +8,7 @@ fn do_stuff(_: T) {} fn if_let() { let m = Mutex::new(1_u8); if let Err(locked) = m.lock() { + //~^ ERROR: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a d do_stuff(locked); } else { let lock = m.lock().unwrap(); @@ -20,6 +21,7 @@ fn if_let() { fn if_let_option() { let m = Mutex::new(Some(0_u8)); if let Some(locked) = m.lock().unwrap().deref() { + //~^ ERROR: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a d do_stuff(locked); } else { let lock = m.lock().unwrap(); @@ -41,6 +43,7 @@ fn if_let_different_mutex() { fn mutex_ref(mutex: &Mutex) { if let Ok(i) = mutex.lock() { + //~^ ERROR: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a d do_stuff(i); } else { let _x = mutex.lock(); diff --git a/src/tools/clippy/tests/ui/if_let_mutex.stderr b/src/tools/clippy/tests/ui/if_let_mutex.stderr index da0cc25f0..893429443 100644 --- a/src/tools/clippy/tests/ui/if_let_mutex.stderr +++ b/src/tools/clippy/tests/ui/if_let_mutex.stderr @@ -5,6 +5,7 @@ LL | if let Err(locked) = m.lock() { | ^ - this Mutex will remain locked for the entire `if let`-block... | _____| | | +LL | | LL | | do_stuff(locked); LL | | } else { LL | | let lock = m.lock().unwrap(); @@ -15,14 +16,16 @@ LL | | }; | = help: move the lock call outside of the `if let ...` expression = note: `-D clippy::if-let-mutex` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::if_let_mutex)]` error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock - --> $DIR/if_let_mutex.rs:22:5 + --> $DIR/if_let_mutex.rs:23:5 | LL | if let Some(locked) = m.lock().unwrap().deref() { | ^ - this Mutex will remain locked for the entire `if let`-block... | _____| | | +LL | | LL | | do_stuff(locked); LL | | } else { LL | | let lock = m.lock().unwrap(); @@ -34,12 +37,13 @@ LL | | }; = help: move the lock call outside of the `if let ...` expression error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock - --> $DIR/if_let_mutex.rs:43:5 + --> $DIR/if_let_mutex.rs:45:5 | LL | if let Ok(i) = mutex.lock() { | ^ ----- this Mutex will remain locked for the entire `if let`-block... | _____| | | +LL | | LL | | do_stuff(i); LL | | } else { LL | | let _x = mutex.lock(); diff --git a/src/tools/clippy/tests/ui/if_not_else.rs b/src/tools/clippy/tests/ui/if_not_else.rs index b7012b43d..fd30e3702 100644 --- a/src/tools/clippy/tests/ui/if_not_else.rs +++ b/src/tools/clippy/tests/ui/if_not_else.rs @@ -10,11 +10,13 @@ fn bla() -> bool { fn main() { if !bla() { + //~^ ERROR: unnecessary boolean `not` operation println!("Bugs"); } else { println!("Bunny"); } if 4 != 5 { + //~^ ERROR: unnecessary `!=` operation println!("Bugs"); } else { println!("Bunny"); diff --git a/src/tools/clippy/tests/ui/if_not_else.stderr b/src/tools/clippy/tests/ui/if_not_else.stderr index 46671c152..8b86f82fa 100644 --- a/src/tools/clippy/tests/ui/if_not_else.stderr +++ b/src/tools/clippy/tests/ui/if_not_else.stderr @@ -2,6 +2,7 @@ error: unnecessary boolean `not` operation --> $DIR/if_not_else.rs:12:5 | LL | / if !bla() { +LL | | LL | | println!("Bugs"); LL | | } else { LL | | println!("Bunny"); @@ -10,11 +11,13 @@ LL | | } | = help: remove the `!` and swap the blocks of the `if`/`else` = note: `-D clippy::if-not-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::if_not_else)]` error: unnecessary `!=` operation - --> $DIR/if_not_else.rs:17:5 + --> $DIR/if_not_else.rs:18:5 | LL | / if 4 != 5 { +LL | | LL | | println!("Bugs"); LL | | } else { LL | | println!("Bunny"); diff --git a/src/tools/clippy/tests/ui/if_same_then_else.stderr b/src/tools/clippy/tests/ui/if_same_then_else.stderr index 774cc0868..fb33e94e6 100644 --- a/src/tools/clippy/tests/ui/if_same_then_else.stderr +++ b/src/tools/clippy/tests/ui/if_same_then_else.stderr @@ -24,6 +24,7 @@ LL | | foo(); LL | | } | |_____^ = note: `-D clippy::if-same-then-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::if_same_then_else)]` error: this `if` has identical blocks --> $DIR/if_same_then_else.rs:67:21 diff --git a/src/tools/clippy/tests/ui/if_same_then_else2.rs b/src/tools/clippy/tests/ui/if_same_then_else2.rs index c545434ef..0b171f21d 100644 --- a/src/tools/clippy/tests/ui/if_same_then_else2.rs +++ b/src/tools/clippy/tests/ui/if_same_then_else2.rs @@ -98,7 +98,7 @@ fn if_same_then_else2() -> Result<&'static str, ()> { }; if true { - // FIXME: should emit "this `if` has identical blocks" + //~^ ERROR: this `if` has identical blocks Ok("foo")?; } else { Ok("foo")?; diff --git a/src/tools/clippy/tests/ui/if_same_then_else2.stderr b/src/tools/clippy/tests/ui/if_same_then_else2.stderr index 37fe787d1..fe68ef271 100644 --- a/src/tools/clippy/tests/ui/if_same_then_else2.stderr +++ b/src/tools/clippy/tests/ui/if_same_then_else2.stderr @@ -24,6 +24,7 @@ LL | | } LL | | } | |_____^ = note: `-D clippy::if-same-then-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::if_same_then_else)]` error: this `if` has identical blocks --> $DIR/if_same_then_else2.rs:36:13 @@ -82,6 +83,25 @@ LL | | f32::NAN LL | | }; | |_____^ +error: this `if` has identical blocks + --> $DIR/if_same_then_else2.rs:100:13 + | +LL | if true { + | _____________^ +LL | | +LL | | Ok("foo")?; +LL | | } else { + | |_____^ + | +note: same as this + --> $DIR/if_same_then_else2.rs:103:12 + | +LL | } else { + | ____________^ +LL | | Ok("foo")?; +LL | | } + | |_____^ + error: this `if` has identical blocks --> $DIR/if_same_then_else2.rs:124:20 | @@ -103,5 +123,5 @@ LL | | return Ok(&foo[0..]); LL | | } | |_____^ -error: aborting due to 5 previous errors +error: aborting due to 6 previous errors diff --git a/src/tools/clippy/tests/ui/if_then_some_else_none.rs b/src/tools/clippy/tests/ui/if_then_some_else_none.rs index 0e89fdb0d..77abd663e 100644 --- a/src/tools/clippy/tests/ui/if_then_some_else_none.rs +++ b/src/tools/clippy/tests/ui/if_then_some_else_none.rs @@ -3,6 +3,7 @@ fn main() { // Should issue an error. let _ = if foo() { + //~^ ERROR: this could be simplified with `bool::then` println!("true!"); Some("foo") } else { @@ -11,6 +12,7 @@ fn main() { // Should issue an error when macros are used. let _ = if matches!(true, true) { + //~^ ERROR: this could be simplified with `bool::then` println!("true!"); Some(matches!(true, false)) } else { @@ -20,10 +22,12 @@ fn main() { // Should issue an error. Binary expression `o < 32` should be parenthesized. let x = Some(5); let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); + //~^ ERROR: this could be simplified with `bool::then_some` // Should issue an error. Unary expression `!x` should be parenthesized. let x = true; let _ = if !x { Some(0) } else { None }; + //~^ ERROR: this could be simplified with `bool::then_some` // Should not issue an error since the `else` block has a statement besides `None`. let _ = if foo() { @@ -79,6 +83,7 @@ fn _msrv_1_49() { #[clippy::msrv = "1.50"] fn _msrv_1_50() { let _ = if foo() { + //~^ ERROR: this could be simplified with `bool::then` println!("true!"); Some(150) } else { @@ -112,3 +117,15 @@ fn f(b: bool, v: Option<()>) -> Option<()> { None } } + +fn issue11394(b: bool, v: Result<(), ()>) -> Result<(), ()> { + let x = if b { + #[allow(clippy::let_unit_value)] + let _ = v?; + Some(()) + } else { + None + }; + + Ok(()) +} diff --git a/src/tools/clippy/tests/ui/if_then_some_else_none.stderr b/src/tools/clippy/tests/ui/if_then_some_else_none.stderr index d728a3c31..5c97b06da 100644 --- a/src/tools/clippy/tests/ui/if_then_some_else_none.stderr +++ b/src/tools/clippy/tests/ui/if_then_some_else_none.stderr @@ -3,6 +3,7 @@ error: this could be simplified with `bool::then` | LL | let _ = if foo() { | _____________^ +LL | | LL | | println!("true!"); LL | | Some("foo") LL | | } else { @@ -12,12 +13,14 @@ LL | | }; | = help: consider using `bool::then` like: `foo().then(|| { /* snippet */ "foo" })` = note: `-D clippy::if-then-some-else-none` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::if_then_some_else_none)]` error: this could be simplified with `bool::then` - --> $DIR/if_then_some_else_none.rs:13:13 + --> $DIR/if_then_some_else_none.rs:14:13 | LL | let _ = if matches!(true, true) { | _____________^ +LL | | LL | | println!("true!"); LL | | Some(matches!(true, false)) LL | | } else { @@ -28,7 +31,7 @@ LL | | }; = help: consider using `bool::then` like: `matches!(true, true).then(|| { /* snippet */ matches!(true, false) })` error: this could be simplified with `bool::then_some` - --> $DIR/if_then_some_else_none.rs:22:28 + --> $DIR/if_then_some_else_none.rs:24:28 | LL | let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +39,7 @@ LL | let _ = x.and_then(|o| if o < 32 { Some(o) } else { None }); = help: consider using `bool::then_some` like: `(o < 32).then_some(o)` error: this could be simplified with `bool::then_some` - --> $DIR/if_then_some_else_none.rs:26:13 + --> $DIR/if_then_some_else_none.rs:29:13 | LL | let _ = if !x { Some(0) } else { None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,10 +47,11 @@ LL | let _ = if !x { Some(0) } else { None }; = help: consider using `bool::then_some` like: `(!x).then_some(0)` error: this could be simplified with `bool::then` - --> $DIR/if_then_some_else_none.rs:81:13 + --> $DIR/if_then_some_else_none.rs:85:13 | LL | let _ = if foo() { | _____________^ +LL | | LL | | println!("true!"); LL | | Some(150) LL | | } else { diff --git a/src/tools/clippy/tests/ui/ifs_same_cond.stderr b/src/tools/clippy/tests/ui/ifs_same_cond.stderr index 3f52c10b7..c5cd6b2c4 100644 --- a/src/tools/clippy/tests/ui/ifs_same_cond.stderr +++ b/src/tools/clippy/tests/ui/ifs_same_cond.stderr @@ -10,6 +10,7 @@ note: same as this LL | if b { | ^ = note: `-D clippy::ifs-same-cond` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ifs_same_cond)]` error: this `if` has the same condition as a previous `if` --> $DIR/ifs_same_cond.rs:19:15 diff --git a/src/tools/clippy/tests/ui/ignored_unit_patterns.fixed b/src/tools/clippy/tests/ui/ignored_unit_patterns.fixed index 492219fe4..6c6f21fee 100644 --- a/src/tools/clippy/tests/ui/ignored_unit_patterns.fixed +++ b/src/tools/clippy/tests/ui/ignored_unit_patterns.fixed @@ -1,7 +1,5 @@ -//@run-rustfix - #![warn(clippy::ignored_unit_patterns)] -#![allow(clippy::redundant_pattern_matching, clippy::single_match)] +#![allow(clippy::let_unit_value, clippy::redundant_pattern_matching, clippy::single_match)] fn foo() -> Result<(), ()> { unimplemented!() @@ -9,9 +7,19 @@ fn foo() -> Result<(), ()> { fn main() { match foo() { - Ok(()) => {}, - Err(()) => {}, + Ok(()) => {}, //~ ERROR: matching over `()` is more explicit + Err(()) => {}, //~ ERROR: matching over `()` is more explicit } if let Ok(()) = foo() {} + //~^ ERROR: matching over `()` is more explicit let _ = foo().map_err(|()| todo!()); + //~^ ERROR: matching over `()` is more explicit +} + +#[allow(unused)] +pub fn moo(_: ()) { + let () = foo().unwrap(); + //~^ ERROR: matching over `()` is more explicit + let _: () = foo().unwrap(); + let _: () = (); } diff --git a/src/tools/clippy/tests/ui/ignored_unit_patterns.rs b/src/tools/clippy/tests/ui/ignored_unit_patterns.rs index 90af36f8e..5e8c2e03b 100644 --- a/src/tools/clippy/tests/ui/ignored_unit_patterns.rs +++ b/src/tools/clippy/tests/ui/ignored_unit_patterns.rs @@ -1,7 +1,5 @@ -//@run-rustfix - #![warn(clippy::ignored_unit_patterns)] -#![allow(clippy::redundant_pattern_matching, clippy::single_match)] +#![allow(clippy::let_unit_value, clippy::redundant_pattern_matching, clippy::single_match)] fn foo() -> Result<(), ()> { unimplemented!() @@ -9,9 +7,19 @@ fn foo() -> Result<(), ()> { fn main() { match foo() { - Ok(_) => {}, - Err(_) => {}, + Ok(_) => {}, //~ ERROR: matching over `()` is more explicit + Err(_) => {}, //~ ERROR: matching over `()` is more explicit } if let Ok(_) = foo() {} + //~^ ERROR: matching over `()` is more explicit let _ = foo().map_err(|_| todo!()); + //~^ ERROR: matching over `()` is more explicit +} + +#[allow(unused)] +pub fn moo(_: ()) { + let _ = foo().unwrap(); + //~^ ERROR: matching over `()` is more explicit + let _: () = foo().unwrap(); + let _: () = (); } diff --git a/src/tools/clippy/tests/ui/ignored_unit_patterns.stderr b/src/tools/clippy/tests/ui/ignored_unit_patterns.stderr index 8feea3cc2..df5e1d89e 100644 --- a/src/tools/clippy/tests/ui/ignored_unit_patterns.stderr +++ b/src/tools/clippy/tests/ui/ignored_unit_patterns.stderr @@ -1,28 +1,35 @@ error: matching over `()` is more explicit - --> $DIR/ignored_unit_patterns.rs:12:12 + --> $DIR/ignored_unit_patterns.rs:10:12 | LL | Ok(_) => {}, | ^ help: use `()` instead of `_`: `()` | = note: `-D clippy::ignored-unit-patterns` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ignored_unit_patterns)]` error: matching over `()` is more explicit - --> $DIR/ignored_unit_patterns.rs:13:13 + --> $DIR/ignored_unit_patterns.rs:11:13 | LL | Err(_) => {}, | ^ help: use `()` instead of `_`: `()` error: matching over `()` is more explicit - --> $DIR/ignored_unit_patterns.rs:15:15 + --> $DIR/ignored_unit_patterns.rs:13:15 | LL | if let Ok(_) = foo() {} | ^ help: use `()` instead of `_`: `()` error: matching over `()` is more explicit - --> $DIR/ignored_unit_patterns.rs:16:28 + --> $DIR/ignored_unit_patterns.rs:15:28 | LL | let _ = foo().map_err(|_| todo!()); | ^ help: use `()` instead of `_`: `()` -error: aborting due to 4 previous errors +error: matching over `()` is more explicit + --> $DIR/ignored_unit_patterns.rs:21:9 + | +LL | let _ = foo().unwrap(); + | ^ help: use `()` instead of `_`: `()` + +error: aborting due to 5 previous errors diff --git a/src/tools/clippy/tests/ui/impl.rs b/src/tools/clippy/tests/ui/impl.rs index aea52a852..7f452cb46 100644 --- a/src/tools/clippy/tests/ui/impl.rs +++ b/src/tools/clippy/tests/ui/impl.rs @@ -8,6 +8,7 @@ impl MyStruct { } impl MyStruct { + //~^ ERROR: multiple implementations of this structure fn second() {} } @@ -22,6 +23,7 @@ mod submod { } impl super::MyStruct { + //~^ ERROR: multiple implementations of this structure fn third() {} } } @@ -42,6 +44,7 @@ impl WithArgs { fn f2() {} } impl WithArgs { + //~^ ERROR: multiple implementations of this structure fn f3() {} } @@ -63,5 +66,6 @@ impl OneAllowedImpl {} #[allow(clippy::multiple_inherent_impl)] impl OneAllowedImpl {} impl OneAllowedImpl {} // Lint, only one of the three blocks is allowed. +//~^ ERROR: multiple implementations of this structure fn main() {} diff --git a/src/tools/clippy/tests/ui/impl.stderr b/src/tools/clippy/tests/ui/impl.stderr index e28b1bf0c..833a10606 100644 --- a/src/tools/clippy/tests/ui/impl.stderr +++ b/src/tools/clippy/tests/ui/impl.stderr @@ -2,6 +2,7 @@ error: multiple implementations of this structure --> $DIR/impl.rs:10:1 | LL | / impl MyStruct { +LL | | LL | | fn second() {} LL | | } | |_^ @@ -14,11 +15,13 @@ LL | | fn first() {} LL | | } | |_^ = note: `-D clippy::multiple-inherent-impl` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::multiple_inherent_impl)]` error: multiple implementations of this structure - --> $DIR/impl.rs:24:5 + --> $DIR/impl.rs:25:5 | LL | / impl super::MyStruct { +LL | | LL | | fn third() {} LL | | } | |_____^ @@ -32,15 +35,16 @@ LL | | } | |_^ error: multiple implementations of this structure - --> $DIR/impl.rs:44:1 + --> $DIR/impl.rs:46:1 | LL | / impl WithArgs { +LL | | LL | | fn f3() {} LL | | } | |_^ | note: first implementation here - --> $DIR/impl.rs:41:1 + --> $DIR/impl.rs:43:1 | LL | / impl WithArgs { LL | | fn f2() {} @@ -48,13 +52,13 @@ LL | | } | |_^ error: multiple implementations of this structure - --> $DIR/impl.rs:65:1 + --> $DIR/impl.rs:68:1 | LL | impl OneAllowedImpl {} // Lint, only one of the three blocks is allowed. | ^^^^^^^^^^^^^^^^^^^^^^ | note: first implementation here - --> $DIR/impl.rs:62:1 + --> $DIR/impl.rs:65:1 | LL | impl OneAllowedImpl {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/impl_trait_in_params.rs b/src/tools/clippy/tests/ui/impl_trait_in_params.rs index 07560101a..b652e4a4a 100644 --- a/src/tools/clippy/tests/ui/impl_trait_in_params.rs +++ b/src/tools/clippy/tests/ui/impl_trait_in_params.rs @@ -1,12 +1,15 @@ #![allow(unused)] #![warn(clippy::impl_trait_in_params)] - +//@no-rustfix pub trait Trait {} pub trait AnotherTrait {} // Should warn pub fn a(_: impl Trait) {} +//~^ ERROR: '`impl Trait` used as a function parameter' +//~| NOTE: `-D clippy::impl-trait-in-params` implied by `-D warnings` pub fn c(_: C, _: impl Trait) {} +//~^ ERROR: '`impl Trait` used as a function parameter' fn d(_: impl AnotherTrait) {} // Shouldn't warn diff --git a/src/tools/clippy/tests/ui/impl_trait_in_params.stderr b/src/tools/clippy/tests/ui/impl_trait_in_params.stderr index 803837435..36b4f27e9 100644 --- a/src/tools/clippy/tests/ui/impl_trait_in_params.stderr +++ b/src/tools/clippy/tests/ui/impl_trait_in_params.stderr @@ -5,13 +5,14 @@ LL | pub fn a(_: impl Trait) {} | ^^^^^^^^^^ | = note: `-D clippy::impl-trait-in-params` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::impl_trait_in_params)]` help: add a type parameter | LL | pub fn a<{ /* Generic name */ }: Trait>(_: impl Trait) {} | +++++++++++++++++++++++++++++++ error: '`impl Trait` used as a function parameter' - --> $DIR/impl_trait_in_params.rs:9:29 + --> $DIR/impl_trait_in_params.rs:11:29 | LL | pub fn c(_: C, _: impl Trait) {} | ^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/implicit_clone.fixed b/src/tools/clippy/tests/ui/implicit_clone.fixed index e62db8b40..98556b4dd 100644 --- a/src/tools/clippy/tests/ui/implicit_clone.fixed +++ b/src/tools/clippy/tests/ui/implicit_clone.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::implicit_clone)] #![allow(clippy::clone_on_copy, clippy::redundant_clone)] use std::borrow::Borrow; @@ -68,7 +67,7 @@ fn main() { let vec_ref = &vec; let _ = return_owned_from_slice(vec_ref); - let _ = vec_ref.clone(); + let _ = vec_ref.to_owned(); let _ = vec_ref.clone(); // we expect no lint for this diff --git a/src/tools/clippy/tests/ui/implicit_clone.rs b/src/tools/clippy/tests/ui/implicit_clone.rs index 88352b06a..a064bd23a 100644 --- a/src/tools/clippy/tests/ui/implicit_clone.rs +++ b/src/tools/clippy/tests/ui/implicit_clone.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::implicit_clone)] #![allow(clippy::clone_on_copy, clippy::redundant_clone)] use std::borrow::Borrow; diff --git a/src/tools/clippy/tests/ui/implicit_clone.stderr b/src/tools/clippy/tests/ui/implicit_clone.stderr index 92c1aa58a..64c31e651 100644 --- a/src/tools/clippy/tests/ui/implicit_clone.stderr +++ b/src/tools/clippy/tests/ui/implicit_clone.stderr @@ -1,76 +1,71 @@ error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type - --> $DIR/implicit_clone.rs:66:13 + --> $DIR/implicit_clone.rs:65:13 | LL | let _ = vec.to_owned(); | ^^^^^^^^^^^^^^ help: consider using: `vec.clone()` | = note: `-D clippy::implicit-clone` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::implicit_clone)]` error: implicitly cloning a `Vec` by calling `to_vec` on its dereferenced type - --> $DIR/implicit_clone.rs:67:13 + --> $DIR/implicit_clone.rs:66:13 | LL | let _ = vec.to_vec(); | ^^^^^^^^^^^^ help: consider using: `vec.clone()` -error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type - --> $DIR/implicit_clone.rs:71:13 - | -LL | let _ = vec_ref.to_owned(); - | ^^^^^^^^^^^^^^^^^^ help: consider using: `vec_ref.clone()` - error: implicitly cloning a `Vec` by calling `to_vec` on its dereferenced type - --> $DIR/implicit_clone.rs:72:13 + --> $DIR/implicit_clone.rs:71:13 | LL | let _ = vec_ref.to_vec(); | ^^^^^^^^^^^^^^^^ help: consider using: `vec_ref.clone()` error: implicitly cloning a `String` by calling `to_owned` on its dereferenced type - --> $DIR/implicit_clone.rs:84:13 + --> $DIR/implicit_clone.rs:83:13 | LL | let _ = str.to_owned(); | ^^^^^^^^^^^^^^ help: consider using: `str.clone()` error: implicitly cloning a `Kitten` by calling `to_owned` on its dereferenced type - --> $DIR/implicit_clone.rs:88:13 + --> $DIR/implicit_clone.rs:87:13 | LL | let _ = kitten.to_owned(); | ^^^^^^^^^^^^^^^^^ help: consider using: `kitten.clone()` error: implicitly cloning a `PathBuf` by calling `to_owned` on its dereferenced type - --> $DIR/implicit_clone.rs:98:13 + --> $DIR/implicit_clone.rs:97:13 | LL | let _ = pathbuf.to_owned(); | ^^^^^^^^^^^^^^^^^^ help: consider using: `pathbuf.clone()` error: implicitly cloning a `PathBuf` by calling `to_path_buf` on its dereferenced type - --> $DIR/implicit_clone.rs:99:13 + --> $DIR/implicit_clone.rs:98:13 | LL | let _ = pathbuf.to_path_buf(); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `pathbuf.clone()` error: implicitly cloning a `OsString` by calling `to_owned` on its dereferenced type - --> $DIR/implicit_clone.rs:102:13 + --> $DIR/implicit_clone.rs:101:13 | LL | let _ = os_string.to_owned(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `os_string.clone()` error: implicitly cloning a `OsString` by calling `to_os_string` on its dereferenced type - --> $DIR/implicit_clone.rs:103:13 + --> $DIR/implicit_clone.rs:102:13 | LL | let _ = os_string.to_os_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `os_string.clone()` error: implicitly cloning a `PathBuf` by calling `to_path_buf` on its dereferenced type - --> $DIR/implicit_clone.rs:114:13 + --> $DIR/implicit_clone.rs:113:13 | LL | let _ = pathbuf_ref.to_path_buf(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(*pathbuf_ref).clone()` error: implicitly cloning a `PathBuf` by calling `to_path_buf` on its dereferenced type - --> $DIR/implicit_clone.rs:117:13 + --> $DIR/implicit_clone.rs:116:13 | LL | let _ = pathbuf_ref.to_path_buf(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(**pathbuf_ref).clone()` -error: aborting due to 12 previous errors +error: aborting due to 11 previous errors diff --git a/src/tools/clippy/tests/ui/implicit_hasher.rs b/src/tools/clippy/tests/ui/implicit_hasher.rs index 7ed7bf94a..f7cd54174 100644 --- a/src/tools/clippy/tests/ui/implicit_hasher.rs +++ b/src/tools/clippy/tests/ui/implicit_hasher.rs @@ -1,5 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro - +//@aux-build:proc_macros.rs +//@no-rustfix #![deny(clippy::implicit_hasher)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/implicit_hasher.stderr b/src/tools/clippy/tests/ui/implicit_hasher.stderr index 83b46de2e..a27590288 100644 --- a/src/tools/clippy/tests/ui/implicit_hasher.stderr +++ b/src/tools/clippy/tests/ui/implicit_hasher.stderr @@ -1,155 +1,40 @@ -error: impl for `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:18:35 +error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` + --> $DIR/implicit_hasher.rs:14:1 | -LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/implicit_hasher.rs:3:9 - | -LL | #![deny(clippy::implicit_hasher)] - | ^^^^^^^^^^^^^^^^^^^^^^^ -help: consider adding a type parameter - | -LL | impl Foo for HashMap { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ -help: ...and use generic constructor - | -LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) - | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: impl for `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:27:36 - | -LL | impl Foo for (HashMap,) { - | ^^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | impl Foo for (HashMap,) { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ -help: ...and use generic constructor - | -LL | ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Default::default()),)) - | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: impl for `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:32:19 - | -LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | impl Foo for HashMap { - | +++++++++++++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~~~~~~~ -help: ...and use generic constructor - | -LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) - | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: impl for `HashSet` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:49:32 - | -LL | impl Foo for HashSet { - | ^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | impl Foo for HashSet { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ -help: ...and use generic constructor - | -LL | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) - | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | pub trait Foo: Sized { + | ^^^^^^^^^^^^^^^^^^^^^^^ -error: impl for `HashSet` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:54:19 - | -LL | impl Foo for HashSet { - | ^^^^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | impl Foo for HashSet { - | +++++++++++++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~ -help: ...and use generic constructor - | -LL | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default())) - | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: parameter of type `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:71:23 +error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` + --> $DIR/implicit_hasher.rs:71:1 | LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: parameter of type `HashSet` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:71:53 - | -LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^ +error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` + --> $DIR/implicit_hasher.rs:74:1 | -help: consider adding a type parameter - | -LL | pub fn foo(_map: &mut HashMap, _set: &mut HashSet) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~ +LL | pub mod gen { + | ^^^^^^^^^^^ -error: impl for `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:77:43 - | -LL | impl Foo for HashMap { - | ^^^^^^^^^^^^^ +error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` + --> $DIR/implicit_hasher.rs:92:1 | - = note: this error originates in the macro `__inline_mac_mod_gen` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider adding a type parameter - | -LL | impl Foo for HashMap { - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ -help: ...and use generic constructor - | -LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default())) - | ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | pub mod test_macro; + | ^^^^^^^^^^^^^^^^^^^ -error: parameter of type `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:83:31 - | -LL | pub fn bar(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^^^^^^ +error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` + --> $DIR/implicit_hasher.rs:96:1 | - = note: this error originates in the macro `__inline_mac_mod_gen` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider adding a type parameter +LL | external! { + | ^^^^^^^^^ | -LL | pub fn bar(_map: &mut HashMap, _set: &mut HashSet) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ + = note: this error originates in the macro `external` (in Nightly builds, run with -Z macro-backtrace for more info) -error: parameter of type `HashSet` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:83:61 - | -LL | pub fn bar(_map: &mut HashMap, _set: &mut HashSet) {} - | ^^^^^^^^^^^^ - | - = note: this error originates in the macro `__inline_mac_mod_gen` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider adding a type parameter - | -LL | pub fn bar(_map: &mut HashMap, _set: &mut HashSet) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~ - -error: parameter of type `HashMap` should be generalized over different hashers - --> $DIR/implicit_hasher.rs:101:35 +error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]` + --> $DIR/implicit_hasher.rs:101:1 | LL | pub async fn election_vote(_data: HashMap) {} - | ^^^^^^^^^^^^^^^^^ - | -help: consider adding a type parameter - | -LL | pub async fn election_vote(_data: HashMap) {} - | +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 11 previous errors +error: aborting due to 6 previous errors diff --git a/src/tools/clippy/tests/ui/implicit_return.fixed b/src/tools/clippy/tests/ui/implicit_return.fixed index 64813eafd..897f1b766 100644 --- a/src/tools/clippy/tests/ui/implicit_return.fixed +++ b/src/tools/clippy/tests/ui/implicit_return.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(lint_reasons)] #![warn(clippy::implicit_return)] #![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)] diff --git a/src/tools/clippy/tests/ui/implicit_return.rs b/src/tools/clippy/tests/ui/implicit_return.rs index 39d47b110..fcff67b58 100644 --- a/src/tools/clippy/tests/ui/implicit_return.rs +++ b/src/tools/clippy/tests/ui/implicit_return.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(lint_reasons)] #![warn(clippy::implicit_return)] #![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)] diff --git a/src/tools/clippy/tests/ui/implicit_return.stderr b/src/tools/clippy/tests/ui/implicit_return.stderr index 522bc3bf8..1edc6cc6f 100644 --- a/src/tools/clippy/tests/ui/implicit_return.stderr +++ b/src/tools/clippy/tests/ui/implicit_return.stderr @@ -1,91 +1,92 @@ error: missing `return` statement - --> $DIR/implicit_return.rs:12:5 + --> $DIR/implicit_return.rs:11:5 | LL | true | ^^^^ help: add `return` as shown: `return true` | = note: `-D clippy::implicit-return` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::implicit_return)]` error: missing `return` statement - --> $DIR/implicit_return.rs:16:15 + --> $DIR/implicit_return.rs:15:15 | LL | if true { true } else { false } | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:16:29 + --> $DIR/implicit_return.rs:15:29 | LL | if true { true } else { false } | ^^^^^ help: add `return` as shown: `return false` error: missing `return` statement - --> $DIR/implicit_return.rs:22:17 + --> $DIR/implicit_return.rs:21:17 | LL | true => false, | ^^^^^ help: add `return` as shown: `return false` error: missing `return` statement - --> $DIR/implicit_return.rs:23:20 + --> $DIR/implicit_return.rs:22:20 | LL | false => { true }, | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:36:9 + --> $DIR/implicit_return.rs:35:9 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:43:13 + --> $DIR/implicit_return.rs:42:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:51:13 + --> $DIR/implicit_return.rs:50:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:69:18 + --> $DIR/implicit_return.rs:68:18 | LL | let _ = || { true }; | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:70:16 + --> $DIR/implicit_return.rs:69:16 | LL | let _ = || true; | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:78:5 + --> $DIR/implicit_return.rs:77:5 | LL | format!("test {}", "test") | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")` error: missing `return` statement - --> $DIR/implicit_return.rs:87:5 + --> $DIR/implicit_return.rs:86:5 | LL | m!(true, false) | ^^^^^^^^^^^^^^^ help: add `return` as shown: `return m!(true, false)` error: missing `return` statement - --> $DIR/implicit_return.rs:93:13 + --> $DIR/implicit_return.rs:92:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:98:17 + --> $DIR/implicit_return.rs:97:17 | LL | break 'outer false; | ^^^^^^^^^^^^^^^^^^ help: change `break` to `return` as shown: `return false` error: missing `return` statement - --> $DIR/implicit_return.rs:113:5 + --> $DIR/implicit_return.rs:112:5 | LL | / loop { LL | | m!(true); @@ -100,7 +101,7 @@ LL + } | error: missing `return` statement - --> $DIR/implicit_return.rs:127:5 + --> $DIR/implicit_return.rs:126:5 | LL | true | ^^^^ help: add `return` as shown: `return true` diff --git a/src/tools/clippy/tests/ui/implicit_saturating_add.fixed b/src/tools/clippy/tests/ui/implicit_saturating_add.fixed index 7fc510d6b..4cf8e3587 100644 --- a/src/tools/clippy/tests/ui/implicit_saturating_add.fixed +++ b/src/tools/clippy/tests/ui/implicit_saturating_add.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::implicit_saturating_add)] diff --git a/src/tools/clippy/tests/ui/implicit_saturating_add.rs b/src/tools/clippy/tests/ui/implicit_saturating_add.rs index 3dcd91f42..94513f34c 100644 --- a/src/tools/clippy/tests/ui/implicit_saturating_add.rs +++ b/src/tools/clippy/tests/ui/implicit_saturating_add.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::implicit_saturating_add)] diff --git a/src/tools/clippy/tests/ui/implicit_saturating_add.stderr b/src/tools/clippy/tests/ui/implicit_saturating_add.stderr index 42ae1b488..7119c8bf6 100644 --- a/src/tools/clippy/tests/ui/implicit_saturating_add.stderr +++ b/src/tools/clippy/tests/ui/implicit_saturating_add.stderr @@ -1,5 +1,5 @@ error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:23:5 + --> $DIR/implicit_saturating_add.rs:21:5 | LL | / if u_8 != u8::MAX { LL | | u_8 += 1; @@ -7,9 +7,10 @@ LL | | } | |_____^ help: use instead: `u_8 = u_8.saturating_add(1);` | = note: `-D clippy::implicit-saturating-add` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::implicit_saturating_add)]` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:27:5 + --> $DIR/implicit_saturating_add.rs:25:5 | LL | / if u_8 < u8::MAX { LL | | u_8 += 1; @@ -17,7 +18,7 @@ LL | | } | |_____^ help: use instead: `u_8 = u_8.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:35:5 + --> $DIR/implicit_saturating_add.rs:33:5 | LL | / if u_16 != u16::MAX { LL | | u_16 += 1; @@ -25,7 +26,7 @@ LL | | } | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:39:5 + --> $DIR/implicit_saturating_add.rs:37:5 | LL | / if u_16 < u16::MAX { LL | | u_16 += 1; @@ -33,7 +34,7 @@ LL | | } | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:43:5 + --> $DIR/implicit_saturating_add.rs:41:5 | LL | / if u16::MAX > u_16 { LL | | u_16 += 1; @@ -41,7 +42,7 @@ LL | | } | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:47:5 + --> $DIR/implicit_saturating_add.rs:45:5 | LL | / if u_32 != u32::MAX { LL | | u_32 += 1; @@ -49,7 +50,7 @@ LL | | } | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:51:5 + --> $DIR/implicit_saturating_add.rs:49:5 | LL | / if u_32 < u32::MAX { LL | | u_32 += 1; @@ -57,7 +58,7 @@ LL | | } | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:55:5 + --> $DIR/implicit_saturating_add.rs:53:5 | LL | / if u32::MAX > u_32 { LL | | u_32 += 1; @@ -65,7 +66,7 @@ LL | | } | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:59:5 + --> $DIR/implicit_saturating_add.rs:57:5 | LL | / if u_64 != u64::MAX { LL | | u_64 += 1; @@ -73,7 +74,7 @@ LL | | } | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:63:5 + --> $DIR/implicit_saturating_add.rs:61:5 | LL | / if u_64 < u64::MAX { LL | | u_64 += 1; @@ -81,7 +82,7 @@ LL | | } | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:67:5 + --> $DIR/implicit_saturating_add.rs:65:5 | LL | / if u64::MAX > u_64 { LL | | u_64 += 1; @@ -89,7 +90,7 @@ LL | | } | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:71:5 + --> $DIR/implicit_saturating_add.rs:69:5 | LL | / if i_8 != i8::MAX { LL | | i_8 += 1; @@ -97,7 +98,7 @@ LL | | } | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:75:5 + --> $DIR/implicit_saturating_add.rs:73:5 | LL | / if i_8 < i8::MAX { LL | | i_8 += 1; @@ -105,7 +106,7 @@ LL | | } | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:79:5 + --> $DIR/implicit_saturating_add.rs:77:5 | LL | / if i8::MAX > i_8 { LL | | i_8 += 1; @@ -113,7 +114,7 @@ LL | | } | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:83:5 + --> $DIR/implicit_saturating_add.rs:81:5 | LL | / if i_16 != i16::MAX { LL | | i_16 += 1; @@ -121,7 +122,7 @@ LL | | } | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:87:5 + --> $DIR/implicit_saturating_add.rs:85:5 | LL | / if i_16 < i16::MAX { LL | | i_16 += 1; @@ -129,7 +130,7 @@ LL | | } | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:91:5 + --> $DIR/implicit_saturating_add.rs:89:5 | LL | / if i16::MAX > i_16 { LL | | i_16 += 1; @@ -137,7 +138,7 @@ LL | | } | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:95:5 + --> $DIR/implicit_saturating_add.rs:93:5 | LL | / if i_32 != i32::MAX { LL | | i_32 += 1; @@ -145,7 +146,7 @@ LL | | } | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:99:5 + --> $DIR/implicit_saturating_add.rs:97:5 | LL | / if i_32 < i32::MAX { LL | | i_32 += 1; @@ -153,7 +154,7 @@ LL | | } | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:103:5 + --> $DIR/implicit_saturating_add.rs:101:5 | LL | / if i32::MAX > i_32 { LL | | i_32 += 1; @@ -161,7 +162,7 @@ LL | | } | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:107:5 + --> $DIR/implicit_saturating_add.rs:105:5 | LL | / if i_64 != i64::MAX { LL | | i_64 += 1; @@ -169,7 +170,7 @@ LL | | } | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:111:5 + --> $DIR/implicit_saturating_add.rs:109:5 | LL | / if i_64 < i64::MAX { LL | | i_64 += 1; @@ -177,7 +178,7 @@ LL | | } | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:115:5 + --> $DIR/implicit_saturating_add.rs:113:5 | LL | / if i64::MAX > i_64 { LL | | i_64 += 1; @@ -185,7 +186,7 @@ LL | | } | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);` error: manual saturating add detected - --> $DIR/implicit_saturating_add.rs:151:12 + --> $DIR/implicit_saturating_add.rs:149:12 | LL | } else if u_32 < u32::MAX { | ____________^ diff --git a/src/tools/clippy/tests/ui/implicit_saturating_sub.fixed b/src/tools/clippy/tests/ui/implicit_saturating_sub.fixed index 1a11db098..27f679797 100644 --- a/src/tools/clippy/tests/ui/implicit_saturating_sub.fixed +++ b/src/tools/clippy/tests/ui/implicit_saturating_sub.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused_assignments, unused_mut, clippy::assign_op_pattern)] #![warn(clippy::implicit_saturating_sub)] diff --git a/src/tools/clippy/tests/ui/implicit_saturating_sub.rs b/src/tools/clippy/tests/ui/implicit_saturating_sub.rs index 9369df674..5d7b95d2c 100644 --- a/src/tools/clippy/tests/ui/implicit_saturating_sub.rs +++ b/src/tools/clippy/tests/ui/implicit_saturating_sub.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused_assignments, unused_mut, clippy::assign_op_pattern)] #![warn(clippy::implicit_saturating_sub)] diff --git a/src/tools/clippy/tests/ui/implicit_saturating_sub.stderr b/src/tools/clippy/tests/ui/implicit_saturating_sub.stderr index 5e589d931..6e026d1a6 100644 --- a/src/tools/clippy/tests/ui/implicit_saturating_sub.stderr +++ b/src/tools/clippy/tests/ui/implicit_saturating_sub.stderr @@ -1,5 +1,5 @@ error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:28:5 + --> $DIR/implicit_saturating_sub.rs:27:5 | LL | / if u_8 > 0 { LL | | u_8 = u_8 - 1; @@ -7,9 +7,10 @@ LL | | } | |_____^ help: try: `u_8 = u_8.saturating_sub(1);` | = note: `-D clippy::implicit-saturating-sub` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::implicit_saturating_sub)]` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:35:13 + --> $DIR/implicit_saturating_sub.rs:34:13 | LL | / if u_8 > 0 { LL | | u_8 -= 1; @@ -17,7 +18,7 @@ LL | | } | |_____________^ help: try: `u_8 = u_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:49:5 + --> $DIR/implicit_saturating_sub.rs:48:5 | LL | / if u_16 > 0 { LL | | u_16 -= 1; @@ -25,7 +26,7 @@ LL | | } | |_____^ help: try: `u_16 = u_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:59:5 + --> $DIR/implicit_saturating_sub.rs:58:5 | LL | / if u_32 != 0 { LL | | u_32 -= 1; @@ -33,7 +34,7 @@ LL | | } | |_____^ help: try: `u_32 = u_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:80:5 + --> $DIR/implicit_saturating_sub.rs:79:5 | LL | / if u_64 > 0 { LL | | u_64 -= 1; @@ -41,7 +42,7 @@ LL | | } | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:85:5 + --> $DIR/implicit_saturating_sub.rs:84:5 | LL | / if 0 < u_64 { LL | | u_64 -= 1; @@ -49,7 +50,7 @@ LL | | } | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:90:5 + --> $DIR/implicit_saturating_sub.rs:89:5 | LL | / if 0 != u_64 { LL | | u_64 -= 1; @@ -57,7 +58,7 @@ LL | | } | |_____^ help: try: `u_64 = u_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:111:5 + --> $DIR/implicit_saturating_sub.rs:110:5 | LL | / if u_usize > 0 { LL | | u_usize -= 1; @@ -65,7 +66,7 @@ LL | | } | |_____^ help: try: `u_usize = u_usize.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:123:5 + --> $DIR/implicit_saturating_sub.rs:122:5 | LL | / if i_8 > i8::MIN { LL | | i_8 -= 1; @@ -73,7 +74,7 @@ LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:128:5 + --> $DIR/implicit_saturating_sub.rs:127:5 | LL | / if i_8 > i8::MIN { LL | | i_8 -= 1; @@ -81,7 +82,7 @@ LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:133:5 + --> $DIR/implicit_saturating_sub.rs:132:5 | LL | / if i_8 != i8::MIN { LL | | i_8 -= 1; @@ -89,7 +90,7 @@ LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:138:5 + --> $DIR/implicit_saturating_sub.rs:137:5 | LL | / if i_8 != i8::MIN { LL | | i_8 -= 1; @@ -97,7 +98,7 @@ LL | | } | |_____^ help: try: `i_8 = i_8.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:148:5 + --> $DIR/implicit_saturating_sub.rs:147:5 | LL | / if i_16 > i16::MIN { LL | | i_16 -= 1; @@ -105,7 +106,7 @@ LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:153:5 + --> $DIR/implicit_saturating_sub.rs:152:5 | LL | / if i_16 > i16::MIN { LL | | i_16 -= 1; @@ -113,7 +114,7 @@ LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:158:5 + --> $DIR/implicit_saturating_sub.rs:157:5 | LL | / if i_16 != i16::MIN { LL | | i_16 -= 1; @@ -121,7 +122,7 @@ LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:163:5 + --> $DIR/implicit_saturating_sub.rs:162:5 | LL | / if i_16 != i16::MIN { LL | | i_16 -= 1; @@ -129,7 +130,7 @@ LL | | } | |_____^ help: try: `i_16 = i_16.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:173:5 + --> $DIR/implicit_saturating_sub.rs:172:5 | LL | / if i_32 > i32::MIN { LL | | i_32 -= 1; @@ -137,7 +138,7 @@ LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:178:5 + --> $DIR/implicit_saturating_sub.rs:177:5 | LL | / if i_32 > i32::MIN { LL | | i_32 -= 1; @@ -145,7 +146,7 @@ LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:183:5 + --> $DIR/implicit_saturating_sub.rs:182:5 | LL | / if i_32 != i32::MIN { LL | | i_32 -= 1; @@ -153,7 +154,7 @@ LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:188:5 + --> $DIR/implicit_saturating_sub.rs:187:5 | LL | / if i_32 != i32::MIN { LL | | i_32 -= 1; @@ -161,7 +162,7 @@ LL | | } | |_____^ help: try: `i_32 = i_32.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:198:5 + --> $DIR/implicit_saturating_sub.rs:197:5 | LL | / if i64::MIN < i_64 { LL | | i_64 -= 1; @@ -169,7 +170,7 @@ LL | | } | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:203:5 + --> $DIR/implicit_saturating_sub.rs:202:5 | LL | / if i64::MIN != i_64 { LL | | i_64 -= 1; @@ -177,7 +178,7 @@ LL | | } | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` error: implicitly performing saturating subtraction - --> $DIR/implicit_saturating_sub.rs:208:5 + --> $DIR/implicit_saturating_sub.rs:207:5 | LL | / if i64::MIN < i_64 { LL | | i_64 -= 1; diff --git a/src/tools/clippy/tests/ui/implied_bounds_in_impls.fixed b/src/tools/clippy/tests/ui/implied_bounds_in_impls.fixed new file mode 100644 index 000000000..a50fa0ccf --- /dev/null +++ b/src/tools/clippy/tests/ui/implied_bounds_in_impls.fixed @@ -0,0 +1,125 @@ +#![warn(clippy::implied_bounds_in_impls)] +#![allow(dead_code)] +#![feature(return_position_impl_trait_in_trait)] + +use std::ops::{Deref, DerefMut}; + +// Only one bound, nothing to lint. +fn normal_deref(x: T) -> impl Deref { + Box::new(x) +} + +// Deref implied by DerefMut +fn deref_derefmut(x: T) -> impl DerefMut { + Box::new(x) +} + +trait GenericTrait {} +trait GenericTrait2 {} +// U is intentionally at a different "index" in GenericSubtrait than `T` is in GenericTrait, +// so this can be a good test to make sure that the calculations are right (no off-by-one errors, +// ...) +trait GenericSubtrait: GenericTrait + GenericTrait2 {} + +impl GenericTrait for () {} +impl GenericTrait for () {} +impl GenericTrait2 for () {} +impl GenericSubtrait<(), i32, V> for () {} +impl GenericSubtrait<(), i64, V> for () {} + +fn generics_implied() -> impl GenericSubtrait +where + (): GenericSubtrait, +{ +} + +fn generics_implied_multi() -> impl GenericSubtrait<(), i32, V> {} + +fn generics_implied_multi2() -> impl GenericSubtrait<(), T, V> +where + (): GenericSubtrait<(), T, V> + GenericTrait, +{ +} + +// i32 != i64, GenericSubtrait<_, i64, _> does not imply GenericTrait, don't lint +fn generics_different() -> impl GenericTrait + GenericSubtrait<(), i64, ()> {} + +// i32 == i32, GenericSubtrait<_, i32, _> does imply GenericTrait, lint +fn generics_same() -> impl GenericSubtrait<(), i32, ()> {} + +trait SomeTrait { + // Check that it works in trait declarations. + fn f() -> impl DerefMut; +} +struct SomeStruct; +impl SomeStruct { + // Check that it works in inherent impl blocks. + fn f() -> impl DerefMut { + Box::new(123) + } +} +impl SomeTrait for SomeStruct { + // Check that it works in trait impls. + fn f() -> impl DerefMut { + Box::new(42) + } +} + +mod issue11422 { + use core::fmt::Debug; + // Some additional tests that would cause ICEs: + + // `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 {} + fn default_generic_param2() -> impl PartialOrd + Debug {} + + // Referring to `Self` in the supertrait clause needs special handling. + trait Trait1 {} + trait Trait2: Trait1 {} + impl Trait1<()> for () {} + impl Trait2 for () {} + + fn f() -> impl Trait1<()> + Trait2 {} +} + +mod issue11435 { + // Associated type needs to be included on DoubleEndedIterator in the suggestion + fn my_iter() -> impl DoubleEndedIterator { + 0..5 + } + + // Removing the `Clone` bound should include the `+` behind it in its remove suggestion + fn f() -> impl Copy { + 1 + } + + trait Trait1 { + type U; + } + impl Trait1 for () { + type U = i64; + } + trait Trait2: Trait1 {} + impl Trait2 for () {} + + // When the other trait has generics, it shouldn't add another pair of `<>` + fn f2() -> impl Trait2 {} + + trait Trait3 { + type X; + type Y; + } + trait Trait4: Trait3 {} + impl Trait3 for () { + type X = i32; + type Y = i128; + } + impl Trait4 for () {} + + // Associated type `X` is specified, but `Y` is not, so only that associated type should be moved + // over + fn f3() -> impl Trait4 {} +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/implied_bounds_in_impls.rs b/src/tools/clippy/tests/ui/implied_bounds_in_impls.rs new file mode 100644 index 000000000..e74ed4425 --- /dev/null +++ b/src/tools/clippy/tests/ui/implied_bounds_in_impls.rs @@ -0,0 +1,125 @@ +#![warn(clippy::implied_bounds_in_impls)] +#![allow(dead_code)] +#![feature(return_position_impl_trait_in_trait)] + +use std::ops::{Deref, DerefMut}; + +// Only one bound, nothing to lint. +fn normal_deref(x: T) -> impl Deref { + Box::new(x) +} + +// Deref implied by DerefMut +fn deref_derefmut(x: T) -> impl Deref + DerefMut { + Box::new(x) +} + +trait GenericTrait {} +trait GenericTrait2 {} +// U is intentionally at a different "index" in GenericSubtrait than `T` is in GenericTrait, +// so this can be a good test to make sure that the calculations are right (no off-by-one errors, +// ...) +trait GenericSubtrait: GenericTrait + GenericTrait2 {} + +impl GenericTrait for () {} +impl GenericTrait for () {} +impl GenericTrait2 for () {} +impl GenericSubtrait<(), i32, V> for () {} +impl GenericSubtrait<(), i64, V> for () {} + +fn generics_implied() -> impl GenericTrait + GenericSubtrait +where + (): GenericSubtrait, +{ +} + +fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} + +fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> +where + (): GenericSubtrait<(), T, V> + GenericTrait, +{ +} + +// i32 != i64, GenericSubtrait<_, i64, _> does not imply GenericTrait, don't lint +fn generics_different() -> impl GenericTrait + GenericSubtrait<(), i64, ()> {} + +// i32 == i32, GenericSubtrait<_, i32, _> does imply GenericTrait, lint +fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} + +trait SomeTrait { + // Check that it works in trait declarations. + fn f() -> impl Deref + DerefMut; +} +struct SomeStruct; +impl SomeStruct { + // Check that it works in inherent impl blocks. + fn f() -> impl Deref + DerefMut { + Box::new(123) + } +} +impl SomeTrait for SomeStruct { + // Check that it works in trait impls. + fn f() -> impl Deref + DerefMut { + Box::new(42) + } +} + +mod issue11422 { + use core::fmt::Debug; + // Some additional tests that would cause ICEs: + + // `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 {} + fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {} + + // Referring to `Self` in the supertrait clause needs special handling. + trait Trait1 {} + trait Trait2: Trait1 {} + impl Trait1<()> for () {} + impl Trait2 for () {} + + fn f() -> impl Trait1<()> + Trait2 {} +} + +mod issue11435 { + // Associated type needs to be included on DoubleEndedIterator in the suggestion + fn my_iter() -> impl Iterator + DoubleEndedIterator { + 0..5 + } + + // Removing the `Clone` bound should include the `+` behind it in its remove suggestion + fn f() -> impl Copy + Clone { + 1 + } + + trait Trait1 { + type U; + } + impl Trait1 for () { + type U = i64; + } + trait Trait2: Trait1 {} + impl Trait2 for () {} + + // When the other trait has generics, it shouldn't add another pair of `<>` + fn f2() -> impl Trait1 + Trait2 {} + + trait Trait3 { + type X; + type Y; + } + trait Trait4: Trait3 {} + impl Trait3 for () { + type X = i32; + type Y = i128; + } + impl Trait4 for () {} + + // Associated type `X` is specified, but `Y` is not, so only that associated type should be moved + // over + fn f3() -> impl Trait3 + Trait4 {} +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/implied_bounds_in_impls.stderr b/src/tools/clippy/tests/ui/implied_bounds_in_impls.stderr new file mode 100644 index 000000000..72dc2a183 --- /dev/null +++ b/src/tools/clippy/tests/ui/implied_bounds_in_impls.stderr @@ -0,0 +1,196 @@ +error: this bound is already specified as the supertrait of `DerefMut` + --> $DIR/implied_bounds_in_impls.rs:13:36 + | +LL | fn deref_derefmut(x: T) -> impl Deref + DerefMut { + | ^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::implied-bounds-in-impls` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::implied_bounds_in_impls)]` +help: try removing this bound + | +LL - fn deref_derefmut(x: T) -> impl Deref + DerefMut { +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:30:37 + | +LL | fn generics_implied() -> impl GenericTrait + GenericSubtrait + | ^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn generics_implied() -> impl GenericTrait + GenericSubtrait +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:36:40 + | +LL | fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} + | ^^^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} +LL + fn generics_implied_multi() -> impl GenericTrait2 + GenericSubtrait<(), i32, V> {} + | + +error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, V>` + --> $DIR/implied_bounds_in_impls.rs:36:60 + | +LL | fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} + | ^^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn generics_implied_multi() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), i32, V> {} +LL + fn generics_implied_multi() -> impl GenericTrait + GenericSubtrait<(), i32, V> {} + | + +error: this bound is already specified as the supertrait of `GenericSubtrait<(), T, V>` + --> $DIR/implied_bounds_in_impls.rs:38:44 + | +LL | fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> + | ^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> +LL + fn generics_implied_multi2() -> impl GenericTrait2 + GenericSubtrait<(), T, V> + | + +error: this bound is already specified as the supertrait of `GenericSubtrait<(), T, V>` + --> $DIR/implied_bounds_in_impls.rs:38:62 + | +LL | fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> + | ^^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn generics_implied_multi2() -> impl GenericTrait + GenericTrait2 + GenericSubtrait<(), T, V> +LL + fn generics_implied_multi2() -> impl GenericTrait + GenericSubtrait<(), T, V> + | + +error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, ()>` + --> $DIR/implied_bounds_in_impls.rs:48:28 + | +LL | fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} + | ^^^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn generics_same() -> impl GenericTrait + GenericSubtrait<(), i32, ()> {} +LL + fn generics_same() -> impl GenericSubtrait<(), i32, ()> {} + | + +error: this bound is already specified as the supertrait of `DerefMut` + --> $DIR/implied_bounds_in_impls.rs:52:20 + | +LL | fn f() -> impl Deref + DerefMut; + | ^^^^^ + | +help: try removing this bound + | +LL - fn f() -> impl Deref + DerefMut; +LL + fn f() -> impl DerefMut; + | + +error: this bound is already specified as the supertrait of `DerefMut` + --> $DIR/implied_bounds_in_impls.rs:57:20 + | +LL | fn f() -> impl Deref + DerefMut { + | ^^^^^ + | +help: try removing this bound + | +LL - fn f() -> impl Deref + DerefMut { +LL + fn f() -> impl DerefMut { + | + +error: this bound is already specified as the supertrait of `DerefMut` + --> $DIR/implied_bounds_in_impls.rs:63:20 + | +LL | fn f() -> impl Deref + DerefMut { + | ^^^^^ + | +help: try removing this bound + | +LL - fn f() -> impl Deref + DerefMut { +LL + fn f() -> impl DerefMut { + | + +error: this bound is already specified as the supertrait of `PartialOrd` + --> $DIR/implied_bounds_in_impls.rs:74:41 + | +LL | fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {} + | ^^^^^^^^^ + | +help: try removing this bound + | +LL - fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {} +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:75:54 + | +LL | fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {} + | ^^^^^^^^^ + | +help: try removing this bound + | +LL - fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {} +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:88:26 + | +LL | fn my_iter() -> impl Iterator + DoubleEndedIterator { + | ^^^^^^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn my_iter() -> impl Iterator + DoubleEndedIterator { +LL + fn my_iter() -> impl DoubleEndedIterator { + | + +error: this bound is already specified as the supertrait of `Copy` + --> $DIR/implied_bounds_in_impls.rs:93:27 + | +LL | fn f() -> impl Copy + Clone { + | ^^^^^ + | +help: try removing this bound + | +LL - fn f() -> impl Copy + Clone { +LL + fn f() -> impl Copy { + | + +error: this bound is already specified as the supertrait of `Trait2` + --> $DIR/implied_bounds_in_impls.rs:107:21 + | +LL | fn f2() -> impl Trait1 + Trait2 {} + | ^^^^^^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn f2() -> impl Trait1 + Trait2 {} +LL + fn f2() -> impl Trait2 {} + | + +error: this bound is already specified as the supertrait of `Trait4` + --> $DIR/implied_bounds_in_impls.rs:122:21 + | +LL | fn f3() -> impl Trait3 + Trait4 {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try removing this bound + | +LL - fn f3() -> impl Trait3 + Trait4 {} +LL + fn f3() -> impl Trait4 {} + | + +error: aborting due to 16 previous errors + diff --git a/src/tools/clippy/tests/ui/inconsistent_digit_grouping.fixed b/src/tools/clippy/tests/ui/inconsistent_digit_grouping.fixed index 06919809e..3f1dfbbae 100644 --- a/src/tools/clippy/tests/ui/inconsistent_digit_grouping.fixed +++ b/src/tools/clippy/tests/ui/inconsistent_digit_grouping.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #[warn(clippy::inconsistent_digit_grouping)] #[deny(clippy::unreadable_literal)] #[allow(unused_variables, clippy::excessive_precision)] diff --git a/src/tools/clippy/tests/ui/inconsistent_digit_grouping.rs b/src/tools/clippy/tests/ui/inconsistent_digit_grouping.rs index 04d9125f2..ac47ae175 100644 --- a/src/tools/clippy/tests/ui/inconsistent_digit_grouping.rs +++ b/src/tools/clippy/tests/ui/inconsistent_digit_grouping.rs @@ -1,4 +1,3 @@ -//@run-rustfix #[warn(clippy::inconsistent_digit_grouping)] #[deny(clippy::unreadable_literal)] #[allow(unused_variables, clippy::excessive_precision)] diff --git a/src/tools/clippy/tests/ui/inconsistent_digit_grouping.stderr b/src/tools/clippy/tests/ui/inconsistent_digit_grouping.stderr index b8ac91554..6aeb33eda 100644 --- a/src/tools/clippy/tests/ui/inconsistent_digit_grouping.stderr +++ b/src/tools/clippy/tests/ui/inconsistent_digit_grouping.stderr @@ -1,67 +1,68 @@ error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:16 + --> $DIR/inconsistent_digit_grouping.rs:25:16 | LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); | ^^^^^^^^ help: consider: `123_456` | = note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inconsistent_digit_grouping)]` error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:26 + --> $DIR/inconsistent_digit_grouping.rs:25:26 | LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); | ^^^^^^^^^^ help: consider: `12_345_678` error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:38 + --> $DIR/inconsistent_digit_grouping.rs:25:38 | LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); | ^^^^^^^^ help: consider: `1_234_567` error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:48 + --> $DIR/inconsistent_digit_grouping.rs:25:48 | LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); | ^^^^^^^^^^^^^^ help: consider: `1_234.567_8_f32` error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:26:64 + --> $DIR/inconsistent_digit_grouping.rs:25:64 | LL | let bad = (1_23_456, 1_234_5678, 1234_567, 1_234.5678_f32, 1.234_5678_f32); | ^^^^^^^^^^^^^^ help: consider: `1.234_567_8_f32` error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:29:13 + --> $DIR/inconsistent_digit_grouping.rs:28:13 | LL | let _ = 0x100000; | ^^^^^^^^ help: consider: `0x0010_0000` | note: the lint level is defined here - --> $DIR/inconsistent_digit_grouping.rs:3:8 + --> $DIR/inconsistent_digit_grouping.rs:2:8 | LL | #[deny(clippy::unreadable_literal)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:30:13 + --> $DIR/inconsistent_digit_grouping.rs:29:13 | LL | let _ = 0x1000000; | ^^^^^^^^^ help: consider: `0x0100_0000` error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:31:13 + --> $DIR/inconsistent_digit_grouping.rs:30:13 | LL | let _ = 0x10000000; | ^^^^^^^^^^ help: consider: `0x1000_0000` error: long literal lacking separators - --> $DIR/inconsistent_digit_grouping.rs:32:13 + --> $DIR/inconsistent_digit_grouping.rs:31:13 | LL | let _ = 0x100000000_u64; | ^^^^^^^^^^^^^^^ help: consider: `0x0001_0000_0000_u64` error: digits grouped inconsistently by underscores - --> $DIR/inconsistent_digit_grouping.rs:35:18 + --> $DIR/inconsistent_digit_grouping.rs:34:18 | LL | let _: f32 = 1_23_456.; | ^^^^^^^^^ help: consider: `123_456.` diff --git a/src/tools/clippy/tests/ui/inconsistent_struct_constructor.fixed b/src/tools/clippy/tests/ui/inconsistent_struct_constructor.fixed index d84346e87..5778f8f52 100644 --- a/src/tools/clippy/tests/ui/inconsistent_struct_constructor.fixed +++ b/src/tools/clippy/tests/ui/inconsistent_struct_constructor.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::inconsistent_struct_constructor)] #![allow(clippy::redundant_field_names)] diff --git a/src/tools/clippy/tests/ui/inconsistent_struct_constructor.rs b/src/tools/clippy/tests/ui/inconsistent_struct_constructor.rs index 87fba7448..9efaf0689 100644 --- a/src/tools/clippy/tests/ui/inconsistent_struct_constructor.rs +++ b/src/tools/clippy/tests/ui/inconsistent_struct_constructor.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::inconsistent_struct_constructor)] #![allow(clippy::redundant_field_names)] diff --git a/src/tools/clippy/tests/ui/inconsistent_struct_constructor.stderr b/src/tools/clippy/tests/ui/inconsistent_struct_constructor.stderr index 785a6dc9d..fc080d7ec 100644 --- a/src/tools/clippy/tests/ui/inconsistent_struct_constructor.stderr +++ b/src/tools/clippy/tests/ui/inconsistent_struct_constructor.stderr @@ -1,13 +1,14 @@ error: struct constructor field order is inconsistent with struct definition field order - --> $DIR/inconsistent_struct_constructor.rs:29:9 + --> $DIR/inconsistent_struct_constructor.rs:28:9 | LL | Foo { y, x, z }; | ^^^^^^^^^^^^^^^ help: try: `Foo { x, y, z }` | = note: `-D clippy::inconsistent-struct-constructor` implied by `-D warnings` + = 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:56:9 + --> $DIR/inconsistent_struct_constructor.rs:55:9 | LL | / Foo { LL | | z, diff --git a/src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.fixed b/src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.fixed deleted file mode 100644 index ac482dcda..000000000 --- a/src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.fixed +++ /dev/null @@ -1,97 +0,0 @@ -//@run-rustfix -#![allow(clippy::clone_on_copy, unused)] -#![no_main] - -// lint - -struct A(u32); - -impl Clone for A { - fn clone(&self) -> Self { *self } - - -} - -impl Copy for A {} - -// do not lint - -struct B(u32); - -impl Clone for B { - fn clone(&self) -> Self { - *self - } -} - -impl Copy for B {} - -// do not lint derived (clone's implementation is `*self` here anyway) - -#[derive(Clone, Copy)] -struct C(u32); - -// do not lint derived (fr this time) - -struct D(u32); - -#[automatically_derived] -impl Clone for D { - fn clone(&self) -> Self { - Self(self.0) - } - - fn clone_from(&mut self, source: &Self) { - source.clone(); - *self = source.clone(); - } -} - -impl Copy for D {} - -// do not lint if clone is not manually implemented - -struct E(u32); - -#[automatically_derived] -impl Clone for E { - fn clone(&self) -> Self { - Self(self.0) - } - - fn clone_from(&mut self, source: &Self) { - source.clone(); - *self = source.clone(); - } -} - -impl Copy for E {} - -// lint since clone is not derived - -#[derive(Copy)] -struct F(u32); - -impl Clone for F { - fn clone(&self) -> Self { *self } - - -} - -// do not lint since copy has more restrictive bounds - -#[derive(Eq, PartialEq)] -struct Uwu(A); - -impl Clone for Uwu { - fn clone(&self) -> Self { - Self(self.0) - } - - fn clone_from(&mut self, source: &Self) { - source.clone(); - *self = source.clone(); - } -} - -impl Copy for Uwu {} diff --git a/src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.rs b/src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.rs deleted file mode 100644 index 00775874f..000000000 --- a/src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.rs +++ /dev/null @@ -1,107 +0,0 @@ -//@run-rustfix -#![allow(clippy::clone_on_copy, unused)] -#![no_main] - -// lint - -struct A(u32); - -impl Clone for A { - fn clone(&self) -> Self { - Self(self.0) - } - - fn clone_from(&mut self, source: &Self) { - source.clone(); - *self = source.clone(); - } -} - -impl Copy for A {} - -// do not lint - -struct B(u32); - -impl Clone for B { - fn clone(&self) -> Self { - *self - } -} - -impl Copy for B {} - -// do not lint derived (clone's implementation is `*self` here anyway) - -#[derive(Clone, Copy)] -struct C(u32); - -// do not lint derived (fr this time) - -struct D(u32); - -#[automatically_derived] -impl Clone for D { - fn clone(&self) -> Self { - Self(self.0) - } - - fn clone_from(&mut self, source: &Self) { - source.clone(); - *self = source.clone(); - } -} - -impl Copy for D {} - -// do not lint if clone is not manually implemented - -struct E(u32); - -#[automatically_derived] -impl Clone for E { - fn clone(&self) -> Self { - Self(self.0) - } - - fn clone_from(&mut self, source: &Self) { - source.clone(); - *self = source.clone(); - } -} - -impl Copy for E {} - -// lint since clone is not derived - -#[derive(Copy)] -struct F(u32); - -impl Clone for F { - fn clone(&self) -> Self { - Self(self.0) - } - - fn clone_from(&mut self, source: &Self) { - source.clone(); - *self = source.clone(); - } -} - -// do not lint since copy has more restrictive bounds - -#[derive(Eq, PartialEq)] -struct Uwu(A); - -impl Clone for Uwu { - fn clone(&self) -> Self { - Self(self.0) - } - - fn clone_from(&mut self, source: &Self) { - source.clone(); - *self = source.clone(); - } -} - -impl Copy for Uwu {} diff --git a/src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.stderr b/src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.stderr deleted file mode 100644 index 7bcba8ba4..000000000 --- a/src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: incorrect implementation of `clone` on a `Copy` type - --> $DIR/incorrect_clone_impl_on_copy_type.rs:10:29 - | -LL | fn clone(&self) -> Self { - | _____________________________^ -LL | | Self(self.0) -LL | | } - | |_____^ help: change this to: `{ *self }` - | - = note: `#[deny(clippy::incorrect_clone_impl_on_copy_type)]` on by default - -error: incorrect implementation of `clone_from` on a `Copy` type - --> $DIR/incorrect_clone_impl_on_copy_type.rs:14:5 - | -LL | / fn clone_from(&mut self, source: &Self) { -LL | | source.clone(); -LL | | *self = source.clone(); -LL | | } - | |_____^ help: remove it - -error: incorrect implementation of `clone` on a `Copy` type - --> $DIR/incorrect_clone_impl_on_copy_type.rs:81:29 - | -LL | fn clone(&self) -> Self { - | _____________________________^ -LL | | Self(self.0) -LL | | } - | |_____^ help: change this to: `{ *self }` - -error: incorrect implementation of `clone_from` on a `Copy` type - --> $DIR/incorrect_clone_impl_on_copy_type.rs:85:5 - | -LL | / fn clone_from(&mut self, source: &Self) { -LL | | source.clone(); -LL | | *self = source.clone(); -LL | | } - | |_____^ help: remove it - -error: aborting due to 4 previous errors - diff --git a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.fixed b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.fixed deleted file mode 100644 index 2f51bf274..000000000 --- a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.fixed +++ /dev/null @@ -1,145 +0,0 @@ -//@run-rustfix -#![no_main] - -use std::cmp::Ordering; - -// lint - -#[derive(Eq, PartialEq)] -struct A(u32); - -impl Ord for A { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for A { - fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } -} - -// do not lint - -#[derive(Eq, PartialEq)] -struct B(u32); - -impl Ord for B { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for B { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -// lint, and give `_` a name - -#[derive(Eq, PartialEq)] -struct C(u32); - -impl Ord for C { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for C { - fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } -} - -// do not lint derived - -#[derive(Eq, Ord, PartialEq, PartialOrd)] -struct D(u32); - -// do not lint if ord is not manually implemented - -#[derive(Eq, PartialEq)] -struct E(u32); - -impl PartialOrd for E { - fn partial_cmp(&self, other: &Self) -> Option { - todo!(); - } -} - -// do not lint since ord has more restrictive bounds - -#[derive(Eq, PartialEq)] -struct Uwu(A); - -impl Ord for Uwu { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for Uwu { - fn partial_cmp(&self, other: &Self) -> Option { - todo!(); - } -} - -// do not lint since `Rhs` is not `Self` - -#[derive(Eq, PartialEq)] -struct F(u32); - -impl Ord for F { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for F { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl PartialEq for F { - fn eq(&self, other: &u32) -> bool { - todo!(); - } -} - -impl PartialOrd for F { - fn partial_cmp(&self, other: &u32) -> Option { - todo!(); - } -} - -// #11178, do not lint - -#[derive(Eq, PartialEq)] -struct G(u32); - -impl Ord for G { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for G { - fn partial_cmp(&self, other: &Self) -> Option { - Some(Self::cmp(self, other)) - } -} - -#[derive(Eq, PartialEq)] -struct H(u32); - -impl Ord for H { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for H { - fn partial_cmp(&self, other: &Self) -> Option { - Some(Ord::cmp(self, other)) - } -} diff --git a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.rs b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.rs deleted file mode 100644 index 47127bdae..000000000 --- a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.rs +++ /dev/null @@ -1,149 +0,0 @@ -//@run-rustfix -#![no_main] - -use std::cmp::Ordering; - -// lint - -#[derive(Eq, PartialEq)] -struct A(u32); - -impl Ord for A { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for A { - fn partial_cmp(&self, other: &Self) -> Option { - todo!(); - } -} - -// do not lint - -#[derive(Eq, PartialEq)] -struct B(u32); - -impl Ord for B { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for B { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -// lint, and give `_` a name - -#[derive(Eq, PartialEq)] -struct C(u32); - -impl Ord for C { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for C { - fn partial_cmp(&self, _: &Self) -> Option { - todo!(); - } -} - -// do not lint derived - -#[derive(Eq, Ord, PartialEq, PartialOrd)] -struct D(u32); - -// do not lint if ord is not manually implemented - -#[derive(Eq, PartialEq)] -struct E(u32); - -impl PartialOrd for E { - fn partial_cmp(&self, other: &Self) -> Option { - todo!(); - } -} - -// do not lint since ord has more restrictive bounds - -#[derive(Eq, PartialEq)] -struct Uwu(A); - -impl Ord for Uwu { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for Uwu { - fn partial_cmp(&self, other: &Self) -> Option { - todo!(); - } -} - -// do not lint since `Rhs` is not `Self` - -#[derive(Eq, PartialEq)] -struct F(u32); - -impl Ord for F { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for F { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl PartialEq for F { - fn eq(&self, other: &u32) -> bool { - todo!(); - } -} - -impl PartialOrd for F { - fn partial_cmp(&self, other: &u32) -> Option { - todo!(); - } -} - -// #11178, do not lint - -#[derive(Eq, PartialEq)] -struct G(u32); - -impl Ord for G { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for G { - fn partial_cmp(&self, other: &Self) -> Option { - Some(Self::cmp(self, other)) - } -} - -#[derive(Eq, PartialEq)] -struct H(u32); - -impl Ord for H { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for H { - fn partial_cmp(&self, other: &Self) -> Option { - Some(Ord::cmp(self, other)) - } -} diff --git a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.stderr b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.stderr deleted file mode 100644 index 66048fc90..000000000 --- a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.stderr +++ /dev/null @@ -1,31 +0,0 @@ -error: incorrect implementation of `partial_cmp` on an `Ord` type - --> $DIR/incorrect_partial_ord_impl_on_ord_type.rs:17:1 - | -LL | / impl PartialOrd for A { -LL | | fn partial_cmp(&self, other: &Self) -> Option { - | | _____________________________________________________________- -LL | || todo!(); -LL | || } - | ||_____- help: change this to: `{ Some(self.cmp(other)) }` -LL | | } - | |__^ - | - = note: `#[deny(clippy::incorrect_partial_ord_impl_on_ord_type)]` on by default - -error: incorrect implementation of `partial_cmp` on an `Ord` type - --> $DIR/incorrect_partial_ord_impl_on_ord_type.rs:51:1 - | -LL | / impl PartialOrd for C { -LL | | fn partial_cmp(&self, _: &Self) -> Option { -LL | | todo!(); -LL | | } -LL | | } - | |_^ - | -help: change this to - | -LL | fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } - | ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: aborting due to 2 previous errors - diff --git a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs deleted file mode 100644 index 3a3b84f93..000000000 --- a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs +++ /dev/null @@ -1,51 +0,0 @@ -// This test's filename is... a bit verbose. But it ensures we suggest the correct code when `Ord` -// is not in scope. -#![no_main] -#![no_implicit_prelude] - -extern crate std; - -use std::cmp::{self, Eq, Ordering, PartialEq, PartialOrd}; -use std::option::Option::{self, Some}; -use std::todo; - -// lint - -#[derive(Eq, PartialEq)] -struct A(u32); - -impl cmp::Ord for A { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -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 - // automatically applied - todo!(); - } -} - -#[derive(Eq, PartialEq)] -struct B(u32); - -impl B { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl cmp::Ord for B { - fn cmp(&self, other: &Self) -> Ordering { - todo!(); - } -} - -impl PartialOrd for B { - fn partial_cmp(&self, other: &Self) -> Option { - // This calls `B.cmp`, not `Ord::cmp`! - Some(self.cmp(other)) - } -} diff --git a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr deleted file mode 100644 index f4374c281..000000000 --- a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr +++ /dev/null @@ -1,31 +0,0 @@ -error: incorrect implementation of `partial_cmp` on an `Ord` type - --> $DIR/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs:23:1 - | -LL | / impl PartialOrd for A { -LL | | fn partial_cmp(&self, other: &Self) -> Option { - | | _____________________________________________________________- -LL | || // NOTE: This suggestion is wrong, as `Ord` is not in scope. But this should be fine as it isn't -LL | || // automatically applied -LL | || todo!(); -LL | || } - | ||_____- help: change this to: `{ Some(self.cmp(other)) }` -LL | | } - | |__^ - | - = note: `#[deny(clippy::incorrect_partial_ord_impl_on_ord_type)]` on by default - -error: incorrect implementation of `partial_cmp` on an `Ord` type - --> $DIR/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs:46:1 - | -LL | / impl PartialOrd for B { -LL | | fn partial_cmp(&self, other: &Self) -> Option { - | | _____________________________________________________________- -LL | || // This calls `B.cmp`, not `Ord::cmp`! -LL | || Some(self.cmp(other)) -LL | || } - | ||_____- help: change this to: `{ Some(std::cmp::Ord::cmp(self, other)) }` -LL | | } - | |__^ - -error: aborting due to 2 previous errors - diff --git a/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.fixed b/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.fixed new file mode 100644 index 000000000..13f0cbe9c --- /dev/null +++ b/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.fixed @@ -0,0 +1,177 @@ +#![deny(clippy::index_refutable_slice)] +#![allow(clippy::uninlined_format_args)] + +enum SomeEnum { + One(T), + Two(T), + Three(T), + Four(T), +} + +fn lintable_examples() { + // Try with reference + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some([slice_0, ..]) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing + println!("{}", slice_0); + } + + // Try with copy + let slice: Option<[u32; 3]> = Some([1, 2, 3]); + if let Some([slice_0, ..]) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing + println!("{}", slice_0); + } + + // Try with long slice and small indices + let slice: Option<[u32; 9]> = Some([1, 2, 3, 4, 5, 6, 7, 8, 9]); + if let Some([slice_0, _, slice_2, ..]) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing + println!("{}", slice_2); + println!("{}", slice_0); + } + + // Multiple bindings + let slice_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([5, 6, 7]); + if let SomeEnum::One([slice_0, ..]) | SomeEnum::Three([slice_0, ..]) = slice_wrapped { + //~^ ERROR: this binding can be a slice pattern to avoid indexing + println!("{}", slice_0); + } + + // Two lintable slices in one if let + let a_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([9, 5, 1]); + let b_wrapped: Option<[u32; 2]> = Some([4, 6]); + if let (SomeEnum::Three([_, _, a_2, ..]), Some([_, b_1, ..])) = (a_wrapped, b_wrapped) { + //~^ ERROR: this binding can be a slice pattern to avoid indexing + //~| ERROR: this binding can be a slice pattern to avoid indexing + println!("{} -> {}", a_2, b_1); + } + + // This requires the slice values to be borrowed as the slice values can only be + // borrowed and `String` doesn't implement copy + let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); + if let Some([_, ref slice_1, ..]) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing + println!("{:?}", slice_1); + } + println!("{:?}", slice); + + // This should not suggest using the `ref` keyword as the scrutinee is already + // a reference + let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); + if let Some([slice_0, ..]) = &slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing + println!("{:?}", slice_0); + } + println!("{:?}", slice); +} + +fn slice_index_above_limit() { + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + + if let Some(slice) = slice { + // Would cause a panic, IDK + println!("{}", slice[7]); + } +} + +fn slice_is_used() { + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some(slice) = slice { + println!("{:?}", slice.len()); + } + + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some(slice) = slice { + println!("{:?}", slice.to_vec()); + } + + let opt: Option<[String; 2]> = Some([String::from("Hello"), String::from("world")]); + if let Some(slice) = opt { + if !slice.is_empty() { + println!("first: {}", slice[0]); + } + } +} + +/// The slice is used by an external function and should therefore not be linted +fn check_slice_as_arg() { + fn is_interesting(slice: &[T; 2]) -> bool { + !slice.is_empty() + } + + let slice_wrapped: Option<[String; 2]> = Some([String::from("Hello"), String::from("world")]); + if let Some(slice) = &slice_wrapped { + if is_interesting(slice) { + println!("This is interesting {}", slice[0]); + } + } + println!("{:?}", slice_wrapped); +} + +fn check_slice_in_struct() { + #[derive(Debug)] + struct Wrapper<'a> { + inner: Option<&'a [String]>, + is_awesome: bool, + } + + impl<'a> Wrapper<'a> { + fn is_super_awesome(&self) -> bool { + self.is_awesome + } + } + + let inner = &[String::from("New"), String::from("World")]; + let wrap = Wrapper { + inner: Some(inner), + is_awesome: true, + }; + + // Test 1: Field access + if let Some([slice_0, ..]) = wrap.inner { + //~^ ERROR: this binding can be a slice pattern to avoid indexing + if wrap.is_awesome { + println!("This is awesome! {}", slice_0); + } + } + + // Test 2: function access + if let Some([slice_0, ..]) = wrap.inner { + //~^ ERROR: this binding can be a slice pattern to avoid indexing + if wrap.is_super_awesome() { + println!("This is super awesome! {}", slice_0); + } + } + println!("Complete wrap: {:?}", wrap); +} + +/// This would be a nice additional feature to have in the future, but adding it +/// now would make the PR too large. This is therefore only a test that we don't +/// lint cases we can't make a reasonable suggestion for +fn mutable_slice_index() { + // Mut access + let mut slice: Option<[String; 1]> = Some([String::from("Penguin")]); + if let Some(ref mut slice) = slice { + slice[0] = String::from("Mr. Penguin"); + } + println!("Use after modification: {:?}", slice); + + // Mut access on reference + let mut slice: Option<[String; 1]> = Some([String::from("Cat")]); + if let Some(slice) = &mut slice { + slice[0] = String::from("Lord Meow Meow"); + } + println!("Use after modification: {:?}", slice); +} + +/// The lint will ignore bindings with sub patterns as it would be hard +/// to build correct suggestions for these instances :) +fn binding_with_sub_pattern() { + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some(slice @ [_, _, _]) = slice { + println!("{:?}", slice[2]); + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs b/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs index 0a3374d11..d8d38c167 100644 --- a/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs +++ b/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs @@ -12,18 +12,21 @@ fn lintable_examples() { // Try with reference let slice: Option<&[u32]> = Some(&[1, 2, 3]); if let Some(slice) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice[0]); } // Try with copy let slice: Option<[u32; 3]> = Some([1, 2, 3]); if let Some(slice) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice[0]); } // Try with long slice and small indices let slice: Option<[u32; 9]> = Some([1, 2, 3, 4, 5, 6, 7, 8, 9]); if let Some(slice) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice[2]); println!("{}", slice[0]); } @@ -31,6 +34,7 @@ fn lintable_examples() { // Multiple bindings let slice_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([5, 6, 7]); if let SomeEnum::One(slice) | SomeEnum::Three(slice) = slice_wrapped { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{}", slice[0]); } @@ -38,6 +42,8 @@ fn lintable_examples() { let a_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([9, 5, 1]); let b_wrapped: Option<[u32; 2]> = Some([4, 6]); if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) { + //~^ ERROR: this binding can be a slice pattern to avoid indexing + //~| ERROR: this binding can be a slice pattern to avoid indexing println!("{} -> {}", a[2], b[1]); } @@ -45,6 +51,7 @@ fn lintable_examples() { // borrowed and `String` doesn't implement copy let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); if let Some(ref slice) = slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{:?}", slice[1]); } println!("{:?}", slice); @@ -53,6 +60,7 @@ fn lintable_examples() { // a reference let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]); if let Some(slice) = &slice { + //~^ ERROR: this binding can be a slice pattern to avoid indexing println!("{:?}", slice[0]); } println!("{:?}", slice); @@ -122,6 +130,7 @@ fn check_slice_in_struct() { // Test 1: Field access if let Some(slice) = wrap.inner { + //~^ ERROR: this binding can be a slice pattern to avoid indexing if wrap.is_awesome { println!("This is awesome! {}", slice[0]); } @@ -129,6 +138,7 @@ fn check_slice_in_struct() { // Test 2: function access if let Some(slice) = wrap.inner { + //~^ ERROR: this binding can be a slice pattern to avoid indexing if wrap.is_super_awesome() { println!("This is super awesome! {}", slice[0]); } diff --git a/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.stderr b/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.stderr index 0a13ac135..f0e635954 100644 --- a/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.stderr +++ b/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.stderr @@ -19,7 +19,7 @@ LL | println!("{}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:20:17 + --> $DIR/if_let_slice_binding.rs:21:17 | LL | if let Some(slice) = slice { | ^^^^^ @@ -34,7 +34,7 @@ LL | println!("{}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:26:17 + --> $DIR/if_let_slice_binding.rs:28:17 | LL | if let Some(slice) = slice { | ^^^^^ @@ -50,7 +50,7 @@ LL ~ println!("{}", slice_0); | error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:33:26 + --> $DIR/if_let_slice_binding.rs:36:26 | LL | if let SomeEnum::One(slice) | SomeEnum::Three(slice) = slice_wrapped { | ^^^^^ @@ -65,7 +65,7 @@ LL | println!("{}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:40:29 + --> $DIR/if_let_slice_binding.rs:44:29 | LL | if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) { | ^ @@ -80,7 +80,7 @@ LL | println!("{} -> {}", a_2, b[1]); | ~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:40:38 + --> $DIR/if_let_slice_binding.rs:44:38 | LL | if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) { | ^ @@ -95,7 +95,7 @@ LL | println!("{} -> {}", a[2], b_1); | ~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:47:21 + --> $DIR/if_let_slice_binding.rs:53:21 | LL | if let Some(ref slice) = slice { | ^^^^^ @@ -110,7 +110,7 @@ LL | println!("{:?}", slice_1); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:55:17 + --> $DIR/if_let_slice_binding.rs:62:17 | LL | if let Some(slice) = &slice { | ^^^^^ @@ -125,7 +125,7 @@ LL | println!("{:?}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:124:17 + --> $DIR/if_let_slice_binding.rs:132:17 | LL | if let Some(slice) = wrap.inner { | ^^^^^ @@ -140,7 +140,7 @@ LL | println!("This is awesome! {}", slice_0); | ~~~~~~~ error: this binding can be a slice pattern to avoid indexing - --> $DIR/if_let_slice_binding.rs:131:17 + --> $DIR/if_let_slice_binding.rs:140:17 | LL | if let Some(slice) = wrap.inner { | ^^^^^ diff --git a/src/tools/clippy/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed b/src/tools/clippy/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed new file mode 100644 index 000000000..72edc539f --- /dev/null +++ b/src/tools/clippy/tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed @@ -0,0 +1,29 @@ +#![deny(clippy::index_refutable_slice)] + +extern crate if_chain; +use if_chain::if_chain; + +macro_rules! if_let_slice_macro { + () => { + // This would normally be linted + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some(slice) = slice { + println!("{}", slice[0]); + } + }; +} + +fn main() { + // Don't lint this + if_let_slice_macro!(); + + // Do lint this + if_chain! { + let slice: Option<&[u32]> = Some(&[1, 2, 3]); + if let Some([slice_0, ..]) = slice; + //~^ ERROR: this binding can be a slice pattern to avoid indexing + then { + println!("{}", slice_0); + } + } +} diff --git a/src/tools/clippy/tests/ui/index_refutable_slice/slice_indexing_in_macro.rs b/src/tools/clippy/tests/ui/index_refutable_slice/slice_indexing_in_macro.rs index 406e82083..7b474ba42 100644 --- a/src/tools/clippy/tests/ui/index_refutable_slice/slice_indexing_in_macro.rs +++ b/src/tools/clippy/tests/ui/index_refutable_slice/slice_indexing_in_macro.rs @@ -21,6 +21,7 @@ fn main() { if_chain! { let slice: Option<&[u32]> = Some(&[1, 2, 3]); if let Some(slice) = slice; + //~^ ERROR: this binding can be a slice pattern to avoid indexing then { println!("{}", slice[0]); } diff --git a/src/tools/clippy/tests/ui/indexing_slicing_index.rs b/src/tools/clippy/tests/ui/indexing_slicing_index.rs index 16f9e47e8..f0da5dfc6 100644 --- a/src/tools/clippy/tests/ui/indexing_slicing_index.rs +++ b/src/tools/clippy/tests/ui/indexing_slicing_index.rs @@ -12,7 +12,9 @@ const ARR: [i32; 2] = [1, 2]; const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +//~^ ERROR: indexing may panic const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. +//~^ ERROR: indexing may panic const fn idx() -> usize { 1 @@ -25,29 +27,51 @@ fn main() { let x = [1, 2, 3, 4]; let index: usize = 1; x[index]; - 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. + //~^ ERROR: indexing may panic + // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. + x[4]; + // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. + x[1 << 3]; - x[0]; // Ok, should not produce stderr. - x[3]; // Ok, should not produce stderr. - x[const { idx() }]; // Ok, should not produce stderr. - x[const { idx4() }]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. - const { &ARR[idx()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. - const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. + // Ok, should not produce stderr. + x[0]; + // Ok, should not produce stderr. + x[3]; + // Ok, should not produce stderr. + x[const { idx() }]; + // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. + x[const { idx4() }]; + // This should be linted, since `suppress-restriction-lint-in-const` default is false. + const { &ARR[idx()] }; + //~^ ERROR: indexing may panic + // This should be linted, since `suppress-restriction-lint-in-const` default is false. + const { &ARR[idx4()] }; + //~^ ERROR: indexing may panic let y = &x; - y[0]; // Ok, referencing shouldn't affect this lint. See the issue 6021 - y[4]; // Ok, rustc will handle references too. + // Ok, referencing shouldn't affect this lint. See the issue 6021 + y[0]; + // Ok, rustc will handle references too. + y[4]; let v = vec![0; 5]; v[0]; + //~^ ERROR: indexing may panic v[10]; + //~^ ERROR: indexing may panic v[1 << 3]; + //~^ ERROR: indexing may panic - 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. + // Out of bounds + const N: usize = 15; + // In bounds + const M: usize = 3; + // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. + x[N]; + // Ok, should not produce stderr. + x[M]; v[N]; + //~^ ERROR: indexing may panic v[M]; + //~^ ERROR: indexing may panic } diff --git a/src/tools/clippy/tests/ui/indexing_slicing_index.stderr b/src/tools/clippy/tests/ui/indexing_slicing_index.stderr index f4357c1d5..1c34875d2 100644 --- a/src/tools/clippy/tests/ui/indexing_slicing_index.stderr +++ b/src/tools/clippy/tests/ui/indexing_slicing_index.stderr @@ -7,9 +7,10 @@ LL | const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-re = help: consider using `.get(n)` or `.get_mut(n)` instead = note: the suggestion might not be applicable in constant blocks = note: `-D clippy::indexing-slicing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` error: indexing may panic - --> $DIR/indexing_slicing_index.rs:15:24 + --> $DIR/indexing_slicing_index.rs:16:24 | LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. | ^^^^^^^^^^^ @@ -18,19 +19,19 @@ LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. = note: the suggestion might not be applicable in constant blocks error[E0080]: evaluation of `main::{constant#3}` failed - --> $DIR/indexing_slicing_index.rs:36:14 + --> $DIR/indexing_slicing_index.rs:48:14 | -LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 -note: erroneous constant used - --> $DIR/indexing_slicing_index.rs:36:5 +note: erroneous constant encountered + --> $DIR/indexing_slicing_index.rs:48:5 | -LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^^^^^^^^^^^^ error: indexing may panic - --> $DIR/indexing_slicing_index.rs:27:5 + --> $DIR/indexing_slicing_index.rs:29:5 | LL | x[index]; | ^^^^^^^^ @@ -38,25 +39,25 @@ LL | x[index]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:35:14 + --> $DIR/indexing_slicing_index.rs:45:14 | -LL | const { &ARR[idx()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +LL | const { &ARR[idx()] }; | ^^^^^^^^^^ | = help: consider using `.get(n)` or `.get_mut(n)` instead = note: the suggestion might not be applicable in constant blocks error: indexing may panic - --> $DIR/indexing_slicing_index.rs:36:14 + --> $DIR/indexing_slicing_index.rs:48:14 | -LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false. +LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ | = help: consider using `.get(n)` or `.get_mut(n)` instead = note: the suggestion might not be applicable in constant blocks error: indexing may panic - --> $DIR/indexing_slicing_index.rs:43:5 + --> $DIR/indexing_slicing_index.rs:58:5 | LL | v[0]; | ^^^^ @@ -64,7 +65,7 @@ LL | v[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:44:5 + --> $DIR/indexing_slicing_index.rs:60:5 | LL | v[10]; | ^^^^^ @@ -72,7 +73,7 @@ LL | v[10]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:45:5 + --> $DIR/indexing_slicing_index.rs:62:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -80,7 +81,7 @@ LL | v[1 << 3]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:51:5 + --> $DIR/indexing_slicing_index.rs:73:5 | LL | v[N]; | ^^^^ @@ -88,7 +89,7 @@ LL | v[N]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:52:5 + --> $DIR/indexing_slicing_index.rs:75:5 | LL | v[M]; | ^^^^ @@ -96,7 +97,7 @@ LL | v[M]; = help: consider using `.get(n)` or `.get_mut(n)` instead error[E0080]: evaluation of constant value failed - --> $DIR/indexing_slicing_index.rs:15:24 + --> $DIR/indexing_slicing_index.rs:16:24 | LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 diff --git a/src/tools/clippy/tests/ui/indexing_slicing_slice.rs b/src/tools/clippy/tests/ui/indexing_slicing_slice.rs index 939b6ac36..fc591021e 100644 --- a/src/tools/clippy/tests/ui/indexing_slicing_slice.rs +++ b/src/tools/clippy/tests/ui/indexing_slicing_slice.rs @@ -10,12 +10,22 @@ fn main() { let index_from: usize = 2; let index_to: usize = 3; &x[index..]; + //~^ ERROR: slicing may panic &x[..index]; + //~^ ERROR: slicing may panic &x[index_from..index_to]; - &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. - &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. + //~^ ERROR: slicing may panic + &x[index_from..][..index_to]; + //~^ ERROR: slicing may panic + //~| ERROR: slicing may panic + &x[5..][..10]; + //~^ ERROR: slicing may panic + //~| ERROR: range is out of bounds + //~| NOTE: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` &x[0..][..3]; + //~^ ERROR: slicing may panic &x[1..][..5]; + //~^ ERROR: slicing may panic &x[0..].get(..3); // Ok, should not produce stderr. &x[0..3]; // Ok, should not produce stderr. @@ -23,15 +33,22 @@ fn main() { let y = &x; &y[1..2]; &y[0..=4]; + //~^ ERROR: range is out of bounds &y[..=4]; + //~^ ERROR: range is out of bounds &y[..]; // Ok, should not produce stderr. let v = vec![0; 5]; &v[10..100]; - &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100]. + //~^ ERROR: slicing may panic + &x[10..][..100]; + //~^ ERROR: slicing may panic + //~| ERROR: range is out of bounds &v[10..]; + //~^ ERROR: slicing may panic &v[..100]; + //~^ ERROR: slicing may panic &v[..]; // Ok, should not produce stderr. } diff --git a/src/tools/clippy/tests/ui/indexing_slicing_slice.stderr b/src/tools/clippy/tests/ui/indexing_slicing_slice.stderr index dc54bd413..eebe67810 100644 --- a/src/tools/clippy/tests/ui/indexing_slicing_slice.stderr +++ b/src/tools/clippy/tests/ui/indexing_slicing_slice.stderr @@ -6,9 +6,10 @@ LL | &x[index..]; | = help: consider using `.get(n..)` or .get_mut(n..)` instead = note: `-D clippy::indexing-slicing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:13:6 + --> $DIR/indexing_slicing_slice.rs:14:6 | LL | &x[..index]; | ^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | &x[..index]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:14:6 + --> $DIR/indexing_slicing_slice.rs:16:6 | LL | &x[index_from..index_to]; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,39 +25,40 @@ LL | &x[index_from..index_to]; = help: consider using `.get(n..m)` or `.get_mut(n..m)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:15:6 + --> $DIR/indexing_slicing_slice.rs:18:6 | -LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. +LL | &x[index_from..][..index_to]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:15:6 + --> $DIR/indexing_slicing_slice.rs:18:6 | -LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. +LL | &x[index_from..][..index_to]; | ^^^^^^^^^^^^^^^ | = help: consider using `.get(n..)` or .get_mut(n..)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:16:6 + --> $DIR/indexing_slicing_slice.rs:21:6 | -LL | &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. +LL | &x[5..][..10]; | ^^^^^^^^^^^^ | = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:16:8 + --> $DIR/indexing_slicing_slice.rs:21:8 | -LL | &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. +LL | &x[5..][..10]; | ^ | = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:17:6 + --> $DIR/indexing_slicing_slice.rs:25:6 | LL | &x[0..][..3]; | ^^^^^^^^^^^ @@ -64,7 +66,7 @@ LL | &x[0..][..3]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:18:6 + --> $DIR/indexing_slicing_slice.rs:27:6 | LL | &x[1..][..5]; | ^^^^^^^^^^^ @@ -72,19 +74,19 @@ LL | &x[1..][..5]; = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:25:12 + --> $DIR/indexing_slicing_slice.rs:35:12 | LL | &y[0..=4]; | ^ error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:26:11 + --> $DIR/indexing_slicing_slice.rs:37:11 | LL | &y[..=4]; | ^ error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:31:6 + --> $DIR/indexing_slicing_slice.rs:43:6 | LL | &v[10..100]; | ^^^^^^^^^^ @@ -92,21 +94,21 @@ LL | &v[10..100]; = help: consider using `.get(n..m)` or `.get_mut(n..m)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:32:6 + --> $DIR/indexing_slicing_slice.rs:45:6 | -LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100]. +LL | &x[10..][..100]; | ^^^^^^^^^^^^^^ | = help: consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> $DIR/indexing_slicing_slice.rs:32:8 + --> $DIR/indexing_slicing_slice.rs:45:8 | -LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100]. +LL | &x[10..][..100]; | ^^ error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:33:6 + --> $DIR/indexing_slicing_slice.rs:48:6 | LL | &v[10..]; | ^^^^^^^ @@ -114,7 +116,7 @@ LL | &v[10..]; = help: consider using `.get(n..)` or .get_mut(n..)` instead error: slicing may panic - --> $DIR/indexing_slicing_slice.rs:34:6 + --> $DIR/indexing_slicing_slice.rs:50:6 | LL | &v[..100]; | ^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/inefficient_to_string.fixed b/src/tools/clippy/tests/ui/inefficient_to_string.fixed index 557f7fb73..1e1932311 100644 --- a/src/tools/clippy/tests/ui/inefficient_to_string.fixed +++ b/src/tools/clippy/tests/ui/inefficient_to_string.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::inefficient_to_string)] use std::borrow::Cow; diff --git a/src/tools/clippy/tests/ui/inefficient_to_string.rs b/src/tools/clippy/tests/ui/inefficient_to_string.rs index 6503001e3..f027bae6f 100644 --- a/src/tools/clippy/tests/ui/inefficient_to_string.rs +++ b/src/tools/clippy/tests/ui/inefficient_to_string.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::inefficient_to_string)] use std::borrow::Cow; diff --git a/src/tools/clippy/tests/ui/inefficient_to_string.stderr b/src/tools/clippy/tests/ui/inefficient_to_string.stderr index 914dc92bf..4b93465c4 100644 --- a/src/tools/clippy/tests/ui/inefficient_to_string.stderr +++ b/src/tools/clippy/tests/ui/inefficient_to_string.stderr @@ -1,18 +1,18 @@ error: calling `to_string` on `&&str` - --> $DIR/inefficient_to_string.rs:11:21 + --> $DIR/inefficient_to_string.rs:10:21 | LL | let _: String = rrstr.to_string(); | ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrstr).to_string()` | = help: `&str` implements `ToString` through a slower blanket impl, but `str` has a fast specialization of `ToString` note: the lint level is defined here - --> $DIR/inefficient_to_string.rs:2:9 + --> $DIR/inefficient_to_string.rs:1:9 | LL | #![deny(clippy::inefficient_to_string)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: calling `to_string` on `&&&str` - --> $DIR/inefficient_to_string.rs:12:21 + --> $DIR/inefficient_to_string.rs:11:21 | LL | let _: String = rrrstr.to_string(); | ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrstr).to_string()` @@ -20,7 +20,7 @@ LL | let _: String = rrrstr.to_string(); = help: `&&str` implements `ToString` through a slower blanket impl, but `str` has a fast specialization of `ToString` error: calling `to_string` on `&&std::string::String` - --> $DIR/inefficient_to_string.rs:20:21 + --> $DIR/inefficient_to_string.rs:19:21 | LL | let _: String = rrstring.to_string(); | ^^^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrstring).to_string()` @@ -28,7 +28,7 @@ LL | let _: String = rrstring.to_string(); = help: `&std::string::String` implements `ToString` through a slower blanket impl, but `std::string::String` has a fast specialization of `ToString` error: calling `to_string` on `&&&std::string::String` - --> $DIR/inefficient_to_string.rs:21:21 + --> $DIR/inefficient_to_string.rs:20:21 | LL | let _: String = rrrstring.to_string(); | ^^^^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrstring).to_string()` @@ -36,7 +36,7 @@ LL | let _: String = rrrstring.to_string(); = help: `&&std::string::String` implements `ToString` through a slower blanket impl, but `std::string::String` has a fast specialization of `ToString` error: calling `to_string` on `&&std::borrow::Cow<'_, str>` - --> $DIR/inefficient_to_string.rs:29:21 + --> $DIR/inefficient_to_string.rs:28:21 | LL | let _: String = rrcow.to_string(); | ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrcow).to_string()` @@ -44,7 +44,7 @@ LL | let _: String = rrcow.to_string(); = help: `&std::borrow::Cow<'_, str>` implements `ToString` through a slower blanket impl, but `std::borrow::Cow<'_, str>` has a fast specialization of `ToString` error: calling `to_string` on `&&&std::borrow::Cow<'_, str>` - --> $DIR/inefficient_to_string.rs:30:21 + --> $DIR/inefficient_to_string.rs:29:21 | LL | let _: String = rrrcow.to_string(); | ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrcow).to_string()` diff --git a/src/tools/clippy/tests/ui/infallible_destructuring_match.fixed b/src/tools/clippy/tests/ui/infallible_destructuring_match.fixed index e396ae94a..60304177b 100644 --- a/src/tools/clippy/tests/ui/infallible_destructuring_match.fixed +++ b/src/tools/clippy/tests/ui/infallible_destructuring_match.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(exhaustive_patterns, never_type)] #![allow(dead_code, unreachable_code, unused_variables)] #![allow(clippy::let_and_return)] diff --git a/src/tools/clippy/tests/ui/infallible_destructuring_match.rs b/src/tools/clippy/tests/ui/infallible_destructuring_match.rs index 3fce7bbb6..b77aac4a1 100644 --- a/src/tools/clippy/tests/ui/infallible_destructuring_match.rs +++ b/src/tools/clippy/tests/ui/infallible_destructuring_match.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(exhaustive_patterns, never_type)] #![allow(dead_code, unreachable_code, unused_variables)] #![allow(clippy::let_and_return)] diff --git a/src/tools/clippy/tests/ui/infallible_destructuring_match.stderr b/src/tools/clippy/tests/ui/infallible_destructuring_match.stderr index 004260a1d..93851aae8 100644 --- a/src/tools/clippy/tests/ui/infallible_destructuring_match.stderr +++ b/src/tools/clippy/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:29:5 + --> $DIR/infallible_destructuring_match.rs:28:5 | LL | / let data = match wrapper { LL | | SingleVariantEnum::Variant(i) => i, @@ -7,9 +7,10 @@ LL | | }; | |______^ help: try: `let SingleVariantEnum::Variant(data) = wrapper;` | = note: `-D clippy::infallible-destructuring-match` implied by `-D warnings` + = 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:61:5 + --> $DIR/infallible_destructuring_match.rs:60:5 | LL | / let data = match wrapper { LL | | TupleStruct(i) => i, @@ -17,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:85:5 + --> $DIR/infallible_destructuring_match.rs:84:5 | LL | / let data = match wrapper { LL | | TupleStructWithNonCopy(ref n) => n, @@ -25,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:104:5 + --> $DIR/infallible_destructuring_match.rs:103:5 | LL | / let data = match wrapper { LL | | Ok(i) => i, diff --git a/src/tools/clippy/tests/ui/infinite_iter.rs b/src/tools/clippy/tests/ui/infinite_iter.rs index 622644f67..da95ba04b 100644 --- a/src/tools/clippy/tests/ui/infinite_iter.rs +++ b/src/tools/clippy/tests/ui/infinite_iter.rs @@ -8,42 +8,73 @@ fn square_is_lower_64(x: &u32) -> bool { #[allow(clippy::maybe_infinite_iter)] #[deny(clippy::infinite_iter)] fn infinite_iters() { - repeat(0_u8).collect::>(); // infinite iter - (0..8_u32).take_while(square_is_lower_64).cycle().count(); // infinite iter - (0..8_u64).chain(0..).max(); // infinite iter + repeat(0_u8).collect::>(); + //~^ ERROR: infinite iteration detected + // infinite iter + (0..8_u32).take_while(square_is_lower_64).cycle().count(); + //~^ ERROR: infinite iteration detected + // infinite iter + (0..8_u64).chain(0..).max(); + //~^ ERROR: infinite iteration detected + // infinite iter (0_usize..) .chain([0usize, 1, 2].iter().cloned()) .skip_while(|x| *x != 42) - .min(); // infinite iter + .min(); + // infinite iter (0..8_u32) + //~^ ERROR: infinite iteration detected .rev() .cycle() .map(|x| x + 1_u32) - .for_each(|x| println!("{}", x)); // infinite iter - (0..3_u32).flat_map(|x| x..).sum::(); // infinite iter - (0_usize..).flat_map(|x| 0..x).product::(); // infinite iter - (0_u64..).filter(|x| x % 2 == 0).last(); // infinite iter - (0..42_u64).by_ref().last(); // not an infinite, because ranges are double-ended - (0..).next(); // iterator is not exhausted + .for_each(|x| println!("{}", x)); + // infinite iter + (0..3_u32).flat_map(|x| x..).sum::(); + // infinite iter + (0_usize..).flat_map(|x| 0..x).product::(); + //~^ ERROR: infinite iteration detected + // infinite iter + (0_u64..).filter(|x| x % 2 == 0).last(); + //~^ ERROR: infinite iteration detected + // not an infinite, because ranges are double-ended + (0..42_u64).by_ref().last(); + // iterator is not exhausted + (0..).next(); } #[deny(clippy::maybe_infinite_iter)] fn potential_infinite_iters() { - (0..).zip((0..).take_while(square_is_lower_64)).count(); // maybe infinite iter - repeat(42).take_while(|x| *x == 42).chain(0..42).max(); // maybe infinite iter + // maybe infinite iter + (0..).zip((0..).take_while(square_is_lower_64)).count(); + //~^ ERROR: possible infinite iteration detected + // maybe infinite iter + repeat(42).take_while(|x| *x == 42).chain(0..42).max(); + //~^ ERROR: possible infinite iteration detected + // maybe infinite iter (1..) + //~^ ERROR: possible infinite iteration detected .scan(0, |state, x| { *state += x; Some(*state) }) - .min(); // maybe infinite iter - (0..).find(|x| *x == 24); // maybe infinite iter - (0..).position(|x| x == 24); // maybe infinite iter - (0..).any(|x| x == 24); // maybe infinite iter - (0..).all(|x| x == 24); // maybe infinite iter + .min(); + // maybe infinite iter + (0..).find(|x| *x == 24); + //~^ ERROR: possible infinite iteration detected + // maybe infinite iter + (0..).position(|x| x == 24); + //~^ ERROR: possible infinite iteration detected + // maybe infinite iter + (0..).any(|x| x == 24); + //~^ ERROR: possible infinite iteration detected + // maybe infinite iter + (0..).all(|x| x == 24); + //~^ ERROR: possible infinite iteration detected - (0..).zip(0..42).take_while(|&(x, _)| x != 42).count(); // not infinite - repeat(42).take_while(|x| *x == 42).next(); // iterator is not exhausted + // not infinite + (0..).zip(0..42).take_while(|&(x, _)| x != 42).count(); + // iterator is not exhausted + repeat(42).take_while(|x| *x == 42).next(); } fn main() { @@ -62,7 +93,10 @@ mod finite_collect { } fn check_collect() { - let _: HashSet = (0..).collect(); // Infinite iter + // Infinite iter + let _: HashSet = (0..).collect(); + //~^ ERROR: infinite iteration detected + //~| NOTE: `#[deny(clippy::infinite_iter)]` on by default // Some data structures don't collect infinitely, such as `ArrayVec` let _: C = (0..).collect(); diff --git a/src/tools/clippy/tests/ui/infinite_iter.stderr b/src/tools/clippy/tests/ui/infinite_iter.stderr index b911163f7..d0d0f0db4 100644 --- a/src/tools/clippy/tests/ui/infinite_iter.stderr +++ b/src/tools/clippy/tests/ui/infinite_iter.stderr @@ -1,7 +1,7 @@ error: infinite iteration detected --> $DIR/infinite_iter.rs:11:5 | -LL | repeat(0_u8).collect::>(); // infinite iter +LL | repeat(0_u8).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here @@ -11,96 +11,98 @@ LL | #[deny(clippy::infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:12:5 + --> $DIR/infinite_iter.rs:14:5 | -LL | (0..8_u32).take_while(square_is_lower_64).cycle().count(); // infinite iter +LL | (0..8_u32).take_while(square_is_lower_64).cycle().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:13:5 + --> $DIR/infinite_iter.rs:17:5 | -LL | (0..8_u64).chain(0..).max(); // infinite iter +LL | (0..8_u64).chain(0..).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:18:5 + --> $DIR/infinite_iter.rs:25:5 | LL | / (0..8_u32) +LL | | LL | | .rev() LL | | .cycle() LL | | .map(|x| x + 1_u32) -LL | | .for_each(|x| println!("{}", x)); // infinite iter +LL | | .for_each(|x| println!("{}", x)); | |________________________________________^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:24:5 + --> $DIR/infinite_iter.rs:34:5 | -LL | (0_usize..).flat_map(|x| 0..x).product::(); // infinite iter +LL | (0_usize..).flat_map(|x| 0..x).product::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:25:5 + --> $DIR/infinite_iter.rs:37:5 | -LL | (0_u64..).filter(|x| x % 2 == 0).last(); // infinite iter +LL | (0_u64..).filter(|x| x % 2 == 0).last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:32:5 + --> $DIR/infinite_iter.rs:48:5 | -LL | (0..).zip((0..).take_while(square_is_lower_64)).count(); // maybe infinite iter +LL | (0..).zip((0..).take_while(square_is_lower_64)).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/infinite_iter.rs:30:8 + --> $DIR/infinite_iter.rs:45:8 | LL | #[deny(clippy::maybe_infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:33:5 + --> $DIR/infinite_iter.rs:51:5 | -LL | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); // maybe infinite iter +LL | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:34:5 + --> $DIR/infinite_iter.rs:54:5 | LL | / (1..) +LL | | LL | | .scan(0, |state, x| { LL | | *state += x; LL | | Some(*state) LL | | }) -LL | | .min(); // maybe infinite iter +LL | | .min(); | |______________^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:40:5 + --> $DIR/infinite_iter.rs:62:5 | -LL | (0..).find(|x| *x == 24); // maybe infinite iter +LL | (0..).find(|x| *x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:41:5 + --> $DIR/infinite_iter.rs:65:5 | -LL | (0..).position(|x| x == 24); // maybe infinite iter +LL | (0..).position(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:42:5 + --> $DIR/infinite_iter.rs:68:5 | -LL | (0..).any(|x| x == 24); // maybe infinite iter +LL | (0..).any(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> $DIR/infinite_iter.rs:43:5 + --> $DIR/infinite_iter.rs:71:5 | -LL | (0..).all(|x| x == 24); // maybe infinite iter +LL | (0..).all(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> $DIR/infinite_iter.rs:65:31 + --> $DIR/infinite_iter.rs:97:31 | -LL | let _: HashSet = (0..).collect(); // Infinite iter +LL | let _: HashSet = (0..).collect(); | ^^^^^^^^^^^^^^^ | = note: `#[deny(clippy::infinite_iter)]` on by default diff --git a/src/tools/clippy/tests/ui/infinite_loop.rs b/src/tools/clippy/tests/ui/infinite_loop.rs index 38e64b9ac..765c67011 100644 --- a/src/tools/clippy/tests/ui/infinite_loop.rs +++ b/src/tools/clippy/tests/ui/infinite_loop.rs @@ -1,3 +1,5 @@ +//@no-rustfix + fn fn_val(i: i32) -> i32 { unimplemented!() } @@ -18,11 +20,15 @@ fn immutable_condition() { // Should warn when all vars mentioned are immutable let y = 0; while y < 10 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop println!("KO - y is immutable"); } let x = 0; while y < 10 && x < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop let mut k = 1; k += 2; println!("KO - x and y immutable"); @@ -30,6 +36,8 @@ fn immutable_condition() { let cond = false; while !cond { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop println!("KO - cond immutable"); } @@ -74,15 +82,21 @@ fn unused_var() { let (mut i, mut j) = (0, 0); while i < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop j = 3; println!("KO - i not mentioned"); } while i < 3 && j > 0 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop println!("KO - i and j not mentioned"); } while i < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop let mut i = 5; fn_mutref(&mut i); println!("KO - shadowed"); @@ -98,11 +112,15 @@ fn used_immutable() { let mut i = 0; while i < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop fn_constref(&i); println!("KO - const reference"); } while i < 3 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop fn_val(i); println!("KO - passed by value"); } @@ -169,6 +187,8 @@ impl Counter { fn print_n(&self, n: usize) { while self.count < n { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop println!("KO - {} is not mutated", self.count); } } @@ -177,6 +197,8 @@ impl Counter { fn while_loop_with_break_and_return() { let y = 0; while y < 10 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop if y == 0 { break; } @@ -184,6 +206,8 @@ fn while_loop_with_break_and_return() { } while y < 10 { + //~^ ERROR: variables in the condition are not mutated in the loop body + //~| NOTE: this may lead to an infinite or to a never running loop if y == 0 { return; } diff --git a/src/tools/clippy/tests/ui/infinite_loop.stderr b/src/tools/clippy/tests/ui/infinite_loop.stderr index 85258b9d6..a78e47d02 100644 --- a/src/tools/clippy/tests/ui/infinite_loop.stderr +++ b/src/tools/clippy/tests/ui/infinite_loop.stderr @@ -1,5 +1,5 @@ error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:20:11 + --> $DIR/infinite_loop.rs:22:11 | LL | while y < 10 { | ^^^^^^ @@ -8,7 +8,7 @@ LL | while y < 10 { = note: `#[deny(clippy::while_immutable_condition)]` on by default error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:25:11 + --> $DIR/infinite_loop.rs:29:11 | LL | while y < 10 && x < 3 { | ^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | while y < 10 && x < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:32:11 + --> $DIR/infinite_loop.rs:38:11 | LL | while !cond { | ^^^^^ @@ -24,7 +24,7 @@ LL | while !cond { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:76:11 + --> $DIR/infinite_loop.rs:84:11 | LL | while i < 3 { | ^^^^^ @@ -32,7 +32,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:81:11 + --> $DIR/infinite_loop.rs:91:11 | LL | while i < 3 && j > 0 { | ^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | while i < 3 && j > 0 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:85:11 + --> $DIR/infinite_loop.rs:97:11 | LL | while i < 3 { | ^^^^^ @@ -48,7 +48,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:100:11 + --> $DIR/infinite_loop.rs:114:11 | LL | while i < 3 { | ^^^^^ @@ -56,7 +56,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:105:11 + --> $DIR/infinite_loop.rs:121:11 | LL | while i < 3 { | ^^^^^ @@ -64,7 +64,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:171:15 + --> $DIR/infinite_loop.rs:189:15 | LL | while self.count < n { | ^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | while self.count < n { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:179:11 + --> $DIR/infinite_loop.rs:199:11 | LL | while y < 10 { | ^^^^^^ @@ -82,7 +82,7 @@ LL | while y < 10 { = help: rewrite it as `if cond { loop { } }` error: variables in the condition are not mutated in the loop body - --> $DIR/infinite_loop.rs:186:11 + --> $DIR/infinite_loop.rs:208:11 | LL | while y < 10 { | ^^^^^^ diff --git a/src/tools/clippy/tests/ui/inherent_to_string.rs b/src/tools/clippy/tests/ui/inherent_to_string.rs index adb0389a0..7b938cdd7 100644 --- a/src/tools/clippy/tests/ui/inherent_to_string.rs +++ b/src/tools/clippy/tests/ui/inherent_to_string.rs @@ -20,6 +20,7 @@ struct J; impl A { // Should be detected; emit warning fn to_string(&self) -> String { + //~^ ERROR: implementation of inherent method `to_string(&self) -> String` for type `A "A.to_string()".to_string() } @@ -44,6 +45,7 @@ impl B { impl C { // Should be detected and emit error as C also implements Display fn to_string(&self) -> String { + //~^ ERROR: type `C` implements inherent method `to_string(&self) -> String` which sha "C.to_string()".to_string() } } diff --git a/src/tools/clippy/tests/ui/inherent_to_string.stderr b/src/tools/clippy/tests/ui/inherent_to_string.stderr index 579b3c8c5..cf8d09180 100644 --- a/src/tools/clippy/tests/ui/inherent_to_string.stderr +++ b/src/tools/clippy/tests/ui/inherent_to_string.stderr @@ -2,17 +2,20 @@ error: implementation of inherent method `to_string(&self) -> String` for type ` --> $DIR/inherent_to_string.rs:22:5 | LL | / fn to_string(&self) -> String { +LL | | LL | | "A.to_string()".to_string() LL | | } | |_____^ | = help: implement trait `Display` for type `A` instead = note: `-D clippy::inherent-to-string` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inherent_to_string)]` error: type `C` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display` - --> $DIR/inherent_to_string.rs:46:5 + --> $DIR/inherent_to_string.rs:47:5 | LL | / fn to_string(&self) -> String { +LL | | LL | | "C.to_string()".to_string() LL | | } | |_____^ diff --git a/src/tools/clippy/tests/ui/inline_fn_without_body.fixed b/src/tools/clippy/tests/ui/inline_fn_without_body.fixed index 9c5819558..acd808ed4 100644 --- a/src/tools/clippy/tests/ui/inline_fn_without_body.fixed +++ b/src/tools/clippy/tests/ui/inline_fn_without_body.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::inline_fn_without_body)] #![allow(clippy::inline_always)] diff --git a/src/tools/clippy/tests/ui/inline_fn_without_body.rs b/src/tools/clippy/tests/ui/inline_fn_without_body.rs index 43ffaf812..af81feaa3 100644 --- a/src/tools/clippy/tests/ui/inline_fn_without_body.rs +++ b/src/tools/clippy/tests/ui/inline_fn_without_body.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::inline_fn_without_body)] #![allow(clippy::inline_always)] diff --git a/src/tools/clippy/tests/ui/inline_fn_without_body.stderr b/src/tools/clippy/tests/ui/inline_fn_without_body.stderr index 32d35e209..60f6eb8df 100644 --- a/src/tools/clippy/tests/ui/inline_fn_without_body.stderr +++ b/src/tools/clippy/tests/ui/inline_fn_without_body.stderr @@ -1,5 +1,5 @@ error: use of `#[inline]` on trait method `default_inline` which has no body - --> $DIR/inline_fn_without_body.rs:7:5 + --> $DIR/inline_fn_without_body.rs:5:5 | LL | #[inline] | _____-^^^^^^^^ @@ -7,9 +7,10 @@ LL | | fn default_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)]` error: use of `#[inline]` on trait method `always_inline` which has no body - --> $DIR/inline_fn_without_body.rs:10:5 + --> $DIR/inline_fn_without_body.rs:8:5 | LL | #[inline(always)] | _____-^^^^^^^^^^^^^^^^ @@ -17,7 +18,7 @@ LL | | fn always_inline(); | |____- help: remove error: use of `#[inline]` on trait method `never_inline` which has no body - --> $DIR/inline_fn_without_body.rs:13:5 + --> $DIR/inline_fn_without_body.rs:11:5 | LL | #[inline(never)] | _____-^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/inspect_for_each.rs b/src/tools/clippy/tests/ui/inspect_for_each.rs index 7fe45c83b..974690eaa 100644 --- a/src/tools/clippy/tests/ui/inspect_for_each.rs +++ b/src/tools/clippy/tests/ui/inspect_for_each.rs @@ -5,6 +5,7 @@ fn main() { let mut b: Vec = Vec::new(); a.into_iter().inspect(|x| assert!(*x > 0)).for_each(|x| { + //~^ ERROR: called `inspect(..).for_each(..)` on an `Iterator` let y = do_some(x); let z = do_more(y); b.push(z); diff --git a/src/tools/clippy/tests/ui/inspect_for_each.stderr b/src/tools/clippy/tests/ui/inspect_for_each.stderr index 67c2d5e53..80df86ad6 100644 --- a/src/tools/clippy/tests/ui/inspect_for_each.stderr +++ b/src/tools/clippy/tests/ui/inspect_for_each.stderr @@ -3,6 +3,7 @@ error: called `inspect(..).for_each(..)` on an `Iterator` | LL | a.into_iter().inspect(|x| assert!(*x > 0)).for_each(|x| { | ___________________^ +LL | | LL | | let y = do_some(x); LL | | let z = do_more(y); LL | | b.push(z); @@ -11,6 +12,7 @@ LL | | }); | = help: move the code from `inspect(..)` to `for_each(..)` and remove the `inspect(..)` = note: `-D clippy::inspect-for-each` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inspect_for_each)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/int_plus_one.fixed b/src/tools/clippy/tests/ui/int_plus_one.fixed index 5a36ec462..77d9cd3f7 100644 --- a/src/tools/clippy/tests/ui/int_plus_one.fixed +++ b/src/tools/clippy/tests/ui/int_plus_one.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #[allow(clippy::no_effect, clippy::unnecessary_operation)] #[warn(clippy::int_plus_one)] fn main() { diff --git a/src/tools/clippy/tests/ui/int_plus_one.rs b/src/tools/clippy/tests/ui/int_plus_one.rs index bffa4afd6..57c87819d 100644 --- a/src/tools/clippy/tests/ui/int_plus_one.rs +++ b/src/tools/clippy/tests/ui/int_plus_one.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #[allow(clippy::no_effect, clippy::unnecessary_operation)] #[warn(clippy::int_plus_one)] fn main() { diff --git a/src/tools/clippy/tests/ui/int_plus_one.stderr b/src/tools/clippy/tests/ui/int_plus_one.stderr index c5b020ba8..6a62eac7c 100644 --- a/src/tools/clippy/tests/ui/int_plus_one.stderr +++ b/src/tools/clippy/tests/ui/int_plus_one.stderr @@ -1,25 +1,26 @@ error: unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:9:13 + --> $DIR/int_plus_one.rs:7:13 | LL | let _ = x >= y + 1; | ^^^^^^^^^^ help: change it to: `x > y` | = note: `-D clippy::int-plus-one` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::int_plus_one)]` error: unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:10:13 + --> $DIR/int_plus_one.rs:8:13 | LL | let _ = y + 1 <= x; | ^^^^^^^^^^ help: change it to: `y < x` error: unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:12:13 + --> $DIR/int_plus_one.rs:10:13 | LL | let _ = x - 1 >= y; | ^^^^^^^^^^ help: change it to: `x > y` error: unnecessary `>= y + 1` or `x - 1 >=` - --> $DIR/int_plus_one.rs:13:13 + --> $DIR/int_plus_one.rs:11:13 | LL | let _ = y <= x - 1; | ^^^^^^^^^^ help: change it to: `y < x` diff --git a/src/tools/clippy/tests/ui/integer_division.rs b/src/tools/clippy/tests/ui/integer_division.rs index 800c75257..137548fec 100644 --- a/src/tools/clippy/tests/ui/integer_division.rs +++ b/src/tools/clippy/tests/ui/integer_division.rs @@ -3,7 +3,10 @@ fn main() { let two = 2; let n = 1 / 2; + //~^ ERROR: integer division let o = 1 / two; + //~^ ERROR: integer division let p = two / 4; + //~^ ERROR: integer division let x = 1. / 2.0; } diff --git a/src/tools/clippy/tests/ui/integer_division.stderr b/src/tools/clippy/tests/ui/integer_division.stderr index ca8001279..420f0f30e 100644 --- a/src/tools/clippy/tests/ui/integer_division.stderr +++ b/src/tools/clippy/tests/ui/integer_division.stderr @@ -6,9 +6,10 @@ LL | let n = 1 / 2; | = help: division of integers may cause loss of precision. consider using floats = note: `-D clippy::integer-division` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::integer_division)]` error: integer division - --> $DIR/integer_division.rs:6:13 + --> $DIR/integer_division.rs:7:13 | LL | let o = 1 / two; | ^^^^^^^ @@ -16,7 +17,7 @@ LL | let o = 1 / two; = help: division of integers may cause loss of precision. consider using floats error: integer division - --> $DIR/integer_division.rs:7:13 + --> $DIR/integer_division.rs:9:13 | LL | let p = two / 4; | ^^^^^^^ diff --git a/src/tools/clippy/tests/ui/into_iter_on_ref.fixed b/src/tools/clippy/tests/ui/into_iter_on_ref.fixed index af197e33f..c03d91c79 100644 --- a/src/tools/clippy/tests/ui/into_iter_on_ref.fixed +++ b/src/tools/clippy/tests/ui/into_iter_on_ref.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::useless_vec, clippy::needless_borrow)] #![warn(clippy::into_iter_on_ref)] diff --git a/src/tools/clippy/tests/ui/into_iter_on_ref.rs b/src/tools/clippy/tests/ui/into_iter_on_ref.rs index 3ac13d7dd..93c732fd6 100644 --- a/src/tools/clippy/tests/ui/into_iter_on_ref.rs +++ b/src/tools/clippy/tests/ui/into_iter_on_ref.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::useless_vec, clippy::needless_borrow)] #![warn(clippy::into_iter_on_ref)] diff --git a/src/tools/clippy/tests/ui/into_iter_on_ref.stderr b/src/tools/clippy/tests/ui/into_iter_on_ref.stderr index 06014a93f..481957d50 100644 --- a/src/tools/clippy/tests/ui/into_iter_on_ref.stderr +++ b/src/tools/clippy/tests/ui/into_iter_on_ref.stderr @@ -1,163 +1,164 @@ error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Vec` - --> $DIR/into_iter_on_ref.rs:14:30 + --> $DIR/into_iter_on_ref.rs:13:30 | LL | let _ = (&vec![1, 2, 3]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` | = note: `-D clippy::into-iter-on-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::into_iter_on_ref)]` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` - --> $DIR/into_iter_on_ref.rs:15:46 + --> $DIR/into_iter_on_ref.rs:14:46 | LL | let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` - --> $DIR/into_iter_on_ref.rs:16:41 + --> $DIR/into_iter_on_ref.rs:15:41 | LL | let _ = std::rc::Rc::from(&[X][..]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` - --> $DIR/into_iter_on_ref.rs:17:44 + --> $DIR/into_iter_on_ref.rs:16:44 | LL | let _ = std::sync::Arc::from(&[X][..]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` - --> $DIR/into_iter_on_ref.rs:19:32 + --> $DIR/into_iter_on_ref.rs:18:32 | LL | let _ = (&&&&&&&[1, 2, 3]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` - --> $DIR/into_iter_on_ref.rs:20:36 + --> $DIR/into_iter_on_ref.rs:19:36 | LL | let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `array` - --> $DIR/into_iter_on_ref.rs:21:40 + --> $DIR/into_iter_on_ref.rs:20:40 | LL | let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Option` - --> $DIR/into_iter_on_ref.rs:23:24 + --> $DIR/into_iter_on_ref.rs:22:24 | LL | let _ = (&Some(4)).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `Option` - --> $DIR/into_iter_on_ref.rs:24:28 + --> $DIR/into_iter_on_ref.rs:23:28 | LL | let _ = (&mut Some(5)).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Result` - --> $DIR/into_iter_on_ref.rs:25:32 + --> $DIR/into_iter_on_ref.rs:24:32 | LL | let _ = (&Ok::<_, i32>(6)).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `Result` - --> $DIR/into_iter_on_ref.rs:26:37 + --> $DIR/into_iter_on_ref.rs:25:37 | LL | let _ = (&mut Err::(7)).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Vec` - --> $DIR/into_iter_on_ref.rs:27:34 + --> $DIR/into_iter_on_ref.rs:26:34 | LL | let _ = (&Vec::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `Vec` - --> $DIR/into_iter_on_ref.rs:28:38 + --> $DIR/into_iter_on_ref.rs:27:38 | LL | let _ = (&mut Vec::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `BTreeMap` - --> $DIR/into_iter_on_ref.rs:29:44 + --> $DIR/into_iter_on_ref.rs:28:44 | LL | let _ = (&BTreeMap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `BTreeMap` - --> $DIR/into_iter_on_ref.rs:30:48 + --> $DIR/into_iter_on_ref.rs:29:48 | LL | let _ = (&mut BTreeMap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `VecDeque` - --> $DIR/into_iter_on_ref.rs:31:39 + --> $DIR/into_iter_on_ref.rs:30:39 | LL | let _ = (&VecDeque::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `VecDeque` - --> $DIR/into_iter_on_ref.rs:32:43 + --> $DIR/into_iter_on_ref.rs:31:43 | LL | let _ = (&mut VecDeque::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `LinkedList` - --> $DIR/into_iter_on_ref.rs:33:41 + --> $DIR/into_iter_on_ref.rs:32:41 | LL | let _ = (&LinkedList::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `LinkedList` - --> $DIR/into_iter_on_ref.rs:34:45 + --> $DIR/into_iter_on_ref.rs:33:45 | LL | let _ = (&mut LinkedList::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `HashMap` - --> $DIR/into_iter_on_ref.rs:35:43 + --> $DIR/into_iter_on_ref.rs:34:43 | LL | let _ = (&HashMap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter_mut()` and will not consume the `HashMap` - --> $DIR/into_iter_on_ref.rs:36:47 + --> $DIR/into_iter_on_ref.rs:35:47 | LL | let _ = (&mut HashMap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter_mut` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `BTreeSet` - --> $DIR/into_iter_on_ref.rs:38:39 + --> $DIR/into_iter_on_ref.rs:37:39 | LL | let _ = (&BTreeSet::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `BinaryHeap` - --> $DIR/into_iter_on_ref.rs:39:41 + --> $DIR/into_iter_on_ref.rs:38:41 | LL | let _ = (&BinaryHeap::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `HashSet` - --> $DIR/into_iter_on_ref.rs:40:38 + --> $DIR/into_iter_on_ref.rs:39:38 | LL | let _ = (&HashSet::::new()).into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Path` - --> $DIR/into_iter_on_ref.rs:41:43 + --> $DIR/into_iter_on_ref.rs:40:43 | LL | let _ = std::path::Path::new("12/34").into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `PathBuf` - --> $DIR/into_iter_on_ref.rs:42:47 + --> $DIR/into_iter_on_ref.rs:41:47 | LL | let _ = std::path::PathBuf::from("12/34").into_iter(); | ^^^^^^^^^ help: call directly: `iter` error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `array` - --> $DIR/into_iter_on_ref.rs:44:26 + --> $DIR/into_iter_on_ref.rs:43:26 | LL | let _ = (&[1, 2, 3]).into_iter().next(); | ^^^^^^^^^ help: call directly: `iter` diff --git a/src/tools/clippy/tests/ui/invalid_null_ptr_usage.fixed b/src/tools/clippy/tests/ui/invalid_null_ptr_usage.fixed index 9264fb7e9..eeddc2349 100644 --- a/src/tools/clippy/tests/ui/invalid_null_ptr_usage.fixed +++ b/src/tools/clippy/tests/ui/invalid_null_ptr_usage.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - fn main() { unsafe { let _slice: &[usize] = std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); diff --git a/src/tools/clippy/tests/ui/invalid_null_ptr_usage.rs b/src/tools/clippy/tests/ui/invalid_null_ptr_usage.rs index 80c942d77..8569b7740 100644 --- a/src/tools/clippy/tests/ui/invalid_null_ptr_usage.rs +++ b/src/tools/clippy/tests/ui/invalid_null_ptr_usage.rs @@ -1,5 +1,3 @@ -//@run-rustfix - fn main() { unsafe { let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null(), 0); diff --git a/src/tools/clippy/tests/ui/invalid_null_ptr_usage.stderr b/src/tools/clippy/tests/ui/invalid_null_ptr_usage.stderr index 532c36abe..22efa0d84 100644 --- a/src/tools/clippy/tests/ui/invalid_null_ptr_usage.stderr +++ b/src/tools/clippy/tests/ui/invalid_null_ptr_usage.stderr @@ -1,5 +1,5 @@ error: pointer must be non-null - --> $DIR/invalid_null_ptr_usage.rs:5:59 + --> $DIR/invalid_null_ptr_usage.rs:3:59 | LL | let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null(), 0); | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` @@ -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:6:59 + --> $DIR/invalid_null_ptr_usage.rs:4: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:8:63 + --> $DIR/invalid_null_ptr_usage.rs:6: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:10:33 + --> $DIR/invalid_null_ptr_usage.rs:8: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:11:73 + --> $DIR/invalid_null_ptr_usage.rs:9: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:13:48 + --> $DIR/invalid_null_ptr_usage.rs:11: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:14:88 + --> $DIR/invalid_null_ptr_usage.rs:12: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:19:36 + --> $DIR/invalid_null_ptr_usage.rs:17: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:20:36 + --> $DIR/invalid_null_ptr_usage.rs:18: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:22:46 + --> $DIR/invalid_null_ptr_usage.rs:20: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:23:46 + --> $DIR/invalid_null_ptr_usage.rs:21: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:25:45 + --> $DIR/invalid_null_ptr_usage.rs:23: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:26:45 + --> $DIR/invalid_null_ptr_usage.rs:24: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:28:39 + --> $DIR/invalid_null_ptr_usage.rs:26: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:30:69 + --> $DIR/invalid_null_ptr_usage.rs:28: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:31:69 + --> $DIR/invalid_null_ptr_usage.rs:29: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:33:73 + --> $DIR/invalid_null_ptr_usage.rs:31: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:35:29 + --> $DIR/invalid_null_ptr_usage.rs:33: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:36:37 + --> $DIR/invalid_null_ptr_usage.rs:34: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:38:44 + --> $DIR/invalid_null_ptr_usage.rs:36: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:39:52 + --> $DIR/invalid_null_ptr_usage.rs:37: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:41:25 + --> $DIR/invalid_null_ptr_usage.rs:39: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:43:35 + --> $DIR/invalid_null_ptr_usage.rs:41: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:45:34 + --> $DIR/invalid_null_ptr_usage.rs:43: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:47:40 + --> $DIR/invalid_null_ptr_usage.rs:45: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/src/tools/clippy/tests/ui/invalid_upcast_comparisons.rs b/src/tools/clippy/tests/ui/invalid_upcast_comparisons.rs index 697416dce..a9db15f20 100644 --- a/src/tools/clippy/tests/ui/invalid_upcast_comparisons.rs +++ b/src/tools/clippy/tests/ui/invalid_upcast_comparisons.rs @@ -19,36 +19,61 @@ fn main() { // always false, since no u8 can be > 300 (u8 as u32) > 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is + //~| NOTE: `-D clippy::invalid-upcast-comparisons` implied by `-D warnings` (u8 as i32) > 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as u32) == 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as i32) == 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 < (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 < (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 == (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 == (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // inverted of the above (u8 as u32) <= 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as i32) <= 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as u32) != 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as i32) != 300; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 >= (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 >= (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 != (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 300 != (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // always false, since u8 -> i32 doesn't wrap (u8 as i32) < 0; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is -5 != (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // inverted of the above (u8 as i32) >= 0; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is -5 == (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // always false, since no u8 can be 1337 1337 == (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 1337 == (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // inverted of the above 1337 != (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is 1337 != (u8 as u32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is // Those are Ok: (u8 as u32) > 20; @@ -63,7 +88,9 @@ fn main() { (u8 as i8) == -1; (u8 as i8) != -1; (u8 as i32) > -1; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u8 as i32) < -1; + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is (u32 as i32) < -5; (u32 as i32) < 10; @@ -80,6 +107,7 @@ fn main() { -5 > (u32 as i32); -5 >= (u8 as i32); + //~^ ERROR: because of the numeric bounds on `u8` prior to casting, this expression is -5 == (u32 as i32); } diff --git a/src/tools/clippy/tests/ui/invalid_upcast_comparisons.stderr b/src/tools/clippy/tests/ui/invalid_upcast_comparisons.stderr index 03c3fb80a..a57b4b02d 100644 --- a/src/tools/clippy/tests/ui/invalid_upcast_comparisons.stderr +++ b/src/tools/clippy/tests/ui/invalid_upcast_comparisons.stderr @@ -5,159 +5,160 @@ LL | (u8 as u32) > 300; | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::invalid-upcast-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::invalid_upcast_comparisons)]` error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:22:5 + --> $DIR/invalid_upcast_comparisons.rs:24:5 | LL | (u8 as i32) > 300; | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:23:5 + --> $DIR/invalid_upcast_comparisons.rs:26:5 | LL | (u8 as u32) == 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:24:5 + --> $DIR/invalid_upcast_comparisons.rs:28:5 | LL | (u8 as i32) == 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:25:5 + --> $DIR/invalid_upcast_comparisons.rs:30:5 | LL | 300 < (u8 as u32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:26:5 + --> $DIR/invalid_upcast_comparisons.rs:32:5 | LL | 300 < (u8 as i32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:27:5 + --> $DIR/invalid_upcast_comparisons.rs:34:5 | LL | 300 == (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:28:5 + --> $DIR/invalid_upcast_comparisons.rs:36:5 | LL | 300 == (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:30:5 + --> $DIR/invalid_upcast_comparisons.rs:39:5 | LL | (u8 as u32) <= 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:31:5 + --> $DIR/invalid_upcast_comparisons.rs:41:5 | LL | (u8 as i32) <= 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:32:5 + --> $DIR/invalid_upcast_comparisons.rs:43:5 | LL | (u8 as u32) != 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:33:5 + --> $DIR/invalid_upcast_comparisons.rs:45:5 | LL | (u8 as i32) != 300; | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:34:5 + --> $DIR/invalid_upcast_comparisons.rs:47:5 | LL | 300 >= (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:35:5 + --> $DIR/invalid_upcast_comparisons.rs:49:5 | LL | 300 >= (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:36:5 + --> $DIR/invalid_upcast_comparisons.rs:51:5 | LL | 300 != (u8 as u32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:37:5 + --> $DIR/invalid_upcast_comparisons.rs:53:5 | LL | 300 != (u8 as i32); | ^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:40:5 + --> $DIR/invalid_upcast_comparisons.rs:57:5 | LL | (u8 as i32) < 0; | ^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:41:5 + --> $DIR/invalid_upcast_comparisons.rs:59:5 | LL | -5 != (u8 as i32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:43:5 + --> $DIR/invalid_upcast_comparisons.rs:62:5 | LL | (u8 as i32) >= 0; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:44:5 + --> $DIR/invalid_upcast_comparisons.rs:64:5 | LL | -5 == (u8 as i32); | ^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:47:5 + --> $DIR/invalid_upcast_comparisons.rs:68:5 | LL | 1337 == (u8 as i32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:48:5 + --> $DIR/invalid_upcast_comparisons.rs:70:5 | LL | 1337 == (u8 as u32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:50:5 + --> $DIR/invalid_upcast_comparisons.rs:73:5 | LL | 1337 != (u8 as i32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:51:5 + --> $DIR/invalid_upcast_comparisons.rs:75:5 | LL | 1337 != (u8 as u32); | ^^^^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always true - --> $DIR/invalid_upcast_comparisons.rs:65:5 + --> $DIR/invalid_upcast_comparisons.rs:90:5 | LL | (u8 as i32) > -1; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:66:5 + --> $DIR/invalid_upcast_comparisons.rs:92:5 | LL | (u8 as i32) < -1; | ^^^^^^^^^^^^^^^^ error: because of the numeric bounds on `u8` prior to casting, this expression is always false - --> $DIR/invalid_upcast_comparisons.rs:82:5 + --> $DIR/invalid_upcast_comparisons.rs:109:5 | LL | -5 >= (u8 as i32); | ^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/is_digit_ascii_radix.fixed b/src/tools/clippy/tests/ui/is_digit_ascii_radix.fixed index bc43303a6..62953ff74 100644 --- a/src/tools/clippy/tests/ui/is_digit_ascii_radix.fixed +++ b/src/tools/clippy/tests/ui/is_digit_ascii_radix.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::is_digit_ascii_radix)] const TEN: u32 = 10; diff --git a/src/tools/clippy/tests/ui/is_digit_ascii_radix.rs b/src/tools/clippy/tests/ui/is_digit_ascii_radix.rs index 93cba5c8e..229f530f6 100644 --- a/src/tools/clippy/tests/ui/is_digit_ascii_radix.rs +++ b/src/tools/clippy/tests/ui/is_digit_ascii_radix.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::is_digit_ascii_radix)] const TEN: u32 = 10; diff --git a/src/tools/clippy/tests/ui/is_digit_ascii_radix.stderr b/src/tools/clippy/tests/ui/is_digit_ascii_radix.stderr index dc5cb2913..28040c3a9 100644 --- a/src/tools/clippy/tests/ui/is_digit_ascii_radix.stderr +++ b/src/tools/clippy/tests/ui/is_digit_ascii_radix.stderr @@ -1,19 +1,20 @@ error: use of `char::is_digit` with literal radix of 10 - --> $DIR/is_digit_ascii_radix.rs:11:13 + --> $DIR/is_digit_ascii_radix.rs:9:13 | LL | let _ = c.is_digit(10); | ^^^^^^^^^^^^^^ help: try: `c.is_ascii_digit()` | = note: `-D clippy::is-digit-ascii-radix` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::is_digit_ascii_radix)]` error: use of `char::is_digit` with literal radix of 16 - --> $DIR/is_digit_ascii_radix.rs:12:13 + --> $DIR/is_digit_ascii_radix.rs:10:13 | LL | let _ = c.is_digit(16); | ^^^^^^^^^^^^^^ help: try: `c.is_ascii_hexdigit()` error: use of `char::is_digit` with literal radix of 16 - --> $DIR/is_digit_ascii_radix.rs:13:13 + --> $DIR/is_digit_ascii_radix.rs:11:13 | LL | let _ = c.is_digit(0x10); | ^^^^^^^^^^^^^^^^ help: try: `c.is_ascii_hexdigit()` diff --git a/src/tools/clippy/tests/ui/issue-7447.rs b/src/tools/clippy/tests/ui/issue-7447.rs index de4362c4d..7e7ef209d 100644 --- a/src/tools/clippy/tests/ui/issue-7447.rs +++ b/src/tools/clippy/tests/ui/issue-7447.rs @@ -24,5 +24,8 @@ pub struct ByteView<'a> { fn main() { byte_view(panic!()); + //~^ ERROR: sub-expression diverges + //~| NOTE: `-D clippy::diverging-sub-expression` implied by `-D warnings` group_entries(panic!()); + //~^ ERROR: sub-expression diverges } diff --git a/src/tools/clippy/tests/ui/issue-7447.stderr b/src/tools/clippy/tests/ui/issue-7447.stderr index 7a113740c..51ecac455 100644 --- a/src/tools/clippy/tests/ui/issue-7447.stderr +++ b/src/tools/clippy/tests/ui/issue-7447.stderr @@ -5,10 +5,11 @@ LL | byte_view(panic!()); | ^^^^^^^^ | = note: `-D clippy::diverging-sub-expression` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::diverging_sub_expression)]` = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) error: sub-expression diverges - --> $DIR/issue-7447.rs:27:19 + --> $DIR/issue-7447.rs:29:19 | LL | group_entries(panic!()); | ^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/issue_2356.fixed b/src/tools/clippy/tests/ui/issue_2356.fixed index a69f5ebdc..892aa4e34 100644 --- a/src/tools/clippy/tests/ui/issue_2356.fixed +++ b/src/tools/clippy/tests/ui/issue_2356.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::while_let_on_iterator)] #![allow(unused_mut)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/issue_2356.rs b/src/tools/clippy/tests/ui/issue_2356.rs index 50e1bce1f..da0eead15 100644 --- a/src/tools/clippy/tests/ui/issue_2356.rs +++ b/src/tools/clippy/tests/ui/issue_2356.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::while_let_on_iterator)] #![allow(unused_mut)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/issue_2356.stderr b/src/tools/clippy/tests/ui/issue_2356.stderr index a24b0b32e..d04b49e52 100644 --- a/src/tools/clippy/tests/ui/issue_2356.stderr +++ b/src/tools/clippy/tests/ui/issue_2356.stderr @@ -1,11 +1,11 @@ error: this loop could be written as a `for` loop - --> $DIR/issue_2356.rs:18:9 + --> $DIR/issue_2356.rs:17:9 | LL | while let Some(e) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for e in it` | note: the lint level is defined here - --> $DIR/issue_2356.rs:2:9 + --> $DIR/issue_2356.rs:1:9 | LL | #![deny(clippy::while_let_on_iterator)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/issue_4266.rs b/src/tools/clippy/tests/ui/issue_4266.rs index 8e0620e52..23453207b 100644 --- a/src/tools/clippy/tests/ui/issue_4266.rs +++ b/src/tools/clippy/tests/ui/issue_4266.rs @@ -2,10 +2,13 @@ #![allow(clippy::uninlined_format_args)] async fn sink1<'a>(_: &'a str) {} // lint +//~^ ERROR: the following explicit lifetimes could be elided: 'a +//~| NOTE: `-D clippy::needless-lifetimes` implied by `-D warnings` async fn sink1_elided(_: &str) {} // ok // lint async fn one_to_one<'a>(s: &'a str) -> &'a str { + //~^ ERROR: the following explicit lifetimes could be elided: 'a s } @@ -26,6 +29,7 @@ struct Foo; impl Foo { // ok pub async fn new(&mut self) -> Self { + //~^ ERROR: methods called `new` usually take no `self` Foo {} } } diff --git a/src/tools/clippy/tests/ui/issue_4266.stderr b/src/tools/clippy/tests/ui/issue_4266.stderr index 5b60646ef..692de2ae5 100644 --- a/src/tools/clippy/tests/ui/issue_4266.stderr +++ b/src/tools/clippy/tests/ui/issue_4266.stderr @@ -5,21 +5,23 @@ LL | async fn sink1<'a>(_: &'a str) {} // lint | ^^ ^^ | = note: `-D clippy::needless-lifetimes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_lifetimes)]` error: the following explicit lifetimes could be elided: 'a - --> $DIR/issue_4266.rs:8:21 + --> $DIR/issue_4266.rs:10:21 | LL | async fn one_to_one<'a>(s: &'a str) -> &'a str { | ^^ ^^ error: methods called `new` usually take no `self` - --> $DIR/issue_4266.rs:28:22 + --> $DIR/issue_4266.rs:31:22 | LL | pub async fn new(&mut self) -> Self { | ^^^^^^^^^ | = help: consider choosing a less ambiguous name = note: `-D clippy::wrong-self-convention` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` error: aborting due to 3 previous errors diff --git a/src/tools/clippy/tests/ui/items_after_statement.rs b/src/tools/clippy/tests/ui/items_after_statement.rs index f12cb8f22..943e7c116 100644 --- a/src/tools/clippy/tests/ui/items_after_statement.rs +++ b/src/tools/clippy/tests/ui/items_after_statement.rs @@ -11,6 +11,8 @@ fn ok() { fn last() { foo(); fn foo() { + //~^ ERROR: adding items after statements is confusing, since items exist from the sta + //~| NOTE: `-D clippy::items-after-statements` implied by `-D warnings` println!("foo"); } } @@ -18,6 +20,7 @@ fn last() { fn main() { foo(); fn foo() { + //~^ ERROR: adding items after statements is confusing, since items exist from the sta println!("foo"); } foo(); diff --git a/src/tools/clippy/tests/ui/items_after_statement.stderr b/src/tools/clippy/tests/ui/items_after_statement.stderr index f69635a97..fa494f217 100644 --- a/src/tools/clippy/tests/ui/items_after_statement.stderr +++ b/src/tools/clippy/tests/ui/items_after_statement.stderr @@ -2,22 +2,26 @@ error: adding items after statements is confusing, since items exist from the st --> $DIR/items_after_statement.rs:13:5 | LL | / fn foo() { +LL | | +LL | | LL | | println!("foo"); LL | | } | |_____^ | = note: `-D clippy::items-after-statements` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::items_after_statements)]` error: adding items after statements is confusing, since items exist from the start of the scope - --> $DIR/items_after_statement.rs:20:5 + --> $DIR/items_after_statement.rs:22:5 | LL | / fn foo() { +LL | | LL | | println!("foo"); LL | | } | |_____^ error: adding items after statements is confusing, since items exist from the start of the scope - --> $DIR/items_after_statement.rs:33:13 + --> $DIR/items_after_statement.rs:36:13 | LL | / fn say_something() { LL | | println!("something"); diff --git a/src/tools/clippy/tests/ui/iter_cloned_collect.fixed b/src/tools/clippy/tests/ui/iter_cloned_collect.fixed index 636f572a3..1d623642a 100644 --- a/src/tools/clippy/tests/ui/iter_cloned_collect.fixed +++ b/src/tools/clippy/tests/ui/iter_cloned_collect.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/iter_cloned_collect.rs b/src/tools/clippy/tests/ui/iter_cloned_collect.rs index 518cb75af..091bd9eaf 100644 --- a/src/tools/clippy/tests/ui/iter_cloned_collect.rs +++ b/src/tools/clippy/tests/ui/iter_cloned_collect.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/iter_cloned_collect.stderr b/src/tools/clippy/tests/ui/iter_cloned_collect.stderr index b2cc497bf..aa7fb98a7 100644 --- a/src/tools/clippy/tests/ui/iter_cloned_collect.stderr +++ b/src/tools/clippy/tests/ui/iter_cloned_collect.stderr @@ -1,19 +1,20 @@ 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:10:27 + --> $DIR/iter_cloned_collect.rs:8:27 | LL | let v2: Vec = v.iter().cloned().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()` | = note: `-D clippy::iter-cloned-collect` implied by `-D warnings` + = 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:15:38 + --> $DIR/iter_cloned_collect.rs:13: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:20:24 + --> $DIR/iter_cloned_collect.rs:18:24 | LL | .to_bytes() | ________________________^ @@ -23,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:28:24 + --> $DIR/iter_cloned_collect.rs:26: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:31:26 + --> $DIR/iter_cloned_collect.rs:29:26 | LL | let _: Vec = v.iter().copied().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()` diff --git a/src/tools/clippy/tests/ui/iter_count.fixed b/src/tools/clippy/tests/ui/iter_count.fixed index b62082014..75c007bb0 100644 --- a/src/tools/clippy/tests/ui/iter_count.fixed +++ b/src/tools/clippy/tests/ui/iter_count.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:option_helpers.rs #![warn(clippy::iter_count)] diff --git a/src/tools/clippy/tests/ui/iter_count.rs b/src/tools/clippy/tests/ui/iter_count.rs index fb2161312..cd8207b2c 100644 --- a/src/tools/clippy/tests/ui/iter_count.rs +++ b/src/tools/clippy/tests/ui/iter_count.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:option_helpers.rs #![warn(clippy::iter_count)] diff --git a/src/tools/clippy/tests/ui/iter_count.stderr b/src/tools/clippy/tests/ui/iter_count.stderr index f9aee0b78..2882b7d28 100644 --- a/src/tools/clippy/tests/ui/iter_count.stderr +++ b/src/tools/clippy/tests/ui/iter_count.stderr @@ -1,151 +1,152 @@ error: called `.iter().count()` on a `slice` - --> $DIR/iter_count.rs:55:6 + --> $DIR/iter_count.rs:54:6 | LL | &vec[..].iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` | = note: `-D clippy::iter-count` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_count)]` error: called `.iter().count()` on a `Vec` - --> $DIR/iter_count.rs:56:5 + --> $DIR/iter_count.rs:55:5 | LL | vec.iter().count(); | ^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` error: called `.iter().count()` on a `slice` - --> $DIR/iter_count.rs:57:5 + --> $DIR/iter_count.rs:56:5 | LL | boxed_slice.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice.len()` error: called `.iter().count()` on a `VecDeque` - --> $DIR/iter_count.rs:58:5 + --> $DIR/iter_count.rs:57:5 | LL | vec_deque.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` error: called `.iter().count()` on a `HashSet` - --> $DIR/iter_count.rs:59:5 + --> $DIR/iter_count.rs:58:5 | LL | hash_set.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()` error: called `.iter().count()` on a `HashMap` - --> $DIR/iter_count.rs:60:5 + --> $DIR/iter_count.rs:59:5 | LL | hash_map.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` error: called `.iter().count()` on a `BTreeMap` - --> $DIR/iter_count.rs:61:5 + --> $DIR/iter_count.rs:60:5 | LL | b_tree_map.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` error: called `.iter().count()` on a `BTreeSet` - --> $DIR/iter_count.rs:62:5 + --> $DIR/iter_count.rs:61:5 | LL | b_tree_set.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()` error: called `.iter().count()` on a `LinkedList` - --> $DIR/iter_count.rs:63:5 + --> $DIR/iter_count.rs:62:5 | LL | linked_list.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` error: called `.iter().count()` on a `BinaryHeap` - --> $DIR/iter_count.rs:64:5 + --> $DIR/iter_count.rs:63:5 | LL | binary_heap.iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()` error: called `.iter_mut().count()` on a `Vec` - --> $DIR/iter_count.rs:66:5 + --> $DIR/iter_count.rs:65:5 | LL | vec.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` error: called `.iter_mut().count()` on a `slice` - --> $DIR/iter_count.rs:67:6 + --> $DIR/iter_count.rs:66:6 | LL | &vec[..].iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` error: called `.iter_mut().count()` on a `VecDeque` - --> $DIR/iter_count.rs:68:5 + --> $DIR/iter_count.rs:67:5 | LL | vec_deque.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` error: called `.iter_mut().count()` on a `HashMap` - --> $DIR/iter_count.rs:69:5 + --> $DIR/iter_count.rs:68:5 | LL | hash_map.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` error: called `.iter_mut().count()` on a `BTreeMap` - --> $DIR/iter_count.rs:70:5 + --> $DIR/iter_count.rs:69:5 | LL | b_tree_map.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` error: called `.iter_mut().count()` on a `LinkedList` - --> $DIR/iter_count.rs:71:5 + --> $DIR/iter_count.rs:70:5 | LL | linked_list.iter_mut().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` error: called `.into_iter().count()` on a `slice` - --> $DIR/iter_count.rs:73:6 + --> $DIR/iter_count.rs:72:6 | LL | &vec[..].into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` error: called `.into_iter().count()` on a `Vec` - --> $DIR/iter_count.rs:74:5 + --> $DIR/iter_count.rs:73:5 | LL | vec.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` error: called `.into_iter().count()` on a `VecDeque` - --> $DIR/iter_count.rs:75:5 + --> $DIR/iter_count.rs:74:5 | LL | vec_deque.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` error: called `.into_iter().count()` on a `HashSet` - --> $DIR/iter_count.rs:76:5 + --> $DIR/iter_count.rs:75:5 | LL | hash_set.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()` error: called `.into_iter().count()` on a `HashMap` - --> $DIR/iter_count.rs:77:5 + --> $DIR/iter_count.rs:76:5 | LL | hash_map.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` error: called `.into_iter().count()` on a `BTreeMap` - --> $DIR/iter_count.rs:78:5 + --> $DIR/iter_count.rs:77:5 | LL | b_tree_map.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` error: called `.into_iter().count()` on a `BTreeSet` - --> $DIR/iter_count.rs:79:5 + --> $DIR/iter_count.rs:78:5 | LL | b_tree_set.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()` error: called `.into_iter().count()` on a `LinkedList` - --> $DIR/iter_count.rs:80:5 + --> $DIR/iter_count.rs:79:5 | LL | linked_list.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` error: called `.into_iter().count()` on a `BinaryHeap` - --> $DIR/iter_count.rs:81:5 + --> $DIR/iter_count.rs:80:5 | LL | binary_heap.into_iter().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()` diff --git a/src/tools/clippy/tests/ui/iter_kv_map.fixed b/src/tools/clippy/tests/ui/iter_kv_map.fixed index 64201b553..566a5b690 100644 --- a/src/tools/clippy/tests/ui/iter_kv_map.fixed +++ b/src/tools/clippy/tests/ui/iter_kv_map.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::iter_kv_map)] #![allow(unused_mut, clippy::redundant_clone, clippy::suspicious_map, clippy::map_identity)] diff --git a/src/tools/clippy/tests/ui/iter_kv_map.rs b/src/tools/clippy/tests/ui/iter_kv_map.rs index ec0231ba5..d85e501da 100644 --- a/src/tools/clippy/tests/ui/iter_kv_map.rs +++ b/src/tools/clippy/tests/ui/iter_kv_map.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::iter_kv_map)] #![allow(unused_mut, clippy::redundant_clone, clippy::suspicious_map, clippy::map_identity)] diff --git a/src/tools/clippy/tests/ui/iter_kv_map.stderr b/src/tools/clippy/tests/ui/iter_kv_map.stderr index e00da223b..62155b7f8 100644 --- a/src/tools/clippy/tests/ui/iter_kv_map.stderr +++ b/src/tools/clippy/tests/ui/iter_kv_map.stderr @@ -1,79 +1,80 @@ error: iterating on a map's keys - --> $DIR/iter_kv_map.rs:16:13 + --> $DIR/iter_kv_map.rs:14:13 | LL | let _ = map.iter().map(|(key, _)| key).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()` | = note: `-D clippy::iter-kv-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_kv_map)]` error: iterating on a map's values - --> $DIR/iter_kv_map.rs:17:13 + --> $DIR/iter_kv_map.rs:15: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:18:13 + --> $DIR/iter_kv_map.rs:16: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:20:13 + --> $DIR/iter_kv_map.rs:18: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:21:13 + --> $DIR/iter_kv_map.rs:19: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:23:13 + --> $DIR/iter_kv_map.rs:21: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:24:13 + --> $DIR/iter_kv_map.rs:22: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:26:13 + --> $DIR/iter_kv_map.rs:24: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:27:13 + --> $DIR/iter_kv_map.rs:25: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:37:13 + --> $DIR/iter_kv_map.rs:35: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:38:13 + --> $DIR/iter_kv_map.rs:36: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:41:13 + --> $DIR/iter_kv_map.rs:39: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:44:13 + --> $DIR/iter_kv_map.rs:42:13 | LL | let _ = map | _____________^ @@ -95,85 +96,85 @@ LL + }) | error: iterating on a map's values - --> $DIR/iter_kv_map.rs:54:13 + --> $DIR/iter_kv_map.rs:52: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:58:13 + --> $DIR/iter_kv_map.rs:56: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:59:13 + --> $DIR/iter_kv_map.rs:57: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:60:13 + --> $DIR/iter_kv_map.rs:58: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:62:13 + --> $DIR/iter_kv_map.rs:60: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:63:13 + --> $DIR/iter_kv_map.rs:61: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:65:13 + --> $DIR/iter_kv_map.rs:63: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:66:13 + --> $DIR/iter_kv_map.rs:64: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:68:13 + --> $DIR/iter_kv_map.rs:66: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:69:13 + --> $DIR/iter_kv_map.rs:67: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:79:13 + --> $DIR/iter_kv_map.rs:77: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:80:13 + --> $DIR/iter_kv_map.rs:78: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:83:13 + --> $DIR/iter_kv_map.rs:81: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:86:13 + --> $DIR/iter_kv_map.rs:84:13 | LL | let _ = map | _____________^ @@ -195,7 +196,7 @@ LL + }) | error: iterating on a map's values - --> $DIR/iter_kv_map.rs:96:13 + --> $DIR/iter_kv_map.rs:94:13 | LL | let _ = map.clone().into_iter().map(|(_, mut val)| val).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()` diff --git a/src/tools/clippy/tests/ui/iter_next_slice.fixed b/src/tools/clippy/tests/ui/iter_next_slice.fixed index 702edccdb..83be12c4e 100644 --- a/src/tools/clippy/tests/ui/iter_next_slice.fixed +++ b/src/tools/clippy/tests/ui/iter_next_slice.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_next_slice)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/iter_next_slice.rs b/src/tools/clippy/tests/ui/iter_next_slice.rs index 30bfc72de..1b257514d 100644 --- a/src/tools/clippy/tests/ui/iter_next_slice.rs +++ b/src/tools/clippy/tests/ui/iter_next_slice.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_next_slice)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/iter_next_slice.stderr b/src/tools/clippy/tests/ui/iter_next_slice.stderr index 0db8201a1..e6b4bd6c0 100644 --- a/src/tools/clippy/tests/ui/iter_next_slice.stderr +++ b/src/tools/clippy/tests/ui/iter_next_slice.stderr @@ -1,25 +1,26 @@ error: using `.iter().next()` on an array - --> $DIR/iter_next_slice.rs:10:13 + --> $DIR/iter_next_slice.rs:9:13 | LL | let _ = s.iter().next(); | ^^^^^^^^^^^^^^^ help: try calling: `s.first()` | = note: `-D clippy::iter-next-slice` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_next_slice)]` error: using `.iter().next()` on a Slice without end index - --> $DIR/iter_next_slice.rs:13:13 + --> $DIR/iter_next_slice.rs:12:13 | LL | let _ = s[2..].iter().next(); | ^^^^^^^^^^^^^^^^^^^^ help: try calling: `s.get(2)` error: using `.iter().next()` on a Slice without end index - --> $DIR/iter_next_slice.rs:16:13 + --> $DIR/iter_next_slice.rs:15:13 | LL | let _ = v[5..].iter().next(); | ^^^^^^^^^^^^^^^^^^^^ help: try calling: `v.get(5)` error: using `.iter().next()` on an array - --> $DIR/iter_next_slice.rs:19:13 + --> $DIR/iter_next_slice.rs:18:13 | LL | let _ = v.iter().next(); | ^^^^^^^^^^^^^^^ help: try calling: `v.first()` diff --git a/src/tools/clippy/tests/ui/iter_not_returning_iterator.rs b/src/tools/clippy/tests/ui/iter_not_returning_iterator.rs index cce216fc6..e694bc7ac 100644 --- a/src/tools/clippy/tests/ui/iter_not_returning_iterator.rs +++ b/src/tools/clippy/tests/ui/iter_not_returning_iterator.rs @@ -28,10 +28,13 @@ struct Counter2 { impl Data2 { fn iter(&self) -> Counter2 { + //~^ ERROR: this method is named `iter` but its return type does not implement `Iterat + //~| NOTE: `-D clippy::iter-not-returning-iterator` implied by `-D warnings` todo!() } fn iter_mut(&self) -> Counter2 { + //~^ ERROR: this method is named `iter_mut` but its return type does not implement `It todo!() } } @@ -48,6 +51,7 @@ impl Iterator for Counter { trait Iter { type I; fn iter(&self) -> Self::I; + //~^ ERROR: this method is named `iter` but its return type does not implement `Iterat } impl Iter for () { diff --git a/src/tools/clippy/tests/ui/iter_not_returning_iterator.stderr b/src/tools/clippy/tests/ui/iter_not_returning_iterator.stderr index 44f029558..c695b1932 100644 --- a/src/tools/clippy/tests/ui/iter_not_returning_iterator.stderr +++ b/src/tools/clippy/tests/ui/iter_not_returning_iterator.stderr @@ -5,15 +5,16 @@ LL | fn iter(&self) -> Counter2 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::iter-not-returning-iterator` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_not_returning_iterator)]` error: this method is named `iter_mut` but its return type does not implement `Iterator` - --> $DIR/iter_not_returning_iterator.rs:34:5 + --> $DIR/iter_not_returning_iterator.rs:36:5 | LL | fn iter_mut(&self) -> Counter2 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this method is named `iter` but its return type does not implement `Iterator` - --> $DIR/iter_not_returning_iterator.rs:50:5 + --> $DIR/iter_not_returning_iterator.rs:53:5 | LL | fn iter(&self) -> Self::I; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/iter_nth.stderr b/src/tools/clippy/tests/ui/iter_nth.stderr index 24be81454..162e6c338 100644 --- a/src/tools/clippy/tests/ui/iter_nth.stderr +++ b/src/tools/clippy/tests/ui/iter_nth.stderr @@ -6,6 +6,7 @@ LL | let bad_vec = some_vec.iter().nth(3); | = help: calling `.get()` is both faster and more readable = note: `-D clippy::iter-nth` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_nth)]` error: called `.iter().nth()` on a slice --> $DIR/iter_nth.rs:35:26 diff --git a/src/tools/clippy/tests/ui/iter_nth_zero.fixed b/src/tools/clippy/tests/ui/iter_nth_zero.fixed index 91f4a7ba0..a3cdb2e59 100644 --- a/src/tools/clippy/tests/ui/iter_nth_zero.fixed +++ b/src/tools/clippy/tests/ui/iter_nth_zero.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::iter_nth_zero)] use std::collections::HashSet; diff --git a/src/tools/clippy/tests/ui/iter_nth_zero.rs b/src/tools/clippy/tests/ui/iter_nth_zero.rs index 160a895bb..64229b512 100644 --- a/src/tools/clippy/tests/ui/iter_nth_zero.rs +++ b/src/tools/clippy/tests/ui/iter_nth_zero.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::iter_nth_zero)] use std::collections::HashSet; diff --git a/src/tools/clippy/tests/ui/iter_nth_zero.stderr b/src/tools/clippy/tests/ui/iter_nth_zero.stderr index 29c56f3a9..939fd0063 100644 --- a/src/tools/clippy/tests/ui/iter_nth_zero.stderr +++ b/src/tools/clippy/tests/ui/iter_nth_zero.stderr @@ -1,19 +1,20 @@ error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent - --> $DIR/iter_nth_zero.rs:20:14 + --> $DIR/iter_nth_zero.rs:18:14 | LL | let _x = s.iter().nth(0); | ^^^^^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `s.iter().next()` | = note: `-D clippy::iter-nth-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_nth_zero)]` error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent - --> $DIR/iter_nth_zero.rs:25:14 + --> $DIR/iter_nth_zero.rs:23:14 | LL | let _y = iter.nth(0); | ^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `iter.next()` error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent - --> $DIR/iter_nth_zero.rs:30:22 + --> $DIR/iter_nth_zero.rs:28:22 | LL | let _unwrapped = iter2.nth(0).unwrap(); | ^^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `iter2.next()` diff --git a/src/tools/clippy/tests/ui/iter_on_empty_collections.fixed b/src/tools/clippy/tests/ui/iter_on_empty_collections.fixed index 4616f0cdc..794629f24 100644 --- a/src/tools/clippy/tests/ui/iter_on_empty_collections.fixed +++ b/src/tools/clippy/tests/ui/iter_on_empty_collections.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_on_empty_collections)] #![allow(clippy::iter_next_slice, clippy::redundant_clone)] diff --git a/src/tools/clippy/tests/ui/iter_on_empty_collections.rs b/src/tools/clippy/tests/ui/iter_on_empty_collections.rs index 81cc7265e..a6461a702 100644 --- a/src/tools/clippy/tests/ui/iter_on_empty_collections.rs +++ b/src/tools/clippy/tests/ui/iter_on_empty_collections.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_on_empty_collections)] #![allow(clippy::iter_next_slice, clippy::redundant_clone)] diff --git a/src/tools/clippy/tests/ui/iter_on_empty_collections.stderr b/src/tools/clippy/tests/ui/iter_on_empty_collections.stderr index cbd611769..57a532019 100644 --- a/src/tools/clippy/tests/ui/iter_on_empty_collections.stderr +++ b/src/tools/clippy/tests/ui/iter_on_empty_collections.stderr @@ -1,37 +1,38 @@ error: `into_iter` call on an empty collection - --> $DIR/iter_on_empty_collections.rs:6:16 + --> $DIR/iter_on_empty_collections.rs:5:16 | LL | assert_eq!([].into_iter().next(), Option::::None); | ^^^^^^^^^^^^^^ help: try: `std::iter::empty()` | = note: `-D clippy::iter-on-empty-collections` implied by `-D warnings` + = 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:7:16 + --> $DIR/iter_on_empty_collections.rs:6: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:8:16 + --> $DIR/iter_on_empty_collections.rs:7: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:9:16 + --> $DIR/iter_on_empty_collections.rs:8: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:10:16 + --> $DIR/iter_on_empty_collections.rs:9: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:11:16 + --> $DIR/iter_on_empty_collections.rs:10:16 | LL | assert_eq!(None.iter().next(), Option::<&i32>::None); | ^^^^^^^^^^^ help: try: `std::iter::empty()` diff --git a/src/tools/clippy/tests/ui/iter_on_single_items.fixed b/src/tools/clippy/tests/ui/iter_on_single_items.fixed index 80dbe454b..117ec8429 100644 --- a/src/tools/clippy/tests/ui/iter_on_single_items.fixed +++ b/src/tools/clippy/tests/ui/iter_on_single_items.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_on_single_items)] #![allow(clippy::iter_next_slice, clippy::redundant_clone)] diff --git a/src/tools/clippy/tests/ui/iter_on_single_items.rs b/src/tools/clippy/tests/ui/iter_on_single_items.rs index 71c8c7a3f..d059370d9 100644 --- a/src/tools/clippy/tests/ui/iter_on_single_items.rs +++ b/src/tools/clippy/tests/ui/iter_on_single_items.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_on_single_items)] #![allow(clippy::iter_next_slice, clippy::redundant_clone)] diff --git a/src/tools/clippy/tests/ui/iter_on_single_items.stderr b/src/tools/clippy/tests/ui/iter_on_single_items.stderr index d6c547116..00398f541 100644 --- a/src/tools/clippy/tests/ui/iter_on_single_items.stderr +++ b/src/tools/clippy/tests/ui/iter_on_single_items.stderr @@ -1,37 +1,38 @@ error: `into_iter` call on a collection with only one item - --> $DIR/iter_on_single_items.rs:6:16 + --> $DIR/iter_on_single_items.rs:5:16 | LL | assert_eq!([123].into_iter().next(), Some(123)); | ^^^^^^^^^^^^^^^^^ help: try: `std::iter::once(123)` | = note: `-D clippy::iter-on-single-items` implied by `-D warnings` + = 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:7:16 + --> $DIR/iter_on_single_items.rs:6: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:8:16 + --> $DIR/iter_on_single_items.rs:7: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:9:16 + --> $DIR/iter_on_single_items.rs:8: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:10:16 + --> $DIR/iter_on_single_items.rs:9: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:11:16 + --> $DIR/iter_on_single_items.rs:10:16 | LL | assert_eq!(Some(123).iter().next(), Some(&123)); | ^^^^^^^^^^^^^^^^ help: try: `std::iter::once(&123)` diff --git a/src/tools/clippy/tests/ui/iter_out_of_bounds.rs b/src/tools/clippy/tests/ui/iter_out_of_bounds.rs new file mode 100644 index 000000000..3cfe6e82f --- /dev/null +++ b/src/tools/clippy/tests/ui/iter_out_of_bounds.rs @@ -0,0 +1,71 @@ +//@no-rustfix + +#![deny(clippy::iter_out_of_bounds)] +#![allow(clippy::useless_vec)] + +fn opaque_empty_iter() -> impl Iterator { + std::iter::empty() +} + +fn main() { + #[allow(clippy::never_loop)] + for _ in [1, 2, 3].iter().skip(4) { + //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + unreachable!(); + } + for (i, _) in [1, 2, 3].iter().take(4).enumerate() { + //~^ ERROR: this `.take()` call takes more items than the iterator will produce + assert!(i <= 2); + } + + #[allow(clippy::needless_borrow)] + for _ in (&&&&&&[1, 2, 3]).iter().take(4) {} + //~^ ERROR: this `.take()` call takes more items than the iterator will produce + + for _ in [1, 2, 3].iter().skip(4) {} + //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + + for _ in [1; 3].iter().skip(4) {} + //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + + // Should not lint + for _ in opaque_empty_iter().skip(1) {} + + for _ in vec![1, 2, 3].iter().skip(4) {} + //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + + for _ in vec![1; 3].iter().skip(4) {} + //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + + let x = [1, 2, 3]; + for _ in x.iter().skip(4) {} + //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + + let n = 4; + for _ in x.iter().skip(n) {} + //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + + let empty = std::iter::empty::; + + for _ in empty().skip(1) {} + //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + + for _ in empty().take(1) {} + //~^ ERROR: this `.take()` call takes more items than the iterator will produce + + for _ in std::iter::once(1).skip(2) {} + //~^ ERROR: this `.skip()` call skips more items than the iterator will produce + + for _ in std::iter::once(1).take(2) {} + //~^ ERROR: this `.take()` call takes more items than the iterator will produce + + for x in [].iter().take(1) { + //~^ ERROR: this `.take()` call takes more items than the iterator will produce + let _: &i32 = x; + } + + // ok, not out of bounds + for _ in [1].iter().take(1) {} + for _ in [1, 2, 3].iter().take(2) {} + for _ in [1, 2, 3].iter().skip(2) {} +} diff --git a/src/tools/clippy/tests/ui/iter_out_of_bounds.stderr b/src/tools/clippy/tests/ui/iter_out_of_bounds.stderr new file mode 100644 index 000000000..f235faec8 --- /dev/null +++ b/src/tools/clippy/tests/ui/iter_out_of_bounds.stderr @@ -0,0 +1,119 @@ +error: this `.skip()` call skips more items than the iterator will produce + --> $DIR/iter_out_of_bounds.rs:12:14 + | +LL | for _ in [1, 2, 3].iter().skip(4) { + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this operation is useless and will create an empty iterator +note: the lint level is defined here + --> $DIR/iter_out_of_bounds.rs:3:9 + | +LL | #![deny(clippy::iter_out_of_bounds)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: this `.take()` call takes more items than the iterator will produce + --> $DIR/iter_out_of_bounds.rs:16:19 + | +LL | for (i, _) in [1, 2, 3].iter().take(4).enumerate() { + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this operation is useless and the returned iterator will simply yield the same items + +error: this `.take()` call takes more items than the iterator will produce + --> $DIR/iter_out_of_bounds.rs:22:14 + | +LL | for _ in (&&&&&&[1, 2, 3]).iter().take(4) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this operation is useless and the returned iterator will simply yield the same items + +error: this `.skip()` call skips more items than the iterator will produce + --> $DIR/iter_out_of_bounds.rs:25:14 + | +LL | for _ in [1, 2, 3].iter().skip(4) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this operation is useless and will create an empty iterator + +error: this `.skip()` call skips more items than the iterator will produce + --> $DIR/iter_out_of_bounds.rs:28:14 + | +LL | for _ in [1; 3].iter().skip(4) {} + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: this operation is useless and will create an empty iterator + +error: this `.skip()` call skips more items than the iterator will produce + --> $DIR/iter_out_of_bounds.rs:34:14 + | +LL | for _ in vec![1, 2, 3].iter().skip(4) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this operation is useless and will create an empty iterator + +error: this `.skip()` call skips more items than the iterator will produce + --> $DIR/iter_out_of_bounds.rs:37:14 + | +LL | for _ in vec![1; 3].iter().skip(4) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this operation is useless and will create an empty iterator + +error: this `.skip()` call skips more items than the iterator will produce + --> $DIR/iter_out_of_bounds.rs:41:14 + | +LL | for _ in x.iter().skip(4) {} + | ^^^^^^^^^^^^^^^^ + | + = note: this operation is useless and will create an empty iterator + +error: this `.skip()` call skips more items than the iterator will produce + --> $DIR/iter_out_of_bounds.rs:45:14 + | +LL | for _ in x.iter().skip(n) {} + | ^^^^^^^^^^^^^^^^ + | + = note: this operation is useless and will create an empty iterator + +error: this `.skip()` call skips more items than the iterator will produce + --> $DIR/iter_out_of_bounds.rs:50:14 + | +LL | for _ in empty().skip(1) {} + | ^^^^^^^^^^^^^^^ + | + = note: this operation is useless and will create an empty iterator + +error: this `.take()` call takes more items than the iterator will produce + --> $DIR/iter_out_of_bounds.rs:53:14 + | +LL | for _ in empty().take(1) {} + | ^^^^^^^^^^^^^^^ + | + = note: this operation is useless and the returned iterator will simply yield the same items + +error: this `.skip()` call skips more items than the iterator will produce + --> $DIR/iter_out_of_bounds.rs:56:14 + | +LL | for _ in std::iter::once(1).skip(2) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this operation is useless and will create an empty iterator + +error: this `.take()` call takes more items than the iterator will produce + --> $DIR/iter_out_of_bounds.rs:59:14 + | +LL | for _ in std::iter::once(1).take(2) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this operation is useless and the returned iterator will simply yield the same items + +error: this `.take()` call takes more items than the iterator will produce + --> $DIR/iter_out_of_bounds.rs:62:14 + | +LL | for x in [].iter().take(1) { + | ^^^^^^^^^^^^^^^^^ + | + = note: this operation is useless and the returned iterator will simply yield the same items + +error: aborting due to 14 previous errors + diff --git a/src/tools/clippy/tests/ui/iter_overeager_cloned.fixed b/src/tools/clippy/tests/ui/iter_overeager_cloned.fixed index 2874513c0..7d8a584b0 100644 --- a/src/tools/clippy/tests/ui/iter_overeager_cloned.fixed +++ b/src/tools/clippy/tests/ui/iter_overeager_cloned.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_overeager_cloned, clippy::redundant_clone, clippy::filter_next)] #![allow(dead_code, clippy::let_unit_value, clippy::useless_vec)] @@ -21,26 +20,52 @@ fn main() { .iter() .flatten().cloned(); - // Not implemented yet - let _ = vec.iter().cloned().filter(|x| x.starts_with('2')); + let _ = vec.iter().filter(|&x| x.starts_with('2')).cloned(); - // Not implemented yet - let _ = vec.iter().cloned().map(|x| x.len()); + let _ = vec.iter().find(|&x| x == "2").cloned(); + + { + let f = |x: &String| x.starts_with('2'); + let _ = vec.iter().filter(|&x| f(x)).cloned(); + let _ = vec.iter().find(|&x| f(x)).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(); + let _ = vec.iter().find(|&x| f(x)).cloned(); + } + + fn test_move<'a>( + iter: impl Iterator + 'a, + target: String, + ) -> impl Iterator + 'a { + iter.filter(move |&(&a, b)| a == 1 && b == &target).cloned() + } + + { + #[derive(Clone)] + struct S<'a> { + a: &'a u32, + b: String, + } + + fn bar<'a>(iter: impl Iterator> + 'a, target: String) -> impl Iterator> + 'a { + iter.filter(move |&S { a, b }| **a == 1 && b == &target).cloned() + } + } + + let _ = vec.iter().map(|x| x.len()); // This would fail if changed. let _ = vec.iter().cloned().map(|x| x + "2"); - // Not implemented yet - let _ = vec.iter().cloned().find(|x| x == "2"); - - // Not implemented yet - let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty())); + let _ = vec.iter().for_each(|x| assert!(!x.is_empty())); - // Not implemented yet - let _ = vec.iter().cloned().all(|x| x.len() == 1); + let _ = vec.iter().all(|x| x.len() == 1); - // Not implemented yet - let _ = vec.iter().cloned().any(|x| x.len() == 1); + let _ = vec.iter().any(|x| x.len() == 1); // Should probably stay as it is. let _ = [0, 1, 2, 3, 4].iter().cloned().take(10); diff --git a/src/tools/clippy/tests/ui/iter_overeager_cloned.rs b/src/tools/clippy/tests/ui/iter_overeager_cloned.rs index 26f39734a..58c374ab8 100644 --- a/src/tools/clippy/tests/ui/iter_overeager_cloned.rs +++ b/src/tools/clippy/tests/ui/iter_overeager_cloned.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::iter_overeager_cloned, clippy::redundant_clone, clippy::filter_next)] #![allow(dead_code, clippy::let_unit_value, clippy::useless_vec)] @@ -22,25 +21,51 @@ fn main() { .cloned() .flatten(); - // Not implemented yet let _ = vec.iter().cloned().filter(|x| x.starts_with('2')); - // Not implemented yet + let _ = vec.iter().cloned().find(|x| x == "2"); + + { + let f = |x: &String| x.starts_with('2'); + let _ = vec.iter().cloned().filter(f); + let _ = vec.iter().cloned().find(f); + } + + { + let vec: Vec<(String, String)> = vec![]; + let f = move |x: &(String, String)| x.0.starts_with('2'); + let _ = vec.iter().cloned().filter(f); + let _ = vec.iter().cloned().find(f); + } + + fn test_move<'a>( + iter: impl Iterator + 'a, + target: String, + ) -> impl Iterator + 'a { + iter.cloned().filter(move |(&a, b)| a == 1 && b == &target) + } + + { + #[derive(Clone)] + struct S<'a> { + a: &'a u32, + b: String, + } + + fn bar<'a>(iter: impl Iterator> + 'a, target: String) -> impl Iterator> + 'a { + iter.cloned().filter(move |S { a, b }| **a == 1 && b == &target) + } + } + let _ = vec.iter().cloned().map(|x| x.len()); // This would fail if changed. let _ = vec.iter().cloned().map(|x| x + "2"); - // Not implemented yet - let _ = vec.iter().cloned().find(|x| x == "2"); - - // Not implemented yet let _ = vec.iter().cloned().for_each(|x| assert!(!x.is_empty())); - // Not implemented yet let _ = vec.iter().cloned().all(|x| x.len() == 1); - // Not implemented yet let _ = vec.iter().cloned().any(|x| x.len() == 1); // Should probably stay as it is. diff --git a/src/tools/clippy/tests/ui/iter_overeager_cloned.stderr b/src/tools/clippy/tests/ui/iter_overeager_cloned.stderr index eaac48be8..a9a739688 100644 --- a/src/tools/clippy/tests/ui/iter_overeager_cloned.stderr +++ b/src/tools/clippy/tests/ui/iter_overeager_cloned.stderr @@ -1,5 +1,5 @@ error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:8:29 + --> $DIR/iter_overeager_cloned.rs:7:29 | LL | let _: Option = vec.iter().cloned().last(); | ^^^^^^^^^^---------------- @@ -7,9 +7,10 @@ LL | let _: Option = vec.iter().cloned().last(); | help: try: `.last().cloned()` | = note: `-D clippy::iter-overeager-cloned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_overeager_cloned)]` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:10:29 + --> $DIR/iter_overeager_cloned.rs:9:29 | LL | let _: Option = vec.iter().chain(vec.iter()).cloned().next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------- @@ -17,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:12:20 + --> $DIR/iter_overeager_cloned.rs:11:20 | LL | let _: usize = vec.iter().filter(|x| x == &"2").cloned().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------- @@ -25,9 +26,10 @@ LL | let _: usize = vec.iter().filter(|x| x == &"2").cloned().count(); | help: try: `.count()` | = note: `-D clippy::redundant-clone` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: unnecessarily eager cloning of iterator items - --> $DIR/iter_overeager_cloned.rs:14:21 + --> $DIR/iter_overeager_cloned.rs:13:21 | LL | let _: Vec<_> = vec.iter().cloned().take(2).collect(); | ^^^^^^^^^^----------------- @@ -35,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:16:21 + --> $DIR/iter_overeager_cloned.rs:15:21 | LL | let _: Vec<_> = vec.iter().cloned().skip(2).collect(); | ^^^^^^^^^^----------------- @@ -43,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:18:13 + --> $DIR/iter_overeager_cloned.rs:17:13 | LL | let _ = vec.iter().filter(|x| x == &"2").cloned().nth(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------- @@ -51,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:20:13 + --> $DIR/iter_overeager_cloned.rs:19:13 | LL | let _ = [Some(Some("str".to_string())), Some(Some("str".to_string()))] | _____________^ @@ -66,5 +68,101 @@ LL ~ .iter() LL ~ .flatten().cloned(); | -error: aborting due to 7 previous errors +error: unnecessarily eager cloning of iterator items + --> $DIR/iter_overeager_cloned.rs:24:13 + | +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 + | +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 + | +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 + | +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 + | +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 + | +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 + | +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 + | +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 + | +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 + | +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 + | +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 + | +LL | let _ = vec.iter().cloned().any(|x| x.len() == 1); + | ^^^^^^^^^^------------------------------- + | | + | help: try: `.any(|x| x.len() == 1)` + +error: aborting due to 19 previous errors diff --git a/src/tools/clippy/tests/ui/iter_skip_next.fixed b/src/tools/clippy/tests/ui/iter_skip_next.fixed index b888d965e..3e41b3632 100644 --- a/src/tools/clippy/tests/ui/iter_skip_next.fixed +++ b/src/tools/clippy/tests/ui/iter_skip_next.fixed @@ -1,10 +1,10 @@ -//@run-rustfix //@aux-build:option_helpers.rs #![warn(clippy::iter_skip_next)] #![allow(clippy::disallowed_names)] #![allow(clippy::iter_nth)] #![allow(clippy::useless_vec)] +#![allow(clippy::iter_out_of_bounds)] #![allow(unused_mut, dead_code)] extern crate option_helpers; diff --git a/src/tools/clippy/tests/ui/iter_skip_next.rs b/src/tools/clippy/tests/ui/iter_skip_next.rs index e44efdebc..6d96441ca 100644 --- a/src/tools/clippy/tests/ui/iter_skip_next.rs +++ b/src/tools/clippy/tests/ui/iter_skip_next.rs @@ -1,10 +1,10 @@ -//@run-rustfix //@aux-build:option_helpers.rs #![warn(clippy::iter_skip_next)] #![allow(clippy::disallowed_names)] #![allow(clippy::iter_nth)] #![allow(clippy::useless_vec)] +#![allow(clippy::iter_out_of_bounds)] #![allow(unused_mut, dead_code)] extern crate option_helpers; diff --git a/src/tools/clippy/tests/ui/iter_skip_next.stderr b/src/tools/clippy/tests/ui/iter_skip_next.stderr index 4ee26e088..39b173e75 100644 --- a/src/tools/clippy/tests/ui/iter_skip_next.stderr +++ b/src/tools/clippy/tests/ui/iter_skip_next.stderr @@ -5,6 +5,7 @@ LL | let _ = some_vec.iter().skip(42).next(); | ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)` | = note: `-D clippy::iter-skip-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_skip_next)]` error: called `skip(..).next()` on an iterator --> $DIR/iter_skip_next.rs:18:36 diff --git a/src/tools/clippy/tests/ui/iter_skip_next_unfixable.rs b/src/tools/clippy/tests/ui/iter_skip_next_unfixable.rs index 3607330cf..6c98bdc8c 100644 --- a/src/tools/clippy/tests/ui/iter_skip_next_unfixable.rs +++ b/src/tools/clippy/tests/ui/iter_skip_next_unfixable.rs @@ -1,19 +1,22 @@ #![warn(clippy::iter_skip_next)] -#![allow(dead_code)] - +#![allow(dead_code, clippy::iter_out_of_bounds)] +//@no-rustfix /// Checks implementation of `ITER_SKIP_NEXT` lint fn main() { // fix #8128 let test_string = "1|1 2"; let sp = test_string.split('|').map(|s| s.trim()); let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect(); + //~^ ERROR: called `skip(..).next()` on an iterator if let Some(s) = Some(test_string.split('|').map(|s| s.trim())) { let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); + //~^ ERROR: called `skip(..).next()` on an iterator }; fn check(s: T) where T: Iterator, { let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); + //~^ ERROR: called `skip(..).next()` on an iterator } } diff --git a/src/tools/clippy/tests/ui/iter_skip_next_unfixable.stderr b/src/tools/clippy/tests/ui/iter_skip_next_unfixable.stderr index 4062706f9..09a467793 100644 --- a/src/tools/clippy/tests/ui/iter_skip_next_unfixable.stderr +++ b/src/tools/clippy/tests/ui/iter_skip_next_unfixable.stderr @@ -10,27 +10,28 @@ help: for this change `sp` has to be mutable LL | let sp = test_string.split('|').map(|s| s.trim()); | ^^ = note: `-D clippy::iter-skip-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_skip_next)]` error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next_unfixable.rs:11:29 + --> $DIR/iter_skip_next_unfixable.rs:12:29 | LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)` | help: for this change `s` has to be mutable - --> $DIR/iter_skip_next_unfixable.rs:10:17 + --> $DIR/iter_skip_next_unfixable.rs:11:17 | LL | if let Some(s) = Some(test_string.split('|').map(|s| s.trim())) { | ^ error: called `skip(..).next()` on an iterator - --> $DIR/iter_skip_next_unfixable.rs:17:29 + --> $DIR/iter_skip_next_unfixable.rs:19:29 | LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect(); | ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)` | help: for this change `s` has to be mutable - --> $DIR/iter_skip_next_unfixable.rs:13:17 + --> $DIR/iter_skip_next_unfixable.rs:15:17 | LL | fn check(s: T) | ^ diff --git a/src/tools/clippy/tests/ui/iter_skip_zero.fixed b/src/tools/clippy/tests/ui/iter_skip_zero.fixed index 1eb0984fe..447d07100 100644 --- a/src/tools/clippy/tests/ui/iter_skip_zero.fixed +++ b/src/tools/clippy/tests/ui/iter_skip_zero.fixed @@ -1,6 +1,5 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro -#![allow(clippy::useless_vec, unused)] +//@aux-build:proc_macros.rs +#![allow(clippy::useless_vec, clippy::iter_out_of_bounds, unused)] #![warn(clippy::iter_skip_zero)] #[macro_use] diff --git a/src/tools/clippy/tests/ui/iter_skip_zero.rs b/src/tools/clippy/tests/ui/iter_skip_zero.rs index 8c103ab1d..ba63c3981 100644 --- a/src/tools/clippy/tests/ui/iter_skip_zero.rs +++ b/src/tools/clippy/tests/ui/iter_skip_zero.rs @@ -1,6 +1,5 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro -#![allow(clippy::useless_vec, unused)] +//@aux-build:proc_macros.rs +#![allow(clippy::useless_vec, clippy::iter_out_of_bounds, unused)] #![warn(clippy::iter_skip_zero)] #[macro_use] diff --git a/src/tools/clippy/tests/ui/iter_skip_zero.stderr b/src/tools/clippy/tests/ui/iter_skip_zero.stderr index 80fecd59e..6b8b3b105 100644 --- a/src/tools/clippy/tests/ui/iter_skip_zero.stderr +++ b/src/tools/clippy/tests/ui/iter_skip_zero.stderr @@ -1,14 +1,15 @@ error: usage of `.skip(0)` - --> $DIR/iter_skip_zero.rs:12:35 + --> $DIR/iter_skip_zero.rs:11:35 | LL | let _ = [1, 2, 3].iter().skip(0); | ^ help: if you meant to skip the first element, use: `1` | = note: this call to `skip` does nothing and is useless; remove it = note: `-D clippy::iter-skip-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_skip_zero)]` error: usage of `.skip(0)` - --> $DIR/iter_skip_zero.rs:13:39 + --> $DIR/iter_skip_zero.rs:12:39 | LL | let _ = vec![1, 2, 3].iter().skip(0); | ^ help: if you meant to skip the first element, use: `1` @@ -16,7 +17,7 @@ LL | let _ = vec![1, 2, 3].iter().skip(0); = note: this call to `skip` does nothing and is useless; remove it error: usage of `.skip(0)` - --> $DIR/iter_skip_zero.rs:14:34 + --> $DIR/iter_skip_zero.rs:13:34 | LL | let _ = once([1, 2, 3]).skip(0); | ^ help: if you meant to skip the first element, use: `1` @@ -24,7 +25,7 @@ LL | let _ = once([1, 2, 3]).skip(0); = note: this call to `skip` does nothing and is useless; remove it error: usage of `.skip(0)` - --> $DIR/iter_skip_zero.rs:15:71 + --> $DIR/iter_skip_zero.rs:14:71 | LL | let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(0)).skip(0); | ^ help: if you meant to skip the first element, use: `1` @@ -32,7 +33,7 @@ LL | let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(0)).skip(0); = note: this call to `skip` does nothing and is useless; remove it error: usage of `.skip(0)` - --> $DIR/iter_skip_zero.rs:15:62 + --> $DIR/iter_skip_zero.rs:14:62 | LL | let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(0)).skip(0); | ^ help: if you meant to skip the first element, use: `1` diff --git a/src/tools/clippy/tests/ui/iter_with_drain.fixed b/src/tools/clippy/tests/ui/iter_with_drain.fixed index 7a8c67701..a03efceed 100644 --- a/src/tools/clippy/tests/ui/iter_with_drain.fixed +++ b/src/tools/clippy/tests/ui/iter_with_drain.fixed @@ -1,4 +1,3 @@ -//@run-rustfix // will emits unused mut warnings after fixing #![allow(unused_mut)] // will emits needless collect warnings after fixing diff --git a/src/tools/clippy/tests/ui/iter_with_drain.rs b/src/tools/clippy/tests/ui/iter_with_drain.rs index cf3a935c3..a8cd47f83 100644 --- a/src/tools/clippy/tests/ui/iter_with_drain.rs +++ b/src/tools/clippy/tests/ui/iter_with_drain.rs @@ -1,4 +1,3 @@ -//@run-rustfix // will emits unused mut warnings after fixing #![allow(unused_mut)] // will emits needless collect warnings after fixing diff --git a/src/tools/clippy/tests/ui/iter_with_drain.stderr b/src/tools/clippy/tests/ui/iter_with_drain.stderr index bfaed29a0..ac04f9396 100644 --- a/src/tools/clippy/tests/ui/iter_with_drain.stderr +++ b/src/tools/clippy/tests/ui/iter_with_drain.stderr @@ -1,37 +1,38 @@ error: `drain(..)` used on a `Vec` - --> $DIR/iter_with_drain.rs:11:34 + --> $DIR/iter_with_drain.rs:10:34 | LL | let mut a: BinaryHeap<_> = a.drain(..).collect(); | ^^^^^^^^^ help: try: `into_iter()` | = note: `-D clippy::iter-with-drain` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iter_with_drain)]` error: `drain(..)` used on a `VecDeque` - --> $DIR/iter_with_drain.rs:14:27 + --> $DIR/iter_with_drain.rs:13:27 | LL | let mut a: Vec<_> = a.drain(..).collect(); | ^^^^^^^^^ help: try: `into_iter()` error: `drain(..)` used on a `Vec` - --> $DIR/iter_with_drain.rs:15:34 + --> $DIR/iter_with_drain.rs:14: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:21:34 + --> $DIR/iter_with_drain.rs:20: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:24:27 + --> $DIR/iter_with_drain.rs:23: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:25:34 + --> $DIR/iter_with_drain.rs:24:34 | LL | let mut a: HashMap<_, _> = a.drain(0..a.len()).map(|x| (x.clone(), x)).collect(); | ^^^^^^^^^^^^^^^^^ help: try: `into_iter()` diff --git a/src/tools/clippy/tests/ui/iterator_step_by_zero.rs b/src/tools/clippy/tests/ui/iterator_step_by_zero.rs index 33ec78e9a..0b51842df 100644 --- a/src/tools/clippy/tests/ui/iterator_step_by_zero.rs +++ b/src/tools/clippy/tests/ui/iterator_step_by_zero.rs @@ -2,8 +2,12 @@ #[warn(clippy::iterator_step_by_zero)] fn main() { let _ = vec!["A", "B", "B"].iter().step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime + //~| NOTE: `-D clippy::iterator-step-by-zero` implied by `-D warnings` let _ = "XXX".chars().step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime let _ = (0..1).step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime // No error, not an iterator. let y = NotIterator; @@ -13,14 +17,18 @@ fn main() { let _ = (0..1).step_by(1); let _ = (1..).step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime let _ = (1..=2).step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime let x = 0..1; let _ = x.step_by(0); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime // check const eval let v1 = vec![1, 2, 3]; let _ = v1.iter().step_by(2 / 3); + //~^ ERROR: `Iterator::step_by(0)` will panic at runtime } struct NotIterator; diff --git a/src/tools/clippy/tests/ui/iterator_step_by_zero.stderr b/src/tools/clippy/tests/ui/iterator_step_by_zero.stderr index b470e2ed2..20ea29322 100644 --- a/src/tools/clippy/tests/ui/iterator_step_by_zero.stderr +++ b/src/tools/clippy/tests/ui/iterator_step_by_zero.stderr @@ -5,39 +5,40 @@ LL | let _ = vec!["A", "B", "B"].iter().step_by(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::iterator-step-by-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::iterator_step_by_zero)]` error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:5:13 + --> $DIR/iterator_step_by_zero.rs:7:13 | LL | let _ = "XXX".chars().step_by(0); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:6:13 + --> $DIR/iterator_step_by_zero.rs:9:13 | LL | let _ = (0..1).step_by(0); | ^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:15:13 + --> $DIR/iterator_step_by_zero.rs:19:13 | LL | let _ = (1..).step_by(0); | ^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:16:13 + --> $DIR/iterator_step_by_zero.rs:21:13 | LL | let _ = (1..=2).step_by(0); | ^^^^^^^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:19:13 + --> $DIR/iterator_step_by_zero.rs:25:13 | LL | let _ = x.step_by(0); | ^^^^^^^^^^^^ error: `Iterator::step_by(0)` will panic at runtime - --> $DIR/iterator_step_by_zero.rs:23:13 + --> $DIR/iterator_step_by_zero.rs:30:13 | LL | let _ = v1.iter().step_by(2 / 3); | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/large_const_arrays.fixed b/src/tools/clippy/tests/ui/large_const_arrays.fixed index f7ce6fbe6..6011bb99d 100644 --- a/src/tools/clippy/tests/ui/large_const_arrays.fixed +++ b/src/tools/clippy/tests/ui/large_const_arrays.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::large_const_arrays)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/large_const_arrays.rs b/src/tools/clippy/tests/ui/large_const_arrays.rs index 002ac77dd..a78425d7b 100644 --- a/src/tools/clippy/tests/ui/large_const_arrays.rs +++ b/src/tools/clippy/tests/ui/large_const_arrays.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::large_const_arrays)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/large_const_arrays.stderr b/src/tools/clippy/tests/ui/large_const_arrays.stderr index 3fb0acbca..e522550ff 100644 --- a/src/tools/clippy/tests/ui/large_const_arrays.stderr +++ b/src/tools/clippy/tests/ui/large_const_arrays.stderr @@ -1,5 +1,5 @@ error: large array defined as const - --> $DIR/large_const_arrays.rs:12:1 + --> $DIR/large_const_arrays.rs:10:1 | LL | pub(crate) const FOO_PUB_CRATE: [u32; 1_000_000] = [0u32; 1_000_000]; | ^^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,9 +7,10 @@ LL | pub(crate) const FOO_PUB_CRATE: [u32; 1_000_000] = [0u32; 1_000_000]; | help: make this a static item: `static` | = note: `-D clippy::large-const-arrays` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_const_arrays)]` error: large array defined as const - --> $DIR/large_const_arrays.rs:13:1 + --> $DIR/large_const_arrays.rs:11:1 | LL | pub const FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,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:14:1 + --> $DIR/large_const_arrays.rs:12:1 | LL | const FOO: [u32; 1_000_000] = [0u32; 1_000_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,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:23:5 + --> $DIR/large_const_arrays.rs:21:5 | LL | pub const BAR_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,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:24:5 + --> $DIR/large_const_arrays.rs:22:5 | LL | const BAR: [u32; 1_000_000] = [0u32; 1_000_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,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:25:5 + --> $DIR/large_const_arrays.rs:23:5 | LL | pub const BAR_STRUCT_PUB: [S; 5_000] = [S { data: [0; 32] }; 5_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,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:26:5 + --> $DIR/large_const_arrays.rs:24:5 | LL | const BAR_STRUCT: [S; 5_000] = [S { data: [0; 32] }; 5_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,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:27:5 + --> $DIR/large_const_arrays.rs:25:5 | LL | pub const BAR_S_PUB: [Option<&str>; 200_000] = [Some("str"); 200_000]; | ^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -65,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:28:5 + --> $DIR/large_const_arrays.rs:26:5 | LL | const BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000]; | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/large_digit_groups.fixed b/src/tools/clippy/tests/ui/large_digit_groups.fixed index f42fcd96d..cdb001e47 100644 --- a/src/tools/clippy/tests/ui/large_digit_groups.fixed +++ b/src/tools/clippy/tests/ui/large_digit_groups.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::large_digit_groups)] fn main() { diff --git a/src/tools/clippy/tests/ui/large_digit_groups.rs b/src/tools/clippy/tests/ui/large_digit_groups.rs index 3db9da6a3..3c30c8670 100644 --- a/src/tools/clippy/tests/ui/large_digit_groups.rs +++ b/src/tools/clippy/tests/ui/large_digit_groups.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::large_digit_groups)] fn main() { diff --git a/src/tools/clippy/tests/ui/large_digit_groups.stderr b/src/tools/clippy/tests/ui/large_digit_groups.stderr index 19c0fae98..e5f37a6cc 100644 --- a/src/tools/clippy/tests/ui/large_digit_groups.stderr +++ b/src/tools/clippy/tests/ui/large_digit_groups.stderr @@ -1,33 +1,35 @@ error: digits of hex, binary or octal literal not in groups of equal size - --> $DIR/large_digit_groups.rs:23:9 + --> $DIR/large_digit_groups.rs:22:9 | LL | 0xd_e_adbee_f_usize, | ^^^^^^^^^^^^^^^^^^^ help: consider: `0xdead_beef_usize` | = note: `-D clippy::unusual-byte-groupings` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unusual_byte_groupings)]` error: digit groups should be smaller - --> $DIR/large_digit_groups.rs:24:9 + --> $DIR/large_digit_groups.rs:23:9 | LL | 1_23456_f32, | ^^^^^^^^^^^ help: consider: `123_456_f32` | = note: `-D clippy::large-digit-groups` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_digit_groups)]` error: digit groups should be smaller - --> $DIR/large_digit_groups.rs:25:9 + --> $DIR/large_digit_groups.rs:24:9 | LL | 1_23456.12_f32, | ^^^^^^^^^^^^^^ help: consider: `123_456.12_f32` error: digit groups should be smaller - --> $DIR/large_digit_groups.rs:26:9 + --> $DIR/large_digit_groups.rs:25:9 | LL | 1_23456.12345_f64, | ^^^^^^^^^^^^^^^^^ help: consider: `123_456.123_45_f64` error: digit groups should be smaller - --> $DIR/large_digit_groups.rs:27:9 + --> $DIR/large_digit_groups.rs:26:9 | LL | 1_23456.12345_6_f64, | ^^^^^^^^^^^^^^^^^^^ help: consider: `123_456.123_456_f64` diff --git a/src/tools/clippy/tests/ui/large_enum_variant.32bit.stderr b/src/tools/clippy/tests/ui/large_enum_variant.32bit.stderr new file mode 100644 index 000000000..0e0eee21c --- /dev/null +++ b/src/tools/clippy/tests/ui/large_enum_variant.32bit.stderr @@ -0,0 +1,280 @@ +error: large size difference between variants + --> $DIR/large_enum_variant.rs:11:1 + | +LL | / enum LargeEnum { +LL | | A(i32), + | | ------ the second-largest variant contains at least 4 bytes +LL | | B([i32; 8000]), + | | -------------- the largest variant contains at least 32000 bytes +LL | | } + | |_^ the entire enum is at least 32004 bytes + | + = note: `-D clippy::large-enum-variant` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]` +help: consider boxing the large fields to reduce the total size of the enum + | +LL | B(Box<[i32; 8000]>), + | ~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:35:1 + | +LL | / enum LargeEnum2 { +LL | | VariantOk(i32, u32), + | | ------------------- the second-largest variant contains at least 8 bytes +LL | | ContainingLargeEnum(LargeEnum), + | | ------------------------------ the largest variant contains at least 32004 bytes +LL | | } + | |_^ the entire enum is at least 32004 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | ContainingLargeEnum(Box), + | ~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:40:1 + | +LL | / enum LargeEnum3 { +LL | | ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), + | | --------------------------------------------------------- the largest variant contains at least 70004 bytes +LL | | VoidVariant, +LL | | StructLikeLittle { x: i32, y: i32 }, + | | ----------------------------------- the second-largest variant contains at least 8 bytes +LL | | } + | |_^ the entire enum is at least 70008 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), + | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:46:1 + | +LL | / enum LargeEnum4 { +LL | | VariantOk(i32, u32), + | | ------------------- the second-largest variant contains at least 8 bytes +LL | | StructLikeLarge { x: [i32; 8000], y: i32 }, + | | ------------------------------------------ the largest variant contains at least 32004 bytes +LL | | } + | |_^ the entire enum is at least 32008 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, + | ~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:51:1 + | +LL | / enum LargeEnum5 { +LL | | VariantOk(i32, u32), + | | ------------------- the second-largest variant contains at least 8 bytes +LL | | StructLikeLarge2 { x: [i32; 8000] }, + | | ----------------------------------- the largest variant contains at least 32000 bytes +LL | | } + | |_^ the entire enum is at least 32004 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | StructLikeLarge2 { x: Box<[i32; 8000]> }, + | ~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:67:1 + | +LL | / enum LargeEnum7 { +LL | | A, +LL | | B([u8; 1255]), + | | ------------- the largest variant contains at least 1255 bytes +LL | | C([u8; 200]), + | | ------------ the second-largest variant contains at least 200 bytes +LL | | } + | |_^ the entire enum is at least 1256 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | B(Box<[u8; 1255]>), + | ~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:73:1 + | +LL | / enum LargeEnum8 { +LL | | VariantOk(i32, u32), + | | ------------------- the second-largest variant contains at least 8 bytes +LL | | ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]), + | | ------------------------------------------------------------------------- the largest variant contains at least 70128 bytes +LL | | } + | |_^ the entire enum is at least 70132 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]>, [i32; 30]), + | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:78:1 + | +LL | / enum LargeEnum9 { +LL | | A(Struct<()>), + | | ------------- the second-largest variant contains at least 4 bytes +LL | | B(Struct2), + | | ---------- the largest variant contains at least 32000 bytes +LL | | } + | |_^ the entire enum is at least 32004 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | B(Box), + | ~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:83:1 + | +LL | / enum LargeEnumOk2 { +LL | | A(T), + | | ---- the second-largest variant contains at least 0 bytes +LL | | B(Struct2), + | | ---------- the largest variant contains at least 32000 bytes +LL | | } + | |_^ the entire enum is at least 32000 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | B(Box), + | ~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:88:1 + | +LL | / enum LargeEnumOk3 { +LL | | A(Struct), + | | ------------ the second-largest variant contains at least 4 bytes +LL | | B(Struct2), + | | ---------- the largest variant contains at least 32000 bytes +LL | | } + | |_^ the entire enum is at least 32000 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | B(Box), + | ~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:103:1 + | +LL | / enum CopyableLargeEnum { +LL | | A(bool), + | | ------- the second-largest variant contains at least 1 bytes +LL | | B([u64; 8000]), + | | -------------- the largest variant contains at least 64000 bytes +LL | | } + | |_^ the entire enum is at least 64004 bytes + | +note: boxing a variant would require the type no longer be `Copy` + --> $DIR/large_enum_variant.rs:103: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 + | +LL | B([u64; 8000]), + | ^^^^^^^^^^^^^^ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:108:1 + | +LL | / enum ManuallyCopyLargeEnum { +LL | | A(bool), + | | ------- the second-largest variant contains at least 1 bytes +LL | | B([u64; 8000]), + | | -------------- the largest variant contains at least 64000 bytes +LL | | } + | |_^ the entire enum is at least 64004 bytes + | +note: boxing a variant would require the type no longer be `Copy` + --> $DIR/large_enum_variant.rs:108: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 + | +LL | B([u64; 8000]), + | ^^^^^^^^^^^^^^ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:121:1 + | +LL | / enum SomeGenericPossiblyCopyEnum { +LL | | A(bool, std::marker::PhantomData), + | | ------------------------------------ the second-largest variant contains at least 1 bytes +LL | | B([u64; 4000]), + | | -------------- the largest variant contains at least 32000 bytes +LL | | } + | |_^ the entire enum is at least 32004 bytes + | +note: boxing a variant would require the type no longer be `Copy` + --> $DIR/large_enum_variant.rs:121: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 + | +LL | B([u64; 4000]), + | ^^^^^^^^^^^^^^ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:134:1 + | +LL | / enum LargeEnumWithGenerics { +LL | | Small, + | | ----- the second-largest variant carries no data at all +LL | | Large((T, [u8; 512])), + | | --------------------- the largest variant contains at least 512 bytes +LL | | } + | |_^ the entire enum is at least 512 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | Large(Box<(T, [u8; 512])>), + | ~~~~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:143:1 + | +LL | / enum WithGenerics { +LL | | Large([Foo; 64]), + | | --------------------- the largest variant contains at least 512 bytes +LL | | Small(u8), + | | --------- the second-largest variant contains at least 1 bytes +LL | | } + | |_^ the entire enum is at least 516 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | Large(Box<[Foo; 64]>), + | ~~~~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:153:1 + | +LL | / enum LargeEnumOfConst { +LL | | Ok, + | | -- the second-largest variant carries no data at all +LL | | Error(PossiblyLargeEnumWithConst<256>), + | | -------------------------------------- the largest variant contains at least 514 bytes +LL | | } + | |_^ the entire enum is at least 514 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | Error(Box>), + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 16 previous errors + diff --git a/src/tools/clippy/tests/ui/large_enum_variant.64bit.stderr b/src/tools/clippy/tests/ui/large_enum_variant.64bit.stderr new file mode 100644 index 000000000..3eba43e05 --- /dev/null +++ b/src/tools/clippy/tests/ui/large_enum_variant.64bit.stderr @@ -0,0 +1,280 @@ +error: large size difference between variants + --> $DIR/large_enum_variant.rs:11:1 + | +LL | / enum LargeEnum { +LL | | A(i32), + | | ------ the second-largest variant contains at least 4 bytes +LL | | B([i32; 8000]), + | | -------------- the largest variant contains at least 32000 bytes +LL | | } + | |_^ the entire enum is at least 32004 bytes + | + = note: `-D clippy::large-enum-variant` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]` +help: consider boxing the large fields to reduce the total size of the enum + | +LL | B(Box<[i32; 8000]>), + | ~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:35:1 + | +LL | / enum LargeEnum2 { +LL | | VariantOk(i32, u32), + | | ------------------- the second-largest variant contains at least 8 bytes +LL | | ContainingLargeEnum(LargeEnum), + | | ------------------------------ the largest variant contains at least 32004 bytes +LL | | } + | |_^ the entire enum is at least 32004 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | ContainingLargeEnum(Box), + | ~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:40:1 + | +LL | / enum LargeEnum3 { +LL | | ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), + | | --------------------------------------------------------- the largest variant contains at least 70004 bytes +LL | | VoidVariant, +LL | | StructLikeLittle { x: i32, y: i32 }, + | | ----------------------------------- the second-largest variant contains at least 8 bytes +LL | | } + | |_^ the entire enum is at least 70008 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), + | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:46:1 + | +LL | / enum LargeEnum4 { +LL | | VariantOk(i32, u32), + | | ------------------- the second-largest variant contains at least 8 bytes +LL | | StructLikeLarge { x: [i32; 8000], y: i32 }, + | | ------------------------------------------ the largest variant contains at least 32004 bytes +LL | | } + | |_^ the entire enum is at least 32008 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, + | ~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:51:1 + | +LL | / enum LargeEnum5 { +LL | | VariantOk(i32, u32), + | | ------------------- the second-largest variant contains at least 8 bytes +LL | | StructLikeLarge2 { x: [i32; 8000] }, + | | ----------------------------------- the largest variant contains at least 32000 bytes +LL | | } + | |_^ the entire enum is at least 32004 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | StructLikeLarge2 { x: Box<[i32; 8000]> }, + | ~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:67:1 + | +LL | / enum LargeEnum7 { +LL | | A, +LL | | B([u8; 1255]), + | | ------------- the largest variant contains at least 1255 bytes +LL | | C([u8; 200]), + | | ------------ the second-largest variant contains at least 200 bytes +LL | | } + | |_^ the entire enum is at least 1256 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | B(Box<[u8; 1255]>), + | ~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:73:1 + | +LL | / enum LargeEnum8 { +LL | | VariantOk(i32, u32), + | | ------------------- the second-largest variant contains at least 8 bytes +LL | | ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]), + | | ------------------------------------------------------------------------- the largest variant contains at least 70128 bytes +LL | | } + | |_^ the entire enum is at least 70132 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]>, [i32; 30]), + | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:78:1 + | +LL | / enum LargeEnum9 { +LL | | A(Struct<()>), + | | ------------- the second-largest variant contains at least 4 bytes +LL | | B(Struct2), + | | ---------- the largest variant contains at least 32000 bytes +LL | | } + | |_^ the entire enum is at least 32004 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | B(Box), + | ~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:83:1 + | +LL | / enum LargeEnumOk2 { +LL | | A(T), + | | ---- the second-largest variant contains at least 0 bytes +LL | | B(Struct2), + | | ---------- the largest variant contains at least 32000 bytes +LL | | } + | |_^ the entire enum is at least 32000 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | B(Box), + | ~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:88:1 + | +LL | / enum LargeEnumOk3 { +LL | | A(Struct), + | | ------------ the second-largest variant contains at least 4 bytes +LL | | B(Struct2), + | | ---------- the largest variant contains at least 32000 bytes +LL | | } + | |_^ the entire enum is at least 32000 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | B(Box), + | ~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:103:1 + | +LL | / enum CopyableLargeEnum { +LL | | A(bool), + | | ------- the second-largest variant contains at least 1 bytes +LL | | B([u64; 8000]), + | | -------------- the largest variant contains at least 64000 bytes +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 + | +LL | enum CopyableLargeEnum { + | ^^^^^^^^^^^^^^^^^ +help: consider boxing the large fields to reduce the total size of the enum + --> $DIR/large_enum_variant.rs:105:5 + | +LL | B([u64; 8000]), + | ^^^^^^^^^^^^^^ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:108:1 + | +LL | / enum ManuallyCopyLargeEnum { +LL | | A(bool), + | | ------- the second-largest variant contains at least 1 bytes +LL | | B([u64; 8000]), + | | -------------- the largest variant contains at least 64000 bytes +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 + | +LL | enum ManuallyCopyLargeEnum { + | ^^^^^^^^^^^^^^^^^^^^^ +help: consider boxing the large fields to reduce the total size of the enum + --> $DIR/large_enum_variant.rs:110:5 + | +LL | B([u64; 8000]), + | ^^^^^^^^^^^^^^ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:121:1 + | +LL | / enum SomeGenericPossiblyCopyEnum { +LL | | A(bool, std::marker::PhantomData), + | | ------------------------------------ the second-largest variant contains at least 1 bytes +LL | | B([u64; 4000]), + | | -------------- the largest variant contains at least 32000 bytes +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 + | +LL | enum SomeGenericPossiblyCopyEnum { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider boxing the large fields to reduce the total size of the enum + --> $DIR/large_enum_variant.rs:123:5 + | +LL | B([u64; 4000]), + | ^^^^^^^^^^^^^^ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:134:1 + | +LL | / enum LargeEnumWithGenerics { +LL | | Small, + | | ----- the second-largest variant carries no data at all +LL | | Large((T, [u8; 512])), + | | --------------------- the largest variant contains at least 512 bytes +LL | | } + | |_^ the entire enum is at least 512 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | Large(Box<(T, [u8; 512])>), + | ~~~~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:143:1 + | +LL | / enum WithGenerics { +LL | | Large([Foo; 64]), + | | --------------------- the largest variant contains at least 512 bytes +LL | | Small(u8), + | | --------- the second-largest variant contains at least 1 bytes +LL | | } + | |_^ the entire enum is at least 520 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | Large(Box<[Foo; 64]>), + | ~~~~~~~~~~~~~~~~~~~ + +error: large size difference between variants + --> $DIR/large_enum_variant.rs:153:1 + | +LL | / enum LargeEnumOfConst { +LL | | Ok, + | | -- the second-largest variant carries no data at all +LL | | Error(PossiblyLargeEnumWithConst<256>), + | | -------------------------------------- the largest variant contains at least 514 bytes +LL | | } + | |_^ the entire enum is at least 514 bytes + | +help: consider boxing the large fields to reduce the total size of the enum + | +LL | Error(Box>), + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 16 previous errors + diff --git a/src/tools/clippy/tests/ui/large_enum_variant.rs b/src/tools/clippy/tests/ui/large_enum_variant.rs index e677cc9a7..3625c011d 100644 --- a/src/tools/clippy/tests/ui/large_enum_variant.rs +++ b/src/tools/clippy/tests/ui/large_enum_variant.rs @@ -1,5 +1,6 @@ -//@aux-build:proc_macros.rs:proc-macro - +//@stderr-per-bitwidth +//@aux-build:proc_macros.rs +//@no-rustfix #![allow(dead_code)] #![allow(unused_variables)] #![warn(clippy::large_enum_variant)] diff --git a/src/tools/clippy/tests/ui/large_enum_variant.stderr b/src/tools/clippy/tests/ui/large_enum_variant.stderr deleted file mode 100644 index 709972b4a..000000000 --- a/src/tools/clippy/tests/ui/large_enum_variant.stderr +++ /dev/null @@ -1,279 +0,0 @@ -error: large size difference between variants - --> $DIR/large_enum_variant.rs:10:1 - | -LL | / enum LargeEnum { -LL | | A(i32), - | | ------ the second-largest variant contains at least 4 bytes -LL | | B([i32; 8000]), - | | -------------- the largest variant contains at least 32000 bytes -LL | | } - | |_^ the entire enum is at least 32004 bytes - | - = note: `-D clippy::large-enum-variant` implied by `-D warnings` -help: consider boxing the large fields to reduce the total size of the enum - | -LL | B(Box<[i32; 8000]>), - | ~~~~~~~~~~~~~~~~ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:34:1 - | -LL | / enum LargeEnum2 { -LL | | VariantOk(i32, u32), - | | ------------------- the second-largest variant contains at least 8 bytes -LL | | ContainingLargeEnum(LargeEnum), - | | ------------------------------ the largest variant contains at least 32004 bytes -LL | | } - | |_^ the entire enum is at least 32004 bytes - | -help: consider boxing the large fields to reduce the total size of the enum - | -LL | ContainingLargeEnum(Box), - | ~~~~~~~~~~~~~~ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:39:1 - | -LL | / enum LargeEnum3 { -LL | | ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]), - | | --------------------------------------------------------- the largest variant contains at least 70004 bytes -LL | | VoidVariant, -LL | | StructLikeLittle { x: i32, y: i32 }, - | | ----------------------------------- the second-largest variant contains at least 8 bytes -LL | | } - | |_^ the entire enum is at least 70008 bytes - | -help: consider boxing the large fields to reduce the total size of the enum - | -LL | ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>), - | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:45:1 - | -LL | / enum LargeEnum4 { -LL | | VariantOk(i32, u32), - | | ------------------- the second-largest variant contains at least 8 bytes -LL | | StructLikeLarge { x: [i32; 8000], y: i32 }, - | | ------------------------------------------ the largest variant contains at least 32004 bytes -LL | | } - | |_^ the entire enum is at least 32008 bytes - | -help: consider boxing the large fields to reduce the total size of the enum - | -LL | StructLikeLarge { x: Box<[i32; 8000]>, y: i32 }, - | ~~~~~~~~~~~~~~~~ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:50:1 - | -LL | / enum LargeEnum5 { -LL | | VariantOk(i32, u32), - | | ------------------- the second-largest variant contains at least 8 bytes -LL | | StructLikeLarge2 { x: [i32; 8000] }, - | | ----------------------------------- the largest variant contains at least 32000 bytes -LL | | } - | |_^ the entire enum is at least 32004 bytes - | -help: consider boxing the large fields to reduce the total size of the enum - | -LL | StructLikeLarge2 { x: Box<[i32; 8000]> }, - | ~~~~~~~~~~~~~~~~ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:66:1 - | -LL | / enum LargeEnum7 { -LL | | A, -LL | | B([u8; 1255]), - | | ------------- the largest variant contains at least 1255 bytes -LL | | C([u8; 200]), - | | ------------ the second-largest variant contains at least 200 bytes -LL | | } - | |_^ the entire enum is at least 1256 bytes - | -help: consider boxing the large fields to reduce the total size of the enum - | -LL | B(Box<[u8; 1255]>), - | ~~~~~~~~~~~~~~~ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:72:1 - | -LL | / enum LargeEnum8 { -LL | | VariantOk(i32, u32), - | | ------------------- the second-largest variant contains at least 8 bytes -LL | | ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]), - | | ------------------------------------------------------------------------- the largest variant contains at least 70128 bytes -LL | | } - | |_^ the entire enum is at least 70132 bytes - | -help: consider boxing the large fields to reduce the total size of the enum - | -LL | ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]>, [i32; 30]), - | ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:77:1 - | -LL | / enum LargeEnum9 { -LL | | A(Struct<()>), - | | ------------- the second-largest variant contains at least 4 bytes -LL | | B(Struct2), - | | ---------- the largest variant contains at least 32000 bytes -LL | | } - | |_^ the entire enum is at least 32004 bytes - | -help: consider boxing the large fields to reduce the total size of the enum - | -LL | B(Box), - | ~~~~~~~~~~~~ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:82:1 - | -LL | / enum LargeEnumOk2 { -LL | | A(T), - | | ---- the second-largest variant contains at least 0 bytes -LL | | B(Struct2), - | | ---------- the largest variant contains at least 32000 bytes -LL | | } - | |_^ the entire enum is at least 32000 bytes - | -help: consider boxing the large fields to reduce the total size of the enum - | -LL | B(Box), - | ~~~~~~~~~~~~ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:87:1 - | -LL | / enum LargeEnumOk3 { -LL | | A(Struct), - | | ------------ the second-largest variant contains at least 4 bytes -LL | | B(Struct2), - | | ---------- the largest variant contains at least 32000 bytes -LL | | } - | |_^ the entire enum is at least 32000 bytes - | -help: consider boxing the large fields to reduce the total size of the enum - | -LL | B(Box), - | ~~~~~~~~~~~~ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:102:1 - | -LL | / enum CopyableLargeEnum { -LL | | A(bool), - | | ------- the second-largest variant contains at least 1 bytes -LL | | B([u64; 8000]), - | | -------------- the largest variant contains at least 64000 bytes -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:102:6 - | -LL | enum CopyableLargeEnum { - | ^^^^^^^^^^^^^^^^^ -help: consider boxing the large fields to reduce the total size of the enum - --> $DIR/large_enum_variant.rs:104:5 - | -LL | B([u64; 8000]), - | ^^^^^^^^^^^^^^ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:107:1 - | -LL | / enum ManuallyCopyLargeEnum { -LL | | A(bool), - | | ------- the second-largest variant contains at least 1 bytes -LL | | B([u64; 8000]), - | | -------------- the largest variant contains at least 64000 bytes -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:107:6 - | -LL | enum ManuallyCopyLargeEnum { - | ^^^^^^^^^^^^^^^^^^^^^ -help: consider boxing the large fields to reduce the total size of the enum - --> $DIR/large_enum_variant.rs:109:5 - | -LL | B([u64; 8000]), - | ^^^^^^^^^^^^^^ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:120:1 - | -LL | / enum SomeGenericPossiblyCopyEnum { -LL | | A(bool, std::marker::PhantomData), - | | ------------------------------------ the second-largest variant contains at least 1 bytes -LL | | B([u64; 4000]), - | | -------------- the largest variant contains at least 32000 bytes -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:120:6 - | -LL | enum SomeGenericPossiblyCopyEnum { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: consider boxing the large fields to reduce the total size of the enum - --> $DIR/large_enum_variant.rs:122:5 - | -LL | B([u64; 4000]), - | ^^^^^^^^^^^^^^ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:133:1 - | -LL | / enum LargeEnumWithGenerics { -LL | | Small, - | | ----- the second-largest variant carries no data at all -LL | | Large((T, [u8; 512])), - | | --------------------- the largest variant contains at least 512 bytes -LL | | } - | |_^ the entire enum is at least 512 bytes - | -help: consider boxing the large fields to reduce the total size of the enum - | -LL | Large(Box<(T, [u8; 512])>), - | ~~~~~~~~~~~~~~~~~~~ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:142:1 - | -LL | / enum WithGenerics { -LL | | Large([Foo; 64]), - | | --------------------- the largest variant contains at least 512 bytes -LL | | Small(u8), - | | --------- the second-largest variant contains at least 1 bytes -LL | | } - | |_^ the entire enum is at least 520 bytes - | -help: consider boxing the large fields to reduce the total size of the enum - | -LL | Large(Box<[Foo; 64]>), - | ~~~~~~~~~~~~~~~~~~~ - -error: large size difference between variants - --> $DIR/large_enum_variant.rs:152:1 - | -LL | / enum LargeEnumOfConst { -LL | | Ok, - | | -- the second-largest variant carries no data at all -LL | | Error(PossiblyLargeEnumWithConst<256>), - | | -------------------------------------- the largest variant contains at least 514 bytes -LL | | } - | |_^ the entire enum is at least 514 bytes - | -help: consider boxing the large fields to reduce the total size of the enum - | -LL | Error(Box>), - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: aborting due to 16 previous errors - diff --git a/src/tools/clippy/tests/ui/large_futures.fixed b/src/tools/clippy/tests/ui/large_futures.fixed new file mode 100644 index 000000000..4c192d1c8 --- /dev/null +++ b/src/tools/clippy/tests/ui/large_futures.fixed @@ -0,0 +1,70 @@ +#![feature(generators)] +#![warn(clippy::large_futures)] +#![allow(clippy::never_loop)] +#![allow(clippy::future_not_send)] +#![allow(clippy::manual_async_fn)] + +async fn big_fut(_arg: [u8; 1024 * 16]) {} + +async fn wait() { + let f = async { + Box::pin(big_fut([0u8; 1024 * 16])).await; + //~^ ERROR: large future with a size of 16385 bytes + //~| NOTE: `-D clippy::large-futures` implied by `-D warnings` + }; + Box::pin(f).await + //~^ ERROR: large future with a size of 16386 bytes +} +async fn calls_fut(fut: impl std::future::Future) { + loop { + Box::pin(wait()).await; + //~^ ERROR: large future with a size of 16387 bytes + if true { + return fut.await; + } else { + Box::pin(wait()).await; + //~^ ERROR: large future with a size of 16387 bytes + } + } +} + +pub async fn test() { + let fut = big_fut([0u8; 1024 * 16]); + Box::pin(foo()).await; + //~^ ERROR: large future with a size of 65540 bytes + Box::pin(calls_fut(fut)).await; + //~^ ERROR: large future with a size of 49159 bytes +} + +pub fn foo() -> impl std::future::Future { + async { + let x = [0i32; 1024 * 16]; + async {}.await; + dbg!(x); + } +} + +pub async fn lines() { + Box::pin(async { + //~^ ERROR: large future with a size of 65540 bytes + let x = [0i32; 1024 * 16]; + async {}.await; + println!("{:?}", x); + }) + .await; +} + +pub async fn macro_expn() { + macro_rules! macro_ { + () => { + Box::pin(async { + let x = [0i32; 1024 * 16]; + async {}.await; + println!("macro: {:?}", x); + }) + }; + } + macro_!().await +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/large_futures.rs b/src/tools/clippy/tests/ui/large_futures.rs index e0f6b3d9d..557d89a9c 100644 --- a/src/tools/clippy/tests/ui/large_futures.rs +++ b/src/tools/clippy/tests/ui/large_futures.rs @@ -9,16 +9,21 @@ async fn big_fut(_arg: [u8; 1024 * 16]) {} async fn wait() { let f = async { big_fut([0u8; 1024 * 16]).await; + //~^ ERROR: large future with a size of 16385 bytes + //~| NOTE: `-D clippy::large-futures` implied by `-D warnings` }; f.await + //~^ ERROR: large future with a size of 16386 bytes } async fn calls_fut(fut: impl std::future::Future) { loop { wait().await; + //~^ ERROR: large future with a size of 16387 bytes if true { return fut.await; } else { wait().await; + //~^ ERROR: large future with a size of 16387 bytes } } } @@ -26,7 +31,9 @@ async fn calls_fut(fut: impl std::future::Future) { pub async fn test() { let fut = big_fut([0u8; 1024 * 16]); foo().await; + //~^ ERROR: large future with a size of 65540 bytes calls_fut(fut).await; + //~^ ERROR: large future with a size of 49159 bytes } pub fn foo() -> impl std::future::Future { @@ -39,6 +46,7 @@ pub fn foo() -> impl std::future::Future { pub async fn lines() { async { + //~^ ERROR: large future with a size of 65540 bytes let x = [0i32; 1024 * 16]; async {}.await; println!("{:?}", x); diff --git a/src/tools/clippy/tests/ui/large_futures.stderr b/src/tools/clippy/tests/ui/large_futures.stderr index 5bcf05488..861366daf 100644 --- a/src/tools/clippy/tests/ui/large_futures.stderr +++ b/src/tools/clippy/tests/ui/large_futures.stderr @@ -5,41 +5,43 @@ LL | big_fut([0u8; 1024 * 16]).await; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(big_fut([0u8; 1024 * 16]))` | = note: `-D clippy::large-futures` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_futures)]` error: large future with a size of 16386 bytes - --> $DIR/large_futures.rs:13:5 + --> $DIR/large_futures.rs:15:5 | LL | f.await | ^ help: consider `Box::pin` on it: `Box::pin(f)` error: large future with a size of 16387 bytes - --> $DIR/large_futures.rs:17:9 + --> $DIR/large_futures.rs:20:9 | LL | wait().await; | ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())` error: large future with a size of 16387 bytes - --> $DIR/large_futures.rs:21:13 + --> $DIR/large_futures.rs:25:13 | LL | wait().await; | ^^^^^^ help: consider `Box::pin` on it: `Box::pin(wait())` error: large future with a size of 65540 bytes - --> $DIR/large_futures.rs:28:5 + --> $DIR/large_futures.rs:33:5 | LL | foo().await; | ^^^^^ help: consider `Box::pin` on it: `Box::pin(foo())` error: large future with a size of 49159 bytes - --> $DIR/large_futures.rs:29:5 + --> $DIR/large_futures.rs:35:5 | LL | calls_fut(fut).await; | ^^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(calls_fut(fut))` error: large future with a size of 65540 bytes - --> $DIR/large_futures.rs:41:5 + --> $DIR/large_futures.rs:48:5 | LL | / async { +LL | | LL | | let x = [0i32; 1024 * 16]; LL | | async {}.await; LL | | println!("{:?}", x); @@ -49,6 +51,7 @@ LL | | } help: consider `Box::pin` on it | LL ~ Box::pin(async { +LL + LL + let x = [0i32; 1024 * 16]; LL + async {}.await; LL + println!("{:?}", x); @@ -56,7 +59,7 @@ LL + }) | error: large future with a size of 65540 bytes - --> $DIR/large_futures.rs:52:13 + --> $DIR/large_futures.rs:60:13 | LL | / async { LL | | let x = [0i32; 1024 * 16]; diff --git a/src/tools/clippy/tests/ui/large_stack_arrays.rs b/src/tools/clippy/tests/ui/large_stack_arrays.rs index 3e9d5e6a4..d5c4f95f8 100644 --- a/src/tools/clippy/tests/ui/large_stack_arrays.rs +++ b/src/tools/clippy/tests/ui/large_stack_arrays.rs @@ -27,17 +27,24 @@ fn issue_10741() { } let _x = [build(); 3]; + //~^ ERROR: allocating a local array larger than 512000 bytes let _y = [build(), build(), build()]; + //~^ ERROR: allocating a local array larger than 512000 bytes } fn main() { let bad = ( [0u32; 20_000_000], + //~^ ERROR: allocating a local array larger than 512000 bytes [S { data: [0; 32] }; 5000], + //~^ ERROR: allocating a local array larger than 512000 bytes [Some(""); 20_000_000], + //~^ ERROR: allocating a local array larger than 512000 bytes [E::T(0); 5000], + //~^ ERROR: allocating a local array larger than 512000 bytes [0u8; usize::MAX], + //~^ ERROR: allocating a local array larger than 512000 bytes ); let good = ( diff --git a/src/tools/clippy/tests/ui/large_stack_arrays.stderr b/src/tools/clippy/tests/ui/large_stack_arrays.stderr index 118d39566..0dfb6732b 100644 --- a/src/tools/clippy/tests/ui/large_stack_arrays.stderr +++ b/src/tools/clippy/tests/ui/large_stack_arrays.stderr @@ -6,9 +6,10 @@ LL | let _x = [build(); 3]; | = help: consider allocating on the heap with `vec![build(); 3].into_boxed_slice()` = note: `-D clippy::large-stack-arrays` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_stack_arrays)]` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:31:14 + --> $DIR/large_stack_arrays.rs:32:14 | LL | let _y = [build(), build(), build()]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | let _y = [build(), build(), build()]; = help: consider allocating on the heap with `vec![build(), build(), build()].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:36:9 + --> $DIR/large_stack_arrays.rs:38:9 | LL | [0u32; 20_000_000], | ^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | [0u32; 20_000_000], = help: consider allocating on the heap with `vec![0u32; 20_000_000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:37:9 + --> $DIR/large_stack_arrays.rs:40:9 | LL | [S { data: [0; 32] }; 5000], | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | [S { data: [0; 32] }; 5000], = help: consider allocating on the heap with `vec![S { data: [0; 32] }; 5000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:38:9 + --> $DIR/large_stack_arrays.rs:42:9 | LL | [Some(""); 20_000_000], | ^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | [Some(""); 20_000_000], = help: consider allocating on the heap with `vec![Some(""); 20_000_000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:39:9 + --> $DIR/large_stack_arrays.rs:44:9 | LL | [E::T(0); 5000], | ^^^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | [E::T(0); 5000], = help: consider allocating on the heap with `vec![E::T(0); 5000].into_boxed_slice()` error: allocating a local array larger than 512000 bytes - --> $DIR/large_stack_arrays.rs:40:9 + --> $DIR/large_stack_arrays.rs:46:9 | LL | [0u8; usize::MAX], | ^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/large_stack_frames.rs b/src/tools/clippy/tests/ui/large_stack_frames.rs index cd9d0c8a6..f32368f93 100644 --- a/src/tools/clippy/tests/ui/large_stack_frames.rs +++ b/src/tools/clippy/tests/ui/large_stack_frames.rs @@ -23,6 +23,8 @@ impl Default for ArrayDefault { } fn many_small_arrays() { + //~^ ERROR: this function allocates a large amount of stack space + //~| NOTE: allocating large amounts of stack space can overflow the stack let x = [0u8; 500_000]; let x2 = [0u8; 500_000]; let x3 = [0u8; 500_000]; @@ -32,10 +34,14 @@ fn many_small_arrays() { } fn large_return_value() -> ArrayDefault<1_000_000> { + //~^ ERROR: this function allocates a large amount of stack space + //~| NOTE: allocating large amounts of stack space can overflow the stack Default::default() } fn large_fn_arg(x: ArrayDefault<1_000_000>) { + //~^ ERROR: this function allocates a large amount of stack space + //~| NOTE: allocating large amounts of stack space can overflow the stack black_box(&x); } diff --git a/src/tools/clippy/tests/ui/large_stack_frames.stderr b/src/tools/clippy/tests/ui/large_stack_frames.stderr index d57df8596..12a458db8 100644 --- a/src/tools/clippy/tests/ui/large_stack_frames.stderr +++ b/src/tools/clippy/tests/ui/large_stack_frames.stderr @@ -2,9 +2,9 @@ error: this function allocates a large amount of stack space --> $DIR/large_stack_frames.rs:25:1 | LL | / fn many_small_arrays() { +LL | | +LL | | LL | | let x = [0u8; 500_000]; -LL | | let x2 = [0u8; 500_000]; -LL | | let x3 = [0u8; 500_000]; ... | LL | | black_box((&x, &x2, &x3, &x4, &x5)); LL | | } @@ -12,11 +12,14 @@ LL | | } | = note: allocating large amounts of stack space can overflow the stack = note: `-D clippy::large-stack-frames` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_stack_frames)]` error: this function allocates a large amount of stack space - --> $DIR/large_stack_frames.rs:34:1 + --> $DIR/large_stack_frames.rs:36:1 | LL | / fn large_return_value() -> ArrayDefault<1_000_000> { +LL | | +LL | | LL | | Default::default() LL | | } | |_^ @@ -24,9 +27,11 @@ LL | | } = note: allocating large amounts of stack space can overflow the stack error: this function allocates a large amount of stack space - --> $DIR/large_stack_frames.rs:38:1 + --> $DIR/large_stack_frames.rs:42:1 | LL | / fn large_fn_arg(x: ArrayDefault<1_000_000>) { +LL | | +LL | | LL | | black_box(&x); LL | | } | |_^ diff --git a/src/tools/clippy/tests/ui/large_types_passed_by_value.rs b/src/tools/clippy/tests/ui/large_types_passed_by_value.rs index f9e3c7192..78994a298 100644 --- a/src/tools/clippy/tests/ui/large_types_passed_by_value.rs +++ b/src/tools/clippy/tests/ui/large_types_passed_by_value.rs @@ -1,6 +1,6 @@ //@normalize-stderr-test: "\(\d+ byte\)" -> "(N byte)" //@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)" - +//@no-rustfix #![warn(clippy::large_types_passed_by_value)] pub struct Large([u8; 2048]); diff --git a/src/tools/clippy/tests/ui/large_types_passed_by_value.stderr b/src/tools/clippy/tests/ui/large_types_passed_by_value.stderr index 5f42dcfb9..b3f102cc4 100644 --- a/src/tools/clippy/tests/ui/large_types_passed_by_value.stderr +++ b/src/tools/clippy/tests/ui/large_types_passed_by_value.stderr @@ -5,6 +5,7 @@ LL | fn bad(a: LargeAndCopy) {} | ^^^^^^^^^^^^ help: consider passing by reference instead: `&LargeAndCopy` | = note: `-D clippy::large-types-passed-by-value` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_types_passed_by_value)]` 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:25:37 diff --git a/src/tools/clippy/tests/ui/len_without_is_empty.rs b/src/tools/clippy/tests/ui/len_without_is_empty.rs index 52aabefae..d62360111 100644 --- a/src/tools/clippy/tests/ui/len_without_is_empty.rs +++ b/src/tools/clippy/tests/ui/len_without_is_empty.rs @@ -5,6 +5,8 @@ pub struct PubOne; impl PubOne { pub fn len(&self) -> isize { + //~^ ERROR: struct `PubOne` has a public `len` method, but no `is_empty` method + //~| NOTE: `-D clippy::len-without-is-empty` implied by `-D warnings` 1 } } @@ -53,6 +55,7 @@ impl PubAllowedStruct { } pub trait PubTraitsToo { + //~^ ERROR: trait `PubTraitsToo` has a `len` method but no (possibly inherited) `is_empty` fn len(&self) -> isize; } @@ -66,6 +69,7 @@ pub struct HasIsEmpty; impl HasIsEmpty { pub fn len(&self) -> isize { + //~^ ERROR: struct `HasIsEmpty` has a public `len` method, but a private `is_empty` me 1 } @@ -78,6 +82,7 @@ pub struct HasWrongIsEmpty; impl HasWrongIsEmpty { pub fn len(&self) -> isize { + //~^ ERROR: struct `HasWrongIsEmpty` has a public `len` method, but the `is_empty` met 1 } @@ -90,6 +95,7 @@ pub struct MismatchedSelf; impl MismatchedSelf { pub fn len(self) -> isize { + //~^ ERROR: struct `MismatchedSelf` has a public `len` method, but the `is_empty` meth 1 } @@ -169,6 +175,7 @@ pub trait InheritingEmpty: Empty { pub trait Foo: Sized {} pub trait DependsOnFoo: Foo { + //~^ ERROR: trait `DependsOnFoo` has a `len` method but no (possibly inherited) `is_empty` fn len(&mut self) -> usize; } @@ -214,6 +221,7 @@ impl OptionalLen2 { pub struct OptionalLen3; impl OptionalLen3 { pub fn len(&self) -> usize { + //~^ ERROR: struct `OptionalLen3` has a public `len` method, but the `is_empty` method 0 } @@ -226,6 +234,8 @@ impl OptionalLen3 { pub struct ResultLen; impl ResultLen { pub fn len(&self) -> Result { + //~^ ERROR: struct `ResultLen` has a public `len` method, but the `is_empty` method ha + //~| ERROR: this returns a `Result<_, ()>` Ok(0) } @@ -238,10 +248,12 @@ impl ResultLen { pub struct ResultLen2; impl ResultLen2 { pub fn len(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Ok(0) } pub fn is_empty(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Ok(true) } } @@ -249,6 +261,7 @@ impl ResultLen2 { pub struct ResultLen3; impl ResultLen3 { pub fn len(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Ok(0) } @@ -290,6 +303,7 @@ impl AsyncLenWithoutIsEmpty { } pub async fn len(&self) -> usize { + //~^ ERROR: struct `AsyncLenWithoutIsEmpty` has a public `len` method, but no `is_empt usize::from(!self.async_task().await) } } @@ -302,6 +316,7 @@ impl AsyncOptionLenWithoutIsEmpty { } pub async fn len(&self) -> Option { + //~^ ERROR: struct `AsyncOptionLenWithoutIsEmpty` has a public `len` method, but no `i None } } @@ -323,6 +338,7 @@ impl AsyncResultLenWithoutIsEmpty { } pub async fn len(&self) -> Result { + //~^ ERROR: struct `AsyncResultLenWithoutIsEmpty` has a public `len` method, but no `i Err(()) } } @@ -420,4 +436,27 @@ impl DifferingErrors { } } +// Issue #11165 +pub struct Aliased1; +pub type Alias1 = Aliased1; + +impl Alias1 { + pub fn len(&self) -> usize { + todo!() + } + + pub fn is_empty(&self) -> bool { + todo!() + } +} + +pub struct Aliased2; +pub type Alias2 = Aliased2; +impl Alias2 { + pub fn len(&self) -> usize { + //~^ ERROR: type `Alias2` has a public `len` method, but no `is_empty` method + todo!() + } +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/len_without_is_empty.stderr b/src/tools/clippy/tests/ui/len_without_is_empty.stderr index 1bce1734b..8e51c28b3 100644 --- a/src/tools/clippy/tests/ui/len_without_is_empty.stderr +++ b/src/tools/clippy/tests/ui/len_without_is_empty.stderr @@ -5,98 +5,102 @@ LL | pub fn len(&self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::len-without-is-empty` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::len_without_is_empty)]` error: trait `PubTraitsToo` has a `len` method but no (possibly inherited) `is_empty` method - --> $DIR/len_without_is_empty.rs:55:1 + --> $DIR/len_without_is_empty.rs:57:1 | LL | / pub trait PubTraitsToo { +LL | | LL | | fn len(&self) -> isize; LL | | } | |_^ error: struct `HasIsEmpty` has a public `len` method, but a private `is_empty` method - --> $DIR/len_without_is_empty.rs:68:5 + --> $DIR/len_without_is_empty.rs:71:5 | LL | pub fn len(&self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:72:5 + --> $DIR/len_without_is_empty.rs:76:5 | LL | fn is_empty(&self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `HasWrongIsEmpty` has a public `len` method, but the `is_empty` method has an unexpected signature - --> $DIR/len_without_is_empty.rs:80:5 + --> $DIR/len_without_is_empty.rs:84:5 | LL | pub fn len(&self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:84:5 + --> $DIR/len_without_is_empty.rs:89:5 | LL | pub fn is_empty(&self, x: u32) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature: `(&self) -> bool` error: struct `MismatchedSelf` has a public `len` method, but the `is_empty` method has an unexpected signature - --> $DIR/len_without_is_empty.rs:92:5 + --> $DIR/len_without_is_empty.rs:97:5 | LL | pub fn len(self) -> isize { | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:96:5 + --> $DIR/len_without_is_empty.rs:102:5 | LL | pub fn is_empty(&self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature: `(self) -> bool` error: trait `DependsOnFoo` has a `len` method but no (possibly inherited) `is_empty` method - --> $DIR/len_without_is_empty.rs:171:1 + --> $DIR/len_without_is_empty.rs:177:1 | LL | / pub trait DependsOnFoo: Foo { +LL | | LL | | fn len(&mut self) -> usize; LL | | } | |_^ error: struct `OptionalLen3` has a public `len` method, but the `is_empty` method has an unexpected signature - --> $DIR/len_without_is_empty.rs:216:5 + --> $DIR/len_without_is_empty.rs:223:5 | LL | pub fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:221:5 + --> $DIR/len_without_is_empty.rs:229:5 | LL | pub fn is_empty(&self) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature: `(&self) -> bool` error: struct `ResultLen` has a public `len` method, but the `is_empty` method has an unexpected signature - --> $DIR/len_without_is_empty.rs:228:5 + --> $DIR/len_without_is_empty.rs:236:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: `is_empty` defined here - --> $DIR/len_without_is_empty.rs:233:5 + --> $DIR/len_without_is_empty.rs:243:5 | LL | pub fn is_empty(&self) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: expected signature: `(&self) -> bool` or `(&self) -> Result error: this returns a `Result<_, ()>` - --> $DIR/len_without_is_empty.rs:228:5 + --> $DIR/len_without_is_empty.rs:236:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use a custom `Error` type instead = note: `-D clippy::result-unit-err` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_unit_err)]` error: this returns a `Result<_, ()>` - --> $DIR/len_without_is_empty.rs:240:5 + --> $DIR/len_without_is_empty.rs:250:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +108,7 @@ LL | pub fn len(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/len_without_is_empty.rs:244:5 + --> $DIR/len_without_is_empty.rs:255:5 | LL | pub fn is_empty(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +116,7 @@ LL | pub fn is_empty(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/len_without_is_empty.rs:251:5 + --> $DIR/len_without_is_empty.rs:263:5 | LL | pub fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,22 +124,28 @@ LL | pub fn len(&self) -> Result { = help: use a custom `Error` type instead error: struct `AsyncLenWithoutIsEmpty` has a public `len` method, but no `is_empty` method - --> $DIR/len_without_is_empty.rs:292:5 + --> $DIR/len_without_is_empty.rs:305:5 | LL | pub async fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `AsyncOptionLenWithoutIsEmpty` has a public `len` method, but no `is_empty` method - --> $DIR/len_without_is_empty.rs:304:5 + --> $DIR/len_without_is_empty.rs:318:5 | LL | pub async fn len(&self) -> Option { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: struct `AsyncResultLenWithoutIsEmpty` has a public `len` method, but no `is_empty` method - --> $DIR/len_without_is_empty.rs:325:5 + --> $DIR/len_without_is_empty.rs:340:5 | LL | pub async fn len(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 15 previous errors +error: type `Alias2` has a public `len` method, but no `is_empty` method + --> $DIR/len_without_is_empty.rs:456:5 + | +LL | pub fn len(&self) -> usize { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 16 previous errors diff --git a/src/tools/clippy/tests/ui/len_zero.fixed b/src/tools/clippy/tests/ui/len_zero.fixed index fafee6a0d..745fc7e1a 100644 --- a/src/tools/clippy/tests/ui/len_zero.fixed +++ b/src/tools/clippy/tests/ui/len_zero.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::len_zero)] #![allow(dead_code, unused, clippy::needless_if, clippy::len_without_is_empty)] diff --git a/src/tools/clippy/tests/ui/len_zero.rs b/src/tools/clippy/tests/ui/len_zero.rs index 6a9006c47..048ad2f4f 100644 --- a/src/tools/clippy/tests/ui/len_zero.rs +++ b/src/tools/clippy/tests/ui/len_zero.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::len_zero)] #![allow(dead_code, unused, clippy::needless_if, clippy::len_without_is_empty)] diff --git a/src/tools/clippy/tests/ui/len_zero.stderr b/src/tools/clippy/tests/ui/len_zero.stderr index 396cfb75f..e1f243441 100644 --- a/src/tools/clippy/tests/ui/len_zero.stderr +++ b/src/tools/clippy/tests/ui/len_zero.stderr @@ -1,141 +1,143 @@ error: length comparison to zero - --> $DIR/len_zero.rs:84:8 + --> $DIR/len_zero.rs:82:8 | LL | if x.len() == 0 { | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `x.is_empty()` | = note: `-D clippy::len-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::len_zero)]` error: length comparison to zero - --> $DIR/len_zero.rs:88:8 + --> $DIR/len_zero.rs:86: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:97:20 + --> $DIR/len_zero.rs:95:20 | LL | println!("{}", *s1 == ""); | ^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s1.is_empty()` | = note: `-D clippy::comparison-to-empty` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::comparison_to_empty)]` error: comparison to empty slice - --> $DIR/len_zero.rs:98:20 + --> $DIR/len_zero.rs:96: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:99:20 + --> $DIR/len_zero.rs:97: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:100:20 + --> $DIR/len_zero.rs:98: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:101:20 + --> $DIR/len_zero.rs:99: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:102:20 + --> $DIR/len_zero.rs:100: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:105:20 + --> $DIR/len_zero.rs:103: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:120:8 + --> $DIR/len_zero.rs:118: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:123:8 + --> $DIR/len_zero.rs:121: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:126: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 one - --> $DIR/len_zero.rs:129:8 + --> $DIR/len_zero.rs:127: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:132:8 + --> $DIR/len_zero.rs:130: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:143:8 + --> $DIR/len_zero.rs:141: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:146:8 + --> $DIR/len_zero.rs:144: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:149:8 + --> $DIR/len_zero.rs:147: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:152:8 + --> $DIR/len_zero.rs:150: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:155:8 + --> $DIR/len_zero.rs:153: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:169:8 + --> $DIR/len_zero.rs:167: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:181:6 + --> $DIR/len_zero.rs:179: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:182:6 + --> $DIR/len_zero.rs:180: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:186:8 + --> $DIR/len_zero.rs:184:8 | LL | if b.len() != 0 {} | ^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!b.is_empty()` diff --git a/src/tools/clippy/tests/ui/len_zero_ranges.fixed b/src/tools/clippy/tests/ui/len_zero_ranges.fixed index 4b1241ec8..1fdeb2c7a 100644 --- a/src/tools/clippy/tests/ui/len_zero_ranges.fixed +++ b/src/tools/clippy/tests/ui/len_zero_ranges.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::len_zero)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/len_zero_ranges.rs b/src/tools/clippy/tests/ui/len_zero_ranges.rs index 4b47132c7..a5c9a969a 100644 --- a/src/tools/clippy/tests/ui/len_zero_ranges.rs +++ b/src/tools/clippy/tests/ui/len_zero_ranges.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::len_zero)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/len_zero_ranges.stderr b/src/tools/clippy/tests/ui/len_zero_ranges.stderr index d0defb5a7..1922e9b30 100644 --- a/src/tools/clippy/tests/ui/len_zero_ranges.stderr +++ b/src/tools/clippy/tests/ui/len_zero_ranges.stderr @@ -1,13 +1,14 @@ error: length comparison to zero - --> $DIR/len_zero_ranges.rs:9:17 + --> $DIR/len_zero_ranges.rs:7:17 | LL | let _ = (0..42).len() == 0; | ^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(0..42).is_empty()` | = note: `-D clippy::len-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::len_zero)]` error: length comparison to zero - --> $DIR/len_zero_ranges.rs:13:17 + --> $DIR/len_zero_ranges.rs:11:17 | LL | let _ = (0_u8..=42).len() == 0; | ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(0_u8..=42).is_empty()` diff --git a/src/tools/clippy/tests/ui/let_and_return.fixed b/src/tools/clippy/tests/ui/let_and_return.fixed new file mode 100644 index 000000000..88b8ae673 --- /dev/null +++ b/src/tools/clippy/tests/ui/let_and_return.fixed @@ -0,0 +1,187 @@ +#![allow(unused)] +#![warn(clippy::let_and_return)] + +use std::cell::RefCell; + +fn test() -> i32 { + let _y = 0; // no warning + + 5 + //~^ ERROR: returning the result of a `let` binding from a block + //~| NOTE: `-D clippy::let-and-return` implied by `-D warnings` +} + +fn test_inner() -> i32 { + if true { + + 5 + //~^ ERROR: returning the result of a `let` binding from a block + } else { + 0 + } +} + +fn test_nowarn_1() -> i32 { + let mut x = 5; + x += 1; + x +} + +fn test_nowarn_2() -> i32 { + let x = 5; + x + 1 +} + +fn test_nowarn_3() -> (i32, i32) { + // this should technically warn, but we do not compare complex patterns + let (x, y) = (5, 9); + (x, y) +} + +fn test_nowarn_4() -> i32 { + // this should technically warn, but not b/c of clippy::let_and_return, but b/c of useless type + let x: i32 = 5; + x +} + +fn test_nowarn_5(x: i16) -> u16 { + #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] + let x = x as u16; + x +} + +// False positive example +trait Decode { + fn decode(d: D) -> Result + where + Self: Sized; +} + +macro_rules! tuple_encode { + ($($x:ident),*) => ( + impl<$($x: Decode),*> Decode for ($($x),*) { + #[inline] + #[allow(non_snake_case)] + fn decode(mut d: D) -> Result { + // Shouldn't trigger lint + Ok(($({let $x = Decode::decode(&mut d)?; $x }),*)) + } + } + ); +} + +fn issue_3792() -> String { + use std::io::{self, BufRead, Stdin}; + + let stdin = io::stdin(); + // `Stdin::lock` returns `StdinLock<'static>` so `line` doesn't borrow from `stdin` + // https://github.com/rust-lang/rust/pull/93965 + + stdin.lock().lines().next().unwrap().unwrap() + //~^ ERROR: returning the result of a `let` binding from a block +} + +tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); + +mod no_lint_if_stmt_borrows { + use std::cell::RefCell; + use std::rc::{Rc, Weak}; + struct Bar; + + impl Bar { + fn new() -> Self { + Bar {} + } + fn baz(&self) -> u32 { + 0 + } + } + + fn issue_3324(value: Weak>) -> u32 { + let value = value.upgrade().unwrap(); + let ret = value.borrow().baz(); + ret + } + + fn borrows_in_closure(value: Weak>) -> u32 { + fn f(mut x: impl FnMut() -> u32) -> impl FnMut() -> u32 { + x + } + + let value = value.upgrade().unwrap(); + let ret = f(|| value.borrow().baz())(); + ret + } + + mod free_function { + struct Inner; + + struct Foo<'a> { + inner: &'a Inner, + } + + impl Drop for Foo<'_> { + fn drop(&mut self) {} + } + + impl<'a> Foo<'a> { + fn new(inner: &'a Inner) -> Self { + Self { inner } + } + + fn value(&self) -> i32 { + 42 + } + } + + fn some_foo(inner: &Inner) -> Foo<'_> { + Foo { inner } + } + + fn test() -> i32 { + let x = Inner {}; + let value = some_foo(&x).value(); + value + } + + fn test2() -> i32 { + let x = Inner {}; + let value = Foo::new(&x).value(); + value + } + } +} + +mod issue_5729 { + use std::sync::Arc; + + trait Foo {} + + trait FooStorage { + fn foo_cloned(&self) -> Arc; + } + + struct FooStorageImpl { + foo: Arc, + } + + impl FooStorage for FooStorageImpl { + fn foo_cloned(&self) -> Arc { + + Arc::clone(&self.foo) as _ + //~^ ERROR: returning the result of a `let` binding from a block + } + } +} + +// https://github.com/rust-lang/rust-clippy/issues/11167 +macro_rules! fn_in_macro { + ($b:block) => { + fn f() -> usize $b + } +} +fn_in_macro!({ + return 1; +}); + +fn main() {} diff --git a/src/tools/clippy/tests/ui/let_and_return.rs b/src/tools/clippy/tests/ui/let_and_return.rs index 64665cc90..f366842c5 100644 --- a/src/tools/clippy/tests/ui/let_and_return.rs +++ b/src/tools/clippy/tests/ui/let_and_return.rs @@ -7,12 +7,15 @@ fn test() -> i32 { let _y = 0; // no warning let x = 5; x + //~^ ERROR: returning the result of a `let` binding from a block + //~| NOTE: `-D clippy::let-and-return` implied by `-D warnings` } fn test_inner() -> i32 { if true { let x = 5; x + //~^ ERROR: returning the result of a `let` binding from a block } else { 0 } @@ -75,6 +78,7 @@ fn issue_3792() -> String { // https://github.com/rust-lang/rust/pull/93965 let line = stdin.lock().lines().next().unwrap().unwrap(); line + //~^ ERROR: returning the result of a `let` binding from a block } tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); @@ -165,6 +169,7 @@ mod issue_5729 { fn foo_cloned(&self) -> Arc { let clone = Arc::clone(&self.foo); clone + //~^ ERROR: returning the result of a `let` binding from a block } } } diff --git a/src/tools/clippy/tests/ui/let_and_return.stderr b/src/tools/clippy/tests/ui/let_and_return.stderr index 4ca0a05c8..c09c2b32a 100644 --- a/src/tools/clippy/tests/ui/let_and_return.stderr +++ b/src/tools/clippy/tests/ui/let_and_return.stderr @@ -7,6 +7,7 @@ LL | x | ^ | = note: `-D clippy::let-and-return` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_and_return)]` help: return the expression directly | LL ~ @@ -14,7 +15,7 @@ LL ~ 5 | error: returning the result of a `let` binding from a block - --> $DIR/let_and_return.rs:15:9 + --> $DIR/let_and_return.rs:17:9 | LL | let x = 5; | ---------- unnecessary `let` binding @@ -28,7 +29,7 @@ LL ~ 5 | error: returning the result of a `let` binding from a block - --> $DIR/let_and_return.rs:77:5 + --> $DIR/let_and_return.rs:80:5 | LL | let line = stdin.lock().lines().next().unwrap().unwrap(); | --------------------------------------------------------- unnecessary `let` binding @@ -42,7 +43,7 @@ LL ~ stdin.lock().lines().next().unwrap().unwrap() | error: returning the result of a `let` binding from a block - --> $DIR/let_and_return.rs:167:13 + --> $DIR/let_and_return.rs:171:13 | LL | let clone = Arc::clone(&self.foo); | ---------------------------------- unnecessary `let` binding diff --git a/src/tools/clippy/tests/ui/let_if_seq.rs b/src/tools/clippy/tests/ui/let_if_seq.rs index 959567f68..9869d9452 100644 --- a/src/tools/clippy/tests/ui/let_if_seq.rs +++ b/src/tools/clippy/tests/ui/let_if_seq.rs @@ -7,7 +7,7 @@ clippy::needless_late_init )] #![warn(clippy::useless_let_if_seq)] - +//@no-rustfix fn f() -> bool { true } @@ -64,11 +64,15 @@ fn main() { issue985_alt(); let mut foo = 0; + //~^ ERROR: `if _ { .. } else { .. }` is an expression + //~| NOTE: you might not need `mut` at all if f() { foo = 42; } let mut bar = 0; + //~^ ERROR: `if _ { .. } else { .. }` is an expression + //~| NOTE: you might not need `mut` at all if f() { f(); bar = 42; @@ -77,6 +81,7 @@ fn main() { } let quz; + //~^ ERROR: `if _ { .. } else { .. }` is an expression if f() { quz = 42; } else { @@ -106,6 +111,8 @@ fn main() { // baz needs to be mut let mut baz = 0; + //~^ ERROR: `if _ { .. } else { .. }` is an expression + //~| NOTE: you might not need `mut` at all if f() { baz = 42; } diff --git a/src/tools/clippy/tests/ui/let_if_seq.stderr b/src/tools/clippy/tests/ui/let_if_seq.stderr index f2e0edb6f..bfb4bb9d0 100644 --- a/src/tools/clippy/tests/ui/let_if_seq.stderr +++ b/src/tools/clippy/tests/ui/let_if_seq.stderr @@ -2,6 +2,8 @@ error: `if _ { .. } else { .. }` is an expression --> $DIR/let_if_seq.rs:66:5 | LL | / let mut foo = 0; +LL | | +LL | | LL | | if f() { LL | | foo = 42; LL | | } @@ -9,15 +11,16 @@ LL | | } | = note: you might not need `mut` at all = note: `-D clippy::useless-let-if-seq` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::useless_let_if_seq)]` error: `if _ { .. } else { .. }` is an expression - --> $DIR/let_if_seq.rs:71:5 + --> $DIR/let_if_seq.rs:73:5 | LL | / let mut bar = 0; +LL | | +LL | | LL | | if f() { -LL | | f(); -LL | | bar = 42; -LL | | } else { +... | LL | | f(); LL | | } | |_____^ help: it is more idiomatic to write: `let bar = if f() { ..; 42 } else { ..; 0 };` @@ -25,9 +28,10 @@ LL | | } = note: you might not need `mut` at all error: `if _ { .. } else { .. }` is an expression - --> $DIR/let_if_seq.rs:79:5 + --> $DIR/let_if_seq.rs:83:5 | LL | / let quz; +LL | | LL | | if f() { LL | | quz = 42; LL | | } else { @@ -36,9 +40,11 @@ LL | | } | |_____^ help: it is more idiomatic to write: `let quz = if f() { 42 } else { 0 };` error: `if _ { .. } else { .. }` is an expression - --> $DIR/let_if_seq.rs:108:5 + --> $DIR/let_if_seq.rs:113:5 | LL | / let mut baz = 0; +LL | | +LL | | LL | | if f() { LL | | baz = 42; LL | | } diff --git a/src/tools/clippy/tests/ui/let_underscore_future.rs b/src/tools/clippy/tests/ui/let_underscore_future.rs index d8f54cdca..c2185e978 100644 --- a/src/tools/clippy/tests/ui/let_underscore_future.rs +++ b/src/tools/clippy/tests/ui/let_underscore_future.rs @@ -1,5 +1,5 @@ use std::future::Future; - +//@no-rustfix async fn some_async_fn() {} fn sync_side_effects() {} @@ -12,9 +12,12 @@ fn do_something_to_future(future: &mut impl Future) {} fn main() { let _ = some_async_fn(); + //~^ ERROR: non-binding `let` on a future let _ = custom(); + //~^ ERROR: non-binding `let` on a future let mut future = some_async_fn(); do_something_to_future(&mut future); let _ = future; + //~^ ERROR: non-binding `let` on a future } diff --git a/src/tools/clippy/tests/ui/let_underscore_future.stderr b/src/tools/clippy/tests/ui/let_underscore_future.stderr index 33a748736..ef927a808 100644 --- a/src/tools/clippy/tests/ui/let_underscore_future.stderr +++ b/src/tools/clippy/tests/ui/let_underscore_future.stderr @@ -6,9 +6,10 @@ LL | let _ = some_async_fn(); | = help: consider awaiting the future or dropping explicitly with `std::mem::drop` = note: `-D clippy::let-underscore-future` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_underscore_future)]` error: non-binding `let` on a future - --> $DIR/let_underscore_future.rs:15:5 + --> $DIR/let_underscore_future.rs:16:5 | LL | let _ = custom(); | ^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | let _ = custom(); = help: consider awaiting the future or dropping explicitly with `std::mem::drop` error: non-binding `let` on a future - --> $DIR/let_underscore_future.rs:19:5 + --> $DIR/let_underscore_future.rs:21:5 | LL | let _ = future; | ^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/let_underscore_lock.rs b/src/tools/clippy/tests/ui/let_underscore_lock.rs index 87f12e278..ccac73be7 100644 --- a/src/tools/clippy/tests/ui/let_underscore_lock.rs +++ b/src/tools/clippy/tests/ui/let_underscore_lock.rs @@ -8,13 +8,17 @@ fn main() { let p_m: Mutex<()> = Mutex::const_new(RawMutex::INIT, ()); let _ = p_m.lock(); + //~^ ERROR: non-binding `let` on a synchronization lock let p_m1 = Mutex::new(0); let _ = p_m1.lock(); + //~^ ERROR: non-binding `let` on a synchronization lock let p_rw = RwLock::new(0); let _ = p_rw.read(); + //~^ ERROR: non-binding `let` on a synchronization lock let _ = p_rw.write(); + //~^ ERROR: non-binding `let` on a synchronization lock // These shouldn't throw an error. let _ = p_m; diff --git a/src/tools/clippy/tests/ui/let_underscore_lock.stderr b/src/tools/clippy/tests/ui/let_underscore_lock.stderr index 5027e6b3c..ac6e0978e 100644 --- a/src/tools/clippy/tests/ui/let_underscore_lock.stderr +++ b/src/tools/clippy/tests/ui/let_underscore_lock.stderr @@ -6,9 +6,10 @@ LL | let _ = p_m.lock(); | = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` = note: `-D clippy::let-underscore-lock` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_underscore_lock)]` error: non-binding `let` on a synchronization lock - --> $DIR/let_underscore_lock.rs:13:5 + --> $DIR/let_underscore_lock.rs:14:5 | LL | let _ = p_m1.lock(); | ^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | let _ = p_m1.lock(); = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` error: non-binding `let` on a synchronization lock - --> $DIR/let_underscore_lock.rs:16:5 + --> $DIR/let_underscore_lock.rs:18:5 | LL | let _ = p_rw.read(); | ^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | let _ = p_rw.read(); = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop` error: non-binding `let` on a synchronization lock - --> $DIR/let_underscore_lock.rs:17:5 + --> $DIR/let_underscore_lock.rs:20:5 | LL | let _ = p_rw.write(); | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/let_underscore_must_use.rs b/src/tools/clippy/tests/ui/let_underscore_must_use.rs index 1edb77c74..3290d0877 100644 --- a/src/tools/clippy/tests/ui/let_underscore_must_use.rs +++ b/src/tools/clippy/tests/ui/let_underscore_must_use.rs @@ -65,30 +65,42 @@ impl Trait for S { fn main() { let _ = f(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = g(); + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let _ = h(); let _ = l(0_u32); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let s = S {}; let _ = s.f(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = s.g(); + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let _ = s.k(); let _ = S::h(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = S::p(); + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let _ = S::a(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = if true { Ok(()) } else { Err(()) }; + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let a = Result::<(), ()>::Ok(()); let _ = a.is_ok(); + //~^ ERROR: non-binding `let` on a result of a `#[must_use]` function let _ = a.map(|_| ()); + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type let _ = a; + //~^ ERROR: non-binding `let` on an expression with `#[must_use]` type #[allow(clippy::let_underscore_must_use)] let _ = a; diff --git a/src/tools/clippy/tests/ui/let_underscore_must_use.stderr b/src/tools/clippy/tests/ui/let_underscore_must_use.stderr index 28d760eb4..83d0372e6 100644 --- a/src/tools/clippy/tests/ui/let_underscore_must_use.stderr +++ b/src/tools/clippy/tests/ui/let_underscore_must_use.stderr @@ -6,9 +6,10 @@ LL | let _ = f(); | = help: consider explicitly using function result = note: `-D clippy::let-underscore-must-use` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_underscore_must_use)]` error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:68:5 + --> $DIR/let_underscore_must_use.rs:69:5 | LL | let _ = g(); | ^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | let _ = g(); = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:70:5 + --> $DIR/let_underscore_must_use.rs:72:5 | LL | let _ = l(0_u32); | ^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | let _ = l(0_u32); = help: consider explicitly using function result error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:74:5 + --> $DIR/let_underscore_must_use.rs:77:5 | LL | let _ = s.f(); | ^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | let _ = s.f(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:75:5 + --> $DIR/let_underscore_must_use.rs:79:5 | LL | let _ = s.g(); | ^^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | let _ = s.g(); = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:78:5 + --> $DIR/let_underscore_must_use.rs:83:5 | LL | let _ = S::h(); | ^^^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | let _ = S::h(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:79:5 + --> $DIR/let_underscore_must_use.rs:85:5 | LL | let _ = S::p(); | ^^^^^^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | let _ = S::p(); = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:81:5 + --> $DIR/let_underscore_must_use.rs:88:5 | LL | let _ = S::a(); | ^^^^^^^^^^^^^^^ @@ -64,7 +65,7 @@ LL | let _ = S::a(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:83:5 + --> $DIR/let_underscore_must_use.rs:91:5 | LL | let _ = if true { Ok(()) } else { Err(()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL | let _ = if true { Ok(()) } else { Err(()) }; = help: consider explicitly using expression value error: non-binding `let` on a result of a `#[must_use]` function - --> $DIR/let_underscore_must_use.rs:87:5 + --> $DIR/let_underscore_must_use.rs:96:5 | LL | let _ = a.is_ok(); | ^^^^^^^^^^^^^^^^^^ @@ -80,7 +81,7 @@ LL | let _ = a.is_ok(); = help: consider explicitly using function result error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:89:5 + --> $DIR/let_underscore_must_use.rs:99:5 | LL | let _ = a.map(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +89,7 @@ LL | let _ = a.map(|_| ()); = help: consider explicitly using expression value error: non-binding `let` on an expression with `#[must_use]` type - --> $DIR/let_underscore_must_use.rs:91:5 + --> $DIR/let_underscore_must_use.rs:102:5 | LL | let _ = a; | ^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/let_underscore_untyped.rs b/src/tools/clippy/tests/ui/let_underscore_untyped.rs index 18630c27f..bd94a3ada 100644 --- a/src/tools/clippy/tests/ui/let_underscore_untyped.rs +++ b/src/tools/clippy/tests/ui/let_underscore_untyped.rs @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![allow(unused)] #![warn(clippy::let_underscore_untyped)] diff --git a/src/tools/clippy/tests/ui/let_underscore_untyped.stderr b/src/tools/clippy/tests/ui/let_underscore_untyped.stderr index e0c39b6ee..0e5647fa1 100644 --- a/src/tools/clippy/tests/ui/let_underscore_untyped.stderr +++ b/src/tools/clippy/tests/ui/let_underscore_untyped.stderr @@ -10,6 +10,7 @@ help: consider adding a type annotation LL | let _ = a(); | ^ = note: `-D clippy::let-underscore-untyped` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_underscore_untyped)]` error: non-binding `let` without a type annotation --> $DIR/let_underscore_untyped.rs:52:5 diff --git a/src/tools/clippy/tests/ui/let_unit.fixed b/src/tools/clippy/tests/ui/let_unit.fixed index 8ba89ec78..f98ce9d50 100644 --- a/src/tools/clippy/tests/ui/let_unit.fixed +++ b/src/tools/clippy/tests/ui/let_unit.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(lint_reasons)] #![warn(clippy::let_unit_value)] #![allow(unused, clippy::no_effect, clippy::needless_late_init, path_statements)] @@ -179,3 +177,5 @@ fn attributes() { async fn issue10433() { let _pending: () = std::future::pending().await; } + +pub async fn issue11502(a: ()) {} diff --git a/src/tools/clippy/tests/ui/let_unit.rs b/src/tools/clippy/tests/ui/let_unit.rs index 7e8764a48..6d942ca89 100644 --- a/src/tools/clippy/tests/ui/let_unit.rs +++ b/src/tools/clippy/tests/ui/let_unit.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(lint_reasons)] #![warn(clippy::let_unit_value)] #![allow(unused, clippy::no_effect, clippy::needless_late_init, path_statements)] @@ -179,3 +177,5 @@ fn attributes() { async fn issue10433() { let _pending: () = std::future::pending().await; } + +pub async fn issue11502(a: ()) {} diff --git a/src/tools/clippy/tests/ui/let_unit.stderr b/src/tools/clippy/tests/ui/let_unit.stderr index 49da74ca7..de106f50e 100644 --- a/src/tools/clippy/tests/ui/let_unit.stderr +++ b/src/tools/clippy/tests/ui/let_unit.stderr @@ -1,19 +1,20 @@ error: this let-binding has unit value - --> $DIR/let_unit.rs:14:5 + --> $DIR/let_unit.rs:12:5 | LL | let _x = println!("x"); | ^^^^^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `println!("x");` | = note: `-D clippy::let-unit-value` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_unit_value)]` error: this let-binding has unit value - --> $DIR/let_unit.rs:18:9 + --> $DIR/let_unit.rs:16:9 | LL | let _a = (); | ^^^^^^^^^^^^ help: omit the `let` binding: `();` error: this let-binding has unit value - --> $DIR/let_unit.rs:53:5 + --> $DIR/let_unit.rs:51:5 | LL | / let _ = v LL | | .into_iter() @@ -36,7 +37,7 @@ LL + .unwrap(); | error: this let-binding has unit value - --> $DIR/let_unit.rs:80:5 + --> $DIR/let_unit.rs:78:5 | LL | let x: () = f(); // Lint. | ^^^^-^^^^^^^^^^^ @@ -44,7 +45,7 @@ LL | let x: () = f(); // Lint. | help: use a wild (`_`) binding: `_` error: this let-binding has unit value - --> $DIR/let_unit.rs:83:5 + --> $DIR/let_unit.rs:81:5 | LL | let x: () = f2(0i32); // Lint. | ^^^^-^^^^^^^^^^^^^^^^ @@ -52,19 +53,19 @@ LL | let x: () = f2(0i32); // Lint. | help: use a wild (`_`) binding: `_` error: this let-binding has unit value - --> $DIR/let_unit.rs:85:5 + --> $DIR/let_unit.rs:83:5 | LL | let _: () = f3(()); // Lint | ^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `f3(());` error: this let-binding has unit value - --> $DIR/let_unit.rs:86:5 + --> $DIR/let_unit.rs:84:5 | LL | let x: () = f3(()); // Lint | ^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `f3(());` error: this let-binding has unit value - --> $DIR/let_unit.rs:102:5 + --> $DIR/let_unit.rs:100:5 | LL | let x: () = if true { f() } else { f2(0) }; // Lint | ^^^^-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL | let x: () = if true { f() } else { f2(0) }; // Lint | help: use a wild (`_`) binding: `_` error: this let-binding has unit value - --> $DIR/let_unit.rs:113:5 + --> $DIR/let_unit.rs:111:5 | LL | / let _: () = match Some(0) { LL | | None => f2(1), @@ -93,7 +94,7 @@ LL + }; | error: this let-binding has unit value - --> $DIR/let_unit.rs:160:13 + --> $DIR/let_unit.rs:158:13 | LL | let _: () = z; | ^^^^^^^^^^^^^^ help: omit the `let` binding: `z;` diff --git a/src/tools/clippy/tests/ui/let_with_type_underscore.rs b/src/tools/clippy/tests/ui/let_with_type_underscore.rs index 8214176cf..ae1a480bc 100644 --- a/src/tools/clippy/tests/ui/let_with_type_underscore.rs +++ b/src/tools/clippy/tests/ui/let_with_type_underscore.rs @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![allow(unused)] #![warn(clippy::let_with_type_underscore)] #![allow(clippy::let_unit_value, clippy::needless_late_init)] diff --git a/src/tools/clippy/tests/ui/let_with_type_underscore.stderr b/src/tools/clippy/tests/ui/let_with_type_underscore.stderr index a749552c7..d4c9ba19c 100644 --- a/src/tools/clippy/tests/ui/let_with_type_underscore.stderr +++ b/src/tools/clippy/tests/ui/let_with_type_underscore.stderr @@ -10,6 +10,7 @@ help: remove the explicit type `_` declaration LL | let x: _ = 1; | ^^^ = note: `-D clippy::let-with-type-underscore` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::let_with_type_underscore)]` error: variable declared with type underscore --> $DIR/let_with_type_underscore.rs:16:5 diff --git a/src/tools/clippy/tests/ui/lines_filter_map_ok.fixed b/src/tools/clippy/tests/ui/lines_filter_map_ok.fixed index 64114f658..74ef6f729 100644 --- a/src/tools/clippy/tests/ui/lines_filter_map_ok.fixed +++ b/src/tools/clippy/tests/ui/lines_filter_map_ok.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::map_identity)] #![warn(clippy::lines_filter_map_ok)] diff --git a/src/tools/clippy/tests/ui/lines_filter_map_ok.rs b/src/tools/clippy/tests/ui/lines_filter_map_ok.rs index 5aedc6863..345f4dc5f 100644 --- a/src/tools/clippy/tests/ui/lines_filter_map_ok.rs +++ b/src/tools/clippy/tests/ui/lines_filter_map_ok.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::map_identity)] #![warn(clippy::lines_filter_map_ok)] diff --git a/src/tools/clippy/tests/ui/lines_filter_map_ok.stderr b/src/tools/clippy/tests/ui/lines_filter_map_ok.stderr index cddd403d5..fa2ba0a9a 100644 --- a/src/tools/clippy/tests/ui/lines_filter_map_ok.stderr +++ b/src/tools/clippy/tests/ui/lines_filter_map_ok.stderr @@ -1,48 +1,49 @@ error: `filter_map()` will run forever if the iterator repeatedly produces an `Err` - --> $DIR/lines_filter_map_ok.rs:11:31 + --> $DIR/lines_filter_map_ok.rs:9:31 | LL | BufReader::new(f).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:11:5 + --> $DIR/lines_filter_map_ok.rs:9:5 | LL | BufReader::new(f).lines().filter_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::lines-filter-map-ok` implied by `-D warnings` + = 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:14:31 + --> $DIR/lines_filter_map_ok.rs:12: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:14:5 + --> $DIR/lines_filter_map_ok.rs:12:5 | LL | BufReader::new(f).lines().flat_map(Result::ok).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `filter_map()` will run forever if the iterator repeatedly produces an `Err` - --> $DIR/lines_filter_map_ok.rs:17:25 + --> $DIR/lines_filter_map_ok.rs:15: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:17:5 + --> $DIR/lines_filter_map_ok.rs:15: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:19:25 + --> $DIR/lines_filter_map_ok.rs:17: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:19:5 + --> $DIR/lines_filter_map_ok.rs:17:5 | LL | io::stdin().lines().filter_map(|x| x.ok()).for_each(|_| ()); | ^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/linkedlist.rs b/src/tools/clippy/tests/ui/linkedlist.rs index 690ea810a..e1e6cff98 100644 --- a/src/tools/clippy/tests/ui/linkedlist.rs +++ b/src/tools/clippy/tests/ui/linkedlist.rs @@ -6,12 +6,17 @@ extern crate alloc; use alloc::collections::linked_list::LinkedList; const C: LinkedList = LinkedList::new(); +//~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data structu static S: LinkedList = LinkedList::new(); +//~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data structu trait Foo { type Baz = LinkedList; + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str fn foo(_: LinkedList); + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str const BAR: Option>; + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str } // Ok, we don’t want to warn for implementations; see issue #605. @@ -22,16 +27,20 @@ impl Foo for LinkedList { pub struct Bar { priv_linked_list_field: LinkedList, + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str pub pub_linked_list_field: LinkedList, } impl Bar { fn foo(_: LinkedList) {} + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data str } // All of these test should be trigger the lint because they are not // part of the public api fn test(my_favorite_linked_list: LinkedList) {} +//~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data structu fn test_ret() -> Option> { + //~^ ERROR: you seem to be using a `LinkedList`! Perhaps you meant some other data structu None } fn test_local_not_linted() { diff --git a/src/tools/clippy/tests/ui/linkedlist.stderr b/src/tools/clippy/tests/ui/linkedlist.stderr index c76c94961..792af4dd0 100644 --- a/src/tools/clippy/tests/ui/linkedlist.stderr +++ b/src/tools/clippy/tests/ui/linkedlist.stderr @@ -6,9 +6,10 @@ LL | const C: LinkedList = LinkedList::new(); | = help: a `VecDeque` might work = note: `-D clippy::linkedlist` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::linkedlist)]` error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:9:11 + --> $DIR/linkedlist.rs:10:11 | LL | static S: LinkedList = LinkedList::new(); | ^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | static S: LinkedList = LinkedList::new(); = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:12:16 + --> $DIR/linkedlist.rs:14:16 | LL | type Baz = LinkedList; | ^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | type Baz = LinkedList; = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:13:15 + --> $DIR/linkedlist.rs:16:15 | LL | fn foo(_: LinkedList); | ^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | fn foo(_: LinkedList); = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:14:23 + --> $DIR/linkedlist.rs:18:23 | LL | const BAR: Option>; | ^^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | const BAR: Option>; = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:24:29 + --> $DIR/linkedlist.rs:29:29 | LL | priv_linked_list_field: LinkedList, | ^^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | priv_linked_list_field: LinkedList, = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:28:15 + --> $DIR/linkedlist.rs:34:15 | LL | fn foo(_: LinkedList) {} | ^^^^^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | fn foo(_: LinkedList) {} = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:33:34 + --> $DIR/linkedlist.rs:40:34 | LL | fn test(my_favorite_linked_list: LinkedList) {} | ^^^^^^^^^^^^^^ @@ -64,7 +65,7 @@ LL | fn test(my_favorite_linked_list: LinkedList) {} = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:34:25 + --> $DIR/linkedlist.rs:42:25 | LL | fn test_ret() -> Option> { | ^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/literals.rs b/src/tools/clippy/tests/ui/literals.rs index 1a646e49c..c275b04d8 100644 --- a/src/tools/clippy/tests/ui/literals.rs +++ b/src/tools/clippy/tests/ui/literals.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions // does not test any rustfixable lints #![warn(clippy::mixed_case_hex_literals)] @@ -10,16 +11,32 @@ fn main() { let ok1 = 0xABCD; let ok3 = 0xab_cd; let ok4 = 0xab_cd_i32; + //~^ ERROR: integer type suffix should not be separated by an underscore + //~| NOTE: `-D clippy::separated-literal-suffix` implied by `-D warnings` let ok5 = 0xAB_CD_u32; + //~^ ERROR: integer type suffix should not be separated by an underscore let ok5 = 0xAB_CD_isize; + //~^ ERROR: integer type suffix should not be separated by an underscore let fail1 = 0xabCD; + //~^ ERROR: inconsistent casing in hexadecimal literal + //~| NOTE: `-D clippy::mixed-case-hex-literals` implied by `-D warnings` let fail2 = 0xabCD_u32; + //~^ ERROR: integer type suffix should not be separated by an underscore + //~| ERROR: inconsistent casing in hexadecimal literal let fail2 = 0xabCD_isize; + //~^ ERROR: integer type suffix should not be separated by an underscore + //~| ERROR: inconsistent casing in hexadecimal literal let fail_multi_zero = 000_123usize; + //~^ ERROR: integer type suffix should be separated by an underscore + //~| NOTE: `-D clippy::unseparated-literal-suffix` implied by `-D warnings` + //~| ERROR: this is a decimal constant + //~| NOTE: `-D clippy::zero-prefixed-literal` implied by `-D warnings` let ok9 = 0; let ok10 = 0_i64; + //~^ ERROR: integer type suffix should not be separated by an underscore let fail8 = 0123; + //~^ ERROR: this is a decimal constant let ok11 = 0o123; let ok12 = 0b10_1010; @@ -29,13 +46,20 @@ fn main() { let ok15 = 0xab_cabc_abca_bcab_cabc; let ok16 = 0xFE_BAFE_ABAB_ABCD; let ok17 = 0x123_4567_8901_usize; + //~^ ERROR: integer type suffix should not be separated by an underscore let ok18 = 0xF; let fail19 = 12_3456_21; + //~^ ERROR: digits grouped inconsistently by underscores + //~| NOTE: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` let fail22 = 3__4___23; + //~^ ERROR: digits grouped inconsistently by underscores let fail23 = 3__16___23; + //~^ ERROR: digits grouped inconsistently by underscores let fail24 = 0xAB_ABC_AB; + //~^ ERROR: digits of hex, binary or octal literal not in groups of equal size + //~| NOTE: `-D clippy::unusual-byte-groupings` implied by `-D warnings` let fail25 = 0b01_100_101; let ok26 = 0x6_A0_BF; let ok27 = 0b1_0010_0101; @@ -44,6 +68,9 @@ fn main() { fn issue9651() { // lint but octal form is not possible here let _ = 08; + //~^ ERROR: this is a decimal constant let _ = 09; + //~^ ERROR: this is a decimal constant let _ = 089; + //~^ ERROR: this is a decimal constant } diff --git a/src/tools/clippy/tests/ui/literals.stderr b/src/tools/clippy/tests/ui/literals.stderr index 9bc7948c7..bc755b112 100644 --- a/src/tools/clippy/tests/ui/literals.stderr +++ b/src/tools/clippy/tests/ui/literals.stderr @@ -1,70 +1,74 @@ error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:12:15 + --> $DIR/literals.rs:13:15 | LL | let ok4 = 0xab_cd_i32; | ^^^^^^^^^^^ help: remove the underscore: `0xab_cdi32` | = note: `-D clippy::separated-literal-suffix` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::separated_literal_suffix)]` error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:13:15 + --> $DIR/literals.rs:16:15 | LL | let ok5 = 0xAB_CD_u32; | ^^^^^^^^^^^ help: remove the underscore: `0xAB_CDu32` error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:14:15 + --> $DIR/literals.rs:18:15 | LL | let ok5 = 0xAB_CD_isize; | ^^^^^^^^^^^^^ help: remove the underscore: `0xAB_CDisize` error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:15:17 + --> $DIR/literals.rs:20:17 | LL | let fail1 = 0xabCD; | ^^^^^^ | = note: `-D clippy::mixed-case-hex-literals` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mixed_case_hex_literals)]` error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:16:17 + --> $DIR/literals.rs:23:17 | LL | let fail2 = 0xabCD_u32; | ^^^^^^^^^^ help: remove the underscore: `0xabCDu32` error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:16:17 + --> $DIR/literals.rs:23:17 | LL | let fail2 = 0xabCD_u32; | ^^^^^^^^^^ error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:17:17 + --> $DIR/literals.rs:26:17 | LL | let fail2 = 0xabCD_isize; | ^^^^^^^^^^^^ help: remove the underscore: `0xabCDisize` error: inconsistent casing in hexadecimal literal - --> $DIR/literals.rs:17:17 + --> $DIR/literals.rs:26:17 | LL | let fail2 = 0xabCD_isize; | ^^^^^^^^^^^^ error: integer type suffix should be separated by an underscore - --> $DIR/literals.rs:18:27 + --> $DIR/literals.rs:29:27 | LL | let fail_multi_zero = 000_123usize; | ^^^^^^^^^^^^ help: add an underscore: `000_123_usize` | = note: `-D clippy::unseparated-literal-suffix` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unseparated_literal_suffix)]` error: this is a decimal constant - --> $DIR/literals.rs:18:27 + --> $DIR/literals.rs:29:27 | LL | let fail_multi_zero = 000_123usize; | ^^^^^^^^^^^^ | = note: `-D clippy::zero-prefixed-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::zero_prefixed_literal)]` help: if you mean to use a decimal constant, remove the `0` to avoid confusion | LL | let fail_multi_zero = 123usize; @@ -75,13 +79,13 @@ LL | let fail_multi_zero = 0o123usize; | ~~~~~~~~~~ error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:21:16 + --> $DIR/literals.rs:36:16 | LL | let ok10 = 0_i64; | ^^^^^ help: remove the underscore: `0i64` error: this is a decimal constant - --> $DIR/literals.rs:22:17 + --> $DIR/literals.rs:38:17 | LL | let fail8 = 0123; | ^^^^ @@ -96,41 +100,43 @@ LL | let fail8 = 0o123; | ~~~~~ error: integer type suffix should not be separated by an underscore - --> $DIR/literals.rs:31:16 + --> $DIR/literals.rs:48:16 | LL | let ok17 = 0x123_4567_8901_usize; | ^^^^^^^^^^^^^^^^^^^^^ help: remove the underscore: `0x123_4567_8901usize` error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:34:18 + --> $DIR/literals.rs:52:18 | LL | let fail19 = 12_3456_21; | ^^^^^^^^^^ help: consider: `12_345_621` | = note: `-D clippy::inconsistent-digit-grouping` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::inconsistent_digit_grouping)]` error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:35:18 + --> $DIR/literals.rs:55:18 | LL | let fail22 = 3__4___23; | ^^^^^^^^^ help: consider: `3_423` error: digits grouped inconsistently by underscores - --> $DIR/literals.rs:36:18 + --> $DIR/literals.rs:57:18 | LL | let fail23 = 3__16___23; | ^^^^^^^^^^ help: consider: `31_623` error: digits of hex, binary or octal literal not in groups of equal size - --> $DIR/literals.rs:38:18 + --> $DIR/literals.rs:60:18 | LL | let fail24 = 0xAB_ABC_AB; | ^^^^^^^^^^^ help: consider: `0x0ABA_BCAB` | = note: `-D clippy::unusual-byte-groupings` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unusual_byte_groupings)]` error: this is a decimal constant - --> $DIR/literals.rs:46:13 + --> $DIR/literals.rs:70:13 | LL | let _ = 08; | ^^ @@ -141,7 +147,7 @@ LL | let _ = 8; | ~ error: this is a decimal constant - --> $DIR/literals.rs:47:13 + --> $DIR/literals.rs:72:13 | LL | let _ = 09; | ^^ @@ -152,7 +158,7 @@ LL | let _ = 9; | ~ error: this is a decimal constant - --> $DIR/literals.rs:48:13 + --> $DIR/literals.rs:74:13 | LL | let _ = 089; | ^^^ diff --git a/src/tools/clippy/tests/ui/lossy_float_literal.fixed b/src/tools/clippy/tests/ui/lossy_float_literal.fixed index e19f4980c..92a0084a6 100644 --- a/src/tools/clippy/tests/ui/lossy_float_literal.fixed +++ b/src/tools/clippy/tests/ui/lossy_float_literal.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::lossy_float_literal)] #![allow(overflowing_literals, unused)] diff --git a/src/tools/clippy/tests/ui/lossy_float_literal.rs b/src/tools/clippy/tests/ui/lossy_float_literal.rs index a2a1cfb31..5abef3c44 100644 --- a/src/tools/clippy/tests/ui/lossy_float_literal.rs +++ b/src/tools/clippy/tests/ui/lossy_float_literal.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::lossy_float_literal)] #![allow(overflowing_literals, unused)] diff --git a/src/tools/clippy/tests/ui/lossy_float_literal.stderr b/src/tools/clippy/tests/ui/lossy_float_literal.stderr index 2d72b1643..ea787f572 100644 --- a/src/tools/clippy/tests/ui/lossy_float_literal.stderr +++ b/src/tools/clippy/tests/ui/lossy_float_literal.stderr @@ -1,67 +1,68 @@ error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:7:18 + --> $DIR/lossy_float_literal.rs:6:18 | LL | let _: f32 = 16_777_217.0; | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_216.0` | = note: `-D clippy::lossy-float-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::lossy_float_literal)]` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:8:18 + --> $DIR/lossy_float_literal.rs:7:18 | LL | let _: f32 = 16_777_219.0; | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:9:18 + --> $DIR/lossy_float_literal.rs:8:18 | LL | let _: f32 = 16_777_219.; | ^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:10:18 + --> $DIR/lossy_float_literal.rs:9:18 | LL | let _: f32 = 16_777_219.000; | ^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:11:13 + --> $DIR/lossy_float_literal.rs:10:13 | LL | let _ = 16_777_219f32; | ^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220_f32` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:12:19 + --> $DIR/lossy_float_literal.rs:11:19 | LL | let _: f32 = -16_777_219.0; | ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_220.0` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:13:18 + --> $DIR/lossy_float_literal.rs:12:18 | LL | let _: f64 = 9_007_199_254_740_993.0; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:14:18 + --> $DIR/lossy_float_literal.rs:13:18 | LL | let _: f64 = 9_007_199_254_740_993.; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:15:18 + --> $DIR/lossy_float_literal.rs:14:18 | LL | let _: f64 = 9_007_199_254_740_993.00; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:16:13 + --> $DIR/lossy_float_literal.rs:15:13 | LL | let _ = 9_007_199_254_740_993f64; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992_f64` error: literal cannot be represented as the underlying type without loss of precision - --> $DIR/lossy_float_literal.rs:17:19 + --> $DIR/lossy_float_literal.rs:16:19 | LL | let _: f64 = -9_007_199_254_740_993.0; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or replacing it with: `9_007_199_254_740_992.0` diff --git a/src/tools/clippy/tests/ui/macro_use_imports.fixed b/src/tools/clippy/tests/ui/macro_use_imports.fixed index 53b6a0250..46c053b77 100644 --- a/src/tools/clippy/tests/ui/macro_use_imports.fixed +++ b/src/tools/clippy/tests/ui/macro_use_imports.fixed @@ -1,7 +1,7 @@ //@aux-build:macro_rules.rs //@aux-build:macro_use_helper.rs -//@aux-build:proc_macro_derive.rs:proc-macro -//@run-rustfix +//@aux-build:proc_macro_derive.rs + //@ignore-32bit #![feature(lint_reasons)] diff --git a/src/tools/clippy/tests/ui/macro_use_imports.rs b/src/tools/clippy/tests/ui/macro_use_imports.rs index a40fa3898..47f5c9bf8 100644 --- a/src/tools/clippy/tests/ui/macro_use_imports.rs +++ b/src/tools/clippy/tests/ui/macro_use_imports.rs @@ -1,7 +1,7 @@ //@aux-build:macro_rules.rs //@aux-build:macro_use_helper.rs -//@aux-build:proc_macro_derive.rs:proc-macro -//@run-rustfix +//@aux-build:proc_macro_derive.rs + //@ignore-32bit #![feature(lint_reasons)] diff --git a/src/tools/clippy/tests/ui/macro_use_imports.stderr b/src/tools/clippy/tests/ui/macro_use_imports.stderr index 67a833e85..6de869699 100644 --- a/src/tools/clippy/tests/ui/macro_use_imports.stderr +++ b/src/tools/clippy/tests/ui/macro_use_imports.stderr @@ -1,10 +1,11 @@ error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:19:5 + --> $DIR/macro_use_imports.rs:25:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` | = note: `-D clippy::macro-use-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::macro_use_imports)]` error: `macro_use` attributes are no longer needed in the Rust 2018 edition --> $DIR/macro_use_imports.rs:23:5 @@ -13,16 +14,16 @@ LL | #[macro_use] | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::mut_mut, inner::try_err};` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:25:5 + --> $DIR/macro_use_imports.rs:21:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;` error: `macro_use` attributes are no longer needed in the Rust 2018 edition - --> $DIR/macro_use_imports.rs:21:5 + --> $DIR/macro_use_imports.rs:19:5 | LL | #[macro_use] - | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;` + | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};` error: aborting due to 4 previous errors diff --git a/src/tools/clippy/tests/ui/macro_use_imports_expect.rs b/src/tools/clippy/tests/ui/macro_use_imports_expect.rs index 3971aadbe..b9677851b 100644 --- a/src/tools/clippy/tests/ui/macro_use_imports_expect.rs +++ b/src/tools/clippy/tests/ui/macro_use_imports_expect.rs @@ -1,6 +1,6 @@ //@aux-build:macro_rules.rs //@aux-build:macro_use_helper.rs -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs //@ignore-32bit #![feature(lint_reasons)] diff --git a/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed b/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed index d8dde0236..75beedfa4 100644 --- a/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed +++ b/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed @@ -1,7 +1,6 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix #![warn(clippy::manual_assert)] #![allow(dead_code, unused_doc_comments)] diff --git a/src/tools/clippy/tests/ui/manual_assert.edition2018.stderr b/src/tools/clippy/tests/ui/manual_assert.edition2018.stderr index 3555ac292..b19cca4d5 100644 --- a/src/tools/clippy/tests/ui/manual_assert.edition2018.stderr +++ b/src/tools/clippy/tests/ui/manual_assert.edition2018.stderr @@ -1,5 +1,5 @@ error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:31:5 + --> $DIR/manual_assert.rs:30:5 | LL | / if !a.is_empty() { LL | | panic!("qaqaq{:?}", a); @@ -7,9 +7,10 @@ LL | | } | |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);` | = note: `-D clippy::manual-assert` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_assert)]` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:34:5 + --> $DIR/manual_assert.rs:33:5 | LL | / if !a.is_empty() { LL | | panic!("qwqwq"); @@ -17,7 +18,7 @@ LL | | } | |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:51:5 + --> $DIR/manual_assert.rs:50:5 | LL | / if b.is_empty() { LL | | panic!("panic1"); @@ -25,7 +26,7 @@ LL | | } | |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:54:5 + --> $DIR/manual_assert.rs:53:5 | LL | / if b.is_empty() && a.is_empty() { LL | | panic!("panic2"); @@ -33,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:57:5 + --> $DIR/manual_assert.rs:56:5 | LL | / if a.is_empty() && !b.is_empty() { LL | | panic!("panic3"); @@ -41,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:60:5 + --> $DIR/manual_assert.rs:59:5 | LL | / if b.is_empty() || a.is_empty() { LL | | panic!("panic4"); @@ -49,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:63:5 + --> $DIR/manual_assert.rs:62:5 | LL | / if a.is_empty() || !b.is_empty() { LL | | panic!("panic5"); @@ -57,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:66:5 + --> $DIR/manual_assert.rs:65:5 | LL | / if a.is_empty() { LL | | panic!("with expansion {}", one!()) @@ -65,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:78:5 + --> $DIR/manual_assert.rs:77:5 | LL | / if a > 2 { LL | | // comment diff --git a/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed b/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed index d8dde0236..75beedfa4 100644 --- a/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed +++ b/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed @@ -1,7 +1,6 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix #![warn(clippy::manual_assert)] #![allow(dead_code, unused_doc_comments)] diff --git a/src/tools/clippy/tests/ui/manual_assert.edition2021.stderr b/src/tools/clippy/tests/ui/manual_assert.edition2021.stderr index 3555ac292..b19cca4d5 100644 --- a/src/tools/clippy/tests/ui/manual_assert.edition2021.stderr +++ b/src/tools/clippy/tests/ui/manual_assert.edition2021.stderr @@ -1,5 +1,5 @@ error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:31:5 + --> $DIR/manual_assert.rs:30:5 | LL | / if !a.is_empty() { LL | | panic!("qaqaq{:?}", a); @@ -7,9 +7,10 @@ LL | | } | |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);` | = note: `-D clippy::manual-assert` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_assert)]` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:34:5 + --> $DIR/manual_assert.rs:33:5 | LL | / if !a.is_empty() { LL | | panic!("qwqwq"); @@ -17,7 +18,7 @@ LL | | } | |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:51:5 + --> $DIR/manual_assert.rs:50:5 | LL | / if b.is_empty() { LL | | panic!("panic1"); @@ -25,7 +26,7 @@ LL | | } | |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");` error: only a `panic!` in `if`-then statement - --> $DIR/manual_assert.rs:54:5 + --> $DIR/manual_assert.rs:53:5 | LL | / if b.is_empty() && a.is_empty() { LL | | panic!("panic2"); @@ -33,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:57:5 + --> $DIR/manual_assert.rs:56:5 | LL | / if a.is_empty() && !b.is_empty() { LL | | panic!("panic3"); @@ -41,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:60:5 + --> $DIR/manual_assert.rs:59:5 | LL | / if b.is_empty() || a.is_empty() { LL | | panic!("panic4"); @@ -49,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:63:5 + --> $DIR/manual_assert.rs:62:5 | LL | / if a.is_empty() || !b.is_empty() { LL | | panic!("panic5"); @@ -57,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:66:5 + --> $DIR/manual_assert.rs:65:5 | LL | / if a.is_empty() { LL | | panic!("with expansion {}", one!()) @@ -65,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:78:5 + --> $DIR/manual_assert.rs:77:5 | LL | / if a > 2 { LL | | // comment diff --git a/src/tools/clippy/tests/ui/manual_assert.rs b/src/tools/clippy/tests/ui/manual_assert.rs index 0f87d6e2d..5979496ca 100644 --- a/src/tools/clippy/tests/ui/manual_assert.rs +++ b/src/tools/clippy/tests/ui/manual_assert.rs @@ -1,7 +1,6 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix #![warn(clippy::manual_assert)] #![allow(dead_code, unused_doc_comments)] diff --git a/src/tools/clippy/tests/ui/manual_async_fn.fixed b/src/tools/clippy/tests/ui/manual_async_fn.fixed index e609b4b1b..18444090a 100644 --- a/src/tools/clippy/tests/ui/manual_async_fn.fixed +++ b/src/tools/clippy/tests/ui/manual_async_fn.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_async_fn)] #![allow(clippy::needless_pub_self, unused)] diff --git a/src/tools/clippy/tests/ui/manual_async_fn.rs b/src/tools/clippy/tests/ui/manual_async_fn.rs index 6c1a9edaa..d42165bbe 100644 --- a/src/tools/clippy/tests/ui/manual_async_fn.rs +++ b/src/tools/clippy/tests/ui/manual_async_fn.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_async_fn)] #![allow(clippy::needless_pub_self, unused)] diff --git a/src/tools/clippy/tests/ui/manual_async_fn.stderr b/src/tools/clippy/tests/ui/manual_async_fn.stderr index f5ee3eb7c..c0c471912 100644 --- a/src/tools/clippy/tests/ui/manual_async_fn.stderr +++ b/src/tools/clippy/tests/ui/manual_async_fn.stderr @@ -1,10 +1,11 @@ error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:7:1 + --> $DIR/manual_async_fn.rs:6:1 | LL | fn fut() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::manual-async-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_async_fn)]` help: make the function `async` and return the output of the future directly | LL | async fn fut() -> i32 { @@ -15,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:12:1 + --> $DIR/manual_async_fn.rs:11:1 | LL | fn fut2() ->impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,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:17:1 + --> $DIR/manual_async_fn.rs:16:1 | LL | fn fut3()-> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,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:21:1 + --> $DIR/manual_async_fn.rs:20:1 | LL | fn empty_fut() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,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:26:1 + --> $DIR/manual_async_fn.rs:25:1 | LL | fn empty_fut2() ->impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -75,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:31:1 + --> $DIR/manual_async_fn.rs:30:1 | LL | fn empty_fut3()-> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -90,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:35:1 + --> $DIR/manual_async_fn.rs:34:1 | LL | fn core_fut() -> impl core::future::Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -105,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:57:5 + --> $DIR/manual_async_fn.rs:56:5 | LL | fn inh_fut() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +133,7 @@ LL + } | error: this function can be simplified using the `async fn` syntax - --> $DIR/manual_async_fn.rs:92:1 + --> $DIR/manual_async_fn.rs:91:1 | LL | fn elided(_: &i32) -> impl Future + '_ { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -147,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:101:1 + --> $DIR/manual_async_fn.rs:100:1 | LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future + 'a + 'b { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -162,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:130:1 + --> $DIR/manual_async_fn.rs:129:1 | LL | pub fn issue_10450() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -177,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:134:1 + --> $DIR/manual_async_fn.rs:133:1 | LL | pub(crate) fn issue_10450_2() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -192,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:138:1 + --> $DIR/manual_async_fn.rs:137:1 | LL | pub(self) fn issue_10450_3() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/manual_bits.fixed b/src/tools/clippy/tests/ui/manual_bits.fixed index 037de0262..4de01905e 100644 --- a/src/tools/clippy/tests/ui/manual_bits.fixed +++ b/src/tools/clippy/tests/ui/manual_bits.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_bits)] #![allow( clippy::no_effect, diff --git a/src/tools/clippy/tests/ui/manual_bits.rs b/src/tools/clippy/tests/ui/manual_bits.rs index b15a531ec..d4f369fcf 100644 --- a/src/tools/clippy/tests/ui/manual_bits.rs +++ b/src/tools/clippy/tests/ui/manual_bits.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_bits)] #![allow( clippy::no_effect, diff --git a/src/tools/clippy/tests/ui/manual_bits.stderr b/src/tools/clippy/tests/ui/manual_bits.stderr index 652fafbc4..2f2ed5909 100644 --- a/src/tools/clippy/tests/ui/manual_bits.stderr +++ b/src/tools/clippy/tests/ui/manual_bits.stderr @@ -1,175 +1,176 @@ error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:16:5 + --> $DIR/manual_bits.rs:14:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `i8::BITS as usize` | = note: `-D clippy::manual-bits` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_bits)]` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:17:5 + --> $DIR/manual_bits.rs:15:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i16::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:18:5 + --> $DIR/manual_bits.rs:16:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i32::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:19:5 + --> $DIR/manual_bits.rs:17:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i64::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:20:5 + --> $DIR/manual_bits.rs:18:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `i128::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:21:5 + --> $DIR/manual_bits.rs:19:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `isize::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:23:5 + --> $DIR/manual_bits.rs:21:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `u8::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:24:5 + --> $DIR/manual_bits.rs:22:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u16::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:25:5 + --> $DIR/manual_bits.rs:23:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u32::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:26:5 + --> $DIR/manual_bits.rs:24:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u64::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:27:5 + --> $DIR/manual_bits.rs:25:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^^ 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:28:5 + --> $DIR/manual_bits.rs:26:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `usize::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:30:5 + --> $DIR/manual_bits.rs:28:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `i8::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:31:5 + --> $DIR/manual_bits.rs:29:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i16::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:32:5 + --> $DIR/manual_bits.rs:30:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i32::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:33:5 + --> $DIR/manual_bits.rs:31:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i64::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:34:5 + --> $DIR/manual_bits.rs:32:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `i128::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:35:5 + --> $DIR/manual_bits.rs:33:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `isize::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:37:5 + --> $DIR/manual_bits.rs:35:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `u8::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:38:5 + --> $DIR/manual_bits.rs:36:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u16::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:39:5 + --> $DIR/manual_bits.rs:37:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u32::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:40:5 + --> $DIR/manual_bits.rs:38:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u64::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:41:5 + --> $DIR/manual_bits.rs:39:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^^ 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:42:5 + --> $DIR/manual_bits.rs:40:5 | LL | 8 * size_of::(); | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `usize::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:52:5 + --> $DIR/manual_bits.rs:50:5 | LL | size_of::() * 8; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `Word::BITS as usize` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:56:18 + --> $DIR/manual_bits.rs:54:18 | LL | let _: u32 = (size_of::() * 8) as u32; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u128::BITS` error: usage of `mem::size_of::()` to obtain the size of `T` in bits - --> $DIR/manual_bits.rs:57:18 + --> $DIR/manual_bits.rs:55:18 | 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:58:13 + --> $DIR/manual_bits.rs:56: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:59:14 + --> $DIR/manual_bits.rs:57:14 | LL | let _ = &(size_of::() * 8); | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(u128::BITS as usize)` diff --git a/src/tools/clippy/tests/ui/manual_clamp.fixed b/src/tools/clippy/tests/ui/manual_clamp.fixed new file mode 100644 index 000000000..c5355cce8 --- /dev/null +++ b/src/tools/clippy/tests/ui/manual_clamp.fixed @@ -0,0 +1,296 @@ +#![warn(clippy::manual_clamp)] +#![allow( + unused, + dead_code, + clippy::unnecessary_operation, + clippy::no_effect, + clippy::if_same_then_else +)] + +use std::cmp::{max as cmp_max, min as cmp_min}; + +const CONST_MAX: i32 = 10; +const CONST_MIN: i32 = 4; + +const CONST_F64_MAX: f64 = 10.0; +const CONST_F64_MIN: f64 = 4.0; + +fn main() { + let (input, min, max) = (0, -2, 3); + // Lint + let x0 = input.clamp(min, max); + + let x1 = input.clamp(min, max); + + let x2 = input.clamp(min, max); + + let x3 = input.clamp(min, max); + + let x4 = input.clamp(min, max); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min + + let x5 = input.clamp(min, max); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min + + let x6 = input.clamp(min, max); + + let x7 = input.clamp(min, max); + + let x8 = input.clamp(min, max); + + let mut x9 = input; + x9 = x9.clamp(min, max); + + let x10 = input.clamp(min, max); + + let mut x11 = input; + let _ = 1; + x11 = x11.clamp(min, max); + + let mut x12 = input; + x12 = x12.clamp(min, max); + + let mut x13 = input; + x13 = x13.clamp(min, max); + + let x14 = input.clamp(CONST_MIN, CONST_MAX); + { + let (input, min, max) = (0.0f64, -2.0, 3.0); + let x15 = input.clamp(min, max); + } + { + let input: i32 = cmp_min_max(1); + // These can only be detected if exactly one of the arguments to the inner function is const. + let x16 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min + let x17 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min + let x18 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min + let x19 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min + let x20 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min + let x21 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min + let x22 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min + let x23 = input.clamp(CONST_MIN, CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min + let input: f64 = cmp_min_max(1) as f64; + let x24 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() + let x25 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() + let x26 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() + let x27 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() + let x28 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() + let x29 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() + let x30 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() + let x31 = input.clamp(CONST_F64_MIN, CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() + } + let mut x32 = input; + x32 = x32.clamp(min, max); + + // It's important this be the last set of statements + let mut x33 = input; + x33 = x33.clamp(min, max); +} + +// This code intentionally nonsense. +fn no_lint() { + let (input, min, max) = (0, -2, 3); + let x0 = if max < input { + max + } else if min > input { + max + } else { + min + }; + + let x1 = if input > max { + max + } else if input > min { + min + } else { + max + }; + + let x2 = if max < min { + min + } else if input > max { + input + } else { + input + }; + + let x3 = if min > input { + input + } else if max < input { + max + } else { + max + }; + + let x6 = match input { + x if x < max => x, + x if x < min => x, + x => x, + }; + + let x7 = match input { + x if x < min => max, + x if x > max => min, + x => x, + }; + + let x8 = match input { + x if max > x => max, + x if min > x => min, + x => x, + }; + + let mut x9 = input; + if x9 > min { + x9 = min; + } + if x9 > max { + x9 = max; + } + + let x10 = match input { + x if min > x => min, + x if max < x => max, + x => min, + }; + + let mut x11 = input; + if x11 > max { + x11 = min; + } + if x11 < min { + x11 = max; + } + + let mut x12 = input; + if min > x12 { + x12 = max * 3; + } + if max < x12 { + x12 = min; + } + + let mut x13 = input; + if max < x13 { + let x13 = max; + } + if min > x13 { + x13 = min; + } + let mut x14 = input; + if x14 < min { + x14 = 3; + } else if x14 > max { + x14 = max; + } + { + let input: i32 = cmp_min_max(1); + // These can only be detected if exactly one of the arguments to the inner function is const. + let x16 = cmp_max(cmp_max(input, CONST_MAX), CONST_MIN); + let x17 = cmp_min(cmp_min(input, CONST_MIN), CONST_MAX); + let x18 = cmp_max(CONST_MIN, cmp_max(input, CONST_MAX)); + let x19 = cmp_min(CONST_MAX, cmp_min(input, CONST_MIN)); + let x20 = cmp_max(cmp_max(CONST_MAX, input), CONST_MIN); + let x21 = cmp_min(cmp_min(CONST_MIN, input), CONST_MAX); + let x22 = cmp_max(CONST_MIN, cmp_max(CONST_MAX, input)); + let x23 = cmp_min(CONST_MAX, cmp_min(CONST_MIN, input)); + let input: f64 = cmp_min_max(1) as f64; + let x24 = f64::max(f64::max(input, CONST_F64_MAX), CONST_F64_MIN); + let x25 = f64::min(f64::min(input, CONST_F64_MIN), CONST_F64_MAX); + let x26 = f64::max(CONST_F64_MIN, f64::max(input, CONST_F64_MAX)); + let x27 = f64::min(CONST_F64_MAX, f64::min(input, CONST_F64_MIN)); + let x28 = f64::max(f64::max(CONST_F64_MAX, input), CONST_F64_MIN); + let x29 = f64::min(f64::min(CONST_F64_MIN, input), CONST_F64_MAX); + let x30 = f64::max(CONST_F64_MIN, f64::max(CONST_F64_MAX, input)); + let x31 = f64::min(CONST_F64_MAX, f64::min(CONST_F64_MIN, input)); + let x32 = f64::min(CONST_F64_MAX, f64::min(CONST_F64_MIN, CONST_F64_MAX)); + } +} + +fn dont_tell_me_what_to_do() { + let (input, min, max) = (0, -2, 3); + let mut x_never = input; + #[allow(clippy::manual_clamp)] + if x_never < min { + x_never = min; + } + if x_never > max { + x_never = max; + } +} + +/// Just to ensure this isn't const evaled +fn cmp_min_max(input: i32) -> i32 { + input * 3 +} + +#[clippy::msrv = "1.49"] +fn msrv_1_49() { + let (input, min, max) = (0, -1, 2); + let _ = if input < min { + min + } else if input > max { + max + } else { + input + }; +} + +#[clippy::msrv = "1.50"] +fn msrv_1_50() { + let (input, min, max) = (0, -1, 2); + let _ = input.clamp(min, max); +} + +const fn _const() { + let (input, min, max) = (0, -1, 2); + let _ = if input < min { + min + } else if input > max { + max + } else { + input + }; + + let mut x = input; + if max < x { + let x = max; + } + if min > x { + x = min; + } +} diff --git a/src/tools/clippy/tests/ui/manual_clamp.rs b/src/tools/clippy/tests/ui/manual_clamp.rs index cdfd8e4c3..cacb40ae0 100644 --- a/src/tools/clippy/tests/ui/manual_clamp.rs +++ b/src/tools/clippy/tests/ui/manual_clamp.rs @@ -19,6 +19,8 @@ fn main() { let (input, min, max) = (0, -2, 3); // Lint let x0 = if max < input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min max } else if min > input { min @@ -27,6 +29,8 @@ fn main() { }; let x1 = if input > max { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min max } else if input < min { min @@ -35,6 +39,8 @@ fn main() { }; let x2 = if input < min { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min min } else if input > max { max @@ -43,6 +49,8 @@ fn main() { }; let x3 = if min > input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min min } else if max < input { max @@ -51,22 +59,32 @@ fn main() { }; let x4 = input.max(min).min(max); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x5 = input.min(max).max(min); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x6 = match input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x if x > max => max, x if x < min => min, x => x, }; let x7 = match input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x if x < min => min, x if x > max => max, x => x, }; let x8 = match input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x if max < x => max, x if min > x => min, x => x, @@ -74,6 +92,8 @@ fn main() { let mut x9 = input; if x9 < min { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x9 = min; } if x9 > max { @@ -81,6 +101,8 @@ fn main() { } let x10 = match input { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x if min > x => min, x if max < x => max, x => x, @@ -89,6 +111,8 @@ fn main() { let mut x11 = input; let _ = 1; if x11 > max { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x11 = max; } if x11 < min { @@ -97,6 +121,8 @@ fn main() { let mut x12 = input; if min > x12 { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x12 = min; } if max < x12 { @@ -105,6 +131,8 @@ fn main() { let mut x13 = input; if max < x13 { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x13 = max; } if min > x13 { @@ -112,6 +140,8 @@ fn main() { } let x14 = if input > CONST_MAX { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min CONST_MAX } else if input < CONST_MIN { CONST_MIN @@ -121,6 +151,8 @@ fn main() { { let (input, min, max) = (0.0f64, -2.0, 3.0); let x15 = if input > max { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() max } else if input < min { min @@ -132,25 +164,59 @@ fn main() { let input: i32 = cmp_min_max(1); // These can only be detected if exactly one of the arguments to the inner function is const. let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min let input: f64 = cmp_min_max(1) as f64; let x24 = f64::max(f64::min(input, CONST_F64_MAX), CONST_F64_MIN); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x25 = f64::min(f64::max(input, CONST_F64_MIN), CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x26 = f64::max(CONST_F64_MIN, f64::min(input, CONST_F64_MAX)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x27 = f64::min(CONST_F64_MAX, f64::max(input, CONST_F64_MIN)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x28 = f64::max(f64::min(CONST_F64_MAX, input), CONST_F64_MIN); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x29 = f64::min(f64::max(CONST_F64_MIN, input), CONST_F64_MAX); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x30 = f64::max(CONST_F64_MIN, f64::min(CONST_F64_MAX, input)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() let x31 = f64::min(CONST_F64_MAX, f64::max(CONST_F64_MIN, input)); + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min, min.is_nan(), or max.is_nan() } let mut x32 = input; if x32 < min { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x32 = min; } else if x32 > max { x32 = max; @@ -159,6 +225,8 @@ fn main() { // It's important this be the last set of statements let mut x33 = input; if max < x33 { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min x33 = max; } if min > x33 { @@ -319,6 +387,8 @@ fn msrv_1_49() { fn msrv_1_50() { let (input, min, max) = (0, -1, 2); let _ = if input < min { + //~^ ERROR: clamp-like pattern without using clamp function + //~| NOTE: clamp will panic if max < min min } else if input > max { max diff --git a/src/tools/clippy/tests/ui/manual_clamp.stderr b/src/tools/clippy/tests/ui/manual_clamp.stderr index 988ad1527..2fa68ede1 100644 --- a/src/tools/clippy/tests/ui/manual_clamp.stderr +++ b/src/tools/clippy/tests/ui/manual_clamp.stderr @@ -1,24 +1,27 @@ error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:76:5 + --> $DIR/manual_clamp.rs:94:5 | LL | / if x9 < min { +LL | | +LL | | LL | | x9 = min; -LL | | } -LL | | if x9 > max { +... | LL | | x9 = max; LL | | } | |_____^ help: replace with clamp: `x9 = x9.clamp(min, max);` | = note: clamp will panic if max < min = note: `-D clippy::manual-clamp` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_clamp)]` error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:91:5 + --> $DIR/manual_clamp.rs:113:5 | LL | / if x11 > max { +LL | | +LL | | LL | | x11 = max; -LL | | } -LL | | if x11 < min { +... | LL | | x11 = min; LL | | } | |_____^ help: replace with clamp: `x11 = x11.clamp(min, max);` @@ -26,12 +29,13 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:99:5 + --> $DIR/manual_clamp.rs:123:5 | LL | / if min > x12 { +LL | | +LL | | LL | | x12 = min; -LL | | } -LL | | if max < x12 { +... | LL | | x12 = max; LL | | } | |_____^ help: replace with clamp: `x12 = x12.clamp(min, max);` @@ -39,12 +43,13 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:107:5 + --> $DIR/manual_clamp.rs:133:5 | LL | / if max < x13 { +LL | | +LL | | LL | | x13 = max; -LL | | } -LL | | if min > x13 { +... | LL | | x13 = min; LL | | } | |_____^ help: replace with clamp: `x13 = x13.clamp(min, max);` @@ -52,12 +57,13 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:161:5 + --> $DIR/manual_clamp.rs:227:5 | LL | / if max < x33 { +LL | | +LL | | LL | | x33 = max; -LL | | } -LL | | if min > x33 { +... | LL | | x33 = min; LL | | } | |_____^ help: replace with clamp: `x33 = x33.clamp(min, max);` @@ -69,10 +75,10 @@ error: clamp-like pattern without using clamp function | LL | let x0 = if max < input { | ______________^ +LL | | +LL | | LL | | max -LL | | } else if min > input { -LL | | min -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` @@ -80,14 +86,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:29:14 + --> $DIR/manual_clamp.rs:31:14 | LL | let x1 = if input > max { | ______________^ +LL | | +LL | | LL | | max -LL | | } else if input < min { -LL | | min -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` @@ -95,14 +101,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:37:14 + --> $DIR/manual_clamp.rs:41:14 | LL | let x2 = if input < min { | ______________^ +LL | | +LL | | LL | | min -LL | | } else if input > max { -LL | | max -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` @@ -110,14 +116,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:45:14 + --> $DIR/manual_clamp.rs:51:14 | LL | let x3 = if min > input { | ______________^ +LL | | +LL | | LL | | min -LL | | } else if max < input { -LL | | max -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` @@ -125,7 +131,7 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:53:14 + --> $DIR/manual_clamp.rs:61:14 | LL | let x4 = input.max(min).min(max); | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(min, max)` @@ -133,7 +139,7 @@ LL | let x4 = input.max(min).min(max); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:55:14 + --> $DIR/manual_clamp.rs:65:14 | LL | let x5 = input.min(max).max(min); | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(min, max)` @@ -141,10 +147,12 @@ LL | let x5 = input.min(max).max(min); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:57:14 + --> $DIR/manual_clamp.rs:69:14 | LL | let x6 = match input { | ______________^ +LL | | +LL | | LL | | x if x > max => max, LL | | x if x < min => min, LL | | x => x, @@ -154,10 +162,12 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:63:14 + --> $DIR/manual_clamp.rs:77:14 | LL | let x7 = match input { | ______________^ +LL | | +LL | | LL | | x if x < min => min, LL | | x if x > max => max, LL | | x => x, @@ -167,10 +177,12 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:69:14 + --> $DIR/manual_clamp.rs:85:14 | LL | let x8 = match input { | ______________^ +LL | | +LL | | LL | | x if max < x => max, LL | | x if min > x => min, LL | | x => x, @@ -180,10 +192,12 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:83:15 + --> $DIR/manual_clamp.rs:103:15 | LL | let x10 = match input { | _______________^ +LL | | +LL | | LL | | x if min > x => min, LL | | x if max < x => max, LL | | x => x, @@ -193,14 +207,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:114:15 + --> $DIR/manual_clamp.rs:142:15 | LL | let x14 = if input > CONST_MAX { | _______________^ +LL | | +LL | | LL | | CONST_MAX -LL | | } else if input < CONST_MIN { -LL | | CONST_MIN -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -208,14 +222,14 @@ LL | | }; = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:123:19 + --> $DIR/manual_clamp.rs:153:19 | LL | let x15 = if input > max { | ___________________^ +LL | | +LL | | LL | | max -LL | | } else if input < min { -LL | | min -LL | | } else { +... | LL | | input LL | | }; | |_________^ help: replace with clamp: `input.clamp(min, max)` @@ -224,7 +238,7 @@ LL | | }; = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:134:19 + --> $DIR/manual_clamp.rs:166:19 | LL | let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -232,7 +246,7 @@ LL | let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:135:19 + --> $DIR/manual_clamp.rs:169:19 | LL | let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -240,7 +254,7 @@ LL | let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:136:19 + --> $DIR/manual_clamp.rs:172:19 | LL | let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -248,7 +262,7 @@ LL | let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX)); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:137:19 + --> $DIR/manual_clamp.rs:175:19 | LL | let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -256,7 +270,7 @@ LL | let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN)); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:138:19 + --> $DIR/manual_clamp.rs:178:19 | LL | let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -264,7 +278,7 @@ LL | let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:139:19 + --> $DIR/manual_clamp.rs:181:19 | LL | let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -272,7 +286,7 @@ LL | let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:140:19 + --> $DIR/manual_clamp.rs:184:19 | LL | let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -280,7 +294,7 @@ LL | let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input)); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:141:19 + --> $DIR/manual_clamp.rs:187:19 | LL | let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)` @@ -288,7 +302,7 @@ LL | let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input)); = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:143:19 + --> $DIR/manual_clamp.rs:191:19 | LL | let x24 = f64::max(f64::min(input, CONST_F64_MAX), CONST_F64_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -297,7 +311,7 @@ LL | let x24 = f64::max(f64::min(input, CONST_F64_MAX), CONST_F64_MIN); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:144:19 + --> $DIR/manual_clamp.rs:194:19 | LL | let x25 = f64::min(f64::max(input, CONST_F64_MIN), CONST_F64_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -306,7 +320,7 @@ LL | let x25 = f64::min(f64::max(input, CONST_F64_MIN), CONST_F64_MAX); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:145:19 + --> $DIR/manual_clamp.rs:197:19 | LL | let x26 = f64::max(CONST_F64_MIN, f64::min(input, CONST_F64_MAX)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -315,7 +329,7 @@ LL | let x26 = f64::max(CONST_F64_MIN, f64::min(input, CONST_F64_MAX)); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:146:19 + --> $DIR/manual_clamp.rs:200:19 | LL | let x27 = f64::min(CONST_F64_MAX, f64::max(input, CONST_F64_MIN)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -324,7 +338,7 @@ LL | let x27 = f64::min(CONST_F64_MAX, f64::max(input, CONST_F64_MIN)); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:147:19 + --> $DIR/manual_clamp.rs:203:19 | LL | let x28 = f64::max(f64::min(CONST_F64_MAX, input), CONST_F64_MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -333,7 +347,7 @@ LL | let x28 = f64::max(f64::min(CONST_F64_MAX, input), CONST_F64_MIN); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:148:19 + --> $DIR/manual_clamp.rs:206:19 | LL | let x29 = f64::min(f64::max(CONST_F64_MIN, input), CONST_F64_MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -342,7 +356,7 @@ LL | let x29 = f64::min(f64::max(CONST_F64_MIN, input), CONST_F64_MAX); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:149:19 + --> $DIR/manual_clamp.rs:209:19 | LL | let x30 = f64::max(CONST_F64_MIN, f64::min(CONST_F64_MAX, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -351,7 +365,7 @@ LL | let x30 = f64::max(CONST_F64_MIN, f64::min(CONST_F64_MAX, input)); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:150:19 + --> $DIR/manual_clamp.rs:212:19 | LL | let x31 = f64::min(CONST_F64_MAX, f64::max(CONST_F64_MIN, input)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)` @@ -360,9 +374,11 @@ LL | let x31 = f64::min(CONST_F64_MAX, f64::max(CONST_F64_MIN, input)); = note: clamp returns NaN if the input is NaN error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:153:5 + --> $DIR/manual_clamp.rs:217:5 | LL | / if x32 < min { +LL | | +LL | | LL | | x32 = min; LL | | } else if x32 > max { LL | | x32 = max; @@ -372,14 +388,14 @@ LL | | } = note: clamp will panic if max < min error: clamp-like pattern without using clamp function - --> $DIR/manual_clamp.rs:321:13 + --> $DIR/manual_clamp.rs:389:13 | LL | let _ = if input < min { | _____________^ +LL | | +LL | | LL | | min -LL | | } else if input > max { -LL | | max -LL | | } else { +... | LL | | input LL | | }; | |_____^ help: replace with clamp: `input.clamp(min, max)` diff --git a/src/tools/clippy/tests/ui/manual_filter.fixed b/src/tools/clippy/tests/ui/manual_filter.fixed index 5e3b12e51..c1bc4aae9 100644 --- a/src/tools/clippy/tests/ui/manual_filter.fixed +++ b/src/tools/clippy/tests/ui/manual_filter.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_filter)] #![allow(unused_variables, dead_code, clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/manual_filter.rs b/src/tools/clippy/tests/ui/manual_filter.rs index b81604b03..06968f8ba 100644 --- a/src/tools/clippy/tests/ui/manual_filter.rs +++ b/src/tools/clippy/tests/ui/manual_filter.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_filter)] #![allow(unused_variables, dead_code, clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/manual_filter.stderr b/src/tools/clippy/tests/ui/manual_filter.stderr index f62d3e960..1490f2097 100644 --- a/src/tools/clippy/tests/ui/manual_filter.stderr +++ b/src/tools/clippy/tests/ui/manual_filter.stderr @@ -1,5 +1,5 @@ error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:7:5 + --> $DIR/manual_filter.rs:5:5 | LL | / match Some(0) { LL | | None => None, @@ -11,9 +11,10 @@ LL | | }; | |_____^ help: try: `Some(0).filter(|&x| x <= 0)` | = note: `-D clippy::manual-filter` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_filter)]` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:18:5 + --> $DIR/manual_filter.rs:16:5 | LL | / match Some(1) { LL | | Some(x) => { @@ -25,7 +26,7 @@ LL | | }; | |_____^ help: try: `Some(1).filter(|&x| x <= 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:29:5 + --> $DIR/manual_filter.rs:27:5 | LL | / match Some(2) { LL | | Some(x) => { @@ -37,7 +38,7 @@ LL | | }; | |_____^ help: try: `Some(2).filter(|&x| x <= 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:40:5 + --> $DIR/manual_filter.rs:38:5 | LL | / match Some(3) { LL | | Some(x) => { @@ -49,7 +50,7 @@ LL | | }; | |_____^ help: try: `Some(3).filter(|&x| x > 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:52:5 + --> $DIR/manual_filter.rs:50:5 | LL | / match y { LL | | // Some(4) @@ -61,7 +62,7 @@ LL | | }; | |_____^ help: try: `y.filter(|&x| x <= 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:64:5 + --> $DIR/manual_filter.rs:62:5 | LL | / match Some(5) { LL | | Some(x) => { @@ -73,7 +74,7 @@ LL | | }; | |_____^ help: try: `Some(5).filter(|&x| x > 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:75:5 + --> $DIR/manual_filter.rs:73:5 | LL | / match Some(6) { LL | | Some(ref x) => { @@ -85,7 +86,7 @@ LL | | }; | |_____^ help: try: `Some(6).as_ref().filter(|&x| x > &0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:87:5 + --> $DIR/manual_filter.rs:85:5 | LL | / match Some(String::new()) { LL | | Some(x) => { @@ -97,7 +98,7 @@ LL | | }; | |_____^ help: try: `Some(String::new()).filter(|x| external_cond)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:98:5 + --> $DIR/manual_filter.rs:96:5 | LL | / if let Some(x) = Some(7) { LL | | if external_cond { Some(x) } else { None } @@ -107,7 +108,7 @@ LL | | }; | |_____^ help: try: `Some(7).filter(|&x| external_cond)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:104:5 + --> $DIR/manual_filter.rs:102:5 | LL | / match &Some(8) { LL | | &Some(x) => { @@ -119,7 +120,7 @@ LL | | }; | |_____^ help: try: `Some(8).filter(|&x| x != 0)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:115:5 + --> $DIR/manual_filter.rs:113:5 | LL | / match Some(9) { LL | | Some(x) => { @@ -131,7 +132,7 @@ LL | | }; | |_____^ help: try: `Some(9).filter(|&x| x > 10 && x < 100)` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:141:5 + --> $DIR/manual_filter.rs:139:5 | LL | / match Some(11) { LL | | // Lint, statement is preserved by `.filter` @@ -151,7 +152,7 @@ LL ~ }); | error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:185:13 + --> $DIR/manual_filter.rs:183:13 | LL | let _ = match Some(14) { | _____________^ @@ -164,7 +165,7 @@ LL | | }; | |_____^ help: try: `Some(14).filter(|&x| unsafe { f(x) })` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:195:13 + --> $DIR/manual_filter.rs:193:13 | LL | let _ = match Some(15) { | _____________^ @@ -176,7 +177,7 @@ LL | | }; | |_____^ help: try: `Some(15).filter(|&x| unsafe { f(x) })` error: manual implementation of `Option::filter` - --> $DIR/manual_filter.rs:205:12 + --> $DIR/manual_filter.rs:203:12 | LL | } else if let Some(x) = Some(16) { | ____________^ diff --git a/src/tools/clippy/tests/ui/manual_filter_map.fixed b/src/tools/clippy/tests/ui/manual_filter_map.fixed index 35872a39a..4de45e39b 100644 --- a/src/tools/clippy/tests/ui/manual_filter_map.fixed +++ b/src/tools/clippy/tests/ui/manual_filter_map.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![warn(clippy::manual_filter_map)] #![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure diff --git a/src/tools/clippy/tests/ui/manual_filter_map.rs b/src/tools/clippy/tests/ui/manual_filter_map.rs index 50d8d2722..22f316f90 100644 --- a/src/tools/clippy/tests/ui/manual_filter_map.rs +++ b/src/tools/clippy/tests/ui/manual_filter_map.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![warn(clippy::manual_filter_map)] #![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure diff --git a/src/tools/clippy/tests/ui/manual_filter_map.stderr b/src/tools/clippy/tests/ui/manual_filter_map.stderr index 0e8672c02..0bfc1f5c7 100644 --- a/src/tools/clippy/tests/ui/manual_filter_map.stderr +++ b/src/tools/clippy/tests/ui/manual_filter_map.stderr @@ -1,42 +1,43 @@ error: `filter(..).map(..)` can be simplified as `filter_map(..)` - --> $DIR/manual_filter_map.rs:9:19 + --> $DIR/manual_filter_map.rs:8:19 | LL | let _ = (0..).filter(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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:9:30 + --> $DIR/manual_filter_map.rs:8:30 | LL | let _ = (0..).filter(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()); | ^^^^^^^^^^ = note: `-D clippy::manual-filter-map` implied by `-D warnings` + = 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:11: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:11: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:14: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:14: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:17:10 | LL | .filter(|&x| to_ref(to_opt(x)).is_some()) | __________^ @@ -44,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:17: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:20:10 | LL | .filter(|x| to_ref(to_opt(*x)).is_some()) | __________^ @@ -58,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:20: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:24:10 | LL | .filter(|&x| to_ref(to_res(x)).is_ok()) | __________^ @@ -72,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:24: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:27:10 | LL | .filter(|x| to_ref(to_res(*x)).is_ok()) | __________^ @@ -86,93 +87,94 @@ 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:27: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:33:27 | LL | iter::>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())` | = note: `-D clippy::manual-find-map` implied by `-D warnings` + = 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:34: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:35: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:36: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:36: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:38: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:39: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:40: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:41: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:42: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:43: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:44: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:44: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:92:10 | LL | .filter(|f| f.option_field.is_some()) | __________^ @@ -180,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:97:10 | LL | .filter(|f| f.ref_field.is_some()) | __________^ @@ -188,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:102:10 | LL | .filter(|f| f.ref_field.is_some()) | __________^ @@ -196,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:107:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -204,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:112:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -212,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:117:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -220,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:122:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -228,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:127:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -236,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:132:10 | LL | .filter(|f| f.result_field.is_ok()) | __________^ @@ -244,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:145:27 | LL | let _x = iter.clone().filter(|x| matches!(x, Enum::A(_))).map(|x| match x { | ___________________________^ @@ -254,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:155:10 | LL | .filter(|x| matches!(x, Enum::A(_))) | __________^ diff --git a/src/tools/clippy/tests/ui/manual_find.rs b/src/tools/clippy/tests/ui/manual_find.rs index 257fe045f..0a105b035 100644 --- a/src/tools/clippy/tests/ui/manual_find.rs +++ b/src/tools/clippy/tests/ui/manual_find.rs @@ -1,8 +1,10 @@ #![allow(unused)] #![warn(clippy::manual_find)] - +//@no-rustfix fn vec_string(strings: Vec) -> Option { for s in strings { + //~^ ERROR: manual implementation of `Iterator::find` + //~| NOTE: you may need to dereference some variables if s == String::new() { return Some(s); } @@ -12,6 +14,8 @@ fn vec_string(strings: Vec) -> Option { fn tuple(arr: Vec<(String, i32)>) -> Option { for (s, _) in arr { + //~^ ERROR: manual implementation of `Iterator::find` + //~| NOTE: you may need to dereference some variables if s == String::new() { return Some(s); } diff --git a/src/tools/clippy/tests/ui/manual_find.stderr b/src/tools/clippy/tests/ui/manual_find.stderr index ea04bb066..286ad5462 100644 --- a/src/tools/clippy/tests/ui/manual_find.stderr +++ b/src/tools/clippy/tests/ui/manual_find.stderr @@ -2,23 +2,26 @@ error: manual implementation of `Iterator::find` --> $DIR/manual_find.rs:5:5 | LL | / for s in strings { +LL | | +LL | | LL | | if s == String::new() { -LL | | return Some(s); -LL | | } +... | LL | | } LL | | None | |________^ help: replace with an iterator: `strings.into_iter().find(|s| s == String::new())` | = note: you may need to dereference some variables = note: `-D clippy::manual-find` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_find)]` error: manual implementation of `Iterator::find` - --> $DIR/manual_find.rs:14:5 + --> $DIR/manual_find.rs:16:5 | LL | / for (s, _) in arr { +LL | | +LL | | LL | | if s == String::new() { -LL | | return Some(s); -LL | | } +... | LL | | } LL | | None | |________^ help: replace with an iterator: `arr.into_iter().map(|(s, _)| s).find(|s| s == String::new())` diff --git a/src/tools/clippy/tests/ui/manual_find_fixable.fixed b/src/tools/clippy/tests/ui/manual_find_fixable.fixed index 9c5eb20c8..5e6849a4d 100644 --- a/src/tools/clippy/tests/ui/manual_find_fixable.fixed +++ b/src/tools/clippy/tests/ui/manual_find_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_find)] #![allow(unused)] #![allow(clippy::needless_return, clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/manual_find_fixable.rs b/src/tools/clippy/tests/ui/manual_find_fixable.rs index 7b670320e..56c3f2629 100644 --- a/src/tools/clippy/tests/ui/manual_find_fixable.rs +++ b/src/tools/clippy/tests/ui/manual_find_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_find)] #![allow(unused)] #![allow(clippy::needless_return, clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/manual_find_fixable.stderr b/src/tools/clippy/tests/ui/manual_find_fixable.stderr index dbc4ff69a..387d1509c 100644 --- a/src/tools/clippy/tests/ui/manual_find_fixable.stderr +++ b/src/tools/clippy/tests/ui/manual_find_fixable.stderr @@ -1,5 +1,5 @@ error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:11:5 + --> $DIR/manual_find_fixable.rs:10:5 | LL | / for &v in ARRAY { LL | | if v == n { @@ -10,9 +10,10 @@ LL | | None | |________^ help: replace with an iterator: `ARRAY.iter().find(|&&v| v == n).copied()` | = note: `-D clippy::manual-find` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_find)]` error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:20:5 + --> $DIR/manual_find_fixable.rs:19:5 | LL | / for (a, _) in arr { LL | | if a % 2 == 0 { @@ -23,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:33:5 + --> $DIR/manual_find_fixable.rs:32:5 | LL | / for el in arr { LL | | if el.name.len() == 10 { @@ -36,7 +37,7 @@ LL | | None = note: you may need to dereference some variables error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:43:5 + --> $DIR/manual_find_fixable.rs:42:5 | LL | / for Tuple(a, _) in arr { LL | | if a >= 3 { @@ -47,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:58:5 + --> $DIR/manual_find_fixable.rs:57:5 | LL | / for el in arr { LL | | if el.should_keep() { @@ -60,7 +61,7 @@ LL | | None = note: you may need to dereference some variables error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:68:5 + --> $DIR/manual_find_fixable.rs:67:5 | LL | / for el in arr { LL | | if f(el) == 20 { @@ -71,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:78:5 + --> $DIR/manual_find_fixable.rs:77:5 | LL | / for &el in arr.values() { LL | | if f(el) { @@ -82,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:87:5 + --> $DIR/manual_find_fixable.rs:86:5 | LL | / for el in arr { LL | | if el.is_true { @@ -95,7 +96,7 @@ LL | | None = note: you may need to dereference some variables error: manual implementation of `Iterator::find` - --> $DIR/manual_find_fixable.rs:117:5 + --> $DIR/manual_find_fixable.rs:116:5 | LL | / for (_, &x) in v { LL | | if x > 10 { @@ -106,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:126:5 + --> $DIR/manual_find_fixable.rs:125:5 | LL | / for &(_, &x) in v { LL | | if x > 10 { @@ -117,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:135:5 + --> $DIR/manual_find_fixable.rs:134:5 | LL | / for x in arr { LL | | if x >= 5 { @@ -128,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:190:9 + --> $DIR/manual_find_fixable.rs:189:9 | LL | / for x in arr { LL | | if x < 1 { diff --git a/src/tools/clippy/tests/ui/manual_find_map.fixed b/src/tools/clippy/tests/ui/manual_find_map.fixed index 0c8eebf04..0e92d25e6 100644 --- a/src/tools/clippy/tests/ui/manual_find_map.fixed +++ b/src/tools/clippy/tests/ui/manual_find_map.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![warn(clippy::manual_find_map)] #![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure diff --git a/src/tools/clippy/tests/ui/manual_find_map.rs b/src/tools/clippy/tests/ui/manual_find_map.rs index b2feb48a8..b2568c823 100644 --- a/src/tools/clippy/tests/ui/manual_find_map.rs +++ b/src/tools/clippy/tests/ui/manual_find_map.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![warn(clippy::manual_find_map)] #![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure diff --git a/src/tools/clippy/tests/ui/manual_find_map.stderr b/src/tools/clippy/tests/ui/manual_find_map.stderr index 4e52b5efa..0dc9ae1df 100644 --- a/src/tools/clippy/tests/ui/manual_find_map.stderr +++ b/src/tools/clippy/tests/ui/manual_find_map.stderr @@ -1,42 +1,43 @@ error: `find(..).map(..)` can be simplified as `find_map(..)` - --> $DIR/manual_find_map.rs:9:19 + --> $DIR/manual_find_map.rs:8:19 | LL | let _ = (0..).find(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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:9:28 + --> $DIR/manual_find_map.rs:8:28 | LL | let _ = (0..).find(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()); | ^^^^^^^^^^ = note: `-D clippy::manual-find-map` implied by `-D warnings` + = 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:11: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:11: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:14: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:14: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:17:10 | LL | .find(|&x| to_ref(to_opt(x)).is_some()) | __________^ @@ -44,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:17: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:20:10 | LL | .find(|x| to_ref(to_opt(*x)).is_some()) | __________^ @@ -58,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:20: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:24:10 | LL | .find(|&x| to_ref(to_res(x)).is_ok()) | __________^ @@ -72,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:24: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:27:10 | LL | .find(|x| to_ref(to_res(*x)).is_ok()) | __________^ @@ -86,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:27: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:33: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:34: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:35: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:36: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:37: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:38: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:39: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:39: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:41: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:42: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:43: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:44: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:45: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:46: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:47: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:47: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:95:10 | LL | .find(|f| f.option_field.is_some()) | __________^ @@ -196,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:100:10 | LL | .find(|f| f.ref_field.is_some()) | __________^ @@ -204,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:105:10 | LL | .find(|f| f.ref_field.is_some()) | __________^ @@ -212,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:110:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -220,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:115:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -228,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:120:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -236,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:125:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -244,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:130:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ @@ -252,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:135:10 | LL | .find(|f| f.result_field.is_ok()) | __________^ diff --git a/src/tools/clippy/tests/ui/manual_flatten.rs b/src/tools/clippy/tests/ui/manual_flatten.rs index 552213a7f..d57333ace 100644 --- a/src/tools/clippy/tests/ui/manual_flatten.rs +++ b/src/tools/clippy/tests/ui/manual_flatten.rs @@ -1,10 +1,11 @@ #![warn(clippy::manual_flatten)] #![allow(clippy::useless_vec, clippy::uninlined_format_args)] - +//@no-rustfix fn main() { // Test for loop over implicitly adjusted `Iterator` with `if let` expression let x = vec![Some(1), Some(2), Some(3)]; for n in x { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(y) = n { println!("{}", y); } @@ -13,6 +14,7 @@ fn main() { // Test for loop over implicitly adjusted `Iterator` with `if let` statement let y: Vec> = vec![]; for n in y.clone() { + //~^ ERROR: unnecessary `if let` since only the `Ok` variant of the iterator element i if let Ok(n) = n { println!("{}", n); }; @@ -20,6 +22,7 @@ fn main() { // Test for loop over by reference for n in &y { + //~^ ERROR: unnecessary `if let` since only the `Ok` variant of the iterator element i if let Ok(n) = n { println!("{}", n); } @@ -28,6 +31,7 @@ fn main() { // Test for loop over an implicit reference let z = &y; for n in z { + //~^ ERROR: unnecessary `if let` since only the `Ok` variant of the iterator element i if let Ok(n) = n { println!("{}", n); } @@ -37,6 +41,7 @@ fn main() { let z = vec![Some(1), Some(2), Some(3)]; let z = z.iter(); for n in z { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(m) = n { println!("{}", m); } @@ -70,6 +75,7 @@ fn main() { let vec_of_ref = vec![&Some(1)]; for n in &vec_of_ref { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(n) = n { println!("{:?}", n); } @@ -77,6 +83,7 @@ fn main() { let vec_of_ref = &vec_of_ref; for n in vec_of_ref { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(n) = n { println!("{:?}", n); } @@ -84,6 +91,7 @@ fn main() { let slice_of_ref = &[&Some(1)]; for n in slice_of_ref { + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element if let Some(n) = n { println!("{:?}", n); } @@ -114,6 +122,7 @@ fn main() { fn run_unformatted_tests() { // Skip rustfmt here on purpose so the suggestion does not fit in one line for n in vec![ + //~^ ERROR: unnecessary `if let` since only the `Some` variant of the iterator element Some(1), Some(2), Some(3) diff --git a/src/tools/clippy/tests/ui/manual_flatten.stderr b/src/tools/clippy/tests/ui/manual_flatten.stderr index 180a6ff4e..aa5c2104f 100644 --- a/src/tools/clippy/tests/ui/manual_flatten.stderr +++ b/src/tools/clippy/tests/ui/manual_flatten.stderr @@ -5,6 +5,7 @@ LL | for n in x { | ^ - help: try: `x.into_iter().flatten()` | _____| | | +LL | | LL | | if let Some(y) = n { LL | | println!("{}", y); LL | | } @@ -12,21 +13,23 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:8:9 + --> $DIR/manual_flatten.rs:9:9 | LL | / if let Some(y) = n { LL | | println!("{}", y); LL | | } | |_________^ = note: `-D clippy::manual-flatten` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_flatten)]` error: unnecessary `if let` since only the `Ok` variant of the iterator element is used - --> $DIR/manual_flatten.rs:15:5 + --> $DIR/manual_flatten.rs:16:5 | LL | for n in y.clone() { | ^ --------- help: try: `y.clone().into_iter().flatten()` | _____| | | +LL | | LL | | if let Ok(n) = n { LL | | println!("{}", n); LL | | }; @@ -34,7 +37,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:16:9 + --> $DIR/manual_flatten.rs:18:9 | LL | / if let Ok(n) = n { LL | | println!("{}", n); @@ -42,12 +45,13 @@ LL | | }; | |_________^ error: unnecessary `if let` since only the `Ok` variant of the iterator element is used - --> $DIR/manual_flatten.rs:22:5 + --> $DIR/manual_flatten.rs:24:5 | LL | for n in &y { | ^ -- help: try: `y.iter().flatten()` | _____| | | +LL | | LL | | if let Ok(n) = n { LL | | println!("{}", n); LL | | } @@ -55,7 +59,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:23:9 + --> $DIR/manual_flatten.rs:26:9 | LL | / if let Ok(n) = n { LL | | println!("{}", n); @@ -63,12 +67,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Ok` variant of the iterator element is used - --> $DIR/manual_flatten.rs:30:5 + --> $DIR/manual_flatten.rs:33:5 | LL | for n in z { | ^ - help: try: `z.iter().flatten()` | _____| | | +LL | | LL | | if let Ok(n) = n { LL | | println!("{}", n); LL | | } @@ -76,7 +81,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:31:9 + --> $DIR/manual_flatten.rs:35:9 | LL | / if let Ok(n) = n { LL | | println!("{}", n); @@ -84,12 +89,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:39:5 + --> $DIR/manual_flatten.rs:43:5 | LL | for n in z { | ^ - help: try: `z.flatten()` | _____| | | +LL | | LL | | if let Some(m) = n { LL | | println!("{}", m); LL | | } @@ -97,7 +103,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:40:9 + --> $DIR/manual_flatten.rs:45:9 | LL | / if let Some(m) = n { LL | | println!("{}", m); @@ -105,12 +111,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:72:5 + --> $DIR/manual_flatten.rs:77:5 | LL | for n in &vec_of_ref { | ^ ----------- help: try: `vec_of_ref.iter().copied().flatten()` | _____| | | +LL | | LL | | if let Some(n) = n { LL | | println!("{:?}", n); LL | | } @@ -118,7 +125,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:73:9 + --> $DIR/manual_flatten.rs:79:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -126,12 +133,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:79:5 + --> $DIR/manual_flatten.rs:85:5 | LL | for n in vec_of_ref { | ^ ---------- help: try: `vec_of_ref.iter().copied().flatten()` | _____| | | +LL | | LL | | if let Some(n) = n { LL | | println!("{:?}", n); LL | | } @@ -139,7 +147,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:80:9 + --> $DIR/manual_flatten.rs:87:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -147,12 +155,13 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:86:5 + --> $DIR/manual_flatten.rs:93:5 | LL | for n in slice_of_ref { | ^ ------------ help: try: `slice_of_ref.iter().copied().flatten()` | _____| | | +LL | | LL | | if let Some(n) = n { LL | | println!("{:?}", n); LL | | } @@ -160,7 +169,7 @@ LL | | } | |_____^ | help: ...and remove the `if let` statement in the for loop - --> $DIR/manual_flatten.rs:87:9 + --> $DIR/manual_flatten.rs:95:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -168,19 +177,19 @@ LL | | } | |_________^ error: unnecessary `if let` since only the `Some` variant of the iterator element is used - --> $DIR/manual_flatten.rs:116:5 + --> $DIR/manual_flatten.rs:124:5 | LL | / for n in vec![ +LL | | LL | | Some(1), LL | | Some(2), -LL | | Some(3) ... | LL | | } LL | | } | |_____^ | help: remove the `if let` statement in the for loop and then... - --> $DIR/manual_flatten.rs:121:9 + --> $DIR/manual_flatten.rs:130:9 | LL | / if let Some(n) = n { LL | | println!("{:?}", n); @@ -189,6 +198,7 @@ LL | | } help: try | LL ~ for n in vec![ +LL + LL + Some(1), LL + Some(2), LL + Some(3) diff --git a/src/tools/clippy/tests/ui/manual_float_methods.rs b/src/tools/clippy/tests/ui/manual_float_methods.rs index af9076cfb..f3e95d680 100644 --- a/src/tools/clippy/tests/ui/manual_float_methods.rs +++ b/src/tools/clippy/tests/ui/manual_float_methods.rs @@ -1,4 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro +//@no-rustfix: overlapping suggestions +//@aux-build:proc_macros.rs #![allow(clippy::needless_if, unused)] #![warn(clippy::manual_is_infinite, clippy::manual_is_finite)] #![feature(inline_const)] diff --git a/src/tools/clippy/tests/ui/manual_float_methods.stderr b/src/tools/clippy/tests/ui/manual_float_methods.stderr index a56118b31..680ab2efa 100644 --- a/src/tools/clippy/tests/ui/manual_float_methods.stderr +++ b/src/tools/clippy/tests/ui/manual_float_methods.stderr @@ -1,18 +1,20 @@ error: manually checking if a float is infinite - --> $DIR/manual_float_methods.rs:22:8 + --> $DIR/manual_float_methods.rs:23:8 | LL | if x == f32::INFINITY || x == f32::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` | = note: `-D clippy::manual-is-infinite` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_is_infinite)]` error: manually checking if a float is finite - --> $DIR/manual_float_methods.rs:23:8 + --> $DIR/manual_float_methods.rs:24:8 | LL | if x != f32::INFINITY && x != f32::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::manual-is-finite` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_is_finite)]` help: use the dedicated method instead | LL | if x.is_finite() {} @@ -27,13 +29,13 @@ LL | if !x.is_infinite() {} | ~~~~~~~~~~~~~~~~ error: manually checking if a float is infinite - --> $DIR/manual_float_methods.rs:24:8 + --> $DIR/manual_float_methods.rs:25: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:25:8 + --> $DIR/manual_float_methods.rs:26:8 | LL | if x != INFINITE && x != NEG_INFINITE {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,13 +54,13 @@ LL | if !x.is_infinite() {} | ~~~~~~~~~~~~~~~~ error: manually checking if a float is infinite - --> $DIR/manual_float_methods.rs:27:8 + --> $DIR/manual_float_methods.rs:28: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:28:8 + --> $DIR/manual_float_methods.rs:29:8 | LL | if x != f64::INFINITY && x != f64::NEG_INFINITY {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/manual_instant_elapsed.fixed b/src/tools/clippy/tests/ui/manual_instant_elapsed.fixed index 55073c3b5..181133765 100644 --- a/src/tools/clippy/tests/ui/manual_instant_elapsed.fixed +++ b/src/tools/clippy/tests/ui/manual_instant_elapsed.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_instant_elapsed)] #![allow(clippy::unnecessary_operation)] #![allow(clippy::unchecked_duration_subtraction)] diff --git a/src/tools/clippy/tests/ui/manual_instant_elapsed.rs b/src/tools/clippy/tests/ui/manual_instant_elapsed.rs index c9029a049..fedca38b1 100644 --- a/src/tools/clippy/tests/ui/manual_instant_elapsed.rs +++ b/src/tools/clippy/tests/ui/manual_instant_elapsed.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_instant_elapsed)] #![allow(clippy::unnecessary_operation)] #![allow(clippy::unchecked_duration_subtraction)] diff --git a/src/tools/clippy/tests/ui/manual_instant_elapsed.stderr b/src/tools/clippy/tests/ui/manual_instant_elapsed.stderr index 4ce1f6891..56d0b9cd7 100644 --- a/src/tools/clippy/tests/ui/manual_instant_elapsed.stderr +++ b/src/tools/clippy/tests/ui/manual_instant_elapsed.stderr @@ -1,13 +1,14 @@ error: manual implementation of `Instant::elapsed` - --> $DIR/manual_instant_elapsed.rs:18:20 + --> $DIR/manual_instant_elapsed.rs:17:20 | LL | let duration = Instant::now() - prev_instant; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `prev_instant.elapsed()` | = note: `-D clippy::manual-instant-elapsed` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_instant_elapsed)]` error: manual implementation of `Instant::elapsed` - --> $DIR/manual_instant_elapsed.rs:27:5 + --> $DIR/manual_instant_elapsed.rs:26:5 | LL | Instant::now() - *ref_to_instant; // to ensure parens are added correctly | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*ref_to_instant).elapsed()` diff --git a/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed b/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed index 87e866586..5be2dd280 100644 --- a/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed +++ b/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, dead_code)] #![warn(clippy::manual_is_ascii_check)] diff --git a/src/tools/clippy/tests/ui/manual_is_ascii_check.rs b/src/tools/clippy/tests/ui/manual_is_ascii_check.rs index 931f0f202..f9249e22a 100644 --- a/src/tools/clippy/tests/ui/manual_is_ascii_check.rs +++ b/src/tools/clippy/tests/ui/manual_is_ascii_check.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, dead_code)] #![warn(clippy::manual_is_ascii_check)] diff --git a/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr b/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr index ee6018850..e0fb46e59 100644 --- a/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr +++ b/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr @@ -1,121 +1,122 @@ error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:7:13 + --> $DIR/manual_is_ascii_check.rs:5:13 | LL | assert!(matches!('x', 'a'..='z')); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_lowercase()` | = note: `-D clippy::manual-is-ascii-check` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_is_ascii_check)]` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:8:13 + --> $DIR/manual_is_ascii_check.rs:6: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:9:13 + --> $DIR/manual_is_ascii_check.rs:7:13 | LL | assert!(matches!(b'x', b'a'..=b'z')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'x'.is_ascii_lowercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:10:13 + --> $DIR/manual_is_ascii_check.rs:8:13 | LL | assert!(matches!(b'X', b'A'..=b'Z')); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'X'.is_ascii_uppercase()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:13:13 + --> $DIR/manual_is_ascii_check.rs:11:13 | LL | assert!(matches!(num, '0'..='9')); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.is_ascii_digit()` error: manual check for common ascii range - --> $DIR/manual_is_ascii_check.rs:14:13 + --> $DIR/manual_is_ascii_check.rs:12: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:15:13 + --> $DIR/manual_is_ascii_check.rs:13: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:19:5 + --> $DIR/manual_is_ascii_check.rs:17: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:20:5 + --> $DIR/manual_is_ascii_check.rs:18: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:21:5 + --> $DIR/manual_is_ascii_check.rs:19: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:23:5 + --> $DIR/manual_is_ascii_check.rs:21: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:24:5 + --> $DIR/manual_is_ascii_check.rs:22: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:25:5 + --> $DIR/manual_is_ascii_check.rs:23: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:28:5 + --> $DIR/manual_is_ascii_check.rs:26: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:29:5 + --> $DIR/manual_is_ascii_check.rs:27: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:30:5 + --> $DIR/manual_is_ascii_check.rs:28: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:42:13 + --> $DIR/manual_is_ascii_check.rs:40: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:43:13 + --> $DIR/manual_is_ascii_check.rs:41: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:44:13 + --> $DIR/manual_is_ascii_check.rs:42: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:54:23 + --> $DIR/manual_is_ascii_check.rs:52:23 | LL | const FOO: bool = matches!('x', '0'..='9'); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_digit()` diff --git a/src/tools/clippy/tests/ui/manual_let_else.rs b/src/tools/clippy/tests/ui/manual_let_else.rs index 381b83409..6775fdc92 100644 --- a/src/tools/clippy/tests/ui/manual_let_else.rs +++ b/src/tools/clippy/tests/ui/manual_let_else.rs @@ -8,7 +8,7 @@ clippy::needless_if )] #![warn(clippy::manual_let_else)] - +//@no-rustfix enum Variant { A(usize, usize), B(usize), @@ -23,13 +23,17 @@ fn main() {} fn fire() { let v = if let Some(v_some) = g() { v_some } else { return }; + //~^ ERROR: this could be rewritten as `let...else` + //~| NOTE: `-D clippy::manual-let-else` implied by `-D warnings` let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { return; }; let v = if let Some(v) = g() { + //~^ ERROR: this could be rewritten as `let...else` // Blocks around the identity should have no impact { { v } @@ -43,14 +47,18 @@ fn fire() { // continue and break diverge loop { let v = if let Some(v_some) = g() { v_some } else { continue }; + //~^ ERROR: this could be rewritten as `let...else` let v = if let Some(v_some) = g() { v_some } else { break }; + //~^ ERROR: this could be rewritten as `let...else` } // panic also diverges let v = if let Some(v_some) = g() { v_some } else { panic!() }; + //~^ ERROR: this could be rewritten as `let...else` // abort also diverges let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { std::process::abort() @@ -58,6 +66,7 @@ fn fire() { // If whose two branches diverge also diverges let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { if true { return } else { panic!() } @@ -65,6 +74,7 @@ fn fire() { // Diverging after an if still makes the block diverge: let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { if true {} @@ -75,6 +85,7 @@ fn fire() { // Note: the corresponding let-else requires a ; at the end of the match // as otherwise the type checker does not turn it into a ! type. let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { match () { @@ -85,9 +96,11 @@ fn fire() { // An if's expression can cause divergence: let v = if let Some(v_some) = g() { v_some } else { if panic!() {} }; + //~^ ERROR: this could be rewritten as `let...else` // An expression of a match can cause divergence: let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { match panic!() { @@ -97,6 +110,7 @@ fn fire() { // Top level else if let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else if true { return; @@ -106,6 +120,7 @@ fn fire() { // All match arms diverge let v = if let Some(v_some) = g() { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { match (g(), g()) { @@ -123,6 +138,7 @@ fn fire() { // Tuples supported for the declared variables let (v, w) = if let Some(v_some) = g().map(|v| (v, 42)) { + //~^ ERROR: this could be rewritten as `let...else` v_some } else { return; @@ -130,6 +146,7 @@ fn fire() { // Tuples supported with multiple bindings let (w, S { v }) = if let (Some(v_some), w_some) = (g().map(|_| S { v: 0 }), 0) { + //~^ ERROR: this could be rewritten as `let...else` (w_some, v_some) } else { return; @@ -148,25 +165,31 @@ fn fire() { } let v = if let Variant::A(a, 0) = e() { a } else { return }; + //~^ ERROR: this could be rewritten as `let...else` // `mut v` is inserted into the pattern let mut v = if let Variant::B(b) = e() { b } else { return }; + //~^ ERROR: this could be rewritten as `let...else` // Nesting works let nested = Ok(Some(e())); let v = if let Ok(Some(Variant::B(b))) | Err(Some(Variant::A(b, _))) = nested { + //~^ ERROR: this could be rewritten as `let...else` b } else { return; }; // dot dot works let v = if let Variant::A(.., a) = e() { a } else { return }; + //~^ ERROR: this could be rewritten as `let...else` // () is preserved: a bit of an edge case but make sure it stays around let w = if let (Some(v), ()) = (g(), ()) { v } else { return }; + //~^ ERROR: this could be rewritten as `let...else` // Tuple structs work let w = if let Some(S { v: x }) = Some(S { v: 0 }) { + //~^ ERROR: this could be rewritten as `let...else` x } else { return; @@ -174,6 +197,7 @@ fn fire() { // Field init shorthand is suggested let v = if let Some(S { v: x }) = Some(S { v: 0 }) { + //~^ ERROR: this could be rewritten as `let...else` x } else { return; @@ -181,6 +205,7 @@ fn fire() { // Multi-field structs also work let (x, S { v }, w) = if let Some(U { v, w, x }) = None::>> { + //~^ ERROR: this could be rewritten as `let...else` (x, v, w) } else { return; @@ -297,6 +322,7 @@ fn not_fire() { let ff = Some(1); let _ = match ff { + //~^ ERROR: this could be rewritten as `let...else` Some(value) => value, _ => macro_call!(), }; diff --git a/src/tools/clippy/tests/ui/manual_let_else.stderr b/src/tools/clippy/tests/ui/manual_let_else.stderr index 912302b17..49dbd7615 100644 --- a/src/tools/clippy/tests/ui/manual_let_else.stderr +++ b/src/tools/clippy/tests/ui/manual_let_else.stderr @@ -5,11 +5,13 @@ LL | let v = if let Some(v_some) = g() { v_some } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { return };` | = note: `-D clippy::manual-let-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:26:5 + --> $DIR/manual_let_else.rs:28:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { LL | | return; @@ -24,12 +26,12 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:32:5 + --> $DIR/manual_let_else.rs:35:5 | LL | / let v = if let Some(v) = g() { +LL | | LL | | // Blocks around the identity should have no impact LL | | { -LL | | { v } ... | LL | | return; LL | | }; @@ -45,27 +47,28 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:45:9 + --> $DIR/manual_let_else.rs:49:9 | LL | let v = if let Some(v_some) = g() { v_some } else { continue }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { continue };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:46:9 + --> $DIR/manual_let_else.rs:51:9 | LL | let v = if let Some(v_some) = g() { v_some } else { break }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { break };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:50:5 + --> $DIR/manual_let_else.rs:56:5 | LL | let v = if let Some(v_some) = g() { v_some } else { panic!() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { panic!() };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:53:5 + --> $DIR/manual_let_else.rs:60:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { LL | | std::process::abort() @@ -80,9 +83,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:60:5 + --> $DIR/manual_let_else.rs:68:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { LL | | if true { return } else { panic!() } @@ -97,9 +101,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:67:5 + --> $DIR/manual_let_else.rs:76:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { LL | | if true {} @@ -116,12 +121,12 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:77:5 + --> $DIR/manual_let_else.rs:87:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { -LL | | match () { ... | LL | | } LL | | }; @@ -138,19 +143,19 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:87:5 + --> $DIR/manual_let_else.rs:98:5 | LL | let v = if let Some(v_some) = g() { v_some } else { if panic!() {} }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { if panic!() {} };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:90:5 + --> $DIR/manual_let_else.rs:102:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { -LL | | match panic!() { -LL | | _ => {}, +... | LL | | } LL | | }; | |______^ @@ -165,13 +170,13 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:99:5 + --> $DIR/manual_let_else.rs:112:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else if true { -LL | | return; -LL | | } else { +... | LL | | panic!("diverge"); LL | | }; | |______^ @@ -186,12 +191,12 @@ LL + } }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:108:5 + --> $DIR/manual_let_else.rs:122:5 | LL | / let v = if let Some(v_some) = g() { +LL | | LL | | v_some LL | | } else { -LL | | match (g(), g()) { ... | LL | | } LL | | }; @@ -215,9 +220,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:125:5 + --> $DIR/manual_let_else.rs:140:5 | LL | / let (v, w) = if let Some(v_some) = g().map(|v| (v, 42)) { +LL | | LL | | v_some LL | | } else { LL | | return; @@ -232,9 +238,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:132:5 + --> $DIR/manual_let_else.rs:148:5 | LL | / let (w, S { v }) = if let (Some(v_some), w_some) = (g().map(|_| S { v: 0 }), 0) { +LL | | LL | | (w_some, v_some) LL | | } else { LL | | return; @@ -249,7 +256,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:141:13 + --> $DIR/manual_let_else.rs:158:13 | LL | let $n = if let Some(v) = $e { v } else { return }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some($n) = g() else { return };` @@ -260,21 +267,22 @@ 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:150:5 + --> $DIR/manual_let_else.rs:167: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:153:5 + --> $DIR/manual_let_else.rs:171: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:157:5 + --> $DIR/manual_let_else.rs:176:5 | LL | / let v = if let Ok(Some(Variant::B(b))) | Err(Some(Variant::A(b, _))) = nested { +LL | | LL | | b LL | | } else { LL | | return; @@ -289,21 +297,22 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:163:5 + --> $DIR/manual_let_else.rs:183: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:166:5 + --> $DIR/manual_let_else.rs:187: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:169:5 + --> $DIR/manual_let_else.rs:191:5 | LL | / let w = if let Some(S { v: x }) = Some(S { v: 0 }) { +LL | | LL | | x LL | | } else { LL | | return; @@ -318,9 +327,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:176:5 + --> $DIR/manual_let_else.rs:199:5 | LL | / let v = if let Some(S { v: x }) = Some(S { v: 0 }) { +LL | | LL | | x LL | | } else { LL | | return; @@ -335,9 +345,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:183:5 + --> $DIR/manual_let_else.rs:207:5 | LL | / let (x, S { v }, w) = if let Some(U { v, w, x }) = None::>> { +LL | | LL | | (x, v, w) LL | | } else { LL | | return; @@ -352,9 +363,10 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else.rs:299:5 + --> $DIR/manual_let_else.rs:324:5 | LL | / let _ = match ff { +LL | | LL | | Some(value) => value, LL | | _ => macro_call!(), LL | | }; diff --git a/src/tools/clippy/tests/ui/manual_let_else_match.fixed b/src/tools/clippy/tests/ui/manual_let_else_match.fixed new file mode 100644 index 000000000..09b713f04 --- /dev/null +++ b/src/tools/clippy/tests/ui/manual_let_else_match.fixed @@ -0,0 +1,135 @@ +#![allow(unused_braces, unused_variables, dead_code)] +#![allow( + clippy::collapsible_else_if, + clippy::let_unit_value, + clippy::redundant_at_rest_pattern +)] +#![warn(clippy::manual_let_else)] +// Ensure that we don't conflict with match -> if let lints +#![warn(clippy::single_match_else, clippy::single_match)] + +fn f() -> Result { + Ok(0) +} + +fn g() -> Option<()> { + None +} + +fn h() -> (Option<()>, Option<()>) { + (None, None) +} + +enum Variant { + Foo, + Bar(u32), + Baz(u32), +} + +fn build_enum() -> Variant { + Variant::Foo +} + +fn main() {} + +fn fire() { + let Some(v) = g() else { return }; + + let Some(v) = g() else { return }; + + loop { + // More complex pattern for the identity arm and diverging arm + let ((Some(v), None) | (None, Some(v))) = h() else { continue }; + // Custom enums are supported as long as the "else" arm is a simple _ + let (Variant::Bar(v) | Variant::Baz(v)) = build_enum() else { continue }; + } + + // There is a _ in the diverging arm + // TODO also support unused bindings aka _v + let Ok(v) = f() else { return }; + + // Err(()) is an allowed pattern + let Ok(v) = f().map_err(|_| ()) else { return }; + + let f = Variant::Bar(1); + + let (Variant::Bar(_value) | Variant::Baz(_value)) = f else { return }; + + let Some(Variant::Bar(_value) | Variant::Baz(_value)) = Some(build_enum()) else { return }; + + let data = [1_u8, 2, 3, 4, 0, 0, 0, 0]; + let ([data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0]) = data.as_slice() else { return }; +} + +fn not_fire() { + // Multiple diverging arms + let v = match h() { + _ => panic!(), + (None, Some(_v)) => return, + (Some(v), None) => v, + }; + + // Multiple identity arms + let v = match h() { + _ => panic!(), + (None, Some(v)) => v, + (Some(v), None) => v, + }; + + // No diverging arm at all, only identity arms. + // This is no case for let else, but destructuring assignment. + let v = match f() { + Ok(v) => v, + Err(e) => e, + }; + + // The identity arm has a guard + let v = match g() { + Some(v) if g().is_none() => v, + _ => return, + }; + + // The diverging arm has a guard + let v = match f() { + Err(v) if v > 0 => panic!(), + Ok(v) | Err(v) => v, + }; + + // The diverging arm creates a binding + let v = match f() { + Ok(v) => v, + Err(e) => panic!("error: {e}"), + }; + + // Custom enum where the diverging arm + // explicitly mentions the variant + let v = match build_enum() { + Variant::Foo => return, + Variant::Bar(v) | Variant::Baz(v) => v, + }; + + // The custom enum is surrounded by an Err() + let v = match Err(build_enum()) { + Ok(v) | Err(Variant::Bar(v) | Variant::Baz(v)) => v, + Err(Variant::Foo) => return, + }; + + // Issue 10241 + // The non-divergent arm arrives in second position and + // may cover values already matched in the first arm. + let v = match h() { + (Some(_), Some(_)) | (None, None) => return, + (Some(v), _) | (None, Some(v)) => v, + }; + + let v = match build_enum() { + _ => return, + Variant::Bar(v) | Variant::Baz(v) => v, + }; + + let data = [1_u8, 2, 3, 4, 0, 0, 0, 0]; + let data = match data.as_slice() { + [] | [0, 0] => return, + [data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ ..] => data, + }; +} diff --git a/src/tools/clippy/tests/ui/manual_let_else_match.rs b/src/tools/clippy/tests/ui/manual_let_else_match.rs index 73ff69eec..e6af47384 100644 --- a/src/tools/clippy/tests/ui/manual_let_else_match.rs +++ b/src/tools/clippy/tests/ui/manual_let_else_match.rs @@ -34,11 +34,14 @@ fn main() {} fn fire() { let v = match g() { + //~^ ERROR: this could be rewritten as `let...else` + //~| NOTE: `-D clippy::manual-let-else` implied by `-D warnings` Some(v_some) => v_some, None => return, }; let v = match g() { + //~^ ERROR: this could be rewritten as `let...else` Some(v_some) => v_some, _ => return, }; @@ -46,11 +49,13 @@ fn fire() { loop { // More complex pattern for the identity arm and diverging arm let v = match h() { + //~^ ERROR: this could be rewritten as `let...else` (Some(v), None) | (None, Some(v)) => v, (Some(_), Some(_)) | (None, None) => continue, }; // Custom enums are supported as long as the "else" arm is a simple _ let v = match build_enum() { + //~^ ERROR: this could be rewritten as `let...else` Variant::Bar(v) | Variant::Baz(v) => v, _ => continue, }; @@ -59,12 +64,14 @@ fn fire() { // There is a _ in the diverging arm // TODO also support unused bindings aka _v let v = match f() { + //~^ ERROR: this could be rewritten as `let...else` Ok(v) => v, Err(_) => return, }; // Err(()) is an allowed pattern let v = match f().map_err(|_| ()) { + //~^ ERROR: this could be rewritten as `let...else` Ok(v) => v, Err(()) => return, }; @@ -72,17 +79,20 @@ fn fire() { let f = Variant::Bar(1); let _value = match f { + //~^ ERROR: this could be rewritten as `let...else` Variant::Bar(v) | Variant::Baz(v) => v, _ => return, }; let _value = match Some(build_enum()) { + //~^ ERROR: this could be rewritten as `let...else` Some(Variant::Bar(v) | Variant::Baz(v)) => v, _ => return, }; let data = [1_u8, 2, 3, 4, 0, 0, 0, 0]; let data = match data.as_slice() { + //~^ ERROR: this could be rewritten as `let...else` [data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0] => data, _ => return, }; diff --git a/src/tools/clippy/tests/ui/manual_let_else_match.stderr b/src/tools/clippy/tests/ui/manual_let_else_match.stderr index 3fd9a6376..8ca2c8407 100644 --- a/src/tools/clippy/tests/ui/manual_let_else_match.stderr +++ b/src/tools/clippy/tests/ui/manual_let_else_match.stderr @@ -2,80 +2,91 @@ error: this could be rewritten as `let...else` --> $DIR/manual_let_else_match.rs:36:5 | LL | / let v = match g() { +LL | | +LL | | LL | | Some(v_some) => v_some, LL | | None => return, LL | | }; | |______^ help: consider writing: `let Some(v) = g() else { return };` | = note: `-D clippy::manual-let-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:41:5 + --> $DIR/manual_let_else_match.rs:43:5 | LL | / let v = match g() { +LL | | LL | | Some(v_some) => v_some, LL | | _ => return, LL | | }; | |______^ help: consider writing: `let Some(v) = g() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:48:9 + --> $DIR/manual_let_else_match.rs:51:9 | LL | / let v = match h() { +LL | | LL | | (Some(v), None) | (None, Some(v)) => v, LL | | (Some(_), Some(_)) | (None, None) => continue, LL | | }; | |__________^ help: consider writing: `let ((Some(v), None) | (None, Some(v))) = h() else { continue };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:53:9 + --> $DIR/manual_let_else_match.rs:57:9 | LL | / let v = match build_enum() { +LL | | LL | | Variant::Bar(v) | Variant::Baz(v) => v, LL | | _ => continue, LL | | }; | |__________^ help: consider writing: `let (Variant::Bar(v) | Variant::Baz(v)) = build_enum() else { continue };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:61:5 + --> $DIR/manual_let_else_match.rs:66:5 | LL | / let v = match f() { +LL | | LL | | Ok(v) => v, LL | | Err(_) => return, LL | | }; | |______^ help: consider writing: `let Ok(v) = f() else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:67:5 + --> $DIR/manual_let_else_match.rs:73:5 | LL | / let v = match f().map_err(|_| ()) { +LL | | LL | | Ok(v) => v, LL | | Err(()) => return, LL | | }; | |______^ help: consider writing: `let Ok(v) = f().map_err(|_| ()) else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:74:5 + --> $DIR/manual_let_else_match.rs:81:5 | LL | / let _value = match f { +LL | | LL | | Variant::Bar(v) | Variant::Baz(v) => v, LL | | _ => return, LL | | }; | |______^ help: consider writing: `let (Variant::Bar(_value) | Variant::Baz(_value)) = f else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:79:5 + --> $DIR/manual_let_else_match.rs:87:5 | LL | / let _value = match Some(build_enum()) { +LL | | LL | | Some(Variant::Bar(v) | Variant::Baz(v)) => v, LL | | _ => return, LL | | }; | |______^ help: consider writing: `let Some(Variant::Bar(_value) | Variant::Baz(_value)) = Some(build_enum()) else { return };` error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_match.rs:85:5 + --> $DIR/manual_let_else_match.rs:94:5 | LL | / let data = match data.as_slice() { +LL | | LL | | [data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0] => data, LL | | _ => return, LL | | }; diff --git a/src/tools/clippy/tests/ui/manual_let_else_question_mark.fixed b/src/tools/clippy/tests/ui/manual_let_else_question_mark.fixed index 02308bc7c..b555186cc 100644 --- a/src/tools/clippy/tests/ui/manual_let_else_question_mark.fixed +++ b/src/tools/clippy/tests/ui/manual_let_else_question_mark.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused_braces, unused_variables, dead_code)] #![allow( clippy::collapsible_else_if, diff --git a/src/tools/clippy/tests/ui/manual_let_else_question_mark.rs b/src/tools/clippy/tests/ui/manual_let_else_question_mark.rs index 9c7ad386d..5852c7094 100644 --- a/src/tools/clippy/tests/ui/manual_let_else_question_mark.rs +++ b/src/tools/clippy/tests/ui/manual_let_else_question_mark.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused_braces, unused_variables, dead_code)] #![allow( clippy::collapsible_else_if, diff --git a/src/tools/clippy/tests/ui/manual_let_else_question_mark.stderr b/src/tools/clippy/tests/ui/manual_let_else_question_mark.stderr index d7d2e127e..bf0b1bbf0 100644 --- a/src/tools/clippy/tests/ui/manual_let_else_question_mark.stderr +++ b/src/tools/clippy/tests/ui/manual_let_else_question_mark.stderr @@ -1,25 +1,26 @@ error: this `let...else` may be rewritten with the `?` operator - --> $DIR/manual_let_else_question_mark.rs:30:5 + --> $DIR/manual_let_else_question_mark.rs:29:5 | LL | let Some(v) = g() else { return None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `let v = g()?;` | = note: `-D clippy::question-mark` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::question_mark)]` error: this `let...else` may be rewritten with the `?` operator - --> $DIR/manual_let_else_question_mark.rs:36:5 + --> $DIR/manual_let_else_question_mark.rs:35:5 | LL | let Some((v, w)) = g() else { return None }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `let (v, w) = g()?;` error: this block may be rewritten with the `?` operator - --> $DIR/manual_let_else_question_mark.rs:39:13 + --> $DIR/manual_let_else_question_mark.rs:38:13 | 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:43:5 + --> $DIR/manual_let_else_question_mark.rs:42:5 | LL | / let v = if let Some(v_some) = g() { LL | | v_some @@ -29,6 +30,7 @@ LL | | }; | |______^ | = note: `-D clippy::manual-let-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]` help: consider writing | LL ~ let Some(v) = g() else { @@ -37,7 +39,7 @@ LL + }; | error: this could be rewritten as `let...else` - --> $DIR/manual_let_else_question_mark.rs:54:9 + --> $DIR/manual_let_else_question_mark.rs:53:9 | LL | / let v = match g() { LL | | Some(v_some) => v_some, @@ -46,7 +48,7 @@ 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:64:9 + --> $DIR/manual_let_else_question_mark.rs:63: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 };` diff --git a/src/tools/clippy/tests/ui/manual_main_separator_str.fixed b/src/tools/clippy/tests/ui/manual_main_separator_str.fixed index 7e7da8f20..6441d6ede 100644 --- a/src/tools/clippy/tests/ui/manual_main_separator_str.fixed +++ b/src/tools/clippy/tests/ui/manual_main_separator_str.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_main_separator_str)] diff --git a/src/tools/clippy/tests/ui/manual_main_separator_str.rs b/src/tools/clippy/tests/ui/manual_main_separator_str.rs index cf90e12ef..339dfd8bb 100644 --- a/src/tools/clippy/tests/ui/manual_main_separator_str.rs +++ b/src/tools/clippy/tests/ui/manual_main_separator_str.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_main_separator_str)] diff --git a/src/tools/clippy/tests/ui/manual_main_separator_str.stderr b/src/tools/clippy/tests/ui/manual_main_separator_str.stderr index e6cefde66..3e92bd023 100644 --- a/src/tools/clippy/tests/ui/manual_main_separator_str.stderr +++ b/src/tools/clippy/tests/ui/manual_main_separator_str.stderr @@ -1,25 +1,26 @@ error: taking a reference on `std::path::MAIN_SEPARATOR` conversion to `String` - --> $DIR/manual_main_separator_str.rs:23:19 + --> $DIR/manual_main_separator_str.rs:21:19 | LL | let _: &str = &MAIN_SEPARATOR.to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `std::path::MAIN_SEPARATOR_STR` | = note: `-D clippy::manual-main-separator-str` implied by `-D warnings` + = 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:24:17 + --> $DIR/manual_main_separator_str.rs:22: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:25:23 + --> $DIR/manual_main_separator_str.rs:23: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:29:12 + --> $DIR/manual_main_separator_str.rs:27:12 | LL | f: &MAIN_SEPARATOR.to_string(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `std::path::MAIN_SEPARATOR_STR` diff --git a/src/tools/clippy/tests/ui/manual_map_option.fixed b/src/tools/clippy/tests/ui/manual_map_option.fixed index e8ff65cad..16cee3fd3 100644 --- a/src/tools/clippy/tests/ui/manual_map_option.fixed +++ b/src/tools/clippy/tests/ui/manual_map_option.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_map)] #![allow( clippy::no_effect, @@ -7,6 +5,7 @@ clippy::unit_arg, clippy::match_ref_pats, clippy::redundant_pattern_matching, + clippy::unnecessary_map_on_constructor, for_loops_over_fallibles, dead_code )] diff --git a/src/tools/clippy/tests/ui/manual_map_option.rs b/src/tools/clippy/tests/ui/manual_map_option.rs index b06a96451..4655acf14 100644 --- a/src/tools/clippy/tests/ui/manual_map_option.rs +++ b/src/tools/clippy/tests/ui/manual_map_option.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_map)] #![allow( clippy::no_effect, @@ -7,6 +5,7 @@ clippy::unit_arg, clippy::match_ref_pats, clippy::redundant_pattern_matching, + clippy::unnecessary_map_on_constructor, for_loops_over_fallibles, dead_code )] diff --git a/src/tools/clippy/tests/ui/manual_map_option.stderr b/src/tools/clippy/tests/ui/manual_map_option.stderr index 3f9caad4e..3754a982c 100644 --- a/src/tools/clippy/tests/ui/manual_map_option.stderr +++ b/src/tools/clippy/tests/ui/manual_map_option.stderr @@ -1,5 +1,5 @@ error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:15:5 + --> $DIR/manual_map_option.rs:14:5 | LL | / match Some(0) { LL | | Some(_) => Some(2), @@ -8,9 +8,10 @@ LL | | }; | |_____^ help: try: `Some(0).map(|_| 2)` | = note: `-D clippy::manual-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_map)]` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:20:5 + --> $DIR/manual_map_option.rs:19:5 | LL | / match Some(0) { LL | | Some(x) => Some(x + 1), @@ -19,7 +20,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| x + 1)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:25:5 + --> $DIR/manual_map_option.rs:24:5 | LL | / match Some("") { LL | | Some(x) => Some(x.is_empty()), @@ -28,7 +29,7 @@ LL | | }; | |_____^ help: try: `Some("").map(|x| x.is_empty())` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:30:5 + --> $DIR/manual_map_option.rs:29:5 | LL | / if let Some(x) = Some(0) { LL | | Some(!x) @@ -38,7 +39,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| !x)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:37:5 + --> $DIR/manual_map_option.rs:36:5 | LL | / match Some(0) { LL | | Some(x) => { Some(std::convert::identity(x)) } @@ -47,7 +48,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(std::convert::identity)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:42:5 + --> $DIR/manual_map_option.rs:41:5 | LL | / match Some(&String::new()) { LL | | Some(x) => Some(str::len(x)), @@ -56,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:52:5 + --> $DIR/manual_map_option.rs:51:5 | LL | / match &Some([0, 1]) { LL | | Some(x) => Some(x[0]), @@ -65,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:57:5 + --> $DIR/manual_map_option.rs:56:5 | LL | / match &Some(0) { LL | | &Some(x) => Some(x * 2), @@ -74,7 +75,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| x * 2)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:62:5 + --> $DIR/manual_map_option.rs:61:5 | LL | / match Some(String::new()) { LL | | Some(ref x) => Some(x.is_empty()), @@ -83,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:67:5 + --> $DIR/manual_map_option.rs:66:5 | LL | / match &&Some(String::new()) { LL | | Some(x) => Some(x.len()), @@ -92,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:72:5 + --> $DIR/manual_map_option.rs:71:5 | LL | / match &&Some(0) { LL | | &&Some(x) => Some(x + x), @@ -101,7 +102,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| x + x)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:85:9 + --> $DIR/manual_map_option.rs:84:9 | LL | / match &mut Some(String::new()) { LL | | Some(x) => Some(x.push_str("")), @@ -110,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:91:5 + --> $DIR/manual_map_option.rs:90:5 | LL | / match &mut Some(String::new()) { LL | | Some(ref x) => Some(x.len()), @@ -119,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:96:5 + --> $DIR/manual_map_option.rs:95:5 | LL | / match &mut &Some(String::new()) { LL | | Some(x) => Some(x.is_empty()), @@ -128,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:101:5 + --> $DIR/manual_map_option.rs:100:5 | LL | / match Some((0, 1, 2)) { LL | | Some((x, y, z)) => Some(x + y + z), @@ -137,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:106:5 + --> $DIR/manual_map_option.rs:105:5 | LL | / match Some([1, 2, 3]) { LL | | Some([first, ..]) => Some(first), @@ -146,7 +147,7 @@ LL | | }; | |_____^ help: try: `Some([1, 2, 3]).map(|[first, ..]| first)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:111:5 + --> $DIR/manual_map_option.rs:110:5 | LL | / match &Some((String::new(), "test")) { LL | | Some((x, y)) => Some((y, x)), @@ -155,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:169:5 + --> $DIR/manual_map_option.rs:168:5 | LL | / match Some(0) { LL | | Some(x) => Some(vec![x]), @@ -164,7 +165,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| vec![x])` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:174:5 + --> $DIR/manual_map_option.rs:173:5 | LL | / match option_env!("") { LL | | Some(x) => Some(String::from(x)), @@ -173,7 +174,7 @@ LL | | }; | |_____^ help: try: `option_env!("").map(String::from)` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:194:12 + --> $DIR/manual_map_option.rs:193:12 | LL | } else if let Some(x) = Some(0) { | ____________^ @@ -184,7 +185,7 @@ LL | | }; | |_____^ help: try: `{ Some(0).map(|x| x + 1) }` error: manual implementation of `Option::map` - --> $DIR/manual_map_option.rs:202:12 + --> $DIR/manual_map_option.rs:201:12 | LL | } else if let Some(x) = Some(0) { | ____________^ diff --git a/src/tools/clippy/tests/ui/manual_map_option_2.fixed b/src/tools/clippy/tests/ui/manual_map_option_2.fixed index dc7228782..513f6e323 100644 --- a/src/tools/clippy/tests/ui/manual_map_option_2.fixed +++ b/src/tools/clippy/tests/ui/manual_map_option_2.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_map)] #![allow(clippy::toplevel_ref_arg)] diff --git a/src/tools/clippy/tests/ui/manual_map_option_2.rs b/src/tools/clippy/tests/ui/manual_map_option_2.rs index c495ab0fa..fd186743f 100644 --- a/src/tools/clippy/tests/ui/manual_map_option_2.rs +++ b/src/tools/clippy/tests/ui/manual_map_option_2.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_map)] #![allow(clippy::toplevel_ref_arg)] diff --git a/src/tools/clippy/tests/ui/manual_map_option_2.stderr b/src/tools/clippy/tests/ui/manual_map_option_2.stderr index 8c78fcffc..bf242c041 100644 --- a/src/tools/clippy/tests/ui/manual_map_option_2.stderr +++ b/src/tools/clippy/tests/ui/manual_map_option_2.stderr @@ -1,5 +1,5 @@ error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:8:13 + --> $DIR/manual_map_option_2.rs:6:13 | LL | let _ = match Some(0) { | _____________^ @@ -12,6 +12,7 @@ LL | | }; | |_____^ | = note: `-D clippy::manual-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_map)]` help: try | LL ~ let _ = Some(0).map(|x| { @@ -21,7 +22,7 @@ LL ~ }); | error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:50:13 + --> $DIR/manual_map_option_2.rs:48:13 | LL | let _ = match &s { | _____________^ @@ -40,7 +41,7 @@ LL ~ }); | error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:62:17 + --> $DIR/manual_map_option_2.rs:60:17 | LL | let _ = match Some(0) { | _________________^ @@ -50,7 +51,7 @@ LL | | }; | |_________^ help: try: `Some(0).map(|x| f(x))` error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:67:13 + --> $DIR/manual_map_option_2.rs:65:13 | LL | let _ = match Some(0) { | _____________^ @@ -60,7 +61,7 @@ LL | | }; | |_____^ help: try: `Some(0).map(|x| unsafe { f(x) })` error: manual implementation of `Option::map` - --> $DIR/manual_map_option_2.rs:71:13 + --> $DIR/manual_map_option_2.rs:69:13 | LL | let _ = match Some(0) { | _____________^ diff --git a/src/tools/clippy/tests/ui/manual_memcpy/with_loop_counters.rs b/src/tools/clippy/tests/ui/manual_memcpy/with_loop_counters.rs index c826b082a..786d7e6e2 100644 --- a/src/tools/clippy/tests/ui/manual_memcpy/with_loop_counters.rs +++ b/src/tools/clippy/tests/ui/manual_memcpy/with_loop_counters.rs @@ -1,50 +1,59 @@ #![warn(clippy::needless_range_loop, clippy::manual_memcpy)] - +//@no-rustfix pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let mut count = 0; for i in 3..src.len() { + //~^ ERROR: it looks like you're manually copying between slices + //~| NOTE: `-D clippy::manual-memcpy` implied by `-D warnings` dst[i] = src[count]; count += 1; } let mut count = 0; for i in 3..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[count] = src[i]; count += 1; } let mut count = 3; for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[count] = src[i]; count += 1; } let mut count = 3; for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1; } let mut count = 0; for i in 3..(3 + src.len()) { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1; } let mut count = 3; for i in 5..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count - 2]; count += 1; } let mut count = 2; for i in 0..dst.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1; } let mut count = 5; for i in 3..10 { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1; } @@ -52,6 +61,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) let mut count = 3; let mut count2 = 30; for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[count] = src[i]; dst2[count2] = src[i]; count += 1; @@ -62,6 +72,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) // arithmetic ones let mut count = 0 << 1; for i in 0..1 << 1 { + //~^ ERROR: it looks like you're manually copying between slices dst[count] = src[i + 2]; count += 1; } @@ -69,6 +80,7 @@ pub fn manual_copy_with_counters(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) // make sure incrementing expressions without semicolons at the end of loops are handled correctly. let mut count = 0; for i in 3..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[count]; count += 1 } diff --git a/src/tools/clippy/tests/ui/manual_memcpy/with_loop_counters.stderr b/src/tools/clippy/tests/ui/manual_memcpy/with_loop_counters.stderr index 79d40c0bc..3f000fbab 100644 --- a/src/tools/clippy/tests/ui/manual_memcpy/with_loop_counters.stderr +++ b/src/tools/clippy/tests/ui/manual_memcpy/with_loop_counters.stderr @@ -2,80 +2,91 @@ error: it looks like you're manually copying between slices --> $DIR/with_loop_counters.rs:5:5 | LL | / for i in 3..src.len() { +LL | | +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[3..src.len()].copy_from_slice(&src[..(src.len() - 3)]);` | = note: `-D clippy::manual-memcpy` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_memcpy)]` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:11:5 + --> $DIR/with_loop_counters.rs:13:5 | LL | / for i in 3..src.len() { +LL | | LL | | dst[count] = src[i]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[..(src.len() - 3)].copy_from_slice(&src[3..]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:17:5 + --> $DIR/with_loop_counters.rs:20:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[count] = src[i]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[3..(src.len() + 3)].copy_from_slice(&src[..]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:23:5 + --> $DIR/with_loop_counters.rs:27:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[..src.len()].copy_from_slice(&src[3..(src.len() + 3)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:29:5 + --> $DIR/with_loop_counters.rs:34:5 | LL | / for i in 3..(3 + src.len()) { +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[3..(3 + src.len())].copy_from_slice(&src[..(3 + src.len() - 3)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:35:5 + --> $DIR/with_loop_counters.rs:41:5 | LL | / for i in 5..src.len() { +LL | | LL | | dst[i] = src[count - 2]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[5..src.len()].copy_from_slice(&src[(3 - 2)..((src.len() - 2) + 3 - 5)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:41:5 + --> $DIR/with_loop_counters.rs:48:5 | LL | / for i in 0..dst.len() { +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[2..(dst.len() + 2)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:47:5 + --> $DIR/with_loop_counters.rs:55:5 | LL | / for i in 3..10 { +LL | | LL | | dst[i] = src[count]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[3..10].copy_from_slice(&src[5..(10 + 5 - 3)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:54:5 + --> $DIR/with_loop_counters.rs:63:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[count] = src[i]; LL | | dst2[count2] = src[i]; LL | | count += 1; @@ -90,18 +101,20 @@ LL + dst2[30..(src.len() + 30)].copy_from_slice(&src[..]); | error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:64:5 + --> $DIR/with_loop_counters.rs:74:5 | LL | / for i in 0..1 << 1 { +LL | | LL | | dst[count] = src[i + 2]; LL | | count += 1; LL | | } | |_____^ help: try replacing the loop by: `dst[(0 << 1)..((1 << 1) + (0 << 1))].copy_from_slice(&src[2..((1 << 1) + 2)]);` error: it looks like you're manually copying between slices - --> $DIR/with_loop_counters.rs:71:5 + --> $DIR/with_loop_counters.rs:82:5 | LL | / for i in 3..src.len() { +LL | | LL | | dst[i] = src[count]; LL | | count += 1 LL | | } diff --git a/src/tools/clippy/tests/ui/manual_memcpy/without_loop_counters.rs b/src/tools/clippy/tests/ui/manual_memcpy/without_loop_counters.rs index 4d5c70f19..a224001a3 100644 --- a/src/tools/clippy/tests/ui/manual_memcpy/without_loop_counters.rs +++ b/src/tools/clippy/tests/ui/manual_memcpy/without_loop_counters.rs @@ -1,31 +1,37 @@ #![warn(clippy::needless_range_loop, clippy::manual_memcpy)] #![allow(clippy::useless_vec)] - +//@no-rustfix const LOOP_OFFSET: usize = 5000; pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { // plain manual memcpy for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices + //~| NOTE: `-D clippy::manual-memcpy` implied by `-D warnings` dst[i] = src[i]; } // dst offset memcpy for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i + 10] = src[i]; } // src offset memcpy for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i + 10]; } // src offset memcpy for i in 11..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i - 10]; } // overwrite entire dst for i in 0..dst.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i]; } @@ -39,6 +45,7 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { // multiple copies - suggest two memcpy statements for i in 10..256 { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i - 5]; dst2[i + 500] = src[i] } @@ -51,6 +58,7 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let some_var = 5; // Offset in variable for i in 10..LOOP_OFFSET { + //~^ ERROR: it looks like you're manually copying between slices dst[i + LOOP_OFFSET] = src[i - some_var]; } @@ -64,6 +72,7 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { // make sure vectors are supported for i in 0..src_vec.len() { + //~^ ERROR: it looks like you're manually copying between slices dst_vec[i] = src_vec[i]; } @@ -93,20 +102,24 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { let from = 1; for i in from..from + src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i - from]; } for i in from..from + 3 { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i - from]; } #[allow(clippy::identity_op)] for i in 0..5 { + //~^ ERROR: it looks like you're manually copying between slices dst[i - 0] = src[i]; } #[allow(clippy::reversed_empty_ranges)] for i in 0..0 { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i]; } @@ -130,6 +143,7 @@ pub fn manual_copy(src: &[i32], dst: &mut [i32], dst2: &mut [i32]) { #[warn(clippy::needless_range_loop, clippy::manual_memcpy)] pub fn manual_clone(src: &[String], dst: &mut [String]) { for i in 0..src.len() { + //~^ ERROR: it looks like you're manually copying between slices dst[i] = src[i].clone(); } } diff --git a/src/tools/clippy/tests/ui/manual_memcpy/without_loop_counters.stderr b/src/tools/clippy/tests/ui/manual_memcpy/without_loop_counters.stderr index 1c6a7d5c0..b9dbda6ed 100644 --- a/src/tools/clippy/tests/ui/manual_memcpy/without_loop_counters.stderr +++ b/src/tools/clippy/tests/ui/manual_memcpy/without_loop_counters.stderr @@ -2,48 +2,56 @@ error: it looks like you're manually copying between slices --> $DIR/without_loop_counters.rs:8:5 | LL | / for i in 0..src.len() { +LL | | +LL | | LL | | dst[i] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst[..src.len()].copy_from_slice(&src[..]);` | = note: `-D clippy::manual-memcpy` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_memcpy)]` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:13:5 + --> $DIR/without_loop_counters.rs:15:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[i + 10] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst[10..(src.len() + 10)].copy_from_slice(&src[..]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:18:5 + --> $DIR/without_loop_counters.rs:21:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[i] = src[i + 10]; LL | | } | |_____^ help: try replacing the loop by: `dst[..src.len()].copy_from_slice(&src[10..(src.len() + 10)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:23:5 + --> $DIR/without_loop_counters.rs:27:5 | LL | / for i in 11..src.len() { +LL | | LL | | dst[i] = src[i - 10]; LL | | } | |_____^ help: try replacing the loop by: `dst[11..src.len()].copy_from_slice(&src[(11 - 10)..(src.len() - 10)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:28:5 + --> $DIR/without_loop_counters.rs:33:5 | LL | / for i in 0..dst.len() { +LL | | LL | | dst[i] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst.copy_from_slice(&src[..dst.len()]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:41:5 + --> $DIR/without_loop_counters.rs:47:5 | LL | / for i in 10..256 { +LL | | LL | | dst[i] = src[i - 5]; LL | | dst2[i + 500] = src[i] LL | | } @@ -56,57 +64,64 @@ LL + dst2[(10 + 500)..(256 + 500)].copy_from_slice(&src[10..256]); | error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:53:5 + --> $DIR/without_loop_counters.rs:60:5 | LL | / for i in 10..LOOP_OFFSET { +LL | | LL | | dst[i + LOOP_OFFSET] = src[i - some_var]; LL | | } | |_____^ help: try replacing the loop by: `dst[(10 + LOOP_OFFSET)..(LOOP_OFFSET + LOOP_OFFSET)].copy_from_slice(&src[(10 - some_var)..(LOOP_OFFSET - some_var)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:66:5 + --> $DIR/without_loop_counters.rs:74:5 | LL | / for i in 0..src_vec.len() { +LL | | LL | | dst_vec[i] = src_vec[i]; LL | | } | |_____^ help: try replacing the loop by: `dst_vec[..src_vec.len()].copy_from_slice(&src_vec[..]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:95:5 + --> $DIR/without_loop_counters.rs:104:5 | LL | / for i in from..from + src.len() { +LL | | LL | | dst[i] = src[i - from]; LL | | } | |_____^ help: try replacing the loop by: `dst[from..(from + src.len())].copy_from_slice(&src[..(from + src.len() - from)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:99:5 + --> $DIR/without_loop_counters.rs:109:5 | LL | / for i in from..from + 3 { +LL | | LL | | dst[i] = src[i - from]; LL | | } | |_____^ help: try replacing the loop by: `dst[from..(from + 3)].copy_from_slice(&src[..(from + 3 - from)]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:104:5 + --> $DIR/without_loop_counters.rs:115:5 | LL | / for i in 0..5 { +LL | | LL | | dst[i - 0] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst[..5].copy_from_slice(&src[..5]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:109:5 + --> $DIR/without_loop_counters.rs:121:5 | LL | / for i in 0..0 { +LL | | LL | | dst[i] = src[i]; LL | | } | |_____^ help: try replacing the loop by: `dst[..0].copy_from_slice(&src[..0]);` error: it looks like you're manually copying between slices - --> $DIR/without_loop_counters.rs:132:5 + --> $DIR/without_loop_counters.rs:145:5 | LL | / for i in 0..src.len() { +LL | | LL | | dst[i] = src[i].clone(); LL | | } | |_____^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..]);` diff --git a/src/tools/clippy/tests/ui/manual_next_back.fixed b/src/tools/clippy/tests/ui/manual_next_back.fixed index e8a47063a..75828f355 100644 --- a/src/tools/clippy/tests/ui/manual_next_back.fixed +++ b/src/tools/clippy/tests/ui/manual_next_back.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_next_back)] diff --git a/src/tools/clippy/tests/ui/manual_next_back.rs b/src/tools/clippy/tests/ui/manual_next_back.rs index 9ec892422..b980e90e1 100644 --- a/src/tools/clippy/tests/ui/manual_next_back.rs +++ b/src/tools/clippy/tests/ui/manual_next_back.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_next_back)] diff --git a/src/tools/clippy/tests/ui/manual_next_back.stderr b/src/tools/clippy/tests/ui/manual_next_back.stderr index 94ccaa9e4..a63d266dd 100644 --- a/src/tools/clippy/tests/ui/manual_next_back.stderr +++ b/src/tools/clippy/tests/ui/manual_next_back.stderr @@ -1,13 +1,14 @@ error: manual backwards iteration - --> $DIR/manual_next_back.rs:34:20 + --> $DIR/manual_next_back.rs:32:20 | LL | let _ = (0..10).rev().next().unwrap(); | ^^^^^^^^^^^^^ help: use: `.next_back()` | = note: `-D clippy::manual-next-back` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_next_back)]` error: manual backwards iteration - --> $DIR/manual_next_back.rs:35:32 + --> $DIR/manual_next_back.rs:33:32 | LL | let _ = "something".bytes().rev().next(); | ^^^^^^^^^^^^^ help: use: `.next_back()` diff --git a/src/tools/clippy/tests/ui/manual_non_exhaustive_enum.rs b/src/tools/clippy/tests/ui/manual_non_exhaustive_enum.rs index 03b2433f6..0e439dabf 100644 --- a/src/tools/clippy/tests/ui/manual_non_exhaustive_enum.rs +++ b/src/tools/clippy/tests/ui/manual_non_exhaustive_enum.rs @@ -1,8 +1,9 @@ #![feature(lint_reasons)] #![warn(clippy::manual_non_exhaustive)] #![allow(unused)] - +//@no-rustfix enum E { + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern A, B, #[doc(hidden)] @@ -12,6 +13,7 @@ enum E { // user forgot to remove the marker #[non_exhaustive] enum Ep { + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern A, B, #[doc(hidden)] diff --git a/src/tools/clippy/tests/ui/manual_non_exhaustive_enum.stderr b/src/tools/clippy/tests/ui/manual_non_exhaustive_enum.stderr index 087f766be..ce7e21c94 100644 --- a/src/tools/clippy/tests/ui/manual_non_exhaustive_enum.stderr +++ b/src/tools/clippy/tests/ui/manual_non_exhaustive_enum.stderr @@ -6,6 +6,7 @@ LL | enum E { | | | _help: add the attribute: `#[non_exhaustive] enum E` | | +LL | | LL | | A, LL | | B, LL | | #[doc(hidden)] @@ -14,16 +15,18 @@ LL | | } | |_^ | help: remove this variant - --> $DIR/manual_non_exhaustive_enum.rs:9:5 + --> $DIR/manual_non_exhaustive_enum.rs:10:5 | LL | _C, | ^^ = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings` + = 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:14:1 + --> $DIR/manual_non_exhaustive_enum.rs:15:1 | LL | / enum Ep { +LL | | LL | | A, LL | | B, LL | | #[doc(hidden)] @@ -32,7 +35,7 @@ LL | | } | |_^ | help: remove this variant - --> $DIR/manual_non_exhaustive_enum.rs:18:5 + --> $DIR/manual_non_exhaustive_enum.rs:20:5 | LL | _C, | ^^ diff --git a/src/tools/clippy/tests/ui/manual_non_exhaustive_struct.rs b/src/tools/clippy/tests/ui/manual_non_exhaustive_struct.rs index 498eee444..4b2803ccc 100644 --- a/src/tools/clippy/tests/ui/manual_non_exhaustive_struct.rs +++ b/src/tools/clippy/tests/ui/manual_non_exhaustive_struct.rs @@ -1,8 +1,9 @@ #![warn(clippy::manual_non_exhaustive)] #![allow(unused)] - +//@no-rustfix mod structs { struct S { + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern pub a: i32, pub b: i32, _c: (), @@ -11,6 +12,7 @@ mod structs { // user forgot to remove the private field #[non_exhaustive] struct Sp { + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern pub a: i32, pub b: i32, _c: (), @@ -52,10 +54,12 @@ mod structs { mod tuple_structs { struct T(pub i32, pub i32, ()); + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern // user forgot to remove the private field #[non_exhaustive] struct Tp(pub i32, pub i32, ()); + //~^ ERROR: this seems like a manual implementation of the non-exhaustive pattern // some other fields are private, should be ignored struct PrivateFields(pub i32, i32, ()); diff --git a/src/tools/clippy/tests/ui/manual_non_exhaustive_struct.stderr b/src/tools/clippy/tests/ui/manual_non_exhaustive_struct.stderr index d0bed8e11..028b8ff76 100644 --- a/src/tools/clippy/tests/ui/manual_non_exhaustive_struct.stderr +++ b/src/tools/clippy/tests/ui/manual_non_exhaustive_struct.stderr @@ -6,6 +6,7 @@ LL | struct S { | | | _____help: add the attribute: `#[non_exhaustive] struct S` | | +LL | | LL | | pub a: i32, LL | | pub b: i32, LL | | _c: (), @@ -13,16 +14,18 @@ LL | | } | |_____^ | help: remove this field - --> $DIR/manual_non_exhaustive_struct.rs:8:9 + --> $DIR/manual_non_exhaustive_struct.rs:9:9 | LL | _c: (), | ^^^^^^ = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings` + = 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_struct.rs:13:5 + --> $DIR/manual_non_exhaustive_struct.rs:14:5 | LL | / struct Sp { +LL | | LL | | pub a: i32, LL | | pub b: i32, LL | | _c: (), @@ -30,13 +33,13 @@ LL | | } | |_____^ | help: remove this field - --> $DIR/manual_non_exhaustive_struct.rs:16:9 + --> $DIR/manual_non_exhaustive_struct.rs:18:9 | LL | _c: (), | ^^^^^^ error: this seems like a manual implementation of the non-exhaustive pattern - --> $DIR/manual_non_exhaustive_struct.rs:54:5 + --> $DIR/manual_non_exhaustive_struct.rs:56:5 | LL | struct T(pub i32, pub i32, ()); | --------^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,19 +47,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:54:32 + --> $DIR/manual_non_exhaustive_struct.rs:56: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:58:5 + --> $DIR/manual_non_exhaustive_struct.rs:61:5 | LL | struct Tp(pub i32, pub i32, ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove this field - --> $DIR/manual_non_exhaustive_struct.rs:58:33 + --> $DIR/manual_non_exhaustive_struct.rs:61:33 | LL | struct Tp(pub i32, pub i32, ()); | ^^ diff --git a/src/tools/clippy/tests/ui/manual_ok_or.fixed b/src/tools/clippy/tests/ui/manual_ok_or.fixed index d8901dc3b..cc53cb416 100644 --- a/src/tools/clippy/tests/ui/manual_ok_or.fixed +++ b/src/tools/clippy/tests/ui/manual_ok_or.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_ok_or)] #![allow(clippy::or_fun_call)] #![allow(clippy::disallowed_names)] diff --git a/src/tools/clippy/tests/ui/manual_ok_or.rs b/src/tools/clippy/tests/ui/manual_ok_or.rs index 7188a5213..39c61a1e4 100644 --- a/src/tools/clippy/tests/ui/manual_ok_or.rs +++ b/src/tools/clippy/tests/ui/manual_ok_or.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_ok_or)] #![allow(clippy::or_fun_call)] #![allow(clippy::disallowed_names)] diff --git a/src/tools/clippy/tests/ui/manual_ok_or.stderr b/src/tools/clippy/tests/ui/manual_ok_or.stderr index b4a17f143..ddb2cf261 100644 --- a/src/tools/clippy/tests/ui/manual_ok_or.stderr +++ b/src/tools/clippy/tests/ui/manual_ok_or.stderr @@ -1,25 +1,26 @@ error: this pattern reimplements `Option::ok_or` - --> $DIR/manual_ok_or.rs:12:5 + --> $DIR/manual_ok_or.rs:11:5 | LL | foo.map_or(Err("error"), |v| Ok(v)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `foo.ok_or("error")` | = note: `-D clippy::manual-ok-or` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_ok_or)]` error: this pattern reimplements `Option::ok_or` - --> $DIR/manual_ok_or.rs:15:5 + --> $DIR/manual_ok_or.rs:14:5 | LL | foo.map_or(Err("error"), Ok); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `foo.ok_or("error")` error: this pattern reimplements `Option::ok_or` - --> $DIR/manual_ok_or.rs:18:5 + --> $DIR/manual_ok_or.rs:17: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:22:5 + --> $DIR/manual_ok_or.rs:21:5 | LL | / foo.map_or(Err::( LL | | &format!( diff --git a/src/tools/clippy/tests/ui/manual_range_patterns.fixed b/src/tools/clippy/tests/ui/manual_range_patterns.fixed index 6bfcf263a..b348d7071 100644 --- a/src/tools/clippy/tests/ui/manual_range_patterns.fixed +++ b/src/tools/clippy/tests/ui/manual_range_patterns.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_range_patterns)] #![feature(exclusive_range_pattern)] @@ -15,8 +13,8 @@ fn main() { 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..=4); + let _ = matches!(f, 1..4); let _ = matches!(f, 1..=48324729); let _ = matches!(f, 0..=48324730); let _ = matches!(f, 0..=3); @@ -27,9 +25,20 @@ fn main() { }; let _ = matches!(f, -5..=3); let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1); // 2 is missing - let _ = matches!(f, -1000001..=1000001); + let _ = matches!(f, -1_000_001..=1_000_001); let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_002); + matches!(f, 0x00..=0x03); + matches!(f, 0x00..=0x07); + matches!(f, -0x09..=0x00); + + matches!(f, 0..=5); + matches!(f, 0..5); + + matches!(f, 0..10); + matches!(f, 0..=10); + matches!(f, 0..=10); + macro_rules! mac { ($e:expr) => { matches!($e, 1..=10) diff --git a/src/tools/clippy/tests/ui/manual_range_patterns.rs b/src/tools/clippy/tests/ui/manual_range_patterns.rs index 4a429bb2a..a0750f54b 100644 --- a/src/tools/clippy/tests/ui/manual_range_patterns.rs +++ b/src/tools/clippy/tests/ui/manual_range_patterns.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_range_patterns)] #![feature(exclusive_range_pattern)] @@ -30,6 +28,17 @@ fn main() { let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001); let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_002); + matches!(f, 0x00 | 0x01 | 0x02 | 0x03); + matches!(f, 0x00..=0x05 | 0x06 | 0x07); + matches!(f, -0x09 | -0x08 | -0x07..=0x00); + + matches!(f, 0..5 | 5); + matches!(f, 0 | 1..5); + + matches!(f, 0..=5 | 6..10); + matches!(f, 0..5 | 5..=10); + matches!(f, 5..=10 | 0..5); + macro_rules! mac { ($e:expr) => { matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10) diff --git a/src/tools/clippy/tests/ui/manual_range_patterns.stderr b/src/tools/clippy/tests/ui/manual_range_patterns.stderr index b1b55d483..fbeb94557 100644 --- a/src/tools/clippy/tests/ui/manual_range_patterns.stderr +++ b/src/tools/clippy/tests/ui/manual_range_patterns.stderr @@ -1,55 +1,116 @@ error: this OR pattern can be rewritten using a range - --> $DIR/manual_range_patterns.rs:10:25 + --> $DIR/manual_range_patterns.rs:8:25 | LL | let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` | = note: `-D clippy::manual-range-patterns` implied by `-D warnings` + = 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:11:25 + --> $DIR/manual_range_patterns.rs:9: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:20:25 + --> $DIR/manual_range_patterns.rs:16: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 + | +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 | 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:21:25 + --> $DIR/manual_range_patterns.rs:19: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:22:25 + --> $DIR/manual_range_patterns.rs:20: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:25:9 + --> $DIR/manual_range_patterns.rs:23: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:28:25 + --> $DIR/manual_range_patterns.rs:26: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:30:25 + --> $DIR/manual_range_patterns.rs:28:25 | LL | let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1000001..=1000001` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 + | +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 + | +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 + | +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 + | +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 + | +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 + | +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 + | +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 + | +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:35:26 + --> $DIR/manual_range_patterns.rs:44:26 | LL | matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10` @@ -59,5 +120,5 @@ LL | mac!(f); | = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 9 previous errors +error: aborting due to 19 previous errors diff --git a/src/tools/clippy/tests/ui/manual_rem_euclid.fixed b/src/tools/clippy/tests/ui/manual_rem_euclid.fixed index 594a76897..2d5086558 100644 --- a/src/tools/clippy/tests/ui/manual_rem_euclid.fixed +++ b/src/tools/clippy/tests/ui/manual_rem_euclid.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::manual_rem_euclid)] #![allow(clippy::let_with_type_underscore)] diff --git a/src/tools/clippy/tests/ui/manual_rem_euclid.rs b/src/tools/clippy/tests/ui/manual_rem_euclid.rs index d5f98e715..e405a2db4 100644 --- a/src/tools/clippy/tests/ui/manual_rem_euclid.rs +++ b/src/tools/clippy/tests/ui/manual_rem_euclid.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::manual_rem_euclid)] #![allow(clippy::let_with_type_underscore)] diff --git a/src/tools/clippy/tests/ui/manual_rem_euclid.stderr b/src/tools/clippy/tests/ui/manual_rem_euclid.stderr index a43707f89..f296f2646 100644 --- a/src/tools/clippy/tests/ui/manual_rem_euclid.stderr +++ b/src/tools/clippy/tests/ui/manual_rem_euclid.stderr @@ -1,37 +1,38 @@ error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:14:18 + --> $DIR/manual_rem_euclid.rs:13:18 | LL | let _: i32 = ((value % 4) + 4) % 4; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` | = note: `-D clippy::manual-rem-euclid` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_rem_euclid)]` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:15:18 + --> $DIR/manual_rem_euclid.rs:14:18 | LL | let _: i32 = (4 + (value % 4)) % 4; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:16:18 + --> $DIR/manual_rem_euclid.rs:15:18 | LL | let _: i32 = (value % 4 + 4) % 4; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:17:18 + --> $DIR/manual_rem_euclid.rs:16:18 | LL | let _: i32 = (4 + value % 4) % 4; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:18:22 + --> $DIR/manual_rem_euclid.rs:17:22 | LL | let _: i32 = 1 + (4 + value % 4) % 4; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:38:22 + --> $DIR/manual_rem_euclid.rs:37:22 | LL | let _: i32 = ((value % 4) + 4) % 4; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)` @@ -39,25 +40,25 @@ LL | let _: i32 = ((value % 4) + 4) % 4; = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:50:5 + --> $DIR/manual_rem_euclid.rs:49:5 | LL | ((num % 4) + 4) % 4 | ^^^^^^^^^^^^^^^^^^^ help: consider using: `num.rem_euclid(4)` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:55:5 + --> $DIR/manual_rem_euclid.rs:54:5 | LL | ((num % 4) + 4) % 4 | ^^^^^^^^^^^^^^^^^^^ help: consider using: `num.rem_euclid(4)` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:67:18 + --> $DIR/manual_rem_euclid.rs:66:18 | LL | let _: i32 = ((x % 4) + 4) % 4; | ^^^^^^^^^^^^^^^^^ help: consider using: `x.rem_euclid(4)` error: manual `rem_euclid` implementation - --> $DIR/manual_rem_euclid.rs:80:18 + --> $DIR/manual_rem_euclid.rs:79:18 | LL | let _: i32 = ((x % 4) + 4) % 4; | ^^^^^^^^^^^^^^^^^ help: consider using: `x.rem_euclid(4)` diff --git a/src/tools/clippy/tests/ui/manual_retain.fixed b/src/tools/clippy/tests/ui/manual_retain.fixed index c95d40fec..4dea3e8bf 100644 --- a/src/tools/clippy/tests/ui/manual_retain.fixed +++ b/src/tools/clippy/tests/ui/manual_retain.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_retain)] #![allow(unused, clippy::redundant_clone)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; @@ -18,22 +17,31 @@ fn main() { } fn binary_heap_retain() { - // NOTE: Do not lint now, because binary_heap_retain is nightly API. - // And we need to add a test case for msrv if we update this implementation. - // https://github.com/rust-lang/rust/issues/71503 - let mut heap = BinaryHeap::from([1, 2, 3]); - heap = heap.into_iter().filter(|x| x % 2 == 0).collect(); - heap = heap.iter().filter(|&x| x % 2 == 0).copied().collect(); - heap = heap.iter().filter(|&x| x % 2 == 0).cloned().collect(); + let mut binary_heap = BinaryHeap::from([1, 2, 3]); + // Do lint. + binary_heap.retain(|x| x % 2 == 0); + binary_heap.retain(|x| x % 2 == 0); + binary_heap.retain(|x| x % 2 == 0); // Do not lint, because type conversion is performed - heap = heap.into_iter().filter(|x| x % 2 == 0).collect::>(); - heap = heap.iter().filter(|&x| x % 2 == 0).copied().collect::>(); - heap = heap.iter().filter(|&x| x % 2 == 0).cloned().collect::>(); + binary_heap = binary_heap + .into_iter() + .filter(|x| x % 2 == 0) + .collect::>(); + binary_heap = binary_heap + .iter() + .filter(|&x| x % 2 == 0) + .copied() + .collect::>(); + binary_heap = binary_heap + .iter() + .filter(|&x| x % 2 == 0) + .cloned() + .collect::>(); // Do not lint, because this expression is not assign. - let mut bar: BinaryHeap = heap.iter().filter(|&x| x % 2 == 0).copied().collect(); - let mut foobar: BinaryHeap = heap.into_iter().filter(|x| x % 2 == 0).collect(); + let mut bar: BinaryHeap = binary_heap.iter().filter(|&x| x % 2 == 0).copied().collect(); + let mut foobar: BinaryHeap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); // Do not lint, because it is an assignment to a different variable. bar = foobar.iter().filter(|&x| x % 2 == 0).copied().collect(); @@ -210,6 +218,12 @@ fn vec_deque_retain() { bar = foobar.into_iter().filter(|x| x % 2 == 0).collect(); } +#[clippy::msrv = "1.69"] +fn _msrv_169() { + let mut binary_heap = BinaryHeap::from([1, 2, 3]); + binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); +} + #[clippy::msrv = "1.52"] fn _msrv_153() { let mut btree_map: BTreeMap = (0..8).map(|x| (x, x * 10)).collect(); diff --git a/src/tools/clippy/tests/ui/manual_retain.rs b/src/tools/clippy/tests/ui/manual_retain.rs index 9a3434f48..d839550f3 100644 --- a/src/tools/clippy/tests/ui/manual_retain.rs +++ b/src/tools/clippy/tests/ui/manual_retain.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::manual_retain)] #![allow(unused, clippy::redundant_clone)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; @@ -18,22 +17,31 @@ fn main() { } fn binary_heap_retain() { - // NOTE: Do not lint now, because binary_heap_retain is nightly API. - // And we need to add a test case for msrv if we update this implementation. - // https://github.com/rust-lang/rust/issues/71503 - let mut heap = BinaryHeap::from([1, 2, 3]); - heap = heap.into_iter().filter(|x| x % 2 == 0).collect(); - heap = heap.iter().filter(|&x| x % 2 == 0).copied().collect(); - heap = heap.iter().filter(|&x| x % 2 == 0).cloned().collect(); + let mut binary_heap = BinaryHeap::from([1, 2, 3]); + // Do lint. + binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); + binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).copied().collect(); + binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).cloned().collect(); // Do not lint, because type conversion is performed - heap = heap.into_iter().filter(|x| x % 2 == 0).collect::>(); - heap = heap.iter().filter(|&x| x % 2 == 0).copied().collect::>(); - heap = heap.iter().filter(|&x| x % 2 == 0).cloned().collect::>(); + binary_heap = binary_heap + .into_iter() + .filter(|x| x % 2 == 0) + .collect::>(); + binary_heap = binary_heap + .iter() + .filter(|&x| x % 2 == 0) + .copied() + .collect::>(); + binary_heap = binary_heap + .iter() + .filter(|&x| x % 2 == 0) + .cloned() + .collect::>(); // Do not lint, because this expression is not assign. - let mut bar: BinaryHeap = heap.iter().filter(|&x| x % 2 == 0).copied().collect(); - let mut foobar: BinaryHeap = heap.into_iter().filter(|x| x % 2 == 0).collect(); + let mut bar: BinaryHeap = binary_heap.iter().filter(|&x| x % 2 == 0).copied().collect(); + let mut foobar: BinaryHeap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); // Do not lint, because it is an assignment to a different variable. bar = foobar.iter().filter(|&x| x % 2 == 0).copied().collect(); @@ -216,6 +224,12 @@ fn vec_deque_retain() { bar = foobar.into_iter().filter(|x| x % 2 == 0).collect(); } +#[clippy::msrv = "1.69"] +fn _msrv_169() { + let mut binary_heap = BinaryHeap::from([1, 2, 3]); + binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); +} + #[clippy::msrv = "1.52"] fn _msrv_153() { let mut btree_map: BTreeMap = (0..8).map(|x| (x, x * 10)).collect(); diff --git a/src/tools/clippy/tests/ui/manual_retain.stderr b/src/tools/clippy/tests/ui/manual_retain.stderr index 0936a2384..0c5b1383b 100644 --- a/src/tools/clippy/tests/ui/manual_retain.stderr +++ b/src/tools/clippy/tests/ui/manual_retain.stderr @@ -1,19 +1,38 @@ error: this expression can be written more simply using `.retain()` - --> $DIR/manual_retain.rs:46:5 + --> $DIR/manual_retain.rs:22: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)` +LL | binary_heap = binary_heap.into_iter().filter(|x| x % 2 == 0).collect(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `binary_heap.retain(|x| x % 2 == 0)` | = note: `-D clippy::manual-retain` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_retain)]` + +error: this expression can be written more simply using `.retain()` + --> $DIR/manual_retain.rs:23: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:24: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:54: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:47:5 + --> $DIR/manual_retain.rs:55: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:48:5 + --> $DIR/manual_retain.rs:56:5 | LL | / btree_map = btree_map LL | | .into_iter() @@ -22,37 +41,37 @@ 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:70:5 + --> $DIR/manual_retain.rs:78: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:71:5 + --> $DIR/manual_retain.rs:79: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:72:5 + --> $DIR/manual_retain.rs:80: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:102:5 + --> $DIR/manual_retain.rs:110: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:103:5 + --> $DIR/manual_retain.rs:111: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:104:5 + --> $DIR/manual_retain.rs:112:5 | LL | / hash_map = hash_map LL | | .into_iter() @@ -61,64 +80,64 @@ 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:125:5 + --> $DIR/manual_retain.rs:133: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:126:5 + --> $DIR/manual_retain.rs:134: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:127:5 + --> $DIR/manual_retain.rs:135: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:156:5 + --> $DIR/manual_retain.rs:164: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:168:5 + --> $DIR/manual_retain.rs:176: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:169:5 + --> $DIR/manual_retain.rs:177: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:170:5 + --> $DIR/manual_retain.rs:178: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:192:5 + --> $DIR/manual_retain.rs:200: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:193:5 + --> $DIR/manual_retain.rs:201: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:194:5 + --> $DIR/manual_retain.rs:202: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: aborting due to 19 previous errors +error: aborting due to 22 previous errors diff --git a/src/tools/clippy/tests/ui/manual_saturating_arithmetic.fixed b/src/tools/clippy/tests/ui/manual_saturating_arithmetic.fixed index 7dd4521fa..8218f1088 100644 --- a/src/tools/clippy/tests/ui/manual_saturating_arithmetic.fixed +++ b/src/tools/clippy/tests/ui/manual_saturating_arithmetic.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_imports)] use std::{i128, i32, u128, u32}; diff --git a/src/tools/clippy/tests/ui/manual_saturating_arithmetic.rs b/src/tools/clippy/tests/ui/manual_saturating_arithmetic.rs index 463ee0692..60022b54b 100644 --- a/src/tools/clippy/tests/ui/manual_saturating_arithmetic.rs +++ b/src/tools/clippy/tests/ui/manual_saturating_arithmetic.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_imports)] use std::{i128, i32, u128, u32}; diff --git a/src/tools/clippy/tests/ui/manual_saturating_arithmetic.stderr b/src/tools/clippy/tests/ui/manual_saturating_arithmetic.stderr index d985f2e75..dc36a5ee7 100644 --- a/src/tools/clippy/tests/ui/manual_saturating_arithmetic.stderr +++ b/src/tools/clippy/tests/ui/manual_saturating_arithmetic.stderr @@ -1,25 +1,26 @@ error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:8:13 + --> $DIR/manual_saturating_arithmetic.rs:6:13 | LL | let _ = 1u32.checked_add(1).unwrap_or(u32::max_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u32.saturating_add(1)` | = note: `-D clippy::manual-saturating-arithmetic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_saturating_arithmetic)]` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:9:13 + --> $DIR/manual_saturating_arithmetic.rs:7:13 | LL | let _ = 1u32.checked_add(1).unwrap_or(u32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u32.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:10:13 + --> $DIR/manual_saturating_arithmetic.rs:8:13 | LL | let _ = 1u8.checked_add(1).unwrap_or(255); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u8.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:11:13 + --> $DIR/manual_saturating_arithmetic.rs:9:13 | LL | let _ = 1u128 | _____________^ @@ -28,49 +29,49 @@ LL | | .unwrap_or(340_282_366_920_938_463_463_374_607_431_768_211_455); | |_______________________________________________________________________^ help: try using `saturating_add`: `1u128.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:16:13 + --> $DIR/manual_saturating_arithmetic.rs:14:13 | LL | let _ = 1u32.checked_mul(1).unwrap_or(u32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_mul`: `1u32.saturating_mul(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:18:13 + --> $DIR/manual_saturating_arithmetic.rs:16:13 | LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::min_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u32.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:19:13 + --> $DIR/manual_saturating_arithmetic.rs:17:13 | LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u32.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:20:13 + --> $DIR/manual_saturating_arithmetic.rs:18:13 | LL | let _ = 1u8.checked_sub(1).unwrap_or(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u8.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:24:13 + --> $DIR/manual_saturating_arithmetic.rs:22:13 | LL | let _ = 1i32.checked_add(1).unwrap_or(i32::max_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:25:13 + --> $DIR/manual_saturating_arithmetic.rs:23:13 | LL | let _ = 1i32.checked_add(1).unwrap_or(i32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:26:13 + --> $DIR/manual_saturating_arithmetic.rs:24:13 | LL | let _ = 1i8.checked_add(1).unwrap_or(127); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i8.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:27:13 + --> $DIR/manual_saturating_arithmetic.rs:25:13 | LL | let _ = 1i128 | _____________^ @@ -79,25 +80,25 @@ LL | | .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727); | |_______________________________________________________________________^ help: try using `saturating_add`: `1i128.saturating_add(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:30:13 + --> $DIR/manual_saturating_arithmetic.rs:28:13 | LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::min_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:31:13 + --> $DIR/manual_saturating_arithmetic.rs:29:13 | LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:32:13 + --> $DIR/manual_saturating_arithmetic.rs:30:13 | LL | let _ = 1i8.checked_add(-1).unwrap_or(-128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i8.saturating_add(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:33:13 + --> $DIR/manual_saturating_arithmetic.rs:31:13 | LL | let _ = 1i128 | _____________^ @@ -106,25 +107,25 @@ LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); | |________________________________________________________________________^ help: try using `saturating_add`: `1i128.saturating_add(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:40:13 + --> $DIR/manual_saturating_arithmetic.rs:38:13 | LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::min_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:41:13 + --> $DIR/manual_saturating_arithmetic.rs:39:13 | LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::MIN); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:42:13 + --> $DIR/manual_saturating_arithmetic.rs:40:13 | LL | let _ = 1i8.checked_sub(1).unwrap_or(-128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i8.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:43:13 + --> $DIR/manual_saturating_arithmetic.rs:41:13 | LL | let _ = 1i128 | _____________^ @@ -133,25 +134,25 @@ LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728); | |________________________________________________________________________^ help: try using `saturating_sub`: `1i128.saturating_sub(1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:46:13 + --> $DIR/manual_saturating_arithmetic.rs:44:13 | LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::max_value()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:47:13 + --> $DIR/manual_saturating_arithmetic.rs:45:13 | LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::MAX); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:48:13 + --> $DIR/manual_saturating_arithmetic.rs:46:13 | LL | let _ = 1i8.checked_sub(-1).unwrap_or(127); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i8.saturating_sub(-1)` error: manual saturating arithmetic - --> $DIR/manual_saturating_arithmetic.rs:49:13 + --> $DIR/manual_saturating_arithmetic.rs:47:13 | LL | let _ = 1i128 | _____________^ diff --git a/src/tools/clippy/tests/ui/manual_slice_size_calculation.fixed b/src/tools/clippy/tests/ui/manual_slice_size_calculation.fixed index 5b9629f4b..62b372f4b 100644 --- a/src/tools/clippy/tests/ui/manual_slice_size_calculation.fixed +++ b/src/tools/clippy/tests/ui/manual_slice_size_calculation.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused)] #![warn(clippy::manual_slice_size_calculation)] diff --git a/src/tools/clippy/tests/ui/manual_slice_size_calculation.rs b/src/tools/clippy/tests/ui/manual_slice_size_calculation.rs index 297887a9c..d59f5fd8b 100644 --- a/src/tools/clippy/tests/ui/manual_slice_size_calculation.rs +++ b/src/tools/clippy/tests/ui/manual_slice_size_calculation.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused)] #![warn(clippy::manual_slice_size_calculation)] diff --git a/src/tools/clippy/tests/ui/manual_slice_size_calculation.stderr b/src/tools/clippy/tests/ui/manual_slice_size_calculation.stderr index e09d8057a..ebdb74813 100644 --- a/src/tools/clippy/tests/ui/manual_slice_size_calculation.stderr +++ b/src/tools/clippy/tests/ui/manual_slice_size_calculation.stderr @@ -1,43 +1,44 @@ error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:16:13 + --> $DIR/manual_slice_size_calculation.rs:15:13 | LL | let _ = s_i32.len() * size_of::(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` | = note: `-D clippy::manual-slice-size-calculation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_slice_size_calculation)]` error: manual slice size calculation - --> $DIR/manual_slice_size_calculation.rs:17:13 + --> $DIR/manual_slice_size_calculation.rs:16: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:18:13 + --> $DIR/manual_slice_size_calculation.rs:17: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:22:13 + --> $DIR/manual_slice_size_calculation.rs:21: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:23:13 + --> $DIR/manual_slice_size_calculation.rs:22: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:24:13 + --> $DIR/manual_slice_size_calculation.rs:23: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:26:13 + --> $DIR/manual_slice_size_calculation.rs:25:13 | LL | let _ = external!(&[1u64][..]).len() * size_of::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(external!(&[1u64][..]))` diff --git a/src/tools/clippy/tests/ui/manual_split_once.fixed b/src/tools/clippy/tests/ui/manual_split_once.fixed index e317c5971..aaac6a048 100644 --- a/src/tools/clippy/tests/ui/manual_split_once.fixed +++ b/src/tools/clippy/tests/ui/manual_split_once.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_split_once)] #![allow(unused, clippy::iter_skip_next, clippy::iter_nth_zero)] diff --git a/src/tools/clippy/tests/ui/manual_split_once.rs b/src/tools/clippy/tests/ui/manual_split_once.rs index 7e2dc22bc..113e1737c 100644 --- a/src/tools/clippy/tests/ui/manual_split_once.rs +++ b/src/tools/clippy/tests/ui/manual_split_once.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_split_once)] #![allow(unused, clippy::iter_skip_next, clippy::iter_nth_zero)] diff --git a/src/tools/clippy/tests/ui/manual_split_once.stderr b/src/tools/clippy/tests/ui/manual_split_once.stderr index f454f95b4..494a035ed 100644 --- a/src/tools/clippy/tests/ui/manual_split_once.stderr +++ b/src/tools/clippy/tests/ui/manual_split_once.stderr @@ -1,85 +1,86 @@ error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:13:13 + --> $DIR/manual_split_once.rs:11:13 | LL | let _ = "key=value".splitn(2, '=').nth(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=').unwrap().1` | = note: `-D clippy::manual-split-once` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_split_once)]` error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:14:13 + --> $DIR/manual_split_once.rs:12: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:15:18 + --> $DIR/manual_split_once.rs:13: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:18:13 + --> $DIR/manual_split_once.rs:16: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:21: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:24:13 + --> $DIR/manual_split_once.rs:22: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:27:17 + --> $DIR/manual_split_once.rs:25: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:28:17 + --> $DIR/manual_split_once.rs:26: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:29:17 + --> $DIR/manual_split_once.rs:27: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:30:17 + --> $DIR/manual_split_once.rs:28: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:38:13 + --> $DIR/manual_split_once.rs:36: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:39:18 + --> $DIR/manual_split_once.rs:37: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:40:13 + --> $DIR/manual_split_once.rs:38: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:44:5 + --> $DIR/manual_split_once.rs:42:5 | LL | let mut iter = "a.b.c".splitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +105,7 @@ LL + | error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:48:5 + --> $DIR/manual_split_once.rs:46:5 | LL | let mut iter = "a.b.c".splitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -129,7 +130,7 @@ LL + | error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:52:5 + --> $DIR/manual_split_once.rs:50:5 | LL | let mut iter = "a.b.c".rsplitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +155,7 @@ LL + | error: manual implementation of `rsplit_once` - --> $DIR/manual_split_once.rs:56:5 + --> $DIR/manual_split_once.rs:54:5 | LL | let mut iter = "a.b.c".rsplitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -179,13 +180,13 @@ LL + | error: manual implementation of `split_once` - --> $DIR/manual_split_once.rs:141:13 + --> $DIR/manual_split_once.rs:139: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:143:5 + --> $DIR/manual_split_once.rs:141:5 | LL | let mut iter = "a.b.c".splitn(2, '.'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/manual_str_repeat.fixed b/src/tools/clippy/tests/ui/manual_str_repeat.fixed index 9468c3df9..888a46627 100644 --- a/src/tools/clippy/tests/ui/manual_str_repeat.fixed +++ b/src/tools/clippy/tests/ui/manual_str_repeat.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_str_repeat)] use std::borrow::Cow; diff --git a/src/tools/clippy/tests/ui/manual_str_repeat.rs b/src/tools/clippy/tests/ui/manual_str_repeat.rs index baa0a1026..a366351ff 100644 --- a/src/tools/clippy/tests/ui/manual_str_repeat.rs +++ b/src/tools/clippy/tests/ui/manual_str_repeat.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_str_repeat)] use std::borrow::Cow; diff --git a/src/tools/clippy/tests/ui/manual_str_repeat.stderr b/src/tools/clippy/tests/ui/manual_str_repeat.stderr index 331bb6ea5..9a13aa972 100644 --- a/src/tools/clippy/tests/ui/manual_str_repeat.stderr +++ b/src/tools/clippy/tests/ui/manual_str_repeat.stderr @@ -1,61 +1,62 @@ error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:9:21 + --> $DIR/manual_str_repeat.rs:7:21 | LL | let _: String = std::iter::repeat("test").take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"test".repeat(10)` | = note: `-D clippy::manual-str-repeat` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_str_repeat)]` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:10:21 + --> $DIR/manual_str_repeat.rs:8: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:11:21 + --> $DIR/manual_str_repeat.rs:9:21 | -LL | let _: String = std::iter::repeat('/'').take(10).collect(); +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:12:21 + --> $DIR/manual_str_repeat.rs:10:21 | LL | let _: String = std::iter::repeat('"').take(10).collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"/"".repeat(10)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"\"".repeat(10)` error: manual implementation of `str::repeat` using iterators - --> $DIR/manual_str_repeat.rs:16:13 + --> $DIR/manual_str_repeat.rs:14: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:25:21 + --> $DIR/manual_str_repeat.rs:23: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:34:21 + --> $DIR/manual_str_repeat.rs:32: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:46:21 + --> $DIR/manual_str_repeat.rs:44: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:49:21 + --> $DIR/manual_str_repeat.rs:47: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:64:21 + --> $DIR/manual_str_repeat.rs:62:21 | LL | let _: String = std::iter::repeat("test").take(10).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"test".repeat(10)` diff --git a/src/tools/clippy/tests/ui/manual_string_new.fixed b/src/tools/clippy/tests/ui/manual_string_new.fixed index 0d1bab233..273be4e0f 100644 --- a/src/tools/clippy/tests/ui/manual_string_new.fixed +++ b/src/tools/clippy/tests/ui/manual_string_new.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_string_new)] macro_rules! create_strings_from_macro { diff --git a/src/tools/clippy/tests/ui/manual_string_new.rs b/src/tools/clippy/tests/ui/manual_string_new.rs index 2392ebfc3..0d5514fc8 100644 --- a/src/tools/clippy/tests/ui/manual_string_new.rs +++ b/src/tools/clippy/tests/ui/manual_string_new.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_string_new)] macro_rules! create_strings_from_macro { diff --git a/src/tools/clippy/tests/ui/manual_string_new.stderr b/src/tools/clippy/tests/ui/manual_string_new.stderr index e5ecfc619..399652d3f 100644 --- a/src/tools/clippy/tests/ui/manual_string_new.stderr +++ b/src/tools/clippy/tests/ui/manual_string_new.stderr @@ -1,55 +1,56 @@ error: empty String is being created manually - --> $DIR/manual_string_new.rs:15:13 + --> $DIR/manual_string_new.rs:13:13 | LL | let _ = "".to_string(); | ^^^^^^^^^^^^^^ help: consider using: `String::new()` | = note: `-D clippy::manual-string-new` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_string_new)]` error: empty String is being created manually - --> $DIR/manual_string_new.rs:18:13 + --> $DIR/manual_string_new.rs:16:13 | LL | let _ = "".to_owned(); | ^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:21:21 + --> $DIR/manual_string_new.rs:19:21 | LL | let _: String = "".into(); | ^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:28:13 + --> $DIR/manual_string_new.rs:26:13 | LL | let _ = String::from(""); | ^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:29:13 + --> $DIR/manual_string_new.rs:27:13 | LL | let _ = ::from(""); | ^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:34:13 + --> $DIR/manual_string_new.rs:32:13 | LL | let _ = String::try_from("").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:40:21 + --> $DIR/manual_string_new.rs:38:21 | LL | let _: String = From::from(""); | ^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:45:21 + --> $DIR/manual_string_new.rs:43:21 | LL | let _: String = TryFrom::try_from("").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` error: empty String is being created manually - --> $DIR/manual_string_new.rs:48:21 + --> $DIR/manual_string_new.rs:46:21 | LL | let _: String = TryFrom::try_from("").expect("this should warn"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::new()` diff --git a/src/tools/clippy/tests/ui/manual_strip.rs b/src/tools/clippy/tests/ui/manual_strip.rs index b0b1c262a..8bd0300e6 100644 --- a/src/tools/clippy/tests/ui/manual_strip.rs +++ b/src/tools/clippy/tests/ui/manual_strip.rs @@ -1,10 +1,11 @@ #![warn(clippy::manual_strip)] - +//@no-rustfix fn main() { let s = "abc"; if s.starts_with("ab") { str::to_string(&s["ab".len()..]); + //~^ ERROR: stripping a prefix manually s["ab".len()..].to_string(); str::to_string(&s[2..]); @@ -13,6 +14,7 @@ fn main() { if s.ends_with("bc") { str::to_string(&s[..s.len() - "bc".len()]); + //~^ ERROR: stripping a suffix manually s[..s.len() - "bc".len()].to_string(); str::to_string(&s[..s.len() - 2]); @@ -22,6 +24,7 @@ fn main() { // Character patterns if s.starts_with('a') { str::to_string(&s[1..]); + //~^ ERROR: stripping a prefix manually s[1..].to_string(); } @@ -29,12 +32,14 @@ fn main() { let prefix = "ab"; if s.starts_with(prefix) { str::to_string(&s[prefix.len()..]); + //~^ ERROR: stripping a prefix manually } // Constant prefix const PREFIX: &str = "ab"; if s.starts_with(PREFIX) { str::to_string(&s[PREFIX.len()..]); + //~^ ERROR: stripping a prefix manually str::to_string(&s[2..]); } @@ -42,12 +47,14 @@ fn main() { const TARGET: &str = "abc"; if TARGET.starts_with(prefix) { str::to_string(&TARGET[prefix.len()..]); + //~^ ERROR: stripping a prefix manually } // String target - not mutated. let s1: String = "abc".into(); if s1.starts_with("ab") { s1[2..].to_uppercase(); + //~^ ERROR: stripping a prefix manually } // String target - mutated. (Don't lint.) @@ -78,5 +85,6 @@ fn msrv_1_45() { let s = "abc"; if s.starts_with('a') { s[1..].to_string(); + //~^ ERROR: stripping a prefix manually } } diff --git a/src/tools/clippy/tests/ui/manual_strip.stderr b/src/tools/clippy/tests/ui/manual_strip.stderr index f592e898f..0bf6975b1 100644 --- a/src/tools/clippy/tests/ui/manual_strip.stderr +++ b/src/tools/clippy/tests/ui/manual_strip.stderr @@ -10,10 +10,12 @@ note: the prefix was tested here LL | if s.starts_with("ab") { | ^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::manual-strip` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_strip)]` help: try using the `strip_prefix` method | LL ~ if let Some() = s.strip_prefix("ab") { LL ~ str::to_string(); +LL | LL ~ .to_string(); LL | LL ~ str::to_string(); @@ -21,13 +23,13 @@ LL ~ .to_string(); | error: stripping a suffix manually - --> $DIR/manual_strip.rs:15:24 + --> $DIR/manual_strip.rs:16:24 | LL | str::to_string(&s[..s.len() - "bc".len()]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the suffix was tested here - --> $DIR/manual_strip.rs:14:5 + --> $DIR/manual_strip.rs:15:5 | LL | if s.ends_with("bc") { | ^^^^^^^^^^^^^^^^^^^^^ @@ -35,6 +37,7 @@ help: try using the `strip_suffix` method | LL ~ if let Some() = s.strip_suffix("bc") { LL ~ str::to_string(); +LL | LL ~ .to_string(); LL | LL ~ str::to_string(); @@ -42,13 +45,13 @@ LL ~ .to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:24:24 + --> $DIR/manual_strip.rs:26:24 | LL | str::to_string(&s[1..]); | ^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:23:5 + --> $DIR/manual_strip.rs:25:5 | LL | if s.starts_with('a') { | ^^^^^^^^^^^^^^^^^^^^^^ @@ -56,17 +59,18 @@ help: try using the `strip_prefix` method | LL ~ if let Some() = s.strip_prefix('a') { LL ~ str::to_string(); +LL | LL ~ .to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:31:24 + --> $DIR/manual_strip.rs:34:24 | LL | str::to_string(&s[prefix.len()..]); | ^^^^^^^^^^^^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:30:5 + --> $DIR/manual_strip.rs:33:5 | LL | if s.starts_with(prefix) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -77,13 +81,13 @@ LL ~ str::to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:37:24 + --> $DIR/manual_strip.rs:41:24 | LL | str::to_string(&s[PREFIX.len()..]); | ^^^^^^^^^^^^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:36:5 + --> $DIR/manual_strip.rs:40:5 | LL | if s.starts_with(PREFIX) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -91,17 +95,18 @@ help: try using the `strip_prefix` method | LL ~ if let Some() = s.strip_prefix(PREFIX) { LL ~ str::to_string(); +LL | LL ~ str::to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:44:24 + --> $DIR/manual_strip.rs:49:24 | LL | str::to_string(&TARGET[prefix.len()..]); | ^^^^^^^^^^^^^^^^^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:43:5 + --> $DIR/manual_strip.rs:48:5 | LL | if TARGET.starts_with(prefix) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,13 +117,13 @@ LL ~ str::to_string(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:50:9 + --> $DIR/manual_strip.rs:56:9 | LL | s1[2..].to_uppercase(); | ^^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:49:5 + --> $DIR/manual_strip.rs:55:5 | LL | if s1.starts_with("ab") { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -129,13 +134,13 @@ LL ~ .to_uppercase(); | error: stripping a prefix manually - --> $DIR/manual_strip.rs:80:9 + --> $DIR/manual_strip.rs:87:9 | LL | s[1..].to_string(); | ^^^^^^ | note: the prefix was tested here - --> $DIR/manual_strip.rs:79:5 + --> $DIR/manual_strip.rs:86:5 | LL | if s.starts_with('a') { | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/manual_try_fold.rs b/src/tools/clippy/tests/ui/manual_try_fold.rs index 05c658579..bddf03ac3 100644 --- a/src/tools/clippy/tests/ui/manual_try_fold.rs +++ b/src/tools/clippy/tests/ui/manual_try_fold.rs @@ -1,8 +1,8 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::unnecessary_fold, unused)] #![warn(clippy::manual_try_fold)] #![feature(try_trait_v2)] - +//@no-rustfix use std::ops::{ControlFlow, FromResidual, Try}; #[macro_use] diff --git a/src/tools/clippy/tests/ui/manual_try_fold.stderr b/src/tools/clippy/tests/ui/manual_try_fold.stderr index f1bb97c6d..4eb3e302b 100644 --- a/src/tools/clippy/tests/ui/manual_try_fold.stderr +++ b/src/tools/clippy/tests/ui/manual_try_fold.stderr @@ -5,6 +5,7 @@ LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(0i32, |sum, i| ...)` | = note: `-D clippy::manual-try-fold` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or.fixed b/src/tools/clippy/tests/ui/manual_unwrap_or.fixed index 20560b87c..737d4c90d 100644 --- a/src/tools/clippy/tests/ui/manual_unwrap_or.fixed +++ b/src/tools/clippy/tests/ui/manual_unwrap_or.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![allow(unused_variables, clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)] diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or.rs b/src/tools/clippy/tests/ui/manual_unwrap_or.rs index 5dbc57565..f59fb8752 100644 --- a/src/tools/clippy/tests/ui/manual_unwrap_or.rs +++ b/src/tools/clippy/tests/ui/manual_unwrap_or.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![allow(unused_variables, clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)] diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or.stderr b/src/tools/clippy/tests/ui/manual_unwrap_or.stderr index 0e4cb798d..3a0759dcc 100644 --- a/src/tools/clippy/tests/ui/manual_unwrap_or.stderr +++ b/src/tools/clippy/tests/ui/manual_unwrap_or.stderr @@ -1,5 +1,5 @@ error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:7:5 + --> $DIR/manual_unwrap_or.rs:6:5 | LL | / match Some(1) { LL | | Some(i) => i, @@ -8,9 +8,10 @@ LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(42)` | = note: `-D clippy::manual-unwrap-or` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_unwrap_or)]` error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:13:5 + --> $DIR/manual_unwrap_or.rs:12:5 | LL | / match Some(1) { LL | | None => 42, @@ -19,7 +20,7 @@ LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(42)` error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:19:5 + --> $DIR/manual_unwrap_or.rs:18:5 | LL | / match Some(1) { LL | | Some(i) => i, @@ -28,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:26:5 + --> $DIR/manual_unwrap_or.rs:25:5 | LL | / match Some(1) { LL | | Some(i) => i, @@ -49,7 +50,7 @@ LL ~ }); | error: this pattern reimplements `Option::unwrap_or` - --> $DIR/manual_unwrap_or.rs:36:5 + --> $DIR/manual_unwrap_or.rs:35:5 | LL | / match Some("Bob") { LL | | Some(i) => i, @@ -58,7 +59,7 @@ LL | | }; | |_____^ help: replace with: `Some("Bob").unwrap_or("Alice")` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:86:5 + --> $DIR/manual_unwrap_or.rs:85:5 | LL | / match Ok::(1) { LL | | Ok(i) => i, @@ -67,7 +68,7 @@ LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:93:5 + --> $DIR/manual_unwrap_or.rs:92:5 | LL | / match a { LL | | Ok(i) => i, @@ -76,7 +77,7 @@ LL | | }; | |_____^ help: replace with: `a.unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:99:5 + --> $DIR/manual_unwrap_or.rs:98:5 | LL | / match Ok(1) as Result { LL | | Ok(i) => i, @@ -85,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:112:5 + --> $DIR/manual_unwrap_or.rs:111:5 | LL | / match s.method() { LL | | Some(i) => i, @@ -94,7 +95,7 @@ LL | | }; | |_____^ help: replace with: `s.method().unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:118:5 + --> $DIR/manual_unwrap_or.rs:117:5 | LL | / match Ok::(1) { LL | | Err(_) => 42, @@ -103,7 +104,7 @@ LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:124:5 + --> $DIR/manual_unwrap_or.rs:123:5 | LL | / match Ok::(1) { LL | | Ok(i) => i, @@ -112,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:131:5 + --> $DIR/manual_unwrap_or.rs:130:5 | LL | / match Ok::(1) { LL | | Ok(i) => i, @@ -133,7 +134,7 @@ LL ~ }); | error: this pattern reimplements `Result::unwrap_or` - --> $DIR/manual_unwrap_or.rs:141:5 + --> $DIR/manual_unwrap_or.rs:140:5 | LL | / match Ok::<&str, &str>("Bob") { LL | | Ok(i) => i, @@ -142,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:201:17 + --> $DIR/manual_unwrap_or.rs:200:17 | LL | let _ = match some_macro!() { | _________________^ diff --git a/src/tools/clippy/tests/ui/manual_while_let_some.fixed b/src/tools/clippy/tests/ui/manual_while_let_some.fixed index 8b6109195..c70d258df 100644 --- a/src/tools/clippy/tests/ui/manual_while_let_some.fixed +++ b/src/tools/clippy/tests/ui/manual_while_let_some.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_while_let_some)] diff --git a/src/tools/clippy/tests/ui/manual_while_let_some.rs b/src/tools/clippy/tests/ui/manual_while_let_some.rs index 85a0a084a..415bb5798 100644 --- a/src/tools/clippy/tests/ui/manual_while_let_some.rs +++ b/src/tools/clippy/tests/ui/manual_while_let_some.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::manual_while_let_some)] diff --git a/src/tools/clippy/tests/ui/manual_while_let_some.stderr b/src/tools/clippy/tests/ui/manual_while_let_some.stderr index 633fe05c4..37387c8c3 100644 --- a/src/tools/clippy/tests/ui/manual_while_let_some.stderr +++ b/src/tools/clippy/tests/ui/manual_while_let_some.stderr @@ -1,10 +1,11 @@ error: you seem to be trying to pop elements from a `Vec` in a loop - --> $DIR/manual_while_let_some.rs:23:9 + --> $DIR/manual_while_let_some.rs:21:9 | LL | let number = numbers.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::manual-while-let-some` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_while_let_some)]` help: consider using a `while..let` loop | LL ~ while let Some(number) = numbers.pop() { @@ -12,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:31:9 + --> $DIR/manual_while_let_some.rs:29:9 | LL | let number = val.numbers.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,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:35:20 + --> $DIR/manual_while_let_some.rs:33:20 | LL | accept_i32(numbers.pop().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -36,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:39:20 + --> $DIR/manual_while_let_some.rs:37:20 | LL | accept_i32(numbers.pop().expect("")); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,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:82:9 + --> $DIR/manual_while_let_some.rs:80:9 | LL | let (a, b) = numbers.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,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:86:26 + --> $DIR/manual_while_let_some.rs:84:26 | LL | accept_i32_tuple(numbers.pop().unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -72,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:91:9 + --> $DIR/manual_while_let_some.rs:89:9 | LL | let Foo { a, b } = results.pop().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/many_single_char_names.rs b/src/tools/clippy/tests/ui/many_single_char_names.rs index 88fcce668..68578340d 100644 --- a/src/tools/clippy/tests/ui/many_single_char_names.rs +++ b/src/tools/clippy/tests/ui/many_single_char_names.rs @@ -3,6 +3,10 @@ fn bla() { let a: i32; + //~^ ERROR: 5 bindings with single-character names in scope + //~| NOTE: `-D clippy::many-single-char-names` implied by `-D warnings` + //~| ERROR: 6 bindings with single-character names in scope + //~| ERROR: 5 bindings with single-character names in scope let (b, c, d): (i32, i64, i16); { { @@ -28,9 +32,11 @@ fn bla() { } fn bindings(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) {} +//~^ ERROR: 8 bindings with single-character names in scope fn bindings2() { let (a, b, c, d, e, f, g, h): (bool, bool, bool, bool, bool, bool, bool, bool) = unimplemented!(); + //~^ ERROR: 8 bindings with single-character names in scope } fn shadowing() { diff --git a/src/tools/clippy/tests/ui/many_single_char_names.stderr b/src/tools/clippy/tests/ui/many_single_char_names.stderr index ade0f84bc..688158cff 100644 --- a/src/tools/clippy/tests/ui/many_single_char_names.stderr +++ b/src/tools/clippy/tests/ui/many_single_char_names.stderr @@ -3,6 +3,7 @@ error: 5 bindings with single-character names in scope | LL | let a: i32; | ^ +... LL | let (b, c, d): (i32, i64, i16); | ^ ^ ^ ... @@ -10,12 +11,14 @@ LL | let e: i32; | ^ | = note: `-D clippy::many-single-char-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::many_single_char_names)]` error: 6 bindings with single-character names in scope --> $DIR/many_single_char_names.rs:5:9 | LL | let a: i32; | ^ +... LL | let (b, c, d): (i32, i64, i16); | ^ ^ ^ ... @@ -29,6 +32,7 @@ error: 5 bindings with single-character names in scope | LL | let a: i32; | ^ +... LL | let (b, c, d): (i32, i64, i16); | ^ ^ ^ ... @@ -36,13 +40,13 @@ LL | e => panic!(), | ^ error: 8 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:30:13 + --> $DIR/many_single_char_names.rs:34:13 | LL | fn bindings(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) {} | ^ ^ ^ ^ ^ ^ ^ ^ error: 8 bindings with single-character names in scope - --> $DIR/many_single_char_names.rs:33:10 + --> $DIR/many_single_char_names.rs:38:10 | LL | let (a, b, c, d, e, f, g, h): (bool, bool, bool, bool, bool, bool, bool, bool) = unimplemented!(); | ^ ^ ^ ^ ^ ^ ^ ^ diff --git a/src/tools/clippy/tests/ui/map_clone.fixed b/src/tools/clippy/tests/ui/map_clone.fixed index 50c0eb1a8..dd979013d 100644 --- a/src/tools/clippy/tests/ui/map_clone.fixed +++ b/src/tools/clippy/tests/ui/map_clone.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::map_clone)] #![allow( clippy::clone_on_copy, diff --git a/src/tools/clippy/tests/ui/map_clone.rs b/src/tools/clippy/tests/ui/map_clone.rs index 91a084f28..96cba7196 100644 --- a/src/tools/clippy/tests/ui/map_clone.rs +++ b/src/tools/clippy/tests/ui/map_clone.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::map_clone)] #![allow( clippy::clone_on_copy, diff --git a/src/tools/clippy/tests/ui/map_clone.stderr b/src/tools/clippy/tests/ui/map_clone.stderr index d768af1f4..eb11f0848 100644 --- a/src/tools/clippy/tests/ui/map_clone.stderr +++ b/src/tools/clippy/tests/ui/map_clone.stderr @@ -1,37 +1,38 @@ error: you are using an explicit closure for copying elements - --> $DIR/map_clone.rs:12:22 + --> $DIR/map_clone.rs:11:22 | LL | let _: Vec = vec![5_i8; 6].iter().map(|x| *x).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![5_i8; 6].iter().copied()` | = note: `-D clippy::map-clone` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_clone)]` error: you are using an explicit closure for cloning elements - --> $DIR/map_clone.rs:13:26 + --> $DIR/map_clone.rs:12: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:14:23 + --> $DIR/map_clone.rs:13: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:16:26 + --> $DIR/map_clone.rs:15: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:17:25 + --> $DIR/map_clone.rs:16: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:28:29 + --> $DIR/map_clone.rs:27:29 | LL | let _ = std::env::args().map(|v| v.clone()); | ^^^^^^^^^^^^^^^^^^^ help: remove the `map` call diff --git a/src/tools/clippy/tests/ui/map_collect_result_unit.fixed b/src/tools/clippy/tests/ui/map_collect_result_unit.fixed index b00c2cf28..374af105f 100644 --- a/src/tools/clippy/tests/ui/map_collect_result_unit.fixed +++ b/src/tools/clippy/tests/ui/map_collect_result_unit.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::map_collect_result_unit)] fn main() { diff --git a/src/tools/clippy/tests/ui/map_collect_result_unit.rs b/src/tools/clippy/tests/ui/map_collect_result_unit.rs index ad2198ec1..5c6fb23e2 100644 --- a/src/tools/clippy/tests/ui/map_collect_result_unit.rs +++ b/src/tools/clippy/tests/ui/map_collect_result_unit.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::map_collect_result_unit)] fn main() { diff --git a/src/tools/clippy/tests/ui/map_collect_result_unit.stderr b/src/tools/clippy/tests/ui/map_collect_result_unit.stderr index 596e51e57..1a505d4ce 100644 --- a/src/tools/clippy/tests/ui/map_collect_result_unit.stderr +++ b/src/tools/clippy/tests/ui/map_collect_result_unit.stderr @@ -1,13 +1,14 @@ error: `.map().collect()` can be replaced with `.try_for_each()` - --> $DIR/map_collect_result_unit.rs:6:17 + --> $DIR/map_collect_result_unit.rs:5:17 | LL | let _ = (0..3).map(|t| Err(t + 1)).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(0..3).try_for_each(|t| Err(t + 1))` | = note: `-D clippy::map-collect-result-unit` implied by `-D warnings` + = 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:7:32 + --> $DIR/map_collect_result_unit.rs:6: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/src/tools/clippy/tests/ui/map_err.rs b/src/tools/clippy/tests/ui/map_err.rs index bb35ab1a1..07c517844 100644 --- a/src/tools/clippy/tests/ui/map_err.rs +++ b/src/tools/clippy/tests/ui/map_err.rs @@ -20,6 +20,7 @@ fn main() -> Result<(), Errors> { let x = u32::try_from(-123_i32); println!("{:?}", x.map_err(|_| Errors::Ignored)); + //~^ ERROR: `map_err(|_|...` wildcard pattern discards the original error // Should not warn you because you explicitly ignore the parameter // using a named wildcard value diff --git a/src/tools/clippy/tests/ui/map_err.stderr b/src/tools/clippy/tests/ui/map_err.stderr index d44403a84..6a845c84a 100644 --- a/src/tools/clippy/tests/ui/map_err.stderr +++ b/src/tools/clippy/tests/ui/map_err.stderr @@ -6,6 +6,7 @@ LL | println!("{:?}", x.map_err(|_| Errors::Ignored)); | = help: consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`) = note: `-D clippy::map-err-ignore` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_err_ignore)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/map_flatten.rs b/src/tools/clippy/tests/ui/map_flatten.rs index 7d47ee09d..76916d465 100644 --- a/src/tools/clippy/tests/ui/map_flatten.rs +++ b/src/tools/clippy/tests/ui/map_flatten.rs @@ -1,11 +1,13 @@ #![warn(clippy::map_flatten)] #![feature(result_flattening)] - +//@no-rustfix // issue #8506, multi-line #[rustfmt::skip] fn long_span() { let _: Option = Some(1) .map(|x| { + //~^ ERROR: called `map(..).flatten()` on `Option` + //~| NOTE: `-D clippy::map-flatten` implied by `-D warnings` if x <= 5 { Some(x) } else { @@ -16,6 +18,7 @@ fn long_span() { let _: Result = Ok(1) .map(|x| { + //~^ ERROR: called `map(..).flatten()` on `Result` if x == 1 { Ok(x) } else { @@ -28,6 +31,7 @@ fn long_span() { fn do_something() { } let _: Result = result .map(|res| { + //~^ ERROR: called `map(..).flatten()` on `Result` if res > 0 { do_something(); Ok(res) @@ -40,6 +44,7 @@ fn long_span() { let _: Vec<_> = vec![5_i8; 6] .into_iter() .map(|some_value| { + //~^ ERROR: called `map(..).flatten()` on `Iterator` if some_value > 3 { Some(some_value) } else { diff --git a/src/tools/clippy/tests/ui/map_flatten.stderr b/src/tools/clippy/tests/ui/map_flatten.stderr index 4b2630d68..a65d8f75d 100644 --- a/src/tools/clippy/tests/ui/map_flatten.stderr +++ b/src/tools/clippy/tests/ui/map_flatten.stderr @@ -3,18 +3,21 @@ error: called `map(..).flatten()` on `Option` | LL | .map(|x| { | __________^ +LL | | +LL | | LL | | if x <= 5 { -LL | | Some(x) -LL | | } else { ... | LL | | }) LL | | .flatten(); | |__________________^ | = note: `-D clippy::map-flatten` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_flatten)]` help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|x| { +LL + +LL + LL + if x <= 5 { LL + Some(x) LL + } else { @@ -24,13 +27,13 @@ LL ~ }); | error: called `map(..).flatten()` on `Result` - --> $DIR/map_flatten.rs:18:10 + --> $DIR/map_flatten.rs:20:10 | LL | .map(|x| { | __________^ +LL | | LL | | if x == 1 { LL | | Ok(x) -LL | | } else { ... | LL | | }) LL | | .flatten(); @@ -39,6 +42,7 @@ LL | | .flatten(); help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|x| { +LL + LL + if x == 1 { LL + Ok(x) LL + } else { @@ -48,13 +52,13 @@ LL ~ }); | error: called `map(..).flatten()` on `Result` - --> $DIR/map_flatten.rs:30:10 + --> $DIR/map_flatten.rs:33:10 | LL | .map(|res| { | __________^ +LL | | LL | | if res > 0 { LL | | do_something(); -LL | | Ok(res) ... | LL | | }) LL | | .flatten(); @@ -63,6 +67,7 @@ LL | | .flatten(); help: try replacing `map` with `and_then` and remove the `.flatten()` | LL ~ .and_then(|res| { +LL + LL + if res > 0 { LL + do_something(); LL + Ok(res) @@ -73,13 +78,13 @@ LL ~ }); | error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten.rs:42:10 + --> $DIR/map_flatten.rs:46:10 | LL | .map(|some_value| { | __________^ +LL | | LL | | if some_value > 3 { LL | | Some(some_value) -LL | | } else { ... | LL | | }) LL | | .flatten() @@ -88,6 +93,7 @@ LL | | .flatten() help: try replacing `map` with `filter_map` and remove the `.flatten()` | LL ~ .filter_map(|some_value| { +LL + LL + if some_value > 3 { LL + Some(some_value) LL + } else { diff --git a/src/tools/clippy/tests/ui/map_flatten_fixable.fixed b/src/tools/clippy/tests/ui/map_flatten_fixable.fixed index 14816de1a..1932f412d 100644 --- a/src/tools/clippy/tests/ui/map_flatten_fixable.fixed +++ b/src/tools/clippy/tests/ui/map_flatten_fixable.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all, clippy::pedantic)] #![allow(clippy::let_underscore_untyped)] #![allow(clippy::missing_docs_in_private_items)] diff --git a/src/tools/clippy/tests/ui/map_flatten_fixable.rs b/src/tools/clippy/tests/ui/map_flatten_fixable.rs index f38a00a59..093fd9b6c 100644 --- a/src/tools/clippy/tests/ui/map_flatten_fixable.rs +++ b/src/tools/clippy/tests/ui/map_flatten_fixable.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all, clippy::pedantic)] #![allow(clippy::let_underscore_untyped)] #![allow(clippy::missing_docs_in_private_items)] diff --git a/src/tools/clippy/tests/ui/map_flatten_fixable.stderr b/src/tools/clippy/tests/ui/map_flatten_fixable.stderr index c91f0b9ae..e5387eead 100644 --- a/src/tools/clippy/tests/ui/map_flatten_fixable.stderr +++ b/src/tools/clippy/tests/ui/map_flatten_fixable.stderr @@ -1,49 +1,50 @@ error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten_fixable.rs:18:47 + --> $DIR/map_flatten_fixable.rs:16:47 | LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id)` | = note: `-D clippy::map-flatten` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_flatten)]` error: called `map(..).flatten()` on `Iterator` - --> $DIR/map_flatten_fixable.rs:19:47 + --> $DIR/map_flatten_fixable.rs:17: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:20:47 + --> $DIR/map_flatten_fixable.rs:18: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:21:47 + --> $DIR/map_flatten_fixable.rs:19: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:24:47 + --> $DIR/map_flatten_fixable.rs:22: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:27:40 + --> $DIR/map_flatten_fixable.rs:25: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:30:42 + --> $DIR/map_flatten_fixable.rs:28: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:39:10 + --> $DIR/map_flatten_fixable.rs:37:10 | LL | .map(|n| match n { | __________^ @@ -72,7 +73,7 @@ LL ~ }); | error: called `map(..).flatten()` on `Option` - --> $DIR/map_flatten_fixable.rs:59:10 + --> $DIR/map_flatten_fixable.rs:57:10 | LL | .map(|_| { | __________^ diff --git a/src/tools/clippy/tests/ui/map_identity.fixed b/src/tools/clippy/tests/ui/map_identity.fixed index 7fb7d8c12..cc40b1620 100644 --- a/src/tools/clippy/tests/ui/map_identity.fixed +++ b/src/tools/clippy/tests/ui/map_identity.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::map_identity)] #![allow(clippy::needless_return)] diff --git a/src/tools/clippy/tests/ui/map_identity.rs b/src/tools/clippy/tests/ui/map_identity.rs index 7891c2426..97a91aea6 100644 --- a/src/tools/clippy/tests/ui/map_identity.rs +++ b/src/tools/clippy/tests/ui/map_identity.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::map_identity)] #![allow(clippy::needless_return)] diff --git a/src/tools/clippy/tests/ui/map_identity.stderr b/src/tools/clippy/tests/ui/map_identity.stderr index b6a77281f..8942fd7c0 100644 --- a/src/tools/clippy/tests/ui/map_identity.stderr +++ b/src/tools/clippy/tests/ui/map_identity.stderr @@ -1,31 +1,32 @@ error: unnecessary map of the identity function - --> $DIR/map_identity.rs:8:47 + --> $DIR/map_identity.rs:7:47 | LL | let _: Vec<_> = x.iter().map(not_identity).map(|x| return x).collect(); | ^^^^^^^^^^^^^^^^^^ help: remove the call to `map` | = note: `-D clippy::map-identity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_identity)]` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:9:57 + --> $DIR/map_identity.rs:8: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:9:29 + --> $DIR/map_identity.rs:8: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:10:32 + --> $DIR/map_identity.rs:9: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:11:36 + --> $DIR/map_identity.rs:10:36 | LL | let _: Result = Ok(-3).map(|x| { | ____________________________________^ @@ -34,7 +35,7 @@ LL | | }); | |______^ help: remove the call to `map` error: unnecessary map of the identity function - --> $DIR/map_identity.rs:21:36 + --> $DIR/map_identity.rs:20:36 | LL | let _: Result = Ok(1).map_err(|a| a); | ^^^^^^^^^^^^^^^ help: remove the call to `map_err` diff --git a/src/tools/clippy/tests/ui/map_unwrap_or.rs b/src/tools/clippy/tests/ui/map_unwrap_or.rs index bb36cb2c5..dfaa8f24f 100644 --- a/src/tools/clippy/tests/ui/map_unwrap_or.rs +++ b/src/tools/clippy/tests/ui/map_unwrap_or.rs @@ -1,5 +1,5 @@ //@aux-build:option_helpers.rs - +//@no-rustfix #![warn(clippy::map_unwrap_or)] #![allow(clippy::uninlined_format_args, clippy::unnecessary_lazy_evaluations)] diff --git a/src/tools/clippy/tests/ui/map_unwrap_or.stderr b/src/tools/clippy/tests/ui/map_unwrap_or.stderr index 5b3c61acf..7b7eeb322 100644 --- a/src/tools/clippy/tests/ui/map_unwrap_or.stderr +++ b/src/tools/clippy/tests/ui/map_unwrap_or.stderr @@ -8,6 +8,7 @@ LL | | .unwrap_or(0); | |_____________________^ | = note: `-D clippy::map-unwrap-or` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_unwrap_or)]` help: use `map_or(, )` instead | LL - let _ = opt.map(|x| x + 1) diff --git a/src/tools/clippy/tests/ui/map_unwrap_or_fixable.fixed b/src/tools/clippy/tests/ui/map_unwrap_or_fixable.fixed index ea5b6a669..90f3cf8ba 100644 --- a/src/tools/clippy/tests/ui/map_unwrap_or_fixable.fixed +++ b/src/tools/clippy/tests/ui/map_unwrap_or_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:option_helpers.rs #![warn(clippy::map_unwrap_or)] diff --git a/src/tools/clippy/tests/ui/map_unwrap_or_fixable.rs b/src/tools/clippy/tests/ui/map_unwrap_or_fixable.rs index f8bb9d8ca..d3d0ae015 100644 --- a/src/tools/clippy/tests/ui/map_unwrap_or_fixable.rs +++ b/src/tools/clippy/tests/ui/map_unwrap_or_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:option_helpers.rs #![warn(clippy::map_unwrap_or)] diff --git a/src/tools/clippy/tests/ui/map_unwrap_or_fixable.stderr b/src/tools/clippy/tests/ui/map_unwrap_or_fixable.stderr index 71dc009f2..ca611ac9d 100644 --- a/src/tools/clippy/tests/ui/map_unwrap_or_fixable.stderr +++ b/src/tools/clippy/tests/ui/map_unwrap_or_fixable.stderr @@ -1,5 +1,5 @@ error: called `map().unwrap_or_else()` on an `Option` value. This can be done more directly by calling `map_or_else(, )` instead - --> $DIR/map_unwrap_or_fixable.rs:17:13 + --> $DIR/map_unwrap_or_fixable.rs:16:13 | LL | let _ = opt.map(|x| x + 1) | _____________^ @@ -8,9 +8,10 @@ LL | | .unwrap_or_else(|| 0); | |_____________________________^ help: try: `opt.map_or_else(|| 0, |x| x + 1)` | = note: `-D clippy::map-unwrap-or` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::map_unwrap_or)]` error: called `map().unwrap_or_else()` on a `Result` value. This can be done more directly by calling `.map_or_else(, )` instead - --> $DIR/map_unwrap_or_fixable.rs:47:13 + --> $DIR/map_unwrap_or_fixable.rs:46:13 | LL | let _ = res.map(|x| x + 1) | _____________^ diff --git a/src/tools/clippy/tests/ui/match_as_ref.fixed b/src/tools/clippy/tests/ui/match_as_ref.fixed index 61d414bdf..8c07076af 100644 --- a/src/tools/clippy/tests/ui/match_as_ref.fixed +++ b/src/tools/clippy/tests/ui/match_as_ref.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::match_as_ref)] diff --git a/src/tools/clippy/tests/ui/match_as_ref.rs b/src/tools/clippy/tests/ui/match_as_ref.rs index cd39514c5..655e16623 100644 --- a/src/tools/clippy/tests/ui/match_as_ref.rs +++ b/src/tools/clippy/tests/ui/match_as_ref.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::match_as_ref)] diff --git a/src/tools/clippy/tests/ui/match_as_ref.stderr b/src/tools/clippy/tests/ui/match_as_ref.stderr index 2e6955eb8..cb0191370 100644 --- a/src/tools/clippy/tests/ui/match_as_ref.stderr +++ b/src/tools/clippy/tests/ui/match_as_ref.stderr @@ -1,5 +1,5 @@ error: use `as_ref()` instead - --> $DIR/match_as_ref.rs:8:33 + --> $DIR/match_as_ref.rs:6:33 | LL | let borrowed: Option<&()> = match owned { | _________________________________^ @@ -9,9 +9,10 @@ LL | | }; | |_____^ help: try: `owned.as_ref()` | = note: `-D clippy::match-as-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_as_ref)]` error: use `as_mut()` instead - --> $DIR/match_as_ref.rs:14:39 + --> $DIR/match_as_ref.rs:12:39 | LL | let borrow_mut: Option<&mut ()> = match mut_owned { | _______________________________________^ @@ -21,7 +22,7 @@ LL | | }; | |_____^ help: try: `mut_owned.as_mut()` error: use `as_ref()` instead - --> $DIR/match_as_ref.rs:32:13 + --> $DIR/match_as_ref.rs:30:13 | LL | / match self.source { LL | | Some(ref s) => Some(s), diff --git a/src/tools/clippy/tests/ui/match_bool.rs b/src/tools/clippy/tests/ui/match_bool.rs index bcc999a49..f84af393e 100644 --- a/src/tools/clippy/tests/ui/match_bool.rs +++ b/src/tools/clippy/tests/ui/match_bool.rs @@ -1,20 +1,24 @@ +//@no-rustfix: overlapping suggestions #![deny(clippy::match_bool)] fn match_bool() { let test: bool = true; match test { + //~^ ERROR: you seem to be trying to match on a boolean expression true => 0, false => 42, }; let option = 1; match option == 1 { + //~^ ERROR: you seem to be trying to match on a boolean expression true => 1, false => 0, }; match test { + //~^ ERROR: you seem to be trying to match on a boolean expression true => (), false => { println!("Noooo!"); @@ -22,6 +26,7 @@ fn match_bool() { }; match test { + //~^ ERROR: you seem to be trying to match on a boolean expression false => { println!("Noooo!"); }, @@ -29,6 +34,11 @@ fn match_bool() { }; match test && test { + //~^ ERROR: this boolean expression can be simplified + //~| NOTE: `-D clippy::nonminimal-bool` implied by `-D warnings` + //~| ERROR: you seem to be trying to match on a boolean expression + //~| ERROR: equal expressions as operands to `&&` + //~| NOTE: `#[deny(clippy::eq_op)]` on by default false => { println!("Noooo!"); }, @@ -36,6 +46,7 @@ fn match_bool() { }; match test { + //~^ ERROR: you seem to be trying to match on a boolean expression false => { println!("Noooo!"); }, diff --git a/src/tools/clippy/tests/ui/match_bool.stderr b/src/tools/clippy/tests/ui/match_bool.stderr index 3fd0468e5..369f4e1c6 100644 --- a/src/tools/clippy/tests/ui/match_bool.stderr +++ b/src/tools/clippy/tests/ui/match_bool.stderr @@ -1,39 +1,43 @@ error: this boolean expression can be simplified - --> $DIR/match_bool.rs:31:11 + --> $DIR/match_bool.rs:36:11 | LL | match test && test { | ^^^^^^^^^^^^ help: try: `test` | = note: `-D clippy::nonminimal-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:6:5 + --> $DIR/match_bool.rs:7:5 | LL | / match test { +LL | | LL | | true => 0, LL | | false => 42, LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if test { 0 } else { 42 }` | note: the lint level is defined here - --> $DIR/match_bool.rs:1:9 + --> $DIR/match_bool.rs:2:9 | LL | #![deny(clippy::match_bool)] | ^^^^^^^^^^^^^^^^^^ error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:12:5 + --> $DIR/match_bool.rs:14:5 | LL | / match option == 1 { +LL | | LL | | true => 1, LL | | false => 0, LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if option == 1 { 1 } else { 0 }` error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:17:5 + --> $DIR/match_bool.rs:20:5 | LL | / match test { +LL | | LL | | true => (), LL | | false => { LL | | println!("Noooo!"); @@ -49,9 +53,10 @@ LL ~ }; | error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:24:5 + --> $DIR/match_bool.rs:28:5 | LL | / match test { +LL | | LL | | false => { LL | | println!("Noooo!"); LL | | }, @@ -67,12 +72,13 @@ LL ~ }; | error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:31:5 + --> $DIR/match_bool.rs:36:5 | LL | / match test && test { -LL | | false => { -LL | | println!("Noooo!"); -LL | | }, +LL | | +LL | | +LL | | +... | LL | | _ => (), LL | | }; | |_____^ @@ -85,7 +91,7 @@ LL ~ }; | error: equal expressions as operands to `&&` - --> $DIR/match_bool.rs:31:11 + --> $DIR/match_bool.rs:36:11 | LL | match test && test { | ^^^^^^^^^^^^ @@ -93,12 +99,12 @@ LL | match test && test { = note: `#[deny(clippy::eq_op)]` on by default error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:38:5 + --> $DIR/match_bool.rs:48:5 | LL | / match test { +LL | | LL | | false => { LL | | println!("Noooo!"); -LL | | }, ... | LL | | }, LL | | }; diff --git a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed index f19149cf9..05edc024b 100644 --- a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed +++ b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::match_like_matches_macro)] #![allow( unreachable_patterns, diff --git a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs index 8f4e58981..d6a0313cd 100644 --- a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs +++ b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::match_like_matches_macro)] #![allow( unreachable_patterns, diff --git a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr index b57b26284..c70252378 100644 --- a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr +++ b/src/tools/clippy/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:16:14 + --> $DIR/match_expr_like_matches_macro.rs:14:14 | LL | let _y = match x { | ______________^ @@ -9,9 +9,10 @@ LL | | }; | |_____^ help: try: `matches!(x, Some(0))` | = note: `-D clippy::match-like-matches-macro` implied by `-D warnings` + = 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:22:14 + --> $DIR/match_expr_like_matches_macro.rs:20:14 | LL | let _w = match x { | ______________^ @@ -21,9 +22,10 @@ LL | | }; | |_____^ help: try: `x.is_some()` | = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = 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:28:14 + --> $DIR/match_expr_like_matches_macro.rs:26:14 | LL | let _z = match x { | ______________^ @@ -33,7 +35,7 @@ LL | | }; | |_____^ help: try: `x.is_none()` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:34:15 + --> $DIR/match_expr_like_matches_macro.rs:32:15 | LL | let _zz = match x { | _______________^ @@ -43,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:40:16 + --> $DIR/match_expr_like_matches_macro.rs:38: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:64:20 + --> $DIR/match_expr_like_matches_macro.rs:62:20 | LL | let _ans = match x { | ____________________^ @@ -60,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:74:20 + --> $DIR/match_expr_like_matches_macro.rs:72:20 | LL | let _ans = match x { | ____________________^ @@ -73,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:84:20 + --> $DIR/match_expr_like_matches_macro.rs:82:20 | LL | let _ans = match x { | ____________________^ @@ -84,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:144:18 + --> $DIR/match_expr_like_matches_macro.rs:142:18 | LL | let _z = match &z { | __________________^ @@ -94,7 +96,7 @@ LL | | }; | |_________^ help: try: `matches!(z, Some(3))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:153:18 + --> $DIR/match_expr_like_matches_macro.rs:151:18 | LL | let _z = match &z { | __________________^ @@ -104,7 +106,7 @@ LL | | }; | |_________^ help: try: `matches!(&z, Some(3))` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:170:21 + --> $DIR/match_expr_like_matches_macro.rs:168:21 | LL | let _ = match &z { | _____________________^ @@ -114,7 +116,7 @@ LL | | }; | |_____________^ help: try: `matches!(&z, AnEnum::X)` error: match expression looks like `matches!` macro - --> $DIR/match_expr_like_matches_macro.rs:184:20 + --> $DIR/match_expr_like_matches_macro.rs:182:20 | LL | let _res = match &val { | ____________________^ @@ -124,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:196:20 + --> $DIR/match_expr_like_matches_macro.rs:194:20 | LL | let _res = match &val { | ____________________^ @@ -134,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:254:14 + --> $DIR/match_expr_like_matches_macro.rs:252:14 | LL | let _y = match Some(5) { | ______________^ diff --git a/src/tools/clippy/tests/ui/match_on_vec_items.rs b/src/tools/clippy/tests/ui/match_on_vec_items.rs index cf9c279cd..f7b8500fa 100644 --- a/src/tools/clippy/tests/ui/match_on_vec_items.rs +++ b/src/tools/clippy/tests/ui/match_on_vec_items.rs @@ -1,6 +1,6 @@ #![warn(clippy::match_on_vec_items)] #![allow(clippy::redundant_at_rest_pattern, clippy::useless_vec)] - +//@no-rustfix fn match_with_wildcard() { let arr = vec![0, 1, 2, 3]; let range = 1..3; @@ -8,6 +8,8 @@ fn match_with_wildcard() { // Lint, may panic match arr[idx] { + //~^ ERROR: indexing into a vector may panic + //~| NOTE: `-D clippy::match-on-vec-items` implied by `-D warnings` 0 => println!("0"), 1 => println!("1"), _ => {}, @@ -15,6 +17,7 @@ fn match_with_wildcard() { // Lint, may panic match arr[range] { + //~^ ERROR: indexing into a vector may panic [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), _ => {}, @@ -28,6 +31,7 @@ fn match_without_wildcard() { // Lint, may panic match arr[idx] { + //~^ ERROR: indexing into a vector may panic 0 => println!("0"), 1 => println!("1"), num => {}, @@ -35,6 +39,7 @@ fn match_without_wildcard() { // Lint, may panic match arr[range] { + //~^ ERROR: indexing into a vector may panic [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), [ref sub @ ..] => {}, @@ -48,6 +53,7 @@ fn match_wildcard_and_action() { // Lint, may panic match arr[idx] { + //~^ ERROR: indexing into a vector may panic 0 => println!("0"), 1 => println!("1"), _ => println!("Hello, World!"), @@ -55,6 +61,7 @@ fn match_wildcard_and_action() { // Lint, may panic match arr[range] { + //~^ ERROR: indexing into a vector may panic [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), _ => println!("Hello, World!"), @@ -68,6 +75,7 @@ fn match_vec_ref() { // Lint, may panic match arr[idx] { + //~^ ERROR: indexing into a vector may panic 0 => println!("0"), 1 => println!("1"), _ => {}, @@ -75,6 +83,7 @@ fn match_vec_ref() { // Lint, may panic match arr[range] { + //~^ ERROR: indexing into a vector may panic [0, 1] => println!("0 1"), [1, 2] => println!("1 2"), _ => {}, diff --git a/src/tools/clippy/tests/ui/match_on_vec_items.stderr b/src/tools/clippy/tests/ui/match_on_vec_items.stderr index fc4a3ce19..140a458cb 100644 --- a/src/tools/clippy/tests/ui/match_on_vec_items.stderr +++ b/src/tools/clippy/tests/ui/match_on_vec_items.stderr @@ -5,45 +5,46 @@ LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` | = note: `-D clippy::match-on-vec-items` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_on_vec_items)]` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:17:11 + --> $DIR/match_on_vec_items.rs:19:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:30:11 + --> $DIR/match_on_vec_items.rs:33:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:37:11 + --> $DIR/match_on_vec_items.rs:41:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:50:11 + --> $DIR/match_on_vec_items.rs:55:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:57:11 + --> $DIR/match_on_vec_items.rs:63:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:70:11 + --> $DIR/match_on_vec_items.rs:77:11 | LL | match arr[idx] { | ^^^^^^^^ help: try: `arr.get(idx)` error: indexing into a vector may panic - --> $DIR/match_on_vec_items.rs:77:11 + --> $DIR/match_on_vec_items.rs:85:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try: `arr.get(range)` diff --git a/src/tools/clippy/tests/ui/match_overlapping_arm.rs b/src/tools/clippy/tests/ui/match_overlapping_arm.rs index b78c1fd06..c2c2f2839 100644 --- a/src/tools/clippy/tests/ui/match_overlapping_arm.rs +++ b/src/tools/clippy/tests/ui/match_overlapping_arm.rs @@ -10,12 +10,14 @@ fn overlapping() { match 42 { 0..=10 => println!("0..=10"), + //~^ ERROR: some ranges overlap 0..=11 => println!("0..=11"), _ => (), } match 42 { 0..=5 => println!("0..=5"), + //~^ ERROR: some ranges overlap 6..=7 => println!("6..=7"), FOO..=11 => println!("FOO..=11"), _ => (), @@ -53,6 +55,7 @@ fn overlapping() { match 42 { 0..11 => println!("0..11"), + //~^ ERROR: some ranges overlap 0..=11 => println!("0..=11"), _ => (), } @@ -78,11 +81,13 @@ fn overlapping() { match 42 { 5..14 => println!("5..14"), 0..=10 => println!("0..=10"), + //~^ ERROR: some ranges overlap _ => (), } match 42 { 0..7 => println!("0..7"), + //~^ ERROR: some ranges overlap 0..=10 => println!("0..=10"), _ => (), } @@ -95,6 +100,7 @@ fn overlapping() { match 42 { ..=23 => println!("..=23"), + //~^ ERROR: some ranges overlap ..26 => println!("..26"), _ => (), } @@ -104,6 +110,7 @@ fn overlapping() { 5..=10 => (), 0..=20 => (), 21..=30 => (), + //~^ ERROR: some ranges overlap 21..=40 => (), _ => (), } @@ -118,6 +125,7 @@ fn overlapping() { // Only warn about the first if there are multiple overlaps match 42u128 { 0..=0x0000_0000_0000_00ff => (), + //~^ ERROR: some ranges overlap 0..=0x0000_0000_0000_ffff => (), 0..=0x0000_0000_ffff_ffff => (), 0..=0xffff_ffff_ffff_ffff => (), diff --git a/src/tools/clippy/tests/ui/match_overlapping_arm.stderr b/src/tools/clippy/tests/ui/match_overlapping_arm.stderr index b98d4799e..322c704f2 100644 --- a/src/tools/clippy/tests/ui/match_overlapping_arm.stderr +++ b/src/tools/clippy/tests/ui/match_overlapping_arm.stderr @@ -5,92 +5,93 @@ LL | 0..=10 => println!("0..=10"), | ^^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:13:9 + --> $DIR/match_overlapping_arm.rs:14:9 | LL | 0..=11 => println!("0..=11"), | ^^^^^^ = note: `-D clippy::match-overlapping-arm` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_overlapping_arm)]` error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:18:9 + --> $DIR/match_overlapping_arm.rs:19:9 | LL | 0..=5 => println!("0..=5"), | ^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:20:9 + --> $DIR/match_overlapping_arm.rs:22:9 | LL | FOO..=11 => println!("FOO..=11"), | ^^^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:55:9 + --> $DIR/match_overlapping_arm.rs:57:9 | LL | 0..11 => println!("0..11"), | ^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:56:9 + --> $DIR/match_overlapping_arm.rs:59:9 | LL | 0..=11 => println!("0..=11"), | ^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:80:9 + --> $DIR/match_overlapping_arm.rs:83:9 | LL | 0..=10 => println!("0..=10"), | ^^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:79:9 + --> $DIR/match_overlapping_arm.rs:82:9 | LL | 5..14 => println!("5..14"), | ^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:85:9 + --> $DIR/match_overlapping_arm.rs:89:9 | LL | 0..7 => println!("0..7"), | ^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:86:9 + --> $DIR/match_overlapping_arm.rs:91:9 | LL | 0..=10 => println!("0..=10"), | ^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:97:9 + --> $DIR/match_overlapping_arm.rs:102:9 | LL | ..=23 => println!("..=23"), | ^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:98:9 + --> $DIR/match_overlapping_arm.rs:104:9 | LL | ..26 => println!("..26"), | ^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:106:9 + --> $DIR/match_overlapping_arm.rs:112:9 | LL | 21..=30 => (), | ^^^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:107:9 + --> $DIR/match_overlapping_arm.rs:114:9 | LL | 21..=40 => (), | ^^^^^^^ error: some ranges overlap - --> $DIR/match_overlapping_arm.rs:120:9 + --> $DIR/match_overlapping_arm.rs:127:9 | LL | 0..=0x0000_0000_0000_00ff => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: overlaps with this - --> $DIR/match_overlapping_arm.rs:121:9 + --> $DIR/match_overlapping_arm.rs:129:9 | LL | 0..=0x0000_0000_0000_ffff => (), | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/match_ref_pats.fixed b/src/tools/clippy/tests/ui/match_ref_pats.fixed index 50c3dcc1e..f8d47b0fd 100644 --- a/src/tools/clippy/tests/ui/match_ref_pats.fixed +++ b/src/tools/clippy/tests/ui/match_ref_pats.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_ref_pats)] #![allow(dead_code, unused_variables)] #![allow(clippy::enum_variant_names, clippy::equatable_if_let, clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/match_ref_pats.rs b/src/tools/clippy/tests/ui/match_ref_pats.rs index d29ddacc0..bcd7bf7ab 100644 --- a/src/tools/clippy/tests/ui/match_ref_pats.rs +++ b/src/tools/clippy/tests/ui/match_ref_pats.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_ref_pats)] #![allow(dead_code, unused_variables)] #![allow(clippy::enum_variant_names, clippy::equatable_if_let, clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/match_ref_pats.stderr b/src/tools/clippy/tests/ui/match_ref_pats.stderr index 1294e0fe5..e3bb2824a 100644 --- a/src/tools/clippy/tests/ui/match_ref_pats.stderr +++ b/src/tools/clippy/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:9:9 + --> $DIR/match_ref_pats.rs:8:9 | LL | / match v { LL | | &Some(v) => println!("{:?}", v), @@ -8,6 +8,7 @@ LL | | } | |_________^ | = note: `-D clippy::match-ref-pats` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_ref_pats)]` help: instead of prefixing all patterns with `&`, you can dereference the expression | LL ~ match *v { @@ -16,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:26:5 + --> $DIR/match_ref_pats.rs:25:5 | LL | / match &w { LL | | &Some(v) => println!("{:?}", v), @@ -32,21 +33,22 @@ LL ~ None => println!("none"), | error: redundant pattern matching, consider using `is_none()` - --> $DIR/match_ref_pats.rs:38:12 + --> $DIR/match_ref_pats.rs:37:12 | LL | if let &None = a { | -------^^^^^---- help: try: `if a.is_none()` | = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_none()` - --> $DIR/match_ref_pats.rs:43:12 + --> $DIR/match_ref_pats.rs:42: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:103:9 + --> $DIR/match_ref_pats.rs:102:9 | LL | / match foobar_variant!(0) { LL | | &FooBar::Foo => println!("Foo"), diff --git a/src/tools/clippy/tests/ui/match_result_ok.fixed b/src/tools/clippy/tests/ui/match_result_ok.fixed index fe67b225f..8d7cddc0a 100644 --- a/src/tools/clippy/tests/ui/match_result_ok.fixed +++ b/src/tools/clippy/tests/ui/match_result_ok.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_result_ok)] #![allow(dead_code)] #![allow(clippy::boxed_local, clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/match_result_ok.rs b/src/tools/clippy/tests/ui/match_result_ok.rs index eac382e1f..9a18b813a 100644 --- a/src/tools/clippy/tests/ui/match_result_ok.rs +++ b/src/tools/clippy/tests/ui/match_result_ok.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_result_ok)] #![allow(dead_code)] #![allow(clippy::boxed_local, clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/match_result_ok.stderr b/src/tools/clippy/tests/ui/match_result_ok.stderr index cbdc56aa2..de0361bd6 100644 --- a/src/tools/clippy/tests/ui/match_result_ok.stderr +++ b/src/tools/clippy/tests/ui/match_result_ok.stderr @@ -1,17 +1,18 @@ error: matching on `Some` with `ok()` is redundant - --> $DIR/match_result_ok.rs:9:5 + --> $DIR/match_result_ok.rs:8:5 | LL | if let Some(y) = x.parse().ok() { y } else { 0 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::match-result-ok` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_result_ok)]` help: consider matching on `Ok(y)` and removing the call to `ok` instead | LL | if let Ok(y) = x.parse() { y } else { 0 } | ~~~~~~~~~~~~~~~~~~~~~~~~ error: matching on `Some` with `ok()` is redundant - --> $DIR/match_result_ok.rs:19:9 + --> $DIR/match_result_ok.rs:18:9 | LL | if let Some(y) = x . parse() . ok () { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +23,7 @@ LL | if let Ok(y) = x . parse() { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: matching on `Some` with `ok()` is redundant - --> $DIR/match_result_ok.rs:45:5 + --> $DIR/match_result_ok.rs:44:5 | LL | while let Some(a) = wat.next().ok() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/match_same_arms.rs b/src/tools/clippy/tests/ui/match_same_arms.rs index fad6a7db9..2f4652dcf 100644 --- a/src/tools/clippy/tests/ui/match_same_arms.rs +++ b/src/tools/clippy/tests/ui/match_same_arms.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::match_same_arms)] pub enum Abc { diff --git a/src/tools/clippy/tests/ui/match_same_arms.stderr b/src/tools/clippy/tests/ui/match_same_arms.stderr index 88b9a20a3..824dcfdce 100644 --- a/src/tools/clippy/tests/ui/match_same_arms.stderr +++ b/src/tools/clippy/tests/ui/match_same_arms.stderr @@ -1,19 +1,20 @@ error: this match arm has an identical body to the `_` wildcard arm - --> $DIR/match_same_arms.rs:11:9 + --> $DIR/match_same_arms.rs:12:9 | LL | Abc::A => 0, | ^^^^^^^^^^^ help: try removing the arm | = help: or try changing either arm body note: `_` wildcard arm here - --> $DIR/match_same_arms.rs:13:9 + --> $DIR/match_same_arms.rs:14:9 | LL | _ => 0, | ^^^^^^ = note: `-D clippy::match-same-arms` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]` error: this match arm has an identical body to another arm - --> $DIR/match_same_arms.rs:17:9 + --> $DIR/match_same_arms.rs:18:9 | LL | (1, .., 3) => 42, | ----------^^^^^^ @@ -22,13 +23,13 @@ LL | (1, .., 3) => 42, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms.rs:18:9 + --> $DIR/match_same_arms.rs:19:9 | LL | (.., 3) => 42, | ^^^^^^^^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms.rs:24:9 + --> $DIR/match_same_arms.rs:25:9 | LL | 51 => 1, | --^^^^^ @@ -37,13 +38,13 @@ LL | 51 => 1, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms.rs:23:9 + --> $DIR/match_same_arms.rs:24:9 | LL | 42 => 1, | ^^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms.rs:25:9 + --> $DIR/match_same_arms.rs:26:9 | LL | 41 => 2, | --^^^^^ @@ -52,13 +53,13 @@ LL | 41 => 2, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms.rs:26:9 + --> $DIR/match_same_arms.rs:27:9 | LL | 52 => 2, | ^^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms.rs:32:9 + --> $DIR/match_same_arms.rs:33:9 | LL | 2 => 2, | -^^^^^ @@ -67,13 +68,13 @@ LL | 2 => 2, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms.rs:31:9 + --> $DIR/match_same_arms.rs:32:9 | LL | 1 => 2, | ^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms.rs:34:9 + --> $DIR/match_same_arms.rs:35:9 | LL | 3 => 2, | -^^^^^ @@ -82,13 +83,13 @@ LL | 3 => 2, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms.rs:31:9 + --> $DIR/match_same_arms.rs:32:9 | LL | 1 => 2, | ^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms.rs:32:9 + --> $DIR/match_same_arms.rs:33:9 | LL | 2 => 2, | -^^^^^ @@ -97,13 +98,13 @@ LL | 2 => 2, | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms.rs:34:9 + --> $DIR/match_same_arms.rs:35:9 | LL | 3 => 2, | ^^^^^^ error: this match arm has an identical body to another arm - --> $DIR/match_same_arms.rs:51:17 + --> $DIR/match_same_arms.rs:52:17 | LL | CommandInfo::External { name, .. } => name.to_string(), | ----------------------------------^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +113,7 @@ LL | CommandInfo::External { name, .. } => name.to_string(), | = help: or try changing either arm body note: other arm here - --> $DIR/match_same_arms.rs:50:17 + --> $DIR/match_same_arms.rs:51:17 | LL | CommandInfo::BuiltIn { name, .. } => name.to_string(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/match_same_arms2.rs b/src/tools/clippy/tests/ui/match_same_arms2.rs index b1b9a6ae3..525a355f4 100644 --- a/src/tools/clippy/tests/ui/match_same_arms2.rs +++ b/src/tools/clippy/tests/ui/match_same_arms2.rs @@ -4,7 +4,7 @@ clippy::diverging_sub_expression, clippy::uninlined_format_args )] - +//@no-rustfix fn bar(_: T) {} fn foo() -> bool { unimplemented!() diff --git a/src/tools/clippy/tests/ui/match_same_arms2.stderr b/src/tools/clippy/tests/ui/match_same_arms2.stderr index a73481875..40b20c7e1 100644 --- a/src/tools/clippy/tests/ui/match_same_arms2.stderr +++ b/src/tools/clippy/tests/ui/match_same_arms2.stderr @@ -23,6 +23,7 @@ LL | | a LL | | }, | |_________^ = note: `-D clippy::match-same-arms` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]` error: this match arm has an identical body to another arm --> $DIR/match_same_arms2.rs:38:9 @@ -147,6 +148,7 @@ LL | | }; | |_____^ help: try: `!matches!(x, E::A | E::B)` | = note: `-D clippy::match-like-matches-macro` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/match_same_arms_non_exhaustive.rs b/src/tools/clippy/tests/ui/match_same_arms_non_exhaustive.rs index 07421173a..1ee048bf7 100644 --- a/src/tools/clippy/tests/ui/match_same_arms_non_exhaustive.rs +++ b/src/tools/clippy/tests/ui/match_same_arms_non_exhaustive.rs @@ -1,7 +1,7 @@ #![feature(non_exhaustive_omitted_patterns_lint)] #![warn(clippy::match_same_arms)] #![no_main] - +//@no-rustfix use std::sync::atomic::Ordering; // #[non_exhaustive] enum pub fn f(x: Ordering) { @@ -39,6 +39,7 @@ pub fn g(x: Ordering) { Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), Ordering::AcqRel | Ordering::SeqCst => panic!(), + //~^ ERROR: this match arm has an identical body to the `_` wildcard arm _ => panic!(), } } @@ -52,6 +53,7 @@ mod g { Ordering::Release => println!("release"), Ordering::Acquire => println!("acquire"), Ordering::AcqRel | Ordering::SeqCst => panic!(), + //~^ ERROR: this match arm has an identical body to the `_` wildcard arm _ => panic!(), } } diff --git a/src/tools/clippy/tests/ui/match_same_arms_non_exhaustive.stderr b/src/tools/clippy/tests/ui/match_same_arms_non_exhaustive.stderr index 088f7d5c0..a03953633 100644 --- a/src/tools/clippy/tests/ui/match_same_arms_non_exhaustive.stderr +++ b/src/tools/clippy/tests/ui/match_same_arms_non_exhaustive.stderr @@ -6,21 +6,22 @@ LL | Ordering::AcqRel | Ordering::SeqCst => panic!(), | = help: or try changing either arm body note: `_` wildcard arm here - --> $DIR/match_same_arms_non_exhaustive.rs:42:9 + --> $DIR/match_same_arms_non_exhaustive.rs:43:9 | LL | _ => panic!(), | ^^^^^^^^^^^^^ = note: `-D clippy::match-same-arms` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]` error: this match arm has an identical body to the `_` wildcard arm - --> $DIR/match_same_arms_non_exhaustive.rs:54:13 + --> $DIR/match_same_arms_non_exhaustive.rs:55:13 | LL | Ordering::AcqRel | Ordering::SeqCst => panic!(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the arm | = help: or try changing either arm body note: `_` wildcard arm here - --> $DIR/match_same_arms_non_exhaustive.rs:55:13 + --> $DIR/match_same_arms_non_exhaustive.rs:57:13 | LL | _ => panic!(), | ^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/match_single_binding.fixed b/src/tools/clippy/tests/ui/match_single_binding.fixed index f59ff456b..3a3eee4c9 100644 --- a/src/tools/clippy/tests/ui/match_single_binding.fixed +++ b/src/tools/clippy/tests/ui/match_single_binding.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_single_binding)] #![allow( unused, diff --git a/src/tools/clippy/tests/ui/match_single_binding.rs b/src/tools/clippy/tests/ui/match_single_binding.rs index e293bc33c..ff2f842ac 100644 --- a/src/tools/clippy/tests/ui/match_single_binding.rs +++ b/src/tools/clippy/tests/ui/match_single_binding.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_single_binding)] #![allow( unused, diff --git a/src/tools/clippy/tests/ui/match_single_binding.stderr b/src/tools/clippy/tests/ui/match_single_binding.stderr index 8998786de..81ec200df 100644 --- a/src/tools/clippy/tests/ui/match_single_binding.stderr +++ b/src/tools/clippy/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:34:5 + --> $DIR/match_single_binding.rs:33:5 | LL | / match (a, b, c) { LL | | (x, y, z) => { @@ -9,6 +9,7 @@ LL | | } | |_____^ | = note: `-D clippy::match-single-binding` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_single_binding)]` help: consider using a `let` statement | LL ~ let (x, y, z) = (a, b, c); @@ -18,7 +19,7 @@ LL + } | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:40:5 + --> $DIR/match_single_binding.rs:39:5 | LL | / match (a, b, c) { LL | | (x, y, z) => println!("{} {} {}", x, y, z), @@ -32,7 +33,7 @@ LL + println!("{} {} {}", x, y, z); | error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:57:5 + --> $DIR/match_single_binding.rs:56:5 | LL | / match a { LL | | _ => println!("whatever"), @@ -40,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:61:5 + --> $DIR/match_single_binding.rs:60:5 | LL | / match a { LL | | _ => { @@ -59,7 +60,7 @@ LL + } | error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:68:5 + --> $DIR/match_single_binding.rs:67:5 | LL | / match a { LL | | _ => { @@ -81,7 +82,7 @@ LL + } | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:78:5 + --> $DIR/match_single_binding.rs:77:5 | LL | / match p { LL | | Point { x, y } => println!("Coords: ({}, {})", x, y), @@ -95,7 +96,7 @@ LL + println!("Coords: ({}, {})", x, y); | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:82:5 + --> $DIR/match_single_binding.rs:81:5 | LL | / match p { LL | | Point { x: x1, y: y1 } => println!("Coords: ({}, {})", x1, y1), @@ -109,7 +110,7 @@ LL + println!("Coords: ({}, {})", x1, y1); | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:87:5 + --> $DIR/match_single_binding.rs:86:5 | LL | / match x { LL | | ref r => println!("Got a reference to {}", r), @@ -123,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:92:5 + --> $DIR/match_single_binding.rs:91:5 | LL | / match x { LL | | ref mut mr => println!("Got a mutable reference to {}", mr), @@ -137,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:96:5 + --> $DIR/match_single_binding.rs:95:5 | LL | / let product = match coords() { LL | | Point { x, y } => x * y, @@ -151,7 +152,7 @@ LL + let product = x * y; | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:104:18 + --> $DIR/match_single_binding.rs:103:18 | LL | .map(|i| match i.unwrap() { | __________________^ @@ -168,7 +169,7 @@ LL ~ }) | error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:130:5 + --> $DIR/match_single_binding.rs:129:5 | LL | / match x { LL | | // => @@ -177,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:139:5 + --> $DIR/match_single_binding.rs:138:5 | LL | / val = match val.split_at(idx) { LL | | (pre, suf) => { @@ -197,7 +198,7 @@ LL ~ }; | error: this match could be replaced by its scrutinee and body - --> $DIR/match_single_binding.rs:152:16 + --> $DIR/match_single_binding.rs:151:16 | LL | let _ = || match side_effects() { | ________________^ @@ -214,7 +215,7 @@ LL ~ }; | error: this match could be written as a `let` statement - --> $DIR/match_single_binding.rs:158:5 + --> $DIR/match_single_binding.rs:157:5 | LL | / match r { LL | | x => match x { @@ -239,7 +240,7 @@ LL ~ }; | error: this match could be replaced by its body itself - --> $DIR/match_single_binding.rs:171:5 + --> $DIR/match_single_binding.rs:170:5 | LL | / match 1 { LL | | _ => (), @@ -247,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:175:13 + --> $DIR/match_single_binding.rs:174:13 | LL | let a = match 1 { | _____________^ @@ -256,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:179:5 + --> $DIR/match_single_binding.rs:178:5 | LL | / match 1 { LL | | _ => side_effects(), @@ -264,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:183:13 + --> $DIR/match_single_binding.rs:182:13 | LL | let b = match 1 { | _____________^ @@ -273,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:187:5 + --> $DIR/match_single_binding.rs:186:5 | LL | / match 1 { LL | | _ => println!("1"), @@ -281,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:191:13 + --> $DIR/match_single_binding.rs:190:13 | LL | let c = match 1 { | _____________^ @@ -290,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:196:9 + --> $DIR/match_single_binding.rs:195:9 | LL | / match 1 { LL | | _ => (), @@ -298,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:199:9 + --> $DIR/match_single_binding.rs:198:9 | LL | / match 1 { LL | | _ => side_effects(), @@ -306,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:202:9 + --> $DIR/match_single_binding.rs:201:9 | LL | / match 1 { LL | | _ => println!("1"), diff --git a/src/tools/clippy/tests/ui/match_single_binding2.fixed b/src/tools/clippy/tests/ui/match_single_binding2.fixed index adfb4ba91..5673aa78c 100644 --- a/src/tools/clippy/tests/ui/match_single_binding2.fixed +++ b/src/tools/clippy/tests/ui/match_single_binding2.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_single_binding)] #![allow(unused_variables)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/match_single_binding2.rs b/src/tools/clippy/tests/ui/match_single_binding2.rs index b5cfe3654..575e7f581 100644 --- a/src/tools/clippy/tests/ui/match_single_binding2.rs +++ b/src/tools/clippy/tests/ui/match_single_binding2.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_single_binding)] #![allow(unused_variables)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/match_single_binding2.stderr b/src/tools/clippy/tests/ui/match_single_binding2.stderr index e180b93e7..e7b9ef8a1 100644 --- a/src/tools/clippy/tests/ui/match_single_binding2.stderr +++ b/src/tools/clippy/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:18:36 + --> $DIR/match_single_binding2.rs:17:36 | LL | Some((iter, _item)) => match iter.size_hint() { | ____________________________________^ @@ -8,6 +8,7 @@ LL | | }, | |_____________^ | = note: `-D clippy::match-single-binding` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_single_binding)]` help: consider using a `let` statement | LL ~ Some((iter, _item)) => { @@ -17,7 +18,7 @@ LL ~ }, | error: this match could be written as a `let` statement - --> $DIR/match_single_binding2.rs:31:13 + --> $DIR/match_single_binding2.rs:30:13 | LL | / match get_tup() { LL | | (a, b) => println!("a {:?} and b {:?}", a, b), @@ -31,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:42:5 + --> $DIR/match_single_binding2.rs:41:5 | LL | / match side_effects() { LL | | _ => println!("Side effects"), @@ -45,7 +46,7 @@ LL + println!("Side effects"); | error: this match could be replaced by its scrutinee and body - --> $DIR/match_single_binding2.rs:49:5 + --> $DIR/match_single_binding2.rs:48:5 | LL | / match match x { LL | | 0 => 1, diff --git a/src/tools/clippy/tests/ui/match_str_case_mismatch.fixed b/src/tools/clippy/tests/ui/match_str_case_mismatch.fixed index cd53b1f06..a608ab0c0 100644 --- a/src/tools/clippy/tests/ui/match_str_case_mismatch.fixed +++ b/src/tools/clippy/tests/ui/match_str_case_mismatch.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_str_case_mismatch)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/match_str_case_mismatch.rs b/src/tools/clippy/tests/ui/match_str_case_mismatch.rs index 688530566..1e4269d1d 100644 --- a/src/tools/clippy/tests/ui/match_str_case_mismatch.rs +++ b/src/tools/clippy/tests/ui/match_str_case_mismatch.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::match_str_case_mismatch)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/match_str_case_mismatch.stderr b/src/tools/clippy/tests/ui/match_str_case_mismatch.stderr index 197520a3d..f799a4698 100644 --- a/src/tools/clippy/tests/ui/match_str_case_mismatch.stderr +++ b/src/tools/clippy/tests/ui/match_str_case_mismatch.stderr @@ -1,17 +1,18 @@ error: this `match` arm has a differing case than its expression - --> $DIR/match_str_case_mismatch.rs:113:9 + --> $DIR/match_str_case_mismatch.rs:112:9 | LL | "Bar" => {}, | ^^^^^ | = note: `-D clippy::match-str-case-mismatch` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_str_case_mismatch)]` help: consider changing the case of this arm to respect `to_ascii_lowercase` | LL | "bar" => {}, | ~~~~~ error: this `match` arm has a differing case than its expression - --> $DIR/match_str_case_mismatch.rs:123:9 + --> $DIR/match_str_case_mismatch.rs:122:9 | LL | "~!@#$%^&*()-_=+Foo" => {}, | ^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +23,7 @@ LL | "~!@#$%^&*()-_=+foo" => {}, | ~~~~~~~~~~~~~~~~~~~~ error: this `match` arm has a differing case than its expression - --> $DIR/match_str_case_mismatch.rs:135:9 + --> $DIR/match_str_case_mismatch.rs:134:9 | LL | "Воды" => {}, | ^^^^^^ @@ -33,7 +34,7 @@ LL | "воды" => {}, | ~~~~~~ error: this `match` arm has a differing case than its expression - --> $DIR/match_str_case_mismatch.rs:146:9 + --> $DIR/match_str_case_mismatch.rs:145:9 | LL | "barDz" => {}, | ^^^^^^ @@ -44,7 +45,7 @@ LL | "bardz" => {}, | ~~~~~~ error: this `match` arm has a differing case than its expression - --> $DIR/match_str_case_mismatch.rs:156:9 + --> $DIR/match_str_case_mismatch.rs:155:9 | LL | "bARʁ" => {}, | ^^^^^^ @@ -55,7 +56,7 @@ LL | "BARʁ" => {}, | ~~~~~~ error: this `match` arm has a differing case than its expression - --> $DIR/match_str_case_mismatch.rs:166:9 + --> $DIR/match_str_case_mismatch.rs:165:9 | LL | "Bar" => {}, | ^^^^^ @@ -66,7 +67,7 @@ LL | "bar" => {}, | ~~~~~ error: this `match` arm has a differing case than its expression - --> $DIR/match_str_case_mismatch.rs:181:9 + --> $DIR/match_str_case_mismatch.rs:180:9 | LL | "bAR" => {}, | ^^^^^ diff --git a/src/tools/clippy/tests/ui/match_wild_err_arm.rs b/src/tools/clippy/tests/ui/match_wild_err_arm.rs index 5a552e4ae..7bdd75d7f 100644 --- a/src/tools/clippy/tests/ui/match_wild_err_arm.rs +++ b/src/tools/clippy/tests/ui/match_wild_err_arm.rs @@ -22,18 +22,24 @@ fn match_wild_err_arm() { Ok(3) => println!("ok"), Ok(_) => println!("ok"), Err(_) => panic!("err"), + //~^ ERROR: `Err(_)` matches all errors + //~| NOTE: match each error separately or use the error output, or use `.expect(ms } match x { Ok(3) => println!("ok"), Ok(_) => println!("ok"), Err(_) => panic!(), + //~^ ERROR: `Err(_)` matches all errors + //~| NOTE: match each error separately or use the error output, or use `.expect(ms } match x { Ok(3) => println!("ok"), Ok(_) => println!("ok"), Err(_) => { + //~^ ERROR: `Err(_)` matches all errors + //~| NOTE: match each error separately or use the error output, or use `.expect(ms panic!(); }, } @@ -42,6 +48,8 @@ fn match_wild_err_arm() { Ok(3) => println!("ok"), Ok(_) => println!("ok"), Err(_e) => panic!(), + //~^ ERROR: `Err(_e)` matches all errors + //~| NOTE: match each error separately or use the error output, or use `.expect(ms } // Allowed when used in `panic!`. diff --git a/src/tools/clippy/tests/ui/match_wild_err_arm.stderr b/src/tools/clippy/tests/ui/match_wild_err_arm.stderr index a9f54feac..c120aec5b 100644 --- a/src/tools/clippy/tests/ui/match_wild_err_arm.stderr +++ b/src/tools/clippy/tests/ui/match_wild_err_arm.stderr @@ -6,9 +6,10 @@ LL | Err(_) => panic!("err"), | = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable = note: `-D clippy::match-wild-err-arm` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_wild_err_arm)]` error: `Err(_)` matches all errors - --> $DIR/match_wild_err_arm.rs:30:9 + --> $DIR/match_wild_err_arm.rs:32:9 | LL | Err(_) => panic!(), | ^^^^^^ @@ -16,7 +17,7 @@ LL | Err(_) => panic!(), = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable error: `Err(_)` matches all errors - --> $DIR/match_wild_err_arm.rs:36:9 + --> $DIR/match_wild_err_arm.rs:40:9 | LL | Err(_) => { | ^^^^^^ @@ -24,7 +25,7 @@ LL | Err(_) => { = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable error: `Err(_e)` matches all errors - --> $DIR/match_wild_err_arm.rs:44:9 + --> $DIR/match_wild_err_arm.rs:50:9 | LL | Err(_e) => panic!(), | ^^^^^^^ diff --git a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.fixed b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.fixed index d2e6fef07..e5ea2fdde 100644 --- a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.fixed +++ b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::match_wildcard_for_single_variants)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.rs b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.rs index cff0c8960..dbd7fbe16 100644 --- a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.rs +++ b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::match_wildcard_for_single_variants)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.stderr b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.stderr index 40ff4fbd3..e07d3bdd3 100644 --- a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.stderr +++ b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.stderr @@ -1,61 +1,62 @@ error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:24:13 + --> $DIR/match_wildcard_for_single_variants.rs:22:13 | LL | _ => (), | ^ help: try: `Self::Rgb(..)` | = note: `-D clippy::match-wildcard-for-single-variants` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::match_wildcard_for_single_variants)]` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:34:9 + --> $DIR/match_wildcard_for_single_variants.rs:32:9 | LL | _ => {}, | ^ help: try: `Foo::C` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:44:9 + --> $DIR/match_wildcard_for_single_variants.rs:42:9 | LL | _ => {}, | ^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:52:9 + --> $DIR/match_wildcard_for_single_variants.rs:50:9 | LL | _ => {}, | ^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:58:9 + --> $DIR/match_wildcard_for_single_variants.rs:56:9 | LL | _ => {}, | ^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:75:9 + --> $DIR/match_wildcard_for_single_variants.rs:73:9 | LL | &_ => (), | ^^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:84:9 + --> $DIR/match_wildcard_for_single_variants.rs:82:9 | LL | _ => (), | ^ help: try: `C::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:91:9 + --> $DIR/match_wildcard_for_single_variants.rs:89:9 | LL | _ => (), | ^ help: try: `Color::Blue` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:126:13 + --> $DIR/match_wildcard_for_single_variants.rs:124:13 | LL | _ => (), | ^ help: try: `Enum::__Private` error: wildcard matches only a single variant and will also match any future added variants - --> $DIR/match_wildcard_for_single_variants.rs:153:13 + --> $DIR/match_wildcard_for_single_variants.rs:151:13 | LL | _ => 2, | ^ help: try: `Foo::B` diff --git a/src/tools/clippy/tests/ui/mem_forget.rs b/src/tools/clippy/tests/ui/mem_forget.rs index b6c8d9e53..1f508b3bc 100644 --- a/src/tools/clippy/tests/ui/mem_forget.rs +++ b/src/tools/clippy/tests/ui/mem_forget.rs @@ -12,15 +12,23 @@ fn main() { let six: Arc = Arc::new(6); memstuff::forget(six); + //~^ ERROR: usage of `mem::forget` on `Drop` type + //~| NOTE: argument has type `std::sync::Arc` let seven: Rc = Rc::new(7); std::mem::forget(seven); + //~^ ERROR: usage of `mem::forget` on `Drop` type + //~| NOTE: argument has type `std::rc::Rc` let eight: Vec = vec![8]; forgetSomething(eight); + //~^ ERROR: usage of `mem::forget` on `Drop` type + //~| NOTE: argument has type `std::vec::Vec` let string = String::new(); std::mem::forget(string); + //~^ ERROR: usage of `mem::forget` on type with `Drop` fields + //~| NOTE: argument has type `std::string::String` std::mem::forget(7); } diff --git a/src/tools/clippy/tests/ui/mem_forget.stderr b/src/tools/clippy/tests/ui/mem_forget.stderr index 8004b2aa8..a5ab15031 100644 --- a/src/tools/clippy/tests/ui/mem_forget.stderr +++ b/src/tools/clippy/tests/ui/mem_forget.stderr @@ -6,9 +6,10 @@ LL | memstuff::forget(six); | = note: argument has type `std::sync::Arc` = note: `-D clippy::mem-forget` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mem_forget)]` error: usage of `mem::forget` on `Drop` type - --> $DIR/mem_forget.rs:17:5 + --> $DIR/mem_forget.rs:19:5 | LL | std::mem::forget(seven); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | std::mem::forget(seven); = note: argument has type `std::rc::Rc` error: usage of `mem::forget` on `Drop` type - --> $DIR/mem_forget.rs:20:5 + --> $DIR/mem_forget.rs:24:5 | LL | forgetSomething(eight); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | forgetSomething(eight); = note: argument has type `std::vec::Vec` error: usage of `mem::forget` on type with `Drop` fields - --> $DIR/mem_forget.rs:23:5 + --> $DIR/mem_forget.rs:29:5 | LL | std::mem::forget(string); | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/mem_replace.fixed b/src/tools/clippy/tests/ui/mem_replace.fixed index d37e97b0a..453d0bcc5 100644 --- a/src/tools/clippy/tests/ui/mem_replace.fixed +++ b/src/tools/clippy/tests/ui/mem_replace.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn( clippy::all, diff --git a/src/tools/clippy/tests/ui/mem_replace.rs b/src/tools/clippy/tests/ui/mem_replace.rs index 34e37f3db..0c4e0f603 100644 --- a/src/tools/clippy/tests/ui/mem_replace.rs +++ b/src/tools/clippy/tests/ui/mem_replace.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn( clippy::all, diff --git a/src/tools/clippy/tests/ui/mem_replace.stderr b/src/tools/clippy/tests/ui/mem_replace.stderr index 58b57be75..ae5f4e534 100644 --- a/src/tools/clippy/tests/ui/mem_replace.stderr +++ b/src/tools/clippy/tests/ui/mem_replace.stderr @@ -1,147 +1,149 @@ error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:16:13 + --> $DIR/mem_replace.rs:14:13 | LL | let _ = mem::replace(&mut an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` | = note: `-D clippy::mem-replace-option-with-none` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mem_replace_option_with_none)]` error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:18:13 + --> $DIR/mem_replace.rs:16: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:23:13 + --> $DIR/mem_replace.rs:21:13 | LL | let _ = std::mem::replace(&mut s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` | = note: `-D clippy::mem-replace-with-default` implied by `-D warnings` + = 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:26:13 + --> $DIR/mem_replace.rs:24: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:27:13 + --> $DIR/mem_replace.rs:25: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:30:13 + --> $DIR/mem_replace.rs:28: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:31:13 + --> $DIR/mem_replace.rs:29: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:32:13 + --> $DIR/mem_replace.rs:30: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:33:13 + --> $DIR/mem_replace.rs:31: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:36:13 + --> $DIR/mem_replace.rs:34: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:39:13 + --> $DIR/mem_replace.rs:37: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:42:13 + --> $DIR/mem_replace.rs:40: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:45:13 + --> $DIR/mem_replace.rs:43: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:48:13 + --> $DIR/mem_replace.rs:46: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:51:13 + --> $DIR/mem_replace.rs:49: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:54:13 + --> $DIR/mem_replace.rs:52: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:57:13 + --> $DIR/mem_replace.rs:55: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:60:13 + --> $DIR/mem_replace.rs:58: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:63:13 + --> $DIR/mem_replace.rs:61: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:91:13 + --> $DIR/mem_replace.rs:89: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:121:13 + --> $DIR/mem_replace.rs:119: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:122:13 + --> $DIR/mem_replace.rs:120: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:123:13 + --> $DIR/mem_replace.rs:121: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:125:13 + --> $DIR/mem_replace.rs:123:13 | LL | let _ = std::mem::replace(&mut b.val, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut b.val)` diff --git a/src/tools/clippy/tests/ui/mem_replace_macro.rs b/src/tools/clippy/tests/ui/mem_replace_macro.rs index e53342f2e..132873858 100644 --- a/src/tools/clippy/tests/ui/mem_replace_macro.rs +++ b/src/tools/clippy/tests/ui/mem_replace_macro.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::mem_replace_with_default)] extern crate proc_macros; diff --git a/src/tools/clippy/tests/ui/mem_replace_macro.stderr b/src/tools/clippy/tests/ui/mem_replace_macro.stderr index 35dda93da..842ad3a85 100644 --- a/src/tools/clippy/tests/ui/mem_replace_macro.stderr +++ b/src/tools/clippy/tests/ui/mem_replace_macro.stderr @@ -5,6 +5,7 @@ LL | inline!(std::mem::replace($s, Default::default())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::mem-replace-with-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]` = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/methods.stderr b/src/tools/clippy/tests/ui/methods.stderr index 6be38b24f..e32b3b336 100644 --- a/src/tools/clippy/tests/ui/methods.stderr +++ b/src/tools/clippy/tests/ui/methods.stderr @@ -7,6 +7,7 @@ LL | | } | |_____^ | = note: `-D clippy::new-ret-no-self` implied by `-D warnings` + = 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 @@ -19,6 +20,7 @@ LL | | ).next(); | |___________________________^ | = note: `-D clippy::filter-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filter_next)]` error: aborting due to 2 previous errors diff --git a/src/tools/clippy/tests/ui/methods_fixable.fixed b/src/tools/clippy/tests/ui/methods_fixable.fixed index ce5d19a8b..bb06b5a48 100644 --- a/src/tools/clippy/tests/ui/methods_fixable.fixed +++ b/src/tools/clippy/tests/ui/methods_fixable.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::filter_next)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/methods_fixable.rs b/src/tools/clippy/tests/ui/methods_fixable.rs index 0615817ec..11de92459 100644 --- a/src/tools/clippy/tests/ui/methods_fixable.rs +++ b/src/tools/clippy/tests/ui/methods_fixable.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::filter_next)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/methods_fixable.stderr b/src/tools/clippy/tests/ui/methods_fixable.stderr index 6f45d100d..1bfe56d91 100644 --- a/src/tools/clippy/tests/ui/methods_fixable.stderr +++ b/src/tools/clippy/tests/ui/methods_fixable.stderr @@ -1,10 +1,11 @@ error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead - --> $DIR/methods_fixable.rs:11:13 + --> $DIR/methods_fixable.rs:9:13 | LL | let _ = v.iter().filter(|&x| *x < 0).next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `v.iter().find(|&x| *x < 0)` | = note: `-D clippy::filter-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filter_next)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/methods_unfixable.rs b/src/tools/clippy/tests/ui/methods_unfixable.rs index 3d88ce4b6..ee59983a7 100644 --- a/src/tools/clippy/tests/ui/methods_unfixable.rs +++ b/src/tools/clippy/tests/ui/methods_unfixable.rs @@ -1,5 +1,5 @@ #![warn(clippy::filter_next)] - +//@no-rustfix fn main() { issue10029(); } @@ -7,4 +7,5 @@ fn main() { pub fn issue10029() { let iter = (0..10); let _ = iter.filter(|_| true).next(); + //~^ ERROR: called `filter(..).next()` on an `Iterator`. This is more succinctly expre } diff --git a/src/tools/clippy/tests/ui/methods_unfixable.stderr b/src/tools/clippy/tests/ui/methods_unfixable.stderr index 6e101fe16..581a985e0 100644 --- a/src/tools/clippy/tests/ui/methods_unfixable.stderr +++ b/src/tools/clippy/tests/ui/methods_unfixable.stderr @@ -10,6 +10,7 @@ help: you will also need to make `iter` mutable, because `find` takes `&mut self LL | let iter = (0..10); | ^^^^ = note: `-D clippy::filter-next` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::filter_next)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/min_ident_chars.rs b/src/tools/clippy/tests/ui/min_ident_chars.rs index 03784442e..030863ca0 100644 --- a/src/tools/clippy/tests/ui/min_ident_chars.rs +++ b/src/tools/clippy/tests/ui/min_ident_chars.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(irrefutable_let_patterns, nonstandard_style, unused)] #![warn(clippy::min_ident_chars)] diff --git a/src/tools/clippy/tests/ui/min_ident_chars.stderr b/src/tools/clippy/tests/ui/min_ident_chars.stderr index 4dff6588b..253636cf9 100644 --- a/src/tools/clippy/tests/ui/min_ident_chars.stderr +++ b/src/tools/clippy/tests/ui/min_ident_chars.stderr @@ -5,6 +5,7 @@ LL | struct A { | ^ | = note: `-D clippy::min-ident-chars` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::min_ident_chars)]` error: this ident consists of a single char --> $DIR/min_ident_chars.rs:9:5 diff --git a/src/tools/clippy/tests/ui/min_max.rs b/src/tools/clippy/tests/ui/min_max.rs index 1215a0228..cf64f85f9 100644 --- a/src/tools/clippy/tests/ui/min_max.rs +++ b/src/tools/clippy/tests/ui/min_max.rs @@ -20,11 +20,17 @@ impl NotOrd { fn main() { let x = 2usize; min(1, max(3, x)); + //~^ ERROR: this `min`/`max` combination leads to constant result + //~| NOTE: `-D clippy::min-max` implied by `-D warnings` min(max(3, x), 1); + //~^ ERROR: this `min`/`max` combination leads to constant result max(min(x, 1), 3); + //~^ ERROR: this `min`/`max` combination leads to constant result max(3, min(x, 1)); + //~^ ERROR: this `min`/`max` combination leads to constant result my_max(3, my_min(x, 1)); + //~^ ERROR: this `min`/`max` combination leads to constant result min(3, max(1, x)); // ok, could be 1, 2 or 3 depending on x @@ -35,24 +41,32 @@ fn main() { let s = "Hello"; min("Apple", max("Zoo", s)); + //~^ ERROR: this `min`/`max` combination leads to constant result max(min(s, "Apple"), "Zoo"); + //~^ ERROR: this `min`/`max` combination leads to constant result max("Apple", min(s, "Zoo")); // ok let f = 3f32; x.min(1).max(3); + //~^ ERROR: this `min`/`max` combination leads to constant result x.max(3).min(1); + //~^ ERROR: this `min`/`max` combination leads to constant result f.max(3f32).min(1f32); + //~^ ERROR: this `min`/`max` combination leads to constant result x.max(1).min(3); // ok x.min(3).max(1); // ok f.min(3f32).max(1f32); // ok max(x.min(1), 3); + //~^ ERROR: this `min`/`max` combination leads to constant result min(x.max(1), 3); // ok s.max("Zoo").min("Apple"); + //~^ ERROR: this `min`/`max` combination leads to constant result s.min("Apple").max("Zoo"); + //~^ ERROR: this `min`/`max` combination leads to constant result s.min("Zoo").max("Apple"); // ok diff --git a/src/tools/clippy/tests/ui/min_max.stderr b/src/tools/clippy/tests/ui/min_max.stderr index 402b094f4..e9c64e56b 100644 --- a/src/tools/clippy/tests/ui/min_max.stderr +++ b/src/tools/clippy/tests/ui/min_max.stderr @@ -5,75 +5,76 @@ LL | min(1, max(3, x)); | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::min-max` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::min_max)]` error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:23:5 + --> $DIR/min_max.rs:25:5 | LL | min(max(3, x), 1); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:24:5 + --> $DIR/min_max.rs:27:5 | LL | max(min(x, 1), 3); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:25:5 + --> $DIR/min_max.rs:29:5 | LL | max(3, min(x, 1)); | ^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:27:5 + --> $DIR/min_max.rs:32:5 | LL | my_max(3, my_min(x, 1)); | ^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:37:5 + --> $DIR/min_max.rs:43:5 | LL | min("Apple", max("Zoo", s)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:38:5 + --> $DIR/min_max.rs:45:5 | LL | max(min(s, "Apple"), "Zoo"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:43:5 + --> $DIR/min_max.rs:51:5 | LL | x.min(1).max(3); | ^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:44:5 + --> $DIR/min_max.rs:53:5 | LL | x.max(3).min(1); | ^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:45:5 + --> $DIR/min_max.rs:55:5 | LL | f.max(3f32).min(1f32); | ^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:51:5 + --> $DIR/min_max.rs:62:5 | LL | max(x.min(1), 3); | ^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:54:5 + --> $DIR/min_max.rs:66:5 | LL | s.max("Zoo").min("Apple"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `min`/`max` combination leads to constant result - --> $DIR/min_max.rs:55:5 + --> $DIR/min_max.rs:68:5 | LL | s.min("Apple").max("Zoo"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/min_rust_version_attr.rs b/src/tools/clippy/tests/ui/min_rust_version_attr.rs index 955e7eb72..5fe3306d6 100644 --- a/src/tools/clippy/tests/ui/min_rust_version_attr.rs +++ b/src/tools/clippy/tests/ui/min_rust_version_attr.rs @@ -11,11 +11,13 @@ fn just_under_msrv() { #[clippy::msrv = "1.43.0"] fn meets_msrv() { let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } #[clippy::msrv = "1.44.0"] fn just_above_msrv() { let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } #[clippy::msrv = "1.42"] @@ -26,6 +28,7 @@ fn no_patch_under() { #[clippy::msrv = "1.43"] fn no_patch_meets() { let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } fn inner_attr_under() { @@ -36,6 +39,7 @@ fn inner_attr_under() { fn inner_attr_meets() { #![clippy::msrv = "1.43"] let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } // https://github.com/rust-lang/rust-clippy/issues/6920 @@ -46,6 +50,7 @@ fn scoping() { // Should warn let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found mod a { #![clippy::msrv = "1.42.0"] @@ -53,6 +58,7 @@ fn scoping() { fn should_warn() { #![clippy::msrv = "1.43.0"] let log2_10 = 3.321928094887362; + //~^ ERROR: approximate value of `f{32, 64}::consts::LOG2_10` found } fn should_not_warn() { diff --git a/src/tools/clippy/tests/ui/min_rust_version_attr.stderr b/src/tools/clippy/tests/ui/min_rust_version_attr.stderr index 7e2135584..3c8555c62 100644 --- a/src/tools/clippy/tests/ui/min_rust_version_attr.stderr +++ b/src/tools/clippy/tests/ui/min_rust_version_attr.stderr @@ -8,7 +8,7 @@ LL | let log2_10 = 3.321928094887362; = note: `#[deny(clippy::approx_constant)]` on by default error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:18:19 + --> $DIR/min_rust_version_attr.rs:19:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:28:19 + --> $DIR/min_rust_version_attr.rs:30:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -24,7 +24,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:38:19 + --> $DIR/min_rust_version_attr.rs:41:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -32,7 +32,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:48:19 + --> $DIR/min_rust_version_attr.rs:52:19 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | let log2_10 = 3.321928094887362; = help: consider using the constant directly error: approximate value of `f{32, 64}::consts::LOG2_10` found - --> $DIR/min_rust_version_attr.rs:55:27 + --> $DIR/min_rust_version_attr.rs:60:27 | LL | let log2_10 = 3.321928094887362; | ^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.rs b/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.rs index 02892f329..c8a0d6641 100644 --- a/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.rs +++ b/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.rs @@ -1,18 +1,23 @@ #![feature(custom_inner_attributes)] #![clippy::msrv = "invalid.version"] +//~^ ERROR: `invalid.version` is not a valid Rust version fn main() {} #[clippy::msrv = "invalid.version"] +//~^ ERROR: `invalid.version` is not a valid Rust version fn outer_attr() {} mod multiple { #![clippy::msrv = "1.40"] #![clippy::msrv = "=1.35.0"] + //~^ ERROR: `msrv` is defined multiple times #![clippy::msrv = "1.10.1"] + //~^ ERROR: `msrv` is defined multiple times mod foo { #![clippy::msrv = "1"] #![clippy::msrv = "1.0.0"] + //~^ ERROR: `msrv` is defined multiple times } } diff --git a/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.stderr b/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.stderr index 675b78031..8d4071e25 100644 --- a/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.stderr +++ b/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.stderr @@ -5,43 +5,43 @@ LL | #![clippy::msrv = "invalid.version"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `invalid.version` is not a valid Rust version - --> $DIR/min_rust_version_invalid_attr.rs:6:1 + --> $DIR/min_rust_version_invalid_attr.rs:7:1 | LL | #[clippy::msrv = "invalid.version"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `msrv` is defined multiple times - --> $DIR/min_rust_version_invalid_attr.rs:11:5 + --> $DIR/min_rust_version_invalid_attr.rs:13:5 | LL | #![clippy::msrv = "=1.35.0"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first definition found here - --> $DIR/min_rust_version_invalid_attr.rs:10:5 + --> $DIR/min_rust_version_invalid_attr.rs:12:5 | LL | #![clippy::msrv = "1.40"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `msrv` is defined multiple times - --> $DIR/min_rust_version_invalid_attr.rs:12:5 + --> $DIR/min_rust_version_invalid_attr.rs:15:5 | LL | #![clippy::msrv = "1.10.1"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first definition found here - --> $DIR/min_rust_version_invalid_attr.rs:10:5 + --> $DIR/min_rust_version_invalid_attr.rs:12:5 | LL | #![clippy::msrv = "1.40"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `msrv` is defined multiple times - --> $DIR/min_rust_version_invalid_attr.rs:16:9 + --> $DIR/min_rust_version_invalid_attr.rs:20:9 | LL | #![clippy::msrv = "1.0.0"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first definition found here - --> $DIR/min_rust_version_invalid_attr.rs:15:9 + --> $DIR/min_rust_version_invalid_attr.rs:19:9 | LL | #![clippy::msrv = "1"] | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.fixed b/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.fixed index f58e9a429..de02b2bee 100644 --- a/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.fixed +++ b/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::mismatched_target_os)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.rs b/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.rs index e00224f5c..a96051875 100644 --- a/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.rs +++ b/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::mismatched_target_os)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.stderr b/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.stderr index 5f1b09083..795d043e2 100644 --- a/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.stderr +++ b/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.stderr @@ -1,5 +1,5 @@ error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:6:1 + --> $DIR/mismatched_target_os_non_unix.rs:4:1 | LL | #[cfg(hermit)] | ^^^^^^------^^ @@ -7,9 +7,10 @@ LL | #[cfg(hermit)] | help: try: `target_os = "hermit"` | = note: `-D clippy::mismatched-target-os` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mismatched_target_os)]` error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:9:1 + --> $DIR/mismatched_target_os_non_unix.rs:7:1 | LL | #[cfg(wasi)] | ^^^^^^----^^ @@ -17,7 +18,7 @@ LL | #[cfg(wasi)] | help: try: `target_os = "wasi"` error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:12:1 + --> $DIR/mismatched_target_os_non_unix.rs:10:1 | LL | #[cfg(none)] | ^^^^^^----^^ @@ -25,7 +26,7 @@ LL | #[cfg(none)] | help: try: `target_os = "none"` error: operating system used in target family position - --> $DIR/mismatched_target_os_non_unix.rs:16:1 + --> $DIR/mismatched_target_os_non_unix.rs:14:1 | LL | #[cfg(all(not(windows), wasi))] | ^^^^^^^^^^^^^^^^^^^^^^^^----^^^ diff --git a/src/tools/clippy/tests/ui/mismatched_target_os_unix.fixed b/src/tools/clippy/tests/ui/mismatched_target_os_unix.fixed index 330587a3c..b945c4d96 100644 --- a/src/tools/clippy/tests/ui/mismatched_target_os_unix.fixed +++ b/src/tools/clippy/tests/ui/mismatched_target_os_unix.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::mismatched_target_os)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/mismatched_target_os_unix.rs b/src/tools/clippy/tests/ui/mismatched_target_os_unix.rs index 5a90019a2..34307facd 100644 --- a/src/tools/clippy/tests/ui/mismatched_target_os_unix.rs +++ b/src/tools/clippy/tests/ui/mismatched_target_os_unix.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::mismatched_target_os)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/mismatched_target_os_unix.stderr b/src/tools/clippy/tests/ui/mismatched_target_os_unix.stderr index 9822c77c9..261c33754 100644 --- a/src/tools/clippy/tests/ui/mismatched_target_os_unix.stderr +++ b/src/tools/clippy/tests/ui/mismatched_target_os_unix.stderr @@ -1,5 +1,5 @@ error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:6:1 + --> $DIR/mismatched_target_os_unix.rs:4:1 | LL | #[cfg(linux)] | ^^^^^^-----^^ @@ -8,9 +8,10 @@ LL | #[cfg(linux)] | = help: did you mean `unix`? = note: `-D clippy::mismatched-target-os` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mismatched_target_os)]` error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:9:1 + --> $DIR/mismatched_target_os_unix.rs:7:1 | LL | #[cfg(freebsd)] | ^^^^^^-------^^ @@ -20,7 +21,7 @@ LL | #[cfg(freebsd)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:12:1 + --> $DIR/mismatched_target_os_unix.rs:10:1 | LL | #[cfg(dragonfly)] | ^^^^^^---------^^ @@ -30,7 +31,7 @@ LL | #[cfg(dragonfly)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:15:1 + --> $DIR/mismatched_target_os_unix.rs:13:1 | LL | #[cfg(openbsd)] | ^^^^^^-------^^ @@ -40,7 +41,7 @@ LL | #[cfg(openbsd)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:18:1 + --> $DIR/mismatched_target_os_unix.rs:16:1 | LL | #[cfg(netbsd)] | ^^^^^^------^^ @@ -50,7 +51,7 @@ LL | #[cfg(netbsd)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:21:1 + --> $DIR/mismatched_target_os_unix.rs:19:1 | LL | #[cfg(macos)] | ^^^^^^-----^^ @@ -60,7 +61,7 @@ LL | #[cfg(macos)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:24:1 + --> $DIR/mismatched_target_os_unix.rs:22:1 | LL | #[cfg(ios)] | ^^^^^^---^^ @@ -70,7 +71,7 @@ LL | #[cfg(ios)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:27:1 + --> $DIR/mismatched_target_os_unix.rs:25:1 | LL | #[cfg(android)] | ^^^^^^-------^^ @@ -80,7 +81,7 @@ LL | #[cfg(android)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:30:1 + --> $DIR/mismatched_target_os_unix.rs:28:1 | LL | #[cfg(emscripten)] | ^^^^^^----------^^ @@ -90,7 +91,7 @@ LL | #[cfg(emscripten)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:33:1 + --> $DIR/mismatched_target_os_unix.rs:31:1 | LL | #[cfg(fuchsia)] | ^^^^^^-------^^ @@ -100,7 +101,7 @@ LL | #[cfg(fuchsia)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:36:1 + --> $DIR/mismatched_target_os_unix.rs:34:1 | LL | #[cfg(haiku)] | ^^^^^^-----^^ @@ -110,7 +111,7 @@ LL | #[cfg(haiku)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:39:1 + --> $DIR/mismatched_target_os_unix.rs:37:1 | LL | #[cfg(illumos)] | ^^^^^^-------^^ @@ -120,7 +121,7 @@ LL | #[cfg(illumos)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:42:1 + --> $DIR/mismatched_target_os_unix.rs:40:1 | LL | #[cfg(l4re)] | ^^^^^^----^^ @@ -130,7 +131,7 @@ LL | #[cfg(l4re)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:45:1 + --> $DIR/mismatched_target_os_unix.rs:43:1 | LL | #[cfg(redox)] | ^^^^^^-----^^ @@ -140,7 +141,7 @@ LL | #[cfg(redox)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:48:1 + --> $DIR/mismatched_target_os_unix.rs:46:1 | LL | #[cfg(solaris)] | ^^^^^^-------^^ @@ -150,7 +151,7 @@ LL | #[cfg(solaris)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:51:1 + --> $DIR/mismatched_target_os_unix.rs:49:1 | LL | #[cfg(vxworks)] | ^^^^^^-------^^ @@ -160,7 +161,7 @@ LL | #[cfg(vxworks)] = help: did you mean `unix`? error: operating system used in target family position - --> $DIR/mismatched_target_os_unix.rs:55:1 + --> $DIR/mismatched_target_os_unix.rs:53:1 | LL | #[cfg(all(not(any(solaris, linux)), freebsd))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/mismatching_type_param_order.rs b/src/tools/clippy/tests/ui/mismatching_type_param_order.rs index 40c1fcae1..af2882e41 100644 --- a/src/tools/clippy/tests/ui/mismatching_type_param_order.rs +++ b/src/tools/clippy/tests/ui/mismatching_type_param_order.rs @@ -9,9 +9,12 @@ fn main() { // lint on both params impl Foo {} + //~^ ERROR: `Foo` has a similarly named generic type parameter `B` in its declaration, + //~| ERROR: `Foo` has a similarly named generic type parameter `A` in its declaration, // lint on the 2nd param impl Foo {} + //~^ ERROR: `Foo` has a similarly named generic type parameter `A` in its declaration, // should not lint impl Foo {} @@ -23,6 +26,8 @@ fn main() { // should not lint on lifetimes impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} + //~^ ERROR: `FooLifetime` has a similarly named generic type parameter `B` in its decl + //~| ERROR: `FooLifetime` has a similarly named generic type parameter `A` in its decl struct Bar { x: i32, @@ -39,6 +44,9 @@ fn main() { } impl FooEnum {} + //~^ ERROR: `FooEnum` has a similarly named generic type parameter `C` in its declarat + //~| ERROR: `FooEnum` has a similarly named generic type parameter `A` in its declarat + //~| ERROR: `FooEnum` has a similarly named generic type parameter `B` in its declarat // also works for unions union FooUnion @@ -50,6 +58,8 @@ fn main() { } impl FooUnion where A: Copy {} + //~^ ERROR: `FooUnion` has a similarly named generic type parameter `B` in its declara + //~| ERROR: `FooUnion` has a similarly named generic type parameter `A` in its declara impl FooUnion where diff --git a/src/tools/clippy/tests/ui/mismatching_type_param_order.stderr b/src/tools/clippy/tests/ui/mismatching_type_param_order.stderr index 204d49905..8edbe3295 100644 --- a/src/tools/clippy/tests/ui/mismatching_type_param_order.stderr +++ b/src/tools/clippy/tests/ui/mismatching_type_param_order.stderr @@ -6,6 +6,7 @@ LL | impl Foo {} | = help: try `A`, or a name that does not conflict with `Foo`'s generic params = note: `-D clippy::mismatching-type-param-order` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mismatching_type_param_order)]` error: `Foo` has a similarly named generic type parameter `A` in its declaration, but in a different order --> $DIR/mismatching_type_param_order.rs:11:23 @@ -16,7 +17,7 @@ LL | impl Foo {} = help: try `B`, or a name that does not conflict with `Foo`'s generic params error: `Foo` has a similarly named generic type parameter `A` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:14:23 + --> $DIR/mismatching_type_param_order.rs:16:23 | LL | impl Foo {} | ^ @@ -24,7 +25,7 @@ LL | impl Foo {} = help: try `B`, or a name that does not conflict with `Foo`'s generic params error: `FooLifetime` has a similarly named generic type parameter `B` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:25:44 + --> $DIR/mismatching_type_param_order.rs:28:44 | LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} | ^ @@ -32,7 +33,7 @@ LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} = help: try `A`, or a name that does not conflict with `FooLifetime`'s generic params error: `FooLifetime` has a similarly named generic type parameter `A` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:25:47 + --> $DIR/mismatching_type_param_order.rs:28:47 | LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} | ^ @@ -40,7 +41,7 @@ LL | impl<'m, 'l, B, A> FooLifetime<'m, 'l, B, A> {} = help: try `B`, or a name that does not conflict with `FooLifetime`'s generic params error: `FooEnum` has a similarly named generic type parameter `C` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:41:27 + --> $DIR/mismatching_type_param_order.rs:46:27 | LL | impl FooEnum {} | ^ @@ -48,7 +49,7 @@ LL | impl FooEnum {} = help: try `A`, or a name that does not conflict with `FooEnum`'s generic params error: `FooEnum` has a similarly named generic type parameter `A` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:41:30 + --> $DIR/mismatching_type_param_order.rs:46:30 | LL | impl FooEnum {} | ^ @@ -56,7 +57,7 @@ LL | impl FooEnum {} = help: try `B`, or a name that does not conflict with `FooEnum`'s generic params error: `FooEnum` has a similarly named generic type parameter `B` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:41:33 + --> $DIR/mismatching_type_param_order.rs:46:33 | LL | impl FooEnum {} | ^ @@ -64,7 +65,7 @@ LL | impl FooEnum {} = help: try `C`, or a name that does not conflict with `FooEnum`'s generic params error: `FooUnion` has a similarly named generic type parameter `B` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:52:31 + --> $DIR/mismatching_type_param_order.rs:60:31 | LL | impl FooUnion where A: Copy {} | ^ @@ -72,7 +73,7 @@ LL | impl FooUnion where A: Copy {} = help: try `A`, or a name that does not conflict with `FooUnion`'s generic params error: `FooUnion` has a similarly named generic type parameter `A` in its declaration, but in a different order - --> $DIR/mismatching_type_param_order.rs:52:34 + --> $DIR/mismatching_type_param_order.rs:60:34 | LL | impl FooUnion where A: Copy {} | ^ diff --git a/src/tools/clippy/tests/ui/misnamed_getters.fixed b/src/tools/clippy/tests/ui/misnamed_getters.fixed new file mode 100644 index 000000000..2a7a2067e --- /dev/null +++ b/src/tools/clippy/tests/ui/misnamed_getters.fixed @@ -0,0 +1,143 @@ +#![allow(unused)] +#![warn(clippy::misnamed_getters)] + +struct A { + a: u8, + b: u8, + c: u8, +} + +impl A { + fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field + //~| NOTE: `-D clippy::misnamed-getters` implied by `-D warnings` + &self.a + } + fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field + &mut self.a + } + + fn b(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field + self.b + } + + fn b_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field + &mut self.b + } + + fn c(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field + &self.c + } + + fn c_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field + &mut self.c + } +} + +union B { + a: u8, + b: u8, +} + +impl B { + unsafe fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field + &self.a + } + unsafe fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field + &mut self.a + } + + unsafe fn b(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field + self.b + } + + unsafe fn b_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field + &mut self.b + } + + unsafe fn c(&self) -> &u8 { + &self.b + } + + unsafe fn c_mut(&mut self) -> &mut u8 { + &mut self.a + } + + unsafe fn a_unchecked(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field + &self.a + } + unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field + &mut self.a + } + + unsafe fn b_unchecked(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field + self.b + } + + unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field + &mut self.b + } + + unsafe fn c_unchecked(&self) -> &u8 { + &self.b + } + + unsafe fn c_unchecked_mut(&mut self) -> &mut u8 { + &mut self.a + } +} + +struct D { + d: u8, + inner: A, +} + +impl core::ops::Deref for D { + type Target = A; + fn deref(&self) -> &A { + &self.inner + } +} + +impl core::ops::DerefMut for D { + fn deref_mut(&mut self) -> &mut A { + &mut self.inner + } +} + +impl D { + fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field + &self.a + } + fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field + &mut self.a + } + + fn d(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field + &self.d + } + fn d_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field + &mut self.d + } +} + +fn main() { + // test code goes here +} diff --git a/src/tools/clippy/tests/ui/misnamed_getters.rs b/src/tools/clippy/tests/ui/misnamed_getters.rs index 03e7dac7d..56ddc46c4 100644 --- a/src/tools/clippy/tests/ui/misnamed_getters.rs +++ b/src/tools/clippy/tests/ui/misnamed_getters.rs @@ -9,25 +9,32 @@ struct A { impl A { fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field + //~| NOTE: `-D clippy::misnamed-getters` implied by `-D warnings` &self.b } fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } fn b(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.a } fn b_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } fn c(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } fn c_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } } @@ -39,17 +46,21 @@ union B { impl B { unsafe fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } unsafe fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } unsafe fn b(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.a } unsafe fn b_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } @@ -62,17 +73,21 @@ impl B { } unsafe fn a_unchecked(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } unsafe fn b_unchecked(self) -> u8 { + //~^ ERROR: getter function appears to return the wrong field self.a } unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.a } @@ -105,16 +120,20 @@ impl core::ops::DerefMut for D { impl D { fn a(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } fn a_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } fn d(&self) -> &u8 { + //~^ ERROR: getter function appears to return the wrong field &self.b } fn d_mut(&mut self) -> &mut u8 { + //~^ ERROR: getter function appears to return the wrong field &mut self.b } } diff --git a/src/tools/clippy/tests/ui/misnamed_getters.stderr b/src/tools/clippy/tests/ui/misnamed_getters.stderr index 1e38a83d0..aadec6549 100644 --- a/src/tools/clippy/tests/ui/misnamed_getters.stderr +++ b/src/tools/clippy/tests/ui/misnamed_getters.stderr @@ -2,161 +2,181 @@ error: getter function appears to return the wrong field --> $DIR/misnamed_getters.rs:11:5 | LL | / fn a(&self) -> &u8 { +LL | | +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } | |_____^ | = note: `-D clippy::misnamed-getters` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::misnamed_getters)]` error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:14:5 + --> $DIR/misnamed_getters.rs:16:5 | LL | / fn a_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:18:5 + --> $DIR/misnamed_getters.rs:21:5 | LL | / fn b(self) -> u8 { +LL | | LL | | self.a | | ------ help: consider using: `self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:22:5 + --> $DIR/misnamed_getters.rs:26:5 | LL | / fn b_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:26:5 + --> $DIR/misnamed_getters.rs:31:5 | LL | / fn c(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.c` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:30:5 + --> $DIR/misnamed_getters.rs:36:5 | LL | / fn c_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.c` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:41:5 + --> $DIR/misnamed_getters.rs:48:5 | LL | / unsafe fn a(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:44:5 + --> $DIR/misnamed_getters.rs:52:5 | LL | / unsafe fn a_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:48:5 + --> $DIR/misnamed_getters.rs:57:5 | LL | / unsafe fn b(self) -> u8 { +LL | | LL | | self.a | | ------ help: consider using: `self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:52:5 + --> $DIR/misnamed_getters.rs:62:5 | LL | / unsafe fn b_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:64:5 + --> $DIR/misnamed_getters.rs:75:5 | LL | / unsafe fn a_unchecked(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:67:5 + --> $DIR/misnamed_getters.rs:79:5 | LL | / unsafe fn a_unchecked_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:71:5 + --> $DIR/misnamed_getters.rs:84:5 | LL | / unsafe fn b_unchecked(self) -> u8 { +LL | | LL | | self.a | | ------ help: consider using: `self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:75:5 + --> $DIR/misnamed_getters.rs:89:5 | LL | / unsafe fn b_unchecked_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.a | | ----------- help: consider using: `&mut self.b` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:107:5 + --> $DIR/misnamed_getters.rs:122:5 | LL | / fn a(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:110:5 + --> $DIR/misnamed_getters.rs:126:5 | LL | / fn a_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.a` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:114:5 + --> $DIR/misnamed_getters.rs:131:5 | LL | / fn d(&self) -> &u8 { +LL | | LL | | &self.b | | ------- help: consider using: `&self.d` LL | | } | |_____^ error: getter function appears to return the wrong field - --> $DIR/misnamed_getters.rs:117:5 + --> $DIR/misnamed_getters.rs:135:5 | LL | / fn d_mut(&mut self) -> &mut u8 { +LL | | LL | | &mut self.b | | ----------- help: consider using: `&mut self.d` LL | | } diff --git a/src/tools/clippy/tests/ui/missing_assert_message.rs b/src/tools/clippy/tests/ui/missing_assert_message.rs index af1358f61..2ad8e0127 100644 --- a/src/tools/clippy/tests/ui/missing_assert_message.rs +++ b/src/tools/clippy/tests/ui/missing_assert_message.rs @@ -10,29 +10,45 @@ macro_rules! bar { // Should trigger warning fn asserts_without_message() { assert!(foo()); + //~^ ERROR: assert without any message assert_eq!(foo(), foo()); + //~^ ERROR: assert without any message assert_ne!(foo(), foo()); + //~^ ERROR: assert without any message debug_assert!(foo()); + //~^ ERROR: assert without any message debug_assert_eq!(foo(), foo()); + //~^ ERROR: assert without any message debug_assert_ne!(foo(), foo()); + //~^ ERROR: assert without any message } // Should trigger warning fn asserts_without_message_but_with_macro_calls() { assert!(bar!(true)); + //~^ ERROR: assert without any message assert!(bar!(true, false)); + //~^ ERROR: assert without any message assert_eq!(bar!(true), foo()); + //~^ ERROR: assert without any message assert_ne!(bar!(true, true), bar!(true)); + //~^ ERROR: assert without any message } // Should trigger warning fn asserts_with_trailing_commas() { assert!(foo(),); + //~^ ERROR: assert without any message assert_eq!(foo(), foo(),); + //~^ ERROR: assert without any message assert_ne!(foo(), foo(),); + //~^ ERROR: assert without any message debug_assert!(foo(),); + //~^ ERROR: assert without any message debug_assert_eq!(foo(), foo(),); + //~^ ERROR: assert without any message debug_assert_ne!(foo(), foo(),); + //~^ ERROR: assert without any message } // Should not trigger warning diff --git a/src/tools/clippy/tests/ui/missing_assert_message.stderr b/src/tools/clippy/tests/ui/missing_assert_message.stderr index 33a5c1f8e..e07f52e3f 100644 --- a/src/tools/clippy/tests/ui/missing_assert_message.stderr +++ b/src/tools/clippy/tests/ui/missing_assert_message.stderr @@ -6,9 +6,10 @@ LL | assert!(foo()); | = help: consider describing why the failing assert is problematic = note: `-D clippy::missing-assert-message` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_assert_message)]` error: assert without any message - --> $DIR/missing_assert_message.rs:13:5 + --> $DIR/missing_assert_message.rs:14:5 | LL | assert_eq!(foo(), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | assert_eq!(foo(), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:14:5 + --> $DIR/missing_assert_message.rs:16:5 | LL | assert_ne!(foo(), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | assert_ne!(foo(), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:15:5 + --> $DIR/missing_assert_message.rs:18:5 | LL | debug_assert!(foo()); | ^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | debug_assert!(foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:16:5 + --> $DIR/missing_assert_message.rs:20:5 | LL | debug_assert_eq!(foo(), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | debug_assert_eq!(foo(), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:17:5 + --> $DIR/missing_assert_message.rs:22:5 | LL | debug_assert_ne!(foo(), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | debug_assert_ne!(foo(), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:22:5 + --> $DIR/missing_assert_message.rs:28:5 | LL | assert!(bar!(true)); | ^^^^^^^^^^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | assert!(bar!(true)); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:23:5 + --> $DIR/missing_assert_message.rs:30:5 | LL | assert!(bar!(true, false)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +65,7 @@ LL | assert!(bar!(true, false)); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:24:5 + --> $DIR/missing_assert_message.rs:32:5 | LL | assert_eq!(bar!(true), foo()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL | assert_eq!(bar!(true), foo()); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:25:5 + --> $DIR/missing_assert_message.rs:34:5 | LL | assert_ne!(bar!(true, true), bar!(true)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +81,7 @@ LL | assert_ne!(bar!(true, true), bar!(true)); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:30:5 + --> $DIR/missing_assert_message.rs:40:5 | LL | assert!(foo(),); | ^^^^^^^^^^^^^^^ @@ -88,7 +89,7 @@ LL | assert!(foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:31:5 + --> $DIR/missing_assert_message.rs:42:5 | LL | assert_eq!(foo(), foo(),); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +97,7 @@ LL | assert_eq!(foo(), foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:32:5 + --> $DIR/missing_assert_message.rs:44:5 | LL | assert_ne!(foo(), foo(),); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +105,7 @@ LL | assert_ne!(foo(), foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:33:5 + --> $DIR/missing_assert_message.rs:46:5 | LL | debug_assert!(foo(),); | ^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +113,7 @@ LL | debug_assert!(foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:34:5 + --> $DIR/missing_assert_message.rs:48:5 | LL | debug_assert_eq!(foo(), foo(),); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +121,7 @@ LL | debug_assert_eq!(foo(), foo(),); = help: consider describing why the failing assert is problematic error: assert without any message - --> $DIR/missing_assert_message.rs:35:5 + --> $DIR/missing_assert_message.rs:50:5 | LL | debug_assert_ne!(foo(), foo(),); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/missing_asserts_for_indexing.fixed b/src/tools/clippy/tests/ui/missing_asserts_for_indexing.fixed new file mode 100644 index 000000000..a96827259 --- /dev/null +++ b/src/tools/clippy/tests/ui/missing_asserts_for_indexing.fixed @@ -0,0 +1,121 @@ +#![allow(unused)] +#![warn(clippy::missing_asserts_for_indexing)] + +// ok +fn sum_with_assert(v: &[u8]) -> u8 { + assert!(v.len() > 4); + v[0] + v[1] + v[2] + v[3] + v[4] +} + +// ok +fn sum_with_assert_other_way(v: &[u8]) -> u8 { + assert!(5 <= v.len()); + v[0] + v[1] + v[2] + v[3] + v[4] +} + +// ok +fn sum_with_assert_ge(v: &[u8]) -> u8 { + assert!(v.len() >= 5); + v[0] + v[1] + v[2] + v[3] + v[4] +} + +// ok +fn sum_with_assert_ge_other_way(v: &[u8]) -> u8 { + assert!(4 < v.len()); + v[0] + v[1] + v[2] + v[3] + v[4] +} + +fn sum_with_assert_lt(v: &[u8]) -> u8 { + assert!(v.len() > 4); + v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the +} + +fn sum_with_assert_le(v: &[u8]) -> u8 { + assert!(v.len() > 4); + v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the +} + +fn sum_with_incorrect_assert_len(v: &[u8]) -> u8 { + assert!(v.len() > 4); + v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the +} + +fn sum_with_incorrect_assert_len2(v: &[u8]) -> u8 { + assert!(v.len() > 4); + v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the +} + +// ok, don't lint for single array access +fn single_access(v: &[u8]) -> u8 { + v[0] +} + +// ok +fn subslice_ok(v: &[u8]) { + assert!(v.len() > 3); + let _ = v[0]; + let _ = v[1..4]; +} + +fn subslice_bad(v: &[u8]) { + assert!(v.len() > 3); + let _ = v[0]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + let _ = v[1..4]; +} + +// ok +fn subslice_inclusive_ok(v: &[u8]) { + assert!(v.len() > 4); + let _ = v[0]; + let _ = v[1..=4]; +} + +fn subslice_inclusive_bad(v: &[u8]) { + assert!(v.len() > 4); + let _ = v[0]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + let _ = v[1..=4]; +} + +fn index_different_slices_ok(v1: &[u8], v2: &[u8]) { + assert!(v1.len() > 12); + assert!(v2.len() > 15); + let _ = v1[0] + v1[12]; + let _ = v2[5] + v2[15]; +} + +fn index_different_slices_wrong_len(v1: &[u8], v2: &[u8]) { + assert!(v1.len() > 12); + assert!(v2.len() > 15); + let _ = v1[0] + v1[12]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + let _ = v2[5] + v2[15]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the +} +fn index_different_slices_one_wrong_len(v1: &[u8], v2: &[u8]) { + assert!(v1.len() > 12); + assert!(v2.len() > 15); + let _ = v1[0] + v1[12]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + let _ = v2[5] + v2[15]; +} + +fn side_effect() -> &'static [u8] { + &[] +} + +fn index_side_effect_expr() { + let _ = side_effect()[0] + side_effect()[1]; +} + +// ok, single access for different slices +fn index_different_slice_in_same_expr(v1: &[u8], v2: &[u8]) { + let _ = v1[0] + v2[1]; +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/missing_asserts_for_indexing.rs b/src/tools/clippy/tests/ui/missing_asserts_for_indexing.rs new file mode 100644 index 000000000..0b4b883ac --- /dev/null +++ b/src/tools/clippy/tests/ui/missing_asserts_for_indexing.rs @@ -0,0 +1,121 @@ +#![allow(unused)] +#![warn(clippy::missing_asserts_for_indexing)] + +// ok +fn sum_with_assert(v: &[u8]) -> u8 { + assert!(v.len() > 4); + v[0] + v[1] + v[2] + v[3] + v[4] +} + +// ok +fn sum_with_assert_other_way(v: &[u8]) -> u8 { + assert!(5 <= v.len()); + v[0] + v[1] + v[2] + v[3] + v[4] +} + +// ok +fn sum_with_assert_ge(v: &[u8]) -> u8 { + assert!(v.len() >= 5); + v[0] + v[1] + v[2] + v[3] + v[4] +} + +// ok +fn sum_with_assert_ge_other_way(v: &[u8]) -> u8 { + assert!(4 < v.len()); + v[0] + v[1] + v[2] + v[3] + v[4] +} + +fn sum_with_assert_lt(v: &[u8]) -> u8 { + assert!(v.len() < 5); + v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the +} + +fn sum_with_assert_le(v: &[u8]) -> u8 { + assert!(v.len() <= 5); + v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the +} + +fn sum_with_incorrect_assert_len(v: &[u8]) -> u8 { + assert!(v.len() > 3); + v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the +} + +fn sum_with_incorrect_assert_len2(v: &[u8]) -> u8 { + assert!(v.len() >= 4); + v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the +} + +// ok, don't lint for single array access +fn single_access(v: &[u8]) -> u8 { + v[0] +} + +// ok +fn subslice_ok(v: &[u8]) { + assert!(v.len() > 3); + let _ = v[0]; + let _ = v[1..4]; +} + +fn subslice_bad(v: &[u8]) { + assert!(v.len() >= 3); + let _ = v[0]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + let _ = v[1..4]; +} + +// ok +fn subslice_inclusive_ok(v: &[u8]) { + assert!(v.len() > 4); + let _ = v[0]; + let _ = v[1..=4]; +} + +fn subslice_inclusive_bad(v: &[u8]) { + assert!(v.len() >= 4); + let _ = v[0]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + let _ = v[1..=4]; +} + +fn index_different_slices_ok(v1: &[u8], v2: &[u8]) { + assert!(v1.len() > 12); + assert!(v2.len() > 15); + let _ = v1[0] + v1[12]; + let _ = v2[5] + v2[15]; +} + +fn index_different_slices_wrong_len(v1: &[u8], v2: &[u8]) { + assert!(v1.len() >= 12); + assert!(v2.len() >= 15); + let _ = v1[0] + v1[12]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + let _ = v2[5] + v2[15]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the +} +fn index_different_slices_one_wrong_len(v1: &[u8], v2: &[u8]) { + assert!(v1.len() >= 12); + assert!(v2.len() > 15); + let _ = v1[0] + v1[12]; + //~^ ERROR: indexing into a slice multiple times with an `assert` that does not cover the + let _ = v2[5] + v2[15]; +} + +fn side_effect() -> &'static [u8] { + &[] +} + +fn index_side_effect_expr() { + let _ = side_effect()[0] + side_effect()[1]; +} + +// ok, single access for different slices +fn index_different_slice_in_same_expr(v1: &[u8], v2: &[u8]) { + let _ = v1[0] + v2[1]; +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/missing_asserts_for_indexing.stderr b/src/tools/clippy/tests/ui/missing_asserts_for_indexing.stderr new file mode 100644 index 000000000..a3e66d795 --- /dev/null +++ b/src/tools/clippy/tests/ui/missing_asserts_for_indexing.stderr @@ -0,0 +1,253 @@ +error: indexing into a slice multiple times with an `assert` that does not cover the highest index + --> $DIR/missing_asserts_for_indexing.rs:30:5 + | +LL | assert!(v.len() < 5); + | -------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:30:5 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:30:12 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:30:19 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:30:26 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:30:33 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ + = note: asserting the length before indexing will elide bounds checks + = note: `-D clippy::missing-asserts-for-indexing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_asserts_for_indexing)]` + +error: indexing into a slice multiple times with an `assert` that does not cover the highest index + --> $DIR/missing_asserts_for_indexing.rs:36:5 + | +LL | assert!(v.len() <= 5); + | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:36:5 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:36:12 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:36:19 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:36:26 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:36:33 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ + = note: asserting the length before indexing will elide bounds checks + +error: indexing into a slice multiple times with an `assert` that does not cover the highest index + --> $DIR/missing_asserts_for_indexing.rs:42:5 + | +LL | assert!(v.len() > 3); + | -------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:42:5 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:42:12 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:42:19 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:42:26 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:42:33 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ + = note: asserting the length before indexing will elide bounds checks + +error: indexing into a slice multiple times with an `assert` that does not cover the highest index + --> $DIR/missing_asserts_for_indexing.rs:48:5 + | +LL | assert!(v.len() >= 4); + | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:48:5 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:48:12 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:48:19 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:48:26 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:48:33 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ + = note: asserting the length before indexing will elide bounds checks + +error: indexing into a slice multiple times with an `assert` that does not cover the highest index + --> $DIR/missing_asserts_for_indexing.rs:66:13 + | +LL | assert!(v.len() >= 3); + | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 3)` +LL | let _ = v[0]; + | _____________^ +LL | | +LL | | let _ = v[1..4]; + | |___________________^ + | +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:66:13 + | +LL | let _ = v[0]; + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:68:13 + | +LL | let _ = v[1..4]; + | ^^^^^^^ + = note: asserting the length before indexing will elide bounds checks + +error: indexing into a slice multiple times with an `assert` that does not cover the highest index + --> $DIR/missing_asserts_for_indexing.rs:80:13 + | +LL | assert!(v.len() >= 4); + | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` +LL | let _ = v[0]; + | _____________^ +LL | | +LL | | let _ = v[1..=4]; + | |____________________^ + | +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:80:13 + | +LL | let _ = v[0]; + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:82:13 + | +LL | let _ = v[1..=4]; + | ^^^^^^^^ + = note: asserting the length before indexing will elide bounds checks + +error: indexing into a slice multiple times with an `assert` that does not cover the highest index + --> $DIR/missing_asserts_for_indexing.rs:95:13 + | +LL | assert!(v1.len() >= 12); + | ----------------------- help: provide the highest index that is indexed with: `assert!(v1.len() > 12)` +LL | assert!(v2.len() >= 15); +LL | let _ = v1[0] + v1[12]; + | ^^^^^^^^^^^^^^ + | +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:95:13 + | +LL | let _ = v1[0] + v1[12]; + | ^^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:95:21 + | +LL | let _ = v1[0] + v1[12]; + | ^^^^^^ + = note: asserting the length before indexing will elide bounds checks + +error: indexing into a slice multiple times with an `assert` that does not cover the highest index + --> $DIR/missing_asserts_for_indexing.rs:97:13 + | +LL | assert!(v2.len() >= 15); + | ----------------------- help: provide the highest index that is indexed with: `assert!(v2.len() > 15)` +... +LL | let _ = v2[5] + v2[15]; + | ^^^^^^^^^^^^^^ + | +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:97:13 + | +LL | let _ = v2[5] + v2[15]; + | ^^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:97:21 + | +LL | let _ = v2[5] + v2[15]; + | ^^^^^^ + = note: asserting the length before indexing will elide bounds checks + +error: indexing into a slice multiple times with an `assert` that does not cover the highest index + --> $DIR/missing_asserts_for_indexing.rs:103:13 + | +LL | assert!(v1.len() >= 12); + | ----------------------- help: provide the highest index that is indexed with: `assert!(v1.len() > 12)` +LL | assert!(v2.len() > 15); +LL | let _ = v1[0] + v1[12]; + | ^^^^^^^^^^^^^^ + | +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:103:13 + | +LL | let _ = v1[0] + v1[12]; + | ^^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing.rs:103:21 + | +LL | let _ = v1[0] + v1[12]; + | ^^^^^^ + = note: asserting the length before indexing will elide bounds checks + +error: aborting due to 9 previous errors + diff --git a/src/tools/clippy/tests/ui/missing_asserts_for_indexing_unfixable.rs b/src/tools/clippy/tests/ui/missing_asserts_for_indexing_unfixable.rs new file mode 100644 index 000000000..4346ed892 --- /dev/null +++ b/src/tools/clippy/tests/ui/missing_asserts_for_indexing_unfixable.rs @@ -0,0 +1,49 @@ +#![allow(unused)] +#![warn(clippy::missing_asserts_for_indexing)] + +fn sum(v: &[u8]) -> u8 { + v[0] + v[1] + v[2] + v[3] + v[4] + //~^ ERROR: indexing into a slice multiple times without an `assert` +} + +fn subslice(v: &[u8]) { + let _ = v[0]; + //~^ ERROR: indexing into a slice multiple times without an `assert` + let _ = v[1..4]; +} + +fn variables(v: &[u8]) -> u8 { + let a = v[0]; + //~^ ERROR: indexing into a slice multiple times without an `assert` + let b = v[1]; + let c = v[2]; + a + b + c +} + +fn index_different_slices(v1: &[u8], v2: &[u8]) { + let _ = v1[0] + v1[12]; + let _ = v2[5] + v2[15]; +} + +fn index_different_slices2(v1: &[u8], v2: &[u8]) { + assert!(v1.len() > 12); + let _ = v1[0] + v1[12]; + let _ = v2[5] + v2[15]; +} + +struct Foo<'a> { + v: &'a [u8], + v2: &'a [u8], +} + +fn index_struct_field(f: &Foo<'_>) { + let _ = f.v[0] + f.v[1]; + //~^ ERROR: indexing into a slice multiple times without an `assert` +} + +fn index_struct_different_fields(f: &Foo<'_>) { + // ok, different fields + let _ = f.v[0] + f.v2[1]; +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/missing_asserts_for_indexing_unfixable.stderr b/src/tools/clippy/tests/ui/missing_asserts_for_indexing_unfixable.stderr new file mode 100644 index 000000000..12c9eed5d --- /dev/null +++ b/src/tools/clippy/tests/ui/missing_asserts_for_indexing_unfixable.stderr @@ -0,0 +1,164 @@ +error: indexing into a slice multiple times without an `assert` + --> $DIR/missing_asserts_for_indexing_unfixable.rs:5:5 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider asserting the length before indexing: `assert!(v.len() > 4);` +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:5:5 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:5:12 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:5:19 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:5:26 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:5:33 + | +LL | v[0] + v[1] + v[2] + v[3] + v[4] + | ^^^^ + = note: asserting the length before indexing will elide bounds checks + = note: `-D clippy::missing-asserts-for-indexing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_asserts_for_indexing)]` + +error: indexing into a slice multiple times without an `assert` + --> $DIR/missing_asserts_for_indexing_unfixable.rs:10:13 + | +LL | let _ = v[0]; + | _____________^ +LL | | +LL | | let _ = v[1..4]; + | |___________________^ + | + = help: consider asserting the length before indexing: `assert!(v.len() > 3);` +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:10:13 + | +LL | let _ = v[0]; + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:12:13 + | +LL | let _ = v[1..4]; + | ^^^^^^^ + = note: asserting the length before indexing will elide bounds checks + +error: indexing into a slice multiple times without an `assert` + --> $DIR/missing_asserts_for_indexing_unfixable.rs:16:13 + | +LL | let a = v[0]; + | _____________^ +LL | | +LL | | let b = v[1]; +LL | | let c = v[2]; + | |________________^ + | + = help: consider asserting the length before indexing: `assert!(v.len() > 2);` +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:16:13 + | +LL | let a = v[0]; + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:18:13 + | +LL | let b = v[1]; + | ^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:19:13 + | +LL | let c = v[2]; + | ^^^^ + = note: asserting the length before indexing will elide bounds checks + +error: indexing into a slice multiple times without an `assert` + --> $DIR/missing_asserts_for_indexing_unfixable.rs:24:13 + | +LL | let _ = v1[0] + v1[12]; + | ^^^^^^^^^^^^^^ + | + = help: consider asserting the length before indexing: `assert!(v1.len() > 12);` +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:24:13 + | +LL | let _ = v1[0] + v1[12]; + | ^^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:24:21 + | +LL | let _ = v1[0] + v1[12]; + | ^^^^^^ + = note: asserting the length before indexing will elide bounds checks + +error: indexing into a slice multiple times without an `assert` + --> $DIR/missing_asserts_for_indexing_unfixable.rs:25:13 + | +LL | let _ = v2[5] + v2[15]; + | ^^^^^^^^^^^^^^ + | + = help: consider asserting the length before indexing: `assert!(v2.len() > 15);` +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:25:13 + | +LL | let _ = v2[5] + v2[15]; + | ^^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:25:21 + | +LL | let _ = v2[5] + v2[15]; + | ^^^^^^ + = note: asserting the length before indexing will elide bounds checks + +error: indexing into a slice multiple times without an `assert` + --> $DIR/missing_asserts_for_indexing_unfixable.rs:31:13 + | +LL | let _ = v2[5] + v2[15]; + | ^^^^^^^^^^^^^^ + | + = help: consider asserting the length before indexing: `assert!(v2.len() > 15);` +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:31:13 + | +LL | let _ = v2[5] + v2[15]; + | ^^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:31:21 + | +LL | let _ = v2[5] + v2[15]; + | ^^^^^^ + = note: asserting the length before indexing will elide bounds checks + +error: indexing into a slice multiple times without an `assert` + --> $DIR/missing_asserts_for_indexing_unfixable.rs:40:13 + | +LL | let _ = f.v[0] + f.v[1]; + | ^^^^^^^^^^^^^^^ + | + = help: consider asserting the length before indexing: `assert!(f.v.len() > 1);` +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:40:13 + | +LL | let _ = f.v[0] + f.v[1]; + | ^^^^^^ +note: slice indexed here + --> $DIR/missing_asserts_for_indexing_unfixable.rs:40:22 + | +LL | let _ = f.v[0] + f.v[1]; + | ^^^^^^ + = note: asserting the length before indexing will elide bounds checks + +error: aborting due to 7 previous errors + diff --git a/src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs b/src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs index 06e053524..d026e0096 100644 --- a/src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs +++ b/src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs @@ -3,7 +3,7 @@ //! The .stderr output of this test should be empty. Otherwise it's a bug somewhere. //@aux-build:helper.rs -//@aux-build:../auxiliary/proc_macros.rs:proc-macro +//@aux-build:../auxiliary/proc_macros.rs #![warn(clippy::missing_const_for_fn)] #![feature(start)] diff --git a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs index 3aaee67e1..6985c2d0c 100644 --- a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs +++ b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs @@ -12,37 +12,45 @@ struct Game { impl Game { // Could be const pub fn new() -> Self { + //~^ ERROR: this could be a `const fn` + //~| NOTE: `-D clippy::missing-const-for-fn` implied by `-D warnings` Self { guess: 42 } } fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] { + //~^ ERROR: this could be a `const fn` b } } // Could be const fn one() -> i32 { + //~^ ERROR: this could be a `const fn` 1 } // Could also be const fn two() -> i32 { + //~^ ERROR: this could be a `const fn` let abc = 2; abc } // Could be const (since Rust 1.39) fn string() -> String { + //~^ ERROR: this could be a `const fn` String::new() } // Could be const unsafe fn four() -> i32 { + //~^ ERROR: this could be a `const fn` 4 } // Could also be const fn generic(t: T) -> T { + //~^ ERROR: this could be a `const fn` t } @@ -51,6 +59,7 @@ fn sub(x: u32) -> usize { } fn generic_arr(t: [T; 1]) -> T { + //~^ ERROR: this could be a `const fn` t[0] } @@ -64,6 +73,7 @@ mod with_drop { impl B { // This can be const, because `a` is passed by reference pub fn b(self, a: &A) -> B { + //~^ ERROR: this could be a `const fn` B } } @@ -73,6 +83,7 @@ mod with_drop { mod const_fn_stabilized_before_msrv { // This could be const because `u8::is_ascii_digit` is a stable const function in 1.47. fn const_fn_stabilized_before_msrv(byte: u8) { + //~^ ERROR: this could be a `const fn` byte.is_ascii_digit(); } } @@ -84,6 +95,7 @@ fn msrv_1_45() -> i32 { #[clippy::msrv = "1.46"] fn msrv_1_46() -> i32 { + //~^ ERROR: this could be a `const fn` 46 } diff --git a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr index 66cf4e315..b3a8ad8fa 100644 --- a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr +++ b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr @@ -2,89 +2,102 @@ error: this could be a `const fn` --> $DIR/could_be_const.rs:14:5 | LL | / pub fn new() -> Self { +LL | | +LL | | LL | | Self { guess: 42 } LL | | } | |_____^ | = note: `-D clippy::missing-const-for-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_const_for_fn)]` error: this could be a `const fn` - --> $DIR/could_be_const.rs:18:5 + --> $DIR/could_be_const.rs:20:5 | LL | / fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] { +LL | | LL | | b LL | | } | |_____^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:24:1 + --> $DIR/could_be_const.rs:27:1 | LL | / fn one() -> i32 { +LL | | LL | | 1 LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:29:1 + --> $DIR/could_be_const.rs:33:1 | LL | / fn two() -> i32 { +LL | | LL | | let abc = 2; LL | | abc LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:35:1 + --> $DIR/could_be_const.rs:40:1 | LL | / fn string() -> String { +LL | | LL | | String::new() LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:40:1 + --> $DIR/could_be_const.rs:46:1 | LL | / unsafe fn four() -> i32 { +LL | | LL | | 4 LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:45:1 + --> $DIR/could_be_const.rs:52:1 | LL | / fn generic(t: T) -> T { +LL | | LL | | t LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:53:1 + --> $DIR/could_be_const.rs:61:1 | LL | / fn generic_arr(t: [T; 1]) -> T { +LL | | LL | | t[0] LL | | } | |_^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:66:9 + --> $DIR/could_be_const.rs:75:9 | LL | / pub fn b(self, a: &A) -> B { +LL | | LL | | B LL | | } | |_________^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:75:5 + --> $DIR/could_be_const.rs:85:5 | LL | / fn const_fn_stabilized_before_msrv(byte: u8) { +LL | | LL | | byte.is_ascii_digit(); LL | | } | |_____^ error: this could be a `const fn` - --> $DIR/could_be_const.rs:86:1 + --> $DIR/could_be_const.rs:97:1 | LL | / fn msrv_1_46() -> i32 { +LL | | LL | | 46 LL | | } | |_^ diff --git a/src/tools/clippy/tests/ui/missing_doc.rs b/src/tools/clippy/tests/ui/missing_doc.rs index 83ebf09c8..9bfad3b96 100644 --- a/src/tools/clippy/tests/ui/missing_doc.rs +++ b/src/tools/clippy/tests/ui/missing_doc.rs @@ -1,5 +1,5 @@ //@needs-asm-support -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![warn(clippy::missing_docs_in_private_items)] // When denying at the crate level, be sure to not get random warnings from the diff --git a/src/tools/clippy/tests/ui/missing_doc.stderr b/src/tools/clippy/tests/ui/missing_doc.stderr index 4e8a49bf1..1d8007fa5 100644 --- a/src/tools/clippy/tests/ui/missing_doc.stderr +++ b/src/tools/clippy/tests/ui/missing_doc.stderr @@ -5,6 +5,7 @@ LL | type Typedef = String; | ^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]` error: missing documentation for a module --> $DIR/missing_doc.rs:19:1 diff --git a/src/tools/clippy/tests/ui/missing_doc_crate_missing.rs b/src/tools/clippy/tests/ui/missing_doc_crate_missing.rs index 51fd57df8..73584ac8c 100644 --- a/src/tools/clippy/tests/ui/missing_doc_crate_missing.rs +++ b/src/tools/clippy/tests/ui/missing_doc_crate_missing.rs @@ -1,3 +1,5 @@ #![warn(clippy::missing_docs_in_private_items)] +//~^ ERROR: missing documentation for the crate +//~| NOTE: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` fn main() {} diff --git a/src/tools/clippy/tests/ui/missing_doc_crate_missing.stderr b/src/tools/clippy/tests/ui/missing_doc_crate_missing.stderr index 19516bf5f..c684bc8e7 100644 --- a/src/tools/clippy/tests/ui/missing_doc_crate_missing.stderr +++ b/src/tools/clippy/tests/ui/missing_doc_crate_missing.stderr @@ -3,10 +3,13 @@ error: missing documentation for the crate | LL | / #![warn(clippy::missing_docs_in_private_items)] LL | | +LL | | +LL | | LL | | fn main() {} | |____________^ | = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/missing_doc_impl.rs b/src/tools/clippy/tests/ui/missing_doc_impl.rs index 2d45132f9..520ddbe16 100644 --- a/src/tools/clippy/tests/ui/missing_doc_impl.rs +++ b/src/tools/clippy/tests/ui/missing_doc_impl.rs @@ -1,4 +1,4 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![warn(clippy::missing_docs_in_private_items)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/missing_doc_impl.stderr b/src/tools/clippy/tests/ui/missing_doc_impl.stderr index 111d65469..e303b7b7d 100644 --- a/src/tools/clippy/tests/ui/missing_doc_impl.stderr +++ b/src/tools/clippy/tests/ui/missing_doc_impl.stderr @@ -8,6 +8,7 @@ LL | | } | |_^ | = note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/missing_fields_in_debug.rs b/src/tools/clippy/tests/ui/missing_fields_in_debug.rs index c156d394e..e91e8ab7f 100644 --- a/src/tools/clippy/tests/ui/missing_fields_in_debug.rs +++ b/src/tools/clippy/tests/ui/missing_fields_in_debug.rs @@ -11,6 +11,7 @@ struct NamedStruct1Ignored { } impl fmt::Debug for NamedStruct1Ignored { + //~^ ERROR: manual `Debug` impl does not include all fields // unused field: hidden fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter @@ -29,6 +30,7 @@ struct NamedStructMultipleIgnored { } impl fmt::Debug for NamedStructMultipleIgnored { + //~^ ERROR: manual `Debug` impl does not include all fields // unused fields: hidden, hidden2, hidden4 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter @@ -90,6 +92,7 @@ struct MultiExprDebugImpl { // ok impl fmt::Debug for MultiExprDebugImpl { + //~^ ERROR: manual `Debug` impl does not include all fields fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { let mut f = formatter.debug_struct("MultiExprDebugImpl"); f.field("a", &self.a); diff --git a/src/tools/clippy/tests/ui/missing_fields_in_debug.stderr b/src/tools/clippy/tests/ui/missing_fields_in_debug.stderr index ef9d02aba..481b2c632 100644 --- a/src/tools/clippy/tests/ui/missing_fields_in_debug.stderr +++ b/src/tools/clippy/tests/ui/missing_fields_in_debug.stderr @@ -2,9 +2,9 @@ error: manual `Debug` impl does not include all fields --> $DIR/missing_fields_in_debug.rs:13:1 | LL | / impl fmt::Debug for NamedStruct1Ignored { +LL | | LL | | // unused field: hidden LL | | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { -LL | | formatter ... | LL | | } LL | | } @@ -18,31 +18,32 @@ LL | hidden: u32, = help: consider including all fields in this `Debug` impl = help: consider calling `.finish_non_exhaustive()` if you intend to ignore fields = note: `-D clippy::missing-fields-in-debug` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_fields_in_debug)]` error: manual `Debug` impl does not include all fields - --> $DIR/missing_fields_in_debug.rs:31:1 + --> $DIR/missing_fields_in_debug.rs:32:1 | LL | / impl fmt::Debug for NamedStructMultipleIgnored { +LL | | LL | | // unused fields: hidden, hidden2, hidden4 LL | | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { -LL | | formatter ... | LL | | } LL | | } | |_^ | note: this field is unused - --> $DIR/missing_fields_in_debug.rs:25:5 + --> $DIR/missing_fields_in_debug.rs:26:5 | LL | hidden: u32, | ^^^^^^^^^^^ note: this field is unused - --> $DIR/missing_fields_in_debug.rs:26:5 + --> $DIR/missing_fields_in_debug.rs:27:5 | LL | hidden2: String, | ^^^^^^^^^^^^^^^ note: this field is unused - --> $DIR/missing_fields_in_debug.rs:28:5 + --> $DIR/missing_fields_in_debug.rs:29:5 | LL | hidden4: ((((u8), u16), u32), u64), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -50,19 +51,19 @@ LL | hidden4: ((((u8), u16), u32), u64), = help: consider calling `.finish_non_exhaustive()` if you intend to ignore fields error: manual `Debug` impl does not include all fields - --> $DIR/missing_fields_in_debug.rs:92:1 + --> $DIR/missing_fields_in_debug.rs:94:1 | LL | / impl fmt::Debug for MultiExprDebugImpl { +LL | | LL | | fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { LL | | let mut f = formatter.debug_struct("MultiExprDebugImpl"); -LL | | f.field("a", &self.a); -LL | | f.finish() +... | LL | | } LL | | } | |_^ | note: this field is unused - --> $DIR/missing_fields_in_debug.rs:88:5 + --> $DIR/missing_fields_in_debug.rs:90:5 | LL | b: String, | ^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/missing_inline.rs b/src/tools/clippy/tests/ui/missing_inline.rs index 07f8e3888..dca85b94d 100644 --- a/src/tools/clippy/tests/ui/missing_inline.rs +++ b/src/tools/clippy/tests/ui/missing_inline.rs @@ -16,7 +16,10 @@ mod module {} // ok pub mod pub_module {} // ok fn foo() {} -pub fn pub_foo() {} // missing #[inline] +// missing #[inline] +pub fn pub_foo() {} +//~^ ERROR: missing `#[inline]` for a function +//~| NOTE: `-D clippy::missing-inline-in-public-items` implied by `-D warnings` #[inline] pub fn pub_foo_inline() {} // ok #[inline(always)] @@ -32,7 +35,9 @@ trait Bar { pub trait PubBar { fn PubBar_a(); // ok - fn PubBar_b() {} // missing #[inline] + // missing #[inline] + fn PubBar_b() {} + //~^ ERROR: missing `#[inline]` for a default trait method #[inline] fn PubBar_c() {} // ok } @@ -46,9 +51,15 @@ impl PubBar for Foo { // all of these need inline because PubFoo is exported impl PubBar for PubFoo { - fn PubBar_a() {} // missing #[inline] - fn PubBar_b() {} // missing #[inline] - fn PubBar_c() {} // missing #[inline] + // missing #[inline] + fn PubBar_a() {} + //~^ ERROR: missing `#[inline]` for a method + // missing #[inline] + fn PubBar_b() {} + //~^ ERROR: missing `#[inline]` for a method + // missing #[inline] + fn PubBar_c() {} + //~^ ERROR: missing `#[inline]` for a method } // do not need inline because Foo is not exported @@ -58,7 +69,9 @@ impl Foo { // need inline because PubFoo is exported impl PubFoo { - pub fn PubFooImpl() {} // missing #[inline] + // missing #[inline] + pub fn PubFooImpl() {} + //~^ ERROR: missing `#[inline]` for a method } // do not lint this since users cannot control the external code diff --git a/src/tools/clippy/tests/ui/missing_inline.stderr b/src/tools/clippy/tests/ui/missing_inline.stderr index 40b92b764..da2a2a7fe 100644 --- a/src/tools/clippy/tests/ui/missing_inline.stderr +++ b/src/tools/clippy/tests/ui/missing_inline.stderr @@ -1,39 +1,40 @@ error: missing `#[inline]` for a function - --> $DIR/missing_inline.rs:19:1 + --> $DIR/missing_inline.rs:20:1 | -LL | pub fn pub_foo() {} // missing #[inline] +LL | pub fn pub_foo() {} | ^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::missing-inline-in-public-items` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_inline_in_public_items)]` error: missing `#[inline]` for a default trait method - --> $DIR/missing_inline.rs:35:5 + --> $DIR/missing_inline.rs:39:5 | -LL | fn PubBar_b() {} // missing #[inline] +LL | fn PubBar_b() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:49:5 + --> $DIR/missing_inline.rs:55:5 | -LL | fn PubBar_a() {} // missing #[inline] +LL | fn PubBar_a() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:50:5 + --> $DIR/missing_inline.rs:58:5 | -LL | fn PubBar_b() {} // missing #[inline] +LL | fn PubBar_b() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:51:5 + --> $DIR/missing_inline.rs:61:5 | -LL | fn PubBar_c() {} // missing #[inline] +LL | fn PubBar_c() {} | ^^^^^^^^^^^^^^^^ error: missing `#[inline]` for a method - --> $DIR/missing_inline.rs:61:5 + --> $DIR/missing_inline.rs:73:5 | -LL | pub fn PubFooImpl() {} // missing #[inline] +LL | pub fn PubFooImpl() {} | ^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/src/tools/clippy/tests/ui/missing_panics_doc.stderr b/src/tools/clippy/tests/ui/missing_panics_doc.stderr index 3dbe2dfbd..efee48550 100644 --- a/src/tools/clippy/tests/ui/missing_panics_doc.stderr +++ b/src/tools/clippy/tests/ui/missing_panics_doc.stderr @@ -10,6 +10,7 @@ note: first possible panic found here LL | result.unwrap() | ^^^^^^^^^^^^^^^ = note: `-D clippy::missing-panics-doc` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/missing_spin_loop.fixed b/src/tools/clippy/tests/ui/missing_spin_loop.fixed index a15298dc3..b6520d478 100644 --- a/src/tools/clippy/tests/ui/missing_spin_loop.fixed +++ b/src/tools/clippy/tests/ui/missing_spin_loop.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::missing_spin_loop)] #![allow(clippy::bool_comparison)] #![allow(unused_braces)] diff --git a/src/tools/clippy/tests/ui/missing_spin_loop.rs b/src/tools/clippy/tests/ui/missing_spin_loop.rs index be74581ec..7b115c66a 100644 --- a/src/tools/clippy/tests/ui/missing_spin_loop.rs +++ b/src/tools/clippy/tests/ui/missing_spin_loop.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::missing_spin_loop)] #![allow(clippy::bool_comparison)] #![allow(unused_braces)] diff --git a/src/tools/clippy/tests/ui/missing_spin_loop.stderr b/src/tools/clippy/tests/ui/missing_spin_loop.stderr index 5795c2c21..a84c19d59 100644 --- a/src/tools/clippy/tests/ui/missing_spin_loop.stderr +++ b/src/tools/clippy/tests/ui/missing_spin_loop.stderr @@ -1,37 +1,38 @@ error: busy-waiting loop should at least have a spin loop hint - --> $DIR/missing_spin_loop.rs:11:37 + --> $DIR/missing_spin_loop.rs:10:37 | LL | while b.load(Ordering::Acquire) {} | ^^ help: try: `{ std::hint::spin_loop() }` | = note: `-D clippy::missing-spin-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_spin_loop)]` error: busy-waiting loop should at least have a spin loop hint - --> $DIR/missing_spin_loop.rs:13:37 + --> $DIR/missing_spin_loop.rs:12:37 | LL | while !b.load(Ordering::SeqCst) {} | ^^ help: try: `{ std::hint::spin_loop() }` error: busy-waiting loop should at least have a spin loop hint - --> $DIR/missing_spin_loop.rs:15:46 + --> $DIR/missing_spin_loop.rs:14:46 | 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:17:49 + --> $DIR/missing_spin_loop.rs:16: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:19:93 + --> $DIR/missing_spin_loop.rs:18: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:21:94 + --> $DIR/missing_spin_loop.rs:20:94 | LL | while Ok(false) != b.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed) {} | ^^ help: try: `{ std::hint::spin_loop() }` diff --git a/src/tools/clippy/tests/ui/missing_spin_loop_no_std.fixed b/src/tools/clippy/tests/ui/missing_spin_loop_no_std.fixed index 960e5c05f..497e0e243 100644 --- a/src/tools/clippy/tests/ui/missing_spin_loop_no_std.fixed +++ b/src/tools/clippy/tests/ui/missing_spin_loop_no_std.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::missing_spin_loop)] #![feature(lang_items, start, libc)] #![no_std] diff --git a/src/tools/clippy/tests/ui/missing_spin_loop_no_std.rs b/src/tools/clippy/tests/ui/missing_spin_loop_no_std.rs index e532ca62d..1c85a9c58 100644 --- a/src/tools/clippy/tests/ui/missing_spin_loop_no_std.rs +++ b/src/tools/clippy/tests/ui/missing_spin_loop_no_std.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::missing_spin_loop)] #![feature(lang_items, start, libc)] #![no_std] diff --git a/src/tools/clippy/tests/ui/missing_spin_loop_no_std.stderr b/src/tools/clippy/tests/ui/missing_spin_loop_no_std.stderr index 3322a7aae..0b7be4616 100644 --- a/src/tools/clippy/tests/ui/missing_spin_loop_no_std.stderr +++ b/src/tools/clippy/tests/ui/missing_spin_loop_no_std.stderr @@ -1,10 +1,11 @@ error: busy-waiting loop should at least have a spin loop hint - --> $DIR/missing_spin_loop_no_std.rs:13:37 + --> $DIR/missing_spin_loop_no_std.rs:12:37 | LL | while b.load(Ordering::Acquire) {} | ^^ help: try: `{ core::hint::spin_loop() }` | = note: `-D clippy::missing-spin-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_spin_loop)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/missing_trait_methods.rs b/src/tools/clippy/tests/ui/missing_trait_methods.rs index 8df885919..1b09b717f 100644 --- a/src/tools/clippy/tests/ui/missing_trait_methods.rs +++ b/src/tools/clippy/tests/ui/missing_trait_methods.rs @@ -20,8 +20,10 @@ trait B { struct Partial; impl A for Partial {} +//~^ ERROR: missing trait method provided by default: `provided` impl B for Partial { + //~^ ERROR: missing trait method provided by default: `b` fn required() {} fn a(_: usize) -> usize { diff --git a/src/tools/clippy/tests/ui/missing_trait_methods.stderr b/src/tools/clippy/tests/ui/missing_trait_methods.stderr index 0c5205e19..3e20a51e0 100644 --- a/src/tools/clippy/tests/ui/missing_trait_methods.stderr +++ b/src/tools/clippy/tests/ui/missing_trait_methods.stderr @@ -10,9 +10,10 @@ help: implement the method LL | fn provided() {} | ^^^^^^^^^^^^^ = note: `-D clippy::missing-trait-methods` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::missing_trait_methods)]` error: missing trait method provided by default: `b` - --> $DIR/missing_trait_methods.rs:24:1 + --> $DIR/missing_trait_methods.rs:25:1 | LL | impl B for Partial { | ^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/mistyped_literal_suffix.fixed b/src/tools/clippy/tests/ui/mistyped_literal_suffix.fixed index 9c2ffcb02..861764a2a 100644 --- a/src/tools/clippy/tests/ui/mistyped_literal_suffix.fixed +++ b/src/tools/clippy/tests/ui/mistyped_literal_suffix.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![allow( dead_code, diff --git a/src/tools/clippy/tests/ui/mistyped_literal_suffix.rs b/src/tools/clippy/tests/ui/mistyped_literal_suffix.rs index a0a1e96a7..4a15c335f 100644 --- a/src/tools/clippy/tests/ui/mistyped_literal_suffix.rs +++ b/src/tools/clippy/tests/ui/mistyped_literal_suffix.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![allow( dead_code, diff --git a/src/tools/clippy/tests/ui/mistyped_literal_suffix.stderr b/src/tools/clippy/tests/ui/mistyped_literal_suffix.stderr index ef8e6a33d..ecd73497a 100644 --- a/src/tools/clippy/tests/ui/mistyped_literal_suffix.stderr +++ b/src/tools/clippy/tests/ui/mistyped_literal_suffix.stderr @@ -1,5 +1,5 @@ error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:17:18 + --> $DIR/mistyped_literal_suffix.rs:16:18 | LL | let fail14 = 2_32; | ^^^^ help: did you mean to write: `2_i32` @@ -7,91 +7,91 @@ LL | let fail14 = 2_32; = note: `#[deny(clippy::mistyped_literal_suffixes)]` on by default error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:18:18 + --> $DIR/mistyped_literal_suffix.rs:17:18 | LL | let fail15 = 4_64; | ^^^^ help: did you mean to write: `4_i64` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:19:18 + --> $DIR/mistyped_literal_suffix.rs:18:18 | LL | let fail16 = 7_8; // | ^^^ help: did you mean to write: `7_i8` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:20:18 + --> $DIR/mistyped_literal_suffix.rs:19:18 | LL | let fail17 = 23_16; // | ^^^^^ help: did you mean to write: `23_i16` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:23:18 + --> $DIR/mistyped_literal_suffix.rs:22:18 | LL | let fail20 = 2__8; // | ^^^^ help: did you mean to write: `2_i8` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:24:18 + --> $DIR/mistyped_literal_suffix.rs:23:18 | LL | let fail21 = 4___16; // | ^^^^^^ help: did you mean to write: `4_i16` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:27:18 + --> $DIR/mistyped_literal_suffix.rs:26:18 | LL | let fail25 = 1E2_32; | ^^^^^^ help: did you mean to write: `1E2_f32` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:28:18 + --> $DIR/mistyped_literal_suffix.rs:27:18 | LL | let fail26 = 43E7_64; | ^^^^^^^ help: did you mean to write: `43E7_f64` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:29:18 + --> $DIR/mistyped_literal_suffix.rs:28:18 | LL | let fail27 = 243E17_32; | ^^^^^^^^^ help: did you mean to write: `243E17_f32` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:30:18 + --> $DIR/mistyped_literal_suffix.rs:29: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:34:18 + --> $DIR/mistyped_literal_suffix.rs:33: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:35:18 + --> $DIR/mistyped_literal_suffix.rs:34: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:37:18 + --> $DIR/mistyped_literal_suffix.rs:36:18 | LL | let fail33 = 0x1234_16; | ^^^^^^^^^ help: did you mean to write: `0x1234_i16` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:38:18 + --> $DIR/mistyped_literal_suffix.rs:37:18 | LL | let fail34 = 0xABCD_16; | ^^^^^^^^^ help: did you mean to write: `0xABCD_u16` error: mistyped literal suffix - --> $DIR/mistyped_literal_suffix.rs:40:18 + --> $DIR/mistyped_literal_suffix.rs:39: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:46:13 + --> $DIR/mistyped_literal_suffix.rs:45:13 | LL | let _ = 1.12345E1_32; | ^^^^^^^^^^^^ help: did you mean to write: `1.123_45E1_f32` diff --git a/src/tools/clippy/tests/ui/mixed_read_write_in_expression.rs b/src/tools/clippy/tests/ui/mixed_read_write_in_expression.rs index 6efc7657e..241536abd 100644 --- a/src/tools/clippy/tests/ui/mixed_read_write_in_expression.rs +++ b/src/tools/clippy/tests/ui/mixed_read_write_in_expression.rs @@ -12,9 +12,11 @@ fn main() { x = 1; 1 } + x; + //~^ ERROR: unsequenced read of `x` // Example from iss#277 x += { + //~^ ERROR: unsequenced read of `x` x = 20; 2 }; @@ -28,6 +30,7 @@ fn main() { let base = Foo { a: 4, b: 5 }; let foo = Foo { a: x, + //~^ ERROR: unsequenced read of `x` ..{ x = 6; base @@ -37,6 +40,7 @@ fn main() { let closure = || { let mut x = 0; x += { + //~^ ERROR: unsequenced read of `x` x = 20; 2 }; diff --git a/src/tools/clippy/tests/ui/mixed_read_write_in_expression.stderr b/src/tools/clippy/tests/ui/mixed_read_write_in_expression.stderr index 8cc68b0ac..3dad98815 100644 --- a/src/tools/clippy/tests/ui/mixed_read_write_in_expression.stderr +++ b/src/tools/clippy/tests/ui/mixed_read_write_in_expression.stderr @@ -10,39 +10,40 @@ note: whether read occurs before this write depends on evaluation order LL | x = 1; | ^^^^^ = note: `-D clippy::mixed-read-write-in-expression` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mixed_read_write_in_expression)]` error: unsequenced read of `x` - --> $DIR/mixed_read_write_in_expression.rs:17:5 + --> $DIR/mixed_read_write_in_expression.rs:18:5 | LL | x += { | ^ | note: whether read occurs before this write depends on evaluation order - --> $DIR/mixed_read_write_in_expression.rs:18:9 + --> $DIR/mixed_read_write_in_expression.rs:20:9 | LL | x = 20; | ^^^^^^ error: unsequenced read of `x` - --> $DIR/mixed_read_write_in_expression.rs:30:12 + --> $DIR/mixed_read_write_in_expression.rs:32:12 | LL | a: x, | ^ | note: whether read occurs before this write depends on evaluation order - --> $DIR/mixed_read_write_in_expression.rs:32:13 + --> $DIR/mixed_read_write_in_expression.rs:35:13 | LL | x = 6; | ^^^^^ error: unsequenced read of `x` - --> $DIR/mixed_read_write_in_expression.rs:39:9 + --> $DIR/mixed_read_write_in_expression.rs:42:9 | LL | x += { | ^ | note: whether read occurs before this write depends on evaluation order - --> $DIR/mixed_read_write_in_expression.rs:40:13 + --> $DIR/mixed_read_write_in_expression.rs:44:13 | LL | x = 20; | ^^^^^^ diff --git a/src/tools/clippy/tests/ui/module_inception.rs b/src/tools/clippy/tests/ui/module_inception.rs index 802c3ec39..ad46e0c29 100644 --- a/src/tools/clippy/tests/ui/module_inception.rs +++ b/src/tools/clippy/tests/ui/module_inception.rs @@ -3,11 +3,14 @@ pub mod foo2 { pub mod bar2 { pub mod bar2 { + //~^ ERROR: module has the same name as its containing module + //~| NOTE: `-D clippy::module-inception` implied by `-D warnings` pub mod foo2 {} } pub mod foo2 {} } pub mod foo2 { + //~^ ERROR: module has the same name as its containing module pub mod bar2 {} } } @@ -15,11 +18,13 @@ pub mod foo2 { mod foo { mod bar { mod bar { + //~^ ERROR: module has the same name as its containing module mod foo {} } mod foo {} } mod foo { + //~^ ERROR: module has the same name as its containing module mod bar {} } } diff --git a/src/tools/clippy/tests/ui/module_inception.stderr b/src/tools/clippy/tests/ui/module_inception.stderr index ebb8e296f..d5856614f 100644 --- a/src/tools/clippy/tests/ui/module_inception.stderr +++ b/src/tools/clippy/tests/ui/module_inception.stderr @@ -2,32 +2,38 @@ error: module has the same name as its containing module --> $DIR/module_inception.rs:5:9 | LL | / pub mod bar2 { +LL | | +LL | | LL | | pub mod foo2 {} LL | | } | |_________^ | = note: `-D clippy::module-inception` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::module_inception)]` error: module has the same name as its containing module - --> $DIR/module_inception.rs:10:5 + --> $DIR/module_inception.rs:12:5 | LL | / pub mod foo2 { +LL | | LL | | pub mod bar2 {} LL | | } | |_____^ error: module has the same name as its containing module - --> $DIR/module_inception.rs:17:9 + --> $DIR/module_inception.rs:20:9 | LL | / mod bar { +LL | | LL | | mod foo {} LL | | } | |_________^ error: module has the same name as its containing module - --> $DIR/module_inception.rs:22:5 + --> $DIR/module_inception.rs:26:5 | LL | / mod foo { +LL | | LL | | mod bar {} LL | | } | |_____^ diff --git a/src/tools/clippy/tests/ui/module_name_repetitions.rs b/src/tools/clippy/tests/ui/module_name_repetitions.rs index fb2c76123..a6cf03890 100644 --- a/src/tools/clippy/tests/ui/module_name_repetitions.rs +++ b/src/tools/clippy/tests/ui/module_name_repetitions.rs @@ -6,10 +6,16 @@ mod foo { pub fn foo() {} pub fn foo_bar() {} + //~^ ERROR: item name starts with its containing module's name + //~| NOTE: `-D clippy::module-name-repetitions` implied by `-D warnings` pub fn bar_foo() {} + //~^ ERROR: item name ends with its containing module's name pub struct FooCake; + //~^ ERROR: item name starts with its containing module's name pub enum CakeFoo {} + //~^ ERROR: item name ends with its containing module's name pub struct Foo7Bar; + //~^ ERROR: item name starts with its containing module's name // Should not warn pub struct Foobar; diff --git a/src/tools/clippy/tests/ui/module_name_repetitions.stderr b/src/tools/clippy/tests/ui/module_name_repetitions.stderr index 277801194..1854d3a85 100644 --- a/src/tools/clippy/tests/ui/module_name_repetitions.stderr +++ b/src/tools/clippy/tests/ui/module_name_repetitions.stderr @@ -5,27 +5,28 @@ LL | pub fn foo_bar() {} | ^^^^^^^ | = note: `-D clippy::module-name-repetitions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::module_name_repetitions)]` error: item name ends with its containing module's name - --> $DIR/module_name_repetitions.rs:9:12 + --> $DIR/module_name_repetitions.rs:11:12 | LL | pub fn bar_foo() {} | ^^^^^^^ error: item name starts with its containing module's name - --> $DIR/module_name_repetitions.rs:10:16 + --> $DIR/module_name_repetitions.rs:13:16 | LL | pub struct FooCake; | ^^^^^^^ error: item name ends with its containing module's name - --> $DIR/module_name_repetitions.rs:11:14 + --> $DIR/module_name_repetitions.rs:15:14 | LL | pub enum CakeFoo {} | ^^^^^^^ error: item name starts with its containing module's name - --> $DIR/module_name_repetitions.rs:12:16 + --> $DIR/module_name_repetitions.rs:17:16 | LL | pub struct Foo7Bar; | ^^^^^^^ diff --git a/src/tools/clippy/tests/ui/modulo_arithmetic_float.rs b/src/tools/clippy/tests/ui/modulo_arithmetic_float.rs index b1861f07c..37895ea09 100644 --- a/src/tools/clippy/tests/ui/modulo_arithmetic_float.rs +++ b/src/tools/clippy/tests/ui/modulo_arithmetic_float.rs @@ -4,22 +4,42 @@ fn main() { // Lint when both sides are const and of the opposite sign -1.6 % 2.1; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1.600 % + //~| NOTE: double check for expected result especially when interoperating with differ 1.6 % -2.1; + //~^ ERROR: you are using modulo operator on constants with different signs: `1.600 % + //~| NOTE: double check for expected result especially when interoperating with differ (1.1 - 2.3) % (1.1 + 2.3); + //~^ ERROR: you are using modulo operator on constants with different signs: `-1.200 % + //~| NOTE: double check for expected result especially when interoperating with differ (1.1 + 2.3) % (1.1 - 2.3); + //~^ ERROR: you are using modulo operator on constants with different signs: `3.400 % + //~| NOTE: double check for expected result especially when interoperating with differ // Lint on floating point numbers let a_f32: f32 = -1.6; let mut b_f32: f32 = 2.1; a_f32 % b_f32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_f32 % a_f32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_f32 %= a_f32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_f64: f64 = -1.6; let mut b_f64: f64 = 2.1; a_f64 % b_f64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_f64 % a_f64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_f64 %= a_f64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ // No lint when both sides are const and of the same sign 1.6 % 2.1; diff --git a/src/tools/clippy/tests/ui/modulo_arithmetic_float.stderr b/src/tools/clippy/tests/ui/modulo_arithmetic_float.stderr index 36106de31..46c8d0288 100644 --- a/src/tools/clippy/tests/ui/modulo_arithmetic_float.stderr +++ b/src/tools/clippy/tests/ui/modulo_arithmetic_float.stderr @@ -6,9 +6,10 @@ LL | -1.6 % 2.1; | = note: double check for expected result especially when interoperating with different languages = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` error: you are using modulo operator on constants with different signs: `1.600 % -2.100` - --> $DIR/modulo_arithmetic_float.rs:7:5 + --> $DIR/modulo_arithmetic_float.rs:9:5 | LL | 1.6 % -2.1; | ^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | 1.6 % -2.1; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on constants with different signs: `-1.200 % 3.400` - --> $DIR/modulo_arithmetic_float.rs:8:5 + --> $DIR/modulo_arithmetic_float.rs:12:5 | LL | (1.1 - 2.3) % (1.1 + 2.3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | (1.1 - 2.3) % (1.1 + 2.3); = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on constants with different signs: `3.400 % -1.200` - --> $DIR/modulo_arithmetic_float.rs:9:5 + --> $DIR/modulo_arithmetic_float.rs:15:5 | LL | (1.1 + 2.3) % (1.1 - 2.3); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | (1.1 + 2.3) % (1.1 - 2.3); = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:14:5 + --> $DIR/modulo_arithmetic_float.rs:22:5 | LL | a_f32 % b_f32; | ^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | a_f32 % b_f32; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:15:5 + --> $DIR/modulo_arithmetic_float.rs:25:5 | LL | b_f32 % a_f32; | ^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | b_f32 % a_f32; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:16:5 + --> $DIR/modulo_arithmetic_float.rs:28:5 | LL | b_f32 %= a_f32; | ^^^^^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | b_f32 %= a_f32; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:20:5 + --> $DIR/modulo_arithmetic_float.rs:34:5 | LL | a_f64 % b_f64; | ^^^^^^^^^^^^^ @@ -64,7 +65,7 @@ LL | a_f64 % b_f64; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:21:5 + --> $DIR/modulo_arithmetic_float.rs:37:5 | LL | b_f64 % a_f64; | ^^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL | b_f64 % a_f64; = note: double check for expected result especially when interoperating with different languages error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_float.rs:22:5 + --> $DIR/modulo_arithmetic_float.rs:40:5 | LL | b_f64 %= a_f64; | ^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/modulo_arithmetic_integral.rs b/src/tools/clippy/tests/ui/modulo_arithmetic_integral.rs index fc1acc39e..4dbed2402 100644 --- a/src/tools/clippy/tests/ui/modulo_arithmetic_integral.rs +++ b/src/tools/clippy/tests/ui/modulo_arithmetic_integral.rs @@ -6,43 +6,77 @@ fn main() { let a = -1; let mut b = 2; a % b; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b % a; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b %= a; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i8: i8 = 1; let mut b_i8: i8 = 2; a_i8 % b_i8; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i8 %= a_i8; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i16: i16 = 1; let mut b_i16: i16 = 2; a_i16 % b_i16; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i16 %= a_i16; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i32: i32 = 1; let mut b_i32: i32 = 2; a_i32 % b_i32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i32 %= a_i32; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i64: i64 = 1; let mut b_i64: i64 = 2; a_i64 % b_i64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i64 %= a_i64; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_i128: i128 = 1; let mut b_i128: i128 = 2; a_i128 % b_i128; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_i128 %= a_i128; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a_isize: isize = 1; let mut b_isize: isize = 2; a_isize % b_isize; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b_isize %= a_isize; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ let a = 1; let mut b = 2; a % b; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ b %= a; + //~^ ERROR: you are using modulo operator on types that might have different signs + //~| NOTE: double check for expected result especially when interoperating with differ // No lint on unsigned integral value let a_u8: u8 = 17; diff --git a/src/tools/clippy/tests/ui/modulo_arithmetic_integral.stderr b/src/tools/clippy/tests/ui/modulo_arithmetic_integral.stderr index 9ff676ff6..033a016c0 100644 --- a/src/tools/clippy/tests/ui/modulo_arithmetic_integral.stderr +++ b/src/tools/clippy/tests/ui/modulo_arithmetic_integral.stderr @@ -7,9 +7,10 @@ LL | a % b; = note: double check for expected result especially when interoperating with different languages = note: or consider using `rem_euclid` or similar function = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:9:5 + --> $DIR/modulo_arithmetic_integral.rs:11:5 | LL | b % a; | ^^^^^ @@ -18,7 +19,7 @@ LL | b % a; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:10:5 + --> $DIR/modulo_arithmetic_integral.rs:14:5 | LL | b %= a; | ^^^^^^ @@ -27,7 +28,7 @@ LL | b %= a; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:14:5 + --> $DIR/modulo_arithmetic_integral.rs:20:5 | LL | a_i8 % b_i8; | ^^^^^^^^^^^ @@ -36,7 +37,7 @@ LL | a_i8 % b_i8; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:15:5 + --> $DIR/modulo_arithmetic_integral.rs:23:5 | LL | b_i8 %= a_i8; | ^^^^^^^^^^^^ @@ -45,7 +46,7 @@ LL | b_i8 %= a_i8; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:19:5 + --> $DIR/modulo_arithmetic_integral.rs:29:5 | LL | a_i16 % b_i16; | ^^^^^^^^^^^^^ @@ -54,7 +55,7 @@ LL | a_i16 % b_i16; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:20:5 + --> $DIR/modulo_arithmetic_integral.rs:32:5 | LL | b_i16 %= a_i16; | ^^^^^^^^^^^^^^ @@ -63,7 +64,7 @@ LL | b_i16 %= a_i16; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:24:5 + --> $DIR/modulo_arithmetic_integral.rs:38:5 | LL | a_i32 % b_i32; | ^^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL | a_i32 % b_i32; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:25:5 + --> $DIR/modulo_arithmetic_integral.rs:41:5 | LL | b_i32 %= a_i32; | ^^^^^^^^^^^^^^ @@ -81,7 +82,7 @@ LL | b_i32 %= a_i32; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:29:5 + --> $DIR/modulo_arithmetic_integral.rs:47:5 | LL | a_i64 % b_i64; | ^^^^^^^^^^^^^ @@ -90,7 +91,7 @@ LL | a_i64 % b_i64; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:30:5 + --> $DIR/modulo_arithmetic_integral.rs:50:5 | LL | b_i64 %= a_i64; | ^^^^^^^^^^^^^^ @@ -99,7 +100,7 @@ LL | b_i64 %= a_i64; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:34:5 + --> $DIR/modulo_arithmetic_integral.rs:56:5 | LL | a_i128 % b_i128; | ^^^^^^^^^^^^^^^ @@ -108,7 +109,7 @@ LL | a_i128 % b_i128; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:35:5 + --> $DIR/modulo_arithmetic_integral.rs:59:5 | LL | b_i128 %= a_i128; | ^^^^^^^^^^^^^^^^ @@ -117,7 +118,7 @@ LL | b_i128 %= a_i128; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:39:5 + --> $DIR/modulo_arithmetic_integral.rs:65:5 | LL | a_isize % b_isize; | ^^^^^^^^^^^^^^^^^ @@ -126,7 +127,7 @@ LL | a_isize % b_isize; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:40:5 + --> $DIR/modulo_arithmetic_integral.rs:68:5 | LL | b_isize %= a_isize; | ^^^^^^^^^^^^^^^^^^ @@ -135,7 +136,7 @@ LL | b_isize %= a_isize; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:44:5 + --> $DIR/modulo_arithmetic_integral.rs:74:5 | LL | a % b; | ^^^^^ @@ -144,7 +145,7 @@ LL | a % b; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on types that might have different signs - --> $DIR/modulo_arithmetic_integral.rs:45:5 + --> $DIR/modulo_arithmetic_integral.rs:77:5 | LL | b %= a; | ^^^^^^ diff --git a/src/tools/clippy/tests/ui/modulo_arithmetic_integral_const.rs b/src/tools/clippy/tests/ui/modulo_arithmetic_integral_const.rs index 3ebe46bc5..dbc679a69 100644 --- a/src/tools/clippy/tests/ui/modulo_arithmetic_integral_const.rs +++ b/src/tools/clippy/tests/ui/modulo_arithmetic_integral_const.rs @@ -9,23 +9,57 @@ fn main() { // Lint when both sides are const and of the opposite sign -1 % 2; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1 % -2; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ (1 - 2) % (1 + 2); + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 3` + //~| NOTE: double check for expected result especially when interoperating with differ (1 + 2) % (1 - 2); + //~^ ERROR: you are using modulo operator on constants with different signs: `3 % -1` + //~| NOTE: double check for expected result especially when interoperating with differ 35 * (7 - 4 * 2) % (-500 * -600); + //~^ ERROR: you are using modulo operator on constants with different signs: `-35 % 30 + //~| NOTE: double check for expected result especially when interoperating with differ -1i8 % 2i8; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i8 % -2i8; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1i16 % 2i16; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i16 % -2i16; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1i32 % 2i32; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i32 % -2i32; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1i64 % 2i64; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i64 % -2i64; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1i128 % 2i128; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1i128 % -2i128; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ -1isize % 2isize; + //~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2` + //~| NOTE: double check for expected result especially when interoperating with differ 1isize % -2isize; + //~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2` + //~| NOTE: double check for expected result especially when interoperating with differ // No lint when both sides are const and of the same sign 1 % 2; diff --git a/src/tools/clippy/tests/ui/modulo_arithmetic_integral_const.stderr b/src/tools/clippy/tests/ui/modulo_arithmetic_integral_const.stderr index 1453d44f4..47ed2261a 100644 --- a/src/tools/clippy/tests/ui/modulo_arithmetic_integral_const.stderr +++ b/src/tools/clippy/tests/ui/modulo_arithmetic_integral_const.stderr @@ -7,9 +7,10 @@ LL | -1 % 2; = note: double check for expected result especially when interoperating with different languages = note: or consider using `rem_euclid` or similar function = note: `-D clippy::modulo-arithmetic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:12:5 + --> $DIR/modulo_arithmetic_integral_const.rs:14:5 | LL | 1 % -2; | ^^^^^^ @@ -18,7 +19,7 @@ LL | 1 % -2; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 3` - --> $DIR/modulo_arithmetic_integral_const.rs:13:5 + --> $DIR/modulo_arithmetic_integral_const.rs:17:5 | LL | (1 - 2) % (1 + 2); | ^^^^^^^^^^^^^^^^^ @@ -27,7 +28,7 @@ LL | (1 - 2) % (1 + 2); = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `3 % -1` - --> $DIR/modulo_arithmetic_integral_const.rs:14:5 + --> $DIR/modulo_arithmetic_integral_const.rs:20:5 | LL | (1 + 2) % (1 - 2); | ^^^^^^^^^^^^^^^^^ @@ -36,7 +37,7 @@ LL | (1 + 2) % (1 - 2); = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-35 % 300000` - --> $DIR/modulo_arithmetic_integral_const.rs:15:5 + --> $DIR/modulo_arithmetic_integral_const.rs:23:5 | LL | 35 * (7 - 4 * 2) % (-500 * -600); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +46,7 @@ LL | 35 * (7 - 4 * 2) % (-500 * -600); = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:17:5 + --> $DIR/modulo_arithmetic_integral_const.rs:27:5 | LL | -1i8 % 2i8; | ^^^^^^^^^^ @@ -54,7 +55,7 @@ LL | -1i8 % 2i8; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:18:5 + --> $DIR/modulo_arithmetic_integral_const.rs:30:5 | LL | 1i8 % -2i8; | ^^^^^^^^^^ @@ -63,7 +64,7 @@ LL | 1i8 % -2i8; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:19:5 + --> $DIR/modulo_arithmetic_integral_const.rs:33:5 | LL | -1i16 % 2i16; | ^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL | -1i16 % 2i16; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:20:5 + --> $DIR/modulo_arithmetic_integral_const.rs:36:5 | LL | 1i16 % -2i16; | ^^^^^^^^^^^^ @@ -81,7 +82,7 @@ LL | 1i16 % -2i16; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:21:5 + --> $DIR/modulo_arithmetic_integral_const.rs:39:5 | LL | -1i32 % 2i32; | ^^^^^^^^^^^^ @@ -90,7 +91,7 @@ LL | -1i32 % 2i32; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:22:5 + --> $DIR/modulo_arithmetic_integral_const.rs:42:5 | LL | 1i32 % -2i32; | ^^^^^^^^^^^^ @@ -99,7 +100,7 @@ LL | 1i32 % -2i32; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:23:5 + --> $DIR/modulo_arithmetic_integral_const.rs:45:5 | LL | -1i64 % 2i64; | ^^^^^^^^^^^^ @@ -108,7 +109,7 @@ LL | -1i64 % 2i64; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:24:5 + --> $DIR/modulo_arithmetic_integral_const.rs:48:5 | LL | 1i64 % -2i64; | ^^^^^^^^^^^^ @@ -117,7 +118,7 @@ LL | 1i64 % -2i64; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:25:5 + --> $DIR/modulo_arithmetic_integral_const.rs:51:5 | LL | -1i128 % 2i128; | ^^^^^^^^^^^^^^ @@ -126,7 +127,7 @@ LL | -1i128 % 2i128; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:26:5 + --> $DIR/modulo_arithmetic_integral_const.rs:54:5 | LL | 1i128 % -2i128; | ^^^^^^^^^^^^^^ @@ -135,7 +136,7 @@ LL | 1i128 % -2i128; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `-1 % 2` - --> $DIR/modulo_arithmetic_integral_const.rs:27:5 + --> $DIR/modulo_arithmetic_integral_const.rs:57:5 | LL | -1isize % 2isize; | ^^^^^^^^^^^^^^^^ @@ -144,7 +145,7 @@ LL | -1isize % 2isize; = note: or consider using `rem_euclid` or similar function error: you are using modulo operator on constants with different signs: `1 % -2` - --> $DIR/modulo_arithmetic_integral_const.rs:28:5 + --> $DIR/modulo_arithmetic_integral_const.rs:60:5 | LL | 1isize % -2isize; | ^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/modulo_one.rs b/src/tools/clippy/tests/ui/modulo_one.rs index adff08e5d..c1dbe9d9a 100644 --- a/src/tools/clippy/tests/ui/modulo_one.rs +++ b/src/tools/clippy/tests/ui/modulo_one.rs @@ -6,18 +6,34 @@ static STATIC_NEG_ONE: i64 = 1 - 2; fn main() { 10 % 1; + //~^ ERROR: any number modulo 1 will be 0 + //~| NOTE: `-D clippy::modulo-one` implied by `-D warnings` 10 % -1; + //~^ ERROR: any number modulo -1 will panic/overflow or result in 0 10 % 2; - i32::MIN % (-1); // also caught by rustc + // also caught by rustc + i32::MIN % (-1); + //~^ ERROR: this operation will panic at runtime + //~| NOTE: `#[deny(unconditional_panic)]` on by default + //~| ERROR: any number modulo -1 will panic/overflow or result in 0 const ONE: u32 = 1 * 1; const NEG_ONE: i64 = 1 - 2; const INT_MIN: i64 = i64::MIN; 2 % ONE; - 5 % STATIC_ONE; // NOT caught by lint + //~^ ERROR: any number modulo 1 will be 0 + // NOT caught by lint + 5 % STATIC_ONE; 2 % NEG_ONE; - 5 % STATIC_NEG_ONE; // NOT caught by lint - INT_MIN % NEG_ONE; // also caught by rustc - INT_MIN % STATIC_NEG_ONE; // ONLY caught by rustc + //~^ ERROR: any number modulo -1 will panic/overflow or result in 0 + // NOT caught by lint + 5 % STATIC_NEG_ONE; + // also caught by rustc + INT_MIN % NEG_ONE; + //~^ ERROR: this operation will panic at runtime + //~| ERROR: any number modulo -1 will panic/overflow or result in 0 + // ONLY caught by rustc + INT_MIN % STATIC_NEG_ONE; + //~^ ERROR: this operation will panic at runtime } diff --git a/src/tools/clippy/tests/ui/modulo_one.stderr b/src/tools/clippy/tests/ui/modulo_one.stderr index 83a76f81d..cc211ab6c 100644 --- a/src/tools/clippy/tests/ui/modulo_one.stderr +++ b/src/tools/clippy/tests/ui/modulo_one.stderr @@ -1,21 +1,21 @@ error: this operation will panic at runtime - --> $DIR/modulo_one.rs:11:5 + --> $DIR/modulo_one.rs:15:5 | -LL | i32::MIN % (-1); // also caught by rustc +LL | i32::MIN % (-1); | ^^^^^^^^^^^^^^^ attempt to compute `i32::MIN % -1_i32`, which would overflow | = note: `#[deny(unconditional_panic)]` on by default error: this operation will panic at runtime - --> $DIR/modulo_one.rs:21:5 + --> $DIR/modulo_one.rs:33:5 | -LL | INT_MIN % NEG_ONE; // also caught by rustc +LL | INT_MIN % NEG_ONE; | ^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow error: this operation will panic at runtime - --> $DIR/modulo_one.rs:22:5 + --> $DIR/modulo_one.rs:37:5 | -LL | INT_MIN % STATIC_NEG_ONE; // ONLY caught by rustc +LL | INT_MIN % STATIC_NEG_ONE; | ^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow error: any number modulo 1 will be 0 @@ -25,35 +25,36 @@ LL | 10 % 1; | ^^^^^^ | = note: `-D clippy::modulo-one` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::modulo_one)]` error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:9:5 + --> $DIR/modulo_one.rs:11:5 | LL | 10 % -1; | ^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:11:5 + --> $DIR/modulo_one.rs:15:5 | -LL | i32::MIN % (-1); // also caught by rustc +LL | i32::MIN % (-1); | ^^^^^^^^^^^^^^^ error: any number modulo 1 will be 0 - --> $DIR/modulo_one.rs:17:5 + --> $DIR/modulo_one.rs:24:5 | LL | 2 % ONE; | ^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:19:5 + --> $DIR/modulo_one.rs:28:5 | LL | 2 % NEG_ONE; | ^^^^^^^^^^^ error: any number modulo -1 will panic/overflow or result in 0 - --> $DIR/modulo_one.rs:21:5 + --> $DIR/modulo_one.rs:33:5 | -LL | INT_MIN % NEG_ONE; // also caught by rustc +LL | INT_MIN % NEG_ONE; | ^^^^^^^^^^^^^^^^^ error: aborting due to 9 previous errors diff --git a/src/tools/clippy/tests/ui/multi_assignments.rs b/src/tools/clippy/tests/ui/multi_assignments.rs index b186bf8bb..cdbf13b68 100644 --- a/src/tools/clippy/tests/ui/multi_assignments.rs +++ b/src/tools/clippy/tests/ui/multi_assignments.rs @@ -2,8 +2,15 @@ fn main() { let (mut a, mut b, mut c, mut d) = ((), (), (), ()); a = b = c; + //~^ ERROR: assignments don't nest intuitively + //~| NOTE: `-D clippy::multi-assignments` implied by `-D warnings` a = b = c = d; + //~^ ERROR: assignments don't nest intuitively + //~| ERROR: assignments don't nest intuitively a = b = { c }; + //~^ ERROR: assignments don't nest intuitively a = { b = c }; + //~^ ERROR: assignments don't nest intuitively a = (b = c); + //~^ ERROR: assignments don't nest intuitively } diff --git a/src/tools/clippy/tests/ui/multi_assignments.stderr b/src/tools/clippy/tests/ui/multi_assignments.stderr index d6c42bb69..9719b5e66 100644 --- a/src/tools/clippy/tests/ui/multi_assignments.stderr +++ b/src/tools/clippy/tests/ui/multi_assignments.stderr @@ -5,33 +5,34 @@ LL | a = b = c; | ^^^^^^^^^ | = note: `-D clippy::multi-assignments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::multi_assignments)]` error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:5:5 + --> $DIR/multi_assignments.rs:7:5 | LL | a = b = c = d; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:5:9 + --> $DIR/multi_assignments.rs:7:9 | LL | a = b = c = d; | ^^^^^^^^^ error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:6:5 + --> $DIR/multi_assignments.rs:10:5 | LL | a = b = { c }; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:7:5 + --> $DIR/multi_assignments.rs:12:5 | LL | a = { b = c }; | ^^^^^^^^^^^^^ error: assignments don't nest intuitively - --> $DIR/multi_assignments.rs:8:5 + --> $DIR/multi_assignments.rs:14:5 | LL | a = (b = c); | ^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs b/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs index 23ad36bb4..4ef6f0ca9 100644 --- a/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs +++ b/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused)] #![allow(deref_nullptr)] #![allow(clippy::unnecessary_operation)] diff --git a/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.stderr b/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.stderr index badc284ec..4803a5089 100644 --- a/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.stderr +++ b/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.stderr @@ -18,6 +18,7 @@ note: unsafe function call occurs here LL | not_very_safe(); | ^^^^^^^^^^^^^^^ = note: `-D clippy::multiple-unsafe-ops-per-block` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/must_use_candidates.fixed b/src/tools/clippy/tests/ui/must_use_candidates.fixed index 3ca20c07d..3ed705b29 100644 --- a/src/tools/clippy/tests/ui/must_use_candidates.fixed +++ b/src/tools/clippy/tests/ui/must_use_candidates.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(never_type)] #![allow( unused_mut, diff --git a/src/tools/clippy/tests/ui/must_use_candidates.rs b/src/tools/clippy/tests/ui/must_use_candidates.rs index dc4e0118e..ab8efea0a 100644 --- a/src/tools/clippy/tests/ui/must_use_candidates.rs +++ b/src/tools/clippy/tests/ui/must_use_candidates.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(never_type)] #![allow( unused_mut, diff --git a/src/tools/clippy/tests/ui/must_use_candidates.stderr b/src/tools/clippy/tests/ui/must_use_candidates.stderr index 5fb302ccb..581399f3e 100644 --- a/src/tools/clippy/tests/ui/must_use_candidates.stderr +++ b/src/tools/clippy/tests/ui/must_use_candidates.stderr @@ -1,31 +1,32 @@ error: this function could have a `#[must_use]` attribute - --> $DIR/must_use_candidates.rs:17:1 + --> $DIR/must_use_candidates.rs:16:1 | LL | pub fn pure(i: u8) -> u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn pure(i: u8) -> u8` | = note: `-D clippy::must-use-candidate` implied by `-D warnings` + = 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:22:5 + --> $DIR/must_use_candidates.rs:21: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:53:1 + --> $DIR/must_use_candidates.rs:52: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:65:1 + --> $DIR/must_use_candidates.rs:64: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:73: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/src/tools/clippy/tests/ui/must_use_unit.fixed b/src/tools/clippy/tests/ui/must_use_unit.fixed index c460fd7c6..75f91e668 100644 --- a/src/tools/clippy/tests/ui/must_use_unit.fixed +++ b/src/tools/clippy/tests/ui/must_use_unit.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::must_use_unit)] #![allow(clippy::unused_unit)] diff --git a/src/tools/clippy/tests/ui/must_use_unit.rs b/src/tools/clippy/tests/ui/must_use_unit.rs index fe95624f7..1305910ed 100644 --- a/src/tools/clippy/tests/ui/must_use_unit.rs +++ b/src/tools/clippy/tests/ui/must_use_unit.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::must_use_unit)] #![allow(clippy::unused_unit)] diff --git a/src/tools/clippy/tests/ui/must_use_unit.stderr b/src/tools/clippy/tests/ui/must_use_unit.stderr index 15e0906b6..e67d9b5b9 100644 --- a/src/tools/clippy/tests/ui/must_use_unit.stderr +++ b/src/tools/clippy/tests/ui/must_use_unit.stderr @@ -1,5 +1,5 @@ error: this unit-returning function has a `#[must_use]` attribute - --> $DIR/must_use_unit.rs:11:1 + --> $DIR/must_use_unit.rs:10:1 | LL | #[must_use] | ----------- help: remove the attribute @@ -7,9 +7,10 @@ LL | pub fn must_use_default() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::must-use-unit` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::must_use_unit)]` error: this unit-returning function has a `#[must_use]` attribute - --> $DIR/must_use_unit.rs:14:1 + --> $DIR/must_use_unit.rs:13:1 | LL | #[must_use] | ----------- help: remove the attribute @@ -17,7 +18,7 @@ LL | pub fn must_use_unit() -> () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this unit-returning function has a `#[must_use]` attribute - --> $DIR/must_use_unit.rs:17:1 + --> $DIR/must_use_unit.rs:16:1 | LL | #[must_use = "With note"] | ------------------------- help: remove the attribute diff --git a/src/tools/clippy/tests/ui/mut_from_ref.rs b/src/tools/clippy/tests/ui/mut_from_ref.rs index 8c0c23b65..0ab6d77de 100644 --- a/src/tools/clippy/tests/ui/mut_from_ref.rs +++ b/src/tools/clippy/tests/ui/mut_from_ref.rs @@ -5,12 +5,14 @@ struct Foo; impl Foo { fn this_wont_hurt_a_bit(&self) -> &mut Foo { + //~^ ERROR: mutable borrow from immutable input(s) unsafe { unimplemented!() } } } trait Ouch { fn ouch(x: &Foo) -> &mut Foo; + //~^ ERROR: mutable borrow from immutable input(s) } impl Ouch for Foo { @@ -20,14 +22,17 @@ impl Ouch for Foo { } fn fail(x: &u32) -> &mut u16 { + //~^ ERROR: mutable borrow from immutable input(s) unsafe { unimplemented!() } } fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { + //~^ ERROR: mutable borrow from immutable input(s) unsafe { unimplemented!() } } fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { + //~^ ERROR: mutable borrow from immutable input(s) unsafe { unimplemented!() } } @@ -42,6 +47,7 @@ fn also_works<'a>(x: &'a u32, y: &'a mut u32) -> &'a mut u32 { } unsafe fn also_broken(x: &u32) -> &mut u32 { + //~^ ERROR: mutable borrow from immutable input(s) unimplemented!() } diff --git a/src/tools/clippy/tests/ui/mut_from_ref.stderr b/src/tools/clippy/tests/ui/mut_from_ref.stderr index c20ff54bf..38f47b9ad 100644 --- a/src/tools/clippy/tests/ui/mut_from_ref.stderr +++ b/src/tools/clippy/tests/ui/mut_from_ref.stderr @@ -10,63 +10,64 @@ note: immutable borrow here LL | fn this_wont_hurt_a_bit(&self) -> &mut Foo { | ^^^^^ = note: `-D clippy::mut-from-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mut_from_ref)]` error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:13:25 + --> $DIR/mut_from_ref.rs:14:25 | LL | fn ouch(x: &Foo) -> &mut Foo; | ^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:13:16 + --> $DIR/mut_from_ref.rs:14:16 | LL | fn ouch(x: &Foo) -> &mut Foo; | ^^^^ error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:22:21 + --> $DIR/mut_from_ref.rs:24:21 | LL | fn fail(x: &u32) -> &mut u16 { | ^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:22:12 + --> $DIR/mut_from_ref.rs:24:12 | LL | fn fail(x: &u32) -> &mut u16 { | ^^^^ error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:26:50 + --> $DIR/mut_from_ref.rs:29:50 | LL | fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { | ^^^^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:26:25 + --> $DIR/mut_from_ref.rs:29:25 | LL | fn fail_lifetime<'a>(x: &'a u32, y: &mut u32) -> &'a mut u32 { | ^^^^^^^ error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:30:67 + --> $DIR/mut_from_ref.rs:34:67 | LL | fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { | ^^^^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:30:27 + --> $DIR/mut_from_ref.rs:34:27 | LL | fn fail_double<'a, 'b>(x: &'a u32, y: &'a u32, z: &'b mut u32) -> &'a mut u32 { | ^^^^^^^ ^^^^^^^ error: mutable borrow from immutable input(s) - --> $DIR/mut_from_ref.rs:44:35 + --> $DIR/mut_from_ref.rs:49:35 | LL | unsafe fn also_broken(x: &u32) -> &mut u32 { | ^^^^^^^^ | note: immutable borrow here - --> $DIR/mut_from_ref.rs:44:26 + --> $DIR/mut_from_ref.rs:49:26 | LL | unsafe fn also_broken(x: &u32) -> &mut u32 { | ^^^^ diff --git a/src/tools/clippy/tests/ui/mut_key.rs b/src/tools/clippy/tests/ui/mut_key.rs index 15d68c089..2d70bfd4c 100644 --- a/src/tools/clippy/tests/ui/mut_key.rs +++ b/src/tools/clippy/tests/ui/mut_key.rs @@ -5,7 +5,7 @@ use std::rc::Rc; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::Relaxed; use std::sync::Arc; - +//@no-rustfix struct Key(AtomicUsize); impl Clone for Key { @@ -29,7 +29,11 @@ impl Hash for Key { } fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> HashSet { + //~^ ERROR: mutable key type + //~| NOTE: `-D clippy::mutable-key-type` implied by `-D warnings` + //~| ERROR: mutable key type let _other: HashMap = HashMap::new(); + //~^ ERROR: mutable key type m.keys().cloned().collect() } @@ -57,6 +61,7 @@ fn generics_are_ok_too(_m: &mut HashSet) { fn tuples(_m: &mut HashMap<((), U), ()>) {} fn tuples_bad(_m: &mut HashMap<(Key, U), bool>) {} +//~^ ERROR: mutable key type fn main() { let _ = should_not_take_this_arg(&mut HashMap::new(), 1); @@ -69,18 +74,31 @@ fn main() { raw_mut_ptr_is_ok(&mut HashMap::new()); let _map = HashMap::, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::<&mut Cell, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::<&mut usize, usize>::new(); + //~^ ERROR: mutable key type // Collection types from `std` who's impl of `Hash` or `Ord` delegate their type parameters let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::, ()>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::, usize>::new(); + //~^ ERROR: mutable key type // Smart pointers from `std` who's impl of `Hash` or `Ord` delegate their type parameters let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type let _map = HashMap::>, usize>::new(); + //~^ ERROR: mutable key type } diff --git a/src/tools/clippy/tests/ui/mut_key.stderr b/src/tools/clippy/tests/ui/mut_key.stderr index 95b9546bf..48eeaff78 100644 --- a/src/tools/clippy/tests/ui/mut_key.stderr +++ b/src/tools/clippy/tests/ui/mut_key.stderr @@ -5,6 +5,7 @@ LL | fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> Hash | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::mutable-key-type` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mutable_key_type)]` error: mutable key type --> $DIR/mut_key.rs:31:72 @@ -13,91 +14,91 @@ LL | fn should_not_take_this_arg(m: &mut HashMap, _n: usize) -> Hash | ^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:32:5 + --> $DIR/mut_key.rs:35:5 | LL | let _other: HashMap = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:59:22 + --> $DIR/mut_key.rs:63:22 | LL | fn tuples_bad(_m: &mut HashMap<(Key, U), bool>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:71:5 + --> $DIR/mut_key.rs:76:5 | LL | let _map = HashMap::, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:72:5 + --> $DIR/mut_key.rs:78:5 | LL | let _map = HashMap::<&mut Cell, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:73:5 + --> $DIR/mut_key.rs:80:5 | LL | let _map = HashMap::<&mut usize, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:75:5 + --> $DIR/mut_key.rs:83:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:76:5 + --> $DIR/mut_key.rs:85:5 | LL | let _map = HashMap::, ()>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:77:5 + --> $DIR/mut_key.rs:87:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:78:5 + --> $DIR/mut_key.rs:89:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:79:5 + --> $DIR/mut_key.rs:91:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:80:5 + --> $DIR/mut_key.rs:93:5 | LL | let _map = HashMap::>>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:81:5 + --> $DIR/mut_key.rs:95:5 | LL | let _map = HashMap::, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:83:5 + --> $DIR/mut_key.rs:98:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:84:5 + --> $DIR/mut_key.rs:100:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: mutable key type - --> $DIR/mut_key.rs:85:5 + --> $DIR/mut_key.rs:102:5 | LL | let _map = HashMap::>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/mut_mut.rs b/src/tools/clippy/tests/ui/mut_mut.rs index fe7d53e8e..72a171119 100644 --- a/src/tools/clippy/tests/ui/mut_mut.rs +++ b/src/tools/clippy/tests/ui/mut_mut.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::mut_mut)] #![allow(unused)] #![allow( diff --git a/src/tools/clippy/tests/ui/mut_mut.stderr b/src/tools/clippy/tests/ui/mut_mut.stderr index 58a1c4e68..5ed9cd1af 100644 --- a/src/tools/clippy/tests/ui/mut_mut.stderr +++ b/src/tools/clippy/tests/ui/mut_mut.stderr @@ -5,6 +5,7 @@ LL | fn fun(x: &mut &mut u32) -> bool { | ^^^^^^^^^^^^^ | = note: `-D clippy::mut-mut` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/mut_mutex_lock.fixed b/src/tools/clippy/tests/ui/mut_mutex_lock.fixed index 433817a4e..bbedbb2be 100644 --- a/src/tools/clippy/tests/ui/mut_mutex_lock.fixed +++ b/src/tools/clippy/tests/ui/mut_mutex_lock.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, unused_mut)] #![warn(clippy::mut_mutex_lock)] diff --git a/src/tools/clippy/tests/ui/mut_mutex_lock.rs b/src/tools/clippy/tests/ui/mut_mutex_lock.rs index 567a0b59e..74116100e 100644 --- a/src/tools/clippy/tests/ui/mut_mutex_lock.rs +++ b/src/tools/clippy/tests/ui/mut_mutex_lock.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, unused_mut)] #![warn(clippy::mut_mutex_lock)] diff --git a/src/tools/clippy/tests/ui/mut_mutex_lock.stderr b/src/tools/clippy/tests/ui/mut_mutex_lock.stderr index 21c1b3486..9b20016be 100644 --- a/src/tools/clippy/tests/ui/mut_mutex_lock.stderr +++ b/src/tools/clippy/tests/ui/mut_mutex_lock.stderr @@ -1,10 +1,11 @@ error: calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference - --> $DIR/mut_mutex_lock.rs:11:33 + --> $DIR/mut_mutex_lock.rs:10:33 | LL | let mut value = value_mutex.lock().unwrap(); | ^^^^ help: change this to: `get_mut` | = note: `-D clippy::mut-mutex-lock` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mut_mutex_lock)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/mut_range_bound.rs b/src/tools/clippy/tests/ui/mut_range_bound.rs index 7fdeb27ed..7aebbf498 100644 --- a/src/tools/clippy/tests/ui/mut_range_bound.rs +++ b/src/tools/clippy/tests/ui/mut_range_bound.rs @@ -6,14 +6,18 @@ fn mut_range_bound_upper() { let mut m = 4; for i in 0..m { m = 5; - } // warning + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged + } } fn mut_range_bound_lower() { let mut m = 4; for i in m..10 { m *= 2; - } // warning + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged + } } fn mut_range_bound_both() { @@ -21,8 +25,12 @@ fn mut_range_bound_both() { let mut n = 6; for i in m..n { m = 5; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged n = 7; - } // warning (1 for each mutated bound) + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged + } } fn mut_range_bound_no_mutation() { @@ -35,7 +43,9 @@ fn mut_range_bound_no_mutation() { fn mut_borrow_range_bound() { let mut m = 4; for i in 0..m { - let n = &mut m; // warning + let n = &mut m; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged *n += 1; } } @@ -43,7 +53,7 @@ fn mut_borrow_range_bound() { fn immut_borrow_range_bound() { let mut m = 4; for i in 0..m { - let n = &m; // should be no warning? + let n = &m; } } @@ -67,7 +77,10 @@ fn mut_range_bound_break() { fn mut_range_bound_no_immediate_break() { let mut m = 4; for i in 0..m { - m = 2; // warning because it is not immediately followed by break + // warning because it is not immediately followed by break + m = 2; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged if m == 4 { break; } @@ -76,7 +89,10 @@ fn mut_range_bound_no_immediate_break() { let mut n = 3; for i in n..10 { if n == 4 { - n = 1; // FIXME: warning because it is not immediately followed by break + // FIXME: warning because it is not immediately followed by break + n = 1; + //~^ ERROR: attempt to mutate range bound within loop + //~| NOTE: the range of the loop is unchanged let _ = 2; break; } diff --git a/src/tools/clippy/tests/ui/mut_range_bound.stderr b/src/tools/clippy/tests/ui/mut_range_bound.stderr index b679b7a0a..42f8a161f 100644 --- a/src/tools/clippy/tests/ui/mut_range_bound.stderr +++ b/src/tools/clippy/tests/ui/mut_range_bound.stderr @@ -6,9 +6,10 @@ LL | m = 5; | = note: the range of the loop is unchanged = note: `-D clippy::mut-range-bound` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mut_range_bound)]` error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:15:9 + --> $DIR/mut_range_bound.rs:17:9 | LL | m *= 2; | ^ @@ -16,7 +17,7 @@ LL | m *= 2; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:23:9 + --> $DIR/mut_range_bound.rs:27:9 | LL | m = 5; | ^ @@ -24,7 +25,7 @@ LL | m = 5; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:24:9 + --> $DIR/mut_range_bound.rs:30:9 | LL | n = 7; | ^ @@ -32,25 +33,25 @@ LL | n = 7; = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:38:22 + --> $DIR/mut_range_bound.rs:46:22 | -LL | let n = &mut m; // warning +LL | let n = &mut m; | ^ | = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:70:9 + --> $DIR/mut_range_bound.rs:81:9 | -LL | m = 2; // warning because it is not immediately followed by break +LL | m = 2; | ^ | = note: the range of the loop is unchanged error: attempt to mutate range bound within loop - --> $DIR/mut_range_bound.rs:79:13 + --> $DIR/mut_range_bound.rs:93:13 | -LL | n = 1; // FIXME: warning because it is not immediately followed by break +LL | n = 1; | ^ | = note: the range of the loop is unchanged diff --git a/src/tools/clippy/tests/ui/mut_reference.rs b/src/tools/clippy/tests/ui/mut_reference.rs index 00661c51a..1d7faaa5e 100644 --- a/src/tools/clippy/tests/ui/mut_reference.rs +++ b/src/tools/clippy/tests/ui/mut_reference.rs @@ -1,5 +1,5 @@ #![allow(unused_variables, dead_code)] - +//@no-rustfix fn takes_an_immutable_reference(a: &i32) {} fn takes_a_mutable_reference(a: &mut i32) {} @@ -28,12 +28,16 @@ impl MyStruct { fn main() { // Functions takes_an_immutable_reference(&mut 42); + //~^ ERROR: the function `takes_an_immutable_reference` doesn't need a mutable referen + //~| NOTE: `-D clippy::unnecessary-mut-passed` implied by `-D warnings` let as_ptr: fn(&i32) = takes_an_immutable_reference; as_ptr(&mut 42); + //~^ ERROR: the function `as_ptr` doesn't need a mutable reference // Methods let my_struct = MyStruct; my_struct.takes_an_immutable_reference(&mut 42); + //~^ ERROR: the method `takes_an_immutable_reference` doesn't need a mutable reference // No error diff --git a/src/tools/clippy/tests/ui/mut_reference.stderr b/src/tools/clippy/tests/ui/mut_reference.stderr index 4ce1cfa4f..87db08e2a 100644 --- a/src/tools/clippy/tests/ui/mut_reference.stderr +++ b/src/tools/clippy/tests/ui/mut_reference.stderr @@ -5,15 +5,16 @@ LL | takes_an_immutable_reference(&mut 42); | ^^^^^^^ | = note: `-D clippy::unnecessary-mut-passed` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_mut_passed)]` error: the function `as_ptr` doesn't need a mutable reference - --> $DIR/mut_reference.rs:32:12 + --> $DIR/mut_reference.rs:34:12 | LL | as_ptr(&mut 42); | ^^^^^^^ error: the method `takes_an_immutable_reference` doesn't need a mutable reference - --> $DIR/mut_reference.rs:36:44 + --> $DIR/mut_reference.rs:39:44 | LL | my_struct.takes_an_immutable_reference(&mut 42); | ^^^^^^^ diff --git a/src/tools/clippy/tests/ui/mutex_atomic.rs b/src/tools/clippy/tests/ui/mutex_atomic.rs index 47b3dad39..198b95d8c 100644 --- a/src/tools/clippy/tests/ui/mutex_atomic.rs +++ b/src/tools/clippy/tests/ui/mutex_atomic.rs @@ -6,12 +6,21 @@ fn main() { use std::sync::Mutex; Mutex::new(true); + //~^ ERROR: consider using an `AtomicBool` instead of a `Mutex` here; if you just want + //~| NOTE: `-D clippy::mutex-atomic` implied by `-D warnings` Mutex::new(5usize); + //~^ ERROR: consider using an `AtomicUsize` instead of a `Mutex` here; if you just wan Mutex::new(9isize); + //~^ ERROR: consider using an `AtomicIsize` instead of a `Mutex` here; if you just wan let mut x = 4u32; Mutex::new(&x as *const u32); + //~^ ERROR: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want Mutex::new(&mut x as *mut u32); + //~^ ERROR: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want Mutex::new(0u32); + //~^ ERROR: consider using an `AtomicUsize` instead of a `Mutex` here; if you just wan + //~| NOTE: `-D clippy::mutex-integer` implied by `-D warnings` Mutex::new(0i32); + //~^ ERROR: consider using an `AtomicIsize` instead of a `Mutex` here; if you just wan Mutex::new(0f32); // there are no float atomics, so this should not lint } diff --git a/src/tools/clippy/tests/ui/mutex_atomic.stderr b/src/tools/clippy/tests/ui/mutex_atomic.stderr index 262028a87..483e1ce15 100644 --- a/src/tools/clippy/tests/ui/mutex_atomic.stderr +++ b/src/tools/clippy/tests/ui/mutex_atomic.stderr @@ -5,41 +5,43 @@ LL | Mutex::new(true); | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::mutex-atomic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mutex_atomic)]` error: consider using an `AtomicUsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:9:5 + --> $DIR/mutex_atomic.rs:11:5 | LL | Mutex::new(5usize); | ^^^^^^^^^^^^^^^^^^ error: consider using an `AtomicIsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:10:5 + --> $DIR/mutex_atomic.rs:13:5 | LL | Mutex::new(9isize); | ^^^^^^^^^^^^^^^^^^ error: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:12:5 + --> $DIR/mutex_atomic.rs:16:5 | LL | Mutex::new(&x as *const u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider using an `AtomicPtr` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:13:5 + --> $DIR/mutex_atomic.rs:18:5 | LL | Mutex::new(&mut x as *mut u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider using an `AtomicUsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:14:5 + --> $DIR/mutex_atomic.rs:20:5 | LL | Mutex::new(0u32); | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::mutex-integer` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mutex_integer)]` error: consider using an `AtomicIsize` instead of a `Mutex` here; if you just want the locking behavior and not the internal type, consider using `Mutex<()>` - --> $DIR/mutex_atomic.rs:15:5 + --> $DIR/mutex_atomic.rs:23:5 | LL | Mutex::new(0i32); | ^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/needless_arbitrary_self_type.fixed b/src/tools/clippy/tests/ui/needless_arbitrary_self_type.fixed index d7eb1a047..9da60c687 100644 --- a/src/tools/clippy/tests/ui/needless_arbitrary_self_type.fixed +++ b/src/tools/clippy/tests/ui/needless_arbitrary_self_type.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_arbitrary_self_type)] #![allow(unused_mut, clippy::needless_lifetimes)] diff --git a/src/tools/clippy/tests/ui/needless_arbitrary_self_type.rs b/src/tools/clippy/tests/ui/needless_arbitrary_self_type.rs index 85a2a957f..fc4ec5cb0 100644 --- a/src/tools/clippy/tests/ui/needless_arbitrary_self_type.rs +++ b/src/tools/clippy/tests/ui/needless_arbitrary_self_type.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_arbitrary_self_type)] #![allow(unused_mut, clippy::needless_lifetimes)] diff --git a/src/tools/clippy/tests/ui/needless_arbitrary_self_type.stderr b/src/tools/clippy/tests/ui/needless_arbitrary_self_type.stderr index f4c645d35..fe2ac34f7 100644 --- a/src/tools/clippy/tests/ui/needless_arbitrary_self_type.stderr +++ b/src/tools/clippy/tests/ui/needless_arbitrary_self_type.stderr @@ -1,37 +1,38 @@ error: the type of the `self` parameter does not need to be arbitrary - --> $DIR/needless_arbitrary_self_type.rs:12:16 + --> $DIR/needless_arbitrary_self_type.rs:10:16 | LL | pub fn bad(self: Self) { | ^^^^^^^^^^ help: consider to change this parameter to: `self` | = note: `-D clippy::needless-arbitrary-self-type` implied by `-D warnings` + = 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:20:20 + --> $DIR/needless_arbitrary_self_type.rs:18: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:28:20 + --> $DIR/needless_arbitrary_self_type.rs:26: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:36:38 + --> $DIR/needless_arbitrary_self_type.rs:34: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:44:24 + --> $DIR/needless_arbitrary_self_type.rs:42: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:52:42 + --> $DIR/needless_arbitrary_self_type.rs:50: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/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.fixed b/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.fixed new file mode 100644 index 000000000..62a6e5932 --- /dev/null +++ b/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.fixed @@ -0,0 +1,46 @@ +//@aux-build:proc_macro_attr.rs + +#![warn(clippy::needless_arbitrary_self_type)] + +#[macro_use] +extern crate proc_macro_attr; + +mod issue_6089 { + // Check that we don't lint if the `self` parameter comes from expansion + + macro_rules! test_from_expansion { + () => { + trait T1 { + fn test(self: &Self); + } + + struct S1; + + impl T1 for S1 { + fn test(self: &Self) {} + } + }; + } + + test_from_expansion!(); + + // If only the lifetime name comes from expansion we will lint, but the suggestion will have + // placeholders and will not be applied automatically, as we can't reliably know the original name. + // This specific case happened with async_trait. + + trait T2 { + fn call_with_mut_self(&mut self); + } + + struct S2; + + // The method's signature will be expanded to: + // fn call_with_mut_self<'life0>(self: &'life0 mut Self) {} + #[rename_my_lifetimes] + impl T2 for S2 { + #[allow(clippy::needless_lifetimes)] + fn call_with_mut_self(&mut self) {} + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.rs b/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.rs index 321aa69a1..00871f9f4 100644 --- a/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.rs +++ b/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.rs @@ -1,7 +1,4 @@ -//@aux-build:proc_macro_attr.rs:proc-macro -// Flaky test, see https://github.com/rust-lang/rust/issues/113585. -//@ignore-32bit -//@ignore-64bit +//@aux-build:proc_macro_attr.rs #![warn(clippy::needless_arbitrary_self_type)] diff --git a/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.stderr b/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.stderr index c7df5936d..183e2dbc8 100644 --- a/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.stderr +++ b/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.stderr @@ -5,6 +5,7 @@ LL | fn call_with_mut_self(self: &mut Self) {} | ^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&mut self` | = note: `-D clippy::needless-arbitrary-self-type` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_arbitrary_self_type)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/needless_bitwise_bool.fixed b/src/tools/clippy/tests/ui/needless_bitwise_bool.fixed index 7543ab72c..201f8a4c1 100644 --- a/src/tools/clippy/tests/ui/needless_bitwise_bool.fixed +++ b/src/tools/clippy/tests/ui/needless_bitwise_bool.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_bitwise_bool)] fn returns_bool() -> bool { diff --git a/src/tools/clippy/tests/ui/needless_bitwise_bool.rs b/src/tools/clippy/tests/ui/needless_bitwise_bool.rs index 2cea701dc..b0e5014b7 100644 --- a/src/tools/clippy/tests/ui/needless_bitwise_bool.rs +++ b/src/tools/clippy/tests/ui/needless_bitwise_bool.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_bitwise_bool)] fn returns_bool() -> bool { diff --git a/src/tools/clippy/tests/ui/needless_bitwise_bool.stderr b/src/tools/clippy/tests/ui/needless_bitwise_bool.stderr index 63c88ef63..2ed9208e6 100644 --- a/src/tools/clippy/tests/ui/needless_bitwise_bool.stderr +++ b/src/tools/clippy/tests/ui/needless_bitwise_bool.stderr @@ -1,10 +1,11 @@ error: use of bitwise operator instead of lazy operator between booleans - --> $DIR/needless_bitwise_bool.rs:24:8 + --> $DIR/needless_bitwise_bool.rs:22:8 | LL | if y & !x { | ^^^^^^ help: try: `y && !x` | = note: `-D clippy::needless-bitwise-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_bitwise_bool)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/needless_bool/fixable.fixed b/src/tools/clippy/tests/ui/needless_bool/fixable.fixed index 7d0e55652..c9ea831f8 100644 --- a/src/tools/clippy/tests/ui/needless_bool/fixable.fixed +++ b/src/tools/clippy/tests/ui/needless_bool/fixable.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_bool)] #![allow( unused, diff --git a/src/tools/clippy/tests/ui/needless_bool/fixable.rs b/src/tools/clippy/tests/ui/needless_bool/fixable.rs index 88bfe8af7..b83d9c3f2 100644 --- a/src/tools/clippy/tests/ui/needless_bool/fixable.rs +++ b/src/tools/clippy/tests/ui/needless_bool/fixable.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_bool)] #![allow( unused, diff --git a/src/tools/clippy/tests/ui/needless_bool/fixable.stderr b/src/tools/clippy/tests/ui/needless_bool/fixable.stderr index 1476aea43..2b189c898 100644 --- a/src/tools/clippy/tests/ui/needless_bool/fixable.stderr +++ b/src/tools/clippy/tests/ui/needless_bool/fixable.stderr @@ -1,5 +1,5 @@ error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:42:5 + --> $DIR/fixable.rs:40:5 | LL | / if x { LL | | true @@ -9,9 +9,10 @@ LL | | }; | |_____^ help: you can reduce it to: `x` | = note: `-D clippy::needless-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_bool)]` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:47:5 + --> $DIR/fixable.rs:45:5 | LL | / if x { LL | | false @@ -21,7 +22,7 @@ LL | | }; | |_____^ help: you can reduce it to: `!x` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:52:5 + --> $DIR/fixable.rs:50:5 | LL | / if x && y { LL | | false @@ -31,7 +32,7 @@ LL | | }; | |_____^ help: you can reduce it to: `!(x && y)` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:60:5 + --> $DIR/fixable.rs:58:5 | LL | / if a == b { LL | | false @@ -41,7 +42,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a != b` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:65:5 + --> $DIR/fixable.rs:63:5 | LL | / if a != b { LL | | false @@ -51,7 +52,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a == b` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:70:5 + --> $DIR/fixable.rs:68:5 | LL | / if a < b { LL | | false @@ -61,7 +62,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a >= b` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:75:5 + --> $DIR/fixable.rs:73:5 | LL | / if a <= b { LL | | false @@ -71,7 +72,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a > b` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:80:5 + --> $DIR/fixable.rs:78:5 | LL | / if a > b { LL | | false @@ -81,7 +82,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a <= b` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:85:5 + --> $DIR/fixable.rs:83:5 | LL | / if a >= b { LL | | false @@ -91,7 +92,7 @@ LL | | }; | |_____^ help: you can reduce it to: `a < b` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:113:5 + --> $DIR/fixable.rs:111:5 | LL | / if x { LL | | return true; @@ -101,7 +102,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return x` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:121:5 + --> $DIR/fixable.rs:119:5 | LL | / if x { LL | | return false; @@ -111,7 +112,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return !x` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:129:5 + --> $DIR/fixable.rs:127:5 | LL | / if x && y { LL | | return true; @@ -121,7 +122,7 @@ LL | | }; | |_____^ help: you can reduce it to: `return x && y` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:137:5 + --> $DIR/fixable.rs:135:5 | LL | / if x && y { LL | | return false; @@ -131,33 +132,34 @@ LL | | }; | |_____^ help: you can reduce it to: `return !(x && y)` error: equality checks against true are unnecessary - --> $DIR/fixable.rs:145:8 + --> $DIR/fixable.rs:143:8 | LL | if x == true {}; | ^^^^^^^^^ help: try simplifying it as shown: `x` | = note: `-D clippy::bool-comparison` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::bool_comparison)]` error: equality checks against false can be replaced by a negation - --> $DIR/fixable.rs:149:8 + --> $DIR/fixable.rs:147:8 | LL | if x == false {}; | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: equality checks against true are unnecessary - --> $DIR/fixable.rs:159:8 + --> $DIR/fixable.rs:157:8 | LL | if x == true {}; | ^^^^^^^^^ help: try simplifying it as shown: `x` error: equality checks against false can be replaced by a negation - --> $DIR/fixable.rs:160:8 + --> $DIR/fixable.rs:158:8 | LL | if x == false {}; | ^^^^^^^^^^ help: try simplifying it as shown: `!x` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:169:12 + --> $DIR/fixable.rs:167:12 | LL | } else if returns_bool() { | ____________^ @@ -168,7 +170,7 @@ LL | | }; | |_____^ help: you can reduce it to: `{ !returns_bool() }` error: this if-then-else expression returns a bool literal - --> $DIR/fixable.rs:182:5 + --> $DIR/fixable.rs:180:5 | LL | / if unsafe { no(4) } & 1 != 0 { LL | | true @@ -178,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/fixable.rs:187:30 + --> $DIR/fixable.rs:185: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/fixable.rs:190:9 + --> $DIR/fixable.rs:188: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/src/tools/clippy/tests/ui/needless_bool/simple.stderr b/src/tools/clippy/tests/ui/needless_bool/simple.stderr index 0ccc9416b..a44205c59 100644 --- a/src/tools/clippy/tests/ui/needless_bool/simple.stderr +++ b/src/tools/clippy/tests/ui/needless_bool/simple.stderr @@ -9,6 +9,7 @@ LL | | }; | |_____^ | = note: `-D clippy::needless-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_bool)]` error: this if-then-else expression will always return false --> $DIR/simple.rs:19:5 diff --git a/src/tools/clippy/tests/ui/needless_bool_assign.fixed b/src/tools/clippy/tests/ui/needless_bool_assign.fixed index 3ed31d4d7..7b10fe78c 100644 --- a/src/tools/clippy/tests/ui/needless_bool_assign.fixed +++ b/src/tools/clippy/tests/ui/needless_bool_assign.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::needless_bool_assign)] diff --git a/src/tools/clippy/tests/ui/needless_bool_assign.rs b/src/tools/clippy/tests/ui/needless_bool_assign.rs index efaeb67fa..85c0a5777 100644 --- a/src/tools/clippy/tests/ui/needless_bool_assign.rs +++ b/src/tools/clippy/tests/ui/needless_bool_assign.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::needless_bool_assign)] diff --git a/src/tools/clippy/tests/ui/needless_bool_assign.stderr b/src/tools/clippy/tests/ui/needless_bool_assign.stderr index 601bbed54..7866c89bd 100644 --- a/src/tools/clippy/tests/ui/needless_bool_assign.stderr +++ b/src/tools/clippy/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:15:5 + --> $DIR/needless_bool_assign.rs:13:5 | LL | / if random() && random() { LL | | a.field = true; @@ -9,9 +9,10 @@ LL | | } | |_____^ help: you can reduce it to: `a.field = random() && random();` | = note: `-D clippy::needless-bool-assign` implied by `-D warnings` + = 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:20:5 + --> $DIR/needless_bool_assign.rs:18:5 | LL | / if random() && random() { LL | | a.field = false; @@ -21,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:34:5 + --> $DIR/needless_bool_assign.rs:32:5 | LL | / if random() { LL | | a.field = true; @@ -31,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:34:17 + --> $DIR/needless_bool_assign.rs:32:17 | LL | if random() { | _________________^ @@ -40,7 +41,7 @@ LL | | } else { | |_____^ | note: same as this - --> $DIR/needless_bool_assign.rs:36:12 + --> $DIR/needless_bool_assign.rs:34:12 | LL | } else { | ____________^ diff --git a/src/tools/clippy/tests/ui/needless_borrow.fixed b/src/tools/clippy/tests/ui/needless_borrow.fixed index 1dfbee150..c2c5f765a 100644 --- a/src/tools/clippy/tests/ui/needless_borrow.fixed +++ b/src/tools/clippy/tests/ui/needless_borrow.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(lint_reasons)] #![allow( unused, @@ -132,21 +131,6 @@ fn main() { 0 } } - - let _ = std::process::Command::new("ls").args(["-a", "-l"]).status().unwrap(); - let _ = std::path::Path::new(".").join("."); - deref_target_is_x(X); - multiple_constraints([[""]]); - multiple_constraints_normalizes_to_same(X, X); - let _ = Some("").unwrap_or(""); - let _ = std::fs::write("x", "".to_string()); - - only_sized(&""); // Don't lint. `Sized` is only bound - let _ = std::any::Any::type_id(&""); // Don't lint. `Any` is only bound - let _ = Box::new(&""); // Don't lint. Type parameter appears in return type - ref_as_ref_path(&""); // Don't lint. Argument type is not a type parameter - refs_only(&()); // Don't lint. `&T` implements trait, but `T` doesn't - multiple_constraints_normalizes_to_different(&[[""]], &[""]); // Don't lint. Projected type appears in arguments } #[allow(clippy::needless_borrowed_reference)] @@ -202,103 +186,6 @@ mod issue9160 { } } -#[derive(Clone, Copy)] -struct X; - -impl std::ops::Deref for X { - type Target = X; - fn deref(&self) -> &Self::Target { - self - } -} - -fn deref_target_is_x(_: T) -where - T: std::ops::Deref, -{ -} - -fn multiple_constraints(_: T) -where - T: IntoIterator + IntoIterator, - U: IntoIterator, - V: AsRef, - X: IntoIterator, - Y: AsRef, -{ -} - -fn multiple_constraints_normalizes_to_same(_: T, _: V) -where - T: std::ops::Deref, - U: std::ops::Deref, -{ -} - -fn only_sized(_: T) {} - -fn ref_as_ref_path(_: &'static T) -where - &'static T: AsRef, -{ -} - -trait RefsOnly { - type Referent; -} - -impl RefsOnly for &T { - type Referent = T; -} - -fn refs_only(_: T) -where - T: RefsOnly, -{ -} - -fn multiple_constraints_normalizes_to_different(_: T, _: U) -where - T: IntoIterator, - U: IntoIterator, - V: AsRef, -{ -} - -// https://github.com/rust-lang/rust-clippy/pull/9136#pullrequestreview-1037379321 -mod copyable_iterator { - #[derive(Clone, Copy)] - struct Iter; - impl Iterator for Iter { - type Item = (); - fn next(&mut self) -> Option { - None - } - } - fn takes_iter(_: impl Iterator) {} - fn dont_warn(mut x: Iter) { - takes_iter(&mut x); - } - #[allow(unused_mut)] - fn warn(mut x: &mut Iter) { - takes_iter(x) - } -} - -#[clippy::msrv = "1.52.0"] -mod under_msrv { - fn foo() { - let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap(); - } -} - -#[clippy::msrv = "1.53.0"] -mod meets_msrv { - fn foo() { - let _ = std::process::Command::new("ls").args(["-a", "-l"]).status().unwrap(); - } -} - fn issue9383() { // Should not lint because unions need explicit deref when accessing field use std::mem::ManuallyDrop; @@ -327,180 +214,15 @@ fn issue9383() { } } -fn closure_test() { - let env = "env".to_owned(); - let arg = "arg".to_owned(); - let f = |arg| { - let loc = "loc".to_owned(); - let _ = std::fs::write("x", &env); // Don't lint. In environment - let _ = std::fs::write("x", arg); - let _ = std::fs::write("x", loc); - }; - let _ = std::fs::write("x", &env); // Don't lint. Borrowed by `f` - f(arg); -} - -mod significant_drop { - #[derive(Debug)] - struct X; - - #[derive(Debug)] - struct Y; - - impl Drop for Y { - fn drop(&mut self) {} - } - - fn foo(x: X, y: Y) { - debug(x); - debug(&y); // Don't lint. Has significant drop - } - - fn debug(_: impl std::fmt::Debug) {} -} - -mod used_exactly_once { - fn foo(x: String) { - use_x(x); - } - fn use_x(_: impl AsRef) {} -} - -mod used_more_than_once { - fn foo(x: String) { - use_x(&x); - use_x_again(&x); - } - fn use_x(_: impl AsRef) {} - fn use_x_again(_: impl AsRef) {} -} - -// https://github.com/rust-lang/rust-clippy/issues/9111#issuecomment-1277114280 -mod issue_9111 { - struct A; - - impl Extend for A { - fn extend>(&mut self, _: T) { - unimplemented!() - } - } - - impl<'a> Extend<&'a u8> for A { - fn extend>(&mut self, _: T) { - unimplemented!() - } - } - - fn main() { - let mut a = A; - a.extend(&[]); // vs a.extend([]); - } -} - -mod issue_9710 { - fn main() { - let string = String::new(); - for _i in 0..10 { - f(&string); - } - } - - fn f>(_: T) {} -} - -mod issue_9739 { - fn foo(_it: impl IntoIterator) {} - - fn main() { - foo(if std::env::var_os("HI").is_some() { - &[0] - } else { - &[] as &[u32] - }); - } -} - -mod issue_9739_method_variant { - struct S; - - impl S { - fn foo(&self, _it: impl IntoIterator) {} - } - - fn main() { - S.foo(if std::env::var_os("HI").is_some() { - &[0] - } else { - &[] as &[u32] - }); - } -} - -mod issue_9782 { - fn foo>(t: T) { - println!("{}", std::mem::size_of::()); - let _t: &[u8] = t.as_ref(); - } - - fn main() { - let a: [u8; 100] = [0u8; 100]; - - // 100 - foo::<[u8; 100]>(a); - foo(a); - - // 16 - foo::<&[u8]>(&a); - foo(a.as_slice()); - - // 8 - foo::<&[u8; 100]>(&a); - foo(a); - } -} - -mod issue_9782_type_relative_variant { - struct S; - - impl S { - fn foo>(t: T) { - println!("{}", std::mem::size_of::()); - let _t: &[u8] = t.as_ref(); - } - } - - fn main() { - let a: [u8; 100] = [0u8; 100]; - - S::foo::<&[u8; 100]>(&a); - } -} - -mod issue_9782_method_variant { +mod issue_10253 { struct S; - - impl S { - fn foo>(&self, t: T) { - println!("{}", std::mem::size_of::()); - let _t: &[u8] = t.as_ref(); - } + trait X { + fn f(&self); } - - fn main() { - let a: [u8; 100] = [0u8; 100]; - - S.foo::<&[u8; 100]>(&a); + impl X for &S { + fn f(&self) {} } -} - -mod issue_10535 { - static SOME_STATIC: String = String::new(); - - static UNIT: () = compute(&SOME_STATIC); - - pub const fn compute(_: T) - where - T: Copy, - { + fn f() { + (&S).f::<()>(); } } diff --git a/src/tools/clippy/tests/ui/needless_borrow.rs b/src/tools/clippy/tests/ui/needless_borrow.rs index 3c0d73f5f..0cd6e41b8 100644 --- a/src/tools/clippy/tests/ui/needless_borrow.rs +++ b/src/tools/clippy/tests/ui/needless_borrow.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(lint_reasons)] #![allow( unused, @@ -132,21 +131,6 @@ fn main() { 0 } } - - let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap(); - let _ = std::path::Path::new(".").join(&&"."); - deref_target_is_x(&X); - multiple_constraints(&[[""]]); - multiple_constraints_normalizes_to_same(&X, X); - let _ = Some("").unwrap_or(&""); - let _ = std::fs::write("x", &"".to_string()); - - only_sized(&""); // Don't lint. `Sized` is only bound - let _ = std::any::Any::type_id(&""); // Don't lint. `Any` is only bound - let _ = Box::new(&""); // Don't lint. Type parameter appears in return type - ref_as_ref_path(&""); // Don't lint. Argument type is not a type parameter - refs_only(&()); // Don't lint. `&T` implements trait, but `T` doesn't - multiple_constraints_normalizes_to_different(&[[""]], &[""]); // Don't lint. Projected type appears in arguments } #[allow(clippy::needless_borrowed_reference)] @@ -202,103 +186,6 @@ mod issue9160 { } } -#[derive(Clone, Copy)] -struct X; - -impl std::ops::Deref for X { - type Target = X; - fn deref(&self) -> &Self::Target { - self - } -} - -fn deref_target_is_x(_: T) -where - T: std::ops::Deref, -{ -} - -fn multiple_constraints(_: T) -where - T: IntoIterator + IntoIterator, - U: IntoIterator, - V: AsRef, - X: IntoIterator, - Y: AsRef, -{ -} - -fn multiple_constraints_normalizes_to_same(_: T, _: V) -where - T: std::ops::Deref, - U: std::ops::Deref, -{ -} - -fn only_sized(_: T) {} - -fn ref_as_ref_path(_: &'static T) -where - &'static T: AsRef, -{ -} - -trait RefsOnly { - type Referent; -} - -impl RefsOnly for &T { - type Referent = T; -} - -fn refs_only(_: T) -where - T: RefsOnly, -{ -} - -fn multiple_constraints_normalizes_to_different(_: T, _: U) -where - T: IntoIterator, - U: IntoIterator, - V: AsRef, -{ -} - -// https://github.com/rust-lang/rust-clippy/pull/9136#pullrequestreview-1037379321 -mod copyable_iterator { - #[derive(Clone, Copy)] - struct Iter; - impl Iterator for Iter { - type Item = (); - fn next(&mut self) -> Option { - None - } - } - fn takes_iter(_: impl Iterator) {} - fn dont_warn(mut x: Iter) { - takes_iter(&mut x); - } - #[allow(unused_mut)] - fn warn(mut x: &mut Iter) { - takes_iter(&mut x) - } -} - -#[clippy::msrv = "1.52.0"] -mod under_msrv { - fn foo() { - let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap(); - } -} - -#[clippy::msrv = "1.53.0"] -mod meets_msrv { - fn foo() { - let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap(); - } -} - fn issue9383() { // Should not lint because unions need explicit deref when accessing field use std::mem::ManuallyDrop; @@ -327,180 +214,15 @@ fn issue9383() { } } -fn closure_test() { - let env = "env".to_owned(); - let arg = "arg".to_owned(); - let f = |arg| { - let loc = "loc".to_owned(); - let _ = std::fs::write("x", &env); // Don't lint. In environment - let _ = std::fs::write("x", &arg); - let _ = std::fs::write("x", &loc); - }; - let _ = std::fs::write("x", &env); // Don't lint. Borrowed by `f` - f(arg); -} - -mod significant_drop { - #[derive(Debug)] - struct X; - - #[derive(Debug)] - struct Y; - - impl Drop for Y { - fn drop(&mut self) {} - } - - fn foo(x: X, y: Y) { - debug(&x); - debug(&y); // Don't lint. Has significant drop - } - - fn debug(_: impl std::fmt::Debug) {} -} - -mod used_exactly_once { - fn foo(x: String) { - use_x(&x); - } - fn use_x(_: impl AsRef) {} -} - -mod used_more_than_once { - fn foo(x: String) { - use_x(&x); - use_x_again(&x); - } - fn use_x(_: impl AsRef) {} - fn use_x_again(_: impl AsRef) {} -} - -// https://github.com/rust-lang/rust-clippy/issues/9111#issuecomment-1277114280 -mod issue_9111 { - struct A; - - impl Extend for A { - fn extend>(&mut self, _: T) { - unimplemented!() - } - } - - impl<'a> Extend<&'a u8> for A { - fn extend>(&mut self, _: T) { - unimplemented!() - } - } - - fn main() { - let mut a = A; - a.extend(&[]); // vs a.extend([]); - } -} - -mod issue_9710 { - fn main() { - let string = String::new(); - for _i in 0..10 { - f(&string); - } - } - - fn f>(_: T) {} -} - -mod issue_9739 { - fn foo(_it: impl IntoIterator) {} - - fn main() { - foo(if std::env::var_os("HI").is_some() { - &[0] - } else { - &[] as &[u32] - }); - } -} - -mod issue_9739_method_variant { - struct S; - - impl S { - fn foo(&self, _it: impl IntoIterator) {} - } - - fn main() { - S.foo(if std::env::var_os("HI").is_some() { - &[0] - } else { - &[] as &[u32] - }); - } -} - -mod issue_9782 { - fn foo>(t: T) { - println!("{}", std::mem::size_of::()); - let _t: &[u8] = t.as_ref(); - } - - fn main() { - let a: [u8; 100] = [0u8; 100]; - - // 100 - foo::<[u8; 100]>(a); - foo(a); - - // 16 - foo::<&[u8]>(&a); - foo(a.as_slice()); - - // 8 - foo::<&[u8; 100]>(&a); - foo(&a); - } -} - -mod issue_9782_type_relative_variant { - struct S; - - impl S { - fn foo>(t: T) { - println!("{}", std::mem::size_of::()); - let _t: &[u8] = t.as_ref(); - } - } - - fn main() { - let a: [u8; 100] = [0u8; 100]; - - S::foo::<&[u8; 100]>(&a); - } -} - -mod issue_9782_method_variant { +mod issue_10253 { struct S; - - impl S { - fn foo>(&self, t: T) { - println!("{}", std::mem::size_of::()); - let _t: &[u8] = t.as_ref(); - } + trait X { + fn f(&self); } - - fn main() { - let a: [u8; 100] = [0u8; 100]; - - S.foo::<&[u8; 100]>(&a); + impl X for &S { + fn f(&self) {} } -} - -mod issue_10535 { - static SOME_STATIC: String = String::new(); - - static UNIT: () = compute(&SOME_STATIC); - - pub const fn compute(_: T) - where - T: Copy, - { + fn f() { + (&S).f::<()>(); } } diff --git a/src/tools/clippy/tests/ui/needless_borrow.stderr b/src/tools/clippy/tests/ui/needless_borrow.stderr index f85b4fb46..e91b78b0a 100644 --- a/src/tools/clippy/tests/ui/needless_borrow.stderr +++ b/src/tools/clippy/tests/ui/needless_borrow.stderr @@ -1,220 +1,137 @@ error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:16:15 + --> $DIR/needless_borrow.rs:15:15 | LL | let _ = x(&&a); // warn | ^^^ help: change this to: `&a` | = note: `-D clippy::needless-borrow` implied by `-D warnings` + = 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:20:13 + --> $DIR/needless_borrow.rs:19: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:32:13 + --> $DIR/needless_borrow.rs:31: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:34:15 + --> $DIR/needless_borrow.rs:33: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:40:27 + --> $DIR/needless_borrow.rs:39: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:47:15 + --> $DIR/needless_borrow.rs:46: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:48:15 + --> $DIR/needless_borrow.rs:47: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:49:15 + --> $DIR/needless_borrow.rs:48: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:50:15 + --> $DIR/needless_borrow.rs:49: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:53:11 + --> $DIR/needless_borrow.rs:52: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:60:13 + --> $DIR/needless_borrow.rs:59: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:61:13 + --> $DIR/needless_borrow.rs:60: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:62:23 + --> $DIR/needless_borrow.rs:61: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:63:23 + --> $DIR/needless_borrow.rs:62: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:72:14 + --> $DIR/needless_borrow.rs:71: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:78:14 + --> $DIR/needless_borrow.rs:77: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:90:13 + --> $DIR/needless_borrow.rs:89: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:92:22 + --> $DIR/needless_borrow.rs:91: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:102:5 + --> $DIR/needless_borrow.rs:101:5 | LL | (&&()).foo(); | ^^^^^^ help: change this to: `(&())` error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:111:5 + --> $DIR/needless_borrow.rs:110:5 | LL | (&&5).foo(); | ^^^^^ help: change this to: `(&5)` -error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:136:51 - | -LL | let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap(); - | ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]` - -error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:137:44 - | -LL | let _ = std::path::Path::new(".").join(&&"."); - | ^^^^^ help: change this to: `"."` - -error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:138:23 - | -LL | deref_target_is_x(&X); - | ^^ help: change this to: `X` - -error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:139:26 - | -LL | multiple_constraints(&[[""]]); - | ^^^^^^^ help: change this to: `[[""]]` - -error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:140:45 - | -LL | multiple_constraints_normalizes_to_same(&X, X); - | ^^ help: change this to: `X` - -error: this expression creates a reference which is immediately dereferenced by the compiler - --> $DIR/needless_borrow.rs:141:32 - | -LL | let _ = Some("").unwrap_or(&""); - | ^^^ help: change this to: `""` - -error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:142:33 - | -LL | let _ = std::fs::write("x", &"".to_string()); - | ^^^^^^^^^^^^^^^ help: change this to: `"".to_string()` - error: this expression borrows a value the compiler would automatically borrow - --> $DIR/needless_borrow.rs:191:13 + --> $DIR/needless_borrow.rs:175: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:200:13 + --> $DIR/needless_borrow.rs:184:13 | LL | (&mut self.f)() | ^^^^^^^^^^^^^ help: change this to: `(self.f)` -error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:284:20 - | -LL | takes_iter(&mut x) - | ^^^^^^ help: change this to: `x` - -error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:298:55 - | -LL | let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap(); - | ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]` - -error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:336:37 - | -LL | let _ = std::fs::write("x", &arg); - | ^^^^ help: change this to: `arg` - -error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:337:37 - | -LL | let _ = std::fs::write("x", &loc); - | ^^^^ help: change this to: `loc` - -error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:355:15 - | -LL | debug(&x); - | ^^ help: change this to: `x` - -error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:364:15 - | -LL | use_x(&x); - | ^^ help: change this to: `x` - -error: the borrowed expression implements the required traits - --> $DIR/needless_borrow.rs:458:13 - | -LL | foo(&a); - | ^^ help: change this to: `a` - -error: aborting due to 36 previous errors +error: aborting due to 22 previous errors diff --git a/src/tools/clippy/tests/ui/needless_borrow_pat.fixed b/src/tools/clippy/tests/ui/needless_borrow_pat.fixed new file mode 100644 index 000000000..8f8887f08 --- /dev/null +++ b/src/tools/clippy/tests/ui/needless_borrow_pat.fixed @@ -0,0 +1,163 @@ +// FIXME: run-rustfix waiting on multi-span suggestions + +#![warn(clippy::needless_borrow)] +#![allow(clippy::needless_borrowed_reference, clippy::explicit_auto_deref)] + +fn f1(_: &str) {} +macro_rules! m1 { + ($e:expr) => { + f1($e) + }; +} +macro_rules! m3 { + ($i:ident) => { + Some(ref $i) + }; +} +macro_rules! if_chain { + (if $e:expr; $($rest:tt)*) => { + if $e { + if_chain!($($rest)*) + } + }; + + (if let $p:pat = $e:expr; $($rest:tt)*) => { + if let $p = $e { + if_chain!($($rest)*) + } + }; + + (then $b:block) => { + $b + }; +} + +#[allow(dead_code)] +fn main() { + let x = String::new(); + + // Ok, reference to a String. + let _: &String = match Some(x.clone()) { + Some(ref x) => x, + None => return, + }; + + // Ok, reference to a &mut String + let _: &&mut String = match Some(&mut x.clone()) { + Some(ref x) => x, + None => return, + }; + + // Ok, the pattern is from a macro + let _: &String = match Some(&x) { + m3!(x) => x, + None => return, + }; + + // Err, reference to a &String + let _: &String = match Some(&x) { + Some(x) => x, + //~^ ERROR: this pattern creates a reference to a reference + //~| NOTE: `-D clippy::needless-borrow` implied by `-D warnings` + None => return, + }; + + // Err, reference to a &String. + let _: &String = match Some(&x) { + Some(x) => x, + //~^ ERROR: this pattern creates a reference to a reference + None => return, + }; + + // Err, reference to a &String + let _: &String = match Some(&x) { + Some(x) => { + //~^ ERROR: this pattern creates a reference to a reference + f1(x); + f1(x); + x + }, + None => return, + }; + + // Err, reference to a &String + match Some(&x) { + Some(x) => m1!(x), + //~^ ERROR: this pattern creates a reference to a reference + None => return, + }; + + // Err, reference to a &String + let _ = |&x: &&String| { + //~^ ERROR: this pattern creates a reference to a reference + let _: &String = x; + }; + + // Err, reference to a &String + let (y,) = (&x,); + //~^ ERROR: this pattern creates a reference to a reference + let _: &String = y; + + let y = &&x; + // Ok, different y + let _: &String = *y; + + let x = (0, 0); + // Err, reference to a &u32. Don't suggest adding a reference to the field access. + let _: u32 = match Some(&x) { + Some(x) => x.0, + //~^ ERROR: this pattern creates a reference to a reference + None => return, + }; + + enum E { + A(&'static u32), + B(&'static u32), + } + // Err, reference to &u32. + let _: &u32 = match E::A(&0) { + E::A(x) | E::B(x) => x, + //~^ ERROR: this pattern creates a reference to a reference + }; + + // Err, reference to &String. + if_chain! { + if true; + if let Some(x) = Some(&String::new()); + //~^ ERROR: this pattern creates a reference to a reference + then { + f1(x); + } + } +} + +// Err, reference to a &String +fn f2<'a>(&x: &&'a String) -> &'a String { + //~^ ERROR: this pattern creates a reference to a reference + let _: &String = x; + x +} + +trait T1 { + // Err, reference to a &String + fn f(&x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference + let _: &String = x; + } +} + +struct S; +impl T1 for S { + // Err, reference to a &String + fn f(&x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference + let _: &String = x; + } +} + +// Ok - used to error due to rustc bug +#[allow(dead_code)] +#[derive(Debug)] +enum Foo<'a> { + Str(&'a str), +} diff --git a/src/tools/clippy/tests/ui/needless_borrow_pat.rs b/src/tools/clippy/tests/ui/needless_borrow_pat.rs index 222e8e617..56dbd923f 100644 --- a/src/tools/clippy/tests/ui/needless_borrow_pat.rs +++ b/src/tools/clippy/tests/ui/needless_borrow_pat.rs @@ -57,18 +57,22 @@ fn main() { // Err, reference to a &String let _: &String = match Some(&x) { Some(ref x) => x, + //~^ ERROR: this pattern creates a reference to a reference + //~| NOTE: `-D clippy::needless-borrow` implied by `-D warnings` None => return, }; // Err, reference to a &String. let _: &String = match Some(&x) { Some(ref x) => *x, + //~^ ERROR: this pattern creates a reference to a reference None => return, }; // Err, reference to a &String let _: &String = match Some(&x) { Some(ref x) => { + //~^ ERROR: this pattern creates a reference to a reference f1(x); f1(*x); x @@ -79,16 +83,19 @@ fn main() { // Err, reference to a &String match Some(&x) { Some(ref x) => m1!(x), + //~^ ERROR: this pattern creates a reference to a reference None => return, }; // Err, reference to a &String let _ = |&ref x: &&String| { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; }; // Err, reference to a &String let (ref y,) = (&x,); + //~^ ERROR: this pattern creates a reference to a reference let _: &String = *y; let y = &&x; @@ -99,6 +106,7 @@ fn main() { // Err, reference to a &u32. Don't suggest adding a reference to the field access. let _: u32 = match Some(&x) { Some(ref x) => x.0, + //~^ ERROR: this pattern creates a reference to a reference None => return, }; @@ -109,12 +117,14 @@ fn main() { // Err, reference to &u32. let _: &u32 = match E::A(&0) { E::A(ref x) | E::B(ref x) => *x, + //~^ ERROR: this pattern creates a reference to a reference }; // Err, reference to &String. if_chain! { if true; if let Some(ref x) = Some(&String::new()); + //~^ ERROR: this pattern creates a reference to a reference then { f1(x); } @@ -123,6 +133,7 @@ fn main() { // Err, reference to a &String fn f2<'a>(&ref x: &&'a String) -> &'a String { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; *x } @@ -130,6 +141,7 @@ fn f2<'a>(&ref x: &&'a String) -> &'a String { trait T1 { // Err, reference to a &String fn f(&ref x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = x; } } @@ -138,6 +150,7 @@ struct S; impl T1 for S { // Err, reference to a &String fn f(&ref x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &String = *x; } } diff --git a/src/tools/clippy/tests/ui/needless_borrow_pat.stderr b/src/tools/clippy/tests/ui/needless_borrow_pat.stderr index 2d9b8f159..ce3a36e35 100644 --- a/src/tools/clippy/tests/ui/needless_borrow_pat.stderr +++ b/src/tools/clippy/tests/ui/needless_borrow_pat.stderr @@ -5,9 +5,10 @@ LL | Some(ref x) => x, | ^^^^^ help: try: `x` | = note: `-D clippy::needless-borrow` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:65:14 + --> $DIR/needless_borrow_pat.rs:67:14 | LL | Some(ref x) => *x, | ^^^^^ @@ -18,7 +19,7 @@ LL | Some(x) => x, | ~ ~ error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:71:14 + --> $DIR/needless_borrow_pat.rs:74:14 | LL | Some(ref x) => { | ^^^^^ @@ -26,24 +27,25 @@ LL | Some(ref x) => { help: try | LL ~ Some(x) => { +LL | LL | f1(x); LL ~ f1(x); | error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:81:14 + --> $DIR/needless_borrow_pat.rs:85:14 | LL | Some(ref x) => m1!(x), | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:86:15 + --> $DIR/needless_borrow_pat.rs:91:15 | LL | let _ = |&ref x: &&String| { | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:91:10 + --> $DIR/needless_borrow_pat.rs:97:10 | LL | let (ref y,) = (&x,); | ^^^^^ @@ -51,17 +53,18 @@ LL | let (ref y,) = (&x,); help: try | LL ~ let (y,) = (&x,); +LL | LL ~ let _: &String = y; | error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:101:14 + --> $DIR/needless_borrow_pat.rs:108:14 | LL | Some(ref x) => x.0, | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:111:14 + --> $DIR/needless_borrow_pat.rs:119:14 | LL | E::A(ref x) | E::B(ref x) => *x, | ^^^^^ ^^^^^ @@ -72,13 +75,13 @@ LL | E::A(x) | E::B(x) => x, | ~ ~ ~ error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:117:21 + --> $DIR/needless_borrow_pat.rs:126:21 | LL | if let Some(ref x) = Some(&String::new()); | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:125:12 + --> $DIR/needless_borrow_pat.rs:135:12 | LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | ^^^^^ @@ -86,18 +89,19 @@ LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { help: try | LL ~ fn f2<'a>(&x: &&'a String) -> &'a String { +LL | LL | let _: &String = x; LL ~ x | error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:132:11 + --> $DIR/needless_borrow_pat.rs:143:11 | LL | fn f(&ref x: &&String) { | ^^^^^ help: try: `x` error: this pattern creates a reference to a reference - --> $DIR/needless_borrow_pat.rs:140:11 + --> $DIR/needless_borrow_pat.rs:152:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -105,6 +109,7 @@ LL | fn f(&ref x: &&String) { help: try | LL ~ fn f(&x: &&String) { +LL | LL ~ let _: &String = x; | diff --git a/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed b/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed index 59a38425b..5d2fd0950 100644 --- a/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed +++ b/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_borrowed_reference)] #![allow( unused, diff --git a/src/tools/clippy/tests/ui/needless_borrowed_ref.rs b/src/tools/clippy/tests/ui/needless_borrowed_ref.rs index e48b19cb1..556fd3a35 100644 --- a/src/tools/clippy/tests/ui/needless_borrowed_ref.rs +++ b/src/tools/clippy/tests/ui/needless_borrowed_ref.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_borrowed_reference)] #![allow( unused, diff --git a/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr b/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr index 35497a01e..15261cfce 100644 --- a/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr +++ b/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr @@ -1,10 +1,11 @@ error: this pattern takes a reference on something that is being dereferenced - --> $DIR/needless_borrowed_ref.rs:32:34 + --> $DIR/needless_borrowed_ref.rs:30:34 | LL | let _ = v.iter_mut().filter(|&ref a| a.is_empty()); | ^^^^^^ | = note: `-D clippy::needless-borrowed-reference` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_borrowed_reference)]` help: try removing the `&ref` part | LL - let _ = v.iter_mut().filter(|&ref a| a.is_empty()); @@ -12,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:36:17 + --> $DIR/needless_borrowed_ref.rs:34:17 | LL | if let Some(&ref v) = thingy {} | ^^^^^^ @@ -24,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:38:14 + --> $DIR/needless_borrowed_ref.rs:36:14 | LL | if let &[&ref a, ref b] = slice_of_refs {} | ^^^^^^ @@ -36,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:40:9 + --> $DIR/needless_borrowed_ref.rs:38:9 | LL | let &[ref a, ..] = &array; | ^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL + let [a, ..] = &array; | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:41:9 + --> $DIR/needless_borrowed_ref.rs:39:9 | LL | let &[ref a, ref b, ..] = &array; | ^^^^^^^^^^^^^^^^^^^ @@ -60,7 +61,7 @@ LL + let [a, b, ..] = &array; | error: dereferencing a slice pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:43:12 + --> $DIR/needless_borrowed_ref.rs:41:12 | LL | if let &[ref a, ref b] = slice {} | ^^^^^^^^^^^^^^^ @@ -72,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:44:12 + --> $DIR/needless_borrowed_ref.rs:42:12 | LL | if let &[ref a, ref b] = &vec[..] {} | ^^^^^^^^^^^^^^^ @@ -84,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:46:12 + --> $DIR/needless_borrowed_ref.rs:44:12 | LL | if let &[ref a, ref b, ..] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -96,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:47:12 + --> $DIR/needless_borrowed_ref.rs:45:12 | LL | if let &[ref a, .., ref b] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -108,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:48:12 + --> $DIR/needless_borrowed_ref.rs:46:12 | LL | if let &[.., ref a, ref b] = slice {} | ^^^^^^^^^^^^^^^^^^^ @@ -120,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:50:12 + --> $DIR/needless_borrowed_ref.rs:48:12 | LL | if let &[ref a, _] = slice {} | ^^^^^^^^^^^ @@ -132,7 +133,7 @@ LL + if let [a, _] = slice {} | error: dereferencing a tuple pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:52:12 + --> $DIR/needless_borrowed_ref.rs:50:12 | LL | if let &(ref a, ref b, ref c) = &tuple {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -144,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:53:12 + --> $DIR/needless_borrowed_ref.rs:51:12 | LL | if let &(ref a, _, ref c) = &tuple {} | ^^^^^^^^^^^^^^^^^^ @@ -156,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:54:12 + --> $DIR/needless_borrowed_ref.rs:52:12 | LL | if let &(ref a, ..) = &tuple {} | ^^^^^^^^^^^^ @@ -168,7 +169,7 @@ LL + if let (a, ..) = &tuple {} | error: dereferencing a tuple pattern where every element takes a reference - --> $DIR/needless_borrowed_ref.rs:56:12 + --> $DIR/needless_borrowed_ref.rs:54:12 | LL | if let &TupleStruct(ref a, ..) = &tuple_struct {} | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -180,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:58:12 + --> $DIR/needless_borrowed_ref.rs:56:12 | LL | if let &Struct { | ____________^ @@ -199,7 +200,7 @@ LL ~ c: renamed, | error: dereferencing a struct pattern where every field's pattern takes a reference - --> $DIR/needless_borrowed_ref.rs:65:12 + --> $DIR/needless_borrowed_ref.rs:63:12 | LL | if let &Struct { ref a, b: _, .. } = &s {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.fixed b/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.fixed new file mode 100644 index 000000000..2a335516f --- /dev/null +++ b/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.fixed @@ -0,0 +1,287 @@ +#![warn(clippy::needless_borrows_for_generic_args)] +#![allow( + clippy::unnecessary_to_owned, + clippy::unnecessary_literal_unwrap, + clippy::needless_borrow +)] + +use core::ops::Deref; +use std::any::Any; +use std::ffi::OsStr; +use std::fmt::{Debug, Display}; +use std::path::Path; +use std::process::Command; + +fn main() { + let _ = Command::new("ls").args(["-a", "-l"]).status().unwrap(); + let _ = Path::new(".").join("."); + 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()); + + { + #[derive(Clone, Copy)] + struct X; + + impl Deref for X { + type Target = X; + fn deref(&self) -> &Self::Target { + self + } + } + + fn deref_target_is_x>(_: T) {} + + deref_target_is_x(X); + } + { + fn multiple_constraints(_: T) + where + T: IntoIterator + IntoIterator, + U: IntoIterator, + V: AsRef, + X: IntoIterator, + Y: AsRef, + { + } + + multiple_constraints([[""]]); + } + { + #[derive(Clone, Copy)] + struct X; + + impl Deref for X { + type Target = X; + fn deref(&self) -> &Self::Target { + self + } + } + + fn multiple_constraints_normalizes_to_same(_: T, _: V) + where + T: Deref, + U: Deref, + { + } + + multiple_constraints_normalizes_to_same(X, X); + } + { + fn only_sized(_: T) {} + only_sized(&""); // Don't lint. `Sized` is only bound + } + { + fn ref_as_ref_path(_: &'static T) + where + &'static T: AsRef, + { + } + + ref_as_ref_path(&""); // Don't lint. Argument type is not a type parameter + } + { + trait RefsOnly { + type Referent; + } + + impl RefsOnly for &T { + type Referent = T; + } + + fn refs_only(_: T) + where + T: RefsOnly, + { + } + + refs_only(&()); // Don't lint. `&T` implements trait, but `T` doesn't + } + { + fn multiple_constraints_normalizes_to_different(_: T, _: U) + where + T: IntoIterator, + U: IntoIterator, + V: AsRef, + { + } + multiple_constraints_normalizes_to_different(&[[""]], &[""]); // Don't lint. Projected type appears in arguments + } + // https://github.com/rust-lang/rust-clippy/pull/9136#pullrequestreview-1037379321 + { + #[derive(Clone, Copy)] + struct Iter; + impl Iterator for Iter { + type Item = (); + fn next(&mut self) -> Option { + None + } + } + fn takes_iter(_: impl Iterator) {} + fn dont_warn(mut x: Iter) { + takes_iter(&mut x); + } + #[allow(unused_mut)] + fn warn(mut x: &mut Iter) { + takes_iter(x) + } + } + #[clippy::msrv = "1.52.0"] + { + let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap(); + }; + #[clippy::msrv = "1.53.0"] + { + let _ = Command::new("ls").args(["-a", "-l"]).status().unwrap(); + }; + { + let env = "env".to_owned(); + let arg = "arg".to_owned(); + let f = |arg| { + let loc = "loc".to_owned(); + let _ = std::fs::write("x", &env); // Don't lint. In environment + let _ = std::fs::write("x", arg); + let _ = std::fs::write("x", loc); + }; + let _ = std::fs::write("x", &env); // Don't lint. Borrowed by `f` + f(arg); + } + { + #[derive(Debug)] + struct X; + + impl Drop for X { + fn drop(&mut self) {} + } + + fn f(_: impl Debug) {} + + let x = X; + f(&x); // Don't lint. Has significant drop + } + { + fn f(_: impl AsRef) {} + + let x = String::new(); + f(x); + } + { + fn f(_: impl AsRef) {} + fn f2(_: impl AsRef) {} + + let x = String::new(); + f(&x); + f2(&x); + } + // https://github.com/rust-lang/rust-clippy/issues/9111#issuecomment-1277114280 + // issue 9111 + { + struct A; + + impl Extend for A { + fn extend>(&mut self, _: T) { + unimplemented!() + } + } + + impl<'a> Extend<&'a u8> for A { + fn extend>(&mut self, _: T) { + unimplemented!() + } + } + + let mut a = A; + a.extend(&[]); // vs a.extend([]); + } + // issue 9710 + { + fn f(_: impl AsRef) {} + + let x = String::new(); + for _ in 0..10 { + f(&x); + } + } + // issue 9739 + { + fn foo(_it: impl IntoIterator) {} + foo(if std::env::var_os("HI").is_some() { + &[0] + } else { + &[] as &[u32] + }); + } + { + struct S; + + impl S { + fn foo(&self, _it: impl IntoIterator) {} + } + + S.foo(if std::env::var_os("HI").is_some() { + &[0] + } else { + &[] as &[u32] + }); + } + // issue 9782 + { + fn foo>(t: T) { + println!("{}", std::mem::size_of::()); + let _t: &[u8] = t.as_ref(); + } + + let a: [u8; 100] = [0u8; 100]; + + // 100 + foo::<[u8; 100]>(a); + foo(a); + + // 16 + foo::<&[u8]>(&a); + foo(a.as_slice()); + + // 8 + foo::<&[u8; 100]>(&a); + foo(a); + } + { + struct S; + + impl S { + fn foo>(t: T) { + println!("{}", std::mem::size_of::()); + let _t: &[u8] = t.as_ref(); + } + } + + let a: [u8; 100] = [0u8; 100]; + S::foo::<&[u8; 100]>(&a); + } + { + struct S; + + impl S { + fn foo>(&self, t: T) { + println!("{}", std::mem::size_of::()); + let _t: &[u8] = t.as_ref(); + } + } + + let a: [u8; 100] = [0u8; 100]; + S.foo::<&[u8; 100]>(&a); + } + // issue 10535 + { + static SOME_STATIC: String = String::new(); + + static UNIT: () = compute(&SOME_STATIC); + + pub const fn compute(_: T) + where + T: Copy, + { + } + } +} diff --git a/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.rs b/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.rs new file mode 100644 index 000000000..f0567f486 --- /dev/null +++ b/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.rs @@ -0,0 +1,287 @@ +#![warn(clippy::needless_borrows_for_generic_args)] +#![allow( + clippy::unnecessary_to_owned, + clippy::unnecessary_literal_unwrap, + clippy::needless_borrow +)] + +use core::ops::Deref; +use std::any::Any; +use std::ffi::OsStr; +use std::fmt::{Debug, Display}; +use std::path::Path; +use std::process::Command; + +fn main() { + let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap(); + let _ = Path::new(".").join(&&"."); + 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()); + + { + #[derive(Clone, Copy)] + struct X; + + impl Deref for X { + type Target = X; + fn deref(&self) -> &Self::Target { + self + } + } + + fn deref_target_is_x>(_: T) {} + + deref_target_is_x(&X); + } + { + fn multiple_constraints(_: T) + where + T: IntoIterator + IntoIterator, + U: IntoIterator, + V: AsRef, + X: IntoIterator, + Y: AsRef, + { + } + + multiple_constraints(&[[""]]); + } + { + #[derive(Clone, Copy)] + struct X; + + impl Deref for X { + type Target = X; + fn deref(&self) -> &Self::Target { + self + } + } + + fn multiple_constraints_normalizes_to_same(_: T, _: V) + where + T: Deref, + U: Deref, + { + } + + multiple_constraints_normalizes_to_same(&X, X); + } + { + fn only_sized(_: T) {} + only_sized(&""); // Don't lint. `Sized` is only bound + } + { + fn ref_as_ref_path(_: &'static T) + where + &'static T: AsRef, + { + } + + ref_as_ref_path(&""); // Don't lint. Argument type is not a type parameter + } + { + trait RefsOnly { + type Referent; + } + + impl RefsOnly for &T { + type Referent = T; + } + + fn refs_only(_: T) + where + T: RefsOnly, + { + } + + refs_only(&()); // Don't lint. `&T` implements trait, but `T` doesn't + } + { + fn multiple_constraints_normalizes_to_different(_: T, _: U) + where + T: IntoIterator, + U: IntoIterator, + V: AsRef, + { + } + multiple_constraints_normalizes_to_different(&[[""]], &[""]); // Don't lint. Projected type appears in arguments + } + // https://github.com/rust-lang/rust-clippy/pull/9136#pullrequestreview-1037379321 + { + #[derive(Clone, Copy)] + struct Iter; + impl Iterator for Iter { + type Item = (); + fn next(&mut self) -> Option { + None + } + } + fn takes_iter(_: impl Iterator) {} + fn dont_warn(mut x: Iter) { + takes_iter(&mut x); + } + #[allow(unused_mut)] + fn warn(mut x: &mut Iter) { + takes_iter(&mut x) + } + } + #[clippy::msrv = "1.52.0"] + { + let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap(); + }; + #[clippy::msrv = "1.53.0"] + { + let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap(); + }; + { + let env = "env".to_owned(); + let arg = "arg".to_owned(); + let f = |arg| { + let loc = "loc".to_owned(); + let _ = std::fs::write("x", &env); // Don't lint. In environment + let _ = std::fs::write("x", &arg); + let _ = std::fs::write("x", &loc); + }; + let _ = std::fs::write("x", &env); // Don't lint. Borrowed by `f` + f(arg); + } + { + #[derive(Debug)] + struct X; + + impl Drop for X { + fn drop(&mut self) {} + } + + fn f(_: impl Debug) {} + + let x = X; + f(&x); // Don't lint. Has significant drop + } + { + fn f(_: impl AsRef) {} + + let x = String::new(); + f(&x); + } + { + fn f(_: impl AsRef) {} + fn f2(_: impl AsRef) {} + + let x = String::new(); + f(&x); + f2(&x); + } + // https://github.com/rust-lang/rust-clippy/issues/9111#issuecomment-1277114280 + // issue 9111 + { + struct A; + + impl Extend for A { + fn extend>(&mut self, _: T) { + unimplemented!() + } + } + + impl<'a> Extend<&'a u8> for A { + fn extend>(&mut self, _: T) { + unimplemented!() + } + } + + let mut a = A; + a.extend(&[]); // vs a.extend([]); + } + // issue 9710 + { + fn f(_: impl AsRef) {} + + let x = String::new(); + for _ in 0..10 { + f(&x); + } + } + // issue 9739 + { + fn foo(_it: impl IntoIterator) {} + foo(if std::env::var_os("HI").is_some() { + &[0] + } else { + &[] as &[u32] + }); + } + { + struct S; + + impl S { + fn foo(&self, _it: impl IntoIterator) {} + } + + S.foo(if std::env::var_os("HI").is_some() { + &[0] + } else { + &[] as &[u32] + }); + } + // issue 9782 + { + fn foo>(t: T) { + println!("{}", std::mem::size_of::()); + let _t: &[u8] = t.as_ref(); + } + + let a: [u8; 100] = [0u8; 100]; + + // 100 + foo::<[u8; 100]>(a); + foo(a); + + // 16 + foo::<&[u8]>(&a); + foo(a.as_slice()); + + // 8 + foo::<&[u8; 100]>(&a); + foo(&a); + } + { + struct S; + + impl S { + fn foo>(t: T) { + println!("{}", std::mem::size_of::()); + let _t: &[u8] = t.as_ref(); + } + } + + let a: [u8; 100] = [0u8; 100]; + S::foo::<&[u8; 100]>(&a); + } + { + struct S; + + impl S { + fn foo>(&self, t: T) { + println!("{}", std::mem::size_of::()); + let _t: &[u8] = t.as_ref(); + } + } + + let a: [u8; 100] = [0u8; 100]; + S.foo::<&[u8; 100]>(&a); + } + // issue 10535 + { + static SOME_STATIC: String = String::new(); + + static UNIT: () = compute(&SOME_STATIC); + + pub const fn compute(_: T) + where + T: Copy, + { + } + } +} diff --git a/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.stderr b/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.stderr new file mode 100644 index 000000000..e2cde2c59 --- /dev/null +++ b/src/tools/clippy/tests/ui/needless_borrows_for_generic_args.stderr @@ -0,0 +1,77 @@ +error: the borrowed expression implements the required traits + --> $DIR/needless_borrows_for_generic_args.rs:16:37 + | +LL | let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap(); + | ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]` + | + = note: `-D clippy::needless-borrows-for-generic-args` implied by `-D warnings` + = 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 + | +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 + | +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 + | +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 + | +LL | multiple_constraints(&[[""]]); + | ^^^^^^^ help: change this to: `[[""]]` + +error: the borrowed expression implements the required traits + --> $DIR/needless_borrows_for_generic_args.rs:69: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 + | +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 + | +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 + | +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 + | +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 + | +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 + | +LL | foo(&a); + | ^^ help: change this to: `a` + +error: aborting due to 12 previous errors + diff --git a/src/tools/clippy/tests/ui/needless_collect.fixed b/src/tools/clippy/tests/ui/needless_collect.fixed index 0f0aaad17..bd83581bd 100644 --- a/src/tools/clippy/tests/ui/needless_collect.fixed +++ b/src/tools/clippy/tests/ui/needless_collect.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::needless_if, clippy::suspicious_map, clippy::iter_count)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList}; diff --git a/src/tools/clippy/tests/ui/needless_collect.rs b/src/tools/clippy/tests/ui/needless_collect.rs index 4f48f24b1..6a81a767b 100644 --- a/src/tools/clippy/tests/ui/needless_collect.rs +++ b/src/tools/clippy/tests/ui/needless_collect.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::needless_if, clippy::suspicious_map, clippy::iter_count)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList}; diff --git a/src/tools/clippy/tests/ui/needless_collect.stderr b/src/tools/clippy/tests/ui/needless_collect.stderr index ad22a7b05..2c21fc596 100644 --- a/src/tools/clippy/tests/ui/needless_collect.stderr +++ b/src/tools/clippy/tests/ui/needless_collect.stderr @@ -1,115 +1,116 @@ error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:11:29 + --> $DIR/needless_collect.rs:9:29 | LL | let len = sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` | = note: `-D clippy::needless-collect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_collect)]` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:12:22 + --> $DIR/needless_collect.rs:10: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:15:28 + --> $DIR/needless_collect.rs:13: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:20:35 + --> $DIR/needless_collect.rs:18: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:21:35 + --> $DIR/needless_collect.rs:19: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:28:19 + --> $DIR/needless_collect.rs:26:19 | LL | sample.iter().collect::>().len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `count()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:29:19 + --> $DIR/needless_collect.rs:27:19 | LL | sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:30:28 + --> $DIR/needless_collect.rs:28: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:31:19 + --> $DIR/needless_collect.rs:29: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:34: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:35:19 + --> $DIR/needless_collect.rs:33:19 | LL | sample.iter().collect::>().is_empty(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:40:27 + --> $DIR/needless_collect.rs:38: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:41:27 + --> $DIR/needless_collect.rs:39: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:63:27 + --> $DIR/needless_collect.rs:61: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:64:27 + --> $DIR/needless_collect.rs:62: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:68:40 + --> $DIR/needless_collect.rs:66:40 | LL | Vec::::new().extend((0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:69:20 + --> $DIR/needless_collect.rs:67:20 | LL | foo((0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:70:49 + --> $DIR/needless_collect.rs:68:49 | LL | bar((0..10).collect::>(), (0..10).collect::>()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this call error: avoid using `collect()` when not needed - --> $DIR/needless_collect.rs:71:37 + --> $DIR/needless_collect.rs:69:37 | LL | baz((0..10), (), ('a'..='z').collect::>()) | ^^^^^^^^^^^^^^^^^^^^ help: remove this call diff --git a/src/tools/clippy/tests/ui/needless_collect_indirect.rs b/src/tools/clippy/tests/ui/needless_collect_indirect.rs index d3d856c2c..9d66c5f25 100644 --- a/src/tools/clippy/tests/ui/needless_collect_indirect.rs +++ b/src/tools/clippy/tests/ui/needless_collect_indirect.rs @@ -1,18 +1,23 @@ #![allow(clippy::uninlined_format_args, clippy::useless_vec)] #![allow(clippy::needless_if, clippy::uninlined_format_args)] #![warn(clippy::needless_collect)] - +//@no-rustfix use std::collections::{BinaryHeap, HashMap, HashSet, LinkedList, VecDeque}; fn main() { let sample = [1; 5]; let indirect_iter = sample.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed + //~| NOTE: `-D clippy::needless-collect` implied by `-D warnings` indirect_iter.into_iter().map(|x| (x, x + 1)).collect::>(); let indirect_len = sample.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed indirect_len.len(); let indirect_empty = sample.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed indirect_empty.is_empty(); let indirect_contains = sample.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed indirect_contains.contains(&&5); let indirect_negative = sample.iter().collect::>(); indirect_negative.len(); @@ -25,6 +30,7 @@ fn main() { let a = "a".to_string(); let sample = vec![a.clone(), "b".to_string(), "c".to_string()]; let non_copy_contains = sample.into_iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed non_copy_contains.contains(&a); // Fix #5991 @@ -54,21 +60,25 @@ mod issue7110 { fn lint_vec(string: &str) -> usize { let buffer: Vec<&str> = string.split('/').collect(); + //~^ ERROR: avoid using `collect()` when not needed buffer.len() } fn lint_vec_deque() -> usize { let sample = [1; 5]; let indirect_len: VecDeque<_> = sample.iter().collect(); + //~^ ERROR: avoid using `collect()` when not needed indirect_len.len() } fn lint_linked_list() -> usize { let sample = [1; 5]; let indirect_len: LinkedList<_> = sample.iter().collect(); + //~^ ERROR: avoid using `collect()` when not needed indirect_len.len() } fn lint_binary_heap() -> usize { let sample = [1; 5]; let indirect_len: BinaryHeap<_> = sample.iter().collect(); + //~^ ERROR: avoid using `collect()` when not needed indirect_len.len() } fn dont_lint(string: &str) -> usize { @@ -129,6 +139,7 @@ mod issue_8553 { for i in 0..2 { let y: Vec = vec.iter().map(|k| k * k).collect(); + //~^ ERROR: avoid using `collect()` when not needed let z: Vec = vec.iter().map(|k| k * k).collect(); // Do lint y.contains(&i); @@ -154,6 +165,7 @@ mod issue_8553 { while n > 2 { let y: Vec = vec.iter().map(|k| k * k).collect(); + //~^ ERROR: avoid using `collect()` when not needed let z: Vec = vec.iter().map(|k| k * k).collect(); // Do lint y.contains(&n); @@ -183,6 +195,7 @@ mod issue_8553 { loop { if n < 2 { let y: Vec = vec.iter().map(|k| k * k).collect(); + //~^ ERROR: avoid using `collect()` when not needed let z: Vec = vec.iter().map(|k| k * k).collect(); // Do lint y.contains(&n); @@ -219,6 +232,7 @@ mod issue_8553 { while let Some(value) = optional { let y: Vec = vec.iter().map(|k| k * k).collect(); + //~^ ERROR: avoid using `collect()` when not needed let z: Vec = vec.iter().map(|k| k * k).collect(); if n < 2 { // Do lint @@ -244,6 +258,7 @@ mod issue_8553 { let vec = vec![1, 2]; let v: Vec = vec.iter().map(|i| i * i).collect(); let w = v.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed // Do lint for _ in 0..w.len() { todo!(); @@ -266,6 +281,7 @@ mod issue_8553 { let mut vec = vec![1, 2]; let mut v: Vec = vec.iter().map(|i| i * i).collect(); let mut w = v.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed // Do lint while 1 == w.len() { todo!(); @@ -288,6 +304,7 @@ mod issue_8553 { let mut vec = vec![1, 2]; let mut v: Vec = vec.iter().map(|i| i * i).collect(); let mut w = v.iter().collect::>(); + //~^ ERROR: avoid using `collect()` when not needed // Do lint while let Some(i) = Some(w.len()) { todo!(); diff --git a/src/tools/clippy/tests/ui/needless_collect_indirect.stderr b/src/tools/clippy/tests/ui/needless_collect_indirect.stderr index 8f84c5596..3d1ad2a1c 100644 --- a/src/tools/clippy/tests/ui/needless_collect_indirect.stderr +++ b/src/tools/clippy/tests/ui/needless_collect_indirect.stderr @@ -3,130 +3,150 @@ error: avoid using `collect()` when not needed | LL | let indirect_iter = sample.iter().collect::>(); | ^^^^^^^ +... LL | indirect_iter.into_iter().map(|x| (x, x + 1)).collect::>(); | ------------------------- the iterator could be used here instead | = note: `-D clippy::needless-collect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_collect)]` help: use the original Iterator instead of collecting it and then producing a new one | LL ~ +LL | +LL | LL ~ sample.iter().map(|x| (x, x + 1)).collect::>(); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:11:38 + --> $DIR/needless_collect_indirect.rs:13:38 | LL | let indirect_len = sample.iter().collect::>(); | ^^^^^^^ +LL | LL | indirect_len.len(); | ------------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ sample.iter().count(); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:13:40 + --> $DIR/needless_collect_indirect.rs:16:40 | LL | let indirect_empty = sample.iter().collect::>(); | ^^^^^^^ +LL | LL | indirect_empty.is_empty(); | ------------------------- the iterator could be used here instead | help: check if the original Iterator has anything instead of collecting it and seeing if it's empty | LL ~ +LL | LL ~ sample.iter().next().is_none(); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:15:43 + --> $DIR/needless_collect_indirect.rs:19:43 | LL | let indirect_contains = sample.iter().collect::>(); | ^^^^^^^ +LL | LL | indirect_contains.contains(&&5); | ------------------------------- the iterator could be used here instead | help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL ~ sample.iter().any(|x| x == &5); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:27:48 + --> $DIR/needless_collect_indirect.rs:32:48 | LL | let non_copy_contains = sample.into_iter().collect::>(); | ^^^^^^^ +LL | LL | non_copy_contains.contains(&a); | ------------------------------ the iterator could be used here instead | help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL ~ sample.into_iter().any(|x| x == a); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:56:51 + --> $DIR/needless_collect_indirect.rs:62:51 | LL | let buffer: Vec<&str> = string.split('/').collect(); | ^^^^^^^ +LL | LL | buffer.len() | ------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ string.split('/').count() | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:61:55 + --> $DIR/needless_collect_indirect.rs:68:55 | LL | let indirect_len: VecDeque<_> = sample.iter().collect(); | ^^^^^^^ +LL | LL | indirect_len.len() | ------------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:66:57 + --> $DIR/needless_collect_indirect.rs:74:57 | LL | let indirect_len: LinkedList<_> = sample.iter().collect(); | ^^^^^^^ +LL | LL | indirect_len.len() | ------------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:71:57 + --> $DIR/needless_collect_indirect.rs:80:57 | LL | let indirect_len: BinaryHeap<_> = sample.iter().collect(); | ^^^^^^^ +LL | LL | indirect_len.len() | ------------------ the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL ~ sample.iter().count() | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:131:59 + --> $DIR/needless_collect_indirect.rs:141:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -137,13 +157,14 @@ LL | y.contains(&i); help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL | let z: Vec = vec.iter().map(|k| k * k).collect(); LL | // Do lint LL ~ vec.iter().map(|k| k * k).any(|x| x == i); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:156:59 + --> $DIR/needless_collect_indirect.rs:167:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -154,13 +175,14 @@ LL | y.contains(&n); help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL | let z: Vec = vec.iter().map(|k| k * k).collect(); LL | // Do lint LL ~ vec.iter().map(|k| k * k).any(|x| x == n); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:185:63 + --> $DIR/needless_collect_indirect.rs:197:63 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -171,13 +193,14 @@ LL | y.contains(&n); help: check if the original Iterator contains an element instead of collecting then checking | LL ~ +LL | LL | let z: Vec = vec.iter().map(|k| k * k).collect(); LL | // Do lint LL ~ vec.iter().map(|k| k * k).any(|x| x == n); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:221:59 + --> $DIR/needless_collect_indirect.rs:234:59 | LL | let y: Vec = vec.iter().map(|k| k * k).collect(); | ^^^^^^^ @@ -188,56 +211,59 @@ LL | y.contains(&n); help: check if the original Iterator contains an element instead of collecting then checking | LL ~ -LL | let z: Vec = vec.iter().map(|k| k * k).collect(); -LL | if n < 2 { +LL | + ... LL | // Do lint LL ~ vec.iter().map(|k| k * k).any(|x| x == n); | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:246:26 + --> $DIR/needless_collect_indirect.rs:260:26 | LL | let w = v.iter().collect::>(); | ^^^^^^^ -LL | // Do lint +... LL | for _ in 0..w.len() { | ------- the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL | // Do lint LL ~ for _ in 0..v.iter().count() { | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:268:30 + --> $DIR/needless_collect_indirect.rs:283:30 | LL | let mut w = v.iter().collect::>(); | ^^^^^^^ -LL | // Do lint +... LL | while 1 == w.len() { | ------- the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL | // Do lint LL ~ while 1 == v.iter().count() { | error: avoid using `collect()` when not needed - --> $DIR/needless_collect_indirect.rs:290:30 + --> $DIR/needless_collect_indirect.rs:306:30 | LL | let mut w = v.iter().collect::>(); | ^^^^^^^ -LL | // Do lint +... LL | while let Some(i) = Some(w.len()) { | ------- the iterator could be used here instead | help: take the original Iterator's count instead of collecting it and finding the length | LL ~ +LL | LL | // Do lint LL ~ while let Some(i) = Some(v.iter().count()) { | diff --git a/src/tools/clippy/tests/ui/needless_continue.rs b/src/tools/clippy/tests/ui/needless_continue.rs index c891c9de3..c26a292c8 100644 --- a/src/tools/clippy/tests/ui/needless_continue.rs +++ b/src/tools/clippy/tests/ui/needless_continue.rs @@ -28,6 +28,7 @@ fn main() { let i = 0; println!("bar {} ", i); } else { + //~^ ERROR: this `else` block is redundant continue; } @@ -43,6 +44,7 @@ fn main() { } if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { + //~^ ERROR: there is no need for an explicit `else` block for this `if` expression continue; } else { println!("Blabber"); @@ -55,21 +57,24 @@ fn main() { fn simple_loop() { loop { - continue; // should lint here + continue; + //~^ ERROR: this `continue` expression is redundant } } fn simple_loop2() { loop { println!("bleh"); - continue; // should lint here + continue; + //~^ ERROR: this `continue` expression is redundant } } #[rustfmt::skip] fn simple_loop3() { loop { - continue // should lint here + continue + //~^ ERROR: this `continue` expression is redundant } } @@ -77,7 +82,8 @@ fn simple_loop3() { fn simple_loop4() { loop { println!("bleh"); - continue // should lint here + continue + //~^ ERROR: this `continue` expression is redundant } } @@ -128,13 +134,15 @@ mod issue_2329 { if condition() { println!("bar-3"); } else { - continue 'inner; // should lint here + //~^ ERROR: this `else` block is redundant + continue 'inner; } println!("bar-4"); update_condition(); if condition() { - continue; // should lint here + //~^ ERROR: there is no need for an explicit `else` block for this `if` ex + continue; } else { println!("bar-5"); } diff --git a/src/tools/clippy/tests/ui/needless_continue.stderr b/src/tools/clippy/tests/ui/needless_continue.stderr index d99989b54..31b5dc280 100644 --- a/src/tools/clippy/tests/ui/needless_continue.stderr +++ b/src/tools/clippy/tests/ui/needless_continue.stderr @@ -3,6 +3,7 @@ error: this `else` block is redundant | LL | } else { | ________________^ +LL | | LL | | continue; LL | | } | |_________^ @@ -25,6 +26,7 @@ LL | | } println!("lama"); } if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { + continue; } else { println!("Blabber"); @@ -33,11 +35,13 @@ LL | | } println!("bleh"); } = note: `-D clippy::needless-continue` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_continue)]` error: there is no need for an explicit `else` block for this `if` expression - --> $DIR/needless_continue.rs:45:9 + --> $DIR/needless_continue.rs:46:9 | LL | / if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { +LL | | LL | | continue; LL | | } else { LL | | println!("Blabber"); @@ -47,6 +51,7 @@ LL | | } | = help: consider dropping the `else` clause if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 { + continue; } { @@ -55,43 +60,44 @@ LL | | } } error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:58:9 + --> $DIR/needless_continue.rs:60:9 | -LL | continue; // should lint here +LL | continue; | ^^^^^^^^^ | = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:65:9 + --> $DIR/needless_continue.rs:68:9 | -LL | continue; // should lint here +LL | continue; | ^^^^^^^^^ | = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:72:9 + --> $DIR/needless_continue.rs:76:9 | -LL | continue // should lint here +LL | continue | ^^^^^^^^ | = help: consider dropping the `continue` expression error: this `continue` expression is redundant - --> $DIR/needless_continue.rs:80:9 + --> $DIR/needless_continue.rs:85:9 | -LL | continue // should lint here +LL | continue | ^^^^^^^^ | = help: consider dropping the `continue` expression error: this `else` block is redundant - --> $DIR/needless_continue.rs:130:24 + --> $DIR/needless_continue.rs:136:24 | LL | } else { | ________________________^ -LL | | continue 'inner; // should lint here +LL | | +LL | | continue 'inner; LL | | } | |_________________^ | @@ -102,7 +108,8 @@ LL | | } println!("bar-4"); update_condition(); if condition() { - continue; // should lint here + + continue; } else { println!("bar-5"); } @@ -110,10 +117,11 @@ LL | | } } error: there is no need for an explicit `else` block for this `if` expression - --> $DIR/needless_continue.rs:136:17 + --> $DIR/needless_continue.rs:143:17 | LL | / if condition() { -LL | | continue; // should lint here +LL | | +LL | | continue; LL | | } else { LL | | println!("bar-5"); LL | | } @@ -121,7 +129,8 @@ LL | | } | = help: consider dropping the `else` clause if condition() { - continue; // should lint here + + continue; } { println!("bar-5"); diff --git a/src/tools/clippy/tests/ui/needless_doc_main.rs b/src/tools/clippy/tests/ui/needless_doc_main.rs index 83e9bbaa3..fee05926c 100644 --- a/src/tools/clippy/tests/ui/needless_doc_main.rs +++ b/src/tools/clippy/tests/ui/needless_doc_main.rs @@ -5,6 +5,8 @@ /// This should lint /// ``` /// fn main() { +//~^ ERROR: needless `fn main` in doctest +//~| NOTE: `-D clippy::needless-doctest-main` implied by `-D warnings` /// unimplemented!(); /// } /// ``` @@ -12,6 +14,7 @@ /// With an explicit return type it should lint too /// ```edition2015 /// fn main() -> () { +//~^ ERROR: needless `fn main` in doctest /// unimplemented!(); /// } /// ``` @@ -19,12 +22,15 @@ /// This should, too. /// ```rust /// fn main() { +//~^ ERROR: needless `fn main` in doctest /// unimplemented!(); /// } /// ``` /// /// This one too. /// ```no_run +/// // the fn is not always the first line +//~^ ERROR: needless `fn main` in doctest /// fn main() { /// unimplemented!(); /// } diff --git a/src/tools/clippy/tests/ui/needless_doc_main.stderr b/src/tools/clippy/tests/ui/needless_doc_main.stderr index 05c7f9d33..842565486 100644 --- a/src/tools/clippy/tests/ui/needless_doc_main.stderr +++ b/src/tools/clippy/tests/ui/needless_doc_main.stderr @@ -1,28 +1,47 @@ error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:7:4 + --> $DIR/needless_doc_main.rs:7:5 | -LL | /// fn main() { - | ^^^^^^^^^^^^ +LL | /// fn main() { + | _____^ +LL | | +LL | | +LL | | /// unimplemented!(); +LL | | /// } + | |_____^ | = note: `-D clippy::needless-doctest-main` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_doctest_main)]` error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:14:4 + --> $DIR/needless_doc_main.rs:16:5 | -LL | /// fn main() -> () { - | ^^^^^^^^^^^^^^^^^^ +LL | /// fn main() -> () { + | _____^ +LL | | +LL | | /// unimplemented!(); +LL | | /// } + | |_____^ error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:21:4 + --> $DIR/needless_doc_main.rs:24:5 | -LL | /// fn main() { - | ^^^^^^^^^^^^ +LL | /// fn main() { + | _____^ +LL | | +LL | | /// unimplemented!(); +LL | | /// } + | |_____^ error: needless `fn main` in doctest - --> $DIR/needless_doc_main.rs:28:4 + --> $DIR/needless_doc_main.rs:32:5 | -LL | /// fn main() { - | ^^^^^^^^^^^^ +LL | /// // the fn is not always the first line + | _____^ +LL | | +LL | | /// fn main() { +LL | | /// unimplemented!(); +LL | | /// } + | |_____^ error: aborting due to 4 previous errors diff --git a/src/tools/clippy/tests/ui/needless_else.fixed b/src/tools/clippy/tests/ui/needless_else.fixed index 06a161627..240b79bae 100644 --- a/src/tools/clippy/tests/ui/needless_else.fixed +++ b/src/tools/clippy/tests/ui/needless_else.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::needless_else)] #![allow(clippy::suspicious_else_formatting)] diff --git a/src/tools/clippy/tests/ui/needless_else.rs b/src/tools/clippy/tests/ui/needless_else.rs index 728032c47..ad84da170 100644 --- a/src/tools/clippy/tests/ui/needless_else.rs +++ b/src/tools/clippy/tests/ui/needless_else.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::needless_else)] #![allow(clippy::suspicious_else_formatting)] diff --git a/src/tools/clippy/tests/ui/needless_else.stderr b/src/tools/clippy/tests/ui/needless_else.stderr index 49cd78501..e6f7138e9 100644 --- a/src/tools/clippy/tests/ui/needless_else.stderr +++ b/src/tools/clippy/tests/ui/needless_else.stderr @@ -1,5 +1,5 @@ error: this `else` branch is empty - --> $DIR/needless_else.rs:24:7 + --> $DIR/needless_else.rs:23:7 | LL | } else { | _______^ @@ -7,6 +7,7 @@ LL | | } | |_____^ help: you can remove it | = note: `-D clippy::needless-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_else)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/needless_for_each_fixable.fixed b/src/tools/clippy/tests/ui/needless_for_each_fixable.fixed index 92572942b..8c0e7ba76 100644 --- a/src/tools/clippy/tests/ui/needless_for_each_fixable.fixed +++ b/src/tools/clippy/tests/ui/needless_for_each_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::needless_for_each)] #![allow(unused)] #![allow( diff --git a/src/tools/clippy/tests/ui/needless_for_each_fixable.rs b/src/tools/clippy/tests/ui/needless_for_each_fixable.rs index 95acbdff8..cdc903a63 100644 --- a/src/tools/clippy/tests/ui/needless_for_each_fixable.rs +++ b/src/tools/clippy/tests/ui/needless_for_each_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::needless_for_each)] #![allow(unused)] #![allow( diff --git a/src/tools/clippy/tests/ui/needless_for_each_fixable.stderr b/src/tools/clippy/tests/ui/needless_for_each_fixable.stderr index aebb762cc..3b5163b01 100644 --- a/src/tools/clippy/tests/ui/needless_for_each_fixable.stderr +++ b/src/tools/clippy/tests/ui/needless_for_each_fixable.stderr @@ -1,5 +1,5 @@ error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:16:5 + --> $DIR/needless_for_each_fixable.rs:15:5 | LL | / v.iter().for_each(|elem| { LL | | acc += elem; @@ -7,6 +7,7 @@ LL | | }); | |_______^ | = note: `-D clippy::needless-for-each` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_for_each)]` help: try | LL ~ for elem in v.iter() { @@ -15,7 +16,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:19:5 + --> $DIR/needless_for_each_fixable.rs:18:5 | LL | / v.into_iter().for_each(|elem| { LL | | acc += elem; @@ -30,7 +31,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:23:5 + --> $DIR/needless_for_each_fixable.rs:22:5 | LL | / [1, 2, 3].iter().for_each(|elem| { LL | | acc += elem; @@ -45,7 +46,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:28:5 + --> $DIR/needless_for_each_fixable.rs:27:5 | LL | / hash_map.iter().for_each(|(k, v)| { LL | | acc += k + v; @@ -60,7 +61,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:31:5 + --> $DIR/needless_for_each_fixable.rs:30:5 | LL | / hash_map.iter_mut().for_each(|(k, v)| { LL | | acc += *k + *v; @@ -75,7 +76,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:34:5 + --> $DIR/needless_for_each_fixable.rs:33:5 | LL | / hash_map.keys().for_each(|k| { LL | | acc += k; @@ -90,7 +91,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:37:5 + --> $DIR/needless_for_each_fixable.rs:36:5 | LL | / hash_map.values().for_each(|v| { LL | | acc += v; @@ -105,7 +106,7 @@ LL + } | error: needless use of `for_each` - --> $DIR/needless_for_each_fixable.rs:44:5 + --> $DIR/needless_for_each_fixable.rs:43:5 | LL | / my_vec().iter().for_each(|elem| { LL | | acc += elem; diff --git a/src/tools/clippy/tests/ui/needless_for_each_unfixable.rs b/src/tools/clippy/tests/ui/needless_for_each_unfixable.rs index 282c72881..2220cf9e1 100644 --- a/src/tools/clippy/tests/ui/needless_for_each_unfixable.rs +++ b/src/tools/clippy/tests/ui/needless_for_each_unfixable.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::needless_for_each)] #![allow(clippy::needless_return, clippy::uninlined_format_args)] @@ -5,6 +6,8 @@ fn main() { let v: Vec = Vec::new(); // This is unfixable because the closure includes `return`. v.iter().for_each(|v| { + //~^ ERROR: needless use of `for_each` + //~| NOTE: `-D clippy::needless-for-each` implied by `-D warnings` if *v == 10 { return; } else { diff --git a/src/tools/clippy/tests/ui/needless_for_each_unfixable.stderr b/src/tools/clippy/tests/ui/needless_for_each_unfixable.stderr index 7893ff31a..73f249ae6 100644 --- a/src/tools/clippy/tests/ui/needless_for_each_unfixable.stderr +++ b/src/tools/clippy/tests/ui/needless_for_each_unfixable.stderr @@ -1,19 +1,22 @@ error: needless use of `for_each` - --> $DIR/needless_for_each_unfixable.rs:7:5 + --> $DIR/needless_for_each_unfixable.rs:8:5 | LL | / v.iter().for_each(|v| { +LL | | +LL | | LL | | if *v == 10 { -LL | | return; -LL | | } else { -LL | | println!("{}", v); +... | LL | | } LL | | }); | |_______^ | = note: `-D clippy::needless-for-each` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_for_each)]` help: try | LL ~ for v in v.iter() { +LL + +LL + LL + if *v == 10 { LL + return; LL + } else { diff --git a/src/tools/clippy/tests/ui/needless_if.fixed b/src/tools/clippy/tests/ui/needless_if.fixed index 6001c9e93..b84182c57 100644 --- a/src/tools/clippy/tests/ui/needless_if.fixed +++ b/src/tools/clippy/tests/ui/needless_if.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(let_chains)] #![allow( clippy::blocks_in_if_conditions, diff --git a/src/tools/clippy/tests/ui/needless_if.rs b/src/tools/clippy/tests/ui/needless_if.rs index c6be4766d..6c6023c72 100644 --- a/src/tools/clippy/tests/ui/needless_if.rs +++ b/src/tools/clippy/tests/ui/needless_if.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(let_chains)] #![allow( clippy::blocks_in_if_conditions, diff --git a/src/tools/clippy/tests/ui/needless_if.stderr b/src/tools/clippy/tests/ui/needless_if.stderr index 14de40095..ed5b9452b 100644 --- a/src/tools/clippy/tests/ui/needless_if.stderr +++ b/src/tools/clippy/tests/ui/needless_if.stderr @@ -1,19 +1,20 @@ error: this `if` branch is empty - --> $DIR/needless_if.rs:27:5 + --> $DIR/needless_if.rs:26:5 | LL | if (true) {} | ^^^^^^^^^^^^ help: you can remove it | = note: `-D clippy::needless-if` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_if)]` error: this `if` branch is empty - --> $DIR/needless_if.rs:29:5 + --> $DIR/needless_if.rs:28:5 | 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:33:5 | LL | / if { LL | | return; @@ -28,7 +29,7 @@ LL + }); | error: this `if` branch is empty - --> $DIR/needless_if.rs:46:5 + --> $DIR/needless_if.rs:45:5 | LL | / if { LL | | if let true = true && true { true } else { false } @@ -44,19 +45,19 @@ LL + } && true); | error: this `if` branch is empty - --> $DIR/needless_if.rs:84:5 + --> $DIR/needless_if.rs:83:5 | LL | if { maybe_side_effect() } {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `({ maybe_side_effect() });` error: this `if` branch is empty - --> $DIR/needless_if.rs:86:5 + --> $DIR/needless_if.rs:85: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:90:5 + --> $DIR/needless_if.rs:89:5 | LL | if true {} | ^^^^^^^^^^ help: you can remove it: `true;` diff --git a/src/tools/clippy/tests/ui/needless_late_init.fixed b/src/tools/clippy/tests/ui/needless_late_init.fixed index 933dd8bed..9f45da048 100644 --- a/src/tools/clippy/tests/ui/needless_late_init.fixed +++ b/src/tools/clippy/tests/ui/needless_late_init.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(let_chains)] #![allow(unused)] #![allow( diff --git a/src/tools/clippy/tests/ui/needless_late_init.rs b/src/tools/clippy/tests/ui/needless_late_init.rs index ba3a04e08..0dab0faad 100644 --- a/src/tools/clippy/tests/ui/needless_late_init.rs +++ b/src/tools/clippy/tests/ui/needless_late_init.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(let_chains)] #![allow(unused)] #![allow( diff --git a/src/tools/clippy/tests/ui/needless_late_init.stderr b/src/tools/clippy/tests/ui/needless_late_init.stderr index 78ba8e11c..602b1a683 100644 --- a/src/tools/clippy/tests/ui/needless_late_init.stderr +++ b/src/tools/clippy/tests/ui/needless_late_init.stderr @@ -1,5 +1,5 @@ error: unneeded late initialization - --> $DIR/needless_late_init.rs:28:5 + --> $DIR/needless_late_init.rs:27:5 | LL | let a; | ^^^^^^ created here @@ -7,13 +7,14 @@ LL | a = "zero"; | ^^^^^^^^^^ initialised here | = note: `-D clippy::needless-late-init` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_late_init)]` help: declare `a` here | LL | let a = "zero"; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:31:5 + --> $DIR/needless_late_init.rs:30:5 | LL | let b; | ^^^^^^ created here @@ -27,7 +28,7 @@ LL | let b = 1; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:32:5 + --> $DIR/needless_late_init.rs:31:5 | LL | let c; | ^^^^^^ created here @@ -41,7 +42,7 @@ LL | let c = 2; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:36:5 + --> $DIR/needless_late_init.rs:35:5 | LL | let d: usize; | ^^^^^^^^^^^^^ created here @@ -54,7 +55,7 @@ LL | let d: usize = 1; | ~~~~~~~~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:39:5 + --> $DIR/needless_late_init.rs:38:5 | LL | let e; | ^^^^^^ created here @@ -67,7 +68,7 @@ LL | let e = format!("{}", d); | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:44:5 + --> $DIR/needless_late_init.rs:43:5 | LL | let a; | ^^^^^^ @@ -88,7 +89,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:53:5 + --> $DIR/needless_late_init.rs:52:5 | LL | let b; | ^^^^^^ @@ -109,7 +110,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:60:5 + --> $DIR/needless_late_init.rs:59:5 | LL | let d; | ^^^^^^ @@ -130,7 +131,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:68:5 + --> $DIR/needless_late_init.rs:67:5 | LL | let e; | ^^^^^^ @@ -151,7 +152,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:75:5 + --> $DIR/needless_late_init.rs:74:5 | LL | let f; | ^^^^^^ @@ -167,7 +168,7 @@ LL + 1 => "three", | error: unneeded late initialization - --> $DIR/needless_late_init.rs:81:5 + --> $DIR/needless_late_init.rs:80:5 | LL | let g: usize; | ^^^^^^^^^^^^^ @@ -187,7 +188,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:89:5 + --> $DIR/needless_late_init.rs:88:5 | LL | let x; | ^^^^^^ created here @@ -201,7 +202,7 @@ LL | let x = 1; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:93:5 + --> $DIR/needless_late_init.rs:92:5 | LL | let x; | ^^^^^^ created here @@ -215,7 +216,7 @@ LL | let x = SignificantDrop; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:97:5 + --> $DIR/needless_late_init.rs:96:5 | LL | let x; | ^^^^^^ created here @@ -229,7 +230,7 @@ LL | let x = SignificantDrop; | ~~~~~ error: unneeded late initialization - --> $DIR/needless_late_init.rs:116:5 + --> $DIR/needless_late_init.rs:115:5 | LL | let a; | ^^^^^^ @@ -250,7 +251,7 @@ LL | }; | + error: unneeded late initialization - --> $DIR/needless_late_init.rs:133:5 + --> $DIR/needless_late_init.rs:132:5 | LL | let a; | ^^^^^^ diff --git a/src/tools/clippy/tests/ui/needless_lifetimes.fixed b/src/tools/clippy/tests/ui/needless_lifetimes.fixed index 302a3f9ed..d1787b35a 100644 --- a/src/tools/clippy/tests/ui/needless_lifetimes.fixed +++ b/src/tools/clippy/tests/ui/needless_lifetimes.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::needless_lifetimes)] #![allow( diff --git a/src/tools/clippy/tests/ui/needless_lifetimes.rs b/src/tools/clippy/tests/ui/needless_lifetimes.rs index b15477c92..03d6f2013 100644 --- a/src/tools/clippy/tests/ui/needless_lifetimes.rs +++ b/src/tools/clippy/tests/ui/needless_lifetimes.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::needless_lifetimes)] #![allow( diff --git a/src/tools/clippy/tests/ui/needless_lifetimes.stderr b/src/tools/clippy/tests/ui/needless_lifetimes.stderr index 0da67b600..7051a2604 100644 --- a/src/tools/clippy/tests/ui/needless_lifetimes.stderr +++ b/src/tools/clippy/tests/ui/needless_lifetimes.stderr @@ -1,10 +1,11 @@ error: the following explicit lifetimes could be elided: 'a, 'b - --> $DIR/needless_lifetimes.rs:18:23 + --> $DIR/needless_lifetimes.rs:17:23 | LL | fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {} | ^^ ^^ ^^ ^^ | = note: `-D clippy::needless-lifetimes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_lifetimes)]` help: elide the lifetimes | LL - fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {} @@ -12,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:20:24 + --> $DIR/needless_lifetimes.rs:19:24 | LL | fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {} | ^^ ^^ ^^ ^^ @@ -24,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:30:15 + --> $DIR/needless_lifetimes.rs:29:15 | LL | fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { | ^^ ^^ ^^ @@ -36,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:42:31 + --> $DIR/needless_lifetimes.rs:41:31 | LL | fn multiple_in_and_out_2a<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { | ^^ ^^ @@ -48,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:49:27 + --> $DIR/needless_lifetimes.rs:48:27 | LL | fn multiple_in_and_out_2b<'a, 'b>(_x: &'a u8, y: &'b u8) -> &'b u8 { | ^^ ^^ @@ -60,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:66:26 + --> $DIR/needless_lifetimes.rs:65:26 | LL | fn deep_reference_1a<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { | ^^ ^^ @@ -72,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:73:22 + --> $DIR/needless_lifetimes.rs:72:22 | LL | fn deep_reference_1b<'a, 'b>(_x: &'a u8, y: &'b u8) -> Result<&'b u8, ()> { | ^^ ^^ @@ -84,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:82:21 + --> $DIR/needless_lifetimes.rs:81:21 | LL | fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { | ^^ ^^ ^^ @@ -96,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:87:28 + --> $DIR/needless_lifetimes.rs:86:28 | LL | fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> | ^^ ^^ ^^ @@ -108,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:99:21 + --> $DIR/needless_lifetimes.rs:98:21 | LL | fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {} | ^^ ^^ ^^ ^^ @@ -120,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:123:15 + --> $DIR/needless_lifetimes.rs:122:15 | LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I> | ^^ ^^ ^^ @@ -132,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:153:21 + --> $DIR/needless_lifetimes.rs:152:21 | LL | fn self_and_out<'s>(&'s self) -> &'s u8 { | ^^ ^^ ^^ @@ -144,7 +145,7 @@ LL + fn self_and_out(&self) -> &u8 { | error: the following explicit lifetimes could be elided: 't - --> $DIR/needless_lifetimes.rs:160:30 + --> $DIR/needless_lifetimes.rs:159:30 | LL | fn self_and_in_out_1<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 { | ^^ ^^ @@ -156,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:167:26 + --> $DIR/needless_lifetimes.rs:166:26 | LL | fn self_and_in_out_2<'s, 't>(&'s self, x: &'t u8) -> &'t u8 { | ^^ ^^ @@ -168,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:171:29 + --> $DIR/needless_lifetimes.rs:170:29 | LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {} | ^^ ^^ ^^ ^^ @@ -180,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:190:19 + --> $DIR/needless_lifetimes.rs:189:19 | LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { | ^^ ^^ ^^ @@ -192,7 +193,7 @@ LL + fn struct_with_lt(_foo: Foo<'_>) -> &str { | error: the following explicit lifetimes could be elided: 'b - --> $DIR/needless_lifetimes.rs:208:25 + --> $DIR/needless_lifetimes.rs:207:25 | LL | fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str { | ^^ ^^ @@ -204,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:216:21 + --> $DIR/needless_lifetimes.rs:215:21 | LL | fn struct_with_lt4b<'a, 'b>(_foo: &'a Foo<'b>) -> &'b str { | ^^ ^^ @@ -216,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:231:22 + --> $DIR/needless_lifetimes.rs:230:22 | LL | fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str { | ^^ ^^ ^^ @@ -228,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:237:18 + --> $DIR/needless_lifetimes.rs:236:18 | LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { | ^^ ^^ ^^ @@ -240,7 +241,7 @@ LL + fn alias_with_lt(_foo: FooAlias<'_>) -> &str { | error: the following explicit lifetimes could be elided: 'b - --> $DIR/needless_lifetimes.rs:255:24 + --> $DIR/needless_lifetimes.rs:254:24 | LL | fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str { | ^^ ^^ @@ -252,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:263:20 + --> $DIR/needless_lifetimes.rs:262:20 | LL | fn alias_with_lt4b<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'b str { | ^^ ^^ @@ -264,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:267:30 + --> $DIR/needless_lifetimes.rs:266:30 | LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { | ^^ ^^ ^ @@ -276,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:275:19 + --> $DIR/needless_lifetimes.rs:274:19 | LL | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { | ^^ ^^ @@ -288,7 +289,7 @@ LL + fn trait_bound_ok>(_: &u8, _: T) { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:311:24 + --> $DIR/needless_lifetimes.rs:310:24 | LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> { | ^^ ^^ ^^ @@ -300,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:318:24 + --> $DIR/needless_lifetimes.rs:317:24 | LL | fn needless_lt<'a>(x: &'a u8) {} | ^^ ^^ @@ -312,7 +313,7 @@ LL + fn needless_lt(x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:322:24 + --> $DIR/needless_lifetimes.rs:321:24 | LL | fn needless_lt<'a>(_x: &'a u8) {} | ^^ ^^ @@ -324,7 +325,7 @@ LL + fn needless_lt(_x: &u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:335:16 + --> $DIR/needless_lifetimes.rs:334:16 | LL | fn baz<'a>(&'a self) -> impl Foo + 'a { | ^^ ^^ ^^ @@ -336,7 +337,7 @@ LL + fn baz(&self) -> impl Foo + '_ { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:367:55 + --> $DIR/needless_lifetimes.rs:366:55 | LL | fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 { | ^^ ^^ ^^ @@ -348,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:376:26 + --> $DIR/needless_lifetimes.rs:375:26 | LL | fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 { | ^^ ^^ ^^ @@ -360,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:388:32 + --> $DIR/needless_lifetimes.rs:387:32 | LL | fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32 | ^^ ^^ ^^ @@ -372,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:403:28 + --> $DIR/needless_lifetimes.rs:402:28 | LL | fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 { | ^^ ^^ ^^ @@ -384,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:416:28 + --> $DIR/needless_lifetimes.rs:415:28 | LL | fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 { | ^^ ^^ @@ -396,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:419:28 + --> $DIR/needless_lifetimes.rs:418:28 | LL | fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) { | ^^ ^^ @@ -408,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:441:21 + --> $DIR/needless_lifetimes.rs:440:21 | LL | fn implicit<'a>(&'a self) -> &'a () { | ^^ ^^ ^^ @@ -420,7 +421,7 @@ LL + fn implicit(&self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:444:25 + --> $DIR/needless_lifetimes.rs:443:25 | LL | fn implicit_mut<'a>(&'a mut self) -> &'a () { | ^^ ^^ ^^ @@ -432,7 +433,7 @@ LL + fn implicit_mut(&mut self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:455:31 + --> $DIR/needless_lifetimes.rs:454:31 | LL | fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a () { | ^^ ^^ ^^ @@ -444,7 +445,7 @@ LL + fn lifetime_elsewhere(self: Box, here: &()) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:461:21 + --> $DIR/needless_lifetimes.rs:460:21 | LL | fn implicit<'a>(&'a self) -> &'a (); | ^^ ^^ ^^ @@ -456,7 +457,7 @@ LL + fn implicit(&self) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:462:30 + --> $DIR/needless_lifetimes.rs:461:30 | LL | fn implicit_provided<'a>(&'a self) -> &'a () { | ^^ ^^ ^^ @@ -468,7 +469,7 @@ LL + fn implicit_provided(&self) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:471:31 + --> $DIR/needless_lifetimes.rs:470:31 | LL | fn lifetime_elsewhere<'a>(self: Box, here: &'a ()) -> &'a (); | ^^ ^^ ^^ @@ -480,7 +481,7 @@ LL + fn lifetime_elsewhere(self: Box, here: &()) -> &(); | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:472:40 + --> $DIR/needless_lifetimes.rs:471:40 | LL | fn lifetime_elsewhere_provided<'a>(self: Box, here: &'a ()) -> &'a () { | ^^ ^^ ^^ @@ -492,7 +493,7 @@ LL + fn lifetime_elsewhere_provided(self: Box, here: &()) -> &() { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:481:12 + --> $DIR/needless_lifetimes.rs:480:12 | LL | fn foo<'a>(x: &'a u8, y: &'_ u8) {} | ^^ ^^ @@ -504,7 +505,7 @@ LL + fn foo(x: &u8, y: &'_ u8) {} | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:483:12 + --> $DIR/needless_lifetimes.rs:482:12 | LL | fn bar<'a>(x: &'a u8, y: &'_ u8, z: &'_ u8) {} | ^^ ^^ @@ -516,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:490:18 + --> $DIR/needless_lifetimes.rs:489:18 | LL | fn one_input<'a>(x: &'a u8) -> &'a u8 { | ^^ ^^ ^^ @@ -528,7 +529,7 @@ LL + fn one_input(x: &u8) -> &u8 { | error: the following explicit lifetimes could be elided: 'a - --> $DIR/needless_lifetimes.rs:495:42 + --> $DIR/needless_lifetimes.rs:494:42 | LL | fn multiple_inputs_output_not_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'b u8 { | ^^ ^^ @@ -540,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:511:22 + --> $DIR/needless_lifetimes.rs:510:22 | LL | fn one_input<'a>(x: &'a u8) -> &'a u8 { | ^^ ^^ ^^ diff --git a/src/tools/clippy/tests/ui/needless_match.fixed b/src/tools/clippy/tests/ui/needless_match.fixed index d8a0400a4..a936eb463 100644 --- a/src/tools/clippy/tests/ui/needless_match.fixed +++ b/src/tools/clippy/tests/ui/needless_match.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::needless_match)] #![allow(clippy::manual_map)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/needless_match.rs b/src/tools/clippy/tests/ui/needless_match.rs index 3de9bd6d7..b1dd6ff07 100644 --- a/src/tools/clippy/tests/ui/needless_match.rs +++ b/src/tools/clippy/tests/ui/needless_match.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::needless_match)] #![allow(clippy::manual_map)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/needless_match.stderr b/src/tools/clippy/tests/ui/needless_match.stderr index 28e78441c..736926b44 100644 --- a/src/tools/clippy/tests/ui/needless_match.stderr +++ b/src/tools/clippy/tests/ui/needless_match.stderr @@ -1,5 +1,5 @@ error: this match expression is unnecessary - --> $DIR/needless_match.rs:16:18 + --> $DIR/needless_match.rs:15:18 | LL | let _: i32 = match i { | __________________^ @@ -11,9 +11,10 @@ LL | | }; | |_____^ help: replace it with: `i` | = note: `-D clippy::needless-match` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_match)]` error: this match expression is unnecessary - --> $DIR/needless_match.rs:23:19 + --> $DIR/needless_match.rs:22:19 | LL | let _: &str = match s { | ___________________^ @@ -24,7 +25,7 @@ LL | | }; | |_____^ help: replace it with: `s` error: this match expression is unnecessary - --> $DIR/needless_match.rs:32:21 + --> $DIR/needless_match.rs:31:21 | LL | let _: Simple = match se { | _____________________^ @@ -36,7 +37,7 @@ LL | | }; | |_____^ help: replace it with: `se` error: this match expression is unnecessary - --> $DIR/needless_match.rs:54:26 + --> $DIR/needless_match.rs:53:26 | LL | let _: Option = match x { | __________________________^ @@ -46,7 +47,7 @@ LL | | }; | |_____^ help: replace it with: `x` error: this match expression is unnecessary - --> $DIR/needless_match.rs:70:31 + --> $DIR/needless_match.rs:69:31 | LL | let _: Result = match Ok(1) { | _______________________________^ @@ -56,7 +57,7 @@ LL | | }; | |_____^ help: replace it with: `Ok(1)` error: this match expression is unnecessary - --> $DIR/needless_match.rs:74:31 + --> $DIR/needless_match.rs:73:31 | LL | let _: Result = match func_ret_err(0_i32) { | _______________________________^ @@ -66,25 +67,25 @@ LL | | }; | |_____^ help: replace it with: `func_ret_err(0_i32)` error: this if-let expression is unnecessary - --> $DIR/needless_match.rs:87:13 + --> $DIR/needless_match.rs:86: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:122:31 + --> $DIR/needless_match.rs:121: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:123:31 + --> $DIR/needless_match.rs:122: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:130:21 + --> $DIR/needless_match.rs:129:21 | LL | let _: Simple = if let Simple::A = x { | _____________________^ @@ -97,7 +98,7 @@ LL | | }; | |_____^ help: replace it with: `x` error: this match expression is unnecessary - --> $DIR/needless_match.rs:169:26 + --> $DIR/needless_match.rs:168:26 | LL | let _: Complex = match ce { | __________________________^ @@ -110,7 +111,7 @@ LL | | }; | |_________^ help: replace it with: `ce` error: this match expression is unnecessary - --> $DIR/needless_match.rs:253:17 + --> $DIR/needless_match.rs:252:17 | LL | let _ = match e { | _________________^ @@ -120,7 +121,7 @@ LL | | }; | |_________^ help: replace it with: `e` error: this match expression is unnecessary - --> $DIR/needless_match.rs:259:17 + --> $DIR/needless_match.rs:258:17 | LL | let _ = match e { | _________________^ diff --git a/src/tools/clippy/tests/ui/needless_option_as_deref.fixed b/src/tools/clippy/tests/ui/needless_option_as_deref.fixed index ec981ad97..58f56eba0 100644 --- a/src/tools/clippy/tests/ui/needless_option_as_deref.fixed +++ b/src/tools/clippy/tests/ui/needless_option_as_deref.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::needless_option_as_deref)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/needless_option_as_deref.rs b/src/tools/clippy/tests/ui/needless_option_as_deref.rs index 6360874f6..842e025f6 100644 --- a/src/tools/clippy/tests/ui/needless_option_as_deref.rs +++ b/src/tools/clippy/tests/ui/needless_option_as_deref.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::needless_option_as_deref)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/needless_option_as_deref.stderr b/src/tools/clippy/tests/ui/needless_option_as_deref.stderr index 4c0d502a2..024d30c17 100644 --- a/src/tools/clippy/tests/ui/needless_option_as_deref.stderr +++ b/src/tools/clippy/tests/ui/needless_option_as_deref.stderr @@ -1,19 +1,20 @@ error: derefed type is same as origin - --> $DIR/needless_option_as_deref.rs:9:29 + --> $DIR/needless_option_as_deref.rs:7:29 | LL | let _: Option<&usize> = Some(&1).as_deref(); | ^^^^^^^^^^^^^^^^^^^ help: try: `Some(&1)` | = note: `-D clippy::needless-option-as-deref` implied by `-D warnings` + = 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:10:33 + --> $DIR/needless_option_as_deref.rs:8: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:14:13 + --> $DIR/needless_option_as_deref.rs:12:13 | LL | let _ = x.as_deref_mut(); | ^^^^^^^^^^^^^^^^ help: try: `x` diff --git a/src/tools/clippy/tests/ui/needless_option_take.fixed b/src/tools/clippy/tests/ui/needless_option_take.fixed index bfc6d20d5..d732a2686 100644 --- a/src/tools/clippy/tests/ui/needless_option_take.fixed +++ b/src/tools/clippy/tests/ui/needless_option_take.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - fn main() { println!("Testing non erroneous option_take_on_temporary"); let mut option = Some(1); diff --git a/src/tools/clippy/tests/ui/needless_option_take.rs b/src/tools/clippy/tests/ui/needless_option_take.rs index 697eeab42..f947d874e 100644 --- a/src/tools/clippy/tests/ui/needless_option_take.rs +++ b/src/tools/clippy/tests/ui/needless_option_take.rs @@ -1,5 +1,3 @@ -//@run-rustfix - fn main() { println!("Testing non erroneous option_take_on_temporary"); let mut option = Some(1); diff --git a/src/tools/clippy/tests/ui/needless_option_take.stderr b/src/tools/clippy/tests/ui/needless_option_take.stderr index cb3bf015b..d3c22441d 100644 --- a/src/tools/clippy/tests/ui/needless_option_take.stderr +++ b/src/tools/clippy/tests/ui/needless_option_take.stderr @@ -1,10 +1,11 @@ error: called `Option::take()` on a temporary value - --> $DIR/needless_option_take.rs:14:5 + --> $DIR/needless_option_take.rs:12:5 | LL | x.as_ref().take(); | ^^^^^^^^^^^^^^^^^ help: try: `x.as_ref()` | = note: `-D clippy::needless-option-take` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_option_take)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/needless_parens_on_range_literals.fixed b/src/tools/clippy/tests/ui/needless_parens_on_range_literals.fixed index 9b98f6ea7..b4d9e3297 100644 --- a/src/tools/clippy/tests/ui/needless_parens_on_range_literals.fixed +++ b/src/tools/clippy/tests/ui/needless_parens_on_range_literals.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@edition:2018 #![warn(clippy::needless_parens_on_range_literals)] diff --git a/src/tools/clippy/tests/ui/needless_parens_on_range_literals.rs b/src/tools/clippy/tests/ui/needless_parens_on_range_literals.rs index 088e7b2b9..2f0e54f80 100644 --- a/src/tools/clippy/tests/ui/needless_parens_on_range_literals.rs +++ b/src/tools/clippy/tests/ui/needless_parens_on_range_literals.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@edition:2018 #![warn(clippy::needless_parens_on_range_literals)] diff --git a/src/tools/clippy/tests/ui/needless_parens_on_range_literals.stderr b/src/tools/clippy/tests/ui/needless_parens_on_range_literals.stderr index 505f7ac91..c73564e21 100644 --- a/src/tools/clippy/tests/ui/needless_parens_on_range_literals.stderr +++ b/src/tools/clippy/tests/ui/needless_parens_on_range_literals.stderr @@ -1,37 +1,38 @@ error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:8:13 + --> $DIR/needless_parens_on_range_literals.rs:7:13 | LL | let _ = ('a')..=('z'); | ^^^^^ help: try: `'a'` | = note: `-D clippy::needless-parens-on-range-literals` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_parens_on_range_literals)]` error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:8:21 + --> $DIR/needless_parens_on_range_literals.rs:7:21 | LL | let _ = ('a')..=('z'); | ^^^^^ help: try: `'z'` error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:9:18 + --> $DIR/needless_parens_on_range_literals.rs:8:18 | LL | let _ = 'a'..('z'); | ^^^^^ help: try: `'z'` error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:11:19 + --> $DIR/needless_parens_on_range_literals.rs:10:19 | LL | let _ = (1.)..(2.); | ^^^^ help: try: `2.` error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:12:13 + --> $DIR/needless_parens_on_range_literals.rs:11:13 | LL | let _ = ('a')..; | ^^^^^ help: try: `'a'` error: needless parenthesis on range literals can be removed - --> $DIR/needless_parens_on_range_literals.rs:13:15 + --> $DIR/needless_parens_on_range_literals.rs:12:15 | LL | let _ = ..('z'); | ^^^^^ help: try: `'z'` diff --git a/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.rs b/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.rs index 4e79e5f53..39d76f999 100644 --- a/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.rs +++ b/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.rs @@ -1,10 +1,7 @@ -#![allow(clippy::if_same_then_else, clippy::no_effect)] +#![allow(clippy::if_same_then_else, clippy::no_effect, clippy::redundant_closure_call)] +#![warn(clippy::needless_pass_by_ref_mut)] #![feature(lint_reasons)] - -// just ignore everywhere for now -//@ignore-32bit -//@ignore-64bit - +//@no-rustfix use std::ptr::NonNull; fn foo(s: &mut Vec, b: &u32, x: &mut u32) { @@ -234,6 +231,44 @@ async fn async_vec(b: &mut Vec) { async fn async_vec2(b: &mut Vec) { b.push(true); } +fn non_mut(n: &str) {} +//Should warn +pub async fn call_in_closure1(n: &mut str) { + (|| non_mut(n))() +} +fn str_mut(str: &mut String) -> bool { + str.pop().is_some() +} +//Should not warn +pub async fn call_in_closure2(str: &mut String) { + (|| str_mut(str))(); +} + +// Should not warn. +pub async fn closure(n: &mut usize) -> impl '_ + FnMut() { + || { + *n += 1; + } +} + +// Should warn. +pub fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize { + //~^ ERROR: this argument is a mutable reference, but not used mutably + || *n + 1 +} + +// Should not warn. +pub async fn closure3(n: &mut usize) { + (|| *n += 1)(); +} + +// Should warn. +pub async fn closure4(n: &mut usize) { + //~^ ERROR: this argument is a mutable reference, but not used mutably + (|| { + let _x = *n + 1; + })(); +} fn main() { let mut u = 0; diff --git a/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.stderr b/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.stderr index 2e06e7252..aa937c3f6 100644 --- a/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.stderr +++ b/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.stderr @@ -1,85 +1,86 @@ error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:6:11 + --> $DIR/needless_pass_by_ref_mut.rs:7:11 | LL | fn foo(s: &mut Vec, b: &u32, x: &mut u32) { | ^^^^^^^^^^^^^ help: consider changing to: `&Vec` | = note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:31:12 + --> $DIR/needless_pass_by_ref_mut.rs:32:12 | LL | fn foo6(s: &mut Vec) { | ^^^^^^^^^^^^^ help: consider changing to: `&Vec` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:44:29 + --> $DIR/needless_pass_by_ref_mut.rs:45:29 | LL | fn mushroom(&self, vec: &mut Vec) -> usize { | ^^^^^^^^^^^^^ help: consider changing to: `&Vec` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:49:31 + --> $DIR/needless_pass_by_ref_mut.rs:50:31 | LL | fn badger(&mut self, vec: &mut Vec) -> usize { | ^^^^^^^^^^^^^ help: consider changing to: `&Vec` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:126:16 + --> $DIR/needless_pass_by_ref_mut.rs:127:16 | LL | async fn a1(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:130:16 + --> $DIR/needless_pass_by_ref_mut.rs:131:16 | LL | async fn a2(x: &mut i32, y: String) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:134:16 + --> $DIR/needless_pass_by_ref_mut.rs:135:16 | LL | async fn a3(x: &mut i32, y: String, z: String) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:138:16 + --> $DIR/needless_pass_by_ref_mut.rs:139:16 | LL | async fn a4(x: &mut i32, y: i32) { | ^^^^^^^^ help: consider changing to: `&i32` error: this argument is a mutable reference, but not used mutably - --> $DIR/needless_pass_by_ref_mut.rs:142:24 + --> $DIR/needless_pass_by_ref_mut.rs:143:24 | LL | async fn a5(x: i32, y: &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:146:24 + --> $DIR/needless_pass_by_ref_mut.rs:147:24 | LL | async fn a6(x: i32, y: &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:150:32 + --> $DIR/needless_pass_by_ref_mut.rs:151:32 | 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:154:24 + --> $DIR/needless_pass_by_ref_mut.rs:155: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:154:45 + --> $DIR/needless_pass_by_ref_mut.rs:155: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:188:16 + --> $DIR/needless_pass_by_ref_mut.rs:189:16 | LL | fn cfg_warn(s: &mut u32) {} | ^^^^^^^^ help: consider changing to: `&u32` @@ -87,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:194:20 + --> $DIR/needless_pass_by_ref_mut.rs:195:20 | LL | fn cfg_warn(s: &mut u32) {} | ^^^^^^^^ help: consider changing to: `&u32` @@ -95,16 +96,48 @@ 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:208:39 + --> $DIR/needless_pass_by_ref_mut.rs:209: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:216:26 + --> $DIR/needless_pass_by_ref_mut.rs:217:26 | LL | async fn inner_async3(x: &mut i32, y: &mut u32) { | ^^^^^^^^ help: consider changing to: `&i32` -error: aborting due to 17 previous errors +error: this argument is a mutable reference, but not used mutably + --> $DIR/needless_pass_by_ref_mut.rs:236:34 + | +LL | pub async fn call_in_closure1(n: &mut str) { + | ^^^^^^^^ help: consider changing to: `&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:248:25 + | +LL | pub async fn closure(n: &mut usize) -> impl '_ + FnMut() { + | ^^^^^^^^^^ help: consider changing to: `&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:255:20 + | +LL | pub fn closure2(n: &mut usize) -> impl '_ + FnMut() -> usize { + | ^^^^^^^^^^ help: consider changing to: `&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:266:26 + | +LL | pub async fn closure4(n: &mut usize) { + | ^^^^^^^^^^ help: consider changing to: `&usize` + | + = warning: changing this function will impact semver compatibility + +error: aborting due to 21 previous errors diff --git a/src/tools/clippy/tests/ui/needless_pass_by_value.rs b/src/tools/clippy/tests/ui/needless_pass_by_value.rs index d79ad86b1..14cba5a7e 100644 --- a/src/tools/clippy/tests/ui/needless_pass_by_value.rs +++ b/src/tools/clippy/tests/ui/needless_pass_by_value.rs @@ -7,7 +7,7 @@ clippy::single_match, clippy::uninlined_format_args )] - +//@no-rustfix use std::borrow::Borrow; use std::collections::HashSet; use std::convert::AsRef; @@ -16,6 +16,8 @@ use std::mem::MaybeUninit; // `v` should be warned // `w`, `x` and `y` are allowed (moved or mutated) fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec { + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| NOTE: `-D clippy::needless-pass-by-value` implied by `-D warnings` assert_eq!(v.len(), 42); consume(w); @@ -30,12 +32,15 @@ fn consume(_: T) {} struct Wrapper(String); fn bar(x: String, y: Wrapper) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body assert_eq!(x.len(), 42); assert_eq!(y.0.len(), 42); } // V implements `Borrow`, but should be warned correctly fn test_borrow_trait, U: AsRef, V>(t: T, u: U, v: V) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body println!("{}", t.borrow()); println!("{}", u.as_ref()); consume(&v); @@ -48,6 +53,7 @@ fn test_fn i32>(f: F) { // x should be warned, but y is ok fn test_match(x: Option>, y: Option>) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body match x { Some(Some(_)) => 1, // not moved _ => 0, @@ -61,6 +67,8 @@ fn test_match(x: Option>, y: Option>) { // x and y should be warned, but z is ok fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body let Wrapper(s) = z; // moved let Wrapper(ref t) = y; // not moved let Wrapper(_) = y; // still not moved @@ -77,8 +85,13 @@ impl<'a, T> Serialize for &'a T where T: Serialize {} impl Serialize for i32 {} fn test_blanket_ref(_foo: T, _serializable: S) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body fn issue_2114(s: String, t: String, u: Vec, v: Vec) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body s.capacity(); let _ = t.clone(); u.capacity(); @@ -92,7 +105,9 @@ impl S { self, // taking `self` by value is always allowed s: String, + //~^ ERROR: this argument is passed by value, but not consumed in the function bod t: String, + //~^ ERROR: this argument is passed by value, but not consumed in the function bod ) -> usize { s.len() + t.capacity() } @@ -102,6 +117,8 @@ impl S { } fn baz(&self, _u: U, _s: Self) {} + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body } trait FalsePositive { @@ -124,12 +141,16 @@ fn range>(range: T) { struct CopyWrapper(u32); fn bar_copy(x: u32, y: CopyWrapper) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body assert_eq!(x, 42); assert_eq!(y.0, 42); } // x and y should be warned, but z is ok fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { + //~^ ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body + //~| ERROR: this argument is passed by value, but not consumed in the function body let CopyWrapper(s) = z; // moved let CopyWrapper(ref t) = y; // not moved let CopyWrapper(_) = y; // still not moved @@ -142,11 +163,13 @@ fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { trait Bar<'a, A> {} impl<'b, T> Bar<'b, T> for T {} fn some_fun<'b, S: Bar<'b, ()>>(_item: S) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body // Also this should not cause an ICE. See #2831 trait Club<'a, A> {} impl Club<'static, T> for T {} fn more_fun(_item: impl Club<'static, i32>) {} +//~^ ERROR: this argument is passed by value, but not consumed in the function body fn is_sync(_: T) where diff --git a/src/tools/clippy/tests/ui/needless_pass_by_value.stderr b/src/tools/clippy/tests/ui/needless_pass_by_value.stderr index 0e660a77d..1c3a63d66 100644 --- a/src/tools/clippy/tests/ui/needless_pass_by_value.stderr +++ b/src/tools/clippy/tests/ui/needless_pass_by_value.stderr @@ -5,57 +5,58 @@ LL | fn foo(v: Vec, w: Vec, mut x: Vec, y: Vec) -> Vec $DIR/needless_pass_by_value.rs:32:11 + --> $DIR/needless_pass_by_value.rs:34:11 | LL | fn bar(x: String, y: Wrapper) { | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:32:22 + --> $DIR/needless_pass_by_value.rs:34:22 | LL | fn bar(x: String, y: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:38:71 + --> $DIR/needless_pass_by_value.rs:42:71 | LL | fn test_borrow_trait, U: AsRef, V>(t: T, u: U, v: V) { | ^ help: consider taking a reference instead: `&V` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:50:18 + --> $DIR/needless_pass_by_value.rs:55:18 | LL | fn test_match(x: Option>, y: Option>) { | ^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&Option>` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:63:24 + --> $DIR/needless_pass_by_value.rs:69:24 | LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:63:36 + --> $DIR/needless_pass_by_value.rs:69:36 | LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:79:49 + --> $DIR/needless_pass_by_value.rs:87:49 | LL | fn test_blanket_ref(_foo: T, _serializable: S) {} | ^ help: consider taking a reference instead: `&T` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:18 + --> $DIR/needless_pass_by_value.rs:90:18 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^ help: consider taking a reference instead: `&String` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:29 + --> $DIR/needless_pass_by_value.rs:90:29 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^ @@ -70,13 +71,13 @@ LL | let _ = t.to_string(); | ~~~~~~~~~~~~~ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:40 + --> $DIR/needless_pass_by_value.rs:90:40 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^^^ help: consider taking a reference instead: `&Vec` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:81:53 + --> $DIR/needless_pass_by_value.rs:90:53 | LL | fn issue_2114(s: String, t: String, u: Vec, v: Vec) { | ^^^^^^^^ @@ -91,85 +92,85 @@ LL | let _ = v.to_owned(); | ~~~~~~~~~~~~ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:94:12 + --> $DIR/needless_pass_by_value.rs:107:12 | LL | s: String, | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:95:12 + --> $DIR/needless_pass_by_value.rs:109:12 | LL | t: String, | ^^^^^^ help: consider taking a reference instead: `&String` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:104:23 + --> $DIR/needless_pass_by_value.rs:119:23 | LL | fn baz(&self, _u: U, _s: Self) {} | ^ help: consider taking a reference instead: `&U` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:104:30 + --> $DIR/needless_pass_by_value.rs:119:30 | LL | fn baz(&self, _u: U, _s: Self) {} | ^^^^ help: consider taking a reference instead: `&Self` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:126:24 + --> $DIR/needless_pass_by_value.rs:143:24 | LL | fn bar_copy(x: u32, y: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 + --> $DIR/needless_pass_by_value.rs:141:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:132:29 + --> $DIR/needless_pass_by_value.rs:150:29 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 + --> $DIR/needless_pass_by_value.rs:141:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:132:45 + --> $DIR/needless_pass_by_value.rs:150:45 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 + --> $DIR/needless_pass_by_value.rs:141:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:132:61 + --> $DIR/needless_pass_by_value.rs:150:61 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: consider marking this type as `Copy` - --> $DIR/needless_pass_by_value.rs:124:1 + --> $DIR/needless_pass_by_value.rs:141:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:144:40 + --> $DIR/needless_pass_by_value.rs:165:40 | LL | fn some_fun<'b, S: Bar<'b, ()>>(_item: S) {} | ^ help: consider taking a reference instead: `&S` error: this argument is passed by value, but not consumed in the function body - --> $DIR/needless_pass_by_value.rs:149:20 + --> $DIR/needless_pass_by_value.rs:171:20 | LL | fn more_fun(_item: impl Club<'static, i32>) {} | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&impl Club<'static, i32>` diff --git a/src/tools/clippy/tests/ui/needless_pub_self.fixed b/src/tools/clippy/tests/ui/needless_pub_self.fixed index 672b4c318..d9f7b92d0 100644 --- a/src/tools/clippy/tests/ui/needless_pub_self.fixed +++ b/src/tools/clippy/tests/ui/needless_pub_self.fixed @@ -1,5 +1,5 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro + +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(unused)] #![warn(clippy::needless_pub_self)] diff --git a/src/tools/clippy/tests/ui/needless_pub_self.rs b/src/tools/clippy/tests/ui/needless_pub_self.rs index 5ac1edf8e..9f0ec7647 100644 --- a/src/tools/clippy/tests/ui/needless_pub_self.rs +++ b/src/tools/clippy/tests/ui/needless_pub_self.rs @@ -1,5 +1,5 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro + +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(unused)] #![warn(clippy::needless_pub_self)] diff --git a/src/tools/clippy/tests/ui/needless_pub_self.stderr b/src/tools/clippy/tests/ui/needless_pub_self.stderr index 3aa2feb5e..c1f6b908b 100644 --- a/src/tools/clippy/tests/ui/needless_pub_self.stderr +++ b/src/tools/clippy/tests/ui/needless_pub_self.stderr @@ -5,6 +5,7 @@ LL | pub(self) fn a() {} | ^^^^^^^^^ help: remove it | = note: `-D clippy::needless-pub-self` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_pub_self)]` error: unnecessary `pub(in self)` --> $DIR/needless_pub_self.rs:14:1 diff --git a/src/tools/clippy/tests/ui/needless_question_mark.fixed b/src/tools/clippy/tests/ui/needless_question_mark.fixed index 679b73d40..07bd6b6f3 100644 --- a/src/tools/clippy/tests/ui/needless_question_mark.fixed +++ b/src/tools/clippy/tests/ui/needless_question_mark.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_question_mark)] #![allow( clippy::needless_return, diff --git a/src/tools/clippy/tests/ui/needless_question_mark.rs b/src/tools/clippy/tests/ui/needless_question_mark.rs index a993d3ec3..fbf8a12fd 100644 --- a/src/tools/clippy/tests/ui/needless_question_mark.rs +++ b/src/tools/clippy/tests/ui/needless_question_mark.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::needless_question_mark)] #![allow( clippy::needless_return, diff --git a/src/tools/clippy/tests/ui/needless_question_mark.stderr b/src/tools/clippy/tests/ui/needless_question_mark.stderr index d1f89e326..cd961a49f 100644 --- a/src/tools/clippy/tests/ui/needless_question_mark.stderr +++ b/src/tools/clippy/tests/ui/needless_question_mark.stderr @@ -1,73 +1,74 @@ error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:22:12 + --> $DIR/needless_question_mark.rs:20:12 | LL | return Some(to.magic?); | ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic` | = note: `-D clippy::needless-question-mark` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_question_mark)]` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:30:12 + --> $DIR/needless_question_mark.rs:28:12 | LL | return Some(to.magic?) | ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:35:5 + --> $DIR/needless_question_mark.rs:33: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:40:21 + --> $DIR/needless_question_mark.rs:38:21 | LL | to.and_then(|t| Some(t.magic?)) | ^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `t.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:49:9 + --> $DIR/needless_question_mark.rs:47:9 | LL | Some(t.magic?) | ^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `t.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:54:12 + --> $DIR/needless_question_mark.rs:52:12 | LL | return Ok(tr.magic?); | ^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `tr.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:61:12 + --> $DIR/needless_question_mark.rs:59:12 | LL | return Ok(tr.magic?) | ^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `tr.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:65:5 + --> $DIR/needless_question_mark.rs:63:5 | LL | Ok(tr.magic?) | ^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `tr.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:69:21 + --> $DIR/needless_question_mark.rs:67:21 | LL | tr.and_then(|t| Ok(t.magic?)) | ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `t.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:77:9 + --> $DIR/needless_question_mark.rs:75:9 | LL | Ok(t.magic?) | ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `t.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:84:16 + --> $DIR/needless_question_mark.rs:82:16 | LL | return Ok(t.magic?); | ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `t.magic` error: question mark operator is useless here - --> $DIR/needless_question_mark.rs:119:27 + --> $DIR/needless_question_mark.rs:117:27 | LL | || -> Option<_> { Some(Some($expr)?) }() | ^^^^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `Some($expr)` @@ -78,13 +79,13 @@ 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:130:5 + --> $DIR/needless_question_mark.rs:128: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:138:5 + --> $DIR/needless_question_mark.rs:136:5 | LL | Ok(s.magic?) | ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `s.magic` diff --git a/src/tools/clippy/tests/ui/needless_range_loop.rs b/src/tools/clippy/tests/ui/needless_range_loop.rs index a16ef5a5b..3f2421953 100644 --- a/src/tools/clippy/tests/ui/needless_range_loop.rs +++ b/src/tools/clippy/tests/ui/needless_range_loop.rs @@ -4,7 +4,7 @@ clippy::unnecessary_literal_unwrap, clippy::useless_vec )] - +//@no-rustfix static STATIC: [usize; 4] = [0, 1, 8, 16]; const CONST: [usize; 4] = [0, 1, 8, 16]; const MAX_LEN: usize = 42; @@ -13,6 +13,8 @@ fn main() { let mut vec = vec![1, 2, 3, 4]; let vec2 = vec![1, 2, 3, 4]; for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is only used to index `vec` + //~| NOTE: `-D clippy::needless-range-loop` implied by `-D warnings` println!("{}", vec[i]); } @@ -22,19 +24,23 @@ fn main() { } for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is only used to index `vec` let _ = vec[i]; } // ICE #746 for j in 0..4 { + //~^ ERROR: the loop variable `j` is only used to index `STATIC` println!("{:?}", STATIC[j]); } for j in 0..4 { + //~^ ERROR: the loop variable `j` is only used to index `CONST` println!("{:?}", CONST[j]); } for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is used to index `vec` println!("{} {}", vec[i], i); } for i in 0..vec.len() { @@ -43,39 +49,48 @@ fn main() { } for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is only used to index `vec2` println!("{}", vec2[i]); } for i in 5..vec.len() { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 0..MAX_LEN { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 0..=MAX_LEN { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 5..10 { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 5..=10 { + //~^ ERROR: the loop variable `i` is only used to index `vec` println!("{}", vec[i]); } for i in 5..vec.len() { + //~^ ERROR: the loop variable `i` is used to index `vec` println!("{} {}", vec[i], i); } for i in 5..10 { + //~^ ERROR: the loop variable `i` is used to index `vec` println!("{} {}", vec[i], i); } // #2542 for i in 0..vec.len() { + //~^ ERROR: the loop variable `i` is used to index `vec` vec[i] = Some(1).unwrap_or_else(|| panic!("error on {}", i)); } diff --git a/src/tools/clippy/tests/ui/needless_range_loop.stderr b/src/tools/clippy/tests/ui/needless_range_loop.stderr index 8ca6b880c..0d8893c26 100644 --- a/src/tools/clippy/tests/ui/needless_range_loop.stderr +++ b/src/tools/clippy/tests/ui/needless_range_loop.stderr @@ -5,13 +5,14 @@ LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ | = note: `-D clippy::needless-range-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_range_loop)]` help: consider using an iterator | LL | for in &vec { | ~~~~~~ ~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:24:14 + --> $DIR/needless_range_loop.rs:26:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -22,7 +23,7 @@ LL | for in &vec { | ~~~~~~ ~~~~ error: the loop variable `j` is only used to index `STATIC` - --> $DIR/needless_range_loop.rs:29:14 + --> $DIR/needless_range_loop.rs:32:14 | LL | for j in 0..4 { | ^^^^ @@ -33,7 +34,7 @@ LL | for in &STATIC { | ~~~~~~ ~~~~~~~ error: the loop variable `j` is only used to index `CONST` - --> $DIR/needless_range_loop.rs:33:14 + --> $DIR/needless_range_loop.rs:37:14 | LL | for j in 0..4 { | ^^^^ @@ -44,7 +45,7 @@ LL | for in &CONST { | ~~~~~~ ~~~~~~ error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:37:14 + --> $DIR/needless_range_loop.rs:42:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -55,7 +56,7 @@ LL | for (i, ) in vec.iter().enumerate() { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec2` - --> $DIR/needless_range_loop.rs:45:14 + --> $DIR/needless_range_loop.rs:51:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ @@ -66,7 +67,7 @@ LL | for in vec2.iter().take(vec.len()) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:49:14 + --> $DIR/needless_range_loop.rs:56:14 | LL | for i in 5..vec.len() { | ^^^^^^^^^^^^ @@ -77,7 +78,7 @@ LL | for in vec.iter().skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:53:14 + --> $DIR/needless_range_loop.rs:61:14 | LL | for i in 0..MAX_LEN { | ^^^^^^^^^^ @@ -88,7 +89,7 @@ LL | for in vec.iter().take(MAX_LEN) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:57:14 + --> $DIR/needless_range_loop.rs:66:14 | LL | for i in 0..=MAX_LEN { | ^^^^^^^^^^^ @@ -99,7 +100,7 @@ LL | for in vec.iter().take(MAX_LEN + 1) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:61:14 + --> $DIR/needless_range_loop.rs:71:14 | LL | for i in 5..10 { | ^^^^^ @@ -110,7 +111,7 @@ LL | for in vec.iter().take(10).skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop.rs:65:14 + --> $DIR/needless_range_loop.rs:76:14 | LL | for i in 5..=10 { | ^^^^^^ @@ -121,7 +122,7 @@ LL | for in vec.iter().take(10 + 1).skip(5) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:69:14 + --> $DIR/needless_range_loop.rs:81:14 | LL | for i in 5..vec.len() { | ^^^^^^^^^^^^ @@ -132,7 +133,7 @@ LL | for (i, ) in vec.iter().enumerate().skip(5) { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:73:14 + --> $DIR/needless_range_loop.rs:86:14 | LL | for i in 5..10 { | ^^^^^ @@ -143,7 +144,7 @@ LL | for (i, ) in vec.iter().enumerate().take(10).skip(5) { | ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is used to index `vec` - --> $DIR/needless_range_loop.rs:78:14 + --> $DIR/needless_range_loop.rs:92:14 | LL | for i in 0..vec.len() { | ^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/needless_range_loop2.rs b/src/tools/clippy/tests/ui/needless_range_loop2.rs index 516d99a35..787ff18f3 100644 --- a/src/tools/clippy/tests/ui/needless_range_loop2.rs +++ b/src/tools/clippy/tests/ui/needless_range_loop2.rs @@ -1,6 +1,6 @@ #![warn(clippy::needless_range_loop)] #![allow(clippy::useless_vec)] - +//@no-rustfix fn calc_idx(i: usize) -> usize { (i + i + 20) % 4 } @@ -9,6 +9,8 @@ fn main() { let ns = vec![2, 3, 5, 7]; for i in 3..10 { + //~^ ERROR: the loop variable `i` is only used to index `ns` + //~| NOTE: `-D clippy::needless-range-loop` implied by `-D warnings` println!("{}", ns[i]); } @@ -30,12 +32,14 @@ fn main() { let mut ms = vec![1, 2, 3, 4, 5, 6]; for i in 0..ms.len() { + //~^ ERROR: the loop variable `i` is only used to index `ms` ms[i] *= 2; } assert_eq!(ms, vec![2, 4, 6, 8, 10, 12]); let mut ms = vec![1, 2, 3, 4, 5, 6]; for i in 0..ms.len() { + //~^ ERROR: the loop variable `i` is only used to index `ms` let x = &mut ms[i]; *x *= 2; } @@ -60,6 +64,7 @@ fn main() { let mut vec = vec![0; 9]; for i in x..x + 4 { + //~^ ERROR: the loop variable `i` is only used to index `vec` vec[i] += 1; } @@ -67,20 +72,24 @@ fn main() { let mut vec = vec![0; 10]; for i in x..=x + 4 { + //~^ ERROR: the loop variable `i` is only used to index `vec` vec[i] += 1; } let arr = [1, 2, 3]; for i in 0..3 { + //~^ ERROR: the loop variable `i` is only used to index `arr` println!("{}", arr[i]); } for i in 0..2 { + //~^ ERROR: the loop variable `i` is only used to index `arr` println!("{}", arr[i]); } for i in 1..3 { + //~^ ERROR: the loop variable `i` is only used to index `arr` println!("{}", arr[i]); } diff --git a/src/tools/clippy/tests/ui/needless_range_loop2.stderr b/src/tools/clippy/tests/ui/needless_range_loop2.stderr index 8c4f5d954..3d1d9e1bf 100644 --- a/src/tools/clippy/tests/ui/needless_range_loop2.stderr +++ b/src/tools/clippy/tests/ui/needless_range_loop2.stderr @@ -5,13 +5,14 @@ LL | for i in 3..10 { | ^^^^^ | = note: `-D clippy::needless-range-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_range_loop)]` help: consider using an iterator | LL | for in ns.iter().take(10).skip(3) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `ms` - --> $DIR/needless_range_loop2.rs:32:14 + --> $DIR/needless_range_loop2.rs:34:14 | LL | for i in 0..ms.len() { | ^^^^^^^^^^^ @@ -22,7 +23,7 @@ LL | for in &mut ms { | ~~~~~~ ~~~~~~~ error: the loop variable `i` is only used to index `ms` - --> $DIR/needless_range_loop2.rs:38:14 + --> $DIR/needless_range_loop2.rs:41:14 | LL | for i in 0..ms.len() { | ^^^^^^^^^^^ @@ -33,7 +34,7 @@ LL | for in &mut ms { | ~~~~~~ ~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop2.rs:62:14 + --> $DIR/needless_range_loop2.rs:66:14 | LL | for i in x..x + 4 { | ^^^^^^^^ @@ -44,7 +45,7 @@ LL | for in vec.iter_mut().skip(x).take(4) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `vec` - --> $DIR/needless_range_loop2.rs:69:14 + --> $DIR/needless_range_loop2.rs:74:14 | LL | for i in x..=x + 4 { | ^^^^^^^^^ @@ -55,7 +56,7 @@ LL | for in vec.iter_mut().skip(x).take(4 + 1) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `arr` - --> $DIR/needless_range_loop2.rs:75:14 + --> $DIR/needless_range_loop2.rs:81:14 | LL | for i in 0..3 { | ^^^^ @@ -66,7 +67,7 @@ LL | for in &arr { | ~~~~~~ ~~~~ error: the loop variable `i` is only used to index `arr` - --> $DIR/needless_range_loop2.rs:79:14 + --> $DIR/needless_range_loop2.rs:86:14 | LL | for i in 0..2 { | ^^^^ @@ -77,7 +78,7 @@ LL | for in arr.iter().take(2) { | ~~~~~~ ~~~~~~~~~~~~~~~~~~ error: the loop variable `i` is only used to index `arr` - --> $DIR/needless_range_loop2.rs:83:14 + --> $DIR/needless_range_loop2.rs:91:14 | LL | for i in 1..3 { | ^^^^ diff --git a/src/tools/clippy/tests/ui/needless_raw_string.fixed b/src/tools/clippy/tests/ui/needless_raw_string.fixed index b36912efb..855498105 100644 --- a/src/tools/clippy/tests/ui/needless_raw_string.fixed +++ b/src/tools/clippy/tests/ui/needless_raw_string.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::needless_raw_strings)] #![feature(c_str_literals)] @@ -10,8 +9,13 @@ fn main() { b"aaa"; br#""aaa""#; br#"\s"#; - // currently disabled: https://github.com/rust-lang/rust/issues/113333 - // cr#"aaa"#; - // cr#""aaa""#; - // cr#"\s"#; + c"aaa"; + cr#""aaa""#; + cr#"\s"#; + + " + a + multiline + string + "; } diff --git a/src/tools/clippy/tests/ui/needless_raw_string.rs b/src/tools/clippy/tests/ui/needless_raw_string.rs index 8f48e7dab..06d497303 100644 --- a/src/tools/clippy/tests/ui/needless_raw_string.rs +++ b/src/tools/clippy/tests/ui/needless_raw_string.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::needless_raw_strings)] #![feature(c_str_literals)] @@ -10,8 +9,13 @@ fn main() { br#"aaa"#; br#""aaa""#; br#"\s"#; - // currently disabled: https://github.com/rust-lang/rust/issues/113333 - // cr#"aaa"#; - // cr#""aaa""#; - // cr#"\s"#; + cr#"aaa"#; + cr#""aaa""#; + cr#"\s"#; + + r#" + a + multiline + string + "#; } diff --git a/src/tools/clippy/tests/ui/needless_raw_string.stderr b/src/tools/clippy/tests/ui/needless_raw_string.stderr index cfb07b647..e6806b31b 100644 --- a/src/tools/clippy/tests/ui/needless_raw_string.stderr +++ b/src/tools/clippy/tests/ui/needless_raw_string.stderr @@ -1,16 +1,59 @@ error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:7:5 + --> $DIR/needless_raw_string.rs:6:5 | LL | r#"aaa"#; - | ^^^^^^^^ help: try: `"aaa"` + | ^^^^^^^^ | = note: `-D clippy::needless-raw-strings` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_raw_strings)]` +help: try + | +LL - r#"aaa"#; +LL + "aaa"; + | error: unnecessary raw string literal - --> $DIR/needless_raw_string.rs:10:5 + --> $DIR/needless_raw_string.rs:9:5 | LL | br#"aaa"#; - | ^^^^^^^^^ help: try: `b"aaa"` + | ^^^^^^^^^ + | +help: try + | +LL - br#"aaa"#; +LL + b"aaa"; + | + +error: unnecessary raw string literal + --> $DIR/needless_raw_string.rs:12:5 + | +LL | cr#"aaa"#; + | ^^^^^^^^^ + | +help: try + | +LL - cr#"aaa"#; +LL + c"aaa"; + | + +error: unnecessary raw string literal + --> $DIR/needless_raw_string.rs:16:5 + | +LL | / r#" +LL | | a +LL | | multiline +LL | | string +LL | | "#; + | |______^ + | +help: try + | +LL ~ " +LL | a +LL | multiline +LL | string +LL ~ "; + | -error: aborting due to 2 previous errors +error: aborting due to 4 previous errors diff --git a/src/tools/clippy/tests/ui/needless_raw_string_hashes.fixed b/src/tools/clippy/tests/ui/needless_raw_string_hashes.fixed index c8507c727..c99c2f465 100644 --- a/src/tools/clippy/tests/ui/needless_raw_string_hashes.fixed +++ b/src/tools/clippy/tests/ui/needless_raw_string_hashes.fixed @@ -1,20 +1,27 @@ -//@run-rustfix #![allow(clippy::no_effect, unused)] #![warn(clippy::needless_raw_string_hashes)] #![feature(c_str_literals)] fn main() { - r#"aaa"#; + r"\aaa"; r#"Hello "world"!"#; r####" "### "## "# "####; r###" "aa" "# "## "###; - br#"aaa"#; + br"\aaa"; br#"Hello "world"!"#; br####" "### "## "# "####; br###" "aa" "# "## "###; - // currently disabled: https://github.com/rust-lang/rust/issues/113333 - // cr#"aaa"#; - // cr##"Hello "world"!"##; - // cr######" "### "## "# "######; - // cr######" "aa" "# "## "######; + cr"\aaa"; + cr#"Hello "world"!"#; + cr####" "### "## "# "####; + cr###" "aa" "# "## "###; + + r" + \a + multiline + string + "; + + r"rust"; + r"hello world"; } diff --git a/src/tools/clippy/tests/ui/needless_raw_string_hashes.rs b/src/tools/clippy/tests/ui/needless_raw_string_hashes.rs index 912fbde16..dcc2af69f 100644 --- a/src/tools/clippy/tests/ui/needless_raw_string_hashes.rs +++ b/src/tools/clippy/tests/ui/needless_raw_string_hashes.rs @@ -1,20 +1,27 @@ -//@run-rustfix #![allow(clippy::no_effect, unused)] #![warn(clippy::needless_raw_string_hashes)] #![feature(c_str_literals)] fn main() { - r#"aaa"#; + r#"\aaa"#; r##"Hello "world"!"##; r######" "### "## "# "######; r######" "aa" "# "## "######; - br#"aaa"#; + br#"\aaa"#; br##"Hello "world"!"##; br######" "### "## "# "######; br######" "aa" "# "## "######; - // currently disabled: https://github.com/rust-lang/rust/issues/113333 - // cr#"aaa"#; - // cr##"Hello "world"!"##; - // cr######" "### "## "# "######; - // cr######" "aa" "# "## "######; + cr#"\aaa"#; + cr##"Hello "world"!"##; + cr######" "### "## "# "######; + cr######" "aa" "# "## "######; + + r#" + \a + multiline + string + "#; + + r###"rust"###; + r#"hello world"#; } diff --git a/src/tools/clippy/tests/ui/needless_raw_string_hashes.stderr b/src/tools/clippy/tests/ui/needless_raw_string_hashes.stderr index 30e6783a3..4399c6555 100644 --- a/src/tools/clippy/tests/ui/needless_raw_string_hashes.stderr +++ b/src/tools/clippy/tests/ui/needless_raw_string_hashes.stderr @@ -1,40 +1,191 @@ error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:8:5 + --> $DIR/needless_raw_string_hashes.rs:6:5 | -LL | r##"Hello "world"!"##; - | ^^^^^^^^^^^^^^^^^^^^^ help: try: `r#"Hello "world"!"#` +LL | r#"\aaa"#; + | ^^^^^^^^^ | = note: `-D clippy::needless-raw-string-hashes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_raw_string_hashes)]` +help: remove all the hashes around the literal + | +LL - r#"\aaa"#; +LL + r"\aaa"; + | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:9:5 + --> $DIR/needless_raw_string_hashes.rs:7:5 + | +LL | r##"Hello "world"!"##; + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: remove one hash from both sides of the literal + | +LL - r##"Hello "world"!"##; +LL + r#"Hello "world"!"#; + | + +error: unnecessary hashes around raw string literal + --> $DIR/needless_raw_string_hashes.rs:8:5 | LL | r######" "### "## "# "######; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `r####" "### "## "# "####` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove 2 hashes from both sides of the literal + | +LL - r######" "### "## "# "######; +LL + r####" "### "## "# "####; + | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:10:5 + --> $DIR/needless_raw_string_hashes.rs:9:5 | LL | r######" "aa" "# "## "######; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `r###" "aa" "# "## "###` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove 3 hashes from both sides of the literal + | +LL - r######" "aa" "# "## "######; +LL + r###" "aa" "# "## "###; + | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:12:5 + --> $DIR/needless_raw_string_hashes.rs:10:5 + | +LL | br#"\aaa"#; + | ^^^^^^^^^^ + | +help: remove all the hashes around the literal + | +LL - br#"\aaa"#; +LL + br"\aaa"; + | + +error: unnecessary hashes around raw string literal + --> $DIR/needless_raw_string_hashes.rs:11:5 | LL | br##"Hello "world"!"##; - | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `br#"Hello "world"!"#` + | ^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove one hash from both sides of the literal + | +LL - br##"Hello "world"!"##; +LL + br#"Hello "world"!"#; + | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:13:5 + --> $DIR/needless_raw_string_hashes.rs:12:5 | LL | br######" "### "## "# "######; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `br####" "### "## "# "####` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove 2 hashes from both sides of the literal + | +LL - br######" "### "## "# "######; +LL + br####" "### "## "# "####; + | error: unnecessary hashes around raw string literal - --> $DIR/needless_raw_string_hashes.rs:14:5 + --> $DIR/needless_raw_string_hashes.rs:13:5 | LL | br######" "aa" "# "## "######; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `br###" "aa" "# "## "###` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove 3 hashes from both sides of the literal + | +LL - br######" "aa" "# "## "######; +LL + br###" "aa" "# "## "###; + | + +error: unnecessary hashes around raw string literal + --> $DIR/needless_raw_string_hashes.rs:14:5 + | +LL | cr#"\aaa"#; + | ^^^^^^^^^^ + | +help: remove all the hashes around the literal + | +LL - cr#"\aaa"#; +LL + cr"\aaa"; + | + +error: unnecessary hashes around raw string literal + --> $DIR/needless_raw_string_hashes.rs:15:5 + | +LL | cr##"Hello "world"!"##; + | ^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove one hash from both sides of the literal + | +LL - cr##"Hello "world"!"##; +LL + cr#"Hello "world"!"#; + | + +error: unnecessary hashes around raw string literal + --> $DIR/needless_raw_string_hashes.rs:16:5 + | +LL | cr######" "### "## "# "######; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove 2 hashes from both sides of the literal + | +LL - cr######" "### "## "# "######; +LL + cr####" "### "## "# "####; + | + +error: unnecessary hashes around raw string literal + --> $DIR/needless_raw_string_hashes.rs:17:5 + | +LL | cr######" "aa" "# "## "######; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove 3 hashes from both sides of the literal + | +LL - cr######" "aa" "# "## "######; +LL + cr###" "aa" "# "## "###; + | + +error: unnecessary hashes around raw string literal + --> $DIR/needless_raw_string_hashes.rs:19:5 + | +LL | / r#" +LL | | \a +LL | | multiline +LL | | string +LL | | "#; + | |______^ + | +help: remove all the hashes around the literal + | +LL ~ r" +LL | \a +LL | multiline +LL | string +LL ~ "; + | + +error: unnecessary hashes around raw string literal + --> $DIR/needless_raw_string_hashes.rs:25:5 + | +LL | r###"rust"###; + | ^^^^^^^^^^^^^ + | +help: remove all the hashes around the literal + | +LL - r###"rust"###; +LL + r"rust"; + | + +error: unnecessary hashes around raw string literal + --> $DIR/needless_raw_string_hashes.rs:26:5 + | +LL | r#"hello world"#; + | ^^^^^^^^^^^^^^^^ + | +help: remove all the hashes around the literal + | +LL - r#"hello world"#; +LL + r"hello world"; + | -error: aborting due to 6 previous errors +error: aborting due to 15 previous errors diff --git a/src/tools/clippy/tests/ui/needless_return.fixed b/src/tools/clippy/tests/ui/needless_return.fixed index 4dabf3139..f9eb39d49 100644 --- a/src/tools/clippy/tests/ui/needless_return.fixed +++ b/src/tools/clippy/tests/ui/needless_return.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(lint_reasons)] #![feature(yeet_expr)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/needless_return.rs b/src/tools/clippy/tests/ui/needless_return.rs index 542f562b3..4dd2e22ea 100644 --- a/src/tools/clippy/tests/ui/needless_return.rs +++ b/src/tools/clippy/tests/ui/needless_return.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(lint_reasons)] #![feature(yeet_expr)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/needless_return.stderr b/src/tools/clippy/tests/ui/needless_return.stderr index 1d9d23d30..cc4883111 100644 --- a/src/tools/clippy/tests/ui/needless_return.stderr +++ b/src/tools/clippy/tests/ui/needless_return.stderr @@ -1,10 +1,11 @@ error: unneeded `return` statement - --> $DIR/needless_return.rs:28:5 + --> $DIR/needless_return.rs:26:5 | LL | return true; | ^^^^^^^^^^^ | = note: `-D clippy::needless-return` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_return)]` help: remove `return` | LL - return true; @@ -12,7 +13,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:32:5 + --> $DIR/needless_return.rs:30:5 | LL | return true; | ^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:37:5 + --> $DIR/needless_return.rs:35:5 | LL | return true;;; | ^^^^^^^^^^^ @@ -36,7 +37,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:42:5 + --> $DIR/needless_return.rs:40:5 | LL | return true;; ; ; | ^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:47:9 + --> $DIR/needless_return.rs:45:9 | LL | return true; | ^^^^^^^^^^^ @@ -60,7 +61,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:49:9 + --> $DIR/needless_return.rs:47:9 | LL | return false; | ^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL + false | error: unneeded `return` statement - --> $DIR/needless_return.rs:55:17 + --> $DIR/needless_return.rs:53:17 | LL | true => return false, | ^^^^^^^^^^^^ @@ -83,7 +84,7 @@ LL | true => false, | ~~~~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:57:13 + --> $DIR/needless_return.rs:55:13 | LL | return true; | ^^^^^^^^^^^ @@ -95,7 +96,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:64:9 + --> $DIR/needless_return.rs:62:9 | LL | return true; | ^^^^^^^^^^^ @@ -107,7 +108,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:66:16 + --> $DIR/needless_return.rs:64:16 | LL | let _ = || return true; | ^^^^^^^^^^^ @@ -118,7 +119,7 @@ LL | let _ = || true; | ~~~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:70:5 + --> $DIR/needless_return.rs:68:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^ @@ -130,7 +131,7 @@ LL + the_answer!() | error: unneeded `return` statement - --> $DIR/needless_return.rs:73:21 + --> $DIR/needless_return.rs:71:21 | LL | fn test_void_fun() { | _____________________^ @@ -145,7 +146,7 @@ LL + fn test_void_fun() { | error: unneeded `return` statement - --> $DIR/needless_return.rs:78:11 + --> $DIR/needless_return.rs:76:11 | LL | if b { | ___________^ @@ -160,7 +161,7 @@ LL + if b { | error: unneeded `return` statement - --> $DIR/needless_return.rs:80:13 + --> $DIR/needless_return.rs:78:13 | LL | } else { | _____________^ @@ -175,7 +176,7 @@ LL + } else { | error: unneeded `return` statement - --> $DIR/needless_return.rs:88:14 + --> $DIR/needless_return.rs:86:14 | LL | _ => return, | ^^^^^^ @@ -186,7 +187,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:96:24 + --> $DIR/needless_return.rs:94:24 | LL | let _ = 42; | ________________________^ @@ -201,7 +202,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> $DIR/needless_return.rs:99:14 + --> $DIR/needless_return.rs:97:14 | LL | _ => return, | ^^^^^^ @@ -212,7 +213,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:112:9 + --> $DIR/needless_return.rs:110:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -224,7 +225,7 @@ LL + String::from("test") | error: unneeded `return` statement - --> $DIR/needless_return.rs:114:9 + --> $DIR/needless_return.rs:112:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -236,7 +237,7 @@ LL + String::new() | error: unneeded `return` statement - --> $DIR/needless_return.rs:136:32 + --> $DIR/needless_return.rs:134:32 | LL | bar.unwrap_or_else(|_| return) | ^^^^^^ @@ -247,7 +248,7 @@ LL | bar.unwrap_or_else(|_| {}) | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:140:21 + --> $DIR/needless_return.rs:138:21 | LL | let _ = || { | _____________________^ @@ -262,7 +263,7 @@ LL + let _ = || { | error: unneeded `return` statement - --> $DIR/needless_return.rs:143:20 + --> $DIR/needless_return.rs:141:20 | LL | let _ = || return; | ^^^^^^ @@ -273,7 +274,7 @@ LL | let _ = || {}; | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:149:32 + --> $DIR/needless_return.rs:147:32 | LL | res.unwrap_or_else(|_| return Foo) | ^^^^^^^^^^ @@ -284,7 +285,7 @@ LL | res.unwrap_or_else(|_| Foo) | ~~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:158:5 + --> $DIR/needless_return.rs:156:5 | LL | return true; | ^^^^^^^^^^^ @@ -296,7 +297,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:162:5 + --> $DIR/needless_return.rs:160:5 | LL | return true; | ^^^^^^^^^^^ @@ -308,7 +309,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:167:9 + --> $DIR/needless_return.rs:165:9 | LL | return true; | ^^^^^^^^^^^ @@ -320,7 +321,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:169:9 + --> $DIR/needless_return.rs:167:9 | LL | return false; | ^^^^^^^^^^^^ @@ -332,7 +333,7 @@ LL + false | error: unneeded `return` statement - --> $DIR/needless_return.rs:175:17 + --> $DIR/needless_return.rs:173:17 | LL | true => return false, | ^^^^^^^^^^^^ @@ -343,7 +344,7 @@ LL | true => false, | ~~~~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:177:13 + --> $DIR/needless_return.rs:175:13 | LL | return true; | ^^^^^^^^^^^ @@ -355,7 +356,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:184:9 + --> $DIR/needless_return.rs:182:9 | LL | return true; | ^^^^^^^^^^^ @@ -367,7 +368,7 @@ LL + true | error: unneeded `return` statement - --> $DIR/needless_return.rs:186:16 + --> $DIR/needless_return.rs:184:16 | LL | let _ = || return true; | ^^^^^^^^^^^ @@ -378,7 +379,7 @@ LL | let _ = || true; | ~~~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:190:5 + --> $DIR/needless_return.rs:188:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^ @@ -390,7 +391,7 @@ LL + the_answer!() | error: unneeded `return` statement - --> $DIR/needless_return.rs:193:33 + --> $DIR/needless_return.rs:191:33 | LL | async fn async_test_void_fun() { | _________________________________^ @@ -405,7 +406,7 @@ LL + async fn async_test_void_fun() { | error: unneeded `return` statement - --> $DIR/needless_return.rs:198:11 + --> $DIR/needless_return.rs:196:11 | LL | if b { | ___________^ @@ -420,7 +421,7 @@ LL + if b { | error: unneeded `return` statement - --> $DIR/needless_return.rs:200:13 + --> $DIR/needless_return.rs:198:13 | LL | } else { | _____________^ @@ -435,7 +436,7 @@ LL + } else { | error: unneeded `return` statement - --> $DIR/needless_return.rs:208:14 + --> $DIR/needless_return.rs:206:14 | LL | _ => return, | ^^^^^^ @@ -446,7 +447,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> $DIR/needless_return.rs:221:9 + --> $DIR/needless_return.rs:219:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -458,7 +459,7 @@ LL + String::from("test") | error: unneeded `return` statement - --> $DIR/needless_return.rs:223:9 + --> $DIR/needless_return.rs:221:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -470,7 +471,7 @@ LL + String::new() | error: unneeded `return` statement - --> $DIR/needless_return.rs:239:5 + --> $DIR/needless_return.rs:237:5 | LL | return format!("Hello {}", "world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -482,7 +483,7 @@ LL + format!("Hello {}", "world!") | error: unneeded `return` statement - --> $DIR/needless_return.rs:251:9 + --> $DIR/needless_return.rs:249:9 | LL | return true; | ^^^^^^^^^^^ @@ -496,7 +497,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:253:9 + --> $DIR/needless_return.rs:251:9 | LL | return false; | ^^^^^^^^^^^^ @@ -508,7 +509,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:260:13 + --> $DIR/needless_return.rs:258:13 | LL | return 10; | ^^^^^^^^^ @@ -523,7 +524,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:263:13 + --> $DIR/needless_return.rs:261:13 | LL | return 100; | ^^^^^^^^^^ @@ -536,7 +537,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:271:9 + --> $DIR/needless_return.rs:269:9 | LL | return 0; | ^^^^^^^^ @@ -548,7 +549,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:278:13 + --> $DIR/needless_return.rs:276:13 | LL | return *(x as *const isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -563,7 +564,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:280:13 + --> $DIR/needless_return.rs:278:13 | LL | return !*(x as *const isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -576,7 +577,7 @@ LL ~ } | error: unneeded `return` statement - --> $DIR/needless_return.rs:287:20 + --> $DIR/needless_return.rs:285:20 | LL | let _ = 42; | ____________________^ @@ -593,7 +594,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> $DIR/needless_return.rs:294:20 + --> $DIR/needless_return.rs:292:20 | LL | let _ = 42; return; | ^^^^^^^ @@ -605,7 +606,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> $DIR/needless_return.rs:306:9 + --> $DIR/needless_return.rs:304:9 | LL | return Ok(format!("ok!")); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -617,7 +618,7 @@ LL + Ok(format!("ok!")) | error: unneeded `return` statement - --> $DIR/needless_return.rs:308:9 + --> $DIR/needless_return.rs:306:9 | LL | return Err(format!("err!")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -629,7 +630,7 @@ LL + Err(format!("err!")) | error: unneeded `return` statement - --> $DIR/needless_return.rs:314:9 + --> $DIR/needless_return.rs:312:9 | LL | return if true { 1 } else { 2 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -641,7 +642,7 @@ LL + if true { 1 } else { 2 } | error: unneeded `return` statement - --> $DIR/needless_return.rs:318:9 + --> $DIR/needless_return.rs:316:9 | LL | return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/needless_return_with_question_mark.fixed b/src/tools/clippy/tests/ui/needless_return_with_question_mark.fixed index d6e47d07b..52d541809 100644 --- a/src/tools/clippy/tests/ui/needless_return_with_question_mark.fixed +++ b/src/tools/clippy/tests/ui/needless_return_with_question_mark.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow( clippy::needless_return, clippy::no_effect, diff --git a/src/tools/clippy/tests/ui/needless_return_with_question_mark.rs b/src/tools/clippy/tests/ui/needless_return_with_question_mark.rs index 4fc04d363..d253cae4d 100644 --- a/src/tools/clippy/tests/ui/needless_return_with_question_mark.rs +++ b/src/tools/clippy/tests/ui/needless_return_with_question_mark.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow( clippy::needless_return, clippy::no_effect, diff --git a/src/tools/clippy/tests/ui/needless_return_with_question_mark.stderr b/src/tools/clippy/tests/ui/needless_return_with_question_mark.stderr index e1d91638d..0de063380 100644 --- a/src/tools/clippy/tests/ui/needless_return_with_question_mark.stderr +++ b/src/tools/clippy/tests/ui/needless_return_with_question_mark.stderr @@ -1,10 +1,11 @@ error: unneeded `return` statement with `?` operator - --> $DIR/needless_return_with_question_mark.rs:28:5 + --> $DIR/needless_return_with_question_mark.rs:27:5 | LL | return Err(())?; | ^^^^^^^ help: remove it | = note: `-D clippy::needless-return-with-question-mark` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_return_with_question_mark)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/needless_splitn.fixed b/src/tools/clippy/tests/ui/needless_splitn.fixed index 30a038312..efc47533e 100644 --- a/src/tools/clippy/tests/ui/needless_splitn.fixed +++ b/src/tools/clippy/tests/ui/needless_splitn.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@edition:2018 #![warn(clippy::needless_splitn)] diff --git a/src/tools/clippy/tests/ui/needless_splitn.rs b/src/tools/clippy/tests/ui/needless_splitn.rs index 1b0b9a598..a4a3736ee 100644 --- a/src/tools/clippy/tests/ui/needless_splitn.rs +++ b/src/tools/clippy/tests/ui/needless_splitn.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@edition:2018 #![warn(clippy::needless_splitn)] diff --git a/src/tools/clippy/tests/ui/needless_splitn.stderr b/src/tools/clippy/tests/ui/needless_splitn.stderr index 0005f7581..f347ca760 100644 --- a/src/tools/clippy/tests/ui/needless_splitn.stderr +++ b/src/tools/clippy/tests/ui/needless_splitn.stderr @@ -1,79 +1,80 @@ error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:14:13 + --> $DIR/needless_splitn.rs:13:13 | LL | let _ = str.splitn(2, '=').next(); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` | = note: `-D clippy::needless-splitn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_splitn)]` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:15:13 + --> $DIR/needless_splitn.rs:14:13 | LL | let _ = str.splitn(2, '=').nth(0); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:18:18 + --> $DIR/needless_splitn.rs:17:18 | LL | let (_, _) = str.splitn(3, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:21:13 + --> $DIR/needless_splitn.rs:20:13 | LL | let _ = str.rsplitn(2, '=').next(); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:22:13 + --> $DIR/needless_splitn.rs:21:13 | LL | let _ = str.rsplitn(2, '=').nth(0); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:25:18 + --> $DIR/needless_splitn.rs:24:18 | LL | let (_, _) = str.rsplitn(3, '=').next_tuple().unwrap(); | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:27:13 + --> $DIR/needless_splitn.rs:26:13 | LL | let _ = str.splitn(5, '=').next(); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:28:13 + --> $DIR/needless_splitn.rs:27:13 | LL | let _ = str.splitn(5, '=').nth(3); | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:34:13 + --> $DIR/needless_splitn.rs:33:13 | LL | let _ = s.splitn(2, '=').next()?; | ^^^^^^^^^^^^^^^^ help: try: `s.split('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:35:13 + --> $DIR/needless_splitn.rs:34:13 | LL | let _ = s.splitn(2, '=').nth(0)?; | ^^^^^^^^^^^^^^^^ help: try: `s.split('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:36:13 + --> $DIR/needless_splitn.rs:35:13 | LL | let _ = s.rsplitn(2, '=').next()?; | ^^^^^^^^^^^^^^^^^ help: try: `s.rsplit('=')` error: unnecessary use of `rsplitn` - --> $DIR/needless_splitn.rs:37:13 + --> $DIR/needless_splitn.rs:36:13 | LL | let _ = s.rsplitn(2, '=').nth(0)?; | ^^^^^^^^^^^^^^^^^ help: try: `s.rsplit('=')` error: unnecessary use of `splitn` - --> $DIR/needless_splitn.rs:45:13 + --> $DIR/needless_splitn.rs:44:13 | LL | let _ = "key=value".splitn(2, '=').nth(0).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split('=')` diff --git a/src/tools/clippy/tests/ui/needless_update.rs b/src/tools/clippy/tests/ui/needless_update.rs index 4e8517cad..7c59abf07 100644 --- a/src/tools/clippy/tests/ui/needless_update.rs +++ b/src/tools/clippy/tests/ui/needless_update.rs @@ -17,6 +17,8 @@ fn main() { S { ..base }; // no error S { a: 1, ..base }; // no error S { a: 1, b: 1, ..base }; + //~^ ERROR: struct update has no effect, all the fields in the struct have already bee + //~| NOTE: `-D clippy::needless-update` implied by `-D warnings` let base = T { x: 0, y: 0 }; T { ..base }; // no error diff --git a/src/tools/clippy/tests/ui/needless_update.stderr b/src/tools/clippy/tests/ui/needless_update.stderr index b154b3b30..3e9e2941a 100644 --- a/src/tools/clippy/tests/ui/needless_update.stderr +++ b/src/tools/clippy/tests/ui/needless_update.stderr @@ -5,6 +5,7 @@ LL | S { a: 1, b: 1, ..base }; | ^^^^ | = note: `-D clippy::needless-update` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_update)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/neg_cmp_op_on_partial_ord.rs b/src/tools/clippy/tests/ui/neg_cmp_op_on_partial_ord.rs index 2d392c593..c79fd2665 100644 --- a/src/tools/clippy/tests/ui/neg_cmp_op_on_partial_ord.rs +++ b/src/tools/clippy/tests/ui/neg_cmp_op_on_partial_ord.rs @@ -14,15 +14,20 @@ fn main() { // Not Less but potentially Greater, Equal or Uncomparable. let _not_less = !(a_value < another_value); + //~^ ERROR: the use of negated comparison operators on partially ordered types produce + //~| NOTE: `-D clippy::neg-cmp-op-on-partial-ord` implied by `-D warnings` // Not Less or Equal but potentially Greater or Uncomparable. let _not_less_or_equal = !(a_value <= another_value); + //~^ ERROR: the use of negated comparison operators on partially ordered types produce // Not Greater but potentially Less, Equal or Uncomparable. let _not_greater = !(a_value > another_value); + //~^ ERROR: the use of negated comparison operators on partially ordered types produce // Not Greater or Equal but potentially Less or Uncomparable. let _not_greater_or_equal = !(a_value >= another_value); + //~^ ERROR: the use of negated comparison operators on partially ordered types produce // --- Good --- diff --git a/src/tools/clippy/tests/ui/neg_cmp_op_on_partial_ord.stderr b/src/tools/clippy/tests/ui/neg_cmp_op_on_partial_ord.stderr index c78560007..c64d96b4b 100644 --- a/src/tools/clippy/tests/ui/neg_cmp_op_on_partial_ord.stderr +++ b/src/tools/clippy/tests/ui/neg_cmp_op_on_partial_ord.stderr @@ -5,21 +5,22 @@ LL | let _not_less = !(a_value < another_value); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::neg-cmp-op-on-partial-ord` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::neg_cmp_op_on_partial_ord)]` error: the use of negated comparison operators on partially ordered types produces code that is hard to read and refactor, please consider using the `partial_cmp` method instead, to make it clear that the two values could be incomparable - --> $DIR/neg_cmp_op_on_partial_ord.rs:19:30 + --> $DIR/neg_cmp_op_on_partial_ord.rs:21:30 | LL | let _not_less_or_equal = !(a_value <= another_value); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the use of negated comparison operators on partially ordered types produces code that is hard to read and refactor, please consider using the `partial_cmp` method instead, to make it clear that the two values could be incomparable - --> $DIR/neg_cmp_op_on_partial_ord.rs:22:24 + --> $DIR/neg_cmp_op_on_partial_ord.rs:25:24 | LL | let _not_greater = !(a_value > another_value); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the use of negated comparison operators on partially ordered types produces code that is hard to read and refactor, please consider using the `partial_cmp` method instead, to make it clear that the two values could be incomparable - --> $DIR/neg_cmp_op_on_partial_ord.rs:25:33 + --> $DIR/neg_cmp_op_on_partial_ord.rs:29:33 | LL | let _not_greater_or_equal = !(a_value >= another_value); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/neg_multiply.fixed b/src/tools/clippy/tests/ui/neg_multiply.fixed index e07e7c88d..52edea73a 100644 --- a/src/tools/clippy/tests/ui/neg_multiply.fixed +++ b/src/tools/clippy/tests/ui/neg_multiply.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::neg_multiply)] #![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::precedence)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/neg_multiply.rs b/src/tools/clippy/tests/ui/neg_multiply.rs index 2887af7b4..23092a35e 100644 --- a/src/tools/clippy/tests/ui/neg_multiply.rs +++ b/src/tools/clippy/tests/ui/neg_multiply.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::neg_multiply)] #![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::precedence)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/neg_multiply.stderr b/src/tools/clippy/tests/ui/neg_multiply.stderr index 388ef29eb..abfc94f97 100644 --- a/src/tools/clippy/tests/ui/neg_multiply.stderr +++ b/src/tools/clippy/tests/ui/neg_multiply.stderr @@ -1,49 +1,50 @@ error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:29:5 + --> $DIR/neg_multiply.rs:28:5 | LL | x * -1; | ^^^^^^ help: consider using: `-x` | = note: `-D clippy::neg-multiply` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::neg_multiply)]` error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:31:5 + --> $DIR/neg_multiply.rs:30:5 | LL | -1 * x; | ^^^^^^ help: consider using: `-x` error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:33:11 + --> $DIR/neg_multiply.rs:32:11 | LL | 100 + x * -1; | ^^^^^^ help: consider using: `-x` error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:35:5 + --> $DIR/neg_multiply.rs:34:5 | LL | (100 + x) * -1; | ^^^^^^^^^^^^^^ help: consider using: `-(100 + x)` error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:37:5 + --> $DIR/neg_multiply.rs:36:5 | LL | -1 * 17; | ^^^^^^^ help: consider using: `-17` error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:39:14 + --> $DIR/neg_multiply.rs:38:14 | LL | 0xcafe | 0xff00 * -1; | ^^^^^^^^^^^ help: consider using: `-0xff00` error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:41:5 + --> $DIR/neg_multiply.rs:40:5 | LL | 3_usize as i32 * -1; | ^^^^^^^^^^^^^^^^^^^ help: consider using: `-(3_usize as i32)` error: this multiplication by -1 can be written more succinctly - --> $DIR/neg_multiply.rs:42:5 + --> $DIR/neg_multiply.rs:41:5 | LL | (3_usize as i32) * -1; | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `-(3_usize as i32)` diff --git a/src/tools/clippy/tests/ui/never_loop.rs b/src/tools/clippy/tests/ui/never_loop.rs index eb179f30e..c67a6d449 100644 --- a/src/tools/clippy/tests/ui/never_loop.rs +++ b/src/tools/clippy/tests/ui/never_loop.rs @@ -6,10 +6,12 @@ unused_variables, clippy::while_immutable_condition )] - +//@no-rustfix fn test1() { let mut x = 0; loop { + //~^ ERROR: this loop never actually loops + //~| NOTE: `#[deny(clippy::never_loop)]` on by default // clippy::never_loop x += 1; if x == 1 { @@ -32,6 +34,7 @@ fn test2() { fn test3() { let mut x = 0; loop { + //~^ ERROR: this loop never actually loops // never loops x += 1; break; @@ -52,8 +55,10 @@ fn test4() { fn test5() { let i = 0; loop { + //~^ ERROR: this loop never actually loops // never loops while i == 0 { + //~^ ERROR: this loop never actually loops // never loops break; } @@ -66,6 +71,7 @@ fn test6() { 'outer: loop { x += 1; loop { + //~^ ERROR: this loop never actually loops // never loops if x == 5 { break; @@ -102,6 +108,7 @@ fn test8() { fn test9() { let x = Some(1); while let Some(y) = x { + //~^ ERROR: this loop never actually loops // never loops return; } @@ -109,6 +116,7 @@ fn test9() { fn test10() { for x in 0..10 { + //~^ ERROR: this loop never actually loops // never loops match x { 1 => break, @@ -157,6 +165,7 @@ pub fn test13() { pub fn test14() { let mut a = true; 'outer: while a { + //~^ ERROR: this loop never actually loops // never loops while a { if a { @@ -172,6 +181,7 @@ pub fn test14() { pub fn test15() { 'label: loop { while false { + //~^ ERROR: this loop never actually loops break 'label; } } @@ -223,6 +233,7 @@ pub fn test18() { }; // never loops let _ = loop { + //~^ ERROR: this loop never actually loops let Some(x) = x else { return; }; @@ -244,9 +255,12 @@ pub fn test19() { pub fn test20() { 'a: loop { + //~^ ERROR: this loop never actually loops 'b: { break 'b 'c: { break 'a; + //~^ ERROR: sub-expression diverges + //~| NOTE: `-D clippy::diverging-sub-expression` implied by `-D warnings` }; } } @@ -278,6 +292,7 @@ pub fn test23() { for _ in 0..10 { 'block: { for _ in 0..20 { + //~^ ERROR: this loop never actually loops break 'block; } } @@ -324,7 +339,6 @@ pub fn test27() { loop { 'label: { let x = true; - // Lints because we cannot prove it's always `true` if x { break 'label; } @@ -333,6 +347,59 @@ pub fn test27() { } } +// issue 11004 +pub fn test29() { + loop { + 'label: { + if true { + break 'label; + } + return; + } + } +} + +pub fn test30() { + 'a: loop { + 'b: { + for j in 0..2 { + if j == 1 { + break 'b; + } + } + break 'a; + } + } +} + +pub fn test31(b: bool) { + 'a: loop { + 'b: { + 'c: loop { + //~^ ERROR: this loop never actually loops + if b { break 'c } else { break 'b } + } + continue 'a; + } + break 'a; + } +} + +pub fn test32() { + loop { + //~^ ERROR: this loop never actually loops + panic!("oh no"); + } + loop { + //~^ ERROR: this loop never actually loops + unimplemented!("not yet"); + } + loop { + // no error + todo!("maybe later"); + } +} + fn main() { test1(); test2(); diff --git a/src/tools/clippy/tests/ui/never_loop.stderr b/src/tools/clippy/tests/ui/never_loop.stderr index 0446c09cd..3982f36ce 100644 --- a/src/tools/clippy/tests/ui/never_loop.stderr +++ b/src/tools/clippy/tests/ui/never_loop.stderr @@ -2,9 +2,9 @@ error: this loop never actually loops --> $DIR/never_loop.rs:12:5 | LL | / loop { +LL | | +LL | | LL | | // clippy::never_loop -LL | | x += 1; -LL | | if x == 1 { ... | LL | | break; LL | | } @@ -13,9 +13,10 @@ LL | | } = note: `#[deny(clippy::never_loop)]` on by default error: this loop never actually loops - --> $DIR/never_loop.rs:34:5 + --> $DIR/never_loop.rs:36:5 | LL | / loop { +LL | | LL | | // never loops LL | | x += 1; LL | | break; @@ -23,55 +24,57 @@ LL | | } | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:54:5 + --> $DIR/never_loop.rs:57:5 | LL | / loop { +LL | | LL | | // never loops LL | | while i == 0 { -LL | | // never loops ... | LL | | return; LL | | } | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:56:9 + --> $DIR/never_loop.rs:60:9 | LL | / while i == 0 { +LL | | LL | | // never loops LL | | break; LL | | } | |_________^ error: this loop never actually loops - --> $DIR/never_loop.rs:68:9 + --> $DIR/never_loop.rs:73:9 | LL | / loop { +LL | | LL | | // never loops LL | | if x == 5 { -LL | | break; -LL | | } +... | LL | | continue 'outer; LL | | } | |_________^ error: this loop never actually loops - --> $DIR/never_loop.rs:104:5 + --> $DIR/never_loop.rs:110:5 | LL | / while let Some(y) = x { +LL | | LL | | // never loops LL | | return; LL | | } | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:111:5 + --> $DIR/never_loop.rs:118:5 | LL | / for x in 0..10 { +LL | | LL | | // never loops LL | | match x { -LL | | 1 => break, -LL | | _ => return, +... | LL | | } LL | | } | |_____^ @@ -82,62 +85,65 @@ LL | if let Some(x) = (0..10).next() { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: this loop never actually loops - --> $DIR/never_loop.rs:159:5 + --> $DIR/never_loop.rs:167:5 | LL | / 'outer: while a { +LL | | LL | | // never loops LL | | while a { -LL | | if a { ... | LL | | break 'outer; LL | | } | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:174:9 + --> $DIR/never_loop.rs:183:9 | LL | / while false { +LL | | LL | | break 'label; LL | | } | |_________^ error: this loop never actually loops - --> $DIR/never_loop.rs:225:13 + --> $DIR/never_loop.rs:235:13 | LL | let _ = loop { | _____________^ +LL | | LL | | let Some(x) = x else { LL | | return; -LL | | }; -LL | | +... | LL | | break x; LL | | }; | |_____^ error: this loop never actually loops - --> $DIR/never_loop.rs:246:5 + --> $DIR/never_loop.rs:257:5 | LL | / 'a: loop { +LL | | LL | | 'b: { LL | | break 'b 'c: { -LL | | break 'a; -LL | | }; +... | LL | | } LL | | } | |_____^ error: sub-expression diverges - --> $DIR/never_loop.rs:249:17 + --> $DIR/never_loop.rs:261:17 | LL | break 'a; | ^^^^^^^^ | = note: `-D clippy::diverging-sub-expression` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::diverging_sub_expression)]` error: this loop never actually loops - --> $DIR/never_loop.rs:280:13 + --> $DIR/never_loop.rs:294:13 | LL | / for _ in 0..20 { +LL | | LL | | break 'block; LL | | } | |_____________^ @@ -148,16 +154,31 @@ LL | if let Some(_) = (0..20).next() { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: this loop never actually loops - --> $DIR/never_loop.rs:324:5 + --> $DIR/never_loop.rs:378:13 + | +LL | / 'c: loop { +LL | | +LL | | if b { break 'c } else { break 'b } +LL | | } + | |_____________^ + +error: this loop never actually loops + --> $DIR/never_loop.rs:389:5 | LL | / loop { -LL | | 'label: { -LL | | let x = true; -LL | | // Lints because we cannot prove it's always `true` -... | -LL | | } +LL | | +LL | | panic!("oh no"); +LL | | } + | |_____^ + +error: this loop never actually loops + --> $DIR/never_loop.rs:393:5 + | +LL | / loop { +LL | | +LL | | unimplemented!("not yet"); LL | | } | |_____^ -error: aborting due to 14 previous errors +error: aborting due to 16 previous errors diff --git a/src/tools/clippy/tests/ui/new_ret_no_self.rs b/src/tools/clippy/tests/ui/new_ret_no_self.rs index 4eff62b85..b944f531e 100644 --- a/src/tools/clippy/tests/ui/new_ret_no_self.rs +++ b/src/tools/clippy/tests/ui/new_ret_no_self.rs @@ -48,6 +48,8 @@ impl R for S3 { impl S3 { // should trigger the lint pub fn new(_: String) -> impl R { + //~^ ERROR: methods called `new` usually return `Self` + //~| NOTE: `-D clippy::new-ret-no-self` implied by `-D warnings` S3 } } @@ -80,6 +82,7 @@ struct U; impl U { // should trigger lint pub fn new() -> u32 { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -89,6 +92,7 @@ struct V; impl V { // should trigger lint pub fn new(_: String) -> u32 { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -125,6 +129,7 @@ struct TupleReturnerBad; impl TupleReturnerBad { // should trigger lint pub fn new() -> (u32, u32) { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -152,6 +157,7 @@ struct MutPointerReturnerBad; impl MutPointerReturnerBad { // should trigger lint pub fn new() -> *mut V { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -170,6 +176,7 @@ struct GenericReturnerBad; impl GenericReturnerBad { // should trigger lint pub fn new() -> Option { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -223,6 +230,7 @@ mod issue5435 { pub trait TraitRet { // should trigger lint as we are in trait definition fn new() -> String; + //~^ ERROR: methods called `new` usually return `Self` } pub struct StructRet; impl TraitRet for StructRet { @@ -235,6 +243,7 @@ mod issue5435 { pub trait TraitRet2 { // should trigger lint fn new(_: String) -> String; + //~^ ERROR: methods called `new` usually return `Self` } trait TupleReturnerOk { @@ -270,6 +279,7 @@ mod issue5435 { trait TupleReturnerBad { // should trigger lint fn new() -> (u32, u32) { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -297,6 +307,7 @@ mod issue5435 { trait MutPointerReturnerBad { // should trigger lint fn new() -> *mut V { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!(); } } @@ -367,6 +378,7 @@ mod issue7344 { impl RetImplTraitNoSelf { // should trigger lint fn new(t: T) -> impl Into { + //~^ ERROR: methods called `new` usually return `Self` 1 } } @@ -388,6 +400,7 @@ mod issue7344 { impl RetImplTraitNoSelf2 { // should trigger lint fn new(t: T) -> impl Trait2<(), i32> { + //~^ ERROR: methods called `new` usually return `Self` unimplemented!() } } diff --git a/src/tools/clippy/tests/ui/new_ret_no_self.stderr b/src/tools/clippy/tests/ui/new_ret_no_self.stderr index 2b053b462..8436e101f 100644 --- a/src/tools/clippy/tests/ui/new_ret_no_self.stderr +++ b/src/tools/clippy/tests/ui/new_ret_no_self.stderr @@ -2,92 +2,104 @@ error: methods called `new` usually return `Self` --> $DIR/new_ret_no_self.rs:50:5 | LL | / pub fn new(_: String) -> impl R { +LL | | +LL | | LL | | S3 LL | | } | |_____^ | = note: `-D clippy::new-ret-no-self` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::new_ret_no_self)]` error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:82:5 + --> $DIR/new_ret_no_self.rs:84:5 | LL | / pub fn new() -> u32 { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:91:5 + --> $DIR/new_ret_no_self.rs:94:5 | LL | / pub fn new(_: String) -> u32 { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:127:5 + --> $DIR/new_ret_no_self.rs:131:5 | LL | / pub fn new() -> (u32, u32) { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:154:5 + --> $DIR/new_ret_no_self.rs:159:5 | LL | / pub fn new() -> *mut V { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:172:5 + --> $DIR/new_ret_no_self.rs:178:5 | LL | / pub fn new() -> Option { +LL | | LL | | unimplemented!(); LL | | } | |_____^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:225:9 + --> $DIR/new_ret_no_self.rs:232:9 | LL | fn new() -> String; | ^^^^^^^^^^^^^^^^^^^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:237:9 + --> $DIR/new_ret_no_self.rs:245:9 | LL | fn new(_: String) -> String; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:272:9 + --> $DIR/new_ret_no_self.rs:281:9 | LL | / fn new() -> (u32, u32) { +LL | | LL | | unimplemented!(); LL | | } | |_________^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:299:9 + --> $DIR/new_ret_no_self.rs:309:9 | LL | / fn new() -> *mut V { +LL | | LL | | unimplemented!(); LL | | } | |_________^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:369:9 + --> $DIR/new_ret_no_self.rs:380:9 | LL | / fn new(t: T) -> impl Into { +LL | | LL | | 1 LL | | } | |_________^ error: methods called `new` usually return `Self` - --> $DIR/new_ret_no_self.rs:390:9 + --> $DIR/new_ret_no_self.rs:402:9 | LL | / fn new(t: T) -> impl Trait2<(), i32> { +LL | | LL | | unimplemented!() LL | | } | |_________^ diff --git a/src/tools/clippy/tests/ui/new_without_default.fixed b/src/tools/clippy/tests/ui/new_without_default.fixed new file mode 100644 index 000000000..1c7ba1a48 --- /dev/null +++ b/src/tools/clippy/tests/ui/new_without_default.fixed @@ -0,0 +1,309 @@ +#![allow( + dead_code, + clippy::missing_safety_doc, + clippy::extra_unused_lifetimes, + clippy::extra_unused_type_parameters +)] +#![warn(clippy::new_without_default)] + +pub struct Foo; + +impl Default for Foo { + fn default() -> Self { + Self::new() + } +} + +impl Foo { + pub fn new() -> Foo { + //~^ ERROR: you should consider adding a `Default` implementation for `Foo` + //~| NOTE: `-D clippy::new-without-default` implied by `-D warnings` + Foo + } +} + +pub struct Bar; + +impl Default for Bar { + fn default() -> Self { + Self::new() + } +} + +impl Bar { + pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `Bar` + Bar + } +} + +pub struct Ok; + +impl Ok { + pub fn new() -> Self { + Ok + } +} + +impl Default for Ok { + fn default() -> Self { + Ok + } +} + +pub struct Params; + +impl Params { + pub fn new(_: u32) -> Self { + Params + } +} + +pub struct GenericsOk { + bar: T, +} + +impl Default for GenericsOk { + fn default() -> Self { + unimplemented!(); + } +} + +impl<'c, V> GenericsOk { + pub fn new() -> GenericsOk { + unimplemented!() + } +} + +pub struct LtOk<'a> { + foo: &'a bool, +} + +impl<'b> Default for LtOk<'b> { + fn default() -> Self { + unimplemented!(); + } +} + +impl<'c> LtOk<'c> { + pub fn new() -> LtOk<'c> { + unimplemented!() + } +} + +pub struct LtKo<'a> { + foo: &'a bool, +} + +impl<'c> Default for LtKo<'c> { + fn default() -> Self { + Self::new() + } +} + +impl<'c> LtKo<'c> { + pub fn new() -> LtKo<'c> { + //~^ ERROR: you should consider adding a `Default` implementation for `LtKo<'c>` + unimplemented!() + } +} + +struct Private; + +impl Private { + fn new() -> Private { + unimplemented!() + } // We don't lint private items +} + +struct PrivateStruct; + +impl PrivateStruct { + pub fn new() -> PrivateStruct { + unimplemented!() + } // We don't lint public items on private structs +} + +pub struct PrivateItem; + +impl PrivateItem { + fn new() -> PrivateItem { + unimplemented!() + } // We don't lint private items on public structs +} + +struct Const; + +impl Const { + pub const fn new() -> Const { + Const + } // const fns can't be implemented via Default +} + +pub struct IgnoreGenericNew; + +impl IgnoreGenericNew { + pub fn new() -> Self { + IgnoreGenericNew + } // the derived Default does not make sense here as the result depends on T +} + +pub trait TraitWithNew: Sized { + fn new() -> Self { + panic!() + } +} + +pub struct IgnoreUnsafeNew; + +impl IgnoreUnsafeNew { + pub unsafe fn new() -> Self { + IgnoreUnsafeNew + } +} + +#[derive(Default)] +pub struct OptionRefWrapper<'a, T>(Option<&'a T>); + +impl<'a, T> OptionRefWrapper<'a, T> { + pub fn new() -> Self { + OptionRefWrapper(None) + } +} + +pub struct Allow(Foo); + +impl Allow { + #[allow(clippy::new_without_default)] + pub fn new() -> Self { + unimplemented!() + } +} + +pub struct AllowDerive; + +impl AllowDerive { + #[allow(clippy::new_without_default)] + pub fn new() -> Self { + unimplemented!() + } +} + +pub struct NewNotEqualToDerive { + foo: i32, +} + +impl Default for NewNotEqualToDerive { + fn default() -> Self { + Self::new() + } +} + +impl NewNotEqualToDerive { + // This `new` implementation is not equal to a derived `Default`, so do not suggest deriving. + pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `NewNotEqualToDe + NewNotEqualToDerive { foo: 1 } + } +} + +// see #6933 +pub struct FooGenerics(std::marker::PhantomData); +impl Default for FooGenerics { + fn default() -> Self { + Self::new() + } +} + +impl FooGenerics { + pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `FooGenerics` + Self(Default::default()) + } +} + +pub struct BarGenerics(std::marker::PhantomData); +impl Default for BarGenerics { + fn default() -> Self { + Self::new() + } +} + +impl BarGenerics { + pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `BarGenerics` + Self(Default::default()) + } +} + +pub mod issue7220 { + pub struct Foo { + _bar: *mut T, + } + + impl Default for Foo { + fn default() -> Self { + Self::new() + } + } + + impl Foo { + pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `Foo` + todo!() + } + } +} + +// see issue #8152 +// This should not create any lints +pub struct DocHidden; +impl DocHidden { + #[doc(hidden)] + pub fn new() -> Self { + DocHidden + } +} + +fn main() {} + +pub struct IgnoreConstGenericNew(usize); +impl IgnoreConstGenericNew { + pub fn new() -> Self { + Self(N) + } +} + +pub struct IgnoreLifetimeNew; +impl IgnoreLifetimeNew { + pub fn new<'a>() -> Self { + Self + } +} + +// From issue #11267 + +pub struct MyStruct +where + K: std::hash::Hash + Eq + PartialEq, +{ + _kv: Option<(K, V)>, +} + +impl Default for MyStruct +where + K: std::hash::Hash + Eq + PartialEq, + { + fn default() -> Self { + Self::new() + } +} + +impl MyStruct +where + K: std::hash::Hash + Eq + PartialEq, +{ + pub fn new() -> Self { + Self { _kv: None } + } +} diff --git a/src/tools/clippy/tests/ui/new_without_default.rs b/src/tools/clippy/tests/ui/new_without_default.rs index 7803418cb..964aa0f63 100644 --- a/src/tools/clippy/tests/ui/new_without_default.rs +++ b/src/tools/clippy/tests/ui/new_without_default.rs @@ -10,6 +10,8 @@ pub struct Foo; impl Foo { pub fn new() -> Foo { + //~^ ERROR: you should consider adding a `Default` implementation for `Foo` + //~| NOTE: `-D clippy::new-without-default` implied by `-D warnings` Foo } } @@ -18,6 +20,7 @@ pub struct Bar; impl Bar { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `Bar` Bar } } @@ -82,9 +85,9 @@ pub struct LtKo<'a> { impl<'c> LtKo<'c> { pub fn new() -> LtKo<'c> { + //~^ ERROR: you should consider adding a `Default` implementation for `LtKo<'c>` unimplemented!() } - // FIXME: that suggestion is missing lifetimes } struct Private; @@ -175,6 +178,7 @@ pub struct NewNotEqualToDerive { impl NewNotEqualToDerive { // This `new` implementation is not equal to a derived `Default`, so do not suggest deriving. pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `NewNotEqualToDe NewNotEqualToDerive { foo: 1 } } } @@ -183,6 +187,7 @@ impl NewNotEqualToDerive { pub struct FooGenerics(std::marker::PhantomData); impl FooGenerics { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `FooGenerics` Self(Default::default()) } } @@ -190,6 +195,7 @@ impl FooGenerics { pub struct BarGenerics(std::marker::PhantomData); impl BarGenerics { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `BarGenerics` Self(Default::default()) } } @@ -201,6 +207,7 @@ pub mod issue7220 { impl Foo { pub fn new() -> Self { + //~^ ERROR: you should consider adding a `Default` implementation for `Foo` todo!() } } @@ -231,3 +238,21 @@ impl IgnoreLifetimeNew { Self } } + +// From issue #11267 + +pub struct MyStruct +where + K: std::hash::Hash + Eq + PartialEq, +{ + _kv: Option<(K, V)>, +} + +impl MyStruct +where + K: std::hash::Hash + Eq + PartialEq, +{ + pub fn new() -> Self { + Self { _kv: None } + } +} diff --git a/src/tools/clippy/tests/ui/new_without_default.stderr b/src/tools/clippy/tests/ui/new_without_default.stderr index 583dd327d..acba5b0d7 100644 --- a/src/tools/clippy/tests/ui/new_without_default.stderr +++ b/src/tools/clippy/tests/ui/new_without_default.stderr @@ -2,11 +2,14 @@ error: you should consider adding a `Default` implementation for `Foo` --> $DIR/new_without_default.rs:12:5 | LL | / pub fn new() -> Foo { +LL | | +LL | | LL | | Foo LL | | } | |_____^ | = note: `-D clippy::new-without-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::new_without_default)]` help: try adding this | LL + impl Default for Foo { @@ -17,9 +20,10 @@ LL + } | error: you should consider adding a `Default` implementation for `Bar` - --> $DIR/new_without_default.rs:20:5 + --> $DIR/new_without_default.rs:22:5 | LL | / pub fn new() -> Self { +LL | | LL | | Bar LL | | } | |_____^ @@ -34,9 +38,10 @@ LL + } | error: you should consider adding a `Default` implementation for `LtKo<'c>` - --> $DIR/new_without_default.rs:84:5 + --> $DIR/new_without_default.rs:87:5 | LL | / pub fn new() -> LtKo<'c> { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -51,9 +56,10 @@ LL + } | error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` - --> $DIR/new_without_default.rs:177:5 + --> $DIR/new_without_default.rs:180:5 | LL | / pub fn new() -> Self { +LL | | LL | | NewNotEqualToDerive { foo: 1 } LL | | } | |_____^ @@ -68,9 +74,10 @@ LL + } | error: you should consider adding a `Default` implementation for `FooGenerics` - --> $DIR/new_without_default.rs:185:5 + --> $DIR/new_without_default.rs:189:5 | LL | / pub fn new() -> Self { +LL | | LL | | Self(Default::default()) LL | | } | |_____^ @@ -85,9 +92,10 @@ LL + } | error: you should consider adding a `Default` implementation for `BarGenerics` - --> $DIR/new_without_default.rs:192:5 + --> $DIR/new_without_default.rs:197:5 | LL | / pub fn new() -> Self { +LL | | LL | | Self(Default::default()) LL | | } | |_____^ @@ -102,9 +110,10 @@ LL + } | error: you should consider adding a `Default` implementation for `Foo` - --> $DIR/new_without_default.rs:203:9 + --> $DIR/new_without_default.rs:209:9 | LL | / pub fn new() -> Self { +LL | | LL | | todo!() LL | | } | |_________^ @@ -120,5 +129,25 @@ LL + LL ~ impl Foo { | -error: aborting due to 7 previous errors +error: you should consider adding a `Default` implementation for `MyStruct` + --> $DIR/new_without_default.rs:255:5 + | +LL | / pub fn new() -> Self { +LL | | Self { _kv: None } +LL | | } + | |_____^ + | +help: try adding this + | +LL + impl Default for MyStruct +LL + where +LL + K: std::hash::Hash + Eq + PartialEq, +LL + { +LL + fn default() -> Self { +LL + Self::new() +LL + } +LL + } + | + +error: aborting due to 8 previous errors diff --git a/src/tools/clippy/tests/ui/no_effect.rs b/src/tools/clippy/tests/ui/no_effect.rs index 6a726941b..c52f43891 100644 --- a/src/tools/clippy/tests/ui/no_effect.rs +++ b/src/tools/clippy/tests/ui/no_effect.rs @@ -96,36 +96,67 @@ fn main() { let s2 = get_struct(); 0; + //~^ ERROR: statement with no effect + //~| NOTE: `-D clippy::no-effect` implied by `-D warnings` s2; + //~^ ERROR: statement with no effect Unit; + //~^ ERROR: statement with no effect Tuple(0); + //~^ ERROR: statement with no effect Struct { field: 0 }; + //~^ ERROR: statement with no effect Struct { ..s }; + //~^ ERROR: statement with no effect Union { a: 0 }; + //~^ ERROR: statement with no effect Enum::Tuple(0); + //~^ ERROR: statement with no effect Enum::Struct { field: 0 }; + //~^ ERROR: statement with no effect 5 + 6; + //~^ ERROR: statement with no effect *&42; + //~^ ERROR: statement with no effect &6; + //~^ ERROR: statement with no effect (5, 6, 7); + //~^ ERROR: statement with no effect ..; + //~^ ERROR: statement with no effect 5..; + //~^ ERROR: statement with no effect ..5; + //~^ ERROR: statement with no effect 5..6; + //~^ ERROR: statement with no effect 5..=6; + //~^ ERROR: statement with no effect [42, 55]; + //~^ ERROR: statement with no effect [42, 55][1]; + //~^ ERROR: statement with no effect (42, 55).1; + //~^ ERROR: statement with no effect [42; 55]; + //~^ ERROR: statement with no effect [42; 55][13]; + //~^ ERROR: statement with no effect let mut x = 0; || x += 5; + //~^ ERROR: statement with no effect let s: String = "foo".into(); FooString { s: s }; + //~^ ERROR: statement with no effect let _unused = 1; + //~^ ERROR: binding to `_` prefixed variable with no side-effect + //~| NOTE: `-D clippy::no-effect-underscore-binding` implied by `-D warnings` let _penguin = || println!("Some helpful closure"); + //~^ ERROR: binding to `_` prefixed variable with no side-effect let _duck = Struct { field: 0 }; + //~^ ERROR: binding to `_` prefixed variable with no side-effect let _cat = [2, 4, 6, 8][2]; + //~^ ERROR: binding to `_` prefixed variable with no side-effect #[allow(clippy::no_effect)] 0; diff --git a/src/tools/clippy/tests/ui/no_effect.stderr b/src/tools/clippy/tests/ui/no_effect.stderr index 64edfc325..feba35697 100644 --- a/src/tools/clippy/tests/ui/no_effect.stderr +++ b/src/tools/clippy/tests/ui/no_effect.stderr @@ -5,173 +5,175 @@ LL | 0; | ^^ | = note: `-D clippy::no-effect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::no_effect)]` error: statement with no effect - --> $DIR/no_effect.rs:99:5 + --> $DIR/no_effect.rs:101:5 | LL | s2; | ^^^ error: statement with no effect - --> $DIR/no_effect.rs:100:5 + --> $DIR/no_effect.rs:103:5 | LL | Unit; | ^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:101:5 + --> $DIR/no_effect.rs:105:5 | LL | Tuple(0); | ^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:102:5 + --> $DIR/no_effect.rs:107:5 | LL | Struct { field: 0 }; | ^^^^^^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:103:5 + --> $DIR/no_effect.rs:109:5 | LL | Struct { ..s }; | ^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:104:5 + --> $DIR/no_effect.rs:111:5 | LL | Union { a: 0 }; | ^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:105:5 + --> $DIR/no_effect.rs:113:5 | LL | Enum::Tuple(0); | ^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:106:5 + --> $DIR/no_effect.rs:115:5 | LL | Enum::Struct { field: 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:107:5 + --> $DIR/no_effect.rs:117:5 | LL | 5 + 6; | ^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:108:5 + --> $DIR/no_effect.rs:119:5 | LL | *&42; | ^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:109:5 + --> $DIR/no_effect.rs:121:5 | LL | &6; | ^^^ error: statement with no effect - --> $DIR/no_effect.rs:110:5 + --> $DIR/no_effect.rs:123:5 | LL | (5, 6, 7); | ^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:111:5 + --> $DIR/no_effect.rs:125:5 | LL | ..; | ^^^ error: statement with no effect - --> $DIR/no_effect.rs:112:5 + --> $DIR/no_effect.rs:127:5 | LL | 5..; | ^^^^ error: statement with no effect - --> $DIR/no_effect.rs:113:5 + --> $DIR/no_effect.rs:129:5 | LL | ..5; | ^^^^ error: statement with no effect - --> $DIR/no_effect.rs:114:5 + --> $DIR/no_effect.rs:131:5 | LL | 5..6; | ^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:115:5 + --> $DIR/no_effect.rs:133:5 | LL | 5..=6; | ^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:116:5 + --> $DIR/no_effect.rs:135:5 | LL | [42, 55]; | ^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:117:5 + --> $DIR/no_effect.rs:137:5 | LL | [42, 55][1]; | ^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:118:5 + --> $DIR/no_effect.rs:139:5 | LL | (42, 55).1; | ^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:119:5 + --> $DIR/no_effect.rs:141:5 | LL | [42; 55]; | ^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:120:5 + --> $DIR/no_effect.rs:143:5 | LL | [42; 55][13]; | ^^^^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:122:5 + --> $DIR/no_effect.rs:146:5 | LL | || x += 5; | ^^^^^^^^^^ error: statement with no effect - --> $DIR/no_effect.rs:124:5 + --> $DIR/no_effect.rs:149:5 | LL | FooString { s: s }; | ^^^^^^^^^^^^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:125:5 + --> $DIR/no_effect.rs:151:5 | LL | let _unused = 1; | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::no-effect-underscore-binding` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::no_effect_underscore_binding)]` error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:126:5 + --> $DIR/no_effect.rs:154:5 | LL | let _penguin = || println!("Some helpful closure"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:127:5 + --> $DIR/no_effect.rs:156:5 | LL | let _duck = Struct { field: 0 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: binding to `_` prefixed variable with no side-effect - --> $DIR/no_effect.rs:128:5 + --> $DIR/no_effect.rs:158:5 | LL | let _cat = [2, 4, 6, 8][2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/no_effect_replace.rs b/src/tools/clippy/tests/ui/no_effect_replace.rs index ad17d53f7..e4fd5caae 100644 --- a/src/tools/clippy/tests/ui/no_effect_replace.rs +++ b/src/tools/clippy/tests/ui/no_effect_replace.rs @@ -2,21 +2,30 @@ fn main() { let _ = "12345".replace('1', "1"); + //~^ ERROR: replacing text with itself + //~| NOTE: `-D clippy::no-effect-replace` implied by `-D warnings` let _ = "12345".replace("12", "12"); + //~^ ERROR: replacing text with itself let _ = String::new().replace("12", "12"); + //~^ ERROR: replacing text with itself let _ = "12345".replacen('1', "1", 1); + //~^ ERROR: replacing text with itself let _ = "12345".replacen("12", "12", 1); + //~^ ERROR: replacing text with itself let _ = String::new().replacen("12", "12", 1); + //~^ ERROR: replacing text with itself let _ = "12345".replace("12", "22"); let _ = "12345".replacen("12", "22", 1); let mut x = X::default(); let _ = "hello".replace(&x.f(), &x.f()); + //~^ ERROR: replacing text with itself let _ = "hello".replace(&x.f(), &x.ff()); let _ = "hello".replace(&y(), &y()); + //~^ ERROR: replacing text with itself let _ = "hello".replace(&y(), &z()); let _ = Replaceme.replace("a", "a"); diff --git a/src/tools/clippy/tests/ui/no_effect_replace.stderr b/src/tools/clippy/tests/ui/no_effect_replace.stderr index 53a28aa73..e1162f04f 100644 --- a/src/tools/clippy/tests/ui/no_effect_replace.stderr +++ b/src/tools/clippy/tests/ui/no_effect_replace.stderr @@ -5,45 +5,46 @@ LL | let _ = "12345".replace('1', "1"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::no-effect-replace` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::no_effect_replace)]` error: replacing text with itself - --> $DIR/no_effect_replace.rs:5:13 + --> $DIR/no_effect_replace.rs:7:13 | LL | let _ = "12345".replace("12", "12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:6:13 + --> $DIR/no_effect_replace.rs:9:13 | LL | let _ = String::new().replace("12", "12"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:8:13 + --> $DIR/no_effect_replace.rs:12:13 | LL | let _ = "12345".replacen('1', "1", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:9:13 + --> $DIR/no_effect_replace.rs:14:13 | LL | let _ = "12345".replacen("12", "12", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:10:13 + --> $DIR/no_effect_replace.rs:16:13 | LL | let _ = String::new().replacen("12", "12", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:16:13 + --> $DIR/no_effect_replace.rs:23:13 | LL | let _ = "hello".replace(&x.f(), &x.f()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: replacing text with itself - --> $DIR/no_effect_replace.rs:19:13 + --> $DIR/no_effect_replace.rs:27:13 | LL | let _ = "hello".replace(&y(), &y()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/no_effect_return.rs b/src/tools/clippy/tests/ui/no_effect_return.rs index 231dd063a..e46c0d735 100644 --- a/src/tools/clippy/tests/ui/no_effect_return.rs +++ b/src/tools/clippy/tests/ui/no_effect_return.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![allow(clippy::unused_unit, dead_code, unused)] #![no_main] @@ -6,6 +7,8 @@ use std::ops::ControlFlow; fn a() -> u32 { { 0u32; + //~^ ERROR: statement with no effect + //~| NOTE: `-D clippy::no-effect` implied by `-D warnings` } 0 } @@ -13,6 +16,7 @@ fn a() -> u32 { async fn b() -> u32 { { 0u32; + //~^ ERROR: statement with no effect } 0 } @@ -21,6 +25,7 @@ type C = i32; async fn c() -> C { { 0i32 as C; + //~^ ERROR: statement with no effect } 0 } @@ -29,6 +34,7 @@ fn d() -> u128 { { // not last stmt 0u128; + //~^ ERROR: statement with no effect println!("lol"); } 0 @@ -38,6 +44,7 @@ fn e() -> u32 { { // mismatched types 0u16; + //~^ ERROR: statement with no effect } 0 } @@ -45,6 +52,7 @@ fn e() -> u32 { fn f() -> [u16; 1] { { [1u16]; + //~^ ERROR: statement with no effect } [1] } @@ -52,6 +60,7 @@ fn f() -> [u16; 1] { fn g() -> ControlFlow<()> { { ControlFlow::Break::<()>(()); + //~^ ERROR: statement with no effect } ControlFlow::Continue(()) } @@ -67,7 +76,9 @@ fn h() -> Vec { fn i() -> () { { + // does not suggest on function with explicit unit return type (); + //~^ ERROR: statement with no effect } () } @@ -76,6 +87,7 @@ fn j() { { // does not suggest on function without explicit return type (); + //~^ ERROR: statement with no effect } () } diff --git a/src/tools/clippy/tests/ui/no_effect_return.stderr b/src/tools/clippy/tests/ui/no_effect_return.stderr index 779900e18..aed079f09 100644 --- a/src/tools/clippy/tests/ui/no_effect_return.stderr +++ b/src/tools/clippy/tests/ui/no_effect_return.stderr @@ -1,5 +1,5 @@ error: statement with no effect - --> $DIR/no_effect_return.rs:8:9 + --> $DIR/no_effect_return.rs:9:9 | LL | 0u32; | -^^^^ @@ -7,9 +7,10 @@ LL | 0u32; | help: did you mean to return it?: `return` | = note: `-D clippy::no-effect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::no_effect)]` error: statement with no effect - --> $DIR/no_effect_return.rs:15:9 + --> $DIR/no_effect_return.rs:18:9 | LL | 0u32; | -^^^^ @@ -17,7 +18,7 @@ LL | 0u32; | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:23:9 + --> $DIR/no_effect_return.rs:27:9 | LL | 0i32 as C; | -^^^^^^^^^ @@ -25,19 +26,19 @@ LL | 0i32 as C; | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:31:9 + --> $DIR/no_effect_return.rs:36:9 | LL | 0u128; | ^^^^^^ error: statement with no effect - --> $DIR/no_effect_return.rs:40:9 + --> $DIR/no_effect_return.rs:46:9 | LL | 0u16; | ^^^^^ error: statement with no effect - --> $DIR/no_effect_return.rs:47:9 + --> $DIR/no_effect_return.rs:54:9 | LL | [1u16]; | -^^^^^^ @@ -45,7 +46,7 @@ LL | [1u16]; | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:54:9 + --> $DIR/no_effect_return.rs:62:9 | LL | ControlFlow::Break::<()>(()); | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -53,15 +54,13 @@ LL | ControlFlow::Break::<()>(()); | help: did you mean to return it?: `return` error: statement with no effect - --> $DIR/no_effect_return.rs:70:9 + --> $DIR/no_effect_return.rs:80:9 | LL | (); - | -^^ - | | - | help: did you mean to return it?: `return` + | ^^^ error: statement with no effect - --> $DIR/no_effect_return.rs:78:9 + --> $DIR/no_effect_return.rs:89:9 | LL | (); | ^^^ diff --git a/src/tools/clippy/tests/ui/no_mangle_with_rust_abi.rs b/src/tools/clippy/tests/ui/no_mangle_with_rust_abi.rs index 818119f7b..8c1ea81d2 100644 --- a/src/tools/clippy/tests/ui/no_mangle_with_rust_abi.rs +++ b/src/tools/clippy/tests/ui/no_mangle_with_rust_abi.rs @@ -1,24 +1,31 @@ +//@no-rustfix: overlapping suggestions #![allow(unused)] #![warn(clippy::no_mangle_with_rust_abi)] #[no_mangle] fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} +//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI +//~| NOTE: `-D clippy::no-mangle-with-rust-abi` implied by `-D warnings` #[no_mangle] pub fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} +//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI /// # Safety /// This function shouldn't be called unless the horsemen are ready #[no_mangle] pub unsafe fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} +//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI /// # Safety /// This function shouldn't be called unless the horsemen are ready #[no_mangle] unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} +//~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI #[no_mangle] fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( + //~^ ERROR: `#[no_mangle]` set on a function with the default (`Rust`) ABI arg_one: u32, arg_two: usize, ) -> u32 { diff --git a/src/tools/clippy/tests/ui/no_mangle_with_rust_abi.stderr b/src/tools/clippy/tests/ui/no_mangle_with_rust_abi.stderr index da5d31d8f..62d53c839 100644 --- a/src/tools/clippy/tests/ui/no_mangle_with_rust_abi.stderr +++ b/src/tools/clippy/tests/ui/no_mangle_with_rust_abi.stderr @@ -1,10 +1,11 @@ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> $DIR/no_mangle_with_rust_abi.rs:5:1 + --> $DIR/no_mangle_with_rust_abi.rs:6:1 | LL | fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::no-mangle-with-rust-abi` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::no_mangle_with_rust_abi)]` help: set an ABI | LL | extern "C" fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} @@ -15,7 +16,7 @@ LL | extern "Rust" fn rust_abi_fn_one(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> $DIR/no_mangle_with_rust_abi.rs:8:1 + --> $DIR/no_mangle_with_rust_abi.rs:11:1 | LL | pub fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,7 +31,7 @@ LL | pub extern "Rust" fn rust_abi_fn_two(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> $DIR/no_mangle_with_rust_abi.rs:13:1 + --> $DIR/no_mangle_with_rust_abi.rs:17:1 | LL | pub unsafe fn rust_abi_fn_three(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -45,7 +46,7 @@ LL | pub unsafe extern "Rust" fn rust_abi_fn_three(arg_one: u32, arg_two: usize) | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> $DIR/no_mangle_with_rust_abi.rs:18:1 + --> $DIR/no_mangle_with_rust_abi.rs:23:1 | LL | unsafe fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,9 +61,10 @@ LL | unsafe extern "Rust" fn rust_abi_fn_four(arg_one: u32, arg_two: usize) {} | +++++++++++++ error: `#[no_mangle]` set on a function with the default (`Rust`) ABI - --> $DIR/no_mangle_with_rust_abi.rs:21:1 + --> $DIR/no_mangle_with_rust_abi.rs:27:1 | LL | / fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lines( +LL | | LL | | arg_one: u32, LL | | arg_two: usize, LL | | ) -> u32 { diff --git a/src/tools/clippy/tests/ui/non_canonical_clone_impl.fixed b/src/tools/clippy/tests/ui/non_canonical_clone_impl.fixed new file mode 100644 index 000000000..165702b30 --- /dev/null +++ b/src/tools/clippy/tests/ui/non_canonical_clone_impl.fixed @@ -0,0 +1,96 @@ +#![allow(clippy::clone_on_copy, unused)] +#![no_main] + +// lint + +struct A(u32); + +impl Clone for A { + fn clone(&self) -> Self { *self } + + +} + +impl Copy for A {} + +// do not lint + +struct B(u32); + +impl Clone for B { + fn clone(&self) -> Self { + *self + } +} + +impl Copy for B {} + +// do not lint derived (clone's implementation is `*self` here anyway) + +#[derive(Clone, Copy)] +struct C(u32); + +// do not lint derived (fr this time) + +struct D(u32); + +#[automatically_derived] +impl Clone for D { + fn clone(&self) -> Self { + Self(self.0) + } + + fn clone_from(&mut self, source: &Self) { + source.clone(); + *self = source.clone(); + } +} + +impl Copy for D {} + +// do not lint if clone is not manually implemented + +struct E(u32); + +#[automatically_derived] +impl Clone for E { + fn clone(&self) -> Self { + Self(self.0) + } + + fn clone_from(&mut self, source: &Self) { + source.clone(); + *self = source.clone(); + } +} + +impl Copy for E {} + +// lint since clone is not derived + +#[derive(Copy)] +struct F(u32); + +impl Clone for F { + fn clone(&self) -> Self { *self } + + +} + +// do not lint since copy has more restrictive bounds + +#[derive(Eq, PartialEq)] +struct Uwu(A); + +impl Clone for Uwu { + fn clone(&self) -> Self { + Self(self.0) + } + + fn clone_from(&mut self, source: &Self) { + source.clone(); + *self = source.clone(); + } +} + +impl Copy for Uwu {} diff --git a/src/tools/clippy/tests/ui/non_canonical_clone_impl.rs b/src/tools/clippy/tests/ui/non_canonical_clone_impl.rs new file mode 100644 index 000000000..3b07dd5ce --- /dev/null +++ b/src/tools/clippy/tests/ui/non_canonical_clone_impl.rs @@ -0,0 +1,106 @@ +#![allow(clippy::clone_on_copy, unused)] +#![no_main] + +// lint + +struct A(u32); + +impl Clone for A { + fn clone(&self) -> Self { + Self(self.0) + } + + fn clone_from(&mut self, source: &Self) { + source.clone(); + *self = source.clone(); + } +} + +impl Copy for A {} + +// do not lint + +struct B(u32); + +impl Clone for B { + fn clone(&self) -> Self { + *self + } +} + +impl Copy for B {} + +// do not lint derived (clone's implementation is `*self` here anyway) + +#[derive(Clone, Copy)] +struct C(u32); + +// do not lint derived (fr this time) + +struct D(u32); + +#[automatically_derived] +impl Clone for D { + fn clone(&self) -> Self { + Self(self.0) + } + + fn clone_from(&mut self, source: &Self) { + source.clone(); + *self = source.clone(); + } +} + +impl Copy for D {} + +// do not lint if clone is not manually implemented + +struct E(u32); + +#[automatically_derived] +impl Clone for E { + fn clone(&self) -> Self { + Self(self.0) + } + + fn clone_from(&mut self, source: &Self) { + source.clone(); + *self = source.clone(); + } +} + +impl Copy for E {} + +// lint since clone is not derived + +#[derive(Copy)] +struct F(u32); + +impl Clone for F { + fn clone(&self) -> Self { + Self(self.0) + } + + fn clone_from(&mut self, source: &Self) { + source.clone(); + *self = source.clone(); + } +} + +// do not lint since copy has more restrictive bounds + +#[derive(Eq, PartialEq)] +struct Uwu(A); + +impl Clone for Uwu { + fn clone(&self) -> Self { + Self(self.0) + } + + fn clone_from(&mut self, source: &Self) { + source.clone(); + *self = source.clone(); + } +} + +impl Copy for Uwu {} diff --git a/src/tools/clippy/tests/ui/non_canonical_clone_impl.stderr b/src/tools/clippy/tests/ui/non_canonical_clone_impl.stderr new file mode 100644 index 000000000..44196751b --- /dev/null +++ b/src/tools/clippy/tests/ui/non_canonical_clone_impl.stderr @@ -0,0 +1,41 @@ +error: non-canonical implementation of `clone` on a `Copy` type + --> $DIR/non_canonical_clone_impl.rs:9:29 + | +LL | fn clone(&self) -> Self { + | _____________________________^ +LL | | Self(self.0) +LL | | } + | |_____^ help: change this to: `{ *self }` + | + = note: `-D clippy::non-canonical-clone-impl` implied by `-D warnings` + = 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 + | +LL | / fn clone_from(&mut self, source: &Self) { +LL | | source.clone(); +LL | | *self = source.clone(); +LL | | } + | |_____^ help: remove it + +error: non-canonical implementation of `clone` on a `Copy` type + --> $DIR/non_canonical_clone_impl.rs:80:29 + | +LL | fn clone(&self) -> Self { + | _____________________________^ +LL | | Self(self.0) +LL | | } + | |_____^ help: change this to: `{ *self }` + +error: unnecessary implementation of `clone_from` on a `Copy` type + --> $DIR/non_canonical_clone_impl.rs:84:5 + | +LL | / fn clone_from(&mut self, source: &Self) { +LL | | source.clone(); +LL | | *self = source.clone(); +LL | | } + | |_____^ help: remove it + +error: aborting due to 4 previous errors + diff --git a/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl.fixed b/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl.fixed new file mode 100644 index 000000000..db55cc094 --- /dev/null +++ b/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl.fixed @@ -0,0 +1,144 @@ +#![no_main] + +use std::cmp::Ordering; + +// lint + +#[derive(Eq, PartialEq)] +struct A(u32); + +impl Ord for A { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for A { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } +} + +// do not lint + +#[derive(Eq, PartialEq)] +struct B(u32); + +impl Ord for B { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for B { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +// lint, and give `_` a name + +#[derive(Eq, PartialEq)] +struct C(u32); + +impl Ord for C { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for C { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } +} + +// do not lint derived + +#[derive(Eq, Ord, PartialEq, PartialOrd)] +struct D(u32); + +// do not lint if ord is not manually implemented + +#[derive(Eq, PartialEq)] +struct E(u32); + +impl PartialOrd for E { + fn partial_cmp(&self, other: &Self) -> Option { + todo!(); + } +} + +// do not lint since ord has more restrictive bounds + +#[derive(Eq, PartialEq)] +struct Uwu(A); + +impl Ord for Uwu { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for Uwu { + fn partial_cmp(&self, other: &Self) -> Option { + todo!(); + } +} + +// do not lint since `Rhs` is not `Self` + +#[derive(Eq, PartialEq)] +struct F(u32); + +impl Ord for F { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for F { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl PartialEq for F { + fn eq(&self, other: &u32) -> bool { + todo!(); + } +} + +impl PartialOrd for F { + fn partial_cmp(&self, other: &u32) -> Option { + todo!(); + } +} + +// #11178, do not lint + +#[derive(Eq, PartialEq)] +struct G(u32); + +impl Ord for G { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for G { + fn partial_cmp(&self, other: &Self) -> Option { + Some(Self::cmp(self, other)) + } +} + +#[derive(Eq, PartialEq)] +struct H(u32); + +impl Ord for H { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for H { + fn partial_cmp(&self, other: &Self) -> Option { + Some(Ord::cmp(self, other)) + } +} diff --git a/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl.rs b/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl.rs new file mode 100644 index 000000000..52f4b85b9 --- /dev/null +++ b/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl.rs @@ -0,0 +1,148 @@ +#![no_main] + +use std::cmp::Ordering; + +// lint + +#[derive(Eq, PartialEq)] +struct A(u32); + +impl Ord for A { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for A { + fn partial_cmp(&self, other: &Self) -> Option { + todo!(); + } +} + +// do not lint + +#[derive(Eq, PartialEq)] +struct B(u32); + +impl Ord for B { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for B { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +// lint, and give `_` a name + +#[derive(Eq, PartialEq)] +struct C(u32); + +impl Ord for C { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for C { + fn partial_cmp(&self, _: &Self) -> Option { + todo!(); + } +} + +// do not lint derived + +#[derive(Eq, Ord, PartialEq, PartialOrd)] +struct D(u32); + +// do not lint if ord is not manually implemented + +#[derive(Eq, PartialEq)] +struct E(u32); + +impl PartialOrd for E { + fn partial_cmp(&self, other: &Self) -> Option { + todo!(); + } +} + +// do not lint since ord has more restrictive bounds + +#[derive(Eq, PartialEq)] +struct Uwu(A); + +impl Ord for Uwu { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for Uwu { + fn partial_cmp(&self, other: &Self) -> Option { + todo!(); + } +} + +// do not lint since `Rhs` is not `Self` + +#[derive(Eq, PartialEq)] +struct F(u32); + +impl Ord for F { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for F { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl PartialEq for F { + fn eq(&self, other: &u32) -> bool { + todo!(); + } +} + +impl PartialOrd for F { + fn partial_cmp(&self, other: &u32) -> Option { + todo!(); + } +} + +// #11178, do not lint + +#[derive(Eq, PartialEq)] +struct G(u32); + +impl Ord for G { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for G { + fn partial_cmp(&self, other: &Self) -> Option { + Some(Self::cmp(self, other)) + } +} + +#[derive(Eq, PartialEq)] +struct H(u32); + +impl Ord for H { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for H { + fn partial_cmp(&self, other: &Self) -> Option { + Some(Ord::cmp(self, other)) + } +} diff --git a/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl.stderr b/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl.stderr new file mode 100644 index 000000000..05cc717b9 --- /dev/null +++ b/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl.stderr @@ -0,0 +1,32 @@ +error: non-canonical implementation of `partial_cmp` on an `Ord` type + --> $DIR/non_canonical_partial_ord_impl.rs:16:1 + | +LL | / impl PartialOrd for A { +LL | | fn partial_cmp(&self, other: &Self) -> Option { + | | _____________________________________________________________- +LL | || todo!(); +LL | || } + | ||_____- help: change this to: `{ Some(self.cmp(other)) }` +LL | | } + | |__^ + | + = note: `-D clippy::non-canonical-partial-ord-impl` implied by `-D warnings` + = 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 + | +LL | / impl PartialOrd for C { +LL | | fn partial_cmp(&self, _: &Self) -> Option { +LL | | todo!(); +LL | | } +LL | | } + | |_^ + | +help: change this to + | +LL | fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } + | ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 2 previous errors + diff --git a/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs b/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs new file mode 100644 index 000000000..2f8d5cf30 --- /dev/null +++ b/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl_fully_qual.rs @@ -0,0 +1,51 @@ +// This test's filename is... a bit verbose. But it ensures we suggest the correct code when `Ord` +// is not in scope. +#![no_main] +#![no_implicit_prelude] +//@no-rustfix +extern crate std; + +use std::cmp::{self, Eq, Ordering, PartialEq, PartialOrd}; +use std::option::Option::{self, Some}; +use std::todo; + +// lint + +#[derive(Eq, PartialEq)] +struct A(u32); + +impl cmp::Ord for A { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +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 + // automatically applied + todo!(); + } +} + +#[derive(Eq, PartialEq)] +struct B(u32); + +impl B { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl cmp::Ord for B { + fn cmp(&self, other: &Self) -> Ordering { + todo!(); + } +} + +impl PartialOrd for B { + fn partial_cmp(&self, other: &Self) -> Option { + // This calls `B.cmp`, not `Ord::cmp`! + Some(self.cmp(other)) + } +} diff --git a/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl_fully_qual.stderr b/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl_fully_qual.stderr new file mode 100644 index 000000000..4978d7a87 --- /dev/null +++ b/src/tools/clippy/tests/ui/non_canonical_partial_ord_impl_fully_qual.stderr @@ -0,0 +1,32 @@ +error: non-canonical implementation of `partial_cmp` on an `Ord` type + --> $DIR/non_canonical_partial_ord_impl_fully_qual.rs:23:1 + | +LL | / impl PartialOrd for A { +LL | | fn partial_cmp(&self, other: &Self) -> Option { + | | _____________________________________________________________- +LL | || // NOTE: This suggestion is wrong, as `Ord` is not in scope. But this should be fine as it isn't +LL | || // automatically applied +LL | || todo!(); +LL | || } + | ||_____- help: change this to: `{ Some(self.cmp(other)) }` +LL | | } + | |__^ + | + = note: `-D clippy::non-canonical-partial-ord-impl` implied by `-D warnings` + = 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 + | +LL | / impl PartialOrd for B { +LL | | fn partial_cmp(&self, other: &Self) -> Option { + | | _____________________________________________________________- +LL | || // This calls `B.cmp`, not `Ord::cmp`! +LL | || Some(self.cmp(other)) +LL | || } + | ||_____- help: change this to: `{ Some(std::cmp::Ord::cmp(self, other)) }` +LL | | } + | |__^ + +error: aborting due to 2 previous errors + diff --git a/src/tools/clippy/tests/ui/non_expressive_names.stderr b/src/tools/clippy/tests/ui/non_expressive_names.stderr index b62748d49..1b78124a9 100644 --- a/src/tools/clippy/tests/ui/non_expressive_names.stderr +++ b/src/tools/clippy/tests/ui/non_expressive_names.stderr @@ -5,6 +5,7 @@ LL | let _1 = 1; | ^^ | = note: `-D clippy::just-underscores-and-digits` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::just_underscores_and_digits)]` error: consider choosing a more descriptive name --> $DIR/non_expressive_names.rs:29:9 diff --git a/src/tools/clippy/tests/ui/non_minimal_cfg.fixed b/src/tools/clippy/tests/ui/non_minimal_cfg.fixed index 430caafb3..2fcecab45 100644 --- a/src/tools/clippy/tests/ui/non_minimal_cfg.fixed +++ b/src/tools/clippy/tests/ui/non_minimal_cfg.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #[cfg(windows)] diff --git a/src/tools/clippy/tests/ui/non_minimal_cfg.rs b/src/tools/clippy/tests/ui/non_minimal_cfg.rs index a38ce1c21..e3ce11b73 100644 --- a/src/tools/clippy/tests/ui/non_minimal_cfg.rs +++ b/src/tools/clippy/tests/ui/non_minimal_cfg.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #[cfg(all(windows))] diff --git a/src/tools/clippy/tests/ui/non_minimal_cfg.stderr b/src/tools/clippy/tests/ui/non_minimal_cfg.stderr index cdfd728aa..c33c35ed8 100644 --- a/src/tools/clippy/tests/ui/non_minimal_cfg.stderr +++ b/src/tools/clippy/tests/ui/non_minimal_cfg.stderr @@ -1,25 +1,26 @@ error: unneeded sub `cfg` when there is only one condition - --> $DIR/non_minimal_cfg.rs:5:7 + --> $DIR/non_minimal_cfg.rs:3:7 | LL | #[cfg(all(windows))] | ^^^^^^^^^^^^ help: try: `windows` | = note: `-D clippy::non-minimal-cfg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::non_minimal_cfg)]` error: unneeded sub `cfg` when there is only one condition - --> $DIR/non_minimal_cfg.rs:8:7 + --> $DIR/non_minimal_cfg.rs:6:7 | LL | #[cfg(any(windows))] | ^^^^^^^^^^^^ help: try: `windows` error: unneeded sub `cfg` when there is only one condition - --> $DIR/non_minimal_cfg.rs:11:11 + --> $DIR/non_minimal_cfg.rs:9:11 | LL | #[cfg(all(any(unix), all(not(windows))))] | ^^^^^^^^^ help: try: `unix` error: unneeded sub `cfg` when there is only one condition - --> $DIR/non_minimal_cfg.rs:11:22 + --> $DIR/non_minimal_cfg.rs:9:22 | LL | #[cfg(all(any(unix), all(not(windows))))] | ^^^^^^^^^^^^^^^^^ help: try: `not(windows)` diff --git a/src/tools/clippy/tests/ui/non_minimal_cfg2.rs b/src/tools/clippy/tests/ui/non_minimal_cfg2.rs index a4c6abce3..f9e3ba4da 100644 --- a/src/tools/clippy/tests/ui/non_minimal_cfg2.rs +++ b/src/tools/clippy/tests/ui/non_minimal_cfg2.rs @@ -1,6 +1,8 @@ #![allow(unused)] #[cfg(all())] +//~^ ERROR: unneeded sub `cfg` when there is no condition +//~| NOTE: `-D clippy::non-minimal-cfg` implied by `-D warnings` fn all() {} fn main() {} diff --git a/src/tools/clippy/tests/ui/non_minimal_cfg2.stderr b/src/tools/clippy/tests/ui/non_minimal_cfg2.stderr index 2a9a36fbc..001fcddd9 100644 --- a/src/tools/clippy/tests/ui/non_minimal_cfg2.stderr +++ b/src/tools/clippy/tests/ui/non_minimal_cfg2.stderr @@ -5,6 +5,7 @@ LL | #[cfg(all())] | ^^^^^ | = note: `-D clippy::non-minimal-cfg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::non_minimal_cfg)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/non_octal_unix_permissions.fixed b/src/tools/clippy/tests/ui/non_octal_unix_permissions.fixed index 5d0da8dce..245d36cb7 100644 --- a/src/tools/clippy/tests/ui/non_octal_unix_permissions.fixed +++ b/src/tools/clippy/tests/ui/non_octal_unix_permissions.fixed @@ -1,5 +1,5 @@ //@ignore-target-windows -//@run-rustfix + #![warn(clippy::non_octal_unix_permissions)] use std::fs::{DirBuilder, File, OpenOptions, Permissions}; use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt, PermissionsExt}; diff --git a/src/tools/clippy/tests/ui/non_octal_unix_permissions.rs b/src/tools/clippy/tests/ui/non_octal_unix_permissions.rs index 04a364305..d1559cba5 100644 --- a/src/tools/clippy/tests/ui/non_octal_unix_permissions.rs +++ b/src/tools/clippy/tests/ui/non_octal_unix_permissions.rs @@ -1,5 +1,5 @@ //@ignore-target-windows -//@run-rustfix + #![warn(clippy::non_octal_unix_permissions)] use std::fs::{DirBuilder, File, OpenOptions, Permissions}; use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt, PermissionsExt}; diff --git a/src/tools/clippy/tests/ui/non_octal_unix_permissions.stderr b/src/tools/clippy/tests/ui/non_octal_unix_permissions.stderr index 32845d065..78c8f1a2f 100644 --- a/src/tools/clippy/tests/ui/non_octal_unix_permissions.stderr +++ b/src/tools/clippy/tests/ui/non_octal_unix_permissions.stderr @@ -5,6 +5,7 @@ LL | options.mode(440); | ^^^ help: consider using an octal literal instead: `0o440` | = note: `-D clippy::non-octal-unix-permissions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::non_octal_unix_permissions)]` error: using a non-octal value to set unix file permissions --> $DIR/non_octal_unix_permissions.rs:17:47 diff --git a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs index 514fb25c8..c6855a096 100644 --- a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs +++ b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs @@ -15,6 +15,7 @@ pub struct RingBuffer { } unsafe impl Send for RingBuffer {} +//~^ ERROR: some fields in `RingBuffer` are not safe to be sent to another thread // noise_search / RUSTSEC-2020-0141 pub struct MvccRwLock { @@ -23,6 +24,7 @@ pub struct MvccRwLock { } unsafe impl Send for MvccRwLock {} +//~^ ERROR: some fields in `MvccRwLock` are not safe to be sent to another thread // async-coap / RUSTSEC-2020-0124 pub struct ArcGuard { @@ -31,6 +33,7 @@ pub struct ArcGuard { } unsafe impl Send for ArcGuard {} +//~^ ERROR: some fields in `ArcGuard` are not safe to be sent to another thread // rusb / RUSTSEC-2020-0098 extern "C" { @@ -47,6 +50,7 @@ pub struct DeviceHandle { } unsafe impl Send for DeviceHandle {} +//~^ ERROR: some fields in `DeviceHandle` are not safe to be sent to another thread // Other basic tests pub struct NoGeneric { @@ -54,6 +58,7 @@ pub struct NoGeneric { } unsafe impl Send for NoGeneric {} +//~^ ERROR: some fields in `NoGeneric` are not safe to be sent to another thread pub struct MultiField { field1: T, @@ -62,6 +67,7 @@ pub struct MultiField { } unsafe impl Send for MultiField {} +//~^ ERROR: some fields in `MultiField` are not safe to be sent to another thread pub enum MyOption { MySome(T), @@ -69,6 +75,7 @@ pub enum MyOption { } unsafe impl Send for MyOption {} +//~^ ERROR: some fields in `MyOption` are not safe to be sent to another thread // Test types that contain `NonNull` instead of raw pointers (#8045) pub struct WrappedNonNull(UnsafeCell>); @@ -81,6 +88,7 @@ pub struct MultiParam { } unsafe impl Send for MultiParam {} +//~^ ERROR: some fields in `MultiParam` are not safe to be sent to another thread // Tests for raw pointer heuristic extern "C" { @@ -99,6 +107,7 @@ pub struct HeuristicTest { } unsafe impl Send for HeuristicTest {} +//~^ ERROR: some fields in `HeuristicTest` are not safe to be sent to another thread // Test attributes #[allow(clippy::non_send_fields_in_send_ty)] @@ -118,6 +127,7 @@ pub enum AttrTest3 { unsafe impl Send for AttrTest1 {} unsafe impl Send for AttrTest2 {} unsafe impl Send for AttrTest3 {} +//~^ ERROR: some fields in `AttrTest3` are not safe to be sent to another thread // Multiple non-overlapping `Send` for a single type pub struct Complex { @@ -126,8 +136,10 @@ pub struct Complex { } unsafe impl

Send for Complex {} +//~^ ERROR: some fields in `Complex` are not safe to be sent to another thread // `MutexGuard` is non-Send unsafe impl Send for Complex> {} +//~^ ERROR: some fields in `Complex>` are not safe to be sent fn main() {} diff --git a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr index e912b59a6..1ea76196a 100644 --- a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr +++ b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr @@ -11,157 +11,158 @@ LL | data: Vec>, | ^^^^^^^^^^^^^^^^^^^^^^^^ = help: add bounds on type parameter `T` that satisfy `Vec>: Send` = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::non_send_fields_in_send_ty)]` error: some fields in `MvccRwLock` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:25:1 + --> $DIR/non_send_fields_in_send_ty.rs:26:1 | LL | unsafe impl Send for MvccRwLock {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `lock` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:22:5 + --> $DIR/non_send_fields_in_send_ty.rs:23:5 | LL | lock: Mutex>, | ^^^^^^^^^^^^^^^^^^^ = help: add bounds on type parameter `T` that satisfy `Mutex>: Send` error: some fields in `ArcGuard` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:33:1 + --> $DIR/non_send_fields_in_send_ty.rs:35:1 | LL | unsafe impl Send for ArcGuard {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `head` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:30:5 + --> $DIR/non_send_fields_in_send_ty.rs:32:5 | LL | head: Arc, | ^^^^^^^^^^^^^ = help: add bounds on type parameter `RC` that satisfy `Arc: Send` error: some fields in `DeviceHandle` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:49:1 + --> $DIR/non_send_fields_in_send_ty.rs:52:1 | LL | unsafe impl Send for DeviceHandle {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `context` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:45:5 + --> $DIR/non_send_fields_in_send_ty.rs:48:5 | LL | context: T, | ^^^^^^^^^^ = help: add `T: Send` bound in `Send` impl error: some fields in `NoGeneric` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:56:1 + --> $DIR/non_send_fields_in_send_ty.rs:60:1 | LL | unsafe impl Send for NoGeneric {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `rc_is_not_send` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:53:5 + --> $DIR/non_send_fields_in_send_ty.rs:57:5 | LL | rc_is_not_send: Rc, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `MultiField` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:64:1 + --> $DIR/non_send_fields_in_send_ty.rs:69:1 | LL | unsafe impl Send for MultiField {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:59:5 + --> $DIR/non_send_fields_in_send_ty.rs:64:5 | LL | field1: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field2` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:60:5 + --> $DIR/non_send_fields_in_send_ty.rs:65:5 | LL | field2: T, | ^^^^^^^^^ = help: add `T: Send` bound in `Send` impl note: it is not safe to send field `field3` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:61:5 + --> $DIR/non_send_fields_in_send_ty.rs:66:5 | 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/non_send_fields_in_send_ty.rs:71:1 + --> $DIR/non_send_fields_in_send_ty.rs:77:1 | LL | unsafe impl Send for MyOption {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:67:12 + --> $DIR/non_send_fields_in_send_ty.rs:73:12 | LL | MySome(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `MultiParam` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:83:1 + --> $DIR/non_send_fields_in_send_ty.rs:90:1 | LL | unsafe impl Send for MultiParam {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `vec` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:80:5 + --> $DIR/non_send_fields_in_send_ty.rs:87:5 | LL | vec: Vec<(A, B)>, | ^^^^^^^^^^^^^^^^ = help: add bounds on type parameters `A, B` that satisfy `Vec<(A, B)>: Send` error: some fields in `HeuristicTest` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:101:1 + --> $DIR/non_send_fields_in_send_ty.rs:109:1 | LL | unsafe impl Send for HeuristicTest {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field4` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:96:5 + --> $DIR/non_send_fields_in_send_ty.rs:104:5 | LL | field4: (*const NonSend, Rc), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `AttrTest3` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:120:1 + --> $DIR/non_send_fields_in_send_ty.rs:129:1 | LL | unsafe impl Send for AttrTest3 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `0` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:115:11 + --> $DIR/non_send_fields_in_send_ty.rs:124:11 | LL | Enum2(T), | ^ = help: add `T: Send` bound in `Send` impl error: some fields in `Complex` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:128:1 + --> $DIR/non_send_fields_in_send_ty.rs:138:1 | LL | unsafe impl

Send for Complex {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field1` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:124:5 + --> $DIR/non_send_fields_in_send_ty.rs:134:5 | LL | field1: A, | ^^^^^^^^^ = help: add `P: Send` bound in `Send` impl error: some fields in `Complex>` are not safe to be sent to another thread - --> $DIR/non_send_fields_in_send_ty.rs:131:1 + --> $DIR/non_send_fields_in_send_ty.rs:142:1 | LL | unsafe impl Send for Complex> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: it is not safe to send field `field2` to another thread - --> $DIR/non_send_fields_in_send_ty.rs:125:5 + --> $DIR/non_send_fields_in_send_ty.rs:135:5 | LL | field2: B, | ^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/nonminimal_bool.rs b/src/tools/clippy/tests/ui/nonminimal_bool.rs index e4aa0937b..da7876e77 100644 --- a/src/tools/clippy/tests/ui/nonminimal_bool.rs +++ b/src/tools/clippy/tests/ui/nonminimal_bool.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![feature(lint_reasons)] #![allow(unused, clippy::diverging_sub_expression, clippy::needless_if)] #![warn(clippy::nonminimal_bool)] @@ -10,15 +11,23 @@ fn main() { let d: bool = unimplemented!(); let e: bool = unimplemented!(); let _ = !true; + //~^ ERROR: this boolean expression can be simplified + //~| NOTE: `-D clippy::nonminimal-bool` implied by `-D warnings` let _ = !false; + //~^ ERROR: this boolean expression can be simplified let _ = !!a; + //~^ ERROR: this boolean expression can be simplified let _ = false || a; + //~^ ERROR: this boolean expression can be simplified // don't lint on cfgs let _ = cfg!(you_shall_not_not_pass) && a; let _ = a || !b || !c || !d || !e; let _ = !(!a && b); + //~^ ERROR: this boolean expression can be simplified let _ = !(!a || b); + //~^ ERROR: this boolean expression can be simplified let _ = !a && !(b && c); + //~^ ERROR: this boolean expression can be simplified } fn equality_stuff() { @@ -27,10 +36,15 @@ fn equality_stuff() { let c: i32 = unimplemented!(); let d: i32 = unimplemented!(); let _ = a == b && c == 5 && a == b; + //~^ ERROR: this boolean expression can be simplified let _ = a == b || c == 5 || a == b; + //~^ ERROR: this boolean expression can be simplified let _ = a == b && c == 5 && b == a; + //~^ ERROR: this boolean expression can be simplified let _ = a != b || !(a != b || c == d); + //~^ ERROR: this boolean expression can be simplified let _ = a != b && !(a != b && c == d); + //~^ ERROR: this boolean expression can be simplified } fn issue3847(a: u32, b: u32) -> bool { @@ -61,6 +75,7 @@ fn check_expect() { fn issue9428() { if matches!(true, true) && true { + //~^ ERROR: this boolean expression can be simplified println!("foo"); } } diff --git a/src/tools/clippy/tests/ui/nonminimal_bool.stderr b/src/tools/clippy/tests/ui/nonminimal_bool.stderr index e2e4d6477..deae389db 100644 --- a/src/tools/clippy/tests/ui/nonminimal_bool.stderr +++ b/src/tools/clippy/tests/ui/nonminimal_bool.stderr @@ -1,49 +1,50 @@ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:12:13 + --> $DIR/nonminimal_bool.rs:13:13 | LL | let _ = !true; | ^^^^^ help: try: `false` | = note: `-D clippy::nonminimal-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:13:13 + --> $DIR/nonminimal_bool.rs:16:13 | LL | let _ = !false; | ^^^^^^ help: try: `true` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:14:13 + --> $DIR/nonminimal_bool.rs:18:13 | LL | let _ = !!a; | ^^^ help: try: `a` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:15:13 + --> $DIR/nonminimal_bool.rs:20:13 | LL | let _ = false || a; | ^^^^^^^^^^ help: try: `a` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:19:13 + --> $DIR/nonminimal_bool.rs:25:13 | LL | let _ = !(!a && b); | ^^^^^^^^^^ help: try: `a || !b` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:20:13 + --> $DIR/nonminimal_bool.rs:27:13 | LL | let _ = !(!a || b); | ^^^^^^^^^^ help: try: `a && !b` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:21:13 + --> $DIR/nonminimal_bool.rs:29:13 | LL | let _ = !a && !(b && c); | ^^^^^^^^^^^^^^^ help: try: `!(a || b && c)` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:29:13 + --> $DIR/nonminimal_bool.rs:38:13 | LL | let _ = a == b && c == 5 && a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | let _ = a == b && c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:30:13 + --> $DIR/nonminimal_bool.rs:40:13 | LL | let _ = a == b || c == 5 || a == b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -69,7 +70,7 @@ LL | let _ = a == b || c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:31:13 + --> $DIR/nonminimal_bool.rs:42:13 | LL | let _ = a == b && c == 5 && b == a; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -82,7 +83,7 @@ LL | let _ = a == b && c == 5; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:32:13 + --> $DIR/nonminimal_bool.rs:44:13 | LL | let _ = a != b || !(a != b || c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +96,7 @@ LL | let _ = a != b || c != d; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:33:13 + --> $DIR/nonminimal_bool.rs:46:13 | LL | let _ = a != b && !(a != b && c == d); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -108,7 +109,7 @@ LL | let _ = a != b && c != d; | ~~~~~~~~~~~~~~~~ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool.rs:63:8 + --> $DIR/nonminimal_bool.rs:77:8 | LL | if matches!(true, true) && true { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(true, true)` diff --git a/src/tools/clippy/tests/ui/nonminimal_bool_methods.fixed b/src/tools/clippy/tests/ui/nonminimal_bool_methods.fixed index 294f2aa48..e27c0350d 100644 --- a/src/tools/clippy/tests/ui/nonminimal_bool_methods.fixed +++ b/src/tools/clippy/tests/ui/nonminimal_bool_methods.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused, clippy::diverging_sub_expression, clippy::needless_if)] #![warn(clippy::nonminimal_bool)] diff --git a/src/tools/clippy/tests/ui/nonminimal_bool_methods.rs b/src/tools/clippy/tests/ui/nonminimal_bool_methods.rs index a165368ab..040a6e920 100644 --- a/src/tools/clippy/tests/ui/nonminimal_bool_methods.rs +++ b/src/tools/clippy/tests/ui/nonminimal_bool_methods.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused, clippy::diverging_sub_expression, clippy::needless_if)] #![warn(clippy::nonminimal_bool)] diff --git a/src/tools/clippy/tests/ui/nonminimal_bool_methods.stderr b/src/tools/clippy/tests/ui/nonminimal_bool_methods.stderr index 21b84db85..d47bbf7e0 100644 --- a/src/tools/clippy/tests/ui/nonminimal_bool_methods.stderr +++ b/src/tools/clippy/tests/ui/nonminimal_bool_methods.stderr @@ -1,79 +1,80 @@ error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:9:13 + --> $DIR/nonminimal_bool_methods.rs:8:13 | LL | let _ = !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` | = note: `-D clippy::nonminimal-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:11:13 + --> $DIR/nonminimal_bool_methods.rs:10:13 | LL | let _ = !a.is_none(); | ^^^^^^^^^^^^ help: try: `a.is_some()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:13:13 + --> $DIR/nonminimal_bool_methods.rs:12:13 | LL | let _ = !b.is_err(); | ^^^^^^^^^^^ help: try: `b.is_ok()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:15:13 + --> $DIR/nonminimal_bool_methods.rs:14:13 | LL | let _ = !b.is_ok(); | ^^^^^^^^^^ help: try: `b.is_err()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:17:13 + --> $DIR/nonminimal_bool_methods.rs:16:13 | LL | let _ = !(a.is_some() && !c); | ^^^^^^^^^^^^^^^^^^^^ help: try: `a.is_none() || c` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:18:13 + --> $DIR/nonminimal_bool_methods.rs:17:13 | LL | let _ = !(a.is_some() || !c); | ^^^^^^^^^^^^^^^^^^^^ help: try: `a.is_none() && c` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:19:26 + --> $DIR/nonminimal_bool_methods.rs:18:26 | LL | let _ = !(!c ^ c) || !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:20:25 + --> $DIR/nonminimal_bool_methods.rs:19:25 | LL | let _ = (!c ^ c) || !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:21:23 + --> $DIR/nonminimal_bool_methods.rs:20:23 | LL | let _ = !c ^ c || !a.is_some(); | ^^^^^^^^^^^^ help: try: `a.is_none()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:93:8 + --> $DIR/nonminimal_bool_methods.rs:92:8 | LL | if !res.is_ok() {} | ^^^^^^^^^^^^ help: try: `res.is_err()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:94:8 + --> $DIR/nonminimal_bool_methods.rs:93:8 | LL | if !res.is_err() {} | ^^^^^^^^^^^^^ help: try: `res.is_ok()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:97:8 + --> $DIR/nonminimal_bool_methods.rs:96:8 | LL | if !res.is_some() {} | ^^^^^^^^^^^^^^ help: try: `res.is_none()` error: this boolean expression can be simplified - --> $DIR/nonminimal_bool_methods.rs:98:8 + --> $DIR/nonminimal_bool_methods.rs:97:8 | LL | if !res.is_none() {} | ^^^^^^^^^^^^^^ help: try: `res.is_some()` diff --git a/src/tools/clippy/tests/ui/numbered_fields.fixed b/src/tools/clippy/tests/ui/numbered_fields.fixed index a52845e53..7f0a6f8e5 100644 --- a/src/tools/clippy/tests/ui/numbered_fields.fixed +++ b/src/tools/clippy/tests/ui/numbered_fields.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::init_numbered_fields)] #![allow(unused_tuple_struct_fields)] diff --git a/src/tools/clippy/tests/ui/numbered_fields.rs b/src/tools/clippy/tests/ui/numbered_fields.rs index ca93f7dce..38f3b36ec 100644 --- a/src/tools/clippy/tests/ui/numbered_fields.rs +++ b/src/tools/clippy/tests/ui/numbered_fields.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::init_numbered_fields)] #![allow(unused_tuple_struct_fields)] diff --git a/src/tools/clippy/tests/ui/numbered_fields.stderr b/src/tools/clippy/tests/ui/numbered_fields.stderr index 26f7ad904..d52a0cf15 100644 --- a/src/tools/clippy/tests/ui/numbered_fields.stderr +++ b/src/tools/clippy/tests/ui/numbered_fields.stderr @@ -1,5 +1,5 @@ error: used a field initializer for a tuple struct - --> $DIR/numbered_fields.rs:19:13 + --> $DIR/numbered_fields.rs:18:13 | LL | let _ = TupleStruct { | _____________^ @@ -10,9 +10,10 @@ LL | | }; | |_____^ help: try: `TupleStruct(1u32, 42, 23u8)` | = note: `-D clippy::init-numbered-fields` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::init_numbered_fields)]` error: used a field initializer for a tuple struct - --> $DIR/numbered_fields.rs:26:13 + --> $DIR/numbered_fields.rs:25:13 | LL | let _ = TupleStruct { | _____________^ diff --git a/src/tools/clippy/tests/ui/obfuscated_if_else.fixed b/src/tools/clippy/tests/ui/obfuscated_if_else.fixed index 9e4f97253..c5ee56980 100644 --- a/src/tools/clippy/tests/ui/obfuscated_if_else.fixed +++ b/src/tools/clippy/tests/ui/obfuscated_if_else.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::obfuscated_if_else)] fn main() { diff --git a/src/tools/clippy/tests/ui/obfuscated_if_else.rs b/src/tools/clippy/tests/ui/obfuscated_if_else.rs index c2351d64c..2b60c855a 100644 --- a/src/tools/clippy/tests/ui/obfuscated_if_else.rs +++ b/src/tools/clippy/tests/ui/obfuscated_if_else.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::obfuscated_if_else)] fn main() { diff --git a/src/tools/clippy/tests/ui/obfuscated_if_else.stderr b/src/tools/clippy/tests/ui/obfuscated_if_else.stderr index e4180c288..ca9f5e1e3 100644 --- a/src/tools/clippy/tests/ui/obfuscated_if_else.stderr +++ b/src/tools/clippy/tests/ui/obfuscated_if_else.stderr @@ -1,10 +1,11 @@ error: use of `.then_some(..).unwrap_or(..)` can be written more clearly with `if .. else ..` - --> $DIR/obfuscated_if_else.rs:6:5 + --> $DIR/obfuscated_if_else.rs:4:5 | LL | true.then_some("a").unwrap_or("b"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { "a" } else { "b" }` | = note: `-D clippy::obfuscated-if-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::obfuscated_if_else)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/octal_escapes.rs b/src/tools/clippy/tests/ui/octal_escapes.rs index 61ea96604..3915dfdb8 100644 --- a/src/tools/clippy/tests/ui/octal_escapes.rs +++ b/src/tools/clippy/tests/ui/octal_escapes.rs @@ -1,16 +1,26 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::octal_escapes)] fn main() { let _bad1 = "\033[0m"; + //~^ ERROR: octal-looking escape in string literal let _bad2 = b"\033[0m"; + //~^ ERROR: octal-looking escape in byte string literal let _bad3 = "\\\033[0m"; + //~^ ERROR: octal-looking escape in string literal // maximum 3 digits (\012 is the escape) let _bad4 = "\01234567"; + //~^ ERROR: octal-looking escape in string literal let _bad5 = "\0\03"; + //~^ ERROR: octal-looking escape in string literal let _bad6 = "Text-\055\077-MoreText"; + //~^ ERROR: octal-looking escape in string literal let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; + //~^ ERROR: octal-looking escape in string literal let _bad8 = "锈\01锈"; + //~^ ERROR: octal-looking escape in string literal let _bad9 = "锈\011锈"; + //~^ ERROR: octal-looking escape in string literal let _good1 = "\\033[0m"; let _good2 = "\0\\0"; diff --git a/src/tools/clippy/tests/ui/octal_escapes.stderr b/src/tools/clippy/tests/ui/octal_escapes.stderr index 63fdfe486..d2161582b 100644 --- a/src/tools/clippy/tests/ui/octal_escapes.stderr +++ b/src/tools/clippy/tests/ui/octal_escapes.stderr @@ -1,146 +1,147 @@ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:4:17 + --> $DIR/octal_escapes.rs:5:17 | -LL | let _bad1 = "/033[0m"; +LL | let _bad1 = "\033[0m"; | ^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character = note: `-D clippy::octal-escapes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::octal_escapes)]` help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad1 = "/x1b[0m"; +LL | let _bad1 = "\x1b[0m"; | ~~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad1 = "/x0033[0m"; +LL | let _bad1 = "\x0033[0m"; | ~~~~~~~~~~~ error: octal-looking escape in byte string literal - --> $DIR/octal_escapes.rs:5:17 + --> $DIR/octal_escapes.rs:7:17 | -LL | let _bad2 = b"/033[0m"; +LL | let _bad2 = b"\033[0m"; | ^^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null byte + = help: octal escapes are not supported, `\0` is always a null byte help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad2 = b"/x1b[0m"; +LL | let _bad2 = b"\x1b[0m"; | ~~~~~~~~~~ help: if the null byte is intended, disambiguate using | -LL | let _bad2 = b"/x0033[0m"; +LL | let _bad2 = b"\x0033[0m"; | ~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:6:17 + --> $DIR/octal_escapes.rs:9:17 | -LL | let _bad3 = "///033[0m"; +LL | let _bad3 = "\\\033[0m"; | ^^^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad3 = "///x1b[0m"; +LL | let _bad3 = "\\\x1b[0m"; | ~~~~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad3 = "///x0033[0m"; +LL | let _bad3 = "\\\x0033[0m"; | ~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:8:17 + --> $DIR/octal_escapes.rs:12:17 | -LL | let _bad4 = "/01234567"; +LL | let _bad4 = "\01234567"; | ^^^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad4 = "/x0a34567"; +LL | let _bad4 = "\x0a34567"; | ~~~~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad4 = "/x001234567"; +LL | let _bad4 = "\x001234567"; | ~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:9:17 + --> $DIR/octal_escapes.rs:14:17 | -LL | let _bad5 = "/0/03"; +LL | let _bad5 = "\0\03"; | ^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad5 = "/0/x03"; +LL | let _bad5 = "\0\x03"; | ~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad5 = "/0/x003"; +LL | let _bad5 = "\0\x003"; | ~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:10:17 + --> $DIR/octal_escapes.rs:16:17 | -LL | let _bad6 = "Text-/055/077-MoreText"; +LL | let _bad6 = "Text-\055\077-MoreText"; | ^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad6 = "Text-/x2d/x3f-MoreText"; +LL | let _bad6 = "Text-\x2d\x3f-MoreText"; | ~~~~~~~~~~~~~~~~~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad6 = "Text-/x0055/x0077-MoreText"; +LL | let _bad6 = "Text-\x0055\x0077-MoreText"; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:11:17 + --> $DIR/octal_escapes.rs:18:17 | -LL | let _bad7 = "EvenMoreText-/01/02-ShortEscapes"; +LL | let _bad7 = "EvenMoreText-\01\02-ShortEscapes"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad7 = "EvenMoreText-/x01/x02-ShortEscapes"; +LL | let _bad7 = "EvenMoreText-\x01\x02-ShortEscapes"; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad7 = "EvenMoreText-/x001/x002-ShortEscapes"; +LL | let _bad7 = "EvenMoreText-\x001\x002-ShortEscapes"; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:12:17 + --> $DIR/octal_escapes.rs:20:17 | -LL | let _bad8 = "锈/01锈"; +LL | let _bad8 = "锈\01锈"; | ^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad8 = "锈/x01锈"; +LL | let _bad8 = "锈\x01锈"; | ~~~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad8 = "锈/x001锈"; +LL | let _bad8 = "锈\x001锈"; | ~~~~~~~~~~~ error: octal-looking escape in string literal - --> $DIR/octal_escapes.rs:13:17 + --> $DIR/octal_escapes.rs:22:17 | -LL | let _bad9 = "锈/011锈"; +LL | let _bad9 = "锈\011锈"; | ^^^^^^^^^^ | - = help: octal escapes are not supported, `/0` is always a null character + = help: octal escapes are not supported, `\0` is always a null character help: if an octal escape was intended, use the hexadecimal representation instead | -LL | let _bad9 = "锈/x09锈"; +LL | let _bad9 = "锈\x09锈"; | ~~~~~~~~~~ help: if the null character is intended, disambiguate using | -LL | let _bad9 = "锈/x0011锈"; +LL | let _bad9 = "锈\x0011锈"; | ~~~~~~~~~~~~ error: aborting due to 9 previous errors diff --git a/src/tools/clippy/tests/ui/ok_expect.rs b/src/tools/clippy/tests/ui/ok_expect.rs index 2047ee689..c2ad21e22 100644 --- a/src/tools/clippy/tests/ui/ok_expect.rs +++ b/src/tools/clippy/tests/ui/ok_expect.rs @@ -14,16 +14,21 @@ fn main() { let _ = res.unwrap(); res.ok().expect("disaster!"); + //~^ ERROR: called `ok().expect()` on a `Result` value // the following should not warn, since `expect` isn't implemented unless // the error type implements `Debug` let res2: Result = Ok(0); res2.ok().expect("oh noes!"); let res3: Result> = Ok(0); res3.ok().expect("whoof"); + //~^ ERROR: called `ok().expect()` on a `Result` value let res4: Result = Ok(0); res4.ok().expect("argh"); + //~^ ERROR: called `ok().expect()` on a `Result` value let res5: io::Result = Ok(0); res5.ok().expect("oops"); + //~^ ERROR: called `ok().expect()` on a `Result` value let res6: Result = Ok(0); res6.ok().expect("meh"); + //~^ ERROR: called `ok().expect()` on a `Result` value } diff --git a/src/tools/clippy/tests/ui/ok_expect.stderr b/src/tools/clippy/tests/ui/ok_expect.stderr index ab9df26eb..ac2b6dcc8 100644 --- a/src/tools/clippy/tests/ui/ok_expect.stderr +++ b/src/tools/clippy/tests/ui/ok_expect.stderr @@ -6,9 +6,10 @@ LL | res.ok().expect("disaster!"); | = help: you can call `expect()` directly on the `Result` = note: `-D clippy::ok-expect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ok_expect)]` error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:22:5 + --> $DIR/ok_expect.rs:23:5 | LL | res3.ok().expect("whoof"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | res3.ok().expect("whoof"); = help: you can call `expect()` directly on the `Result` error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:24:5 + --> $DIR/ok_expect.rs:26:5 | LL | res4.ok().expect("argh"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | res4.ok().expect("argh"); = help: you can call `expect()` directly on the `Result` error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:26:5 + --> $DIR/ok_expect.rs:29:5 | LL | res5.ok().expect("oops"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | res5.ok().expect("oops"); = help: you can call `expect()` directly on the `Result` error: called `ok().expect()` on a `Result` value - --> $DIR/ok_expect.rs:28:5 + --> $DIR/ok_expect.rs:32:5 | LL | res6.ok().expect("meh"); | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/only_used_in_recursion.rs b/src/tools/clippy/tests/ui/only_used_in_recursion.rs index f71e8ead5..169fb790f 100644 --- a/src/tools/clippy/tests/ui/only_used_in_recursion.rs +++ b/src/tools/clippy/tests/ui/only_used_in_recursion.rs @@ -1,5 +1,5 @@ #![warn(clippy::only_used_in_recursion)] - +//@no-rustfix fn _simple(x: u32) -> u32 { x } @@ -9,14 +9,18 @@ fn _simple2(x: u32) -> u32 { } fn _one_unused(flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { _one_unused(flag - 1, a) } } fn _two_unused(flag: u32, a: u32, b: i32) -> usize { + //~^ ERROR: parameter is only used in recursion + //~| ERROR: parameter is only used in recursion if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } } fn _with_calc(flag: u32, a: i64) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { @@ -30,6 +34,8 @@ fn _used_with_flag(flag: u32, a: u32) -> usize { } fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { + //~^ ERROR: parameter is only used in recursion + //~| ERROR: parameter is only used in recursion if flag == 0 { 0 } else { @@ -38,6 +44,8 @@ fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { } fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { + //~^ ERROR: parameter is only used in recursion + //~| ERROR: parameter is only used in recursion if flag == 0 { 0 } else { @@ -46,6 +54,7 @@ fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { } fn _not_primitive(flag: u32, b: String) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { _not_primitive(flag - 1, b) } } @@ -53,10 +62,13 @@ struct A; impl A { fn _method(flag: usize, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { Self::_method(flag - 1, a) } } fn _method_self(&self, flag: usize, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion + //~| ERROR: parameter is only used in recursion if flag == 0 { 0 } else { self._method_self(flag - 1, a) } } } @@ -68,10 +80,12 @@ trait B { impl B for A { fn method(flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { Self::method(flag - 1, a) } } fn method_self(&self, flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { self.method_self(flag - 1, a) } } } @@ -98,10 +112,12 @@ impl B for u32 { trait C { fn method(flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { Self::method(flag - 1, a) } } fn method_self(&self, flag: u32, a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { self.method_self(flag - 1, a) } } } diff --git a/src/tools/clippy/tests/ui/only_used_in_recursion.stderr b/src/tools/clippy/tests/ui/only_used_in_recursion.stderr index 571e5c4b5..85eee99c0 100644 --- a/src/tools/clippy/tests/ui/only_used_in_recursion.stderr +++ b/src/tools/clippy/tests/ui/only_used_in_recursion.stderr @@ -5,188 +5,189 @@ LL | fn _one_unused(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:12:53 + --> $DIR/only_used_in_recursion.rs:13:53 | LL | if flag == 0 { 0 } else { _one_unused(flag - 1, a) } | ^ = note: `-D clippy::only-used-in-recursion` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::only_used_in_recursion)]` error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:15:27 + --> $DIR/only_used_in_recursion.rs:16:27 | LL | fn _two_unused(flag: u32, a: u32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:16:53 + --> $DIR/only_used_in_recursion.rs:19:53 | LL | if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:15:35 + --> $DIR/only_used_in_recursion.rs:16:35 | LL | fn _two_unused(flag: u32, a: u32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:16:56 + --> $DIR/only_used_in_recursion.rs:19:56 | LL | if flag == 0 { 0 } else { _two_unused(flag - 1, a, b) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:19:26 + --> $DIR/only_used_in_recursion.rs:22:26 | LL | fn _with_calc(flag: u32, a: i64) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:23:32 + --> $DIR/only_used_in_recursion.rs:27:32 | LL | _with_calc(flag - 1, (-a + 10) * 5) | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:32:33 + --> $DIR/only_used_in_recursion.rs:36:33 | LL | fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:36:38 + --> $DIR/only_used_in_recursion.rs:42:38 | LL | _used_with_unused(flag - 1, -a, a + b) | ^ ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:32:41 + --> $DIR/only_used_in_recursion.rs:36:41 | LL | fn _used_with_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:36:45 + --> $DIR/only_used_in_recursion.rs:42:45 | LL | _used_with_unused(flag - 1, -a, a + b) | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:40:35 + --> $DIR/only_used_in_recursion.rs:46:35 | LL | fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:44:39 + --> $DIR/only_used_in_recursion.rs:52:39 | LL | _codependent_unused(flag - 1, a * b, a + b) | ^ ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:40:43 + --> $DIR/only_used_in_recursion.rs:46:43 | LL | fn _codependent_unused(flag: u32, a: i32, b: i32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:44:43 + --> $DIR/only_used_in_recursion.rs:52:43 | LL | _codependent_unused(flag - 1, a * b, a + b) | ^ ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:48:30 + --> $DIR/only_used_in_recursion.rs:56:30 | LL | fn _not_primitive(flag: u32, b: String) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:49:56 + --> $DIR/only_used_in_recursion.rs:58:56 | LL | if flag == 0 { 0 } else { _not_primitive(flag - 1, b) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:55:29 + --> $DIR/only_used_in_recursion.rs:64:29 | LL | fn _method(flag: usize, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:56:59 + --> $DIR/only_used_in_recursion.rs:66:59 | LL | if flag == 0 { 0 } else { Self::_method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:59:22 + --> $DIR/only_used_in_recursion.rs:69:22 | LL | fn _method_self(&self, flag: usize, a: usize) -> usize { | ^^^^ | note: parameter used here - --> $DIR/only_used_in_recursion.rs:60:35 + --> $DIR/only_used_in_recursion.rs:72:35 | LL | if flag == 0 { 0 } else { self._method_self(flag - 1, a) } | ^^^^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:59:41 + --> $DIR/only_used_in_recursion.rs:69:41 | LL | fn _method_self(&self, flag: usize, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:60:63 + --> $DIR/only_used_in_recursion.rs:72:63 | LL | if flag == 0 { 0 } else { self._method_self(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:70:26 + --> $DIR/only_used_in_recursion.rs:82:26 | LL | fn method(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:71:58 + --> $DIR/only_used_in_recursion.rs:84:58 | LL | if flag == 0 { 0 } else { Self::method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:74:38 + --> $DIR/only_used_in_recursion.rs:87:38 | LL | fn method_self(&self, flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:75:62 + --> $DIR/only_used_in_recursion.rs:89:62 | LL | if flag == 0 { 0 } else { self.method_self(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:100:26 + --> $DIR/only_used_in_recursion.rs:114:26 | LL | fn method(flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:101:58 + --> $DIR/only_used_in_recursion.rs:116:58 | LL | if flag == 0 { 0 } else { Self::method(flag - 1, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion.rs:104:38 + --> $DIR/only_used_in_recursion.rs:119:38 | LL | fn method_self(&self, flag: u32, a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion.rs:105:62 + --> $DIR/only_used_in_recursion.rs:121:62 | LL | if flag == 0 { 0 } else { self.method_self(flag - 1, a) } | ^ diff --git a/src/tools/clippy/tests/ui/only_used_in_recursion2.rs b/src/tools/clippy/tests/ui/only_used_in_recursion2.rs index 45dd0553f..1353ff881 100644 --- a/src/tools/clippy/tests/ui/only_used_in_recursion2.rs +++ b/src/tools/clippy/tests/ui/only_used_in_recursion2.rs @@ -1,7 +1,9 @@ #![warn(clippy::only_used_in_recursion)] - +//@no-rustfix fn _with_inner(flag: u32, a: u32, b: u32) -> usize { + //~^ ERROR: parameter is only used in recursion fn inner(flag: u32, a: u32) -> u32 { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { inner(flag, a) } } @@ -10,6 +12,7 @@ fn _with_inner(flag: u32, a: u32, b: u32) -> usize { } fn _with_closure(a: Option, b: u32, f: impl Fn(u32, u32) -> Option) -> u32 { + //~^ ERROR: parameter is only used in recursion if let Some(x) = a.and_then(|x| f(x, x)) { _with_closure(Some(x), b, f) } else { @@ -60,6 +63,7 @@ impl E<()> for () { } fn overwritten_param(flag: u32, mut a: usize) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { return 0; } else if flag > 5 { @@ -71,6 +75,7 @@ fn overwritten_param(flag: u32, mut a: usize) -> usize { } fn field_direct(flag: u32, mut a: (usize,)) -> usize { + //~^ ERROR: parameter is only used in recursion if flag == 0 { 0 } else { diff --git a/src/tools/clippy/tests/ui/only_used_in_recursion2.stderr b/src/tools/clippy/tests/ui/only_used_in_recursion2.stderr index 8dcbfdd61..3ddd9758c 100644 --- a/src/tools/clippy/tests/ui/only_used_in_recursion2.stderr +++ b/src/tools/clippy/tests/ui/only_used_in_recursion2.stderr @@ -5,56 +5,57 @@ LL | fn _with_inner(flag: u32, a: u32, b: u32) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:9:52 + --> $DIR/only_used_in_recursion2.rs:11:52 | LL | if flag == 0 { 0 } else { _with_inner(flag, a, b + x) } | ^ = note: `-D clippy::only-used-in-recursion` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::only_used_in_recursion)]` error: parameter is only used in recursion - --> $DIR/only_used_in_recursion2.rs:4:25 + --> $DIR/only_used_in_recursion2.rs:5:25 | LL | fn inner(flag: u32, a: u32) -> u32 { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:5:47 + --> $DIR/only_used_in_recursion2.rs:7:47 | LL | if flag == 0 { 0 } else { inner(flag, a) } | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion2.rs:12:34 + --> $DIR/only_used_in_recursion2.rs:14:34 | LL | fn _with_closure(a: Option, b: u32, f: impl Fn(u32, u32) -> Option) -> u32 { | ^ help: if this is intentional, prefix it with an underscore: `_b` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:14:32 + --> $DIR/only_used_in_recursion2.rs:17:32 | LL | _with_closure(Some(x), b, f) | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion2.rs:62:37 + --> $DIR/only_used_in_recursion2.rs:65:37 | LL | fn overwritten_param(flag: u32, mut a: usize) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:70:29 + --> $DIR/only_used_in_recursion2.rs:74:29 | LL | overwritten_param(flag, a) | ^ error: parameter is only used in recursion - --> $DIR/only_used_in_recursion2.rs:73:32 + --> $DIR/only_used_in_recursion2.rs:77:32 | LL | fn field_direct(flag: u32, mut a: (usize,)) -> usize { | ^ help: if this is intentional, prefix it with an underscore: `_a` | note: parameter used here - --> $DIR/only_used_in_recursion2.rs:78:32 + --> $DIR/only_used_in_recursion2.rs:83:32 | LL | field_direct(flag - 1, a) | ^ diff --git a/src/tools/clippy/tests/ui/op_ref.fixed b/src/tools/clippy/tests/ui/op_ref.fixed new file mode 100644 index 000000000..183dcf4f0 --- /dev/null +++ b/src/tools/clippy/tests/ui/op_ref.fixed @@ -0,0 +1,99 @@ +#![allow(unused_variables, clippy::disallowed_names)] +#![warn(clippy::op_ref)] +use std::collections::HashSet; +use std::ops::{BitAnd, Mul}; + +fn main() { + let tracked_fds: HashSet = HashSet::new(); + let new_fds = HashSet::new(); + let unwanted = &tracked_fds - &new_fds; + + let foo = 5 - 6; + //~^ ERROR: needlessly taken reference of both operands + //~| NOTE: `-D clippy::op-ref` implied by `-D warnings` + + let bar = String::new(); + let bar = "foo" == &bar; + + let a = "a".to_string(); + let b = "a"; + + if b < &a { + println!("OK"); + } + + struct X(i32); + impl BitAnd for X { + type Output = X; + fn bitand(self, rhs: X) -> X { + X(self.0 & rhs.0) + } + } + impl<'a> BitAnd<&'a X> for X { + type Output = X; + fn bitand(self, rhs: &'a X) -> X { + X(self.0 & rhs.0) + } + } + let x = X(1); + let y = X(2); + let z = x & &y; + + #[derive(Copy, Clone)] + struct Y(i32); + impl BitAnd for Y { + type Output = Y; + fn bitand(self, rhs: Y) -> Y { + Y(self.0 & rhs.0) + } + } + impl<'a> BitAnd<&'a Y> for Y { + type Output = Y; + fn bitand(self, rhs: &'a Y) -> Y { + Y(self.0 & rhs.0) + } + } + let x = Y(1); + let y = Y(2); + let z = x & y; + //~^ ERROR: taken reference of right operand +} + +#[derive(Clone, Copy)] +struct A(i32); +#[derive(Clone, Copy)] +struct B(i32); + +impl Mul<&A> for B { + type Output = i32; + fn mul(self, rhs: &A) -> Self::Output { + self.0 * rhs.0 + } +} +impl Mul for B { + type Output = i32; + fn mul(self, rhs: A) -> Self::Output { + // Should not lint because removing the reference would lead to unconditional recursion + self * &rhs + } +} +impl Mul<&A> for A { + type Output = i32; + fn mul(self, rhs: &A) -> Self::Output { + self.0 * rhs.0 + } +} +impl Mul for A { + type Output = i32; + fn mul(self, rhs: A) -> Self::Output { + let one = B(1); + let two = 2; + let three = 3; + let _ = one * self; + //~^ ERROR: taken reference of right operand + let _ = two + three; + //~^ ERROR: taken reference of right operand + // Removing the reference would lead to unconditional recursion + self * &rhs + } +} diff --git a/src/tools/clippy/tests/ui/op_ref.rs b/src/tools/clippy/tests/ui/op_ref.rs index 07226b0a1..6ed4f23d2 100644 --- a/src/tools/clippy/tests/ui/op_ref.rs +++ b/src/tools/clippy/tests/ui/op_ref.rs @@ -9,6 +9,8 @@ fn main() { let unwanted = &tracked_fds - &new_fds; let foo = &5 - &6; + //~^ ERROR: needlessly taken reference of both operands + //~| NOTE: `-D clippy::op-ref` implied by `-D warnings` let bar = String::new(); let bar = "foo" == &bar; @@ -54,6 +56,7 @@ fn main() { let x = Y(1); let y = Y(2); let z = x & &y; + //~^ ERROR: taken reference of right operand } #[derive(Clone, Copy)] @@ -87,7 +90,9 @@ impl Mul for A { let two = 2; let three = 3; let _ = one * &self; + //~^ ERROR: taken reference of right operand let _ = two + &three; + //~^ ERROR: taken reference of right operand // Removing the reference would lead to unconditional recursion self * &rhs } diff --git a/src/tools/clippy/tests/ui/op_ref.stderr b/src/tools/clippy/tests/ui/op_ref.stderr index fe36c0116..f03e24b84 100644 --- a/src/tools/clippy/tests/ui/op_ref.stderr +++ b/src/tools/clippy/tests/ui/op_ref.stderr @@ -5,13 +5,14 @@ LL | let foo = &5 - &6; | ^^^^^^^ | = note: `-D clippy::op-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::op_ref)]` help: use the values directly | LL | let foo = 5 - 6; | ~ ~ error: taken reference of right operand - --> $DIR/op_ref.rs:56:13 + --> $DIR/op_ref.rs:58:13 | LL | let z = x & &y; | ^^^^-- @@ -19,7 +20,7 @@ LL | let z = x & &y; | help: use the right value directly: `y` error: taken reference of right operand - --> $DIR/op_ref.rs:89:17 + --> $DIR/op_ref.rs:92:17 | LL | let _ = one * &self; | ^^^^^^----- @@ -27,7 +28,7 @@ LL | let _ = one * &self; | help: use the right value directly: `self` error: taken reference of right operand - --> $DIR/op_ref.rs:90:17 + --> $DIR/op_ref.rs:94:17 | LL | let _ = two + &three; | ^^^^^^------ diff --git a/src/tools/clippy/tests/ui/open_options.rs b/src/tools/clippy/tests/ui/open_options.rs index 9063fafbc..0cdc5bf2b 100644 --- a/src/tools/clippy/tests/ui/open_options.rs +++ b/src/tools/clippy/tests/ui/open_options.rs @@ -4,11 +4,19 @@ use std::fs::OpenOptions; #[warn(clippy::nonsensical_open_options)] fn main() { OpenOptions::new().read(true).truncate(true).open("foo.txt"); + //~^ ERROR: file opened with `truncate` and `read` + //~| NOTE: `-D clippy::nonsensical-open-options` implied by `-D warnings` OpenOptions::new().append(true).truncate(true).open("foo.txt"); + //~^ ERROR: file opened with `append` and `truncate` OpenOptions::new().read(true).read(false).open("foo.txt"); + //~^ ERROR: the method `read` is called more than once OpenOptions::new().create(true).create(false).open("foo.txt"); + //~^ ERROR: the method `create` is called more than once OpenOptions::new().write(true).write(false).open("foo.txt"); + //~^ ERROR: the method `write` is called more than once OpenOptions::new().append(true).append(false).open("foo.txt"); + //~^ ERROR: the method `append` is called more than once OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); + //~^ ERROR: the method `truncate` is called more than once } diff --git a/src/tools/clippy/tests/ui/open_options.stderr b/src/tools/clippy/tests/ui/open_options.stderr index 26fe9f6fb..7ac826f52 100644 --- a/src/tools/clippy/tests/ui/open_options.stderr +++ b/src/tools/clippy/tests/ui/open_options.stderr @@ -5,39 +5,40 @@ LL | OpenOptions::new().read(true).truncate(true).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::nonsensical-open-options` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::nonsensical_open_options)]` error: file opened with `append` and `truncate` - --> $DIR/open_options.rs:7:5 + --> $DIR/open_options.rs:9:5 | LL | OpenOptions::new().append(true).truncate(true).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `read` is called more than once - --> $DIR/open_options.rs:9:5 + --> $DIR/open_options.rs:12:5 | LL | OpenOptions::new().read(true).read(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `create` is called more than once - --> $DIR/open_options.rs:10:5 + --> $DIR/open_options.rs:14:5 | LL | OpenOptions::new().create(true).create(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `write` is called more than once - --> $DIR/open_options.rs:11:5 + --> $DIR/open_options.rs:16:5 | LL | OpenOptions::new().write(true).write(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `append` is called more than once - --> $DIR/open_options.rs:12:5 + --> $DIR/open_options.rs:18:5 | LL | OpenOptions::new().append(true).append(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the method `truncate` is called more than once - --> $DIR/open_options.rs:13:5 + --> $DIR/open_options.rs:20:5 | LL | OpenOptions::new().truncate(true).truncate(false).open("foo.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/option_as_ref_deref.fixed b/src/tools/clippy/tests/ui/option_as_ref_deref.fixed index 4d1a6a1ab..c5a959ba5 100644 --- a/src/tools/clippy/tests/ui/option_as_ref_deref.fixed +++ b/src/tools/clippy/tests/ui/option_as_ref_deref.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::redundant_clone, clippy::useless_vec)] #![warn(clippy::option_as_ref_deref)] diff --git a/src/tools/clippy/tests/ui/option_as_ref_deref.rs b/src/tools/clippy/tests/ui/option_as_ref_deref.rs index 66d5a1250..1aeedf211 100644 --- a/src/tools/clippy/tests/ui/option_as_ref_deref.rs +++ b/src/tools/clippy/tests/ui/option_as_ref_deref.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::redundant_clone, clippy::useless_vec)] #![warn(clippy::option_as_ref_deref)] diff --git a/src/tools/clippy/tests/ui/option_as_ref_deref.stderr b/src/tools/clippy/tests/ui/option_as_ref_deref.stderr index e471b56ee..eb0661c52 100644 --- a/src/tools/clippy/tests/ui/option_as_ref_deref.stderr +++ b/src/tools/clippy/tests/ui/option_as_ref_deref.stderr @@ -1,13 +1,14 @@ error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead - --> $DIR/option_as_ref_deref.rs:13:13 + --> $DIR/option_as_ref_deref.rs:11:13 | LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.clone().as_deref()` | = note: `-D clippy::option-as-ref-deref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::option_as_ref_deref)]` error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead - --> $DIR/option_as_ref_deref.rs:16:13 + --> $DIR/option_as_ref_deref.rs:14:13 | LL | let _ = opt.clone() | _____________^ @@ -17,97 +18,97 @@ LL | | ) | |_________^ help: try using as_deref instead: `opt.clone().as_deref()` error: called `.as_mut().map(DerefMut::deref_mut)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:22:13 + --> $DIR/option_as_ref_deref.rs:20:13 | LL | let _ = opt.as_mut().map(DerefMut::deref_mut); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()` error: called `.as_ref().map(String::as_str)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:24:13 + --> $DIR/option_as_ref_deref.rs:22:13 | LL | let _ = opt.as_ref().map(String::as_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` error: called `.as_ref().map(|x| x.as_str())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:25:13 + --> $DIR/option_as_ref_deref.rs:23:13 | LL | let _ = opt.as_ref().map(|x| x.as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` error: called `.as_mut().map(String::as_mut_str)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:26:13 + --> $DIR/option_as_ref_deref.rs:24:13 | LL | let _ = opt.as_mut().map(String::as_mut_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()` error: called `.as_mut().map(|x| x.as_mut_str())` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:27:13 + --> $DIR/option_as_ref_deref.rs:25:13 | LL | let _ = opt.as_mut().map(|x| x.as_mut_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()` error: called `.as_ref().map(CString::as_c_str)` on an Option value. This can be done more directly by calling `Some(CString::new(vec![]).unwrap()).as_deref()` instead - --> $DIR/option_as_ref_deref.rs:28:13 + --> $DIR/option_as_ref_deref.rs:26:13 | LL | let _ = Some(CString::new(vec![]).unwrap()).as_ref().map(CString::as_c_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(CString::new(vec![]).unwrap()).as_deref()` error: called `.as_ref().map(OsString::as_os_str)` on an Option value. This can be done more directly by calling `Some(OsString::new()).as_deref()` instead - --> $DIR/option_as_ref_deref.rs:29:13 + --> $DIR/option_as_ref_deref.rs:27:13 | LL | let _ = Some(OsString::new()).as_ref().map(OsString::as_os_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(OsString::new()).as_deref()` error: called `.as_ref().map(PathBuf::as_path)` on an Option value. This can be done more directly by calling `Some(PathBuf::new()).as_deref()` instead - --> $DIR/option_as_ref_deref.rs:30:13 + --> $DIR/option_as_ref_deref.rs:28:13 | LL | let _ = Some(PathBuf::new()).as_ref().map(PathBuf::as_path); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(PathBuf::new()).as_deref()` error: called `.as_ref().map(Vec::as_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref()` instead - --> $DIR/option_as_ref_deref.rs:31:13 + --> $DIR/option_as_ref_deref.rs:29:13 | LL | let _ = Some(Vec::<()>::new()).as_ref().map(Vec::as_slice); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(Vec::<()>::new()).as_deref()` error: called `.as_mut().map(Vec::as_mut_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:32:13 + --> $DIR/option_as_ref_deref.rs:30:13 | LL | let _ = Some(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `Some(Vec::<()>::new()).as_deref_mut()` error: called `.as_ref().map(|x| x.deref())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:34:13 + --> $DIR/option_as_ref_deref.rs:32:13 | LL | let _ = opt.as_ref().map(|x| x.deref()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` error: called `.as_mut().map(|x| x.deref_mut())` on an Option value. This can be done more directly by calling `opt.clone().as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:35:13 + --> $DIR/option_as_ref_deref.rs:33:13 | LL | let _ = opt.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.clone().as_deref_mut()` error: called `.as_ref().map(|x| &**x)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:42:13 + --> $DIR/option_as_ref_deref.rs:40:13 | LL | let _ = opt.as_ref().map(|x| &**x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` error: called `.as_mut().map(|x| &mut **x)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead - --> $DIR/option_as_ref_deref.rs:43:13 + --> $DIR/option_as_ref_deref.rs:41:13 | LL | let _ = opt.as_mut().map(|x| &mut **x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()` error: called `.as_ref().map(std::ops::Deref::deref)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:46:13 + --> $DIR/option_as_ref_deref.rs:44:13 | LL | let _ = opt.as_ref().map(std::ops::Deref::deref); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` error: called `.as_ref().map(String::as_str)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead - --> $DIR/option_as_ref_deref.rs:58:13 + --> $DIR/option_as_ref_deref.rs:56:13 | LL | let _ = opt.as_ref().map(String::as_str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()` diff --git a/src/tools/clippy/tests/ui/option_env_unwrap.rs b/src/tools/clippy/tests/ui/option_env_unwrap.rs index 61dbad939..f8d382340 100644 --- a/src/tools/clippy/tests/ui/option_env_unwrap.rs +++ b/src/tools/clippy/tests/ui/option_env_unwrap.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::option_env_unwrap)] #![allow(clippy::map_flatten)] diff --git a/src/tools/clippy/tests/ui/option_env_unwrap.stderr b/src/tools/clippy/tests/ui/option_env_unwrap.stderr index cfa9dd58a..de31d0c7f 100644 --- a/src/tools/clippy/tests/ui/option_env_unwrap.stderr +++ b/src/tools/clippy/tests/ui/option_env_unwrap.stderr @@ -6,6 +6,7 @@ LL | let _ = option_env!("PATH").unwrap(); | = help: consider using the `env!` macro instead = note: `-D clippy::option-env-unwrap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::option_env_unwrap)]` error: this will panic at run-time if the environment variable doesn't exist at compile-time --> $DIR/option_env_unwrap.rs:11:13 diff --git a/src/tools/clippy/tests/ui/option_filter_map.fixed b/src/tools/clippy/tests/ui/option_filter_map.fixed index 93c250cfa..ee004c0e1 100644 --- a/src/tools/clippy/tests/ui/option_filter_map.fixed +++ b/src/tools/clippy/tests/ui/option_filter_map.fixed @@ -1,6 +1,5 @@ -//@run-rustfix #![warn(clippy::option_filter_map)] -#![allow(clippy::map_flatten)] +#![allow(clippy::map_flatten, clippy::unnecessary_map_on_constructor)] fn main() { let _ = Some(Some(1)).flatten(); diff --git a/src/tools/clippy/tests/ui/option_filter_map.rs b/src/tools/clippy/tests/ui/option_filter_map.rs index 2c5f03250..eae2fa176 100644 --- a/src/tools/clippy/tests/ui/option_filter_map.rs +++ b/src/tools/clippy/tests/ui/option_filter_map.rs @@ -1,6 +1,5 @@ -//@run-rustfix #![warn(clippy::option_filter_map)] -#![allow(clippy::map_flatten)] +#![allow(clippy::map_flatten, clippy::unnecessary_map_on_constructor)] fn main() { let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap); diff --git a/src/tools/clippy/tests/ui/option_filter_map.stderr b/src/tools/clippy/tests/ui/option_filter_map.stderr index 4a030ac9a..148f9d02f 100644 --- a/src/tools/clippy/tests/ui/option_filter_map.stderr +++ b/src/tools/clippy/tests/ui/option_filter_map.stderr @@ -1,43 +1,44 @@ error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:6:27 + --> $DIR/option_filter_map.rs:5:27 | LL | let _ = Some(Some(1)).filter(Option::is_some).map(Option::unwrap); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` | = note: `-D clippy::option-filter-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::option_filter_map)]` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:7:27 + --> $DIR/option_filter_map.rs:6:27 | LL | let _ = Some(Some(1)).filter(|o| o.is_some()).map(|o| o.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:8:35 + --> $DIR/option_filter_map.rs:7:35 | LL | let _ = Some(1).map(odds_out).filter(Option::is_some).map(Option::unwrap); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:9:35 + --> $DIR/option_filter_map.rs:8:35 | LL | let _ = Some(1).map(odds_out).filter(|o| o.is_some()).map(|o| o.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:11:39 + --> $DIR/option_filter_map.rs:10:39 | LL | let _ = vec![Some(1)].into_iter().filter(Option::is_some).map(Option::unwrap); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:12:39 + --> $DIR/option_filter_map.rs:11:39 | LL | let _ = vec![Some(1)].into_iter().filter(|o| o.is_some()).map(|o| o.unwrap()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:16:10 + --> $DIR/option_filter_map.rs:15:10 | LL | .filter(Option::is_some) | __________^ @@ -45,7 +46,7 @@ LL | | .map(Option::unwrap); | |____________________________^ help: consider using `flatten` instead: `flatten()` error: `filter` for `Some` followed by `unwrap` - --> $DIR/option_filter_map.rs:21:10 + --> $DIR/option_filter_map.rs:20:10 | LL | .filter(|o| o.is_some()) | __________^ diff --git a/src/tools/clippy/tests/ui/option_if_let_else.fixed b/src/tools/clippy/tests/ui/option_if_let_else.fixed index 6fee3cce6..c3415a7df 100644 --- a/src/tools/clippy/tests/ui/option_if_let_else.fixed +++ b/src/tools/clippy/tests/ui/option_if_let_else.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::option_if_let_else)] #![allow( unused_tuple_struct_fields, diff --git a/src/tools/clippy/tests/ui/option_if_let_else.rs b/src/tools/clippy/tests/ui/option_if_let_else.rs index 4b3cf948a..86537f620 100644 --- a/src/tools/clippy/tests/ui/option_if_let_else.rs +++ b/src/tools/clippy/tests/ui/option_if_let_else.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::option_if_let_else)] #![allow( unused_tuple_struct_fields, diff --git a/src/tools/clippy/tests/ui/option_if_let_else.stderr b/src/tools/clippy/tests/ui/option_if_let_else.stderr index 350f0f07e..6d7d02f8c 100644 --- a/src/tools/clippy/tests/ui/option_if_let_else.stderr +++ b/src/tools/clippy/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:13:5 + --> $DIR/option_if_let_else.rs:12:5 | LL | / if let Some(x) = string { LL | | (true, x) @@ -9,21 +9,22 @@ LL | | } | |_____^ help: try: `string.map_or((false, "hello"), |x| (true, x))` | = note: `-D clippy::option-if-let-else` implied by `-D warnings` + = 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:31:13 + --> $DIR/option_if_let_else.rs:30: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:32: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:33:13 + --> $DIR/option_if_let_else.rs:32:13 | LL | let _ = if let Some(s) = &mut num { | _____________^ @@ -43,13 +44,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:39:13 + --> $DIR/option_if_let_else.rs:38: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:40:13 + --> $DIR/option_if_let_else.rs:39:13 | LL | let _ = if let Some(mut s) = num { | _____________^ @@ -69,7 +70,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:46:13 + --> $DIR/option_if_let_else.rs:45:13 | LL | let _ = if let Some(ref mut s) = num { | _____________^ @@ -89,7 +90,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:55:5 + --> $DIR/option_if_let_else.rs:54:5 | LL | / if let Some(x) = arg { LL | | let y = x * x; @@ -108,7 +109,7 @@ LL + }) | error: use Option::map_or_else instead of an if let/else - --> $DIR/option_if_let_else.rs:68:13 + --> $DIR/option_if_let_else.rs:67:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -120,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:77:13 + --> $DIR/option_if_let_else.rs:76:13 | LL | let _ = if let Some(x) = arg { | _____________^ @@ -143,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:110:13 + --> $DIR/option_if_let_else.rs:109:13 | LL | / if let Some(idx) = s.find('.') { LL | | vec![s[..idx].to_string(), s[idx..].to_string()] @@ -153,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:121:5 + --> $DIR/option_if_let_else.rs:120:5 | LL | / if let Ok(binding) = variable { LL | | println!("Ok {binding}"); @@ -172,13 +173,13 @@ LL + }) | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:143:13 + --> $DIR/option_if_let_else.rs:142: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:153:13 + --> $DIR/option_if_let_else.rs:152:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -200,13 +201,13 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:181:13 + --> $DIR/option_if_let_else.rs:180: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:185:13 + --> $DIR/option_if_let_else.rs:184:13 | LL | let _ = if let Some(x) = Some(0) { | _____________^ @@ -226,7 +227,7 @@ LL ~ }); | error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:224:13 + --> $DIR/option_if_let_else.rs:223:13 | LL | let _ = match s { | _____________^ @@ -236,7 +237,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:228:13 + --> $DIR/option_if_let_else.rs:227:13 | LL | let _ = match Some(10) { | _____________^ @@ -246,7 +247,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:234:13 + --> $DIR/option_if_let_else.rs:233:13 | LL | let _ = match res { | _____________^ @@ -256,7 +257,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:238:13 + --> $DIR/option_if_let_else.rs:237:13 | LL | let _ = match res { | _____________^ @@ -266,13 +267,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:242:13 + --> $DIR/option_if_let_else.rs:241: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:259:9 + --> $DIR/option_if_let_else.rs:258:9 | LL | / match initial { LL | | Some(value) => do_something(value), @@ -281,7 +282,7 @@ LL | | } | |_________^ help: try: `initial.as_ref().map_or({}, |value| do_something(value))` error: use Option::map_or instead of an if let/else - --> $DIR/option_if_let_else.rs:266:9 + --> $DIR/option_if_let_else.rs:265:9 | LL | / match initial { LL | | Some(value) => do_something2(value), diff --git a/src/tools/clippy/tests/ui/option_map_or_none.fixed b/src/tools/clippy/tests/ui/option_map_or_none.fixed index 501757647..5f0ef34d2 100644 --- a/src/tools/clippy/tests/ui/option_map_or_none.fixed +++ b/src/tools/clippy/tests/ui/option_map_or_none.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::bind_instead_of_map)] fn main() { diff --git a/src/tools/clippy/tests/ui/option_map_or_none.rs b/src/tools/clippy/tests/ui/option_map_or_none.rs index 4d8704e73..56b1f6121 100644 --- a/src/tools/clippy/tests/ui/option_map_or_none.rs +++ b/src/tools/clippy/tests/ui/option_map_or_none.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::bind_instead_of_map)] fn main() { diff --git a/src/tools/clippy/tests/ui/option_map_or_none.stderr b/src/tools/clippy/tests/ui/option_map_or_none.stderr index 7befcb890..fa150718f 100644 --- a/src/tools/clippy/tests/ui/option_map_or_none.stderr +++ b/src/tools/clippy/tests/ui/option_map_or_none.stderr @@ -1,13 +1,14 @@ error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead - --> $DIR/option_map_or_none.rs:12:26 + --> $DIR/option_map_or_none.rs:10:26 | LL | let _: Option = opt.map_or(None, |x| Some(x + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `map` instead: `opt.map(|x| x + 1)` | = note: `-D clippy::option-map-or-none` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::option_map_or_none)]` error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead - --> $DIR/option_map_or_none.rs:15:26 + --> $DIR/option_map_or_none.rs:13:26 | LL | let _: Option = opt.map_or(None, |x| { | __________________________^ @@ -16,13 +17,13 @@ LL | | }); | |_________________________^ help: try using `map` instead: `opt.map(|x| x + 1)` error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead - --> $DIR/option_map_or_none.rs:19:26 + --> $DIR/option_map_or_none.rs:17:26 | LL | let _: Option = opt.map_or(None, bar); | ^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(bar)` error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead - --> $DIR/option_map_or_none.rs:20:26 + --> $DIR/option_map_or_none.rs:18:26 | LL | let _: Option = opt.map_or(None, |x| { | __________________________^ @@ -42,12 +43,13 @@ LL ~ }); | error: called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling `ok()` instead - --> $DIR/option_map_or_none.rs:27:26 + --> $DIR/option_map_or_none.rs:25:26 | LL | let _: Option = r.map_or(None, Some); | ^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `r.ok()` | = note: `-D clippy::result-map-or-into-option` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_map_or_into_option)]` error: aborting due to 5 previous errors diff --git a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.fixed b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.fixed index 8f64451ed..5dcc6464f 100644 --- a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.fixed +++ b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::option_map_unit_fn)] #![allow(unused)] #![allow(clippy::uninlined_format_args, clippy::unnecessary_wraps)] diff --git a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.rs b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.rs index 2bf7a8e0f..5489545fe 100644 --- a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.rs +++ b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::option_map_unit_fn)] #![allow(unused)] #![allow(clippy::uninlined_format_args, clippy::unnecessary_wraps)] diff --git a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.stderr b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.stderr index 5be5f10b0..34aca31e9 100644 --- a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.stderr +++ b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.stderr @@ -1,5 +1,5 @@ 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:38:5 + --> $DIR/option_map_unit_fn_fixable.rs:37:5 | LL | x.field.map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^- @@ -7,9 +7,10 @@ LL | x.field.map(do_nothing); | help: try: `if let Some(x_field) = x.field { do_nothing(x_field) }` | = note: `-D clippy::option-map-unit-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::option_map_unit_fn)]` 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:40:5 + --> $DIR/option_map_unit_fn_fixable.rs:39:5 | LL | x.field.map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^- @@ -17,7 +18,7 @@ LL | x.field.map(do_nothing); | help: try: `if let Some(x_field) = x.field { do_nothing(x_field) }` 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:42:5 + --> $DIR/option_map_unit_fn_fixable.rs:41:5 | LL | x.field.map(diverge); | ^^^^^^^^^^^^^^^^^^^^- @@ -25,7 +26,7 @@ LL | x.field.map(diverge); | help: try: `if let Some(x_field) = x.field { diverge(x_field) }` 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:48:5 + --> $DIR/option_map_unit_fn_fixable.rs:47:5 | LL | x.field.map(|value| x.do_option_nothing(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -33,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:50:5 + --> $DIR/option_map_unit_fn_fixable.rs:49:5 | LL | x.field.map(|value| { x.do_option_plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -41,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:53:5 + --> $DIR/option_map_unit_fn_fixable.rs:52:5 | LL | x.field.map(|value| do_nothing(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -49,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:55:5 + --> $DIR/option_map_unit_fn_fixable.rs:54:5 | LL | x.field.map(|value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -57,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:57:5 + --> $DIR/option_map_unit_fn_fixable.rs:56:5 | LL | x.field.map(|value| { do_nothing(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -65,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:59:5 + --> $DIR/option_map_unit_fn_fixable.rs:58:5 | LL | x.field.map(|value| { { do_nothing(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -73,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:62:5 + --> $DIR/option_map_unit_fn_fixable.rs:61:5 | LL | x.field.map(|value| diverge(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -81,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:64:5 + --> $DIR/option_map_unit_fn_fixable.rs:63:5 | LL | x.field.map(|value| { diverge(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -89,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:66:5 + --> $DIR/option_map_unit_fn_fixable.rs:65:5 | LL | x.field.map(|value| { diverge(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -97,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:68:5 + --> $DIR/option_map_unit_fn_fixable.rs:67:5 | LL | x.field.map(|value| { { diverge(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -105,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:73:5 + --> $DIR/option_map_unit_fn_fixable.rs:72:5 | LL | x.field.map(|value| { let y = plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -113,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:75:5 + --> $DIR/option_map_unit_fn_fixable.rs:74:5 | LL | x.field.map(|value| { plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -121,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:77:5 + --> $DIR/option_map_unit_fn_fixable.rs:76:5 | LL | x.field.map(|value| { { plus_one(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -129,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:80:5 + --> $DIR/option_map_unit_fn_fixable.rs:79:5 | LL | x.field.map(|ref value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -137,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:82:5 + --> $DIR/option_map_unit_fn_fixable.rs:81:5 | LL | option().map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^^- @@ -145,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:84:5 + --> $DIR/option_map_unit_fn_fixable.rs:83:5 | LL | option().map(|value| println!("{:?}", value)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- diff --git a/src/tools/clippy/tests/ui/option_option.rs b/src/tools/clippy/tests/ui/option_option.rs index 2faab9e03..9bbdd3aaa 100644 --- a/src/tools/clippy/tests/ui/option_option.rs +++ b/src/tools/clippy/tests/ui/option_option.rs @@ -2,40 +2,51 @@ #![allow(clippy::unnecessary_wraps)] const C: Option> = None; +//~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if static S: Option> = None; +//~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if fn input(_: Option>) {} +//~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if fn output() -> Option> { + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if None } fn output_nested() -> Vec>> { + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if vec![None] } // The lint only generates one warning for this fn output_nested_nested() -> Option>> { + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum if None } struct Struct { x: Option>, + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum } impl Struct { fn struct_fn() -> Option> { + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum None } } trait Trait { fn trait_fn() -> Option>; + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum } enum Enum { Tuple(Option>), + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum Struct { x: Option> }, + //~^ ERROR: consider using `Option` instead of `Option>` or a custom enum } // The lint allows this @@ -77,6 +88,7 @@ mod issue_4298 { #[serde(default)] #[serde(borrow)] foo: Option>>, + //~^ ERROR: consider using `Option` instead of `Option>` or a custom } #[allow(clippy::option_option)] diff --git a/src/tools/clippy/tests/ui/option_option.stderr b/src/tools/clippy/tests/ui/option_option.stderr index a925bb35b..fcae9655d 100644 --- a/src/tools/clippy/tests/ui/option_option.stderr +++ b/src/tools/clippy/tests/ui/option_option.stderr @@ -11,67 +11,67 @@ LL | #![deny(clippy::option_option)] | ^^^^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:5:11 + --> $DIR/option_option.rs:6:11 | LL | static S: Option> = None; | ^^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:7:13 + --> $DIR/option_option.rs:9:13 | LL | fn input(_: Option>) {} | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:9:16 + --> $DIR/option_option.rs:12:16 | LL | fn output() -> Option> { | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:13:27 + --> $DIR/option_option.rs:17:27 | LL | fn output_nested() -> Vec>> { | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:18:30 + --> $DIR/option_option.rs:23:30 | LL | fn output_nested_nested() -> Option>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:23:8 + --> $DIR/option_option.rs:29:8 | LL | x: Option>, | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:27:23 + --> $DIR/option_option.rs:34:23 | LL | fn struct_fn() -> Option> { | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:33:22 + --> $DIR/option_option.rs:41:22 | LL | fn trait_fn() -> Option>; | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:37:11 + --> $DIR/option_option.rs:46:11 | LL | Tuple(Option>), | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:38:17 + --> $DIR/option_option.rs:48:17 | LL | Struct { x: Option> }, | ^^^^^^^^^^^^^^^^^^ error: consider using `Option` instead of `Option>` or a custom enum if you need to distinguish all 3 cases - --> $DIR/option_option.rs:79:14 + --> $DIR/option_option.rs:90:14 | LL | foo: Option>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/or_fun_call.fixed b/src/tools/clippy/tests/ui/or_fun_call.fixed index 581f3ad45..e7ba54864 100644 --- a/src/tools/clippy/tests/ui/or_fun_call.fixed +++ b/src/tools/clippy/tests/ui/or_fun_call.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::or_fun_call)] #![allow(dead_code)] #![allow( diff --git a/src/tools/clippy/tests/ui/or_fun_call.rs b/src/tools/clippy/tests/ui/or_fun_call.rs index 1f3987eb8..196632133 100644 --- a/src/tools/clippy/tests/ui/or_fun_call.rs +++ b/src/tools/clippy/tests/ui/or_fun_call.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::or_fun_call)] #![allow(dead_code)] #![allow( diff --git a/src/tools/clippy/tests/ui/or_fun_call.stderr b/src/tools/clippy/tests/ui/or_fun_call.stderr index 519f09165..afa4b7628 100644 --- a/src/tools/clippy/tests/ui/or_fun_call.stderr +++ b/src/tools/clippy/tests/ui/or_fun_call.stderr @@ -1,189 +1,191 @@ error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:53:22 + --> $DIR/or_fun_call.rs:52:22 | LL | with_constructor.unwrap_or(make()); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(make)` | = note: `-D clippy::or-fun-call` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::or_fun_call)]` error: use of `unwrap_or` to construct default value - --> $DIR/or_fun_call.rs:56:14 + --> $DIR/or_fun_call.rs:55:14 | LL | with_new.unwrap_or(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` | = note: `-D clippy::unwrap-or-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_or_default)]` error: use of `unwrap_or` followed by a function call - --> $DIR/or_fun_call.rs:59:21 + --> $DIR/or_fun_call.rs:58:21 | 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:62:14 + --> $DIR/or_fun_call.rs:61: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:65:19 + --> $DIR/or_fun_call.rs:64: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:68:24 + --> $DIR/or_fun_call.rs:67: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:71:23 + --> $DIR/or_fun_call.rs:70: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:74:18 + --> $DIR/or_fun_call.rs:73: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:77:18 + --> $DIR/or_fun_call.rs:76: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:80:14 + --> $DIR/or_fun_call.rs:79: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:83:21 + --> $DIR/or_fun_call.rs:82: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:86:19 + --> $DIR/or_fun_call.rs:85: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:89:23 + --> $DIR/or_fun_call.rs:88: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:92:21 + --> $DIR/or_fun_call.rs:91: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:95:25 + --> $DIR/or_fun_call.rs:94: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:98:21 + --> $DIR/or_fun_call.rs:97: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:106:21 + --> $DIR/or_fun_call.rs:105: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:108:21 + --> $DIR/or_fun_call.rs:107: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:132:35 + --> $DIR/or_fun_call.rs:131: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:171:14 + --> $DIR/or_fun_call.rs:170: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:177:14 + --> $DIR/or_fun_call.rs:176: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:179:14 + --> $DIR/or_fun_call.rs:178: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:254:25 + --> $DIR/or_fun_call.rs:253: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:255:25 + --> $DIR/or_fun_call.rs:254: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:286:18 + --> $DIR/or_fun_call.rs:285: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:289:28 + --> $DIR/or_fun_call.rs:288: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:292:27 + --> $DIR/or_fun_call.rs:291: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:295:22 + --> $DIR/or_fun_call.rs:294: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:298:23 + --> $DIR/or_fun_call.rs:297: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:301:25 + --> $DIR/or_fun_call.rs:300: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:304:25 + --> $DIR/or_fun_call.rs:303:25 | LL | let _ = stringy.unwrap_or_else(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` diff --git a/src/tools/clippy/tests/ui/or_then_unwrap.fixed b/src/tools/clippy/tests/ui/or_then_unwrap.fixed index 773dfc3c5..c94478614 100644 --- a/src/tools/clippy/tests/ui/or_then_unwrap.fixed +++ b/src/tools/clippy/tests/ui/or_then_unwrap.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::or_then_unwrap)] #![allow(clippy::map_identity, clippy::let_unit_value, clippy::unnecessary_literal_unwrap)] diff --git a/src/tools/clippy/tests/ui/or_then_unwrap.rs b/src/tools/clippy/tests/ui/or_then_unwrap.rs index 5867e0148..10e43e1d1 100644 --- a/src/tools/clippy/tests/ui/or_then_unwrap.rs +++ b/src/tools/clippy/tests/ui/or_then_unwrap.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::or_then_unwrap)] #![allow(clippy::map_identity, clippy::let_unit_value, clippy::unnecessary_literal_unwrap)] diff --git a/src/tools/clippy/tests/ui/or_then_unwrap.stderr b/src/tools/clippy/tests/ui/or_then_unwrap.stderr index 2a1a52407..99e4488c0 100644 --- a/src/tools/clippy/tests/ui/or_then_unwrap.stderr +++ b/src/tools/clippy/tests/ui/or_then_unwrap.stderr @@ -1,19 +1,20 @@ error: found `.or(Some(…)).unwrap()` - --> $DIR/or_then_unwrap.rs:24:20 + --> $DIR/or_then_unwrap.rs:22:20 | LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")` | = note: `-D clippy::or-then-unwrap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::or_then_unwrap)]` error: found `.or(Ok(…)).unwrap()` - --> $DIR/or_then_unwrap.rs:27:20 + --> $DIR/or_then_unwrap.rs:25: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:31:31 + --> $DIR/or_then_unwrap.rs:29: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/src/tools/clippy/tests/ui/out_of_bounds_indexing/issue-3102.rs b/src/tools/clippy/tests/ui/out_of_bounds_indexing/issue-3102.rs index edd2123d4..81674653b 100644 --- a/src/tools/clippy/tests/ui/out_of_bounds_indexing/issue-3102.rs +++ b/src/tools/clippy/tests/ui/out_of_bounds_indexing/issue-3102.rs @@ -6,6 +6,9 @@ fn main() { // issue 3102 let num = 1; - &x[num..10]; // should trigger out of bounds error - &x[10..num]; // should trigger out of bounds error + &x[num..10]; + //~^ ERROR: range is out of bounds + //~| NOTE: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` + &x[10..num]; + //~^ ERROR: range is out of bounds } diff --git a/src/tools/clippy/tests/ui/out_of_bounds_indexing/issue-3102.stderr b/src/tools/clippy/tests/ui/out_of_bounds_indexing/issue-3102.stderr index 516c1df40..37db11caa 100644 --- a/src/tools/clippy/tests/ui/out_of_bounds_indexing/issue-3102.stderr +++ b/src/tools/clippy/tests/ui/out_of_bounds_indexing/issue-3102.stderr @@ -1,15 +1,16 @@ error: range is out of bounds --> $DIR/issue-3102.rs:9:13 | -LL | &x[num..10]; // should trigger out of bounds error +LL | &x[num..10]; | ^^ | = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: range is out of bounds - --> $DIR/issue-3102.rs:10:8 + --> $DIR/issue-3102.rs:12:8 | -LL | &x[10..num]; // should trigger out of bounds error +LL | &x[10..num]; | ^^ error: aborting due to 2 previous errors diff --git a/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs b/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs index 4c541c23f..c38ca5123 100644 --- a/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs +++ b/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs @@ -5,11 +5,18 @@ fn main() { let x = [1, 2, 3, 4]; &x[..=4]; + //~^ ERROR: range is out of bounds + //~| NOTE: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` &x[1..5]; + //~^ ERROR: range is out of bounds &x[5..]; + //~^ ERROR: range is out of bounds &x[..5]; + //~^ ERROR: range is out of bounds &x[5..].iter().map(|x| 2 * x).collect::>(); + //~^ ERROR: range is out of bounds &x[0..=4]; + //~^ ERROR: range is out of bounds &x[4..]; // Ok, should not produce stderr. &x[..4]; // Ok, should not produce stderr. diff --git a/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.stderr b/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.stderr index 3d95afcda..ddef38beb 100644 --- a/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.stderr +++ b/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.stderr @@ -5,33 +5,34 @@ LL | &x[..=4]; | ^ | = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: range is out of bounds - --> $DIR/simple.rs:8:11 + --> $DIR/simple.rs:10:11 | LL | &x[1..5]; | ^ error: range is out of bounds - --> $DIR/simple.rs:9:8 + --> $DIR/simple.rs:12:8 | LL | &x[5..]; | ^ error: range is out of bounds - --> $DIR/simple.rs:10:10 + --> $DIR/simple.rs:14:10 | LL | &x[..5]; | ^ error: range is out of bounds - --> $DIR/simple.rs:11:8 + --> $DIR/simple.rs:16:8 | LL | &x[5..].iter().map(|x| 2 * x).collect::>(); | ^ error: range is out of bounds - --> $DIR/simple.rs:12:12 + --> $DIR/simple.rs:18:12 | LL | &x[0..=4]; | ^ diff --git a/src/tools/clippy/tests/ui/overflow_check_conditional.rs b/src/tools/clippy/tests/ui/overflow_check_conditional.rs index 14a6b98d0..a70bb3bc4 100644 --- a/src/tools/clippy/tests/ui/overflow_check_conditional.rs +++ b/src/tools/clippy/tests/ui/overflow_check_conditional.rs @@ -3,13 +3,22 @@ fn test(a: u32, b: u32, c: u32) { if a + b < a {} + //~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust + //~| NOTE: `-D clippy::overflow-check-conditional` implied by `-D warnings` if a > a + b {} + //~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust if a + b < b {} + //~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust if b > a + b {} + //~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust if a - b > b {} + //~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus if b < a - b {} + //~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus if a - b > a {} + //~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus if a < a - b {} + //~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus if a + b < c {} if c > a + b {} if a - b < c {} diff --git a/src/tools/clippy/tests/ui/overflow_check_conditional.stderr b/src/tools/clippy/tests/ui/overflow_check_conditional.stderr index 3ec2298f8..b3cab8a21 100644 --- a/src/tools/clippy/tests/ui/overflow_check_conditional.stderr +++ b/src/tools/clippy/tests/ui/overflow_check_conditional.stderr @@ -5,45 +5,46 @@ LL | if a + b < a {} | ^^^^^^^^^ | = note: `-D clippy::overflow-check-conditional` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::overflow_check_conditional)]` error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:6:8 + --> $DIR/overflow_check_conditional.rs:8:8 | LL | if a > a + b {} | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:7:8 + --> $DIR/overflow_check_conditional.rs:10:8 | LL | if a + b < b {} | ^^^^^^^^^ error: you are trying to use classic C overflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:8:8 + --> $DIR/overflow_check_conditional.rs:12:8 | LL | if b > a + b {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:9:8 + --> $DIR/overflow_check_conditional.rs:14:8 | LL | if a - b > b {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:10:8 + --> $DIR/overflow_check_conditional.rs:16:8 | LL | if b < a - b {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:11:8 + --> $DIR/overflow_check_conditional.rs:18:8 | LL | if a - b > a {} | ^^^^^^^^^ error: you are trying to use classic C underflow conditions that will fail in Rust - --> $DIR/overflow_check_conditional.rs:12:8 + --> $DIR/overflow_check_conditional.rs:20:8 | LL | if a < a - b {} | ^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/overly_complex_bool_expr.fixed b/src/tools/clippy/tests/ui/overly_complex_bool_expr.fixed new file mode 100644 index 000000000..e44f60631 --- /dev/null +++ b/src/tools/clippy/tests/ui/overly_complex_bool_expr.fixed @@ -0,0 +1,39 @@ +#![feature(lint_reasons)] +#![allow(unused, clippy::diverging_sub_expression)] +#![warn(clippy::overly_complex_bool_expr)] + +fn main() { + let a: bool = unimplemented!(); + let b: bool = unimplemented!(); + let c: bool = unimplemented!(); + let d: bool = unimplemented!(); + let e: bool = unimplemented!(); + let _ = a; + //~^ ERROR: this boolean expression contains a logic bug + let _ = !(a && b); + let _ = false; + //~^ ERROR: this boolean expression contains a logic bug + // don't lint on cfgs + let _ = cfg!(you_shall_not_not_pass) && a; + let _ = a || !b || !c || !d || !e; + let _ = !(a && b || c); +} + +fn equality_stuff() { + let a: i32 = unimplemented!(); + let b: i32 = unimplemented!(); + let _ = false; + //~^ ERROR: this boolean expression contains a logic bug + let _ = false; + //~^ ERROR: this boolean expression contains a logic bug + let _ = false; + //~^ ERROR: this boolean expression contains a logic bug + let _ = a > b && a == b; +} + +fn check_expect() { + let a: i32 = unimplemented!(); + let b: i32 = unimplemented!(); + #[expect(clippy::overly_complex_bool_expr)] + let _ = a < b && a >= b; +} diff --git a/src/tools/clippy/tests/ui/overly_complex_bool_expr.rs b/src/tools/clippy/tests/ui/overly_complex_bool_expr.rs index 04a30a832..f010a8537 100644 --- a/src/tools/clippy/tests/ui/overly_complex_bool_expr.rs +++ b/src/tools/clippy/tests/ui/overly_complex_bool_expr.rs @@ -9,8 +9,10 @@ fn main() { let d: bool = unimplemented!(); let e: bool = unimplemented!(); let _ = a && b || a; + //~^ ERROR: this boolean expression contains a logic bug let _ = !(a && b); let _ = false && a; + //~^ ERROR: this boolean expression contains a logic bug // don't lint on cfgs let _ = cfg!(you_shall_not_not_pass) && a; let _ = a || !b || !c || !d || !e; @@ -21,8 +23,11 @@ fn equality_stuff() { let a: i32 = unimplemented!(); let b: i32 = unimplemented!(); let _ = a == b && a != b; + //~^ ERROR: this boolean expression contains a logic bug let _ = a < b && a >= b; + //~^ ERROR: this boolean expression contains a logic bug let _ = a > b && a <= b; + //~^ ERROR: this boolean expression contains a logic bug let _ = a > b && a == b; } diff --git a/src/tools/clippy/tests/ui/overly_complex_bool_expr.stderr b/src/tools/clippy/tests/ui/overly_complex_bool_expr.stderr index e989f2ece..dc62d0e1d 100644 --- a/src/tools/clippy/tests/ui/overly_complex_bool_expr.stderr +++ b/src/tools/clippy/tests/ui/overly_complex_bool_expr.stderr @@ -10,51 +10,52 @@ help: this expression can be optimized out by applying boolean operations to the LL | let _ = a && b || a; | ^ = note: `-D clippy::overly-complex-bool-expr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::overly_complex_bool_expr)]` error: this boolean expression contains a logic bug - --> $DIR/overly_complex_bool_expr.rs:13:13 + --> $DIR/overly_complex_bool_expr.rs:14:13 | LL | let _ = false && a; | ^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/overly_complex_bool_expr.rs:13:22 + --> $DIR/overly_complex_bool_expr.rs:14:22 | LL | let _ = false && a; | ^ error: this boolean expression contains a logic bug - --> $DIR/overly_complex_bool_expr.rs:23:13 + --> $DIR/overly_complex_bool_expr.rs:25:13 | LL | let _ = a == b && a != b; | ^^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/overly_complex_bool_expr.rs:23:13 + --> $DIR/overly_complex_bool_expr.rs:25:13 | LL | let _ = a == b && a != b; | ^^^^^^ error: this boolean expression contains a logic bug - --> $DIR/overly_complex_bool_expr.rs:24:13 + --> $DIR/overly_complex_bool_expr.rs:27:13 | LL | let _ = a < b && a >= b; | ^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/overly_complex_bool_expr.rs:24:13 + --> $DIR/overly_complex_bool_expr.rs:27:13 | LL | let _ = a < b && a >= b; | ^^^^^ error: this boolean expression contains a logic bug - --> $DIR/overly_complex_bool_expr.rs:25:13 + --> $DIR/overly_complex_bool_expr.rs:29:13 | LL | let _ = a > b && a <= b; | ^^^^^^^^^^^^^^^ help: it would look like the following: `false` | help: this expression can be optimized out by applying boolean operations to the outer expression - --> $DIR/overly_complex_bool_expr.rs:25:13 + --> $DIR/overly_complex_bool_expr.rs:29:13 | LL | let _ = a > b && a <= b; | ^^^^^ diff --git a/src/tools/clippy/tests/ui/panic_in_result_fn.rs b/src/tools/clippy/tests/ui/panic_in_result_fn.rs index e75eb1b6e..41e2f5226 100644 --- a/src/tools/clippy/tests/ui/panic_in_result_fn.rs +++ b/src/tools/clippy/tests/ui/panic_in_result_fn.rs @@ -4,6 +4,7 @@ struct A; impl A { fn result_with_panic() -> Result // should emit lint + //~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { panic!("error"); } @@ -50,6 +51,7 @@ impl A { } fn function_result_with_panic() -> Result // should emit lint +//~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { panic!("error"); } diff --git a/src/tools/clippy/tests/ui/panic_in_result_fn.stderr b/src/tools/clippy/tests/ui/panic_in_result_fn.stderr index b758fc238..d55c5cf36 100644 --- a/src/tools/clippy/tests/ui/panic_in_result_fn.stderr +++ b/src/tools/clippy/tests/ui/panic_in_result_fn.stderr @@ -2,6 +2,7 @@ error: used `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn.rs:6:5 | LL | / fn result_with_panic() -> Result // should emit lint +LL | | LL | | { LL | | panic!("error"); LL | | } @@ -9,16 +10,18 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn.rs:8:9 + --> $DIR/panic_in_result_fn.rs:9:9 | LL | panic!("error"); | ^^^^^^^^^^^^^^^ = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::panic_in_result_fn)]` error: used `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn.rs:52:1 + --> $DIR/panic_in_result_fn.rs:53:1 | LL | / fn function_result_with_panic() -> Result // should emit lint +LL | | LL | | { LL | | panic!("error"); LL | | } @@ -26,7 +29,7 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn.rs:54:5 + --> $DIR/panic_in_result_fn.rs:56:5 | LL | panic!("error"); | ^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.rs b/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.rs index 08ab4d868..672c4c738 100644 --- a/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.rs +++ b/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.rs @@ -5,18 +5,21 @@ struct A; impl A { fn result_with_assert_with_message(x: i32) -> Result // should emit lint + //~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { assert!(x == 5, "wrong argument"); Ok(true) } fn result_with_assert_eq(x: i32) -> Result // should emit lint + //~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { assert_eq!(x, 5); Ok(true) } fn result_with_assert_ne(x: i32) -> Result // should emit lint + //~^ ERROR: used `panic!()` or assertion in a function that returns `Result` { assert_ne!(x, 1); Ok(true) diff --git a/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr b/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr index 0dd213a7e..a80e6f27a 100644 --- a/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr +++ b/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr @@ -2,6 +2,7 @@ error: used `panic!()` or assertion in a function that returns `Result` --> $DIR/panic_in_result_fn_assertions.rs:7:5 | LL | / fn result_with_assert_with_message(x: i32) -> Result // should emit lint +LL | | LL | | { LL | | assert!(x == 5, "wrong argument"); LL | | Ok(true) @@ -10,16 +11,18 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_assertions.rs:9:9 + --> $DIR/panic_in_result_fn_assertions.rs:10:9 | LL | assert!(x == 5, "wrong argument"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::panic-in-result-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::panic_in_result_fn)]` error: used `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn_assertions.rs:13:5 + --> $DIR/panic_in_result_fn_assertions.rs:14:5 | LL | / fn result_with_assert_eq(x: i32) -> Result // should emit lint +LL | | LL | | { LL | | assert_eq!(x, 5); LL | | Ok(true) @@ -28,15 +31,16 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_assertions.rs:15:9 + --> $DIR/panic_in_result_fn_assertions.rs:17:9 | LL | assert_eq!(x, 5); | ^^^^^^^^^^^^^^^^ error: used `panic!()` or assertion in a function that returns `Result` - --> $DIR/panic_in_result_fn_assertions.rs:19:5 + --> $DIR/panic_in_result_fn_assertions.rs:21:5 | LL | / fn result_with_assert_ne(x: i32) -> Result // should emit lint +LL | | LL | | { LL | | assert_ne!(x, 1); LL | | Ok(true) @@ -45,7 +49,7 @@ LL | | } | = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing note: return Err() instead of panicking - --> $DIR/panic_in_result_fn_assertions.rs:21:9 + --> $DIR/panic_in_result_fn_assertions.rs:24:9 | LL | assert_ne!(x, 1); | ^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/panicking_macros.rs b/src/tools/clippy/tests/ui/panicking_macros.rs index 041ef17fa..dccfbd409 100644 --- a/src/tools/clippy/tests/ui/panicking_macros.rs +++ b/src/tools/clippy/tests/ui/panicking_macros.rs @@ -21,41 +21,61 @@ fn inline_const() { fn panic() { let a = 2; panic!(); + //~^ ERROR: `panic` should not be present in production code + //~| NOTE: `-D clippy::panic` implied by `-D warnings` panic!("message"); + //~^ ERROR: `panic` should not be present in production code panic!("{} {}", "panic with", "multiple arguments"); + //~^ ERROR: `panic` should not be present in production code let b = a + 2; } fn todo() { let a = 2; todo!(); + //~^ ERROR: `todo` should not be present in production code + //~| NOTE: `-D clippy::todo` implied by `-D warnings` todo!("message"); + //~^ ERROR: `todo` should not be present in production code todo!("{} {}", "panic with", "multiple arguments"); + //~^ ERROR: `todo` should not be present in production code let b = a + 2; } fn unimplemented() { let a = 2; unimplemented!(); + //~^ ERROR: `unimplemented` should not be present in production code + //~| NOTE: `-D clippy::unimplemented` implied by `-D warnings` unimplemented!("message"); + //~^ ERROR: `unimplemented` should not be present in production code unimplemented!("{} {}", "panic with", "multiple arguments"); + //~^ ERROR: `unimplemented` should not be present in production code let b = a + 2; } fn unreachable() { let a = 2; unreachable!(); + //~^ ERROR: usage of the `unreachable!` macro + //~| NOTE: `-D clippy::unreachable` implied by `-D warnings` unreachable!("message"); + //~^ ERROR: usage of the `unreachable!` macro unreachable!("{} {}", "panic with", "multiple arguments"); + //~^ ERROR: usage of the `unreachable!` macro let b = a + 2; } fn core_versions() { use core::{panic, todo, unimplemented, unreachable}; panic!(); + //~^ ERROR: `panic` should not be present in production code todo!(); + //~^ ERROR: `todo` should not be present in production code unimplemented!(); + //~^ ERROR: `unimplemented` should not be present in production code unreachable!(); + //~^ ERROR: usage of the `unreachable!` macro } fn assert() { diff --git a/src/tools/clippy/tests/ui/panicking_macros.stderr b/src/tools/clippy/tests/ui/panicking_macros.stderr index 4ceb6d144..59ce57d0b 100644 --- a/src/tools/clippy/tests/ui/panicking_macros.stderr +++ b/src/tools/clippy/tests/ui/panicking_macros.stderr @@ -5,99 +5,103 @@ LL | panic!(); | ^^^^^^^^ | = note: `-D clippy::panic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::panic)]` error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:24:5 + --> $DIR/panicking_macros.rs:26:5 | LL | panic!("message"); | ^^^^^^^^^^^^^^^^^ error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:25:5 + --> $DIR/panicking_macros.rs:28:5 | LL | panic!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:31:5 + --> $DIR/panicking_macros.rs:35:5 | LL | todo!(); | ^^^^^^^ | = note: `-D clippy::todo` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::todo)]` error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:32:5 + --> $DIR/panicking_macros.rs:38:5 | LL | todo!("message"); | ^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:33:5 + --> $DIR/panicking_macros.rs:40:5 | LL | todo!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:39:5 + --> $DIR/panicking_macros.rs:47:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::unimplemented` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unimplemented)]` error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:40:5 + --> $DIR/panicking_macros.rs:50:5 | LL | unimplemented!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:41:5 + --> $DIR/panicking_macros.rs:52:5 | LL | unimplemented!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:47:5 + --> $DIR/panicking_macros.rs:59:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^ | = note: `-D clippy::unreachable` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unreachable)]` error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:48:5 + --> $DIR/panicking_macros.rs:62:5 | LL | unreachable!("message"); | ^^^^^^^^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:49:5 + --> $DIR/panicking_macros.rs:64:5 | LL | unreachable!("{} {}", "panic with", "multiple arguments"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `panic` should not be present in production code - --> $DIR/panicking_macros.rs:55:5 + --> $DIR/panicking_macros.rs:71:5 | LL | panic!(); | ^^^^^^^^ error: `todo` should not be present in production code - --> $DIR/panicking_macros.rs:56:5 + --> $DIR/panicking_macros.rs:73:5 | LL | todo!(); | ^^^^^^^ error: `unimplemented` should not be present in production code - --> $DIR/panicking_macros.rs:57:5 + --> $DIR/panicking_macros.rs:75:5 | LL | unimplemented!(); | ^^^^^^^^^^^^^^^^ error: usage of the `unreachable!` macro - --> $DIR/panicking_macros.rs:58:5 + --> $DIR/panicking_macros.rs:77:5 | LL | unreachable!(); | ^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/partial_pub_fields.rs b/src/tools/clippy/tests/ui/partial_pub_fields.rs index 668545da8..316b36c25 100644 --- a/src/tools/clippy/tests/ui/partial_pub_fields.rs +++ b/src/tools/clippy/tests/ui/partial_pub_fields.rs @@ -8,19 +8,23 @@ fn main() { pub struct FileSet { files: HashMap, pub paths: HashMap, + //~^ ERROR: mixed usage of pub and non-pub fields } pub struct Color { pub r: u8, pub g: u8, b: u8, + //~^ ERROR: mixed usage of pub and non-pub fields } pub struct Point(i32, pub i32); + //~^ ERROR: mixed usage of pub and non-pub fields pub struct Visibility { r#pub: bool, pub pos: u32, + //~^ ERROR: mixed usage of pub and non-pub fields } // Don't lint on empty structs; diff --git a/src/tools/clippy/tests/ui/partial_pub_fields.stderr b/src/tools/clippy/tests/ui/partial_pub_fields.stderr index 84cfc1a91..a15228740 100644 --- a/src/tools/clippy/tests/ui/partial_pub_fields.stderr +++ b/src/tools/clippy/tests/ui/partial_pub_fields.stderr @@ -6,9 +6,10 @@ LL | pub paths: HashMap, | = help: consider using private field here = note: `-D clippy::partial-pub-fields` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::partial_pub_fields)]` error: mixed usage of pub and non-pub fields - --> $DIR/partial_pub_fields.rs:16:9 + --> $DIR/partial_pub_fields.rs:17:9 | LL | b: u8, | ^ @@ -16,7 +17,7 @@ LL | b: u8, = help: consider using public field here error: mixed usage of pub and non-pub fields - --> $DIR/partial_pub_fields.rs:19:27 + --> $DIR/partial_pub_fields.rs:21:27 | LL | pub struct Point(i32, pub i32); | ^^^ @@ -24,7 +25,7 @@ LL | pub struct Point(i32, pub i32); = help: consider using private field here error: mixed usage of pub and non-pub fields - --> $DIR/partial_pub_fields.rs:23:9 + --> $DIR/partial_pub_fields.rs:26:9 | LL | pub pos: u32, | ^^^ diff --git a/src/tools/clippy/tests/ui/partialeq_ne_impl.rs b/src/tools/clippy/tests/ui/partialeq_ne_impl.rs index 1338d3c74..555eeebe1 100644 --- a/src/tools/clippy/tests/ui/partialeq_ne_impl.rs +++ b/src/tools/clippy/tests/ui/partialeq_ne_impl.rs @@ -7,6 +7,8 @@ impl PartialEq for Foo { true } fn ne(&self, _: &Foo) -> bool { + //~^ ERROR: re-implementing `PartialEq::ne` is unnecessary + //~| NOTE: `-D clippy::partialeq-ne-impl` implied by `-D warnings` false } } diff --git a/src/tools/clippy/tests/ui/partialeq_ne_impl.stderr b/src/tools/clippy/tests/ui/partialeq_ne_impl.stderr index b92da4511..163d6b1dd 100644 --- a/src/tools/clippy/tests/ui/partialeq_ne_impl.stderr +++ b/src/tools/clippy/tests/ui/partialeq_ne_impl.stderr @@ -2,11 +2,14 @@ error: re-implementing `PartialEq::ne` is unnecessary --> $DIR/partialeq_ne_impl.rs:9:5 | LL | / fn ne(&self, _: &Foo) -> bool { +LL | | +LL | | LL | | false LL | | } | |_____^ | = note: `-D clippy::partialeq-ne-impl` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::partialeq_ne_impl)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/partialeq_to_none.fixed b/src/tools/clippy/tests/ui/partialeq_to_none.fixed index 95e184b1d..87adbca39 100644 --- a/src/tools/clippy/tests/ui/partialeq_to_none.fixed +++ b/src/tools/clippy/tests/ui/partialeq_to_none.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::partialeq_to_none)] #![allow(clippy::eq_op, clippy::needless_if)] diff --git a/src/tools/clippy/tests/ui/partialeq_to_none.rs b/src/tools/clippy/tests/ui/partialeq_to_none.rs index 4fa50dcc1..b623e6a66 100644 --- a/src/tools/clippy/tests/ui/partialeq_to_none.rs +++ b/src/tools/clippy/tests/ui/partialeq_to_none.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::partialeq_to_none)] #![allow(clippy::eq_op, clippy::needless_if)] diff --git a/src/tools/clippy/tests/ui/partialeq_to_none.stderr b/src/tools/clippy/tests/ui/partialeq_to_none.stderr index 4f84862a2..50ce15001 100644 --- a/src/tools/clippy/tests/ui/partialeq_to_none.stderr +++ b/src/tools/clippy/tests/ui/partialeq_to_none.stderr @@ -1,61 +1,62 @@ error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:15:8 + --> $DIR/partialeq_to_none.rs:14:8 | LL | if f != None { "yay" } else { "nay" } | ^^^^^^^^^ help: use `Option::is_some()` instead: `f.is_some()` | = note: `-D clippy::partialeq-to-none` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::partialeq_to_none)]` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:45:13 + --> $DIR/partialeq_to_none.rs:44:13 | LL | let _ = x == None; | ^^^^^^^^^ help: use `Option::is_none()` instead: `x.is_none()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:46:13 + --> $DIR/partialeq_to_none.rs:45:13 | LL | let _ = x != None; | ^^^^^^^^^ help: use `Option::is_some()` instead: `x.is_some()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:47:13 + --> $DIR/partialeq_to_none.rs:46:13 | LL | let _ = None == x; | ^^^^^^^^^ help: use `Option::is_none()` instead: `x.is_none()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:48:13 + --> $DIR/partialeq_to_none.rs:47:13 | LL | let _ = None != x; | ^^^^^^^^^ help: use `Option::is_some()` instead: `x.is_some()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:50:8 + --> $DIR/partialeq_to_none.rs:49:8 | LL | if foobar() == None {} | ^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `foobar().is_none()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:52:8 + --> $DIR/partialeq_to_none.rs:51:8 | LL | if bar().ok() != None {} | ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `bar().ok().is_some()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:54:13 + --> $DIR/partialeq_to_none.rs:53:13 | LL | let _ = Some(1 + 2) != None; | ^^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `Some(1 + 2).is_some()` error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:56:13 + --> $DIR/partialeq_to_none.rs:55:13 | 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:58:13 + --> $DIR/partialeq_to_none.rs:57:13 | LL | let _ = { | _____________^ @@ -77,31 +78,31 @@ LL ~ }.is_some(); | error: binary comparison to literal `Option::None` - --> $DIR/partialeq_to_none.rs:68:13 + --> $DIR/partialeq_to_none.rs:67: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:69:13 + --> $DIR/partialeq_to_none.rs:68: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:70:13 + --> $DIR/partialeq_to_none.rs:69: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:71:13 + --> $DIR/partialeq_to_none.rs:70: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:74:13 + --> $DIR/partialeq_to_none.rs:73:13 | LL | let _ = None != *x; | ^^^^^^^^^^ help: use `Option::is_some()` instead: `(*x).is_some()` diff --git a/src/tools/clippy/tests/ui/path_buf_push_overwrite.fixed b/src/tools/clippy/tests/ui/path_buf_push_overwrite.fixed index 393fc6e1c..86e3e5bbd 100644 --- a/src/tools/clippy/tests/ui/path_buf_push_overwrite.fixed +++ b/src/tools/clippy/tests/ui/path_buf_push_overwrite.fixed @@ -1,4 +1,3 @@ -//@run-rustfix use std::path::PathBuf; #[warn(clippy::all, clippy::path_buf_push_overwrite)] diff --git a/src/tools/clippy/tests/ui/path_buf_push_overwrite.rs b/src/tools/clippy/tests/ui/path_buf_push_overwrite.rs index 18de6e064..460cc254e 100644 --- a/src/tools/clippy/tests/ui/path_buf_push_overwrite.rs +++ b/src/tools/clippy/tests/ui/path_buf_push_overwrite.rs @@ -1,4 +1,3 @@ -//@run-rustfix use std::path::PathBuf; #[warn(clippy::all, clippy::path_buf_push_overwrite)] diff --git a/src/tools/clippy/tests/ui/path_buf_push_overwrite.stderr b/src/tools/clippy/tests/ui/path_buf_push_overwrite.stderr index bb8dce2bb..1453d020c 100644 --- a/src/tools/clippy/tests/ui/path_buf_push_overwrite.stderr +++ b/src/tools/clippy/tests/ui/path_buf_push_overwrite.stderr @@ -1,10 +1,11 @@ -error: calling `push` with '/' or '/' (file system root) will overwrite the previous path definition - --> $DIR/path_buf_push_overwrite.rs:7:12 +error: calling `push` with '/' or '\' (file system root) will overwrite the previous path definition + --> $DIR/path_buf_push_overwrite.rs:6:12 | LL | x.push("/bar"); | ^^^^^^ help: try: `"bar"` | = note: `-D clippy::path-buf-push-overwrite` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::path_buf_push_overwrite)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/path_ends_with_ext.fixed b/src/tools/clippy/tests/ui/path_ends_with_ext.fixed new file mode 100644 index 000000000..49767e242 --- /dev/null +++ b/src/tools/clippy/tests/ui/path_ends_with_ext.fixed @@ -0,0 +1,36 @@ +#![warn(clippy::path_ends_with_ext)] +use std::path::Path; + +macro_rules! arg { + () => { + ".md" + }; +} + +fn test(path: &Path) { + path.extension().is_some_and(|ext| ext == "md"); + //~^ ERROR: this looks like a failed attempt at checking for the file extension + + // some "extensions" are allowed by default + path.ends_with(".git"); + + // most legitimate "dotfiles" are longer than 3 chars, so we allow them as well + path.ends_with(".bashrc"); + + // argument from expn shouldn't trigger + path.ends_with(arg!()); + + path.ends_with(".."); + path.ends_with("./a"); + path.ends_with("."); + path.ends_with(""); +} + +// is_some_and was stabilized in 1.70, so suggest map_or(false, ..) if under that +#[clippy::msrv = "1.69"] +fn under_msv(path: &Path) -> bool { + path.extension().map_or(false, |ext| ext == "md") + //~^ ERROR: this looks like a failed attempt at checking for the file extension +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/path_ends_with_ext.rs b/src/tools/clippy/tests/ui/path_ends_with_ext.rs new file mode 100644 index 000000000..2dfd04621 --- /dev/null +++ b/src/tools/clippy/tests/ui/path_ends_with_ext.rs @@ -0,0 +1,36 @@ +#![warn(clippy::path_ends_with_ext)] +use std::path::Path; + +macro_rules! arg { + () => { + ".md" + }; +} + +fn test(path: &Path) { + path.ends_with(".md"); + //~^ ERROR: this looks like a failed attempt at checking for the file extension + + // some "extensions" are allowed by default + path.ends_with(".git"); + + // most legitimate "dotfiles" are longer than 3 chars, so we allow them as well + path.ends_with(".bashrc"); + + // argument from expn shouldn't trigger + path.ends_with(arg!()); + + path.ends_with(".."); + path.ends_with("./a"); + path.ends_with("."); + path.ends_with(""); +} + +// is_some_and was stabilized in 1.70, so suggest map_or(false, ..) if under that +#[clippy::msrv = "1.69"] +fn under_msv(path: &Path) -> bool { + path.ends_with(".md") + //~^ ERROR: this looks like a failed attempt at checking for the file extension +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/path_ends_with_ext.stderr b/src/tools/clippy/tests/ui/path_ends_with_ext.stderr new file mode 100644 index 000000000..a73ab4d08 --- /dev/null +++ b/src/tools/clippy/tests/ui/path_ends_with_ext.stderr @@ -0,0 +1,17 @@ +error: this looks like a failed attempt at checking for the file extension + --> $DIR/path_ends_with_ext.rs:11:5 + | +LL | path.ends_with(".md"); + | ^^^^^^^^^^^^^^^^^^^^^ help: try: `path.extension().is_some_and(|ext| ext == "md")` + | + = note: `-D clippy::path-ends-with-ext` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::path_ends_with_ext)]` + +error: this looks like a failed attempt at checking for the file extension + --> $DIR/path_ends_with_ext.rs:32:5 + | +LL | path.ends_with(".md") + | ^^^^^^^^^^^^^^^^^^^^^ help: try: `path.extension().map_or(false, |ext| ext == "md")` + +error: aborting due to 2 previous errors + diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/mutability.rs b/src/tools/clippy/tests/ui/pattern_type_mismatch/mutability.rs index 55a8c2621..61dee47cb 100644 --- a/src/tools/clippy/tests/ui/pattern_type_mismatch/mutability.rs +++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/mutability.rs @@ -7,12 +7,14 @@ fn should_lint() { let value = &Some(23); match value { Some(_) => (), + //~^ ERROR: type of pattern does not match the expression type _ => (), } let value = &mut Some(23); match value { Some(_) => (), + //~^ ERROR: type of pattern does not match the expression type _ => (), } } diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/mutability.stderr b/src/tools/clippy/tests/ui/pattern_type_mismatch/mutability.stderr index 87fb243b6..f21e1894a 100644 --- a/src/tools/clippy/tests/ui/pattern_type_mismatch/mutability.stderr +++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/mutability.stderr @@ -6,9 +6,10 @@ LL | Some(_) => (), | = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type - --> $DIR/mutability.rs:15:9 + --> $DIR/mutability.rs:16:9 | LL | Some(_) => (), | ^^^^^^^ diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_alternatives.rs b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_alternatives.rs index 065ea9fb9..558d496ae 100644 --- a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_alternatives.rs +++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_alternatives.rs @@ -13,8 +13,11 @@ fn alternatives() { // not ok if let Value::B | Value::A(_) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let &Value::B | &Value::A(Some(_)) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let Value::B | Value::A(Some(_)) = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok if let &Value::B | &Value::A(_) = ref_value {} diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr index a91b5ac6c..b72c24840 100644 --- a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr +++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr @@ -6,9 +6,10 @@ LL | if let Value::B | Value::A(_) = ref_value {} | = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type - --> $DIR/pattern_alternatives.rs:16:34 + --> $DIR/pattern_alternatives.rs:17:34 | LL | if let &Value::B | &Value::A(Some(_)) = ref_value {} | ^^^^^^^ @@ -16,7 +17,7 @@ LL | if let &Value::B | &Value::A(Some(_)) = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_alternatives.rs:17:32 + --> $DIR/pattern_alternatives.rs:19:32 | LL | if let Value::B | Value::A(Some(_)) = *ref_value {} | ^^^^^^^ diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_structs.rs b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_structs.rs index 417b1c107..d9b22693f 100644 --- a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_structs.rs +++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_structs.rs @@ -11,8 +11,11 @@ fn struct_types() { // not ok let Struct { .. } = ref_value; + //~^ ERROR: type of pattern does not match the expression type if let &Struct { ref_inner: Some(_) } = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let Struct { ref_inner: Some(_) } = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok let &Struct { .. } = ref_value; @@ -30,10 +33,15 @@ fn struct_enum_variants() { // not ok if let StructEnum::Var { .. } = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let StructEnum::Var { inner_ref: Some(_) } = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let &StructEnum::Var { inner_ref: Some(_) } = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let StructEnum::Var { inner_ref: Some(_) } = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let StructEnum::Empty = ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok if let &StructEnum::Var { .. } = ref_value {} diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_structs.stderr b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_structs.stderr index 8bc5c63ba..c46c7de6d 100644 --- a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_structs.stderr +++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_structs.stderr @@ -6,9 +6,10 @@ LL | let Struct { .. } = ref_value; | = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:14:33 + --> $DIR/pattern_structs.rs:15:33 | LL | if let &Struct { ref_inner: Some(_) } = ref_value {} | ^^^^^^^ @@ -16,7 +17,7 @@ LL | if let &Struct { ref_inner: Some(_) } = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:15:32 + --> $DIR/pattern_structs.rs:17:32 | LL | if let Struct { ref_inner: Some(_) } = *ref_value {} | ^^^^^^^ @@ -24,7 +25,7 @@ LL | if let Struct { ref_inner: Some(_) } = *ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:32:12 + --> $DIR/pattern_structs.rs:35:12 | LL | if let StructEnum::Var { .. } = ref_value {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | if let StructEnum::Var { .. } = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:33:12 + --> $DIR/pattern_structs.rs:37:12 | LL | if let StructEnum::Var { inner_ref: Some(_) } = ref_value {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | if let StructEnum::Var { inner_ref: Some(_) } = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:34:42 + --> $DIR/pattern_structs.rs:39:42 | LL | if let &StructEnum::Var { inner_ref: Some(_) } = ref_value {} | ^^^^^^^ @@ -48,7 +49,7 @@ LL | if let &StructEnum::Var { inner_ref: Some(_) } = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:35:41 + --> $DIR/pattern_structs.rs:41:41 | LL | if let StructEnum::Var { inner_ref: Some(_) } = *ref_value {} | ^^^^^^^ @@ -56,7 +57,7 @@ LL | if let StructEnum::Var { inner_ref: Some(_) } = *ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_structs.rs:36:12 + --> $DIR/pattern_structs.rs:43:12 | LL | if let StructEnum::Empty = ref_value {} | ^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_tuples.rs b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_tuples.rs index 19504a051..f44e3543c 100644 --- a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_tuples.rs +++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_tuples.rs @@ -9,8 +9,11 @@ fn tuple_types() { // not ok let TupleStruct(_) = ref_value; + //~^ ERROR: type of pattern does not match the expression type if let &TupleStruct(Some(_)) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let TupleStruct(Some(_)) = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok let &TupleStruct(_) = ref_value; @@ -28,9 +31,13 @@ fn tuple_enum_variants() { // not ok if let TupleEnum::Var(_) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let &TupleEnum::Var(Some(_)) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let TupleEnum::Var(Some(_)) = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let TupleEnum::Empty = ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok if let &TupleEnum::Var(_) = ref_value {} @@ -46,8 +53,11 @@ fn plain_tuples() { // not ok let (_a, _b) = ref_value; + //~^ ERROR: type of pattern does not match the expression type if let &(_a, Some(_)) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type if let (_a, Some(_)) = *ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok let &(_a, _b) = ref_value; diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_tuples.stderr b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_tuples.stderr index a1ef540d2..b365731d5 100644 --- a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_tuples.stderr +++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_tuples.stderr @@ -6,9 +6,10 @@ LL | let TupleStruct(_) = ref_value; | = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:12:25 + --> $DIR/pattern_tuples.rs:13:25 | LL | if let &TupleStruct(Some(_)) = ref_value {} | ^^^^^^^ @@ -16,7 +17,7 @@ LL | if let &TupleStruct(Some(_)) = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:13:24 + --> $DIR/pattern_tuples.rs:15:24 | LL | if let TupleStruct(Some(_)) = *ref_value {} | ^^^^^^^ @@ -24,7 +25,7 @@ LL | if let TupleStruct(Some(_)) = *ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:30:12 + --> $DIR/pattern_tuples.rs:33:12 | LL | if let TupleEnum::Var(_) = ref_value {} | ^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | if let TupleEnum::Var(_) = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:31:28 + --> $DIR/pattern_tuples.rs:35:28 | LL | if let &TupleEnum::Var(Some(_)) = ref_value {} | ^^^^^^^ @@ -40,7 +41,7 @@ LL | if let &TupleEnum::Var(Some(_)) = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:32:27 + --> $DIR/pattern_tuples.rs:37:27 | LL | if let TupleEnum::Var(Some(_)) = *ref_value {} | ^^^^^^^ @@ -48,7 +49,7 @@ LL | if let TupleEnum::Var(Some(_)) = *ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:33:12 + --> $DIR/pattern_tuples.rs:39:12 | LL | if let TupleEnum::Empty = ref_value {} | ^^^^^^^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | if let TupleEnum::Empty = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:48:9 + --> $DIR/pattern_tuples.rs:55:9 | LL | let (_a, _b) = ref_value; | ^^^^^^^^ @@ -64,7 +65,7 @@ LL | let (_a, _b) = ref_value; = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:49:18 + --> $DIR/pattern_tuples.rs:57:18 | LL | if let &(_a, Some(_)) = ref_value {} | ^^^^^^^ @@ -72,7 +73,7 @@ LL | if let &(_a, Some(_)) = ref_value {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/pattern_tuples.rs:50:17 + --> $DIR/pattern_tuples.rs:59:17 | LL | if let (_a, Some(_)) = *ref_value {} | ^^^^^^^ diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.rs b/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.rs index e89917c41..dbc7c3f31 100644 --- a/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.rs +++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.rs @@ -9,6 +9,7 @@ fn syntax_match() { // not ok match ref_value { Some(_) => (), + //~^ ERROR: type of pattern does not match the expression type None => (), } @@ -28,6 +29,7 @@ fn syntax_if_let() { // not ok if let Some(_) = ref_value {} + //~^ ERROR: type of pattern does not match the expression type // ok if let &Some(_) = ref_value {} @@ -39,6 +41,7 @@ fn syntax_while_let() { // not ok while let Some(_) = ref_value { + //~^ ERROR: type of pattern does not match the expression type break; } @@ -57,6 +60,7 @@ fn syntax_for() { // not ok for (_a, _b) in slice.iter() {} + //~^ ERROR: type of pattern does not match the expression type // ok for &(_a, _b) in slice.iter() {} @@ -67,6 +71,7 @@ fn syntax_let() { // not ok let (_n, _m) = ref_value; + //~^ ERROR: type of pattern does not match the expression type // ok let &(_n, _m) = ref_value; @@ -76,6 +81,7 @@ fn syntax_let() { fn syntax_fn() { // not ok fn foo((_a, _b): &(i32, i32)) {} + //~^ ERROR: type of pattern does not match the expression type // ok fn foo_ok_1(&(_a, _b): &(i32, i32)) {} @@ -90,6 +96,7 @@ fn syntax_closure() { // not ok foo(|(_a, _b)| ()); + //~^ ERROR: type of pattern does not match the expression type // ok foo(|&(_a, _b)| ()); @@ -106,6 +113,7 @@ fn macro_with_expression() { // not ok matching_macro!(match value { Some(_) => (), + //~^ ERROR: type of pattern does not match the expression type _ => (), }); diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.stderr b/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.stderr index f56a3a893..dfe4639c7 100644 --- a/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.stderr +++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.stderr @@ -6,9 +6,10 @@ LL | Some(_) => (), | = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pattern_type_mismatch)]` error: type of pattern does not match the expression type - --> $DIR/syntax.rs:30:12 + --> $DIR/syntax.rs:31:12 | LL | if let Some(_) = ref_value {} | ^^^^^^^ @@ -16,7 +17,7 @@ LL | if let Some(_) = ref_value {} = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:41:15 + --> $DIR/syntax.rs:43:15 | LL | while let Some(_) = ref_value { | ^^^^^^^ @@ -24,7 +25,7 @@ LL | while let Some(_) = ref_value { = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:59:9 + --> $DIR/syntax.rs:62:9 | LL | for (_a, _b) in slice.iter() {} | ^^^^^^^^ @@ -32,7 +33,7 @@ LL | for (_a, _b) in slice.iter() {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:69:9 + --> $DIR/syntax.rs:73:9 | LL | let (_n, _m) = ref_value; | ^^^^^^^^ @@ -40,7 +41,7 @@ LL | let (_n, _m) = ref_value; = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:78:12 + --> $DIR/syntax.rs:83:12 | LL | fn foo((_a, _b): &(i32, i32)) {} | ^^^^^^^^ @@ -48,7 +49,7 @@ LL | fn foo((_a, _b): &(i32, i32)) {} = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:92:10 + --> $DIR/syntax.rs:98:10 | LL | foo(|(_a, _b)| ()); | ^^^^^^^^ @@ -56,7 +57,7 @@ LL | foo(|(_a, _b)| ()); = help: explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:108:9 + --> $DIR/syntax.rs:115:9 | LL | Some(_) => (), | ^^^^^^^ @@ -64,7 +65,7 @@ LL | Some(_) => (), = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings error: type of pattern does not match the expression type - --> $DIR/syntax.rs:128:17 + --> $DIR/syntax.rs:136:17 | LL | Some(_) => (), | ^^^^^^^ diff --git a/src/tools/clippy/tests/ui/patterns.fixed b/src/tools/clippy/tests/ui/patterns.fixed index 714143e75..332cba971 100644 --- a/src/tools/clippy/tests/ui/patterns.fixed +++ b/src/tools/clippy/tests/ui/patterns.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::all)] #![allow(unused)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/patterns.rs b/src/tools/clippy/tests/ui/patterns.rs index 153e26407..45d907688 100644 --- a/src/tools/clippy/tests/ui/patterns.rs +++ b/src/tools/clippy/tests/ui/patterns.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::all)] #![allow(unused)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/patterns.stderr b/src/tools/clippy/tests/ui/patterns.stderr index 276330d21..2f608bbc1 100644 --- a/src/tools/clippy/tests/ui/patterns.stderr +++ b/src/tools/clippy/tests/ui/patterns.stderr @@ -1,19 +1,20 @@ error: the `y @ _` pattern can be written as just `y` - --> $DIR/patterns.rs:15:9 + --> $DIR/patterns.rs:14:9 | LL | y @ _ => (), | ^^^^^ help: try: `y` | = note: `-D clippy::redundant-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern)]` error: the `x @ _` pattern can be written as just `x` - --> $DIR/patterns.rs:30:9 + --> $DIR/patterns.rs:29:9 | LL | ref mut x @ _ => { | ^^^^^^^^^^^^^ help: try: `ref mut x` error: the `x @ _` pattern can be written as just `x` - --> $DIR/patterns.rs:38:9 + --> $DIR/patterns.rs:37:9 | LL | ref x @ _ => println!("vec: {:?}", x), | ^^^^^^^^^ help: try: `ref x` diff --git a/src/tools/clippy/tests/ui/permissions_set_readonly_false.rs b/src/tools/clippy/tests/ui/permissions_set_readonly_false.rs index 28c00d100..5a84a64fd 100644 --- a/src/tools/clippy/tests/ui/permissions_set_readonly_false.rs +++ b/src/tools/clippy/tests/ui/permissions_set_readonly_false.rs @@ -17,6 +17,8 @@ fn main() { let mut permissions = metadata.permissions(); // lint here permissions.set_readonly(false); + //~^ ERROR: call to `set_readonly` with argument `false` + //~| NOTE: on Unix platforms this results in the file being world writable // no lint permissions.set_readonly(true); diff --git a/src/tools/clippy/tests/ui/permissions_set_readonly_false.stderr b/src/tools/clippy/tests/ui/permissions_set_readonly_false.stderr index e7a8ee6cb..58a7de84d 100644 --- a/src/tools/clippy/tests/ui/permissions_set_readonly_false.stderr +++ b/src/tools/clippy/tests/ui/permissions_set_readonly_false.stderr @@ -8,6 +8,7 @@ LL | permissions.set_readonly(false); = help: you can set the desired permissions using `PermissionsExt`. For more information, see https://doc.rust-lang.org/std/os/unix/fs/trait.PermissionsExt.html = note: `-D clippy::permissions-set-readonly-false` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::permissions_set_readonly_false)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/precedence.fixed b/src/tools/clippy/tests/ui/precedence.fixed index af4d5636b..cc87de0d9 100644 --- a/src/tools/clippy/tests/ui/precedence.fixed +++ b/src/tools/clippy/tests/ui/precedence.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::precedence)] #![allow(unused_must_use, clippy::no_effect, clippy::unnecessary_operation)] #![allow(clippy::identity_op)] diff --git a/src/tools/clippy/tests/ui/precedence.rs b/src/tools/clippy/tests/ui/precedence.rs index e23ae9127..00c18d92b 100644 --- a/src/tools/clippy/tests/ui/precedence.rs +++ b/src/tools/clippy/tests/ui/precedence.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::precedence)] #![allow(unused_must_use, clippy::no_effect, clippy::unnecessary_operation)] #![allow(clippy::identity_op)] diff --git a/src/tools/clippy/tests/ui/precedence.stderr b/src/tools/clippy/tests/ui/precedence.stderr index 03d585b39..bd0cbccc7 100644 --- a/src/tools/clippy/tests/ui/precedence.stderr +++ b/src/tools/clippy/tests/ui/precedence.stderr @@ -1,73 +1,74 @@ error: operator precedence can trip the unwary - --> $DIR/precedence.rs:17:5 + --> $DIR/precedence.rs:16:5 | LL | 1 << 2 + 3; | ^^^^^^^^^^ help: consider parenthesizing your expression: `1 << (2 + 3)` | = note: `-D clippy::precedence` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::precedence)]` error: operator precedence can trip the unwary - --> $DIR/precedence.rs:18:5 + --> $DIR/precedence.rs:17:5 | LL | 1 + 2 << 3; | ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 2) << 3` error: operator precedence can trip the unwary - --> $DIR/precedence.rs:19:5 + --> $DIR/precedence.rs:18:5 | LL | 4 >> 1 + 1; | ^^^^^^^^^^ help: consider parenthesizing your expression: `4 >> (1 + 1)` error: operator precedence can trip the unwary - --> $DIR/precedence.rs:20:5 + --> $DIR/precedence.rs:19:5 | LL | 1 + 3 >> 2; | ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 3) >> 2` error: operator precedence can trip the unwary - --> $DIR/precedence.rs:21:5 + --> $DIR/precedence.rs:20:5 | LL | 1 ^ 1 - 1; | ^^^^^^^^^ help: consider parenthesizing your expression: `1 ^ (1 - 1)` error: operator precedence can trip the unwary - --> $DIR/precedence.rs:22:5 + --> $DIR/precedence.rs:21:5 | LL | 3 | 2 - 1; | ^^^^^^^^^ help: consider parenthesizing your expression: `3 | (2 - 1)` error: operator precedence can trip the unwary - --> $DIR/precedence.rs:23:5 + --> $DIR/precedence.rs:22:5 | LL | 3 & 5 - 2; | ^^^^^^^^^ help: consider parenthesizing your expression: `3 & (5 - 2)` error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:24:5 + --> $DIR/precedence.rs:23:5 | LL | -1i32.abs(); | ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1i32.abs())` error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:25:5 + --> $DIR/precedence.rs:24:5 | LL | -1f32.abs(); | ^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1f32.abs())` error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:52:13 + --> $DIR/precedence.rs:51:13 | LL | let _ = -1.0_f64.cos().cos(); | ^^^^^^^^^^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1.0_f64.cos().cos())` error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:53:13 + --> $DIR/precedence.rs:52:13 | LL | let _ = -1.0_f64.cos().sin(); | ^^^^^^^^^^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1.0_f64.cos().sin())` error: unary minus has lower precedence than method call - --> $DIR/precedence.rs:54:13 + --> $DIR/precedence.rs:53:13 | LL | let _ = -1.0_f64.sin().cos(); | ^^^^^^^^^^^^^^^^^^^^ help: consider adding parentheses to clarify your intent: `-(1.0_f64.sin().cos())` diff --git a/src/tools/clippy/tests/ui/print.rs b/src/tools/clippy/tests/ui/print.rs index 366ccc2b3..9ac4b51e1 100644 --- a/src/tools/clippy/tests/ui/print.rs +++ b/src/tools/clippy/tests/ui/print.rs @@ -9,6 +9,8 @@ struct Foo; impl Display for Foo { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{:?}", 43.1415) + //~^ ERROR: use of `Debug`-based formatting + //~| NOTE: `-D clippy::use-debug` implied by `-D warnings` } } @@ -21,13 +23,21 @@ impl Debug for Foo { fn main() { println!("Hello"); + //~^ ERROR: use of `println!` + //~| NOTE: `-D clippy::print-stdout` implied by `-D warnings` print!("Hello"); + //~^ ERROR: use of `print!` print!("Hello {}", "World"); + //~^ ERROR: use of `print!` print!("Hello {:?}", "World"); + //~^ ERROR: use of `print!` + //~| ERROR: use of `Debug`-based formatting print!("Hello {:#?}", "#orld"); + //~^ ERROR: use of `print!` + //~| ERROR: use of `Debug`-based formatting assert_eq!(42, 1337); diff --git a/src/tools/clippy/tests/ui/print.stderr b/src/tools/clippy/tests/ui/print.stderr index 1754c4183..bb8d94508 100644 --- a/src/tools/clippy/tests/ui/print.stderr +++ b/src/tools/clippy/tests/ui/print.stderr @@ -5,47 +5,49 @@ LL | write!(f, "{:?}", 43.1415) | ^^^^ | = note: `-D clippy::use-debug` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::use_debug)]` error: use of `println!` - --> $DIR/print.rs:23:5 + --> $DIR/print.rs:25:5 | LL | println!("Hello"); | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::print-stdout` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_stdout)]` error: use of `print!` - --> $DIR/print.rs:24:5 + --> $DIR/print.rs:28:5 | LL | print!("Hello"); | ^^^^^^^^^^^^^^^ error: use of `print!` - --> $DIR/print.rs:26:5 + --> $DIR/print.rs:31:5 | LL | print!("Hello {}", "World"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `print!` - --> $DIR/print.rs:28:5 + --> $DIR/print.rs:34:5 | LL | print!("Hello {:?}", "World"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `Debug`-based formatting - --> $DIR/print.rs:28:19 + --> $DIR/print.rs:34:19 | LL | print!("Hello {:?}", "World"); | ^^^^ error: use of `print!` - --> $DIR/print.rs:30:5 + --> $DIR/print.rs:38:5 | LL | print!("Hello {:#?}", "#orld"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: use of `Debug`-based formatting - --> $DIR/print.rs:30:19 + --> $DIR/print.rs:38:19 | LL | print!("Hello {:#?}", "#orld"); | ^^^^^ diff --git a/src/tools/clippy/tests/ui/print_in_format_impl.rs b/src/tools/clippy/tests/ui/print_in_format_impl.rs index 64e886866..261f50832 100644 --- a/src/tools/clippy/tests/ui/print_in_format_impl.rs +++ b/src/tools/clippy/tests/ui/print_in_format_impl.rs @@ -1,7 +1,7 @@ #![allow(unused, clippy::print_literal, clippy::write_literal)] #![warn(clippy::print_in_format_impl)] use std::fmt::{Debug, Display, Error, Formatter}; - +//@no-rustfix macro_rules! indirect { () => {{ println!() }}; } @@ -18,11 +18,17 @@ impl Debug for Foo { static WORKS_WITH_NESTED_ITEMS: bool = true; print!("{}", 1); + //~^ ERROR: use of `print!` in `Debug` impl + //~| NOTE: `-D clippy::print-in-format-impl` implied by `-D warnings` println!("{}", 2); + //~^ ERROR: use of `println!` in `Debug` impl eprint!("{}", 3); + //~^ ERROR: use of `eprint!` in `Debug` impl eprintln!("{}", 4); + //~^ ERROR: use of `eprintln!` in `Debug` impl nested! { println!("nested"); + //~^ ERROR: use of `println!` in `Debug` impl }; write!(f, "{}", 5); @@ -36,6 +42,7 @@ impl Debug for Foo { impl Display for Foo { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { print!("Display"); + //~^ ERROR: use of `print!` in `Display` impl write!(f, "Display"); Ok(()) @@ -46,6 +53,7 @@ struct UnnamedFormatter; impl Debug for UnnamedFormatter { fn fmt(&self, _: &mut Formatter) -> Result<(), Error> { println!("UnnamedFormatter"); + //~^ ERROR: use of `println!` in `Debug` impl Ok(()) } } diff --git a/src/tools/clippy/tests/ui/print_in_format_impl.stderr b/src/tools/clippy/tests/ui/print_in_format_impl.stderr index 63b7179bc..57f06dc11 100644 --- a/src/tools/clippy/tests/ui/print_in_format_impl.stderr +++ b/src/tools/clippy/tests/ui/print_in_format_impl.stderr @@ -5,39 +5,40 @@ LL | print!("{}", 1); | ^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` | = note: `-D clippy::print-in-format-impl` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_in_format_impl)]` error: use of `println!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:21:9 + --> $DIR/print_in_format_impl.rs:23:9 | LL | println!("{}", 2); | ^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `eprint!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:22:9 + --> $DIR/print_in_format_impl.rs:25:9 | LL | eprint!("{}", 3); | ^^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` error: use of `eprintln!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:23:9 + --> $DIR/print_in_format_impl.rs:27:9 | LL | eprintln!("{}", 4); | ^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `println!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:25:13 + --> $DIR/print_in_format_impl.rs:30:13 | LL | println!("nested"); | ^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(f, ..)` error: use of `print!` in `Display` impl - --> $DIR/print_in_format_impl.rs:38:9 + --> $DIR/print_in_format_impl.rs:44:9 | LL | print!("Display"); | ^^^^^^^^^^^^^^^^^ help: replace with: `write!(f, ..)` error: use of `println!` in `Debug` impl - --> $DIR/print_in_format_impl.rs:48:9 + --> $DIR/print_in_format_impl.rs:55:9 | LL | println!("UnnamedFormatter"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `writeln!(..)` diff --git a/src/tools/clippy/tests/ui/print_literal.fixed b/src/tools/clippy/tests/ui/print_literal.fixed new file mode 100644 index 000000000..88cd3a54b --- /dev/null +++ b/src/tools/clippy/tests/ui/print_literal.fixed @@ -0,0 +1,58 @@ +#![warn(clippy::print_literal)] +#![allow(clippy::uninlined_format_args)] + +fn main() { + // these should be fine + print!("Hello"); + println!("Hello"); + let world = "world"; + println!("Hello {}", world); + println!("Hello {world}", world = world); + println!("3 in hex is {:X}", 3); + println!("2 + 1 = {:.4}", 3); + println!("2 + 1 = {:5.4}", 3); + println!("Debug test {:?}", "hello, world"); + println!("{0:8} {1:>8}", "hello", "world"); + println!("{1:8} {0:>8}", "hello", "world"); + println!("{foo:8} {bar:>8}", foo = "hello", bar = "world"); + println!("{bar:8} {foo:>8}", foo = "hello", bar = "world"); + println!("{number:>width$}", number = 1, width = 6); + println!("{number:>0width$}", number = 1, width = 6); + println!("{} of {:b} people know binary, the other half doesn't", 1, 2); + println!("10 / 4 is {}", 2.5); + println!("2 + 1 = {}", 3); + println!("From expansion {}", stringify!(not a string literal)); + + // these should throw warnings + print!("Hello world"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::print-literal` implied by `-D warnings` + println!("Hello {} world", world); + //~^ ERROR: literal with an empty format string + println!("Hello world"); + //~^ ERROR: literal with an empty format string + println!("a literal {:.4}", 5); + //~^ ERROR: literal with an empty format string + + // positional args don't change the fact + // that we're using a literal -- this should + // throw a warning + println!("hello world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string + println!("world hello"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string + + // named args shouldn't change anything either + println!("hello world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string + println!("world hello"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string + + // The string literal from `file!()` has a callsite span that isn't marked as coming from an + // expansion + println!("file: {}", file!()); +} diff --git a/src/tools/clippy/tests/ui/print_literal.rs b/src/tools/clippy/tests/ui/print_literal.rs index 538513e91..bd7444c96 100644 --- a/src/tools/clippy/tests/ui/print_literal.rs +++ b/src/tools/clippy/tests/ui/print_literal.rs @@ -25,19 +25,32 @@ fn main() { // these should throw warnings print!("Hello {}", "world"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::print-literal` implied by `-D warnings` println!("Hello {} {}", world, "world"); + //~^ ERROR: literal with an empty format string println!("Hello {}", "world"); + //~^ ERROR: literal with an empty format string println!("{} {:.4}", "a literal", 5); + //~^ ERROR: literal with an empty format string // positional args don't change the fact // that we're using a literal -- this should // throw a warning println!("{0} {1}", "hello", "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string println!("{1} {0}", "hello", "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // named args shouldn't change anything either println!("{foo} {bar}", foo = "hello", bar = "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string println!("{bar} {foo}", foo = "hello", bar = "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // The string literal from `file!()` has a callsite span that isn't marked as coming from an // expansion diff --git a/src/tools/clippy/tests/ui/print_literal.stderr b/src/tools/clippy/tests/ui/print_literal.stderr index 71c8d188f..1d9751b92 100644 --- a/src/tools/clippy/tests/ui/print_literal.stderr +++ b/src/tools/clippy/tests/ui/print_literal.stderr @@ -5,6 +5,7 @@ LL | print!("Hello {}", "world"); | ^^^^^^^ | = note: `-D clippy::print-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_literal)]` help: try | LL - print!("Hello {}", "world"); @@ -12,7 +13,7 @@ LL + print!("Hello world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:28:36 + --> $DIR/print_literal.rs:30:36 | LL | println!("Hello {} {}", world, "world"); | ^^^^^^^ @@ -24,7 +25,7 @@ LL + println!("Hello {} world", world); | error: literal with an empty format string - --> $DIR/print_literal.rs:29:26 + --> $DIR/print_literal.rs:32:26 | LL | println!("Hello {}", "world"); | ^^^^^^^ @@ -36,7 +37,7 @@ LL + println!("Hello world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:30:26 + --> $DIR/print_literal.rs:34:26 | LL | println!("{} {:.4}", "a literal", 5); | ^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL + println!("a literal {:.4}", 5); | error: literal with an empty format string - --> $DIR/print_literal.rs:35:25 + --> $DIR/print_literal.rs:40:25 | LL | println!("{0} {1}", "hello", "world"); | ^^^^^^^ @@ -60,7 +61,7 @@ LL + println!("hello {1}", "world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:35:34 + --> $DIR/print_literal.rs:40:34 | LL | println!("{0} {1}", "hello", "world"); | ^^^^^^^ @@ -72,7 +73,7 @@ LL + println!("{0} world", "hello"); | error: literal with an empty format string - --> $DIR/print_literal.rs:36:34 + --> $DIR/print_literal.rs:43:34 | LL | println!("{1} {0}", "hello", "world"); | ^^^^^^^ @@ -84,7 +85,7 @@ LL + println!("world {0}", "hello"); | error: literal with an empty format string - --> $DIR/print_literal.rs:36:25 + --> $DIR/print_literal.rs:43:25 | LL | println!("{1} {0}", "hello", "world"); | ^^^^^^^ @@ -96,7 +97,7 @@ LL + println!("{1} hello", "world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:39:35 + --> $DIR/print_literal.rs:48:35 | LL | println!("{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -108,7 +109,7 @@ LL + println!("hello {bar}", bar = "world"); | error: literal with an empty format string - --> $DIR/print_literal.rs:39:50 + --> $DIR/print_literal.rs:48:50 | LL | println!("{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -120,7 +121,7 @@ LL + println!("{foo} world", foo = "hello"); | error: literal with an empty format string - --> $DIR/print_literal.rs:40:50 + --> $DIR/print_literal.rs:51:50 | LL | println!("{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -132,7 +133,7 @@ LL + println!("world {foo}", foo = "hello"); | error: literal with an empty format string - --> $DIR/print_literal.rs:40:35 + --> $DIR/print_literal.rs:51:35 | LL | println!("{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^ diff --git a/src/tools/clippy/tests/ui/print_stderr.rs b/src/tools/clippy/tests/ui/print_stderr.rs index fa07e74a7..109f43ffe 100644 --- a/src/tools/clippy/tests/ui/print_stderr.rs +++ b/src/tools/clippy/tests/ui/print_stderr.rs @@ -2,7 +2,10 @@ fn main() { eprintln!("Hello"); + //~^ ERROR: use of `eprintln!` + //~| NOTE: `-D clippy::print-stderr` implied by `-D warnings` println!("This should not do anything"); eprint!("World"); + //~^ ERROR: use of `eprint!` print!("Nor should this"); } diff --git a/src/tools/clippy/tests/ui/print_stderr.stderr b/src/tools/clippy/tests/ui/print_stderr.stderr index 5af735af6..7de163310 100644 --- a/src/tools/clippy/tests/ui/print_stderr.stderr +++ b/src/tools/clippy/tests/ui/print_stderr.stderr @@ -5,9 +5,10 @@ LL | eprintln!("Hello"); | ^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::print-stderr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_stderr)]` error: use of `eprint!` - --> $DIR/print_stderr.rs:6:5 + --> $DIR/print_stderr.rs:8:5 | LL | eprint!("World"); | ^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/print_with_newline.fixed b/src/tools/clippy/tests/ui/print_with_newline.fixed index 6098dea39..7ac6d2870 100644 --- a/src/tools/clippy/tests/ui/print_with_newline.fixed +++ b/src/tools/clippy/tests/ui/print_with_newline.fixed @@ -1,15 +1,20 @@ // FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 -//@run-rustfix #![allow(clippy::print_literal)] #![warn(clippy::print_with_newline)] fn main() { println!("Hello"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::print-with-newline` implied by `-D warnings` println!("Hello {}", "world"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline println!("Hello {} {}", "world", "#2"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline println!("{}", 1265); + //~^ ERROR: using `print!()` with a format string that ends in a single newline println!(); + //~^ ERROR: using `print!()` with a format string that ends in a single newline // these are all fine print!(""); @@ -23,29 +28,38 @@ fn main() { print!("\n\n"); print!("like eof\n\n"); print!("Hello {} {}\n\n", "world", "#2"); - println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - println!("\nbla\n\n"); // #3126 + // #3126 + println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + println!("\nbla\n\n"); // Escaping - print!("\\n"); // #3514 - println!("\\"); // should fail + // #3514 + print!("\\n"); + println!("\\"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("\\\\n"); // Raw strings - print!(r"\n"); // #3778 + // #3778 + print!(r"\n"); // Literal newlines should also fail println!( + //~^ ERROR: using `print!()` with a format string that ends in a single newline ); println!( + //~^ ERROR: using `print!()` with a format string that ends in a single newline ); // Don't warn on CRLF (#4208) print!("\r\n"); print!("foo\r\n"); - println!("\\r"); // should fail + // should fail + println!("\\r"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("foo\rbar\n"); // Ignore expanded format strings diff --git a/src/tools/clippy/tests/ui/print_with_newline.rs b/src/tools/clippy/tests/ui/print_with_newline.rs index d9c7acc27..602d1ea3e 100644 --- a/src/tools/clippy/tests/ui/print_with_newline.rs +++ b/src/tools/clippy/tests/ui/print_with_newline.rs @@ -1,15 +1,20 @@ // FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 -// #![allow(clippy::print_literal)] #![warn(clippy::print_with_newline)] fn main() { print!("Hello\n"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::print-with-newline` implied by `-D warnings` print!("Hello {}\n", "world"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("Hello {} {}\n", "world", "#2"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("{}\n", 1265); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("\n"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline // these are all fine print!(""); @@ -23,23 +28,30 @@ fn main() { print!("\n\n"); print!("like eof\n\n"); print!("Hello {} {}\n\n", "world", "#2"); - println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - println!("\nbla\n\n"); // #3126 + // #3126 + println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + println!("\nbla\n\n"); // Escaping - print!("\\n"); // #3514 - print!("\\\n"); // should fail + // #3514 + print!("\\n"); + print!("\\\n"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("\\\\n"); // Raw strings - print!(r"\n"); // #3778 + // #3778 + print!(r"\n"); // Literal newlines should also fail print!( + //~^ ERROR: using `print!()` with a format string that ends in a single newline " " ); print!( + //~^ ERROR: using `print!()` with a format string that ends in a single newline r" " ); @@ -47,7 +59,9 @@ fn main() { // Don't warn on CRLF (#4208) print!("\r\n"); print!("foo\r\n"); - print!("\\r\n"); // should fail + // should fail + print!("\\r\n"); + //~^ ERROR: using `print!()` with a format string that ends in a single newline print!("foo\rbar\n"); // Ignore expanded format strings diff --git a/src/tools/clippy/tests/ui/print_with_newline.stderr b/src/tools/clippy/tests/ui/print_with_newline.stderr index b97711e77..7ff6a5f06 100644 --- a/src/tools/clippy/tests/ui/print_with_newline.stderr +++ b/src/tools/clippy/tests/ui/print_with_newline.stderr @@ -1,80 +1,82 @@ error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:8:5 + --> $DIR/print_with_newline.rs:7:5 | -LL | print!("Hello/n"); +LL | print!("Hello\n"); | ^^^^^^^^^^^^^^^^^ | = note: `-D clippy::print-with-newline` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::print_with_newline)]` help: use `println!` instead | -LL - print!("Hello/n"); +LL - print!("Hello\n"); LL + println!("Hello"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:9:5 + --> $DIR/print_with_newline.rs:10:5 | -LL | print!("Hello {}/n", "world"); +LL | print!("Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("Hello {}/n", "world"); +LL - print!("Hello {}\n", "world"); LL + println!("Hello {}", "world"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:10:5 + --> $DIR/print_with_newline.rs:12:5 | -LL | print!("Hello {} {}/n", "world", "#2"); +LL | print!("Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("Hello {} {}/n", "world", "#2"); +LL - print!("Hello {} {}\n", "world", "#2"); LL + println!("Hello {} {}", "world", "#2"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:11:5 + --> $DIR/print_with_newline.rs:14:5 | -LL | print!("{}/n", 1265); +LL | print!("{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("{}/n", 1265); +LL - print!("{}\n", 1265); LL + println!("{}", 1265); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:12:5 + --> $DIR/print_with_newline.rs:16:5 | -LL | print!("/n"); +LL | print!("\n"); | ^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("/n"); +LL - print!("\n"); LL + println!(); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:31:5 + --> $DIR/print_with_newline.rs:39:5 | -LL | print!("///n"); // should fail +LL | print!("\\\n"); | ^^^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("///n"); // should fail -LL + println!("//"); // should fail +LL - print!("\\\n"); +LL + println!("\\"); | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:38:5 + --> $DIR/print_with_newline.rs:48:5 | LL | / print!( +LL | | LL | | " LL | | " LL | | ); @@ -83,13 +85,15 @@ LL | | ); help: use `println!` instead | LL ~ println!( +LL | LL ~ | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:42:5 + --> $DIR/print_with_newline.rs:53:5 | LL | / print!( +LL | | LL | | r" LL | | " LL | | ); @@ -98,19 +102,20 @@ LL | | ); help: use `println!` instead | LL ~ println!( +LL | LL ~ | error: using `print!()` with a format string that ends in a single newline - --> $DIR/print_with_newline.rs:50:5 + --> $DIR/print_with_newline.rs:63:5 | -LL | print!("//r/n"); // should fail +LL | print!("\\r\n"); | ^^^^^^^^^^^^^^^ | help: use `println!` instead | -LL - print!("//r/n"); // should fail -LL + println!("//r"); // should fail +LL - print!("\\r\n"); +LL + println!("\\r"); | error: aborting due to 9 previous errors diff --git a/src/tools/clippy/tests/ui/println_empty_string.fixed b/src/tools/clippy/tests/ui/println_empty_string.fixed index abf951ae2..20811fc75 100644 --- a/src/tools/clippy/tests/ui/println_empty_string.fixed +++ b/src/tools/clippy/tests/ui/println_empty_string.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::match_single_binding)] fn main() { diff --git a/src/tools/clippy/tests/ui/println_empty_string.rs b/src/tools/clippy/tests/ui/println_empty_string.rs index fd86e2543..47f7277dc 100644 --- a/src/tools/clippy/tests/ui/println_empty_string.rs +++ b/src/tools/clippy/tests/ui/println_empty_string.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::match_single_binding)] fn main() { diff --git a/src/tools/clippy/tests/ui/println_empty_string.stderr b/src/tools/clippy/tests/ui/println_empty_string.stderr index 3cc8bb947..c89e64f66 100644 --- a/src/tools/clippy/tests/ui/println_empty_string.stderr +++ b/src/tools/clippy/tests/ui/println_empty_string.stderr @@ -1,5 +1,5 @@ error: empty string literal in `println!` - --> $DIR/println_empty_string.rs:6:5 + --> $DIR/println_empty_string.rs:5:5 | LL | println!(""); | ^^^^^^^^^--^ @@ -7,9 +7,10 @@ LL | println!(""); | help: remove the empty string | = note: `-D clippy::println-empty-string` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::println_empty_string)]` error: empty string literal in `println!` - --> $DIR/println_empty_string.rs:9:14 + --> $DIR/println_empty_string.rs:8:14 | LL | _ => println!(""), | ^^^^^^^^^--^ @@ -17,7 +18,7 @@ LL | _ => println!(""), | help: remove the empty string error: empty string literal in `eprintln!` - --> $DIR/println_empty_string.rs:13:5 + --> $DIR/println_empty_string.rs:12:5 | LL | eprintln!(""); | ^^^^^^^^^^--^ @@ -25,7 +26,7 @@ LL | eprintln!(""); | help: remove the empty string error: empty string literal in `eprintln!` - --> $DIR/println_empty_string.rs:16:14 + --> $DIR/println_empty_string.rs:15:14 | LL | _ => eprintln!(""), | ^^^^^^^^^^--^ diff --git a/src/tools/clippy/tests/ui/proc_macro.rs b/src/tools/clippy/tests/ui/proc_macro.rs index b77874034..e5b155dd1 100644 --- a/src/tools/clippy/tests/ui/proc_macro.rs +++ b/src/tools/clippy/tests/ui/proc_macro.rs @@ -7,6 +7,7 @@ use proc_macro::TokenStream; #[allow(dead_code)] fn f() { let _x = 3.14; + //~^ ERROR: approximate value of `f{32, 64}::consts::PI` found } #[proc_macro] diff --git a/src/tools/clippy/tests/ui/ptr_arg.rs b/src/tools/clippy/tests/ui/ptr_arg.rs index 08075c382..91e2e7fd6 100644 --- a/src/tools/clippy/tests/ui/ptr_arg.rs +++ b/src/tools/clippy/tests/ui/ptr_arg.rs @@ -7,31 +7,38 @@ clippy::needless_pass_by_ref_mut )] #![warn(clippy::ptr_arg)] - +//@no-rustfix use std::borrow::Cow; use std::path::{Path, PathBuf}; fn do_vec(x: &Vec) { + //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will do + //~| NOTE: `-D clippy::ptr-arg` implied by `-D warnings` //Nothing here } fn do_vec_mut(x: &mut Vec) { + //~^ ERROR: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice w //Nothing here } fn do_str(x: &String) { + //~^ ERROR: writing `&String` instead of `&str` involves a new object where a slice will d //Nothing here either } fn do_str_mut(x: &mut String) { + //~^ ERROR: writing `&mut String` instead of `&mut str` involves a new object where a slic //Nothing here either } fn do_path(x: &PathBuf) { + //~^ ERROR: writing `&PathBuf` instead of `&Path` involves a new object where a slice will //Nothing here either } fn do_path_mut(x: &mut PathBuf) { + //~^ ERROR: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a sl //Nothing here either } @@ -40,6 +47,7 @@ fn main() {} trait Foo { type Item; fn do_vec(x: &Vec); + //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will fn do_item(x: &Self::Item); } @@ -53,6 +61,7 @@ impl Foo for Bar { } fn cloned(x: &Vec) -> Vec { + //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will do let e = x.clone(); let f = e.clone(); // OK let g = x; @@ -62,6 +71,7 @@ fn cloned(x: &Vec) -> Vec { } fn str_cloned(x: &String) -> String { + //~^ ERROR: writing `&String` instead of `&str` involves a new object where a slice will d let a = x.clone(); let b = x.clone(); let c = b.clone(); @@ -70,6 +80,7 @@ fn str_cloned(x: &String) -> String { } fn path_cloned(x: &PathBuf) -> PathBuf { + //~^ ERROR: writing `&PathBuf` instead of `&Path` involves a new object where a slice will let a = x.clone(); let b = x.clone(); let c = b.clone(); @@ -78,6 +89,7 @@ fn path_cloned(x: &PathBuf) -> PathBuf { } fn false_positive_capacity(x: &Vec, y: &String) { + //~^ ERROR: writing `&String` instead of `&str` involves a new object where a slice will d let a = x.capacity(); let b = y.clone(); let c = y.as_str(); @@ -92,6 +104,7 @@ fn false_positive_capacity_too(x: &String) -> String { #[allow(dead_code)] fn test_cow_with_ref(c: &Cow<[i32]>) {} +//~^ ERROR: using a reference to `Cow` is not recommended fn test_cow(c: Cow<[i32]>) { let _c = c; @@ -121,6 +134,7 @@ mod issue_5644 { } fn some_allowed(#[allow(clippy::ptr_arg)] _v: &Vec, _s: &String) {} + //~^ ERROR: writing `&String` instead of `&str` involves a new object where a slice wi struct S; impl S { @@ -150,22 +164,26 @@ mod issue6509 { use std::path::PathBuf; fn foo_vec(vec: &Vec) { + //~^ ERROR: writing `&Vec` instead of `&[_]` involves a new object where a slice will let _ = vec.clone().pop(); let _ = vec.clone().clone(); } fn foo_path(path: &PathBuf) { + //~^ ERROR: writing `&PathBuf` instead of `&Path` involves a new object where a slice let _ = path.clone().pop(); let _ = path.clone().clone(); } fn foo_str(str: &PathBuf) { + //~^ ERROR: writing `&PathBuf` instead of `&Path` involves a new object where a slice let _ = str.clone().pop(); let _ = str.clone().clone(); } } fn mut_vec_slice_methods(v: &mut Vec) { + //~^ ERROR: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice w v.copy_within(1..5, 10); } @@ -228,6 +246,9 @@ fn dyn_trait_ok(a: &mut Vec, b: &mut String, c: &mut PathBuf) { } fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { + //~^ ERROR: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice w + //~| ERROR: writing `&mut String` instead of `&mut str` involves a new object where a slic + //~| ERROR: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a sl trait T {} impl T for Vec {} impl T for [U] {} @@ -251,14 +272,17 @@ mod issue_9218 { // This one has an anonymous lifetime so it's not okay fn cow_elided_lifetime<'a>(input: &'a Cow) -> &'a str { + //~^ ERROR: using a reference to `Cow` is not recommended todo!() } // These two's return types don't use use 'a so it's not okay fn cow_bad_ret_ty_1<'a>(input: &'a Cow<'a, str>) -> &'static str { + //~^ ERROR: using a reference to `Cow` is not recommended todo!() } fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str { + //~^ ERROR: using a reference to `Cow` is not recommended todo!() } diff --git a/src/tools/clippy/tests/ui/ptr_arg.stderr b/src/tools/clippy/tests/ui/ptr_arg.stderr index 0e9dd760f..cccf2d62d 100644 --- a/src/tools/clippy/tests/ui/ptr_arg.stderr +++ b/src/tools/clippy/tests/ui/ptr_arg.stderr @@ -5,45 +5,46 @@ LL | fn do_vec(x: &Vec) { | ^^^^^^^^^ help: change this to: `&[i64]` | = note: `-D clippy::ptr-arg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ptr_arg)]` error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:18:18 + --> $DIR/ptr_arg.rs:20:18 | LL | fn do_vec_mut(x: &mut Vec) { | ^^^^^^^^^^^^^ help: change this to: `&mut [i64]` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:22:14 + --> $DIR/ptr_arg.rs:25:14 | LL | fn do_str(x: &String) { | ^^^^^^^ help: change this to: `&str` error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:26:18 + --> $DIR/ptr_arg.rs:30:18 | LL | fn do_str_mut(x: &mut String) { | ^^^^^^^^^^^ help: change this to: `&mut str` error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:30:15 + --> $DIR/ptr_arg.rs:35:15 | LL | fn do_path(x: &PathBuf) { | ^^^^^^^^ help: change this to: `&Path` error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:34:19 + --> $DIR/ptr_arg.rs:40:19 | LL | fn do_path_mut(x: &mut PathBuf) { | ^^^^^^^^^^^^ help: change this to: `&mut Path` error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:42:18 + --> $DIR/ptr_arg.rs:49:18 | LL | fn do_vec(x: &Vec); | ^^^^^^^^^ help: change this to: `&[i64]` error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:55:14 + --> $DIR/ptr_arg.rs:63:14 | LL | fn cloned(x: &Vec) -> Vec { | ^^^^^^^^ @@ -51,6 +52,7 @@ LL | fn cloned(x: &Vec) -> Vec { help: change this to | LL ~ fn cloned(x: &[u8]) -> Vec { +LL | LL ~ let e = x.to_owned(); LL | let f = e.clone(); // OK LL | let g = x; @@ -60,7 +62,7 @@ LL ~ x.to_owned() | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:64:18 + --> $DIR/ptr_arg.rs:73:18 | LL | fn str_cloned(x: &String) -> String { | ^^^^^^^ @@ -68,6 +70,7 @@ LL | fn str_cloned(x: &String) -> String { help: change this to | LL ~ fn str_cloned(x: &str) -> String { +LL | LL ~ let a = x.to_owned(); LL ~ let b = x.to_owned(); LL | let c = b.clone(); @@ -76,7 +79,7 @@ LL ~ x.to_owned() | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:72:19 + --> $DIR/ptr_arg.rs:82:19 | LL | fn path_cloned(x: &PathBuf) -> PathBuf { | ^^^^^^^^ @@ -84,6 +87,7 @@ LL | fn path_cloned(x: &PathBuf) -> PathBuf { help: change this to | LL ~ fn path_cloned(x: &Path) -> PathBuf { +LL | LL ~ let a = x.to_path_buf(); LL ~ let b = x.to_path_buf(); LL | let c = b.clone(); @@ -92,7 +96,7 @@ LL ~ x.to_path_buf() | error: writing `&String` instead of `&str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:80:44 + --> $DIR/ptr_arg.rs:91:44 | LL | fn false_positive_capacity(x: &Vec, y: &String) { | ^^^^^^^ @@ -100,25 +104,26 @@ LL | fn false_positive_capacity(x: &Vec, y: &String) { help: change this to | LL ~ fn false_positive_capacity(x: &Vec, y: &str) { +LL | LL | let a = x.capacity(); LL ~ let b = y.to_owned(); LL ~ let c = y; | error: using a reference to `Cow` is not recommended - --> $DIR/ptr_arg.rs:94:25 + --> $DIR/ptr_arg.rs:106:25 | LL | fn test_cow_with_ref(c: &Cow<[i32]>) {} | ^^^^^^^^^^^ help: change this to: `&[i32]` error: writing `&String` instead of `&str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:123:66 + --> $DIR/ptr_arg.rs:136:66 | LL | fn some_allowed(#[allow(clippy::ptr_arg)] _v: &Vec, _s: &String) {} | ^^^^^^^ help: change this to: `&str` error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:152:21 + --> $DIR/ptr_arg.rs:166:21 | LL | fn foo_vec(vec: &Vec) { | ^^^^^^^^ @@ -126,12 +131,13 @@ LL | fn foo_vec(vec: &Vec) { help: change this to | LL ~ fn foo_vec(vec: &[u8]) { +LL | LL ~ let _ = vec.to_owned().pop(); LL ~ let _ = vec.to_owned().clone(); | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:157:23 + --> $DIR/ptr_arg.rs:172:23 | LL | fn foo_path(path: &PathBuf) { | ^^^^^^^^ @@ -139,12 +145,13 @@ LL | fn foo_path(path: &PathBuf) { help: change this to | LL ~ fn foo_path(path: &Path) { +LL | LL ~ let _ = path.to_path_buf().pop(); LL ~ let _ = path.to_path_buf().clone(); | error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:162:21 + --> $DIR/ptr_arg.rs:178:21 | LL | fn foo_str(str: &PathBuf) { | ^^^^^^^^ @@ -152,48 +159,49 @@ LL | fn foo_str(str: &PathBuf) { help: change this to | LL ~ fn foo_str(str: &Path) { +LL | LL ~ let _ = str.to_path_buf().pop(); LL ~ let _ = str.to_path_buf().clone(); | error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:168:29 + --> $DIR/ptr_arg.rs:185:29 | LL | fn mut_vec_slice_methods(v: &mut Vec) { | ^^^^^^^^^^^^^ help: change this to: `&mut [u32]` error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:230:17 + --> $DIR/ptr_arg.rs:248:17 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^^^ help: change this to: `&mut [u32]` error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:230:35 + --> $DIR/ptr_arg.rs:248:35 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^ help: change this to: `&mut str` error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do - --> $DIR/ptr_arg.rs:230:51 + --> $DIR/ptr_arg.rs:248:51 | LL | fn dyn_trait(a: &mut Vec, b: &mut String, c: &mut PathBuf) { | ^^^^^^^^^^^^ help: change this to: `&mut Path` error: using a reference to `Cow` is not recommended - --> $DIR/ptr_arg.rs:253:39 + --> $DIR/ptr_arg.rs:274:39 | LL | fn cow_elided_lifetime<'a>(input: &'a Cow) -> &'a str { | ^^^^^^^^^^^^ help: change this to: `&str` error: using a reference to `Cow` is not recommended - --> $DIR/ptr_arg.rs:258:36 + --> $DIR/ptr_arg.rs:280:36 | LL | fn cow_bad_ret_ty_1<'a>(input: &'a Cow<'a, str>) -> &'static str { | ^^^^^^^^^^^^^^^^ help: change this to: `&str` error: using a reference to `Cow` is not recommended - --> $DIR/ptr_arg.rs:261:40 + --> $DIR/ptr_arg.rs:284:40 | LL | fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str { | ^^^^^^^^^^^^^^^^ help: change this to: `&str` diff --git a/src/tools/clippy/tests/ui/ptr_as_ptr.fixed b/src/tools/clippy/tests/ui/ptr_as_ptr.fixed index 84babb974..ca13b52ae 100644 --- a/src/tools/clippy/tests/ui/ptr_as_ptr.fixed +++ b/src/tools/clippy/tests/ui/ptr_as_ptr.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::ptr_as_ptr)] diff --git a/src/tools/clippy/tests/ui/ptr_as_ptr.rs b/src/tools/clippy/tests/ui/ptr_as_ptr.rs index 34fd76428..942c87344 100644 --- a/src/tools/clippy/tests/ui/ptr_as_ptr.rs +++ b/src/tools/clippy/tests/ui/ptr_as_ptr.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::ptr_as_ptr)] diff --git a/src/tools/clippy/tests/ui/ptr_as_ptr.stderr b/src/tools/clippy/tests/ui/ptr_as_ptr.stderr index e64f33515..c0ce69b43 100644 --- a/src/tools/clippy/tests/ui/ptr_as_ptr.stderr +++ b/src/tools/clippy/tests/ui/ptr_as_ptr.stderr @@ -1,43 +1,44 @@ error: `as` casting between raw pointers without changing its mutability - --> $DIR/ptr_as_ptr.rs:19:33 + --> $DIR/ptr_as_ptr.rs:18:33 | LL | *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::issue_11278_a::T) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `Box::into_raw(Box::new(o)).cast::>()` | = note: `-D clippy::ptr-as-ptr` implied by `-D warnings` + = 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:28:13 + --> $DIR/ptr_as_ptr.rs:27: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:29:13 + --> $DIR/ptr_as_ptr.rs:28: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:34:17 + --> $DIR/ptr_as_ptr.rs:33: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:47:25 + --> $DIR/ptr_as_ptr.rs:46: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:48:23 + --> $DIR/ptr_as_ptr.rs:47: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:51:21 + --> $DIR/ptr_as_ptr.rs:50:21 | LL | let _ = inline!($ptr as *const i32); | ^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `$ptr.cast::()` @@ -45,13 +46,13 @@ 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:72:13 + --> $DIR/ptr_as_ptr.rs:71: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:73:13 + --> $DIR/ptr_as_ptr.rs:72:13 | LL | let _ = mut_ptr as *mut i32; | ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::()` diff --git a/src/tools/clippy/tests/ui/ptr_cast_constness.fixed b/src/tools/clippy/tests/ui/ptr_cast_constness.fixed index 1ef1809d1..c410a660d 100644 --- a/src/tools/clippy/tests/ui/ptr_cast_constness.fixed +++ b/src/tools/clippy/tests/ui/ptr_cast_constness.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::ptr_cast_constness)] #![allow(clippy::transmute_ptr_to_ref, clippy::unnecessary_cast, unused)] diff --git a/src/tools/clippy/tests/ui/ptr_cast_constness.rs b/src/tools/clippy/tests/ui/ptr_cast_constness.rs index 2c15cd429..6025b857b 100644 --- a/src/tools/clippy/tests/ui/ptr_cast_constness.rs +++ b/src/tools/clippy/tests/ui/ptr_cast_constness.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::ptr_cast_constness)] #![allow(clippy::transmute_ptr_to_ref, clippy::unnecessary_cast, unused)] diff --git a/src/tools/clippy/tests/ui/ptr_cast_constness.stderr b/src/tools/clippy/tests/ui/ptr_cast_constness.stderr index 0c3ff8636..a4bf778ad 100644 --- a/src/tools/clippy/tests/ui/ptr_cast_constness.stderr +++ b/src/tools/clippy/tests/ui/ptr_cast_constness.stderr @@ -1,43 +1,44 @@ error: `as` casting between raw pointers while changing only its constness - --> $DIR/ptr_cast_constness.rs:11:41 + --> $DIR/ptr_cast_constness.rs:10:41 | LL | let _: &mut T = std::mem::transmute(p as *mut T); | ^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `p.cast_mut()` | = note: `-D clippy::ptr-cast-constness` implied by `-D warnings` + = 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:12:19 + --> $DIR/ptr_cast_constness.rs:11: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:27:17 + --> $DIR/ptr_cast_constness.rs:26: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:30:13 + --> $DIR/ptr_cast_constness.rs:29: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:31:13 + --> $DIR/ptr_cast_constness.rs:30: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:60:13 + --> $DIR/ptr_cast_constness.rs:59: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:61:13 + --> $DIR/ptr_cast_constness.rs:60:13 | LL | let _ = mut_ptr as *const u32; | ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()` diff --git a/src/tools/clippy/tests/ui/ptr_eq.fixed b/src/tools/clippy/tests/ui/ptr_eq.fixed index d5fa273d4..3ae6df18c 100644 --- a/src/tools/clippy/tests/ui/ptr_eq.fixed +++ b/src/tools/clippy/tests/ui/ptr_eq.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::ptr_eq)] macro_rules! mac { diff --git a/src/tools/clippy/tests/ui/ptr_eq.rs b/src/tools/clippy/tests/ui/ptr_eq.rs index e033366a4..440d5d94a 100644 --- a/src/tools/clippy/tests/ui/ptr_eq.rs +++ b/src/tools/clippy/tests/ui/ptr_eq.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::ptr_eq)] macro_rules! mac { diff --git a/src/tools/clippy/tests/ui/ptr_eq.stderr b/src/tools/clippy/tests/ui/ptr_eq.stderr index 45d8c6038..2a384acca 100644 --- a/src/tools/clippy/tests/ui/ptr_eq.stderr +++ b/src/tools/clippy/tests/ui/ptr_eq.stderr @@ -1,13 +1,14 @@ error: use `std::ptr::eq` when comparing raw pointers - --> $DIR/ptr_eq.rs:20:13 + --> $DIR/ptr_eq.rs:19:13 | LL | let _ = a as *const _ as usize == b as *const _ as usize; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(a, b)` | = note: `-D clippy::ptr-eq` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ptr_eq)]` error: use `std::ptr::eq` when comparing raw pointers - --> $DIR/ptr_eq.rs:21:13 + --> $DIR/ptr_eq.rs:20:13 | LL | let _ = a as *const _ == b as *const _; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(a, b)` diff --git a/src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed b/src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed index 6ffa401d7..929512be6 100644 --- a/src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed +++ b/src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::unnecessary_cast, clippy::useless_vec)] fn main() { diff --git a/src/tools/clippy/tests/ui/ptr_offset_with_cast.rs b/src/tools/clippy/tests/ui/ptr_offset_with_cast.rs index de1f86cb8..146bc2776 100644 --- a/src/tools/clippy/tests/ui/ptr_offset_with_cast.rs +++ b/src/tools/clippy/tests/ui/ptr_offset_with_cast.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::unnecessary_cast, clippy::useless_vec)] fn main() { diff --git a/src/tools/clippy/tests/ui/ptr_offset_with_cast.stderr b/src/tools/clippy/tests/ui/ptr_offset_with_cast.stderr index 3ba40593d..e99053846 100644 --- a/src/tools/clippy/tests/ui/ptr_offset_with_cast.stderr +++ b/src/tools/clippy/tests/ui/ptr_offset_with_cast.stderr @@ -1,13 +1,14 @@ error: use of `offset` with a `usize` casted to an `isize` - --> $DIR/ptr_offset_with_cast.rs:13:17 + --> $DIR/ptr_offset_with_cast.rs:12:17 | LL | let _ = ptr.offset(offset_usize as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.add(offset_usize)` | = note: `-D clippy::ptr-offset-with-cast` implied by `-D warnings` + = 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:17:17 + --> $DIR/ptr_offset_with_cast.rs:16:17 | LL | let _ = ptr.wrapping_offset(offset_usize as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.wrapping_add(offset_usize)` diff --git a/src/tools/clippy/tests/ui/pub_use.rs b/src/tools/clippy/tests/ui/pub_use.rs index 65542bede..aef947e40 100644 --- a/src/tools/clippy/tests/ui/pub_use.rs +++ b/src/tools/clippy/tests/ui/pub_use.rs @@ -8,6 +8,7 @@ pub mod outer { } // should be linted pub use inner::Test; + //~^ ERROR: using `pub use` } // should not be linted diff --git a/src/tools/clippy/tests/ui/pub_use.stderr b/src/tools/clippy/tests/ui/pub_use.stderr index ba4ee732c..781572736 100644 --- a/src/tools/clippy/tests/ui/pub_use.stderr +++ b/src/tools/clippy/tests/ui/pub_use.stderr @@ -6,6 +6,7 @@ LL | pub use inner::Test; | = help: move the exported item to a public module instead = note: `-D clippy::pub-use` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pub_use)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/pub_with_shorthand.fixed b/src/tools/clippy/tests/ui/pub_with_shorthand.fixed index a774faa0a..028209de0 100644 --- a/src/tools/clippy/tests/ui/pub_with_shorthand.fixed +++ b/src/tools/clippy/tests/ui/pub_with_shorthand.fixed @@ -1,5 +1,5 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro + +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(clippy::needless_pub_self, unused)] #![warn(clippy::pub_with_shorthand)] diff --git a/src/tools/clippy/tests/ui/pub_with_shorthand.rs b/src/tools/clippy/tests/ui/pub_with_shorthand.rs index 4a4bbc187..8578e3e0c 100644 --- a/src/tools/clippy/tests/ui/pub_with_shorthand.rs +++ b/src/tools/clippy/tests/ui/pub_with_shorthand.rs @@ -1,5 +1,5 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro + +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(clippy::needless_pub_self, unused)] #![warn(clippy::pub_with_shorthand)] diff --git a/src/tools/clippy/tests/ui/pub_with_shorthand.stderr b/src/tools/clippy/tests/ui/pub_with_shorthand.stderr index 323b5a23b..423b05080 100644 --- a/src/tools/clippy/tests/ui/pub_with_shorthand.stderr +++ b/src/tools/clippy/tests/ui/pub_with_shorthand.stderr @@ -5,6 +5,7 @@ LL | pub(self) fn a() {} | ^^^^^^^^^ help: add it: `pub(in self)` | = note: `-D clippy::pub-with-shorthand` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pub_with_shorthand)]` error: usage of `pub` without `in` --> $DIR/pub_with_shorthand.rs:19:5 diff --git a/src/tools/clippy/tests/ui/pub_without_shorthand.fixed b/src/tools/clippy/tests/ui/pub_without_shorthand.fixed index fdb49ac4d..715e86c17 100644 --- a/src/tools/clippy/tests/ui/pub_without_shorthand.fixed +++ b/src/tools/clippy/tests/ui/pub_without_shorthand.fixed @@ -1,5 +1,5 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro + +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(clippy::needless_pub_self, unused)] #![warn(clippy::pub_without_shorthand)] diff --git a/src/tools/clippy/tests/ui/pub_without_shorthand.rs b/src/tools/clippy/tests/ui/pub_without_shorthand.rs index 1f2ef7ece..ed2fd6f0f 100644 --- a/src/tools/clippy/tests/ui/pub_without_shorthand.rs +++ b/src/tools/clippy/tests/ui/pub_without_shorthand.rs @@ -1,5 +1,5 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro + +//@aux-build:proc_macros.rs #![feature(custom_inner_attributes)] #![allow(clippy::needless_pub_self, unused)] #![warn(clippy::pub_without_shorthand)] diff --git a/src/tools/clippy/tests/ui/pub_without_shorthand.stderr b/src/tools/clippy/tests/ui/pub_without_shorthand.stderr index a18c9bf89..4fb11cb3d 100644 --- a/src/tools/clippy/tests/ui/pub_without_shorthand.stderr +++ b/src/tools/clippy/tests/ui/pub_without_shorthand.stderr @@ -5,6 +5,7 @@ LL | pub(in self) fn b() {} | ^^^^^^^^^^^^ help: remove it: `pub(self)` | = note: `-D clippy::pub-without-shorthand` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::pub_without_shorthand)]` error: usage of `pub` with `in` --> $DIR/pub_without_shorthand.rs:18:5 diff --git a/src/tools/clippy/tests/ui/question_mark.fixed b/src/tools/clippy/tests/ui/question_mark.fixed index 20b9e42a7..2ef006c14 100644 --- a/src/tools/clippy/tests/ui/question_mark.fixed +++ b/src/tools/clippy/tests/ui/question_mark.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(try_blocks)] #![allow(unreachable_code)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/question_mark.rs b/src/tools/clippy/tests/ui/question_mark.rs index 8bdafd46e..c17066982 100644 --- a/src/tools/clippy/tests/ui/question_mark.rs +++ b/src/tools/clippy/tests/ui/question_mark.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![feature(try_blocks)] #![allow(unreachable_code)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/question_mark.stderr b/src/tools/clippy/tests/ui/question_mark.stderr index 62489c8c8..7b7b85d08 100644 --- a/src/tools/clippy/tests/ui/question_mark.stderr +++ b/src/tools/clippy/tests/ui/question_mark.stderr @@ -1,5 +1,5 @@ error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:8:5 + --> $DIR/question_mark.rs:7:5 | LL | / if a.is_none() { LL | | return None; @@ -7,9 +7,10 @@ LL | | } | |_____^ help: replace it with: `a?;` | = note: `-D clippy::question-mark` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::question_mark)]` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:53:9 + --> $DIR/question_mark.rs:52:9 | LL | / if (self.opt).is_none() { LL | | return None; @@ -17,7 +18,7 @@ LL | | } | |_________^ help: replace it with: `(self.opt)?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:57:9 + --> $DIR/question_mark.rs:56:9 | LL | / if self.opt.is_none() { LL | | return None @@ -25,7 +26,7 @@ LL | | } | |_________^ help: replace it with: `self.opt?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:61:17 + --> $DIR/question_mark.rs:60:17 | LL | let _ = if self.opt.is_none() { | _________________^ @@ -36,7 +37,7 @@ LL | | }; | |_________^ help: replace it with: `Some(self.opt?)` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:67:17 + --> $DIR/question_mark.rs:66:17 | LL | let _ = if let Some(x) = self.opt { | _________________^ @@ -47,7 +48,7 @@ LL | | }; | |_________^ help: replace it with: `self.opt?` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:84:9 + --> $DIR/question_mark.rs:83:9 | LL | / if self.opt.is_none() { LL | | return None; @@ -55,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:92:9 + --> $DIR/question_mark.rs:91:9 | LL | / if self.opt.is_none() { LL | | return None; @@ -63,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:100:9 + --> $DIR/question_mark.rs:99:9 | LL | / if self.opt.is_none() { LL | | return None; @@ -71,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:107:26 + --> $DIR/question_mark.rs:106:26 | LL | let v: &Vec<_> = if let Some(ref v) = self.opt { | __________________________^ @@ -82,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:117:17 + --> $DIR/question_mark.rs:116:17 | LL | let v = if let Some(v) = self.opt { | _________________^ @@ -93,7 +94,7 @@ LL | | }; | |_________^ help: replace it with: `self.opt?` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:132:5 + --> $DIR/question_mark.rs:131:5 | LL | / if f().is_none() { LL | | return None; @@ -101,13 +102,13 @@ LL | | } | |_____^ help: replace it with: `f()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:144:13 + --> $DIR/question_mark.rs:143: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:146:5 + --> $DIR/question_mark.rs:145:5 | LL | / if x.is_err() { LL | | return x; @@ -115,7 +116,7 @@ LL | | } | |_____^ help: replace it with: `x?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:214:5 + --> $DIR/question_mark.rs:213:5 | LL | / if let Err(err) = func_returning_result() { LL | | return Err(err); @@ -123,7 +124,7 @@ LL | | } | |_____^ help: replace it with: `func_returning_result()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:221:5 + --> $DIR/question_mark.rs:220:5 | LL | / if let Err(err) = func_returning_result() { LL | | return Err(err); @@ -131,7 +132,7 @@ LL | | } | |_____^ help: replace it with: `func_returning_result()?;` error: this block may be rewritten with the `?` operator - --> $DIR/question_mark.rs:298:13 + --> $DIR/question_mark.rs:297:13 | LL | / if a.is_none() { LL | | return None; diff --git a/src/tools/clippy/tests/ui/question_mark_used.rs b/src/tools/clippy/tests/ui/question_mark_used.rs index 8c3ef7896..715d7fab8 100644 --- a/src/tools/clippy/tests/ui/question_mark_used.rs +++ b/src/tools/clippy/tests/ui/question_mark_used.rs @@ -9,6 +9,7 @@ fn other_function() -> Option { fn my_function() -> Option { other_function()?; + //~^ ERROR: question mark operator was used None } diff --git a/src/tools/clippy/tests/ui/question_mark_used.stderr b/src/tools/clippy/tests/ui/question_mark_used.stderr index 8b5fcbcdb..a3f440de8 100644 --- a/src/tools/clippy/tests/ui/question_mark_used.stderr +++ b/src/tools/clippy/tests/ui/question_mark_used.stderr @@ -6,6 +6,7 @@ LL | other_function()?; | = help: consider using a custom macro or match expression = note: `-D clippy::question-mark-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::question_mark_used)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/range.rs b/src/tools/clippy/tests/ui/range.rs index 46edf0921..9541812b0 100644 --- a/src/tools/clippy/tests/ui/range.rs +++ b/src/tools/clippy/tests/ui/range.rs @@ -4,6 +4,8 @@ fn main() { let v1 = vec![1, 2, 3]; let v2 = vec![4, 5]; let _x = v1.iter().zip(0..v1.len()); + //~^ ERROR: it is more idiomatic to use `v1.iter().enumerate()` + //~| NOTE: `-D clippy::range-zip-with-len` implied by `-D warnings` let _y = v1.iter().zip(0..v2.len()); // No error } diff --git a/src/tools/clippy/tests/ui/range.stderr b/src/tools/clippy/tests/ui/range.stderr index ac83b67fd..9f174307b 100644 --- a/src/tools/clippy/tests/ui/range.stderr +++ b/src/tools/clippy/tests/ui/range.stderr @@ -5,6 +5,7 @@ LL | let _x = v1.iter().zip(0..v1.len()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::range-zip-with-len` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::range_zip_with_len)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/range_contains.fixed b/src/tools/clippy/tests/ui/range_contains.fixed index 47c524811..ed248df37 100644 --- a/src/tools/clippy/tests/ui/range_contains.fixed +++ b/src/tools/clippy/tests/ui/range_contains.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_range_contains)] #![allow(unused)] #![allow(clippy::no_effect)] diff --git a/src/tools/clippy/tests/ui/range_contains.rs b/src/tools/clippy/tests/ui/range_contains.rs index a35315a64..c3188ec6d 100644 --- a/src/tools/clippy/tests/ui/range_contains.rs +++ b/src/tools/clippy/tests/ui/range_contains.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::manual_range_contains)] #![allow(unused)] #![allow(clippy::no_effect)] diff --git a/src/tools/clippy/tests/ui/range_contains.stderr b/src/tools/clippy/tests/ui/range_contains.stderr index 1265db695..349adea21 100644 --- a/src/tools/clippy/tests/ui/range_contains.stderr +++ b/src/tools/clippy/tests/ui/range_contains.stderr @@ -1,127 +1,128 @@ error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:15:5 + --> $DIR/range_contains.rs:13:5 | LL | x >= 8 && x < 12; | ^^^^^^^^^^^^^^^^ help: use: `(8..12).contains(&x)` | = note: `-D clippy::manual-range-contains` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_range_contains)]` error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:16:5 + --> $DIR/range_contains.rs:14:5 | LL | x < 42 && x >= 21; | ^^^^^^^^^^^^^^^^^ help: use: `(21..42).contains(&x)` error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:17:5 + --> $DIR/range_contains.rs:15:5 | LL | 100 > x && 1 <= x; | ^^^^^^^^^^^^^^^^^ help: use: `(1..100).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:20:5 + --> $DIR/range_contains.rs:18:5 | LL | x >= 9 && x <= 99; | ^^^^^^^^^^^^^^^^^ help: use: `(9..=99).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:21:5 + --> $DIR/range_contains.rs:19:5 | LL | x <= 33 && x >= 1; | ^^^^^^^^^^^^^^^^^ help: use: `(1..=33).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:22:5 + --> $DIR/range_contains.rs:20:5 | LL | 999 >= x && 1 <= x; | ^^^^^^^^^^^^^^^^^^ help: use: `(1..=999).contains(&x)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:25:5 + --> $DIR/range_contains.rs:23:5 | LL | x < 8 || x >= 12; | ^^^^^^^^^^^^^^^^ help: use: `!(8..12).contains(&x)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:26:5 + --> $DIR/range_contains.rs:24:5 | LL | x >= 42 || x < 21; | ^^^^^^^^^^^^^^^^^ help: use: `!(21..42).contains(&x)` error: manual `!Range::contains` implementation - --> $DIR/range_contains.rs:27:5 + --> $DIR/range_contains.rs:25:5 | LL | 100 <= x || 1 > x; | ^^^^^^^^^^^^^^^^^ help: use: `!(1..100).contains(&x)` error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:30:5 + --> $DIR/range_contains.rs:28:5 | LL | x < 9 || x > 99; | ^^^^^^^^^^^^^^^ help: use: `!(9..=99).contains(&x)` error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:31:5 + --> $DIR/range_contains.rs:29:5 | LL | x > 33 || x < 1; | ^^^^^^^^^^^^^^^ help: use: `!(1..=33).contains(&x)` error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:32:5 + --> $DIR/range_contains.rs:30:5 | LL | 999 < x || 1 > x; | ^^^^^^^^^^^^^^^^ help: use: `!(1..=999).contains(&x)` error: manual `Range::contains` implementation - --> $DIR/range_contains.rs:47:5 + --> $DIR/range_contains.rs:45:5 | LL | y >= 0. && y < 1.; | ^^^^^^^^^^^^^^^^^ help: use: `(0. ..1.).contains(&y)` error: manual `!RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:48:5 + --> $DIR/range_contains.rs:46:5 | LL | y < 0. || y > 1.; | ^^^^^^^^^^^^^^^^ help: use: `!(0. ..=1.).contains(&y)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:51:5 + --> $DIR/range_contains.rs:49:5 | LL | x >= -10 && x <= 10; | ^^^^^^^^^^^^^^^^^^^ help: use: `(-10..=10).contains(&x)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:53:5 + --> $DIR/range_contains.rs:51:5 | LL | y >= -3. && y <= 3.; | ^^^^^^^^^^^^^^^^^^^ help: use: `(-3. ..=3.).contains(&y)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:58:30 + --> $DIR/range_contains.rs:56:30 | LL | (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10); | ^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=10).contains(&z)` error: manual `RangeInclusive::contains` implementation - --> $DIR/range_contains.rs:58:5 + --> $DIR/range_contains.rs:56: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:59:29 + --> $DIR/range_contains.rs:57: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:59:5 + --> $DIR/range_contains.rs:57: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:78:5 + --> $DIR/range_contains.rs:76:5 | LL | x >= 8 && x < 35; | ^^^^^^^^^^^^^^^^ help: use: `(8..35).contains(&x)` diff --git a/src/tools/clippy/tests/ui/range_plus_minus_one.fixed b/src/tools/clippy/tests/ui/range_plus_minus_one.fixed index 79c133cb5..e701dde86 100644 --- a/src/tools/clippy/tests/ui/range_plus_minus_one.fixed +++ b/src/tools/clippy/tests/ui/range_plus_minus_one.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_parens)] #![allow(clippy::iter_with_drain)] fn f() -> usize { diff --git a/src/tools/clippy/tests/ui/range_plus_minus_one.rs b/src/tools/clippy/tests/ui/range_plus_minus_one.rs index 689a6b7a1..7057fa8e3 100644 --- a/src/tools/clippy/tests/ui/range_plus_minus_one.rs +++ b/src/tools/clippy/tests/ui/range_plus_minus_one.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_parens)] #![allow(clippy::iter_with_drain)] fn f() -> usize { diff --git a/src/tools/clippy/tests/ui/range_plus_minus_one.stderr b/src/tools/clippy/tests/ui/range_plus_minus_one.stderr index 022369624..c5c9b145d 100644 --- a/src/tools/clippy/tests/ui/range_plus_minus_one.stderr +++ b/src/tools/clippy/tests/ui/range_plus_minus_one.stderr @@ -1,57 +1,59 @@ error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:31:14 + --> $DIR/range_plus_minus_one.rs:29:14 | LL | for _ in 0..3 + 1 {} | ^^^^^^^^ help: use: `0..=3` | = note: `-D clippy::range-plus-one` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::range_plus_one)]` error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:34:14 + --> $DIR/range_plus_minus_one.rs:32:14 | LL | for _ in 0..1 + 5 {} | ^^^^^^^^ help: use: `0..=5` error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:37:14 + --> $DIR/range_plus_minus_one.rs:35:14 | LL | for _ in 1..1 + 1 {} | ^^^^^^^^ help: use: `1..=1` error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:43:14 + --> $DIR/range_plus_minus_one.rs:41:14 | LL | for _ in 0..(1 + f()) {} | ^^^^^^^^^^^^ help: use: `0..=f()` error: an exclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:47:13 + --> $DIR/range_plus_minus_one.rs:45:13 | LL | let _ = ..=11 - 1; | ^^^^^^^^^ help: use: `..11` | = note: `-D clippy::range-minus-one` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::range_minus_one)]` error: an exclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:48:13 + --> $DIR/range_plus_minus_one.rs:46:13 | LL | let _ = ..=(11 - 1); | ^^^^^^^^^^^ help: use: `..11` error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:49:13 + --> $DIR/range_plus_minus_one.rs:47:13 | LL | let _ = (1..11 + 1); | ^^^^^^^^^^^ help: use: `(1..=11)` error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:50:13 + --> $DIR/range_plus_minus_one.rs:48:13 | LL | let _ = (f() + 1)..(f() + 1); | ^^^^^^^^^^^^^^^^^^^^ help: use: `((f() + 1)..=f())` error: an inclusive range would be more readable - --> $DIR/range_plus_minus_one.rs:54:14 + --> $DIR/range_plus_minus_one.rs:52:14 | LL | for _ in 1..ONE + ONE {} | ^^^^^^^^^^^^ help: use: `1..=ONE` diff --git a/src/tools/clippy/tests/ui/rc_buffer.fixed b/src/tools/clippy/tests/ui/rc_buffer.fixed index 4cba292c1..35ac95a76 100644 --- a/src/tools/clippy/tests/ui/rc_buffer.fixed +++ b/src/tools/clippy/tests/ui/rc_buffer.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::rc_buffer)] #![allow(dead_code, unused_imports)] diff --git a/src/tools/clippy/tests/ui/rc_buffer.rs b/src/tools/clippy/tests/ui/rc_buffer.rs index d8a9aa278..e78fb5a6d 100644 --- a/src/tools/clippy/tests/ui/rc_buffer.rs +++ b/src/tools/clippy/tests/ui/rc_buffer.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::rc_buffer)] #![allow(dead_code, unused_imports)] diff --git a/src/tools/clippy/tests/ui/rc_buffer.stderr b/src/tools/clippy/tests/ui/rc_buffer.stderr index 9ed028e3d..04080326a 100644 --- a/src/tools/clippy/tests/ui/rc_buffer.stderr +++ b/src/tools/clippy/tests/ui/rc_buffer.stderr @@ -1,49 +1,50 @@ error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:12:11 + --> $DIR/rc_buffer.rs:11:11 | LL | bad1: Rc, | ^^^^^^^^^^ help: try: `Rc` | = note: `-D clippy::rc-buffer` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rc_buffer)]` error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:13:11 + --> $DIR/rc_buffer.rs:12:11 | LL | bad2: Rc, | ^^^^^^^^^^^ help: try: `Rc` error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:14:11 + --> $DIR/rc_buffer.rs:13:11 | LL | bad3: Rc>, | ^^^^^^^^^^^ help: try: `Rc<[u8]>` error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:15:11 + --> $DIR/rc_buffer.rs:14:11 | LL | bad4: Rc, | ^^^^^^^^^^^^ help: try: `Rc` error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:21:17 + --> $DIR/rc_buffer.rs:20:17 | LL | fn func_bad1(_: Rc) {} | ^^^^^^^^^^ help: try: `Rc` error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:22:17 + --> $DIR/rc_buffer.rs:21:17 | LL | fn func_bad2(_: Rc) {} | ^^^^^^^^^^^ help: try: `Rc` error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:23:17 + --> $DIR/rc_buffer.rs:22:17 | LL | fn func_bad3(_: Rc>) {} | ^^^^^^^^^^^ help: try: `Rc<[u8]>` error: usage of `Rc` when T is a buffer type - --> $DIR/rc_buffer.rs:24:17 + --> $DIR/rc_buffer.rs:23:17 | LL | fn func_bad4(_: Rc) {} | ^^^^^^^^^^^^ help: try: `Rc` diff --git a/src/tools/clippy/tests/ui/rc_buffer_arc.fixed b/src/tools/clippy/tests/ui/rc_buffer_arc.fixed index ac51ac9e4..0d01c7c47 100644 --- a/src/tools/clippy/tests/ui/rc_buffer_arc.fixed +++ b/src/tools/clippy/tests/ui/rc_buffer_arc.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::rc_buffer)] #![allow(dead_code, unused_imports)] diff --git a/src/tools/clippy/tests/ui/rc_buffer_arc.rs b/src/tools/clippy/tests/ui/rc_buffer_arc.rs index 21dc27bc5..61ab16dc1 100644 --- a/src/tools/clippy/tests/ui/rc_buffer_arc.rs +++ b/src/tools/clippy/tests/ui/rc_buffer_arc.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::rc_buffer)] #![allow(dead_code, unused_imports)] diff --git a/src/tools/clippy/tests/ui/rc_buffer_arc.stderr b/src/tools/clippy/tests/ui/rc_buffer_arc.stderr index 911feea73..52522dd72 100644 --- a/src/tools/clippy/tests/ui/rc_buffer_arc.stderr +++ b/src/tools/clippy/tests/ui/rc_buffer_arc.stderr @@ -1,49 +1,50 @@ error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:11:11 + --> $DIR/rc_buffer_arc.rs:10:11 | LL | bad1: Arc, | ^^^^^^^^^^^ help: try: `Arc` | = note: `-D clippy::rc-buffer` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rc_buffer)]` error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:12:11 + --> $DIR/rc_buffer_arc.rs:11:11 | LL | bad2: Arc, | ^^^^^^^^^^^^ help: try: `Arc` error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:13:11 + --> $DIR/rc_buffer_arc.rs:12:11 | LL | bad3: Arc>, | ^^^^^^^^^^^^ help: try: `Arc<[u8]>` error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:14:11 + --> $DIR/rc_buffer_arc.rs:13:11 | LL | bad4: Arc, | ^^^^^^^^^^^^^ help: try: `Arc` error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:20:17 + --> $DIR/rc_buffer_arc.rs:19:17 | LL | fn func_bad1(_: Arc) {} | ^^^^^^^^^^^ help: try: `Arc` error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:21:17 + --> $DIR/rc_buffer_arc.rs:20:17 | LL | fn func_bad2(_: Arc) {} | ^^^^^^^^^^^^ help: try: `Arc` error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:22:17 + --> $DIR/rc_buffer_arc.rs:21:17 | LL | fn func_bad3(_: Arc>) {} | ^^^^^^^^^^^^ help: try: `Arc<[u8]>` error: usage of `Arc` when T is a buffer type - --> $DIR/rc_buffer_arc.rs:23:17 + --> $DIR/rc_buffer_arc.rs:22:17 | LL | fn func_bad4(_: Arc) {} | ^^^^^^^^^^^^^ help: try: `Arc` diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.rs b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.rs index 53fcbf3c4..1c9e9aa7e 100644 --- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.rs +++ b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::rc_clone_in_vec_init)] #![allow(clippy::useless_vec)] use std::sync::{Arc, Mutex}; @@ -6,6 +7,8 @@ fn main() {} fn should_warn_simple_case() { let v = vec![Arc::new("x".to_string()); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Arc` instance } fn should_warn_simple_case_with_big_indentation() { @@ -14,12 +17,16 @@ fn should_warn_simple_case_with_big_indentation() { dbg!(k); if true { let v = vec![Arc::new("x".to_string()); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Arc` instance } } } fn should_warn_complex_case() { let v = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Arc` instance std::sync::Arc::new(Mutex::new({ let x = 1; dbg!(x); @@ -29,6 +36,8 @@ fn should_warn_complex_case() { ]; let v1 = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Arc` instance Arc::new(Mutex::new({ let x = 1; dbg!(x); diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.stderr b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.stderr index a8fd28b84..5dc4b5a10 100644 --- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.stderr +++ b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.stderr @@ -1,11 +1,12 @@ error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/arc.rs:8:13 + --> $DIR/arc.rs:9:13 | LL | let v = vec![Arc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: each element will point to the same `Arc` instance = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rc_clone_in_vec_init)]` help: consider initializing each `Arc` element individually | LL ~ let v = { @@ -23,7 +24,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/arc.rs:16:21 + --> $DIR/arc.rs:19:21 | LL | let v = vec![Arc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,13 +47,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/arc.rs:22:13 + --> $DIR/arc.rs:27:13 | LL | let v = vec![ | _____________^ +LL | | +LL | | LL | | std::sync::Arc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; @@ -76,13 +77,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/arc.rs:31:14 + --> $DIR/arc.rs:38:14 | LL | let v1 = vec![ | ______________^ +LL | | +LL | | LL | | Arc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.rs b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.rs index 88ea39bf9..01cc433cb 100644 --- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.rs +++ b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::rc_clone_in_vec_init)] #![allow(clippy::useless_vec)] use std::rc::Rc; @@ -7,6 +8,8 @@ fn main() {} fn should_warn_simple_case() { let v = vec![Rc::new("x".to_string()); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Rc` instance } fn should_warn_simple_case_with_big_indentation() { @@ -15,12 +18,16 @@ fn should_warn_simple_case_with_big_indentation() { dbg!(k); if true { let v = vec![Rc::new("x".to_string()); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Rc` instance } } } fn should_warn_complex_case() { let v = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Rc` instance std::rc::Rc::new(Mutex::new({ let x = 1; dbg!(x); @@ -30,6 +37,8 @@ fn should_warn_complex_case() { ]; let v1 = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Rc` instance Rc::new(Mutex::new({ let x = 1; dbg!(x); diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.stderr b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.stderr index eab464800..e6bc6f68b 100644 --- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.stderr +++ b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.stderr @@ -1,11 +1,12 @@ error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/rc.rs:9:13 + --> $DIR/rc.rs:10:13 | LL | let v = vec![Rc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: each element will point to the same `Rc` instance = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rc_clone_in_vec_init)]` help: consider initializing each `Rc` element individually | LL ~ let v = { @@ -23,7 +24,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/rc.rs:17:21 + --> $DIR/rc.rs:20:21 | LL | let v = vec![Rc::new("x".to_string()); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,13 +47,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/rc.rs:23:13 + --> $DIR/rc.rs:28:13 | LL | let v = vec![ | _____________^ +LL | | +LL | | LL | | std::rc::Rc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; @@ -76,13 +77,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/rc.rs:32:14 + --> $DIR/rc.rs:39:14 | LL | let v1 = vec![ | ______________^ +LL | | +LL | | LL | | Rc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.rs b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.rs index 031421650..fd2895d40 100644 --- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.rs +++ b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::rc_clone_in_vec_init)] #![allow(clippy::useless_vec)] use std::rc::{Rc, Weak as UnSyncWeak}; @@ -7,10 +8,18 @@ fn main() {} fn should_warn_simple_case() { let v = vec![SyncWeak::::new(); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance let v2 = vec![UnSyncWeak::::new(); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance let v = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance } fn should_warn_simple_case_with_big_indentation() { @@ -19,13 +28,19 @@ fn should_warn_simple_case_with_big_indentation() { dbg!(k); if true { let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance let v2 = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance } } } fn should_warn_complex_case() { let v = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance Arc::downgrade(&Arc::new(Mutex::new({ let x = 1; dbg!(x); @@ -35,6 +50,8 @@ fn should_warn_complex_case() { ]; let v1 = vec![ + //~^ ERROR: initializing a reference-counted pointer in `vec![elem; len]` + //~| NOTE: each element will point to the same `Weak` instance Rc::downgrade(&Rc::new(Mutex::new({ let x = 1; dbg!(x); diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.stderr b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.stderr index 1f7a849b1..25d7dae72 100644 --- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.stderr +++ b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.stderr @@ -1,11 +1,12 @@ error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:9:13 + --> $DIR/weak.rs:10:13 | LL | let v = vec![SyncWeak::::new(); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: each element will point to the same `Weak` instance = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rc_clone_in_vec_init)]` help: consider initializing each `Weak` element individually | LL ~ let v = { @@ -23,7 +24,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:10:14 + --> $DIR/weak.rs:13:14 | LL | let v2 = vec![UnSyncWeak::::new(); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +47,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:12:13 + --> $DIR/weak.rs:17:13 | LL | let v = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -69,7 +70,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:13:13 + --> $DIR/weak.rs:20:13 | LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,7 +93,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:21:21 + --> $DIR/weak.rs:30:21 | LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -115,7 +116,7 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:22:22 + --> $DIR/weak.rs:33:22 | LL | let v2 = vec![Rc::downgrade(&Rc::new("x".to_string())); 2]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -138,13 +139,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:28:13 + --> $DIR/weak.rs:41:13 | LL | let v = vec![ | _____________^ +LL | | +LL | | LL | | Arc::downgrade(&Arc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; @@ -168,13 +169,13 @@ LL ~ }; | error: initializing a reference-counted pointer in `vec![elem; len]` - --> $DIR/weak.rs:37:14 + --> $DIR/weak.rs:52:14 | LL | let v1 = vec![ | ______________^ +LL | | +LL | | LL | | Rc::downgrade(&Rc::new(Mutex::new({ -LL | | let x = 1; -LL | | dbg!(x); ... | LL | | 2 LL | | ]; diff --git a/src/tools/clippy/tests/ui/rc_mutex.rs b/src/tools/clippy/tests/ui/rc_mutex.rs index 432972bbc..40adb3ddc 100644 --- a/src/tools/clippy/tests/ui/rc_mutex.rs +++ b/src/tools/clippy/tests/ui/rc_mutex.rs @@ -6,6 +6,7 @@ use std::sync::Mutex; pub struct MyStructWithPrivItem { foo: Rc>, + //~^ ERROR: usage of `Rc>` } pub struct MyStructWithPubItem { @@ -24,8 +25,11 @@ pub enum MyEnum { // All of these test should be trigger the lint because they are not // part of the public api fn test1(foo: Rc>) {} +//~^ ERROR: usage of `Rc>` fn test2(foo: Rc>) {} +//~^ ERROR: usage of `Rc>` fn test3(foo: Rc>>) {} +//~^ ERROR: usage of `Rc>` // All of these test should be allowed because they are part of the // public api and `avoid_breaking_exported_api` is `false` by default. diff --git a/src/tools/clippy/tests/ui/rc_mutex.stderr b/src/tools/clippy/tests/ui/rc_mutex.stderr index cee3bd8b2..50922fb67 100644 --- a/src/tools/clippy/tests/ui/rc_mutex.stderr +++ b/src/tools/clippy/tests/ui/rc_mutex.stderr @@ -6,9 +6,10 @@ LL | foo: Rc>, | = help: consider using `Rc>` or `Arc>` instead = note: `-D clippy::rc-mutex` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rc_mutex)]` error: usage of `Rc>` - --> $DIR/rc_mutex.rs:26:18 + --> $DIR/rc_mutex.rs:27:18 | LL | fn test1(foo: Rc>) {} | ^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | fn test1(foo: Rc>) {} = help: consider using `Rc>` or `Arc>` instead error: usage of `Rc>` - --> $DIR/rc_mutex.rs:27:15 + --> $DIR/rc_mutex.rs:29:15 | LL | fn test2(foo: Rc>) {} | ^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | fn test2(foo: Rc>) {} = help: consider using `Rc>` or `Arc>` instead error: usage of `Rc>` - --> $DIR/rc_mutex.rs:28:15 + --> $DIR/rc_mutex.rs:31:15 | LL | fn test3(foo: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/read_line_without_trim.fixed b/src/tools/clippy/tests/ui/read_line_without_trim.fixed index cb6aab84e..03a99b17d 100644 --- a/src/tools/clippy/tests/ui/read_line_without_trim.fixed +++ b/src/tools/clippy/tests/ui/read_line_without_trim.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::read_line_without_trim)] diff --git a/src/tools/clippy/tests/ui/read_line_without_trim.rs b/src/tools/clippy/tests/ui/read_line_without_trim.rs index bdc409a70..65510aea0 100644 --- a/src/tools/clippy/tests/ui/read_line_without_trim.rs +++ b/src/tools/clippy/tests/ui/read_line_without_trim.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #![warn(clippy::read_line_without_trim)] diff --git a/src/tools/clippy/tests/ui/read_line_without_trim.stderr b/src/tools/clippy/tests/ui/read_line_without_trim.stderr index f3d7b6042..8d46e0f79 100644 --- a/src/tools/clippy/tests/ui/read_line_without_trim.stderr +++ b/src/tools/clippy/tests/ui/read_line_without_trim.stderr @@ -1,5 +1,5 @@ error: calling `.parse()` without trimming the trailing newline character - --> $DIR/read_line_without_trim.rs:14:25 + --> $DIR/read_line_without_trim.rs:12:25 | LL | let _x: i32 = input.parse().unwrap(); | ----- ^^^^^^^ @@ -7,14 +7,15 @@ LL | let _x: i32 = 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:13:5 + --> $DIR/read_line_without_trim.rs:11:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::read-line-without-trim` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::read_line_without_trim)]` error: calling `.parse()` without trimming the trailing newline character - --> $DIR/read_line_without_trim.rs:18:20 + --> $DIR/read_line_without_trim.rs:16:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^ @@ -22,13 +23,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:17:5 + --> $DIR/read_line_without_trim.rs:15: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:22:20 + --> $DIR/read_line_without_trim.rs:20:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^ @@ -36,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:21:5 + --> $DIR/read_line_without_trim.rs:19: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:26:20 + --> $DIR/read_line_without_trim.rs:24:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^ @@ -50,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:25:5 + --> $DIR/read_line_without_trim.rs:23: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:30:20 + --> $DIR/read_line_without_trim.rs:28:20 | LL | let _x = input.parse::().unwrap(); | ----- ^^^^^^^^^^^^^^^ @@ -64,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:29:5 + --> $DIR/read_line_without_trim.rs:27:5 | LL | std::io::stdin().read_line(&mut input).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/read_zero_byte_vec.rs b/src/tools/clippy/tests/ui/read_zero_byte_vec.rs index ff2ad8644..76b9b9818 100644 --- a/src/tools/clippy/tests/ui/read_zero_byte_vec.rs +++ b/src/tools/clippy/tests/ui/read_zero_byte_vec.rs @@ -7,7 +7,7 @@ use std::fs::File; use std::io; use std::io::prelude::*; - +//@no-rustfix extern crate futures; use futures::io::{AsyncRead, AsyncReadExt}; use tokio::io::{AsyncRead as TokioAsyncRead, AsyncReadExt as _, AsyncWrite as TokioAsyncWrite, AsyncWriteExt as _}; @@ -19,29 +19,36 @@ fn test() -> io::Result<()> { // should lint let mut data = Vec::with_capacity(20); f.read_exact(&mut data).unwrap(); + //~^ ERROR: reading zero byte data to `Vec` + //~| NOTE: `-D clippy::read-zero-byte-vec` implied by `-D warnings` // should lint let mut data2 = Vec::with_capacity(cap); f.read_exact(&mut data2)?; + //~^ ERROR: reading zero byte data to `Vec` // should lint let mut data3 = Vec::new(); f.read_exact(&mut data3)?; + //~^ ERROR: reading zero byte data to `Vec` // should lint let mut data4 = vec![]; let _ = f.read(&mut data4)?; + //~^ ERROR: reading zero byte data to `Vec` // should lint let _ = { let mut data5 = Vec::new(); f.read(&mut data5) + //~^ ERROR: reading zero byte data to `Vec` }; // should lint let _ = { let mut data6: Vec = Default::default(); f.read(&mut data6) + //~^ ERROR: reading zero byte data to `Vec` }; // should not lint @@ -72,20 +79,24 @@ async fn test_futures(r: &mut R) { // should lint let mut data = Vec::new(); r.read(&mut data).await.unwrap(); + //~^ ERROR: reading zero byte data to `Vec` // should lint let mut data2 = Vec::new(); r.read_exact(&mut data2).await.unwrap(); + //~^ ERROR: reading zero byte data to `Vec` } async fn test_tokio(r: &mut R) { // should lint let mut data = Vec::new(); r.read(&mut data).await.unwrap(); + //~^ ERROR: reading zero byte data to `Vec` // should lint let mut data2 = Vec::new(); r.read_exact(&mut data2).await.unwrap(); + //~^ ERROR: reading zero byte data to `Vec` } fn main() {} diff --git a/src/tools/clippy/tests/ui/read_zero_byte_vec.stderr b/src/tools/clippy/tests/ui/read_zero_byte_vec.stderr index 4c7f605f4..523ecb294 100644 --- a/src/tools/clippy/tests/ui/read_zero_byte_vec.stderr +++ b/src/tools/clippy/tests/ui/read_zero_byte_vec.stderr @@ -5,57 +5,58 @@ LL | f.read_exact(&mut data).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `data.resize(20, 0); f.read_exact(&mut data).unwrap();` | = note: `-D clippy::read-zero-byte-vec` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::read_zero_byte_vec)]` error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:25:5 + --> $DIR/read_zero_byte_vec.rs:27:5 | LL | f.read_exact(&mut data2)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `data2.resize(cap, 0); f.read_exact(&mut data2)?;` error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:29:5 + --> $DIR/read_zero_byte_vec.rs:32:5 | LL | f.read_exact(&mut data3)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:33:5 + --> $DIR/read_zero_byte_vec.rs:37:5 | LL | let _ = f.read(&mut data4)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:38:9 + --> $DIR/read_zero_byte_vec.rs:43:9 | LL | f.read(&mut data5) | ^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:44:9 + --> $DIR/read_zero_byte_vec.rs:50:9 | LL | f.read(&mut data6) | ^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:74:5 + --> $DIR/read_zero_byte_vec.rs:81:5 | LL | r.read(&mut data).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:78:5 + --> $DIR/read_zero_byte_vec.rs:86:5 | LL | r.read_exact(&mut data2).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:84:5 + --> $DIR/read_zero_byte_vec.rs:93:5 | LL | r.read(&mut data).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: reading zero byte data to `Vec` - --> $DIR/read_zero_byte_vec.rs:88:5 + --> $DIR/read_zero_byte_vec.rs:98:5 | LL | r.read_exact(&mut data2).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/readonly_write_lock.fixed b/src/tools/clippy/tests/ui/readonly_write_lock.fixed new file mode 100644 index 000000000..76f4a43ae --- /dev/null +++ b/src/tools/clippy/tests/ui/readonly_write_lock.fixed @@ -0,0 +1,45 @@ +#![warn(clippy::readonly_write_lock)] + +use std::sync::RwLock; + +fn mutate_i32(x: &mut i32) { + *x += 1; +} + +fn accept_i32(_: i32) {} + +fn main() { + let lock = RwLock::new(42); + let lock2 = RwLock::new(1234); + + { + let writer = lock.read().unwrap(); + //~^ ERROR: this write lock is used only for reading + //~| NOTE: `-D clippy::readonly-write-lock` implied by `-D warnings` + dbg!(&writer); + } + + { + let writer = lock.read().unwrap(); + //~^ ERROR: this write lock is used only for reading + accept_i32(*writer); + } + + { + let mut writer = lock.write().unwrap(); + mutate_i32(&mut writer); + dbg!(&writer); + } + + { + let mut writer = lock.write().unwrap(); + *writer += 1; + } + + { + let mut writer1 = lock.write().unwrap(); + let mut writer2 = lock2.write().unwrap(); + *writer2 += 1; + *writer1 = *writer2; + } +} diff --git a/src/tools/clippy/tests/ui/readonly_write_lock.rs b/src/tools/clippy/tests/ui/readonly_write_lock.rs index 656b45787..3d1d3855f 100644 --- a/src/tools/clippy/tests/ui/readonly_write_lock.rs +++ b/src/tools/clippy/tests/ui/readonly_write_lock.rs @@ -14,11 +14,14 @@ fn main() { { let writer = lock.write().unwrap(); + //~^ ERROR: this write lock is used only for reading + //~| NOTE: `-D clippy::readonly-write-lock` implied by `-D warnings` dbg!(&writer); } { let writer = lock.write().unwrap(); + //~^ ERROR: this write lock is used only for reading accept_i32(*writer); } diff --git a/src/tools/clippy/tests/ui/readonly_write_lock.stderr b/src/tools/clippy/tests/ui/readonly_write_lock.stderr index e3d8fce7b..b4a093ce9 100644 --- a/src/tools/clippy/tests/ui/readonly_write_lock.stderr +++ b/src/tools/clippy/tests/ui/readonly_write_lock.stderr @@ -5,9 +5,10 @@ LL | let writer = lock.write().unwrap(); | ^^^^^^^^^^^^ help: consider using a read lock instead: `lock.read()` | = note: `-D clippy::readonly-write-lock` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::readonly_write_lock)]` error: this write lock is used only for reading - --> $DIR/readonly_write_lock.rs:21:22 + --> $DIR/readonly_write_lock.rs:23:22 | LL | let writer = lock.write().unwrap(); | ^^^^^^^^^^^^ help: consider using a read lock instead: `lock.read()` diff --git a/src/tools/clippy/tests/ui/recursive_format_impl.rs b/src/tools/clippy/tests/ui/recursive_format_impl.rs index b92490b4c..b3eafc6da 100644 --- a/src/tools/clippy/tests/ui/recursive_format_impl.rs +++ b/src/tools/clippy/tests/ui/recursive_format_impl.rs @@ -29,6 +29,8 @@ impl B for A { impl fmt::Display for A { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.to_string()) + //~^ ERROR: using `self.to_string` in `fmt::Display` implementation will cause inf + //~| NOTE: `-D clippy::recursive-format-impl` implied by `-D warnings` } } @@ -73,6 +75,7 @@ struct G; impl std::fmt::Display for G { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } @@ -82,12 +85,14 @@ struct H; impl std::fmt::Display for H { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } impl std::fmt::Debug for H { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}", &self) + //~^ ERROR: using `self` as `Debug` in `impl Debug` will cause infinite recursion } } @@ -97,6 +102,7 @@ struct H2; impl std::fmt::Display for H2 { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", &&&self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } @@ -171,12 +177,14 @@ impl std::ops::Deref for J { impl std::fmt::Display for J { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", &*self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } impl std::fmt::Debug for J { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{:?}", &*self) + //~^ ERROR: using `self` as `Debug` in `impl Debug` will cause infinite recursion } } @@ -193,6 +201,7 @@ impl std::ops::Deref for J2 { impl std::fmt::Display for J2 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", *self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } @@ -209,6 +218,7 @@ impl std::ops::Deref for J3 { impl std::fmt::Display for J3 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", **&&*self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } @@ -225,6 +235,7 @@ impl std::ops::Deref for J4 { impl std::fmt::Display for J4 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", &&**&&*self) + //~^ ERROR: using `self` as `Display` in `impl Display` will cause infinite recurs } } diff --git a/src/tools/clippy/tests/ui/recursive_format_impl.stderr b/src/tools/clippy/tests/ui/recursive_format_impl.stderr index 8a58b9a3b..adb16f44a 100644 --- a/src/tools/clippy/tests/ui/recursive_format_impl.stderr +++ b/src/tools/clippy/tests/ui/recursive_format_impl.stderr @@ -5,9 +5,10 @@ LL | write!(f, "{}", self.to_string()) | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::recursive-format-impl` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::recursive_format_impl)]` error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:75:9 + --> $DIR/recursive_format_impl.rs:77:9 | LL | write!(f, "{}", self) | ^^^^^^^^^^^^^^^^^^^^^ @@ -15,7 +16,7 @@ LL | write!(f, "{}", self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:84:9 + --> $DIR/recursive_format_impl.rs:87:9 | LL | write!(f, "{}", &self) | ^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +24,7 @@ LL | write!(f, "{}", &self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Debug` in `impl Debug` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:90:9 + --> $DIR/recursive_format_impl.rs:94:9 | LL | write!(f, "{:?}", &self) | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +32,7 @@ LL | write!(f, "{:?}", &self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:99:9 + --> $DIR/recursive_format_impl.rs:104:9 | LL | write!(f, "{}", &&&self) | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -39,7 +40,7 @@ LL | write!(f, "{}", &&&self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:173:9 + --> $DIR/recursive_format_impl.rs:179:9 | LL | write!(f, "{}", &*self) | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -47,7 +48,7 @@ LL | write!(f, "{}", &*self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Debug` in `impl Debug` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:179:9 + --> $DIR/recursive_format_impl.rs:186:9 | LL | write!(f, "{:?}", &*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -55,7 +56,7 @@ LL | write!(f, "{:?}", &*self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:195:9 + --> $DIR/recursive_format_impl.rs:203:9 | LL | write!(f, "{}", *self) | ^^^^^^^^^^^^^^^^^^^^^^ @@ -63,7 +64,7 @@ LL | write!(f, "{}", *self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:211:9 + --> $DIR/recursive_format_impl.rs:220:9 | LL | write!(f, "{}", **&&*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -71,7 +72,7 @@ LL | write!(f, "{}", **&&*self) = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) error: using `self` as `Display` in `impl Display` will cause infinite recursion - --> $DIR/recursive_format_impl.rs:227:9 + --> $DIR/recursive_format_impl.rs:237:9 | LL | write!(f, "{}", &&**&&*self) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/redundant_allocation.rs b/src/tools/clippy/tests/ui/redundant_allocation.rs index 9eb58a3e5..e70f8e71f 100644 --- a/src/tools/clippy/tests/ui/redundant_allocation.rs +++ b/src/tools/clippy/tests/ui/redundant_allocation.rs @@ -14,14 +14,24 @@ mod outer_box { use std::sync::Arc; pub fn box_test6(foo: Box>) {} + //~^ ERROR: usage of `Box>` + //~| NOTE: `Rc` is already on the heap, `Box>` makes an extra allocation pub fn box_test7(foo: Box>) {} + //~^ ERROR: usage of `Box>` + //~| NOTE: `Arc` is already on the heap, `Box>` makes an extra allocation pub fn box_test8() -> Box>> { + //~^ ERROR: usage of `Box>>` + //~| NOTE: `Rc>` is already on the heap, `Box>>` makes an e unimplemented!(); } pub fn box_test9(foo: Box>) -> Box>> { + //~^ ERROR: usage of `Box>` + //~| NOTE: `Arc` is already on the heap, `Box>` makes an extra allocation + //~| ERROR: usage of `Box>>` + //~| NOTE: `Arc>` is already on the heap, `Box>>` makes an extra a unimplemented!(); } } @@ -33,14 +43,24 @@ mod outer_rc { use std::sync::Arc; pub fn rc_test5(a: Rc>) {} + //~^ ERROR: usage of `Rc>` + //~| NOTE: `Box` is already on the heap, `Rc>` makes an extra allocati pub fn rc_test7(a: Rc>) {} + //~^ ERROR: usage of `Rc>` + //~| NOTE: `Arc` is already on the heap, `Rc>` makes an extra allocati pub fn rc_test8() -> Rc>> { + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes an unimplemented!(); } pub fn rc_test9(foo: Rc>) -> Rc>> { + //~^ ERROR: usage of `Rc>` + //~| NOTE: `Arc` is already on the heap, `Rc>` makes an extra allocation + //~| ERROR: usage of `Rc>>` + //~| NOTE: `Arc>` is already on the heap, `Rc>>` makes an extra al unimplemented!(); } } @@ -52,14 +72,24 @@ mod outer_arc { use std::sync::Arc; pub fn arc_test5(a: Arc>) {} + //~^ ERROR: usage of `Arc>` + //~| NOTE: `Box` is already on the heap, `Arc>` makes an extra allocat pub fn arc_test6(a: Arc>) {} + //~^ ERROR: usage of `Arc>` + //~| NOTE: `Rc` is already on the heap, `Arc>` makes an extra allocatio pub fn arc_test8() -> Arc>> { + //~^ ERROR: usage of `Arc>>` + //~| NOTE: `Box>` is already on the heap, `Arc>>` makes an unimplemented!(); } pub fn arc_test9(foo: Arc>) -> Arc>> { + //~^ ERROR: usage of `Arc>` + //~| NOTE: `Rc` is already on the heap, `Arc>` makes an extra allocation + //~| ERROR: usage of `Arc>>` + //~| NOTE: `Rc>` is already on the heap, `Arc>>` makes an extra all unimplemented!(); } } @@ -82,6 +112,8 @@ mod box_dyn { pub fn test_rc(_: Rc>) {} pub fn test_arc(_: Arc>) {} pub fn test_rc_box(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes an ex } // https://github.com/rust-lang/rust-clippy/issues/8604 @@ -114,9 +146,22 @@ mod box_fat_ptr { pub fn test_box_custom(_: Box>) {} pub fn test_rc_box_str(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes an extra pub fn test_rc_box_slice(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes a pub fn test_rc_box_path(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes an extr pub fn test_rc_box_custom(_: Rc>>) {} + //~^ ERROR: usage of `Rc>>` + //~| NOTE: `Box>` is already on the heap, `Rc>>` makes +} + +// https://github.com/rust-lang/rust-clippy/issues/11417 +fn type_in_closure() { + let _ = |_: &mut Box>| {}; } fn main() {} diff --git a/src/tools/clippy/tests/ui/redundant_allocation.stderr b/src/tools/clippy/tests/ui/redundant_allocation.stderr index a9a1eed70..d72f6b202 100644 --- a/src/tools/clippy/tests/ui/redundant_allocation.stderr +++ b/src/tools/clippy/tests/ui/redundant_allocation.stderr @@ -7,9 +7,10 @@ LL | pub fn box_test6(foo: Box>) {} = note: `Rc` is already on the heap, `Box>` makes an extra allocation = help: consider using just `Box` or `Rc` = note: `-D clippy::redundant-allocation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_allocation)]` error: usage of `Box>` - --> $DIR/redundant_allocation.rs:18:30 + --> $DIR/redundant_allocation.rs:20:30 | LL | pub fn box_test7(foo: Box>) {} | ^^^^^^^^^^^ @@ -18,7 +19,7 @@ LL | pub fn box_test7(foo: Box>) {} = help: consider using just `Box` or `Arc` error: usage of `Box>>` - --> $DIR/redundant_allocation.rs:20:27 + --> $DIR/redundant_allocation.rs:24:27 | LL | pub fn box_test8() -> Box>> { | ^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +28,7 @@ LL | pub fn box_test8() -> Box>> { = help: consider using just `Box>` or `Rc>` error: usage of `Box>` - --> $DIR/redundant_allocation.rs:24:30 + --> $DIR/redundant_allocation.rs:30:30 | LL | pub fn box_test9(foo: Box>) -> Box>> { | ^^^^^^^^^^^ @@ -36,7 +37,7 @@ LL | pub fn box_test9(foo: Box>) -> Box>> { = help: consider using just `Box` or `Arc` error: usage of `Box>>` - --> $DIR/redundant_allocation.rs:24:46 + --> $DIR/redundant_allocation.rs:30:46 | LL | pub fn box_test9(foo: Box>) -> Box>> { | ^^^^^^^^^^^^^^^^^ @@ -45,7 +46,7 @@ LL | pub fn box_test9(foo: Box>) -> Box>> { = help: consider using just `Box>` or `Arc>` error: usage of `Rc>` - --> $DIR/redundant_allocation.rs:35:24 + --> $DIR/redundant_allocation.rs:45:24 | LL | pub fn rc_test5(a: Rc>) {} | ^^^^^^^^^^^^^ @@ -54,7 +55,7 @@ LL | pub fn rc_test5(a: Rc>) {} = help: consider using just `Rc` or `Box` error: usage of `Rc>` - --> $DIR/redundant_allocation.rs:37:24 + --> $DIR/redundant_allocation.rs:49:24 | LL | pub fn rc_test7(a: Rc>) {} | ^^^^^^^^^^^^^ @@ -63,7 +64,7 @@ LL | pub fn rc_test7(a: Rc>) {} = help: consider using just `Rc` or `Arc` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:39:26 + --> $DIR/redundant_allocation.rs:53:26 | LL | pub fn rc_test8() -> Rc>> { | ^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL | pub fn rc_test8() -> Rc>> { = help: consider using just `Rc>` or `Box>` error: usage of `Rc>` - --> $DIR/redundant_allocation.rs:43:29 + --> $DIR/redundant_allocation.rs:59:29 | LL | pub fn rc_test9(foo: Rc>) -> Rc>> { | ^^^^^^^^^^ @@ -81,7 +82,7 @@ LL | pub fn rc_test9(foo: Rc>) -> Rc>> { = help: consider using just `Rc` or `Arc` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:43:44 + --> $DIR/redundant_allocation.rs:59:44 | LL | pub fn rc_test9(foo: Rc>) -> Rc>> { | ^^^^^^^^^^^^^^^^ @@ -90,7 +91,7 @@ LL | pub fn rc_test9(foo: Rc>) -> Rc>> { = help: consider using just `Rc>` or `Arc>` error: usage of `Arc>` - --> $DIR/redundant_allocation.rs:54:25 + --> $DIR/redundant_allocation.rs:74:25 | LL | pub fn arc_test5(a: Arc>) {} | ^^^^^^^^^^^^^^ @@ -99,7 +100,7 @@ LL | pub fn arc_test5(a: Arc>) {} = help: consider using just `Arc` or `Box` error: usage of `Arc>` - --> $DIR/redundant_allocation.rs:56:25 + --> $DIR/redundant_allocation.rs:78:25 | LL | pub fn arc_test6(a: Arc>) {} | ^^^^^^^^^^^^^ @@ -108,7 +109,7 @@ LL | pub fn arc_test6(a: Arc>) {} = help: consider using just `Arc` or `Rc` error: usage of `Arc>>` - --> $DIR/redundant_allocation.rs:58:27 + --> $DIR/redundant_allocation.rs:82:27 | LL | pub fn arc_test8() -> Arc>> { | ^^^^^^^^^^^^^^^^^^^^^ @@ -117,7 +118,7 @@ LL | pub fn arc_test8() -> Arc>> { = help: consider using just `Arc>` or `Box>` error: usage of `Arc>` - --> $DIR/redundant_allocation.rs:62:30 + --> $DIR/redundant_allocation.rs:88:30 | LL | pub fn arc_test9(foo: Arc>) -> Arc>> { | ^^^^^^^^^^ @@ -126,7 +127,7 @@ LL | pub fn arc_test9(foo: Arc>) -> Arc>> { = help: consider using just `Arc` or `Rc` error: usage of `Arc>>` - --> $DIR/redundant_allocation.rs:62:45 + --> $DIR/redundant_allocation.rs:88:45 | LL | pub fn arc_test9(foo: Arc>) -> Arc>> { | ^^^^^^^^^^^^^^^^ @@ -135,7 +136,7 @@ LL | pub fn arc_test9(foo: Arc>) -> Arc>> { = help: consider using just `Arc>` or `Rc>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:84:27 + --> $DIR/redundant_allocation.rs:114:27 | LL | pub fn test_rc_box(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^ @@ -144,7 +145,7 @@ LL | pub fn test_rc_box(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:116:31 + --> $DIR/redundant_allocation.rs:148:31 | LL | pub fn test_rc_box_str(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^ @@ -153,7 +154,7 @@ LL | pub fn test_rc_box_str(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:117:33 + --> $DIR/redundant_allocation.rs:151:33 | LL | pub fn test_rc_box_slice(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^ @@ -162,7 +163,7 @@ LL | pub fn test_rc_box_slice(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:118:32 + --> $DIR/redundant_allocation.rs:154:32 | LL | pub fn test_rc_box_path(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^ @@ -171,7 +172,7 @@ LL | pub fn test_rc_box_path(_: Rc>>) {} = help: consider using just `Rc>` or `Box>` error: usage of `Rc>>` - --> $DIR/redundant_allocation.rs:119:34 + --> $DIR/redundant_allocation.rs:157:34 | LL | pub fn test_rc_box_custom(_: Rc>>) {} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/redundant_allocation_fixable.fixed b/src/tools/clippy/tests/ui/redundant_allocation_fixable.fixed index b97863daf..61c989c67 100644 --- a/src/tools/clippy/tests/ui/redundant_allocation_fixable.fixed +++ b/src/tools/clippy/tests/ui/redundant_allocation_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::all)] #![allow(clippy::boxed_local, clippy::needless_pass_by_value)] #![allow(clippy::disallowed_names, unused_variables, dead_code)] diff --git a/src/tools/clippy/tests/ui/redundant_allocation_fixable.rs b/src/tools/clippy/tests/ui/redundant_allocation_fixable.rs index bffb6f8c0..3ad1e9a97 100644 --- a/src/tools/clippy/tests/ui/redundant_allocation_fixable.rs +++ b/src/tools/clippy/tests/ui/redundant_allocation_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::all)] #![allow(clippy::boxed_local, clippy::needless_pass_by_value)] #![allow(clippy::disallowed_names, unused_variables, dead_code)] diff --git a/src/tools/clippy/tests/ui/redundant_allocation_fixable.stderr b/src/tools/clippy/tests/ui/redundant_allocation_fixable.stderr index 524ca5bf4..603600f30 100644 --- a/src/tools/clippy/tests/ui/redundant_allocation_fixable.stderr +++ b/src/tools/clippy/tests/ui/redundant_allocation_fixable.stderr @@ -1,14 +1,15 @@ error: usage of `Box<&T>` - --> $DIR/redundant_allocation_fixable.rs:24:30 + --> $DIR/redundant_allocation_fixable.rs:23:30 | LL | pub fn box_test1(foo: Box<&T>) {} | ^^^^^^^ help: try: `&T` | = note: `&T` is already a pointer, `Box<&T>` allocates a pointer on the heap = note: `-D clippy::redundant-allocation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_allocation)]` error: usage of `Box<&MyStruct>` - --> $DIR/redundant_allocation_fixable.rs:26:27 + --> $DIR/redundant_allocation_fixable.rs:25:27 | LL | pub fn box_test2(foo: Box<&MyStruct>) {} | ^^^^^^^^^^^^^^ help: try: `&MyStruct` @@ -16,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:28:27 + --> $DIR/redundant_allocation_fixable.rs:27:27 | LL | pub fn box_test3(foo: Box<&MyEnum>) {} | ^^^^^^^^^^^^ help: try: `&MyEnum` @@ -24,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:32:30 + --> $DIR/redundant_allocation_fixable.rs:31:30 | LL | pub fn box_test5(foo: Box>) {} | ^^^^^^^^^^^ help: try: `Box` @@ -32,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:41:29 + --> $DIR/redundant_allocation_fixable.rs:40:29 | LL | pub fn rc_test1(foo: Rc<&T>) {} | ^^^^^^ help: try: `&T` @@ -40,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:43:26 + --> $DIR/redundant_allocation_fixable.rs:42:26 | LL | pub fn rc_test2(foo: Rc<&MyStruct>) {} | ^^^^^^^^^^^^^ help: try: `&MyStruct` @@ -48,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:45:26 + --> $DIR/redundant_allocation_fixable.rs:44:26 | LL | pub fn rc_test3(foo: Rc<&MyEnum>) {} | ^^^^^^^^^^^ help: try: `&MyEnum` @@ -56,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:49:24 + --> $DIR/redundant_allocation_fixable.rs:48:24 | LL | pub fn rc_test6(a: Rc>) {} | ^^^^^^^^^^^^ help: try: `Rc` @@ -64,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:58:30 + --> $DIR/redundant_allocation_fixable.rs:57:30 | LL | pub fn arc_test1(foo: Arc<&T>) {} | ^^^^^^^ help: try: `&T` @@ -72,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:60:27 + --> $DIR/redundant_allocation_fixable.rs:59:27 | LL | pub fn arc_test2(foo: Arc<&MyStruct>) {} | ^^^^^^^^^^^^^^ help: try: `&MyStruct` @@ -80,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:62:27 + --> $DIR/redundant_allocation_fixable.rs:61:27 | LL | pub fn arc_test3(foo: Arc<&MyEnum>) {} | ^^^^^^^^^^^^ help: try: `&MyEnum` @@ -88,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:66:25 + --> $DIR/redundant_allocation_fixable.rs:65:25 | LL | pub fn arc_test7(a: Arc>) {} | ^^^^^^^^^^^^^^ help: try: `Arc` diff --git a/src/tools/clippy/tests/ui/redundant_as_str.fixed b/src/tools/clippy/tests/ui/redundant_as_str.fixed new file mode 100644 index 000000000..a38523a7c --- /dev/null +++ b/src/tools/clippy/tests/ui/redundant_as_str.fixed @@ -0,0 +1,24 @@ +#![warn(clippy::redundant_as_str)] + +fn main() { + let string = "Hello, world!".to_owned(); + + // These methods are redundant and the `as_str` can be removed + let _redundant = string.as_bytes(); + let _redundant = string.is_empty(); + + // These methods don't use `as_str` when they are redundant + let _no_as_str = string.as_bytes(); + let _no_as_str = string.is_empty(); + + // These methods are not redundant, and are equivelant to + // doing dereferencing the string and applying the method + let _not_redundant = string.as_str().escape_unicode(); + let _not_redundant = string.as_str().trim(); + let _not_redundant = string.as_str().split_whitespace(); + + // These methods don't use `as_str` and are applied on a `str` directly + let borrowed_str = "Hello, world!"; + let _is_str = borrowed_str.as_bytes(); + let _is_str = borrowed_str.is_empty(); +} diff --git a/src/tools/clippy/tests/ui/redundant_as_str.rs b/src/tools/clippy/tests/ui/redundant_as_str.rs new file mode 100644 index 000000000..33adb6099 --- /dev/null +++ b/src/tools/clippy/tests/ui/redundant_as_str.rs @@ -0,0 +1,24 @@ +#![warn(clippy::redundant_as_str)] + +fn main() { + let string = "Hello, world!".to_owned(); + + // These methods are redundant and the `as_str` can be removed + let _redundant = string.as_str().as_bytes(); + let _redundant = string.as_str().is_empty(); + + // These methods don't use `as_str` when they are redundant + let _no_as_str = string.as_bytes(); + let _no_as_str = string.is_empty(); + + // These methods are not redundant, and are equivelant to + // doing dereferencing the string and applying the method + let _not_redundant = string.as_str().escape_unicode(); + let _not_redundant = string.as_str().trim(); + let _not_redundant = string.as_str().split_whitespace(); + + // These methods don't use `as_str` and are applied on a `str` directly + let borrowed_str = "Hello, world!"; + let _is_str = borrowed_str.as_bytes(); + let _is_str = borrowed_str.is_empty(); +} diff --git a/src/tools/clippy/tests/ui/redundant_as_str.stderr b/src/tools/clippy/tests/ui/redundant_as_str.stderr new file mode 100644 index 000000000..0ea42a94a --- /dev/null +++ b/src/tools/clippy/tests/ui/redundant_as_str.stderr @@ -0,0 +1,17 @@ +error: this `as_str` is redundant and can be removed as the method immediately following exists on `String` too + --> $DIR/redundant_as_str.rs:7:29 + | +LL | let _redundant = string.as_str().as_bytes(); + | ^^^^^^^^^^^^^^^^^ help: try: `as_bytes` + | + = note: `-D clippy::redundant-as-str` implied by `-D warnings` + = 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 + | +LL | let _redundant = string.as_str().is_empty(); + | ^^^^^^^^^^^^^^^^^ help: try: `is_empty` + +error: aborting due to 2 previous errors + diff --git a/src/tools/clippy/tests/ui/redundant_async_block.fixed b/src/tools/clippy/tests/ui/redundant_async_block.fixed index 328958491..d492ea1be 100644 --- a/src/tools/clippy/tests/ui/redundant_async_block.fixed +++ b/src/tools/clippy/tests/ui/redundant_async_block.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::manual_async_fn)] #![warn(clippy::redundant_async_block)] diff --git a/src/tools/clippy/tests/ui/redundant_async_block.rs b/src/tools/clippy/tests/ui/redundant_async_block.rs index cd189b315..dd96e1410 100644 --- a/src/tools/clippy/tests/ui/redundant_async_block.rs +++ b/src/tools/clippy/tests/ui/redundant_async_block.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::manual_async_fn)] #![warn(clippy::redundant_async_block)] diff --git a/src/tools/clippy/tests/ui/redundant_async_block.stderr b/src/tools/clippy/tests/ui/redundant_async_block.stderr index f3dcb09b4..adb44d7a6 100644 --- a/src/tools/clippy/tests/ui/redundant_async_block.stderr +++ b/src/tools/clippy/tests/ui/redundant_async_block.stderr @@ -1,55 +1,56 @@ error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:15:13 + --> $DIR/redundant_async_block.rs:13:13 | LL | let x = async { f.await }; | ^^^^^^^^^^^^^^^^^ help: you can reduce it to: `f` | = note: `-D clippy::redundant-async-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_async_block)]` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:22:16 + --> $DIR/redundant_async_block.rs:20:16 | LL | let fut2 = async { fut1.await }; | ^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut1` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:26:16 + --> $DIR/redundant_async_block.rs:24:16 | LL | let fut2 = async move { fut1.await }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `fut1` error: this async expression only awaits a single future - --> $DIR/redundant_async_block.rs:29:15 + --> $DIR/redundant_async_block.rs:27:15 | 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:45:5 + --> $DIR/redundant_async_block.rs:43: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:58:5 + --> $DIR/redundant_async_block.rs:56: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:63:5 + --> $DIR/redundant_async_block.rs:61: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:86:5 + --> $DIR/redundant_async_block.rs:84: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:149:13 + --> $DIR/redundant_async_block.rs:147:13 | LL | async { async { 42 }.await } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `async { 42 }` @@ -60,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:169:13 + --> $DIR/redundant_async_block.rs:167:13 | LL | async { async { $e }.await } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `async { $e }` diff --git a/src/tools/clippy/tests/ui/redundant_at_rest_pattern.fixed b/src/tools/clippy/tests/ui/redundant_at_rest_pattern.fixed index 080cf13b5..a79976373 100644 --- a/src/tools/clippy/tests/ui/redundant_at_rest_pattern.fixed +++ b/src/tools/clippy/tests/ui/redundant_at_rest_pattern.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(irrefutable_let_patterns, unused)] #![warn(clippy::redundant_at_rest_pattern)] diff --git a/src/tools/clippy/tests/ui/redundant_at_rest_pattern.rs b/src/tools/clippy/tests/ui/redundant_at_rest_pattern.rs index a8a802829..f103d1f1a 100644 --- a/src/tools/clippy/tests/ui/redundant_at_rest_pattern.rs +++ b/src/tools/clippy/tests/ui/redundant_at_rest_pattern.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(irrefutable_let_patterns, unused)] #![warn(clippy::redundant_at_rest_pattern)] diff --git a/src/tools/clippy/tests/ui/redundant_at_rest_pattern.stderr b/src/tools/clippy/tests/ui/redundant_at_rest_pattern.stderr index e2a4d9ffd..3a44636fc 100644 --- a/src/tools/clippy/tests/ui/redundant_at_rest_pattern.stderr +++ b/src/tools/clippy/tests/ui/redundant_at_rest_pattern.stderr @@ -1,37 +1,38 @@ error: using a rest pattern to bind an entire slice to a local - --> $DIR/redundant_at_rest_pattern.rs:10:12 + --> $DIR/redundant_at_rest_pattern.rs:9:12 | LL | if let [a @ ..] = [()] {} | ^^^^^^^^ help: this is better represented with just the binding: `a` | = note: `-D clippy::redundant-at-rest-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_at_rest_pattern)]` error: using a rest pattern to bind an entire slice to a local - --> $DIR/redundant_at_rest_pattern.rs:11:12 + --> $DIR/redundant_at_rest_pattern.rs:10:12 | LL | if let [ref a @ ..] = [()] {} | ^^^^^^^^^^^^ help: this is better represented with just the binding: `ref a` error: using a rest pattern to bind an entire slice to a local - --> $DIR/redundant_at_rest_pattern.rs:12:12 + --> $DIR/redundant_at_rest_pattern.rs:11:12 | LL | if let [mut a @ ..] = [()] {} | ^^^^^^^^^^^^ help: this is better represented with just the binding: `mut a` error: using a rest pattern to bind an entire slice to a local - --> $DIR/redundant_at_rest_pattern.rs:13:12 + --> $DIR/redundant_at_rest_pattern.rs:12:12 | LL | if let [ref mut a @ ..] = [()] {} | ^^^^^^^^^^^^^^^^ help: this is better represented with just the binding: `ref mut a` error: using a rest pattern to bind an entire slice to a local - --> $DIR/redundant_at_rest_pattern.rs:15:12 + --> $DIR/redundant_at_rest_pattern.rs:14:12 | LL | if let [a @ ..] = &*v {} | ^^^^^^^^ help: this is better represented with just the binding: `a` error: using a rest pattern to bind an entire slice to a local - --> $DIR/redundant_at_rest_pattern.rs:17:12 + --> $DIR/redundant_at_rest_pattern.rs:16:12 | LL | if let [a @ ..] = s {} | ^^^^^^^^ help: this is better represented with just the binding: `a` diff --git a/src/tools/clippy/tests/ui/redundant_clone.fixed b/src/tools/clippy/tests/ui/redundant_clone.fixed index 5037c08eb..867f5b210 100644 --- a/src/tools/clippy/tests/ui/redundant_clone.fixed +++ b/src/tools/clippy/tests/ui/redundant_clone.fixed @@ -1,4 +1,3 @@ -//@run-rustfix // rustfix-only-machine-applicable #![feature(lint_reasons)] #![warn(clippy::redundant_clone)] diff --git a/src/tools/clippy/tests/ui/redundant_clone.rs b/src/tools/clippy/tests/ui/redundant_clone.rs index 501898bf1..adcbd01e8 100644 --- a/src/tools/clippy/tests/ui/redundant_clone.rs +++ b/src/tools/clippy/tests/ui/redundant_clone.rs @@ -1,4 +1,3 @@ -//@run-rustfix // rustfix-only-machine-applicable #![feature(lint_reasons)] #![warn(clippy::redundant_clone)] diff --git a/src/tools/clippy/tests/ui/redundant_clone.stderr b/src/tools/clippy/tests/ui/redundant_clone.stderr index 8660c0e1f..4115fcf21 100644 --- a/src/tools/clippy/tests/ui/redundant_clone.stderr +++ b/src/tools/clippy/tests/ui/redundant_clone.stderr @@ -1,180 +1,181 @@ error: redundant clone - --> $DIR/redundant_clone.rs:16:42 + --> $DIR/redundant_clone.rs:15:42 | LL | let _s = ["lorem", "ipsum"].join(" ").to_string(); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:16:14 + --> $DIR/redundant_clone.rs:15:14 | LL | let _s = ["lorem", "ipsum"].join(" ").to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::redundant-clone` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: redundant clone - --> $DIR/redundant_clone.rs:19:15 + --> $DIR/redundant_clone.rs:18:15 | LL | let _s = s.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:19:14 + --> $DIR/redundant_clone.rs:18:14 | LL | let _s = s.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:22:15 + --> $DIR/redundant_clone.rs:21:15 | LL | let _s = s.to_string(); | ^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:22:14 + --> $DIR/redundant_clone.rs:21:14 | LL | let _s = s.to_string(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:25:15 + --> $DIR/redundant_clone.rs:24:15 | LL | let _s = s.to_owned(); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:25:14 + --> $DIR/redundant_clone.rs:24:14 | LL | let _s = s.to_owned(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:27:42 + --> $DIR/redundant_clone.rs:26: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:27:14 + --> $DIR/redundant_clone.rs:26:14 | LL | let _s = Path::new("/a/b/").join("c").to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:29:42 + --> $DIR/redundant_clone.rs:28: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:29:14 + --> $DIR/redundant_clone.rs:28:14 | LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:31:29 + --> $DIR/redundant_clone.rs:30:29 | LL | let _s = OsString::new().to_owned(); | ^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:31:14 + --> $DIR/redundant_clone.rs:30:14 | LL | let _s = OsString::new().to_owned(); | ^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:33:29 + --> $DIR/redundant_clone.rs:32:29 | LL | let _s = OsString::new().to_os_string(); | ^^^^^^^^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:33:14 + --> $DIR/redundant_clone.rs:32:14 | LL | let _s = OsString::new().to_os_string(); | ^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:44:19 + --> $DIR/redundant_clone.rs:43:19 | LL | let _t = tup.0.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:44:14 + --> $DIR/redundant_clone.rs:43:14 | LL | let _t = tup.0.clone(); | ^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:76:25 + --> $DIR/redundant_clone.rs:75: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:76:24 + --> $DIR/redundant_clone.rs:75:24 | LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) } | ^ error: redundant clone - --> $DIR/redundant_clone.rs:133:15 + --> $DIR/redundant_clone.rs:132:15 | LL | let _s = s.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:133:14 + --> $DIR/redundant_clone.rs:132:14 | LL | let _s = s.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:134:15 + --> $DIR/redundant_clone.rs:133:15 | LL | let _t = t.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:134:14 + --> $DIR/redundant_clone.rs:133:14 | LL | let _t = t.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:144:19 + --> $DIR/redundant_clone.rs:143:19 | LL | let _f = f.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:144:18 + --> $DIR/redundant_clone.rs:143:18 | LL | let _f = f.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:156:14 + --> $DIR/redundant_clone.rs:155:14 | LL | let y = x.clone().join("matthias"); | ^^^^^^^^ help: remove this | note: cloned value is neither consumed nor mutated - --> $DIR/redundant_clone.rs:156:13 + --> $DIR/redundant_clone.rs:155:13 | LL | let y = x.clone().join("matthias"); | ^^^^^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:210:11 + --> $DIR/redundant_clone.rs:209:11 | LL | foo(&x.clone(), move || { | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:210:10 + --> $DIR/redundant_clone.rs:209:10 | LL | foo(&x.clone(), move || { | ^ diff --git a/src/tools/clippy/tests/ui/redundant_closure_call_early.rs b/src/tools/clippy/tests/ui/redundant_closure_call_early.rs index 5649d8dd1..6f9c9fd52 100644 --- a/src/tools/clippy/tests/ui/redundant_closure_call_early.rs +++ b/src/tools/clippy/tests/ui/redundant_closure_call_early.rs @@ -7,9 +7,12 @@ fn main() { // lint here let mut k = (|m| m + 1)(i); + //~^ ERROR: try not to call a closure in the expression where it is declared + //~| NOTE: `-D clippy::redundant-closure-call` implied by `-D warnings` // lint here k = (|a, b| a * b)(1, 5); + //~^ ERROR: try not to call a closure in the expression where it is declared // don't lint these #[allow(clippy::needless_return)] diff --git a/src/tools/clippy/tests/ui/redundant_closure_call_early.stderr b/src/tools/clippy/tests/ui/redundant_closure_call_early.stderr index 2735e4173..be7a981dc 100644 --- a/src/tools/clippy/tests/ui/redundant_closure_call_early.stderr +++ b/src/tools/clippy/tests/ui/redundant_closure_call_early.stderr @@ -5,9 +5,10 @@ LL | let mut k = (|m| m + 1)(i); | ^^^^^^^^^^^^^^ | = note: `-D clippy::redundant-closure-call` implied by `-D warnings` + = 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_early.rs:12:9 + --> $DIR/redundant_closure_call_early.rs:14:9 | LL | k = (|a, b| a * b)(1, 5); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed index f3669a669..bf268d0b5 100644 --- a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed +++ b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(async_closure)] #![warn(clippy::redundant_closure_call)] #![allow(clippy::redundant_async_block)] diff --git a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs index db8c7f80d..c8a91049d 100644 --- a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs +++ b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(async_closure)] #![warn(clippy::redundant_closure_call)] #![allow(clippy::redundant_async_block)] diff --git a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.stderr b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.stderr index 618f5e071..a7cdb4369 100644 --- a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.stderr +++ b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.stderr @@ -1,13 +1,14 @@ error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:18:13 + --> $DIR/redundant_closure_call_fixable.rs:16:13 | LL | let a = (|| 42)(); | ^^^^^^^^^ help: try doing something like: `42` | = note: `-D clippy::redundant-closure-call` implied by `-D warnings` + = 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:19:13 + --> $DIR/redundant_closure_call_fixable.rs:17:13 | LL | let b = (async || { | _____________^ @@ -27,7 +28,7 @@ LL ~ }; | error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:24:13 + --> $DIR/redundant_closure_call_fixable.rs:22:13 | LL | let c = (|| { | _____________^ @@ -47,13 +48,13 @@ LL ~ }; | error: try not to call a closure in the expression where it is declared - --> $DIR/redundant_closure_call_fixable.rs:29:13 + --> $DIR/redundant_closure_call_fixable.rs:27: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:38:13 + --> $DIR/redundant_closure_call_fixable.rs:36:13 | LL | (|| m!())() | ^^^^^^^^^^^ help: try doing something like: `m!()` @@ -64,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:33:13 + --> $DIR/redundant_closure_call_fixable.rs:31:13 | LL | (|| 0)() | ^^^^^^^^ help: try doing something like: `0` @@ -75,49 +76,49 @@ 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:46:16 + --> $DIR/redundant_closure_call_fixable.rs:44: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:55:10 + --> $DIR/redundant_closure_call_fixable.rs:53: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:58:13 + --> $DIR/redundant_closure_call_fixable.rs:56: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:62:13 + --> $DIR/redundant_closure_call_fixable.rs:60: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:71:13 + --> $DIR/redundant_closure_call_fixable.rs:69: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:73:13 + --> $DIR/redundant_closure_call_fixable.rs:71: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:86:11 + --> $DIR/redundant_closure_call_fixable.rs:84: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:87:9 + --> $DIR/redundant_closure_call_fixable.rs:85:9 | LL | foo((|| || 42)()(), 5); | ^^^^^^^^^^^^^^ help: try doing something like: `42` diff --git a/src/tools/clippy/tests/ui/redundant_closure_call_late.rs b/src/tools/clippy/tests/ui/redundant_closure_call_late.rs index 5612827bd..dc369c3bc 100644 --- a/src/tools/clippy/tests/ui/redundant_closure_call_late.rs +++ b/src/tools/clippy/tests/ui/redundant_closure_call_late.rs @@ -14,12 +14,16 @@ fn main() { // lint here let redun_closure = || 1; i = redun_closure(); + //~^ ERROR: closure called just once immediately after it was declared + //~| NOTE: `-D clippy::redundant-closure-call` implied by `-D warnings` // shadowed closures are supported, lint here let shadowed_closure = || 1; i = shadowed_closure(); + //~^ ERROR: closure called just once immediately after it was declared let shadowed_closure = || 2; i = shadowed_closure(); + //~^ ERROR: closure called just once immediately after it was declared // don't lint here let shadowed_closure = || 2; diff --git a/src/tools/clippy/tests/ui/redundant_closure_call_late.stderr b/src/tools/clippy/tests/ui/redundant_closure_call_late.stderr index 4eca43a2b..a89bfc770 100644 --- a/src/tools/clippy/tests/ui/redundant_closure_call_late.stderr +++ b/src/tools/clippy/tests/ui/redundant_closure_call_late.stderr @@ -5,15 +5,16 @@ LL | i = redun_closure(); | ^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::redundant-closure-call` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_call)]` error: closure called just once immediately after it was declared - --> $DIR/redundant_closure_call_late.rs:20:5 + --> $DIR/redundant_closure_call_late.rs:22:5 | LL | i = shadowed_closure(); | ^^^^^^^^^^^^^^^^^^^^^^ error: closure called just once immediately after it was declared - --> $DIR/redundant_closure_call_late.rs:22:5 + --> $DIR/redundant_closure_call_late.rs:25:5 | LL | i = shadowed_closure(); | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/redundant_else.rs b/src/tools/clippy/tests/ui/redundant_else.rs index 64f566735..8bcf2ce52 100644 --- a/src/tools/clippy/tests/ui/redundant_else.rs +++ b/src/tools/clippy/tests/ui/redundant_else.rs @@ -8,6 +8,7 @@ fn main() { println!("Love your neighbor;"); break; } else { + //~^ ERROR: redundant else block println!("yet don't pull down your hedge."); } // continue @@ -15,6 +16,7 @@ fn main() { println!("He that lies down with Dogs,"); continue; } else { + //~^ ERROR: redundant else block println!("shall rise up with fleas."); } // match block @@ -24,6 +26,7 @@ fn main() { _ => return, } } else { + //~^ ERROR: redundant else block println!("You may delay, but time will not."); } } @@ -33,6 +36,7 @@ fn main() { } else if foo() { return; } else { + //~^ ERROR: redundant else block println!("A fat kitchen makes a lean will."); } // let binding outside of block @@ -40,6 +44,7 @@ fn main() { if foo() { return; } else { + //~^ ERROR: redundant else block 1 } }; @@ -50,6 +55,7 @@ fn main() { } else if foo() { return; } else { + //~^ ERROR: redundant else block 2 } }; @@ -59,6 +65,7 @@ fn main() { if foo() { return; } else { + //~^ ERROR: redundant else block 1 } } else { diff --git a/src/tools/clippy/tests/ui/redundant_else.stderr b/src/tools/clippy/tests/ui/redundant_else.stderr index de9d00a60..af33e05a6 100644 --- a/src/tools/clippy/tests/ui/redundant_else.stderr +++ b/src/tools/clippy/tests/ui/redundant_else.stderr @@ -3,18 +3,21 @@ error: redundant else block | LL | } else { | ________________^ +LL | | LL | | println!("yet don't pull down your hedge."); LL | | } | |_________^ | = help: remove the `else` block and move the contents out = note: `-D clippy::redundant-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_else)]` error: redundant else block - --> $DIR/redundant_else.rs:17:16 + --> $DIR/redundant_else.rs:18:16 | LL | } else { | ________________^ +LL | | LL | | println!("shall rise up with fleas."); LL | | } | |_________^ @@ -22,10 +25,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:26:16 + --> $DIR/redundant_else.rs:28:16 | LL | } else { | ________________^ +LL | | LL | | println!("You may delay, but time will not."); LL | | } | |_________^ @@ -33,10 +37,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:35:12 + --> $DIR/redundant_else.rs:38:12 | LL | } else { | ____________^ +LL | | LL | | println!("A fat kitchen makes a lean will."); LL | | } | |_____^ @@ -44,10 +49,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:42:16 + --> $DIR/redundant_else.rs:46:16 | LL | } else { | ________________^ +LL | | LL | | 1 LL | | } | |_________^ @@ -55,10 +61,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:52:16 + --> $DIR/redundant_else.rs:57:16 | LL | } else { | ________________^ +LL | | LL | | 2 LL | | } | |_________^ @@ -66,10 +73,11 @@ LL | | } = help: remove the `else` block and move the contents out error: redundant else block - --> $DIR/redundant_else.rs:61:16 + --> $DIR/redundant_else.rs:67:16 | LL | } else { | ________________^ +LL | | LL | | 1 LL | | } | |_________^ diff --git a/src/tools/clippy/tests/ui/redundant_field_names.fixed b/src/tools/clippy/tests/ui/redundant_field_names.fixed index d2a65399d..c578e7864 100644 --- a/src/tools/clippy/tests/ui/redundant_field_names.fixed +++ b/src/tools/clippy/tests/ui/redundant_field_names.fixed @@ -1,10 +1,9 @@ -//@run-rustfix - +//@aux-build:proc_macros.rs #![warn(clippy::redundant_field_names)] #![allow(clippy::extra_unused_type_parameters, clippy::no_effect, dead_code, unused_variables)] #[macro_use] -extern crate derive_new; +extern crate proc_macros; use std::ops::{Range, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive}; @@ -20,7 +19,6 @@ struct Person { foo: u8, } -#[derive(new)] pub struct S { v: String, } @@ -59,6 +57,13 @@ fn main() { let _ = Range { start, end }; let _ = RangeInclusive::new(start, end); let _ = RangeToInclusive { end }; + + external! { + let v = String::new(); + let _ = S { + v: v + }; + } } fn issue_3476() { diff --git a/src/tools/clippy/tests/ui/redundant_field_names.rs b/src/tools/clippy/tests/ui/redundant_field_names.rs index 605ffd21e..d8c2286d5 100644 --- a/src/tools/clippy/tests/ui/redundant_field_names.rs +++ b/src/tools/clippy/tests/ui/redundant_field_names.rs @@ -1,10 +1,9 @@ -//@run-rustfix - +//@aux-build:proc_macros.rs #![warn(clippy::redundant_field_names)] #![allow(clippy::extra_unused_type_parameters, clippy::no_effect, dead_code, unused_variables)] #[macro_use] -extern crate derive_new; +extern crate proc_macros; use std::ops::{Range, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive}; @@ -20,7 +19,6 @@ struct Person { foo: u8, } -#[derive(new)] pub struct S { v: String, } @@ -59,6 +57,13 @@ fn main() { let _ = Range { start: start, end: end }; let _ = RangeInclusive::new(start, end); let _ = RangeToInclusive { end: end }; + + external! { + let v = String::new(); + let _ = S { + v: v + }; + } } fn issue_3476() { diff --git a/src/tools/clippy/tests/ui/redundant_field_names.stderr b/src/tools/clippy/tests/ui/redundant_field_names.stderr index 00a72c50c..6eb1cc753 100644 --- a/src/tools/clippy/tests/ui/redundant_field_names.stderr +++ b/src/tools/clippy/tests/ui/redundant_field_names.stderr @@ -1,49 +1,50 @@ error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:35:9 + --> $DIR/redundant_field_names.rs:33:9 | LL | gender: gender, | ^^^^^^^^^^^^^^ help: replace it with: `gender` | = note: `-D clippy::redundant-field-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_field_names)]` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:36:9 + --> $DIR/redundant_field_names.rs:34:9 | LL | age: age, | ^^^^^^^^ help: replace it with: `age` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:57:25 + --> $DIR/redundant_field_names.rs:55:25 | LL | let _ = RangeFrom { start: start }; | ^^^^^^^^^^^^ help: replace it with: `start` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:58:23 + --> $DIR/redundant_field_names.rs:56:23 | LL | let _ = RangeTo { end: end }; | ^^^^^^^^ help: replace it with: `end` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:59:21 + --> $DIR/redundant_field_names.rs:57:21 | LL | let _ = Range { start: start, end: end }; | ^^^^^^^^^^^^ help: replace it with: `start` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:59:35 + --> $DIR/redundant_field_names.rs:57:35 | LL | let _ = Range { start: start, end: end }; | ^^^^^^^^ help: replace it with: `end` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:61:32 + --> $DIR/redundant_field_names.rs:59:32 | LL | let _ = RangeToInclusive { end: end }; | ^^^^^^^^ help: replace it with: `end` error: redundant field names in struct initialization - --> $DIR/redundant_field_names.rs:83:25 + --> $DIR/redundant_field_names.rs:88:25 | LL | let _ = RangeFrom { start: start }; | ^^^^^^^^^^^^ help: replace it with: `start` diff --git a/src/tools/clippy/tests/ui/redundant_guards.fixed b/src/tools/clippy/tests/ui/redundant_guards.fixed index 49d7336ee..f23116a7e 100644 --- a/src/tools/clippy/tests/ui/redundant_guards.fixed +++ b/src/tools/clippy/tests/ui/redundant_guards.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(if_let_guard)] #![allow(clippy::no_effect, unused)] #![warn(clippy::redundant_guards)] @@ -44,6 +43,7 @@ fn main() { }, Some(Some(1)) => .., Some(Some(2)) => .., + Some(Some(2)) => .., // Don't lint, since x is used in the body Some(x) if let Some(1) = x => { x; @@ -57,11 +57,13 @@ fn main() { Some(x) if matches!(y, 1 if true) => .., Some(x) if let 1 = y => .., Some(x) if y == 2 => .., + Some(x) if 2 == y => .., _ => todo!(), }; let a = A(1); match a { _ if a.0 == 1 => {}, + _ if 1 == a.0 => {}, _ => todo!(), } let b = B { e: Some(A(0)) }; @@ -120,6 +122,7 @@ fn h(v: Option) { fn f(s: Option) { match s { Some(x) if x == "a" => {}, + Some(x) if "a" == x => {}, _ => {}, } } @@ -141,6 +144,52 @@ static CONST_S: S = S { a: 1 }; fn g(opt_s: Option) { match opt_s { Some(x) if x == CONST_S => {}, + Some(x) if CONST_S == x => {}, _ => {}, } } + +mod issue11465 { + enum A { + Foo([u8; 3]), + } + + struct B { + b: String, + c: i32, + } + + fn issue11465() { + let c = Some(1); + match c { + Some(1) => {}, + Some(1) => {}, + Some(2) => {}, + Some(3) => {}, + _ => {}, + }; + + let enum_a = A::Foo([98, 97, 114]); + match enum_a { + A::Foo(ref arr) if arr == b"foo" => {}, + A::Foo(ref arr) if b"foo" == arr => {}, + A::Foo(ref arr) if let b"bar" = arr => {}, + A::Foo(ref arr) if matches!(arr, b"baz") => {}, + _ => {}, + }; + + let struct_b = B { + b: "bar".to_string(), + c: 42, + }; + match struct_b { + B { ref b, .. } if b == "bar" => {}, + B { ref b, .. } if "bar" == b => {}, + B { c: 1, .. } => {}, + B { c: 1, .. } => {}, + B { c: 1, .. } => {}, + B { c: 1, .. } => {}, + _ => {}, + } + } +} diff --git a/src/tools/clippy/tests/ui/redundant_guards.rs b/src/tools/clippy/tests/ui/redundant_guards.rs index 87761010d..c0206b4ce 100644 --- a/src/tools/clippy/tests/ui/redundant_guards.rs +++ b/src/tools/clippy/tests/ui/redundant_guards.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(if_let_guard)] #![allow(clippy::no_effect, unused)] #![warn(clippy::redundant_guards)] @@ -44,6 +43,7 @@ fn main() { }, Some(x) if let Some(1) = x => .., Some(x) if x == Some(2) => .., + Some(x) if Some(2) == x => .., // Don't lint, since x is used in the body Some(x) if let Some(1) = x => { x; @@ -57,11 +57,13 @@ fn main() { Some(x) if matches!(y, 1 if true) => .., Some(x) if let 1 = y => .., Some(x) if y == 2 => .., + Some(x) if 2 == y => .., _ => todo!(), }; let a = A(1); match a { _ if a.0 == 1 => {}, + _ if 1 == a.0 => {}, _ => todo!(), } let b = B { e: Some(A(0)) }; @@ -120,6 +122,7 @@ fn h(v: Option) { fn f(s: Option) { match s { Some(x) if x == "a" => {}, + Some(x) if "a" == x => {}, _ => {}, } } @@ -141,6 +144,52 @@ static CONST_S: S = S { a: 1 }; fn g(opt_s: Option) { match opt_s { Some(x) if x == CONST_S => {}, + Some(x) if CONST_S == x => {}, _ => {}, } } + +mod issue11465 { + enum A { + Foo([u8; 3]), + } + + struct B { + b: String, + c: i32, + } + + 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 matches!(x, &3) => {}, + _ => {}, + }; + + let enum_a = A::Foo([98, 97, 114]); + match enum_a { + A::Foo(ref arr) if arr == b"foo" => {}, + A::Foo(ref arr) if b"foo" == arr => {}, + A::Foo(ref arr) if let b"bar" = arr => {}, + A::Foo(ref arr) if matches!(arr, b"baz") => {}, + _ => {}, + }; + + let struct_b = B { + b: "bar".to_string(), + c: 42, + }; + 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 let &1 = c => {}, + B { ref c, .. } if matches!(c, &1) => {}, + _ => {}, + } + } +} diff --git a/src/tools/clippy/tests/ui/redundant_guards.stderr b/src/tools/clippy/tests/ui/redundant_guards.stderr index 5bdf43d23..b8d7834e3 100644 --- a/src/tools/clippy/tests/ui/redundant_guards.stderr +++ b/src/tools/clippy/tests/ui/redundant_guards.stderr @@ -1,10 +1,11 @@ error: redundant guard - --> $DIR/redundant_guards.rs:34:20 + --> $DIR/redundant_guards.rs:33:20 | LL | C(x, y) if let 1 = y => .., | ^^^^^^^^^ | = note: `-D clippy::redundant-guards` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_guards)]` help: try | LL - C(x, y) if let 1 = y => .., @@ -12,7 +13,7 @@ LL + C(x, 1) => .., | error: redundant guard - --> $DIR/redundant_guards.rs:40:20 + --> $DIR/redundant_guards.rs:39:20 | LL | Some(x) if matches!(x, Some(1) if true) => .., | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +24,7 @@ LL | Some(Some(1)) if true => .., | ~~~~~~~ ~~~~~~~ error: redundant guard - --> $DIR/redundant_guards.rs:41:20 + --> $DIR/redundant_guards.rs:40:20 | LL | Some(x) if matches!(x, Some(1)) => { | ^^^^^^^^^^^^^^^^^^^^ @@ -35,7 +36,7 @@ LL + Some(Some(1)) => { | error: redundant guard - --> $DIR/redundant_guards.rs:45:20 + --> $DIR/redundant_guards.rs:44:20 | LL | Some(x) if let Some(1) = x => .., | ^^^^^^^^^^^^^^^ @@ -47,7 +48,7 @@ LL + Some(Some(1)) => .., | error: redundant guard - --> $DIR/redundant_guards.rs:46:20 + --> $DIR/redundant_guards.rs:45:20 | LL | Some(x) if x == Some(2) => .., | ^^^^^^^^^^^^ @@ -59,7 +60,19 @@ LL + Some(Some(2)) => .., | error: redundant guard - --> $DIR/redundant_guards.rs:69:20 + --> $DIR/redundant_guards.rs:46:20 + | +LL | Some(x) if Some(2) == x => .., + | ^^^^^^^^^^^^ + | +help: try + | +LL - Some(x) if Some(2) == x => .., +LL + Some(Some(2)) => .., + | + +error: redundant guard + --> $DIR/redundant_guards.rs:71:20 | LL | B { e } if matches!(e, Some(A(2))) => .., | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -71,7 +84,7 @@ LL + B { e: Some(A(2)) } => .., | error: redundant guard - --> $DIR/redundant_guards.rs:106:20 + --> $DIR/redundant_guards.rs:108:20 | LL | E::A(y) if y == "not from an or pattern" => {}, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -83,7 +96,7 @@ LL + E::A("not from an or pattern") => {}, | error: redundant guard - --> $DIR/redundant_guards.rs:113:14 + --> $DIR/redundant_guards.rs:115:14 | LL | x if matches!(x, Some(0)) => .., | ^^^^^^^^^^^^^^^^^^^^ @@ -94,5 +107,101 @@ LL - x if matches!(x, Some(0)) => .., LL + Some(0) => .., | -error: aborting due to 8 previous errors +error: redundant guard + --> $DIR/redundant_guards.rs:165:28 + | +LL | Some(ref x) if x == &1 => {}, + | ^^^^^^^ + | +help: try + | +LL - Some(ref x) if x == &1 => {}, +LL + Some(1) => {}, + | + +error: redundant guard + --> $DIR/redundant_guards.rs:166:28 + | +LL | Some(ref x) if &1 == x => {}, + | ^^^^^^^ + | +help: try + | +LL - Some(ref x) if &1 == x => {}, +LL + Some(1) => {}, + | + +error: redundant guard + --> $DIR/redundant_guards.rs:167:28 + | +LL | Some(ref x) if let &2 = x => {}, + | ^^^^^^^^^^ + | +help: try + | +LL - Some(ref x) if let &2 = x => {}, +LL + Some(2) => {}, + | + +error: redundant guard + --> $DIR/redundant_guards.rs:168:28 + | +LL | Some(ref x) if matches!(x, &3) => {}, + | ^^^^^^^^^^^^^^^ + | +help: try + | +LL - Some(ref x) if matches!(x, &3) => {}, +LL + Some(3) => {}, + | + +error: redundant guard + --> $DIR/redundant_guards.rs:188:32 + | +LL | B { ref c, .. } if c == &1 => {}, + | ^^^^^^^ + | +help: try + | +LL - B { ref c, .. } if c == &1 => {}, +LL + B { c: 1, .. } => {}, + | + +error: redundant guard + --> $DIR/redundant_guards.rs:189:32 + | +LL | B { ref c, .. } if &1 == c => {}, + | ^^^^^^^ + | +help: try + | +LL - B { ref c, .. } if &1 == c => {}, +LL + B { c: 1, .. } => {}, + | + +error: redundant guard + --> $DIR/redundant_guards.rs:190:32 + | +LL | B { ref c, .. } if let &1 = c => {}, + | ^^^^^^^^^^ + | +help: try + | +LL - B { ref c, .. } if let &1 = c => {}, +LL + B { c: 1, .. } => {}, + | + +error: redundant guard + --> $DIR/redundant_guards.rs:191:32 + | +LL | B { ref c, .. } if matches!(c, &1) => {}, + | ^^^^^^^^^^^^^^^ + | +help: try + | +LL - B { ref c, .. } if matches!(c, &1) => {}, +LL + B { c: 1, .. } => {}, + | + +error: aborting due to 17 previous errors diff --git a/src/tools/clippy/tests/ui/redundant_locals.rs b/src/tools/clippy/tests/ui/redundant_locals.rs index 80af38f47..c5d93e436 100644 --- a/src/tools/clippy/tests/ui/redundant_locals.rs +++ b/src/tools/clippy/tests/ui/redundant_locals.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(unused, clippy::no_effect, clippy::needless_pass_by_ref_mut)] #![warn(clippy::redundant_locals)] diff --git a/src/tools/clippy/tests/ui/redundant_locals.stderr b/src/tools/clippy/tests/ui/redundant_locals.stderr index 587de0575..13b872e95 100644 --- a/src/tools/clippy/tests/ui/redundant_locals.stderr +++ b/src/tools/clippy/tests/ui/redundant_locals.stderr @@ -8,6 +8,7 @@ LL | let x = x; | = help: remove the redefinition of `x` = note: `-D clippy::redundant-locals` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_locals)]` error: redundant redefinition of a binding --> $DIR/redundant_locals.rs:16:9 diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.fixed index d1134de5a..148eaa4b3 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.fixed +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - // Issue #5746 #![warn(clippy::redundant_pattern_matching)] #![allow( diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.rs index d144086e7..5bc06f3cc 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.rs +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.rs @@ -1,5 +1,3 @@ -//@run-rustfix - // Issue #5746 #![warn(clippy::redundant_pattern_matching)] #![allow( diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.stderr b/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.stderr index 28f33f0c9..28f0244b9 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.stderr +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.stderr @@ -1,5 +1,5 @@ error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_drop_order.rs:17:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:15:12 | LL | if let Ok(_) = m.lock() {} | -------^^^^^----------- help: try: `if m.lock().is_ok()` @@ -7,9 +7,10 @@ LL | if let Ok(_) = m.lock() {} = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_drop_order.rs:18:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:16:12 | LL | if let Err(_) = Err::<(), _>(m.lock().unwrap().0) {} | -------^^^^^^------------------------------------ help: try: `if Err::<(), _>(m.lock().unwrap().0).is_err()` @@ -18,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:21:16 + --> $DIR/redundant_pattern_matching_drop_order.rs:19:16 | LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {} | -------^^^^^----------------------------------------- help: try: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()` @@ -27,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:23:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:21:12 | LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) { | -------^^^^^----------------------------------------- help: try: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()` @@ -36,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:26: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()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_drop_order.rs:27:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:25: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:29:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:27: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:30:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:28: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:33:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:31:12 | LL | if let Some(_) = Some(m.lock()) {} | -------^^^^^^^----------------- help: try: `if Some(m.lock()).is_some()` @@ -69,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:34:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:32:12 | LL | if let Some(_) = Some(m.lock().unwrap().0) {} | -------^^^^^^^---------------------------- help: try: `if Some(m.lock().unwrap().0).is_some()` @@ -78,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:37:16 + --> $DIR/redundant_pattern_matching_drop_order.rs:35:16 | LL | if let None = None::> {} | -------^^^^------------------------------------ help: try: `if None::>.is_none()` @@ -87,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:39:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:37:12 | LL | if let None = None::> { | -------^^^^------------------------------------ help: try: `if None::>.is_none()` @@ -96,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:43:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:41: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:45:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:43: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:46:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:44: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:49:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:47:12 | LL | if let Ready(_) = Ready(m.lock()) {} | -------^^^^^^^^------------------ help: try: `if Ready(m.lock()).is_ready()` @@ -123,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:50:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:48:12 | LL | if let Ready(_) = Ready(m.lock().unwrap().0) {} | -------^^^^^^^^----------------------------- help: try: `if Ready(m.lock().unwrap().0).is_ready()` @@ -132,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:53:16 + --> $DIR/redundant_pattern_matching_drop_order.rs:51:16 | LL | if let Pending = Pending::> {} | -------^^^^^^^--------------------------------------- help: try: `if Pending::>.is_pending()` @@ -141,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:55:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:53:12 | LL | if let Pending = Pending::> { | -------^^^^^^^--------------------------------------- help: try: `if Pending::>.is_pending()` @@ -150,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:59:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:57: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:61:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:59: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:62:12 + --> $DIR/redundant_pattern_matching_drop_order.rs:60:12 | LL | if let Ready(_) = Ready((String::new(), ())) {} | -------^^^^^^^^----------------------------- help: try: `if Ready((String::new(), ())).is_ready()` diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed index 02f197aa2..70dd9fc25 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::all, clippy::redundant_pattern_matching)] #![allow(unused_must_use)] #![allow( diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs index 5c1e1810f..6e2a2f7b6 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::all, clippy::redundant_pattern_matching)] #![allow(unused_must_use)] #![allow( diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr index bec8d3088..d36129a2b 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr @@ -1,37 +1,38 @@ error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:16:12 + --> $DIR/redundant_pattern_matching_ipaddr.rs:15:12 | LL | if let V4(_) = &ipaddr {} | -------^^^^^---------- help: try: `if ipaddr.is_ipv4()` | = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:18:12 + --> $DIR/redundant_pattern_matching_ipaddr.rs:17: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:20:12 + --> $DIR/redundant_pattern_matching_ipaddr.rs:19: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:15 + --> $DIR/redundant_pattern_matching_ipaddr.rs:21: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:24:15 + --> $DIR/redundant_pattern_matching_ipaddr.rs:23: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:34:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:33:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { LL | | V4(_) => true, @@ -40,7 +41,7 @@ LL | | }; | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:39:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:38:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { LL | | V4(_) => false, @@ -49,7 +50,7 @@ LL | | }; | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:44:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:43:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { LL | | V4(_) => false, @@ -58,7 +59,7 @@ LL | | }; | |_____^ help: try: `V6(Ipv6Addr::LOCALHOST).is_ipv6()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:49:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:48:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { LL | | V4(_) => true, @@ -67,49 +68,49 @@ LL | | }; | |_____^ help: try: `V6(Ipv6Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv4()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:54:20 + --> $DIR/redundant_pattern_matching_ipaddr.rs:53: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:62:20 + --> $DIR/redundant_pattern_matching_ipaddr.rs:61: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:64:19 + --> $DIR/redundant_pattern_matching_ipaddr.rs:63: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:76:12 + --> $DIR/redundant_pattern_matching_ipaddr.rs:75: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:78:12 + --> $DIR/redundant_pattern_matching_ipaddr.rs:77: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:80:15 + --> $DIR/redundant_pattern_matching_ipaddr.rs:79: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:82:15 + --> $DIR/redundant_pattern_matching_ipaddr.rs:81: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:84:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:83:5 | LL | / match V4(Ipv4Addr::LOCALHOST) { LL | | V4(_) => true, @@ -118,7 +119,7 @@ LL | | }; | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv4()` error: redundant pattern matching, consider using `is_ipv6()` - --> $DIR/redundant_pattern_matching_ipaddr.rs:89:5 + --> $DIR/redundant_pattern_matching_ipaddr.rs:88:5 | LL | / match V6(Ipv6Addr::LOCALHOST) { LL | | V4(_) => false, diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed index d9fcd98c5..60f9fb6d4 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow( diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.rs index cbd9494f1..94bbb569c 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.rs +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow( diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.stderr b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.stderr index b0e43924d..fdf395d82 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.stderr +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.stderr @@ -1,61 +1,62 @@ error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:16:5 + --> $DIR/redundant_pattern_matching_option.rs:14:5 | LL | matches!(maybe_some, None if !boolean) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `maybe_some.is_none() && (!boolean)` | = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = 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:20:13 + --> $DIR/redundant_pattern_matching_option.rs:18: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:29:12 + --> $DIR/redundant_pattern_matching_option.rs:27: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:31:12 + --> $DIR/redundant_pattern_matching_option.rs:29: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:33:12 + --> $DIR/redundant_pattern_matching_option.rs:31: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:39:15 + --> $DIR/redundant_pattern_matching_option.rs:37: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:41:15 + --> $DIR/redundant_pattern_matching_option.rs:39: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:43:15 + --> $DIR/redundant_pattern_matching_option.rs:41: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:46:15 + --> $DIR/redundant_pattern_matching_option.rs:44: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:54:5 + --> $DIR/redundant_pattern_matching_option.rs:52:5 | LL | / match Some(42) { LL | | Some(_) => true, @@ -64,7 +65,7 @@ LL | | }; | |_____^ help: try: `Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:59:5 + --> $DIR/redundant_pattern_matching_option.rs:57:5 | LL | / match None::<()> { LL | | Some(_) => false, @@ -73,7 +74,7 @@ LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:64:13 + --> $DIR/redundant_pattern_matching_option.rs:62:13 | LL | let _ = match None::<()> { | _____________^ @@ -83,55 +84,55 @@ LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:70:20 + --> $DIR/redundant_pattern_matching_option.rs:68: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:76:20 + --> $DIR/redundant_pattern_matching_option.rs:74: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:78:19 + --> $DIR/redundant_pattern_matching_option.rs:76: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:84:12 + --> $DIR/redundant_pattern_matching_option.rs:82: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:99:12 + --> $DIR/redundant_pattern_matching_option.rs:97: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:101:12 + --> $DIR/redundant_pattern_matching_option.rs:99: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:103:15 + --> $DIR/redundant_pattern_matching_option.rs:101: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:105:15 + --> $DIR/redundant_pattern_matching_option.rs:103: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:107:5 + --> $DIR/redundant_pattern_matching_option.rs:105:5 | LL | / match Some(42) { LL | | Some(_) => true, @@ -140,7 +141,7 @@ LL | | }; | |_____^ help: try: `Some(42).is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:112:5 + --> $DIR/redundant_pattern_matching_option.rs:110:5 | LL | / match None::<()> { LL | | Some(_) => false, @@ -149,19 +150,19 @@ LL | | }; | |_____^ help: try: `None::<()>.is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:120:12 + --> $DIR/redundant_pattern_matching_option.rs:118: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:121:12 + --> $DIR/redundant_pattern_matching_option.rs:119: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:127:5 + --> $DIR/redundant_pattern_matching_option.rs:125:5 | LL | / match x { LL | | Some(_) => true, @@ -170,7 +171,7 @@ LL | | }; | |_____^ help: try: `x.is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:132:5 + --> $DIR/redundant_pattern_matching_option.rs:130:5 | LL | / match x { LL | | None => true, @@ -179,7 +180,7 @@ LL | | }; | |_____^ help: try: `x.is_none()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:137:5 + --> $DIR/redundant_pattern_matching_option.rs:135:5 | LL | / match x { LL | | Some(_) => false, @@ -188,7 +189,7 @@ LL | | }; | |_____^ help: try: `x.is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:142:5 + --> $DIR/redundant_pattern_matching_option.rs:140:5 | LL | / match x { LL | | None => false, @@ -197,13 +198,13 @@ LL | | }; | |_____^ help: try: `x.is_some()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:157:13 + --> $DIR/redundant_pattern_matching_option.rs:155: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:159:13 + --> $DIR/redundant_pattern_matching_option.rs:157:13 | LL | let _ = matches!(x, None); | ^^^^^^^^^^^^^^^^^ help: try: `x.is_none()` diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.fixed index f739deaf5..718c2f8ea 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.fixed +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow( diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.rs index 88dde02b3..daa4761af 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.rs +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow( diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.stderr b/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.stderr index 28d3606c4..c010c3c44 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.stderr +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.stderr @@ -1,43 +1,44 @@ error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:17:12 + --> $DIR/redundant_pattern_matching_poll.rs:15:12 | LL | if let Pending = Pending::<()> {} | -------^^^^^^^---------------- help: try: `if Pending::<()>.is_pending()` | = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:19:12 + --> $DIR/redundant_pattern_matching_poll.rs:17: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:21:12 + --> $DIR/redundant_pattern_matching_poll.rs:19: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:27:15 + --> $DIR/redundant_pattern_matching_poll.rs:25: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:29:15 + --> $DIR/redundant_pattern_matching_poll.rs:27: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:31:15 + --> $DIR/redundant_pattern_matching_poll.rs:29: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:37:5 + --> $DIR/redundant_pattern_matching_poll.rs:35:5 | LL | / match Ready(42) { LL | | Ready(_) => true, @@ -46,7 +47,7 @@ LL | | }; | |_____^ help: try: `Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:42:5 + --> $DIR/redundant_pattern_matching_poll.rs:40:5 | LL | / match Pending::<()> { LL | | Ready(_) => false, @@ -55,7 +56,7 @@ LL | | }; | |_____^ help: try: `Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:47:13 + --> $DIR/redundant_pattern_matching_poll.rs:45:13 | LL | let _ = match Pending::<()> { | _____________^ @@ -65,49 +66,49 @@ LL | | }; | |_____^ help: try: `Pending::<()>.is_pending()` error: redundant pattern matching, consider using `is_ready()` - --> $DIR/redundant_pattern_matching_poll.rs:53:20 + --> $DIR/redundant_pattern_matching_poll.rs:51: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:57:20 + --> $DIR/redundant_pattern_matching_poll.rs:55: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:59:19 + --> $DIR/redundant_pattern_matching_poll.rs:57: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:75:12 + --> $DIR/redundant_pattern_matching_poll.rs:73: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:77:12 + --> $DIR/redundant_pattern_matching_poll.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_poll.rs:79:15 + --> $DIR/redundant_pattern_matching_poll.rs:77: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:81:15 + --> $DIR/redundant_pattern_matching_poll.rs:79: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:83:5 + --> $DIR/redundant_pattern_matching_poll.rs:81:5 | LL | / match Ready(42) { LL | | Ready(_) => true, @@ -116,7 +117,7 @@ LL | | }; | |_____^ help: try: `Ready(42).is_ready()` error: redundant pattern matching, consider using `is_pending()` - --> $DIR/redundant_pattern_matching_poll.rs:88:5 + --> $DIR/redundant_pattern_matching_poll.rs:86:5 | LL | / match Pending::<()> { LL | | Ready(_) => false, diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed index 343e0d043..9571aaee7 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow(deprecated, unused_must_use)] diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs index 4d64eafe5..4fc65aa70 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::all)] #![warn(clippy::redundant_pattern_matching)] #![allow(deprecated, unused_must_use)] diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr index 2b1ce9f54..19e7f8229 100644 --- a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr +++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr @@ -1,37 +1,38 @@ error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:16:12 + --> $DIR/redundant_pattern_matching_result.rs:15:12 | LL | if let Ok(_) = &result {} | -------^^^^^---------- help: try: `if result.is_ok()` | = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:18:12 + --> $DIR/redundant_pattern_matching_result.rs:17: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:20:12 + --> $DIR/redundant_pattern_matching_result.rs:19: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:22:15 + --> $DIR/redundant_pattern_matching_result.rs:21: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:24:15 + --> $DIR/redundant_pattern_matching_result.rs:23: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:34:5 + --> $DIR/redundant_pattern_matching_result.rs:33:5 | LL | / match Ok::(42) { LL | | Ok(_) => true, @@ -40,7 +41,7 @@ LL | | }; | |_____^ help: try: `Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:39:5 + --> $DIR/redundant_pattern_matching_result.rs:38:5 | LL | / match Ok::(42) { LL | | Ok(_) => false, @@ -49,7 +50,7 @@ LL | | }; | |_____^ help: try: `Ok::(42).is_err()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:44:5 + --> $DIR/redundant_pattern_matching_result.rs:43:5 | LL | / match Err::(42) { LL | | Ok(_) => false, @@ -58,7 +59,7 @@ LL | | }; | |_____^ help: try: `Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:49:5 + --> $DIR/redundant_pattern_matching_result.rs:48:5 | LL | / match Err::(42) { LL | | Ok(_) => true, @@ -67,73 +68,73 @@ LL | | }; | |_____^ help: try: `Err::(42).is_ok()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:54:20 + --> $DIR/redundant_pattern_matching_result.rs:53: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:62:20 + --> $DIR/redundant_pattern_matching_result.rs:61: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:64:19 + --> $DIR/redundant_pattern_matching_result.rs:63: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:87:19 + --> $DIR/redundant_pattern_matching_result.rs:86: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:88:16 + --> $DIR/redundant_pattern_matching_result.rs:87: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:94:12 + --> $DIR/redundant_pattern_matching_result.rs:93: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:95:15 + --> $DIR/redundant_pattern_matching_result.rs:94: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:113:12 + --> $DIR/redundant_pattern_matching_result.rs:112: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:115:12 + --> $DIR/redundant_pattern_matching_result.rs:114: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:117:15 + --> $DIR/redundant_pattern_matching_result.rs:116: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:119:15 + --> $DIR/redundant_pattern_matching_result.rs:118: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:121:5 + --> $DIR/redundant_pattern_matching_result.rs:120:5 | LL | / match Ok::(42) { LL | | Ok(_) => true, @@ -142,7 +143,7 @@ LL | | }; | |_____^ help: try: `Ok::(42).is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:126:5 + --> $DIR/redundant_pattern_matching_result.rs:125:5 | LL | / match Err::(42) { LL | | Ok(_) => false, @@ -151,7 +152,7 @@ LL | | }; | |_____^ help: try: `Err::(42).is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:136:5 + --> $DIR/redundant_pattern_matching_result.rs:135:5 | LL | / match x { LL | | Ok(_) => true, @@ -160,7 +161,7 @@ LL | | }; | |_____^ help: try: `x.is_ok()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:141:5 + --> $DIR/redundant_pattern_matching_result.rs:140:5 | LL | / match x { LL | | Ok(_) => false, @@ -169,7 +170,7 @@ LL | | }; | |_____^ help: try: `x.is_err()` error: redundant pattern matching, consider using `is_err()` - --> $DIR/redundant_pattern_matching_result.rs:146:5 + --> $DIR/redundant_pattern_matching_result.rs:145:5 | LL | / match x { LL | | Err(_) => true, @@ -178,7 +179,7 @@ LL | | }; | |_____^ help: try: `x.is_err()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:151:5 + --> $DIR/redundant_pattern_matching_result.rs:150:5 | LL | / match x { LL | | Err(_) => false, @@ -187,13 +188,13 @@ LL | | }; | |_____^ help: try: `x.is_ok()` error: redundant pattern matching, consider using `is_ok()` - --> $DIR/redundant_pattern_matching_result.rs:172:13 + --> $DIR/redundant_pattern_matching_result.rs:171: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:174:13 + --> $DIR/redundant_pattern_matching_result.rs:173:13 | LL | let _ = matches!(x, Err(_)); | ^^^^^^^^^^^^^^^^^^^ help: try: `x.is_err()` diff --git a/src/tools/clippy/tests/ui/redundant_pub_crate.fixed b/src/tools/clippy/tests/ui/redundant_pub_crate.fixed index a1ed491bb..e1d845721 100644 --- a/src/tools/clippy/tests/ui/redundant_pub_crate.fixed +++ b/src/tools/clippy/tests/ui/redundant_pub_crate.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![warn(clippy::redundant_pub_crate)] diff --git a/src/tools/clippy/tests/ui/redundant_pub_crate.rs b/src/tools/clippy/tests/ui/redundant_pub_crate.rs index 9accd297f..4d7f44892 100644 --- a/src/tools/clippy/tests/ui/redundant_pub_crate.rs +++ b/src/tools/clippy/tests/ui/redundant_pub_crate.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #![warn(clippy::redundant_pub_crate)] diff --git a/src/tools/clippy/tests/ui/redundant_pub_crate.stderr b/src/tools/clippy/tests/ui/redundant_pub_crate.stderr index 6fccdaa4e..5d7744aa8 100644 --- a/src/tools/clippy/tests/ui/redundant_pub_crate.stderr +++ b/src/tools/clippy/tests/ui/redundant_pub_crate.stderr @@ -1,5 +1,5 @@ error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:7:5 + --> $DIR/redundant_pub_crate.rs:6:5 | LL | pub(crate) fn g() {} // private due to m1 | ----------^^^^^ @@ -7,9 +7,10 @@ LL | pub(crate) fn g() {} // private due to m1 | help: consider using: `pub` | = note: `-D clippy::redundant-pub-crate` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_pub_crate)]` error: pub(crate) function inside private module - --> $DIR/redundant_pub_crate.rs:12:9 + --> $DIR/redundant_pub_crate.rs:11:9 | LL | pub(crate) fn g() {} // private due to m1_1 and m1 | ----------^^^^^ @@ -17,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:16:5 + --> $DIR/redundant_pub_crate.rs:15:5 | LL | pub(crate) mod m1_2 { | ----------^^^^^^^^^ @@ -25,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:19:9 + --> $DIR/redundant_pub_crate.rs:18:9 | LL | pub(crate) fn g() {} // private due to m1_2 and m1 | ----------^^^^^ @@ -33,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:25:9 + --> $DIR/redundant_pub_crate.rs:24:9 | LL | pub(crate) fn g() {} // private due to m1 | ----------^^^^^ @@ -41,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:32:5 + --> $DIR/redundant_pub_crate.rs:31:5 | LL | pub(crate) fn g() {} // already crate visible due to m2 | ----------^^^^^ @@ -49,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:37:9 + --> $DIR/redundant_pub_crate.rs:36:9 | LL | pub(crate) fn g() {} // private due to m2_1 | ----------^^^^^ @@ -57,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:41:5 + --> $DIR/redundant_pub_crate.rs:40:5 | LL | pub(crate) mod m2_2 { | ----------^^^^^^^^^ @@ -65,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:44:9 + --> $DIR/redundant_pub_crate.rs:43:9 | LL | pub(crate) fn g() {} // already crate visible due to m2_2 and m2 | ----------^^^^^ @@ -73,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:50:9 + --> $DIR/redundant_pub_crate.rs:49:9 | LL | pub(crate) fn g() {} // already crate visible due to m2 | ----------^^^^^ @@ -81,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:62:9 + --> $DIR/redundant_pub_crate.rs:61:9 | LL | pub(crate) fn g() {} // private due to m3_1 | ----------^^^^^ @@ -89,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:69:9 + --> $DIR/redundant_pub_crate.rs:68:9 | LL | pub(crate) fn g() {} // already crate visible due to m3_2 | ----------^^^^^ @@ -97,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:82:5 + --> $DIR/redundant_pub_crate.rs:81:5 | LL | pub(crate) fn g() {} // private: not re-exported by `pub use m4::*` | ----------^^^^^ @@ -105,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:87:9 + --> $DIR/redundant_pub_crate.rs:86:9 | LL | pub(crate) fn g() {} // private due to m4_1 | ----------^^^^^ @@ -113,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:91:5 + --> $DIR/redundant_pub_crate.rs:90:5 | LL | pub(crate) mod m4_2 { | ----------^^^^^^^^^ @@ -121,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:94:9 + --> $DIR/redundant_pub_crate.rs:93:9 | LL | pub(crate) fn g() {} // private due to m4_2 | ----------^^^^^ diff --git a/src/tools/clippy/tests/ui/redundant_slicing.fixed b/src/tools/clippy/tests/ui/redundant_slicing.fixed index 56ddca719..a4c035ba8 100644 --- a/src/tools/clippy/tests/ui/redundant_slicing.fixed +++ b/src/tools/clippy/tests/ui/redundant_slicing.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::deref_by_slicing)] #![warn(clippy::redundant_slicing)] diff --git a/src/tools/clippy/tests/ui/redundant_slicing.rs b/src/tools/clippy/tests/ui/redundant_slicing.rs index d67b6665e..67fe702ac 100644 --- a/src/tools/clippy/tests/ui/redundant_slicing.rs +++ b/src/tools/clippy/tests/ui/redundant_slicing.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused, clippy::deref_by_slicing)] #![warn(clippy::redundant_slicing)] diff --git a/src/tools/clippy/tests/ui/redundant_slicing.stderr b/src/tools/clippy/tests/ui/redundant_slicing.stderr index 82367143c..05287c882 100644 --- a/src/tools/clippy/tests/ui/redundant_slicing.stderr +++ b/src/tools/clippy/tests/ui/redundant_slicing.stderr @@ -1,19 +1,20 @@ error: redundant slicing of the whole range - --> $DIR/redundant_slicing.rs:10:13 + --> $DIR/redundant_slicing.rs:8:13 | LL | let _ = &slice[..]; // Redundant slice | ^^^^^^^^^^ help: use the original value instead: `slice` | = note: `-D clippy::redundant-slicing` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_slicing)]` error: redundant slicing of the whole range - --> $DIR/redundant_slicing.rs:14:13 + --> $DIR/redundant_slicing.rs:12: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:31:13 + --> $DIR/redundant_slicing.rs:29:13 | LL | let _ = &m!(slice)[..]; | ^^^^^^^^^^^^^^ help: use the original value instead: `slice` diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed b/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed index a83699ec6..9787bb635 100644 --- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed +++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #[derive(Debug)] diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs b/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs index b165cbaa3..b5a4827fa 100644 --- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs +++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused)] #[derive(Debug)] diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr b/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr index a13e5eadf..26f503453 100644 --- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr +++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr @@ -1,109 +1,110 @@ error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:8:17 + --> $DIR/redundant_static_lifetimes.rs:6:17 | LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removing 'static. | -^^^^^^^---- help: consider removing `'static`: `&str` | = note: `-D clippy::redundant-static-lifetimes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_static_lifetimes)]` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes.rs:12:21 + --> $DIR/redundant_static_lifetimes.rs:10: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:14:32 + --> $DIR/redundant_static_lifetimes.rs:12: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:14:47 + --> $DIR/redundant_static_lifetimes.rs:12: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:16:17 + --> $DIR/redundant_static_lifetimes.rs:14: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:18:20 + --> $DIR/redundant_static_lifetimes.rs:16: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:20:19 + --> $DIR/redundant_static_lifetimes.rs:18: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:22:19 + --> $DIR/redundant_static_lifetimes.rs:20: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:24:19 + --> $DIR/redundant_static_lifetimes.rs:22: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:26:25 + --> $DIR/redundant_static_lifetimes.rs:24: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:30:29 + --> $DIR/redundant_static_lifetimes.rs:28: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:32:25 + --> $DIR/redundant_static_lifetimes.rs:30: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:34:28 + --> $DIR/redundant_static_lifetimes.rs:32: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:36:27 + --> $DIR/redundant_static_lifetimes.rs:34: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:38:27 + --> $DIR/redundant_static_lifetimes.rs:36: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:40:27 + --> $DIR/redundant_static_lifetimes.rs:38: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:42:31 + --> $DIR/redundant_static_lifetimes.rs:40: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:71:16 + --> $DIR/redundant_static_lifetimes.rs:69:16 | LL | static V: &'static u8 = &17; | -^^^^^^^--- help: consider removing `'static`: `&u8` diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes_multiple.rs b/src/tools/clippy/tests/ui/redundant_static_lifetimes_multiple.rs index b3f263a7d..bfcab420b 100644 --- a/src/tools/clippy/tests/ui/redundant_static_lifetimes_multiple.rs +++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes_multiple.rs @@ -1,13 +1,25 @@ +//@no-rustfix: overlapping suggestions // these are rustfixable, but run-rustfix tests cannot handle them const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static +//~^ ERROR: constants have by default a `'static` lifetime +//~| NOTE: `-D clippy::redundant-static-lifetimes` implied by `-D warnings` +//~| ERROR: constants have by default a `'static` lifetime const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; +//~^ ERROR: constants have by default a `'static` lifetime +//~| ERROR: constants have by default a `'static` lifetime static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static +//~^ ERROR: statics have by default a `'static` lifetime +//~| ERROR: statics have by default a `'static` lifetime static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static +//~^ ERROR: statics have by default a `'static` lifetime +//~| ERROR: statics have by default a `'static` lifetime static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; +//~^ ERROR: statics have by default a `'static` lifetime +//~| ERROR: statics have by default a `'static` lifetime fn main() {} diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes_multiple.stderr b/src/tools/clippy/tests/ui/redundant_static_lifetimes_multiple.stderr index 4e7500903..bf4d21120 100644 --- a/src/tools/clippy/tests/ui/redundant_static_lifetimes_multiple.stderr +++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes_multiple.stderr @@ -1,61 +1,62 @@ error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:3:18 + --> $DIR/redundant_static_lifetimes_multiple.rs:4:18 | LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static | -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]` | = note: `-D clippy::redundant-static-lifetimes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_static_lifetimes)]` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:3:30 + --> $DIR/redundant_static_lifetimes_multiple.rs:4:30 | LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:5:29 + --> $DIR/redundant_static_lifetimes_multiple.rs:9:29 | LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]` error: constants have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:5:39 + --> $DIR/redundant_static_lifetimes_multiple.rs:9:39 | LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:7:40 + --> $DIR/redundant_static_lifetimes_multiple.rs:13:40 | LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:7:55 + --> $DIR/redundant_static_lifetimes_multiple.rs:13:55 | LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:9:26 + --> $DIR/redundant_static_lifetimes_multiple.rs:17:26 | LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static | -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:9:38 + --> $DIR/redundant_static_lifetimes_multiple.rs:17:38 | LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static | -^^^^^^^---- help: consider removing `'static`: `&str` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:11:37 + --> $DIR/redundant_static_lifetimes_multiple.rs:21:37 | LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]` error: statics have by default a `'static` lifetime - --> $DIR/redundant_static_lifetimes_multiple.rs:11:47 + --> $DIR/redundant_static_lifetimes_multiple.rs:21:47 | LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; | -^^^^^^^---- help: consider removing `'static`: `&str` diff --git a/src/tools/clippy/tests/ui/redundant_type_annotations.rs b/src/tools/clippy/tests/ui/redundant_type_annotations.rs index 09dbd3c9b..acf53fea2 100644 --- a/src/tools/clippy/tests/ui/redundant_type_annotations.rs +++ b/src/tools/clippy/tests/ui/redundant_type_annotations.rs @@ -79,8 +79,12 @@ impl Pie { // Everything here should be lint let v: u32 = self.return_an_int(); + //~^ ERROR: redundant type annotation + //~| NOTE: `-D clippy::redundant-type-annotations` implied by `-D warnings` let v: &u32 = self.return_a_ref(); + //~^ ERROR: redundant type annotation let v: &Slice = self.return_a_ref_to_struct(); + //~^ ERROR: redundant type annotation } } @@ -153,36 +157,50 @@ fn test_functions() { // Everything here should be lint let _return: String = return_a_string(); + //~^ ERROR: redundant type annotation let _return: Pie = return_a_struct(); + //~^ ERROR: redundant type annotation let _return: Pizza = return_an_enum(); + //~^ ERROR: redundant type annotation let _return: u32 = return_an_int(); + //~^ ERROR: redundant type annotation let _return: String = String::new(); + //~^ ERROR: redundant type annotation let new_pie: Pie = Pie::new(); + //~^ ERROR: redundant type annotation let _return: u32 = new_pie.return_an_int(); + //~^ ERROR: redundant type annotation let _return: u32 = Pie::associated_return_an_int(); + //~^ ERROR: redundant type annotation let _return: String = Pie::associated_return_a_string(); + //~^ ERROR: redundant type annotation } fn test_simple_types() { // Everything here should be lint let _var: u32 = u32::MAX; + //~^ ERROR: redundant type annotation let _var: u32 = 5_u32; + //~^ ERROR: redundant type annotation let _var: &str = "test"; + //~^ ERROR: redundant type annotation let _var: &[u8] = b"test"; + //~^ ERROR: redundant type annotation let _var: bool = false; + //~^ ERROR: redundant type annotation } fn issue11190() {} diff --git a/src/tools/clippy/tests/ui/redundant_type_annotations.stderr b/src/tools/clippy/tests/ui/redundant_type_annotations.stderr index 988ebe637..d1f26f183 100644 --- a/src/tools/clippy/tests/ui/redundant_type_annotations.stderr +++ b/src/tools/clippy/tests/ui/redundant_type_annotations.stderr @@ -5,99 +5,100 @@ LL | let v: u32 = self.return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::redundant-type-annotations` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_type_annotations)]` error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:82:9 + --> $DIR/redundant_type_annotations.rs:84:9 | LL | let v: &u32 = self.return_a_ref(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:83:9 + --> $DIR/redundant_type_annotations.rs:86:9 | LL | let v: &Slice = self.return_a_ref_to_struct(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:155:5 + --> $DIR/redundant_type_annotations.rs:159:5 | LL | let _return: String = return_a_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:157:5 + --> $DIR/redundant_type_annotations.rs:162:5 | LL | let _return: Pie = return_a_struct(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:159:5 + --> $DIR/redundant_type_annotations.rs:165:5 | LL | let _return: Pizza = return_an_enum(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:161:5 + --> $DIR/redundant_type_annotations.rs:168:5 | LL | let _return: u32 = return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:163:5 + --> $DIR/redundant_type_annotations.rs:171:5 | LL | let _return: String = String::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:165:5 + --> $DIR/redundant_type_annotations.rs:174:5 | LL | let new_pie: Pie = Pie::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:167:5 + --> $DIR/redundant_type_annotations.rs:177:5 | LL | let _return: u32 = new_pie.return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:169:5 + --> $DIR/redundant_type_annotations.rs:180:5 | LL | let _return: u32 = Pie::associated_return_an_int(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:171:5 + --> $DIR/redundant_type_annotations.rs:183:5 | LL | let _return: String = Pie::associated_return_a_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:177:5 + --> $DIR/redundant_type_annotations.rs:190:5 | LL | let _var: u32 = u32::MAX; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:179:5 + --> $DIR/redundant_type_annotations.rs:193:5 | LL | let _var: u32 = 5_u32; | ^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:181:5 + --> $DIR/redundant_type_annotations.rs:196:5 | LL | let _var: &str = "test"; | ^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:183:5 + --> $DIR/redundant_type_annotations.rs:199:5 | LL | let _var: &[u8] = b"test"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant type annotation - --> $DIR/redundant_type_annotations.rs:185:5 + --> $DIR/redundant_type_annotations.rs:202:5 | LL | let _var: bool = false; | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/ref_binding_to_reference.rs b/src/tools/clippy/tests/ui/ref_binding_to_reference.rs index c8d0e56b1..a4444c95e 100644 --- a/src/tools/clippy/tests/ui/ref_binding_to_reference.rs +++ b/src/tools/clippy/tests/ui/ref_binding_to_reference.rs @@ -1,5 +1,5 @@ // FIXME: run-rustfix waiting on multi-span suggestions - +//@no-rustfix #![feature(lint_reasons)] #![warn(clippy::ref_binding_to_reference)] #![allow(clippy::needless_borrowed_reference, clippy::explicit_auto_deref)] @@ -29,12 +29,15 @@ fn main() { // Err, reference to a &String let _: &&String = match Some(&x) { Some(ref x) => x, + //~^ ERROR: this pattern creates a reference to a reference + //~| NOTE: `-D clippy::ref-binding-to-reference` implied by `-D warnings` None => return, }; // Err, reference to a &String let _: &&String = match Some(&x) { Some(ref x) => { + //~^ ERROR: this pattern creates a reference to a reference f1(x); f1(*x); x @@ -45,17 +48,20 @@ fn main() { // Err, reference to a &String match Some(&x) { Some(ref x) => m2!(x), + //~^ ERROR: this pattern creates a reference to a reference None => return, } // Err, reference to a &String let _ = |&ref x: &&String| { + //~^ ERROR: this pattern creates a reference to a reference let _: &&String = x; }; } // Err, reference to a &String fn f2<'a>(&ref x: &&'a String) -> &'a String { + //~^ ERROR: this pattern creates a reference to a reference let _: &&String = x; *x } @@ -63,6 +69,7 @@ fn f2<'a>(&ref x: &&'a String) -> &'a String { trait T1 { // Err, reference to a &String fn f(&ref x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &&String = x; } } @@ -71,6 +78,7 @@ struct S; impl T1 for S { // Err, reference to a &String fn f(&ref x: &&String) { + //~^ ERROR: this pattern creates a reference to a reference let _: &&String = x; } } diff --git a/src/tools/clippy/tests/ui/ref_binding_to_reference.stderr b/src/tools/clippy/tests/ui/ref_binding_to_reference.stderr index 016feb103..6e8b43a3e 100644 --- a/src/tools/clippy/tests/ui/ref_binding_to_reference.stderr +++ b/src/tools/clippy/tests/ui/ref_binding_to_reference.stderr @@ -5,13 +5,14 @@ LL | Some(ref x) => x, | ^^^^^ | = note: `-D clippy::ref-binding-to-reference` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ref_binding_to_reference)]` help: try | LL | Some(x) => &x, | ~ ~~ error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:37:14 + --> $DIR/ref_binding_to_reference.rs:39:14 | LL | Some(ref x) => { | ^^^^^ @@ -19,13 +20,14 @@ LL | Some(ref x) => { help: try | LL ~ Some(x) => { +LL | LL | f1(x); LL ~ f1(x); LL ~ &x | error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:47:14 + --> $DIR/ref_binding_to_reference.rs:50:14 | LL | Some(ref x) => m2!(x), | ^^^^^ @@ -36,7 +38,7 @@ LL | Some(x) => m2!(&x), | ~ ~~ error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:52:15 + --> $DIR/ref_binding_to_reference.rs:56:15 | LL | let _ = |&ref x: &&String| { | ^^^^^ @@ -44,11 +46,12 @@ LL | let _ = |&ref x: &&String| { help: try | LL ~ let _ = |&x: &&String| { +LL | LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:58:12 + --> $DIR/ref_binding_to_reference.rs:63:12 | LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { | ^^^^^ @@ -56,12 +59,13 @@ LL | fn f2<'a>(&ref x: &&'a String) -> &'a String { help: try | LL ~ fn f2<'a>(&x: &&'a String) -> &'a String { +LL | LL ~ let _: &&String = &x; LL ~ x | error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:65:11 + --> $DIR/ref_binding_to_reference.rs:71:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -69,11 +73,12 @@ LL | fn f(&ref x: &&String) { help: try | LL ~ fn f(&x: &&String) { +LL | LL ~ let _: &&String = &x; | error: this pattern creates a reference to a reference - --> $DIR/ref_binding_to_reference.rs:73:11 + --> $DIR/ref_binding_to_reference.rs:80:11 | LL | fn f(&ref x: &&String) { | ^^^^^ @@ -81,6 +86,7 @@ LL | fn f(&ref x: &&String) { help: try | LL ~ fn f(&x: &&String) { +LL | LL ~ let _: &&String = &x; | diff --git a/src/tools/clippy/tests/ui/ref_option_ref.rs b/src/tools/clippy/tests/ui/ref_option_ref.rs index e487799e1..44001c45e 100644 --- a/src/tools/clippy/tests/ui/ref_option_ref.rs +++ b/src/tools/clippy/tests/ui/ref_option_ref.rs @@ -1,6 +1,6 @@ #![allow(unused)] #![warn(clippy::ref_option_ref)] - +//@no-rustfix // This lint is not tagged as run-rustfix because automatically // changing the type of a variable would also means changing // all usages of this variable to match and This is not handled @@ -8,27 +8,37 @@ static THRESHOLD: i32 = 10; static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD); +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt +//~| NOTE: `-D clippy::ref-option-ref` implied by `-D warnings` const CONST_THRESHOLD: &i32 = &10; const REF_CONST: &Option<&i32> = &Some(CONST_THRESHOLD); +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt type RefOptRefU32<'a> = &'a Option<&'a u32>; +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt type RefOptRef<'a, T> = &'a Option<&'a T>; +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt fn foo(data: &Option<&u32>) {} +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt fn bar(data: &u32) -> &Option<&u32> { + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt &None } struct StructRef<'a> { data: &'a Option<&'a u32>, + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to } struct StructTupleRef<'a>(u32, &'a Option<&'a u32>); +//~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Opt enum EnumRef<'a> { Variant1(u32), Variant2(&'a Option<&'a u32>), + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to } trait RefOptTrait { @@ -38,12 +48,14 @@ trait RefOptTrait { impl RefOptTrait for u32 { type A = &'static Option<&'static Self>; + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to fn foo(&self, _: Self::A) {} } fn main() { let x: &Option<&u32> = &None; + //~^ ERROR: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to } fn issue9682(arg: &Option<&mut String>) { diff --git a/src/tools/clippy/tests/ui/ref_option_ref.stderr b/src/tools/clippy/tests/ui/ref_option_ref.stderr index b61334758..6a28a68dc 100644 --- a/src/tools/clippy/tests/ui/ref_option_ref.stderr +++ b/src/tools/clippy/tests/ui/ref_option_ref.stderr @@ -5,63 +5,64 @@ LL | static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD); | ^^^^^^^^^^^^^ help: try: `Option<&i32>` | = note: `-D clippy::ref-option-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ref_option_ref)]` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:12:18 + --> $DIR/ref_option_ref.rs:14:18 | LL | const REF_CONST: &Option<&i32> = &Some(CONST_THRESHOLD); | ^^^^^^^^^^^^^ help: try: `Option<&i32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:14:25 + --> $DIR/ref_option_ref.rs:17:25 | LL | type RefOptRefU32<'a> = &'a Option<&'a u32>; | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:15:25 + --> $DIR/ref_option_ref.rs:19:25 | LL | type RefOptRef<'a, T> = &'a Option<&'a T>; | ^^^^^^^^^^^^^^^^^ help: try: `Option<&'a T>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:17:14 + --> $DIR/ref_option_ref.rs:22:14 | LL | fn foo(data: &Option<&u32>) {} | ^^^^^^^^^^^^^ help: try: `Option<&u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:19:23 + --> $DIR/ref_option_ref.rs:25:23 | LL | fn bar(data: &u32) -> &Option<&u32> { | ^^^^^^^^^^^^^ help: try: `Option<&u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:24:11 + --> $DIR/ref_option_ref.rs:31:11 | LL | data: &'a Option<&'a u32>, | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:27:32 + --> $DIR/ref_option_ref.rs:35:32 | LL | struct StructTupleRef<'a>(u32, &'a Option<&'a u32>); | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:31:14 + --> $DIR/ref_option_ref.rs:40:14 | LL | Variant2(&'a Option<&'a u32>), | ^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'a u32>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:40:14 + --> $DIR/ref_option_ref.rs:50:14 | LL | type A = &'static Option<&'static Self>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Option<&'static Self>` error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>` - --> $DIR/ref_option_ref.rs:46:12 + --> $DIR/ref_option_ref.rs:57:12 | LL | let x: &Option<&u32> = &None; | ^^^^^^^^^^^^^ help: try: `Option<&u32>` diff --git a/src/tools/clippy/tests/ui/ref_patterns.rs b/src/tools/clippy/tests/ui/ref_patterns.rs index c51e0bc76..acd42ec89 100644 --- a/src/tools/clippy/tests/ui/ref_patterns.rs +++ b/src/tools/clippy/tests/ui/ref_patterns.rs @@ -6,14 +6,17 @@ fn use_in_pattern() { match opt { None => {}, Some(ref opt) => {}, + //~^ ERROR: usage of ref pattern } } fn use_in_binding() { let x = 5; let ref y = x; + //~^ ERROR: usage of ref pattern } fn use_in_parameter(ref x: i32) {} +//~^ ERROR: usage of ref pattern fn main() {} diff --git a/src/tools/clippy/tests/ui/ref_patterns.stderr b/src/tools/clippy/tests/ui/ref_patterns.stderr index aa0077826..74892bac6 100644 --- a/src/tools/clippy/tests/ui/ref_patterns.stderr +++ b/src/tools/clippy/tests/ui/ref_patterns.stderr @@ -6,9 +6,10 @@ LL | Some(ref opt) => {}, | = help: consider using `&` for clarity instead = note: `-D clippy::ref-patterns` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ref_patterns)]` error: usage of ref pattern - --> $DIR/ref_patterns.rs:14:9 + --> $DIR/ref_patterns.rs:15:9 | LL | let ref y = x; | ^^^^^ @@ -16,7 +17,7 @@ LL | let ref y = x; = help: consider using `&` for clarity instead error: usage of ref pattern - --> $DIR/ref_patterns.rs:17:21 + --> $DIR/ref_patterns.rs:19:21 | LL | fn use_in_parameter(ref x: i32) {} | ^^^^^ diff --git a/src/tools/clippy/tests/ui/regex.rs b/src/tools/clippy/tests/ui/regex.rs index 89d1d9494..094d9574a 100644 --- a/src/tools/clippy/tests/ui/regex.rs +++ b/src/tools/clippy/tests/ui/regex.rs @@ -2,7 +2,8 @@ unused, clippy::needless_raw_strings, clippy::needless_raw_string_hashes, - clippy::needless_borrow + clippy::needless_borrow, + clippy::needless_borrows_for_generic_args )] #![warn(clippy::invalid_regex, clippy::trivial_regex)] @@ -16,13 +17,19 @@ const NOT_A_REAL_REGEX: &str = "foobar"; fn syntax_error() { let pipe_in_wrong_position = Regex::new("|"); + //~^ ERROR: trivial regex let pipe_in_wrong_position_builder = RegexBuilder::new("|"); + //~^ ERROR: trivial regex let wrong_char_ranice = Regex::new("[z-a]"); + //~^ ERROR: regex syntax error: invalid character class range, the start must be <= th + //~| NOTE: `-D clippy::invalid-regex` implied by `-D warnings` 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 binary_pipe_in_wrong_position = BRegex::new("|"); + //~^ ERROR: trivial regex let some_binary_regex = BRegex::new(OPENING_PAREN); let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); @@ -47,36 +54,49 @@ fn syntax_error() { let escaped_string_span = Regex::new("\\b\\c"); let aux_span = Regex::new("(?ixi)"); + //~^ ERROR: regex syntax error: duplicate flag let should_not_lint = Regex::new("(?u)."); let should_not_lint = BRegex::new("(?u)."); let invalid_utf8_should_not_lint = BRegex::new("(?-u)."); let invalid_utf8_should_lint = Regex::new("(?-u)."); + //~^ ERROR: regex syntax error: pattern can match invalid UTF-8 } fn trivial_regex() { let trivial_eq = Regex::new("^foobar$"); + //~^ ERROR: trivial regex let trivial_eq_builder = RegexBuilder::new("^foobar$"); + //~^ ERROR: trivial regex let trivial_starts_with = Regex::new("^foobar"); + //~^ ERROR: trivial regex let trivial_ends_with = Regex::new("foobar$"); + //~^ ERROR: trivial regex let trivial_contains = Regex::new("foobar"); + //~^ ERROR: trivial regex let trivial_contains = Regex::new(NOT_A_REAL_REGEX); + //~^ ERROR: trivial regex let trivial_backslash = Regex::new("a\\.b"); + //~^ ERROR: trivial regex // unlikely corner cases let trivial_empty = Regex::new(""); + //~^ ERROR: trivial regex let trivial_empty = Regex::new("^"); + //~^ ERROR: trivial regex let trivial_empty = Regex::new("^$"); + //~^ ERROR: trivial regex let binary_trivial_empty = BRegex::new("^$"); + //~^ ERROR: trivial regex // non-trivial regexes let non_trivial_dot = Regex::new("a.b"); diff --git a/src/tools/clippy/tests/ui/regex.stderr b/src/tools/clippy/tests/ui/regex.stderr index 21f1cb444..6d98d691d 100644 --- a/src/tools/clippy/tests/ui/regex.stderr +++ b/src/tools/clippy/tests/ui/regex.stderr @@ -1,14 +1,15 @@ error: trivial regex - --> $DIR/regex.rs:18:45 + --> $DIR/regex.rs:19:45 | LL | let pipe_in_wrong_position = Regex::new("|"); | ^^^ | = help: the regex is unlikely to be useful as it is = note: `-D clippy::trivial-regex` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::trivial_regex)]` error: trivial regex - --> $DIR/regex.rs:19:60 + --> $DIR/regex.rs:21:60 | LL | let pipe_in_wrong_position_builder = RegexBuilder::new("|"); | ^^^ @@ -16,15 +17,16 @@ LL | let pipe_in_wrong_position_builder = RegexBuilder::new("|"); = help: the regex is unlikely to be useful as it is error: regex syntax error: invalid character class range, the start must be <= the end - --> $DIR/regex.rs:20:42 + --> $DIR/regex.rs:23:42 | LL | let wrong_char_ranice = Regex::new("[z-a]"); | ^^^ | = note: `-D clippy::invalid-regex` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::invalid_regex)]` error: regex syntax error: invalid character class range, the start must be <= the end - --> $DIR/regex.rs:21:37 + --> $DIR/regex.rs:26:37 | LL | let some_unicode = Regex::new("[é-è]"); | ^^^ @@ -33,13 +35,13 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:23:33 + --> $DIR/regex.rs:29:33 | LL | let some_regex = Regex::new(OPENING_PAREN); | ^^^^^^^^^^^^^ error: trivial regex - --> $DIR/regex.rs:25:53 + --> $DIR/regex.rs:31:53 | LL | let binary_pipe_in_wrong_position = BRegex::new("|"); | ^^^ @@ -50,7 +52,7 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:26:41 + --> $DIR/regex.rs:33:41 | LL | let some_binary_regex = BRegex::new(OPENING_PAREN); | ^^^^^^^^^^^^^ @@ -59,7 +61,7 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:27:56 + --> $DIR/regex.rs:34:56 | LL | let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); | ^^^^^^^^^^^^^ @@ -68,45 +70,45 @@ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:39:37 + --> $DIR/regex.rs:46:37 | -LL | let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+/.(com|org|net)"]); +LL | let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); | ^^^^^^^^^^^^^ error: regex parse error: ( ^ error: unclosed group - --> $DIR/regex.rs:40:39 + --> $DIR/regex.rs:47:39 | -LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+/.(com|org|net)"]); +LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]); | ^^^^^^^^^^^^^ error: regex parse error: - /b/c + \b\c ^^ error: unrecognized escape sequence - --> $DIR/regex.rs:47:42 + --> $DIR/regex.rs:54:42 | -LL | let escaped_string_span = Regex::new("//b//c"); +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:49:34 + --> $DIR/regex.rs:56:34 | LL | let aux_span = Regex::new("(?ixi)"); | ^ ^ error: regex syntax error: pattern can match invalid UTF-8 - --> $DIR/regex.rs:54:53 + --> $DIR/regex.rs:62:53 | LL | let invalid_utf8_should_lint = Regex::new("(?-u)."); | ^ error: trivial regex - --> $DIR/regex.rs:58:33 + --> $DIR/regex.rs:67:33 | LL | let trivial_eq = Regex::new("^foobar$"); | ^^^^^^^^^^ @@ -114,7 +116,7 @@ LL | let trivial_eq = Regex::new("^foobar$"); = help: consider using `==` on `str`s error: trivial regex - --> $DIR/regex.rs:60:48 + --> $DIR/regex.rs:70:48 | LL | let trivial_eq_builder = RegexBuilder::new("^foobar$"); | ^^^^^^^^^^ @@ -122,7 +124,7 @@ LL | let trivial_eq_builder = RegexBuilder::new("^foobar$"); = help: consider using `==` on `str`s error: trivial regex - --> $DIR/regex.rs:62:42 + --> $DIR/regex.rs:73:42 | LL | let trivial_starts_with = Regex::new("^foobar"); | ^^^^^^^^^ @@ -130,7 +132,7 @@ LL | let trivial_starts_with = Regex::new("^foobar"); = help: consider using `str::starts_with` error: trivial regex - --> $DIR/regex.rs:64:40 + --> $DIR/regex.rs:76:40 | LL | let trivial_ends_with = Regex::new("foobar$"); | ^^^^^^^^^ @@ -138,7 +140,7 @@ LL | let trivial_ends_with = Regex::new("foobar$"); = help: consider using `str::ends_with` error: trivial regex - --> $DIR/regex.rs:66:39 + --> $DIR/regex.rs:79:39 | LL | let trivial_contains = Regex::new("foobar"); | ^^^^^^^^ @@ -146,7 +148,7 @@ LL | let trivial_contains = Regex::new("foobar"); = help: consider using `str::contains` error: trivial regex - --> $DIR/regex.rs:68:39 + --> $DIR/regex.rs:82:39 | LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); | ^^^^^^^^^^^^^^^^ @@ -154,15 +156,15 @@ LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); = help: consider using `str::contains` error: trivial regex - --> $DIR/regex.rs:70:40 + --> $DIR/regex.rs:85:40 | -LL | let trivial_backslash = Regex::new("a//.b"); +LL | let trivial_backslash = Regex::new("a\\.b"); | ^^^^^^^ | = help: consider using `str::contains` error: trivial regex - --> $DIR/regex.rs:73:36 + --> $DIR/regex.rs:89:36 | LL | let trivial_empty = Regex::new(""); | ^^ @@ -170,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:75:36 + --> $DIR/regex.rs:92:36 | LL | let trivial_empty = Regex::new("^"); | ^^^ @@ -178,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:77:36 + --> $DIR/regex.rs:95:36 | LL | let trivial_empty = Regex::new("^$"); | ^^^^ @@ -186,7 +188,7 @@ LL | let trivial_empty = Regex::new("^$"); = help: consider using `str::is_empty` error: trivial regex - --> $DIR/regex.rs:79:44 + --> $DIR/regex.rs:98:44 | LL | let binary_trivial_empty = BRegex::new("^$"); | ^^^^ diff --git a/src/tools/clippy/tests/ui/rename.fixed b/src/tools/clippy/tests/ui/rename.fixed index e78b9e5c9..4df9be2c2 100644 --- a/src/tools/clippy/tests/ui/rename.fixed +++ b/src/tools/clippy/tests/ui/rename.fixed @@ -2,8 +2,6 @@ // Use that command to update this file and do not edit by hand. // Manual edits will be overwritten. -//@run-rustfix - #![allow(clippy::almost_complete_range)] #![allow(clippy::disallowed_names)] #![allow(clippy::blocks_in_if_conditions)] @@ -16,6 +14,8 @@ #![allow(clippy::mixed_read_write_in_expression)] #![allow(clippy::useless_conversion)] #![allow(clippy::match_result_ok)] +#![allow(clippy::non_canonical_clone_impl)] +#![allow(clippy::non_canonical_partial_ord_impl)] #![allow(clippy::arithmetic_side_effects)] #![allow(clippy::overly_complex_bool_expr)] #![allow(clippy::new_without_default)] @@ -35,10 +35,10 @@ #![allow(drop_bounds)] #![allow(dropping_copy_types)] #![allow(dropping_references)] +#![allow(useless_ptr_null_checks)] #![allow(for_loops_over_fallibles)] #![allow(forgetting_copy_types)] #![allow(forgetting_references)] -#![allow(useless_ptr_null_checks)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] @@ -64,6 +64,8 @@ #![warn(clippy::mixed_read_write_in_expression)] #![warn(clippy::useless_conversion)] #![warn(clippy::match_result_ok)] +#![warn(clippy::non_canonical_clone_impl)] +#![warn(clippy::non_canonical_partial_ord_impl)] #![warn(clippy::arithmetic_side_effects)] #![warn(clippy::overly_complex_bool_expr)] #![warn(clippy::new_without_default)] @@ -87,12 +89,12 @@ #![warn(drop_bounds)] #![warn(dropping_copy_types)] #![warn(dropping_references)] +#![warn(useless_ptr_null_checks)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] #![warn(forgetting_copy_types)] #![warn(forgetting_references)] -#![warn(useless_ptr_null_checks)] #![warn(array_into_iter)] #![warn(invalid_atomic_ordering)] #![warn(invalid_value)] diff --git a/src/tools/clippy/tests/ui/rename.rs b/src/tools/clippy/tests/ui/rename.rs index 2e6ef60cb..940e60068 100644 --- a/src/tools/clippy/tests/ui/rename.rs +++ b/src/tools/clippy/tests/ui/rename.rs @@ -2,8 +2,6 @@ // Use that command to update this file and do not edit by hand. // Manual edits will be overwritten. -//@run-rustfix - #![allow(clippy::almost_complete_range)] #![allow(clippy::disallowed_names)] #![allow(clippy::blocks_in_if_conditions)] @@ -16,6 +14,8 @@ #![allow(clippy::mixed_read_write_in_expression)] #![allow(clippy::useless_conversion)] #![allow(clippy::match_result_ok)] +#![allow(clippy::non_canonical_clone_impl)] +#![allow(clippy::non_canonical_partial_ord_impl)] #![allow(clippy::arithmetic_side_effects)] #![allow(clippy::overly_complex_bool_expr)] #![allow(clippy::new_without_default)] @@ -35,10 +35,10 @@ #![allow(drop_bounds)] #![allow(dropping_copy_types)] #![allow(dropping_references)] +#![allow(useless_ptr_null_checks)] #![allow(for_loops_over_fallibles)] #![allow(forgetting_copy_types)] #![allow(forgetting_references)] -#![allow(useless_ptr_null_checks)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] @@ -64,6 +64,8 @@ #![warn(clippy::eval_order_dependence)] #![warn(clippy::identity_conversion)] #![warn(clippy::if_let_some_result)] +#![warn(clippy::incorrect_clone_impl_on_copy_type)] +#![warn(clippy::incorrect_partial_ord_impl_on_ord_type)] #![warn(clippy::integer_arithmetic)] #![warn(clippy::logic_bug)] #![warn(clippy::new_without_default_derive)] @@ -87,12 +89,12 @@ #![warn(clippy::drop_bounds)] #![warn(clippy::drop_copy)] #![warn(clippy::drop_ref)] +#![warn(clippy::fn_null_check)] #![warn(clippy::for_loop_over_option)] #![warn(clippy::for_loop_over_result)] #![warn(clippy::for_loops_over_fallibles)] #![warn(clippy::forget_copy)] #![warn(clippy::forget_ref)] -#![warn(clippy::fn_null_check)] #![warn(clippy::into_iter_on_array)] #![warn(clippy::invalid_atomic_ordering)] #![warn(clippy::invalid_ref)] diff --git a/src/tools/clippy/tests/ui/rename.stderr b/src/tools/clippy/tests/ui/rename.stderr index 57e991e56..30824e154 100644 --- a/src/tools/clippy/tests/ui/rename.stderr +++ b/src/tools/clippy/tests/ui/rename.stderr @@ -5,6 +5,7 @@ LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` | = note: `-D renamed-and-removed-lints` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(renamed_and_removed_lints)]` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` --> $DIR/rename.rs:55:9 @@ -78,251 +79,263 @@ error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_resu LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` -error: lint `clippy::integer_arithmetic` has been renamed to `clippy::arithmetic_side_effects` +error: lint `clippy::incorrect_clone_impl_on_copy_type` has been renamed to `clippy::non_canonical_clone_impl` --> $DIR/rename.rs:67:9 | +LL | #![warn(clippy::incorrect_clone_impl_on_copy_type)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::non_canonical_clone_impl` + +error: lint `clippy::incorrect_partial_ord_impl_on_ord_type` has been renamed to `clippy::non_canonical_partial_ord_impl` + --> $DIR/rename.rs:68:9 + | +LL | #![warn(clippy::incorrect_partial_ord_impl_on_ord_type)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::non_canonical_partial_ord_impl` + +error: lint `clippy::integer_arithmetic` has been renamed to `clippy::arithmetic_side_effects` + --> $DIR/rename.rs:69:9 + | LL | #![warn(clippy::integer_arithmetic)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::arithmetic_side_effects` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::unwrap_or_else_default` has been renamed to `clippy::unwrap_or_default` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::unwrap_or_else_default)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_or_default` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::cast_ref_to_mut` has been renamed to `invalid_reference_casting` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::cast_ref_to_mut)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_reference_casting` error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::clone_double_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op` error: lint `clippy::cmp_nan` has been renamed to `invalid_nan_comparisons` - --> $DIR/rename.rs:86:9 + --> $DIR/rename.rs:88:9 | LL | #![warn(clippy::cmp_nan)] | ^^^^^^^^^^^^^^^ help: use the new name: `invalid_nan_comparisons` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:87:9 + --> $DIR/rename.rs:89:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types` - --> $DIR/rename.rs:88:9 + --> $DIR/rename.rs:90:9 | LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types` error: lint `clippy::drop_ref` has been renamed to `dropping_references` - --> $DIR/rename.rs:89:9 + --> $DIR/rename.rs:91:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `dropping_references` +error: lint `clippy::fn_null_check` has been renamed to `useless_ptr_null_checks` + --> $DIR/rename.rs:92:9 + | +LL | #![warn(clippy::fn_null_check)] + | ^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `useless_ptr_null_checks` + error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:90:9 + --> $DIR/rename.rs:93:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:91:9 + --> $DIR/rename.rs:94:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:92:9 + --> $DIR/rename.rs:95:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types` - --> $DIR/rename.rs:93:9 + --> $DIR/rename.rs:96:9 | LL | #![warn(clippy::forget_copy)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types` error: lint `clippy::forget_ref` has been renamed to `forgetting_references` - --> $DIR/rename.rs:94:9 + --> $DIR/rename.rs:97:9 | LL | #![warn(clippy::forget_ref)] | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references` -error: lint `clippy::fn_null_check` has been renamed to `useless_ptr_null_checks` - --> $DIR/rename.rs:95:9 - | -LL | #![warn(clippy::fn_null_check)] - | ^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `useless_ptr_null_checks` - error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:96:9 + --> $DIR/rename.rs:98:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:97:9 + --> $DIR/rename.rs:99:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:98:9 + --> $DIR/rename.rs:100:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::invalid_utf8_in_unchecked` has been renamed to `invalid_from_utf8_unchecked` - --> $DIR/rename.rs:99:9 + --> $DIR/rename.rs:101:9 | LL | #![warn(clippy::invalid_utf8_in_unchecked)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_from_utf8_unchecked` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:100:9 + --> $DIR/rename.rs:102:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:101:9 + --> $DIR/rename.rs:103:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:102:9 + --> $DIR/rename.rs:104:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:103:9 + --> $DIR/rename.rs:105:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:104:9 + --> $DIR/rename.rs:106:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::undropped_manually_drops` has been renamed to `undropped_manually_drops` - --> $DIR/rename.rs:105:9 + --> $DIR/rename.rs:107:9 | LL | #![warn(clippy::undropped_manually_drops)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `undropped_manually_drops` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:106:9 + --> $DIR/rename.rs:108:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:107:9 + --> $DIR/rename.rs:109:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 54 previous errors +error: aborting due to 56 previous errors diff --git a/src/tools/clippy/tests/ui/renamed_builtin_attr.fixed b/src/tools/clippy/tests/ui/renamed_builtin_attr.fixed index 0334c1e1a..bc0552157 100644 --- a/src/tools/clippy/tests/ui/renamed_builtin_attr.fixed +++ b/src/tools/clippy/tests/ui/renamed_builtin_attr.fixed @@ -1,4 +1,2 @@ -//@run-rustfix - #[clippy::cognitive_complexity = "1"] fn main() {} diff --git a/src/tools/clippy/tests/ui/renamed_builtin_attr.rs b/src/tools/clippy/tests/ui/renamed_builtin_attr.rs index d350370c2..fdb425363 100644 --- a/src/tools/clippy/tests/ui/renamed_builtin_attr.rs +++ b/src/tools/clippy/tests/ui/renamed_builtin_attr.rs @@ -1,4 +1,2 @@ -//@run-rustfix - #[clippy::cyclomatic_complexity = "1"] fn main() {} diff --git a/src/tools/clippy/tests/ui/renamed_builtin_attr.stderr b/src/tools/clippy/tests/ui/renamed_builtin_attr.stderr index 880467624..636d88fcd 100644 --- a/src/tools/clippy/tests/ui/renamed_builtin_attr.stderr +++ b/src/tools/clippy/tests/ui/renamed_builtin_attr.stderr @@ -1,5 +1,5 @@ error: usage of deprecated attribute - --> $DIR/renamed_builtin_attr.rs:3:11 + --> $DIR/renamed_builtin_attr.rs:1:11 | LL | #[clippy::cyclomatic_complexity = "1"] | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `cognitive_complexity` diff --git a/src/tools/clippy/tests/ui/repeat_once.fixed b/src/tools/clippy/tests/ui/repeat_once.fixed index c517bfcc6..72e97350a 100644 --- a/src/tools/clippy/tests/ui/repeat_once.fixed +++ b/src/tools/clippy/tests/ui/repeat_once.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::repeat_once)] #[allow(unused, clippy::redundant_clone)] fn main() { diff --git a/src/tools/clippy/tests/ui/repeat_once.rs b/src/tools/clippy/tests/ui/repeat_once.rs index 9a30b4741..7557c4d0b 100644 --- a/src/tools/clippy/tests/ui/repeat_once.rs +++ b/src/tools/clippy/tests/ui/repeat_once.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::repeat_once)] #[allow(unused, clippy::redundant_clone)] fn main() { diff --git a/src/tools/clippy/tests/ui/repeat_once.stderr b/src/tools/clippy/tests/ui/repeat_once.stderr index 915eea3bf..895729390 100644 --- a/src/tools/clippy/tests/ui/repeat_once.stderr +++ b/src/tools/clippy/tests/ui/repeat_once.stderr @@ -1,37 +1,38 @@ error: calling `repeat(1)` on slice - --> $DIR/repeat_once.rs:10:13 + --> $DIR/repeat_once.rs:9:13 | LL | let a = [1; 5].repeat(1); | ^^^^^^^^^^^^^^^^ help: consider using `.to_vec()` instead: `[1; 5].to_vec()` | = note: `-D clippy::repeat-once` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::repeat_once)]` error: calling `repeat(1)` on slice - --> $DIR/repeat_once.rs:11:13 + --> $DIR/repeat_once.rs:10:13 | LL | let b = slice.repeat(1); | ^^^^^^^^^^^^^^^ help: consider using `.to_vec()` instead: `slice.to_vec()` error: calling `repeat(1)` on str - --> $DIR/repeat_once.rs:12:13 + --> $DIR/repeat_once.rs:11:13 | LL | let c = "hello".repeat(N); | ^^^^^^^^^^^^^^^^^ help: consider using `.to_string()` instead: `"hello".to_string()` error: calling `repeat(1)` on str - --> $DIR/repeat_once.rs:13:13 + --> $DIR/repeat_once.rs:12:13 | LL | let d = "hi".repeat(1); | ^^^^^^^^^^^^^^ help: consider using `.to_string()` instead: `"hi".to_string()` error: calling `repeat(1)` on str - --> $DIR/repeat_once.rs:14:13 + --> $DIR/repeat_once.rs:13:13 | LL | let e = s.repeat(1); | ^^^^^^^^^^^ help: consider using `.to_string()` instead: `s.to_string()` error: calling `repeat(1)` on a string literal - --> $DIR/repeat_once.rs:15:13 + --> $DIR/repeat_once.rs:14:13 | LL | let f = string.repeat(1); | ^^^^^^^^^^^^^^^^ help: consider using `.clone()` instead: `string.clone()` diff --git a/src/tools/clippy/tests/ui/repl_uninit.rs b/src/tools/clippy/tests/ui/repl_uninit.rs index 6c7e2b854..01bdf79e6 100644 --- a/src/tools/clippy/tests/ui/repl_uninit.rs +++ b/src/tools/clippy/tests/ui/repl_uninit.rs @@ -1,6 +1,6 @@ #![allow(deprecated, invalid_value, clippy::uninit_assumed_init)] #![warn(clippy::mem_replace_with_uninit)] - +//@no-rustfix use std::mem; fn might_panic(x: X) -> X { @@ -13,18 +13,22 @@ fn main() { // the following is UB if `might_panic` panics unsafe { let taken_v = mem::replace(&mut v, mem::uninitialized()); + //~^ ERROR: replacing with `mem::uninitialized()` + //~| NOTE: `-D clippy::mem-replace-with-uninit` implied by `-D warnings` let new_v = might_panic(taken_v); std::mem::forget(mem::replace(&mut v, new_v)); } unsafe { let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init()); + //~^ ERROR: replacing with `mem::MaybeUninit::uninit().assume_init()` let new_v = might_panic(taken_v); std::mem::forget(mem::replace(&mut v, new_v)); } unsafe { let taken_v = mem::replace(&mut v, mem::zeroed()); + //~^ ERROR: replacing with `mem::zeroed()` let new_v = might_panic(taken_v); std::mem::forget(mem::replace(&mut v, new_v)); } @@ -37,5 +41,6 @@ fn main() { // this is still not OK, because uninit let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) }; + //~^ ERROR: replacing with `mem::uninitialized()` *uref = taken_u + 1; } diff --git a/src/tools/clippy/tests/ui/repl_uninit.stderr b/src/tools/clippy/tests/ui/repl_uninit.stderr index 09468eeae..c82f29adb 100644 --- a/src/tools/clippy/tests/ui/repl_uninit.stderr +++ b/src/tools/clippy/tests/ui/repl_uninit.stderr @@ -5,15 +5,16 @@ LL | let taken_v = mem::replace(&mut v, mem::uninitialized()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(&mut v)` | = note: `-D clippy::mem-replace-with-uninit` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_uninit)]` error: replacing with `mem::MaybeUninit::uninit().assume_init()` - --> $DIR/repl_uninit.rs:21:23 + --> $DIR/repl_uninit.rs:23:23 | LL | let taken_v = mem::replace(&mut v, mem::MaybeUninit::uninit().assume_init()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(&mut v)` error: replacing with `mem::zeroed()` - --> $DIR/repl_uninit.rs:27:23 + --> $DIR/repl_uninit.rs:30:23 | LL | let taken_v = mem::replace(&mut v, mem::zeroed()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -21,7 +22,7 @@ LL | let taken_v = mem::replace(&mut v, mem::zeroed()); = help: consider using a default value or the `take_mut` crate instead error: replacing with `mem::uninitialized()` - --> $DIR/repl_uninit.rs:39:28 + --> $DIR/repl_uninit.rs:43:28 | LL | let taken_u = unsafe { mem::replace(uref, mem::uninitialized()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::ptr::read(uref)` diff --git a/src/tools/clippy/tests/ui/reserve_after_initialization.fixed b/src/tools/clippy/tests/ui/reserve_after_initialization.fixed new file mode 100644 index 000000000..067527784 --- /dev/null +++ b/src/tools/clippy/tests/ui/reserve_after_initialization.fixed @@ -0,0 +1,48 @@ +//@aux-build:proc_macros.rs +#![warn(clippy::reserve_after_initialization)] +#![no_main] + +extern crate proc_macros; +use proc_macros::{external, with_span}; + +// Should lint +fn standard() { + let mut v1: Vec = Vec::with_capacity(10); +} + +// Should lint +fn capacity_as_expr() { + let capacity = 10; + let mut v2: Vec = Vec::with_capacity(capacity); +} + +// Shouldn't lint +fn vec_init_with_argument() { + let mut v3 = vec![1]; + v3.reserve(10); +} + +// Shouldn't lint +fn called_with_capacity() { + let _v4: Vec = Vec::with_capacity(10); +} + +// Should lint +fn assign_expression() { + let mut v5: Vec = Vec::new(); + v5 = Vec::with_capacity(10); +} + +fn in_macros() { + external! { + let mut v: Vec = vec![]; + v.reserve(10); + } + + with_span! { + span + + let mut v: Vec = vec![]; + v.reserve(10); + } +} diff --git a/src/tools/clippy/tests/ui/reserve_after_initialization.rs b/src/tools/clippy/tests/ui/reserve_after_initialization.rs new file mode 100644 index 000000000..b57a8e162 --- /dev/null +++ b/src/tools/clippy/tests/ui/reserve_after_initialization.rs @@ -0,0 +1,51 @@ +//@aux-build:proc_macros.rs +#![warn(clippy::reserve_after_initialization)] +#![no_main] + +extern crate proc_macros; +use proc_macros::{external, with_span}; + +// Should lint +fn standard() { + let mut v1: Vec = vec![]; + v1.reserve(10); +} + +// Should lint +fn capacity_as_expr() { + let capacity = 10; + let mut v2: Vec = vec![]; + v2.reserve(capacity); +} + +// Shouldn't lint +fn vec_init_with_argument() { + let mut v3 = vec![1]; + v3.reserve(10); +} + +// Shouldn't lint +fn called_with_capacity() { + let _v4: Vec = Vec::with_capacity(10); +} + +// Should lint +fn assign_expression() { + let mut v5: Vec = Vec::new(); + v5 = Vec::new(); + v5.reserve(10); +} + +fn in_macros() { + external! { + let mut v: Vec = vec![]; + v.reserve(10); + } + + with_span! { + span + + let mut v: Vec = vec![]; + v.reserve(10); + } +} diff --git a/src/tools/clippy/tests/ui/reserve_after_initialization.stderr b/src/tools/clippy/tests/ui/reserve_after_initialization.stderr new file mode 100644 index 000000000..a91033890 --- /dev/null +++ b/src/tools/clippy/tests/ui/reserve_after_initialization.stderr @@ -0,0 +1,26 @@ +error: call to `reserve` immediately after creation + --> $DIR/reserve_after_initialization.rs:10:5 + | +LL | / let mut v1: Vec = vec![]; +LL | | v1.reserve(10); + | |___________________^ help: consider using `Vec::with_capacity(/* Space hint */)`: `let mut v1: Vec = Vec::with_capacity(10);` + | + = note: `-D clippy::reserve-after-initialization` implied by `-D warnings` + = 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 + | +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 + | +LL | / v5 = Vec::new(); +LL | | v5.reserve(10); + | |___________________^ help: consider using `Vec::with_capacity(/* Space hint */)`: `v5 = Vec::with_capacity(10);` + +error: aborting due to 3 previous errors + diff --git a/src/tools/clippy/tests/ui/rest_pat_in_fully_bound_structs.rs b/src/tools/clippy/tests/ui/rest_pat_in_fully_bound_structs.rs index 086331af6..e25609f75 100644 --- a/src/tools/clippy/tests/ui/rest_pat_in_fully_bound_structs.rs +++ b/src/tools/clippy/tests/ui/rest_pat_in_fully_bound_structs.rs @@ -20,13 +20,16 @@ fn main() { match a_struct { A { a: 5, b: 42, c: "", .. } => {}, // Lint - A { a: 0, b: 0, c: "", .. } => {}, // Lint + //~^ ERROR: unnecessary use of `..` pattern in struct binding. All fields were alr + A { a: 0, b: 0, c: "", .. } => {}, // Lint + //~^ ERROR: unnecessary use of `..` pattern in struct binding. All fields were alr _ => {}, } match a_struct { A { a: 5, b: 42, .. } => {}, A { a: 0, b: 0, c: "", .. } => {}, // Lint + //~^ ERROR: unnecessary use of `..` pattern in struct binding. All fields were alr _ => {}, } diff --git a/src/tools/clippy/tests/ui/rest_pat_in_fully_bound_structs.stderr b/src/tools/clippy/tests/ui/rest_pat_in_fully_bound_structs.stderr index e15633fb1..2c221b4db 100644 --- a/src/tools/clippy/tests/ui/rest_pat_in_fully_bound_structs.stderr +++ b/src/tools/clippy/tests/ui/rest_pat_in_fully_bound_structs.stderr @@ -6,17 +6,18 @@ LL | A { a: 5, b: 42, c: "", .. } => {}, // Lint | = help: consider removing `..` from this binding = note: `-D clippy::rest-pat-in-fully-bound-structs` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::rest_pat_in_fully_bound_structs)]` error: unnecessary use of `..` pattern in struct binding. All fields were already bound - --> $DIR/rest_pat_in_fully_bound_structs.rs:23:9 + --> $DIR/rest_pat_in_fully_bound_structs.rs:24:9 | -LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint +LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider removing `..` from this binding error: unnecessary use of `..` pattern in struct binding. All fields were already bound - --> $DIR/rest_pat_in_fully_bound_structs.rs:29:9 + --> $DIR/rest_pat_in_fully_bound_structs.rs:31:9 | LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/result_large_err.rs b/src/tools/clippy/tests/ui/result_large_err.rs index 1c12cebfd..b25348bf9 100644 --- a/src/tools/clippy/tests/ui/result_large_err.rs +++ b/src/tools/clippy/tests/ui/result_large_err.rs @@ -1,3 +1,5 @@ +//@ignore-32bit + #![warn(clippy::result_large_err)] #![allow(clippy::large_enum_variant)] @@ -6,6 +8,7 @@ pub fn small_err() -> Result<(), u128> { } pub fn large_err() -> Result<(), [u8; 512]> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } @@ -17,16 +20,19 @@ pub struct FullyDefinedLargeError { impl FullyDefinedLargeError { pub fn ret() -> Result<(), Self> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } } pub fn struct_error() -> Result<(), FullyDefinedLargeError> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } type Fdlr = std::result::Result; pub fn large_err_via_type_alias(x: T) -> Fdlr { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(x) } @@ -35,6 +41,7 @@ pub fn param_small_error() -> Result<(), (R, u128)> { } pub fn param_large_error() -> Result<(), (u128, R, FullyDefinedLargeError)> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } @@ -46,6 +53,7 @@ pub enum LargeErrorVariants { impl LargeErrorVariants<()> { pub fn large_enum_error() -> Result<(), Self> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } } @@ -58,12 +66,14 @@ enum MultipleLargeVariants { impl MultipleLargeVariants { fn large_enum_error() -> Result<(), Self> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } } trait TraitForcesLargeError { fn large_error() -> Result<(), [u8; 512]> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } } @@ -83,6 +93,7 @@ pub union FullyDefinedUnionError { } pub fn large_union_err() -> Result<(), FullyDefinedUnionError> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } @@ -92,6 +103,7 @@ pub union UnionError { } pub fn param_large_union() -> Result<(), UnionError> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } @@ -101,10 +113,12 @@ pub struct ArrayError { } pub fn array_error_subst() -> Result<(), ArrayError> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } pub fn array_error() -> Result<(), ArrayError<(i32, T), U>> { + //~^ ERROR: the `Err`-variant returned from this function is very large Ok(()) } diff --git a/src/tools/clippy/tests/ui/result_large_err.stderr b/src/tools/clippy/tests/ui/result_large_err.stderr index c386edfd2..6602f396a 100644 --- a/src/tools/clippy/tests/ui/result_large_err.stderr +++ b/src/tools/clippy/tests/ui/result_large_err.stderr @@ -1,14 +1,15 @@ error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:8:23 + --> $DIR/result_large_err.rs:10:23 | LL | pub fn large_err() -> Result<(), [u8; 512]> { | ^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes | = help: try reducing the size of `[u8; 512]`, for example by boxing large elements or replacing it with `Box<[u8; 512]>` = note: `-D clippy::result-large-err` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_large_err)]` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:19:21 + --> $DIR/result_large_err.rs:22:21 | LL | pub fn ret() -> Result<(), Self> { | ^^^^^^^^^^^^^^^^ the `Err`-variant is at least 240 bytes @@ -16,7 +17,7 @@ LL | pub fn ret() -> Result<(), Self> { = help: try reducing the size of `FullyDefinedLargeError`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:24:26 + --> $DIR/result_large_err.rs:28:26 | LL | pub fn struct_error() -> Result<(), FullyDefinedLargeError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 240 bytes @@ -24,7 +25,7 @@ LL | pub fn struct_error() -> Result<(), FullyDefinedLargeError> { = help: try reducing the size of `FullyDefinedLargeError`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:29:45 + --> $DIR/result_large_err.rs:34:45 | LL | pub fn large_err_via_type_alias(x: T) -> Fdlr { | ^^^^^^^ the `Err`-variant is at least 240 bytes @@ -32,7 +33,7 @@ LL | pub fn large_err_via_type_alias(x: T) -> Fdlr { = help: try reducing the size of `FullyDefinedLargeError`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:37:34 + --> $DIR/result_large_err.rs:43:34 | LL | pub fn param_large_error() -> Result<(), (u128, R, FullyDefinedLargeError)> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 256 bytes @@ -40,7 +41,7 @@ LL | pub fn param_large_error() -> Result<(), (u128, R, FullyDefinedLargeErro = help: try reducing the size of `(u128, R, FullyDefinedLargeError)`, for example by boxing large elements or replacing it with `Box<(u128, R, FullyDefinedLargeError)>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:48:34 + --> $DIR/result_large_err.rs:55:34 | LL | _Omg([u8; 512]), | --------------- the largest variant contains at least 512 bytes @@ -51,7 +52,7 @@ LL | pub fn large_enum_error() -> Result<(), Self> { = help: try reducing the size of `LargeErrorVariants<()>`, for example by boxing large elements or replacing it with `Box>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:60:30 + --> $DIR/result_large_err.rs:68:30 | LL | _Biggest([u8; 1024]), | -------------------- the largest variant contains at least 1024 bytes @@ -64,7 +65,7 @@ LL | fn large_enum_error() -> Result<(), Self> { = help: try reducing the size of `MultipleLargeVariants`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:66:25 + --> $DIR/result_large_err.rs:75:25 | LL | fn large_error() -> Result<(), [u8; 512]> { | ^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes @@ -72,7 +73,7 @@ LL | fn large_error() -> Result<(), [u8; 512]> { = help: try reducing the size of `[u8; 512]`, for example by boxing large elements or replacing it with `Box<[u8; 512]>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:85:29 + --> $DIR/result_large_err.rs:95:29 | LL | pub fn large_union_err() -> Result<(), FullyDefinedUnionError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes @@ -80,7 +81,7 @@ LL | pub fn large_union_err() -> Result<(), FullyDefinedUnionError> { = help: try reducing the size of `FullyDefinedUnionError`, for example by boxing large elements or replacing it with `Box` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:94:40 + --> $DIR/result_large_err.rs:105:40 | LL | pub fn param_large_union() -> Result<(), UnionError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes @@ -88,7 +89,7 @@ LL | pub fn param_large_union() -> Result<(), UnionError> { = help: try reducing the size of `UnionError`, for example by boxing large elements or replacing it with `Box>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:103:34 + --> $DIR/result_large_err.rs:115:34 | LL | pub fn array_error_subst() -> Result<(), ArrayError> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 128 bytes @@ -96,7 +97,7 @@ LL | pub fn array_error_subst() -> Result<(), ArrayError> { = help: try reducing the size of `ArrayError`, for example by boxing large elements or replacing it with `Box>` error: the `Err`-variant returned from this function is very large - --> $DIR/result_large_err.rs:107:31 + --> $DIR/result_large_err.rs:120:31 | LL | pub fn array_error() -> Result<(), ArrayError<(i32, T), U>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 128 bytes diff --git a/src/tools/clippy/tests/ui/result_map_or_into_option.fixed b/src/tools/clippy/tests/ui/result_map_or_into_option.fixed index 6850eeb7a..fb2db6cf5 100644 --- a/src/tools/clippy/tests/ui/result_map_or_into_option.fixed +++ b/src/tools/clippy/tests/ui/result_map_or_into_option.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::result_map_or_into_option)] fn main() { diff --git a/src/tools/clippy/tests/ui/result_map_or_into_option.rs b/src/tools/clippy/tests/ui/result_map_or_into_option.rs index 8e1518144..06779a699 100644 --- a/src/tools/clippy/tests/ui/result_map_or_into_option.rs +++ b/src/tools/clippy/tests/ui/result_map_or_into_option.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::result_map_or_into_option)] fn main() { diff --git a/src/tools/clippy/tests/ui/result_map_or_into_option.stderr b/src/tools/clippy/tests/ui/result_map_or_into_option.stderr index febf32147..9396ea4c0 100644 --- a/src/tools/clippy/tests/ui/result_map_or_into_option.stderr +++ b/src/tools/clippy/tests/ui/result_map_or_into_option.stderr @@ -1,10 +1,11 @@ error: called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling `ok()` instead - --> $DIR/result_map_or_into_option.rs:7:13 + --> $DIR/result_map_or_into_option.rs:5:13 | LL | let _ = opt.map_or(None, Some); | ^^^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `opt.ok()` | = note: `-D clippy::result-map-or-into-option` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_map_or_into_option)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.fixed b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.fixed index 0583d2927..3890f916b 100644 --- a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.fixed +++ b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::result_map_unit_fn)] #![allow(unused)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.rs b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.rs index 7ad3bdd04..c3f5aca7b 100644 --- a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.rs +++ b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::result_map_unit_fn)] #![allow(unused)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.stderr b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.stderr index ad941fa8b..42ee273c2 100644 --- a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.stderr +++ b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.stderr @@ -1,5 +1,5 @@ error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:35:5 + --> $DIR/result_map_unit_fn_fixable.rs:34:5 | LL | x.field.map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^- @@ -7,9 +7,10 @@ LL | x.field.map(do_nothing); | help: try: `if let Ok(x_field) = x.field { do_nothing(x_field) }` | = note: `-D clippy::result-map-unit-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_map_unit_fn)]` error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:37:5 + --> $DIR/result_map_unit_fn_fixable.rs:36:5 | LL | x.field.map(do_nothing); | ^^^^^^^^^^^^^^^^^^^^^^^- @@ -17,7 +18,7 @@ LL | x.field.map(do_nothing); | help: try: `if let Ok(x_field) = x.field { do_nothing(x_field) }` error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_fixable.rs:39:5 + --> $DIR/result_map_unit_fn_fixable.rs:38:5 | LL | x.field.map(diverge); | ^^^^^^^^^^^^^^^^^^^^- @@ -25,7 +26,7 @@ LL | x.field.map(diverge); | help: try: `if let Ok(x_field) = x.field { diverge(x_field) }` 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:45:5 + --> $DIR/result_map_unit_fn_fixable.rs:44:5 | LL | x.field.map(|value| x.do_result_nothing(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -33,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:47:5 + --> $DIR/result_map_unit_fn_fixable.rs:46:5 | LL | x.field.map(|value| { x.do_result_plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -41,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:50:5 + --> $DIR/result_map_unit_fn_fixable.rs:49:5 | LL | x.field.map(|value| do_nothing(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -49,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:52:5 + --> $DIR/result_map_unit_fn_fixable.rs:51:5 | LL | x.field.map(|value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -57,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:54:5 + --> $DIR/result_map_unit_fn_fixable.rs:53:5 | LL | x.field.map(|value| { do_nothing(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -65,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:56:5 + --> $DIR/result_map_unit_fn_fixable.rs:55:5 | LL | x.field.map(|value| { { do_nothing(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -73,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:59:5 + --> $DIR/result_map_unit_fn_fixable.rs:58:5 | LL | x.field.map(|value| diverge(value + captured)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -81,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:61:5 + --> $DIR/result_map_unit_fn_fixable.rs:60:5 | LL | x.field.map(|value| { diverge(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -89,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:63:5 + --> $DIR/result_map_unit_fn_fixable.rs:62:5 | LL | x.field.map(|value| { diverge(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -97,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:65:5 + --> $DIR/result_map_unit_fn_fixable.rs:64:5 | LL | x.field.map(|value| { { diverge(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -105,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:70:5 + --> $DIR/result_map_unit_fn_fixable.rs:69:5 | LL | x.field.map(|value| { let y = plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -113,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:72:5 + --> $DIR/result_map_unit_fn_fixable.rs:71:5 | LL | x.field.map(|value| { plus_one(value + captured); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -121,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:74:5 + --> $DIR/result_map_unit_fn_fixable.rs:73:5 | LL | x.field.map(|value| { { plus_one(value + captured); } }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -129,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:77:5 + --> $DIR/result_map_unit_fn_fixable.rs:76:5 | LL | x.field.map(|ref value| { do_nothing(value + captured) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -137,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:79:5 + --> $DIR/result_map_unit_fn_fixable.rs:78:5 | LL | x.field.map(|value| println!("{:?}", value)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- diff --git a/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.rs b/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.rs index b197c609d..62798b6d3 100644 --- a/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.rs +++ b/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.rs @@ -1,7 +1,7 @@ #![warn(clippy::result_map_unit_fn)] #![feature(never_type)] -#![allow(unused)] - +#![allow(unused, clippy::unnecessary_map_on_constructor)] +//@no-rustfix struct HasResult { field: Result, } @@ -21,26 +21,33 @@ fn result_map_unit_fn() { let x = HasResult { field: Ok(10) }; x.field.map(|value| { do_nothing(value); do_nothing(value) }); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a closure that returns t + //~| NOTE: `-D clippy::result-map-unit-fn` implied by `-D warnings` x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a closure that returns t // Suggestion for the let block should be `{ ... }` as it's too difficult to build a // proper suggestion for these cases x.field.map(|value| { + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a closure that returns t do_nothing(value); do_nothing(value) }); x.field.map(|value| { do_nothing(value); do_nothing(value); }); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a closure that returns t // The following should suggest `if let Ok(_X) ...` as it's difficult to generate a proper let variable name for them let res: Result = Ok(42).map(diverge); "12".parse::().map(diverge); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a function that returns let res: Result<(), usize> = Ok(plus_one(1)).map(do_nothing); // Should suggest `if let Ok(_y) ...` to not override the existing foo variable let y: Result = Ok(42); y.map(do_nothing); + //~^ ERROR: called `map(f)` on an `Result` value where `f` is a function that returns } fn main() {} diff --git a/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr b/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr index 75ec1ba80..ccf9bfb94 100644 --- a/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr +++ b/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr @@ -7,9 +7,10 @@ LL | x.field.map(|value| { do_nothing(value); do_nothing(value) }); | help: try: `if let Ok(value) = x.field { ... }` | = note: `-D clippy::result-map-unit-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_map_unit_fn)]` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:25:5 + --> $DIR/result_map_unit_fn_unfixable.rs:27:5 | LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -17,9 +18,10 @@ LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) | help: try: `if let Ok(value) = x.field { ... }` error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:29:5 + --> $DIR/result_map_unit_fn_unfixable.rs:32:5 | LL | // x.field.map(|value| { +LL | || LL | || do_nothing(value); LL | || do_nothing(value) LL | || }); @@ -28,7 +30,7 @@ LL | || }); | error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:33:5 + --> $DIR/result_map_unit_fn_unfixable.rs:37:5 | LL | x.field.map(|value| { do_nothing(value); do_nothing(value); }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -36,7 +38,7 @@ LL | x.field.map(|value| { do_nothing(value); do_nothing(value); }); | help: try: `if let Ok(value) = x.field { ... }` error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:37:5 + --> $DIR/result_map_unit_fn_unfixable.rs:42:5 | LL | "12".parse::().map(diverge); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- @@ -44,7 +46,7 @@ LL | "12".parse::().map(diverge); | help: try: `if let Ok(a) = "12".parse::() { diverge(a) }` error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()` - --> $DIR/result_map_unit_fn_unfixable.rs:43:5 + --> $DIR/result_map_unit_fn_unfixable.rs:49:5 | LL | y.map(do_nothing); | ^^^^^^^^^^^^^^^^^- diff --git a/src/tools/clippy/tests/ui/result_unit_error.rs b/src/tools/clippy/tests/ui/result_unit_error.rs index a4ec80302..f3159f2e9 100644 --- a/src/tools/clippy/tests/ui/result_unit_error.rs +++ b/src/tools/clippy/tests/ui/result_unit_error.rs @@ -1,6 +1,7 @@ #![warn(clippy::result_unit_err)] pub fn returns_unit_error() -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Err(()) } @@ -10,8 +11,10 @@ fn private_unit_errors() -> Result { pub trait HasUnitError { fn get_that_error(&self) -> Result; + //~^ ERROR: this returns a `Result<_, ()>` fn get_this_one_too(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Err(()) } } @@ -30,6 +33,7 @@ pub struct UnitErrorHolder; impl UnitErrorHolder { pub fn unit_error(&self) -> Result { + //~^ ERROR: this returns a `Result<_, ()>` Ok(0) } } @@ -39,6 +43,7 @@ pub mod issue_6546 { type ResInv = Result; pub fn should_lint() -> ResInv<(), usize> { + //~^ ERROR: this returns a `Result<_, ()>` Ok(0) } diff --git a/src/tools/clippy/tests/ui/result_unit_error.stderr b/src/tools/clippy/tests/ui/result_unit_error.stderr index 8393a4bf0..72208f539 100644 --- a/src/tools/clippy/tests/ui/result_unit_error.stderr +++ b/src/tools/clippy/tests/ui/result_unit_error.stderr @@ -6,9 +6,10 @@ LL | pub fn returns_unit_error() -> Result { | = help: use a custom `Error` type instead = note: `-D clippy::result-unit-err` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::result_unit_err)]` error: this returns a `Result<_, ()>` - --> $DIR/result_unit_error.rs:12:5 + --> $DIR/result_unit_error.rs:13:5 | LL | fn get_that_error(&self) -> Result; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | fn get_that_error(&self) -> Result; = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/result_unit_error.rs:14:5 + --> $DIR/result_unit_error.rs:16:5 | LL | fn get_this_one_too(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | fn get_this_one_too(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/result_unit_error.rs:32:5 + --> $DIR/result_unit_error.rs:35:5 | LL | pub fn unit_error(&self) -> Result { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | pub fn unit_error(&self) -> Result { = help: use a custom `Error` type instead error: this returns a `Result<_, ()>` - --> $DIR/result_unit_error.rs:41:5 + --> $DIR/result_unit_error.rs:45:5 | LL | pub fn should_lint() -> ResInv<(), usize> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/return_self_not_must_use.rs b/src/tools/clippy/tests/ui/return_self_not_must_use.rs index 9b33ad6d3..ec6f0feb8 100644 --- a/src/tools/clippy/tests/ui/return_self_not_must_use.rs +++ b/src/tools/clippy/tests/ui/return_self_not_must_use.rs @@ -6,6 +6,7 @@ pub struct Bar; pub trait Whatever { fn what(&self) -> Self; + //~^ ERROR: missing `#[must_use]` attribute on a method returning `Self` // There should be no warning here! (returns a reference) fn what2(&self) -> &Self; } @@ -16,9 +17,11 @@ impl Bar { Self } pub fn foo(&self) -> Self { + //~^ ERROR: missing `#[must_use]` attribute on a method returning `Self` Self } pub fn bar(self) -> Self { + //~^ ERROR: missing `#[must_use]` attribute on a method returning `Self` self } // There should be no warning here! (private method) diff --git a/src/tools/clippy/tests/ui/return_self_not_must_use.stderr b/src/tools/clippy/tests/ui/return_self_not_must_use.stderr index 34932fe1c..b3e41470d 100644 --- a/src/tools/clippy/tests/ui/return_self_not_must_use.stderr +++ b/src/tools/clippy/tests/ui/return_self_not_must_use.stderr @@ -6,11 +6,13 @@ LL | fn what(&self) -> Self; | = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type = note: `-D clippy::return-self-not-must-use` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::return_self_not_must_use)]` error: missing `#[must_use]` attribute on a method returning `Self` - --> $DIR/return_self_not_must_use.rs:18:5 + --> $DIR/return_self_not_must_use.rs:19:5 | LL | / pub fn foo(&self) -> Self { +LL | | LL | | Self LL | | } | |_____^ @@ -18,9 +20,10 @@ LL | | } = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type error: missing `#[must_use]` attribute on a method returning `Self` - --> $DIR/return_self_not_must_use.rs:21:5 + --> $DIR/return_self_not_must_use.rs:23:5 | LL | / pub fn bar(self) -> Self { +LL | | LL | | self LL | | } | |_____^ diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed index 30dfc9776..c8bf1b350 100644 --- a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed +++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::reversed_empty_ranges)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs index 1837249ea..6733c0964 100644 --- a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs +++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::reversed_empty_ranges)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.stderr b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.stderr index c2495ea95..92fbac8e3 100644 --- a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.stderr +++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.stderr @@ -1,17 +1,18 @@ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_fixable.rs:10:5 + --> $DIR/reversed_empty_ranges_fixable.rs:9:5 | LL | (42..=21).for_each(|x| println!("{}", x)); | ^^^^^^^^^ | = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` help: consider using the following if you are attempting to iterate over this range in reverse | 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:11:13 + --> $DIR/reversed_empty_ranges_fixable.rs:10:13 | LL | let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::>(); | ^^^^^^^^^^^^ @@ -22,7 +23,7 @@ LL | let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect:: $DIR/reversed_empty_ranges_fixable.rs:13:14 + --> $DIR/reversed_empty_ranges_fixable.rs:12:14 | LL | for _ in -21..=-42 {} | ^^^^^^^^^ @@ -33,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:14:14 + --> $DIR/reversed_empty_ranges_fixable.rs:13:14 | LL | for _ in 42u32..21u32 {} | ^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed index a74569599..df5f2c441 100644 --- a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed +++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::reversed_empty_ranges)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs index 42f9957df..92481be6c 100644 --- a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs +++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::reversed_empty_ranges)] #![allow(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.stderr b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.stderr index dfc52e64c..843d6a36d 100644 --- a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.stderr +++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.stderr @@ -1,17 +1,18 @@ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_fixable.rs:8:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:7:14 | LL | for i in 10..0 { | ^^^^^ | = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` help: consider using the following if you are attempting to iterate over this range in reverse | 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:12:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:11:14 | LL | for i in 10..=0 { | ^^^^^^ @@ -22,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:16:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:15:14 | LL | for i in MAX_LEN..0 { | ^^^^^^^^^^ @@ -33,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:35:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:34:14 | LL | for i in (10..0).map(|x| x * 2) { | ^^^^^^^ @@ -44,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:40:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:39:14 | LL | for i in 10..5 + 4 { | ^^^^^^^^^ @@ -55,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:44:14 + --> $DIR/reversed_empty_ranges_loops_fixable.rs:43:14 | LL | for i in (5 + 2)..(3 - 1) { | ^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.rs b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.rs index 50264ef68..cd1701dd4 100644 --- a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.rs +++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.rs @@ -3,10 +3,13 @@ fn main() { for i in 5..5 { + //~^ ERROR: this range is empty so it will yield no values + //~| NOTE: `-D clippy::reversed-empty-ranges` implied by `-D warnings` println!("{}", i); } for i in (5 + 2)..(8 - 1) { + //~^ ERROR: this range is empty so it will yield no values println!("{}", i); } } diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.stderr b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.stderr index 4490ff35f..73165e091 100644 --- a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.stderr +++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.stderr @@ -5,9 +5,10 @@ LL | for i in 5..5 { | ^^^^ | = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_loops_unfixable.rs:9:14 + --> $DIR/reversed_empty_ranges_loops_unfixable.rs:11:14 | LL | for i in (5 + 2)..(8 - 1) { | ^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_unfixable.rs b/src/tools/clippy/tests/ui/reversed_empty_ranges_unfixable.rs index 264d3d1e9..16c1121ae 100644 --- a/src/tools/clippy/tests/ui/reversed_empty_ranges_unfixable.rs +++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_unfixable.rs @@ -6,9 +6,13 @@ const SOME_NUM: usize = 3; fn main() { let arr = [1, 2, 3, 4, 5]; let _ = &arr[3usize..=1usize]; + //~^ ERROR: this range is reversed and using it to index a slice will panic at run-tim + //~| NOTE: `-D clippy::reversed-empty-ranges` implied by `-D warnings` let _ = &arr[SOME_NUM..1]; + //~^ ERROR: this range is reversed and using it to index a slice will panic at run-tim for _ in ANSWER..ANSWER {} + //~^ ERROR: this range is empty so it will yield no values // Should not be linted, see issue #5689 let _ = (42 + 10..42 + 10).map(|x| x / 2).find(|&x| x == 21); diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_unfixable.stderr b/src/tools/clippy/tests/ui/reversed_empty_ranges_unfixable.stderr index f23d4eb0f..e3dc96dfb 100644 --- a/src/tools/clippy/tests/ui/reversed_empty_ranges_unfixable.stderr +++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_unfixable.stderr @@ -5,15 +5,16 @@ LL | let _ = &arr[3usize..=1usize]; | ^^^^^^^^^^^^^^^ | = note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::reversed_empty_ranges)]` error: this range is reversed and using it to index a slice will panic at run-time - --> $DIR/reversed_empty_ranges_unfixable.rs:9:18 + --> $DIR/reversed_empty_ranges_unfixable.rs:11:18 | LL | let _ = &arr[SOME_NUM..1]; | ^^^^^^^^^^^ error: this range is empty so it will yield no values - --> $DIR/reversed_empty_ranges_unfixable.rs:11:14 + --> $DIR/reversed_empty_ranges_unfixable.rs:14:14 | LL | for _ in ANSWER..ANSWER {} | ^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/same_item_push.rs b/src/tools/clippy/tests/ui/same_item_push.rs index af01a8df7..df9c2817f 100644 --- a/src/tools/clippy/tests/ui/same_item_push.rs +++ b/src/tools/clippy/tests/ui/same_item_push.rs @@ -21,28 +21,33 @@ fn main() { let item = 2; for _ in 5..=20 { vec.push(item); + //~^ ERROR: it looks like the same item is being pushed into this Vec } let mut vec: Vec = Vec::new(); for _ in 0..15 { let item = 2; vec.push(item); + //~^ ERROR: it looks like the same item is being pushed into this Vec } let mut vec: Vec = Vec::new(); for _ in 0..15 { vec.push(13); + //~^ ERROR: it looks like the same item is being pushed into this Vec } let mut vec = Vec::new(); for _ in 0..20 { vec.push(VALUE); + //~^ ERROR: it looks like the same item is being pushed into this Vec } let mut vec = Vec::new(); let item = VALUE; for _ in 0..20 { vec.push(item); + //~^ ERROR: it looks like the same item is being pushed into this Vec } // ** non-linted cases ** diff --git a/src/tools/clippy/tests/ui/same_item_push.stderr b/src/tools/clippy/tests/ui/same_item_push.stderr index 1d1254d9f..f519be463 100644 --- a/src/tools/clippy/tests/ui/same_item_push.stderr +++ b/src/tools/clippy/tests/ui/same_item_push.stderr @@ -6,9 +6,10 @@ LL | vec.push(item); | = help: try using vec![item;SIZE] or vec.resize(NEW_SIZE, item) = note: `-D clippy::same-item-push` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::same_item_push)]` error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:29:9 + --> $DIR/same_item_push.rs:30:9 | LL | vec.push(item); | ^^^ @@ -16,7 +17,7 @@ LL | vec.push(item); = help: try using vec![item;SIZE] or vec.resize(NEW_SIZE, item) error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:34:9 + --> $DIR/same_item_push.rs:36:9 | LL | vec.push(13); | ^^^ @@ -24,7 +25,7 @@ LL | vec.push(13); = help: try using vec![13;SIZE] or vec.resize(NEW_SIZE, 13) error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:39:9 + --> $DIR/same_item_push.rs:42:9 | LL | vec.push(VALUE); | ^^^ @@ -32,7 +33,7 @@ LL | vec.push(VALUE); = help: try using vec![VALUE;SIZE] or vec.resize(NEW_SIZE, VALUE) error: it looks like the same item is being pushed into this Vec - --> $DIR/same_item_push.rs:45:9 + --> $DIR/same_item_push.rs:49:9 | LL | vec.push(item); | ^^^ diff --git a/src/tools/clippy/tests/ui/same_name_method.rs b/src/tools/clippy/tests/ui/same_name_method.rs index f31a7e33c..1c166a19b 100644 --- a/src/tools/clippy/tests/ui/same_name_method.rs +++ b/src/tools/clippy/tests/ui/same_name_method.rs @@ -19,6 +19,7 @@ mod should_lint { impl S { fn foo() {} + //~^ ERROR: method's name is the same as an existing method in a trait } impl T1 for S { @@ -33,6 +34,7 @@ mod should_lint { impl S { fn clone() {} + //~^ ERROR: method's name is the same as an existing method in a trait } } @@ -43,6 +45,7 @@ mod should_lint { impl S { fn foo() {} + //~^ ERROR: method's name is the same as an existing method in a trait } impl T1 for S { @@ -57,6 +60,7 @@ mod should_lint { impl S { fn foo() {} + //~^ ERROR: method's name is the same as an existing method in a trait } impl T1 for S {} @@ -69,6 +73,7 @@ mod should_lint { impl S { fn foo() {} + //~^ ERROR: method's name is the same as an existing method in a trait } impl T1 for S {} diff --git a/src/tools/clippy/tests/ui/same_name_method.stderr b/src/tools/clippy/tests/ui/same_name_method.stderr index 0c6908c09..3c5c4a53a 100644 --- a/src/tools/clippy/tests/ui/same_name_method.stderr +++ b/src/tools/clippy/tests/ui/same_name_method.stderr @@ -5,57 +5,58 @@ LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> $DIR/same_name_method.rs:25:13 + --> $DIR/same_name_method.rs:26:13 | LL | fn foo() {} | ^^^^^^^^^^^ = note: `-D clippy::same-name-method` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::same_name_method)]` error: method's name is the same as an existing method in a trait - --> $DIR/same_name_method.rs:35:13 + --> $DIR/same_name_method.rs:36:13 | LL | fn clone() {} | ^^^^^^^^^^^^^ | note: existing `clone` defined here - --> $DIR/same_name_method.rs:31:18 + --> $DIR/same_name_method.rs:32:18 | LL | #[derive(Clone)] | ^^^^^ = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) error: method's name is the same as an existing method in a trait - --> $DIR/same_name_method.rs:45:13 + --> $DIR/same_name_method.rs:47:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> $DIR/same_name_method.rs:49:13 + --> $DIR/same_name_method.rs:52:13 | LL | fn foo() {} | ^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> $DIR/same_name_method.rs:59:13 + --> $DIR/same_name_method.rs:62:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> $DIR/same_name_method.rs:62:9 + --> $DIR/same_name_method.rs:66:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ error: method's name is the same as an existing method in a trait - --> $DIR/same_name_method.rs:71:13 + --> $DIR/same_name_method.rs:75:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here - --> $DIR/same_name_method.rs:74:9 + --> $DIR/same_name_method.rs:79:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/search_is_some.rs b/src/tools/clippy/tests/ui/search_is_some.rs index 3cdbfaa16..e8a0920b6 100644 --- a/src/tools/clippy/tests/ui/search_is_some.rs +++ b/src/tools/clippy/tests/ui/search_is_some.rs @@ -4,7 +4,7 @@ #![allow(dead_code)] extern crate option_helpers; use option_helpers::IteratorFalsePositives; - +//@no-rustfix #[rustfmt::skip] fn main() { let v = vec![3, 2, 1, 0, -1, -2, -3]; diff --git a/src/tools/clippy/tests/ui/search_is_some.stderr b/src/tools/clippy/tests/ui/search_is_some.stderr index 7eff614d1..a7a47447f 100644 --- a/src/tools/clippy/tests/ui/search_is_some.stderr +++ b/src/tools/clippy/tests/ui/search_is_some.stderr @@ -10,6 +10,7 @@ LL | | ).is_some(); | = help: this is more succinctly expressed by calling `any()` = note: `-D clippy::search-is-some` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/search_is_some_fixable_none.fixed b/src/tools/clippy/tests/ui/search_is_some_fixable_none.fixed index 08fb87cb3..51636392f 100644 --- a/src/tools/clippy/tests/ui/search_is_some_fixable_none.fixed +++ b/src/tools/clippy/tests/ui/search_is_some_fixable_none.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)] #![warn(clippy::search_is_some)] diff --git a/src/tools/clippy/tests/ui/search_is_some_fixable_none.rs b/src/tools/clippy/tests/ui/search_is_some_fixable_none.rs index ec3386933..c7d773e18 100644 --- a/src/tools/clippy/tests/ui/search_is_some_fixable_none.rs +++ b/src/tools/clippy/tests/ui/search_is_some_fixable_none.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)] #![warn(clippy::search_is_some)] diff --git a/src/tools/clippy/tests/ui/search_is_some_fixable_none.stderr b/src/tools/clippy/tests/ui/search_is_some_fixable_none.stderr index 933ce5cf4..f33b04309 100644 --- a/src/tools/clippy/tests/ui/search_is_some_fixable_none.stderr +++ b/src/tools/clippy/tests/ui/search_is_some_fixable_none.stderr @@ -1,55 +1,56 @@ 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:9:13 | LL | let _ = v.iter().find(|&x| *x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|x| *x < 0)` | = note: `-D clippy::search-is-some` implied by `-D warnings` + = 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:11:13 + --> $DIR/search_is_some_fixable_none.rs:10:13 | LL | let _ = (0..1).find(|x| **y == *x).is_none(); // one dereference less | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(0..1).any(|x| **y == x)` 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:11:13 | LL | let _ = (0..1).find(|x| *x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(0..1).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:12:13 | LL | let _ = v.iter().find(|x| **x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|x| *x == 0)` 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:13:13 | LL | let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(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:15:13 + --> $DIR/search_is_some_fixable_none.rs:14:13 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(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:16:13 + --> $DIR/search_is_some_fixable_none.rs:15:13 | LL | let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(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:17:13 + --> $DIR/search_is_some_fixable_none.rs:16:13 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(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:18:13 + --> $DIR/search_is_some_fixable_none.rs:17:13 | LL | let _ = (1..3) | _____________^ @@ -58,91 +59,91 @@ LL | | .is_none(); | |__________________^ help: use `!_.any()` instead: `!(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:23:13 + --> $DIR/search_is_some_fixable_none.rs:22:13 | LL | let _ = v.iter().position(|&x| x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|&x| x < 0)` error: called `is_none()` after searching an `Iterator` with `rposition` - --> $DIR/search_is_some_fixable_none.rs:26:13 + --> $DIR/search_is_some_fixable_none.rs:25:13 | LL | let _ = v.iter().rposition(|&x| x < 0).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|&x| x < 0)` 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:31:13 | LL | let _ = "hello world".find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!"hello world".contains("world")` 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:32:13 | LL | let _ = "hello world".find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!"hello world".contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:34:13 + --> $DIR/search_is_some_fixable_none.rs:33:13 | LL | let _ = "hello world".find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!"hello world".contains(&s2[2..])` 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:35:13 | LL | let _ = s1.find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1.contains("world")` 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:36:13 | LL | let _ = s1.find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1.contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:38:13 + --> $DIR/search_is_some_fixable_none.rs:37:13 | LL | let _ = s1.find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1.contains(&s2[2..])` 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:39:13 | LL | let _ = s1[2..].find("world").is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1[2..].contains("world")` 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:40:13 | LL | let _ = s1[2..].find(&s2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1[2..].contains(&s2)` error: called `is_none()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_none.rs:42:13 + --> $DIR/search_is_some_fixable_none.rs:41:13 | LL | let _ = s1[2..].find(&s2[2..]).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.contains()` instead: `!s1[2..].contains(&s2[2..])` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:58:25 + --> $DIR/search_is_some_fixable_none.rs:57:25 | LL | .filter(|c| filter_hand.iter().find(|cc| c == cc).is_none()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!filter_hand.iter().any(|cc| c == &cc)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:74:30 + --> $DIR/search_is_some_fixable_none.rs:73:30 | LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_none()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!filter_hand.iter().any(|cc| c == cc)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:85:17 + --> $DIR/search_is_some_fixable_none.rs:84:17 | LL | let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!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:88:17 + --> $DIR/search_is_some_fixable_none.rs:87:17 | LL | let _ = vfoo | _________________^ @@ -158,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:96:17 + --> $DIR/search_is_some_fixable_none.rs:95:17 | LL | let _ = vfoo.iter().find(|a| a[0] == 42).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!vfoo.iter().any(|a| a[0] == 42)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:102:17 + --> $DIR/search_is_some_fixable_none.rs:101:17 | LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!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:120:17 + --> $DIR/search_is_some_fixable_none.rs:119:17 | LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `![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:121:17 + --> $DIR/search_is_some_fixable_none.rs:120:17 | LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `![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:124:17 + --> $DIR/search_is_some_fixable_none.rs:123:17 | LL | let _ = v.iter().find(|x| deref_enough(**x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|x| deref_enough(*x))` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:125:17 + --> $DIR/search_is_some_fixable_none.rs:124:17 | LL | let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!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:128:17 + --> $DIR/search_is_some_fixable_none.rs:127:17 | LL | let _ = v.iter().find(|x| arg_no_deref(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!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:130:17 + --> $DIR/search_is_some_fixable_none.rs:129:17 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!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:150:17 + --> $DIR/search_is_some_fixable_none.rs:149:17 | LL | let _ = vfoo | _________________^ @@ -222,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:166:17 + --> $DIR/search_is_some_fixable_none.rs:165:17 | LL | let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!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:171:17 + --> $DIR/search_is_some_fixable_none.rs:170:17 | LL | let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!vfoo.iter().any(|x| (**x)[0] == 9)` error: called `is_none()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_none.rs:184:17 + --> $DIR/search_is_some_fixable_none.rs:183:17 | LL | let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!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:188:17 + --> $DIR/search_is_some_fixable_none.rs:187:17 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `![&(&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:189:17 + --> $DIR/search_is_some_fixable_none.rs:188:17 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `![&(&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:208:17 + --> $DIR/search_is_some_fixable_none.rs:207:17 | LL | let _ = v.iter().find(|s| s[0].is_empty()).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!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:209:17 + --> $DIR/search_is_some_fixable_none.rs:208:17 | LL | let _ = v.iter().find(|s| test_string_1(&s[0])).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!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:218:17 + --> $DIR/search_is_some_fixable_none.rs:217:17 | LL | let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!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:219:17 + --> $DIR/search_is_some_fixable_none.rs:218:17 | LL | let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!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:220:17 + --> $DIR/search_is_some_fixable_none.rs:219:17 | LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_none(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!v.iter().any(|fp| test_u32_2(*fp.field))` diff --git a/src/tools/clippy/tests/ui/search_is_some_fixable_some.fixed b/src/tools/clippy/tests/ui/search_is_some_fixable_some.fixed index aa16f9da0..ae3cbc3c4 100644 --- a/src/tools/clippy/tests/ui/search_is_some_fixable_some.fixed +++ b/src/tools/clippy/tests/ui/search_is_some_fixable_some.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)] #![warn(clippy::search_is_some)] diff --git a/src/tools/clippy/tests/ui/search_is_some_fixable_some.rs b/src/tools/clippy/tests/ui/search_is_some_fixable_some.rs index aeb6f118b..19a44803f 100644 --- a/src/tools/clippy/tests/ui/search_is_some_fixable_some.rs +++ b/src/tools/clippy/tests/ui/search_is_some_fixable_some.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)] #![warn(clippy::search_is_some)] diff --git a/src/tools/clippy/tests/ui/search_is_some_fixable_some.stderr b/src/tools/clippy/tests/ui/search_is_some_fixable_some.stderr index c5c3c92c9..e878e62de 100644 --- a/src/tools/clippy/tests/ui/search_is_some_fixable_some.stderr +++ b/src/tools/clippy/tests/ui/search_is_some_fixable_some.stderr @@ -1,55 +1,56 @@ error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:10:22 + --> $DIR/search_is_some_fixable_some.rs:9:22 | LL | let _ = v.iter().find(|&x| *x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| *x < 0)` | = note: `-D clippy::search-is-some` implied by `-D warnings` + = 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:11:20 + --> $DIR/search_is_some_fixable_some.rs:10:20 | LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| **y == x)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:12:20 + --> $DIR/search_is_some_fixable_some.rs:11:20 | LL | let _ = (0..1).find(|x| *x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| x == 0)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:13:22 + --> $DIR/search_is_some_fixable_some.rs:12:22 | LL | let _ = v.iter().find(|x| **x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| *x == 0)` 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:13:20 | LL | let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `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:15:20 + --> $DIR/search_is_some_fixable_some.rs:14:20 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| [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:15:20 | LL | let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `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:17:20 + --> $DIR/search_is_some_fixable_some.rs:16:20 | LL | let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `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:19:10 + --> $DIR/search_is_some_fixable_some.rs:18:10 | LL | .find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1) | __________^ @@ -57,91 +58,91 @@ LL | | .is_some(); | |__________________^ help: use `any()` instead: `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:23:22 + --> $DIR/search_is_some_fixable_some.rs:22:22 | LL | let _ = v.iter().position(|&x| x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|&x| x < 0)` error: called `is_some()` after searching an `Iterator` with `rposition` - --> $DIR/search_is_some_fixable_some.rs:26:22 + --> $DIR/search_is_some_fixable_some.rs:25:22 | LL | let _ = v.iter().rposition(|&x| x < 0).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|&x| x < 0)` 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:30:27 | LL | let _ = "hello world".find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")` 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:31:27 | LL | let _ = "hello world".find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:33:27 + --> $DIR/search_is_some_fixable_some.rs:32:27 | LL | let _ = "hello world".find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])` 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:34:16 | LL | let _ = s1.find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")` 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:35:16 | LL | let _ = s1.find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:37:16 + --> $DIR/search_is_some_fixable_some.rs:36:16 | LL | let _ = s1.find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])` 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:38:21 | LL | let _ = s1[2..].find("world").is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")` 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:39:21 | LL | let _ = s1[2..].find(&s2).is_some(); | ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)` error: called `is_some()` after calling `find()` on a string - --> $DIR/search_is_some_fixable_some.rs:41:21 + --> $DIR/search_is_some_fixable_some.rs:40:21 | LL | let _ = s1[2..].find(&s2[2..]).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:57:44 + --> $DIR/search_is_some_fixable_some.rs:56:44 | LL | .filter(|c| filter_hand.iter().find(|cc| c == cc).is_some()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|cc| c == &cc)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:73:49 + --> $DIR/search_is_some_fixable_some.rs:72:49 | LL | .filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_some()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|cc| c == cc)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:84:29 + --> $DIR/search_is_some_fixable_some.rs:83:29 | LL | let _ = vfoo.iter().find(|v| v.foo == 1 && v.bar == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `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:89:14 + --> $DIR/search_is_some_fixable_some.rs:88:14 | LL | .find(|(i, v)| *i == 42 && v.foo == 1 && v.bar == 2) | ______________^ @@ -149,55 +150,55 @@ LL | | .is_some(); | |______________________^ help: use `any()` instead: `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:95:29 + --> $DIR/search_is_some_fixable_some.rs:94:29 | LL | let _ = vfoo.iter().find(|a| a[0] == 42).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|a| a[0] == 42)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:101:29 + --> $DIR/search_is_some_fixable_some.rs:100:29 | LL | let _ = vfoo.iter().find(|sub| sub[1..4].len() == 3).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|sub| sub[1..4].len() == 3)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:119:30 + --> $DIR/search_is_some_fixable_some.rs:118:30 | LL | let _ = [ppx].iter().find(|ppp_x: &&&u32| please(**ppp_x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|ppp_x: &&u32| please(ppp_x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:120:50 + --> $DIR/search_is_some_fixable_some.rs:119:50 | LL | let _ = [String::from("Hey hey")].iter().find(|s| s.len() == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|s| s.len() == 2)` 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:122:26 | LL | let _ = v.iter().find(|x| deref_enough(**x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| deref_enough(*x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:124:26 + --> $DIR/search_is_some_fixable_some.rs:123:26 | LL | let _ = v.iter().find(|x: &&u32| deref_enough(**x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x: &u32| deref_enough(*x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:127:26 + --> $DIR/search_is_some_fixable_some.rs:126:26 | LL | let _ = v.iter().find(|x| arg_no_deref(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| arg_no_deref(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:129:26 + --> $DIR/search_is_some_fixable_some.rs:128:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x: &u32| arg_no_deref(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:151:14 + --> $DIR/search_is_some_fixable_some.rs:150:14 | LL | .find(|v| v.inner_double.bar[0][0] == 2 && v.inner.bar[0] == 2) | ______________^ @@ -205,85 +206,85 @@ LL | | .is_some(); | |______________________^ help: use `any()` instead: `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:165:29 + --> $DIR/search_is_some_fixable_some.rs:164:29 | LL | let _ = vfoo.iter().find(|v| v.inner[0].bar == 2).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|v| v.inner[0].bar == 2)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:170:29 + --> $DIR/search_is_some_fixable_some.rs:169:29 | LL | let _ = vfoo.iter().find(|x| (**x)[0] == 9).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| (**x)[0] == 9)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:183:29 + --> $DIR/search_is_some_fixable_some.rs:182:29 | LL | let _ = vfoo.iter().find(|v| v.by_ref(&v.bar)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|v| v.by_ref(&v.bar))` 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:186:55 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|(&x, y)| x == *y).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|(&x, y)| x == *y)` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:188:55 + --> $DIR/search_is_some_fixable_some.rs:187:55 | LL | let _ = [&(&1, 2), &(&3, 4), &(&5, 4)].iter().find(|&(&x, y)| x == *y).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|(&x, y)| x == *y)` 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:206:26 | LL | let _ = v.iter().find(|s| s[0].is_empty()).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|s| s[0].is_empty())` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:208:26 + --> $DIR/search_is_some_fixable_some.rs:207:26 | LL | let _ = v.iter().find(|s| test_string_1(&s[0])).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|s| test_string_1(&s[0]))` 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:216:26 | LL | let _ = v.iter().find(|fp| fp.field.is_power_of_two()).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `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:218:26 + --> $DIR/search_is_some_fixable_some.rs:217:26 | LL | let _ = v.iter().find(|fp| test_u32_1(fp.field)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|fp| test_u32_1(fp.field))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:219:26 + --> $DIR/search_is_some_fixable_some.rs:218:26 | LL | let _ = v.iter().find(|fp| test_u32_2(*fp.field)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|fp| test_u32_2(*fp.field))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:234:18 + --> $DIR/search_is_some_fixable_some.rs:233:18 | LL | v.iter().find(|x: &&u32| func(x)).is_some() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x: &u32| func(&x))` error: called `is_some()` after searching an `Iterator` with `find` - --> $DIR/search_is_some_fixable_some.rs:243:26 + --> $DIR/search_is_some_fixable_some.rs:242:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref_impl(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `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:246:26 + --> $DIR/search_is_some_fixable_some.rs:245:26 | LL | let _ = v.iter().find(|x: &&u32| arg_no_deref_dyn(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `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:249:26 + --> $DIR/search_is_some_fixable_some.rs:248:26 | LL | let _ = v.iter().find(|x: &&u32| (*arg_no_deref_dyn)(x)).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x: &u32| (*arg_no_deref_dyn)(&x))` diff --git a/src/tools/clippy/tests/ui/seek_from_current.fixed b/src/tools/clippy/tests/ui/seek_from_current.fixed index 34c33baf6..543f0c681 100644 --- a/src/tools/clippy/tests/ui/seek_from_current.fixed +++ b/src/tools/clippy/tests/ui/seek_from_current.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::seek_from_current)] use std::fs::File; diff --git a/src/tools/clippy/tests/ui/seek_from_current.rs b/src/tools/clippy/tests/ui/seek_from_current.rs index 22bcff1bc..4ed877f8e 100644 --- a/src/tools/clippy/tests/ui/seek_from_current.rs +++ b/src/tools/clippy/tests/ui/seek_from_current.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::seek_from_current)] use std::fs::File; diff --git a/src/tools/clippy/tests/ui/seek_from_current.stderr b/src/tools/clippy/tests/ui/seek_from_current.stderr index c079f3611..42eb342c1 100644 --- a/src/tools/clippy/tests/ui/seek_from_current.stderr +++ b/src/tools/clippy/tests/ui/seek_from_current.stderr @@ -1,10 +1,11 @@ error: using `SeekFrom::Current` to start from current position - --> $DIR/seek_from_current.rs:20:5 + --> $DIR/seek_from_current.rs:19:5 | LL | f.seek(SeekFrom::Current(0))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `f.stream_position()` | = note: `-D clippy::seek-from-current` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::seek_from_current)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed index d8a6e6985..15cc8d54f 100644 --- a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed +++ b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::seek_to_start_instead_of_rewind)] diff --git a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs index fc6a6433c..197225ffb 100644 --- a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs +++ b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::seek_to_start_instead_of_rewind)] diff --git a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.stderr b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.stderr index 342ec00fe..05c11cf7f 100644 --- a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.stderr +++ b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.stderr @@ -1,19 +1,20 @@ error: used `seek` to go to the start of the stream - --> $DIR/seek_to_start_instead_of_rewind.rs:53:7 + --> $DIR/seek_to_start_instead_of_rewind.rs:52:7 | LL | t.seek(SeekFrom::Start(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()` | = note: `-D clippy::seek-to-start-instead-of-rewind` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::seek_to_start_instead_of_rewind)]` error: used `seek` to go to the start of the stream - --> $DIR/seek_to_start_instead_of_rewind.rs:58:7 + --> $DIR/seek_to_start_instead_of_rewind.rs:57:7 | LL | t.seek(SeekFrom::Start(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()` error: used `seek` to go to the start of the stream - --> $DIR/seek_to_start_instead_of_rewind.rs:134:7 + --> $DIR/seek_to_start_instead_of_rewind.rs:133:7 | LL | f.seek(SeekFrom::Start(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()` diff --git a/src/tools/clippy/tests/ui/self_assignment.rs b/src/tools/clippy/tests/ui/self_assignment.rs index a7f9fbaae..213bca6c4 100644 --- a/src/tools/clippy/tests/ui/self_assignment.rs +++ b/src/tools/clippy/tests/ui/self_assignment.rs @@ -11,18 +11,30 @@ pub struct S<'a> { pub fn positives(mut a: usize, b: &mut u32, mut s: S) { a = a; + //~^ ERROR: self-assignment of `a` to `a` + //~| NOTE: `-D clippy::self-assignment` implied by `-D warnings` *b = *b; + //~^ ERROR: self-assignment of `*b` to `*b` s = s; + //~^ ERROR: self-assignment of `s` to `s` s.a = s.a; + //~^ ERROR: self-assignment of `s.a` to `s.a` s.b[9] = s.b[5 + 4]; + //~^ ERROR: self-assignment of `s.b[5 + 4]` to `s.b[9]` s.c[0][1] = s.c[0][1]; + //~^ ERROR: self-assignment of `s.c[0][1]` to `s.c[0][1]` s.b[a] = s.b[a]; + //~^ ERROR: self-assignment of `s.b[a]` to `s.b[a]` *s.e = *s.e; + //~^ ERROR: self-assignment of `*s.e` to `*s.e` s.b[a + 10] = s.b[10 + a]; + //~^ ERROR: self-assignment of `s.b[10 + a]` to `s.b[a + 10]` let mut t = (0, 1); t.1 = t.1; + //~^ ERROR: self-assignment of `t.1` to `t.1` t.0 = (t.0); + //~^ ERROR: self-assignment of `(t.0)` to `t.0` } pub fn negatives_not_equal(mut a: usize, b: &mut usize, mut s: S) { diff --git a/src/tools/clippy/tests/ui/self_assignment.stderr b/src/tools/clippy/tests/ui/self_assignment.stderr index 25b8569fa..4612f8f82 100644 --- a/src/tools/clippy/tests/ui/self_assignment.stderr +++ b/src/tools/clippy/tests/ui/self_assignment.stderr @@ -5,63 +5,64 @@ LL | a = a; | ^^^^^ | = note: `-D clippy::self-assignment` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::self_assignment)]` error: self-assignment of `*b` to `*b` - --> $DIR/self_assignment.rs:14:5 + --> $DIR/self_assignment.rs:16:5 | LL | *b = *b; | ^^^^^^^ error: self-assignment of `s` to `s` - --> $DIR/self_assignment.rs:15:5 + --> $DIR/self_assignment.rs:18:5 | LL | s = s; | ^^^^^ error: self-assignment of `s.a` to `s.a` - --> $DIR/self_assignment.rs:16:5 + --> $DIR/self_assignment.rs:20:5 | LL | s.a = s.a; | ^^^^^^^^^ error: self-assignment of `s.b[5 + 4]` to `s.b[9]` - --> $DIR/self_assignment.rs:17:5 + --> $DIR/self_assignment.rs:22:5 | LL | s.b[9] = s.b[5 + 4]; | ^^^^^^^^^^^^^^^^^^^ error: self-assignment of `s.c[0][1]` to `s.c[0][1]` - --> $DIR/self_assignment.rs:18:5 + --> $DIR/self_assignment.rs:24:5 | LL | s.c[0][1] = s.c[0][1]; | ^^^^^^^^^^^^^^^^^^^^^ error: self-assignment of `s.b[a]` to `s.b[a]` - --> $DIR/self_assignment.rs:19:5 + --> $DIR/self_assignment.rs:26:5 | LL | s.b[a] = s.b[a]; | ^^^^^^^^^^^^^^^ error: self-assignment of `*s.e` to `*s.e` - --> $DIR/self_assignment.rs:20:5 + --> $DIR/self_assignment.rs:28:5 | LL | *s.e = *s.e; | ^^^^^^^^^^^ error: self-assignment of `s.b[10 + a]` to `s.b[a + 10]` - --> $DIR/self_assignment.rs:21:5 + --> $DIR/self_assignment.rs:30:5 | LL | s.b[a + 10] = s.b[10 + a]; | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: self-assignment of `t.1` to `t.1` - --> $DIR/self_assignment.rs:24:5 + --> $DIR/self_assignment.rs:34:5 | LL | t.1 = t.1; | ^^^^^^^^^ error: self-assignment of `(t.0)` to `t.0` - --> $DIR/self_assignment.rs:25:5 + --> $DIR/self_assignment.rs:36:5 | LL | t.0 = (t.0); | ^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/self_named_constructors.rs b/src/tools/clippy/tests/ui/self_named_constructors.rs index 356f701c9..dc326b399 100644 --- a/src/tools/clippy/tests/ui/self_named_constructors.rs +++ b/src/tools/clippy/tests/ui/self_named_constructors.rs @@ -5,6 +5,8 @@ struct ShouldNotSpawn; impl ShouldSpawn { pub fn should_spawn() -> ShouldSpawn { + //~^ ERROR: constructor `should_spawn` has the same name as the type + //~| NOTE: `-D clippy::self-named-constructors` implied by `-D warnings` ShouldSpawn } diff --git a/src/tools/clippy/tests/ui/self_named_constructors.stderr b/src/tools/clippy/tests/ui/self_named_constructors.stderr index ba989f06d..f299b860d 100644 --- a/src/tools/clippy/tests/ui/self_named_constructors.stderr +++ b/src/tools/clippy/tests/ui/self_named_constructors.stderr @@ -2,11 +2,14 @@ error: constructor `should_spawn` has the same name as the type --> $DIR/self_named_constructors.rs:7:5 | LL | / pub fn should_spawn() -> ShouldSpawn { +LL | | +LL | | LL | | ShouldSpawn LL | | } | |_____^ | = note: `-D clippy::self-named-constructors` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::self_named_constructors)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.fixed b/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.fixed index 653f4533b..bbcc0de27 100644 --- a/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.fixed +++ b/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::semicolon_if_nothing_returned)] #![allow(clippy::redundant_closure, clippy::uninlined_format_args, clippy::needless_late_init)] diff --git a/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs b/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs index 9db038219..fdc9c0c33 100644 --- a/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs +++ b/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::semicolon_if_nothing_returned)] #![allow(clippy::redundant_closure, clippy::uninlined_format_args, clippy::needless_late_init)] diff --git a/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.stderr b/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.stderr index 78813e7cc..66373a13c 100644 --- a/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.stderr +++ b/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.stderr @@ -1,31 +1,32 @@ error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:9:5 + --> $DIR/semicolon_if_nothing_returned.rs:8:5 | LL | println!("Hello") | ^^^^^^^^^^^^^^^^^ help: add a `;` here: `println!("Hello");` | = note: `-D clippy::semicolon-if-nothing-returned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::semicolon_if_nothing_returned)]` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:13:5 + --> $DIR/semicolon_if_nothing_returned.rs:12:5 | LL | get_unit() | ^^^^^^^^^^ help: add a `;` here: `get_unit();` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:18:5 + --> $DIR/semicolon_if_nothing_returned.rs:17:5 | LL | y = x + 1 | ^^^^^^^^^ help: add a `;` here: `y = x + 1;` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:24:9 + --> $DIR/semicolon_if_nothing_returned.rs:23:9 | LL | hello() | ^^^^^^^ help: add a `;` here: `hello();` error: consider adding a `;` to the last statement for consistent formatting - --> $DIR/semicolon_if_nothing_returned.rs:35:9 + --> $DIR/semicolon_if_nothing_returned.rs:34:9 | LL | ptr::drop_in_place(s.as_mut_ptr()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `ptr::drop_in_place(s.as_mut_ptr());` diff --git a/src/tools/clippy/tests/ui/semicolon_inside_block.fixed b/src/tools/clippy/tests/ui/semicolon_inside_block.fixed index ee359f60c..21681e715 100644 --- a/src/tools/clippy/tests/ui/semicolon_inside_block.fixed +++ b/src/tools/clippy/tests/ui/semicolon_inside_block.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/src/tools/clippy/tests/ui/semicolon_inside_block.rs b/src/tools/clippy/tests/ui/semicolon_inside_block.rs index e8516f79b..3a81661cd 100644 --- a/src/tools/clippy/tests/ui/semicolon_inside_block.rs +++ b/src/tools/clippy/tests/ui/semicolon_inside_block.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/src/tools/clippy/tests/ui/semicolon_inside_block.stderr b/src/tools/clippy/tests/ui/semicolon_inside_block.stderr index 48d3690e2..1bfc1f24c 100644 --- a/src/tools/clippy/tests/ui/semicolon_inside_block.stderr +++ b/src/tools/clippy/tests/ui/semicolon_inside_block.stderr @@ -1,10 +1,11 @@ error: consider moving the `;` inside the block for consistent formatting - --> $DIR/semicolon_inside_block.rs:39:5 + --> $DIR/semicolon_inside_block.rs:38:5 | LL | { unit_fn_block() }; | ^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::semicolon-inside-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::semicolon_inside_block)]` help: put the `;` here | LL - { unit_fn_block() }; @@ -12,7 +13,7 @@ LL + { unit_fn_block(); } | error: consider moving the `;` inside the block for consistent formatting - --> $DIR/semicolon_inside_block.rs:40:5 + --> $DIR/semicolon_inside_block.rs:39:5 | LL | unsafe { unit_fn_block() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL + unsafe { unit_fn_block(); } | error: consider moving the `;` inside the block for consistent formatting - --> $DIR/semicolon_inside_block.rs:48:5 + --> $DIR/semicolon_inside_block.rs:47:5 | LL | / { LL | | unit_fn_block(); @@ -39,7 +40,7 @@ LL ~ } | error: consider moving the `;` inside the block for consistent formatting - --> $DIR/semicolon_inside_block.rs:61:5 + --> $DIR/semicolon_inside_block.rs:60:5 | LL | { m!(()) }; | ^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/semicolon_outside_block.fixed b/src/tools/clippy/tests/ui/semicolon_outside_block.fixed index 034c7f8c7..148e112e0 100644 --- a/src/tools/clippy/tests/ui/semicolon_outside_block.fixed +++ b/src/tools/clippy/tests/ui/semicolon_outside_block.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/src/tools/clippy/tests/ui/semicolon_outside_block.rs b/src/tools/clippy/tests/ui/semicolon_outside_block.rs index 4dc956d8a..c76720146 100644 --- a/src/tools/clippy/tests/ui/semicolon_outside_block.rs +++ b/src/tools/clippy/tests/ui/semicolon_outside_block.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow( unused, clippy::unused_unit, diff --git a/src/tools/clippy/tests/ui/semicolon_outside_block.stderr b/src/tools/clippy/tests/ui/semicolon_outside_block.stderr index dcc102e60..427271fca 100644 --- a/src/tools/clippy/tests/ui/semicolon_outside_block.stderr +++ b/src/tools/clippy/tests/ui/semicolon_outside_block.stderr @@ -1,10 +1,11 @@ error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:42:5 + --> $DIR/semicolon_outside_block.rs:41:5 | LL | { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::semicolon-outside-block` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::semicolon_outside_block)]` help: put the `;` here | LL - { unit_fn_block(); } @@ -12,7 +13,7 @@ LL + { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:43:5 + --> $DIR/semicolon_outside_block.rs:42:5 | LL | unsafe { unit_fn_block(); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL + unsafe { unit_fn_block() }; | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:52:5 + --> $DIR/semicolon_outside_block.rs:51:5 | LL | / { LL | | unit_fn_block(); @@ -39,7 +40,7 @@ LL ~ }; | error: consider moving the `;` outside the block for consistent formatting - --> $DIR/semicolon_outside_block.rs:62:5 + --> $DIR/semicolon_outside_block.rs:61:5 | LL | { m!(()); } | ^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/serde.rs b/src/tools/clippy/tests/ui/serde.rs index 5843344eb..610a50020 100644 --- a/src/tools/clippy/tests/ui/serde.rs +++ b/src/tools/clippy/tests/ui/serde.rs @@ -37,6 +37,8 @@ impl<'de> serde::de::Visitor<'de> for B { } fn visit_string(self, _v: String) -> Result + //~^ ERROR: you should not implement `visit_string` without also implementing `visit_s + //~| NOTE: `-D clippy::serde-api-misuse` implied by `-D warnings` where E: serde::de::Error, { diff --git a/src/tools/clippy/tests/ui/serde.stderr b/src/tools/clippy/tests/ui/serde.stderr index 760c9c990..e5d64e271 100644 --- a/src/tools/clippy/tests/ui/serde.stderr +++ b/src/tools/clippy/tests/ui/serde.stderr @@ -2,14 +2,16 @@ error: you should not implement `visit_string` without also implementing `visit_ --> $DIR/serde.rs:39:5 | LL | / fn visit_string(self, _v: String) -> Result +LL | | +LL | | LL | | where -LL | | E: serde::de::Error, -LL | | { +... | LL | | unimplemented!() LL | | } | |_____^ | = note: `-D clippy::serde-api-misuse` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::serde_api_misuse)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/shadow.rs b/src/tools/clippy/tests/ui/shadow.rs index 1b40a43d0..258dba9dd 100644 --- a/src/tools/clippy/tests/ui/shadow.rs +++ b/src/tools/clippy/tests/ui/shadow.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![warn(clippy::shadow_same, clippy::shadow_reuse, clippy::shadow_unrelated)] #![allow( diff --git a/src/tools/clippy/tests/ui/shadow.stderr b/src/tools/clippy/tests/ui/shadow.stderr index 88b02f53b..26ace287b 100644 --- a/src/tools/clippy/tests/ui/shadow.stderr +++ b/src/tools/clippy/tests/ui/shadow.stderr @@ -10,6 +10,7 @@ note: previous binding is here LL | let x = 1; | ^ = note: `-D clippy::shadow-same` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::shadow_same)]` error: `mut x` is shadowed by itself in `&x` --> $DIR/shadow.rs:25:13 @@ -59,6 +60,7 @@ note: previous binding is here LL | let x = ([[0]], ()); | ^ = note: `-D clippy::shadow-reuse` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::shadow_reuse)]` error: `x` is shadowed --> $DIR/shadow.rs:33:9 @@ -156,6 +158,7 @@ note: previous binding is here LL | let x = 1; | ^ = note: `-D clippy::shadow-unrelated` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::shadow_unrelated)]` error: `x` shadows a previous, unrelated binding --> $DIR/shadow.rs:60:13 diff --git a/src/tools/clippy/tests/ui/short_circuit_statement.fixed b/src/tools/clippy/tests/ui/short_circuit_statement.fixed index 1737d5014..a9930ef4d 100644 --- a/src/tools/clippy/tests/ui/short_circuit_statement.fixed +++ b/src/tools/clippy/tests/ui/short_circuit_statement.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::short_circuit_statement)] #![allow(clippy::nonminimal_bool)] diff --git a/src/tools/clippy/tests/ui/short_circuit_statement.rs b/src/tools/clippy/tests/ui/short_circuit_statement.rs index ab93aa1ca..71f7c7f2a 100644 --- a/src/tools/clippy/tests/ui/short_circuit_statement.rs +++ b/src/tools/clippy/tests/ui/short_circuit_statement.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::short_circuit_statement)] #![allow(clippy::nonminimal_bool)] diff --git a/src/tools/clippy/tests/ui/short_circuit_statement.stderr b/src/tools/clippy/tests/ui/short_circuit_statement.stderr index aa84ac3a7..dbdf44dfc 100644 --- a/src/tools/clippy/tests/ui/short_circuit_statement.stderr +++ b/src/tools/clippy/tests/ui/short_circuit_statement.stderr @@ -1,19 +1,20 @@ error: boolean short circuit operator in statement may be clearer using an explicit test - --> $DIR/short_circuit_statement.rs:7:5 + --> $DIR/short_circuit_statement.rs:5:5 | LL | f() && g(); | ^^^^^^^^^^^ help: replace it with: `if f() { g(); }` | = note: `-D clippy::short-circuit-statement` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::short_circuit_statement)]` error: boolean short circuit operator in statement may be clearer using an explicit test - --> $DIR/short_circuit_statement.rs:8:5 + --> $DIR/short_circuit_statement.rs:6:5 | LL | f() || g(); | ^^^^^^^^^^^ help: replace it with: `if !f() { g(); }` error: boolean short circuit operator in statement may be clearer using an explicit test - --> $DIR/short_circuit_statement.rs:9:5 + --> $DIR/short_circuit_statement.rs:7:5 | LL | 1 == 2 || g(); | ^^^^^^^^^^^^^^ help: replace it with: `if 1 != 2 { g(); }` diff --git a/src/tools/clippy/tests/ui/should_impl_trait/method_list_1.rs b/src/tools/clippy/tests/ui/should_impl_trait/method_list_1.rs index 20d49f5a9..85eed3f06 100644 --- a/src/tools/clippy/tests/ui/should_impl_trait/method_list_1.rs +++ b/src/tools/clippy/tests/ui/should_impl_trait/method_list_1.rs @@ -23,62 +23,77 @@ impl T { // trait method list part 1, should lint all // ***************************************** pub fn add(self, other: T) -> T { + //~^ ERROR: method `add` can be confused for the standard trait method `std::ops::Add: unimplemented!() } pub fn as_mut(&mut self) -> &mut T { + //~^ ERROR: method `as_mut` can be confused for the standard trait method `std::conver unimplemented!() } pub fn as_ref(&self) -> &T { + //~^ ERROR: method `as_ref` can be confused for the standard trait method `std::conver unimplemented!() } pub fn bitand(self, rhs: T) -> T { + //~^ ERROR: method `bitand` can be confused for the standard trait method `std::ops::B unimplemented!() } pub fn bitor(self, rhs: Self) -> Self { + //~^ ERROR: method `bitor` can be confused for the standard trait method `std::ops::Bi unimplemented!() } pub fn bitxor(self, rhs: Self) -> Self { + //~^ ERROR: method `bitxor` can be confused for the standard trait method `std::ops::B unimplemented!() } pub fn borrow(&self) -> &str { + //~^ ERROR: method `borrow` can be confused for the standard trait method `std::borrow unimplemented!() } pub fn borrow_mut(&mut self) -> &mut str { + //~^ ERROR: method `borrow_mut` can be confused for the standard trait method `std::bo unimplemented!() } pub fn clone(&self) -> Self { + //~^ ERROR: method `clone` can be confused for the standard trait method `std::clone:: unimplemented!() } pub fn cmp(&self, other: &Self) -> Self { + //~^ ERROR: method `cmp` can be confused for the standard trait method `std::cmp::Ord: unimplemented!() } pub fn default() -> Self { + //~^ ERROR: method `default` can be confused for the standard trait method `std::defau unimplemented!() } pub fn deref(&self) -> &Self { + //~^ ERROR: method `deref` can be confused for the standard trait method `std::ops::De unimplemented!() } pub fn deref_mut(&mut self) -> &mut Self { + //~^ ERROR: method `deref_mut` can be confused for the standard trait method `std::ops unimplemented!() } pub fn div(self, rhs: Self) -> Self { + //~^ ERROR: method `div` can be confused for the standard trait method `std::ops::Div: unimplemented!() } pub fn drop(&mut self) { + //~^ ERROR: method `drop` can be confused for the standard trait method `std::ops::Dro unimplemented!() } // ********** diff --git a/src/tools/clippy/tests/ui/should_impl_trait/method_list_1.stderr b/src/tools/clippy/tests/ui/should_impl_trait/method_list_1.stderr index 161dd66b0..c9894eec5 100644 --- a/src/tools/clippy/tests/ui/should_impl_trait/method_list_1.stderr +++ b/src/tools/clippy/tests/ui/should_impl_trait/method_list_1.stderr @@ -2,17 +2,20 @@ error: method `add` can be confused for the standard trait method `std::ops::Add --> $DIR/method_list_1.rs:25:5 | LL | / pub fn add(self, other: T) -> T { +LL | | LL | | unimplemented!() LL | | } | |_____^ | = help: consider implementing the trait `std::ops::Add` or choosing a less ambiguous method name = note: `-D clippy::should-implement-trait` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::should_implement_trait)]` error: method `as_mut` can be confused for the standard trait method `std::convert::AsMut::as_mut` - --> $DIR/method_list_1.rs:29:5 + --> $DIR/method_list_1.rs:30:5 | LL | / pub fn as_mut(&mut self) -> &mut T { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -20,9 +23,10 @@ LL | | } = help: consider implementing the trait `std::convert::AsMut` or choosing a less ambiguous method name error: method `as_ref` can be confused for the standard trait method `std::convert::AsRef::as_ref` - --> $DIR/method_list_1.rs:33:5 + --> $DIR/method_list_1.rs:35:5 | LL | / pub fn as_ref(&self) -> &T { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -30,9 +34,10 @@ LL | | } = help: consider implementing the trait `std::convert::AsRef` or choosing a less ambiguous method name error: method `bitand` can be confused for the standard trait method `std::ops::BitAnd::bitand` - --> $DIR/method_list_1.rs:37:5 + --> $DIR/method_list_1.rs:40:5 | LL | / pub fn bitand(self, rhs: T) -> T { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -40,9 +45,10 @@ LL | | } = help: consider implementing the trait `std::ops::BitAnd` or choosing a less ambiguous method name error: method `bitor` can be confused for the standard trait method `std::ops::BitOr::bitor` - --> $DIR/method_list_1.rs:41:5 + --> $DIR/method_list_1.rs:45:5 | LL | / pub fn bitor(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -50,9 +56,10 @@ LL | | } = help: consider implementing the trait `std::ops::BitOr` or choosing a less ambiguous method name error: method `bitxor` can be confused for the standard trait method `std::ops::BitXor::bitxor` - --> $DIR/method_list_1.rs:45:5 + --> $DIR/method_list_1.rs:50:5 | LL | / pub fn bitxor(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -60,9 +67,10 @@ LL | | } = help: consider implementing the trait `std::ops::BitXor` or choosing a less ambiguous method name error: method `borrow` can be confused for the standard trait method `std::borrow::Borrow::borrow` - --> $DIR/method_list_1.rs:49:5 + --> $DIR/method_list_1.rs:55:5 | LL | / pub fn borrow(&self) -> &str { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -70,9 +78,10 @@ LL | | } = help: consider implementing the trait `std::borrow::Borrow` or choosing a less ambiguous method name error: method `borrow_mut` can be confused for the standard trait method `std::borrow::BorrowMut::borrow_mut` - --> $DIR/method_list_1.rs:53:5 + --> $DIR/method_list_1.rs:60:5 | LL | / pub fn borrow_mut(&mut self) -> &mut str { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -80,9 +89,10 @@ LL | | } = help: consider implementing the trait `std::borrow::BorrowMut` or choosing a less ambiguous method name error: method `clone` can be confused for the standard trait method `std::clone::Clone::clone` - --> $DIR/method_list_1.rs:57:5 + --> $DIR/method_list_1.rs:65:5 | LL | / pub fn clone(&self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -90,9 +100,10 @@ LL | | } = help: consider implementing the trait `std::clone::Clone` or choosing a less ambiguous method name error: method `cmp` can be confused for the standard trait method `std::cmp::Ord::cmp` - --> $DIR/method_list_1.rs:61:5 + --> $DIR/method_list_1.rs:70:5 | LL | / pub fn cmp(&self, other: &Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -100,9 +111,10 @@ LL | | } = help: consider implementing the trait `std::cmp::Ord` or choosing a less ambiguous method name error: method `default` can be confused for the standard trait method `std::default::Default::default` - --> $DIR/method_list_1.rs:65:5 + --> $DIR/method_list_1.rs:75:5 | LL | / pub fn default() -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -110,9 +122,10 @@ LL | | } = help: consider implementing the trait `std::default::Default` or choosing a less ambiguous method name error: method `deref` can be confused for the standard trait method `std::ops::Deref::deref` - --> $DIR/method_list_1.rs:69:5 + --> $DIR/method_list_1.rs:80:5 | LL | / pub fn deref(&self) -> &Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -120,9 +133,10 @@ LL | | } = help: consider implementing the trait `std::ops::Deref` or choosing a less ambiguous method name error: method `deref_mut` can be confused for the standard trait method `std::ops::DerefMut::deref_mut` - --> $DIR/method_list_1.rs:73:5 + --> $DIR/method_list_1.rs:85:5 | LL | / pub fn deref_mut(&mut self) -> &mut Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -130,9 +144,10 @@ LL | | } = help: consider implementing the trait `std::ops::DerefMut` or choosing a less ambiguous method name error: method `div` can be confused for the standard trait method `std::ops::Div::div` - --> $DIR/method_list_1.rs:77:5 + --> $DIR/method_list_1.rs:90:5 | LL | / pub fn div(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -140,9 +155,10 @@ LL | | } = help: consider implementing the trait `std::ops::Div` or choosing a less ambiguous method name error: method `drop` can be confused for the standard trait method `std::ops::Drop::drop` - --> $DIR/method_list_1.rs:81:5 + --> $DIR/method_list_1.rs:95:5 | LL | / pub fn drop(&mut self) { +LL | | LL | | unimplemented!() LL | | } | |_____^ diff --git a/src/tools/clippy/tests/ui/should_impl_trait/method_list_2.rs b/src/tools/clippy/tests/ui/should_impl_trait/method_list_2.rs index 3efec1c52..33211b32d 100644 --- a/src/tools/clippy/tests/ui/should_impl_trait/method_list_2.rs +++ b/src/tools/clippy/tests/ui/should_impl_trait/method_list_2.rs @@ -10,7 +10,7 @@ clippy::missing_panics_doc, clippy::return_self_not_must_use )] - +//@no-rustfix use std::ops::Mul; use std::rc::{self, Rc}; use std::sync::{self, Arc}; @@ -24,62 +24,77 @@ impl T { // ***************************************** pub fn eq(&self, other: &Self) -> bool { + //~^ ERROR: method `eq` can be confused for the standard trait method `std::cmp::Parti unimplemented!() } pub fn from_iter(iter: T) -> Self { + //~^ ERROR: method `from_iter` can be confused for the standard trait method `std::ite unimplemented!() } pub fn from_str(s: &str) -> Result { + //~^ ERROR: method `from_str` can be confused for the standard trait method `std::str: unimplemented!() } pub fn hash(&self, state: &mut T) { + //~^ ERROR: method `hash` can be confused for the standard trait method `std::hash::Ha unimplemented!() } pub fn index(&self, index: usize) -> &Self { + //~^ ERROR: method `index` can be confused for the standard trait method `std::ops::In unimplemented!() } pub fn index_mut(&mut self, index: usize) -> &mut Self { + //~^ ERROR: method `index_mut` can be confused for the standard trait method `std::ops unimplemented!() } pub fn into_iter(self) -> Self { + //~^ ERROR: method `into_iter` can be confused for the standard trait method `std::ite unimplemented!() } pub fn mul(self, rhs: Self) -> Self { + //~^ ERROR: method `mul` can be confused for the standard trait method `std::ops::Mul: unimplemented!() } pub fn neg(self) -> Self { + //~^ ERROR: method `neg` can be confused for the standard trait method `std::ops::Neg: unimplemented!() } pub fn next(&mut self) -> Option { + //~^ ERROR: method `next` can be confused for the standard trait method `std::iter::It unimplemented!() } pub fn not(self) -> Self { + //~^ ERROR: method `not` can be confused for the standard trait method `std::ops::Not: unimplemented!() } pub fn rem(self, rhs: Self) -> Self { + //~^ ERROR: method `rem` can be confused for the standard trait method `std::ops::Rem: unimplemented!() } pub fn shl(self, rhs: Self) -> Self { + //~^ ERROR: method `shl` can be confused for the standard trait method `std::ops::Shl: unimplemented!() } pub fn shr(self, rhs: Self) -> Self { + //~^ ERROR: method `shr` can be confused for the standard trait method `std::ops::Shr: unimplemented!() } pub fn sub(self, rhs: Self) -> Self { + //~^ ERROR: method `sub` can be confused for the standard trait method `std::ops::Sub: unimplemented!() } // ********** diff --git a/src/tools/clippy/tests/ui/should_impl_trait/method_list_2.stderr b/src/tools/clippy/tests/ui/should_impl_trait/method_list_2.stderr index 10bfea68f..c257f4113 100644 --- a/src/tools/clippy/tests/ui/should_impl_trait/method_list_2.stderr +++ b/src/tools/clippy/tests/ui/should_impl_trait/method_list_2.stderr @@ -2,17 +2,20 @@ error: method `eq` can be confused for the standard trait method `std::cmp::Part --> $DIR/method_list_2.rs:26:5 | LL | / pub fn eq(&self, other: &Self) -> bool { +LL | | LL | | unimplemented!() LL | | } | |_____^ | = help: consider implementing the trait `std::cmp::PartialEq` or choosing a less ambiguous method name = note: `-D clippy::should-implement-trait` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::should_implement_trait)]` error: method `from_iter` can be confused for the standard trait method `std::iter::FromIterator::from_iter` - --> $DIR/method_list_2.rs:30:5 + --> $DIR/method_list_2.rs:31:5 | LL | / pub fn from_iter(iter: T) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -20,9 +23,10 @@ LL | | } = help: consider implementing the trait `std::iter::FromIterator` or choosing a less ambiguous method name error: method `from_str` can be confused for the standard trait method `std::str::FromStr::from_str` - --> $DIR/method_list_2.rs:34:5 + --> $DIR/method_list_2.rs:36:5 | LL | / pub fn from_str(s: &str) -> Result { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -30,9 +34,10 @@ LL | | } = help: consider implementing the trait `std::str::FromStr` or choosing a less ambiguous method name error: method `hash` can be confused for the standard trait method `std::hash::Hash::hash` - --> $DIR/method_list_2.rs:38:5 + --> $DIR/method_list_2.rs:41:5 | LL | / pub fn hash(&self, state: &mut T) { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -40,9 +45,10 @@ LL | | } = help: consider implementing the trait `std::hash::Hash` or choosing a less ambiguous method name error: method `index` can be confused for the standard trait method `std::ops::Index::index` - --> $DIR/method_list_2.rs:42:5 + --> $DIR/method_list_2.rs:46:5 | LL | / pub fn index(&self, index: usize) -> &Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -50,9 +56,10 @@ LL | | } = help: consider implementing the trait `std::ops::Index` or choosing a less ambiguous method name error: method `index_mut` can be confused for the standard trait method `std::ops::IndexMut::index_mut` - --> $DIR/method_list_2.rs:46:5 + --> $DIR/method_list_2.rs:51:5 | LL | / pub fn index_mut(&mut self, index: usize) -> &mut Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -60,9 +67,10 @@ LL | | } = help: consider implementing the trait `std::ops::IndexMut` or choosing a less ambiguous method name error: method `into_iter` can be confused for the standard trait method `std::iter::IntoIterator::into_iter` - --> $DIR/method_list_2.rs:50:5 + --> $DIR/method_list_2.rs:56:5 | LL | / pub fn into_iter(self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -70,9 +78,10 @@ LL | | } = help: consider implementing the trait `std::iter::IntoIterator` or choosing a less ambiguous method name error: method `mul` can be confused for the standard trait method `std::ops::Mul::mul` - --> $DIR/method_list_2.rs:54:5 + --> $DIR/method_list_2.rs:61:5 | LL | / pub fn mul(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -80,9 +89,10 @@ LL | | } = help: consider implementing the trait `std::ops::Mul` or choosing a less ambiguous method name error: method `neg` can be confused for the standard trait method `std::ops::Neg::neg` - --> $DIR/method_list_2.rs:58:5 + --> $DIR/method_list_2.rs:66:5 | LL | / pub fn neg(self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -90,9 +100,10 @@ LL | | } = help: consider implementing the trait `std::ops::Neg` or choosing a less ambiguous method name error: method `next` can be confused for the standard trait method `std::iter::Iterator::next` - --> $DIR/method_list_2.rs:62:5 + --> $DIR/method_list_2.rs:71:5 | LL | / pub fn next(&mut self) -> Option { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -100,9 +111,10 @@ LL | | } = help: consider implementing the trait `std::iter::Iterator` or choosing a less ambiguous method name error: method `not` can be confused for the standard trait method `std::ops::Not::not` - --> $DIR/method_list_2.rs:66:5 + --> $DIR/method_list_2.rs:76:5 | LL | / pub fn not(self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -110,9 +122,10 @@ LL | | } = help: consider implementing the trait `std::ops::Not` or choosing a less ambiguous method name error: method `rem` can be confused for the standard trait method `std::ops::Rem::rem` - --> $DIR/method_list_2.rs:70:5 + --> $DIR/method_list_2.rs:81:5 | LL | / pub fn rem(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -120,9 +133,10 @@ LL | | } = help: consider implementing the trait `std::ops::Rem` or choosing a less ambiguous method name error: method `shl` can be confused for the standard trait method `std::ops::Shl::shl` - --> $DIR/method_list_2.rs:74:5 + --> $DIR/method_list_2.rs:86:5 | LL | / pub fn shl(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -130,9 +144,10 @@ LL | | } = help: consider implementing the trait `std::ops::Shl` or choosing a less ambiguous method name error: method `shr` can be confused for the standard trait method `std::ops::Shr::shr` - --> $DIR/method_list_2.rs:78:5 + --> $DIR/method_list_2.rs:91:5 | LL | / pub fn shr(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ @@ -140,9 +155,10 @@ LL | | } = help: consider implementing the trait `std::ops::Shr` or choosing a less ambiguous method name error: method `sub` can be confused for the standard trait method `std::ops::Sub::sub` - --> $DIR/method_list_2.rs:82:5 + --> $DIR/method_list_2.rs:96:5 | LL | / pub fn sub(self, rhs: Self) -> Self { +LL | | LL | | unimplemented!() LL | | } | |_____^ diff --git a/src/tools/clippy/tests/ui/should_panic_without_expect.rs b/src/tools/clippy/tests/ui/should_panic_without_expect.rs new file mode 100644 index 000000000..b554fdaf2 --- /dev/null +++ b/src/tools/clippy/tests/ui/should_panic_without_expect.rs @@ -0,0 +1,21 @@ +//@no-rustfix +#![deny(clippy::should_panic_without_expect)] + +#[test] +#[should_panic] +fn no_message() {} + +#[test] +#[should_panic] +#[cfg(not(test))] +fn no_message_cfg_false() {} + +#[test] +#[should_panic = "message"] +fn metastr() {} + +#[test] +#[should_panic(expected = "message")] +fn metalist() {} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/should_panic_without_expect.stderr b/src/tools/clippy/tests/ui/should_panic_without_expect.stderr new file mode 100644 index 000000000..dfcef52a9 --- /dev/null +++ b/src/tools/clippy/tests/ui/should_panic_without_expect.stderr @@ -0,0 +1,14 @@ +error: #[should_panic] attribute without a reason + --> $DIR/should_panic_without_expect.rs:5:1 + | +LL | #[should_panic] + | ^^^^^^^^^^^^^^^ help: consider specifying the expected panic: `#[should_panic(expected = /* panic message */)]` + | +note: the lint level is defined here + --> $DIR/should_panic_without_expect.rs:2:9 + | +LL | #![deny(clippy::should_panic_without_expect)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.fixed b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.fixed deleted file mode 100644 index acc78d6bb..000000000 --- a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.fixed +++ /dev/null @@ -1,627 +0,0 @@ -// FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 -// //@run-rustfix -#![warn(clippy::significant_drop_in_scrutinee)] -#![allow(dead_code, unused_assignments)] -#![allow(clippy::match_single_binding, clippy::single_match, clippy::uninlined_format_args)] - -use std::num::ParseIntError; -use std::ops::Deref; -use std::sync::atomic::{AtomicU64, Ordering}; -use std::sync::RwLock; -use std::sync::{Mutex, MutexGuard}; - -struct State {} - -impl State { - fn foo(&self) -> bool { - true - } - - fn bar(&self) {} -} - -fn should_not_trigger_lint_with_mutex_guard_outside_match() { - let mutex = Mutex::new(State {}); - - // Should not trigger lint because the temporary should drop at the `;` on line before the match - let is_foo = mutex.lock().unwrap().foo(); - match is_foo { - true => { - mutex.lock().unwrap().bar(); - }, - false => {}, - }; -} - -fn should_not_trigger_lint_with_mutex_guard_when_taking_ownership_in_match() { - let mutex = Mutex::new(State {}); - - // Should not trigger lint because the scrutinee is explicitly returning the MutexGuard, - // so its lifetime should not be surprising. - match mutex.lock() { - Ok(guard) => { - guard.foo(); - mutex.lock().unwrap().bar(); - }, - _ => {}, - }; -} - -fn should_trigger_lint_with_mutex_guard_in_match_scrutinee() { - let mutex = Mutex::new(State {}); - - // Should trigger lint because the lifetime of the temporary MutexGuard is surprising because it - // is preserved until the end of the match, but there is no clear indication that this is the - // case. - match mutex.lock().unwrap().foo() { - true => { - mutex.lock().unwrap().bar(); - }, - false => {}, - }; -} - -fn should_not_trigger_lint_with_mutex_guard_in_match_scrutinee_when_lint_allowed() { - let mutex = Mutex::new(State {}); - - // Lint should not be triggered because it is "allowed" below. - #[allow(clippy::significant_drop_in_scrutinee)] - match mutex.lock().unwrap().foo() { - true => { - mutex.lock().unwrap().bar(); - }, - false => {}, - }; -} - -fn should_not_trigger_lint_for_insignificant_drop() { - // Should not trigger lint because there are no temporaries whose drops have a significant - // side effect. - match 1u64.to_string().is_empty() { - true => { - println!("It was empty") - }, - false => { - println!("It was not empty") - }, - } -} - -struct StateWithMutex { - m: Mutex, -} - -struct MutexGuardWrapper<'a> { - mg: MutexGuard<'a, u64>, -} - -impl<'a> MutexGuardWrapper<'a> { - fn get_the_value(&self) -> u64 { - *self.mg.deref() - } -} - -struct MutexGuardWrapperWrapper<'a> { - mg: MutexGuardWrapper<'a>, -} - -impl<'a> MutexGuardWrapperWrapper<'a> { - fn get_the_value(&self) -> u64 { - *self.mg.mg.deref() - } -} - -impl StateWithMutex { - fn lock_m(&self) -> MutexGuardWrapper<'_> { - MutexGuardWrapper { - mg: self.m.lock().unwrap(), - } - } - - fn lock_m_m(&self) -> MutexGuardWrapperWrapper<'_> { - MutexGuardWrapperWrapper { - mg: MutexGuardWrapper { - mg: self.m.lock().unwrap(), - }, - } - } - - fn foo(&self) -> bool { - true - } - - fn bar(&self) {} -} - -fn should_trigger_lint_with_wrapped_mutex() { - let s = StateWithMutex { m: Mutex::new(1) }; - - // Should trigger lint because a temporary contains a type with a significant drop and its - // lifetime is not obvious. Additionally, it is not obvious from looking at the scrutinee that - // the temporary contains such a type, making it potentially even more surprising. - match s.lock_m().get_the_value() { - 1 => { - println!("Got 1. Is it still 1?"); - println!("{}", s.lock_m().get_the_value()); - }, - 2 => { - println!("Got 2. Is it still 2?"); - println!("{}", s.lock_m().get_the_value()); - }, - _ => {}, - } - println!("All done!"); -} - -fn should_trigger_lint_with_double_wrapped_mutex() { - let s = StateWithMutex { m: Mutex::new(1) }; - - // Should trigger lint because a temporary contains a type which further contains a type with a - // significant drop and its lifetime is not obvious. Additionally, it is not obvious from - // looking at the scrutinee that the temporary contains such a type, making it potentially even - // more surprising. - match s.lock_m_m().get_the_value() { - 1 => { - println!("Got 1. Is it still 1?"); - println!("{}", s.lock_m().get_the_value()); - }, - 2 => { - println!("Got 2. Is it still 2?"); - println!("{}", s.lock_m().get_the_value()); - }, - _ => {}, - } - println!("All done!"); -} - -struct Counter { - i: AtomicU64, -} - -#[clippy::has_significant_drop] -struct CounterWrapper<'a> { - counter: &'a Counter, -} - -impl<'a> CounterWrapper<'a> { - fn new(counter: &Counter) -> CounterWrapper { - counter.i.fetch_add(1, Ordering::Relaxed); - CounterWrapper { counter } - } -} - -impl<'a> Drop for CounterWrapper<'a> { - fn drop(&mut self) { - self.counter.i.fetch_sub(1, Ordering::Relaxed); - } -} - -impl Counter { - fn temp_increment(&self) -> Vec { - vec![CounterWrapper::new(self), CounterWrapper::new(self)] - } -} - -fn should_trigger_lint_for_vec() { - let counter = Counter { i: AtomicU64::new(0) }; - - // Should trigger lint because the temporary in the scrutinee returns a collection of types - // which have significant drops. The types with significant drops are also non-obvious when - // reading the expression in the scrutinee. - match counter.temp_increment().len() { - 2 => { - let current_count = counter.i.load(Ordering::Relaxed); - println!("Current count {}", current_count); - assert_eq!(current_count, 0); - }, - 1 => {}, - 3 => {}, - _ => {}, - }; -} - -struct StateWithField { - s: String, -} - -// Should trigger lint only on the type in the tuple which is created using a temporary -// with a significant drop. Additionally, this test ensures that the format of the tuple -// is preserved correctly in the suggestion. -fn should_trigger_lint_for_tuple_in_scrutinee() { - let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); - - { - match (mutex1.lock().unwrap().s.len(), true) { - (3, _) => { - println!("started"); - mutex1.lock().unwrap().s.len(); - println!("done"); - }, - (_, _) => {}, - }; - - match (true, mutex1.lock().unwrap().s.len(), true) { - (_, 3, _) => { - println!("started"); - mutex1.lock().unwrap().s.len(); - println!("done"); - }, - (_, _, _) => {}, - }; - - let mutex2 = Mutex::new(StateWithField { s: "two".to_owned() }); - match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { - (3, _, 3) => { - println!("started"); - mutex1.lock().unwrap().s.len(); - mutex2.lock().unwrap().s.len(); - println!("done"); - }, - (_, _, _) => {}, - }; - - let mutex3 = Mutex::new(StateWithField { s: "three".to_owned() }); - match mutex3.lock().unwrap().s.as_str() { - "three" => { - println!("started"); - mutex1.lock().unwrap().s.len(); - mutex2.lock().unwrap().s.len(); - println!("done"); - }, - _ => {}, - }; - - match (true, mutex3.lock().unwrap().s.as_str()) { - (_, "three") => { - println!("started"); - mutex1.lock().unwrap().s.len(); - mutex2.lock().unwrap().s.len(); - println!("done"); - }, - (_, _) => {}, - }; - } -} - -// Should trigger lint when either side of a binary operation creates a temporary with a -// significant drop. -// To avoid potential unnecessary copies or creating references that would trigger the significant -// drop problem, the lint recommends moving the entire binary operation. -fn should_trigger_lint_for_accessing_field_in_mutex_in_one_side_of_binary_op() { - let mutex = Mutex::new(StateWithField { s: "state".to_owned() }); - - match mutex.lock().unwrap().s.len() > 1 { - true => { - mutex.lock().unwrap().s.len(); - }, - false => {}, - }; - - match 1 < mutex.lock().unwrap().s.len() { - true => { - mutex.lock().unwrap().s.len(); - }, - false => {}, - }; -} - -// Should trigger lint when both sides of a binary operation creates a temporary with a -// significant drop. -// To avoid potential unnecessary copies or creating references that would trigger the significant -// drop problem, the lint recommends moving the entire binary operation. -fn should_trigger_lint_for_accessing_fields_in_mutex_in_both_sides_of_binary_op() { - let mutex1 = Mutex::new(StateWithField { s: "state".to_owned() }); - let mutex2 = Mutex::new(StateWithField { - s: "statewithfield".to_owned(), - }); - - match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { - true => { - println!( - "{} < {}", - mutex1.lock().unwrap().s.len(), - mutex2.lock().unwrap().s.len() - ); - }, - false => {}, - }; - - match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { - true => { - println!( - "{} >= {}", - mutex1.lock().unwrap().s.len(), - mutex2.lock().unwrap().s.len() - ); - }, - false => {}, - }; -} - -fn should_not_trigger_lint_for_closure_in_scrutinee() { - let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); - - let get_mutex_guard = || mutex1.lock().unwrap().s.len(); - - // Should not trigger lint because the temporary with a significant drop will be dropped - // at the end of the closure, so the MutexGuard will be unlocked and not have a potentially - // surprising lifetime. - match get_mutex_guard() > 1 { - true => { - mutex1.lock().unwrap().s.len(); - }, - false => {}, - }; -} - -fn should_trigger_lint_for_return_from_closure_in_scrutinee() { - let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); - - let get_mutex_guard = || mutex1.lock().unwrap(); - - // Should trigger lint because the temporary with a significant drop is returned from the - // closure but not used directly in any match arms, so it has a potentially surprising lifetime. - match get_mutex_guard().s.len() > 1 { - true => { - mutex1.lock().unwrap().s.len(); - }, - false => {}, - }; -} - -fn should_trigger_lint_for_return_from_match_in_scrutinee() { - let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); - let mutex2 = Mutex::new(StateWithField { s: "two".to_owned() }); - - let i = 100; - - // Should trigger lint because the nested match within the scrutinee returns a temporary with a - // significant drop is but not used directly in any match arms, so it has a potentially - // surprising lifetime. - match match i { - 100 => mutex1.lock().unwrap(), - _ => mutex2.lock().unwrap(), - } - .s - .len() - > 1 - { - true => { - mutex1.lock().unwrap().s.len(); - }, - false => { - println!("nothing to do here"); - }, - }; -} - -fn should_trigger_lint_for_return_from_if_in_scrutinee() { - let mutex1 = Mutex::new(StateWithField { s: "one".to_owned() }); - let mutex2 = Mutex::new(StateWithField { s: "two".to_owned() }); - - let i = 100; - - // Should trigger lint because the nested if-expression within the scrutinee returns a temporary - // with a significant drop is but not used directly in any match arms, so it has a potentially - // surprising lifetime. - match if i > 1 { - mutex1.lock().unwrap() - } else { - mutex2.lock().unwrap() - } - .s - .len() - > 1 - { - true => { - mutex1.lock().unwrap().s.len(); - }, - false => {}, - }; -} - -fn should_not_trigger_lint_for_if_in_scrutinee() { - let mutex = Mutex::new(StateWithField { s: "state".to_owned() }); - - let i = 100; - - // Should not trigger the lint because the temporary with a significant drop *is* dropped within - // the body of the if-expression nested within the match scrutinee, and therefore does not have - // a potentially surprising lifetime. - match if i > 1 { - mutex.lock().unwrap().s.len() > 1 - } else { - false - } { - true => { - mutex.lock().unwrap().s.len(); - }, - false => {}, - }; -} - -struct StateWithBoxedMutexGuard { - u: Mutex, -} - -impl StateWithBoxedMutexGuard { - fn new() -> StateWithBoxedMutexGuard { - StateWithBoxedMutexGuard { u: Mutex::new(42) } - } - fn lock(&self) -> Box> { - Box::new(self.u.lock().unwrap()) - } -} - -fn should_trigger_lint_for_boxed_mutex_guard() { - let s = StateWithBoxedMutexGuard::new(); - - // Should trigger lint because a temporary Box holding a type with a significant drop in a match - // scrutinee may have a potentially surprising lifetime. - match s.lock().deref().deref() { - 0 | 1 => println!("Value was less than 2"), - _ => println!("Value is {}", s.lock().deref()), - }; -} - -struct StateStringWithBoxedMutexGuard { - s: Mutex, -} - -impl StateStringWithBoxedMutexGuard { - fn new() -> StateStringWithBoxedMutexGuard { - StateStringWithBoxedMutexGuard { - s: Mutex::new("A String".to_owned()), - } - } - fn lock(&self) -> Box> { - Box::new(self.s.lock().unwrap()) - } -} - -fn should_trigger_lint_for_boxed_mutex_guard_holding_string() { - let s = StateStringWithBoxedMutexGuard::new(); - - let matcher = String::from("A String"); - - // Should trigger lint because a temporary Box holding a type with a significant drop in a match - // scrutinee may have a potentially surprising lifetime. - match s.lock().deref().deref() { - matcher => println!("Value is {}", s.lock().deref()), - _ => println!("Value was not a match"), - }; -} - -struct StateWithIntField { - i: u64, -} - -// Should trigger lint when either side of an assign expression contains a temporary with a -// significant drop, because the temporary's lifetime will be extended to the end of the match. -// To avoid potential unnecessary copies or creating references that would trigger the significant -// drop problem, the lint recommends moving the entire binary operation. -fn should_trigger_lint_in_assign_expr() { - let mutex = Mutex::new(StateWithIntField { i: 10 }); - - let mut i = 100; - - match mutex.lock().unwrap().i = i { - _ => { - println!("{}", mutex.lock().unwrap().i); - }, - }; - - match i = mutex.lock().unwrap().i { - _ => { - println!("{}", mutex.lock().unwrap().i); - }, - }; - - match mutex.lock().unwrap().i += 1 { - _ => { - println!("{}", mutex.lock().unwrap().i); - }, - }; - - match i += mutex.lock().unwrap().i { - _ => { - println!("{}", mutex.lock().unwrap().i); - }, - }; -} - -#[derive(Debug)] -enum RecursiveEnum { - Foo(Option>), -} - -#[derive(Debug)] -enum GenericRecursiveEnum { - Foo(T, Option>>), -} - -fn should_not_cause_stack_overflow() { - // Test that when a type recursively contains itself, a stack overflow does not occur when - // checking sub-types for significant drops. - let f = RecursiveEnum::Foo(Some(Box::new(RecursiveEnum::Foo(None)))); - match f { - RecursiveEnum::Foo(Some(f)) => { - println!("{:?}", f) - }, - RecursiveEnum::Foo(f) => { - println!("{:?}", f) - }, - } - - let f = GenericRecursiveEnum::Foo(1u64, Some(Box::new(GenericRecursiveEnum::Foo(2u64, None)))); - match f { - GenericRecursiveEnum::Foo(i, Some(f)) => { - println!("{} {:?}", i, f) - }, - GenericRecursiveEnum::Foo(i, f) => { - println!("{} {:?}", i, f) - }, - } -} - -fn should_not_produce_lint_for_try_desugar() -> Result { - // TryDesugar (i.e. using `?` for a Result type) will turn into a match but is out of scope - // for this lint - let rwlock = RwLock::new("1".to_string()); - let result = rwlock.read().unwrap().parse::()?; - println!("{}", result); - rwlock.write().unwrap().push('2'); - Ok(result) -} - -struct ResultReturner { - s: String, -} - -impl ResultReturner { - fn to_number(&self) -> Result { - self.s.parse::() - } -} - -fn should_trigger_lint_for_non_ref_move_and_clone_suggestion() { - let rwlock = RwLock::::new(ResultReturner { s: "1".to_string() }); - match rwlock.read().unwrap().to_number() { - Ok(n) => println!("Converted to number: {}", n), - Err(e) => println!("Could not convert {} to number", e), - }; -} - -fn should_trigger_lint_for_read_write_lock_for_loop() { - // For-in loops desugar to match expressions and are prone to the type of deadlock this lint is - // designed to look for. - let rwlock = RwLock::>::new(vec!["1".to_string()]); - for s in rwlock.read().unwrap().iter() { - println!("{}", s); - } -} - -fn do_bar(mutex: &Mutex) { - mutex.lock().unwrap().bar(); -} - -fn should_trigger_lint_without_significant_drop_in_arm() { - let mutex = Mutex::new(State {}); - - // Should trigger lint because the lifetime of the temporary MutexGuard is surprising because it - // is preserved until the end of the match, but there is no clear indication that this is the - // case. - match mutex.lock().unwrap().foo() { - true => do_bar(&mutex), - false => {}, - }; -} - -fn should_not_trigger_on_significant_iterator_drop() { - let lines = std::io::stdin().lines(); - for line in lines { - println!("foo: {}", line.unwrap()); - } -} - -fn main() {} diff --git a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs index 17df9f88f..0305d895f 100644 --- a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs +++ b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs @@ -1,5 +1,5 @@ // FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 -// +//@no-rustfix #![warn(clippy::significant_drop_in_scrutinee)] #![allow(dead_code, unused_assignments)] #![allow(clippy::match_single_binding, clippy::single_match, clippy::uninlined_format_args)] @@ -53,6 +53,8 @@ fn should_trigger_lint_with_mutex_guard_in_match_scrutinee() { // is preserved until the end of the match, but there is no clear indication that this is the // case. match mutex.lock().unwrap().foo() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { mutex.lock().unwrap().bar(); }, @@ -139,6 +141,8 @@ fn should_trigger_lint_with_wrapped_mutex() { // lifetime is not obvious. Additionally, it is not obvious from looking at the scrutinee that // the temporary contains such a type, making it potentially even more surprising. match s.lock_m().get_the_value() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 1 => { println!("Got 1. Is it still 1?"); println!("{}", s.lock_m().get_the_value()); @@ -160,6 +164,8 @@ fn should_trigger_lint_with_double_wrapped_mutex() { // looking at the scrutinee that the temporary contains such a type, making it potentially even // more surprising. match s.lock_m_m().get_the_value() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 1 => { println!("Got 1. Is it still 1?"); println!("{}", s.lock_m().get_the_value()); @@ -208,6 +214,8 @@ fn should_trigger_lint_for_vec() { // which have significant drops. The types with significant drops are also non-obvious when // reading the expression in the scrutinee. match counter.temp_increment().len() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 2 => { let current_count = counter.i.load(Ordering::Relaxed); println!("Current count {}", current_count); @@ -231,6 +239,8 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { { match (mutex1.lock().unwrap().s.len(), true) { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior (3, _) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -240,6 +250,8 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { }; match (true, mutex1.lock().unwrap().s.len(), true) { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior (_, 3, _) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -250,6 +262,10 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { let mutex2 = Mutex::new(StateWithField { s: "two".to_owned() }); match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior + //~| ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior (3, _, 3) => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -261,6 +277,8 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { let mutex3 = Mutex::new(StateWithField { s: "three".to_owned() }); match mutex3.lock().unwrap().s.as_str() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior "three" => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -271,6 +289,8 @@ fn should_trigger_lint_for_tuple_in_scrutinee() { }; match (true, mutex3.lock().unwrap().s.as_str()) { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior (_, "three") => { println!("started"); mutex1.lock().unwrap().s.len(); @@ -290,6 +310,8 @@ fn should_trigger_lint_for_accessing_field_in_mutex_in_one_side_of_binary_op() { let mutex = Mutex::new(StateWithField { s: "state".to_owned() }); match mutex.lock().unwrap().s.len() > 1 { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { mutex.lock().unwrap().s.len(); }, @@ -297,6 +319,8 @@ fn should_trigger_lint_for_accessing_field_in_mutex_in_one_side_of_binary_op() { }; match 1 < mutex.lock().unwrap().s.len() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { mutex.lock().unwrap().s.len(); }, @@ -315,6 +339,8 @@ fn should_trigger_lint_for_accessing_fields_in_mutex_in_both_sides_of_binary_op( }); match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { println!( "{} < {}", @@ -326,6 +352,8 @@ fn should_trigger_lint_for_accessing_fields_in_mutex_in_both_sides_of_binary_op( }; match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { println!( "{} >= {}", @@ -361,6 +389,8 @@ fn should_trigger_lint_for_return_from_closure_in_scrutinee() { // Should trigger lint because the temporary with a significant drop is returned from the // closure but not used directly in any match arms, so it has a potentially surprising lifetime. match get_mutex_guard().s.len() > 1 { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => { mutex1.lock().unwrap().s.len(); }, @@ -378,6 +408,8 @@ fn should_trigger_lint_for_return_from_match_in_scrutinee() { // significant drop is but not used directly in any match arms, so it has a potentially // surprising lifetime. match match i { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 100 => mutex1.lock().unwrap(), _ => mutex2.lock().unwrap(), } @@ -404,6 +436,8 @@ fn should_trigger_lint_for_return_from_if_in_scrutinee() { // with a significant drop is but not used directly in any match arms, so it has a potentially // surprising lifetime. match if i > 1 { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior mutex1.lock().unwrap() } else { mutex2.lock().unwrap() @@ -458,6 +492,8 @@ fn should_trigger_lint_for_boxed_mutex_guard() { // Should trigger lint because a temporary Box holding a type with a significant drop in a match // scrutinee may have a potentially surprising lifetime. match s.lock().deref().deref() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior 0 | 1 => println!("Value was less than 2"), _ => println!("Value is {}", s.lock().deref()), }; @@ -486,6 +522,8 @@ fn should_trigger_lint_for_boxed_mutex_guard_holding_string() { // Should trigger lint because a temporary Box holding a type with a significant drop in a match // scrutinee may have a potentially surprising lifetime. match s.lock().deref().deref() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior matcher => println!("Value is {}", s.lock().deref()), _ => println!("Value was not a match"), }; @@ -505,24 +543,32 @@ fn should_trigger_lint_in_assign_expr() { let mut i = 100; match mutex.lock().unwrap().i = i { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior _ => { println!("{}", mutex.lock().unwrap().i); }, }; match i = mutex.lock().unwrap().i { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior _ => { println!("{}", mutex.lock().unwrap().i); }, }; match mutex.lock().unwrap().i += 1 { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior _ => { println!("{}", mutex.lock().unwrap().i); }, }; match i += mutex.lock().unwrap().i { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior _ => { println!("{}", mutex.lock().unwrap().i); }, @@ -586,6 +632,8 @@ impl ResultReturner { fn should_trigger_lint_for_non_ref_move_and_clone_suggestion() { let rwlock = RwLock::::new(ResultReturner { s: "1".to_string() }); match rwlock.read().unwrap().to_number() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior Ok(n) => println!("Converted to number: {}", n), Err(e) => println!("Could not convert {} to number", e), }; @@ -596,6 +644,8 @@ fn should_trigger_lint_for_read_write_lock_for_loop() { // designed to look for. let rwlock = RwLock::>::new(vec!["1".to_string()]); for s in rwlock.read().unwrap().iter() { + //~^ ERROR: temporary with significant `Drop` in `for` loop condition will live until + //~| NOTE: this might lead to deadlocks or other unexpected behavior println!("{}", s); } } @@ -611,6 +661,8 @@ fn should_trigger_lint_without_significant_drop_in_arm() { // is preserved until the end of the match, but there is no clear indication that this is the // case. match mutex.lock().unwrap().foo() { + //~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the + //~| NOTE: this might lead to deadlocks or other unexpected behavior true => do_bar(&mutex), false => {}, }; diff --git a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.stderr b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.stderr index b56ace200..05bfda547 100644 --- a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.stderr +++ b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.stderr @@ -3,7 +3,7 @@ error: temporary with significant `Drop` in `match` scrutinee will live until th | LL | match mutex.lock().unwrap().foo() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | true => { +... LL | mutex.lock().unwrap().bar(); | --------------------- another value with significant `Drop` created here ... @@ -12,6 +12,7 @@ LL | }; | = note: this might lead to deadlocks or other unexpected behavior = note: `-D clippy::significant-drop-in-scrutinee` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::significant_drop_in_scrutinee)]` help: try moving the temporary above the match | LL ~ let value = mutex.lock().unwrap().foo(); @@ -19,7 +20,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:141:11 + --> $DIR/significant_drop_in_scrutinee.rs:143:11 | LL | match s.lock_m().get_the_value() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -38,7 +39,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:162:11 + --> $DIR/significant_drop_in_scrutinee.rs:166:11 | LL | match s.lock_m_m().get_the_value() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -57,7 +58,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:210:11 + --> $DIR/significant_drop_in_scrutinee.rs:216:11 | LL | match counter.temp_increment().len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +74,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:233:16 + --> $DIR/significant_drop_in_scrutinee.rs:241:16 | LL | match (mutex1.lock().unwrap().s.len(), true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,7 +93,7 @@ LL ~ match (value, true) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:242:22 + --> $DIR/significant_drop_in_scrutinee.rs:252:22 | LL | match (true, mutex1.lock().unwrap().s.len(), true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -111,7 +112,7 @@ LL ~ match (true, value, true) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:252:16 + --> $DIR/significant_drop_in_scrutinee.rs:264:16 | LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +133,7 @@ LL ~ match (value, true, mutex2.lock().unwrap().s.len()) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:252:54 + --> $DIR/significant_drop_in_scrutinee.rs:264:54 | LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -153,7 +154,7 @@ LL ~ match (mutex1.lock().unwrap().s.len(), true, value) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:263:15 + --> $DIR/significant_drop_in_scrutinee.rs:279:15 | LL | match mutex3.lock().unwrap().s.as_str() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +170,7 @@ LL | }; = note: this might lead to deadlocks or other unexpected behavior error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:273:22 + --> $DIR/significant_drop_in_scrutinee.rs:291:22 | LL | match (true, mutex3.lock().unwrap().s.as_str()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -185,11 +186,11 @@ LL | }; = note: this might lead to deadlocks or other unexpected behavior error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:292:11 + --> $DIR/significant_drop_in_scrutinee.rs:312:11 | LL | match mutex.lock().unwrap().s.len() > 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | true => { +... LL | mutex.lock().unwrap().s.len(); | --------------------- another value with significant `Drop` created here ... @@ -204,11 +205,11 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:299:11 + --> $DIR/significant_drop_in_scrutinee.rs:321:11 | LL | match 1 < mutex.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | true => { +... LL | mutex.lock().unwrap().s.len(); | --------------------- another value with significant `Drop` created here ... @@ -223,7 +224,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:317:11 + --> $DIR/significant_drop_in_scrutinee.rs:341:11 | LL | match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -244,7 +245,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:328:11 + --> $DIR/significant_drop_in_scrutinee.rs:354:11 | LL | match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -265,11 +266,11 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:363:11 + --> $DIR/significant_drop_in_scrutinee.rs:391:11 | LL | match get_mutex_guard().s.len() > 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | true => { +... LL | mutex1.lock().unwrap().s.len(); | ---------------------- another value with significant `Drop` created here ... @@ -284,14 +285,14 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:380:11 + --> $DIR/significant_drop_in_scrutinee.rs:410:11 | LL | match match i { | ___________^ +LL | | +LL | | LL | | 100 => mutex1.lock().unwrap(), -LL | | _ => mutex2.lock().unwrap(), -LL | | } -LL | | .s +... | LL | | .len() LL | | > 1 | |___________^ @@ -306,6 +307,8 @@ LL | }; help: try moving the temporary above the match | LL ~ let value = match i { +LL + +LL + LL + 100 => mutex1.lock().unwrap(), LL + _ => mutex2.lock().unwrap(), LL + } @@ -316,13 +319,13 @@ LL ~ match value | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:406:11 + --> $DIR/significant_drop_in_scrutinee.rs:438:11 | LL | match if i > 1 { | ___________^ +LL | | +LL | | LL | | mutex1.lock().unwrap() -LL | | } else { -LL | | mutex2.lock().unwrap() ... | LL | | .len() LL | | > 1 @@ -338,6 +341,8 @@ LL | }; help: try moving the temporary above the match | LL ~ let value = if i > 1 { +LL + +LL + LL + mutex1.lock().unwrap() LL + } else { LL + mutex2.lock().unwrap() @@ -349,11 +354,11 @@ LL ~ match value | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:460:11 + --> $DIR/significant_drop_in_scrutinee.rs:494:11 | LL | match s.lock().deref().deref() { | ^^^^^^^^^^^^^^^^^^^^^^^^ -LL | 0 | 1 => println!("Value was less than 2"), +... LL | _ => println!("Value is {}", s.lock().deref()), | ---------------- another value with significant `Drop` created here LL | }; @@ -367,10 +372,11 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:488:11 + --> $DIR/significant_drop_in_scrutinee.rs:524:11 | LL | match s.lock().deref().deref() { | ^^^^^^^^^^^^^^^^^^^^^^^^ +... LL | matcher => println!("Value is {}", s.lock().deref()), | ---------------- another value with significant `Drop` created here LL | _ => println!("Value was not a match"), @@ -380,11 +386,11 @@ LL | }; = note: this might lead to deadlocks or other unexpected behavior error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:507:11 + --> $DIR/significant_drop_in_scrutinee.rs:545:11 | LL | match mutex.lock().unwrap().i = i { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | _ => { +... LL | println!("{}", mutex.lock().unwrap().i); | --------------------- another value with significant `Drop` created here LL | }, @@ -399,11 +405,11 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:513:11 + --> $DIR/significant_drop_in_scrutinee.rs:553:11 | LL | match i = mutex.lock().unwrap().i { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | _ => { +... LL | println!("{}", mutex.lock().unwrap().i); | --------------------- another value with significant `Drop` created here LL | }, @@ -418,11 +424,11 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:519:11 + --> $DIR/significant_drop_in_scrutinee.rs:561:11 | LL | match mutex.lock().unwrap().i += 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | _ => { +... LL | println!("{}", mutex.lock().unwrap().i); | --------------------- another value with significant `Drop` created here LL | }, @@ -437,11 +443,11 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:525:11 + --> $DIR/significant_drop_in_scrutinee.rs:569:11 | LL | match i += mutex.lock().unwrap().i { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | _ => { +... LL | println!("{}", mutex.lock().unwrap().i); | --------------------- another value with significant `Drop` created here LL | }, @@ -456,7 +462,7 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:588:11 + --> $DIR/significant_drop_in_scrutinee.rs:634:11 | LL | match rwlock.read().unwrap().to_number() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -467,18 +473,18 @@ LL | }; = note: this might lead to deadlocks or other unexpected behavior error: temporary with significant `Drop` in `for` loop condition will live until the end of the `for` expression - --> $DIR/significant_drop_in_scrutinee.rs:598:14 + --> $DIR/significant_drop_in_scrutinee.rs:646:14 | LL | for s in rwlock.read().unwrap().iter() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | println!("{}", s); +... LL | } | - temporary lives until here | = note: this might lead to deadlocks or other unexpected behavior error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> $DIR/significant_drop_in_scrutinee.rs:613:11 + --> $DIR/significant_drop_in_scrutinee.rs:663:11 | LL | match mutex.lock().unwrap().foo() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/significant_drop_tightening.fixed b/src/tools/clippy/tests/ui/significant_drop_tightening.fixed index 8065e9e5f..ed05f6e0c 100644 --- a/src/tools/clippy/tests/ui/significant_drop_tightening.fixed +++ b/src/tools/clippy/tests/ui/significant_drop_tightening.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::significant_drop_tightening)] use std::sync::Mutex; diff --git a/src/tools/clippy/tests/ui/significant_drop_tightening.rs b/src/tools/clippy/tests/ui/significant_drop_tightening.rs index 1620b7684..e5f17278f 100644 --- a/src/tools/clippy/tests/ui/significant_drop_tightening.rs +++ b/src/tools/clippy/tests/ui/significant_drop_tightening.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::significant_drop_tightening)] use std::sync::Mutex; diff --git a/src/tools/clippy/tests/ui/significant_drop_tightening.stderr b/src/tools/clippy/tests/ui/significant_drop_tightening.stderr index b5cad88ad..6572d9969 100644 --- a/src/tools/clippy/tests/ui/significant_drop_tightening.stderr +++ b/src/tools/clippy/tests/ui/significant_drop_tightening.stderr @@ -1,5 +1,5 @@ error: temporary with significant `Drop` can be early dropped - --> $DIR/significant_drop_tightening.rs:12:9 + --> $DIR/significant_drop_tightening.rs:10:9 | LL | pub fn complex_return_triggers_the_lint() -> i32 { | __________________________________________________- @@ -16,6 +16,7 @@ LL | | } | = note: this might lead to unnecessary resource contention = note: `-D clippy::significant-drop-tightening` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::significant_drop_tightening)]` help: drop the temporary after the end of its last usage | LL ~ let _ = *lock; @@ -23,7 +24,7 @@ LL + drop(lock); | error: temporary with significant `Drop` can be early dropped - --> $DIR/significant_drop_tightening.rs:106:13 + --> $DIR/significant_drop_tightening.rs:104:13 | LL | / { LL | | let mutex = Mutex::new(1i32); @@ -43,7 +44,7 @@ LL + drop(lock); | error: temporary with significant `Drop` can be early dropped - --> $DIR/significant_drop_tightening.rs:127:13 + --> $DIR/significant_drop_tightening.rs:125:13 | LL | / { LL | | let mutex = Mutex::new(1i32); @@ -67,7 +68,7 @@ LL + | error: temporary with significant `Drop` can be early dropped - --> $DIR/significant_drop_tightening.rs:133:17 + --> $DIR/significant_drop_tightening.rs:131:17 | LL | / { LL | | let mutex = Mutex::new(vec![1i32]); diff --git a/src/tools/clippy/tests/ui/similar_names.rs b/src/tools/clippy/tests/ui/similar_names.rs index c21225d15..f46af56c6 100644 --- a/src/tools/clippy/tests/ui/similar_names.rs +++ b/src/tools/clippy/tests/ui/similar_names.rs @@ -3,6 +3,7 @@ unused, clippy::println_empty_string, clippy::empty_loop, + clippy::never_loop, clippy::diverging_sub_expression, clippy::let_unit_value )] @@ -19,8 +20,10 @@ fn main() { let apple: i32; let bpple: i32; + //~^ ERROR: binding's name is too similar to existing binding let cpple: i32; + //~^ ERROR: binding's name is too similar to existing binding let a_bar: i32; let b_bar: i32; @@ -45,10 +48,12 @@ fn main() { let blubx: i32; let bluby: i32; + //~^ ERROR: binding's name is too similar to existing binding let cake: i32; let cakes: i32; let coke: i32; + //~^ ERROR: binding's name is too similar to existing binding match 5 { cheese @ 1 => {}, @@ -67,10 +72,12 @@ fn main() { let xyz1abc: i32; let xyz2abc: i32; let xyzeabc: i32; + //~^ ERROR: binding's name is too similar to existing binding let parser: i32; let parsed: i32; let parsee: i32; + //~^ ERROR: binding's name is too similar to existing binding let setter: i32; let getter: i32; @@ -92,6 +99,7 @@ fn foo() { let Foo { apple: spring, bpple: sprang, + //~^ ERROR: binding's name is too similar to existing binding } = unimplemented!(); } diff --git a/src/tools/clippy/tests/ui/similar_names.stderr b/src/tools/clippy/tests/ui/similar_names.stderr index 43c5cee4b..44ae3532a 100644 --- a/src/tools/clippy/tests/ui/similar_names.stderr +++ b/src/tools/clippy/tests/ui/similar_names.stderr @@ -1,84 +1,85 @@ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:21:9 + --> $DIR/similar_names.rs:22:9 | LL | let bpple: i32; | ^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:19:9 + --> $DIR/similar_names.rs:20:9 | LL | let apple: i32; | ^^^^^ = note: `-D clippy::similar-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::similar_names)]` error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:23:9 + --> $DIR/similar_names.rs:25:9 | LL | let cpple: i32; | ^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:19:9 + --> $DIR/similar_names.rs:20:9 | LL | let apple: i32; | ^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:47:9 + --> $DIR/similar_names.rs:50:9 | LL | let bluby: i32; | ^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:46:9 + --> $DIR/similar_names.rs:49:9 | LL | let blubx: i32; | ^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:51:9 + --> $DIR/similar_names.rs:55:9 | LL | let coke: i32; | ^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:49:9 + --> $DIR/similar_names.rs:53:9 | LL | let cake: i32; | ^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:69:9 + --> $DIR/similar_names.rs:74:9 | LL | let xyzeabc: i32; | ^^^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:67:9 + --> $DIR/similar_names.rs:72:9 | LL | let xyz1abc: i32; | ^^^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:73:9 + --> $DIR/similar_names.rs:79:9 | LL | let parsee: i32; | ^^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:71:9 + --> $DIR/similar_names.rs:77:9 | LL | let parser: i32; | ^^^^^^ error: binding's name is too similar to existing binding - --> $DIR/similar_names.rs:94:16 + --> $DIR/similar_names.rs:101:16 | LL | bpple: sprang, | ^^^^^^ | note: existing binding defined here - --> $DIR/similar_names.rs:93:16 + --> $DIR/similar_names.rs:100:16 | LL | apple: spring, | ^^^^^^ diff --git a/src/tools/clippy/tests/ui/single_call_fn.rs b/src/tools/clippy/tests/ui/single_call_fn.rs index 76e175014..3cc806164 100644 --- a/src/tools/clippy/tests/ui/single_call_fn.rs +++ b/src/tools/clippy/tests/ui/single_call_fn.rs @@ -1,4 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro +//@ignore-32bit +//@aux-build:proc_macros.rs #![allow(clippy::redundant_closure_call, unused)] #![warn(clippy::single_call_fn)] #![no_main] diff --git a/src/tools/clippy/tests/ui/single_call_fn.stderr b/src/tools/clippy/tests/ui/single_call_fn.stderr index 9ef8c4878..d5cd70775 100644 --- a/src/tools/clippy/tests/ui/single_call_fn.stderr +++ b/src/tools/clippy/tests/ui/single_call_fn.stderr @@ -1,5 +1,5 @@ error: this function is only used once - --> $DIR/single_call_fn.rs:33:1 + --> $DIR/single_call_fn.rs:34:1 | LL | / fn c() { LL | | println!("really"); @@ -9,44 +9,45 @@ LL | | } | |_^ | help: used here - --> $DIR/single_call_fn.rs:40:5 + --> $DIR/single_call_fn.rs:41:5 | LL | c(); | ^ = note: `-D clippy::single-call-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_call_fn)]` error: this function is only used once - --> $DIR/single_call_fn.rs:12:1 + --> $DIR/single_call_fn.rs:13:1 | LL | fn i() {} | ^^^^^^^^^ | help: used here - --> $DIR/single_call_fn.rs:17:13 + --> $DIR/single_call_fn.rs:18:13 | LL | let a = i; | ^ error: this function is only used once - --> $DIR/single_call_fn.rs:43:1 + --> $DIR/single_call_fn.rs:44:1 | LL | fn a() {} | ^^^^^^^^^ | help: used here - --> $DIR/single_call_fn.rs:46:5 + --> $DIR/single_call_fn.rs:47:5 | LL | a(); | ^ error: this function is only used once - --> $DIR/single_call_fn.rs:13:1 + --> $DIR/single_call_fn.rs:14:1 | LL | fn j() {} | ^^^^^^^^^ | help: used here - --> $DIR/single_call_fn.rs:24:9 + --> $DIR/single_call_fn.rs:25:9 | LL | j(); | ^ diff --git a/src/tools/clippy/tests/ui/single_char_add_str.fixed b/src/tools/clippy/tests/ui/single_char_add_str.fixed index cb301c8bc..eafd17f53 100644 --- a/src/tools/clippy/tests/ui/single_char_add_str.fixed +++ b/src/tools/clippy/tests/ui/single_char_add_str.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::single_char_add_str)] #![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes)] diff --git a/src/tools/clippy/tests/ui/single_char_add_str.rs b/src/tools/clippy/tests/ui/single_char_add_str.rs index 99baf35ac..5326c7cf2 100644 --- a/src/tools/clippy/tests/ui/single_char_add_str.rs +++ b/src/tools/clippy/tests/ui/single_char_add_str.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::single_char_add_str)] #![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes)] diff --git a/src/tools/clippy/tests/ui/single_char_add_str.stderr b/src/tools/clippy/tests/ui/single_char_add_str.stderr index 3f93c1847..a6f2b3e03 100644 --- a/src/tools/clippy/tests/ui/single_char_add_str.stderr +++ b/src/tools/clippy/tests/ui/single_char_add_str.stderr @@ -1,91 +1,92 @@ error: calling `push_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:15:5 + --> $DIR/single_char_add_str.rs:14:5 | LL | string.push_str("R"); | ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('R')` | = note: `-D clippy::single-char-add-str` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_char_add_str)]` error: calling `push_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:16:5 + --> $DIR/single_char_add_str.rs:15:5 | LL | string.push_str("'"); - | ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/'')` + | ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('\'')` error: calling `push_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:21:5 + --> $DIR/single_char_add_str.rs:20:5 | -LL | string.push_str("/x52"); - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/x52')` +LL | string.push_str("\x52"); + | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('\x52')` error: calling `push_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:22:5 + --> $DIR/single_char_add_str.rs:21:5 | -LL | string.push_str("/u{0052}"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('/u{0052}')` +LL | string.push_str("\u{0052}"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('\u{0052}')` error: calling `push_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:23:5 + --> $DIR/single_char_add_str.rs:22:5 | LL | string.push_str(r##"a"##); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('a')` error: calling `push_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:25:5 + --> $DIR/single_char_add_str.rs:24:5 | LL | get_string!().push_str("ö"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `get_string!().push('ö')` error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:30:5 + --> $DIR/single_char_add_str.rs:29:5 | LL | string.insert_str(0, "R"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, 'R')` error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:31:5 + --> $DIR/single_char_add_str.rs:30:5 | LL | string.insert_str(1, "'"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(1, '/'')` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(1, '\'')` error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:36:5 + --> $DIR/single_char_add_str.rs:35:5 | -LL | string.insert_str(0, "/x52"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '/x52')` +LL | string.insert_str(0, "\x52"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '\x52')` error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:37:5 + --> $DIR/single_char_add_str.rs:36:5 | -LL | string.insert_str(0, "/u{0052}"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '/u{0052}')` +LL | string.insert_str(0, "\u{0052}"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(0, '\u{0052}')` error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:39:5 + --> $DIR/single_char_add_str.rs:38:5 | LL | string.insert_str(x, r##"a"##); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(x, 'a')` error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:41:5 + --> $DIR/single_char_add_str.rs:40:5 | LL | string.insert_str(Y, r##"a"##); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, 'a')` error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:42:5 + --> $DIR/single_char_add_str.rs:41:5 | LL | string.insert_str(Y, r##"""##); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, '"')` error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:43:5 + --> $DIR/single_char_add_str.rs:42:5 | LL | string.insert_str(Y, r##"'"##); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, '/'')` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `string.insert(Y, '\'')` error: calling `insert_str()` using a single-character string literal - --> $DIR/single_char_add_str.rs:45:5 + --> $DIR/single_char_add_str.rs:44:5 | LL | get_string!().insert_str(1, "?"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `insert` with a character literal: `get_string!().insert(1, '?')` diff --git a/src/tools/clippy/tests/ui/single_char_lifetime_names.rs b/src/tools/clippy/tests/ui/single_char_lifetime_names.rs index 69c5b236f..6731b5b13 100644 --- a/src/tools/clippy/tests/ui/single_char_lifetime_names.rs +++ b/src/tools/clippy/tests/ui/single_char_lifetime_names.rs @@ -3,6 +3,8 @@ // Lifetimes should only be linted when they're introduced struct DiagnosticCtx<'a, 'b> +//~^ ERROR: single-character lifetime names are likely uninformative +//~| ERROR: single-character lifetime names are likely uninformative where 'a: 'b, { @@ -12,6 +14,8 @@ where // Only the lifetimes on the `impl`'s generics should be linted impl<'a, 'b> DiagnosticCtx<'a, 'b> { + //~^ ERROR: single-character lifetime names are likely uninformative + //~| ERROR: single-character lifetime names are likely uninformative fn new(source: &'a str, unit: &'b ()) -> DiagnosticCtx<'a, 'b> { Self { _source: source, @@ -32,6 +36,7 @@ impl<'src, 'unit> DiagnosticCtx<'src, 'unit> { // Only 'a should be linted here fn split_once<'a>(base: &'a str, other: &'_ str) -> (&'a str, Option<&'a str>) { + //~^ ERROR: single-character lifetime names are likely uninformative base.split_once(other) .map(|(left, right)| (left, Some(right))) .unwrap_or((base, None)) diff --git a/src/tools/clippy/tests/ui/single_char_lifetime_names.stderr b/src/tools/clippy/tests/ui/single_char_lifetime_names.stderr index bfe6d44b5..2cdfd6135 100644 --- a/src/tools/clippy/tests/ui/single_char_lifetime_names.stderr +++ b/src/tools/clippy/tests/ui/single_char_lifetime_names.stderr @@ -6,6 +6,7 @@ LL | struct DiagnosticCtx<'a, 'b> | = help: use a more informative name = note: `-D clippy::single-char-lifetime-names` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_char_lifetime_names)]` error: single-character lifetime names are likely uninformative --> $DIR/single_char_lifetime_names.rs:5:26 @@ -16,7 +17,7 @@ LL | struct DiagnosticCtx<'a, 'b> = help: use a more informative name error: single-character lifetime names are likely uninformative - --> $DIR/single_char_lifetime_names.rs:14:6 + --> $DIR/single_char_lifetime_names.rs:16:6 | LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { | ^^ @@ -24,7 +25,7 @@ LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { = help: use a more informative name error: single-character lifetime names are likely uninformative - --> $DIR/single_char_lifetime_names.rs:14:10 + --> $DIR/single_char_lifetime_names.rs:16:10 | LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { | ^^ @@ -32,7 +33,7 @@ LL | impl<'a, 'b> DiagnosticCtx<'a, 'b> { = help: use a more informative name error: single-character lifetime names are likely uninformative - --> $DIR/single_char_lifetime_names.rs:34:15 + --> $DIR/single_char_lifetime_names.rs:38:15 | LL | fn split_once<'a>(base: &'a str, other: &'_ str) -> (&'a str, Option<&'a str>) { | ^^ diff --git a/src/tools/clippy/tests/ui/single_char_pattern.fixed b/src/tools/clippy/tests/ui/single_char_pattern.fixed index 7ae62231a..79e7eda40 100644 --- a/src/tools/clippy/tests/ui/single_char_pattern.fixed +++ b/src/tools/clippy/tests/ui/single_char_pattern.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes, unused_must_use)] use std::collections::HashSet; diff --git a/src/tools/clippy/tests/ui/single_char_pattern.rs b/src/tools/clippy/tests/ui/single_char_pattern.rs index 0604624e7..81962c0a6 100644 --- a/src/tools/clippy/tests/ui/single_char_pattern.rs +++ b/src/tools/clippy/tests/ui/single_char_pattern.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes, unused_must_use)] use std::collections::HashSet; diff --git a/src/tools/clippy/tests/ui/single_char_pattern.stderr b/src/tools/clippy/tests/ui/single_char_pattern.stderr index 5ae2450c2..6e57ab348 100644 --- a/src/tools/clippy/tests/ui/single_char_pattern.stderr +++ b/src/tools/clippy/tests/ui/single_char_pattern.stderr @@ -1,238 +1,239 @@ error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:9:13 + --> $DIR/single_char_pattern.rs:7:13 | LL | x.split("x"); | ^^^ help: try using a `char` instead: `'x'` | = note: `-D clippy::single-char-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_char_pattern)]` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:15:13 + --> $DIR/single_char_pattern.rs:13:13 | LL | x.split("ß"); | ^^^ help: try using a `char` instead: `'ß'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:16:13 + --> $DIR/single_char_pattern.rs:14:13 | LL | x.split("ℝ"); | ^^^ help: try using a `char` instead: `'ℝ'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:17:13 + --> $DIR/single_char_pattern.rs:15:13 | LL | x.split("💣"); | ^^^^ help: try using a `char` instead: `'💣'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:20:23 + --> $DIR/single_char_pattern.rs:18:23 | LL | x.split_inclusive("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:21:16 + --> $DIR/single_char_pattern.rs:19:16 | LL | x.contains("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:22:19 + --> $DIR/single_char_pattern.rs:20:19 | LL | x.starts_with("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:23:17 + --> $DIR/single_char_pattern.rs:21:17 | LL | x.ends_with("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:24:12 + --> $DIR/single_char_pattern.rs:22:12 | LL | x.find("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:25:13 + --> $DIR/single_char_pattern.rs:23:13 | LL | x.rfind("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:26:14 + --> $DIR/single_char_pattern.rs:24:14 | LL | x.rsplit("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:27:24 + --> $DIR/single_char_pattern.rs:25:24 | LL | x.split_terminator("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:28:25 + --> $DIR/single_char_pattern.rs:26:25 | LL | x.rsplit_terminator("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:29:17 + --> $DIR/single_char_pattern.rs:27:17 | LL | x.splitn(2, "x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:30:18 + --> $DIR/single_char_pattern.rs:28:18 | LL | x.rsplitn(2, "x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:31:18 + --> $DIR/single_char_pattern.rs:29:18 | LL | x.split_once("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:32:19 + --> $DIR/single_char_pattern.rs:30:19 | LL | x.rsplit_once("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:33:15 + --> $DIR/single_char_pattern.rs:31:15 | LL | x.matches("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:34:16 + --> $DIR/single_char_pattern.rs:32:16 | LL | x.rmatches("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:35:21 + --> $DIR/single_char_pattern.rs:33:21 | LL | x.match_indices("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:36:22 + --> $DIR/single_char_pattern.rs:34:22 | LL | x.rmatch_indices("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:37:26 + --> $DIR/single_char_pattern.rs:35:26 | LL | x.trim_start_matches("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:38:24 + --> $DIR/single_char_pattern.rs:36:24 | LL | x.trim_end_matches("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:39:20 + --> $DIR/single_char_pattern.rs:37:20 | LL | x.strip_prefix("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:40:20 + --> $DIR/single_char_pattern.rs:38:20 | LL | x.strip_suffix("x"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:41:15 + --> $DIR/single_char_pattern.rs:39:15 | LL | x.replace("x", "y"); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:42:16 + --> $DIR/single_char_pattern.rs:40:16 | LL | x.replacen("x", "y", 3); | ^^^ help: try using a `char` instead: `'x'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:44:13 + --> $DIR/single_char_pattern.rs:42:13 | -LL | x.split("/n"); - | ^^^^ help: try using a `char` instead: `'/n'` +LL | x.split("\n"); + | ^^^^ help: try using a `char` instead: `'\n'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:45:13 + --> $DIR/single_char_pattern.rs:43:13 | LL | x.split("'"); - | ^^^ help: try using a `char` instead: `'/''` + | ^^^ help: try using a `char` instead: `'\''` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:46:13 + --> $DIR/single_char_pattern.rs:44:13 | -LL | x.split("/'"); - | ^^^^ help: try using a `char` instead: `'/''` +LL | x.split("\'"); + | ^^^^ help: try using a `char` instead: `'\''` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:51:31 + --> $DIR/single_char_pattern.rs:49:31 | LL | x.replace(';', ",").split(","); // issue #2978 | ^^^ help: try using a `char` instead: `','` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:52:19 + --> $DIR/single_char_pattern.rs:50:19 | -LL | x.starts_with("/x03"); // issue #2996 - | ^^^^^^ help: try using a `char` instead: `'/x03'` +LL | x.starts_with("\x03"); // issue #2996 + | ^^^^^^ help: try using a `char` instead: `'\x03'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:59:13 + --> $DIR/single_char_pattern.rs:57:13 | LL | x.split(r"a"); | ^^^^ help: try using a `char` instead: `'a'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:60:13 + --> $DIR/single_char_pattern.rs:58:13 | LL | x.split(r#"a"#); | ^^^^^^ help: try using a `char` instead: `'a'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:61:13 + --> $DIR/single_char_pattern.rs:59:13 | LL | x.split(r###"a"###); | ^^^^^^^^^^ help: try using a `char` instead: `'a'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:62:13 + --> $DIR/single_char_pattern.rs:60:13 | LL | x.split(r###"'"###); - | ^^^^^^^^^^ help: try using a `char` instead: `'/''` + | ^^^^^^^^^^ help: try using a `char` instead: `'\''` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:63:13 + --> $DIR/single_char_pattern.rs:61:13 | LL | x.split(r###"#"###); | ^^^^^^^^^^ help: try using a `char` instead: `'#'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:65:13 + --> $DIR/single_char_pattern.rs:63:13 | -LL | x.split(r#"/"#); - | ^^^^^^ help: try using a `char` instead: `'//'` +LL | x.split(r#"\"#); + | ^^^^^^ help: try using a `char` instead: `'\\'` error: single-character string constant used as pattern - --> $DIR/single_char_pattern.rs:66:13 + --> $DIR/single_char_pattern.rs:64:13 | -LL | x.split(r"/"); - | ^^^^ help: try using a `char` instead: `'//'` +LL | x.split(r"\"); + | ^^^^ help: try using a `char` instead: `'\\'` error: aborting due to 39 previous errors diff --git a/src/tools/clippy/tests/ui/single_component_path_imports.fixed b/src/tools/clippy/tests/ui/single_component_path_imports.fixed index b6b6b0288..fdff336c2 100644 --- a/src/tools/clippy/tests/ui/single_component_path_imports.fixed +++ b/src/tools/clippy/tests/ui/single_component_path_imports.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::single_component_path_imports)] #![allow(unused_imports)] diff --git a/src/tools/clippy/tests/ui/single_component_path_imports.rs b/src/tools/clippy/tests/ui/single_component_path_imports.rs index a8c4d8990..2d72f122a 100644 --- a/src/tools/clippy/tests/ui/single_component_path_imports.rs +++ b/src/tools/clippy/tests/ui/single_component_path_imports.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::single_component_path_imports)] #![allow(unused_imports)] diff --git a/src/tools/clippy/tests/ui/single_component_path_imports.stderr b/src/tools/clippy/tests/ui/single_component_path_imports.stderr index 853a2fe0e..440d34002 100644 --- a/src/tools/clippy/tests/ui/single_component_path_imports.stderr +++ b/src/tools/clippy/tests/ui/single_component_path_imports.stderr @@ -1,13 +1,14 @@ error: this import is redundant - --> $DIR/single_component_path_imports.rs:7:1 + --> $DIR/single_component_path_imports.rs:6:1 | LL | use regex; | ^^^^^^^^^^ help: remove it entirely | = note: `-D clippy::single-component-path-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_component_path_imports)]` error: this import is redundant - --> $DIR/single_component_path_imports.rs:33:5 + --> $DIR/single_component_path_imports.rs:32:5 | LL | use regex; | ^^^^^^^^^^ help: remove it entirely diff --git a/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.rs b/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.rs index d6243c19f..b4a1ce1d6 100644 --- a/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.rs +++ b/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.rs @@ -1,7 +1,9 @@ #![warn(clippy::single_component_path_imports)] #![allow(unused_imports)] - +//@no-rustfix use regex; +//~^ ERROR: this import is redundant +//~| NOTE: `-D clippy::single-component-path-imports` implied by `-D warnings` use serde as edres; @@ -13,6 +15,8 @@ fn main() { mod root_nested_use_mod { use {regex, serde}; + //~^ ERROR: this import is redundant + //~| ERROR: this import is redundant #[allow(dead_code)] fn root_nested_use_mod() {} } diff --git a/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr b/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr index ff148355e..d65ab5620 100644 --- a/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr +++ b/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr @@ -5,9 +5,10 @@ LL | use regex; | ^^^^^^^^^^ help: remove it entirely | = note: `-D clippy::single-component-path-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_component_path_imports)]` error: this import is redundant - --> $DIR/single_component_path_imports_nested_first.rs:15:10 + --> $DIR/single_component_path_imports_nested_first.rs:17:10 | LL | use {regex, serde}; | ^^^^^ @@ -15,7 +16,7 @@ LL | use {regex, serde}; = help: remove this import error: this import is redundant - --> $DIR/single_component_path_imports_nested_first.rs:15:17 + --> $DIR/single_component_path_imports_nested_first.rs:17:17 | LL | use {regex, serde}; | ^^^^^ diff --git a/src/tools/clippy/tests/ui/single_element_loop.fixed b/src/tools/clippy/tests/ui/single_element_loop.fixed index 598f25941..a82eb6afc 100644 --- a/src/tools/clippy/tests/ui/single_element_loop.fixed +++ b/src/tools/clippy/tests/ui/single_element_loop.fixed @@ -1,4 +1,3 @@ -//@run-rustfix // Tests from for_loop.rs that don't have suggestions #![allow(clippy::single_range_in_vec_init)] diff --git a/src/tools/clippy/tests/ui/single_element_loop.rs b/src/tools/clippy/tests/ui/single_element_loop.rs index 3fc461735..a55ece6b0 100644 --- a/src/tools/clippy/tests/ui/single_element_loop.rs +++ b/src/tools/clippy/tests/ui/single_element_loop.rs @@ -1,4 +1,3 @@ -//@run-rustfix // Tests from for_loop.rs that don't have suggestions #![allow(clippy::single_range_in_vec_init)] diff --git a/src/tools/clippy/tests/ui/single_element_loop.stderr b/src/tools/clippy/tests/ui/single_element_loop.stderr index c40c61989..603dd7406 100644 --- a/src/tools/clippy/tests/ui/single_element_loop.stderr +++ b/src/tools/clippy/tests/ui/single_element_loop.stderr @@ -1,5 +1,5 @@ error: for loop over a single element - --> $DIR/single_element_loop.rs:9:5 + --> $DIR/single_element_loop.rs:8:5 | LL | / for item in &[item1] { LL | | dbg!(item); @@ -7,6 +7,7 @@ LL | | } | |_____^ | = note: `-D clippy::single-element-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_element_loop)]` help: try | LL ~ { @@ -16,7 +17,7 @@ LL + } | error: for loop over a single element - --> $DIR/single_element_loop.rs:13:5 + --> $DIR/single_element_loop.rs:12:5 | LL | / for item in [item1].iter() { LL | | dbg!(item); @@ -32,7 +33,7 @@ LL + } | error: for loop over a single element - --> $DIR/single_element_loop.rs:17:5 + --> $DIR/single_element_loop.rs:16:5 | LL | / for item in &[0..5] { LL | | dbg!(item); @@ -48,7 +49,7 @@ LL + } | error: for loop over a single element - --> $DIR/single_element_loop.rs:21:5 + --> $DIR/single_element_loop.rs:20:5 | LL | / for item in [0..5].iter_mut() { LL | | dbg!(item); @@ -64,7 +65,7 @@ LL + } | error: for loop over a single element - --> $DIR/single_element_loop.rs:25:5 + --> $DIR/single_element_loop.rs:24:5 | LL | / for item in [0..5] { LL | | dbg!(item); @@ -80,7 +81,7 @@ LL + } | error: for loop over a single element - --> $DIR/single_element_loop.rs:29:5 + --> $DIR/single_element_loop.rs:28:5 | LL | / for item in [0..5].into_iter() { LL | | dbg!(item); @@ -96,7 +97,7 @@ LL + } | error: for loop over a single element - --> $DIR/single_element_loop.rs:48:5 + --> $DIR/single_element_loop.rs:47:5 | LL | / for _ in [42] { LL | | let _f = |n: u32| { diff --git a/src/tools/clippy/tests/ui/single_match.fixed b/src/tools/clippy/tests/ui/single_match.fixed index 163ba94af..0a49be2dc 100644 --- a/src/tools/clippy/tests/ui/single_match.fixed +++ b/src/tools/clippy/tests/ui/single_match.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::single_match)] #![allow( unused, diff --git a/src/tools/clippy/tests/ui/single_match.rs b/src/tools/clippy/tests/ui/single_match.rs index 0dcdb125f..4e35d265a 100644 --- a/src/tools/clippy/tests/ui/single_match.rs +++ b/src/tools/clippy/tests/ui/single_match.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::single_match)] #![allow( unused, diff --git a/src/tools/clippy/tests/ui/single_match.stderr b/src/tools/clippy/tests/ui/single_match.stderr index d35361599..d4b865995 100644 --- a/src/tools/clippy/tests/ui/single_match.stderr +++ b/src/tools/clippy/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:15:5 + --> $DIR/single_match.rs:14:5 | LL | / match x { LL | | Some(y) => { @@ -10,6 +10,7 @@ LL | | }; | |_____^ | = note: `-D clippy::single-match` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_match)]` help: try | LL ~ if let Some(y) = x { @@ -18,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:23:5 + --> $DIR/single_match.rs:22:5 | LL | / match x { LL | | // Note the missing block braces. @@ -30,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:32:5 + --> $DIR/single_match.rs:31:5 | LL | / match z { LL | | (2..=3, 7..=9) => dummy(), @@ -39,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:61:5 + --> $DIR/single_match.rs:60:5 | LL | / match x { LL | | Some(y) => dummy(), @@ -48,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:66:5 + --> $DIR/single_match.rs:65:5 | LL | / match y { LL | | Ok(y) => dummy(), @@ -57,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:73:5 + --> $DIR/single_match.rs:72:5 | LL | / match c { LL | | Cow::Borrowed(..) => dummy(), @@ -66,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:94:5 + --> $DIR/single_match.rs:93:5 | LL | / match x { LL | | "test" => println!(), @@ -75,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:107:5 + --> $DIR/single_match.rs:106:5 | LL | / match x { LL | | Foo::A => println!(), @@ -84,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:113:5 + --> $DIR/single_match.rs:112:5 | LL | / match x { LL | | FOO_C => println!(), @@ -93,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:118:5 + --> $DIR/single_match.rs:117:5 | LL | / match &&x { LL | | Foo::A => println!(), @@ -102,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:124:5 + --> $DIR/single_match.rs:123:5 | LL | / match &x { LL | | Foo::A => println!(), @@ -111,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:141:5 + --> $DIR/single_match.rs:140:5 | LL | / match x { LL | | Bar::A => println!(), @@ -120,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:149:5 + --> $DIR/single_match.rs:148:5 | LL | / match x { LL | | None => println!(), @@ -129,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:171:5 + --> $DIR/single_match.rs:170:5 | LL | / match x { LL | | (Some(_), _) => {}, @@ -138,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:177:5 + --> $DIR/single_match.rs:176:5 | LL | / match x { LL | | (Some(E::V), _) => todo!(), @@ -147,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:183:5 + --> $DIR/single_match.rs:182:5 | LL | / match (Some(42), Some(E::V), Some(42)) { LL | | (.., Some(E::V), _) => {}, @@ -156,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:255:5 + --> $DIR/single_match.rs:254:5 | LL | / match bar { LL | | Some(v) => unsafe { @@ -176,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:263:5 + --> $DIR/single_match.rs:262:5 | LL | / match bar { LL | | #[rustfmt::skip] diff --git a/src/tools/clippy/tests/ui/single_match_else.fixed b/src/tools/clippy/tests/ui/single_match_else.fixed index fcc8f1480..f3b1de3b4 100644 --- a/src/tools/clippy/tests/ui/single_match_else.fixed +++ b/src/tools/clippy/tests/ui/single_match_else.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![warn(clippy::single_match_else)] #![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)] extern crate proc_macros; diff --git a/src/tools/clippy/tests/ui/single_match_else.rs b/src/tools/clippy/tests/ui/single_match_else.rs index 77afd58a0..ddee2e42e 100644 --- a/src/tools/clippy/tests/ui/single_match_else.rs +++ b/src/tools/clippy/tests/ui/single_match_else.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![warn(clippy::single_match_else)] #![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)] extern crate proc_macros; diff --git a/src/tools/clippy/tests/ui/single_match_else.stderr b/src/tools/clippy/tests/ui/single_match_else.stderr index 5e7d4062e..3b4b1332c 100644 --- a/src/tools/clippy/tests/ui/single_match_else.stderr +++ b/src/tools/clippy/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:17:13 + --> $DIR/single_match_else.rs:16:13 | LL | let _ = match ExprNode::Butterflies { | _____________^ @@ -12,6 +12,7 @@ LL | | }; | |_____^ | = note: `-D clippy::single-match-else` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_match_else)]` help: try | LL ~ let _ = if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else { @@ -21,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:82:5 + --> $DIR/single_match_else.rs:81:5 | LL | / match Some(1) { LL | | Some(a) => println!("${:?}", a), @@ -41,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:91:5 + --> $DIR/single_match_else.rs:90:5 | LL | / match Some(1) { LL | | Some(a) => println!("${:?}", a), @@ -61,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:101:5 + --> $DIR/single_match_else.rs:100:5 | LL | / match Result::::Ok(1) { LL | | Ok(a) => println!("${:?}", a), @@ -81,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:110:5 + --> $DIR/single_match_else.rs:109:5 | LL | / match Cow::from("moo") { LL | | Cow::Owned(a) => println!("${:?}", a), @@ -101,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:120:5 + --> $DIR/single_match_else.rs:119:5 | LL | / match bar { LL | | Some(v) => unsafe { @@ -124,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:131:5 + --> $DIR/single_match_else.rs:130:5 | LL | / match bar { LL | | Some(v) => { @@ -148,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:143:5 + --> $DIR/single_match_else.rs:142:5 | LL | / match bar { LL | | Some(v) => unsafe { @@ -172,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:155:5 + --> $DIR/single_match_else.rs:154:5 | LL | / match bar { LL | | #[rustfmt::skip] diff --git a/src/tools/clippy/tests/ui/single_range_in_vec_init.rs b/src/tools/clippy/tests/ui/single_range_in_vec_init.rs index 833e1c43b..7887cfc61 100644 --- a/src/tools/clippy/tests/ui/single_range_in_vec_init.rs +++ b/src/tools/clippy/tests/ui/single_range_in_vec_init.rs @@ -1,4 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs +//@no-rustfix: overlapping suggestions #![allow(clippy::no_effect, clippy::useless_vec, unused)] #![warn(clippy::single_range_in_vec_init)] #![feature(generic_arg_infer)] diff --git a/src/tools/clippy/tests/ui/single_range_in_vec_init.stderr b/src/tools/clippy/tests/ui/single_range_in_vec_init.stderr index 3e3d521f4..e83e49af6 100644 --- a/src/tools/clippy/tests/ui/single_range_in_vec_init.stderr +++ b/src/tools/clippy/tests/ui/single_range_in_vec_init.stderr @@ -1,10 +1,11 @@ error: an array of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:25:5 + --> $DIR/single_range_in_vec_init.rs:26:5 | LL | [0..200]; | ^^^^^^^^ | = note: `-D clippy::single-range-in-vec-init` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::single_range_in_vec_init)]` help: if you wanted a `Vec` that contains the entire range, try | LL | (0..200).collect::>(); @@ -15,7 +16,7 @@ LL | [0; 200]; | ~~~~~~ error: a `Vec` of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:26:5 + --> $DIR/single_range_in_vec_init.rs:27:5 | LL | vec![0..200]; | ^^^^^^^^^^^^ @@ -30,7 +31,7 @@ LL | vec![0; 200]; | ~~~~~~ error: an array of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:27:5 + --> $DIR/single_range_in_vec_init.rs:28:5 | LL | [0u8..200]; | ^^^^^^^^^^ @@ -45,7 +46,7 @@ LL | [0u8; 200]; | ~~~~~~~~ error: an array of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:28:5 + --> $DIR/single_range_in_vec_init.rs:29:5 | LL | [0usize..200]; | ^^^^^^^^^^^^^ @@ -60,7 +61,7 @@ LL | [0usize; 200]; | ~~~~~~~~~~~ error: an array of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:29:5 + --> $DIR/single_range_in_vec_init.rs:30:5 | LL | [0..200usize]; | ^^^^^^^^^^^^^ @@ -75,7 +76,7 @@ LL | [0; 200usize]; | ~~~~~~~~~~~ error: a `Vec` of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:30:5 + --> $DIR/single_range_in_vec_init.rs:31:5 | LL | vec![0u8..200]; | ^^^^^^^^^^^^^^ @@ -90,7 +91,7 @@ LL | vec![0u8; 200]; | ~~~~~~~~ error: a `Vec` of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:31:5 + --> $DIR/single_range_in_vec_init.rs:32:5 | LL | vec![0usize..200]; | ^^^^^^^^^^^^^^^^^ @@ -105,7 +106,7 @@ LL | vec![0usize; 200]; | ~~~~~~~~~~~ error: a `Vec` of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:32:5 + --> $DIR/single_range_in_vec_init.rs:33:5 | LL | vec![0..200usize]; | ^^^^^^^^^^^^^^^^^ @@ -120,7 +121,7 @@ LL | vec![0; 200usize]; | ~~~~~~~~~~~ error: an array of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:34:5 + --> $DIR/single_range_in_vec_init.rs:35:5 | LL | [0..200isize]; | ^^^^^^^^^^^^^ @@ -131,7 +132,7 @@ LL | (0..200isize).collect::>(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: a `Vec` of `Range` that is only one element - --> $DIR/single_range_in_vec_init.rs:35:5 + --> $DIR/single_range_in_vec_init.rs:36:5 | LL | vec![0..200isize]; | ^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/size_of_in_element_count/expressions.rs b/src/tools/clippy/tests/ui/size_of_in_element_count/expressions.rs index 2594e8fa6..91b7ea392 100644 --- a/src/tools/clippy/tests/ui/size_of_in_element_count/expressions.rs +++ b/src/tools/clippy/tests/ui/size_of_in_element_count/expressions.rs @@ -13,12 +13,15 @@ fn main() { // Count expression involving multiplication of size_of (Should trigger the lint) unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` // Count expression involving nested multiplications of size_of (Should trigger the lint) unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * size_of_val(&x[0]) * 2) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` // Count expression involving divisions of size_of (Should trigger the lint) unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() / 2) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` // Count expression involving divisions by size_of (Should not trigger the lint) unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / size_of::()) }; @@ -28,6 +31,7 @@ fn main() { // Count expression involving recursive divisions by size_of (Should trigger the lint) unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / (2 / size_of::())) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` // No size_of calls (Should not trigger the lint) unsafe { copy(x.as_ptr(), y.as_mut_ptr(), SIZE) }; diff --git a/src/tools/clippy/tests/ui/size_of_in_element_count/expressions.stderr b/src/tools/clippy/tests/ui/size_of_in_element_count/expressions.stderr index 037f695f3..47f9632b8 100644 --- a/src/tools/clippy/tests/ui/size_of_in_element_count/expressions.stderr +++ b/src/tools/clippy/tests/ui/size_of_in_element_count/expressions.stderr @@ -6,9 +6,10 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::( | = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::size_of_in_element_count)]` error: found a count of bytes instead of a count of elements of `T` - --> $DIR/expressions.rs:18:62 + --> $DIR/expressions.rs:19:62 | LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * size_of_val(&x[0]) * 2) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * si = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/expressions.rs:21:47 + --> $DIR/expressions.rs:23:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() / 2) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::() = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/expressions.rs:30:47 + --> $DIR/expressions.rs:33:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE / (2 / size_of::())) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/size_of_in_element_count/functions.rs b/src/tools/clippy/tests/ui/size_of_in_element_count/functions.rs index 09d08ac37..3501cbdf8 100644 --- a/src/tools/clippy/tests/ui/size_of_in_element_count/functions.rs +++ b/src/tools/clippy/tests/ui/size_of_in_element_count/functions.rs @@ -16,31 +16,52 @@ fn main() { // Count is size_of (Should trigger the lint) unsafe { copy_nonoverlapping::(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { write_bytes(y.as_mut_ptr(), 0u8, size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_mut_ptr().sub(size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` y.as_ptr().wrapping_sub(size_of::()); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_ptr().add(size_of::()) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` y.as_mut_ptr().wrapping_add(size_of::()); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` unsafe { y.as_ptr().offset(size_of::() as isize) }; + //~^ ERROR: found a count of bytes instead of a count of elements of `T` y.as_mut_ptr().wrapping_offset(size_of::() as isize); + //~^ ERROR: found a count of bytes instead of a count of elements of `T` } diff --git a/src/tools/clippy/tests/ui/size_of_in_element_count/functions.stderr b/src/tools/clippy/tests/ui/size_of_in_element_count/functions.stderr index 4351e6a14..aba4c800e 100644 --- a/src/tools/clippy/tests/ui/size_of_in_element_count/functions.stderr +++ b/src/tools/clippy/tests/ui/size_of_in_element_count/functions.stderr @@ -6,9 +6,10 @@ LL | unsafe { copy_nonoverlapping::(x.as_ptr(), y.as_mut_ptr(), size_of: | = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type = note: `-D clippy::size-of-in-element-count` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::size_of_in_element_count)]` error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:19:62 + --> $DIR/functions.rs:20:62 | LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; | ^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:21:49 + --> $DIR/functions.rs:23:49 | LL | unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::()) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:22:64 + --> $DIR/functions.rs:25:64 | LL | unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of:: $DIR/functions.rs:23:51 + --> $DIR/functions.rs:27:51 | LL | unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), size_of::()) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:24:66 + --> $DIR/functions.rs:29:66 | LL | unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::< = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:26:47 + --> $DIR/functions.rs:32:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::()) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:27:47 + --> $DIR/functions.rs:34:47 | LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; | ^^^^^^^^^^^^^^^^^^ @@ -64,7 +65,7 @@ LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:29:46 + --> $DIR/functions.rs:37:46 | LL | unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL | unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::() * SIZE) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:30:47 + --> $DIR/functions.rs:39:47 | LL | unsafe { write_bytes(y.as_mut_ptr(), 0u8, size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +81,7 @@ LL | unsafe { write_bytes(y.as_mut_ptr(), 0u8, size_of::() * SIZE) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:32:66 + --> $DIR/functions.rs:42:66 | LL | unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +89,7 @@ LL | unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::< = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:34:46 + --> $DIR/functions.rs:45:46 | LL | slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +97,7 @@ LL | slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE); = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:35:38 + --> $DIR/functions.rs:47:38 | LL | slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +105,7 @@ LL | slice_from_raw_parts(y.as_ptr(), size_of::() * SIZE); = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:37:49 + --> $DIR/functions.rs:50:49 | LL | unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +113,7 @@ LL | unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::() * SIZE) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:38:41 + --> $DIR/functions.rs:52:41 | LL | unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +121,7 @@ LL | unsafe { from_raw_parts(y.as_ptr(), size_of::() * SIZE) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:40:33 + --> $DIR/functions.rs:55:33 | LL | unsafe { y.as_mut_ptr().sub(size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -128,7 +129,7 @@ LL | unsafe { y.as_mut_ptr().sub(size_of::()) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:41:29 + --> $DIR/functions.rs:57:29 | LL | y.as_ptr().wrapping_sub(size_of::()); | ^^^^^^^^^^^^^^^ @@ -136,7 +137,7 @@ LL | y.as_ptr().wrapping_sub(size_of::()); = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:42:29 + --> $DIR/functions.rs:59:29 | LL | unsafe { y.as_ptr().add(size_of::()) }; | ^^^^^^^^^^^^^^^ @@ -144,7 +145,7 @@ LL | unsafe { y.as_ptr().add(size_of::()) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:43:33 + --> $DIR/functions.rs:61:33 | LL | y.as_mut_ptr().wrapping_add(size_of::()); | ^^^^^^^^^^^^^^^ @@ -152,7 +153,7 @@ LL | y.as_mut_ptr().wrapping_add(size_of::()); = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:44:32 + --> $DIR/functions.rs:63:32 | LL | unsafe { y.as_ptr().offset(size_of::() as isize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -160,7 +161,7 @@ LL | unsafe { y.as_ptr().offset(size_of::() as isize) }; = help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type error: found a count of bytes instead of a count of elements of `T` - --> $DIR/functions.rs:45:36 + --> $DIR/functions.rs:65:36 | LL | y.as_mut_ptr().wrapping_offset(size_of::() as isize); | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/size_of_ref.rs b/src/tools/clippy/tests/ui/size_of_ref.rs index 1e83ab829..670c6c080 100644 --- a/src/tools/clippy/tests/ui/size_of_ref.rs +++ b/src/tools/clippy/tests/ui/size_of_ref.rs @@ -11,7 +11,9 @@ fn main() { size_of_val(y); // no lint size_of_val(&&x); + //~^ ERROR: argument to `std::mem::size_of_val()` is a reference to a reference size_of_val(&y); + //~^ ERROR: argument to `std::mem::size_of_val()` is a reference to a reference } struct S { @@ -23,5 +25,6 @@ impl S { /// Get size of object including `self`, in bytes. pub fn size(&self) -> usize { std::mem::size_of_val(&self) + (std::mem::size_of::() * self.data.capacity()) + //~^ ERROR: argument to `std::mem::size_of_val()` is a reference to a reference } } diff --git a/src/tools/clippy/tests/ui/size_of_ref.stderr b/src/tools/clippy/tests/ui/size_of_ref.stderr index d4c13ac32..e239c5810 100644 --- a/src/tools/clippy/tests/ui/size_of_ref.stderr +++ b/src/tools/clippy/tests/ui/size_of_ref.stderr @@ -6,9 +6,10 @@ LL | size_of_val(&&x); | = help: dereference the argument to `std::mem::size_of_val()` to get the size of the value instead of the size of the reference-type = note: `-D clippy::size-of-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::size_of_ref)]` error: argument to `std::mem::size_of_val()` is a reference to a reference - --> $DIR/size_of_ref.rs:14:5 + --> $DIR/size_of_ref.rs:15:5 | LL | size_of_val(&y); | ^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | size_of_val(&y); = help: dereference the argument to `std::mem::size_of_val()` to get the size of the value instead of the size of the reference-type error: argument to `std::mem::size_of_val()` is a reference to a reference - --> $DIR/size_of_ref.rs:25:9 + --> $DIR/size_of_ref.rs:27:9 | LL | std::mem::size_of_val(&self) + (std::mem::size_of::() * self.data.capacity()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/skip_while_next.stderr b/src/tools/clippy/tests/ui/skip_while_next.stderr index 7308ab4e5..3c33af3a1 100644 --- a/src/tools/clippy/tests/ui/skip_while_next.stderr +++ b/src/tools/clippy/tests/ui/skip_while_next.stderr @@ -6,6 +6,7 @@ LL | let _ = v.iter().skip_while(|&x| *x < 0).next(); | = help: this is more succinctly expressed by calling `.find(!

)` instead = note: `-D clippy::skip-while-next` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/slow_vector_initialization.rs b/src/tools/clippy/tests/ui/slow_vector_initialization.rs index cfb856861..16f810195 100644 --- a/src/tools/clippy/tests/ui/slow_vector_initialization.rs +++ b/src/tools/clippy/tests/ui/slow_vector_initialization.rs @@ -1,5 +1,5 @@ +//@no-rustfix use std::iter::repeat; - fn main() { resize_vector(); extend_vector(); @@ -12,10 +12,13 @@ fn extend_vector() { let len = 300; let mut vec1 = Vec::with_capacity(len); vec1.extend(repeat(0).take(len)); + //~^ ERROR: slow zero-filling initialization + //~| NOTE: `-D clippy::slow-vector-initialization` implied by `-D warnings` // Extend with len expression let mut vec2 = Vec::with_capacity(len - 10); vec2.extend(repeat(0).take(len - 10)); + //~^ ERROR: slow zero-filling initialization // Extend with mismatching expression should not be warned let mut vec3 = Vec::with_capacity(24322); @@ -23,6 +26,7 @@ fn extend_vector() { let mut vec4 = Vec::with_capacity(len); vec4.extend(repeat(0).take(vec4.capacity())); + //~^ ERROR: slow zero-filling initialization } fn mixed_extend_resize_vector() { @@ -33,9 +37,11 @@ fn mixed_extend_resize_vector() { // Slow initialization let mut resized_vec = Vec::with_capacity(30); resized_vec.resize(30, 0); + //~^ ERROR: slow zero-filling initialization let mut extend_vec = Vec::with_capacity(30); extend_vec.extend(repeat(0).take(30)); + //~^ ERROR: slow zero-filling initialization } fn resize_vector() { @@ -43,6 +49,7 @@ fn resize_vector() { let len = 300; let mut vec1 = Vec::with_capacity(len); vec1.resize(len, 0); + //~^ ERROR: slow zero-filling initialization // Resize mismatch len let mut vec2 = Vec::with_capacity(200); @@ -51,13 +58,16 @@ fn resize_vector() { // Resize with len expression let mut vec3 = Vec::with_capacity(len - 10); vec3.resize(len - 10, 0); + //~^ ERROR: slow zero-filling initialization let mut vec4 = Vec::with_capacity(len); vec4.resize(vec4.capacity(), 0); + //~^ ERROR: slow zero-filling initialization // Reinitialization should be warned vec1 = Vec::with_capacity(10); vec1.resize(10, 0); + //~^ ERROR: slow zero-filling initialization } fn from_empty_vec() { @@ -65,14 +75,31 @@ fn from_empty_vec() { let len = 300; let mut vec1 = Vec::new(); vec1.resize(len, 0); + //~^ ERROR: slow zero-filling initialization // Resize with len expression let mut vec3 = Vec::new(); vec3.resize(len - 10, 0); + //~^ ERROR: slow zero-filling initialization // Reinitialization should be warned vec1 = Vec::new(); vec1.resize(10, 0); + //~^ ERROR: slow zero-filling initialization + + vec1 = vec![]; + vec1.resize(10, 0); + //~^ ERROR: slow zero-filling initialization + + macro_rules! x { + () => { + vec![] + }; + } + + // `vec![]` comes from another macro, don't warn + vec1 = x!(); + vec1.resize(10, 0); } fn do_stuff(vec: &mut [u8]) {} diff --git a/src/tools/clippy/tests/ui/slow_vector_initialization.stderr b/src/tools/clippy/tests/ui/slow_vector_initialization.stderr index c88c97a55..16a705765 100644 --- a/src/tools/clippy/tests/ui/slow_vector_initialization.stderr +++ b/src/tools/clippy/tests/ui/slow_vector_initialization.stderr @@ -7,9 +7,10 @@ LL | vec1.extend(repeat(0).take(len)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::slow-vector-initialization` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::slow_vector_initialization)]` error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:18:5 + --> $DIR/slow_vector_initialization.rs:20:5 | LL | let mut vec2 = Vec::with_capacity(len - 10); | ---------------------------- help: consider replacing this with: `vec![0; len - 10]` @@ -17,7 +18,7 @@ LL | vec2.extend(repeat(0).take(len - 10)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:25:5 + --> $DIR/slow_vector_initialization.rs:28:5 | LL | let mut vec4 = Vec::with_capacity(len); | ----------------------- help: consider replacing this with: `vec![0; len]` @@ -25,7 +26,7 @@ LL | vec4.extend(repeat(0).take(vec4.capacity())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:35:5 + --> $DIR/slow_vector_initialization.rs:39:5 | LL | let mut resized_vec = Vec::with_capacity(30); | ---------------------- help: consider replacing this with: `vec![0; 30]` @@ -33,7 +34,7 @@ LL | resized_vec.resize(30, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:38:5 + --> $DIR/slow_vector_initialization.rs:43:5 | LL | let mut extend_vec = Vec::with_capacity(30); | ---------------------- help: consider replacing this with: `vec![0; 30]` @@ -41,7 +42,7 @@ LL | extend_vec.extend(repeat(0).take(30)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:45:5 + --> $DIR/slow_vector_initialization.rs:51:5 | LL | let mut vec1 = Vec::with_capacity(len); | ----------------------- help: consider replacing this with: `vec![0; len]` @@ -49,7 +50,7 @@ LL | vec1.resize(len, 0); | ^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:53:5 + --> $DIR/slow_vector_initialization.rs:60:5 | LL | let mut vec3 = Vec::with_capacity(len - 10); | ---------------------------- help: consider replacing this with: `vec![0; len - 10]` @@ -57,7 +58,7 @@ LL | vec3.resize(len - 10, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:56:5 + --> $DIR/slow_vector_initialization.rs:64:5 | LL | let mut vec4 = Vec::with_capacity(len); | ----------------------- help: consider replacing this with: `vec![0; len]` @@ -65,7 +66,7 @@ LL | vec4.resize(vec4.capacity(), 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:60:5 + --> $DIR/slow_vector_initialization.rs:69:5 | LL | vec1 = Vec::with_capacity(10); | ---------------------- help: consider replacing this with: `vec![0; 10]` @@ -73,7 +74,7 @@ LL | vec1.resize(10, 0); | ^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:67:5 + --> $DIR/slow_vector_initialization.rs:77:5 | LL | let mut vec1 = Vec::new(); | ---------- help: consider replacing this with: `vec![0; len]` @@ -81,7 +82,7 @@ LL | vec1.resize(len, 0); | ^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:71:5 + --> $DIR/slow_vector_initialization.rs:82:5 | LL | let mut vec3 = Vec::new(); | ---------- help: consider replacing this with: `vec![0; len - 10]` @@ -89,12 +90,20 @@ LL | vec3.resize(len - 10, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: slow zero-filling initialization - --> $DIR/slow_vector_initialization.rs:75:5 + --> $DIR/slow_vector_initialization.rs:87:5 | LL | vec1 = Vec::new(); | ---------- help: consider replacing this with: `vec![0; 10]` LL | vec1.resize(10, 0); | ^^^^^^^^^^^^^^^^^^ -error: aborting due to 12 previous errors +error: slow zero-filling initialization + --> $DIR/slow_vector_initialization.rs:91:5 + | +LL | vec1 = vec![]; + | ------ help: consider replacing this with: `vec![0; 10]` +LL | vec1.resize(10, 0); + | ^^^^^^^^^^^^^^^^^^ + +error: aborting due to 13 previous errors diff --git a/src/tools/clippy/tests/ui/stable_sort_primitive.fixed b/src/tools/clippy/tests/ui/stable_sort_primitive.fixed index 50c1fc71a..97f3a9223 100644 --- a/src/tools/clippy/tests/ui/stable_sort_primitive.fixed +++ b/src/tools/clippy/tests/ui/stable_sort_primitive.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::stable_sort_primitive)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/stable_sort_primitive.rs b/src/tools/clippy/tests/ui/stable_sort_primitive.rs index bd1bb428f..26e3d8e74 100644 --- a/src/tools/clippy/tests/ui/stable_sort_primitive.rs +++ b/src/tools/clippy/tests/ui/stable_sort_primitive.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::stable_sort_primitive)] #![allow(clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/stable_sort_primitive.stderr b/src/tools/clippy/tests/ui/stable_sort_primitive.stderr index aa5d7b7e4..b66503328 100644 --- a/src/tools/clippy/tests/ui/stable_sort_primitive.stderr +++ b/src/tools/clippy/tests/ui/stable_sort_primitive.stderr @@ -1,14 +1,15 @@ error: used `sort` on primitive type `i32` - --> $DIR/stable_sort_primitive.rs:8:5 + --> $DIR/stable_sort_primitive.rs:7:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` | = note: an unstable sort typically performs faster without any observable difference for this data type = note: `-D clippy::stable-sort-primitive` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::stable_sort_primitive)]` error: used `sort` on primitive type `bool` - --> $DIR/stable_sort_primitive.rs:10:5 + --> $DIR/stable_sort_primitive.rs:9:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` @@ -16,7 +17,7 @@ LL | vec.sort(); = note: an unstable sort typically performs faster without any observable difference for this data type error: used `sort` on primitive type `char` - --> $DIR/stable_sort_primitive.rs:12:5 + --> $DIR/stable_sort_primitive.rs:11:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` @@ -24,7 +25,7 @@ LL | vec.sort(); = note: an unstable sort typically performs faster without any observable difference for this data type error: used `sort` on primitive type `str` - --> $DIR/stable_sort_primitive.rs:14:5 + --> $DIR/stable_sort_primitive.rs:13:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` @@ -32,7 +33,7 @@ LL | vec.sort(); = note: an unstable sort typically performs faster without any observable difference for this data type error: used `sort` on primitive type `tuple` - --> $DIR/stable_sort_primitive.rs:16:5 + --> $DIR/stable_sort_primitive.rs:15:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` @@ -40,7 +41,7 @@ LL | vec.sort(); = note: an unstable sort typically performs faster without any observable difference for this data type error: used `sort` on primitive type `array` - --> $DIR/stable_sort_primitive.rs:18:5 + --> $DIR/stable_sort_primitive.rs:17:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` @@ -48,7 +49,7 @@ LL | vec.sort(); = note: an unstable sort typically performs faster without any observable difference for this data type error: used `sort` on primitive type `i32` - --> $DIR/stable_sort_primitive.rs:20:5 + --> $DIR/stable_sort_primitive.rs:19:5 | LL | arr.sort(); | ^^^^^^^^^^ help: try: `arr.sort_unstable()` diff --git a/src/tools/clippy/tests/ui/starts_ends_with.fixed b/src/tools/clippy/tests/ui/starts_ends_with.fixed index b7237069d..4a66ca7ec 100644 --- a/src/tools/clippy/tests/ui/starts_ends_with.fixed +++ b/src/tools/clippy/tests/ui/starts_ends_with.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::needless_if, dead_code, unused_must_use)] fn main() {} diff --git a/src/tools/clippy/tests/ui/starts_ends_with.rs b/src/tools/clippy/tests/ui/starts_ends_with.rs index 658312e87..16a68e02d 100644 --- a/src/tools/clippy/tests/ui/starts_ends_with.rs +++ b/src/tools/clippy/tests/ui/starts_ends_with.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(clippy::needless_if, dead_code, unused_must_use)] fn main() {} diff --git a/src/tools/clippy/tests/ui/starts_ends_with.stderr b/src/tools/clippy/tests/ui/starts_ends_with.stderr index 2dd9f53b8..c4c547949 100644 --- a/src/tools/clippy/tests/ui/starts_ends_with.stderr +++ b/src/tools/clippy/tests/ui/starts_ends_with.stderr @@ -1,102 +1,104 @@ error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:8:5 + --> $DIR/starts_ends_with.rs:7:5 | LL | "".chars().next() == Some(' '); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".starts_with(' ')` | = note: `-D clippy::chars-next-cmp` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::chars_next_cmp)]` error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:9:5 + --> $DIR/starts_ends_with.rs:8:5 | LL | Some(' ') != "".chars().next(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with(' ')` error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:12:5 + --> $DIR/starts_ends_with.rs:11:5 | -LL | "".chars().next() == Some('/n'); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".starts_with('/n')` +LL | "".chars().next() == Some('\n'); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".starts_with('\n')` error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:13:5 + --> $DIR/starts_ends_with.rs:12:5 | -LL | Some('/n') != "".chars().next(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with('/n')` +LL | Some('\n') != "".chars().next(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".starts_with('\n')` error: you should use the `starts_with` method - --> $DIR/starts_ends_with.rs:18:8 + --> $DIR/starts_ends_with.rs:17: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:22:8 + --> $DIR/starts_ends_with.rs:21:8 | LL | if s.chars().next_back().unwrap() == 'o' { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')` | = note: `-D clippy::chars-last-cmp` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::chars_last_cmp)]` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:26:8 + --> $DIR/starts_ends_with.rs:25: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:30:8 + --> $DIR/starts_ends_with.rs:29: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:34:8 + --> $DIR/starts_ends_with.rs:33: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:38:8 + --> $DIR/starts_ends_with.rs:37:8 | -LL | if s.chars().last().unwrap() != '/n' { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('/n')` +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:46:5 + --> $DIR/starts_ends_with.rs:45:5 | LL | "".chars().last() == Some(' '); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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:46:5 | LL | Some(' ') != "".chars().last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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:47:5 | LL | "".chars().next_back() == Some(' '); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:49:5 + --> $DIR/starts_ends_with.rs:48:5 | LL | Some(' ') != "".chars().next_back(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:52:5 + --> $DIR/starts_ends_with.rs:51:5 | -LL | "".chars().last() == Some('/n'); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with('/n')` +LL | "".chars().last() == Some('\n'); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with('\n')` error: you should use the `ends_with` method - --> $DIR/starts_ends_with.rs:53:5 + --> $DIR/starts_ends_with.rs:52:5 | -LL | Some('/n') != "".chars().last(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with('/n')` +LL | Some('\n') != "".chars().last(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with('\n')` error: aborting due to 16 previous errors diff --git a/src/tools/clippy/tests/ui/std_instead_of_core.fixed b/src/tools/clippy/tests/ui/std_instead_of_core.fixed new file mode 100644 index 000000000..8027c053f --- /dev/null +++ b/src/tools/clippy/tests/ui/std_instead_of_core.fixed @@ -0,0 +1,62 @@ +#![warn(clippy::std_instead_of_core)] +#![allow(unused_imports)] + +extern crate alloc; + +#[warn(clippy::std_instead_of_core)] +fn std_instead_of_core() { + // Regular import + use core::hash::Hasher; + //~^ ERROR: used import from `std` instead of `core` + // Absolute path + use ::core::hash::Hash; + //~^ ERROR: used import from `std` instead of `core` + // Don't lint on `env` macro + use std::env; + + // Multiple imports + use core::fmt::{Debug, Result}; + //~^ ERROR: used import from `std` instead of `core` + + // Function calls + let ptr = core::ptr::null::(); + //~^ ERROR: used import from `std` instead of `core` + let ptr_mut = ::core::ptr::null_mut::(); + //~^ ERROR: used import from `std` instead of `core` + + // Types + let cell = core::cell::Cell::new(8u32); + //~^ ERROR: used import from `std` instead of `core` + let cell_absolute = ::core::cell::Cell::new(8u32); + //~^ ERROR: used import from `std` instead of `core` + + let _ = std::env!("PATH"); + + // do not lint until `error_in_core` is stable + use std::error::Error; + + // lint items re-exported from private modules, `core::iter::traits::iterator::Iterator` + use core::iter::Iterator; + //~^ ERROR: used import from `std` instead of `core` +} + +#[warn(clippy::std_instead_of_alloc)] +fn std_instead_of_alloc() { + // Only lint once. + use alloc::vec; + //~^ ERROR: used import from `std` instead of `alloc` + use alloc::vec::Vec; + //~^ ERROR: used import from `std` instead of `alloc` +} + +#[warn(clippy::alloc_instead_of_core)] +fn alloc_instead_of_core() { + use core::slice::from_ref; + //~^ ERROR: used import from `alloc` instead of `core` +} + +fn main() { + std_instead_of_core(); + std_instead_of_alloc(); + alloc_instead_of_core(); +} diff --git a/src/tools/clippy/tests/ui/std_instead_of_core.rs b/src/tools/clippy/tests/ui/std_instead_of_core.rs index 75b114ba0..63a096384 100644 --- a/src/tools/clippy/tests/ui/std_instead_of_core.rs +++ b/src/tools/clippy/tests/ui/std_instead_of_core.rs @@ -7,21 +7,28 @@ extern crate alloc; fn std_instead_of_core() { // Regular import use std::hash::Hasher; + //~^ ERROR: used import from `std` instead of `core` // Absolute path use ::std::hash::Hash; + //~^ ERROR: used import from `std` instead of `core` // Don't lint on `env` macro use std::env; // Multiple imports use std::fmt::{Debug, Result}; + //~^ ERROR: used import from `std` instead of `core` // Function calls let ptr = std::ptr::null::(); + //~^ ERROR: used import from `std` instead of `core` let ptr_mut = ::std::ptr::null_mut::(); + //~^ ERROR: used import from `std` instead of `core` // Types let cell = std::cell::Cell::new(8u32); + //~^ ERROR: used import from `std` instead of `core` let cell_absolute = ::std::cell::Cell::new(8u32); + //~^ ERROR: used import from `std` instead of `core` let _ = std::env!("PATH"); @@ -30,18 +37,22 @@ fn std_instead_of_core() { // lint items re-exported from private modules, `core::iter::traits::iterator::Iterator` use std::iter::Iterator; + //~^ ERROR: used import from `std` instead of `core` } #[warn(clippy::std_instead_of_alloc)] fn std_instead_of_alloc() { // Only lint once. use std::vec; + //~^ ERROR: used import from `std` instead of `alloc` use std::vec::Vec; + //~^ ERROR: used import from `std` instead of `alloc` } #[warn(clippy::alloc_instead_of_core)] fn alloc_instead_of_core() { use alloc::slice::from_ref; + //~^ ERROR: used import from `alloc` instead of `core` } fn main() { diff --git a/src/tools/clippy/tests/ui/std_instead_of_core.stderr b/src/tools/clippy/tests/ui/std_instead_of_core.stderr index d21024973..ca26f77bd 100644 --- a/src/tools/clippy/tests/ui/std_instead_of_core.stderr +++ b/src/tools/clippy/tests/ui/std_instead_of_core.stderr @@ -2,100 +2,76 @@ error: used import from `std` instead of `core` --> $DIR/std_instead_of_core.rs:9:9 | LL | use std::hash::Hasher; - | ^^^^^^^^^^^^^^^^^ + | ^^^ help: consider importing the item from `core`: `core` | - = help: consider importing the item from `core` = note: `-D clippy::std-instead-of-core` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::std_instead_of_core)]` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:11:9 + --> $DIR/std_instead_of_core.rs:12:11 | LL | use ::std::hash::Hash; - | ^^^^^^^^^^^^^^^^^ - | - = help: consider importing the item from `core` - -error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:16:20 - | -LL | use std::fmt::{Debug, Result}; - | ^^^^^ - | - = help: consider importing the item from `core` + | ^^^ help: consider importing the item from `core`: `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:16:27 + --> $DIR/std_instead_of_core.rs:18:9 | LL | use std::fmt::{Debug, Result}; - | ^^^^^^ - | - = help: consider importing the item from `core` + | ^^^ help: consider importing the item from `core`: `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:19:15 + --> $DIR/std_instead_of_core.rs:22:15 | LL | let ptr = std::ptr::null::(); - | ^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider importing the item from `core` + | ^^^ help: consider importing the item from `core`: `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:20:19 + --> $DIR/std_instead_of_core.rs:24:21 | LL | let ptr_mut = ::std::ptr::null_mut::(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider importing the item from `core` + | ^^^ help: consider importing the item from `core`: `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:23:16 + --> $DIR/std_instead_of_core.rs:28:16 | LL | let cell = std::cell::Cell::new(8u32); - | ^^^^^^^^^^^^^^^ - | - = help: consider importing the item from `core` + | ^^^ help: consider importing the item from `core`: `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:24:25 + --> $DIR/std_instead_of_core.rs:30:27 | LL | let cell_absolute = ::std::cell::Cell::new(8u32); - | ^^^^^^^^^^^^^^^^^ - | - = help: consider importing the item from `core` + | ^^^ help: consider importing the item from `core`: `core` error: used import from `std` instead of `core` - --> $DIR/std_instead_of_core.rs:32:9 + --> $DIR/std_instead_of_core.rs:39:9 | LL | use std::iter::Iterator; - | ^^^^^^^^^^^^^^^^^^^ - | - = help: consider importing the item from `core` + | ^^^ help: consider importing the item from `core`: `core` error: used import from `std` instead of `alloc` - --> $DIR/std_instead_of_core.rs:38:9 + --> $DIR/std_instead_of_core.rs:46:9 | LL | use std::vec; - | ^^^^^^^^ + | ^^^ help: consider importing the item from `alloc`: `alloc` | - = help: consider importing the item from `alloc` = note: `-D clippy::std-instead-of-alloc` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::std_instead_of_alloc)]` error: used import from `std` instead of `alloc` - --> $DIR/std_instead_of_core.rs:39:9 + --> $DIR/std_instead_of_core.rs:48:9 | LL | use std::vec::Vec; - | ^^^^^^^^^^^^^ - | - = help: consider importing the item from `alloc` + | ^^^ help: consider importing the item from `alloc`: `alloc` error: used import from `alloc` instead of `core` - --> $DIR/std_instead_of_core.rs:44:9 + --> $DIR/std_instead_of_core.rs:54:9 | LL | use alloc::slice::from_ref; - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^ help: consider importing the item from `core`: `core` | - = help: consider importing the item from `core` = note: `-D clippy::alloc-instead-of-core` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::alloc_instead_of_core)]` -error: aborting due to 12 previous errors +error: aborting due to 11 previous errors diff --git a/src/tools/clippy/tests/ui/str_to_string.rs b/src/tools/clippy/tests/ui/str_to_string.rs index 08f734025..f93b289c2 100644 --- a/src/tools/clippy/tests/ui/str_to_string.rs +++ b/src/tools/clippy/tests/ui/str_to_string.rs @@ -2,6 +2,8 @@ fn main() { let hello = "hello world".to_string(); + //~^ ERROR: `to_string()` called on a `&str` let msg = &hello[..]; msg.to_string(); + //~^ ERROR: `to_string()` called on a `&str` } diff --git a/src/tools/clippy/tests/ui/str_to_string.stderr b/src/tools/clippy/tests/ui/str_to_string.stderr index 1d47da571..203805eca 100644 --- a/src/tools/clippy/tests/ui/str_to_string.stderr +++ b/src/tools/clippy/tests/ui/str_to_string.stderr @@ -6,9 +6,10 @@ LL | let hello = "hello world".to_string(); | = help: consider using `.to_owned()` = note: `-D clippy::str-to-string` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::str_to_string)]` error: `to_string()` called on a `&str` - --> $DIR/str_to_string.rs:6:5 + --> $DIR/str_to_string.rs:7:5 | LL | msg.to_string(); | ^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/string_add.rs b/src/tools/clippy/tests/ui/string_add.rs index 6980242ae..c535f2ebb 100644 --- a/src/tools/clippy/tests/ui/string_add.rs +++ b/src/tools/clippy/tests/ui/string_add.rs @@ -1,5 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro - +//@aux-build:proc_macros.rs +//@no-rustfix extern crate proc_macros; use proc_macros::external; diff --git a/src/tools/clippy/tests/ui/string_add.stderr b/src/tools/clippy/tests/ui/string_add.stderr index 3987641c7..892753b90 100644 --- a/src/tools/clippy/tests/ui/string_add.stderr +++ b/src/tools/clippy/tests/ui/string_add.stderr @@ -5,6 +5,7 @@ LL | x = x + "."; | ^^^^^^^^^^^ help: replace it with: `x += "."` | = note: `-D clippy::assign-op-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]` error: you added something to a string. Consider using `String::push_str()` instead --> $DIR/string_add.rs:13:13 @@ -13,6 +14,7 @@ LL | x = x + "."; | ^^^^^^^ | = note: `-D clippy::string-add` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/string_add_assign.fixed b/src/tools/clippy/tests/ui/string_add_assign.fixed index 616c6daaf..31d84831d 100644 --- a/src/tools/clippy/tests/ui/string_add_assign.fixed +++ b/src/tools/clippy/tests/ui/string_add_assign.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #[allow(clippy::string_add, unused)] #[warn(clippy::string_add_assign)] fn main() { diff --git a/src/tools/clippy/tests/ui/string_add_assign.rs b/src/tools/clippy/tests/ui/string_add_assign.rs index e1f885975..cdea91573 100644 --- a/src/tools/clippy/tests/ui/string_add_assign.rs +++ b/src/tools/clippy/tests/ui/string_add_assign.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #[allow(clippy::string_add, unused)] #[warn(clippy::string_add_assign)] fn main() { diff --git a/src/tools/clippy/tests/ui/string_add_assign.stderr b/src/tools/clippy/tests/ui/string_add_assign.stderr index 7676175c1..7d37c98a8 100644 --- a/src/tools/clippy/tests/ui/string_add_assign.stderr +++ b/src/tools/clippy/tests/ui/string_add_assign.stderr @@ -1,21 +1,23 @@ error: you assigned the result of adding something to this string. Consider using `String::push_str()` instead - --> $DIR/string_add_assign.rs:10:9 + --> $DIR/string_add_assign.rs:8:9 | LL | x = x + "."; | ^^^^^^^^^^^ | = note: `-D clippy::string-add-assign` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_add_assign)]` error: manual implementation of an assign operation - --> $DIR/string_add_assign.rs:10:9 + --> $DIR/string_add_assign.rs:8:9 | LL | x = x + "."; | ^^^^^^^^^^^ help: replace it with: `x += "."` | = note: `-D clippy::assign-op-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]` error: manual implementation of an assign operation - --> $DIR/string_add_assign.rs:19:5 + --> $DIR/string_add_assign.rs:17:5 | LL | x = x + 1; | ^^^^^^^^^ help: replace it with: `x += 1` diff --git a/src/tools/clippy/tests/ui/string_extend.fixed b/src/tools/clippy/tests/ui/string_extend.fixed index 65c9abff3..142cb6a34 100644 --- a/src/tools/clippy/tests/ui/string_extend.fixed +++ b/src/tools/clippy/tests/ui/string_extend.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #[derive(Copy, Clone)] struct HasChars; diff --git a/src/tools/clippy/tests/ui/string_extend.rs b/src/tools/clippy/tests/ui/string_extend.rs index 5f72ffe2f..41c0d29fa 100644 --- a/src/tools/clippy/tests/ui/string_extend.rs +++ b/src/tools/clippy/tests/ui/string_extend.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #[derive(Copy, Clone)] struct HasChars; diff --git a/src/tools/clippy/tests/ui/string_extend.stderr b/src/tools/clippy/tests/ui/string_extend.stderr index 34b432901..e063d87e3 100644 --- a/src/tools/clippy/tests/ui/string_extend.stderr +++ b/src/tools/clippy/tests/ui/string_extend.stderr @@ -1,25 +1,26 @@ error: calling `.extend(_.chars())` - --> $DIR/string_extend.rs:18:5 + --> $DIR/string_extend.rs:16:5 | LL | s.extend(abc.chars()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str(abc)` | = note: `-D clippy::string-extend-chars` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_extend_chars)]` error: calling `.extend(_.chars())` - --> $DIR/string_extend.rs:21:5 + --> $DIR/string_extend.rs:19:5 | LL | s.extend("abc".chars()); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str("abc")` error: calling `.extend(_.chars())` - --> $DIR/string_extend.rs:24:5 + --> $DIR/string_extend.rs:22:5 | LL | s.extend(def.chars()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str(&def)` error: calling `.extend(_.chars())` - --> $DIR/string_extend.rs:34:5 + --> $DIR/string_extend.rs:32:5 | LL | s.extend(abc[0..2].chars()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str(&abc[0..2])` diff --git a/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.fixed b/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.fixed index 9b315ae2b..6aa5a95c6 100644 --- a/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.fixed +++ b/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::string_from_utf8_as_bytes)] fn main() { diff --git a/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.rs b/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.rs index 043dd2350..c8717f795 100644 --- a/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.rs +++ b/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::string_from_utf8_as_bytes)] fn main() { diff --git a/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.stderr b/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.stderr index bf5e5d33e..cf5688a97 100644 --- a/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.stderr +++ b/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.stderr @@ -1,10 +1,11 @@ error: calling a slice of `as_bytes()` with `from_utf8` should be not necessary - --> $DIR/string_from_utf8_as_bytes.rs:5:13 + --> $DIR/string_from_utf8_as_bytes.rs:4:13 | LL | let _ = std::str::from_utf8(&"Hello World!".as_bytes()[6..11]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(&"Hello World!"[6..11])` | = note: `-D clippy::string-from-utf8-as-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_from_utf8_as_bytes)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/string_lit_as_bytes.fixed b/src/tools/clippy/tests/ui/string_lit_as_bytes.fixed index 0edd81acc..225d4e90c 100644 --- a/src/tools/clippy/tests/ui/string_lit_as_bytes.fixed +++ b/src/tools/clippy/tests/ui/string_lit_as_bytes.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:macro_rules.rs #![allow(clippy::needless_raw_string_hashes, dead_code, unused_variables)] diff --git a/src/tools/clippy/tests/ui/string_lit_as_bytes.rs b/src/tools/clippy/tests/ui/string_lit_as_bytes.rs index 2647f02f0..3d116214c 100644 --- a/src/tools/clippy/tests/ui/string_lit_as_bytes.rs +++ b/src/tools/clippy/tests/ui/string_lit_as_bytes.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:macro_rules.rs #![allow(clippy::needless_raw_string_hashes, dead_code, unused_variables)] diff --git a/src/tools/clippy/tests/ui/string_lit_as_bytes.stderr b/src/tools/clippy/tests/ui/string_lit_as_bytes.stderr index 61b4e210e..1c12cb8e5 100644 --- a/src/tools/clippy/tests/ui/string_lit_as_bytes.stderr +++ b/src/tools/clippy/tests/ui/string_lit_as_bytes.stderr @@ -1,31 +1,32 @@ error: calling `as_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:17:14 + --> $DIR/string_lit_as_bytes.rs:16:14 | LL | let bs = "hello there".as_bytes(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"hello there"` | = note: `-D clippy::string-lit-as-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_lit_as_bytes)]` error: calling `as_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:19:14 + --> $DIR/string_lit_as_bytes.rs:18:14 | 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:21:14 + --> $DIR/string_lit_as_bytes.rs:20: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:22:14 + --> $DIR/string_lit_as_bytes.rs:21: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()` error: calling `as_bytes()` on a string literal - --> $DIR/string_lit_as_bytes.rs:12:26 + --> $DIR/string_lit_as_bytes.rs:11:26 | LL | const B: &[u8] = $b.as_bytes(); | ^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"warning"` @@ -36,16 +37,16 @@ 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:39:22 + --> $DIR/string_lit_as_bytes.rs:38: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:41:13 + --> $DIR/string_lit_as_bytes.rs:40:13 | -LL | let _ = "string with newline/t/n".as_bytes(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"string with newline/t/n"` +LL | let _ = "string with newline\t\n".as_bytes(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"string with newline\t\n"` error: aborting due to 7 previous errors diff --git a/src/tools/clippy/tests/ui/string_lit_chars_any.fixed b/src/tools/clippy/tests/ui/string_lit_chars_any.fixed index d7ab9c339..03e20c16e 100644 --- a/src/tools/clippy/tests/ui/string_lit_chars_any.fixed +++ b/src/tools/clippy/tests/ui/string_lit_chars_any.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::eq_op, clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::string_lit_chars_any)] diff --git a/src/tools/clippy/tests/ui/string_lit_chars_any.rs b/src/tools/clippy/tests/ui/string_lit_chars_any.rs index 9408d7bb2..12e6ffb6a 100644 --- a/src/tools/clippy/tests/ui/string_lit_chars_any.rs +++ b/src/tools/clippy/tests/ui/string_lit_chars_any.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::eq_op, clippy::needless_raw_string_hashes, clippy::no_effect, unused)] #![warn(clippy::string_lit_chars_any)] diff --git a/src/tools/clippy/tests/ui/string_lit_chars_any.stderr b/src/tools/clippy/tests/ui/string_lit_chars_any.stderr index ff951b73d..09c4f02eb 100644 --- a/src/tools/clippy/tests/ui/string_lit_chars_any.stderr +++ b/src/tools/clippy/tests/ui/string_lit_chars_any.stderr @@ -1,57 +1,58 @@ 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:18:5 | -LL | "//.+*?()|[]{}^$#&-~".chars().any(|x| x == c); +LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::string-lit-chars-any` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_lit_chars_any)]` help: use `matches!(...)` instead | -LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); +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:19:5 | -LL | r#"/.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c); +LL | r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `matches!(...)` instead | -LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); +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:20:5 | -LL | "//.+*?()|[]{}^$#&-~".chars().any(|x| c == x); +LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| c == x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `matches!(...)` instead | -LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); +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:22:5 + --> $DIR/string_lit_chars_any.rs:21:5 | -LL | r#"/.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x); +LL | r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `matches!(...)` instead | -LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); +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:24:5 + --> $DIR/string_lit_chars_any.rs:23:5 | -LL | "//.+*?()|[]{}^$#&-~".chars().any(|x| { x == c }); +LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| { x == c }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `matches!(...)` instead | -LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); +LL | matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 5 previous errors diff --git a/src/tools/clippy/tests/ui/string_slice.rs b/src/tools/clippy/tests/ui/string_slice.rs index be4dfc881..440a86b10 100644 --- a/src/tools/clippy/tests/ui/string_slice.rs +++ b/src/tools/clippy/tests/ui/string_slice.rs @@ -3,8 +3,12 @@ fn main() { &"Ölkanne"[1..]; + //~^ ERROR: indexing into a string may panic if the index is within a UTF-8 character + //~| NOTE: `-D clippy::string-slice` implied by `-D warnings` let m = "Mötörhead"; &m[2..5]; + //~^ ERROR: indexing into a string may panic if the index is within a UTF-8 character let s = String::from(m); &s[0..2]; + //~^ ERROR: indexing into a string may panic if the index is within a UTF-8 character } diff --git a/src/tools/clippy/tests/ui/string_slice.stderr b/src/tools/clippy/tests/ui/string_slice.stderr index 55040bf5d..e9e773aaf 100644 --- a/src/tools/clippy/tests/ui/string_slice.stderr +++ b/src/tools/clippy/tests/ui/string_slice.stderr @@ -5,15 +5,16 @@ LL | &"Ölkanne"[1..]; | ^^^^^^^^^^^^^^ | = note: `-D clippy::string-slice` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_slice)]` error: indexing into a string may panic if the index is within a UTF-8 character - --> $DIR/string_slice.rs:7:6 + --> $DIR/string_slice.rs:9:6 | LL | &m[2..5]; | ^^^^^^^ error: indexing into a string may panic if the index is within a UTF-8 character - --> $DIR/string_slice.rs:9:6 + --> $DIR/string_slice.rs:12:6 | LL | &s[0..2]; | ^^^^^^^ diff --git a/src/tools/clippy/tests/ui/string_to_string.rs b/src/tools/clippy/tests/ui/string_to_string.rs index 4c66855f7..007685b60 100644 --- a/src/tools/clippy/tests/ui/string_to_string.rs +++ b/src/tools/clippy/tests/ui/string_to_string.rs @@ -4,4 +4,5 @@ fn main() { let mut message = String::from("Hello"); let mut v = message.to_string(); + //~^ ERROR: `to_string()` called on a `String` } diff --git a/src/tools/clippy/tests/ui/string_to_string.stderr b/src/tools/clippy/tests/ui/string_to_string.stderr index e304c3e34..27a844315 100644 --- a/src/tools/clippy/tests/ui/string_to_string.stderr +++ b/src/tools/clippy/tests/ui/string_to_string.stderr @@ -6,6 +6,7 @@ LL | let mut v = message.to_string(); | = help: consider using `.clone()` = note: `-D clippy::string-to-string` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::string_to_string)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/strlen_on_c_strings.fixed b/src/tools/clippy/tests/ui/strlen_on_c_strings.fixed index ef207e28c..8304e2afd 100644 --- a/src/tools/clippy/tests/ui/strlen_on_c_strings.fixed +++ b/src/tools/clippy/tests/ui/strlen_on_c_strings.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::strlen_on_c_strings)] #![allow(dead_code)] #![feature(rustc_private)] diff --git a/src/tools/clippy/tests/ui/strlen_on_c_strings.rs b/src/tools/clippy/tests/ui/strlen_on_c_strings.rs index 03ec5f79d..deba40a9e 100644 --- a/src/tools/clippy/tests/ui/strlen_on_c_strings.rs +++ b/src/tools/clippy/tests/ui/strlen_on_c_strings.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::strlen_on_c_strings)] #![allow(dead_code)] #![feature(rustc_private)] diff --git a/src/tools/clippy/tests/ui/strlen_on_c_strings.stderr b/src/tools/clippy/tests/ui/strlen_on_c_strings.stderr index fcd17f689..6d8ad3981 100644 --- a/src/tools/clippy/tests/ui/strlen_on_c_strings.stderr +++ b/src/tools/clippy/tests/ui/strlen_on_c_strings.stderr @@ -1,43 +1,44 @@ error: using `libc::strlen` on a `CString` or `CStr` value - --> $DIR/strlen_on_c_strings.rs:15:13 + --> $DIR/strlen_on_c_strings.rs:13:13 | LL | let _ = unsafe { libc::strlen(cstring.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cstring.as_bytes().len()` | = note: `-D clippy::strlen-on-c-strings` implied by `-D warnings` + = 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:19:13 + --> $DIR/strlen_on_c_strings.rs:17: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:21:13 + --> $DIR/strlen_on_c_strings.rs:19: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:24:22 + --> $DIR/strlen_on_c_strings.rs:22: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:29:22 + --> $DIR/strlen_on_c_strings.rs:27: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:30:13 + --> $DIR/strlen_on_c_strings.rs:28: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:33:22 + --> $DIR/strlen_on_c_strings.rs:31:22 | LL | let _ = unsafe { strlen(f(cstr).as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `f(cstr).to_bytes().len()` diff --git a/src/tools/clippy/tests/ui/struct_excessive_bools.rs b/src/tools/clippy/tests/ui/struct_excessive_bools.rs index ce4fe830a..8137ce7a8 100644 --- a/src/tools/clippy/tests/ui/struct_excessive_bools.rs +++ b/src/tools/clippy/tests/ui/struct_excessive_bools.rs @@ -20,6 +20,7 @@ struct Foo { } struct BadFoo { + //~^ ERROR: more than 3 bools in a struct a: bool, b: bool, c: bool, @@ -36,6 +37,7 @@ struct Bar { fn main() { struct FooFoo { + //~^ ERROR: more than 3 bools in a struct a: bool, b: bool, c: bool, diff --git a/src/tools/clippy/tests/ui/struct_excessive_bools.stderr b/src/tools/clippy/tests/ui/struct_excessive_bools.stderr index e4d50043a..5284949c2 100644 --- a/src/tools/clippy/tests/ui/struct_excessive_bools.stderr +++ b/src/tools/clippy/tests/ui/struct_excessive_bools.stderr @@ -2,6 +2,7 @@ error: more than 3 bools in a struct --> $DIR/struct_excessive_bools.rs:22:1 | LL | / struct BadFoo { +LL | | LL | | a: bool, LL | | b: bool, LL | | c: bool, @@ -11,11 +12,13 @@ LL | | } | = help: consider using a state machine or refactoring bools into two-variant enums = note: `-D clippy::struct-excessive-bools` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::struct_excessive_bools)]` error: more than 3 bools in a struct - --> $DIR/struct_excessive_bools.rs:38:5 + --> $DIR/struct_excessive_bools.rs:39:5 | LL | / struct FooFoo { +LL | | LL | | a: bool, LL | | b: bool, LL | | c: bool, diff --git a/src/tools/clippy/tests/ui/suspicious_arithmetic_impl.rs b/src/tools/clippy/tests/ui/suspicious_arithmetic_impl.rs index ae253a048..1bd4cd5fb 100644 --- a/src/tools/clippy/tests/ui/suspicious_arithmetic_impl.rs +++ b/src/tools/clippy/tests/ui/suspicious_arithmetic_impl.rs @@ -11,12 +11,16 @@ impl Add for Foo { fn add(self, other: Self) -> Self { Foo(self.0 - other.0) + //~^ ERROR: suspicious use of `-` in `Add` impl + //~| NOTE: `-D clippy::suspicious-arithmetic-impl` implied by `-D warnings` } } impl AddAssign for Foo { fn add_assign(&mut self, other: Foo) { *self = *self - other; + //~^ ERROR: suspicious use of `-` in `AddAssign` impl + //~| NOTE: `-D clippy::suspicious-op-assign-impl` implied by `-D warnings` } } @@ -30,6 +34,7 @@ impl BitOrAssign for Foo { impl MulAssign for Foo { fn mul_assign(&mut self, other: Foo) { self.0 /= other.0; + //~^ ERROR: suspicious use of `/` in `MulAssign` impl } } @@ -68,6 +73,7 @@ impl Rem for Foo { fn rem(self, other: Self) -> Self { Foo(self.0 / other.0) + //~^ ERROR: suspicious use of `/` in `Rem` impl } } @@ -76,6 +82,7 @@ impl BitAnd for Foo { fn bitand(self, other: Self) -> Self { Foo(self.0 | other.0) + //~^ ERROR: suspicious use of `|` in `BitAnd` impl } } @@ -84,6 +91,7 @@ impl BitOr for Foo { fn bitor(self, other: Self) -> Self { Foo(self.0 ^ other.0) + //~^ ERROR: suspicious use of `^` in `BitOr` impl } } @@ -92,6 +100,7 @@ impl BitXor for Foo { fn bitxor(self, other: Self) -> Self { Foo(self.0 & other.0) + //~^ ERROR: suspicious use of `&` in `BitXor` impl } } @@ -100,6 +109,7 @@ impl Shl for Foo { fn shl(self, other: Self) -> Self { Foo(self.0 >> other.0) + //~^ ERROR: suspicious use of `>>` in `Shl` impl } } @@ -108,6 +118,7 @@ impl Shr for Foo { fn shr(self, other: Self) -> Self { Foo(self.0 << other.0) + //~^ ERROR: suspicious use of `<<` in `Shr` impl } } diff --git a/src/tools/clippy/tests/ui/suspicious_arithmetic_impl.stderr b/src/tools/clippy/tests/ui/suspicious_arithmetic_impl.stderr index ced130587..3995c6eb5 100644 --- a/src/tools/clippy/tests/ui/suspicious_arithmetic_impl.stderr +++ b/src/tools/clippy/tests/ui/suspicious_arithmetic_impl.stderr @@ -5,53 +5,55 @@ LL | Foo(self.0 - other.0) | ^ | = note: `-D clippy::suspicious-arithmetic-impl` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_arithmetic_impl)]` error: suspicious use of `-` in `AddAssign` impl - --> $DIR/suspicious_arithmetic_impl.rs:19:23 + --> $DIR/suspicious_arithmetic_impl.rs:21:23 | LL | *self = *self - other; | ^ | = note: `-D clippy::suspicious-op-assign-impl` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_op_assign_impl)]` error: suspicious use of `/` in `MulAssign` impl - --> $DIR/suspicious_arithmetic_impl.rs:32:16 + --> $DIR/suspicious_arithmetic_impl.rs:36:16 | LL | self.0 /= other.0; | ^^ error: suspicious use of `/` in `Rem` impl - --> $DIR/suspicious_arithmetic_impl.rs:70:20 + --> $DIR/suspicious_arithmetic_impl.rs:75:20 | LL | Foo(self.0 / other.0) | ^ error: suspicious use of `|` in `BitAnd` impl - --> $DIR/suspicious_arithmetic_impl.rs:78:20 + --> $DIR/suspicious_arithmetic_impl.rs:84:20 | LL | Foo(self.0 | other.0) | ^ error: suspicious use of `^` in `BitOr` impl - --> $DIR/suspicious_arithmetic_impl.rs:86:20 + --> $DIR/suspicious_arithmetic_impl.rs:93:20 | LL | Foo(self.0 ^ other.0) | ^ error: suspicious use of `&` in `BitXor` impl - --> $DIR/suspicious_arithmetic_impl.rs:94:20 + --> $DIR/suspicious_arithmetic_impl.rs:102:20 | LL | Foo(self.0 & other.0) | ^ error: suspicious use of `>>` in `Shl` impl - --> $DIR/suspicious_arithmetic_impl.rs:102:20 + --> $DIR/suspicious_arithmetic_impl.rs:111:20 | LL | Foo(self.0 >> other.0) | ^^ error: suspicious use of `<<` in `Shr` impl - --> $DIR/suspicious_arithmetic_impl.rs:110:20 + --> $DIR/suspicious_arithmetic_impl.rs:120:20 | LL | Foo(self.0 << other.0) | ^^ diff --git a/src/tools/clippy/tests/ui/suspicious_command_arg_space.fixed b/src/tools/clippy/tests/ui/suspicious_command_arg_space.fixed new file mode 100644 index 000000000..5d7b1e0c1 --- /dev/null +++ b/src/tools/clippy/tests/ui/suspicious_command_arg_space.fixed @@ -0,0 +1,13 @@ +fn main() { + // Things it should warn about: + std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap(); + //~^ ERROR: single argument that looks like it should be multiple arguments + //~| NOTE: `-D clippy::suspicious-command-arg-space` implied by `-D warnings` + std::process::Command::new("cat").args(["--number", "file"]).spawn().unwrap(); + //~^ ERROR: single argument that looks like it should be multiple arguments + + // Things it should not warn about: + std::process::Command::new("echo").arg("hello world").spawn().unwrap(); + std::process::Command::new("a").arg("--fmt=%a %b %c").spawn().unwrap(); + std::process::Command::new("b").arg("-ldflags=-s -w").spawn().unwrap(); +} diff --git a/src/tools/clippy/tests/ui/suspicious_command_arg_space.rs b/src/tools/clippy/tests/ui/suspicious_command_arg_space.rs index bdc6113a2..8abd9803a 100644 --- a/src/tools/clippy/tests/ui/suspicious_command_arg_space.rs +++ b/src/tools/clippy/tests/ui/suspicious_command_arg_space.rs @@ -1,7 +1,10 @@ fn main() { // Things it should warn about: std::process::Command::new("echo").arg("-n hello").spawn().unwrap(); + //~^ ERROR: single argument that looks like it should be multiple arguments + //~| NOTE: `-D clippy::suspicious-command-arg-space` implied by `-D warnings` std::process::Command::new("cat").arg("--number file").spawn().unwrap(); + //~^ ERROR: single argument that looks like it should be multiple arguments // Things it should not warn about: std::process::Command::new("echo").arg("hello world").spawn().unwrap(); diff --git a/src/tools/clippy/tests/ui/suspicious_command_arg_space.stderr b/src/tools/clippy/tests/ui/suspicious_command_arg_space.stderr index 9bc0ca93a..9bf3128cb 100644 --- a/src/tools/clippy/tests/ui/suspicious_command_arg_space.stderr +++ b/src/tools/clippy/tests/ui/suspicious_command_arg_space.stderr @@ -5,13 +5,14 @@ LL | std::process::Command::new("echo").arg("-n hello").spawn().unwrap(); | ^^^^^^^^^^ | = note: `-D clippy::suspicious-command-arg-space` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_command_arg_space)]` help: consider splitting the argument | LL | std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap(); | ~~~~ ~~~~~~~~~~~~~~~ error: single argument that looks like it should be multiple arguments - --> $DIR/suspicious_command_arg_space.rs:4:43 + --> $DIR/suspicious_command_arg_space.rs:6:43 | LL | std::process::Command::new("cat").arg("--number file").spawn().unwrap(); | ^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/suspicious_doc_comments.fixed b/src/tools/clippy/tests/ui/suspicious_doc_comments.fixed index bffda1cc4..614fc0357 100644 --- a/src/tools/clippy/tests/ui/suspicious_doc_comments.fixed +++ b/src/tools/clippy/tests/ui/suspicious_doc_comments.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::suspicious_doc_comments)] diff --git a/src/tools/clippy/tests/ui/suspicious_doc_comments.rs b/src/tools/clippy/tests/ui/suspicious_doc_comments.rs index cdd972ee3..7dcba0fef 100644 --- a/src/tools/clippy/tests/ui/suspicious_doc_comments.rs +++ b/src/tools/clippy/tests/ui/suspicious_doc_comments.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(unused)] #![warn(clippy::suspicious_doc_comments)] diff --git a/src/tools/clippy/tests/ui/suspicious_doc_comments.stderr b/src/tools/clippy/tests/ui/suspicious_doc_comments.stderr index 6c167df27..1b238f501 100644 --- a/src/tools/clippy/tests/ui/suspicious_doc_comments.stderr +++ b/src/tools/clippy/tests/ui/suspicious_doc_comments.stderr @@ -1,17 +1,18 @@ error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments.rs:6:1 + --> $DIR/suspicious_doc_comments.rs:5:1 | LL | ///! Fake module documentation. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::suspicious-doc-comments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_doc_comments)]` help: use an inner doc comment to document the parent module or crate | 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:10:5 + --> $DIR/suspicious_doc_comments.rs:9:5 | LL | ///! This module contains useful functions. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,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:22:5 + --> $DIR/suspicious_doc_comments.rs:21:5 | LL | / /**! This module contains useful functions. LL | | */ @@ -35,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:36:5 + --> $DIR/suspicious_doc_comments.rs:35:5 | LL | / ///! This module LL | | ///! contains @@ -50,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:44:5 + --> $DIR/suspicious_doc_comments.rs:43:5 | LL | / ///! a LL | | ///! b @@ -63,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:52:5 + --> $DIR/suspicious_doc_comments.rs:51:5 | LL | ///! a | ^^^^^^ @@ -74,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:58:5 + --> $DIR/suspicious_doc_comments.rs:57:5 | LL | / ///! a LL | | @@ -89,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:70:5 + --> $DIR/suspicious_doc_comments.rs:69:5 | LL | ///! Very cool macro | ^^^^^^^^^^^^^^^^^^^^ @@ -100,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:77:5 + --> $DIR/suspicious_doc_comments.rs:76:5 | LL | ///! Huh. | ^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/suspicious_doc_comments_unfixable.rs b/src/tools/clippy/tests/ui/suspicious_doc_comments_unfixable.rs index ad98c7f49..9e9c47757 100644 --- a/src/tools/clippy/tests/ui/suspicious_doc_comments_unfixable.rs +++ b/src/tools/clippy/tests/ui/suspicious_doc_comments_unfixable.rs @@ -1,13 +1,16 @@ #![allow(unused)] #![warn(clippy::suspicious_doc_comments)] - +//@no-rustfix ///! a +//~^ ERROR: this is an outer doc comment and does not apply to the parent module or crate +//~| NOTE: `-D clippy::suspicious-doc-comments` implied by `-D warnings` ///! b /// c ///! d pub fn foo() {} ///! a +//~^ ERROR: this is an outer doc comment and does not apply to the parent module or crate ///! b /// c ///! d diff --git a/src/tools/clippy/tests/ui/suspicious_doc_comments_unfixable.stderr b/src/tools/clippy/tests/ui/suspicious_doc_comments_unfixable.stderr index f89146dad..ae92c334f 100644 --- a/src/tools/clippy/tests/ui/suspicious_doc_comments_unfixable.stderr +++ b/src/tools/clippy/tests/ui/suspicious_doc_comments_unfixable.stderr @@ -2,24 +2,30 @@ error: this is an outer doc comment and does not apply to the parent module or c --> $DIR/suspicious_doc_comments_unfixable.rs:4:1 | LL | / ///! a +LL | | +LL | | LL | | ///! b LL | | /// c LL | | ///! d | |______^ | = note: `-D clippy::suspicious-doc-comments` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_doc_comments)]` help: use an inner doc comment to document the parent module or crate | LL + //! a +LL | +LL | LL + //! b LL | /// c LL + //! d | error: this is an outer doc comment and does not apply to the parent module or crate - --> $DIR/suspicious_doc_comments_unfixable.rs:10:1 + --> $DIR/suspicious_doc_comments_unfixable.rs:12:1 | LL | / ///! a +LL | | LL | | ///! b LL | | /// c LL | | ///! d @@ -28,6 +34,7 @@ LL | | ///! d help: use an inner doc comment to document the parent module or crate | LL + //! a +LL | LL + //! b LL | /// c LL + //! d diff --git a/src/tools/clippy/tests/ui/suspicious_else_formatting.rs b/src/tools/clippy/tests/ui/suspicious_else_formatting.rs index 0473ccdc3..c0856427e 100644 --- a/src/tools/clippy/tests/ui/suspicious_else_formatting.rs +++ b/src/tools/clippy/tests/ui/suspicious_else_formatting.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macro_suspicious_else_formatting.rs:proc-macro +//@aux-build:proc_macro_suspicious_else_formatting.rs #![warn(clippy::suspicious_else_formatting)] #![allow( diff --git a/src/tools/clippy/tests/ui/suspicious_else_formatting.stderr b/src/tools/clippy/tests/ui/suspicious_else_formatting.stderr index 723fdd7e9..95047cb95 100644 --- a/src/tools/clippy/tests/ui/suspicious_else_formatting.stderr +++ b/src/tools/clippy/tests/ui/suspicious_else_formatting.stderr @@ -6,6 +6,7 @@ LL | } { | = note: to remove this lint, add the missing `else` or add a new line before the next block = note: `-D clippy::suspicious-else-formatting` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/suspicious_map.rs b/src/tools/clippy/tests/ui/suspicious_map.rs index 3a2a10cf0..d4247fcd9 100644 --- a/src/tools/clippy/tests/ui/suspicious_map.rs +++ b/src/tools/clippy/tests/ui/suspicious_map.rs @@ -2,9 +2,11 @@ fn main() { let _ = (0..3).map(|x| x + 2).count(); + //~^ ERROR: this call to `map()` won't have an effect on the call to `count()` let f = |x| x + 1; let _ = (0..3).map(f).count(); + //~^ ERROR: this call to `map()` won't have an effect on the call to `count()` } fn negative() { diff --git a/src/tools/clippy/tests/ui/suspicious_map.stderr b/src/tools/clippy/tests/ui/suspicious_map.stderr index e25167481..9c065e05c 100644 --- a/src/tools/clippy/tests/ui/suspicious_map.stderr +++ b/src/tools/clippy/tests/ui/suspicious_map.stderr @@ -6,9 +6,10 @@ LL | let _ = (0..3).map(|x| x + 2).count(); | = help: make sure you did not confuse `map` with `filter`, `for_each` or `inspect` = note: `-D clippy::suspicious-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_map)]` error: this call to `map()` won't have an effect on the call to `count()` - --> $DIR/suspicious_map.rs:7:13 + --> $DIR/suspicious_map.rs:8:13 | LL | let _ = (0..3).map(f).count(); | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/suspicious_operation_groupings.fixed b/src/tools/clippy/tests/ui/suspicious_operation_groupings.fixed index 0e37701ec..9d9732307 100644 --- a/src/tools/clippy/tests/ui/suspicious_operation_groupings.fixed +++ b/src/tools/clippy/tests/ui/suspicious_operation_groupings.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suspicious_operation_groupings)] #![allow(dead_code, unused_parens, clippy::eq_op)] diff --git a/src/tools/clippy/tests/ui/suspicious_operation_groupings.rs b/src/tools/clippy/tests/ui/suspicious_operation_groupings.rs index dd4f3b71c..201b8e657 100644 --- a/src/tools/clippy/tests/ui/suspicious_operation_groupings.rs +++ b/src/tools/clippy/tests/ui/suspicious_operation_groupings.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::suspicious_operation_groupings)] #![allow(dead_code, unused_parens, clippy::eq_op)] diff --git a/src/tools/clippy/tests/ui/suspicious_operation_groupings.stderr b/src/tools/clippy/tests/ui/suspicious_operation_groupings.stderr index 29f229245..0784da06e 100644 --- a/src/tools/clippy/tests/ui/suspicious_operation_groupings.stderr +++ b/src/tools/clippy/tests/ui/suspicious_operation_groupings.stderr @@ -1,157 +1,158 @@ error: this sequence of operators looks suspiciously like a bug - --> $DIR/suspicious_operation_groupings.rs:16:9 + --> $DIR/suspicious_operation_groupings.rs:15:9 | LL | self.x == other.y && self.y == other.y && self.z == other.z | ^^^^^^^^^^^^^^^^^ help: did you mean: `self.x == other.x` | = note: `-D clippy::suspicious-operation-groupings` implied by `-D warnings` + = 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:29:20 + --> $DIR/suspicious_operation_groupings.rs:28: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:77:33 + --> $DIR/suspicious_operation_groupings.rs:76: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:82:19 + --> $DIR/suspicious_operation_groupings.rs:81: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:82:19 + --> $DIR/suspicious_operation_groupings.rs:81: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:87:19 + --> $DIR/suspicious_operation_groupings.rs:86: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:92:19 + --> $DIR/suspicious_operation_groupings.rs:91: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:97:5 + --> $DIR/suspicious_operation_groupings.rs:96: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:102:33 + --> $DIR/suspicious_operation_groupings.rs:101: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:115:20 + --> $DIR/suspicious_operation_groupings.rs:114: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:120:34 + --> $DIR/suspicious_operation_groupings.rs:119: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:125:38 + --> $DIR/suspicious_operation_groupings.rs:124: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:130:39 + --> $DIR/suspicious_operation_groupings.rs:129: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:135:42 + --> $DIR/suspicious_operation_groupings.rs:134: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:135:42 + --> $DIR/suspicious_operation_groupings.rs:134: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:140:40 + --> $DIR/suspicious_operation_groupings.rs:139: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:145:40 + --> $DIR/suspicious_operation_groupings.rs:144: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:150:20 + --> $DIR/suspicious_operation_groupings.rs:149: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:155:35 + --> $DIR/suspicious_operation_groupings.rs:154: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:160:29 + --> $DIR/suspicious_operation_groupings.rs:159: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:165:17 + --> $DIR/suspicious_operation_groupings.rs:164: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:174:77 + --> $DIR/suspicious_operation_groupings.rs:173: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:188:25 + --> $DIR/suspicious_operation_groupings.rs:187: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:194:23 + --> $DIR/suspicious_operation_groupings.rs:193: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:201:48 + --> $DIR/suspicious_operation_groupings.rs:200: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:206:27 + --> $DIR/suspicious_operation_groupings.rs:205: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/src/tools/clippy/tests/ui/suspicious_splitn.rs b/src/tools/clippy/tests/ui/suspicious_splitn.rs index 528f2ddcc..7aa609706 100644 --- a/src/tools/clippy/tests/ui/suspicious_splitn.rs +++ b/src/tools/clippy/tests/ui/suspicious_splitn.rs @@ -8,14 +8,32 @@ fn main() { let _ = [].splitn(0, |&x: &u32| x == 1); let _ = "a,b".splitn(0, ','); + //~^ ERROR: `splitn` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` let _ = "a,b".rsplitn(0, ','); + //~^ ERROR: `rsplitn` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` let _ = "a,b".splitn(1, ','); + //~^ ERROR: `splitn` called with `1` split + //~| NOTE: the resulting iterator will always return the entire string followed by `No let _ = [0, 1, 2].splitn(0, |&x| x == 1); + //~^ ERROR: `splitn` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); + //~^ ERROR: `splitn_mut` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` let _ = [0, 1, 2].splitn(1, |&x| x == 1); + //~^ ERROR: `splitn` called with `1` split + //~| NOTE: the resulting iterator will always return the entire slice followed by `Non let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); + //~^ ERROR: `rsplitn_mut` called with `1` split + //~| NOTE: the resulting iterator will always return the entire slice followed by `Non const X: usize = 0; let _ = "a,b".splitn(X + 1, ','); + //~^ ERROR: `splitn` called with `1` split + //~| NOTE: the resulting iterator will always return the entire string followed by `No let _ = "a,b".splitn(X, ','); + //~^ ERROR: `splitn` called with `0` splits + //~| NOTE: the resulting iterator will always return `None` } diff --git a/src/tools/clippy/tests/ui/suspicious_splitn.stderr b/src/tools/clippy/tests/ui/suspicious_splitn.stderr index 55ce63d4f..4513beac8 100644 --- a/src/tools/clippy/tests/ui/suspicious_splitn.stderr +++ b/src/tools/clippy/tests/ui/suspicious_splitn.stderr @@ -6,9 +6,10 @@ LL | let _ = "a,b".splitn(0, ','); | = note: the resulting iterator will always return `None` = note: `-D clippy::suspicious-splitn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_splitn)]` error: `rsplitn` called with `0` splits - --> $DIR/suspicious_splitn.rs:11:13 + --> $DIR/suspicious_splitn.rs:13:13 | LL | let _ = "a,b".rsplitn(0, ','); | ^^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | let _ = "a,b".rsplitn(0, ','); = note: the resulting iterator will always return `None` error: `splitn` called with `1` split - --> $DIR/suspicious_splitn.rs:12:13 + --> $DIR/suspicious_splitn.rs:16:13 | LL | let _ = "a,b".splitn(1, ','); | ^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | let _ = "a,b".splitn(1, ','); = note: the resulting iterator will always return the entire string followed by `None` error: `splitn` called with `0` splits - --> $DIR/suspicious_splitn.rs:13:13 + --> $DIR/suspicious_splitn.rs:19:13 | LL | let _ = [0, 1, 2].splitn(0, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | let _ = [0, 1, 2].splitn(0, |&x| x == 1); = note: the resulting iterator will always return `None` error: `splitn_mut` called with `0` splits - --> $DIR/suspicious_splitn.rs:14:13 + --> $DIR/suspicious_splitn.rs:22:13 | LL | let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | let _ = [0, 1, 2].splitn_mut(0, |&x| x == 1); = note: the resulting iterator will always return `None` error: `splitn` called with `1` split - --> $DIR/suspicious_splitn.rs:15:13 + --> $DIR/suspicious_splitn.rs:25:13 | LL | let _ = [0, 1, 2].splitn(1, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | let _ = [0, 1, 2].splitn(1, |&x| x == 1); = note: the resulting iterator will always return the entire slice followed by `None` error: `rsplitn_mut` called with `1` split - --> $DIR/suspicious_splitn.rs:16:13 + --> $DIR/suspicious_splitn.rs:28:13 | LL | let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | let _ = [0, 1, 2].rsplitn_mut(1, |&x| x == 1); = note: the resulting iterator will always return the entire slice followed by `None` error: `splitn` called with `1` split - --> $DIR/suspicious_splitn.rs:19:13 + --> $DIR/suspicious_splitn.rs:33:13 | LL | let _ = "a,b".splitn(X + 1, ','); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +65,7 @@ LL | let _ = "a,b".splitn(X + 1, ','); = note: the resulting iterator will always return the entire string followed by `None` error: `splitn` called with `0` splits - --> $DIR/suspicious_splitn.rs:20:13 + --> $DIR/suspicious_splitn.rs:36:13 | LL | let _ = "a,b".splitn(X, ','); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/suspicious_to_owned.rs b/src/tools/clippy/tests/ui/suspicious_to_owned.rs index cba21bf4a..f32b07d45 100644 --- a/src/tools/clippy/tests/ui/suspicious_to_owned.rs +++ b/src/tools/clippy/tests/ui/suspicious_to_owned.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::suspicious_to_owned)] #![warn(clippy::implicit_clone)] #![allow(clippy::redundant_clone)] @@ -14,6 +15,8 @@ fn main() { // we expect this to be linted let cow = Cow::Borrowed(moo); let _ = cow.to_owned(); + //~^ ERROR: this `to_owned` call clones the Cow<'_, str> itself and does not cause the + //~| NOTE: `-D clippy::suspicious-to-owned` implied by `-D warnings` // we expect no lints for this let cow = Cow::Borrowed(moo); let _ = cow.into_owned(); @@ -24,6 +27,7 @@ fn main() { // we expect this to be linted let cow = Cow::Borrowed(&moos); let _ = cow.to_owned(); + //~^ ERROR: this `to_owned` call clones the Cow<'_, [char; 3]> itself and does not cau // we expect no lints for this let cow = Cow::Borrowed(&moos); let _ = cow.into_owned(); @@ -34,6 +38,7 @@ fn main() { // we expect this to be linted let cow = Cow::Borrowed(&moos_vec); let _ = cow.to_owned(); + //~^ ERROR: this `to_owned` call clones the Cow<'_, Vec> itself and does not cau // we expect no lints for this let cow = Cow::Borrowed(&moos_vec); let _ = cow.into_owned(); @@ -44,6 +49,7 @@ fn main() { // we expect this to be linted let cow = unsafe { CStr::from_ptr(c_moo_ptr) }.to_string_lossy(); let _ = cow.to_owned(); + //~^ ERROR: this `to_owned` call clones the Cow<'_, str> itself and does not cause the // we expect no lints for this let cow = unsafe { CStr::from_ptr(c_moo_ptr) }.to_string_lossy(); let _ = cow.into_owned(); @@ -58,5 +64,8 @@ fn main() { // we expect implicit_clone lints for these let _ = String::from(moo).to_owned(); + //~^ ERROR: implicitly cloning a `String` by calling `to_owned` on its dereferenced ty + //~| NOTE: `-D clippy::implicit-clone` implied by `-D warnings` let _ = moos_vec.to_owned(); + //~^ ERROR: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type } diff --git a/src/tools/clippy/tests/ui/suspicious_to_owned.stderr b/src/tools/clippy/tests/ui/suspicious_to_owned.stderr index c4ec7aa88..eb967a714 100644 --- a/src/tools/clippy/tests/ui/suspicious_to_owned.stderr +++ b/src/tools/clippy/tests/ui/suspicious_to_owned.stderr @@ -1,10 +1,11 @@ error: this `to_owned` call clones the Cow<'_, str> itself and does not cause the Cow<'_, str> contents to become owned - --> $DIR/suspicious_to_owned.rs:16:13 + --> $DIR/suspicious_to_owned.rs:17:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ | = note: `-D clippy::suspicious-to-owned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_to_owned)]` help: depending on intent, either make the Cow an Owned variant | LL | let _ = cow.into_owned(); @@ -15,7 +16,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: this `to_owned` call clones the Cow<'_, [char; 3]> itself and does not cause the Cow<'_, [char; 3]> contents to become owned - --> $DIR/suspicious_to_owned.rs:26:13 + --> $DIR/suspicious_to_owned.rs:29:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -30,7 +31,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: this `to_owned` call clones the Cow<'_, Vec> itself and does not cause the Cow<'_, Vec> contents to become owned - --> $DIR/suspicious_to_owned.rs:36:13 + --> $DIR/suspicious_to_owned.rs:40:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -45,7 +46,7 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: this `to_owned` call clones the Cow<'_, str> itself and does not cause the Cow<'_, str> contents to become owned - --> $DIR/suspicious_to_owned.rs:46:13 + --> $DIR/suspicious_to_owned.rs:51:13 | LL | let _ = cow.to_owned(); | ^^^^^^^^^^^^^^ @@ -60,15 +61,16 @@ LL | let _ = cow.clone(); | ~~~~~~~~~~~ error: implicitly cloning a `String` by calling `to_owned` on its dereferenced type - --> $DIR/suspicious_to_owned.rs:60:13 + --> $DIR/suspicious_to_owned.rs:66:13 | LL | let _ = String::from(moo).to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `String::from(moo).clone()` | = note: `-D clippy::implicit-clone` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::implicit_clone)]` error: implicitly cloning a `Vec` by calling `to_owned` on its dereferenced type - --> $DIR/suspicious_to_owned.rs:61:13 + --> $DIR/suspicious_to_owned.rs:69:13 | LL | let _ = moos_vec.to_owned(); | ^^^^^^^^^^^^^^^^^^^ help: consider using: `moos_vec.clone()` diff --git a/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.rs b/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.rs index 3c5ca1762..a7a62154e 100644 --- a/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.rs +++ b/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.rs @@ -7,14 +7,18 @@ fn main() { let a = 42; if a >- 30 {} + //~^ ERROR: by not having a space between `>` and `-` it looks like `>-` is a single o if a >=- 30 {} + //~^ ERROR: by not having a space between `>=` and `-` it looks like `>=-` is a single let b = true; let c = false; if b &&! c {} + //~^ ERROR: by not having a space between `&&` and `!` it looks like `&&!` is a single if a >- 30 {} + //~^ ERROR: by not having a space between `>` and `-` it looks like `>-` is a single o // those are ok: if a >-30 {} diff --git a/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.stderr b/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.stderr index 52b0e99a1..3cddde4ec 100644 --- a/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.stderr +++ b/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.stderr @@ -6,9 +6,10 @@ LL | if a >- 30 {} | = help: put a space between `>` and `-` and remove the space after `-` = note: `-D clippy::suspicious-unary-op-formatting` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_unary_op_formatting)]` error: by not having a space between `>=` and `-` it looks like `>=-` is a single operator - --> $DIR/suspicious_unary_op_formatting.rs:10:9 + --> $DIR/suspicious_unary_op_formatting.rs:11:9 | LL | if a >=- 30 {} | ^^^^^ @@ -16,7 +17,7 @@ LL | if a >=- 30 {} = help: put a space between `>=` and `-` and remove the space after `-` error: by not having a space between `&&` and `!` it looks like `&&!` is a single operator - --> $DIR/suspicious_unary_op_formatting.rs:15:9 + --> $DIR/suspicious_unary_op_formatting.rs:17:9 | LL | if b &&! c {} | ^^^^^ @@ -24,7 +25,7 @@ LL | if b &&! c {} = help: put a space between `&&` and `!` and remove the space after `!` error: by not having a space between `>` and `-` it looks like `>-` is a single operator - --> $DIR/suspicious_unary_op_formatting.rs:17:9 + --> $DIR/suspicious_unary_op_formatting.rs:20:9 | LL | if a >- 30 {} | ^^^^^^ diff --git a/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.rs b/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.rs index eb9fc63fb..a5319e1b2 100644 --- a/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.rs +++ b/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.rs @@ -1,7 +1,7 @@ #![allow(unused)] #![warn(clippy::suspicious_xor_used_as_pow)] #![allow(clippy::eq_op)] - +//@no-rustfix macro_rules! macro_test { () => { 13 @@ -17,11 +17,18 @@ macro_rules! macro_test_inside { fn main() { // Should warn: let _ = 2 ^ 5; + //~^ ERROR: `^` is not the exponentiation operator + //~| NOTE: `-D clippy::suspicious-xor-used-as-pow` implied by `-D warnings` let _ = 2i32 ^ 9i32; + //~^ ERROR: `^` is not the exponentiation operator let _ = 2i32 ^ 2i32; + //~^ ERROR: `^` is not the exponentiation operator let _ = 50i32 ^ 3i32; + //~^ ERROR: `^` is not the exponentiation operator let _ = 5i32 ^ 8i32; + //~^ ERROR: `^` is not the exponentiation operator let _ = 2i32 ^ 32i32; + //~^ ERROR: `^` is not the exponentiation operator macro_test_inside!(); // Should not warn: diff --git a/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr b/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr index d93a55ba9..29e9fa771 100644 --- a/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr +++ b/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr @@ -5,33 +5,34 @@ LL | let _ = 2 ^ 5; | ^^^^^ help: did you mean to write: `2.pow(5)` | = note: `-D clippy::suspicious-xor-used-as-pow` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::suspicious_xor_used_as_pow)]` error: `^` is not the exponentiation operator - --> $DIR/suspicious_xor_used_as_pow.rs:20:13 + --> $DIR/suspicious_xor_used_as_pow.rs:22: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:21:13 + --> $DIR/suspicious_xor_used_as_pow.rs:24: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:22:13 + --> $DIR/suspicious_xor_used_as_pow.rs:26: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:23:13 + --> $DIR/suspicious_xor_used_as_pow.rs:28: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:24:13 + --> $DIR/suspicious_xor_used_as_pow.rs:30:13 | LL | let _ = 2i32 ^ 32i32; | ^^^^^^^^^^^^ help: did you mean to write: `2i32.pow(32i32)` diff --git a/src/tools/clippy/tests/ui/swap.fixed b/src/tools/clippy/tests/ui/swap.fixed index 7b74a83b6..888665a17 100644 --- a/src/tools/clippy/tests/ui/swap.fixed +++ b/src/tools/clippy/tests/ui/swap.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build: macro_rules.rs #![warn(clippy::all)] diff --git a/src/tools/clippy/tests/ui/swap.rs b/src/tools/clippy/tests/ui/swap.rs index 93855cd7b..c9ad77629 100644 --- a/src/tools/clippy/tests/ui/swap.rs +++ b/src/tools/clippy/tests/ui/swap.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build: macro_rules.rs #![warn(clippy::all)] diff --git a/src/tools/clippy/tests/ui/swap.stderr b/src/tools/clippy/tests/ui/swap.stderr index 1097b29bb..e69ad02b0 100644 --- a/src/tools/clippy/tests/ui/swap.stderr +++ b/src/tools/clippy/tests/ui/swap.stderr @@ -1,5 +1,5 @@ error: this looks like you are swapping `bar.a` and `bar.b` manually - --> $DIR/swap.rs:29:5 + --> $DIR/swap.rs:28:5 | LL | / let temp = bar.a; LL | | bar.a = bar.b; @@ -8,9 +8,10 @@ LL | | bar.b = temp; | = note: or maybe you should use `std::mem::replace`? = note: `-D clippy::manual-swap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::manual_swap)]` error: this looks like you are swapping elements of `foo` manually - --> $DIR/swap.rs:41:5 + --> $DIR/swap.rs:40:5 | LL | / let temp = foo[0]; LL | | foo[0] = foo[1]; @@ -18,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:50:5 + --> $DIR/swap.rs:49:5 | LL | / let temp = foo[0]; LL | | foo[0] = foo[1]; @@ -26,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:69:5 + --> $DIR/swap.rs:68:5 | LL | / let temp = foo[0]; LL | | foo[0] = foo[1]; @@ -34,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:80:5 + --> $DIR/swap.rs:79:5 | LL | / a ^= b; LL | | b ^= a; @@ -42,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:88:5 + --> $DIR/swap.rs:87:5 | LL | / bar.a ^= bar.b; LL | | bar.b ^= bar.a; @@ -50,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:96:5 + --> $DIR/swap.rs:95:5 | LL | / foo[0] ^= foo[1]; LL | | foo[1] ^= foo[0]; @@ -58,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:125:5 + --> $DIR/swap.rs:124:5 | LL | / let temp = foo[0][1]; LL | | foo[0][1] = bar[1][0]; @@ -68,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:139:7 + --> $DIR/swap.rs:138:7 | LL | ; let t = a; | _______^ @@ -79,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:148:7 + --> $DIR/swap.rs:147:7 | LL | ; let t = c.0; | _______^ @@ -90,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:174:5 + --> $DIR/swap.rs:173:5 | LL | / let t = b; LL | | b = a; @@ -100,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:136:5 + --> $DIR/swap.rs:135:5 | LL | / a = b; LL | | b = a; @@ -108,9 +109,10 @@ LL | | b = a; | = note: or maybe you should use `std::mem::replace`? = note: `-D clippy::almost-swapped` implied by `-D warnings` + = 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:145:5 + --> $DIR/swap.rs:144:5 | LL | / c.0 = a; LL | | a = c.0; @@ -119,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:152:5 + --> $DIR/swap.rs:151:5 | LL | / let a = b; LL | | let b = a; @@ -128,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:157:5 + --> $DIR/swap.rs:156:5 | LL | / d = c; LL | | c = d; @@ -137,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:161:5 + --> $DIR/swap.rs:160:5 | LL | / let a = b; LL | | b = a; @@ -146,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:209:5 + --> $DIR/swap.rs:208:5 | LL | / let t = s.0.x; LL | | s.0.x = s.0.y; diff --git a/src/tools/clippy/tests/ui/swap_ptr_to_ref.fixed b/src/tools/clippy/tests/ui/swap_ptr_to_ref.fixed index 3bede3017..599bb0e80 100644 --- a/src/tools/clippy/tests/ui/swap_ptr_to_ref.fixed +++ b/src/tools/clippy/tests/ui/swap_ptr_to_ref.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::swap_ptr_to_ref)] use core::ptr::addr_of_mut; diff --git a/src/tools/clippy/tests/ui/swap_ptr_to_ref.rs b/src/tools/clippy/tests/ui/swap_ptr_to_ref.rs index 726b09d37..3a8a8daef 100644 --- a/src/tools/clippy/tests/ui/swap_ptr_to_ref.rs +++ b/src/tools/clippy/tests/ui/swap_ptr_to_ref.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::swap_ptr_to_ref)] use core::ptr::addr_of_mut; diff --git a/src/tools/clippy/tests/ui/swap_ptr_to_ref.stderr b/src/tools/clippy/tests/ui/swap_ptr_to_ref.stderr index 401ce0708..42455f492 100644 --- a/src/tools/clippy/tests/ui/swap_ptr_to_ref.stderr +++ b/src/tools/clippy/tests/ui/swap_ptr_to_ref.stderr @@ -1,25 +1,26 @@ error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> $DIR/swap_ptr_to_ref.rs:13:9 + --> $DIR/swap_ptr_to_ref.rs:11:9 | LL | core::mem::swap(&mut *y, &mut *z); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use ptr::swap: `core::ptr::swap(y, z)` | = note: `-D clippy::swap-ptr-to-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::swap_ptr_to_ref)]` error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> $DIR/swap_ptr_to_ref.rs:14:9 + --> $DIR/swap_ptr_to_ref.rs:12:9 | LL | core::mem::swap(&mut *y, &mut x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use ptr::swap: `core::ptr::swap(y, &mut x)` error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> $DIR/swap_ptr_to_ref.rs:15:9 + --> $DIR/swap_ptr_to_ref.rs:13:9 | LL | core::mem::swap(&mut x, &mut *y); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use ptr::swap: `core::ptr::swap(&mut x, y)` error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> $DIR/swap_ptr_to_ref.rs:16:9 + --> $DIR/swap_ptr_to_ref.rs:14:9 | LL | core::mem::swap(&mut *addr_of_mut!(x), &mut *addr_of_mut!(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use ptr::swap: `core::ptr::swap(addr_of_mut!(x), addr_of_mut!(x))` diff --git a/src/tools/clippy/tests/ui/swap_ptr_to_ref_unfixable.rs b/src/tools/clippy/tests/ui/swap_ptr_to_ref_unfixable.rs index 66ea7c652..08e56a5d0 100644 --- a/src/tools/clippy/tests/ui/swap_ptr_to_ref_unfixable.rs +++ b/src/tools/clippy/tests/ui/swap_ptr_to_ref_unfixable.rs @@ -12,7 +12,11 @@ fn main() { unsafe { core::mem::swap(addr_of_mut_to_ref!(x), &mut *y); + //~^ ERROR: call to `core::mem::swap` with a parameter derived from a raw pointer + //~| NOTE: `-D clippy::swap-ptr-to-ref` implied by `-D warnings` core::mem::swap(&mut *y, addr_of_mut_to_ref!(x)); + //~^ ERROR: call to `core::mem::swap` with a parameter derived from a raw pointer core::mem::swap(addr_of_mut_to_ref!(x), addr_of_mut_to_ref!(x)); + //~^ ERROR: call to `core::mem::swap` with a parameter derived from a raw pointer } } diff --git a/src/tools/clippy/tests/ui/swap_ptr_to_ref_unfixable.stderr b/src/tools/clippy/tests/ui/swap_ptr_to_ref_unfixable.stderr index c261205d5..ce1d78142 100644 --- a/src/tools/clippy/tests/ui/swap_ptr_to_ref_unfixable.stderr +++ b/src/tools/clippy/tests/ui/swap_ptr_to_ref_unfixable.stderr @@ -5,15 +5,16 @@ LL | core::mem::swap(addr_of_mut_to_ref!(x), &mut *y); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::swap-ptr-to-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::swap_ptr_to_ref)]` error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> $DIR/swap_ptr_to_ref_unfixable.rs:15:9 + --> $DIR/swap_ptr_to_ref_unfixable.rs:17:9 | LL | core::mem::swap(&mut *y, addr_of_mut_to_ref!(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: call to `core::mem::swap` with a parameter derived from a raw pointer - --> $DIR/swap_ptr_to_ref_unfixable.rs:16:9 + --> $DIR/swap_ptr_to_ref_unfixable.rs:19:9 | LL | core::mem::swap(addr_of_mut_to_ref!(x), addr_of_mut_to_ref!(x)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/tabs_in_doc_comments.fixed b/src/tools/clippy/tests/ui/tabs_in_doc_comments.fixed index 21020182c..26cc5c27e 100644 --- a/src/tools/clippy/tests/ui/tabs_in_doc_comments.fixed +++ b/src/tools/clippy/tests/ui/tabs_in_doc_comments.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::tabs_in_doc_comments)] #[allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/tabs_in_doc_comments.rs b/src/tools/clippy/tests/ui/tabs_in_doc_comments.rs index df704267d..14b06966e 100644 --- a/src/tools/clippy/tests/ui/tabs_in_doc_comments.rs +++ b/src/tools/clippy/tests/ui/tabs_in_doc_comments.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::tabs_in_doc_comments)] #[allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/tabs_in_doc_comments.stderr b/src/tools/clippy/tests/ui/tabs_in_doc_comments.stderr index 355f2e805..69ce214ae 100644 --- a/src/tools/clippy/tests/ui/tabs_in_doc_comments.stderr +++ b/src/tools/clippy/tests/ui/tabs_in_doc_comments.stderr @@ -1,49 +1,50 @@ error: using tabs in doc comments is not recommended - --> $DIR/tabs_in_doc_comments.rs:12:9 + --> $DIR/tabs_in_doc_comments.rs:10:9 | LL | /// - First String: | ^^^^ help: consider using four spaces per tab | = note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings` + = 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:13:9 + --> $DIR/tabs_in_doc_comments.rs:11: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:16:9 + --> $DIR/tabs_in_doc_comments.rs:14: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:17:9 + --> $DIR/tabs_in_doc_comments.rs:15: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:8:5 + --> $DIR/tabs_in_doc_comments.rs:6: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:8:13 + --> $DIR/tabs_in_doc_comments.rs:6: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:9:5 + --> $DIR/tabs_in_doc_comments.rs:7: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:9:14 + --> $DIR/tabs_in_doc_comments.rs:7:14 | LL | /// - second one | ^^^^ help: consider using four spaces per tab diff --git a/src/tools/clippy/tests/ui/temporary_assignment.rs b/src/tools/clippy/tests/ui/temporary_assignment.rs index b4a931043..383e70be9 100644 --- a/src/tools/clippy/tests/ui/temporary_assignment.rs +++ b/src/tools/clippy/tests/ui/temporary_assignment.rs @@ -46,13 +46,18 @@ fn main() { let mut t = (0, 0); Struct { field: 0 }.field = 1; + //~^ ERROR: assignment to temporary + //~| NOTE: `-D clippy::temporary-assignment` implied by `-D warnings` MultiStruct { + //~^ ERROR: assignment to temporary structure: Struct { field: 0 }, } .structure .field = 1; ArrayStruct { array: [0] }.array[0] = 1; + //~^ ERROR: assignment to temporary (0, 0).0 = 1; + //~^ ERROR: assignment to temporary // no error s.field = 1; diff --git a/src/tools/clippy/tests/ui/temporary_assignment.stderr b/src/tools/clippy/tests/ui/temporary_assignment.stderr index 4cc32c79f..cbb892418 100644 --- a/src/tools/clippy/tests/ui/temporary_assignment.stderr +++ b/src/tools/clippy/tests/ui/temporary_assignment.stderr @@ -5,11 +5,13 @@ LL | Struct { field: 0 }.field = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::temporary-assignment` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::temporary_assignment)]` error: assignment to temporary - --> $DIR/temporary_assignment.rs:49:5 + --> $DIR/temporary_assignment.rs:51:5 | LL | / MultiStruct { +LL | | LL | | structure: Struct { field: 0 }, LL | | } LL | | .structure @@ -17,13 +19,13 @@ LL | | .field = 1; | |______________^ error: assignment to temporary - --> $DIR/temporary_assignment.rs:54:5 + --> $DIR/temporary_assignment.rs:57:5 | LL | ArrayStruct { array: [0] }.array[0] = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: assignment to temporary - --> $DIR/temporary_assignment.rs:55:5 + --> $DIR/temporary_assignment.rs:59:5 | LL | (0, 0).0 = 1; | ^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/tests_outside_test_module.rs b/src/tools/clippy/tests/ui/tests_outside_test_module.rs index d53c692b7..0abde4a57 100644 --- a/src/tools/clippy/tests/ui/tests_outside_test_module.rs +++ b/src/tools/clippy/tests/ui/tests_outside_test_module.rs @@ -8,6 +8,8 @@ fn main() { // Should lint #[test] fn my_test() {} +//~^ ERROR: this function marked with #[test] is outside a #[cfg(test)] module +//~| NOTE: move it to a testing module marked with #[cfg(test)] #[cfg(test)] mod tests { diff --git a/src/tools/clippy/tests/ui/tests_outside_test_module.stderr b/src/tools/clippy/tests/ui/tests_outside_test_module.stderr index 71c649c5d..112d6ce1f 100644 --- a/src/tools/clippy/tests/ui/tests_outside_test_module.stderr +++ b/src/tools/clippy/tests/ui/tests_outside_test_module.stderr @@ -6,6 +6,7 @@ LL | fn my_test() {} | = note: move it to a testing module marked with #[cfg(test)] = note: `-D clippy::tests-outside-test-module` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::tests_outside_test_module)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/to_digit_is_some.fixed b/src/tools/clippy/tests/ui/to_digit_is_some.fixed index dc9be66d4..2ef4c0528 100644 --- a/src/tools/clippy/tests/ui/to_digit_is_some.fixed +++ b/src/tools/clippy/tests/ui/to_digit_is_some.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::to_digit_is_some)] fn main() { diff --git a/src/tools/clippy/tests/ui/to_digit_is_some.rs b/src/tools/clippy/tests/ui/to_digit_is_some.rs index d2a09ac30..54d954580 100644 --- a/src/tools/clippy/tests/ui/to_digit_is_some.rs +++ b/src/tools/clippy/tests/ui/to_digit_is_some.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::to_digit_is_some)] fn main() { diff --git a/src/tools/clippy/tests/ui/to_digit_is_some.stderr b/src/tools/clippy/tests/ui/to_digit_is_some.stderr index c4718825d..5067ad7fb 100644 --- a/src/tools/clippy/tests/ui/to_digit_is_some.stderr +++ b/src/tools/clippy/tests/ui/to_digit_is_some.stderr @@ -1,13 +1,14 @@ error: use of `.to_digit(..).is_some()` - --> $DIR/to_digit_is_some.rs:9:13 + --> $DIR/to_digit_is_some.rs:7:13 | LL | let _ = d.to_digit(8).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `d.is_digit(8)` | = note: `-D clippy::to-digit-is-some` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::to_digit_is_some)]` error: use of `.to_digit(..).is_some()` - --> $DIR/to_digit_is_some.rs:10:13 + --> $DIR/to_digit_is_some.rs:8:13 | LL | let _ = char::to_digit(c, 8).is_some(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `char::is_digit(c, 8)` diff --git a/src/tools/clippy/tests/ui/to_string_in_format_args_incremental.fixed b/src/tools/clippy/tests/ui/to_string_in_format_args_incremental.fixed index 9f75ad895..1f7895796 100644 --- a/src/tools/clippy/tests/ui/to_string_in_format_args_incremental.fixed +++ b/src/tools/clippy/tests/ui/to_string_in_format_args_incremental.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@compile-flags: -C incremental=target/debug/test/incr // see https://github.com/rust-lang/rust-clippy/issues/10969 diff --git a/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed b/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed index 9ad45c7a8..ff5cd7abb 100644 --- a/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed +++ b/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::toplevel_ref_arg)] #![allow(clippy::uninlined_format_args, unused, clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/toplevel_ref_arg.rs b/src/tools/clippy/tests/ui/toplevel_ref_arg.rs index 45ccc024c..ab79b8959 100644 --- a/src/tools/clippy/tests/ui/toplevel_ref_arg.rs +++ b/src/tools/clippy/tests/ui/toplevel_ref_arg.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::toplevel_ref_arg)] #![allow(clippy::uninlined_format_args, unused, clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/toplevel_ref_arg.stderr b/src/tools/clippy/tests/ui/toplevel_ref_arg.stderr index 407c2d9fc..2c27a3c8e 100644 --- a/src/tools/clippy/tests/ui/toplevel_ref_arg.stderr +++ b/src/tools/clippy/tests/ui/toplevel_ref_arg.stderr @@ -1,37 +1,38 @@ error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:15:9 + --> $DIR/toplevel_ref_arg.rs:14:9 | LL | let ref _x = 1; | ----^^^^^^----- help: try: `let _x = &1;` | = note: `-D clippy::toplevel-ref-arg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::toplevel_ref_arg)]` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:17:9 + --> $DIR/toplevel_ref_arg.rs:16:9 | LL | let ref _y: (&_, u8) = (&1, 2); | ----^^^^^^--------------------- help: try: `let _y: &(&_, u8) = &(&1, 2);` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:19:9 + --> $DIR/toplevel_ref_arg.rs:18:9 | LL | let ref _z = 1 + 2; | ----^^^^^^--------- help: try: `let _z = &(1 + 2);` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:21:9 + --> $DIR/toplevel_ref_arg.rs:20:9 | LL | let ref mut _z = 1 + 2; | ----^^^^^^^^^^--------- help: try: `let _z = &mut (1 + 2);` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:26:9 + --> $DIR/toplevel_ref_arg.rs:25:9 | LL | let ref _x = vec![1, 2, 3]; | ----^^^^^^----------------- help: try: `let _x = &vec![1, 2, 3];` error: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead - --> $DIR/toplevel_ref_arg.rs:36:17 + --> $DIR/toplevel_ref_arg.rs:35:17 | LL | inline!(let ref _y = 42;); | ----^^^^^^------ help: try: `let _y = &42;` diff --git a/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.rs b/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.rs index 464762af8..8aaf47b1b 100644 --- a/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.rs +++ b/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::toplevel_ref_arg)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.stderr b/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.stderr index 7307bd599..45123dd5e 100644 --- a/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.stderr +++ b/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.stderr @@ -5,6 +5,7 @@ LL | fn the_answer(ref mut x: u8) { | ^^^^^^^^^ | = note: `-D clippy::toplevel-ref-arg` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/trailing_empty_array.rs b/src/tools/clippy/tests/ui/trailing_empty_array.rs index 928475b5f..3d06c2621 100644 --- a/src/tools/clippy/tests/ui/trailing_empty_array.rs +++ b/src/tools/clippy/tests/ui/trailing_empty_array.rs @@ -3,33 +3,39 @@ // Do lint: struct RarelyUseful { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; 0], } struct OnlyField { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib first_and_last: [usize; 0], } struct GenericArrayType { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [T; 0], } #[must_use] struct OnlyAnotherAttribute { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; 0], } #[derive(Debug)] struct OnlyADeriveAttribute { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; 0], } const ZERO: usize = 0; struct ZeroSizedWithConst { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; ZERO], } @@ -39,6 +45,7 @@ const fn compute_zero() -> usize { (4 + 6) - (2 * 5) } struct ZeroSizedWithConstFunction { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; compute_zero()], } @@ -47,15 +54,19 @@ const fn compute_zero_from_arg(x: usize) -> usize { x - 1 } struct ZeroSizedWithConstFunction2 { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib field: i32, last: [usize; compute_zero_from_arg(1)], } struct ZeroSizedArrayWrapper([usize; 0]); +//~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib struct TupleStruct(i32, [usize; 0]); +//~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib struct LotsOfFields { + //~^ ERROR: trailing zero-sized array in a struct which is not marked with a `repr` attrib f1: u32, f2: u32, f3: u32, diff --git a/src/tools/clippy/tests/ui/trailing_empty_array.stderr b/src/tools/clippy/tests/ui/trailing_empty_array.stderr index 2e1484400..ef7fc24c3 100644 --- a/src/tools/clippy/tests/ui/trailing_empty_array.stderr +++ b/src/tools/clippy/tests/ui/trailing_empty_array.stderr @@ -2,6 +2,7 @@ error: trailing zero-sized array in a struct which is not marked with a `repr` a --> $DIR/trailing_empty_array.rs:5:1 | LL | / struct RarelyUseful { +LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -9,11 +10,13 @@ LL | | } | = help: consider annotating `RarelyUseful` with `#[repr(C)]` or another `repr` attribute = note: `-D clippy::trailing-empty-array` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::trailing_empty_array)]` error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:10:1 + --> $DIR/trailing_empty_array.rs:11:1 | LL | / struct OnlyField { +LL | | LL | | first_and_last: [usize; 0], LL | | } | |_^ @@ -21,9 +24,10 @@ LL | | } = help: consider annotating `OnlyField` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:14:1 + --> $DIR/trailing_empty_array.rs:16:1 | LL | / struct GenericArrayType { +LL | | LL | | field: i32, LL | | last: [T; 0], LL | | } @@ -32,9 +36,10 @@ LL | | } = help: consider annotating `GenericArrayType` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:20:1 + --> $DIR/trailing_empty_array.rs:23:1 | LL | / struct OnlyAnotherAttribute { +LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -43,9 +48,10 @@ LL | | } = help: consider annotating `OnlyAnotherAttribute` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:26:1 + --> $DIR/trailing_empty_array.rs:30:1 | LL | / struct OnlyADeriveAttribute { +LL | | LL | | field: i32, LL | | last: [usize; 0], LL | | } @@ -54,9 +60,10 @@ LL | | } = help: consider annotating `OnlyADeriveAttribute` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:32:1 + --> $DIR/trailing_empty_array.rs:37:1 | LL | / struct ZeroSizedWithConst { +LL | | LL | | field: i32, LL | | last: [usize; ZERO], LL | | } @@ -65,9 +72,10 @@ LL | | } = help: consider annotating `ZeroSizedWithConst` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:41:1 + --> $DIR/trailing_empty_array.rs:47:1 | LL | / struct ZeroSizedWithConstFunction { +LL | | LL | | field: i32, LL | | last: [usize; compute_zero()], LL | | } @@ -76,9 +84,10 @@ LL | | } = help: consider annotating `ZeroSizedWithConstFunction` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:49:1 + --> $DIR/trailing_empty_array.rs:56:1 | LL | / struct ZeroSizedWithConstFunction2 { +LL | | LL | | field: i32, LL | | last: [usize; compute_zero_from_arg(1)], LL | | } @@ -87,7 +96,7 @@ LL | | } = help: consider annotating `ZeroSizedWithConstFunction2` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:54:1 + --> $DIR/trailing_empty_array.rs:62:1 | LL | struct ZeroSizedArrayWrapper([usize; 0]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +104,7 @@ LL | struct ZeroSizedArrayWrapper([usize; 0]); = help: consider annotating `ZeroSizedArrayWrapper` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:56:1 + --> $DIR/trailing_empty_array.rs:65:1 | LL | struct TupleStruct(i32, [usize; 0]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -103,12 +112,12 @@ LL | struct TupleStruct(i32, [usize; 0]); = help: consider annotating `TupleStruct` with `#[repr(C)]` or another `repr` attribute error: trailing zero-sized array in a struct which is not marked with a `repr` attribute - --> $DIR/trailing_empty_array.rs:58:1 + --> $DIR/trailing_empty_array.rs:68:1 | LL | / struct LotsOfFields { +LL | | LL | | f1: u32, LL | | f2: u32, -LL | | f3: u32, ... | LL | | last: [usize; 0], LL | | } diff --git a/src/tools/clippy/tests/ui/trailing_zeros.fixed b/src/tools/clippy/tests/ui/trailing_zeros.fixed new file mode 100644 index 000000000..f7de976f1 --- /dev/null +++ b/src/tools/clippy/tests/ui/trailing_zeros.fixed @@ -0,0 +1,13 @@ +#![allow(unused_parens)] +#![warn(clippy::verbose_bit_mask)] + +fn main() { + let x: i32 = 42; + let _ = x.trailing_zeros() >= 4; + //~^ ERROR: bit mask could be simplified with a call to `trailing_zeros` + //~| NOTE: `-D clippy::verbose-bit-mask` implied by `-D warnings` + let _ = x.trailing_zeros() >= 5; + //~^ ERROR: bit mask could be simplified with a call to `trailing_zeros` + let _ = x & 0b1_1010 == 0; // do not lint + let _ = x & 1 == 0; // do not lint +} diff --git a/src/tools/clippy/tests/ui/trailing_zeros.rs b/src/tools/clippy/tests/ui/trailing_zeros.rs index fbdc977b7..a05b09233 100644 --- a/src/tools/clippy/tests/ui/trailing_zeros.rs +++ b/src/tools/clippy/tests/ui/trailing_zeros.rs @@ -3,8 +3,11 @@ fn main() { let x: i32 = 42; - let _ = (x & 0b1111 == 0); // suggest trailing_zeros - let _ = x & 0b1_1111 == 0; // suggest trailing_zeros + let _ = (x & 0b1111 == 0); + //~^ ERROR: bit mask could be simplified with a call to `trailing_zeros` + //~| NOTE: `-D clippy::verbose-bit-mask` implied by `-D warnings` + let _ = x & 0b1_1111 == 0; + //~^ ERROR: bit mask could be simplified with a call to `trailing_zeros` let _ = x & 0b1_1010 == 0; // do not lint let _ = x & 1 == 0; // do not lint } diff --git a/src/tools/clippy/tests/ui/trailing_zeros.stderr b/src/tools/clippy/tests/ui/trailing_zeros.stderr index 798551118..10924ad12 100644 --- a/src/tools/clippy/tests/ui/trailing_zeros.stderr +++ b/src/tools/clippy/tests/ui/trailing_zeros.stderr @@ -1,15 +1,16 @@ error: bit mask could be simplified with a call to `trailing_zeros` --> $DIR/trailing_zeros.rs:6:13 | -LL | let _ = (x & 0b1111 == 0); // suggest trailing_zeros +LL | let _ = (x & 0b1111 == 0); | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 4` | = note: `-D clippy::verbose-bit-mask` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::verbose_bit_mask)]` error: bit mask could be simplified with a call to `trailing_zeros` - --> $DIR/trailing_zeros.rs:7:13 + --> $DIR/trailing_zeros.rs:9:13 | -LL | let _ = x & 0b1_1111 == 0; // suggest trailing_zeros +LL | let _ = x & 0b1_1111 == 0; | ^^^^^^^^^^^^^^^^^ help: try: `x.trailing_zeros() >= 5` error: aborting due to 2 previous errors diff --git a/src/tools/clippy/tests/ui/trait_duplication_in_bounds.fixed b/src/tools/clippy/tests/ui/trait_duplication_in_bounds.fixed index fdac0e4cb..4fca29698 100644 --- a/src/tools/clippy/tests/ui/trait_duplication_in_bounds.fixed +++ b/src/tools/clippy/tests/ui/trait_duplication_in_bounds.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::trait_duplication_in_bounds)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/trait_duplication_in_bounds.rs b/src/tools/clippy/tests/ui/trait_duplication_in_bounds.rs index a0300da55..f67c8e35e 100644 --- a/src/tools/clippy/tests/ui/trait_duplication_in_bounds.rs +++ b/src/tools/clippy/tests/ui/trait_duplication_in_bounds.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::trait_duplication_in_bounds)] #![allow(unused)] diff --git a/src/tools/clippy/tests/ui/trait_duplication_in_bounds.stderr b/src/tools/clippy/tests/ui/trait_duplication_in_bounds.stderr index 539b6114c..61a45538b 100644 --- a/src/tools/clippy/tests/ui/trait_duplication_in_bounds.stderr +++ b/src/tools/clippy/tests/ui/trait_duplication_in_bounds.stderr @@ -1,59 +1,59 @@ error: these bounds contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:7:15 + --> $DIR/trait_duplication_in_bounds.rs:6:15 | LL | fn bad_foo(arg0: T, argo1: U) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` | note: the lint level is defined here - --> $DIR/trait_duplication_in_bounds.rs:2:9 + --> $DIR/trait_duplication_in_bounds.rs:1:9 | LL | #![deny(clippy::trait_duplication_in_bounds)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: these where clauses contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:13:8 + --> $DIR/trait_duplication_in_bounds.rs:12:8 | LL | T: Clone + Clone + Clone + Copy, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these bounds contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:41:26 + --> $DIR/trait_duplication_in_bounds.rs:40:26 | LL | trait BadSelfTraitBound: Clone + Clone + Clone { | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone` error: these where clauses contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:48:15 + --> $DIR/trait_duplication_in_bounds.rs:47:15 | LL | Self: Clone + Clone + Clone; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone` error: these bounds contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:62:24 + --> $DIR/trait_duplication_in_bounds.rs:61:24 | LL | trait BadTraitBound { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these where clauses contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:69:12 + --> $DIR/trait_duplication_in_bounds.rs:68:12 | LL | T: Clone + Clone + Clone + Copy, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these bounds contain repeated elements - --> $DIR/trait_duplication_in_bounds.rs:102:19 + --> $DIR/trait_duplication_in_bounds.rs:101: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:110:22 + --> $DIR/trait_duplication_in_bounds.rs:109: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:118:33 + --> $DIR/trait_duplication_in_bounds.rs:117:33 | LL | fn bad_trait_object(arg0: &(dyn Any + Send + Send)) { | ^^^^^^^^^^^^^^^^^ help: try: `Any + Send` diff --git a/src/tools/clippy/tests/ui/trait_duplication_in_bounds_unfixable.rs b/src/tools/clippy/tests/ui/trait_duplication_in_bounds_unfixable.rs index 5630a0345..effed3a26 100644 --- a/src/tools/clippy/tests/ui/trait_duplication_in_bounds_unfixable.rs +++ b/src/tools/clippy/tests/ui/trait_duplication_in_bounds_unfixable.rs @@ -4,6 +4,8 @@ use std::collections::BTreeMap; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; fn bad_foo(arg0: T, arg1: Z) +//~^ ERROR: this trait bound is already specified in the where clause +//~| ERROR: this trait bound is already specified in the where clause where T: Clone, T: Default, @@ -33,6 +35,7 @@ trait T: Default { fn f() where Self: Default; + //~^ ERROR: this trait bound is already specified in trait declaration } trait U: Default { @@ -47,15 +50,19 @@ trait ZZ: Default { fn f() where Self: Default + Clone; + //~^ ERROR: this trait bound is already specified in trait declaration } trait BadTrait: Default + Clone { fn f() where Self: Default + Clone; + //~^ ERROR: this trait bound is already specified in trait declaration + //~| ERROR: this trait bound is already specified in trait declaration fn g() where Self: Default; + //~^ ERROR: this trait bound is already specified in trait declaration fn h() where Self: Copy; @@ -91,6 +98,7 @@ trait FooIter: Iterator { fn bar() where Self: Iterator, + //~^ ERROR: this trait bound is already specified in trait declaration { } } diff --git a/src/tools/clippy/tests/ui/trait_duplication_in_bounds_unfixable.stderr b/src/tools/clippy/tests/ui/trait_duplication_in_bounds_unfixable.stderr index 4d56a9464..80dc7d8b6 100644 --- a/src/tools/clippy/tests/ui/trait_duplication_in_bounds_unfixable.stderr +++ b/src/tools/clippy/tests/ui/trait_duplication_in_bounds_unfixable.stderr @@ -20,7 +20,7 @@ LL | fn bad_foo(arg0: T, arg1: Z) = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:35:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:37:15 | LL | Self: Default; | ^^^^^^^ @@ -28,7 +28,7 @@ LL | Self: Default; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:49:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:52:15 | LL | Self: Default + Clone; | ^^^^^^^ @@ -36,7 +36,7 @@ LL | Self: Default + Clone; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:55:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:59:15 | LL | Self: Default + Clone; | ^^^^^^^ @@ -44,7 +44,7 @@ LL | Self: Default + Clone; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:55:25 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:59:25 | LL | Self: Default + Clone; | ^^^^^ @@ -52,7 +52,7 @@ LL | Self: Default + Clone; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:58:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:64:15 | LL | Self: Default; | ^^^^^^^ @@ -60,7 +60,7 @@ LL | Self: Default; = help: consider removing this trait bound error: this trait bound is already specified in trait declaration - --> $DIR/trait_duplication_in_bounds_unfixable.rs:93:15 + --> $DIR/trait_duplication_in_bounds_unfixable.rs:100:15 | LL | Self: Iterator, | ^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/transmute.rs b/src/tools/clippy/tests/ui/transmute.rs index 1cbacf0fe..32f6027e9 100644 --- a/src/tools/clippy/tests/ui/transmute.rs +++ b/src/tools/clippy/tests/ui/transmute.rs @@ -1,5 +1,5 @@ #![allow(dead_code, clippy::borrow_as_ptr, clippy::needless_lifetimes)] - +//@no-rustfix extern crate core; use std::mem::transmute as my_transmute; @@ -22,30 +22,41 @@ unsafe fn _generic<'a, T, U: 'a>(t: &'a T) { let _: &'a U = core::intrinsics::transmute(t); let _: *const T = core::intrinsics::transmute(t); + //~^ ERROR: transmute from a reference to a pointer + //~| NOTE: `-D clippy::useless-transmute` implied by `-D warnings` let _: *mut T = core::intrinsics::transmute(t); + //~^ ERROR: transmute from a reference to a pointer let _: *const U = core::intrinsics::transmute(t); + //~^ ERROR: transmute from a reference to a pointer } #[warn(clippy::useless_transmute)] fn useless() { unsafe { let _: Vec = core::intrinsics::transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: Vec = core::mem::transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: Vec = std::intrinsics::transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: Vec = std::mem::transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: Vec = my_transmute(my_vec()); + //~^ ERROR: transmute from a type (`std::vec::Vec`) to itself let _: *const usize = std::mem::transmute(5_isize); + //~^ ERROR: transmute from an integer to a pointer let _ = 5_isize as *const usize; let _: *const usize = std::mem::transmute(1 + 1usize); + //~^ ERROR: transmute from an integer to a pointer let _ = (1 + 1_usize) as *const usize; } @@ -77,19 +88,27 @@ fn crosspointer() { unsafe { let _: Usize = core::intrinsics::transmute(int_const_ptr); + //~^ ERROR: transmute from a type (`*const Usize`) to the type that it points to ( + //~| NOTE: `-D clippy::crosspointer-transmute` implied by `-D warnings` let _: Usize = core::intrinsics::transmute(int_mut_ptr); + //~^ ERROR: transmute from a type (`*mut Usize`) to the type that it points to (`U let _: *const Usize = core::intrinsics::transmute(my_int()); + //~^ ERROR: transmute from a type (`Usize`) to a pointer to that type (`*const Usi let _: *mut Usize = core::intrinsics::transmute(my_int()); + //~^ ERROR: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize } } #[warn(clippy::transmute_int_to_char)] fn int_to_char() { let _: char = unsafe { std::mem::transmute(0_u32) }; + //~^ ERROR: transmute from a `u32` to a `char` + //~| NOTE: `-D clippy::transmute-int-to-char` implied by `-D warnings` let _: char = unsafe { std::mem::transmute(0_i32) }; + //~^ ERROR: transmute from a `i32` to a `char` // These shouldn't warn const _: char = unsafe { std::mem::transmute(0_u32) }; @@ -99,15 +118,22 @@ fn int_to_char() { #[warn(clippy::transmute_int_to_bool)] fn int_to_bool() { let _: bool = unsafe { std::mem::transmute(0_u8) }; + //~^ ERROR: transmute from a `u8` to a `bool` + //~| NOTE: `-D clippy::transmute-int-to-bool` implied by `-D warnings` } #[warn(clippy::transmute_int_to_float)] mod int_to_float { fn test() { let _: f32 = unsafe { std::mem::transmute(0_u32) }; + //~^ ERROR: transmute from a `u32` to a `f32` + //~| NOTE: `-D clippy::transmute-int-to-float` implied by `-D warnings` let _: f32 = unsafe { std::mem::transmute(0_i32) }; + //~^ ERROR: transmute from a `i32` to a `f32` let _: f64 = unsafe { std::mem::transmute(0_u64) }; + //~^ ERROR: transmute from a `u64` to a `f64` let _: f64 = unsafe { std::mem::transmute(0_i64) }; + //~^ ERROR: transmute from a `i64` to a `f64` } mod issue_5747 { @@ -128,23 +154,38 @@ mod num_to_bytes { fn test() { unsafe { let _: [u8; 1] = std::mem::transmute(0u8); + //~^ ERROR: transmute from a `u8` to a `[u8; 1]` + //~| NOTE: `-D clippy::transmute-num-to-bytes` implied by `-D warnings` let _: [u8; 4] = std::mem::transmute(0u32); + //~^ ERROR: transmute from a `u32` to a `[u8; 4]` let _: [u8; 16] = std::mem::transmute(0u128); + //~^ ERROR: transmute from a `u128` to a `[u8; 16]` let _: [u8; 1] = std::mem::transmute(0i8); + //~^ ERROR: transmute from a `i8` to a `[u8; 1]` let _: [u8; 4] = std::mem::transmute(0i32); + //~^ ERROR: transmute from a `i32` to a `[u8; 4]` let _: [u8; 16] = std::mem::transmute(0i128); + //~^ ERROR: transmute from a `i128` to a `[u8; 16]` let _: [u8; 4] = std::mem::transmute(0.0f32); + //~^ ERROR: transmute from a `f32` to a `[u8; 4]` let _: [u8; 8] = std::mem::transmute(0.0f64); + //~^ ERROR: transmute from a `f64` to a `[u8; 8]` } } const fn test_const() { unsafe { let _: [u8; 1] = std::mem::transmute(0u8); + //~^ ERROR: transmute from a `u8` to a `[u8; 1]` let _: [u8; 4] = std::mem::transmute(0u32); + //~^ ERROR: transmute from a `u32` to a `[u8; 4]` let _: [u8; 16] = std::mem::transmute(0u128); + //~^ ERROR: transmute from a `u128` to a `[u8; 16]` let _: [u8; 1] = std::mem::transmute(0i8); + //~^ ERROR: transmute from a `i8` to a `[u8; 1]` let _: [u8; 4] = std::mem::transmute(0i32); + //~^ ERROR: transmute from a `i32` to a `[u8; 4]` let _: [u8; 16] = std::mem::transmute(0i128); + //~^ ERROR: transmute from a `i128` to a `[u8; 16]` let _: [u8; 4] = std::mem::transmute(0.0f32); let _: [u8; 8] = std::mem::transmute(0.0f64); } @@ -155,8 +196,12 @@ fn bytes_to_str(mb: &mut [u8]) { const B: &[u8] = b""; let _: &str = unsafe { std::mem::transmute(B) }; + //~^ ERROR: transmute from a `&[u8]` to a `&str` + //~| NOTE: `-D clippy::transmute-bytes-to-str` implied by `-D warnings` let _: &mut str = unsafe { std::mem::transmute(mb) }; + //~^ ERROR: transmute from a `&mut [u8]` to a `&mut str` const _: &str = unsafe { std::mem::transmute(B) }; + //~^ ERROR: transmute from a `&[u8]` to a `&str` } fn main() {} diff --git a/src/tools/clippy/tests/ui/transmute.stderr b/src/tools/clippy/tests/ui/transmute.stderr index 008b4a981..cdc733b54 100644 --- a/src/tools/clippy/tests/ui/transmute.stderr +++ b/src/tools/clippy/tests/ui/transmute.stderr @@ -5,237 +5,244 @@ LL | let _: *const T = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T` | = note: `-D clippy::useless-transmute` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::useless_transmute)]` error: transmute from a reference to a pointer - --> $DIR/transmute.rs:26:21 + --> $DIR/transmute.rs:28:21 | LL | let _: *mut T = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *mut T` error: transmute from a reference to a pointer - --> $DIR/transmute.rs:28:23 + --> $DIR/transmute.rs:31:23 | LL | let _: *const U = core::intrinsics::transmute(t); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `t as *const T as *const U` error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:34:27 + --> $DIR/transmute.rs:38:27 | LL | let _: Vec = core::intrinsics::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:36:27 + --> $DIR/transmute.rs:41:27 | LL | let _: Vec = core::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:38:27 + --> $DIR/transmute.rs:44:27 | LL | let _: Vec = std::intrinsics::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:40:27 + --> $DIR/transmute.rs:47:27 | LL | let _: Vec = std::mem::transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`std::vec::Vec`) to itself - --> $DIR/transmute.rs:42:27 + --> $DIR/transmute.rs:50:27 | LL | let _: Vec = my_transmute(my_vec()); | ^^^^^^^^^^^^^^^^^^^^^^ error: transmute from an integer to a pointer - --> $DIR/transmute.rs:44:31 + --> $DIR/transmute.rs:53:31 | LL | let _: *const usize = std::mem::transmute(5_isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `5_isize as *const usize` error: transmute from an integer to a pointer - --> $DIR/transmute.rs:48:31 + --> $DIR/transmute.rs:58:31 | LL | let _: *const usize = std::mem::transmute(1 + 1usize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(1 + 1usize) as *const usize` error: transmute from a type (`*const Usize`) to the type that it points to (`Usize`) - --> $DIR/transmute.rs:79:24 + --> $DIR/transmute.rs:90:24 | LL | let _: Usize = core::intrinsics::transmute(int_const_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::crosspointer-transmute` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::crosspointer_transmute)]` error: transmute from a type (`*mut Usize`) to the type that it points to (`Usize`) - --> $DIR/transmute.rs:81:24 + --> $DIR/transmute.rs:94:24 | LL | let _: Usize = core::intrinsics::transmute(int_mut_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*const Usize`) - --> $DIR/transmute.rs:83:31 + --> $DIR/transmute.rs:97:31 | LL | let _: *const Usize = core::intrinsics::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a type (`Usize`) to a pointer to that type (`*mut Usize`) - --> $DIR/transmute.rs:85:29 + --> $DIR/transmute.rs:100:29 | LL | let _: *mut Usize = core::intrinsics::transmute(my_int()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from a `u32` to a `char` - --> $DIR/transmute.rs:91:28 + --> $DIR/transmute.rs:107:28 | LL | let _: char = unsafe { std::mem::transmute(0_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_u32).unwrap()` | = note: `-D clippy::transmute-int-to-char` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_char)]` error: transmute from a `i32` to a `char` - --> $DIR/transmute.rs:92:28 + --> $DIR/transmute.rs:110:28 | LL | let _: char = unsafe { std::mem::transmute(0_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::char::from_u32(0_i32 as u32).unwrap()` error: transmute from a `u8` to a `bool` - --> $DIR/transmute.rs:101:28 + --> $DIR/transmute.rs:120:28 | LL | let _: bool = unsafe { std::mem::transmute(0_u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `0_u8 != 0` | = note: `-D clippy::transmute-int-to-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_bool)]` error: transmute from a `u32` to a `f32` - --> $DIR/transmute.rs:107:31 + --> $DIR/transmute.rs:128:31 | LL | let _: f32 = unsafe { std::mem::transmute(0_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_u32)` | = note: `-D clippy::transmute-int-to-float` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_float)]` error: transmute from a `i32` to a `f32` - --> $DIR/transmute.rs:108:31 + --> $DIR/transmute.rs:131:31 | LL | let _: f32 = unsafe { std::mem::transmute(0_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f32::from_bits(0_i32 as u32)` error: transmute from a `u64` to a `f64` - --> $DIR/transmute.rs:109:31 + --> $DIR/transmute.rs:133:31 | LL | let _: f64 = unsafe { std::mem::transmute(0_u64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_u64)` error: transmute from a `i64` to a `f64` - --> $DIR/transmute.rs:110:31 + --> $DIR/transmute.rs:135:31 | LL | let _: f64 = unsafe { std::mem::transmute(0_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f64::from_bits(0_i64 as u64)` error: transmute from a `u8` to a `[u8; 1]` - --> $DIR/transmute.rs:130:30 + --> $DIR/transmute.rs:156:30 | LL | let _: [u8; 1] = std::mem::transmute(0u8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u8.to_ne_bytes()` | = note: `-D clippy::transmute-num-to-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_num_to_bytes)]` error: transmute from a `u32` to a `[u8; 4]` - --> $DIR/transmute.rs:131:30 + --> $DIR/transmute.rs:159:30 | LL | let _: [u8; 4] = std::mem::transmute(0u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u32.to_ne_bytes()` error: transmute from a `u128` to a `[u8; 16]` - --> $DIR/transmute.rs:132:31 + --> $DIR/transmute.rs:161:31 | LL | let _: [u8; 16] = std::mem::transmute(0u128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u128.to_ne_bytes()` error: transmute from a `i8` to a `[u8; 1]` - --> $DIR/transmute.rs:133:30 + --> $DIR/transmute.rs:163:30 | LL | let _: [u8; 1] = std::mem::transmute(0i8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i8.to_ne_bytes()` error: transmute from a `i32` to a `[u8; 4]` - --> $DIR/transmute.rs:134:30 + --> $DIR/transmute.rs:165:30 | LL | let _: [u8; 4] = std::mem::transmute(0i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i32.to_ne_bytes()` error: transmute from a `i128` to a `[u8; 16]` - --> $DIR/transmute.rs:135:31 + --> $DIR/transmute.rs:167:31 | LL | let _: [u8; 16] = std::mem::transmute(0i128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i128.to_ne_bytes()` error: transmute from a `f32` to a `[u8; 4]` - --> $DIR/transmute.rs:136:30 + --> $DIR/transmute.rs:169:30 | LL | let _: [u8; 4] = std::mem::transmute(0.0f32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f32.to_ne_bytes()` error: transmute from a `f64` to a `[u8; 8]` - --> $DIR/transmute.rs:137:30 + --> $DIR/transmute.rs:171:30 | LL | let _: [u8; 8] = std::mem::transmute(0.0f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0.0f64.to_ne_bytes()` error: transmute from a `u8` to a `[u8; 1]` - --> $DIR/transmute.rs:142:30 + --> $DIR/transmute.rs:177:30 | LL | let _: [u8; 1] = std::mem::transmute(0u8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u8.to_ne_bytes()` error: transmute from a `u32` to a `[u8; 4]` - --> $DIR/transmute.rs:143:30 + --> $DIR/transmute.rs:179:30 | LL | let _: [u8; 4] = std::mem::transmute(0u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u32.to_ne_bytes()` error: transmute from a `u128` to a `[u8; 16]` - --> $DIR/transmute.rs:144:31 + --> $DIR/transmute.rs:181:31 | LL | let _: [u8; 16] = std::mem::transmute(0u128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0u128.to_ne_bytes()` error: transmute from a `i8` to a `[u8; 1]` - --> $DIR/transmute.rs:145:30 + --> $DIR/transmute.rs:183:30 | LL | let _: [u8; 1] = std::mem::transmute(0i8); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i8.to_ne_bytes()` error: transmute from a `i32` to a `[u8; 4]` - --> $DIR/transmute.rs:146:30 + --> $DIR/transmute.rs:185:30 | LL | let _: [u8; 4] = std::mem::transmute(0i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i32.to_ne_bytes()` error: transmute from a `i128` to a `[u8; 16]` - --> $DIR/transmute.rs:147:31 + --> $DIR/transmute.rs:187:31 | LL | let _: [u8; 16] = std::mem::transmute(0i128); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `to_ne_bytes()`: `0i128.to_ne_bytes()` error: transmute from a `&[u8]` to a `&str` - --> $DIR/transmute.rs:157:28 + --> $DIR/transmute.rs:198:28 | LL | let _: &str = unsafe { std::mem::transmute(B) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8(B).unwrap()` | = note: `-D clippy::transmute-bytes-to-str` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_bytes_to_str)]` error: transmute from a `&mut [u8]` to a `&mut str` - --> $DIR/transmute.rs:158:32 + --> $DIR/transmute.rs:201:32 | LL | let _: &mut str = unsafe { std::mem::transmute(mb) }; | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_mut(mb).unwrap()` error: transmute from a `&[u8]` to a `&str` - --> $DIR/transmute.rs:159:30 + --> $DIR/transmute.rs:203:30 | LL | const _: &str = unsafe { std::mem::transmute(B) }; | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::str::from_utf8_unchecked(B)` diff --git a/src/tools/clippy/tests/ui/transmute_32bit.stderr b/src/tools/clippy/tests/ui/transmute_32bit.stderr index 75ddca60d..baa819e30 100644 --- a/src/tools/clippy/tests/ui/transmute_32bit.stderr +++ b/src/tools/clippy/tests/ui/transmute_32bit.stderr @@ -1,39 +1,29 @@ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types +error: transmute from a `f32` to a pointer --> $DIR/transmute_32bit.rs:6:31 | LL | let _: *const usize = std::mem::transmute(6.0f32); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: source type: `f32` (32 bits) - = note: target type: `*const usize` (64 bits) + = note: `-D clippy::wrong-transmute` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wrong_transmute)]` -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types +error: transmute from a `f32` to a pointer --> $DIR/transmute_32bit.rs:8:29 | LL | let _: *mut usize = std::mem::transmute(6.0f32); - | ^^^^^^^^^^^^^^^^^^^ - | - = note: source type: `f32` (32 bits) - = note: target type: `*mut usize` (64 bits) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types +error: transmute from a `char` to a pointer --> $DIR/transmute_32bit.rs:10:31 | LL | let _: *const usize = std::mem::transmute('x'); - | ^^^^^^^^^^^^^^^^^^^ - | - = note: source type: `char` (32 bits) - = note: target type: `*const usize` (64 bits) + | ^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0512]: cannot transmute between types of different sizes, or dependently-sized types +error: transmute from a `char` to a pointer --> $DIR/transmute_32bit.rs:12:29 | LL | let _: *mut usize = std::mem::transmute('x'); - | ^^^^^^^^^^^^^^^^^^^ - | - = note: source type: `char` (32 bits) - = note: target type: `*mut usize` (64 bits) + | ^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0512`. diff --git a/src/tools/clippy/tests/ui/transmute_64bit.rs b/src/tools/clippy/tests/ui/transmute_64bit.rs index ceecf9b27..767cc503a 100644 --- a/src/tools/clippy/tests/ui/transmute_64bit.rs +++ b/src/tools/clippy/tests/ui/transmute_64bit.rs @@ -4,7 +4,10 @@ fn main() { unsafe { let _: *const usize = std::mem::transmute(6.0f64); + //~^ ERROR: transmute from a `f64` to a pointer + //~| NOTE: `-D clippy::wrong-transmute` implied by `-D warnings` let _: *mut usize = std::mem::transmute(6.0f64); + //~^ ERROR: transmute from a `f64` to a pointer } } diff --git a/src/tools/clippy/tests/ui/transmute_64bit.stderr b/src/tools/clippy/tests/ui/transmute_64bit.stderr index d1854c009..a30480eb7 100644 --- a/src/tools/clippy/tests/ui/transmute_64bit.stderr +++ b/src/tools/clippy/tests/ui/transmute_64bit.stderr @@ -5,9 +5,10 @@ LL | let _: *const usize = std::mem::transmute(6.0f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::wrong-transmute` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wrong_transmute)]` error: transmute from a `f64` to a pointer - --> $DIR/transmute_64bit.rs:8:29 + --> $DIR/transmute_64bit.rs:10:29 | LL | let _: *mut usize = std::mem::transmute(6.0f64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/transmute_collection.rs b/src/tools/clippy/tests/ui/transmute_collection.rs index 5a431bee0..8bf454573 100644 --- a/src/tools/clippy/tests/ui/transmute_collection.rs +++ b/src/tools/clippy/tests/ui/transmute_collection.rs @@ -7,42 +7,61 @@ fn main() { unsafe { // wrong size let _ = transmute::<_, Vec>(vec![0u8]); + //~^ ERROR: transmute from `std::vec::Vec` to `std::vec::Vec` with mismat + //~| NOTE: `-D clippy::unsound-collection-transmute` implied by `-D warnings` // wrong layout let _ = transmute::<_, Vec<[u8; 4]>>(vec![1234u32]); + //~^ ERROR: transmute from `std::vec::Vec` to `std::vec::Vec<[u8; 4]>` with m // wrong size let _ = transmute::<_, VecDeque>(VecDeque::::new()); + //~^ ERROR: transmute from `std::collections::VecDeque` to `std::collections:: // wrong layout let _ = transmute::<_, VecDeque>(VecDeque::<[u8; 4]>::new()); + //~^ ERROR: transmute from `std::collections::VecDeque<[u8; 4]>` to `std::collecti // wrong size let _ = transmute::<_, BinaryHeap>(BinaryHeap::::new()); + //~^ ERROR: transmute from `std::collections::BinaryHeap` to `std::collections // wrong layout let _ = transmute::<_, BinaryHeap>(BinaryHeap::<[u8; 4]>::new()); + //~^ ERROR: transmute from `std::collections::BinaryHeap<[u8; 4]>` to `std::collec // wrong size let _ = transmute::<_, BTreeSet>(BTreeSet::::new()); + //~^ ERROR: transmute from `std::collections::BTreeSet` to `std::collections:: // wrong layout let _ = transmute::<_, BTreeSet>(BTreeSet::<[u8; 4]>::new()); + //~^ ERROR: transmute from `std::collections::BTreeSet<[u8; 4]>` to `std::collecti // wrong size let _ = transmute::<_, HashSet>(HashSet::::new()); + //~^ ERROR: transmute from `std::collections::HashSet` to `std::collections::H // wrong layout let _ = transmute::<_, HashSet>(HashSet::<[u8; 4]>::new()); + //~^ ERROR: transmute from `std::collections::HashSet<[u8; 4]>` to `std::collectio // wrong size let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); + //~^ ERROR: transmute from `std::collections::BTreeMap` to `std::collectio let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); + //~^ ERROR: transmute from `std::collections::BTreeMap` to `std::collect // wrong layout let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); + //~^ ERROR: transmute from `std::collections::BTreeMap` to `std::coll let _ = transmute::<_, BTreeMap>(BTreeMap::<[u8; 4], u32>::new()); + //~^ ERROR: transmute from `std::collections::BTreeMap<[u8; 4], u32>` to `std::col // wrong size let _ = transmute::<_, HashMap>(HashMap::::new()); + //~^ ERROR: transmute from `std::collections::HashMap` to `std::collection let _ = transmute::<_, HashMap>(HashMap::::new()); + //~^ ERROR: transmute from `std::collections::HashMap` to `std::collecti // wrong layout let _ = transmute::<_, HashMap>(HashMap::::new()); + //~^ ERROR: transmute from `std::collections::HashMap` to `std::colle let _ = transmute::<_, HashMap>(HashMap::<[u8; 4], u32>::new()); + //~^ ERROR: transmute from `std::collections::HashMap<[u8; 4], u32>` to `std::coll let _ = transmute::<_, Vec>(Vec::>::new()); let _ = transmute::<_, Vec<*mut u32>>(Vec::>::new()); diff --git a/src/tools/clippy/tests/ui/transmute_collection.stderr b/src/tools/clippy/tests/ui/transmute_collection.stderr index ebc05c402..2163142ee 100644 --- a/src/tools/clippy/tests/ui/transmute_collection.stderr +++ b/src/tools/clippy/tests/ui/transmute_collection.stderr @@ -5,105 +5,106 @@ LL | let _ = transmute::<_, Vec>(vec![0u8]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unsound-collection-transmute` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unsound_collection_transmute)]` error: transmute from `std::vec::Vec` to `std::vec::Vec<[u8; 4]>` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:11:17 + --> $DIR/transmute_collection.rs:13:17 | LL | let _ = transmute::<_, Vec<[u8; 4]>>(vec![1234u32]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::VecDeque` to `std::collections::VecDeque` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:14:17 + --> $DIR/transmute_collection.rs:17:17 | LL | let _ = transmute::<_, VecDeque>(VecDeque::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::VecDeque<[u8; 4]>` to `std::collections::VecDeque` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:16:17 + --> $DIR/transmute_collection.rs:20:17 | LL | let _ = transmute::<_, VecDeque>(VecDeque::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BinaryHeap` to `std::collections::BinaryHeap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:19:17 + --> $DIR/transmute_collection.rs:24:17 | LL | let _ = transmute::<_, BinaryHeap>(BinaryHeap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BinaryHeap<[u8; 4]>` to `std::collections::BinaryHeap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:21:17 + --> $DIR/transmute_collection.rs:27:17 | LL | let _ = transmute::<_, BinaryHeap>(BinaryHeap::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeSet` to `std::collections::BTreeSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:24:17 + --> $DIR/transmute_collection.rs:31:17 | LL | let _ = transmute::<_, BTreeSet>(BTreeSet::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeSet<[u8; 4]>` to `std::collections::BTreeSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:26:17 + --> $DIR/transmute_collection.rs:34:17 | LL | let _ = transmute::<_, BTreeSet>(BTreeSet::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashSet` to `std::collections::HashSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:29:17 + --> $DIR/transmute_collection.rs:38:17 | LL | let _ = transmute::<_, HashSet>(HashSet::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashSet<[u8; 4]>` to `std::collections::HashSet` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:31:17 + --> $DIR/transmute_collection.rs:41:17 | LL | let _ = transmute::<_, HashSet>(HashSet::<[u8; 4]>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:34:17 + --> $DIR/transmute_collection.rs:45:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:35:17 + --> $DIR/transmute_collection.rs:47:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:37:17 + --> $DIR/transmute_collection.rs:50:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::BTreeMap<[u8; 4], u32>` to `std::collections::BTreeMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:38:17 + --> $DIR/transmute_collection.rs:52:17 | LL | let _ = transmute::<_, BTreeMap>(BTreeMap::<[u8; 4], u32>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:41:17 + --> $DIR/transmute_collection.rs:56:17 | LL | let _ = transmute::<_, HashMap>(HashMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:42:17 + --> $DIR/transmute_collection.rs:58:17 | LL | let _ = transmute::<_, HashMap>(HashMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:44:17 + --> $DIR/transmute_collection.rs:61:17 | LL | let _ = transmute::<_, HashMap>(HashMap::::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `std::collections::HashMap<[u8; 4], u32>` to `std::collections::HashMap` with mismatched layout is unsound - --> $DIR/transmute_collection.rs:45:17 + --> $DIR/transmute_collection.rs:63:17 | LL | let _ = transmute::<_, HashMap>(HashMap::<[u8; 4], u32>::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/transmute_float_to_int.fixed b/src/tools/clippy/tests/ui/transmute_float_to_int.fixed new file mode 100644 index 000000000..cef0bcfa6 --- /dev/null +++ b/src/tools/clippy/tests/ui/transmute_float_to_int.fixed @@ -0,0 +1,32 @@ +#![warn(clippy::transmute_float_to_int)] + +fn float_to_int() { + let _: u32 = unsafe { 1f32.to_bits() }; + //~^ ERROR: transmute from a `f32` to a `u32` + //~| NOTE: `-D clippy::transmute-float-to-int` implied by `-D warnings` + let _: i32 = unsafe { 1f32.to_bits() as i32 }; + //~^ ERROR: transmute from a `f32` to a `i32` + let _: u64 = unsafe { 1f64.to_bits() }; + //~^ ERROR: transmute from a `f64` to a `u64` + let _: i64 = unsafe { 1f64.to_bits() as i64 }; + //~^ ERROR: transmute from a `f64` to a `i64` + let _: u64 = unsafe { 1.0f64.to_bits() }; + //~^ ERROR: transmute from a `f64` to a `u64` + let _: u64 = unsafe { (-1.0f64).to_bits() }; + //~^ ERROR: transmute from a `f64` to a `u64` +} + +mod issue_5747 { + const VALUE32: i32 = unsafe { std::mem::transmute(1f32) }; + const VALUE64: u64 = unsafe { std::mem::transmute(1f64) }; + + const fn to_bits_32(v: f32) -> u32 { + unsafe { std::mem::transmute(v) } + } + + const fn to_bits_64(v: f64) -> i64 { + unsafe { std::mem::transmute(v) } + } +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/transmute_float_to_int.rs b/src/tools/clippy/tests/ui/transmute_float_to_int.rs index 806b2d77d..3d95bec2a 100644 --- a/src/tools/clippy/tests/ui/transmute_float_to_int.rs +++ b/src/tools/clippy/tests/ui/transmute_float_to_int.rs @@ -2,11 +2,18 @@ fn float_to_int() { let _: u32 = unsafe { std::mem::transmute(1f32) }; + //~^ ERROR: transmute from a `f32` to a `u32` + //~| NOTE: `-D clippy::transmute-float-to-int` implied by `-D warnings` let _: i32 = unsafe { std::mem::transmute(1f32) }; + //~^ ERROR: transmute from a `f32` to a `i32` let _: u64 = unsafe { std::mem::transmute(1f64) }; + //~^ ERROR: transmute from a `f64` to a `u64` let _: i64 = unsafe { std::mem::transmute(1f64) }; + //~^ ERROR: transmute from a `f64` to a `i64` let _: u64 = unsafe { std::mem::transmute(1.0) }; + //~^ ERROR: transmute from a `f64` to a `u64` let _: u64 = unsafe { std::mem::transmute(-1.0) }; + //~^ ERROR: transmute from a `f64` to a `u64` } mod issue_5747 { diff --git a/src/tools/clippy/tests/ui/transmute_float_to_int.stderr b/src/tools/clippy/tests/ui/transmute_float_to_int.stderr index eb786bb39..1895120c0 100644 --- a/src/tools/clippy/tests/ui/transmute_float_to_int.stderr +++ b/src/tools/clippy/tests/ui/transmute_float_to_int.stderr @@ -5,33 +5,34 @@ LL | let _: u32 = unsafe { std::mem::transmute(1f32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits()` | = note: `-D clippy::transmute-float-to-int` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_float_to_int)]` error: transmute from a `f32` to a `i32` - --> $DIR/transmute_float_to_int.rs:5:27 + --> $DIR/transmute_float_to_int.rs:7:27 | LL | let _: i32 = unsafe { std::mem::transmute(1f32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f32.to_bits() as i32` error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:6:27 + --> $DIR/transmute_float_to_int.rs:9:27 | LL | let _: u64 = unsafe { std::mem::transmute(1f64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits()` error: transmute from a `f64` to a `i64` - --> $DIR/transmute_float_to_int.rs:7:27 + --> $DIR/transmute_float_to_int.rs:11:27 | LL | let _: i64 = unsafe { std::mem::transmute(1f64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1f64.to_bits() as i64` error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:8:27 + --> $DIR/transmute_float_to_int.rs:13:27 | LL | let _: u64 = unsafe { std::mem::transmute(1.0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.0f64.to_bits()` error: transmute from a `f64` to a `u64` - --> $DIR/transmute_float_to_int.rs:9:27 + --> $DIR/transmute_float_to_int.rs:15:27 | LL | let _: u64 = unsafe { std::mem::transmute(-1.0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-1.0f64).to_bits()` diff --git a/src/tools/clippy/tests/ui/transmute_int_to_non_zero.fixed b/src/tools/clippy/tests/ui/transmute_int_to_non_zero.fixed new file mode 100644 index 000000000..866c0bbf1 --- /dev/null +++ b/src/tools/clippy/tests/ui/transmute_int_to_non_zero.fixed @@ -0,0 +1,52 @@ +#![warn(clippy::transmute_int_to_non_zero)] + +use core::num::*; + +fn main() { + let int_u8: u8 = 1; + let int_u16: u16 = 1; + let int_u32: u32 = 1; + let int_u64: u64 = 1; + let int_u128: u128 = 1; + + let int_i8: i8 = 1; + let int_i16: i16 = 1; + let int_i32: i32 = 1; + let int_i64: i64 = 1; + let int_i128: i128 = 1; + + let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) }; + //~^ ERROR: transmute from a `u8` to a `NonZeroU8` + //~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` + let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) }; + //~^ ERROR: transmute from a `u16` to a `NonZeroU16` + let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) }; + //~^ ERROR: transmute from a `u32` to a `NonZeroU32` + let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) }; + //~^ ERROR: transmute from a `u64` to a `NonZeroU64` + let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) }; + //~^ ERROR: transmute from a `u128` to a `NonZeroU128` + + let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) }; + //~^ ERROR: transmute from a `i8` to a `NonZeroI8` + let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) }; + //~^ ERROR: transmute from a `i16` to a `NonZeroI16` + let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) }; + //~^ ERROR: transmute from a `i32` to a `NonZeroI32` + let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) }; + //~^ ERROR: transmute from a `i64` to a `NonZeroI64` + let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) }; + //~^ ERROR: transmute from a `i128` to a `NonZeroI128` + + let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) }; + let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) }; + let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) }; + let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) }; + let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) }; + + let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) }; + let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) }; + let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) }; + let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) }; + let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) }; +} diff --git a/src/tools/clippy/tests/ui/transmute_int_to_non_zero.rs b/src/tools/clippy/tests/ui/transmute_int_to_non_zero.rs index a38406782..803c4945c 100644 --- a/src/tools/clippy/tests/ui/transmute_int_to_non_zero.rs +++ b/src/tools/clippy/tests/ui/transmute_int_to_non_zero.rs @@ -16,16 +16,27 @@ fn main() { let int_i128: i128 = 1; let _: NonZeroU8 = unsafe { std::mem::transmute(int_u8) }; + //~^ ERROR: transmute from a `u8` to a `NonZeroU8` + //~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` let _: NonZeroU16 = unsafe { std::mem::transmute(int_u16) }; + //~^ ERROR: transmute from a `u16` to a `NonZeroU16` let _: NonZeroU32 = unsafe { std::mem::transmute(int_u32) }; + //~^ ERROR: transmute from a `u32` to a `NonZeroU32` let _: NonZeroU64 = unsafe { std::mem::transmute(int_u64) }; + //~^ ERROR: transmute from a `u64` to a `NonZeroU64` let _: NonZeroU128 = unsafe { std::mem::transmute(int_u128) }; + //~^ ERROR: transmute from a `u128` to a `NonZeroU128` let _: NonZeroI8 = unsafe { std::mem::transmute(int_i8) }; + //~^ ERROR: transmute from a `i8` to a `NonZeroI8` let _: NonZeroI16 = unsafe { std::mem::transmute(int_i16) }; + //~^ ERROR: transmute from a `i16` to a `NonZeroI16` let _: NonZeroI32 = unsafe { std::mem::transmute(int_i32) }; + //~^ ERROR: transmute from a `i32` to a `NonZeroI32` let _: NonZeroI64 = unsafe { std::mem::transmute(int_i64) }; + //~^ ERROR: transmute from a `i64` to a `NonZeroI64` let _: NonZeroI128 = unsafe { std::mem::transmute(int_i128) }; + //~^ ERROR: transmute from a `i128` to a `NonZeroI128` let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) }; let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) }; diff --git a/src/tools/clippy/tests/ui/transmute_int_to_non_zero.stderr b/src/tools/clippy/tests/ui/transmute_int_to_non_zero.stderr index 33f8ce79e..b79a80c32 100644 --- a/src/tools/clippy/tests/ui/transmute_int_to_non_zero.stderr +++ b/src/tools/clippy/tests/ui/transmute_int_to_non_zero.stderr @@ -5,57 +5,58 @@ LL | let _: NonZeroU8 = unsafe { std::mem::transmute(int_u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU8::new_unchecked(int_u8)` | = note: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_non_zero)]` error: transmute from a `u16` to a `NonZeroU16` - --> $DIR/transmute_int_to_non_zero.rs:19:34 + --> $DIR/transmute_int_to_non_zero.rs:21:34 | LL | let _: NonZeroU16 = unsafe { std::mem::transmute(int_u16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU16::new_unchecked(int_u16)` error: transmute from a `u32` to a `NonZeroU32` - --> $DIR/transmute_int_to_non_zero.rs:20:34 + --> $DIR/transmute_int_to_non_zero.rs:23:34 | LL | let _: NonZeroU32 = unsafe { std::mem::transmute(int_u32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU32::new_unchecked(int_u32)` error: transmute from a `u64` to a `NonZeroU64` - --> $DIR/transmute_int_to_non_zero.rs:21:34 + --> $DIR/transmute_int_to_non_zero.rs:25:34 | LL | let _: NonZeroU64 = unsafe { std::mem::transmute(int_u64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU64::new_unchecked(int_u64)` error: transmute from a `u128` to a `NonZeroU128` - --> $DIR/transmute_int_to_non_zero.rs:22:35 + --> $DIR/transmute_int_to_non_zero.rs:27:35 | LL | let _: NonZeroU128 = unsafe { std::mem::transmute(int_u128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU128::new_unchecked(int_u128)` error: transmute from a `i8` to a `NonZeroI8` - --> $DIR/transmute_int_to_non_zero.rs:24:33 + --> $DIR/transmute_int_to_non_zero.rs:30:33 | LL | let _: NonZeroI8 = unsafe { std::mem::transmute(int_i8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI8::new_unchecked(int_i8)` error: transmute from a `i16` to a `NonZeroI16` - --> $DIR/transmute_int_to_non_zero.rs:25:34 + --> $DIR/transmute_int_to_non_zero.rs:32:34 | LL | let _: NonZeroI16 = unsafe { std::mem::transmute(int_i16) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI16::new_unchecked(int_i16)` error: transmute from a `i32` to a `NonZeroI32` - --> $DIR/transmute_int_to_non_zero.rs:26:34 + --> $DIR/transmute_int_to_non_zero.rs:34:34 | LL | let _: NonZeroI32 = unsafe { std::mem::transmute(int_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI32::new_unchecked(int_i32)` error: transmute from a `i64` to a `NonZeroI64` - --> $DIR/transmute_int_to_non_zero.rs:27:34 + --> $DIR/transmute_int_to_non_zero.rs:36:34 | LL | let _: NonZeroI64 = unsafe { std::mem::transmute(int_i64) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI64::new_unchecked(int_i64)` error: transmute from a `i128` to a `NonZeroI128` - --> $DIR/transmute_int_to_non_zero.rs:28:35 + --> $DIR/transmute_int_to_non_zero.rs:38:35 | LL | let _: NonZeroI128 = unsafe { std::mem::transmute(int_i128) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI128::new_unchecked(int_i128)` diff --git a/src/tools/clippy/tests/ui/transmute_null_to_fn.rs b/src/tools/clippy/tests/ui/transmute_null_to_fn.rs index b3ea3d903..b07851e86 100644 --- a/src/tools/clippy/tests/ui/transmute_null_to_fn.rs +++ b/src/tools/clippy/tests/ui/transmute_null_to_fn.rs @@ -6,7 +6,9 @@ fn one_liners() { unsafe { let _: fn() = std::mem::transmute(0 as *const ()); + //~^ ERROR: transmuting a known null pointer into a function pointer let _: fn() = std::mem::transmute(std::ptr::null::<()>()); + //~^ ERROR: transmuting a known null pointer into a function pointer } } @@ -17,11 +19,23 @@ fn transmute_const() { unsafe { // Should raise a lint. let _: fn() = std::mem::transmute(ZPTR); + //~^ ERROR: transmuting a known null pointer into a function pointer // Should NOT raise a lint. let _: fn() = std::mem::transmute(NOT_ZPTR); } } +fn issue_11485() { + unsafe { + let _: fn() = std::mem::transmute(0 as *const u8 as *const ()); + //~^ ERROR: transmuting a known null pointer into a function pointer + let _: fn() = std::mem::transmute(std::ptr::null::<()>() as *const u8); + //~^ ERROR: transmuting a known null pointer into a function pointer + let _: fn() = std::mem::transmute(ZPTR as *const u8); + //~^ ERROR: transmuting a known null pointer into a function pointer + } +} + fn main() { one_liners(); transmute_const(); diff --git a/src/tools/clippy/tests/ui/transmute_null_to_fn.stderr b/src/tools/clippy/tests/ui/transmute_null_to_fn.stderr index f0c65497d..9073080cb 100644 --- a/src/tools/clippy/tests/ui/transmute_null_to_fn.stderr +++ b/src/tools/clippy/tests/ui/transmute_null_to_fn.stderr @@ -6,9 +6,10 @@ LL | let _: fn() = std::mem::transmute(0 as *const ()); | = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value = note: `-D clippy::transmute-null-to-fn` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_null_to_fn)]` error: transmuting a known null pointer into a function pointer - --> $DIR/transmute_null_to_fn.rs:9:23 + --> $DIR/transmute_null_to_fn.rs:10:23 | LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior @@ -16,12 +17,36 @@ LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>()); = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value error: transmuting a known null pointer into a function pointer - --> $DIR/transmute_null_to_fn.rs:19:23 + --> $DIR/transmute_null_to_fn.rs:21:23 | LL | let _: fn() = std::mem::transmute(ZPTR); | ^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior | = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value -error: aborting due to 3 previous errors +error: transmuting a known null pointer into a function pointer + --> $DIR/transmute_null_to_fn.rs:30:23 + | +LL | let _: fn() = std::mem::transmute(0 as *const u8 as *const ()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior + | + = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value + +error: transmuting a known null pointer into a function pointer + --> $DIR/transmute_null_to_fn.rs:32:23 + | +LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>() as *const u8); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior + | + = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value + +error: transmuting a known null pointer into a function pointer + --> $DIR/transmute_null_to_fn.rs:34:23 + | +LL | let _: fn() = std::mem::transmute(ZPTR as *const u8); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior + | + = help: try wrapping your function pointer type in `Option` instead, and using `None` as a null pointer value + +error: aborting due to 6 previous errors diff --git a/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.fixed b/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.fixed new file mode 100644 index 000000000..19abced98 --- /dev/null +++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.fixed @@ -0,0 +1,70 @@ +#![warn(clippy::transmute_ptr_to_ptr)] +#![allow(clippy::borrow_as_ptr)] + +// Make sure we can modify lifetimes, which is one of the recommended uses +// of transmute + +// Make sure we can do static lifetime transmutes +unsafe fn transmute_lifetime_to_static<'a, T>(t: &'a T) -> &'static T { + std::mem::transmute::<&'a T, &'static T>(t) +} + +// Make sure we can do non-static lifetime transmutes +unsafe fn transmute_lifetime<'a, 'b, T>(t: &'a T, u: &'b T) -> &'b T { + std::mem::transmute::<&'a T, &'b T>(t) +} + +struct LifetimeParam<'a> { + s: &'a str, +} + +struct GenericParam { + t: T, +} + +fn transmute_ptr_to_ptr() { + let ptr = &1u32 as *const u32; + let mut_ptr = &mut 1u32 as *mut u32; + unsafe { + // pointer-to-pointer transmutes; bad + let _: *const f32 = ptr as *const f32; + //~^ ERROR: transmute from a pointer to a pointer + //~| NOTE: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` + let _: *mut f32 = mut_ptr as *mut f32; + //~^ ERROR: transmute from a pointer to a pointer + // ref-ref transmutes; bad + let _: &f32 = &*(&1u32 as *const u32 as *const f32); + //~^ ERROR: transmute from a reference to a reference + let _: &f64 = &*(&1f32 as *const f32 as *const f64); + //~^ ERROR: transmute from a reference to a reference + //:^ this test is here because both f32 and f64 are the same TypeVariant, but they are not + // the same type + let _: &mut f32 = &mut *(&mut 1u32 as *mut u32 as *mut f32); + //~^ ERROR: transmute from a reference to a reference + let _: &GenericParam = &*(&GenericParam { t: 1u32 } as *const GenericParam as *const GenericParam); + //~^ ERROR: transmute from a reference to a reference + } + + // these are recommendations for solving the above; if these lint we need to update + // those suggestions + let _ = ptr as *const f32; + let _ = mut_ptr as *mut f32; + let _ = unsafe { &*(&1u32 as *const u32 as *const f32) }; + let _ = unsafe { &mut *(&mut 1u32 as *mut u32 as *mut f32) }; + + // transmute internal lifetimes, should not lint + let s = "hello world".to_owned(); + let lp = LifetimeParam { s: &s }; + let _: &LifetimeParam<'static> = unsafe { std::mem::transmute(&lp) }; + let _: &GenericParam<&LifetimeParam<'static>> = unsafe { std::mem::transmute(&GenericParam { t: &lp }) }; +} + +// dereferencing raw pointers in const contexts, should not lint as it's unstable (issue 5959) +const _: &() = { + struct Zst; + let zst = &Zst; + + unsafe { std::mem::transmute::<&'static Zst, &'static ()>(zst) } +}; + +fn main() {} diff --git a/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs b/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs index 61a6c98ed..abba2b8e5 100644 --- a/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs +++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs @@ -28,14 +28,21 @@ fn transmute_ptr_to_ptr() { unsafe { // pointer-to-pointer transmutes; bad let _: *const f32 = std::mem::transmute(ptr); + //~^ ERROR: transmute from a pointer to a pointer + //~| NOTE: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` let _: *mut f32 = std::mem::transmute(mut_ptr); + //~^ ERROR: transmute from a pointer to a pointer // ref-ref transmutes; bad let _: &f32 = std::mem::transmute(&1u32); + //~^ ERROR: transmute from a reference to a reference let _: &f64 = std::mem::transmute(&1f32); + //~^ ERROR: transmute from a reference to a reference //:^ this test is here because both f32 and f64 are the same TypeVariant, but they are not // the same type let _: &mut f32 = std::mem::transmute(&mut 1u32); + //~^ ERROR: transmute from a reference to a reference let _: &GenericParam = std::mem::transmute(&GenericParam { t: 1u32 }); + //~^ ERROR: transmute from a reference to a reference } // these are recommendations for solving the above; if these lint we need to update diff --git a/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.stderr b/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.stderr index 49a8a3347..564339c06 100644 --- a/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.stderr +++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.stderr @@ -5,33 +5,34 @@ LL | let _: *const f32 = std::mem::transmute(ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr as *const f32` | = note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ptr)]` error: transmute from a pointer to a pointer - --> $DIR/transmute_ptr_to_ptr.rs:31:27 + --> $DIR/transmute_ptr_to_ptr.rs:33:27 | LL | let _: *mut f32 = std::mem::transmute(mut_ptr); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `mut_ptr as *mut f32` error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:33:23 + --> $DIR/transmute_ptr_to_ptr.rs:36:23 | LL | let _: &f32 = std::mem::transmute(&1u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1u32 as *const u32 as *const f32)` error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:34:23 + --> $DIR/transmute_ptr_to_ptr.rs:38:23 | LL | let _: &f64 = std::mem::transmute(&1f32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1f32 as *const f32 as *const f64)` error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:37:27 + --> $DIR/transmute_ptr_to_ptr.rs:42:27 | LL | let _: &mut f32 = std::mem::transmute(&mut 1u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(&mut 1u32 as *mut u32 as *mut f32)` error: transmute from a reference to a reference - --> $DIR/transmute_ptr_to_ptr.rs:38:37 + --> $DIR/transmute_ptr_to_ptr.rs:44:37 | LL | let _: &GenericParam = std::mem::transmute(&GenericParam { t: 1u32 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&GenericParam { t: 1u32 } as *const GenericParam as *const GenericParam)` diff --git a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed index 215f0ac18..acec14ccb 100644 --- a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed +++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::transmute_ptr_to_ref)] #![allow(clippy::match_single_binding, clippy::unnecessary_cast)] diff --git a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs index 3528e1379..3376401e2 100644 --- a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs +++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::transmute_ptr_to_ref)] #![allow(clippy::match_single_binding, clippy::unnecessary_cast)] diff --git a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.stderr b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.stderr index b3e6c09d2..9d1b22a79 100644 --- a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.stderr +++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.stderr @@ -1,133 +1,134 @@ error: transmute from a pointer type (`*const T`) to a reference type (`&T`) - --> $DIR/transmute_ptr_to_ref.rs:7:17 + --> $DIR/transmute_ptr_to_ref.rs:5:17 | LL | let _: &T = std::mem::transmute(p); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*p` | = note: `-D clippy::transmute-ptr-to-ref` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ref)]` error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) - --> $DIR/transmute_ptr_to_ref.rs:10:21 + --> $DIR/transmute_ptr_to_ref.rs:8:21 | LL | let _: &mut T = std::mem::transmute(m); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *m` error: transmute from a pointer type (`*mut T`) to a reference type (`&T`) - --> $DIR/transmute_ptr_to_ref.rs:13:17 + --> $DIR/transmute_ptr_to_ref.rs:11:17 | LL | let _: &T = std::mem::transmute(m); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*m` error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`) - --> $DIR/transmute_ptr_to_ref.rs:16:21 + --> $DIR/transmute_ptr_to_ref.rs:14:21 | 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:19:17 + --> $DIR/transmute_ptr_to_ref.rs:17: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:22:21 + --> $DIR/transmute_ptr_to_ref.rs:20: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:25:17 + --> $DIR/transmute_ptr_to_ref.rs:23: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:35:32 + --> $DIR/transmute_ptr_to_ref.rs:33: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:37:33 + --> $DIR/transmute_ptr_to_ref.rs:35: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:41:14 + --> $DIR/transmute_ptr_to_ref.rs:39: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:46:14 + --> $DIR/transmute_ptr_to_ref.rs:44: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:47:14 + --> $DIR/transmute_ptr_to_ref.rs:45: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:48:14 + --> $DIR/transmute_ptr_to_ref.rs:46: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:49:14 + --> $DIR/transmute_ptr_to_ref.rs:47: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:57:19 + --> $DIR/transmute_ptr_to_ref.rs:55: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:58:19 + --> $DIR/transmute_ptr_to_ref.rs:56: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:60:14 + --> $DIR/transmute_ptr_to_ref.rs:58: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:61:14 + --> $DIR/transmute_ptr_to_ref.rs:59: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:69:19 + --> $DIR/transmute_ptr_to_ref.rs:67: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:70:19 + --> $DIR/transmute_ptr_to_ref.rs:68: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:72:14 + --> $DIR/transmute_ptr_to_ref.rs:70: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:73:14 + --> $DIR/transmute_ptr_to_ref.rs:71:14 | LL | _ => std::mem::transmute::<_, &&'b u32>(x), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(x as *const () as *const &'b u32)` diff --git a/src/tools/clippy/tests/ui/transmute_undefined_repr.rs b/src/tools/clippy/tests/ui/transmute_undefined_repr.rs index 5aad0b442..a087d09c1 100644 --- a/src/tools/clippy/tests/ui/transmute_undefined_repr.rs +++ b/src/tools/clippy/tests/ui/transmute_undefined_repr.rs @@ -25,102 +25,179 @@ fn main() { let _: Ty = transmute(value::()); let _: Ty = transmute(value::()); - let _: Ty2C = transmute(value::>()); // Lint, Ty2 is unordered - let _: Ty2 = transmute(value::>()); // Lint, Ty2 is unordered - - let _: Ty2 = transmute(value::>>()); // Ok, Ty2 types are the same - let _: Ty> = transmute(value::>()); // Ok, Ty2 types are the same - - let _: Ty2 = transmute(value::>>()); // Lint, different Ty2 instances - let _: Ty> = transmute(value::>()); // Lint, different Ty2 instances + // Lint, Ty2 is unordered + let _: Ty2C = transmute(value::>()); + //~^ ERROR: transmute from `Ty2` which has an undefined layout + //~| NOTE: `-D clippy::transmute-undefined-repr` implied by `-D warnings` + // Lint, Ty2 is unordered + let _: Ty2 = transmute(value::>()); + //~^ ERROR: transmute into `Ty2` which has an undefined layout + + // Ok, Ty2 types are the same + let _: Ty2 = transmute(value::>>()); + // Ok, Ty2 types are the same + let _: Ty> = transmute(value::>()); + + // Lint, different Ty2 instances + let _: Ty2 = transmute(value::>>()); + //~^ ERROR: transmute from `Ty>` to `Ty2`, both of which h + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou + // Lint, different Ty2 instances + let _: Ty> = transmute(value::>()); + //~^ ERROR: transmute from `Ty2` to `Ty>`, both of which h + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou let _: Ty<&()> = transmute(value::<&()>()); let _: &() = transmute(value::>()); - let _: &Ty2 = transmute(value::>>()); // Lint, different Ty2 instances - let _: Ty<&Ty2> = transmute(value::<&Ty2>()); // Lint, different Ty2 instances - - let _: Ty = transmute(value::<&Ty2>()); // Ok, pointer to usize conversion - let _: &Ty2 = transmute(value::>()); // Ok, pointer to usize conversion - - let _: Ty<[u8; 8]> = transmute(value::>()); // Ok, transmute to byte array - let _: Ty2 = transmute(value::>()); // Ok, transmute from byte array + // Lint, different Ty2 instances + let _: &Ty2 = transmute(value::>>()); + //~^ ERROR: transmute from `Ty<&Ty2>` to `&Ty2`, both of which + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou + // Lint, different Ty2 instances + let _: Ty<&Ty2> = transmute(value::<&Ty2>()); + //~^ ERROR: transmute from `&Ty2` to `Ty<&Ty2>`, both of which + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou + + // Ok, pointer to usize conversion + let _: Ty = transmute(value::<&Ty2>()); + // Ok, pointer to usize conversion + let _: &Ty2 = transmute(value::>()); + + // Ok, transmute to byte array + let _: Ty<[u8; 8]> = transmute(value::>()); + // Ok, transmute from byte array + let _: Ty2 = transmute(value::>()); // issue #8417 - let _: Ty2C, ()> = transmute(value::>()); // Ok, Ty2 types are the same - let _: Ty2 = transmute(value::, ()>>()); // Ok, Ty2 types are the same - - let _: &'static mut Ty2 = transmute(value::>>()); // Ok, Ty2 types are the same - let _: Box> = transmute(value::<&'static mut Ty2>()); // Ok, Ty2 types are the same - let _: *mut Ty2 = transmute(value::>>()); // Ok, Ty2 types are the same - let _: Box> = transmute(value::<*mut Ty2>()); // Ok, Ty2 types are the same - - let _: &'static mut Ty2 = transmute(value::>>()); // Lint, different Ty2 instances - let _: Box> = transmute(value::<&'static mut Ty2>()); // Lint, different Ty2 instances - - let _: *const () = transmute(value::>>()); // Ok, type erasure - let _: Ty<&Ty2> = transmute(value::<*const ()>()); // Ok, reverse type erasure - - let _: *const c_void = transmute(value::>>()); // Ok, type erasure - let _: Ty<&Ty2> = transmute(value::<*const c_void>()); // Ok, reverse type erasure + // Ok, Ty2 types are the same + let _: Ty2C, ()> = transmute(value::>()); + // Ok, Ty2 types are the same + let _: Ty2 = transmute(value::, ()>>()); + + // Ok, Ty2 types are the same + let _: &'static mut Ty2 = transmute(value::>>()); + // Ok, Ty2 types are the same + let _: Box> = transmute(value::<&'static mut Ty2>()); + // Ok, Ty2 types are the same + let _: *mut Ty2 = transmute(value::>>()); + // Ok, Ty2 types are the same + let _: Box> = transmute(value::<*mut Ty2>()); + + // Lint, different Ty2 instances + let _: &'static mut Ty2 = transmute(value::>>()); + //~^ ERROR: transmute from `std::boxed::Box>` to `&mut Ty2 + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou + // Lint, different Ty2 instances + let _: Box> = transmute(value::<&'static mut Ty2>()); + //~^ ERROR: transmute from `&mut Ty2` to `std::boxed::Box> + //~| NOTE: two instances of the same generic type (`Ty2`) may have different layou + + // Ok, type erasure + let _: *const () = transmute(value::>>()); + // Ok, reverse type erasure + let _: Ty<&Ty2> = transmute(value::<*const ()>()); + + // Ok, type erasure + let _: *const c_void = transmute(value::>>()); + // Ok, reverse type erasure + let _: Ty<&Ty2> = transmute(value::<*const c_void>()); enum Erase {} - let _: *const Erase = transmute(value::>>()); // Ok, type erasure - let _: Ty<&Ty2> = transmute(value::<*const Erase>()); // Ok, reverse type erasure + // Ok, type erasure + let _: *const Erase = transmute(value::>>()); + // Ok, reverse type erasure + let _: Ty<&Ty2> = transmute(value::<*const Erase>()); struct Erase2( [u8; 0], core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, ); - let _: *const Erase2 = transmute(value::>>()); // Ok, type erasure - let _: Ty<&Ty2> = transmute(value::<*const Erase2>()); // Ok, reverse type erasure - - let _: *const () = transmute(value::<&&[u8]>()); // Ok, type erasure - let _: &&[u8] = transmute(value::<*const ()>()); // Ok, reverse type erasure - - let _: *mut c_void = transmute(value::<&mut &[u8]>()); // Ok, type erasure - let _: &mut &[u8] = transmute(value::<*mut c_void>()); // Ok, reverse type erasure - - let _: [u8; size_of::<&[u8]>()] = transmute(value::<&[u8]>()); // Ok, transmute to byte array - let _: &[u8] = transmute(value::<[u8; size_of::<&[u8]>()]>()); // Ok, transmute from byte array - - let _: [usize; 2] = transmute(value::<&[u8]>()); // Ok, transmute to int array - let _: &[u8] = transmute(value::<[usize; 2]>()); // Ok, transmute from int array - - let _: *const [u8] = transmute(value::>()); // Ok - let _: Box<[u8]> = transmute(value::<*mut [u8]>()); // Ok - - let _: Ty2 = transmute(value::<(Ty2,)>()); // Ok - let _: (Ty2,) = transmute(value::>()); // Ok - - let _: Ty2 = transmute(value::<(Ty2, ())>()); // Ok - let _: (Ty2, ()) = transmute(value::>()); // Ok - - let _: Ty2 = transmute(value::<((), Ty2)>()); // Ok - let _: ((), Ty2) = transmute(value::>()); // Ok - - let _: (usize, usize) = transmute(value::<&[u8]>()); // Ok - let _: &[u8] = transmute(value::<(usize, usize)>()); // Ok + // Ok, type erasure + let _: *const Erase2 = transmute(value::>>()); + // Ok, reverse type erasure + let _: Ty<&Ty2> = transmute(value::<*const Erase2>()); + + // Ok, type erasure + let _: *const () = transmute(value::<&&[u8]>()); + // Ok, reverse type erasure + let _: &&[u8] = transmute(value::<*const ()>()); + + // Ok, type erasure + let _: *mut c_void = transmute(value::<&mut &[u8]>()); + // Ok, reverse type erasure + let _: &mut &[u8] = transmute(value::<*mut c_void>()); + + // Ok, transmute to byte array + let _: [u8; size_of::<&[u8]>()] = transmute(value::<&[u8]>()); + // Ok, transmute from byte array + let _: &[u8] = transmute(value::<[u8; size_of::<&[u8]>()]>()); + + // Ok, transmute to int array + let _: [usize; 2] = transmute(value::<&[u8]>()); + // Ok, transmute from int array + let _: &[u8] = transmute(value::<[usize; 2]>()); + + // Ok + let _: *const [u8] = transmute(value::>()); + // Ok + let _: Box<[u8]> = transmute(value::<*mut [u8]>()); + + // Ok + let _: Ty2 = transmute(value::<(Ty2,)>()); + // Ok + let _: (Ty2,) = transmute(value::>()); + + // Ok + let _: Ty2 = transmute(value::<(Ty2, ())>()); + // Ok + let _: (Ty2, ()) = transmute(value::>()); + + // Ok + let _: Ty2 = transmute(value::<((), Ty2)>()); + // Ok + let _: ((), Ty2) = transmute(value::>()); + + // Ok + let _: (usize, usize) = transmute(value::<&[u8]>()); + // Ok + let _: &[u8] = transmute(value::<(usize, usize)>()); trait Trait {} - let _: (isize, isize) = transmute(value::<&dyn Trait>()); // Ok - let _: &dyn Trait = transmute(value::<(isize, isize)>()); // Ok - - let _: MaybeUninit> = transmute(value::>()); // Ok - let _: Ty2 = transmute(value::>>()); // Ok - - let _: Ty<&[u32]> = transmute::<&[u32], _>(value::<&Vec>()); // Ok - - let _: *const Ty2 = transmute(value::<*const Ty2C, u32>>()); // Ok - let _: *const Ty2C, u32> = transmute(value::<*const Ty2>()); // Ok - let _: *const Ty2 = transmute(value::<*const Ty2C<(), Ty2>>()); // Ok - let _: *const Ty2C<(), Ty2> = transmute(value::<*const Ty2>()); // Ok - - let _: *const Ty2 = transmute(value::<*const Ty2C>>()); // Err - let _: *const Ty2C> = transmute(value::<*const Ty2>()); // Err - - let _: NonNull = transmute(value::>()); // Ok - let _: NonNull<(String, String)> = transmute(value::>()); // Ok + // Ok + let _: (isize, isize) = transmute(value::<&dyn Trait>()); + let _: &dyn Trait = transmute(value::<(isize, isize)>()); + + // Ok + let _: MaybeUninit> = transmute(value::>()); + // Ok + let _: Ty2 = transmute(value::>>()); + + // Ok + let _: Ty<&[u32]> = transmute::<&[u32], _>(value::<&Vec>()); + + // Ok + let _: *const Ty2 = transmute(value::<*const Ty2C, u32>>()); + // Ok + let _: *const Ty2C, u32> = transmute(value::<*const Ty2>()); + // Ok + let _: *const Ty2 = transmute(value::<*const Ty2C<(), Ty2>>()); + // Ok + let _: *const Ty2C<(), Ty2> = transmute(value::<*const Ty2>()); + + // Err + let _: *const Ty2 = transmute(value::<*const Ty2C>>()); + //~^ ERROR: transmute into `*const Ty2` which has an undefined layout + //~| NOTE: the contained type `Ty2` has an undefined layout + // Err + let _: *const Ty2C> = transmute(value::<*const Ty2>()); + //~^ ERROR: transmute from `*const Ty2` which has an undefined layout + //~| NOTE: the contained type `Ty2` has an undefined layout + + // Ok + let _: NonNull = transmute(value::>()); + // Ok + let _: NonNull<(String, String)> = transmute(value::>()); } } @@ -129,28 +206,48 @@ fn _with_generics() { return; } unsafe { - let _: &u32 = transmute(value::<&T>()); // Ok - let _: &T = transmute(value::<&u32>()); // Ok - - let _: Vec = transmute(value::>()); // Ok - let _: Vec = transmute(value::>()); // Ok - - let _: Ty<&u32> = transmute(value::<&T>()); // Ok - let _: Ty<&T> = transmute(value::<&u32>()); // Ok - - let _: Vec = transmute(value::>()); // Ok - let _: Vec = transmute(value::>()); // Ok - - let _: &Ty2 = transmute(value::<&Ty2>()); // Ok - let _: &Ty2 = transmute(value::<&Ty2>()); // Ok - - let _: Vec> = transmute(value::>>()); // Ok - let _: Vec> = transmute(value::>>()); // Ok - - let _: Vec> = transmute(value::>>()); // Err - let _: Vec> = transmute(value::>>()); // Err - - let _: *const u32 = transmute(value::>()); // Ok - let _: Box = transmute(value::<*const u32>()); // Ok + // Ok + let _: &u32 = transmute(value::<&T>()); + // Ok + let _: &T = transmute(value::<&u32>()); + + // Ok + let _: Vec = transmute(value::>()); + // Ok + let _: Vec = transmute(value::>()); + + // Ok + let _: Ty<&u32> = transmute(value::<&T>()); + // Ok + let _: Ty<&T> = transmute(value::<&u32>()); + + // Ok + let _: Vec = transmute(value::>()); + // Ok + let _: Vec = transmute(value::>()); + + // Ok + let _: &Ty2 = transmute(value::<&Ty2>()); + // Ok + let _: &Ty2 = transmute(value::<&Ty2>()); + + // Ok + let _: Vec> = transmute(value::>>()); + // Ok + let _: Vec> = transmute(value::>>()); + + // Err + let _: Vec> = transmute(value::>>()); + //~^ ERROR: transmute from `std::vec::Vec>` to `std::vec::Vec> = transmute(value::>>()); + //~^ ERROR: transmute from `std::vec::Vec>` to `std::vec::Vec>()); + // Ok + let _: Box = transmute(value::<*const u32>()); } } diff --git a/src/tools/clippy/tests/ui/transmute_undefined_repr.stderr b/src/tools/clippy/tests/ui/transmute_undefined_repr.stderr index e50a77329..f87b1ece9 100644 --- a/src/tools/clippy/tests/ui/transmute_undefined_repr.stderr +++ b/src/tools/clippy/tests/ui/transmute_undefined_repr.stderr @@ -1,93 +1,94 @@ error: transmute from `Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:28:33 + --> $DIR/transmute_undefined_repr.rs:29:33 | -LL | let _: Ty2C = transmute(value::>()); // Lint, Ty2 is unordered +LL | let _: Ty2C = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::transmute-undefined-repr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmute_undefined_repr)]` error: transmute into `Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:29:32 + --> $DIR/transmute_undefined_repr.rs:33:32 | -LL | let _: Ty2 = transmute(value::>()); // Lint, Ty2 is unordered +LL | let _: Ty2 = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmute from `Ty>` to `Ty2`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:34:32 + --> $DIR/transmute_undefined_repr.rs:42:32 | -LL | let _: Ty2 = transmute(value::>>()); // Lint, different Ty2 instances +LL | let _: Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `Ty2` to `Ty>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:35:36 + --> $DIR/transmute_undefined_repr.rs:46:36 | -LL | let _: Ty> = transmute(value::>()); // Lint, different Ty2 instances +LL | let _: Ty> = transmute(value::>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `Ty<&Ty2>` to `&Ty2`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:40:33 + --> $DIR/transmute_undefined_repr.rs:54:33 | -LL | let _: &Ty2 = transmute(value::>>()); // Lint, different Ty2 instances +LL | let _: &Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `&Ty2` to `Ty<&Ty2>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:41:37 + --> $DIR/transmute_undefined_repr.rs:58:37 | -LL | let _: Ty<&Ty2> = transmute(value::<&Ty2>()); // Lint, different Ty2 instances +LL | let _: Ty<&Ty2> = transmute(value::<&Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `std::boxed::Box>` to `&mut Ty2`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:58:45 + --> $DIR/transmute_undefined_repr.rs:88:45 | -LL | let _: &'static mut Ty2 = transmute(value::>>()); // Lint, different Ty2 instances +LL | let _: &'static mut Ty2 = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute from `&mut Ty2` to `std::boxed::Box>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:59:37 + --> $DIR/transmute_undefined_repr.rs:92:37 | -LL | let _: Box> = transmute(value::<&'static mut Ty2>()); // Lint, different Ty2 instances +LL | let _: Box> = transmute(value::<&'static mut Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Ty2`) may have different layouts error: transmute into `*const Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:119:39 + --> $DIR/transmute_undefined_repr.rs:189:39 | -LL | let _: *const Ty2 = transmute(value::<*const Ty2C>>()); // Err +LL | let _: *const Ty2 = transmute(value::<*const Ty2C>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the contained type `Ty2` has an undefined layout error: transmute from `*const Ty2` which has an undefined layout - --> $DIR/transmute_undefined_repr.rs:120:50 + --> $DIR/transmute_undefined_repr.rs:193:50 | -LL | let _: *const Ty2C> = transmute(value::<*const Ty2>()); // Err +LL | let _: *const Ty2C> = transmute(value::<*const Ty2>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the contained type `Ty2` has an undefined layout error: transmute from `std::vec::Vec>` to `std::vec::Vec>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:150:35 + --> $DIR/transmute_undefined_repr.rs:240:35 | -LL | let _: Vec> = transmute(value::>>()); // Err +LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Vec`) may have different layouts error: transmute from `std::vec::Vec>` to `std::vec::Vec>`, both of which have an undefined layout - --> $DIR/transmute_undefined_repr.rs:151:35 + --> $DIR/transmute_undefined_repr.rs:244:35 | -LL | let _: Vec> = transmute(value::>>()); // Err +LL | let _: Vec> = transmute(value::>>()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: two instances of the same generic type (`Vec`) may have different layouts diff --git a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed index 05aa86c47..08b8e7866 100644 --- a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed +++ b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::transmutes_expressible_as_ptr_casts)] // These two warnings currently cover the cases transmutes_expressible_as_ptr_casts // would otherwise be responsible for diff --git a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs index 29fa6914c..92eb765e5 100644 --- a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::transmutes_expressible_as_ptr_casts)] // These two warnings currently cover the cases transmutes_expressible_as_ptr_casts // would otherwise be responsible for diff --git a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.stderr b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.stderr index 58f5162c7..a7988dc4b 100644 --- a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.stderr +++ b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.stderr @@ -1,65 +1,68 @@ error: transmute from an integer to a pointer - --> $DIR/transmutes_expressible_as_ptr_casts.rs:18:39 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:17:39 | LL | let _ptr_i32_transmute = unsafe { transmute::(usize::MAX) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `usize::MAX as *const i32` | = note: `-D clippy::useless-transmute` implied by `-D warnings` + = 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:22:38 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:21:38 | LL | let _ptr_i8_transmute = unsafe { transmute::<*const i32, *const i8>(ptr_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as *const i8` | = note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` + = 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:28:46 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:27: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:34:50 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:33:50 | LL | let _usize_from_int_ptr_transmute = unsafe { transmute::<*const i32, usize>(ptr_i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr_i32 as usize` | = note: `-D clippy::transmutes-expressible-as-ptr-casts` implied by `-D warnings` + = 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:40:41 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:39: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:48:41 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:47: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:52:49 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:51: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:55:36 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:54: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:66:14 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:65: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:84:28 + --> $DIR/transmutes_expressible_as_ptr_casts.rs:83:28 | LL | let _x: u8 = unsafe { *std::mem::transmute::(f) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(f as *const u8)` diff --git a/src/tools/clippy/tests/ui/transmuting_null.rs b/src/tools/clippy/tests/ui/transmuting_null.rs index ea3ee8edc..88b8c9965 100644 --- a/src/tools/clippy/tests/ui/transmuting_null.rs +++ b/src/tools/clippy/tests/ui/transmuting_null.rs @@ -8,7 +8,10 @@ fn one_liners() { unsafe { let _: &u64 = std::mem::transmute(0 as *const u64); + //~^ ERROR: transmuting a known null pointer into a reference + //~| NOTE: `-D clippy::transmuting-null` implied by `-D warnings` let _: &u64 = std::mem::transmute(std::ptr::null::()); + //~^ ERROR: transmuting a known null pointer into a reference } } @@ -19,6 +22,7 @@ fn transmute_const() { unsafe { // Should raise a lint. let _: &u64 = std::mem::transmute(ZPTR); + //~^ ERROR: transmuting a known null pointer into a reference // Should NOT raise a lint. let _: &u64 = std::mem::transmute(NOT_ZPTR); } diff --git a/src/tools/clippy/tests/ui/transmuting_null.stderr b/src/tools/clippy/tests/ui/transmuting_null.stderr index 1848fc249..402de38fe 100644 --- a/src/tools/clippy/tests/ui/transmuting_null.stderr +++ b/src/tools/clippy/tests/ui/transmuting_null.stderr @@ -5,15 +5,16 @@ LL | let _: &u64 = std::mem::transmute(0 as *const u64); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::transmuting-null` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::transmuting_null)]` error: transmuting a known null pointer into a reference - --> $DIR/transmuting_null.rs:11:23 + --> $DIR/transmuting_null.rs:13:23 | LL | let _: &u64 = std::mem::transmute(std::ptr::null::()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: transmuting a known null pointer into a reference - --> $DIR/transmuting_null.rs:21:23 + --> $DIR/transmuting_null.rs:24:23 | LL | let _: &u64 = std::mem::transmute(ZPTR); | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/trim_split_whitespace.fixed b/src/tools/clippy/tests/ui/trim_split_whitespace.fixed index 7909b319d..6d3daf798 100644 --- a/src/tools/clippy/tests/ui/trim_split_whitespace.fixed +++ b/src/tools/clippy/tests/ui/trim_split_whitespace.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::trim_split_whitespace)] #![allow(clippy::let_unit_value)] diff --git a/src/tools/clippy/tests/ui/trim_split_whitespace.rs b/src/tools/clippy/tests/ui/trim_split_whitespace.rs index 0cf58979f..b49d9e8b3 100644 --- a/src/tools/clippy/tests/ui/trim_split_whitespace.rs +++ b/src/tools/clippy/tests/ui/trim_split_whitespace.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::trim_split_whitespace)] #![allow(clippy::let_unit_value)] diff --git a/src/tools/clippy/tests/ui/trim_split_whitespace.stderr b/src/tools/clippy/tests/ui/trim_split_whitespace.stderr index 5ae7849e2..a1c66eea0 100644 --- a/src/tools/clippy/tests/ui/trim_split_whitespace.stderr +++ b/src/tools/clippy/tests/ui/trim_split_whitespace.stderr @@ -1,49 +1,50 @@ error: found call to `str::trim` before `str::split_whitespace` - --> $DIR/trim_split_whitespace.rs:62:23 + --> $DIR/trim_split_whitespace.rs:61:23 | LL | let _ = " A B C ".trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` | = note: `-D clippy::trim-split-whitespace` implied by `-D warnings` + = 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:63:23 + --> $DIR/trim_split_whitespace.rs:62: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:64:23 + --> $DIR/trim_split_whitespace.rs:63: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:67:37 + --> $DIR/trim_split_whitespace.rs:66: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:68:37 + --> $DIR/trim_split_whitespace.rs:67: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:69:37 + --> $DIR/trim_split_whitespace.rs:68: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:76:15 + --> $DIR/trim_split_whitespace.rs:75: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:84:15 + --> $DIR/trim_split_whitespace.rs:83:15 | LL | let _ = s.trim().split_whitespace(); // should trigger lint | ^^^^^^^ help: remove `trim()` diff --git a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs index 86f5cc937..043a7b63a 100644 --- a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs +++ b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs @@ -1,5 +1,5 @@ //@normalize-stderr-test: "\(\d+ byte\)" -> "(N byte)" -//@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)" +//@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: 8 byte)" #![deny(clippy::trivially_copy_pass_by_ref)] #![allow( clippy::disallowed_names, @@ -8,7 +8,7 @@ clippy::uninlined_format_args, clippy::needless_pass_by_ref_mut )] - +//@no-rustfix #[derive(Copy, Clone)] struct Foo(u32); @@ -50,6 +50,8 @@ fn good_return_explicit_lt_struct<'a>(foo: &'a Foo) -> FooRef<'a> { } fn bad(x: &u32, y: &Foo, z: &Baz) {} +//~^ 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 impl Foo { fn good(self, a: &mut u32, b: u32, c: &Bar) {} @@ -57,10 +59,18 @@ impl Foo { fn good2(&mut self) {} fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} + //~^ 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 + //~| 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 fn bad2(x: &u32, y: &Foo, z: &Baz) {} + //~^ 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 + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by fn bad_issue7518(self, other: &Self) {} + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if } impl AsRef for Foo { @@ -73,10 +83,14 @@ impl Bar { fn good(&self, a: &mut u32, b: u32, c: &Bar) {} fn bad2(x: &u32, y: &Foo, z: &Baz) {} + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if + //~| ERROR: this argument (4 byte) is passed by reference, but would be more efficient if } trait MyTrait { fn trait_method(&self, _foo: &Foo); + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if } pub trait MyTrait2 { @@ -109,11 +123,13 @@ mod issue5876 { #[inline(never)] fn foo_never(x: &i32) { + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by println!("{}", x); } #[inline] fn foo(x: &i32) { + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by println!("{}", x); } } @@ -141,6 +157,7 @@ async fn _async_explicit<'a>(x: &'a u32) -> &'a u32 { } fn _unrelated_lifetimes<'a, 'b>(_x: &'a u32, y: &'b u32) -> &'b u32 { + //~^ ERROR: this argument (4 byte) is passed by reference, but would be more efficient if passed by y } diff --git a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr index 2af668537..c9585e519 100644 --- a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr +++ b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr @@ -1,4 +1,4 @@ -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> $DIR/trivially_copy_pass_by_ref.rs:52:11 | LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} @@ -10,104 +10,104 @@ note: the lint level is defined here LL | #![deny(clippy::trivially_copy_pass_by_ref)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> $DIR/trivially_copy_pass_by_ref.rs:52:20 | LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> $DIR/trivially_copy_pass_by_ref.rs:52:29 | LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:59:12 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:61:12 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^^ help: consider passing by value instead: `self` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:59:22 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:61:22 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `u32` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:59:31 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:61:31 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:59:40 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:61:40 | LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:61:16 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:67:16 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `u32` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:61:25 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:67:25 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:61:34 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:67:34 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:63:35 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:72:35 | LL | fn bad_issue7518(self, other: &Self) {} | ^^^^^ help: consider passing by value instead: `Self` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:75:16 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:85:16 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `u32` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:75:25 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:85:25 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Foo` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:75:34 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:85:34 | LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} | ^^^^ help: consider passing by value instead: `Baz` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:79:34 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:92:34 | LL | fn trait_method(&self, _foo: &Foo); | ^^^^ help: consider passing by value instead: `Foo` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:111:21 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:125:21 | LL | fn foo_never(x: &i32) { | ^^^^ help: consider passing by value instead: `i32` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:116:15 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:131:15 | LL | fn foo(x: &i32) { | ^^^^ help: consider passing by value instead: `i32` -error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte) - --> $DIR/trivially_copy_pass_by_ref.rs:143:37 +error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) + --> $DIR/trivially_copy_pass_by_ref.rs:159:37 | LL | fn _unrelated_lifetimes<'a, 'b>(_x: &'a u32, y: &'b u32) -> &'b u32 { | ^^^^^^^ help: consider passing by value instead: `u32` diff --git a/src/tools/clippy/tests/ui/try_err.fixed b/src/tools/clippy/tests/ui/try_err.fixed index 930489fab..aae4f8ac4 100644 --- a/src/tools/clippy/tests/ui/try_err.fixed +++ b/src/tools/clippy/tests/ui/try_err.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![deny(clippy::try_err)] #![allow( diff --git a/src/tools/clippy/tests/ui/try_err.rs b/src/tools/clippy/tests/ui/try_err.rs index f5baf3d8f..927eccf2d 100644 --- a/src/tools/clippy/tests/ui/try_err.rs +++ b/src/tools/clippy/tests/ui/try_err.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![deny(clippy::try_err)] #![allow( diff --git a/src/tools/clippy/tests/ui/try_err.stderr b/src/tools/clippy/tests/ui/try_err.stderr index 9968b383e..887889ffd 100644 --- a/src/tools/clippy/tests/ui/try_err.stderr +++ b/src/tools/clippy/tests/ui/try_err.stderr @@ -1,35 +1,35 @@ error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:23:9 + --> $DIR/try_err.rs:22:9 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err)` | note: the lint level is defined here - --> $DIR/try_err.rs:4:9 + --> $DIR/try_err.rs:3:9 | LL | #![deny(clippy::try_err)] | ^^^^^^^^^^^^^^^ error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:33:9 + --> $DIR/try_err.rs:32:9 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err.into())` error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:53:17 + --> $DIR/try_err.rs:52:17 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err)` error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:72:17 + --> $DIR/try_err.rs:71:17 | LL | Err(err)?; | ^^^^^^^^^ help: try: `return Err(err.into())` error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:92:23 + --> $DIR/try_err.rs:91:23 | LL | Err(_) => Err(1)?, | ^^^^^^^ help: try: `return Err(1)` @@ -37,7 +37,7 @@ LL | Err(_) => Err(1)?, = note: this error originates in the macro `__inline_mac_fn_calling_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:99:23 + --> $DIR/try_err.rs:98:23 | LL | Err(_) => Err(inline!(1))?, | ^^^^^^^^^^^^^^^^ help: try: `return Err(inline!(1))` @@ -45,31 +45,31 @@ LL | Err(_) => Err(inline!(1))?, = note: this error originates in the macro `__inline_mac_fn_calling_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: returning an `Err(_)` with the `?` operator - --> $DIR/try_err.rs:126:9 + --> $DIR/try_err.rs:125:9 | 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:133:9 + --> $DIR/try_err.rs:132: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:135:9 + --> $DIR/try_err.rs:134: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:143:9 + --> $DIR/try_err.rs:142: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:152:16 + --> $DIR/try_err.rs:151:16 | LL | return Err(42)?; | ^^^^^^^^ help: try: `Err(42)` diff --git a/src/tools/clippy/tests/ui/tuple_array_conversions.rs b/src/tools/clippy/tests/ui/tuple_array_conversions.rs index 569415acb..ca79cc104 100644 --- a/src/tools/clippy/tests/ui/tuple_array_conversions.rs +++ b/src/tools/clippy/tests/ui/tuple_array_conversions.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::no_effect, clippy::useless_vec, unused)] #![warn(clippy::tuple_array_conversions)] @@ -82,6 +82,11 @@ fn main() { [a, c]; let [[a, b], [c, d]] = [[1, 2], [3, 4]]; (a, c); + // Array length is not usize (#11144) + fn generic_array_length() { + let src = [0; N]; + let dest: (u8,) = (src[0],); + } } #[clippy::msrv = "1.70.0"] diff --git a/src/tools/clippy/tests/ui/tuple_array_conversions.stderr b/src/tools/clippy/tests/ui/tuple_array_conversions.stderr index 50bdcf29d..f8f5b3e75 100644 --- a/src/tools/clippy/tests/ui/tuple_array_conversions.stderr +++ b/src/tools/clippy/tests/ui/tuple_array_conversions.stderr @@ -6,6 +6,7 @@ LL | let x = (x[0], x[1]); | = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed = note: `-D clippy::tuple-array-conversions` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::tuple_array_conversions)]` error: it looks like you're trying to convert a tuple to an array --> $DIR/tuple_array_conversions.rs:11:13 @@ -64,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:99:13 + --> $DIR/tuple_array_conversions.rs:104:13 | LL | let x = (x[0], x[1]); | ^^^^^^^^^^^^ @@ -72,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:100:13 + --> $DIR/tuple_array_conversions.rs:105:13 | LL | let x = [x.0, x.1]; | ^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/type_complexity.rs b/src/tools/clippy/tests/ui/type_complexity.rs index 816950110..be28ee2da 100644 --- a/src/tools/clippy/tests/ui/type_complexity.rs +++ b/src/tools/clippy/tests/ui/type_complexity.rs @@ -5,29 +5,42 @@ type Alias = Vec>>; // no warning here const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); +//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions +//~| NOTE: `-D clippy::type-complexity` implied by `-D warnings` static ST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); +//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions struct S { f: Vec>>, + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } struct Ts(Vec>>); +//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions enum E { Tuple(Vec>>), + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions Struct { f: Vec>> }, + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } impl S { const A: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions fn impl_method(&self, p: Vec>>) {} + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } trait T { const A: Vec>>; + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions type B = Vec>>; + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions fn method(&self, p: Vec>>); + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions fn def_method(&self, p: Vec>>) {} + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } // Should not warn since there is likely no way to simplify this (#1013) @@ -40,13 +53,16 @@ impl T for () { } fn test1() -> Vec>> { + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions vec![] } fn test2(_x: Vec>>) {} +//~^ ERROR: very complex type used. Consider factoring parts into `type` definitions fn test3() { let _y: Vec>> = vec![]; + //~^ ERROR: very complex type used. Consider factoring parts into `type` definitions } #[repr(C)] diff --git a/src/tools/clippy/tests/ui/type_complexity.stderr b/src/tools/clippy/tests/ui/type_complexity.stderr index 9da7edb1c..a3cf6ffe9 100644 --- a/src/tools/clippy/tests/ui/type_complexity.stderr +++ b/src/tools/clippy/tests/ui/type_complexity.stderr @@ -5,87 +5,88 @@ LL | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::type-complexity` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::type_complexity)]` error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:8:12 + --> $DIR/type_complexity.rs:10:12 | LL | static ST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:11:8 + --> $DIR/type_complexity.rs:14:8 | LL | f: Vec>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:14:11 + --> $DIR/type_complexity.rs:18:11 | LL | struct Ts(Vec>>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:17:11 + --> $DIR/type_complexity.rs:22:11 | LL | Tuple(Vec>>), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:18:17 + --> $DIR/type_complexity.rs:24:17 | LL | Struct { f: Vec>> }, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:22:14 + --> $DIR/type_complexity.rs:29:14 | LL | const A: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0)))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:23:30 + --> $DIR/type_complexity.rs:31:30 | LL | fn impl_method(&self, p: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:27:14 + --> $DIR/type_complexity.rs:36:14 | LL | const A: Vec>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:28:14 + --> $DIR/type_complexity.rs:38:14 | LL | type B = Vec>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:29:25 + --> $DIR/type_complexity.rs:40:25 | LL | fn method(&self, p: Vec>>); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:30:29 + --> $DIR/type_complexity.rs:42:29 | LL | fn def_method(&self, p: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:42:15 + --> $DIR/type_complexity.rs:55:15 | LL | fn test1() -> Vec>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:46:14 + --> $DIR/type_complexity.rs:60:14 | LL | fn test2(_x: Vec>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: very complex type used. Consider factoring parts into `type` definitions - --> $DIR/type_complexity.rs:49:13 + --> $DIR/type_complexity.rs:64:13 | LL | let _y: Vec>> = vec![]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/type_id_on_box.fixed b/src/tools/clippy/tests/ui/type_id_on_box.fixed index 615d809c8..538c38b70 100644 --- a/src/tools/clippy/tests/ui/type_id_on_box.fixed +++ b/src/tools/clippy/tests/ui/type_id_on_box.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::type_id_on_box)] use std::any::{Any, TypeId}; diff --git a/src/tools/clippy/tests/ui/type_id_on_box.rs b/src/tools/clippy/tests/ui/type_id_on_box.rs index 74b6c74ae..f224d273b 100644 --- a/src/tools/clippy/tests/ui/type_id_on_box.rs +++ b/src/tools/clippy/tests/ui/type_id_on_box.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::type_id_on_box)] use std::any::{Any, TypeId}; diff --git a/src/tools/clippy/tests/ui/type_id_on_box.stderr b/src/tools/clippy/tests/ui/type_id_on_box.stderr index 1525328c0..844dae158 100644 --- a/src/tools/clippy/tests/ui/type_id_on_box.stderr +++ b/src/tools/clippy/tests/ui/type_id_on_box.stderr @@ -1,5 +1,5 @@ error: calling `.type_id()` on a `Box` - --> $DIR/type_id_on_box.rs:26:13 + --> $DIR/type_id_on_box.rs:24:13 | LL | let _ = any_box.type_id(); | -------^^^^^^^^^^ @@ -9,9 +9,10 @@ LL | let _ = any_box.type_id(); = note: this returns the type id of the literal type `Box` instead of the type id of the boxed value, which is most likely not what you want = note: if this is intentional, use `TypeId::of::>()` instead, which makes it more clear = note: `-D clippy::type-id-on-box` implied by `-D warnings` + = 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:30:13 + --> $DIR/type_id_on_box.rs:28:13 | LL | let _ = any_box.type_id(); // 2 derefs are needed here to get to the `dyn Any` | -------^^^^^^^^^^ @@ -22,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:36:13 + --> $DIR/type_id_on_box.rs:34:13 | LL | let _ = b.type_id(); | -^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/type_repetition_in_bounds.rs b/src/tools/clippy/tests/ui/type_repetition_in_bounds.rs index 874d97f7a..504a00394 100644 --- a/src/tools/clippy/tests/ui/type_repetition_in_bounds.rs +++ b/src/tools/clippy/tests/ui/type_repetition_in_bounds.rs @@ -8,6 +8,7 @@ pub fn foo(_t: T) where T: Copy, T: Clone, + //~^ ERROR: this type has already been used as a bound predicate { unimplemented!(); } @@ -25,6 +26,7 @@ trait LintBounds where Self: Clone, Self: Copy + Default + Ord, + //~^ ERROR: this type has already been used as a bound predicate Self: Add + AddAssign + Sub + SubAssign, Self: Mul + MulAssign + Div + DivAssign, { @@ -99,11 +101,13 @@ where pub fn f() where T: Clone, + //~^ ERROR: this type has already been used as a bound predicate { } pub fn g() where T: ?Sized, + //~^ ERROR: this type has already been used as a bound predicate { } @@ -129,6 +133,7 @@ mod issue8772_pass { pub fn f(arg: usize) where T: Trait, Box<[String]>, bool> + 'static, + //~^ ERROR: this type has already been used as a bound predicate U: Clone + Sync + 'static, { } diff --git a/src/tools/clippy/tests/ui/type_repetition_in_bounds.stderr b/src/tools/clippy/tests/ui/type_repetition_in_bounds.stderr index 54973c5bd..607cd1fbf 100644 --- a/src/tools/clippy/tests/ui/type_repetition_in_bounds.stderr +++ b/src/tools/clippy/tests/ui/type_repetition_in_bounds.stderr @@ -12,7 +12,7 @@ LL | #![deny(clippy::type_repetition_in_bounds)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:27:5 + --> $DIR/type_repetition_in_bounds.rs:28:5 | LL | Self: Copy + Default + Ord, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | Self: Copy + Default + Ord, = help: consider combining the bounds: `Self: Clone + Copy + Default + Ord` error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:101:5 + --> $DIR/type_repetition_in_bounds.rs:103:5 | LL | T: Clone, | ^^^^^^^^ @@ -28,7 +28,7 @@ LL | T: Clone, = help: consider combining the bounds: `T: ?Sized + Clone` error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:106:5 + --> $DIR/type_repetition_in_bounds.rs:109:5 | LL | T: ?Sized, | ^^^^^^^^^ @@ -36,7 +36,7 @@ LL | T: ?Sized, = help: consider combining the bounds: `T: Clone + ?Sized` error: this type has already been used as a bound predicate - --> $DIR/type_repetition_in_bounds.rs:131:9 + --> $DIR/type_repetition_in_bounds.rs:135:9 | LL | T: Trait, Box<[String]>, bool> + 'static, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/types.fixed b/src/tools/clippy/tests/ui/types.fixed index 4a2616a7a..6f1f55f0e 100644 --- a/src/tools/clippy/tests/ui/types.fixed +++ b/src/tools/clippy/tests/ui/types.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code, unused_variables)] #![warn(clippy::cast_lossless)] diff --git a/src/tools/clippy/tests/ui/types.rs b/src/tools/clippy/tests/ui/types.rs index 5e0917907..960aee460 100644 --- a/src/tools/clippy/tests/ui/types.rs +++ b/src/tools/clippy/tests/ui/types.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code, unused_variables)] #![warn(clippy::cast_lossless)] diff --git a/src/tools/clippy/tests/ui/types.stderr b/src/tools/clippy/tests/ui/types.stderr index 59c3e05a1..b253cf338 100644 --- a/src/tools/clippy/tests/ui/types.stderr +++ b/src/tools/clippy/tests/ui/types.stderr @@ -1,10 +1,11 @@ error: casting `i32` to `i64` may become silently lossy if you later change the type - --> $DIR/types.rs:14:22 + --> $DIR/types.rs:12:22 | LL | let c_i64: i64 = c as i64; | ^^^^^^^^ help: try: `i64::from(c)` | = note: `-D clippy::cast-lossless` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::cast_lossless)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/unchecked_duration_subtraction.fixed b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.fixed index 757d15921..a0c3330d1 100644 --- a/src/tools/clippy/tests/ui/unchecked_duration_subtraction.fixed +++ b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unchecked_duration_subtraction)] use std::time::{Duration, Instant}; diff --git a/src/tools/clippy/tests/ui/unchecked_duration_subtraction.rs b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.rs index da7faab67..fff1d1372 100644 --- a/src/tools/clippy/tests/ui/unchecked_duration_subtraction.rs +++ b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unchecked_duration_subtraction)] use std::time::{Duration, Instant}; diff --git a/src/tools/clippy/tests/ui/unchecked_duration_subtraction.stderr b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.stderr index a2e0aa1d7..2b62bc964 100644 --- a/src/tools/clippy/tests/ui/unchecked_duration_subtraction.stderr +++ b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.stderr @@ -1,25 +1,26 @@ error: unchecked subtraction of a 'Duration' from an 'Instant' - --> $DIR/unchecked_duration_subtraction.rs:10:13 + --> $DIR/unchecked_duration_subtraction.rs:9:13 | LL | let _ = _first - second; | ^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(second).unwrap()` | = note: `-D clippy::unchecked-duration-subtraction` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unchecked_duration_subtraction)]` error: unchecked subtraction of a 'Duration' from an 'Instant' - --> $DIR/unchecked_duration_subtraction.rs:12:13 + --> $DIR/unchecked_duration_subtraction.rs:11: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:14:13 + --> $DIR/unchecked_duration_subtraction.rs:13: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:16:13 + --> $DIR/unchecked_duration_subtraction.rs:15:13 | LL | let _ = Instant::now() - second; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(second).unwrap()` diff --git a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs b/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs deleted file mode 100644 index a9cc42954..000000000 --- a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs +++ /dev/null @@ -1,534 +0,0 @@ -//@aux-build:proc_macro_unsafe.rs:proc-macro - -#![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)] -#![allow(clippy::let_unit_value, clippy::missing_safety_doc)] - -extern crate proc_macro_unsafe; - -// Valid comments - -fn nested_local() { - let _ = { - let _ = { - // SAFETY: - let _ = unsafe {}; - }; - }; -} - -fn deep_nest() { - let _ = { - let _ = { - // SAFETY: - let _ = unsafe {}; - - // Safety: - unsafe {}; - - let _ = { - let _ = { - let _ = { - let _ = { - let _ = { - // Safety: - let _ = unsafe {}; - - // SAFETY: - unsafe {}; - }; - }; - }; - - // Safety: - unsafe {}; - }; - }; - }; - - // Safety: - unsafe {}; - }; - - // SAFETY: - unsafe {}; -} - -fn local_tuple_expression() { - // Safety: - let _ = (42, unsafe {}); -} - -fn line_comment() { - // Safety: - unsafe {} -} - -fn line_comment_newlines() { - // SAFETY: - - unsafe {} -} - -fn line_comment_empty() { - // Safety: - // - // - // - unsafe {} -} - -fn line_comment_with_extras() { - // This is a description - // Safety: - unsafe {} -} - -fn block_comment() { - /* Safety: */ - unsafe {} -} - -fn block_comment_newlines() { - /* SAFETY: */ - - unsafe {} -} - -fn block_comment_with_extras() { - /* This is a description - * SAFETY: - */ - unsafe {} -} - -fn block_comment_terminator_same_line() { - /* This is a description - * Safety: */ - unsafe {} -} - -fn buried_safety() { - // Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor - // incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation - // ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in - // reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint - // occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est - // laborum. Safety: - // Tellus elementum sagittis vitae et leo duis ut diam quam. Sit amet nulla facilisi - // morbi tempus iaculis urna. Amet luctus venenatis lectus magna. At quis risus sed vulputate odio - // ut. Luctus venenatis lectus magna fringilla urna. Tortor id aliquet lectus proin nibh nisl - // condimentum id venenatis. Vulputate dignissim suspendisse in est ante in nibh mauris cursus. - unsafe {} -} - -fn safety_with_prepended_text() { - // This is a test. safety: - unsafe {} -} - -fn local_line_comment() { - // Safety: - let _ = unsafe {}; -} - -fn local_block_comment() { - /* SAFETY: */ - let _ = unsafe {}; -} - -fn comment_array() { - // Safety: - let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; -} - -fn comment_tuple() { - // sAFETY: - let _ = (42, unsafe {}, "test", unsafe {}); -} - -fn comment_unary() { - // SAFETY: - let _ = *unsafe { &42 }; -} - -#[allow(clippy::match_single_binding)] -fn comment_match() { - // SAFETY: - let _ = match unsafe {} { - _ => {}, - }; -} - -fn comment_addr_of() { - // Safety: - let _ = &unsafe {}; -} - -fn comment_repeat() { - // Safety: - let _ = [unsafe {}; 5]; -} - -fn comment_macro_call() { - macro_rules! t { - ($b:expr) => { - $b - }; - } - - t!( - // SAFETY: - unsafe {} - ); -} - -fn comment_macro_def() { - macro_rules! t { - () => { - // Safety: - unsafe {} - }; - } - - t!(); -} - -fn non_ascii_comment() { - // ॐ᧻໒ SaFeTy: ௵∰ - unsafe {}; -} - -fn local_commented_block() { - let _ = - // safety: - unsafe {}; -} - -fn local_nest() { - // safety: - let _ = [(42, unsafe {}, unsafe {}), (52, unsafe {}, unsafe {})]; -} - -fn in_fn_call(x: *const u32) { - fn f(x: u32) {} - - // Safety: reason - f(unsafe { *x }); -} - -fn multi_in_fn_call(x: *const u32) { - fn f(x: u32, y: u32) {} - - // Safety: reason - f(unsafe { *x }, unsafe { *x }); -} - -fn in_multiline_fn_call(x: *const u32) { - fn f(x: u32, y: u32) {} - - f( - // Safety: reason - unsafe { *x }, - 0, - ); -} - -fn in_macro_call(x: *const u32) { - // Safety: reason - println!("{}", unsafe { *x }); -} - -fn in_multiline_macro_call(x: *const u32) { - println!( - "{}", - // Safety: reason - unsafe { *x }, - ); -} - -fn from_proc_macro() { - proc_macro_unsafe::unsafe_block!(token); -} - -fn in_closure(x: *const u32) { - // Safety: reason - let _ = || unsafe { *x }; -} - -// Invalid comments - -#[rustfmt::skip] -fn inline_block_comment() { - /* Safety: */ unsafe {} -} - -fn no_comment() { - unsafe {} -} - -fn no_comment_array() { - let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }]; -} - -fn no_comment_tuple() { - let _ = (42, unsafe {}, "test", unsafe {}); -} - -fn no_comment_unary() { - let _ = *unsafe { &42 }; -} - -#[allow(clippy::match_single_binding)] -fn no_comment_match() { - let _ = match unsafe {} { - _ => {}, - }; -} - -fn no_comment_addr_of() { - let _ = &unsafe {}; -} - -fn no_comment_repeat() { - let _ = [unsafe {}; 5]; -} - -fn local_no_comment() { - let _ = unsafe {}; -} - -fn no_comment_macro_call() { - macro_rules! t { - ($b:expr) => { - $b - }; - } - - t!(unsafe {}); -} - -fn no_comment_macro_def() { - macro_rules! t { - () => { - unsafe {} - }; - } - - t!(); -} - -fn trailing_comment() { - unsafe {} // SAFETY: -} - -fn internal_comment() { - unsafe { - // SAFETY: - } -} - -fn interference() { - // SAFETY - - let _ = 42; - - unsafe {}; -} - -pub fn print_binary_tree() { - println!("{}", unsafe { String::from_utf8_unchecked(vec![]) }); -} - -mod unsafe_impl_smoke_test { - unsafe trait A {} - - // error: no safety comment - unsafe impl A for () {} - - // Safety: ok - unsafe impl A for (i32) {} - - mod sub_mod { - // error: - unsafe impl B for (u32) {} - unsafe trait B {} - } - - #[rustfmt::skip] - mod sub_mod2 { - // - // SAFETY: ok - // - - unsafe impl B for (u32) {} - unsafe trait B {} - } -} - -mod unsafe_impl_from_macro { - unsafe trait T {} - - // error - macro_rules! no_safety_comment { - ($t:ty) => { - unsafe impl T for $t {} - }; - } - - // ok - no_safety_comment!(()); - - // ok - macro_rules! with_safety_comment { - ($t:ty) => { - // SAFETY: - unsafe impl T for $t {} - }; - } - - // ok - with_safety_comment!((i32)); -} - -mod unsafe_impl_macro_and_not_macro { - unsafe trait T {} - - // error - macro_rules! no_safety_comment { - ($t:ty) => { - unsafe impl T for $t {} - }; - } - - // ok - no_safety_comment!(()); - - // error - unsafe impl T for (i32) {} - - // ok - no_safety_comment!(u32); - - // error - unsafe impl T for (bool) {} -} - -#[rustfmt::skip] -mod unsafe_impl_valid_comment { - unsafe trait SaFety {} - // SaFety: - unsafe impl SaFety for () {} - - unsafe trait MultiLineComment {} - // The following impl is safe - // ... - // Safety: reason - unsafe impl MultiLineComment for () {} - - unsafe trait NoAscii {} - // 安全 SAFETY: 以下のコードは安全です - unsafe impl NoAscii for () {} - - unsafe trait InlineAndPrecedingComment {} - // SAFETY: - /* comment */ unsafe impl InlineAndPrecedingComment for () {} - - unsafe trait BuriedSafety {} - // Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor - // incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation - // ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in - // reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint - // occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est - // laborum. Safety: - // Tellus elementum sagittis vitae et leo duis ut diam quam. Sit amet nulla facilisi - // morbi tempus iaculis urna. Amet luctus venenatis lectus magna. At quis risus sed vulputate odio - // ut. Luctus venenatis lectus magna fringilla urna. Tortor id aliquet lectus proin nibh nisl - // condimentum id venenatis. Vulputate dignissim suspendisse in est ante in nibh mauris cursus. - unsafe impl BuriedSafety for () {} - - unsafe trait MultiLineBlockComment {} - /* This is a description - * Safety: */ - unsafe impl MultiLineBlockComment for () {} -} - -#[rustfmt::skip] -mod unsafe_impl_invalid_comment { - unsafe trait NoComment {} - - unsafe impl NoComment for () {} - - unsafe trait InlineComment {} - - /* SAFETY: */ unsafe impl InlineComment for () {} - - unsafe trait TrailingComment {} - - unsafe impl TrailingComment for () {} // SAFETY: - - unsafe trait Interference {} - // SAFETY: - const BIG_NUMBER: i32 = 1000000; - unsafe impl Interference for () {} -} - -unsafe trait ImplInFn {} - -fn impl_in_fn() { - // error - unsafe impl ImplInFn for () {} - - // SAFETY: ok - unsafe impl ImplInFn for (i32) {} -} - -unsafe trait CrateRoot {} - -// error -unsafe impl CrateRoot for () {} - -// SAFETY: ok -unsafe impl CrateRoot for (i32) {} - -fn issue_9142() { - // SAFETY: ok - let _ = - // we need this comment to avoid rustfmt putting - // it all on one line - unsafe {}; - - // SAFETY: this is more than one level away, so it should warn - let _ = { - if unsafe { true } { - todo!(); - } else { - let bar = unsafe {}; - todo!(); - bar - } - }; -} - -pub unsafe fn a_function_with_a_very_long_name_to_break_the_line() -> u32 { - 1 -} - -pub const unsafe fn a_const_function_with_a_very_long_name_to_break_the_line() -> u32 { - 2 -} - -fn issue_10832() { - // Safety: A safety comment. But it will warn anyways - let _some_variable_with_a_very_long_name_to_break_the_line = - unsafe { a_function_with_a_very_long_name_to_break_the_line() }; - - // Safety: Another safety comment. But it will warn anyways - 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() }; - - // Safety: Yet another safety comment. But it will warn anyways - 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() }; -} - -fn main() {} diff --git a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr b/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr deleted file mode 100644 index ee1d3aa28..000000000 --- a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr +++ /dev/null @@ -1,346 +0,0 @@ -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:262:19 - | -LL | /* Safety: */ unsafe {} - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings` - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:266:5 - | -LL | unsafe {} - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:270:14 - | -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.rs:270:29 - | -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.rs:270:48 - | -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.rs:274:18 - | -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.rs:274:37 - | -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.rs:278:14 - | -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.rs:283:19 - | -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.rs:289:14 - | -LL | let _ = &unsafe {}; - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:293:14 - | -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.rs:297:13 - | -LL | let _ = unsafe {}; - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:307:8 - | -LL | t!(unsafe {}); - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:313:13 - | -LL | unsafe {} - | ^^^^^^^^^ -... -LL | t!(); - | ---- in this macro invocation - | - = help: consider adding a safety comment on the preceding line - = 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.rs:321:5 - | -LL | unsafe {} // SAFETY: - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:325:5 - | -LL | unsafe { - | ^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:335:5 - | -LL | unsafe {}; - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: unsafe block missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:339:20 - | -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.rs:346:5 - | -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.rs:353:9 - | -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.rs:374:13 - | -LL | unsafe impl T for $t {} - | ^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | no_safety_comment!(()); - | ---------------------- in this macro invocation - | - = help: consider adding a safety comment on the preceding line - = 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.rs:399:13 - | -LL | unsafe impl T for $t {} - | ^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | no_safety_comment!(()); - | ---------------------- in this macro invocation - | - = help: consider adding a safety comment on the preceding line - = 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.rs:407:5 - | -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.rs:399:13 - | -LL | unsafe impl T for $t {} - | ^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | no_safety_comment!(u32); - | ----------------------- in this macro invocation - | - = help: consider adding a safety comment on the preceding line - = 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.rs:413:5 - | -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.rs:459:5 - | -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.rs:463:19 - | -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.rs:467:5 - | -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.rs:471:5 - | -LL | const BIG_NUMBER: i32 = 1000000; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: consider removing the safety comment - --> $DIR/undocumented_unsafe_blocks.rs:470:5 - | -LL | // SAFETY: - | ^^^^^^^^^^ - = note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings` - -error: unsafe impl missing a safety comment - --> $DIR/undocumented_unsafe_blocks.rs:472:5 - | -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.rs:479:5 - | -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.rs:488:1 - | -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.rs:498:9 - | -LL | unsafe {}; - | ^^^^^^^^^ - | - = help: consider adding a safety comment on the preceding line - -error: statement has unnecessary safety comment - --> $DIR/undocumented_unsafe_blocks.rs:501:5 - | -LL | / let _ = { -LL | | if unsafe { true } { -LL | | todo!(); -LL | | } else { -... | -LL | | } -LL | | }; - | |______^ - | -help: consider removing the safety comment - --> $DIR/undocumented_unsafe_blocks.rs:500: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.rs:502:12 - | -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.rs:505:23 - | -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.rs:523:9 - | -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.rs:527:9 - | -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.rs:531:9 - | -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: aborting due to 39 previous errors - diff --git a/src/tools/clippy/tests/ui/unicode.fixed b/src/tools/clippy/tests/ui/unicode.fixed index 032040c48..f9efb4ec3 100644 --- a/src/tools/clippy/tests/ui/unicode.fixed +++ b/src/tools/clippy/tests/ui/unicode.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #[warn(clippy::invisible_characters)] diff --git a/src/tools/clippy/tests/ui/unicode.rs b/src/tools/clippy/tests/ui/unicode.rs index dd215bc60..bba613e22 100644 --- a/src/tools/clippy/tests/ui/unicode.rs +++ b/src/tools/clippy/tests/ui/unicode.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![allow(dead_code)] #[warn(clippy::invisible_characters)] diff --git a/src/tools/clippy/tests/ui/unicode.stderr b/src/tools/clippy/tests/ui/unicode.stderr index 21cc22a77..0b6e20664 100644 --- a/src/tools/clippy/tests/ui/unicode.stderr +++ b/src/tools/clippy/tests/ui/unicode.stderr @@ -1,63 +1,65 @@ error: invisible character detected - --> $DIR/unicode.rs:6:12 + --> $DIR/unicode.rs:5:12 | LL | print!("Here >​< is a ZWS, and ​another"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >/u{200B}< is a ZWS, and /u{200B}another"` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{200B}< is a ZWS, and \u{200B}another"` | = note: `-D clippy::invisible-characters` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::invisible_characters)]` error: invisible character detected - --> $DIR/unicode.rs:8:12 + --> $DIR/unicode.rs:7: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"` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >\u{AD}< is a SHY, and \u{AD}another"` error: invisible character detected - --> $DIR/unicode.rs:10:12 + --> $DIR/unicode.rs:9: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"` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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:16:12 + --> $DIR/unicode.rs:15:12 | LL | print!("̀àh?"); | ^^^^^ help: consider replacing the string with: `"̀àh?"` | = note: `-D clippy::unicode-not-nfc` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unicode_not_nfc)]` error: literal non-ASCII character detected - --> $DIR/unicode.rs:24:16 + --> $DIR/unicode.rs:23:16 | LL | print!("Üben!"); - | ^^^^^^^ help: consider replacing the string with: `"/u{dc}ben!"` + | ^^^^^^^ help: consider replacing the string with: `"\u{dc}ben!"` | note: the lint level is defined here - --> $DIR/unicode.rs:21:13 + --> $DIR/unicode.rs:20:13 | LL | #![deny(clippy::non_ascii_literal)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: literal non-ASCII character detected - --> $DIR/unicode.rs:30:36 + --> $DIR/unicode.rs:29:36 | LL | const _EMPTY_BLOCK: char = '▱'; - | ^^^ help: consider replacing the string with: `'/u{25b1}'` + | ^^^ help: consider replacing the string with: `'\u{25b1}'` error: literal non-ASCII character detected - --> $DIR/unicode.rs:31:35 + --> $DIR/unicode.rs:30:35 | LL | const _FULL_BLOCK: char = '▰'; - | ^^^ help: consider replacing the string with: `'/u{25b0}'` + | ^^^ help: consider replacing the string with: `'\u{25b0}'` error: literal non-ASCII character detected - --> $DIR/unicode.rs:51:21 + --> $DIR/unicode.rs:50: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}"` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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:40:17 + --> $DIR/unicode.rs:39:17 | LL | #![deny(clippy::non_ascii_literal)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/uninit.rs b/src/tools/clippy/tests/ui/uninit.rs index 2d567630e..10a4c22b5 100644 --- a/src/tools/clippy/tests/ui/uninit.rs +++ b/src/tools/clippy/tests/ui/uninit.rs @@ -10,6 +10,8 @@ union MyOwnMaybeUninit { fn main() { let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; + //~^ ERROR: this call for this type may be undefined behavior + //~| NOTE: `#[deny(clippy::uninit_assumed_init)]` on by default // This is OK, because ZSTs do not contain data. let _: () = unsafe { MaybeUninit::uninit().assume_init() }; @@ -31,6 +33,7 @@ fn main() { // Was a false negative. let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; + //~^ ERROR: this call for this type may be undefined behavior polymorphic::<()>(); polymorphic_maybe_uninit_array::<10>(); @@ -39,6 +42,7 @@ fn main() { fn polymorphic() { // We are conservative around polymorphic types. let _: T = unsafe { MaybeUninit::uninit().assume_init() }; + //~^ ERROR: this call for this type may be undefined behavior } fn polymorphic_maybe_uninit_array() { diff --git a/src/tools/clippy/tests/ui/uninit.stderr b/src/tools/clippy/tests/ui/uninit.stderr index 248de56da..1cc27ffe7 100644 --- a/src/tools/clippy/tests/ui/uninit.stderr +++ b/src/tools/clippy/tests/ui/uninit.stderr @@ -7,13 +7,13 @@ LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; = note: `#[deny(clippy::uninit_assumed_init)]` on by default error: this call for this type may be undefined behavior - --> $DIR/uninit.rs:33:29 + --> $DIR/uninit.rs:35:29 | LL | let _: usize = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this call for this type may be undefined behavior - --> $DIR/uninit.rs:41:29 + --> $DIR/uninit.rs:44:29 | LL | let _: T = unsafe { MaybeUninit::uninit().assume_init() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/uninit_vec.rs b/src/tools/clippy/tests/ui/uninit_vec.rs index 79effc82f..c069b9adf 100644 --- a/src/tools/clippy/tests/ui/uninit_vec.rs +++ b/src/tools/clippy/tests/ui/uninit_vec.rs @@ -15,29 +15,34 @@ union MyOwnMaybeUninit { fn main() { // with_capacity() -> set_len() should be detected let mut vec: Vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { vec.set_len(200); } // reserve() -> set_len() should be detected vec.reserve(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { vec.set_len(200); } // new() -> set_len() should be detected let mut vec: Vec = Vec::new(); + //~^ ERROR: calling `set_len()` on empty `Vec` creates out-of-bound values unsafe { vec.set_len(200); } // default() -> set_len() should be detected let mut vec: Vec = Default::default(); + //~^ ERROR: calling `set_len()` on empty `Vec` creates out-of-bound values unsafe { vec.set_len(200); } let mut vec: Vec = Vec::default(); + //~^ ERROR: calling `set_len()` on empty `Vec` creates out-of-bound values unsafe { vec.set_len(200); } @@ -45,13 +50,16 @@ fn main() { // test when both calls are enclosed in the same unsafe block unsafe { let mut vec: Vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates unini vec.set_len(200); vec.reserve(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates unini vec.set_len(200); } let mut vec: Vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { // test the case where there are other statements in the following unsafe block vec.set_len(200); @@ -61,11 +69,13 @@ fn main() { // handle vec stored in the field of a struct let mut my_vec = MyVec::default(); my_vec.vec.reserve(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { my_vec.vec.set_len(200); } my_vec.vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates uninitial unsafe { my_vec.vec.set_len(200); } @@ -120,6 +130,7 @@ fn main() { fn polymorphic() { // We are conservative around polymorphic types. let mut vec: Vec = Vec::with_capacity(1000); + //~^ ERROR: calling `set_len()` immediately after reserving a buffer creates unini unsafe { vec.set_len(10); } diff --git a/src/tools/clippy/tests/ui/uninit_vec.stderr b/src/tools/clippy/tests/ui/uninit_vec.stderr index 9cdf0c95a..d39f05839 100644 --- a/src/tools/clippy/tests/ui/uninit_vec.stderr +++ b/src/tools/clippy/tests/ui/uninit_vec.stderr @@ -3,53 +3,54 @@ error: calling `set_len()` immediately after reserving a buffer creates uninitia | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` = note: `-D clippy::uninit-vec` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::uninit_vec)]` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:23:5 + --> $DIR/uninit_vec.rs:24:5 | LL | vec.reserve(1000); | ^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` on empty `Vec` creates out-of-bound values - --> $DIR/uninit_vec.rs:29:5 + --> $DIR/uninit_vec.rs:31:5 | LL | let mut vec: Vec = Vec::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ error: calling `set_len()` on empty `Vec` creates out-of-bound values - --> $DIR/uninit_vec.rs:35:5 + --> $DIR/uninit_vec.rs:38:5 | LL | let mut vec: Vec = Default::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ error: calling `set_len()` on empty `Vec` creates out-of-bound values - --> $DIR/uninit_vec.rs:40:5 + --> $DIR/uninit_vec.rs:44:5 | LL | let mut vec: Vec = Vec::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:54:5 + --> $DIR/uninit_vec.rs:61:5 | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,53 +61,55 @@ LL | vec.set_len(200); = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:63:5 + --> $DIR/uninit_vec.rs:71:5 | LL | my_vec.vec.reserve(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | my_vec.vec.set_len(200); | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:68:5 + --> $DIR/uninit_vec.rs:77:5 | LL | my_vec.vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | my_vec.vec.set_len(200); | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:47:9 + --> $DIR/uninit_vec.rs:52:9 | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:50:9 + --> $DIR/uninit_vec.rs:56:9 | LL | vec.reserve(1000); | ^^^^^^^^^^^^^^^^^^ +LL | LL | vec.set_len(200); | ^^^^^^^^^^^^^^^^ | = help: initialize the buffer or wrap the content in `MaybeUninit` error: calling `set_len()` immediately after reserving a buffer creates uninitialized values - --> $DIR/uninit_vec.rs:122:9 + --> $DIR/uninit_vec.rs:132:9 | LL | let mut vec: Vec = Vec::with_capacity(1000); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | unsafe { +... LL | vec.set_len(10); | ^^^^^^^^^^^^^^^ | diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.fixed b/src/tools/clippy/tests/ui/uninlined_format_args.fixed index a042731a9..3f5b0e52e 100644 --- a/src/tools/clippy/tests/ui/uninlined_format_args.fixed +++ b/src/tools/clippy/tests/ui/uninlined_format_args.fixed @@ -1,5 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro -//@run-rustfix +//@aux-build:proc_macros.rs + #![warn(clippy::uninlined_format_args)] #![allow(named_arguments_used_positionally, unused)] #![allow( diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.rs b/src/tools/clippy/tests/ui/uninlined_format_args.rs index d830b74d6..b311aa491 100644 --- a/src/tools/clippy/tests/ui/uninlined_format_args.rs +++ b/src/tools/clippy/tests/ui/uninlined_format_args.rs @@ -1,5 +1,5 @@ -//@aux-build:proc_macros.rs:proc-macro -//@run-rustfix +//@aux-build:proc_macros.rs + #![warn(clippy::uninlined_format_args)] #![allow(named_arguments_used_positionally, unused)] #![allow( diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.stderr b/src/tools/clippy/tests/ui/uninlined_format_args.stderr index 44ca61f00..829d646b8 100644 --- a/src/tools/clippy/tests/ui/uninlined_format_args.stderr +++ b/src/tools/clippy/tests/ui/uninlined_format_args.stderr @@ -5,6 +5,7 @@ LL | println!("val='{}'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::uninlined-format-args` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::uninlined_format_args)]` help: change this to | LL - println!("val='{}'", local_i32); @@ -216,24 +217,24 @@ LL + println!("{val}"); error: variables can be used directly in the `format!` string --> $DIR/uninlined_format_args.rs:72:5 | -LL | println!("val='{/t }'", local_i32); +LL | println!("val='{\t }'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: change this to | -LL - println!("val='{/t }'", local_i32); +LL - println!("val='{\t }'", local_i32); LL + println!("val='{local_i32}'"); | error: variables can be used directly in the `format!` string --> $DIR/uninlined_format_args.rs:73:5 | -LL | println!("val='{/n }'", local_i32); +LL | println!("val='{\n }'", local_i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: change this to | -LL - println!("val='{/n }'", local_i32); +LL - println!("val='{\n }'", local_i32); LL + println!("val='{local_i32}'"); | diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed index 559050b3d..f0d570efd 100644 --- a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed +++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed @@ -1,7 +1,6 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix #![warn(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.stderr b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.stderr index 2c8061259..221efeb50 100644 --- a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.stderr +++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.stderr @@ -1,10 +1,11 @@ error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args_panic.rs:11:5 + --> $DIR/uninlined_format_args_panic.rs:10:5 | LL | println!("val='{}'", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::uninlined-format-args` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::uninlined_format_args)]` help: change this to | LL - println!("val='{}'", var); diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed index 3a753b49c..7c0f28c45 100644 --- a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed +++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed @@ -1,7 +1,6 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix #![warn(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.stderr b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.stderr index fc7b12508..ec1e3a1cf 100644 --- a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.stderr +++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.stderr @@ -1,10 +1,11 @@ error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args_panic.rs:11:5 + --> $DIR/uninlined_format_args_panic.rs:10:5 | LL | println!("val='{}'", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::uninlined-format-args` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::uninlined_format_args)]` help: change this to | LL - println!("val='{}'", var); @@ -12,7 +13,7 @@ LL + println!("val='{var}'"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args_panic.rs:14:9 + --> $DIR/uninlined_format_args_panic.rs:13:9 | LL | panic!("p1 {}", var); | ^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL + panic!("p1 {var}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args_panic.rs:17:9 + --> $DIR/uninlined_format_args_panic.rs:16:9 | LL | panic!("p2 {0}", var); | ^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +37,7 @@ LL + panic!("p2 {var}"); | error: variables can be used directly in the `format!` string - --> $DIR/uninlined_format_args_panic.rs:20:9 + --> $DIR/uninlined_format_args_panic.rs:19:9 | LL | panic!("p3 {var}", var = var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL + panic!("p3 {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:29:5 | LL | assert!(var == 1, "p5 {}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,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:31:5 + --> $DIR/uninlined_format_args_panic.rs:30:5 | LL | debug_assert!(var == 1, "p6 {}", var); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs b/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs index 83fbb9afd..fa594d9a9 100644 --- a/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs +++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs @@ -1,7 +1,6 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix #![warn(clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/unit_arg.rs b/src/tools/clippy/tests/ui/unit_arg.rs index fded8db5d..2e1390621 100644 --- a/src/tools/clippy/tests/ui/unit_arg.rs +++ b/src/tools/clippy/tests/ui/unit_arg.rs @@ -1,4 +1,5 @@ -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs +//@no-rustfix: overlapping suggestions #![warn(clippy::unit_arg)] #![allow(unused_must_use, unused_variables)] #![allow( diff --git a/src/tools/clippy/tests/ui/unit_arg.stderr b/src/tools/clippy/tests/ui/unit_arg.stderr index 74d4d2f40..8656c8fdd 100644 --- a/src/tools/clippy/tests/ui/unit_arg.stderr +++ b/src/tools/clippy/tests/ui/unit_arg.stderr @@ -1,5 +1,5 @@ error: passing a unit value to a function - --> $DIR/unit_arg.rs:62:5 + --> $DIR/unit_arg.rs:63:5 | LL | / foo({ LL | | 1; @@ -7,6 +7,7 @@ LL | | }); | |______^ | = note: `-D clippy::unit-arg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unit_arg)]` help: remove the semicolon from the last statement in the block | LL | 1 @@ -20,7 +21,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:65:5 + --> $DIR/unit_arg.rs:66:5 | LL | foo(foo(1)); | ^^^^^^^^^^^ @@ -32,7 +33,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({ LL | | foo(1); @@ -54,7 +55,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:71:5 + --> $DIR/unit_arg.rs:72:5 | LL | / b.bar({ LL | | 1; @@ -74,7 +75,7 @@ LL ~ b.bar(()); | error: passing unit values to a function - --> $DIR/unit_arg.rs:74:5 + --> $DIR/unit_arg.rs:75:5 | LL | taking_multiple_units(foo(0), foo(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -87,7 +88,7 @@ LL ~ taking_multiple_units((), ()); | error: passing unit values to a function - --> $DIR/unit_arg.rs:75:5 + --> $DIR/unit_arg.rs:76:5 | LL | / taking_multiple_units(foo(0), { LL | | foo(1); @@ -110,7 +111,7 @@ LL ~ taking_multiple_units((), ()); | error: passing unit values to a function - --> $DIR/unit_arg.rs:79:5 + --> $DIR/unit_arg.rs:80:5 | LL | / taking_multiple_units( LL | | { @@ -146,7 +147,7 @@ LL ~ ); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:90:13 + --> $DIR/unit_arg.rs:91:13 | LL | None.or(Some(foo(2))); | ^^^^^^^^^^^^ @@ -160,7 +161,7 @@ LL ~ }); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:93:5 + --> $DIR/unit_arg.rs:94:5 | LL | foo(foo(())); | ^^^^^^^^^^^^ @@ -172,7 +173,7 @@ LL ~ foo(()); | error: passing a unit value to a function - --> $DIR/unit_arg.rs:130:5 + --> $DIR/unit_arg.rs:131:5 | LL | Some(foo(1)) | ^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.fixed b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.fixed index 8c065115a..a947ded7b 100644 --- a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.fixed +++ b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unit_arg)] #![allow(unused_must_use, unused_variables)] #![allow(clippy::no_effect, clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs index af166b56f..058c4f84a 100644 --- a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs +++ b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unit_arg)] #![allow(unused_must_use, unused_variables)] #![allow(clippy::no_effect, clippy::uninlined_format_args)] diff --git a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.stderr b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.stderr index c697dfb1e..b207acb59 100644 --- a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.stderr +++ b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.stderr @@ -1,5 +1,5 @@ error: passing a unit value to a function - --> $DIR/unit_arg_empty_blocks.rs:17:5 + --> $DIR/unit_arg_empty_blocks.rs:16:5 | LL | foo({}); | ^^^^--^ @@ -7,9 +7,10 @@ LL | foo({}); | help: use a unit literal instead: `()` | = note: `-D clippy::unit-arg` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unit_arg)]` error: passing a unit value to a function - --> $DIR/unit_arg_empty_blocks.rs:18:5 + --> $DIR/unit_arg_empty_blocks.rs:17:5 | LL | foo3({}, 2, 2); | ^^^^^--^^^^^^^ @@ -17,7 +18,7 @@ LL | foo3({}, 2, 2); | help: use a unit literal instead: `()` error: passing unit values to a function - --> $DIR/unit_arg_empty_blocks.rs:19:5 + --> $DIR/unit_arg_empty_blocks.rs:18:5 | LL | taking_two_units({}, foo(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -29,7 +30,7 @@ LL ~ taking_two_units((), ()); | error: passing unit values to a function - --> $DIR/unit_arg_empty_blocks.rs:20:5 + --> $DIR/unit_arg_empty_blocks.rs:19:5 | LL | taking_three_units({}, foo(0), foo(1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unit_cmp.rs b/src/tools/clippy/tests/ui/unit_cmp.rs index fc75f548a..cea89026d 100644 --- a/src/tools/clippy/tests/ui/unit_cmp.rs +++ b/src/tools/clippy/tests/ui/unit_cmp.rs @@ -15,18 +15,22 @@ fn main() { // this warns if { + //~^ ERROR: ==-comparison of unit values detected. This will always be true + //~| NOTE: `-D clippy::unit-cmp` implied by `-D warnings` true; } == { false; } {} if { + //~^ ERROR: >-comparison of unit values detected. This will always be false true; } > { false; } {} assert_eq!( + //~^ ERROR: `assert_eq` of unit values detected. This will always succeed { true; }, @@ -35,6 +39,7 @@ fn main() { } ); debug_assert_eq!( + //~^ ERROR: `debug_assert_eq` of unit values detected. This will always succeed { true; }, @@ -44,6 +49,7 @@ fn main() { ); assert_ne!( + //~^ ERROR: `assert_ne` of unit values detected. This will always fail { true; }, @@ -52,6 +58,7 @@ fn main() { } ); debug_assert_ne!( + //~^ ERROR: `debug_assert_ne` of unit values detected. This will always fail { true; }, diff --git a/src/tools/clippy/tests/ui/unit_cmp.stderr b/src/tools/clippy/tests/ui/unit_cmp.stderr index 79c890d64..17355e237 100644 --- a/src/tools/clippy/tests/ui/unit_cmp.stderr +++ b/src/tools/clippy/tests/ui/unit_cmp.stderr @@ -3,6 +3,8 @@ error: ==-comparison of unit values detected. This will always be true | LL | if { | ________^ +LL | | +LL | | LL | | true; LL | | } == { LL | | false; @@ -10,12 +12,14 @@ LL | | } {} | |_____^ | = note: `-D clippy::unit-cmp` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unit_cmp)]` error: >-comparison of unit values detected. This will always be false - --> $DIR/unit_cmp.rs:23:8 + --> $DIR/unit_cmp.rs:25:8 | LL | if { | ________^ +LL | | LL | | true; LL | | } > { LL | | false; @@ -23,48 +27,48 @@ LL | | } {} | |_____^ error: `assert_eq` of unit values detected. This will always succeed - --> $DIR/unit_cmp.rs:29:5 + --> $DIR/unit_cmp.rs:32:5 | LL | / assert_eq!( +LL | | LL | | { LL | | true; -LL | | }, ... | LL | | } LL | | ); | |_____^ error: `debug_assert_eq` of unit values detected. This will always succeed - --> $DIR/unit_cmp.rs:37:5 + --> $DIR/unit_cmp.rs:41:5 | LL | / debug_assert_eq!( +LL | | LL | | { LL | | true; -LL | | }, ... | LL | | } LL | | ); | |_____^ error: `assert_ne` of unit values detected. This will always fail - --> $DIR/unit_cmp.rs:46:5 + --> $DIR/unit_cmp.rs:51:5 | LL | / assert_ne!( +LL | | LL | | { LL | | true; -LL | | }, ... | LL | | } LL | | ); | |_____^ error: `debug_assert_ne` of unit values detected. This will always fail - --> $DIR/unit_cmp.rs:54:5 + --> $DIR/unit_cmp.rs:60:5 | LL | / debug_assert_ne!( +LL | | LL | | { LL | | true; -LL | | }, ... | LL | | } LL | | ); diff --git a/src/tools/clippy/tests/ui/unit_hash.fixed b/src/tools/clippy/tests/ui/unit_hash.fixed new file mode 100644 index 000000000..ed0facf1b --- /dev/null +++ b/src/tools/clippy/tests/ui/unit_hash.fixed @@ -0,0 +1,34 @@ +#![warn(clippy::unit_hash)] +#![allow(clippy::let_unit_value)] + +use std::collections::hash_map::DefaultHasher; +use std::hash::Hash; + +enum Foo { + Empty, + WithValue(u8), +} + +fn do_nothing() {} + +fn main() { + let mut state = DefaultHasher::new(); + let my_enum = Foo::Empty; + + match my_enum { + Foo::Empty => 0_u8.hash(&mut state), + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op + Foo::WithValue(x) => x.hash(&mut state), + } + + let res = (); + 0_u8.hash(&mut state); + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op + + #[allow(clippy::unit_arg)] + 0_u8.hash(&mut state); + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op +} diff --git a/src/tools/clippy/tests/ui/unit_hash.rs b/src/tools/clippy/tests/ui/unit_hash.rs index 43eb54eff..f3636d164 100644 --- a/src/tools/clippy/tests/ui/unit_hash.rs +++ b/src/tools/clippy/tests/ui/unit_hash.rs @@ -17,12 +17,18 @@ fn main() { match my_enum { Foo::Empty => ().hash(&mut state), + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op Foo::WithValue(x) => x.hash(&mut state), } let res = (); res.hash(&mut state); + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op #[allow(clippy::unit_arg)] do_nothing().hash(&mut state); + //~^ ERROR: this call to `hash` on the unit type will do nothing + //~| NOTE: the implementation of `Hash` for `()` is a no-op } diff --git a/src/tools/clippy/tests/ui/unit_hash.stderr b/src/tools/clippy/tests/ui/unit_hash.stderr index 089d1212d..a26fd7344 100644 --- a/src/tools/clippy/tests/ui/unit_hash.stderr +++ b/src/tools/clippy/tests/ui/unit_hash.stderr @@ -6,9 +6,10 @@ LL | Foo::Empty => ().hash(&mut state), | = note: the implementation of `Hash` for `()` is a no-op = note: `-D clippy::unit-hash` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unit_hash)]` error: this call to `hash` on the unit type will do nothing - --> $DIR/unit_hash.rs:24:5 + --> $DIR/unit_hash.rs:26:5 | LL | res.hash(&mut state); | ^^^^^^^^^^^^^^^^^^^^ help: remove the call to `hash` or consider using: `0_u8.hash(&mut state)` @@ -16,7 +17,7 @@ LL | res.hash(&mut state); = note: the implementation of `Hash` for `()` is a no-op error: this call to `hash` on the unit type will do nothing - --> $DIR/unit_hash.rs:27:5 + --> $DIR/unit_hash.rs:31:5 | LL | do_nothing().hash(&mut state); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `hash` or consider using: `0_u8.hash(&mut state)` diff --git a/src/tools/clippy/tests/ui/unit_return_expecting_ord.rs b/src/tools/clippy/tests/ui/unit_return_expecting_ord.rs index f2a9694f9..59b2f7e35 100644 --- a/src/tools/clippy/tests/ui/unit_return_expecting_ord.rs +++ b/src/tools/clippy/tests/ui/unit_return_expecting_ord.rs @@ -17,13 +17,16 @@ fn unit(_i: isize) {} fn main() { let mut structs = vec![Struct { field: 2 }, Struct { field: 1 }]; structs.sort_by_key(|s| { + //~^ ERROR: this closure returns the unit type which also implements Ord double(s.field); }); structs.sort_by_key(|s| double(s.field)); structs.is_sorted_by_key(|s| { + //~^ ERROR: this closure returns the unit type which also implements PartialOrd double(s.field); }); structs.is_sorted_by_key(|s| { + //~^ ERROR: this closure returns the unit type which also implements PartialOrd if s.field > 0 { () } else { @@ -34,4 +37,5 @@ fn main() { return double(s.field); }); structs.sort_by_key(|s| unit(s.field)); + //~^ ERROR: this closure returns the unit type which also implements Ord } diff --git a/src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr b/src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr index 3a295af55..9220fb89e 100644 --- a/src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr +++ b/src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr @@ -5,32 +5,33 @@ LL | structs.sort_by_key(|s| { | ^^^ | help: probably caused by this trailing semicolon - --> $DIR/unit_return_expecting_ord.rs:20:24 + --> $DIR/unit_return_expecting_ord.rs:21:24 | LL | double(s.field); | ^ = note: `-D clippy::unit-return-expecting-ord` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unit_return_expecting_ord)]` error: this closure returns the unit type which also implements PartialOrd - --> $DIR/unit_return_expecting_ord.rs:23:30 + --> $DIR/unit_return_expecting_ord.rs:24:30 | LL | structs.is_sorted_by_key(|s| { | ^^^ | help: probably caused by this trailing semicolon - --> $DIR/unit_return_expecting_ord.rs:24:24 + --> $DIR/unit_return_expecting_ord.rs:26:24 | LL | double(s.field); | ^ error: this closure returns the unit type which also implements PartialOrd - --> $DIR/unit_return_expecting_ord.rs:26:30 + --> $DIR/unit_return_expecting_ord.rs:28:30 | LL | structs.is_sorted_by_key(|s| { | ^^^ error: this closure returns the unit type which also implements Ord - --> $DIR/unit_return_expecting_ord.rs:36:25 + --> $DIR/unit_return_expecting_ord.rs:39:25 | LL | structs.sort_by_key(|s| unit(s.field)); | ^^^ diff --git a/src/tools/clippy/tests/ui/unknown_attribute.rs b/src/tools/clippy/tests/ui/unknown_attribute.rs index e993e63f8..932f284d5 100644 --- a/src/tools/clippy/tests/ui/unknown_attribute.rs +++ b/src/tools/clippy/tests/ui/unknown_attribute.rs @@ -1,3 +1,4 @@ #[clippy::unknown] +//~^ ERROR: usage of unknown attribute #[clippy::cognitive_complexity = "1"] fn main() {} diff --git a/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed b/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed index debc7e152..cba32ce6b 100644 --- a/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed +++ b/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::pedantic)] // Should suggest lowercase #![allow(clippy::all)] diff --git a/src/tools/clippy/tests/ui/unknown_clippy_lints.rs b/src/tools/clippy/tests/ui/unknown_clippy_lints.rs index 16140fd10..c15d54197 100644 --- a/src/tools/clippy/tests/ui/unknown_clippy_lints.rs +++ b/src/tools/clippy/tests/ui/unknown_clippy_lints.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::pedantic)] // Should suggest lowercase #![allow(clippy::All)] diff --git a/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr b/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr index 880673eef..ee82db31c 100644 --- a/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr +++ b/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr @@ -1,49 +1,50 @@ error: unknown lint: `clippy::All` - --> $DIR/unknown_clippy_lints.rs:5:10 + --> $DIR/unknown_clippy_lints.rs:3:10 | LL | #![allow(clippy::All)] | ^^^^^^^^^^^ help: did you mean: `clippy::all` | = note: `-D unknown-lints` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(unknown_lints)]` error: unknown lint: `clippy::CMP_OWNED` - --> $DIR/unknown_clippy_lints.rs:6:9 + --> $DIR/unknown_clippy_lints.rs:4:9 | LL | #![warn(clippy::CMP_OWNED)] | ^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::cmp_owned` error: unknown lint: `clippy::if_not_els` - --> $DIR/unknown_clippy_lints.rs:9:8 + --> $DIR/unknown_clippy_lints.rs:7:8 | LL | #[warn(clippy::if_not_els)] | ^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::if_not_else` error: unknown lint: `clippy::UNNecsaRy_cAst` - --> $DIR/unknown_clippy_lints.rs:10:8 + --> $DIR/unknown_clippy_lints.rs:8:8 | LL | #[warn(clippy::UNNecsaRy_cAst)] | ^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::unnecessary_cast` error: unknown lint: `clippy::useles_transute` - --> $DIR/unknown_clippy_lints.rs:11:8 + --> $DIR/unknown_clippy_lints.rs:9:8 | LL | #[warn(clippy::useles_transute)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::useless_transmute` error: unknown lint: `clippy::dead_cod` - --> $DIR/unknown_clippy_lints.rs:13:8 + --> $DIR/unknown_clippy_lints.rs:11:8 | LL | #[warn(clippy::dead_cod)] | ^^^^^^^^^^^^^^^^ help: did you mean: `clippy::eq_op` error: unknown lint: `clippy::unused_colle` - --> $DIR/unknown_clippy_lints.rs:15:8 + --> $DIR/unknown_clippy_lints.rs:13:8 | LL | #[warn(clippy::unused_colle)] | ^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::unused_self` error: unknown lint: `clippy::const_static_lifetim` - --> $DIR/unknown_clippy_lints.rs:17:8 + --> $DIR/unknown_clippy_lints.rs:15:8 | LL | #[warn(clippy::const_static_lifetim)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::redundant_static_lifetimes` diff --git a/src/tools/clippy/tests/ui/unnecessary_box_returns.rs b/src/tools/clippy/tests/ui/unnecessary_box_returns.rs index ce7cc2e97..bcdaca33b 100644 --- a/src/tools/clippy/tests/ui/unnecessary_box_returns.rs +++ b/src/tools/clippy/tests/ui/unnecessary_box_returns.rs @@ -1,8 +1,9 @@ #![warn(clippy::unnecessary_box_returns)] - +//@no-rustfix trait Bar { // lint fn baz(&self) -> Box; + //~^ ERROR: boxed return of the sized type `usize` } pub struct Foo {} @@ -16,6 +17,7 @@ impl Bar for Foo { impl Foo { fn baz(&self) -> Box { + //~^ ERROR: boxed return of the sized type `usize` // lint Box::new(13) } @@ -23,11 +25,13 @@ impl Foo { // lint fn bxed_usize() -> Box { + //~^ ERROR: boxed return of the sized type `usize` Box::new(5) } // lint fn _bxed_foo() -> Box { + //~^ ERROR: boxed return of the sized type `Foo` Box::new(Foo {}) } diff --git a/src/tools/clippy/tests/ui/unnecessary_box_returns.stderr b/src/tools/clippy/tests/ui/unnecessary_box_returns.stderr index b17512c10..944e911fa 100644 --- a/src/tools/clippy/tests/ui/unnecessary_box_returns.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_box_returns.stderr @@ -6,9 +6,10 @@ LL | fn baz(&self) -> Box; | = help: changing this also requires a change to the return expressions in this function = note: `-D clippy::unnecessary-box-returns` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_box_returns)]` error: boxed return of the sized type `usize` - --> $DIR/unnecessary_box_returns.rs:18:22 + --> $DIR/unnecessary_box_returns.rs:19:22 | LL | fn baz(&self) -> Box { | ^^^^^^^^^^ help: try: `usize` @@ -16,7 +17,7 @@ LL | fn baz(&self) -> Box { = help: changing this also requires a change to the return expressions in this function error: boxed return of the sized type `usize` - --> $DIR/unnecessary_box_returns.rs:25:20 + --> $DIR/unnecessary_box_returns.rs:27:20 | LL | fn bxed_usize() -> Box { | ^^^^^^^^^^ help: try: `usize` @@ -24,7 +25,7 @@ LL | fn bxed_usize() -> Box { = help: changing this also requires a change to the return expressions in this function error: boxed return of the sized type `Foo` - --> $DIR/unnecessary_box_returns.rs:30:19 + --> $DIR/unnecessary_box_returns.rs:33:19 | LL | fn _bxed_foo() -> Box { | ^^^^^^^^ help: try: `Foo` diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.fixed b/src/tools/clippy/tests/ui/unnecessary_cast.fixed index 2bf02f134..18dd53bf2 100644 --- a/src/tools/clippy/tests/ui/unnecessary_cast.fixed +++ b/src/tools/clippy/tests/ui/unnecessary_cast.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:extern_fake_libc.rs #![warn(clippy::unnecessary_cast)] #![allow( diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.rs b/src/tools/clippy/tests/ui/unnecessary_cast.rs index 25b6b0f9b..fcdd4c60c 100644 --- a/src/tools/clippy/tests/ui/unnecessary_cast.rs +++ b/src/tools/clippy/tests/ui/unnecessary_cast.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:extern_fake_libc.rs #![warn(clippy::unnecessary_cast)] #![allow( diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.stderr b/src/tools/clippy/tests/ui/unnecessary_cast.stderr index 19411a01b..d4786f66e 100644 --- a/src/tools/clippy/tests/ui/unnecessary_cast.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_cast.stderr @@ -1,241 +1,242 @@ error: casting raw pointers to the same type and constness is unnecessary (`*const T` -> `*const T`) - --> $DIR/unnecessary_cast.rs:19:5 + --> $DIR/unnecessary_cast.rs:18:5 | LL | ptr as *const T | ^^^^^^^^^^^^^^^ help: try: `ptr` | = note: `-D clippy::unnecessary-cast` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_cast)]` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:54:5 + --> $DIR/unnecessary_cast.rs:53:5 | LL | 1i32 as i32; | ^^^^^^^^^^^ help: try: `1_i32` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:55:5 + --> $DIR/unnecessary_cast.rs:54:5 | LL | 1f32 as f32; | ^^^^^^^^^^^ help: try: `1_f32` error: casting to the same type is unnecessary (`bool` -> `bool`) - --> $DIR/unnecessary_cast.rs:56:5 + --> $DIR/unnecessary_cast.rs:55:5 | LL | false as bool; | ^^^^^^^^^^^^^ help: try: `false` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:59:5 + --> $DIR/unnecessary_cast.rs:58:5 | LL | -1_i32 as i32; | ^^^^^^^^^^^^^ help: try: `-1_i32` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:60:5 + --> $DIR/unnecessary_cast.rs:59:5 | LL | - 1_i32 as i32; | ^^^^^^^^^^^^^^ help: try: `- 1_i32` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:61:5 + --> $DIR/unnecessary_cast.rs:60:5 | LL | -1f32 as f32; | ^^^^^^^^^^^^ help: try: `-1_f32` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:62:5 + --> $DIR/unnecessary_cast.rs:61:5 | LL | 1_i32 as i32; | ^^^^^^^^^^^^ help: try: `1_i32` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:63:5 + --> $DIR/unnecessary_cast.rs:62:5 | LL | 1_f32 as f32; | ^^^^^^^^^^^^ help: try: `1_f32` error: casting raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`) - --> $DIR/unnecessary_cast.rs:65:22 + --> $DIR/unnecessary_cast.rs:64:22 | 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:67:5 + --> $DIR/unnecessary_cast.rs:66: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:69:5 + --> $DIR/unnecessary_cast.rs:68: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:80:5 + --> $DIR/unnecessary_cast.rs:79: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:81:5 + --> $DIR/unnecessary_cast.rs:80: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:83:5 + --> $DIR/unnecessary_cast.rs:82: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:118:5 + --> $DIR/unnecessary_cast.rs:117:5 | LL | aaa() as u32; | ^^^^^^^^^^^^ help: try: `aaa()` error: casting to the same type is unnecessary (`u32` -> `u32`) - --> $DIR/unnecessary_cast.rs:120:5 + --> $DIR/unnecessary_cast.rs:119:5 | LL | aaa() as u32; | ^^^^^^^^^^^^ help: try: `aaa()` error: casting integer literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:156:9 + --> $DIR/unnecessary_cast.rs:155:9 | LL | 100 as f32; | ^^^^^^^^^^ help: try: `100_f32` error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:157:9 + --> $DIR/unnecessary_cast.rs:156:9 | LL | 100 as f64; | ^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:158:9 + --> $DIR/unnecessary_cast.rs:157:9 | LL | 100_i32 as f64; | ^^^^^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:159:17 + --> $DIR/unnecessary_cast.rs:158:17 | LL | let _ = -100 as f32; | ^^^^^^^^^^^ help: try: `-100_f32` error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:160:17 + --> $DIR/unnecessary_cast.rs:159:17 | LL | let _ = -100 as f64; | ^^^^^^^^^^^ help: try: `-100_f64` error: casting integer literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:161:17 + --> $DIR/unnecessary_cast.rs:160:17 | LL | let _ = -100_i32 as f64; | ^^^^^^^^^^^^^^^ help: try: `-100_f64` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:162:9 + --> $DIR/unnecessary_cast.rs:161:9 | LL | 100. as f32; | ^^^^^^^^^^^ help: try: `100_f32` error: casting float literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:163:9 + --> $DIR/unnecessary_cast.rs:162:9 | LL | 100. as f64; | ^^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `u32` is unnecessary - --> $DIR/unnecessary_cast.rs:175:9 + --> $DIR/unnecessary_cast.rs:174:9 | LL | 1 as u32; | ^^^^^^^^ help: try: `1_u32` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:176:9 + --> $DIR/unnecessary_cast.rs:175:9 | LL | 0x10 as i32; | ^^^^^^^^^^^ help: try: `0x10_i32` error: casting integer literal to `usize` is unnecessary - --> $DIR/unnecessary_cast.rs:177:9 + --> $DIR/unnecessary_cast.rs:176:9 | LL | 0b10 as usize; | ^^^^^^^^^^^^^ help: try: `0b10_usize` error: casting integer literal to `u16` is unnecessary - --> $DIR/unnecessary_cast.rs:178:9 + --> $DIR/unnecessary_cast.rs:177:9 | LL | 0o73 as u16; | ^^^^^^^^^^^ help: try: `0o73_u16` error: casting integer literal to `u32` is unnecessary - --> $DIR/unnecessary_cast.rs:179:9 + --> $DIR/unnecessary_cast.rs:178: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:181:9 + --> $DIR/unnecessary_cast.rs:180:9 | LL | 1.0 as f64; | ^^^^^^^^^^ help: try: `1.0_f64` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:182:9 + --> $DIR/unnecessary_cast.rs:181:9 | LL | 0.5 as f32; | ^^^^^^^^^^ help: try: `0.5_f32` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:186:17 + --> $DIR/unnecessary_cast.rs:185:17 | LL | let _ = -1 as i32; | ^^^^^^^^^ help: try: `-1_i32` error: casting float literal to `f32` is unnecessary - --> $DIR/unnecessary_cast.rs:187:17 + --> $DIR/unnecessary_cast.rs:186: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:193:18 + --> $DIR/unnecessary_cast.rs:192:18 | LL | let _ = &(x as i32); | ^^^^^^^^^^ help: try: `{ x }` error: casting integer literal to `i32` is unnecessary - --> $DIR/unnecessary_cast.rs:199:22 + --> $DIR/unnecessary_cast.rs:198:22 | LL | let _: i32 = -(1) as i32; | ^^^^^^^^^^^ help: try: `-1_i32` error: casting integer literal to `i64` is unnecessary - --> $DIR/unnecessary_cast.rs:201:22 + --> $DIR/unnecessary_cast.rs:200:22 | LL | let _: i64 = -(1) as i64; | ^^^^^^^^^^^ help: try: `-1_i64` error: casting float literal to `f64` is unnecessary - --> $DIR/unnecessary_cast.rs:208:22 + --> $DIR/unnecessary_cast.rs:207: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:210:23 + --> $DIR/unnecessary_cast.rs:209: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:218:20 + --> $DIR/unnecessary_cast.rs:217:20 | LL | let _num = foo() as f32; | ^^^^^^^^^^^^ help: try: `foo()` diff --git a/src/tools/clippy/tests/ui/unnecessary_cast_unfixable.rs b/src/tools/clippy/tests/ui/unnecessary_cast_unfixable.rs index 0e027f604..36adf19c9 100644 --- a/src/tools/clippy/tests/ui/unnecessary_cast_unfixable.rs +++ b/src/tools/clippy/tests/ui/unnecessary_cast_unfixable.rs @@ -1,7 +1,9 @@ #![warn(clippy::unnecessary_cast)] - +//@no-rustfix fn main() { let _ = std::ptr::null() as *const u8; + //~^ ERROR: casting raw pointers to the same type and constness is unnecessary (`*cons + //~| NOTE: `-D clippy::unnecessary-cast` implied by `-D warnings` } mod issue11113 { @@ -17,6 +19,7 @@ mod issue11113 { impl TearOff { unsafe fn query(&self) { ((*(*(self.object as *mut *mut _) as *mut Vtbl)).query)() + //~^ ERROR: casting raw pointers to the same type and constness is unnecessary } } } diff --git a/src/tools/clippy/tests/ui/unnecessary_cast_unfixable.stderr b/src/tools/clippy/tests/ui/unnecessary_cast_unfixable.stderr index eecf24568..2d38a2a77 100644 --- a/src/tools/clippy/tests/ui/unnecessary_cast_unfixable.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_cast_unfixable.stderr @@ -5,9 +5,10 @@ LL | let _ = std::ptr::null() as *const u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::null()` | = note: `-D clippy::unnecessary-cast` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_cast)]` error: casting raw pointers to the same type and constness is unnecessary (`*mut issue11113::Vtbl` -> `*mut issue11113::Vtbl`) - --> $DIR/unnecessary_cast_unfixable.rs:19:16 + --> $DIR/unnecessary_cast_unfixable.rs:21:16 | LL | ((*(*(self.object as *mut *mut _) as *mut Vtbl)).query)() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `*(self.object as *mut *mut _)` diff --git a/src/tools/clippy/tests/ui/unnecessary_clone.rs b/src/tools/clippy/tests/ui/unnecessary_clone.rs index 7ceed3c75..12ac96aa6 100644 --- a/src/tools/clippy/tests/ui/unnecessary_clone.rs +++ b/src/tools/clippy/tests/ui/unnecessary_clone.rs @@ -2,7 +2,7 @@ #![warn(clippy::clone_on_ref_ptr)] #![allow(unused)] #![allow(clippy::redundant_clone, clippy::uninlined_format_args, clippy::unnecessary_wraps)] - +//@no-rustfix use std::cell::RefCell; use std::rc::{self, Rc}; use std::sync::{self, Arc}; @@ -21,25 +21,34 @@ fn clone_on_ref_ptr() { let arc_weak = Arc::downgrade(&arc); rc.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer + //~| NOTE: `-D clippy::clone-on-ref-ptr` implied by `-D warnings` Rc::clone(&rc); arc.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer Arc::clone(&arc); rcweak.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer rc::Weak::clone(&rcweak); arc_weak.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer sync::Weak::clone(&arc_weak); let x = Arc::new(SomeImpl); let _: Arc = x.clone(); + //~^ ERROR: using `.clone()` on a ref-counted pointer } fn clone_on_copy_generic(t: T) { t.clone(); + //~^ ERROR: using `clone` on type `T` which implements the `Copy` trait + //~| NOTE: `-D clippy::clone-on-copy` implied by `-D warnings` Some(t).clone(); + //~^ ERROR: using `clone` on type `Option` which implements the `Copy` trait } mod many_derefs { @@ -74,6 +83,7 @@ mod many_derefs { fn go1() { let a = A; let _: E = a.clone(); + //~^ ERROR: using `clone` on type `E` which implements the `Copy` trait let _: E = *****a; } } @@ -93,5 +103,6 @@ mod issue2076 { fn func() -> Option> { let rc = Rc::new(42); Some(try_opt!(Some(rc)).clone()) + //~^ ERROR: using `.clone()` on a ref-counted pointer } } diff --git a/src/tools/clippy/tests/ui/unnecessary_clone.stderr b/src/tools/clippy/tests/ui/unnecessary_clone.stderr index 23639f6d4..eab5f0423 100644 --- a/src/tools/clippy/tests/ui/unnecessary_clone.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_clone.stderr @@ -5,53 +5,55 @@ LL | rc.clone(); | ^^^^^^^^^^ help: try: `Rc::::clone(&rc)` | = note: `-D clippy::clone-on-ref-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::clone_on_ref_ptr)]` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:26:5 + --> $DIR/unnecessary_clone.rs:28:5 | LL | arc.clone(); | ^^^^^^^^^^^ help: try: `Arc::::clone(&arc)` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:29:5 + --> $DIR/unnecessary_clone.rs:32:5 | LL | rcweak.clone(); | ^^^^^^^^^^^^^^ help: try: `Weak::::clone(&rcweak)` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:32:5 + --> $DIR/unnecessary_clone.rs:36:5 | LL | arc_weak.clone(); | ^^^^^^^^^^^^^^^^ help: try: `Weak::::clone(&arc_weak)` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:36:33 + --> $DIR/unnecessary_clone.rs:41:33 | LL | let _: Arc = x.clone(); | ^^^^^^^^^ help: try: `Arc::::clone(&x)` error: using `clone` on type `T` which implements the `Copy` trait - --> $DIR/unnecessary_clone.rs:40:5 + --> $DIR/unnecessary_clone.rs:46:5 | LL | t.clone(); | ^^^^^^^^^ help: try removing the `clone` call: `t` | = note: `-D clippy::clone-on-copy` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::clone_on_copy)]` error: using `clone` on type `Option` which implements the `Copy` trait - --> $DIR/unnecessary_clone.rs:42:5 + --> $DIR/unnecessary_clone.rs:50:5 | LL | Some(t).clone(); | ^^^^^^^^^^^^^^^ help: try removing the `clone` call: `Some(t)` error: using `clone` on type `E` which implements the `Copy` trait - --> $DIR/unnecessary_clone.rs:76:20 + --> $DIR/unnecessary_clone.rs:85:20 | LL | let _: E = a.clone(); | ^^^^^^^^^ help: try dereferencing it: `*****a` error: using `.clone()` on a ref-counted pointer - --> $DIR/unnecessary_clone.rs:95:14 + --> $DIR/unnecessary_clone.rs:105:14 | LL | Some(try_opt!(Some(rc)).clone()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Rc::::clone(&try_opt!(Some(rc)))` diff --git a/src/tools/clippy/tests/ui/unnecessary_filter_map.rs b/src/tools/clippy/tests/ui/unnecessary_filter_map.rs index 3c8c6ec94..1e0d7d129 100644 --- a/src/tools/clippy/tests/ui/unnecessary_filter_map.rs +++ b/src/tools/clippy/tests/ui/unnecessary_filter_map.rs @@ -2,18 +2,23 @@ fn main() { let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); + //~^ ERROR: this `.filter_map` can be written more simply using `.filter` + //~| NOTE: `-D clippy::unnecessary-filter-map` implied by `-D warnings` let _ = (0..4).filter_map(|x| { + //~^ ERROR: this `.filter_map` can be written more simply using `.filter` if x > 1 { return Some(x); }; None }); let _ = (0..4).filter_map(|x| match x { + //~^ ERROR: this `.filter_map` can be written more simply using `.filter` 0 | 1 => None, _ => Some(x), }); let _ = (0..4).filter_map(|x| Some(x + 1)); + //~^ ERROR: this `.filter_map` can be written more simply using `.map` let _ = (0..4).filter_map(i32::checked_abs); } diff --git a/src/tools/clippy/tests/ui/unnecessary_filter_map.stderr b/src/tools/clippy/tests/ui/unnecessary_filter_map.stderr index 2d5403ce3..0dd65f652 100644 --- a/src/tools/clippy/tests/ui/unnecessary_filter_map.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_filter_map.stderr @@ -5,12 +5,14 @@ LL | let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unnecessary-filter-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_filter_map)]` error: this `.filter_map` can be written more simply using `.filter` - --> $DIR/unnecessary_filter_map.rs:5:13 + --> $DIR/unnecessary_filter_map.rs:7:13 | LL | let _ = (0..4).filter_map(|x| { | _____________^ +LL | | LL | | if x > 1 { LL | | return Some(x); LL | | }; @@ -19,23 +21,24 @@ LL | | }); | |______^ error: this `.filter_map` can be written more simply using `.filter` - --> $DIR/unnecessary_filter_map.rs:11:13 + --> $DIR/unnecessary_filter_map.rs:14:13 | LL | let _ = (0..4).filter_map(|x| match x { | _____________^ +LL | | LL | | 0 | 1 => None, LL | | _ => Some(x), LL | | }); | |______^ error: this `.filter_map` can be written more simply using `.map` - --> $DIR/unnecessary_filter_map.rs:16:13 + --> $DIR/unnecessary_filter_map.rs:20:13 | LL | let _ = (0..4).filter_map(|x| Some(x + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `.filter_map` can be written more simply using `.filter` - --> $DIR/unnecessary_filter_map.rs:155:14 + --> $DIR/unnecessary_filter_map.rs:160:14 | LL | let _x = std::iter::once(1).filter_map(|n| (n > 1).then_some(n)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unnecessary_find_map.rs b/src/tools/clippy/tests/ui/unnecessary_find_map.rs index 2c228fbbc..9972b6809 100644 --- a/src/tools/clippy/tests/ui/unnecessary_find_map.rs +++ b/src/tools/clippy/tests/ui/unnecessary_find_map.rs @@ -2,18 +2,23 @@ fn main() { let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None }); + //~^ ERROR: this `.find_map` can be written more simply using `.find` + //~| NOTE: `-D clippy::unnecessary-find-map` implied by `-D warnings` let _ = (0..4).find_map(|x| { + //~^ ERROR: this `.find_map` can be written more simply using `.find` if x > 1 { return Some(x); }; None }); let _ = (0..4).find_map(|x| match x { + //~^ ERROR: this `.find_map` can be written more simply using `.find` 0 | 1 => None, _ => Some(x), }); let _ = (0..4).find_map(|x| Some(x + 1)); + //~^ ERROR: this `.find_map` can be written more simply using `.map(..).next()` let _ = (0..4).find_map(i32::checked_abs); } diff --git a/src/tools/clippy/tests/ui/unnecessary_find_map.stderr b/src/tools/clippy/tests/ui/unnecessary_find_map.stderr index 3a995b41b..662623fb6 100644 --- a/src/tools/clippy/tests/ui/unnecessary_find_map.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_find_map.stderr @@ -5,12 +5,14 @@ LL | let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unnecessary-find-map` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_find_map)]` error: this `.find_map` can be written more simply using `.find` - --> $DIR/unnecessary_find_map.rs:5:13 + --> $DIR/unnecessary_find_map.rs:7:13 | LL | let _ = (0..4).find_map(|x| { | _____________^ +LL | | LL | | if x > 1 { LL | | return Some(x); LL | | }; @@ -19,23 +21,24 @@ LL | | }); | |______^ error: this `.find_map` can be written more simply using `.find` - --> $DIR/unnecessary_find_map.rs:11:13 + --> $DIR/unnecessary_find_map.rs:14:13 | LL | let _ = (0..4).find_map(|x| match x { | _____________^ +LL | | LL | | 0 | 1 => None, LL | | _ => Some(x), LL | | }); | |______^ error: this `.find_map` can be written more simply using `.map(..).next()` - --> $DIR/unnecessary_find_map.rs:16:13 + --> $DIR/unnecessary_find_map.rs:20:13 | LL | let _ = (0..4).find_map(|x| Some(x + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this `.find_map` can be written more simply using `.find` - --> $DIR/unnecessary_find_map.rs:27:14 + --> $DIR/unnecessary_find_map.rs:32:14 | LL | let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unnecessary_fold.fixed b/src/tools/clippy/tests/ui/unnecessary_fold.fixed index bd1d4a152..c884d26eb 100644 --- a/src/tools/clippy/tests/ui/unnecessary_fold.fixed +++ b/src/tools/clippy/tests/ui/unnecessary_fold.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] /// Calls which should trigger the `UNNECESSARY_FOLD` lint diff --git a/src/tools/clippy/tests/ui/unnecessary_fold.rs b/src/tools/clippy/tests/ui/unnecessary_fold.rs index d27cc460c..2e6d6ba52 100644 --- a/src/tools/clippy/tests/ui/unnecessary_fold.rs +++ b/src/tools/clippy/tests/ui/unnecessary_fold.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] /// Calls which should trigger the `UNNECESSARY_FOLD` lint diff --git a/src/tools/clippy/tests/ui/unnecessary_fold.stderr b/src/tools/clippy/tests/ui/unnecessary_fold.stderr index 98979f747..f0d039638 100644 --- a/src/tools/clippy/tests/ui/unnecessary_fold.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_fold.stderr @@ -1,91 +1,92 @@ error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:8:20 + --> $DIR/unnecessary_fold.rs:6:20 | LL | let _ = (0..3).fold(false, |acc, x| acc || x > 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `any(|x| x > 2)` | = note: `-D clippy::unnecessary-fold` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_fold)]` error: this `.fold` can be written more succinctly using another method - --> $DIR/unnecessary_fold.rs:10:20 + --> $DIR/unnecessary_fold.rs:8: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:12:25 + --> $DIR/unnecessary_fold.rs:10: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:14:25 + --> $DIR/unnecessary_fold.rs:12: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:19:41 + --> $DIR/unnecessary_fold.rs:17: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:49:10 + --> $DIR/unnecessary_fold.rs:47: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:60:33 + --> $DIR/unnecessary_fold.rs:58: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:63:30 + --> $DIR/unnecessary_fold.rs:61: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:64:30 + --> $DIR/unnecessary_fold.rs:62: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:65:35 + --> $DIR/unnecessary_fold.rs:63: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:66:35 + --> $DIR/unnecessary_fold.rs:64: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:67:31 + --> $DIR/unnecessary_fold.rs:65: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:68:31 + --> $DIR/unnecessary_fold.rs:66: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:69:26 + --> $DIR/unnecessary_fold.rs:67: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:70:26 + --> $DIR/unnecessary_fold.rs:68:26 | LL | num(map.values().fold(1, |x, y| x * y)); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `product()` diff --git a/src/tools/clippy/tests/ui/unnecessary_iter_cloned.fixed b/src/tools/clippy/tests/ui/unnecessary_iter_cloned.fixed index a0f8dd1a2..ad0e5fab0 100644 --- a/src/tools/clippy/tests/ui/unnecessary_iter_cloned.fixed +++ b/src/tools/clippy/tests/ui/unnecessary_iter_cloned.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_assignments)] #![warn(clippy::unnecessary_to_owned)] diff --git a/src/tools/clippy/tests/ui/unnecessary_iter_cloned.rs b/src/tools/clippy/tests/ui/unnecessary_iter_cloned.rs index 98f2dfe75..d3d59c4c7 100644 --- a/src/tools/clippy/tests/ui/unnecessary_iter_cloned.rs +++ b/src/tools/clippy/tests/ui/unnecessary_iter_cloned.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_assignments)] #![warn(clippy::unnecessary_to_owned)] diff --git a/src/tools/clippy/tests/ui/unnecessary_iter_cloned.stderr b/src/tools/clippy/tests/ui/unnecessary_iter_cloned.stderr index 8f151e620..ba40c6c14 100644 --- a/src/tools/clippy/tests/ui/unnecessary_iter_cloned.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_iter_cloned.stderr @@ -1,10 +1,11 @@ error: unnecessary use of `copied` - --> $DIR/unnecessary_iter_cloned.rs:31:22 + --> $DIR/unnecessary_iter_cloned.rs:29:22 | LL | for (t, path) in files.iter().copied() { | ^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unnecessary-to-owned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_to_owned)]` help: use | LL | for (t, path) in files { @@ -16,7 +17,7 @@ LL + let other = match get_file_path(t) { | error: unnecessary use of `copied` - --> $DIR/unnecessary_iter_cloned.rs:46:22 + --> $DIR/unnecessary_iter_cloned.rs:44:22 | LL | for (t, path) in files.iter().copied() { | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unnecessary_join.fixed b/src/tools/clippy/tests/ui/unnecessary_join.fixed index f13a5275e..dab09be7e 100644 --- a/src/tools/clippy/tests/ui/unnecessary_join.fixed +++ b/src/tools/clippy/tests/ui/unnecessary_join.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unnecessary_join)] #![allow(clippy::uninlined_format_args, clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/unnecessary_join.rs b/src/tools/clippy/tests/ui/unnecessary_join.rs index 6014d723a..d042d9e5c 100644 --- a/src/tools/clippy/tests/ui/unnecessary_join.rs +++ b/src/tools/clippy/tests/ui/unnecessary_join.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unnecessary_join)] #![allow(clippy::uninlined_format_args, clippy::useless_vec)] diff --git a/src/tools/clippy/tests/ui/unnecessary_join.stderr b/src/tools/clippy/tests/ui/unnecessary_join.stderr index e919a6d1d..8bf2ac5fd 100644 --- a/src/tools/clippy/tests/ui/unnecessary_join.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_join.stderr @@ -1,5 +1,5 @@ error: called `.collect::>().join("")` on an iterator - --> $DIR/unnecessary_join.rs:11:10 + --> $DIR/unnecessary_join.rs:10:10 | LL | .collect::>() | __________^ @@ -7,9 +7,10 @@ LL | | .join(""); | |_________________^ help: try using: `collect::()` | = note: `-D clippy::unnecessary-join` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_join)]` error: called `.collect::>().join("")` on an iterator - --> $DIR/unnecessary_join.rs:20:10 + --> $DIR/unnecessary_join.rs:19:10 | LL | .collect::>() | __________^ diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed index dca380341..304e7b7fd 100644 --- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed +++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![warn(clippy::unnecessary_lazy_evaluations)] #![allow(clippy::redundant_closure)] #![allow(clippy::bind_instead_of_map)] diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs index 7fda719ed..ddfa6bb3e 100644 --- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs +++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build: proc_macros.rs:proc-macro +//@aux-build: proc_macros.rs #![warn(clippy::unnecessary_lazy_evaluations)] #![allow(clippy::redundant_closure)] #![allow(clippy::bind_instead_of_map)] diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr index 458eed1f3..4f1ca3748 100644 --- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr @@ -1,5 +1,5 @@ error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:69:13 + --> $DIR/unnecessary_lazy_eval.rs:68:13 | LL | let _ = opt.unwrap_or_else(|| 2); | ^^^^-------------------- @@ -7,9 +7,10 @@ LL | let _ = opt.unwrap_or_else(|| 2); | help: use `unwrap_or(..)` instead: `unwrap_or(2)` | = note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings` + = 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:70:13 + --> $DIR/unnecessary_lazy_eval.rs:69:13 | LL | let _ = opt.unwrap_or_else(|| astronomers_pi); | ^^^^--------------------------------- @@ -17,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:71:13 + --> $DIR/unnecessary_lazy_eval.rs:70:13 | LL | let _ = opt.unwrap_or_else(|| ext_str.some_field); | ^^^^------------------------------------- @@ -25,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:73:13 + --> $DIR/unnecessary_lazy_eval.rs:72:13 | LL | let _ = opt.and_then(|_| ext_opt); | ^^^^--------------------- @@ -33,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:74:13 + --> $DIR/unnecessary_lazy_eval.rs:73:13 | LL | let _ = opt.or_else(|| ext_opt); | ^^^^------------------- @@ -41,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:75:13 + --> $DIR/unnecessary_lazy_eval.rs:74:13 | LL | let _ = opt.or_else(|| None); | ^^^^---------------- @@ -49,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:76:13 + --> $DIR/unnecessary_lazy_eval.rs:75:13 | LL | let _ = opt.get_or_insert_with(|| 2); | ^^^^------------------------ @@ -57,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:77:13 + --> $DIR/unnecessary_lazy_eval.rs:76:13 | LL | let _ = opt.ok_or_else(|| 2); | ^^^^---------------- @@ -65,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:78:13 + --> $DIR/unnecessary_lazy_eval.rs:77:13 | LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2))); | ^^^^^^^^^^^^^^^^^------------------------------- @@ -73,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:79:13 + --> $DIR/unnecessary_lazy_eval.rs:78:13 | LL | let _ = cond.then(|| astronomers_pi); | ^^^^^----------------------- @@ -81,7 +82,7 @@ LL | let _ = cond.then(|| astronomers_pi); | help: use `then_some(..)` instead: `then_some(astronomers_pi)` error: unnecessary closure used to substitute value for `Option::None` - --> $DIR/unnecessary_lazy_eval.rs:83:13 + --> $DIR/unnecessary_lazy_eval.rs:82:13 | LL | let _ = Some(1).unwrap_or_else(|| *r); | ^^^^^^^^--------------------- @@ -89,7 +90,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:85:13 + --> $DIR/unnecessary_lazy_eval.rs:84:13 | LL | let _ = Some(1).unwrap_or_else(|| *b); | ^^^^^^^^--------------------- @@ -97,7 +98,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:87:13 + --> $DIR/unnecessary_lazy_eval.rs:86:13 | LL | let _ = Some(1).as_ref().unwrap_or_else(|| &r); | ^^^^^^^^^^^^^^^^^--------------------- @@ -105,7 +106,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:88:13 + --> $DIR/unnecessary_lazy_eval.rs:87:13 | LL | let _ = Some(1).as_ref().unwrap_or_else(|| &b); | ^^^^^^^^^^^^^^^^^--------------------- @@ -113,7 +114,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:91:13 + --> $DIR/unnecessary_lazy_eval.rs:90:13 | LL | let _ = Some(10).unwrap_or_else(|| 2); | ^^^^^^^^^-------------------- @@ -121,7 +122,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:92:13 + --> $DIR/unnecessary_lazy_eval.rs:91:13 | LL | let _ = Some(10).and_then(|_| ext_opt); | ^^^^^^^^^--------------------- @@ -129,7 +130,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:93:28 + --> $DIR/unnecessary_lazy_eval.rs:92:28 | LL | let _: Option = None.or_else(|| ext_opt); | ^^^^^------------------- @@ -137,7 +138,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:94:13 + --> $DIR/unnecessary_lazy_eval.rs:93:13 | LL | let _ = None.get_or_insert_with(|| 2); | ^^^^^------------------------ @@ -145,7 +146,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:95:35 + --> $DIR/unnecessary_lazy_eval.rs:94:35 | LL | let _: Result = None.ok_or_else(|| 2); | ^^^^^---------------- @@ -153,7 +154,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:96:28 + --> $DIR/unnecessary_lazy_eval.rs:95:28 | LL | let _: Option = None.or_else(|| None); | ^^^^^---------------- @@ -161,7 +162,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:99:13 + --> $DIR/unnecessary_lazy_eval.rs:98:13 | LL | let _ = deep.0.unwrap_or_else(|| 2); | ^^^^^^^-------------------- @@ -169,7 +170,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:100:13 + --> $DIR/unnecessary_lazy_eval.rs:99:13 | LL | let _ = deep.0.and_then(|_| ext_opt); | ^^^^^^^--------------------- @@ -177,7 +178,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:101:13 + --> $DIR/unnecessary_lazy_eval.rs:100:13 | LL | let _ = deep.0.or_else(|| None); | ^^^^^^^---------------- @@ -185,7 +186,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:102:13 + --> $DIR/unnecessary_lazy_eval.rs:101:13 | LL | let _ = deep.0.get_or_insert_with(|| 2); | ^^^^^^^------------------------ @@ -193,7 +194,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:103:13 + --> $DIR/unnecessary_lazy_eval.rs:102:13 | LL | let _ = deep.0.ok_or_else(|| 2); | ^^^^^^^---------------- @@ -201,7 +202,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:133:28 + --> $DIR/unnecessary_lazy_eval.rs:132:28 | LL | let _: Option = None.or_else(|| Some(3)); | ^^^^^------------------- @@ -209,7 +210,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:134:13 + --> $DIR/unnecessary_lazy_eval.rs:133:13 | LL | let _ = deep.0.or_else(|| Some(3)); | ^^^^^^^------------------- @@ -217,7 +218,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:135:13 + --> $DIR/unnecessary_lazy_eval.rs:134:13 | LL | let _ = opt.or_else(|| Some(3)); | ^^^^------------------- @@ -225,7 +226,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:141:13 + --> $DIR/unnecessary_lazy_eval.rs:140:13 | LL | let _ = res2.unwrap_or_else(|_| 2); | ^^^^^--------------------- @@ -233,7 +234,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:142:13 + --> $DIR/unnecessary_lazy_eval.rs:141:13 | LL | let _ = res2.unwrap_or_else(|_| astronomers_pi); | ^^^^^---------------------------------- @@ -241,7 +242,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:143:13 + --> $DIR/unnecessary_lazy_eval.rs:142:13 | LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field); | ^^^^^-------------------------------------- @@ -249,7 +250,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:165:35 + --> $DIR/unnecessary_lazy_eval.rs:164:35 | LL | let _: Result = res.and_then(|_| Err(2)); | ^^^^-------------------- @@ -257,7 +258,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:166:35 + --> $DIR/unnecessary_lazy_eval.rs:165:35 | LL | let _: Result = res.and_then(|_| Err(astronomers_pi)); | ^^^^--------------------------------- @@ -265,7 +266,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:167:35 + --> $DIR/unnecessary_lazy_eval.rs:166:35 | LL | let _: Result = res.and_then(|_| Err(ext_str.some_field)); | ^^^^------------------------------------- @@ -273,7 +274,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:169:35 + --> $DIR/unnecessary_lazy_eval.rs:168:35 | LL | let _: Result = res.or_else(|_| Ok(2)); | ^^^^------------------ @@ -281,7 +282,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:170:35 + --> $DIR/unnecessary_lazy_eval.rs:169:35 | LL | let _: Result = res.or_else(|_| Ok(astronomers_pi)); | ^^^^------------------------------- @@ -289,7 +290,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:171:35 + --> $DIR/unnecessary_lazy_eval.rs:170:35 | LL | let _: Result = res.or_else(|_| Ok(ext_str.some_field)); | ^^^^----------------------------------- @@ -297,7 +298,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:172:35 + --> $DIR/unnecessary_lazy_eval.rs:171:35 | LL | let _: Result = res. | ___________________________________^ diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.rs b/src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.rs index b4a1f8167..33685bfb7 100644 --- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.rs +++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.rs @@ -1,6 +1,6 @@ #![warn(clippy::unnecessary_lazy_evaluations)] #![allow(clippy::unnecessary_literal_unwrap)] - +//@no-rustfix struct Deep(Option); #[derive(Copy, Clone)] @@ -11,11 +11,15 @@ struct SomeStruct { fn main() { // fix will break type inference let _ = Ok(1).unwrap_or_else(|()| 2); + //~^ ERROR: unnecessary closure used to substitute value for `Result::Err` + //~| NOTE: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings` mod e { pub struct E; } let _ = Ok(1).unwrap_or_else(|e::E| 2); + //~^ ERROR: unnecessary closure used to substitute value for `Result::Err` let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); + //~^ ERROR: unnecessary closure used to substitute value for `Result::Err` // Fix #6343 let arr = [(Some(1),)]; diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.stderr b/src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.stderr index 7f353ba06..27fa560d4 100644 --- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.stderr @@ -7,9 +7,10 @@ LL | let _ = Ok(1).unwrap_or_else(|()| 2); | help: use `unwrap_or(..)` instead: `unwrap_or(2)` | = note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_lazy_evaluations)]` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval_unfixable.rs:17:13 + --> $DIR/unnecessary_lazy_eval_unfixable.rs:19:13 | LL | let _ = Ok(1).unwrap_or_else(|e::E| 2); | ^^^^^^------------------------ @@ -17,7 +18,7 @@ LL | let _ = Ok(1).unwrap_or_else(|e::E| 2); | help: use `unwrap_or(..)` instead: `unwrap_or(2)` error: unnecessary closure used to substitute value for `Result::Err` - --> $DIR/unnecessary_lazy_eval_unfixable.rs:18:13 + --> $DIR/unnecessary_lazy_eval_unfixable.rs:21:13 | LL | let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); | ^^^^^^------------------------------------- diff --git a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.fixed b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.fixed index 72d52c623..87df1f8cb 100644 --- a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.fixed +++ b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unnecessary_literal_unwrap)] #![allow(unreachable_code)] #![allow( diff --git a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.rs b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.rs index 7d713ea20..7bd8deea4 100644 --- a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.rs +++ b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unnecessary_literal_unwrap)] #![allow(unreachable_code)] #![allow( diff --git a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.stderr b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.stderr index 7f603d6ef..013907f59 100644 --- a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.stderr @@ -1,10 +1,11 @@ error: used `unwrap()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:12:16 + --> $DIR/unnecessary_literal_unwrap.rs:11:16 | LL | let _val = Some(1).unwrap(); | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_literal_unwrap)]` help: remove the `Some` and `unwrap()` | LL - let _val = Some(1).unwrap(); @@ -12,7 +13,7 @@ LL + let _val = 1; | error: used `expect()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:13:16 + --> $DIR/unnecessary_literal_unwrap.rs:12:16 | LL | let _val = Some(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL + let _val = 1; | error: used `unwrap()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:15:5 + --> $DIR/unnecessary_literal_unwrap.rs:14:5 | LL | Some(1).unwrap(); | ^^^^^^^^^^^^^^^^ @@ -36,7 +37,7 @@ LL + 1; | error: used `expect()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:16:5 + --> $DIR/unnecessary_literal_unwrap.rs:15:5 | LL | Some(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -48,13 +49,13 @@ LL + 1; | error: used `unwrap()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:21:16 + --> $DIR/unnecessary_literal_unwrap.rs:20:16 | LL | let _val = None::<()>.unwrap(); | ^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()` error: used `expect()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:22:16 + --> $DIR/unnecessary_literal_unwrap.rs:21:16 | LL | let _val = None::<()>.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -65,13 +66,13 @@ LL | let _val = panic!("this always happens"); | ~~~~~~~ ~ error: used `unwrap_or_default()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:23:24 + --> $DIR/unnecessary_literal_unwrap.rs:22: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:24:21 + --> $DIR/unnecessary_literal_unwrap.rs:23:21 | LL | let _val: u16 = None.unwrap_or(234); | ^^^^^^^^^^^^^^^^^^^ @@ -83,7 +84,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:24:21 | LL | let _val: u16 = None.unwrap_or_else(|| 234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +96,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:25:21 | LL | let _val: u16 = None.unwrap_or_else(|| { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -107,7 +108,7 @@ LL + let _val: u16 = { 234 }; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:27:21 + --> $DIR/unnecessary_literal_unwrap.rs:26:21 | LL | let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -119,13 +120,13 @@ LL + let _val: u16 = { 234 }; | error: used `unwrap()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:29:5 + --> $DIR/unnecessary_literal_unwrap.rs:28:5 | LL | None::<()>.unwrap(); | ^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()` error: used `expect()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:30:5 + --> $DIR/unnecessary_literal_unwrap.rs:29:5 | LL | None::<()>.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -136,13 +137,13 @@ LL | panic!("this always happens"); | ~~~~~~~ ~ error: used `unwrap_or_default()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:31:5 + --> $DIR/unnecessary_literal_unwrap.rs:30: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:32:5 + --> $DIR/unnecessary_literal_unwrap.rs:31:5 | LL | None::.unwrap_or(234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +155,7 @@ LL + 234; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:33:5 + --> $DIR/unnecessary_literal_unwrap.rs:32:5 | LL | None::.unwrap_or_else(|| 234); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -166,7 +167,7 @@ LL + 234; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:34:5 + --> $DIR/unnecessary_literal_unwrap.rs:33:5 | LL | None::.unwrap_or_else(|| { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -178,7 +179,7 @@ LL + { 234 }; | error: used `unwrap_or_else()` on `None` value - --> $DIR/unnecessary_literal_unwrap.rs:35:5 + --> $DIR/unnecessary_literal_unwrap.rs:34:5 | LL | None::.unwrap_or_else(|| -> u16 { 234 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -190,7 +191,7 @@ LL + { 234 }; | error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:39:16 + --> $DIR/unnecessary_literal_unwrap.rs:38:16 | LL | let _val = Ok::<_, ()>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -202,7 +203,7 @@ LL + let _val = 1; | error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:40:16 + --> $DIR/unnecessary_literal_unwrap.rs:39:16 | LL | let _val = Ok::<_, ()>(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -214,7 +215,7 @@ LL + let _val = 1; | error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:41:16 + --> $DIR/unnecessary_literal_unwrap.rs:40:16 | LL | let _val = Ok::<_, ()>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -225,7 +226,7 @@ LL | let _val = panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:42:16 + --> $DIR/unnecessary_literal_unwrap.rs:41:16 | LL | let _val = Ok::<_, ()>(1).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -236,7 +237,7 @@ LL | let _val = panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:44:5 + --> $DIR/unnecessary_literal_unwrap.rs:43:5 | LL | Ok::<_, ()>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -248,7 +249,7 @@ LL + 1; | error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:45:5 + --> $DIR/unnecessary_literal_unwrap.rs:44:5 | LL | Ok::<_, ()>(1).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -260,7 +261,7 @@ LL + 1; | error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:46:5 + --> $DIR/unnecessary_literal_unwrap.rs:45:5 | LL | Ok::<_, ()>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -271,7 +272,7 @@ LL | panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:47:5 + --> $DIR/unnecessary_literal_unwrap.rs:46:5 | LL | Ok::<_, ()>(1).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -282,7 +283,7 @@ LL | panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:51:16 + --> $DIR/unnecessary_literal_unwrap.rs:50:16 | LL | let _val = Err::<(), _>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -294,7 +295,7 @@ LL + let _val = 1; | error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:52:16 + --> $DIR/unnecessary_literal_unwrap.rs:51:16 | LL | let _val = Err::<(), _>(1).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -306,7 +307,7 @@ LL + let _val = 1; | error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:53:16 + --> $DIR/unnecessary_literal_unwrap.rs:52:16 | LL | let _val = Err::<(), _>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -317,7 +318,7 @@ LL | let _val = panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:54:16 + --> $DIR/unnecessary_literal_unwrap.rs:53:16 | LL | let _val = Err::<(), _>(1).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -328,7 +329,7 @@ LL | let _val = panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:56:5 + --> $DIR/unnecessary_literal_unwrap.rs:55:5 | LL | Err::<(), _>(1).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -340,7 +341,7 @@ LL + 1; | error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:57:5 + --> $DIR/unnecessary_literal_unwrap.rs:56:5 | LL | Err::<(), _>(1).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -352,7 +353,7 @@ LL + 1; | error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:58:5 + --> $DIR/unnecessary_literal_unwrap.rs:57:5 | LL | Err::<(), _>(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -363,7 +364,7 @@ LL | panic!("{:?}", 1); | ~~~~~~~~~~~~~~ ~ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:59:5 + --> $DIR/unnecessary_literal_unwrap.rs:58:5 | LL | Err::<(), _>(1).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -374,7 +375,7 @@ LL | panic!("{1}: {:?}", 1, "this always happens"); | ~~~~~~~~~~~~~~~~~~~ ~ error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:63:16 + --> $DIR/unnecessary_literal_unwrap.rs:62:16 | LL | let _val = Some(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^ @@ -386,7 +387,7 @@ LL + let _val = 1; | error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:64:16 + --> $DIR/unnecessary_literal_unwrap.rs:63:16 | LL | let _val = Some(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -398,7 +399,7 @@ LL + let _val = 1; | error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:65:16 + --> $DIR/unnecessary_literal_unwrap.rs:64:16 | LL | let _val = Some(1).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -410,7 +411,7 @@ LL + let _val = 1; | error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:67:5 + --> $DIR/unnecessary_literal_unwrap.rs:66:5 | LL | Some(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^ @@ -422,7 +423,7 @@ LL + 1; | error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:68:5 + --> $DIR/unnecessary_literal_unwrap.rs:67:5 | LL | Some(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -434,7 +435,7 @@ LL + 1; | error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:69:5 + --> $DIR/unnecessary_literal_unwrap.rs:68:5 | LL | Some(1).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -446,7 +447,7 @@ LL + 1; | error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:73:16 + --> $DIR/unnecessary_literal_unwrap.rs:72:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -458,7 +459,7 @@ LL + let _val = 1; | error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:74:16 + --> $DIR/unnecessary_literal_unwrap.rs:73:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -470,7 +471,7 @@ LL + let _val = 1; | error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:75:16 + --> $DIR/unnecessary_literal_unwrap.rs:74:16 | LL | let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -482,7 +483,7 @@ LL + let _val = 1; | error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:77:5 + --> $DIR/unnecessary_literal_unwrap.rs:76:5 | LL | Ok::<_, ()>(1).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -494,7 +495,7 @@ LL + 1; | error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:78:5 + --> $DIR/unnecessary_literal_unwrap.rs:77:5 | LL | Ok::<_, ()>(1).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -506,7 +507,7 @@ LL + 1; | error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:79:5 + --> $DIR/unnecessary_literal_unwrap.rs:78:5 | LL | Ok::<_, ()>(1).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -518,7 +519,7 @@ LL + 1; | error: used `unwrap_unchecked()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:93:22 + --> $DIR/unnecessary_literal_unwrap.rs:92:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -530,7 +531,7 @@ LL + let _ = 1; | error: used `unwrap_unchecked()` on `Some` value - --> $DIR/unnecessary_literal_unwrap.rs:94:22 + --> $DIR/unnecessary_literal_unwrap.rs:93:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -542,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:95:22 + --> $DIR/unnecessary_literal_unwrap.rs:94:22 | LL | let _ = unsafe { Some(1).unwrap_unchecked() } + 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -554,7 +555,7 @@ LL + let _ = 1 + 1; | error: used `unwrap_unchecked()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:96:22 + --> $DIR/unnecessary_literal_unwrap.rs:95:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -566,7 +567,7 @@ LL + let _ = 1; | error: used `unwrap_unchecked()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:97:22 + --> $DIR/unnecessary_literal_unwrap.rs:96:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -578,7 +579,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) }; | error: used `unwrap_unchecked()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap.rs:98:22 + --> $DIR/unnecessary_literal_unwrap.rs:97:22 | LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -590,7 +591,7 @@ LL + let _ = 1 + 1; | error: used `unwrap_err_unchecked()` on `Err` value - --> $DIR/unnecessary_literal_unwrap.rs:99:22 + --> $DIR/unnecessary_literal_unwrap.rs:98:22 | LL | let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.rs b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.rs index 41300aceb..61058b798 100644 --- a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.rs +++ b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.rs @@ -1,106 +1,158 @@ #![warn(clippy::unnecessary_literal_unwrap)] #![allow(unreachable_code)] #![allow(clippy::unnecessary_lazy_evaluations, clippy::let_unit_value)] - +//@no-rustfix fn unwrap_option_some() { let val = Some(1); let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Some` value let _val2 = val.expect("this never happens"); + //~^ ERROR: used `expect()` on `Some` value } fn unwrap_option_some_context() { let _val = Some::([1, 2, 3].iter().sum()).unwrap(); + //~^ ERROR: used `unwrap()` on `Some` value let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); + //~^ ERROR: used `expect()` on `Some` value let val = Some::([1, 2, 3].iter().sum()); let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Some` value let _val2 = val.expect("this never happens"); + //~^ ERROR: used `expect()` on `Some` value } fn unwrap_option_none() { let val = None::<()>; let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `None` value let _val2 = val.expect("this always happens"); + //~^ ERROR: used `expect()` on `None` value let _val3: u8 = None.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `None` value None::<()>.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `None` value } fn unwrap_result_ok() { let val = Ok::<_, ()>(1); let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Ok` value let _val2 = val.expect("this never happens"); + //~^ ERROR: used `expect()` on `Ok` value let _val2 = val.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Ok` value let _val2 = val.expect_err("this always happens"); + //~^ ERROR: used `expect_err()` on `Ok` value } fn unwrap_result_ok_context() { let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); + //~^ ERROR: used `unwrap()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); + //~^ ERROR: used `expect()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); + //~^ ERROR: used `expect_err()` on `Ok` value let val = Ok::([1, 2, 3].iter().sum()); let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Ok` value let _val2 = val.expect("this never happens"); + //~^ ERROR: used `expect()` on `Ok` value let _val2 = val.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Ok` value let _val2 = val.expect_err("this always happens"); + //~^ ERROR: used `expect_err()` on `Ok` value } fn unwrap_result_err() { let val = Err::<(), _>(1); let _val2 = val.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Err` value let _val2 = val.expect_err("this never happens"); + //~^ ERROR: used `expect_err()` on `Err` value let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Err` value let _val2 = val.expect("this always happens"); + //~^ ERROR: used `expect()` on `Err` value } fn unwrap_result_err_context() { let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Err` value let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); + //~^ ERROR: used `expect_err()` on `Err` value let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); + //~^ ERROR: used `unwrap()` on `Err` value let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); + //~^ ERROR: used `expect()` on `Err` value let val = Err::<(), usize>([1, 2, 3].iter().sum()); let _val2 = val.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on `Err` value let _val2 = val.expect_err("this never happens"); + //~^ ERROR: used `expect_err()` on `Err` value let _val2 = val.unwrap(); + //~^ ERROR: used `unwrap()` on `Err` value let _val2 = val.expect("this always happens"); + //~^ ERROR: used `expect()` on `Err` value } fn unwrap_methods_option() { let val = Some(1); let _val2 = val.unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Some` value let _val2 = val.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Some` value let _val2 = val.unwrap_or_else(|| 2); + //~^ ERROR: used `unwrap_or_else()` on `Some` value } fn unwrap_methods_option_context() { let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Some` value let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Some` value let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); + //~^ ERROR: used `unwrap_or_else()` on `Some` value let val = Some::([1, 2, 3].iter().sum()); let _val2 = val.unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Some` value let _val2 = val.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Some` value let _val2 = val.unwrap_or_else(|| 2); + //~^ ERROR: used `unwrap_or_else()` on `Some` value } fn unwrap_methods_result() { let val = Ok::<_, ()>(1); let _val2 = val.unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Ok` value let _val2 = val.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Ok` value let _val2 = val.unwrap_or_else(|_| 2); + //~^ ERROR: used `unwrap_or_else()` on `Ok` value } fn unwrap_methods_result_context() { let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Ok` value let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); + //~^ ERROR: used `unwrap_or_else()` on `Ok` value let val = Ok::([1, 2, 3].iter().sum()); let _val2 = val.unwrap_or(2); + //~^ ERROR: used `unwrap_or()` on `Ok` value let _val2 = val.unwrap_or_default(); + //~^ ERROR: used `unwrap_or_default()` on `Ok` value let _val2 = val.unwrap_or_else(|_| 2); + //~^ ERROR: used `unwrap_or_else()` on `Ok` value } fn main() { diff --git a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.stderr b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.stderr index 2d1270d47..c6ecd6de6 100644 --- a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.stderr @@ -10,9 +10,10 @@ help: remove the `Some` and `unwrap()` LL | let val = Some(1); | ^^^^^^^ = note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_literal_unwrap)]` error: used `expect()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:8:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:9:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,589 +25,589 @@ LL | let val = Some(1); | ^^^^^^^ error: used `unwrap()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:14:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:14:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:13:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:16:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:13:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:16:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:16:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:20:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Some` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:15:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:19:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:17:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:22:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:15:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:19:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `None` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:22:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:28:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `None` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:21:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:15 | LL | let val = None::<()>; | ^^^^^^^^^^ error: used `expect()` on `None` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:23:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:30:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `None` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:21:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:15 | LL | let val = None::<()>; | ^^^^^^^^^^ error: used `unwrap_or_default()` on `None` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:24:21 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:32:21 | LL | let _val3: u8 = None.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `Default::default()` error: used `unwrap_or_default()` on `None` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:25:5 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:34:5 | LL | None::<()>.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `Default::default()` error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:30:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:31:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:32:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:44:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:33:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:46:17 | LL | let _val2 = val.expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:51:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:51:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:38:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:53:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:38:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:53:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:55:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:55:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:57:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:57:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:43:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:44:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:17 | LL | let _val2 = val.expect("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:45:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:65:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:46:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:67:17 | LL | let _val2 = val.expect_err("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:51:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:73:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:52:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:75:17 | LL | let _val2 = val.expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:53:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:77:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:54:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:79:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:15 | LL | let val = Err::<(), _>(1); | ^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:58:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:84:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:58:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:84:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:59:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:86:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:59:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:86:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:88:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:60:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:88:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:90:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:90:16 | LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:64:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:94:17 | LL | let _val2 = val.unwrap_err(); | ^^^^^^^^^^^^^^^^ | help: remove the `Err` and `unwrap_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:93:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect_err()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:65:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:17 | LL | let _val2 = val.expect_err("this never happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect_err()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:93:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:66:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:17 | LL | let _val2 = val.unwrap(); | ^^^^^^^^^^^^ | help: remove the `Err` and `unwrap()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:93:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `expect()` on `Err` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:67:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:17 | LL | let _val2 = val.expect("this always happens"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Err` and `expect()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:93:15 | LL | let val = Err::<(), usize>([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:106:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:105:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:73:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:108:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:105:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:74:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:110:17 | LL | let _val2 = val.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:105:15 | LL | let val = Some(1); | ^^^^^^^ error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:78:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:115:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:78:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:115:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:79:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:117:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:79:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:117:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:80:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:119:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:80:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:119:16 | LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:83:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:123:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:122:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:84:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:125:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:122:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Some` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:85:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:127:17 | LL | let _val2 = val.unwrap_or_else(|| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Some` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:122:15 | LL | let val = Some::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:90:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:133:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:132:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:91:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:135:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:132:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:92:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:137:17 | LL | let _val2 = val.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:132:15 | LL | let val = Ok::<_, ()>(1); | ^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:142:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:142:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or(2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:97:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:144:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:97:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:144:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:146:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:16 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:146:16 | LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:101:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:150:17 | LL | let _val2 = val.unwrap_or(2); | ^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:149:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_default()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:102:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:152:17 | LL | let _val2 = val.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_default()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:149:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: used `unwrap_or_else()` on `Ok` value - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:103:17 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:154:17 | LL | let _val2 = val.unwrap_or_else(|_| 2); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove the `Ok` and `unwrap_or_else()` - --> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:15 + --> $DIR/unnecessary_literal_unwrap_unfixable.rs:149:15 | LL | let val = Ok::([1, 2, 3].iter().sum()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unnecessary_map_on_constructor.fixed b/src/tools/clippy/tests/ui/unnecessary_map_on_constructor.fixed new file mode 100644 index 000000000..d0ba7ed74 --- /dev/null +++ b/src/tools/clippy/tests/ui/unnecessary_map_on_constructor.fixed @@ -0,0 +1,56 @@ +#![allow(unused)] +#![warn(clippy::unnecessary_map_on_constructor)] + +use std::ffi::OsStr; + +fn fun(t: i32) -> i32 { + t +} + +fn notfun(e: SimpleError) -> SimpleError { + e +} +macro_rules! expands_to_fun { + () => { + fun + }; +} + +#[derive(Copy, Clone)] +struct SimpleError {} + +type SimpleResult = std::result::Result; + +fn main() { + let x: i32 = 4; + + let err = SimpleError {}; + let a = Some(x); + let b: SimpleResult = Ok(x); + let c: SimpleResult = Err(err); + + let a = Some(fun(x)); + let b: SimpleResult = Ok(fun(x)); + let c: SimpleResult = Err(notfun(err)); + + let a = Option::Some(fun(x)); + let b: SimpleResult = SimpleResult::Ok(fun(x)); + let c: SimpleResult = SimpleResult::Err(notfun(err)); + let b: std::result::Result = Ok(fun(x)); + let c: std::result::Result = Err(notfun(err)); + + let a = Some(fun(x)); + let b: SimpleResult = Ok(fun(x)); + let c: SimpleResult = Err(notfun(err)); + + // Should not trigger warning + a.map(fun); + b.map(fun); + c.map_err(notfun); + + b.map_err(notfun); // Ok(_).map_err + c.map(fun); // Err(_).map() + + option_env!("PATH").map(OsStr::new); + Some(x).map(expands_to_fun!()); +} diff --git a/src/tools/clippy/tests/ui/unnecessary_map_on_constructor.rs b/src/tools/clippy/tests/ui/unnecessary_map_on_constructor.rs new file mode 100644 index 000000000..e89e7aad4 --- /dev/null +++ b/src/tools/clippy/tests/ui/unnecessary_map_on_constructor.rs @@ -0,0 +1,56 @@ +#![allow(unused)] +#![warn(clippy::unnecessary_map_on_constructor)] + +use std::ffi::OsStr; + +fn fun(t: i32) -> i32 { + t +} + +fn notfun(e: SimpleError) -> SimpleError { + e +} +macro_rules! expands_to_fun { + () => { + fun + }; +} + +#[derive(Copy, Clone)] +struct SimpleError {} + +type SimpleResult = std::result::Result; + +fn main() { + let x: i32 = 4; + + let err = SimpleError {}; + let a = Some(x); + let b: SimpleResult = Ok(x); + let c: SimpleResult = Err(err); + + let a = Some(x).map(fun); + let b: SimpleResult = Ok(x).map(fun); + let c: SimpleResult = Err(err).map_err(notfun); + + let a = Option::Some(x).map(fun); + let b: SimpleResult = SimpleResult::Ok(x).map(fun); + let c: SimpleResult = SimpleResult::Err(err).map_err(notfun); + let b: std::result::Result = Ok(x).map(fun); + let c: std::result::Result = Err(err).map_err(notfun); + + let a = Some(fun(x)); + let b: SimpleResult = Ok(fun(x)); + let c: SimpleResult = Err(notfun(err)); + + // Should not trigger warning + a.map(fun); + b.map(fun); + c.map_err(notfun); + + b.map_err(notfun); // Ok(_).map_err + c.map(fun); // Err(_).map() + + option_env!("PATH").map(OsStr::new); + Some(x).map(expands_to_fun!()); +} diff --git a/src/tools/clippy/tests/ui/unnecessary_map_on_constructor.stderr b/src/tools/clippy/tests/ui/unnecessary_map_on_constructor.stderr new file mode 100644 index 000000000..d522b68d8 --- /dev/null +++ b/src/tools/clippy/tests/ui/unnecessary_map_on_constructor.stderr @@ -0,0 +1,53 @@ +error: unnecessary map on constructor Some(_) + --> $DIR/unnecessary_map_on_constructor.rs:32:13 + | +LL | let a = Some(x).map(fun); + | ^^^^^^^^^^^^^^^^ help: try: `Some(fun(x))` + | + = note: `-D clippy::unnecessary-map-on-constructor` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_map_on_constructor)]` + +error: unnecessary map on constructor Ok(_) + --> $DIR/unnecessary_map_on_constructor.rs:33:27 + | +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 + | +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 + | +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 + | +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 + | +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 + | +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 + | +LL | let c: std::result::Result = Err(err).map_err(notfun); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Err(notfun(err))` + +error: aborting due to 8 previous errors + diff --git a/src/tools/clippy/tests/ui/unnecessary_operation.fixed b/src/tools/clippy/tests/ui/unnecessary_operation.fixed index fbd2d3459..d0c0298ef 100644 --- a/src/tools/clippy/tests/ui/unnecessary_operation.fixed +++ b/src/tools/clippy/tests/ui/unnecessary_operation.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( clippy::deref_addrof, dead_code, diff --git a/src/tools/clippy/tests/ui/unnecessary_operation.rs b/src/tools/clippy/tests/ui/unnecessary_operation.rs index b45298a6d..e8e3a2d56 100644 --- a/src/tools/clippy/tests/ui/unnecessary_operation.rs +++ b/src/tools/clippy/tests/ui/unnecessary_operation.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow( clippy::deref_addrof, dead_code, diff --git a/src/tools/clippy/tests/ui/unnecessary_operation.stderr b/src/tools/clippy/tests/ui/unnecessary_operation.stderr index a1d0d9399..fbe495f51 100644 --- a/src/tools/clippy/tests/ui/unnecessary_operation.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_operation.stderr @@ -1,109 +1,110 @@ error: unnecessary operation - --> $DIR/unnecessary_operation.rs:56:5 + --> $DIR/unnecessary_operation.rs:54:5 | LL | Tuple(get_number()); | ^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` | = note: `-D clippy::unnecessary-operation` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_operation)]` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:57:5 + --> $DIR/unnecessary_operation.rs:55:5 | LL | Struct { field: get_number() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:58:5 + --> $DIR/unnecessary_operation.rs:56:5 | LL | Struct { ..get_struct() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_struct();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:59:5 + --> $DIR/unnecessary_operation.rs:57:5 | LL | Enum::Tuple(get_number()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:60:5 + --> $DIR/unnecessary_operation.rs:58:5 | LL | Enum::Struct { field: get_number() }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:61:5 + --> $DIR/unnecessary_operation.rs:59:5 | LL | 5 + get_number(); | ^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:62:5 + --> $DIR/unnecessary_operation.rs:60:5 | LL | *&get_number(); | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:63:5 + --> $DIR/unnecessary_operation.rs:61:5 | LL | &get_number(); | ^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:64:5 + --> $DIR/unnecessary_operation.rs:62:5 | LL | (5, 6, get_number()); | ^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;6;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:65:5 + --> $DIR/unnecessary_operation.rs:63:5 | LL | get_number()..; | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:66:5 + --> $DIR/unnecessary_operation.rs:64:5 | LL | ..get_number(); | ^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:67:5 + --> $DIR/unnecessary_operation.rs:65:5 | LL | 5..get_number(); | ^^^^^^^^^^^^^^^^ help: statement can be reduced to: `5;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:68:5 + --> $DIR/unnecessary_operation.rs:66:5 | LL | [42, get_number()]; | ^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `42;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:69:5 + --> $DIR/unnecessary_operation.rs:67:5 | LL | [42, 55][get_usize()]; | ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42, 55].len() > get_usize());` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:70:5 + --> $DIR/unnecessary_operation.rs:68:5 | LL | (42, get_number()).1; | ^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `42;get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:71:5 + --> $DIR/unnecessary_operation.rs:69:5 | LL | [get_number(); 55]; | ^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:72:5 + --> $DIR/unnecessary_operation.rs:70:5 | LL | [42; 55][get_usize()]; | ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42; 55].len() > get_usize());` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:73:5 + --> $DIR/unnecessary_operation.rs:71:5 | LL | / { LL | | get_number() @@ -111,7 +112,7 @@ LL | | }; | |______^ help: statement can be reduced to: `get_number();` error: unnecessary operation - --> $DIR/unnecessary_operation.rs:76:5 + --> $DIR/unnecessary_operation.rs:74:5 | LL | / FooString { LL | | s: String::from("blah"), diff --git a/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.fixed b/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.fixed index af12fd1d6..75cd63db8 100644 --- a/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.fixed +++ b/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::unnecessary_owned_empty_strings)] fn ref_str_argument(_value: &str) {} diff --git a/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.rs b/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.rs index a460b21af..2edc0bd86 100644 --- a/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.rs +++ b/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::unnecessary_owned_empty_strings)] fn ref_str_argument(_value: &str) {} diff --git a/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.stderr b/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.stderr index 1eb198a86..58d925b10 100644 --- a/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.stderr @@ -1,13 +1,14 @@ error: usage of `&String::new()` for a function expecting a `&str` argument - --> $DIR/unnecessary_owned_empty_strings.rs:12:22 + --> $DIR/unnecessary_owned_empty_strings.rs:10:22 | LL | ref_str_argument(&String::new()); | ^^^^^^^^^^^^^^ help: try: `""` | = note: `-D clippy::unnecessary-owned-empty-strings` implied by `-D warnings` + = 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:16:22 + --> $DIR/unnecessary_owned_empty_strings.rs:14:22 | LL | ref_str_argument(&String::from("")); | ^^^^^^^^^^^^^^^^^ help: try: `""` diff --git a/src/tools/clippy/tests/ui/unnecessary_safety_comment.rs b/src/tools/clippy/tests/ui/unnecessary_safety_comment.rs index d858701ae..d9a7ad8e5 100644 --- a/src/tools/clippy/tests/ui/unnecessary_safety_comment.rs +++ b/src/tools/clippy/tests/ui/unnecessary_safety_comment.rs @@ -4,14 +4,19 @@ mod unsafe_items_invalid_comment { // SAFETY: const CONST: u32 = 0; + //~^ ERROR: constant item has unnecessary safety comment // SAFETY: static STATIC: u32 = 0; + //~^ ERROR: static item has unnecessary safety comment // SAFETY: struct Struct; + //~^ ERROR: struct has unnecessary safety comment // SAFETY: enum Enum {} + //~^ ERROR: enum has unnecessary safety comment // SAFETY: mod module {} + //~^ ERROR: module has unnecessary safety comment } mod unnecessary_from_macro { @@ -40,12 +45,15 @@ mod unnecessary_from_macro { fn unnecessary_on_stmt_and_expr() -> u32 { // SAFETY: unnecessary let num = 42; + //~^ ERROR: statement has unnecessary safety comment // SAFETY: unnecessary if num > 24 {} + //~^ ERROR: statement has unnecessary safety comment // SAFETY: unnecessary 24 + //~^ ERROR: expression has unnecessary safety comment } mod issue_10084 { diff --git a/src/tools/clippy/tests/ui/unnecessary_safety_comment.stderr b/src/tools/clippy/tests/ui/unnecessary_safety_comment.stderr index 7b2af67d6..6d4ef6c30 100644 --- a/src/tools/clippy/tests/ui/unnecessary_safety_comment.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_safety_comment.stderr @@ -10,57 +10,58 @@ help: consider removing the safety comment LL | // SAFETY: | ^^^^^^^^^^ = note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]` error: static item has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:8:5 + --> $DIR/unnecessary_safety_comment.rs:9:5 | LL | static STATIC: u32 = 0; | ^^^^^^^^^^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:7:5 + --> $DIR/unnecessary_safety_comment.rs:8:5 | LL | // SAFETY: | ^^^^^^^^^^ error: struct has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:10:5 + --> $DIR/unnecessary_safety_comment.rs:12:5 | LL | struct Struct; | ^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:9:5 + --> $DIR/unnecessary_safety_comment.rs:11:5 | LL | // SAFETY: | ^^^^^^^^^^ error: enum has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:12:5 + --> $DIR/unnecessary_safety_comment.rs:15:5 | LL | enum Enum {} | ^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:11:5 + --> $DIR/unnecessary_safety_comment.rs:14:5 | LL | // SAFETY: | ^^^^^^^^^^ error: module has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:14:5 + --> $DIR/unnecessary_safety_comment.rs:18:5 | LL | mod module {} | ^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:13:5 + --> $DIR/unnecessary_safety_comment.rs:17:5 | LL | // SAFETY: | ^^^^^^^^^^ error: impl has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:33:13 + --> $DIR/unnecessary_safety_comment.rs:38:13 | LL | impl T for $t {} | ^^^^^^^^^^^^^^^^ @@ -69,44 +70,44 @@ LL | with_safety_comment!(i32); | ------------------------- in this macro invocation | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:32:13 + --> $DIR/unnecessary_safety_comment.rs:37:13 | LL | // Safety: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `with_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info) error: expression has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:48:5 + --> $DIR/unnecessary_safety_comment.rs:55:5 | LL | 24 | ^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:47:5 + --> $DIR/unnecessary_safety_comment.rs:54:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ error: statement has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:42:5 + --> $DIR/unnecessary_safety_comment.rs:47:5 | LL | let num = 42; | ^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:41:5 + --> $DIR/unnecessary_safety_comment.rs:46:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ error: statement has unnecessary safety comment - --> $DIR/unnecessary_safety_comment.rs:45:5 + --> $DIR/unnecessary_safety_comment.rs:51:5 | LL | if num > 24 {} | ^^^^^^^^^^^^^^ | help: consider removing the safety comment - --> $DIR/unnecessary_safety_comment.rs:44:5 + --> $DIR/unnecessary_safety_comment.rs:50:5 | LL | // SAFETY: unnecessary | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unnecessary_self_imports.fixed b/src/tools/clippy/tests/ui/unnecessary_self_imports.fixed index 7fc978d3e..c265dcd24 100644 --- a/src/tools/clippy/tests/ui/unnecessary_self_imports.fixed +++ b/src/tools/clippy/tests/ui/unnecessary_self_imports.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unnecessary_self_imports)] #![allow(unused_imports, dead_code)] diff --git a/src/tools/clippy/tests/ui/unnecessary_self_imports.rs b/src/tools/clippy/tests/ui/unnecessary_self_imports.rs index 02424bc12..c3fcf7c95 100644 --- a/src/tools/clippy/tests/ui/unnecessary_self_imports.rs +++ b/src/tools/clippy/tests/ui/unnecessary_self_imports.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unnecessary_self_imports)] #![allow(unused_imports, dead_code)] diff --git a/src/tools/clippy/tests/ui/unnecessary_self_imports.stderr b/src/tools/clippy/tests/ui/unnecessary_self_imports.stderr index db805eb36..4e50aaece 100644 --- a/src/tools/clippy/tests/ui/unnecessary_self_imports.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_self_imports.stderr @@ -1,5 +1,5 @@ error: import ending with `::{self}` - --> $DIR/unnecessary_self_imports.rs:6:1 + --> $DIR/unnecessary_self_imports.rs:5:1 | LL | use std::fs::{self as alias}; | ^^^^^^^^^-------------------- @@ -8,9 +8,10 @@ LL | use std::fs::{self as alias}; | = note: this will slightly change semantics; any non-module items at the same path will also be imported = note: `-D clippy::unnecessary-self-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_self_imports)]` error: import ending with `::{self}` - --> $DIR/unnecessary_self_imports.rs:8:1 + --> $DIR/unnecessary_self_imports.rs:7:1 | LL | use std::rc::{self}; | ^^^^^^^^^----------- diff --git a/src/tools/clippy/tests/ui/unnecessary_sort_by.fixed b/src/tools/clippy/tests/ui/unnecessary_sort_by.fixed index 19380ad00..6b667e00c 100644 --- a/src/tools/clippy/tests/ui/unnecessary_sort_by.fixed +++ b/src/tools/clippy/tests/ui/unnecessary_sort_by.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::stable_sort_primitive, clippy::useless_vec)] use std::cell::Ref; diff --git a/src/tools/clippy/tests/ui/unnecessary_sort_by.rs b/src/tools/clippy/tests/ui/unnecessary_sort_by.rs index cea1b65b5..0ff20fb9e 100644 --- a/src/tools/clippy/tests/ui/unnecessary_sort_by.rs +++ b/src/tools/clippy/tests/ui/unnecessary_sort_by.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(clippy::stable_sort_primitive, clippy::useless_vec)] use std::cell::Ref; diff --git a/src/tools/clippy/tests/ui/unnecessary_sort_by.stderr b/src/tools/clippy/tests/ui/unnecessary_sort_by.stderr index 89da5e7ea..9d54c8d50 100644 --- a/src/tools/clippy/tests/ui/unnecessary_sort_by.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_sort_by.stderr @@ -1,73 +1,74 @@ error: use Vec::sort here instead - --> $DIR/unnecessary_sort_by.rs:14:5 + --> $DIR/unnecessary_sort_by.rs:12:5 | LL | vec.sort_by(|a, b| a.cmp(b)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort()` | = note: `-D clippy::unnecessary-sort-by` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_sort_by)]` error: use Vec::sort here instead - --> $DIR/unnecessary_sort_by.rs:15:5 + --> $DIR/unnecessary_sort_by.rs:13:5 | LL | vec.sort_unstable_by(|a, b| a.cmp(b)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable()` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:16:5 + --> $DIR/unnecessary_sort_by.rs:14:5 | LL | vec.sort_by(|a, b| (a + 5).abs().cmp(&(b + 5).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|a| (a + 5).abs())` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:17:5 + --> $DIR/unnecessary_sort_by.rs:15:5 | LL | vec.sort_unstable_by(|a, b| id(-a).cmp(&id(-b))); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|a| id(-a))` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:20:5 + --> $DIR/unnecessary_sort_by.rs:18: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: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:21:5 + --> $DIR/unnecessary_sort_by.rs:19: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: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:31:5 + --> $DIR/unnecessary_sort_by.rs:29:5 | LL | vec.sort_by(|a, b| (***a).abs().cmp(&(***b).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_by_key(|a| (***a).abs())` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:32:5 + --> $DIR/unnecessary_sort_by.rs:30:5 | LL | vec.sort_unstable_by(|a, b| (***a).abs().cmp(&(***b).abs())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.sort_unstable_by_key(|a| (***a).abs())` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:91:9 + --> $DIR/unnecessary_sort_by.rs:89:9 | LL | args.sort_by(|a, b| a.name().cmp(&b.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_by_key(|a| a.name())` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:92:9 + --> $DIR/unnecessary_sort_by.rs:90:9 | LL | args.sort_unstable_by(|a, b| a.name().cmp(&b.name())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `args.sort_unstable_by_key(|a| a.name())` error: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:94:9 + --> $DIR/unnecessary_sort_by.rs:92: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: use Vec::sort_by_key here instead - --> $DIR/unnecessary_sort_by.rs:95:9 + --> $DIR/unnecessary_sort_by.rs:93: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/src/tools/clippy/tests/ui/unnecessary_struct_initialization.fixed b/src/tools/clippy/tests/ui/unnecessary_struct_initialization.fixed index eae1271d1..f3cf65da2 100644 --- a/src/tools/clippy/tests/ui/unnecessary_struct_initialization.fixed +++ b/src/tools/clippy/tests/ui/unnecessary_struct_initialization.fixed @@ -1,6 +1,4 @@ -//@run-rustfix - -#![allow(clippy::incorrect_clone_impl_on_copy_type, unused)] +#![allow(clippy::non_canonical_clone_impl, unused)] #![warn(clippy::unnecessary_struct_initialization)] struct S { diff --git a/src/tools/clippy/tests/ui/unnecessary_struct_initialization.rs b/src/tools/clippy/tests/ui/unnecessary_struct_initialization.rs index 4abd560f8..bd5302f9d 100644 --- a/src/tools/clippy/tests/ui/unnecessary_struct_initialization.rs +++ b/src/tools/clippy/tests/ui/unnecessary_struct_initialization.rs @@ -1,6 +1,4 @@ -//@run-rustfix - -#![allow(clippy::incorrect_clone_impl_on_copy_type, unused)] +#![allow(clippy::non_canonical_clone_impl, unused)] #![warn(clippy::unnecessary_struct_initialization)] struct S { diff --git a/src/tools/clippy/tests/ui/unnecessary_struct_initialization.stderr b/src/tools/clippy/tests/ui/unnecessary_struct_initialization.stderr index ca4970577..d8e0ce6cc 100644 --- a/src/tools/clippy/tests/ui/unnecessary_struct_initialization.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_struct_initialization.stderr @@ -1,31 +1,32 @@ error: unnecessary struct building - --> $DIR/unnecessary_struct_initialization.rs:34:9 + --> $DIR/unnecessary_struct_initialization.rs:32:9 | LL | Self { ..*self } | ^^^^^^^^^^^^^^^^ help: replace with: `*self` | = note: `-D clippy::unnecessary-struct-initialization` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_struct_initialization)]` error: unnecessary struct building - --> $DIR/unnecessary_struct_initialization.rs:41:17 + --> $DIR/unnecessary_struct_initialization.rs:39:17 | LL | let mut b = S { ..a }; | ^^^^^^^^^ help: replace with: `a` error: unnecessary struct building - --> $DIR/unnecessary_struct_initialization.rs:44:18 + --> $DIR/unnecessary_struct_initialization.rs:42:18 | LL | let c = &mut S { ..b }; | ^^^^^^^^^ help: replace with: `b` error: unnecessary struct building - --> $DIR/unnecessary_struct_initialization.rs:52:14 + --> $DIR/unnecessary_struct_initialization.rs:50:14 | LL | let g = &S { ..f }; | ^^^^^^^^^ help: replace with: `f` error: unnecessary struct building - --> $DIR/unnecessary_struct_initialization.rs:55:18 + --> $DIR/unnecessary_struct_initialization.rs:53:18 | LL | let h = &mut S { | __________________^ @@ -34,7 +35,7 @@ LL | | }; | |_____^ help: replace with: `*Box::new(S { f: String::from("foo") })` error: unnecessary struct building - --> $DIR/unnecessary_struct_initialization.rs:74:18 + --> $DIR/unnecessary_struct_initialization.rs:72:18 | LL | let p = &mut T { | __________________^ diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed index cb7562351..67faabc53 100644 --- a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed +++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed @@ -1,6 +1,4 @@ -//@run-rustfix - -#![allow(clippy::needless_borrow, clippy::ptr_arg)] +#![allow(clippy::needless_borrow, clippy::needless_borrows_for_generic_args, clippy::ptr_arg)] #![warn(clippy::unnecessary_to_owned, clippy::redundant_clone)] use std::borrow::Cow; diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs index f82ddb2d2..99f913642 100644 --- a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs +++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs @@ -1,6 +1,4 @@ -//@run-rustfix - -#![allow(clippy::needless_borrow, clippy::ptr_arg)] +#![allow(clippy::needless_borrow, clippy::needless_borrows_for_generic_args, clippy::ptr_arg)] #![warn(clippy::unnecessary_to_owned, clippy::redundant_clone)] use std::borrow::Cow; diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr b/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr index 4918fe355..d8971b51d 100644 --- a/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr @@ -1,482 +1,484 @@ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:150:64 + --> $DIR/unnecessary_to_owned.rs:148: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:150:20 + --> $DIR/unnecessary_to_owned.rs:148:20 | LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::redundant-clone` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::redundant_clone)]` error: redundant clone - --> $DIR/unnecessary_to_owned.rs:151:40 + --> $DIR/unnecessary_to_owned.rs:149: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:151:21 + --> $DIR/unnecessary_to_owned.rs:149:21 | LL | require_os_str(&OsString::from("x").to_os_string()); | ^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:152:48 + --> $DIR/unnecessary_to_owned.rs:150: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:152:19 + --> $DIR/unnecessary_to_owned.rs:150:19 | LL | require_path(&std::path::PathBuf::from("x").to_path_buf()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:153:35 + --> $DIR/unnecessary_to_owned.rs:151: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:153:18 + --> $DIR/unnecessary_to_owned.rs:151:18 | LL | require_str(&String::from("x").to_string()); | ^^^^^^^^^^^^^^^^^ error: redundant clone - --> $DIR/unnecessary_to_owned.rs:154:39 + --> $DIR/unnecessary_to_owned.rs:152: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:154:20 + --> $DIR/unnecessary_to_owned.rs:152:20 | LL | require_slice(&[String::from("x")].to_owned()); | ^^^^^^^^^^^^^^^^^^^ error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:59:36 + --> $DIR/unnecessary_to_owned.rs:57:36 | LL | require_c_str(&Cow::from(c_str).into_owned()); | ^^^^^^^^^^^^^ help: remove this | = note: `-D clippy::unnecessary-to-owned` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_to_owned)]` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:60:19 + --> $DIR/unnecessary_to_owned.rs:58: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:62:20 + --> $DIR/unnecessary_to_owned.rs:60: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:63:38 + --> $DIR/unnecessary_to_owned.rs:61: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:64:20 + --> $DIR/unnecessary_to_owned.rs:62: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:66:18 + --> $DIR/unnecessary_to_owned.rs:64:18 | LL | require_path(&path.to_path_buf()); | ^^^^^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:67:34 + --> $DIR/unnecessary_to_owned.rs:65:34 | LL | require_path(&Cow::from(path).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:68:18 + --> $DIR/unnecessary_to_owned.rs:66:18 | LL | require_path(&path.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:70:17 + --> $DIR/unnecessary_to_owned.rs:68:17 | LL | require_str(&s.to_string()); | ^^^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:71:30 + --> $DIR/unnecessary_to_owned.rs:69:30 | LL | require_str(&Cow::from(s).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:72:17 + --> $DIR/unnecessary_to_owned.rs:70:17 | LL | require_str(&s.to_owned()); | ^^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:73:17 + --> $DIR/unnecessary_to_owned.rs:71: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:75:19 + --> $DIR/unnecessary_to_owned.rs:73:19 | LL | require_slice(&slice.to_vec()); | ^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:76:36 + --> $DIR/unnecessary_to_owned.rs:74:36 | LL | require_slice(&Cow::from(slice).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:77:19 + --> $DIR/unnecessary_to_owned.rs:75:19 | LL | require_slice(&array.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `array.as_ref()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:78:19 + --> $DIR/unnecessary_to_owned.rs:76: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:79:19 + --> $DIR/unnecessary_to_owned.rs:77:19 | LL | require_slice(&slice.to_owned()); | ^^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `into_owned` - --> $DIR/unnecessary_to_owned.rs:82:42 + --> $DIR/unnecessary_to_owned.rs:80:42 | LL | require_x(&Cow::::Owned(x.clone()).into_owned()); | ^^^^^^^^^^^^^ help: remove this error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:85:25 + --> $DIR/unnecessary_to_owned.rs:83: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:86:26 + --> $DIR/unnecessary_to_owned.rs:84: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:87:24 + --> $DIR/unnecessary_to_owned.rs:85:24 | LL | require_deref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:88:23 + --> $DIR/unnecessary_to_owned.rs:86:23 | LL | require_deref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:89:25 + --> $DIR/unnecessary_to_owned.rs:87:25 | LL | require_deref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:91:30 + --> $DIR/unnecessary_to_owned.rs:89: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:92:31 + --> $DIR/unnecessary_to_owned.rs:90: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:93:29 + --> $DIR/unnecessary_to_owned.rs:91:29 | LL | require_impl_deref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:94:28 + --> $DIR/unnecessary_to_owned.rs:92:28 | LL | require_impl_deref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:95:30 + --> $DIR/unnecessary_to_owned.rs:93:30 | LL | require_impl_deref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:97:29 + --> $DIR/unnecessary_to_owned.rs:95: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:97:43 + --> $DIR/unnecessary_to_owned.rs:95: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:98:29 + --> $DIR/unnecessary_to_owned.rs:96: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:98:47 + --> $DIR/unnecessary_to_owned.rs:96: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:100:26 + --> $DIR/unnecessary_to_owned.rs:98: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:101:27 + --> $DIR/unnecessary_to_owned.rs:99: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:102:25 + --> $DIR/unnecessary_to_owned.rs:100:25 | LL | require_as_ref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:103:24 + --> $DIR/unnecessary_to_owned.rs:101:24 | LL | require_as_ref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:104:24 + --> $DIR/unnecessary_to_owned.rs:102:24 | LL | require_as_ref_str(x.to_owned()); | ^^^^^^^^^^^^ help: use: `&x` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:105:26 + --> $DIR/unnecessary_to_owned.rs:103:26 | LL | require_as_ref_slice(array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:106:26 + --> $DIR/unnecessary_to_owned.rs:104: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:107:26 + --> $DIR/unnecessary_to_owned.rs:105:26 | LL | require_as_ref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:109:31 + --> $DIR/unnecessary_to_owned.rs:107: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:110:32 + --> $DIR/unnecessary_to_owned.rs:108: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:111:30 + --> $DIR/unnecessary_to_owned.rs:109:30 | LL | require_impl_as_ref_path(path.to_owned()); | ^^^^^^^^^^^^^^^ help: use: `path` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:112:29 + --> $DIR/unnecessary_to_owned.rs:110:29 | LL | require_impl_as_ref_str(s.to_owned()); | ^^^^^^^^^^^^ help: use: `s` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:113:29 + --> $DIR/unnecessary_to_owned.rs:111:29 | LL | require_impl_as_ref_str(x.to_owned()); | ^^^^^^^^^^^^ help: use: `&x` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:114:31 + --> $DIR/unnecessary_to_owned.rs:112:31 | LL | require_impl_as_ref_slice(array.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `array` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:115:31 + --> $DIR/unnecessary_to_owned.rs:113: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:116:31 + --> $DIR/unnecessary_to_owned.rs:114:31 | LL | require_impl_as_ref_slice(slice.to_owned()); | ^^^^^^^^^^^^^^^^ help: use: `slice` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:118:30 + --> $DIR/unnecessary_to_owned.rs:116: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:118:44 + --> $DIR/unnecessary_to_owned.rs:116: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:119:30 + --> $DIR/unnecessary_to_owned.rs:117: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:119:44 + --> $DIR/unnecessary_to_owned.rs:117: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:120:30 + --> $DIR/unnecessary_to_owned.rs:118: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:120:44 + --> $DIR/unnecessary_to_owned.rs:118: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:121:30 + --> $DIR/unnecessary_to_owned.rs:119: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:121:48 + --> $DIR/unnecessary_to_owned.rs:119: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:122:30 + --> $DIR/unnecessary_to_owned.rs:120: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:122:52 + --> $DIR/unnecessary_to_owned.rs:120: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:123:30 + --> $DIR/unnecessary_to_owned.rs:121: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:123:48 + --> $DIR/unnecessary_to_owned.rs:121: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:125:20 + --> $DIR/unnecessary_to_owned.rs:123:20 | LL | let _ = x.join(&x_ref.to_string()); | ^^^^^^^^^^^^^^^^^^ help: use: `x_ref` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:127:13 + --> $DIR/unnecessary_to_owned.rs:125:13 | LL | let _ = slice.to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_owned` - --> $DIR/unnecessary_to_owned.rs:128:13 + --> $DIR/unnecessary_to_owned.rs:126:13 | LL | let _ = slice.to_owned().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:129:13 + --> $DIR/unnecessary_to_owned.rs:127: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:130:13 + --> $DIR/unnecessary_to_owned.rs:128: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:132:13 + --> $DIR/unnecessary_to_owned.rs:130: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:133:13 + --> $DIR/unnecessary_to_owned.rs:131: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:134:13 + --> $DIR/unnecessary_to_owned.rs:132: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:135:13 + --> $DIR/unnecessary_to_owned.rs:133: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:197:14 + --> $DIR/unnecessary_to_owned.rs:195:14 | LL | for t in file_types.to_vec() { | ^^^^^^^^^^^^^^^^^^^ @@ -492,25 +494,25 @@ LL + let path = match get_file_path(t) { | error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:220:14 + --> $DIR/unnecessary_to_owned.rs:218:14 | LL | let _ = &["x"][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().cloned()` error: unnecessary use of `to_vec` - --> $DIR/unnecessary_to_owned.rs:225:14 + --> $DIR/unnecessary_to_owned.rs:223:14 | LL | let _ = &["x"][..].to_vec().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().copied()` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:272:24 + --> $DIR/unnecessary_to_owned.rs:270:24 | LL | Box::new(build(y.to_string())) | ^^^^^^^^^^^^^ help: use: `y` error: unnecessary use of `to_string` - --> $DIR/unnecessary_to_owned.rs:380:12 + --> $DIR/unnecessary_to_owned.rs:378:12 | LL | id("abc".to_string()) | ^^^^^^^^^^^^^^^^^ help: use: `"abc"` diff --git a/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs b/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs index 2d55dc664..373b18470 100644 --- a/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs +++ b/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![allow(clippy::let_unit_value)] #![warn(clippy::unnecessary_safety_doc)] diff --git a/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.stderr b/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.stderr index b0f20fdac..817eb3e26 100644 --- a/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.stderr @@ -5,6 +5,7 @@ LL | pub fn apocalypse(universe: &mut ()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unnecessary-safety-doc` implied by `-D warnings` + = 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 diff --git a/src/tools/clippy/tests/ui/unnecessary_wraps.rs b/src/tools/clippy/tests/ui/unnecessary_wraps.rs index 63648ef58..200aefff1 100644 --- a/src/tools/clippy/tests/ui/unnecessary_wraps.rs +++ b/src/tools/clippy/tests/ui/unnecessary_wraps.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![warn(clippy::unnecessary_wraps)] #![allow(clippy::no_effect)] #![allow(clippy::needless_return)] @@ -6,6 +7,8 @@ // should be linted fn func1(a: bool, b: bool) -> Option { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Option` + //~| NOTE: `-D clippy::unnecessary-wraps` implied by `-D warnings` if a && b { return Some(42); } @@ -19,6 +22,7 @@ fn func1(a: bool, b: bool) -> Option { // should be linted fn func2(a: bool, b: bool) -> Option { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Option` if a && b { return Some(10); } @@ -37,6 +41,7 @@ fn func4(a: bool) -> Option { // should be linted fn func5() -> Option { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Option` Some(1) } @@ -47,6 +52,7 @@ fn func6() -> Option { // should be linted fn func7() -> Result { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Result` Ok(1) } @@ -75,6 +81,7 @@ impl A { // should be linted fn func12() -> Option { + //~^ ERROR: this function's return value is unnecessarily wrapped by `Option` Some(1) } } @@ -102,6 +109,7 @@ fn issue_6384(s: &str) -> Option<&str> { // should be linted fn issue_6640_1(a: bool, b: bool) -> Option<()> { + //~^ ERROR: this function's return value is unnecessary if a && b { return Some(()); } @@ -115,6 +123,7 @@ fn issue_6640_1(a: bool, b: bool) -> Option<()> { // should be linted fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { + //~^ ERROR: this function's return value is unnecessary if a && b { return Ok(()); } diff --git a/src/tools/clippy/tests/ui/unnecessary_wraps.stderr b/src/tools/clippy/tests/ui/unnecessary_wraps.stderr index a6a0b22cf..20d3e070e 100644 --- a/src/tools/clippy/tests/ui/unnecessary_wraps.stderr +++ b/src/tools/clippy/tests/ui/unnecessary_wraps.stderr @@ -1,16 +1,17 @@ error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:8:1 + --> $DIR/unnecessary_wraps.rs:9:1 | LL | / fn func1(a: bool, b: bool) -> Option { +LL | | +LL | | LL | | if a && b { -LL | | return Some(42); -LL | | } ... | LL | | } LL | | } | |_^ | = note: `-D clippy::unnecessary-wraps` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_wraps)]` help: remove `Option` from the return type... | LL | fn func1(a: bool, b: bool) -> i32 { @@ -27,9 +28,10 @@ LL ~ return 1337; | error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:21:1 + --> $DIR/unnecessary_wraps.rs:24:1 | LL | / fn func2(a: bool, b: bool) -> Option { +LL | | LL | | if a && b { LL | | return Some(10); LL | | } @@ -49,9 +51,10 @@ LL ~ if a { 20 } else { 30 } | error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:39:1 + --> $DIR/unnecessary_wraps.rs:43:1 | LL | / fn func5() -> Option { +LL | | LL | | Some(1) LL | | } | |_^ @@ -66,9 +69,10 @@ LL | 1 | error: this function's return value is unnecessarily wrapped by `Result` - --> $DIR/unnecessary_wraps.rs:49:1 + --> $DIR/unnecessary_wraps.rs:54:1 | LL | / fn func7() -> Result { +LL | | LL | | Ok(1) LL | | } | |_^ @@ -83,9 +87,10 @@ LL | 1 | error: this function's return value is unnecessarily wrapped by `Option` - --> $DIR/unnecessary_wraps.rs:77:5 + --> $DIR/unnecessary_wraps.rs:83:5 | LL | / fn func12() -> Option { +LL | | LL | | Some(1) LL | | } | |_____^ @@ -100,12 +105,12 @@ LL | 1 | error: this function's return value is unnecessary - --> $DIR/unnecessary_wraps.rs:104:1 + --> $DIR/unnecessary_wraps.rs:111:1 | LL | / fn issue_6640_1(a: bool, b: bool) -> Option<()> { +LL | | LL | | if a && b { LL | | return Some(()); -LL | | } ... | LL | | } LL | | } @@ -127,12 +132,12 @@ LL ~ return ; | error: this function's return value is unnecessary - --> $DIR/unnecessary_wraps.rs:117:1 + --> $DIR/unnecessary_wraps.rs:125:1 | LL | / fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> { +LL | | LL | | if a && b { LL | | return Ok(()); -LL | | } ... | LL | | } LL | | } diff --git a/src/tools/clippy/tests/ui/unneeded_field_pattern.rs b/src/tools/clippy/tests/ui/unneeded_field_pattern.rs index 48ae1cf66..0dc21f4ce 100644 --- a/src/tools/clippy/tests/ui/unneeded_field_pattern.rs +++ b/src/tools/clippy/tests/ui/unneeded_field_pattern.rs @@ -1,4 +1,4 @@ -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![warn(clippy::unneeded_field_pattern)] #![allow(dead_code, unused)] diff --git a/src/tools/clippy/tests/ui/unneeded_field_pattern.stderr b/src/tools/clippy/tests/ui/unneeded_field_pattern.stderr index 3f1568498..68b433df8 100644 --- a/src/tools/clippy/tests/ui/unneeded_field_pattern.stderr +++ b/src/tools/clippy/tests/ui/unneeded_field_pattern.stderr @@ -6,6 +6,7 @@ LL | Foo { a: _, b: 0, .. } => {}, | = help: try with `Foo { b: 0, .. }` = note: `-D clippy::unneeded-field-pattern` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unneeded_field_pattern)]` error: all the struct fields are matched to a wildcard pattern, consider using `..` --> $DIR/unneeded_field_pattern.rs:20:9 diff --git a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.fixed b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.fixed index 2eeba509e..cbf91ed49 100644 --- a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.fixed +++ b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(stmt_expr_attributes)] #![deny(clippy::unneeded_wildcard_pattern)] #![allow(clippy::needless_if)] diff --git a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.rs b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.rs index 5416cfaa5..10df2b93d 100644 --- a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.rs +++ b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macros.rs:proc-macro +//@aux-build:proc_macros.rs #![feature(stmt_expr_attributes)] #![deny(clippy::unneeded_wildcard_pattern)] #![allow(clippy::needless_if)] diff --git a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.stderr b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.stderr index ffbdc0495..f2880a8e6 100644 --- a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.stderr +++ b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.stderr @@ -1,89 +1,89 @@ error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:13:18 + --> $DIR/unneeded_wildcard_pattern.rs:12:18 | LL | if let (0, .., _) = t {}; | ^^^ help: remove it | note: the lint level is defined here - --> $DIR/unneeded_wildcard_pattern.rs:4:9 + --> $DIR/unneeded_wildcard_pattern.rs:3:9 | LL | #![deny(clippy::unneeded_wildcard_pattern)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:14:16 + --> $DIR/unneeded_wildcard_pattern.rs:13:16 | LL | if let (0, _, ..) = t {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:15:13 + --> $DIR/unneeded_wildcard_pattern.rs:14:13 | LL | if let (_, .., 0) = t {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:16:15 + --> $DIR/unneeded_wildcard_pattern.rs:15:15 | LL | if let (.., _, 0) = t {}; | ^^^ help: remove it error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:17:16 + --> $DIR/unneeded_wildcard_pattern.rs:16:16 | LL | if let (0, _, _, ..) = t {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:18:18 + --> $DIR/unneeded_wildcard_pattern.rs:17:18 | LL | if let (0, .., _, _) = t {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:27:22 + --> $DIR/unneeded_wildcard_pattern.rs:26:22 | LL | if let (0, .., _, _,) = t {}; | ^^^^^^ help: remove them error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:34:19 + --> $DIR/unneeded_wildcard_pattern.rs:33:19 | LL | if let S(0, .., _) = s {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:35:17 + --> $DIR/unneeded_wildcard_pattern.rs:34:17 | LL | if let S(0, _, ..) = s {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:36:14 + --> $DIR/unneeded_wildcard_pattern.rs:35:14 | LL | if let S(_, .., 0) = s {}; | ^^^ help: remove it error: this pattern is unneeded as the `..` pattern can match that element - --> $DIR/unneeded_wildcard_pattern.rs:37:16 + --> $DIR/unneeded_wildcard_pattern.rs:36:16 | LL | if let S(.., _, 0) = s {}; | ^^^ help: remove it error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:38:17 + --> $DIR/unneeded_wildcard_pattern.rs:37:17 | LL | if let S(0, _, _, ..) = s {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:39:19 + --> $DIR/unneeded_wildcard_pattern.rs:38:19 | LL | if let S(0, .., _, _) = s {}; | ^^^^^^ help: remove them error: these patterns are unneeded as the `..` pattern can match those elements - --> $DIR/unneeded_wildcard_pattern.rs:48:23 + --> $DIR/unneeded_wildcard_pattern.rs:47:23 | LL | if let S(0, .., _, _,) = s {}; | ^^^^^^ help: remove them diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns.fixed b/src/tools/clippy/tests/ui/unnested_or_patterns.fixed index 738045595..53ec556d1 100644 --- a/src/tools/clippy/tests/ui/unnested_or_patterns.fixed +++ b/src/tools/clippy/tests/ui/unnested_or_patterns.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] #![allow( diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns.rs b/src/tools/clippy/tests/ui/unnested_or_patterns.rs index 9e0e7b5de..e5e378e92 100644 --- a/src/tools/clippy/tests/ui/unnested_or_patterns.rs +++ b/src/tools/clippy/tests/ui/unnested_or_patterns.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] #![allow( diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns.stderr b/src/tools/clippy/tests/ui/unnested_or_patterns.stderr index b997e4ce8..98ca7e373 100644 --- a/src/tools/clippy/tests/ui/unnested_or_patterns.stderr +++ b/src/tools/clippy/tests/ui/unnested_or_patterns.stderr @@ -1,17 +1,18 @@ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:18:12 + --> $DIR/unnested_or_patterns.rs:16:12 | LL | if let box 0 | box 2 = Box::new(0) {} | ^^^^^^^^^^^^^ | = note: `-D clippy::unnested-or-patterns` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnested_or_patterns)]` help: nest the patterns | LL | if let box (0 | 2) = Box::new(0) {} | ~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:19:12 + --> $DIR/unnested_or_patterns.rs:17:12 | LL | if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +23,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:21:12 + --> $DIR/unnested_or_patterns.rs:19:12 | LL | if let Some(1) | C0 | Some(2) = None {} | ^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +34,7 @@ LL | if let Some(1 | 2) | C0 = None {} | ~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:22:12 + --> $DIR/unnested_or_patterns.rs:20:12 | LL | if let &mut 0 | &mut 2 = &mut 0 {} | ^^^^^^^^^^^^^^^ @@ -44,7 +45,7 @@ LL | if let &mut (0 | 2) = &mut 0 {} | ~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:23:12 + --> $DIR/unnested_or_patterns.rs:21:12 | LL | if let x @ 0 | x @ 2 = 0 {} | ^^^^^^^^^^^^^ @@ -55,7 +56,7 @@ LL | if let x @ (0 | 2) = 0 {} | ~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:24:12 + --> $DIR/unnested_or_patterns.rs:22:12 | LL | if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,7 +67,7 @@ LL | if let (0, 1 | 2 | 3) = (0, 0) {} | ~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:25:12 + --> $DIR/unnested_or_patterns.rs:23:12 | LL | if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -77,7 +78,7 @@ LL | if let (1 | 2 | 3, 0) = (0, 0) {} | ~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:26:12 + --> $DIR/unnested_or_patterns.rs:24:12 | LL | if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +89,7 @@ LL | if let (x, ..) | (x, 1 | 2) = (0, 1) {} | ~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:27:12 + --> $DIR/unnested_or_patterns.rs:25:12 | LL | if let [0] | [1] = [0] {} | ^^^^^^^^^ @@ -99,7 +100,7 @@ LL | if let [0 | 1] = [0] {} | ~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:28:12 + --> $DIR/unnested_or_patterns.rs:26:12 | LL | if let [x, 0] | [x, 1] = [0, 1] {} | ^^^^^^^^^^^^^^^ @@ -110,7 +111,7 @@ LL | if let [x, 0 | 1] = [0, 1] {} | ~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:29:12 + --> $DIR/unnested_or_patterns.rs:27:12 | LL | if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +122,7 @@ LL | if let [x, 0 | 1 | 2] = [0, 1] {} | ~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:30:12 + --> $DIR/unnested_or_patterns.rs:28:12 | LL | if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -132,7 +133,7 @@ LL | if let [x, ..] | [x, 1 | 2] = [0, 1] {} | ~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:32:12 + --> $DIR/unnested_or_patterns.rs:30:12 | LL | if let TS(0, x) | TS(1, x) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^ @@ -143,7 +144,7 @@ LL | if let TS(0 | 1, x) = TS(0, 0) {} | ~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:33:12 + --> $DIR/unnested_or_patterns.rs:31:12 | LL | if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -154,7 +155,7 @@ LL | if let TS(1 | 2 | 3, 0) = TS(0, 0) {} | ~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:34:12 + --> $DIR/unnested_or_patterns.rs:32:12 | LL | if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -165,7 +166,7 @@ LL | if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {} | ~~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns.rs:39:12 + --> $DIR/unnested_or_patterns.rs:37:12 | LL | if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -176,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:50:12 + --> $DIR/unnested_or_patterns.rs:48:12 | LL | if let [1] | [53] = [0] {} | ^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns2.fixed b/src/tools/clippy/tests/ui/unnested_or_patterns2.fixed index 11dc34378..b2a4e83da 100644 --- a/src/tools/clippy/tests/ui/unnested_or_patterns2.fixed +++ b/src/tools/clippy/tests/ui/unnested_or_patterns2.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] #![allow( diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns2.rs b/src/tools/clippy/tests/ui/unnested_or_patterns2.rs index b25560827..58435f899 100644 --- a/src/tools/clippy/tests/ui/unnested_or_patterns2.rs +++ b/src/tools/clippy/tests/ui/unnested_or_patterns2.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(box_patterns)] #![warn(clippy::unnested_or_patterns)] #![allow( diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns2.stderr b/src/tools/clippy/tests/ui/unnested_or_patterns2.stderr index 76e890b3a..182ae00de 100644 --- a/src/tools/clippy/tests/ui/unnested_or_patterns2.stderr +++ b/src/tools/clippy/tests/ui/unnested_or_patterns2.stderr @@ -1,17 +1,18 @@ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:14:12 + --> $DIR/unnested_or_patterns2.rs:12:12 | LL | if let Some(Some(0)) | Some(Some(1)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unnested-or-patterns` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnested_or_patterns)]` help: nest the patterns | LL | if let Some(Some(0 | 1)) = None {} | ~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:15:12 + --> $DIR/unnested_or_patterns2.rs:13:12 | LL | if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +23,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:14:12 | LL | if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +34,7 @@ LL | if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {} | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:17:12 + --> $DIR/unnested_or_patterns2.rs:15:12 | LL | if let Some(Some(0) | Some(1 | 2)) = None {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +45,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {} | ~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:18:12 + --> $DIR/unnested_or_patterns2.rs:16:12 | LL | if let ((0,),) | ((1,) | (2,),) = ((0,),) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -55,7 +56,7 @@ LL | if let ((0 | 1 | 2,),) = ((0,),) {} | ~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:19:12 + --> $DIR/unnested_or_patterns2.rs:17:12 | LL | if let 0 | (1 | 2) = 0 {} | ^^^^^^^^^^^ @@ -66,7 +67,7 @@ LL | if let 0 | 1 | 2 = 0 {} | ~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:20:12 + --> $DIR/unnested_or_patterns2.rs:18:12 | LL | if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -77,7 +78,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {} | ~~~~~~~~~~~~~~~~~~~~~~~ error: unnested or-patterns - --> $DIR/unnested_or_patterns2.rs:21:12 + --> $DIR/unnested_or_patterns2.rs:19:12 | LL | if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unreadable_literal.fixed b/src/tools/clippy/tests/ui/unreadable_literal.fixed index f5e87648a..6d8c719ee 100644 --- a/src/tools/clippy/tests/ui/unreadable_literal.fixed +++ b/src/tools/clippy/tests/ui/unreadable_literal.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::unreadable_literal)] #![allow(unused_tuple_struct_fields)] diff --git a/src/tools/clippy/tests/ui/unreadable_literal.rs b/src/tools/clippy/tests/ui/unreadable_literal.rs index 426bdf7d7..42ca773c3 100644 --- a/src/tools/clippy/tests/ui/unreadable_literal.rs +++ b/src/tools/clippy/tests/ui/unreadable_literal.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::unreadable_literal)] #![allow(unused_tuple_struct_fields)] diff --git a/src/tools/clippy/tests/ui/unreadable_literal.stderr b/src/tools/clippy/tests/ui/unreadable_literal.stderr index 450121b1c..d7a3377ec 100644 --- a/src/tools/clippy/tests/ui/unreadable_literal.stderr +++ b/src/tools/clippy/tests/ui/unreadable_literal.stderr @@ -1,61 +1,62 @@ error: long literal lacking separators - --> $DIR/unreadable_literal.rs:34:17 + --> $DIR/unreadable_literal.rs:32:17 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^ help: consider: `0b11_0110_i64` | = note: `-D clippy::unreadable-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unreadable_literal)]` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:34:31 + --> $DIR/unreadable_literal.rs:32:31 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^^^^^^^ help: consider: `0x1234_5678_usize` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:34:49 + --> $DIR/unreadable_literal.rs:32:49 | LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32); | ^^^^^^^^^^ help: consider: `123_456_f32` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:34:61 + --> $DIR/unreadable_literal.rs:32:61 | 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:36:20 + --> $DIR/unreadable_literal.rs:34:20 | LL | let _bad_sci = 1.123456e1; | ^^^^^^^^^^ help: consider: `1.123_456e1` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:38:18 + --> $DIR/unreadable_literal.rs:36:18 | LL | let _fail1 = 0xabcdef; | ^^^^^^^^ help: consider: `0x00ab_cdef` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:39:23 + --> $DIR/unreadable_literal.rs:37:23 | LL | let _fail2: u32 = 0xBAFEBAFE; | ^^^^^^^^^^ help: consider: `0xBAFE_BAFE` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:40:18 + --> $DIR/unreadable_literal.rs:38:18 | LL | let _fail3 = 0xabcdeff; | ^^^^^^^^^ help: consider: `0x0abc_deff` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:41:24 + --> $DIR/unreadable_literal.rs:39:24 | LL | let _fail4: i128 = 0xabcabcabcabcabcabc; | ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc` error: long literal lacking separators - --> $DIR/unreadable_literal.rs:42:18 + --> $DIR/unreadable_literal.rs:40:18 | LL | let _fail5 = 1.100300400; | ^^^^^^^^^^^ help: consider: `1.100_300_400` diff --git a/src/tools/clippy/tests/ui/unsafe_derive_deserialize.rs b/src/tools/clippy/tests/ui/unsafe_derive_deserialize.rs index bafca9191..70dcaa3af 100644 --- a/src/tools/clippy/tests/ui/unsafe_derive_deserialize.rs +++ b/src/tools/clippy/tests/ui/unsafe_derive_deserialize.rs @@ -6,6 +6,7 @@ extern crate serde; use serde::Deserialize; #[derive(Deserialize)] +//~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe pub struct A; impl A { pub unsafe fn new(_a: i32, _b: i32) -> Self { @@ -14,12 +15,14 @@ impl A { } #[derive(Deserialize)] +//~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe pub struct B; impl B { pub unsafe fn unsafe_method(&self) {} } #[derive(Deserialize)] +//~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe pub struct C; impl C { pub fn unsafe_block(&self) { @@ -28,6 +31,7 @@ impl C { } #[derive(Deserialize)] +//~^ ERROR: you are deriving `serde::Deserialize` on a type that has methods using `unsafe pub struct D; impl D { pub fn inner_unsafe_fn(&self) { diff --git a/src/tools/clippy/tests/ui/unsafe_derive_deserialize.stderr b/src/tools/clippy/tests/ui/unsafe_derive_deserialize.stderr index 8aaae2d7f..d6fb82398 100644 --- a/src/tools/clippy/tests/ui/unsafe_derive_deserialize.stderr +++ b/src/tools/clippy/tests/ui/unsafe_derive_deserialize.stderr @@ -6,10 +6,11 @@ LL | #[derive(Deserialize)] | = help: consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html = note: `-D clippy::unsafe-derive-deserialize` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unsafe_derive_deserialize)]` = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> $DIR/unsafe_derive_deserialize.rs:16:10 + --> $DIR/unsafe_derive_deserialize.rs:17:10 | LL | #[derive(Deserialize)] | ^^^^^^^^^^^ @@ -18,7 +19,7 @@ LL | #[derive(Deserialize)] = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> $DIR/unsafe_derive_deserialize.rs:22:10 + --> $DIR/unsafe_derive_deserialize.rs:24:10 | LL | #[derive(Deserialize)] | ^^^^^^^^^^^ @@ -27,7 +28,7 @@ LL | #[derive(Deserialize)] = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe` - --> $DIR/unsafe_derive_deserialize.rs:30:10 + --> $DIR/unsafe_derive_deserialize.rs:33:10 | LL | #[derive(Deserialize)] | ^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs b/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs index 04f6ef29a..e0e0ded14 100644 --- a/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs +++ b/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs @@ -3,8 +3,11 @@ #![warn(clippy::unsafe_removed_from_name)] use std::cell::UnsafeCell as TotallySafeCell; +//~^ ERROR: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCell` +//~| NOTE: `-D clippy::unsafe-removed-from-name` implied by `-D warnings` use std::cell::UnsafeCell as TotallySafeCellAgain; +//~^ ERROR: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCellAgain // Shouldn't error use std::cell::RefCell as ProbablyNotUnsafe; @@ -23,9 +26,12 @@ mod mod_with_some_unsafe_things { } use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; +//~^ ERROR: removed `unsafe` from the name of `Unsafe` in use as `LieAboutModSafety` // merged imports use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B}; +//~^ ERROR: removed `unsafe` from the name of `Unsafe` in use as `A` +//~| ERROR: removed `unsafe` from the name of `Unsafe` in use as `B` // Shouldn't error use mod_with_some_unsafe_things::Safe as IPromiseItsSafeThisTime; diff --git a/src/tools/clippy/tests/ui/unsafe_removed_from_name.stderr b/src/tools/clippy/tests/ui/unsafe_removed_from_name.stderr index 090d917bd..261c7837a 100644 --- a/src/tools/clippy/tests/ui/unsafe_removed_from_name.stderr +++ b/src/tools/clippy/tests/ui/unsafe_removed_from_name.stderr @@ -5,27 +5,28 @@ LL | use std::cell::UnsafeCell as TotallySafeCell; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unsafe-removed-from-name` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unsafe_removed_from_name)]` error: removed `unsafe` from the name of `UnsafeCell` in use as `TotallySafeCellAgain` - --> $DIR/unsafe_removed_from_name.rs:7:1 + --> $DIR/unsafe_removed_from_name.rs:9:1 | LL | use std::cell::UnsafeCell as TotallySafeCellAgain; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `LieAboutModSafety` - --> $DIR/unsafe_removed_from_name.rs:25:1 + --> $DIR/unsafe_removed_from_name.rs:28:1 | LL | use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `A` - --> $DIR/unsafe_removed_from_name.rs:28:1 + --> $DIR/unsafe_removed_from_name.rs:32:1 | LL | use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: removed `unsafe` from the name of `Unsafe` in use as `B` - --> $DIR/unsafe_removed_from_name.rs:28:1 + --> $DIR/unsafe_removed_from_name.rs:32:1 | LL | use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unseparated_prefix_literals.fixed b/src/tools/clippy/tests/ui/unseparated_prefix_literals.fixed index 125120872..93f7f747b 100644 --- a/src/tools/clippy/tests/ui/unseparated_prefix_literals.fixed +++ b/src/tools/clippy/tests/ui/unseparated_prefix_literals.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![warn(clippy::unseparated_literal_suffix)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/unseparated_prefix_literals.rs b/src/tools/clippy/tests/ui/unseparated_prefix_literals.rs index 0a3ffc478..c960ff6b5 100644 --- a/src/tools/clippy/tests/ui/unseparated_prefix_literals.rs +++ b/src/tools/clippy/tests/ui/unseparated_prefix_literals.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![warn(clippy::unseparated_literal_suffix)] #![allow(dead_code)] diff --git a/src/tools/clippy/tests/ui/unseparated_prefix_literals.stderr b/src/tools/clippy/tests/ui/unseparated_prefix_literals.stderr index ab2f75e0c..d74e72875 100644 --- a/src/tools/clippy/tests/ui/unseparated_prefix_literals.stderr +++ b/src/tools/clippy/tests/ui/unseparated_prefix_literals.stderr @@ -1,49 +1,50 @@ error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:24:18 + --> $DIR/unseparated_prefix_literals.rs:23:18 | LL | let _fail1 = 1234i32; | ^^^^^^^ help: add an underscore: `1234_i32` | = note: `-D clippy::unseparated-literal-suffix` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unseparated_literal_suffix)]` error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:25:18 + --> $DIR/unseparated_prefix_literals.rs:24:18 | LL | let _fail2 = 1234u32; | ^^^^^^^ help: add an underscore: `1234_u32` error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:26:18 + --> $DIR/unseparated_prefix_literals.rs:25:18 | LL | let _fail3 = 1234isize; | ^^^^^^^^^ help: add an underscore: `1234_isize` error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:27:18 + --> $DIR/unseparated_prefix_literals.rs:26:18 | LL | let _fail4 = 1234usize; | ^^^^^^^^^ help: add an underscore: `1234_usize` error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:28:18 + --> $DIR/unseparated_prefix_literals.rs:27:18 | LL | let _fail5 = 0x123isize; | ^^^^^^^^^^ help: add an underscore: `0x123_isize` error: float type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:32:19 + --> $DIR/unseparated_prefix_literals.rs:31:19 | LL | let _failf1 = 1.5f32; | ^^^^^^ help: add an underscore: `1.5_f32` error: float type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:33:19 + --> $DIR/unseparated_prefix_literals.rs:32:19 | LL | let _failf2 = 1f32; | ^^^^ help: add an underscore: `1_f32` error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:16:9 + --> $DIR/unseparated_prefix_literals.rs:15:9 | LL | 42usize | ^^^^^^^ help: add an underscore: `42_usize` @@ -54,7 +55,7 @@ LL | let _ = lit_from_macro!(); = note: this error originates in the macro `lit_from_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: integer type suffix should be separated by an underscore - --> $DIR/unseparated_prefix_literals.rs:41:16 + --> $DIR/unseparated_prefix_literals.rs:40:16 | LL | assert_eq!(4897u32, 32223); | ^^^^^^^ help: add an underscore: `4897_u32` diff --git a/src/tools/clippy/tests/ui/unused_async.rs b/src/tools/clippy/tests/ui/unused_async.rs index 1d188025e..71722e9af 100644 --- a/src/tools/clippy/tests/ui/unused_async.rs +++ b/src/tools/clippy/tests/ui/unused_async.rs @@ -11,6 +11,7 @@ mod issue10800 { use std::future::ready; async fn async_block_await() { + //~^ ERROR: unused `async` for function with no await statements async { ready(()).await; }; @@ -43,6 +44,7 @@ mod issue9695 { async fn f() {} async fn f2() {} async fn f3() {} + //~^ ERROR: unused `async` for function with no await statements fn needs_async_fn>(_: fn() -> F) {} @@ -55,6 +57,7 @@ mod issue9695 { } async fn foo() -> i32 { + //~^ ERROR: unused `async` for function with no await statements 4 } @@ -66,6 +69,7 @@ struct S; impl S { async fn unused(&self) -> i32 { + //~^ ERROR: unused `async` for function with no await statements 1 } diff --git a/src/tools/clippy/tests/ui/unused_async.stderr b/src/tools/clippy/tests/ui/unused_async.stderr index 8d9b72c48..077e8cacc 100644 --- a/src/tools/clippy/tests/ui/unused_async.stderr +++ b/src/tools/clippy/tests/ui/unused_async.stderr @@ -2,6 +2,7 @@ error: unused `async` for function with no await statements --> $DIR/unused_async.rs:13:5 | LL | / async fn async_block_await() { +LL | | LL | | async { LL | | ready(()).await; LL | | }; @@ -10,14 +11,15 @@ LL | | } | = help: consider removing the `async` from this function note: `await` used in an async block, which does not require the enclosing function to be `async` - --> $DIR/unused_async.rs:15:23 + --> $DIR/unused_async.rs:16:23 | LL | ready(()).await; | ^^^^^ = note: `-D clippy::unused-async` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unused_async)]` error: unused `async` for function with no await statements - --> $DIR/unused_async.rs:45:5 + --> $DIR/unused_async.rs:46:5 | LL | async fn f3() {} | ^^^^^^^^^^^^^^^^ @@ -25,9 +27,10 @@ LL | async fn f3() {} = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> $DIR/unused_async.rs:57:1 + --> $DIR/unused_async.rs:59:1 | LL | / async fn foo() -> i32 { +LL | | LL | | 4 LL | | } | |_^ @@ -35,9 +38,10 @@ LL | | } = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> $DIR/unused_async.rs:68:5 + --> $DIR/unused_async.rs:71:5 | LL | / async fn unused(&self) -> i32 { +LL | | LL | | 1 LL | | } | |_____^ diff --git a/src/tools/clippy/tests/ui/unused_format_specs_unfixable.rs b/src/tools/clippy/tests/ui/unused_format_specs_unfixable.rs index 78601a348..be9919353 100644 --- a/src/tools/clippy/tests/ui/unused_format_specs_unfixable.rs +++ b/src/tools/clippy/tests/ui/unused_format_specs_unfixable.rs @@ -1,6 +1,6 @@ #![warn(clippy::unused_format_specs)] #![allow(unused)] - +//@no-rustfix macro_rules! format_args_from_macro { () => { format_args!("from macro") @@ -10,13 +10,18 @@ macro_rules! format_args_from_macro { fn main() { // prints `.`, not ` .` println!("{:5}.", format_args!("")); + //~^ ERROR: format specifiers have no effect on `format_args!()` + //~| NOTE: `-D clippy::unused-format-specs` implied by `-D warnings` //prints `abcde`, not `abc` println!("{:.3}", format_args!("abcde")); + //~^ ERROR: format specifiers have no effect on `format_args!()` println!("{:5}.", format_args_from_macro!()); + //~^ ERROR: format specifiers have no effect on `format_args!()` let args = format_args!(""); println!("{args:5}"); + //~^ ERROR: format specifiers have no effect on `format_args!()` } fn should_not_lint() { diff --git a/src/tools/clippy/tests/ui/unused_format_specs_unfixable.stderr b/src/tools/clippy/tests/ui/unused_format_specs_unfixable.stderr index cb7156b6b..183e80c85 100644 --- a/src/tools/clippy/tests/ui/unused_format_specs_unfixable.stderr +++ b/src/tools/clippy/tests/ui/unused_format_specs_unfixable.stderr @@ -5,6 +5,7 @@ LL | println!("{:5}.", format_args!("")); | ^^^^ | = note: `-D clippy::unused-format-specs` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unused_format_specs)]` help: for the width to apply consider using `format!()` | LL | println!("{:5}.", format!("")); @@ -16,7 +17,7 @@ LL + println!("{}.", format_args!("")); | error: format specifiers have no effect on `format_args!()` - --> $DIR/unused_format_specs_unfixable.rs:14:15 + --> $DIR/unused_format_specs_unfixable.rs:16:15 | LL | println!("{:.3}", format_args!("abcde")); | ^^^^^ @@ -32,7 +33,7 @@ LL + println!("{}", format_args!("abcde")); | error: format specifiers have no effect on `format_args!()` - --> $DIR/unused_format_specs_unfixable.rs:16:15 + --> $DIR/unused_format_specs_unfixable.rs:19:15 | LL | println!("{:5}.", format_args_from_macro!()); | ^^^^ @@ -45,7 +46,7 @@ LL + println!("{}.", format_args_from_macro!()); | error: format specifiers have no effect on `format_args!()` - --> $DIR/unused_format_specs_unfixable.rs:19:15 + --> $DIR/unused_format_specs_unfixable.rs:23:15 | LL | println!("{args:5}"); | ^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unused_io_amount.rs b/src/tools/clippy/tests/ui/unused_io_amount.rs index e9d1eeb31..62aec6e9e 100644 --- a/src/tools/clippy/tests/ui/unused_io_amount.rs +++ b/src/tools/clippy/tests/ui/unused_io_amount.rs @@ -7,20 +7,26 @@ use std::io::{self, Read}; fn question_mark(s: &mut T) -> io::Result<()> { s.write(b"test")?; + //~^ ERROR: written amount is not handled let mut buf = [0u8; 4]; s.read(&mut buf)?; + //~^ ERROR: read amount is not handled Ok(()) } fn unwrap(s: &mut T) { s.write(b"test").unwrap(); + //~^ ERROR: written amount is not handled let mut buf = [0u8; 4]; s.read(&mut buf).unwrap(); + //~^ ERROR: read amount is not handled } fn vectored(s: &mut T) -> io::Result<()> { s.read_vectored(&mut [io::IoSliceMut::new(&mut [])])?; + //~^ ERROR: read amount is not handled s.write_vectored(&[io::IoSlice::new(&[])])?; + //~^ ERROR: written amount is not handled Ok(()) } @@ -28,6 +34,7 @@ fn ok(file: &str) -> Option<()> { let mut reader = std::fs::File::open(file).ok()?; let mut result = [0u8; 0]; reader.read(&mut result).ok()?; + //~^ ERROR: read amount is not handled Some(()) } @@ -37,6 +44,7 @@ fn or_else(file: &str) -> io::Result<()> { let mut reader = std::fs::File::open(file)?; let mut result = [0u8; 0]; reader.read(&mut result).or_else(|err| Err(err))?; + //~^ ERROR: read amount is not handled Ok(()) } @@ -49,6 +57,7 @@ fn or(file: &str) -> Result<(), Error> { let mut reader = std::fs::File::open(file).unwrap(); let mut result = [0u8; 0]; reader.read(&mut result).or(Err(Error::Kind))?; + //~^ ERROR: read amount is not handled Ok(()) } @@ -56,6 +65,7 @@ fn combine_or(file: &str) -> Result<(), Error> { let mut reader = std::fs::File::open(file).unwrap(); let mut result = [0u8; 0]; reader + //~^ ERROR: read amount is not handled .read(&mut result) .or(Err(Error::Kind)) .or(Err(Error::Kind)) @@ -65,19 +75,25 @@ fn combine_or(file: &str) -> Result<(), Error> { fn is_ok_err(s: &mut T) { s.write(b"ok").is_ok(); + //~^ ERROR: written amount is not handled s.write(b"err").is_err(); + //~^ ERROR: written amount is not handled let mut buf = [0u8; 0]; s.read(&mut buf).is_ok(); + //~^ ERROR: read amount is not handled s.read(&mut buf).is_err(); + //~^ ERROR: read amount is not handled } async fn bad_async_write(w: &mut W) { w.write(b"hello world").await.unwrap(); + //~^ ERROR: written amount is not handled } async fn bad_async_read(r: &mut R) { let mut buf = [0u8; 0]; r.read(&mut buf[..]).await.unwrap(); + //~^ ERROR: read amount is not handled } async fn io_not_ignored_async_write(mut w: W) { @@ -91,6 +107,7 @@ fn bad_async_write_closure(w: W) -> impl future let mut w = w; async move { w.write(b"hello world").await?; + //~^ ERROR: written amount is not handled Ok(()) } } @@ -99,6 +116,7 @@ async fn async_read_nested_or(r: &mut R, do_it: bool) -> R let mut buf = [0u8; 1]; if do_it { r.read(&mut buf[..]).await.or(Err(Error::Kind))?; + //~^ ERROR: read amount is not handled } Ok(buf) } @@ -107,11 +125,13 @@ use tokio::io::{AsyncRead as TokioAsyncRead, AsyncReadExt as _, AsyncWrite as To async fn bad_async_write_tokio(w: &mut W) { w.write(b"hello world").await.unwrap(); + //~^ ERROR: written amount is not handled } async fn bad_async_read_tokio(r: &mut R) { let mut buf = [0u8; 0]; r.read(&mut buf[..]).await.unwrap(); + //~^ ERROR: read amount is not handled } async fn undetected_bad_async_write(w: &mut W) { diff --git a/src/tools/clippy/tests/ui/unused_io_amount.stderr b/src/tools/clippy/tests/ui/unused_io_amount.stderr index 0865c5213..f9aef596a 100644 --- a/src/tools/clippy/tests/ui/unused_io_amount.stderr +++ b/src/tools/clippy/tests/ui/unused_io_amount.stderr @@ -6,9 +6,10 @@ LL | s.write(b"test")?; | = help: use `Write::write_all` instead, or handle partial writes = note: `-D clippy::unused-io-amount` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unused_io_amount)]` error: read amount is not handled - --> $DIR/unused_io_amount.rs:11:5 + --> $DIR/unused_io_amount.rs:12:5 | LL | s.read(&mut buf)?; | ^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | s.read(&mut buf)?; = help: use `Read::read_exact` instead, or handle partial reads error: written amount is not handled - --> $DIR/unused_io_amount.rs:16:5 + --> $DIR/unused_io_amount.rs:18:5 | LL | s.write(b"test").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | s.write(b"test").unwrap(); = help: use `Write::write_all` instead, or handle partial writes error: read amount is not handled - --> $DIR/unused_io_amount.rs:18:5 + --> $DIR/unused_io_amount.rs:21:5 | LL | s.read(&mut buf).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,19 +33,19 @@ LL | s.read(&mut buf).unwrap(); = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> $DIR/unused_io_amount.rs:22:5 + --> $DIR/unused_io_amount.rs:26:5 | LL | s.read_vectored(&mut [io::IoSliceMut::new(&mut [])])?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: written amount is not handled - --> $DIR/unused_io_amount.rs:23:5 + --> $DIR/unused_io_amount.rs:28:5 | LL | s.write_vectored(&[io::IoSlice::new(&[])])?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: read amount is not handled - --> $DIR/unused_io_amount.rs:30:5 + --> $DIR/unused_io_amount.rs:36:5 | LL | reader.read(&mut result).ok()?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,7 +53,7 @@ LL | reader.read(&mut result).ok()?; = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> $DIR/unused_io_amount.rs:39:5 + --> $DIR/unused_io_amount.rs:46:5 | LL | reader.read(&mut result).or_else(|err| Err(err))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +61,7 @@ LL | reader.read(&mut result).or_else(|err| Err(err))?; = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> $DIR/unused_io_amount.rs:51:5 + --> $DIR/unused_io_amount.rs:59:5 | LL | reader.read(&mut result).or(Err(Error::Kind))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -68,9 +69,10 @@ LL | reader.read(&mut result).or(Err(Error::Kind))?; = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> $DIR/unused_io_amount.rs:58:5 + --> $DIR/unused_io_amount.rs:67:5 | LL | / reader +LL | | LL | | .read(&mut result) LL | | .or(Err(Error::Kind)) LL | | .or(Err(Error::Kind)) @@ -80,7 +82,7 @@ LL | | .expect("error"); = help: use `Read::read_exact` instead, or handle partial reads error: written amount is not handled - --> $DIR/unused_io_amount.rs:67:5 + --> $DIR/unused_io_amount.rs:77:5 | LL | s.write(b"ok").is_ok(); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +90,7 @@ LL | s.write(b"ok").is_ok(); = help: use `Write::write_all` instead, or handle partial writes error: written amount is not handled - --> $DIR/unused_io_amount.rs:68:5 + --> $DIR/unused_io_amount.rs:79:5 | LL | s.write(b"err").is_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +98,7 @@ LL | s.write(b"err").is_err(); = help: use `Write::write_all` instead, or handle partial writes error: read amount is not handled - --> $DIR/unused_io_amount.rs:70:5 + --> $DIR/unused_io_amount.rs:82:5 | LL | s.read(&mut buf).is_ok(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +106,7 @@ LL | s.read(&mut buf).is_ok(); = help: use `Read::read_exact` instead, or handle partial reads error: read amount is not handled - --> $DIR/unused_io_amount.rs:71:5 + --> $DIR/unused_io_amount.rs:84:5 | LL | s.read(&mut buf).is_err(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +114,7 @@ LL | s.read(&mut buf).is_err(); = help: use `Read::read_exact` instead, or handle partial reads error: written amount is not handled - --> $DIR/unused_io_amount.rs:75:5 + --> $DIR/unused_io_amount.rs:89:5 | LL | w.write(b"hello world").await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -120,7 +122,7 @@ LL | w.write(b"hello world").await.unwrap(); = help: use `AsyncWriteExt::write_all` instead, or handle partial writes error: read amount is not handled - --> $DIR/unused_io_amount.rs:80:5 + --> $DIR/unused_io_amount.rs:95:5 | LL | r.read(&mut buf[..]).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -128,7 +130,7 @@ LL | r.read(&mut buf[..]).await.unwrap(); = help: use `AsyncReadExt::read_exact` instead, or handle partial reads error: written amount is not handled - --> $DIR/unused_io_amount.rs:93:9 + --> $DIR/unused_io_amount.rs:109:9 | LL | w.write(b"hello world").await?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -136,7 +138,7 @@ LL | w.write(b"hello world").await?; = help: use `AsyncWriteExt::write_all` instead, or handle partial writes error: read amount is not handled - --> $DIR/unused_io_amount.rs:101:9 + --> $DIR/unused_io_amount.rs:118:9 | LL | r.read(&mut buf[..]).await.or(Err(Error::Kind))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -144,7 +146,7 @@ LL | r.read(&mut buf[..]).await.or(Err(Error::Kind))?; = help: use `AsyncReadExt::read_exact` instead, or handle partial reads error: written amount is not handled - --> $DIR/unused_io_amount.rs:109:5 + --> $DIR/unused_io_amount.rs:127:5 | LL | w.write(b"hello world").await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -152,7 +154,7 @@ LL | w.write(b"hello world").await.unwrap(); = help: use `AsyncWriteExt::write_all` instead, or handle partial writes error: read amount is not handled - --> $DIR/unused_io_amount.rs:114:5 + --> $DIR/unused_io_amount.rs:133:5 | LL | r.read(&mut buf[..]).await.unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unused_peekable.rs b/src/tools/clippy/tests/ui/unused_peekable.rs index b227f8660..131b51e01 100644 --- a/src/tools/clippy/tests/ui/unused_peekable.rs +++ b/src/tools/clippy/tests/ui/unused_peekable.rs @@ -11,14 +11,17 @@ fn main() { #[allow(clippy::unused_unit)] fn invalid() { let peekable = std::iter::empty::().peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator // Only lint `new_local` let old_local = std::iter::empty::().peekable(); let new_local = old_local; + //~^ ERROR: `peek` never called on `Peekable` iterator // Behind mut ref let mut by_mut_ref_test = std::iter::empty::().peekable(); let by_mut_ref = &mut by_mut_ref_test; + //~^ ERROR: `peek` never called on `Peekable` iterator // Explicitly returns `Peekable` fn returns_peekable() -> Peekable> { @@ -26,21 +29,26 @@ fn invalid() { } let peekable_from_fn = returns_peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator // Using a method not exclusive to `Peekable` let mut peekable_using_iterator_method = std::iter::empty::().peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator peekable_using_iterator_method.next(); // Passed by ref to another function fn takes_ref(_peek: &Peekable>) {} let passed_along_ref = std::iter::empty::().peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator takes_ref(&passed_along_ref); // `by_ref` without `peek` let mut by_ref_test = std::iter::empty::().peekable(); let _by_ref = by_ref_test.by_ref(); + //~^ ERROR: `peek` never called on `Peekable` iterator let mut peekable_in_for_loop = std::iter::empty::().peekable(); + //~^ ERROR: `peek` never called on `Peekable` iterator for x in peekable_in_for_loop {} } diff --git a/src/tools/clippy/tests/ui/unused_peekable.stderr b/src/tools/clippy/tests/ui/unused_peekable.stderr index d969232fd..157d6fc15 100644 --- a/src/tools/clippy/tests/ui/unused_peekable.stderr +++ b/src/tools/clippy/tests/ui/unused_peekable.stderr @@ -6,9 +6,10 @@ LL | let peekable = std::iter::empty::().peekable(); | = help: consider removing the call to `peekable` = note: `-D clippy::unused-peekable` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unused_peekable)]` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:17:9 + --> $DIR/unused_peekable.rs:18:9 | LL | let new_local = old_local; | ^^^^^^^^^ @@ -16,7 +17,7 @@ LL | let new_local = old_local; = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:21:9 + --> $DIR/unused_peekable.rs:23:9 | LL | let by_mut_ref = &mut by_mut_ref_test; | ^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | let by_mut_ref = &mut by_mut_ref_test; = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:28:9 + --> $DIR/unused_peekable.rs:31:9 | LL | let peekable_from_fn = returns_peekable(); | ^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | let peekable_from_fn = returns_peekable(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:31:13 + --> $DIR/unused_peekable.rs:35:13 | LL | let mut peekable_using_iterator_method = std::iter::empty::().peekable(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | let mut peekable_using_iterator_method = std::iter::empty::().peek = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:36:9 + --> $DIR/unused_peekable.rs:41:9 | LL | let passed_along_ref = std::iter::empty::().peekable(); | ^^^^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | let passed_along_ref = std::iter::empty::().peekable(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:41:9 + --> $DIR/unused_peekable.rs:47:9 | LL | let _by_ref = by_ref_test.by_ref(); | ^^^^^^^ @@ -56,7 +57,7 @@ LL | let _by_ref = by_ref_test.by_ref(); = help: consider removing the call to `peekable` error: `peek` never called on `Peekable` iterator - --> $DIR/unused_peekable.rs:43:13 + --> $DIR/unused_peekable.rs:50:13 | LL | let mut peekable_in_for_loop = std::iter::empty::().peekable(); | ^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unused_rounding.fixed b/src/tools/clippy/tests/ui/unused_rounding.fixed index f02b55502..02f970f42 100644 --- a/src/tools/clippy/tests/ui/unused_rounding.fixed +++ b/src/tools/clippy/tests/ui/unused_rounding.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unused_rounding)] fn main() { diff --git a/src/tools/clippy/tests/ui/unused_rounding.rs b/src/tools/clippy/tests/ui/unused_rounding.rs index c7bd4906d..fd14c466f 100644 --- a/src/tools/clippy/tests/ui/unused_rounding.rs +++ b/src/tools/clippy/tests/ui/unused_rounding.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::unused_rounding)] fn main() { diff --git a/src/tools/clippy/tests/ui/unused_rounding.stderr b/src/tools/clippy/tests/ui/unused_rounding.stderr index b867996fe..d6ce27351 100644 --- a/src/tools/clippy/tests/ui/unused_rounding.stderr +++ b/src/tools/clippy/tests/ui/unused_rounding.stderr @@ -1,31 +1,32 @@ error: used the `ceil` method with a whole number float - --> $DIR/unused_rounding.rs:5:13 + --> $DIR/unused_rounding.rs:4:13 | LL | let _ = 1f32.ceil(); | ^^^^^^^^^^^ help: remove the `ceil` method call: `1f32` | = note: `-D clippy::unused-rounding` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unused_rounding)]` error: used the `floor` method with a whole number float - --> $DIR/unused_rounding.rs:6:13 + --> $DIR/unused_rounding.rs:5:13 | LL | let _ = 1.0f64.floor(); | ^^^^^^^^^^^^^^ help: remove the `floor` method call: `1.0f64` error: used the `round` method with a whole number float - --> $DIR/unused_rounding.rs:7:13 + --> $DIR/unused_rounding.rs:6:13 | LL | let _ = 1.00f32.round(); | ^^^^^^^^^^^^^^^ help: remove the `round` method call: `1.00f32` error: used the `round` method with a whole number float - --> $DIR/unused_rounding.rs:13:13 + --> $DIR/unused_rounding.rs:12:13 | LL | let _ = 3.0_f32.round(); | ^^^^^^^^^^^^^^^ help: remove the `round` method call: `3.0_f32` error: used the `round` method with a whole number float - --> $DIR/unused_rounding.rs:15:13 + --> $DIR/unused_rounding.rs:14:13 | LL | let _ = 3_3.0_0_f32.round(); | ^^^^^^^^^^^^^^^^^^^ help: remove the `round` method call: `3_3.0_0_f32` diff --git a/src/tools/clippy/tests/ui/unused_self.rs b/src/tools/clippy/tests/ui/unused_self.rs index 55bd56071..d3d06037c 100644 --- a/src/tools/clippy/tests/ui/unused_self.rs +++ b/src/tools/clippy/tests/ui/unused_self.rs @@ -9,16 +9,25 @@ mod unused_self { impl A { fn unused_self_move(self) {} + //~^ ERROR: unused `self` argument fn unused_self_ref(&self) {} + //~^ ERROR: unused `self` argument fn unused_self_mut_ref(&mut self) {} + //~^ ERROR: unused `self` argument fn unused_self_pin_ref(self: Pin<&Self>) {} + //~^ ERROR: unused `self` argument fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {} + //~^ ERROR: unused `self` argument fn unused_self_pin_nested(self: Pin>) {} + //~^ ERROR: unused `self` argument fn unused_self_box(self: Box) {} + //~^ ERROR: unused `self` argument fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 { + //~^ ERROR: unused `self` argument x + y } fn unused_self_class_method(&self) { + //~^ ERROR: unused `self` argument Self::static_method(); } diff --git a/src/tools/clippy/tests/ui/unused_self.stderr b/src/tools/clippy/tests/ui/unused_self.stderr index 919f9b6ef..3865095bb 100644 --- a/src/tools/clippy/tests/ui/unused_self.stderr +++ b/src/tools/clippy/tests/ui/unused_self.stderr @@ -6,9 +6,10 @@ LL | fn unused_self_move(self) {} | = help: consider refactoring to an associated function = note: `-D clippy::unused-self` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unused_self)]` error: unused `self` argument - --> $DIR/unused_self.rs:12:28 + --> $DIR/unused_self.rs:13:28 | LL | fn unused_self_ref(&self) {} | ^^^^^ @@ -16,7 +17,7 @@ LL | fn unused_self_ref(&self) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:13:32 + --> $DIR/unused_self.rs:15:32 | LL | fn unused_self_mut_ref(&mut self) {} | ^^^^^^^^^ @@ -24,7 +25,7 @@ LL | fn unused_self_mut_ref(&mut self) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:14:32 + --> $DIR/unused_self.rs:17:32 | LL | fn unused_self_pin_ref(self: Pin<&Self>) {} | ^^^^ @@ -32,7 +33,7 @@ LL | fn unused_self_pin_ref(self: Pin<&Self>) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:15:36 + --> $DIR/unused_self.rs:19:36 | LL | fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {} | ^^^^ @@ -40,7 +41,7 @@ LL | fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:16:35 + --> $DIR/unused_self.rs:21:35 | LL | fn unused_self_pin_nested(self: Pin>) {} | ^^^^ @@ -48,7 +49,7 @@ LL | fn unused_self_pin_nested(self: Pin>) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:17:28 + --> $DIR/unused_self.rs:23:28 | LL | fn unused_self_box(self: Box) {} | ^^^^ @@ -56,7 +57,7 @@ LL | fn unused_self_box(self: Box) {} = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:18:40 + --> $DIR/unused_self.rs:25:40 | LL | fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 { | ^^^^^ @@ -64,7 +65,7 @@ LL | fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 { = help: consider refactoring to an associated function error: unused `self` argument - --> $DIR/unused_self.rs:21:37 + --> $DIR/unused_self.rs:29:37 | LL | fn unused_self_class_method(&self) { | ^^^^^ diff --git a/src/tools/clippy/tests/ui/unused_unit.fixed b/src/tools/clippy/tests/ui/unused_unit.fixed index 7b8f7847d..16da9a25b 100644 --- a/src/tools/clippy/tests/ui/unused_unit.fixed +++ b/src/tools/clippy/tests/ui/unused_unit.fixed @@ -1,4 +1,4 @@ -//@run-rustfix + // The output for humans should just highlight the whole span without showing // the suggested replacement, but we also want to test that suggested diff --git a/src/tools/clippy/tests/ui/unused_unit.rs b/src/tools/clippy/tests/ui/unused_unit.rs index fdde1ecad..e37403143 100644 --- a/src/tools/clippy/tests/ui/unused_unit.rs +++ b/src/tools/clippy/tests/ui/unused_unit.rs @@ -1,4 +1,4 @@ -//@run-rustfix + // The output for humans should just highlight the whole span without showing // the suggested replacement, but we also want to test that suggested diff --git a/src/tools/clippy/tests/ui/unwrap.rs b/src/tools/clippy/tests/ui/unwrap.rs index 64d643783..8ad7e9850 100644 --- a/src/tools/clippy/tests/ui/unwrap.rs +++ b/src/tools/clippy/tests/ui/unwrap.rs @@ -4,12 +4,15 @@ fn unwrap_option() { let opt = Some(0); let _ = opt.unwrap(); + //~^ ERROR: used `unwrap()` on an `Option` value } fn unwrap_result() { let res: Result = Ok(0); let _ = res.unwrap(); + //~^ ERROR: used `unwrap()` on a `Result` value let _ = res.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on a `Result` value } fn main() { diff --git a/src/tools/clippy/tests/ui/unwrap.stderr b/src/tools/clippy/tests/ui/unwrap.stderr index 41db819f6..25911ded2 100644 --- a/src/tools/clippy/tests/ui/unwrap.stderr +++ b/src/tools/clippy/tests/ui/unwrap.stderr @@ -7,9 +7,10 @@ LL | let _ = opt.unwrap(); = note: if this value is `None`, it will panic = help: consider using `expect()` to provide a better panic message = note: `-D clippy::unwrap-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: used `unwrap()` on a `Result` value - --> $DIR/unwrap.rs:11:13 + --> $DIR/unwrap.rs:12:13 | LL | let _ = res.unwrap(); | ^^^^^^^^^^^^ @@ -18,7 +19,7 @@ LL | let _ = res.unwrap(); = help: consider using `expect()` to provide a better panic message error: used `unwrap_err()` on a `Result` value - --> $DIR/unwrap.rs:12:13 + --> $DIR/unwrap.rs:14:13 | LL | let _ = res.unwrap_err(); | ^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unwrap_expect_used.rs b/src/tools/clippy/tests/ui/unwrap_expect_used.rs index 26f92ccde..96368a070 100644 --- a/src/tools/clippy/tests/ui/unwrap_expect_used.rs +++ b/src/tools/clippy/tests/ui/unwrap_expect_used.rs @@ -25,7 +25,9 @@ impl OptionExt for Option { fn main() { Some(3).unwrap(); + //~^ ERROR: used `unwrap()` on an `Option` value Some(3).expect("Hello world!"); + //~^ ERROR: used `expect()` on an `Option` value // Don't trigger on unwrap_err on an option Some(3).unwrap_err(); @@ -41,7 +43,11 @@ fn main() { let a: Result = Ok(3); a.unwrap(); + //~^ ERROR: used `unwrap()` on a `Result` value a.expect("Hello world!"); + //~^ ERROR: used `expect()` on a `Result` value a.unwrap_err(); + //~^ ERROR: used `unwrap_err()` on a `Result` value a.expect_err("Hello error!"); + //~^ ERROR: used `expect_err()` on a `Result` value } diff --git a/src/tools/clippy/tests/ui/unwrap_expect_used.stderr b/src/tools/clippy/tests/ui/unwrap_expect_used.stderr index f66e47612..cbe6ea22e 100644 --- a/src/tools/clippy/tests/ui/unwrap_expect_used.stderr +++ b/src/tools/clippy/tests/ui/unwrap_expect_used.stderr @@ -6,18 +6,20 @@ LL | Some(3).unwrap(); | = note: if this value is `None`, it will panic = note: `-D clippy::unwrap-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` error: used `expect()` on an `Option` value - --> $DIR/unwrap_expect_used.rs:28:5 + --> $DIR/unwrap_expect_used.rs:29:5 | LL | Some(3).expect("Hello world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: if this value is `None`, it will panic = note: `-D clippy::expect-used` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::expect_used)]` error: used `unwrap()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:43:5 + --> $DIR/unwrap_expect_used.rs:45:5 | LL | a.unwrap(); | ^^^^^^^^^^ @@ -25,7 +27,7 @@ LL | a.unwrap(); = note: if this value is an `Err`, it will panic error: used `expect()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:44:5 + --> $DIR/unwrap_expect_used.rs:47:5 | LL | a.expect("Hello world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -33,7 +35,7 @@ LL | a.expect("Hello world!"); = note: if this value is an `Err`, it will panic error: used `unwrap_err()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:45:5 + --> $DIR/unwrap_expect_used.rs:49:5 | LL | a.unwrap_err(); | ^^^^^^^^^^^^^^ @@ -41,7 +43,7 @@ LL | a.unwrap_err(); = note: if this value is an `Ok`, it will panic error: used `expect_err()` on a `Result` value - --> $DIR/unwrap_expect_used.rs:46:5 + --> $DIR/unwrap_expect_used.rs:51:5 | LL | a.expect_err("Hello error!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unwrap_in_result.rs b/src/tools/clippy/tests/ui/unwrap_in_result.rs index 2aa842adc..a19db46c6 100644 --- a/src/tools/clippy/tests/ui/unwrap_in_result.rs +++ b/src/tools/clippy/tests/ui/unwrap_in_result.rs @@ -20,6 +20,7 @@ impl A { // should be detected fn bad_divisible_by_3(i_str: String) -> Result { + //~^ ERROR: used unwrap or expect in a function that returns result or option // checks whether a string represents a number divisible by 3 let i = i_str.parse::().unwrap(); if i % 3 == 0 { @@ -30,6 +31,7 @@ impl A { } fn example_option_expect(i_str: String) -> Option { + //~^ ERROR: used unwrap or expect in a function that returns result or option let i = i_str.parse::().expect("not a number"); if i % 3 == 0 { return Some(true); diff --git a/src/tools/clippy/tests/ui/unwrap_in_result.stderr b/src/tools/clippy/tests/ui/unwrap_in_result.stderr index 40e6bfe08..9a0a32d47 100644 --- a/src/tools/clippy/tests/ui/unwrap_in_result.stderr +++ b/src/tools/clippy/tests/ui/unwrap_in_result.stderr @@ -2,9 +2,9 @@ error: used unwrap or expect in a function that returns result or option --> $DIR/unwrap_in_result.rs:22:5 | LL | / fn bad_divisible_by_3(i_str: String) -> Result { +LL | | LL | | // checks whether a string represents a number divisible by 3 LL | | let i = i_str.parse::().unwrap(); -LL | | if i % 3 == 0 { ... | LL | | } LL | | } @@ -12,27 +12,28 @@ LL | | } | = help: unwrap and expect should not be used in a function that returns result or option note: potential non-recoverable error(s) - --> $DIR/unwrap_in_result.rs:24:17 + --> $DIR/unwrap_in_result.rs:25:17 | LL | let i = i_str.parse::().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D clippy::unwrap-in-result` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_in_result)]` error: used unwrap or expect in a function that returns result or option - --> $DIR/unwrap_in_result.rs:32:5 + --> $DIR/unwrap_in_result.rs:33:5 | LL | / fn example_option_expect(i_str: String) -> Option { +LL | | LL | | let i = i_str.parse::().expect("not a number"); LL | | if i % 3 == 0 { -LL | | return Some(true); -LL | | } +... | LL | | None LL | | } | |_____^ | = help: unwrap and expect should not be used in a function that returns result or option note: potential non-recoverable error(s) - --> $DIR/unwrap_in_result.rs:33:17 + --> $DIR/unwrap_in_result.rs:35:17 | LL | let i = i_str.parse::().expect("not a number"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/unwrap_or.fixed b/src/tools/clippy/tests/ui/unwrap_or.fixed new file mode 100644 index 000000000..e1a47fc7b --- /dev/null +++ b/src/tools/clippy/tests/ui/unwrap_or.fixed @@ -0,0 +1,13 @@ +#![warn(clippy::all, clippy::or_fun_call)] +#![allow(clippy::unnecessary_literal_unwrap)] + +fn main() { + let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); + //~^ ERROR: use of `unwrap_or` followed by a function call + //~| NOTE: `-D clippy::or-fun-call` implied by `-D warnings` +} + +fn new_lines() { + let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); + //~^ ERROR: use of `unwrap_or` followed by a function call +} diff --git a/src/tools/clippy/tests/ui/unwrap_or.rs b/src/tools/clippy/tests/ui/unwrap_or.rs index 5bea85e66..914bfb939 100644 --- a/src/tools/clippy/tests/ui/unwrap_or.rs +++ b/src/tools/clippy/tests/ui/unwrap_or.rs @@ -3,8 +3,11 @@ fn main() { let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); + //~^ ERROR: use of `unwrap_or` followed by a function call + //~| NOTE: `-D clippy::or-fun-call` implied by `-D warnings` } fn new_lines() { let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); + //~^ ERROR: use of `unwrap_or` followed by a function call } diff --git a/src/tools/clippy/tests/ui/unwrap_or.stderr b/src/tools/clippy/tests/ui/unwrap_or.stderr index e384bbbb0..3a32092f7 100644 --- a/src/tools/clippy/tests/ui/unwrap_or.stderr +++ b/src/tools/clippy/tests/ui/unwrap_or.stderr @@ -5,9 +5,10 @@ LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| "Fail".to_string())` | = note: `-D clippy::or-fun-call` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::or_fun_call)]` error: use of `unwrap_or` followed by a function call - --> $DIR/unwrap_or.rs:9:47 + --> $DIR/unwrap_or.rs:11:47 | LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| "Fail".to_string())` diff --git a/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed b/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed index acdb96942..8d5d34175 100644 --- a/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed +++ b/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::unwrap_or_default)] #![allow(dead_code)] #![allow(clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)] @@ -132,4 +130,34 @@ fn method_call_with_deref() { let _ = inner_map.entry(0).or_default(); } +fn missing_suggested_method() { + #[derive(Copy, Clone)] + struct S(T); + + impl S { + fn or_insert_with(&mut self, default: impl FnOnce() -> T) -> &mut T { + &mut self.0 + } + + fn or_insert(&mut self, default: T) -> &mut T { + &mut self.0 + } + + fn unwrap_or_else(self, default: impl FnOnce() -> T) -> T { + self.0 + } + + fn unwrap_or(self, default: T) -> T { + self.0 + } + } + + // Don't lint when or_default/unwrap_or_default do not exist on the type + let mut s = S(1); + s.or_insert_with(Default::default); + s.or_insert(Default::default()); + s.unwrap_or_else(Default::default); + s.unwrap_or(Default::default()); +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/unwrap_or_else_default.rs b/src/tools/clippy/tests/ui/unwrap_or_else_default.rs index 55ccd00e1..adbcb4b44 100644 --- a/src/tools/clippy/tests/ui/unwrap_or_else_default.rs +++ b/src/tools/clippy/tests/ui/unwrap_or_else_default.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::unwrap_or_default)] #![allow(dead_code)] #![allow(clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)] @@ -132,4 +130,34 @@ fn method_call_with_deref() { let _ = inner_map.entry(0).or_insert_with(Default::default); } +fn missing_suggested_method() { + #[derive(Copy, Clone)] + struct S(T); + + impl S { + fn or_insert_with(&mut self, default: impl FnOnce() -> T) -> &mut T { + &mut self.0 + } + + fn or_insert(&mut self, default: T) -> &mut T { + &mut self.0 + } + + fn unwrap_or_else(self, default: impl FnOnce() -> T) -> T { + self.0 + } + + fn unwrap_or(self, default: T) -> T { + self.0 + } + } + + // Don't lint when or_default/unwrap_or_default do not exist on the type + let mut s = S(1); + s.or_insert_with(Default::default); + s.or_insert(Default::default()); + s.unwrap_or_else(Default::default); + s.unwrap_or(Default::default()); +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/unwrap_or_else_default.stderr b/src/tools/clippy/tests/ui/unwrap_or_else_default.stderr index af662c6de..3119aba19 100644 --- a/src/tools/clippy/tests/ui/unwrap_or_else_default.stderr +++ b/src/tools/clippy/tests/ui/unwrap_or_else_default.stderr @@ -1,97 +1,98 @@ error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:48:14 + --> $DIR/unwrap_or_else_default.rs:46:14 | LL | with_new.unwrap_or_else(Vec::new); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` | = note: `-D clippy::unwrap-or-default` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unwrap_or_default)]` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:62:23 + --> $DIR/unwrap_or_else_default.rs:60:23 | LL | with_real_default.unwrap_or_else(::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` error: use of `unwrap_or_else` to construct default value - --> $DIR/unwrap_or_else_default.rs:65:24 + --> $DIR/unwrap_or_else_default.rs:63: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:68:23 + --> $DIR/unwrap_or_else_default.rs:66: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:71:23 + --> $DIR/unwrap_or_else_default.rs:69: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:74:18 + --> $DIR/unwrap_or_else_default.rs:72: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:78:12 + --> $DIR/unwrap_or_else_default.rs:76: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:81:12 + --> $DIR/unwrap_or_else_default.rs:79: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:84:12 + --> $DIR/unwrap_or_else_default.rs:82: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:87:12 + --> $DIR/unwrap_or_else_default.rs:85: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:90:12 + --> $DIR/unwrap_or_else_default.rs:88: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:93:12 + --> $DIR/unwrap_or_else_default.rs:91: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:96:12 + --> $DIR/unwrap_or_else_default.rs:94: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:99:12 + --> $DIR/unwrap_or_else_default.rs:97: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:115:12 + --> $DIR/unwrap_or_else_default.rs:113: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:132:32 + --> $DIR/unwrap_or_else_default.rs:130:32 | LL | let _ = inner_map.entry(0).or_insert_with(Default::default); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()` diff --git a/src/tools/clippy/tests/ui/upper_case_acronyms.fixed b/src/tools/clippy/tests/ui/upper_case_acronyms.fixed new file mode 100644 index 000000000..460567b09 --- /dev/null +++ b/src/tools/clippy/tests/ui/upper_case_acronyms.fixed @@ -0,0 +1,62 @@ +#![warn(clippy::upper_case_acronyms)] + +struct HTTPResponse; // not linted by default, but with cfg option + +struct CString; // not linted + +enum Flags { + NS, // not linted + Cwr, + //~^ ERROR: name `CWR` contains a capitalized acronym + //~| NOTE: `-D clippy::upper-case-acronyms` implied by `-D warnings` + Ece, + //~^ ERROR: name `ECE` contains a capitalized acronym + Urg, + //~^ ERROR: name `URG` contains a capitalized acronym + Ack, + //~^ ERROR: name `ACK` contains a capitalized acronym + Psh, + //~^ ERROR: name `PSH` contains a capitalized acronym + Rst, + //~^ ERROR: name `RST` contains a capitalized acronym + Syn, + //~^ ERROR: name `SYN` contains a capitalized acronym + Fin, + //~^ ERROR: name `FIN` contains a capitalized acronym +} + +// linted with cfg option, beware that lint suggests `GccllvmSomething` instead of +// `GccLlvmSomething` +struct GCCLLVMSomething; + +// public items must not be linted +pub struct NOWARNINGHERE; +pub struct ALSONoWarningHERE; + +// enum variants should not be linted if the num is pub +pub enum ParseError { + YDB(u8), + Utf8(std::string::FromUtf8Error), + Parse(T, String), +} + +// private, do lint here +enum ParseErrorPrivate { + Wasd(u8), + //~^ ERROR: name `WASD` contains a capitalized acronym + Utf8(std::string::FromUtf8Error), + Parse(T, String), +} + +// do lint here +struct Json; +//~^ ERROR: name `JSON` contains a capitalized acronym + +// do lint here +enum Yaml { + //~^ ERROR: name `YAML` contains a capitalized acronym + Num(u32), + Str(String), +} + +fn main() {} diff --git a/src/tools/clippy/tests/ui/upper_case_acronyms.rs b/src/tools/clippy/tests/ui/upper_case_acronyms.rs index 9b7c2f28e..6a20aee62 100644 --- a/src/tools/clippy/tests/ui/upper_case_acronyms.rs +++ b/src/tools/clippy/tests/ui/upper_case_acronyms.rs @@ -7,13 +7,22 @@ struct CString; // not linted enum Flags { NS, // not linted CWR, + //~^ ERROR: name `CWR` contains a capitalized acronym + //~| NOTE: `-D clippy::upper-case-acronyms` implied by `-D warnings` ECE, + //~^ ERROR: name `ECE` contains a capitalized acronym URG, + //~^ ERROR: name `URG` contains a capitalized acronym ACK, + //~^ ERROR: name `ACK` contains a capitalized acronym PSH, + //~^ ERROR: name `PSH` contains a capitalized acronym RST, + //~^ ERROR: name `RST` contains a capitalized acronym SYN, + //~^ ERROR: name `SYN` contains a capitalized acronym FIN, + //~^ ERROR: name `FIN` contains a capitalized acronym } // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of @@ -34,15 +43,18 @@ pub enum ParseError { // private, do lint here enum ParseErrorPrivate { WASD(u8), + //~^ ERROR: name `WASD` contains a capitalized acronym Utf8(std::string::FromUtf8Error), Parse(T, String), } // do lint here struct JSON; +//~^ ERROR: name `JSON` contains a capitalized acronym // do lint here enum YAML { + //~^ ERROR: name `YAML` contains a capitalized acronym Num(u32), Str(String), } diff --git a/src/tools/clippy/tests/ui/upper_case_acronyms.stderr b/src/tools/clippy/tests/ui/upper_case_acronyms.stderr index 74082ec16..c57b325e9 100644 --- a/src/tools/clippy/tests/ui/upper_case_acronyms.stderr +++ b/src/tools/clippy/tests/ui/upper_case_acronyms.stderr @@ -5,63 +5,64 @@ LL | CWR, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Cwr` | = note: `-D clippy::upper-case-acronyms` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::upper_case_acronyms)]` error: name `ECE` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:10:5 + --> $DIR/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.rs:11:5 + --> $DIR/upper_case_acronyms.rs:14: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.rs:12:5 + --> $DIR/upper_case_acronyms.rs:16: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.rs:13:5 + --> $DIR/upper_case_acronyms.rs:18: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.rs:14:5 + --> $DIR/upper_case_acronyms.rs:20: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.rs:15:5 + --> $DIR/upper_case_acronyms.rs:22: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.rs:16:5 + --> $DIR/upper_case_acronyms.rs:24:5 | LL | FIN, | ^^^ help: consider making the acronym lowercase, except the initial letter: `Fin` error: name `WASD` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:36:5 + --> $DIR/upper_case_acronyms.rs:45:5 | LL | WASD(u8), | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Wasd` error: name `JSON` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:42:8 + --> $DIR/upper_case_acronyms.rs:52:8 | LL | struct JSON; | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Json` error: name `YAML` contains a capitalized acronym - --> $DIR/upper_case_acronyms.rs:45:6 + --> $DIR/upper_case_acronyms.rs:56:6 | LL | enum YAML { | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Yaml` diff --git a/src/tools/clippy/tests/ui/use_self.fixed b/src/tools/clippy/tests/ui/use_self.fixed index 4179f21c5..787dd3ec7 100644 --- a/src/tools/clippy/tests/ui/use_self.fixed +++ b/src/tools/clippy/tests/ui/use_self.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![warn(clippy::use_self)] #![allow(dead_code, unreachable_code)] diff --git a/src/tools/clippy/tests/ui/use_self.rs b/src/tools/clippy/tests/ui/use_self.rs index 01a36def9..39e182fae 100644 --- a/src/tools/clippy/tests/ui/use_self.rs +++ b/src/tools/clippy/tests/ui/use_self.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![warn(clippy::use_self)] #![allow(dead_code, unreachable_code)] diff --git a/src/tools/clippy/tests/ui/use_self.stderr b/src/tools/clippy/tests/ui/use_self.stderr index 48364c40c..a1d4eac5d 100644 --- a/src/tools/clippy/tests/ui/use_self.stderr +++ b/src/tools/clippy/tests/ui/use_self.stderr @@ -1,253 +1,254 @@ error: unnecessary structure name repetition - --> $DIR/use_self.rs:22:21 + --> $DIR/use_self.rs:21:21 | LL | fn new() -> Foo { | ^^^ help: use the applicable keyword: `Self` | = note: `-D clippy::use-self` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::use_self)]` error: unnecessary structure name repetition - --> $DIR/use_self.rs:23:13 + --> $DIR/use_self.rs:22:13 | LL | Foo {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:25:22 + --> $DIR/use_self.rs:24:22 | LL | fn test() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:26:13 + --> $DIR/use_self.rs:25:13 | LL | Foo::new() | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:31:25 + --> $DIR/use_self.rs:30:25 | LL | fn default() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:32:13 + --> $DIR/use_self.rs:31:13 | LL | Foo::new() | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:97:24 + --> $DIR/use_self.rs:96:24 | LL | fn bad(foos: &[Foo]) -> impl Iterator { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:97:55 + --> $DIR/use_self.rs:96:55 | LL | fn bad(foos: &[Foo]) -> impl Iterator { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:112:13 + --> $DIR/use_self.rs:111:13 | LL | TS(0) | ^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:147:29 + --> $DIR/use_self.rs:146:29 | LL | fn bar() -> Bar { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:148:21 + --> $DIR/use_self.rs:147:21 | LL | Bar { foo: Foo {} } | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:159:21 + --> $DIR/use_self.rs:158:21 | LL | fn baz() -> Foo { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:160:13 + --> $DIR/use_self.rs:159:13 | LL | Foo {} | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:177:21 + --> $DIR/use_self.rs:176:21 | LL | let _ = Enum::B(42); | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:178:21 + --> $DIR/use_self.rs:177:21 | LL | let _ = Enum::C { field: true }; | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:179:21 + --> $DIR/use_self.rs:178:21 | LL | let _ = Enum::A; | ^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:221:13 + --> $DIR/use_self.rs:220:13 | LL | nested::A::fun_1(); | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:222:13 + --> $DIR/use_self.rs:221:13 | LL | nested::A::A; | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:224:13 + --> $DIR/use_self.rs:223:13 | LL | nested::A {}; | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:243:13 + --> $DIR/use_self.rs:242:13 | LL | TestStruct::from_something() | ^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:257:25 + --> $DIR/use_self.rs:256:25 | LL | async fn g() -> S { | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:258:13 + --> $DIR/use_self.rs:257:13 | LL | S {} | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:262:16 + --> $DIR/use_self.rs:261:16 | LL | &p[S::A..S::B] | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:262:22 + --> $DIR/use_self.rs:261:22 | LL | &p[S::A..S::B] | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:285:29 + --> $DIR/use_self.rs:284:29 | LL | fn foo(value: T) -> Foo { | ^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:286:13 + --> $DIR/use_self.rs:285:13 | LL | Foo:: { value } | ^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:458:13 + --> $DIR/use_self.rs:457:13 | LL | A::new::(submod::B {}) | ^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:495:13 + --> $DIR/use_self.rs:494:13 | LL | S2::new() | ^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:532:17 + --> $DIR/use_self.rs:531:17 | LL | Foo::Bar => unimplemented!(), | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:533:17 + --> $DIR/use_self.rs:532:17 | LL | Foo::Baz => unimplemented!(), | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:539:20 + --> $DIR/use_self.rs:538:20 | LL | if let Foo::Bar = self { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:563:17 + --> $DIR/use_self.rs:562:17 | LL | Something::Num(n) => *n, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:564:17 + --> $DIR/use_self.rs:563:17 | LL | Something::TupleNums(n, _m) => *n, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:565:17 + --> $DIR/use_self.rs:564:17 | LL | Something::StructNums { one, two: _ } => *one, | ^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:571:17 + --> $DIR/use_self.rs:570:17 | LL | crate::issue8845::Something::Num(n) => *n, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:572:17 + --> $DIR/use_self.rs:571:17 | LL | crate::issue8845::Something::TupleNums(n, _m) => *n, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:573:17 + --> $DIR/use_self.rs:572:17 | LL | crate::issue8845::Something::StructNums { one, two: _ } => *one, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:589:17 + --> $DIR/use_self.rs:588:17 | LL | let Foo(x) = self; | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:594:17 + --> $DIR/use_self.rs:593:17 | LL | let crate::issue8845::Foo(x) = self; | ^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:601:17 + --> $DIR/use_self.rs:600:17 | LL | let Bar { x, .. } = self; | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:606:17 + --> $DIR/use_self.rs:605:17 | LL | let crate::issue8845::Bar { x, .. } = self; | ^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self.rs:645:17 + --> $DIR/use_self.rs:644:17 | LL | E::A => {}, | ^ help: use the applicable keyword: `Self` diff --git a/src/tools/clippy/tests/ui/use_self_trait.fixed b/src/tools/clippy/tests/ui/use_self_trait.fixed index 20138a29f..2758ec7ac 100644 --- a/src/tools/clippy/tests/ui/use_self_trait.fixed +++ b/src/tools/clippy/tests/ui/use_self_trait.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::use_self)] #![allow(dead_code)] #![allow(clippy::should_implement_trait, clippy::boxed_local)] diff --git a/src/tools/clippy/tests/ui/use_self_trait.rs b/src/tools/clippy/tests/ui/use_self_trait.rs index bf697b01a..31031e8f5 100644 --- a/src/tools/clippy/tests/ui/use_self_trait.rs +++ b/src/tools/clippy/tests/ui/use_self_trait.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![warn(clippy::use_self)] #![allow(dead_code)] #![allow(clippy::should_implement_trait, clippy::boxed_local)] diff --git a/src/tools/clippy/tests/ui/use_self_trait.stderr b/src/tools/clippy/tests/ui/use_self_trait.stderr index 6257f802d..71a227174 100644 --- a/src/tools/clippy/tests/ui/use_self_trait.stderr +++ b/src/tools/clippy/tests/ui/use_self_trait.stderr @@ -1,97 +1,98 @@ error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:21:18 + --> $DIR/use_self_trait.rs:19:18 | LL | fn refs(p1: &Bad) -> &Bad { | ^^^ help: use the applicable keyword: `Self` | = note: `-D clippy::use-self` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::use_self)]` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:21:27 + --> $DIR/use_self_trait.rs:19:27 | LL | fn refs(p1: &Bad) -> &Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:25:33 + --> $DIR/use_self_trait.rs:23: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:25:49 + --> $DIR/use_self_trait.rs:23: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:29:26 + --> $DIR/use_self_trait.rs:27: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:29:39 + --> $DIR/use_self_trait.rs:27: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:33:24 + --> $DIR/use_self_trait.rs:31: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:33:42 + --> $DIR/use_self_trait.rs:31: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:35:16 + --> $DIR/use_self_trait.rs:33:16 | LL | fn vals(_: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:35:24 + --> $DIR/use_self_trait.rs:33:24 | LL | fn vals(_: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:36:9 + --> $DIR/use_self_trait.rs:34:9 | LL | Bad | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:41:19 + --> $DIR/use_self_trait.rs:39:19 | LL | type Output = Bad; | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:43:23 + --> $DIR/use_self_trait.rs:41:23 | LL | fn mul(self, rhs: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:43:31 + --> $DIR/use_self_trait.rs:41:31 | LL | fn mul(self, rhs: Bad) -> Bad { | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:50:9 + --> $DIR/use_self_trait.rs:48:9 | LL | Bad | ^^^ help: use the applicable keyword: `Self` error: unnecessary structure name repetition - --> $DIR/use_self_trait.rs:147:13 + --> $DIR/use_self_trait.rs:145:13 | LL | std::fmt::Error // Should lint | ^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self` diff --git a/src/tools/clippy/tests/ui/used_underscore_binding.rs b/src/tools/clippy/tests/ui/used_underscore_binding.rs index 879e2e24a..a8f404b14 100644 --- a/src/tools/clippy/tests/ui/used_underscore_binding.rs +++ b/src/tools/clippy/tests/ui/used_underscore_binding.rs @@ -1,6 +1,5 @@ -//@aux-build:proc_macro_derive.rs:proc-macro -#![feature(rustc_private)] -#![warn(clippy::all)] +//@aux-build:proc_macro_derive.rs +#![feature(rustc_private, lint_reasons)] #![warn(clippy::used_underscore_binding)] #![allow(clippy::disallowed_names, clippy::eq_op, clippy::uninlined_format_args)] @@ -107,6 +106,31 @@ async fn await_desugaring() { .await } +struct PhantomField { + _marker: std::marker::PhantomData, +} + +impl std::fmt::Debug for PhantomField { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.debug_struct("PhantomField").field("_marker", &self._marker).finish() + } +} + +struct AllowedField { + #[allow(clippy::used_underscore_binding)] + _allowed: usize, +} + +struct ExpectedField { + #[expect(clippy::used_underscore_binding)] + _expected: usize, +} + +fn lint_levels(allowed: AllowedField, expected: ExpectedField) { + let _ = allowed._allowed; + let _ = expected._expected; +} + fn main() { let foo = 0u32; // tests of unused_underscore lint diff --git a/src/tools/clippy/tests/ui/used_underscore_binding.stderr b/src/tools/clippy/tests/ui/used_underscore_binding.stderr index 875fafe43..78d827981 100644 --- a/src/tools/clippy/tests/ui/used_underscore_binding.stderr +++ b/src/tools/clippy/tests/ui/used_underscore_binding.stderr @@ -1,40 +1,76 @@ error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used - --> $DIR/used_underscore_binding.rs:24:5 + --> $DIR/used_underscore_binding.rs:23:5 | LL | _foo + 1 | ^^^^ | +note: `_foo` is defined here + --> $DIR/used_underscore_binding.rs:22:22 + | +LL | fn prefix_underscore(_foo: u32) -> u32 { + | ^^^^ = note: `-D clippy::used-underscore-binding` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::used_underscore_binding)]` error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used - --> $DIR/used_underscore_binding.rs:29:20 + --> $DIR/used_underscore_binding.rs:28:20 | LL | println!("{}", _foo); | ^^^^ + | +note: `_foo` is defined here + --> $DIR/used_underscore_binding.rs:27:24 + | +LL | fn in_macro_or_desugar(_foo: u32) { + | ^^^^ error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used - --> $DIR/used_underscore_binding.rs:30:16 + --> $DIR/used_underscore_binding.rs:29:16 | LL | assert_eq!(_foo, _foo); | ^^^^ + | +note: `_foo` is defined here + --> $DIR/used_underscore_binding.rs:27:24 + | +LL | fn in_macro_or_desugar(_foo: u32) { + | ^^^^ error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used - --> $DIR/used_underscore_binding.rs:30:22 + --> $DIR/used_underscore_binding.rs:29:22 | LL | assert_eq!(_foo, _foo); | ^^^^ + | +note: `_foo` is defined here + --> $DIR/used_underscore_binding.rs:27:24 + | +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:43:5 + --> $DIR/used_underscore_binding.rs:42:5 | LL | s._underscore_field += 1; | ^^^^^^^^^^^^^^^^^^^ + | +note: `_underscore_field` is defined here + --> $DIR/used_underscore_binding.rs:36: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:104:16 + --> $DIR/used_underscore_binding.rs:103:16 | LL | uses_i(_i); | ^^ + | +note: `_i` is defined here + --> $DIR/used_underscore_binding.rs:102:13 + | +LL | let _i = 5; + | ^^ error: aborting due to 6 previous errors diff --git a/src/tools/clippy/tests/ui/useless_asref.fixed b/src/tools/clippy/tests/ui/useless_asref.fixed index e42731f9b..f6770558b 100644 --- a/src/tools/clippy/tests/ui/useless_asref.fixed +++ b/src/tools/clippy/tests/ui/useless_asref.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::useless_asref)] #![allow( clippy::explicit_auto_deref, diff --git a/src/tools/clippy/tests/ui/useless_asref.rs b/src/tools/clippy/tests/ui/useless_asref.rs index 50c9990bb..099621807 100644 --- a/src/tools/clippy/tests/ui/useless_asref.rs +++ b/src/tools/clippy/tests/ui/useless_asref.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![deny(clippy::useless_asref)] #![allow( clippy::explicit_auto_deref, diff --git a/src/tools/clippy/tests/ui/useless_asref.stderr b/src/tools/clippy/tests/ui/useless_asref.stderr index c97851ac6..163eb7b14 100644 --- a/src/tools/clippy/tests/ui/useless_asref.stderr +++ b/src/tools/clippy/tests/ui/useless_asref.stderr @@ -1,71 +1,71 @@ error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:47:18 + --> $DIR/useless_asref.rs:46:18 | LL | foo_rstr(rstr.as_ref()); | ^^^^^^^^^^^^^ help: try: `rstr` | note: the lint level is defined here - --> $DIR/useless_asref.rs:2:9 + --> $DIR/useless_asref.rs:1:9 | LL | #![deny(clippy::useless_asref)] | ^^^^^^^^^^^^^^^^^^^^^ error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:49:20 + --> $DIR/useless_asref.rs:48:20 | LL | foo_rslice(rslice.as_ref()); | ^^^^^^^^^^^^^^^ help: try: `rslice` error: this call to `as_mut` does nothing - --> $DIR/useless_asref.rs:53:21 + --> $DIR/useless_asref.rs:52:21 | LL | foo_mrslice(mrslice.as_mut()); | ^^^^^^^^^^^^^^^^ help: try: `mrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:55:20 + --> $DIR/useless_asref.rs:54:20 | LL | foo_rslice(mrslice.as_ref()); | ^^^^^^^^^^^^^^^^ help: try: `mrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:62:20 + --> $DIR/useless_asref.rs:61:20 | LL | foo_rslice(rrrrrslice.as_ref()); | ^^^^^^^^^^^^^^^^^^^ help: try: `rrrrrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:64:18 + --> $DIR/useless_asref.rs:63:18 | LL | foo_rstr(rrrrrstr.as_ref()); | ^^^^^^^^^^^^^^^^^ help: try: `rrrrrstr` error: this call to `as_mut` does nothing - --> $DIR/useless_asref.rs:69:21 + --> $DIR/useless_asref.rs:68:21 | LL | foo_mrslice(mrrrrrslice.as_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: try: `mrrrrrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:71:20 + --> $DIR/useless_asref.rs:70:20 | LL | foo_rslice(mrrrrrslice.as_ref()); | ^^^^^^^^^^^^^^^^^^^^ help: try: `mrrrrrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:75:16 + --> $DIR/useless_asref.rs:74:16 | LL | foo_rrrrmr((&&&&MoreRef).as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `(&&&&MoreRef)` error: this call to `as_mut` does nothing - --> $DIR/useless_asref.rs:125:13 + --> $DIR/useless_asref.rs:124:13 | LL | foo_mrt(mrt.as_mut()); | ^^^^^^^^^^^^ help: try: `mrt` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:127:12 + --> $DIR/useless_asref.rs:126:12 | LL | foo_rt(mrt.as_ref()); | ^^^^^^^^^^^^ help: try: `mrt` diff --git a/src/tools/clippy/tests/ui/useless_attribute.fixed b/src/tools/clippy/tests/ui/useless_attribute.fixed index 8e77ec444..98a2bed0e 100644 --- a/src/tools/clippy/tests/ui/useless_attribute.fixed +++ b/src/tools/clippy/tests/ui/useless_attribute.fixed @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![allow(unused)] #![warn(clippy::useless_attribute)] diff --git a/src/tools/clippy/tests/ui/useless_attribute.rs b/src/tools/clippy/tests/ui/useless_attribute.rs index 27498d9bc..c5e324717 100644 --- a/src/tools/clippy/tests/ui/useless_attribute.rs +++ b/src/tools/clippy/tests/ui/useless_attribute.rs @@ -1,5 +1,4 @@ -//@run-rustfix -//@aux-build:proc_macro_derive.rs:proc-macro +//@aux-build:proc_macro_derive.rs #![allow(unused)] #![warn(clippy::useless_attribute)] diff --git a/src/tools/clippy/tests/ui/useless_attribute.stderr b/src/tools/clippy/tests/ui/useless_attribute.stderr index a7ea0df22..e65c59aba 100644 --- a/src/tools/clippy/tests/ui/useless_attribute.stderr +++ b/src/tools/clippy/tests/ui/useless_attribute.stderr @@ -1,19 +1,20 @@ error: useless lint attribute - --> $DIR/useless_attribute.rs:9:1 + --> $DIR/useless_attribute.rs:8:1 | LL | #[allow(dead_code)] | ^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(dead_code)]` | = note: `-D clippy::useless-attribute` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::useless_attribute)]` error: useless lint attribute - --> $DIR/useless_attribute.rs:10:1 + --> $DIR/useless_attribute.rs:9:1 | LL | #[cfg_attr(feature = "cargo-clippy", allow(dead_code))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![cfg_attr(feature = "cargo-clippy", allow(dead_code)` error: useless lint attribute - --> $DIR/useless_attribute.rs:21:5 + --> $DIR/useless_attribute.rs:20:5 | LL | #[allow(clippy::almost_swapped)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(clippy::almost_swapped)]` diff --git a/src/tools/clippy/tests/ui/useless_conversion.fixed b/src/tools/clippy/tests/ui/useless_conversion.fixed index 53d8a5a9f..ed8387b7e 100644 --- a/src/tools/clippy/tests/ui/useless_conversion.fixed +++ b/src/tools/clippy/tests/ui/useless_conversion.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::useless_conversion)] #![allow(clippy::needless_if, clippy::unnecessary_wraps)] @@ -153,6 +151,8 @@ fn main() { let _ = s3; let s4: Foo<'a'> = Foo; let _ = vec![s4, s4, s4].into_iter(); + + issue11300::bar(); } #[allow(dead_code)] @@ -198,6 +198,95 @@ fn explicit_into_iter_fn_arg() { b(macro_generated!()); } +mod issue11300 { + pub fn foo(i: I) + where + I: IntoIterator + ExactSizeIterator, + { + assert_eq!(i.len(), 3); + } + + trait Helper {} + impl Helper for [i32; 3] {} + impl Helper for std::array::IntoIter {} + impl Helper<()> for std::array::IntoIter {} + + fn foo2(_: I) + where + I: IntoIterator + Helper, + { + } + + trait Helper2 {} + impl Helper2> for i32 {} + impl Helper2<[i32; 3]> for i32 {} + fn foo3(_: I) + where + I: IntoIterator, + i32: Helper2, + { + } + + pub fn bar() { + // This should not trigger the lint: + // `[i32, 3]` does not satisfy the `ExactSizeIterator` bound, so the into_iter call cannot be + // removed and is not useless. + foo([1, 2, 3].into_iter()); + + // This should trigger the lint, receiver type [i32; 3] also implements `Helper` + foo2::([1, 2, 3]); + + // 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). + foo2::<(), _>([1, 2, 3].into_iter()); + + // 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 unncessary. + foo3([1, 2, 3]); + } + + fn ice() { + struct S1; + impl S1 { + pub fn foo(&self, _: I) {} + } + + S1.foo([1, 2]); + + // ICE that occured in itertools + trait Itertools { + fn interleave_shortest(self, other: J) + where + J: IntoIterator, + Self: Sized; + } + impl Itertools for I { + fn interleave_shortest(self, other: J) + where + J: IntoIterator, + Self: Sized, + { + } + } + let v0: Vec = vec![0, 2, 4]; + let v1: Vec = vec![1, 3, 5, 7]; + v0.into_iter().interleave_shortest(v1); + + trait TraitWithLifetime<'a> {} + impl<'a> TraitWithLifetime<'a> for std::array::IntoIter<&'a i32, 2> {} + + struct Helper; + impl<'a> Helper { + fn with_lt(&self, _: I) + where + I: IntoIterator + TraitWithLifetime<'a>, + { + } + } + Helper.with_lt([&1, &2].into_iter()); + } +} + #[derive(Copy, Clone)] struct Foo; diff --git a/src/tools/clippy/tests/ui/useless_conversion.rs b/src/tools/clippy/tests/ui/useless_conversion.rs index 51ba49873..991a7762f 100644 --- a/src/tools/clippy/tests/ui/useless_conversion.rs +++ b/src/tools/clippy/tests/ui/useless_conversion.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![deny(clippy::useless_conversion)] #![allow(clippy::needless_if, clippy::unnecessary_wraps)] @@ -153,6 +151,8 @@ fn main() { let _ = Foo::<'a'>::from(s3); let s4: Foo<'a'> = Foo; let _ = vec![s4, s4, s4].into_iter().into_iter(); + + issue11300::bar(); } #[allow(dead_code)] @@ -198,6 +198,95 @@ fn explicit_into_iter_fn_arg() { b(macro_generated!()); } +mod issue11300 { + pub fn foo(i: I) + where + I: IntoIterator + ExactSizeIterator, + { + assert_eq!(i.len(), 3); + } + + trait Helper {} + impl Helper for [i32; 3] {} + impl Helper for std::array::IntoIter {} + impl Helper<()> for std::array::IntoIter {} + + fn foo2(_: I) + where + I: IntoIterator + Helper, + { + } + + trait Helper2 {} + impl Helper2> for i32 {} + impl Helper2<[i32; 3]> for i32 {} + fn foo3(_: I) + where + I: IntoIterator, + i32: Helper2, + { + } + + pub fn bar() { + // This should not trigger the lint: + // `[i32, 3]` does not satisfy the `ExactSizeIterator` bound, so the into_iter call cannot be + // removed and is not useless. + foo([1, 2, 3].into_iter()); + + // This should trigger the lint, receiver type [i32; 3] also implements `Helper` + foo2::([1, 2, 3].into_iter()); + + // 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). + foo2::<(), _>([1, 2, 3].into_iter()); + + // 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 unncessary. + foo3([1, 2, 3].into_iter()); + } + + fn ice() { + struct S1; + impl S1 { + pub fn foo(&self, _: I) {} + } + + S1.foo([1, 2].into_iter()); + + // ICE that occured in itertools + trait Itertools { + fn interleave_shortest(self, other: J) + where + J: IntoIterator, + Self: Sized; + } + impl Itertools for I { + fn interleave_shortest(self, other: J) + where + J: IntoIterator, + Self: Sized, + { + } + } + let v0: Vec = vec![0, 2, 4]; + let v1: Vec = vec![1, 3, 5, 7]; + v0.into_iter().interleave_shortest(v1.into_iter()); + + trait TraitWithLifetime<'a> {} + impl<'a> TraitWithLifetime<'a> for std::array::IntoIter<&'a i32, 2> {} + + struct Helper; + impl<'a> Helper { + fn with_lt(&self, _: I) + where + I: IntoIterator + TraitWithLifetime<'a>, + { + } + } + Helper.with_lt([&1, &2].into_iter()); + } +} + #[derive(Copy, Clone)] struct Foo; diff --git a/src/tools/clippy/tests/ui/useless_conversion.stderr b/src/tools/clippy/tests/ui/useless_conversion.stderr index 6f7dc01d2..c1f8b6b4a 100644 --- a/src/tools/clippy/tests/ui/useless_conversion.stderr +++ b/src/tools/clippy/tests/ui/useless_conversion.stderr @@ -1,119 +1,119 @@ error: useless conversion to the same type: `T` - --> $DIR/useless_conversion.rs:7:13 + --> $DIR/useless_conversion.rs:5:13 | LL | let _ = T::from(val); | ^^^^^^^^^^^^ help: consider removing `T::from()`: `val` | note: the lint level is defined here - --> $DIR/useless_conversion.rs:3:9 + --> $DIR/useless_conversion.rs:1:9 | LL | #![deny(clippy::useless_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: useless conversion to the same type: `T` - --> $DIR/useless_conversion.rs:8:5 + --> $DIR/useless_conversion.rs:6:5 | LL | val.into() | ^^^^^^^^^^ help: consider removing `.into()`: `val` error: useless conversion to the same type: `i32` - --> $DIR/useless_conversion.rs:20:22 + --> $DIR/useless_conversion.rs:18:22 | LL | let _: i32 = 0i32.into(); | ^^^^^^^^^^^ help: consider removing `.into()`: `0i32` error: useless conversion to the same type: `std::str::Lines<'_>` - --> $DIR/useless_conversion.rs:50:22 + --> $DIR/useless_conversion.rs:48:22 | 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:55:21 + --> $DIR/useless_conversion.rs:53: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:61:22 + --> $DIR/useless_conversion.rs:59: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:67:13 + --> $DIR/useless_conversion.rs:65: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:72:17 + --> $DIR/useless_conversion.rs:70: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:134:21 + --> $DIR/useless_conversion.rs:132: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:135:21 + --> $DIR/useless_conversion.rs:133: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:136:13 + --> $DIR/useless_conversion.rs:134: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:137:13 + --> $DIR/useless_conversion.rs:135: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:138:13 + --> $DIR/useless_conversion.rs:136: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:139:13 + --> $DIR/useless_conversion.rs:137: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:140:21 + --> $DIR/useless_conversion.rs:138: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:145:13 + --> $DIR/useless_conversion.rs:143: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:151:23 + --> $DIR/useless_conversion.rs:149: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:153:13 + --> $DIR/useless_conversion.rs:151: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:155:13 + --> $DIR/useless_conversion.rs:153:13 | LL | let _ = vec![s4, s4, s4].into_iter().into_iter(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![s4, s4, s4].into_iter()` @@ -178,5 +178,53 @@ note: this parameter accepts any `IntoIterator`, so you don't need to call `.int LL | fn b>(_: T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 24 previous errors +error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` + --> $DIR/useless_conversion.rs:237: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 + | +LL | I: IntoIterator + Helper, + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` + --> $DIR/useless_conversion.rs:245: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 + | +LL | I: IntoIterator, + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` + --> $DIR/useless_conversion.rs:254: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 + | +LL | pub fn foo(&self, _: I) {} + | ^^^^^^^^^^^^ + +error: explicit call to `.into_iter()` in function argument accepting `IntoIterator` + --> $DIR/useless_conversion.rs:273: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 + | +LL | J: IntoIterator, + | ^^^^^^^^^^^^ + +error: aborting due to 28 previous errors diff --git a/src/tools/clippy/tests/ui/useless_conversion_try.rs b/src/tools/clippy/tests/ui/useless_conversion_try.rs index ec0512ce2..a5feefbe0 100644 --- a/src/tools/clippy/tests/ui/useless_conversion_try.rs +++ b/src/tools/clippy/tests/ui/useless_conversion_try.rs @@ -3,7 +3,9 @@ fn test_generic(val: T) -> T { let _ = T::try_from(val).unwrap(); + //~^ ERROR: useless conversion to the same type: `T` val.try_into().unwrap() + //~^ ERROR: useless conversion to the same type: `T` } fn test_generic2 + Into, U: From>(val: T) { @@ -26,12 +28,19 @@ fn main() { let _: String = "foo".try_into().unwrap(); } let _: String = "foo".to_string().try_into().unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = TryFrom::try_from("foo".to_string()).unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _ = String::try_from("foo".to_string()).unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _ = String::try_from(format!("A: {:04}", 123)).unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = format!("Hello {}", "world").try_into().unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = String::new().try_into().unwrap(); + //~^ ERROR: useless conversion to the same type: `std::string::String` let _: String = match String::from("_").try_into() { + //~^ ERROR: useless conversion to the same type: `std::string::String` Ok(a) => a, Err(_) => String::new(), }; diff --git a/src/tools/clippy/tests/ui/useless_conversion_try.stderr b/src/tools/clippy/tests/ui/useless_conversion_try.stderr index 54189f8d2..938bfb523 100644 --- a/src/tools/clippy/tests/ui/useless_conversion_try.stderr +++ b/src/tools/clippy/tests/ui/useless_conversion_try.stderr @@ -12,7 +12,7 @@ LL | #![deny(clippy::useless_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: useless conversion to the same type: `T` - --> $DIR/useless_conversion_try.rs:6:5 + --> $DIR/useless_conversion_try.rs:7:5 | LL | val.try_into().unwrap() | ^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | val.try_into().unwrap() = help: consider removing `.try_into()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:28:21 + --> $DIR/useless_conversion_try.rs:30:21 | LL | let _: String = "foo".to_string().try_into().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | let _: String = "foo".to_string().try_into().unwrap(); = help: consider removing `.try_into()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:29:21 + --> $DIR/useless_conversion_try.rs:32:21 | LL | let _: String = TryFrom::try_from("foo".to_string()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | let _: String = TryFrom::try_from("foo".to_string()).unwrap(); = help: consider removing `TryFrom::try_from()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:30:13 + --> $DIR/useless_conversion_try.rs:34:13 | LL | let _ = String::try_from("foo".to_string()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -44,7 +44,7 @@ LL | let _ = String::try_from("foo".to_string()).unwrap(); = help: consider removing `String::try_from()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:31:13 + --> $DIR/useless_conversion_try.rs:36:13 | LL | let _ = String::try_from(format!("A: {:04}", 123)).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -52,7 +52,7 @@ LL | let _ = String::try_from(format!("A: {:04}", 123)).unwrap(); = help: consider removing `String::try_from()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:32:21 + --> $DIR/useless_conversion_try.rs:38:21 | LL | let _: String = format!("Hello {}", "world").try_into().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | let _: String = format!("Hello {}", "world").try_into().unwrap(); = help: consider removing `.try_into()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:33:21 + --> $DIR/useless_conversion_try.rs:40:21 | LL | let _: String = String::new().try_into().unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -68,7 +68,7 @@ LL | let _: String = String::new().try_into().unwrap(); = help: consider removing `.try_into()` error: useless conversion to the same type: `std::string::String` - --> $DIR/useless_conversion_try.rs:34:27 + --> $DIR/useless_conversion_try.rs:42:27 | LL | let _: String = match String::from("_").try_into() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/vec.fixed b/src/tools/clippy/tests/ui/vec.fixed index 7a7d0026f..bcbca971a 100644 --- a/src/tools/clippy/tests/ui/vec.fixed +++ b/src/tools/clippy/tests/ui/vec.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::useless_vec)] #![allow(clippy::nonstandard_macro_braces, clippy::uninlined_format_args, unused)] @@ -121,6 +120,7 @@ fn issue11075() { stringify!($e) }; } + #[allow(clippy::never_loop)] for _string in [repro!(true), repro!(null)] { unimplemented!(); } diff --git a/src/tools/clippy/tests/ui/vec.rs b/src/tools/clippy/tests/ui/vec.rs index cbe7685b4..087425585 100644 --- a/src/tools/clippy/tests/ui/vec.rs +++ b/src/tools/clippy/tests/ui/vec.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::useless_vec)] #![allow(clippy::nonstandard_macro_braces, clippy::uninlined_format_args, unused)] @@ -121,6 +120,7 @@ fn issue11075() { stringify!($e) }; } + #[allow(clippy::never_loop)] for _string in vec![repro!(true), repro!(null)] { unimplemented!(); } diff --git a/src/tools/clippy/tests/ui/vec.stderr b/src/tools/clippy/tests/ui/vec.stderr index 8f6d2a1df..fc261838f 100644 --- a/src/tools/clippy/tests/ui/vec.stderr +++ b/src/tools/clippy/tests/ui/vec.stderr @@ -1,85 +1,86 @@ error: useless use of `vec!` - --> $DIR/vec.rs:31:14 + --> $DIR/vec.rs:30:14 | LL | on_slice(&vec![]); | ^^^^^^^ help: you can use a slice directly: `&[]` | = note: `-D clippy::useless-vec` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::useless_vec)]` error: useless use of `vec!` - --> $DIR/vec.rs:33:18 + --> $DIR/vec.rs:32:18 | LL | on_mut_slice(&mut vec![]); | ^^^^^^^^^^^ help: you can use a slice directly: `&mut []` error: useless use of `vec!` - --> $DIR/vec.rs:35:14 + --> $DIR/vec.rs:34:14 | LL | on_slice(&vec![1, 2]); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> $DIR/vec.rs:37:18 + --> $DIR/vec.rs:36:18 | LL | on_mut_slice(&mut vec![1, 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` error: useless use of `vec!` - --> $DIR/vec.rs:39:14 + --> $DIR/vec.rs:38:14 | LL | on_slice(&vec![1, 2]); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> $DIR/vec.rs:41:18 + --> $DIR/vec.rs:40:18 | LL | on_mut_slice(&mut vec![1, 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` error: useless use of `vec!` - --> $DIR/vec.rs:43:14 + --> $DIR/vec.rs:42:14 | LL | on_slice(&vec!(1, 2)); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> $DIR/vec.rs:45:18 + --> $DIR/vec.rs:44:18 | LL | on_mut_slice(&mut vec![1, 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` error: useless use of `vec!` - --> $DIR/vec.rs:47:14 + --> $DIR/vec.rs:46:14 | LL | on_slice(&vec![1; 2]); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1; 2]` error: useless use of `vec!` - --> $DIR/vec.rs:49:18 + --> $DIR/vec.rs:48:18 | LL | on_mut_slice(&mut vec![1; 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1; 2]` error: useless use of `vec!` - --> $DIR/vec.rs:75:19 + --> $DIR/vec.rs:74:19 | LL | let _x: i32 = vec![1, 2, 3].iter().sum(); | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> $DIR/vec.rs:78:17 + --> $DIR/vec.rs:77:17 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> $DIR/vec.rs:84:22 + --> $DIR/vec.rs:83:22 | LL | let _x: &[i32] = &vec![1, 2, 3]; | ^^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2, 3]` error: useless use of `vec!` - --> $DIR/vec.rs:86:14 + --> $DIR/vec.rs:85:14 | LL | for _ in vec![1, 2, 3] {} | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` diff --git a/src/tools/clippy/tests/ui/vec_box_sized.fixed b/src/tools/clippy/tests/ui/vec_box_sized.fixed index 0d0f710b5..4363d2224 100644 --- a/src/tools/clippy/tests/ui/vec_box_sized.fixed +++ b/src/tools/clippy/tests/ui/vec_box_sized.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] struct SizedStruct(i32); @@ -51,4 +49,9 @@ mod inner_mod { } } +// https://github.com/rust-lang/rust-clippy/issues/11417 +fn in_closure() { + let _ = |_: Vec>| {}; +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/vec_box_sized.rs b/src/tools/clippy/tests/ui/vec_box_sized.rs index fd3a7543e..f4e27fe4b 100644 --- a/src/tools/clippy/tests/ui/vec_box_sized.rs +++ b/src/tools/clippy/tests/ui/vec_box_sized.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(dead_code)] struct SizedStruct(i32); @@ -51,4 +49,9 @@ mod inner_mod { } } +// https://github.com/rust-lang/rust-clippy/issues/11417 +fn in_closure() { + let _ = |_: Vec>| {}; +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/vec_box_sized.stderr b/src/tools/clippy/tests/ui/vec_box_sized.stderr index c518267f0..9118f284b 100644 --- a/src/tools/clippy/tests/ui/vec_box_sized.stderr +++ b/src/tools/clippy/tests/ui/vec_box_sized.stderr @@ -1,37 +1,38 @@ error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:12:14 + --> $DIR/vec_box_sized.rs:10:14 | LL | const C: Vec> = Vec::new(); | ^^^^^^^^^^^^^ help: try: `Vec` | = note: `-D clippy::vec-box` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::vec_box)]` error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:13:15 + --> $DIR/vec_box_sized.rs:11:15 | LL | static S: Vec> = Vec::new(); | ^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:16:21 + --> $DIR/vec_box_sized.rs:14:21 | LL | sized_type: Vec>, | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:19:14 + --> $DIR/vec_box_sized.rs:17:14 | LL | struct A(Vec>); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:20:18 + --> $DIR/vec_box_sized.rs:18:18 | LL | struct B(Vec>>); | ^^^^^^^^^^^^^^^ help: try: `Vec` error: `Vec` is already on the heap, the boxing is unnecessary - --> $DIR/vec_box_sized.rs:48:23 + --> $DIR/vec_box_sized.rs:46:23 | LL | pub fn f() -> Vec> { | ^^^^^^^^^^^ help: try: `Vec` diff --git a/src/tools/clippy/tests/ui/vec_init_then_push.rs b/src/tools/clippy/tests/ui/vec_init_then_push.rs index 8dd098a5b..1c60a75c5 100644 --- a/src/tools/clippy/tests/ui/vec_init_then_push.rs +++ b/src/tools/clippy/tests/ui/vec_init_then_push.rs @@ -1,14 +1,18 @@ #![allow(unused_variables)] #![warn(clippy::vec_init_then_push)] - +//@no-rustfix fn main() { let mut def_err: Vec = Default::default(); + //~^ ERROR: calls to `push` immediately after creation + //~| NOTE: `-D clippy::vec-init-then-push` implied by `-D warnings` def_err.push(0); let mut new_err = Vec::::new(); + //~^ ERROR: calls to `push` immediately after creation new_err.push(1); let mut cap_err = Vec::with_capacity(2); + //~^ ERROR: calls to `push` immediately after creation cap_err.push(0); cap_err.push(1); cap_err.push(2); @@ -21,6 +25,7 @@ fn main() { cap_ok.push(0); new_err = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation new_err.push(0); let mut vec = Vec::new(); @@ -71,6 +76,7 @@ fn _cond_push(x: bool) -> Vec { fn _push_then_edit(x: u32) -> Vec { let mut v = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation v.push(x); v.push(1); v[0] = v[1] + 5; @@ -79,6 +85,7 @@ fn _push_then_edit(x: u32) -> Vec { fn _cond_push_with_large_start(x: bool) -> Vec { let mut v = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation v.push(0); v.push(1); v.push(0); @@ -92,6 +99,7 @@ fn _cond_push_with_large_start(x: bool) -> Vec { } let mut v2 = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation v2.push(0); v2.push(1); v2.push(0); @@ -107,6 +115,7 @@ fn _cond_push_with_large_start(x: bool) -> Vec { fn f() { let mut v = Vec::new(); + //~^ ERROR: calls to `push` immediately after creation v.push((0i32, 0i32)); let y = v[0].0.abs(); } diff --git a/src/tools/clippy/tests/ui/vec_init_then_push.stderr b/src/tools/clippy/tests/ui/vec_init_then_push.stderr index a9da1c520..978201bd1 100644 --- a/src/tools/clippy/tests/ui/vec_init_then_push.stderr +++ b/src/tools/clippy/tests/ui/vec_init_then_push.stderr @@ -2,70 +2,78 @@ error: calls to `push` immediately after creation --> $DIR/vec_init_then_push.rs:5:5 | LL | / let mut def_err: Vec = Default::default(); +LL | | +LL | | LL | | def_err.push(0); | |____________________^ help: consider using the `vec![]` macro: `let def_err: Vec = vec![..];` | = note: `-D clippy::vec-init-then-push` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::vec_init_then_push)]` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:8:5 + --> $DIR/vec_init_then_push.rs:10:5 | LL | / let mut new_err = Vec::::new(); +LL | | LL | | new_err.push(1); | |____________________^ help: consider using the `vec![]` macro: `let mut new_err = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:11:5 + --> $DIR/vec_init_then_push.rs:14:5 | LL | / let mut cap_err = Vec::with_capacity(2); +LL | | LL | | cap_err.push(0); LL | | cap_err.push(1); LL | | cap_err.push(2); | |____________________^ help: consider using the `vec![]` macro: `let mut cap_err = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:23:5 + --> $DIR/vec_init_then_push.rs:27:5 | LL | / new_err = Vec::new(); +LL | | LL | | new_err.push(0); | |____________________^ help: consider using the `vec![]` macro: `new_err = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:73:5 + --> $DIR/vec_init_then_push.rs:78:5 | LL | / let mut v = Vec::new(); +LL | | LL | | v.push(x); LL | | v.push(1); | |______________^ help: consider using the `vec![]` macro: `let mut v = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:81:5 + --> $DIR/vec_init_then_push.rs:87:5 | LL | / let mut v = Vec::new(); +LL | | LL | | v.push(0); LL | | v.push(1); -LL | | v.push(0); ... | LL | | v.push(1); LL | | v.push(0); | |______________^ help: consider using the `vec![]` macro: `let mut v = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:94:5 + --> $DIR/vec_init_then_push.rs:101:5 | LL | / let mut v2 = Vec::new(); +LL | | LL | | v2.push(0); LL | | v2.push(1); -LL | | v2.push(0); ... | LL | | v2.push(1); LL | | v2.push(0); | |_______________^ help: consider using the `vec![]` macro: `let mut v2 = vec![..];` error: calls to `push` immediately after creation - --> $DIR/vec_init_then_push.rs:109:5 + --> $DIR/vec_init_then_push.rs:117:5 | LL | / let mut v = Vec::new(); +LL | | LL | | v.push((0i32, 0i32)); | |_________________________^ help: consider using the `vec![]` macro: `let v = vec![..];` diff --git a/src/tools/clippy/tests/ui/vec_resize_to_zero.fixed b/src/tools/clippy/tests/ui/vec_resize_to_zero.fixed new file mode 100644 index 000000000..b4c2d8209 --- /dev/null +++ b/src/tools/clippy/tests/ui/vec_resize_to_zero.fixed @@ -0,0 +1,20 @@ +#![warn(clippy::vec_resize_to_zero)] + +fn main() { + let mut v = vec![1, 2, 3, 4, 5]; + + // applicable here + v.clear(); + //~^ ERROR: emptying a vector with `resize` + + // not applicable + v.resize(2, 5); + + let mut v = vec!["foo", "bar", "baz"]; + + // applicable here, but only implemented for integer literals for now + v.resize(0, "bar"); + + // not applicable + v.resize(2, "bar") +} diff --git a/src/tools/clippy/tests/ui/vec_resize_to_zero.rs b/src/tools/clippy/tests/ui/vec_resize_to_zero.rs index a8307e741..5b11c940f 100644 --- a/src/tools/clippy/tests/ui/vec_resize_to_zero.rs +++ b/src/tools/clippy/tests/ui/vec_resize_to_zero.rs @@ -5,6 +5,7 @@ fn main() { // applicable here v.resize(0, 5); + //~^ ERROR: emptying a vector with `resize` // not applicable v.resize(2, 5); diff --git a/src/tools/clippy/tests/ui/vec_resize_to_zero.stderr b/src/tools/clippy/tests/ui/vec_resize_to_zero.stderr index 8851e9f38..715c9923b 100644 --- a/src/tools/clippy/tests/ui/vec_resize_to_zero.stderr +++ b/src/tools/clippy/tests/ui/vec_resize_to_zero.stderr @@ -8,6 +8,7 @@ LL | v.resize(0, 5); | = help: the arguments may be inverted... = note: `-D clippy::vec-resize-to-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::vec_resize_to_zero)]` error: aborting due to previous error diff --git a/src/tools/clippy/tests/ui/verbose_file_reads.rs b/src/tools/clippy/tests/ui/verbose_file_reads.rs index df267e987..9dd4f4e1d 100644 --- a/src/tools/clippy/tests/ui/verbose_file_reads.rs +++ b/src/tools/clippy/tests/ui/verbose_file_reads.rs @@ -21,8 +21,10 @@ fn main() -> std::io::Result<()> { let mut f = File::open(path)?; let mut buffer = Vec::new(); f.read_to_end(&mut buffer)?; + //~^ ERROR: use of `File::read_to_end` // ...and this let mut string_buffer = String::new(); f.read_to_string(&mut string_buffer)?; + //~^ ERROR: use of `File::read_to_string` Ok(()) } diff --git a/src/tools/clippy/tests/ui/verbose_file_reads.stderr b/src/tools/clippy/tests/ui/verbose_file_reads.stderr index 44266c7c0..04e1aedf7 100644 --- a/src/tools/clippy/tests/ui/verbose_file_reads.stderr +++ b/src/tools/clippy/tests/ui/verbose_file_reads.stderr @@ -6,9 +6,10 @@ LL | f.read_to_end(&mut buffer)?; | = help: consider using `fs::read` instead = note: `-D clippy::verbose-file-reads` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::verbose_file_reads)]` error: use of `File::read_to_string` - --> $DIR/verbose_file_reads.rs:26:5 + --> $DIR/verbose_file_reads.rs:27:5 | LL | f.read_to_string(&mut string_buffer)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/vtable_address_comparisons.rs b/src/tools/clippy/tests/ui/vtable_address_comparisons.rs index 99c3f468f..75647c027 100644 --- a/src/tools/clippy/tests/ui/vtable_address_comparisons.rs +++ b/src/tools/clippy/tests/ui/vtable_address_comparisons.rs @@ -12,16 +12,24 @@ fn main() { // These should fail: let _ = a == b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a != b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a < b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a <= b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a > b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let _ = a >= b; + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address ptr::eq(a, b); + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address let a = &1 as &dyn Debug; let b = &1 as &dyn Debug; ptr::eq(a, b); + //~^ ERROR: comparing trait object pointers compares a non-unique vtable address // These should be fine: let a = &1; diff --git a/src/tools/clippy/tests/ui/vtable_address_comparisons.stderr b/src/tools/clippy/tests/ui/vtable_address_comparisons.stderr index 7b866d274..83c82f379 100644 --- a/src/tools/clippy/tests/ui/vtable_address_comparisons.stderr +++ b/src/tools/clippy/tests/ui/vtable_address_comparisons.stderr @@ -6,9 +6,10 @@ LL | let _ = a == b; | = help: consider extracting and comparing data pointers only = note: `-D clippy::vtable-address-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::vtable_address_comparisons)]` error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:15:13 + --> $DIR/vtable_address_comparisons.rs:16:13 | LL | let _ = a != b; | ^^^^^^ @@ -16,7 +17,7 @@ LL | let _ = a != b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:16:13 + --> $DIR/vtable_address_comparisons.rs:18:13 | LL | let _ = a < b; | ^^^^^ @@ -24,7 +25,7 @@ LL | let _ = a < b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:17:13 + --> $DIR/vtable_address_comparisons.rs:20:13 | LL | let _ = a <= b; | ^^^^^^ @@ -32,7 +33,7 @@ LL | let _ = a <= b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:18:13 + --> $DIR/vtable_address_comparisons.rs:22:13 | LL | let _ = a > b; | ^^^^^ @@ -40,7 +41,7 @@ LL | let _ = a > b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:19:13 + --> $DIR/vtable_address_comparisons.rs:24:13 | LL | let _ = a >= b; | ^^^^^^ @@ -48,7 +49,7 @@ LL | let _ = a >= b; = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:20:5 + --> $DIR/vtable_address_comparisons.rs:26:5 | LL | ptr::eq(a, b); | ^^^^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | ptr::eq(a, b); = help: consider extracting and comparing data pointers only error: comparing trait object pointers compares a non-unique vtable address - --> $DIR/vtable_address_comparisons.rs:24:5 + --> $DIR/vtable_address_comparisons.rs:31:5 | LL | ptr::eq(a, b); | ^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/while_let_loop.rs b/src/tools/clippy/tests/ui/while_let_loop.rs index 5b8075731..fa5325beb 100644 --- a/src/tools/clippy/tests/ui/while_let_loop.rs +++ b/src/tools/clippy/tests/ui/while_let_loop.rs @@ -1,9 +1,11 @@ #![warn(clippy::while_let_loop)] #![allow(clippy::uninlined_format_args)] - +//@no-rustfix fn main() { let y = Some(true); loop { + //~^ ERROR: this loop could be written as a `while let` loop + //~| NOTE: `-D clippy::while-let-loop` implied by `-D warnings` if let Some(_x) = y { let _v = 1; } else { @@ -21,6 +23,7 @@ fn main() { } loop { + //~^ ERROR: this loop could be written as a `while let` loop match y { Some(_x) => true, None => break, @@ -28,6 +31,7 @@ fn main() { } loop { + //~^ ERROR: this loop could be written as a `while let` loop let x = match y { Some(x) => x, None => break, @@ -37,6 +41,7 @@ fn main() { } loop { + //~^ ERROR: this loop could be written as a `while let` loop let x = match y { Some(x) => x, None => break, @@ -67,6 +72,7 @@ fn main() { // #675, this used to have a wrong suggestion loop { + //~^ ERROR: this loop could be written as a `while let` loop let (e, l) = match "".split_whitespace().next() { Some(word) => (word.is_empty(), word.len()), None => break, diff --git a/src/tools/clippy/tests/ui/while_let_loop.stderr b/src/tools/clippy/tests/ui/while_let_loop.stderr index 04808c0b3..db887dc65 100644 --- a/src/tools/clippy/tests/ui/while_let_loop.stderr +++ b/src/tools/clippy/tests/ui/while_let_loop.stderr @@ -2,20 +2,22 @@ error: this loop could be written as a `while let` loop --> $DIR/while_let_loop.rs:6:5 | LL | / loop { +LL | | +LL | | LL | | if let Some(_x) = y { -LL | | let _v = 1; -LL | | } else { -LL | | break; +... | LL | | } LL | | } | |_____^ help: try: `while let Some(_x) = y { .. }` | = note: `-D clippy::while-let-loop` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::while_let_loop)]` error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:23:5 + --> $DIR/while_let_loop.rs:25:5 | LL | / loop { +LL | | LL | | match y { LL | | Some(_x) => true, LL | | None => break, @@ -24,36 +26,36 @@ LL | | } | |_____^ help: try: `while let Some(_x) = y { .. }` error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:30:5 + --> $DIR/while_let_loop.rs:33:5 | LL | / loop { +LL | | LL | | let x = match y { LL | | Some(x) => x, -LL | | None => break, ... | LL | | let _str = "foo"; LL | | } | |_____^ help: try: `while let Some(x) = y { .. }` error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:39:5 + --> $DIR/while_let_loop.rs:43:5 | LL | / loop { +LL | | LL | | let x = match y { LL | | Some(x) => x, -LL | | None => break, ... | LL | | } LL | | } | |_____^ help: try: `while let Some(x) = y { .. }` error: this loop could be written as a `while let` loop - --> $DIR/while_let_loop.rs:69:5 + --> $DIR/while_let_loop.rs:74:5 | LL | / loop { +LL | | LL | | let (e, l) = match "".split_whitespace().next() { LL | | Some(word) => (word.is_empty(), word.len()), -LL | | None => break, ... | LL | | let _ = (e, l); LL | | } diff --git a/src/tools/clippy/tests/ui/while_let_on_iterator.fixed b/src/tools/clippy/tests/ui/while_let_on_iterator.fixed index 41a380ab8..d628d2227 100644 --- a/src/tools/clippy/tests/ui/while_let_on_iterator.fixed +++ b/src/tools/clippy/tests/ui/while_let_on_iterator.fixed @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::while_let_on_iterator)] #![allow(dead_code, unreachable_code, unused_mut)] #![allow( diff --git a/src/tools/clippy/tests/ui/while_let_on_iterator.rs b/src/tools/clippy/tests/ui/while_let_on_iterator.rs index 4c6433880..525dbbaaa 100644 --- a/src/tools/clippy/tests/ui/while_let_on_iterator.rs +++ b/src/tools/clippy/tests/ui/while_let_on_iterator.rs @@ -1,4 +1,3 @@ -//@run-rustfix #![warn(clippy::while_let_on_iterator)] #![allow(dead_code, unreachable_code, unused_mut)] #![allow( diff --git a/src/tools/clippy/tests/ui/while_let_on_iterator.stderr b/src/tools/clippy/tests/ui/while_let_on_iterator.stderr index 3236765e1..cdc83b816 100644 --- a/src/tools/clippy/tests/ui/while_let_on_iterator.stderr +++ b/src/tools/clippy/tests/ui/while_let_on_iterator.stderr @@ -1,157 +1,158 @@ error: this loop could be written as a `for` loop - --> $DIR/while_let_on_iterator.rs:16:5 + --> $DIR/while_let_on_iterator.rs:15:5 | LL | while let Option::Some(x) = iter.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter` | = note: `-D clippy::while-let-on-iterator` implied by `-D warnings` + = 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:21:5 + --> $DIR/while_let_on_iterator.rs:20: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:26:5 + --> $DIR/while_let_on_iterator.rs:25: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:102:9 + --> $DIR/while_let_on_iterator.rs:101: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:109:9 + --> $DIR/while_let_on_iterator.rs:108: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:122:9 + --> $DIR/while_let_on_iterator.rs:121: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:142:9 + --> $DIR/while_let_on_iterator.rs:141: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:199:9 + --> $DIR/while_let_on_iterator.rs:198: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:210:5 + --> $DIR/while_let_on_iterator.rs:209: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:212:9 + --> $DIR/while_let_on_iterator.rs:211: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:221: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:230:9 + --> $DIR/while_let_on_iterator.rs:229: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:247:9 + --> $DIR/while_let_on_iterator.rs:246: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:262:13 + --> $DIR/while_let_on_iterator.rs:261: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:294:13 + --> $DIR/while_let_on_iterator.rs:293: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:323:5 + --> $DIR/while_let_on_iterator.rs:322: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:335:9 + --> $DIR/while_let_on_iterator.rs:334: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:349:5 + --> $DIR/while_let_on_iterator.rs:348: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:360:5 + --> $DIR/while_let_on_iterator.rs:359: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:395:5 + --> $DIR/while_let_on_iterator.rs:394: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:402:5 + --> $DIR/while_let_on_iterator.rs:401: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:410:9 + --> $DIR/while_let_on_iterator.rs:409: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:420:9 + --> $DIR/while_let_on_iterator.rs:419: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:430:9 + --> $DIR/while_let_on_iterator.rs:429: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:440:9 + --> $DIR/while_let_on_iterator.rs:439: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:450:5 + --> $DIR/while_let_on_iterator.rs:449:5 | LL | while let Some(..) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in it` diff --git a/src/tools/clippy/tests/ui/wild_in_or_pats.rs b/src/tools/clippy/tests/ui/wild_in_or_pats.rs index ad600f125..f8bb31b83 100644 --- a/src/tools/clippy/tests/ui/wild_in_or_pats.rs +++ b/src/tools/clippy/tests/ui/wild_in_or_pats.rs @@ -6,6 +6,7 @@ fn main() { dbg!("matched a"); }, "bar" | _ => { + //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway dbg!("matched (bar or) wild"); }, }; @@ -14,6 +15,7 @@ fn main() { dbg!("matched a"); }, "bar" | "bar2" | _ => { + //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway dbg!("matched (bar or bar2 or) wild"); }, }; @@ -22,6 +24,7 @@ fn main() { dbg!("matched a"); }, _ | "bar" | _ => { + //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway dbg!("matched (bar or) wild"); }, }; @@ -30,6 +33,7 @@ fn main() { dbg!("matched a"); }, _ | "bar" => { + //~^ ERROR: wildcard pattern covers any other pattern as it will match anyway dbg!("matched (bar or) wild"); }, }; diff --git a/src/tools/clippy/tests/ui/wild_in_or_pats.stderr b/src/tools/clippy/tests/ui/wild_in_or_pats.stderr index bd5860f45..4cfa0d993 100644 --- a/src/tools/clippy/tests/ui/wild_in_or_pats.stderr +++ b/src/tools/clippy/tests/ui/wild_in_or_pats.stderr @@ -6,9 +6,10 @@ LL | "bar" | _ => { | = help: consider handling `_` separately = note: `-D clippy::wildcard-in-or-patterns` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wildcard_in_or_patterns)]` error: wildcard pattern covers any other pattern as it will match anyway - --> $DIR/wild_in_or_pats.rs:16:9 + --> $DIR/wild_in_or_pats.rs:17:9 | LL | "bar" | "bar2" | _ => { | ^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | "bar" | "bar2" | _ => { = help: consider handling `_` separately error: wildcard pattern covers any other pattern as it will match anyway - --> $DIR/wild_in_or_pats.rs:24:9 + --> $DIR/wild_in_or_pats.rs:26:9 | LL | _ | "bar" | _ => { | ^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | _ | "bar" | _ => { = help: consider handling `_` separately error: wildcard pattern covers any other pattern as it will match anyway - --> $DIR/wild_in_or_pats.rs:32:9 + --> $DIR/wild_in_or_pats.rs:35:9 | LL | _ | "bar" => { | ^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed index ccb40acfb..108941573 100644 --- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed +++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:non-exhaustive-enum.rs #![deny(clippy::wildcard_enum_match_arm)] #![allow(dead_code, unreachable_code, unused_variables)] diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs index 3ce00b021..d9285c56f 100644 --- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs +++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs @@ -1,4 +1,3 @@ -//@run-rustfix //@aux-build:non-exhaustive-enum.rs #![deny(clippy::wildcard_enum_match_arm)] #![allow(dead_code, unreachable_code, unused_variables)] diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr index 5b88ae4ab..7fbb16e69 100644 --- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr +++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr @@ -1,41 +1,41 @@ error: wildcard match will also match any future added variants - --> $DIR/wildcard_enum_match_arm.rs:40:9 + --> $DIR/wildcard_enum_match_arm.rs:39:9 | LL | _ => eprintln!("Not red"), | ^ help: try: `Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan` | note: the lint level is defined here - --> $DIR/wildcard_enum_match_arm.rs:3:9 + --> $DIR/wildcard_enum_match_arm.rs:2:9 | LL | #![deny(clippy::wildcard_enum_match_arm)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: wildcard match will also match any future added variants - --> $DIR/wildcard_enum_match_arm.rs:44:9 + --> $DIR/wildcard_enum_match_arm.rs:43:9 | 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:48:9 + --> $DIR/wildcard_enum_match_arm.rs:47: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:64:9 + --> $DIR/wildcard_enum_match_arm.rs:63: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:81:9 + --> $DIR/wildcard_enum_match_arm.rs:80:9 | LL | _ => {}, | ^ help: try: `ErrorKind::PermissionDenied | _` error: wildcard match will also match any future added variants - --> $DIR/wildcard_enum_match_arm.rs:99:13 + --> $DIR/wildcard_enum_match_arm.rs:98:13 | LL | _ => (), | ^ help: try: `Enum::B | Enum::__Private` diff --git a/src/tools/clippy/tests/ui/wildcard_imports.fixed b/src/tools/clippy/tests/ui/wildcard_imports.fixed index 67173f406..2828f9d04 100644 --- a/src/tools/clippy/tests/ui/wildcard_imports.fixed +++ b/src/tools/clippy/tests/ui/wildcard_imports.fixed @@ -1,5 +1,5 @@ //@edition:2015 -//@run-rustfix + //@aux-build:wildcard_imports_helper.rs // the 2015 edition here is needed because edition 2018 changed the module system diff --git a/src/tools/clippy/tests/ui/wildcard_imports.rs b/src/tools/clippy/tests/ui/wildcard_imports.rs index 8223b6930..cbe70e505 100644 --- a/src/tools/clippy/tests/ui/wildcard_imports.rs +++ b/src/tools/clippy/tests/ui/wildcard_imports.rs @@ -1,5 +1,5 @@ //@edition:2015 -//@run-rustfix + //@aux-build:wildcard_imports_helper.rs // the 2015 edition here is needed because edition 2018 changed the module system diff --git a/src/tools/clippy/tests/ui/wildcard_imports.stderr b/src/tools/clippy/tests/ui/wildcard_imports.stderr index f7baf234c..3c750815b 100644 --- a/src/tools/clippy/tests/ui/wildcard_imports.stderr +++ b/src/tools/clippy/tests/ui/wildcard_imports.stderr @@ -5,6 +5,7 @@ LL | use crate::fn_mod::*; | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` | = note: `-D clippy::wildcard-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]` error: usage of wildcard import --> $DIR/wildcard_imports.rs:16:5 diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed index 8a6337567..b27281fa2 100644 --- a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed +++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed @@ -1,7 +1,7 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix + //@aux-build:wildcard_imports_helper.rs #![warn(clippy::wildcard_imports)] diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.stderr b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.stderr index af9ae6e78..709a665d6 100644 --- a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.stderr +++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.stderr @@ -5,6 +5,7 @@ LL | use crate::fn_mod::*; | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` | = note: `-D clippy::wildcard-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]` error: usage of wildcard import --> $DIR/wildcard_imports_2021.rs:14:5 diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed index 8a6337567..b27281fa2 100644 --- a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed +++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed @@ -1,7 +1,7 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix + //@aux-build:wildcard_imports_helper.rs #![warn(clippy::wildcard_imports)] diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.stderr b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.stderr index af9ae6e78..709a665d6 100644 --- a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.stderr +++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.stderr @@ -5,6 +5,7 @@ LL | use crate::fn_mod::*; | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` | = note: `-D clippy::wildcard-imports` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]` error: usage of wildcard import --> $DIR/wildcard_imports_2021.rs:14:5 diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.rs b/src/tools/clippy/tests/ui/wildcard_imports_2021.rs index 52cd2c828..7dd2103ec 100644 --- a/src/tools/clippy/tests/ui/wildcard_imports_2021.rs +++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.rs @@ -1,7 +1,7 @@ //@revisions: edition2018 edition2021 //@[edition2018] edition:2018 //@[edition2021] edition:2021 -//@run-rustfix + //@aux-build:wildcard_imports_helper.rs #![warn(clippy::wildcard_imports)] diff --git a/src/tools/clippy/tests/ui/write_literal.fixed b/src/tools/clippy/tests/ui/write_literal.fixed new file mode 100644 index 000000000..ee577574d --- /dev/null +++ b/src/tools/clippy/tests/ui/write_literal.fixed @@ -0,0 +1,58 @@ +#![warn(clippy::write_literal)] +#![allow(clippy::uninlined_format_args, unused_must_use)] + +use std::io::Write; + +fn main() { + let mut v = Vec::new(); + + // these should be fine + write!(v, "Hello"); + writeln!(v, "Hello"); + let world = "world"; + writeln!(v, "Hello {}", world); + writeln!(v, "Hello {world}", world = world); + writeln!(v, "3 in hex is {:X}", 3); + writeln!(v, "2 + 1 = {:.4}", 3); + writeln!(v, "2 + 1 = {:5.4}", 3); + writeln!(v, "Debug test {:?}", "hello, world"); + writeln!(v, "{0:8} {1:>8}", "hello", "world"); + writeln!(v, "{1:8} {0:>8}", "hello", "world"); + writeln!(v, "{foo:8} {bar:>8}", foo = "hello", bar = "world"); + writeln!(v, "{bar:8} {foo:>8}", foo = "hello", bar = "world"); + writeln!(v, "{number:>width$}", number = 1, width = 6); + writeln!(v, "{number:>0width$}", number = 1, width = 6); + writeln!(v, "{} of {:b} people know binary, the other half doesn't", 1, 2); + writeln!(v, "10 / 4 is {}", 2.5); + writeln!(v, "2 + 1 = {}", 3); + writeln!(v, "From expansion {}", stringify!(not a string literal)); + + // these should throw warnings + write!(v, "Hello world"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::write-literal` implied by `-D warnings` + writeln!(v, "Hello {} world", world); + //~^ ERROR: literal with an empty format string + writeln!(v, "Hello world"); + //~^ ERROR: literal with an empty format string + writeln!(v, "a literal {:.4}", 5); + //~^ ERROR: literal with an empty format string + + // positional args don't change the fact + // that we're using a literal -- this should + // throw a warning + writeln!(v, "hello world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string + writeln!(v, "world hello"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string + + // named args shouldn't change anything either + writeln!(v, "hello world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string + writeln!(v, "world hello"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string +} diff --git a/src/tools/clippy/tests/ui/write_literal.rs b/src/tools/clippy/tests/ui/write_literal.rs index 218385ea1..588e8fd41 100644 --- a/src/tools/clippy/tests/ui/write_literal.rs +++ b/src/tools/clippy/tests/ui/write_literal.rs @@ -29,17 +29,30 @@ fn main() { // these should throw warnings write!(v, "Hello {}", "world"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::write-literal` implied by `-D warnings` writeln!(v, "Hello {} {}", world, "world"); + //~^ ERROR: literal with an empty format string writeln!(v, "Hello {}", "world"); + //~^ ERROR: literal with an empty format string writeln!(v, "{} {:.4}", "a literal", 5); + //~^ ERROR: literal with an empty format string // positional args don't change the fact // that we're using a literal -- this should // throw a warning writeln!(v, "{0} {1}", "hello", "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string writeln!(v, "{1} {0}", "hello", "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string // named args shouldn't change anything either writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string } diff --git a/src/tools/clippy/tests/ui/write_literal.stderr b/src/tools/clippy/tests/ui/write_literal.stderr index 8b72c8bd2..372a54cf7 100644 --- a/src/tools/clippy/tests/ui/write_literal.stderr +++ b/src/tools/clippy/tests/ui/write_literal.stderr @@ -5,6 +5,7 @@ LL | write!(v, "Hello {}", "world"); | ^^^^^^^ | = note: `-D clippy::write-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::write_literal)]` help: try | LL - write!(v, "Hello {}", "world"); @@ -12,7 +13,7 @@ LL + write!(v, "Hello world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:32:39 + --> $DIR/write_literal.rs:34:39 | LL | writeln!(v, "Hello {} {}", world, "world"); | ^^^^^^^ @@ -24,7 +25,7 @@ LL + writeln!(v, "Hello {} world", world); | error: literal with an empty format string - --> $DIR/write_literal.rs:33:29 + --> $DIR/write_literal.rs:36:29 | LL | writeln!(v, "Hello {}", "world"); | ^^^^^^^ @@ -36,7 +37,7 @@ LL + writeln!(v, "Hello world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:34:29 + --> $DIR/write_literal.rs:38:29 | LL | writeln!(v, "{} {:.4}", "a literal", 5); | ^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL + writeln!(v, "a literal {:.4}", 5); | error: literal with an empty format string - --> $DIR/write_literal.rs:39:28 + --> $DIR/write_literal.rs:44:28 | LL | writeln!(v, "{0} {1}", "hello", "world"); | ^^^^^^^ @@ -60,7 +61,7 @@ LL + writeln!(v, "hello {1}", "world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:39:37 + --> $DIR/write_literal.rs:44:37 | LL | writeln!(v, "{0} {1}", "hello", "world"); | ^^^^^^^ @@ -72,7 +73,7 @@ LL + writeln!(v, "{0} world", "hello"); | error: literal with an empty format string - --> $DIR/write_literal.rs:40:37 + --> $DIR/write_literal.rs:47:37 | LL | writeln!(v, "{1} {0}", "hello", "world"); | ^^^^^^^ @@ -84,7 +85,7 @@ LL + writeln!(v, "world {0}", "hello"); | error: literal with an empty format string - --> $DIR/write_literal.rs:40:28 + --> $DIR/write_literal.rs:47:28 | LL | writeln!(v, "{1} {0}", "hello", "world"); | ^^^^^^^ @@ -96,7 +97,7 @@ LL + writeln!(v, "{1} hello", "world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:43:38 + --> $DIR/write_literal.rs:52:38 | LL | writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -108,7 +109,7 @@ LL + writeln!(v, "hello {bar}", bar = "world"); | error: literal with an empty format string - --> $DIR/write_literal.rs:43:53 + --> $DIR/write_literal.rs:52:53 | LL | writeln!(v, "{foo} {bar}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -120,7 +121,7 @@ LL + writeln!(v, "{foo} world", foo = "hello"); | error: literal with an empty format string - --> $DIR/write_literal.rs:44:53 + --> $DIR/write_literal.rs:55:53 | LL | writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^ @@ -132,7 +133,7 @@ LL + writeln!(v, "world {foo}", foo = "hello"); | error: literal with an empty format string - --> $DIR/write_literal.rs:44:38 + --> $DIR/write_literal.rs:55:38 | LL | writeln!(v, "{bar} {foo}", foo = "hello", bar = "world"); | ^^^^^^^ diff --git a/src/tools/clippy/tests/ui/write_literal_2.rs b/src/tools/clippy/tests/ui/write_literal_2.rs index 805127e27..aa0c13c13 100644 --- a/src/tools/clippy/tests/ui/write_literal_2.rs +++ b/src/tools/clippy/tests/ui/write_literal_2.rs @@ -1,3 +1,4 @@ +//@no-rustfix: overlapping suggestions #![allow(unused_must_use)] #![warn(clippy::needless_raw_strings, clippy::write_literal)] @@ -7,28 +8,50 @@ fn main() { let mut v = Vec::new(); writeln!(v, "{}", "{hello}"); + //~^ ERROR: literal with an empty format string + //~| NOTE: `-D clippy::write-literal` implied by `-D warnings` writeln!(v, r"{}", r"{hello}"); + //~^ ERROR: unnecessary raw string literal + //~| NOTE: `-D clippy::needless-raw-strings` implied by `-D warnings` + //~| ERROR: literal with an empty format string writeln!(v, "{}", '\''); + //~^ ERROR: literal with an empty format string writeln!(v, "{}", '"'); + //~^ ERROR: literal with an empty format string writeln!(v, r"{}", '"'); + //~^ ERROR: literal with an empty format string writeln!(v, r"{}", '\''); + //~^ ERROR: literal with an empty format string writeln!( v, "some {}", "hello \ + //~^ ERROR: literal with an empty format string world!" ); writeln!( v, "some {}\ {} \\ {}", - "1", "2", "3", + "1", + "2", + "3", + //~^ ERROR: literal with an empty format string ); writeln!(v, "{}", "\\"); + //~^ ERROR: literal with an empty format string writeln!(v, r"{}", "\\"); + //~^ ERROR: literal with an empty format string writeln!(v, r#"{}"#, "\\"); + //~^ ERROR: literal with an empty format string writeln!(v, "{}", r"\"); + //~^ ERROR: literal with an empty format string writeln!(v, "{}", "\r"); - writeln!(v, r#"{}{}"#, '#', '"'); // hard mode - writeln!(v, r"{}", "\r"); // should not lint + //~^ ERROR: literal with an empty format string + // hard mode + writeln!(v, r#"{}{}"#, '#', '"'); + //~^ ERROR: literal with an empty format string + //~| ERROR: literal with an empty format string + // should not lint + writeln!(v, r"{}", "\r"); } diff --git a/src/tools/clippy/tests/ui/write_literal_2.stderr b/src/tools/clippy/tests/ui/write_literal_2.stderr index c30ec385b..6d382a267 100644 --- a/src/tools/clippy/tests/ui/write_literal_2.stderr +++ b/src/tools/clippy/tests/ui/write_literal_2.stderr @@ -1,18 +1,22 @@ error: unnecessary raw string literal - --> $DIR/write_literal_2.rs:10:24 + --> $DIR/write_literal_2.rs:13:24 | LL | writeln!(v, r"{}", r"{hello}"); - | ^^^^^^^^^^ help: try: `"{hello}"` + | -^^^^^^^^^ + | | + | help: use a string literal instead: `"{hello}"` | = note: `-D clippy::needless-raw-strings` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_raw_strings)]` error: literal with an empty format string - --> $DIR/write_literal_2.rs:9:23 + --> $DIR/write_literal_2.rs:10:23 | LL | writeln!(v, "{}", "{hello}"); | ^^^^^^^^^ | = note: `-D clippy::write-literal` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::write_literal)]` help: try | LL - writeln!(v, "{}", "{hello}"); @@ -20,7 +24,7 @@ LL + writeln!(v, "{{hello}}"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:10:24 + --> $DIR/write_literal_2.rs:13:24 | LL | writeln!(v, r"{}", r"{hello}"); | ^^^^^^^^^^ @@ -32,19 +36,19 @@ LL + writeln!(v, r"{{hello}}"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:11:23 + --> $DIR/write_literal_2.rs:17:23 | -LL | writeln!(v, "{}", '/''); +LL | writeln!(v, "{}", '\''); | ^^^^ | help: try | -LL - writeln!(v, "{}", '/''); +LL - writeln!(v, "{}", '\''); LL + writeln!(v, "'"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:12:23 + --> $DIR/write_literal_2.rs:19:23 | LL | writeln!(v, "{}", '"'); | ^^^ @@ -52,146 +56,149 @@ LL | writeln!(v, "{}", '"'); help: try | LL - writeln!(v, "{}", '"'); -LL + writeln!(v, "/""); +LL + writeln!(v, "\""); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:13:24 + --> $DIR/write_literal_2.rs:21:24 | LL | writeln!(v, r"{}", '"'); | ^^^ error: literal with an empty format string - --> $DIR/write_literal_2.rs:14:24 + --> $DIR/write_literal_2.rs:23:24 | -LL | writeln!(v, r"{}", '/''); +LL | writeln!(v, r"{}", '\''); | ^^^^ | help: try | -LL - writeln!(v, r"{}", '/''); +LL - writeln!(v, r"{}", '\''); LL + writeln!(v, r"'"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:18:9 + --> $DIR/write_literal_2.rs:28:9 | -LL | / "hello / +LL | / "hello \ +LL | | LL | | world!" | |_______________^ | help: try | -LL ~ "some hello / +LL ~ "some hello \ +LL + LL ~ world!" | error: literal with an empty format string - --> $DIR/write_literal_2.rs:25:9 + --> $DIR/write_literal_2.rs:36:9 | -LL | "1", "2", "3", +LL | "1", | ^^^ | help: try | -LL ~ "some 1/ -LL ~ {} // {}", "2", "3", +LL ~ "some 1\ +LL ~ {} \\ {}", | error: literal with an empty format string - --> $DIR/write_literal_2.rs:25:14 + --> $DIR/write_literal_2.rs:37:9 | -LL | "1", "2", "3", - | ^^^ +LL | "2", + | ^^^ | help: try | -LL ~ 2 // {}", -LL ~ "1", "3", +LL ~ 2 \\ {}", +LL ~ "1", | error: literal with an empty format string - --> $DIR/write_literal_2.rs:25:19 + --> $DIR/write_literal_2.rs:38:9 | -LL | "1", "2", "3", - | ^^^ +LL | "3", + | ^^^ | help: try | -LL ~ {} // 3", -LL ~ "1", "2", +LL ~ {} \\ 3", +LL | "1", +LL ~ "2", | error: literal with an empty format string - --> $DIR/write_literal_2.rs:27:23 + --> $DIR/write_literal_2.rs:41:23 | -LL | writeln!(v, "{}", "//"); +LL | writeln!(v, "{}", "\\"); | ^^^^ | help: try | -LL - writeln!(v, "{}", "//"); -LL + writeln!(v, "//"); +LL - writeln!(v, "{}", "\\"); +LL + writeln!(v, "\\"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:28:24 + --> $DIR/write_literal_2.rs:43:24 | -LL | writeln!(v, r"{}", "//"); +LL | writeln!(v, r"{}", "\\"); | ^^^^ | help: try | -LL - writeln!(v, r"{}", "//"); -LL + writeln!(v, r"/"); +LL - writeln!(v, r"{}", "\\"); +LL + writeln!(v, r"\"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:29:26 + --> $DIR/write_literal_2.rs:45:26 | -LL | writeln!(v, r#"{}"#, "//"); +LL | writeln!(v, r#"{}"#, "\\"); | ^^^^ | help: try | -LL - writeln!(v, r#"{}"#, "//"); -LL + writeln!(v, r#"/"#); +LL - writeln!(v, r#"{}"#, "\\"); +LL + writeln!(v, r#"\"#); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:30:23 + --> $DIR/write_literal_2.rs:47:23 | -LL | writeln!(v, "{}", r"/"); +LL | writeln!(v, "{}", r"\"); | ^^^^ | help: try | -LL - writeln!(v, "{}", r"/"); -LL + writeln!(v, "//"); +LL - writeln!(v, "{}", r"\"); +LL + writeln!(v, "\\"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:31:23 + --> $DIR/write_literal_2.rs:49:23 | -LL | writeln!(v, "{}", "/r"); +LL | writeln!(v, "{}", "\r"); | ^^^^ | help: try | -LL - writeln!(v, "{}", "/r"); -LL + writeln!(v, "/r"); +LL - writeln!(v, "{}", "\r"); +LL + writeln!(v, "\r"); | error: literal with an empty format string - --> $DIR/write_literal_2.rs:32:28 + --> $DIR/write_literal_2.rs:52:28 | -LL | writeln!(v, r#"{}{}"#, '#', '"'); // hard mode +LL | writeln!(v, r#"{}{}"#, '#', '"'); | ^^^ error: literal with an empty format string - --> $DIR/write_literal_2.rs:32:33 + --> $DIR/write_literal_2.rs:52:33 | -LL | writeln!(v, r#"{}{}"#, '#', '"'); // hard mode +LL | writeln!(v, r#"{}{}"#, '#', '"'); | ^^^ error: aborting due to 18 previous errors diff --git a/src/tools/clippy/tests/ui/write_with_newline.fixed b/src/tools/clippy/tests/ui/write_with_newline.fixed index 0a10e526a..82afff5c8 100644 --- a/src/tools/clippy/tests/ui/write_with_newline.fixed +++ b/src/tools/clippy/tests/ui/write_with_newline.fixed @@ -1,5 +1,4 @@ // FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 -// //@run-rustfix #![allow(clippy::write_literal)] #![warn(clippy::write_with_newline)] @@ -11,10 +10,16 @@ fn main() { // These should fail writeln!(v, "Hello"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::write-with-newline` implied by `-D warnings` writeln!(v, "Hello {}", "world"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline writeln!(v, "Hello {} {}", "world", "#2"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline writeln!(v, "{}", 1265); + //~^ ERROR: using `write!()` with a format string that ends in a single newline writeln!(v); + //~^ ERROR: using `write!()` with a format string that ends in a single newline // These should be fine write!(v, ""); @@ -28,29 +33,37 @@ fn main() { write!(v, "\n\n"); write!(v, "like eof\n\n"); write!(v, "Hello {} {}\n\n", "world", "#2"); - writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - writeln!(v, "\nbla\n\n"); // #3126 + // #3126 + writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + writeln!(v, "\nbla\n\n"); // Escaping - write!(v, "\\n"); // #3514 - writeln!(v, "\\"); // should fail + // #3514 + write!(v, "\\n"); + writeln!(v, "\\"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "\\\\n"); // Raw strings - write!(v, r"\n"); // #3778 + // #3778 + write!(v, r"\n"); // Literal newlines should also fail writeln!( + //~^ ERROR: using `write!()` with a format string that ends in a single newline v ); writeln!( + //~^ ERROR: using `write!()` with a format string that ends in a single newline v ); // Don't warn on CRLF (#4208) write!(v, "\r\n"); write!(v, "foo\r\n"); - writeln!(v, "\\r"); // warns + writeln!(v, "\\r"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "foo\rbar\n"); // Ignore expanded format strings diff --git a/src/tools/clippy/tests/ui/write_with_newline.rs b/src/tools/clippy/tests/ui/write_with_newline.rs index 35bd9e7f3..96e4bf0fb 100644 --- a/src/tools/clippy/tests/ui/write_with_newline.rs +++ b/src/tools/clippy/tests/ui/write_with_newline.rs @@ -1,5 +1,4 @@ // FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 -// #![allow(clippy::write_literal)] #![warn(clippy::write_with_newline)] @@ -11,10 +10,16 @@ fn main() { // These should fail write!(v, "Hello\n"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline + //~| NOTE: `-D clippy::write-with-newline` implied by `-D warnings` write!(v, "Hello {}\n", "world"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "Hello {} {}\n", "world", "#2"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "{}\n", 1265); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "\n"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline // These should be fine write!(v, ""); @@ -28,24 +33,31 @@ fn main() { write!(v, "\n\n"); write!(v, "like eof\n\n"); write!(v, "Hello {} {}\n\n", "world", "#2"); - writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 - writeln!(v, "\nbla\n\n"); // #3126 + // #3126 + writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); + // #3126 + writeln!(v, "\nbla\n\n"); // Escaping - write!(v, "\\n"); // #3514 - write!(v, "\\\n"); // should fail + // #3514 + write!(v, "\\n"); + write!(v, "\\\n"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "\\\\n"); // Raw strings - write!(v, r"\n"); // #3778 + // #3778 + write!(v, r"\n"); // Literal newlines should also fail write!( + //~^ ERROR: using `write!()` with a format string that ends in a single newline v, " " ); write!( + //~^ ERROR: using `write!()` with a format string that ends in a single newline v, r" " @@ -55,6 +67,7 @@ fn main() { write!(v, "\r\n"); write!(v, "foo\r\n"); write!(v, "\\r\n"); + //~^ ERROR: using `write!()` with a format string that ends in a single newline write!(v, "foo\rbar\n"); // Ignore expanded format strings diff --git a/src/tools/clippy/tests/ui/write_with_newline.stderr b/src/tools/clippy/tests/ui/write_with_newline.stderr index 03a18a4dc..78874ffad 100644 --- a/src/tools/clippy/tests/ui/write_with_newline.stderr +++ b/src/tools/clippy/tests/ui/write_with_newline.stderr @@ -1,80 +1,82 @@ error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:13:5 + --> $DIR/write_with_newline.rs:12:5 | -LL | write!(v, "Hello/n"); +LL | write!(v, "Hello\n"); | ^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::write-with-newline` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::write_with_newline)]` help: use `writeln!` instead | -LL - write!(v, "Hello/n"); +LL - write!(v, "Hello\n"); LL + writeln!(v, "Hello"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:14:5 + --> $DIR/write_with_newline.rs:15:5 | -LL | write!(v, "Hello {}/n", "world"); +LL | write!(v, "Hello {}\n", "world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `writeln!` instead | -LL - write!(v, "Hello {}/n", "world"); +LL - write!(v, "Hello {}\n", "world"); LL + writeln!(v, "Hello {}", "world"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:15:5 + --> $DIR/write_with_newline.rs:17:5 | -LL | write!(v, "Hello {} {}/n", "world", "#2"); +LL | write!(v, "Hello {} {}\n", "world", "#2"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: use `writeln!` instead | -LL - write!(v, "Hello {} {}/n", "world", "#2"); +LL - write!(v, "Hello {} {}\n", "world", "#2"); LL + writeln!(v, "Hello {} {}", "world", "#2"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:16:5 + --> $DIR/write_with_newline.rs:19:5 | -LL | write!(v, "{}/n", 1265); +LL | write!(v, "{}\n", 1265); | ^^^^^^^^^^^^^^^^^^^^^^^ | help: use `writeln!` instead | -LL - write!(v, "{}/n", 1265); +LL - write!(v, "{}\n", 1265); LL + writeln!(v, "{}", 1265); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:17:5 + --> $DIR/write_with_newline.rs:21:5 | -LL | write!(v, "/n"); +LL | write!(v, "\n"); | ^^^^^^^^^^^^^^^ | help: use `writeln!` instead | -LL - write!(v, "/n"); +LL - write!(v, "\n"); LL + writeln!(v); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:36:5 + --> $DIR/write_with_newline.rs:44:5 | -LL | write!(v, "///n"); // should fail +LL | write!(v, "\\\n"); | ^^^^^^^^^^^^^^^^^ | help: use `writeln!` instead | -LL - write!(v, "///n"); // should fail -LL + writeln!(v, "//"); // should fail +LL - write!(v, "\\\n"); +LL + writeln!(v, "\\"); | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:43:5 + --> $DIR/write_with_newline.rs:53:5 | LL | / write!( +LL | | LL | | v, LL | | " LL | | " @@ -84,13 +86,15 @@ LL | | ); help: use `writeln!` instead | LL ~ writeln!( +LL | LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:48:5 + --> $DIR/write_with_newline.rs:59:5 | LL | / write!( +LL | | LL | | v, LL | | r" LL | | " @@ -100,19 +104,20 @@ LL | | ); help: use `writeln!` instead | LL ~ writeln!( +LL | LL ~ v | error: using `write!()` with a format string that ends in a single newline - --> $DIR/write_with_newline.rs:57:5 + --> $DIR/write_with_newline.rs:69:5 | -LL | write!(v, "//r/n"); +LL | write!(v, "\\r\n"); | ^^^^^^^^^^^^^^^^^^ | help: use `writeln!` instead | -LL - write!(v, "//r/n"); -LL + writeln!(v, "//r"); +LL - write!(v, "\\r\n"); +LL + writeln!(v, "\\r"); | error: aborting due to 9 previous errors diff --git a/src/tools/clippy/tests/ui/writeln_empty_string.fixed b/src/tools/clippy/tests/ui/writeln_empty_string.fixed index 45dedd9ea..f6a7481f6 100644 --- a/src/tools/clippy/tests/ui/writeln_empty_string.fixed +++ b/src/tools/clippy/tests/ui/writeln_empty_string.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_must_use)] #![warn(clippy::writeln_empty_string)] use std::io::Write; diff --git a/src/tools/clippy/tests/ui/writeln_empty_string.rs b/src/tools/clippy/tests/ui/writeln_empty_string.rs index 3b9f51a15..0297dba8c 100644 --- a/src/tools/clippy/tests/ui/writeln_empty_string.rs +++ b/src/tools/clippy/tests/ui/writeln_empty_string.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![allow(unused_must_use)] #![warn(clippy::writeln_empty_string)] use std::io::Write; diff --git a/src/tools/clippy/tests/ui/writeln_empty_string.stderr b/src/tools/clippy/tests/ui/writeln_empty_string.stderr index 25e69ec48..037475543 100644 --- a/src/tools/clippy/tests/ui/writeln_empty_string.stderr +++ b/src/tools/clippy/tests/ui/writeln_empty_string.stderr @@ -1,5 +1,5 @@ error: empty string literal in `writeln!` - --> $DIR/writeln_empty_string.rs:11:5 + --> $DIR/writeln_empty_string.rs:9:5 | LL | writeln!(v, ""); | ^^^^^^^^^^----^ @@ -7,9 +7,10 @@ LL | writeln!(v, ""); | help: remove the empty string | = note: `-D clippy::writeln-empty-string` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::writeln_empty_string)]` error: empty string literal in `writeln!` - --> $DIR/writeln_empty_string.rs:14:5 + --> $DIR/writeln_empty_string.rs:12:5 | LL | writeln!(suggestion, ""); | ^^^^^^^^^^^^^^^^^^^----^ diff --git a/src/tools/clippy/tests/ui/wrong_self_convention.rs b/src/tools/clippy/tests/ui/wrong_self_convention.rs index e3cc90ee2..d7ed883b7 100644 --- a/src/tools/clippy/tests/ui/wrong_self_convention.rs +++ b/src/tools/clippy/tests/ui/wrong_self_convention.rs @@ -14,12 +14,14 @@ impl Foo { fn is_u32(&self) {} fn to_i32(self) {} fn from_i32(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` pub fn as_i64(self) {} pub fn into_i64(self) {} pub fn is_i64(self) {} pub fn to_i64(self) {} pub fn from_i64(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] pub fn from_cake(self) {} @@ -32,20 +34,30 @@ struct Bar; impl Bar { fn as_i32(self) {} + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mutabl fn as_u32(&self) {} fn into_i32(&self) {} + //~^ ERROR: methods called `into_*` usually take `self` by value fn into_u32(self) {} fn is_i32(self) {} + //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `self` b fn is_u32(&self) {} fn to_i32(self) {} + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is not fn to_u32(&self) {} fn from_i32(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` pub fn as_i64(self) {} + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mutabl pub fn into_i64(&self) {} + //~^ ERROR: methods called `into_*` usually take `self` by value pub fn is_i64(self) {} + //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `self` b pub fn to_i64(self) {} + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is not pub fn from_i64(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` // test for false positives fn as_(self) {} @@ -91,15 +103,19 @@ mod issue4037 { mod issue6307 { trait T: Sized { fn as_i32(self) {} + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mu fn as_u32(&self) {} fn into_i32(self) {} fn into_i32_ref(&self) {} + //~^ ERROR: methods called `into_*` usually take `self` by value fn into_u32(self) {} fn is_i32(self) {} + //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `sel fn is_u32(&self) {} fn to_i32(self) {} fn to_u32(&self) {} fn from_i32(self) {} + //~^ ERROR: methods called `from_*` usually take no `self` // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] fn from_cake(self) {} @@ -115,15 +131,19 @@ mod issue6307 { trait U { fn as_i32(self); + //~^ ERROR: methods called `as_*` usually take `self` by reference or `self` by mu fn as_u32(&self); fn into_i32(self); fn into_i32_ref(&self); + //~^ ERROR: methods called `into_*` usually take `self` by value fn into_u32(self); fn is_i32(self); + //~^ ERROR: methods called `is_*` usually take `self` by mutable reference or `sel fn is_u32(&self); fn to_i32(self); fn to_u32(&self); fn from_i32(self); + //~^ ERROR: methods called `from_*` usually take no `self` // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] fn from_cake(self); @@ -142,12 +162,14 @@ mod issue6307 { fn as_u32(&self); fn into_i32(self); fn into_i32_ref(&self); + //~^ ERROR: methods called `into_*` usually take `self` by value fn into_u32(self); fn is_i32(self); fn is_u32(&self); fn to_i32(self); fn to_u32(&self); fn from_i32(self); + //~^ ERROR: methods called `from_*` usually take no `self` // check whether the lint can be allowed at the function level #[allow(clippy::wrong_self_convention)] fn from_cake(self); @@ -172,6 +194,7 @@ mod issue6727 { } // trigger lint fn to_u64_v2(&self) -> u64 { + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is 1 } } @@ -181,6 +204,7 @@ mod issue6727 { impl FooNoCopy { // trigger lint fn to_u64(self) -> u64 { + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is 2 } fn to_u64_v2(&self) -> u64 { diff --git a/src/tools/clippy/tests/ui/wrong_self_convention.stderr b/src/tools/clippy/tests/ui/wrong_self_convention.stderr index d002e55c5..9f457b50c 100644 --- a/src/tools/clippy/tests/ui/wrong_self_convention.stderr +++ b/src/tools/clippy/tests/ui/wrong_self_convention.stderr @@ -6,9 +6,10 @@ LL | fn from_i32(self) {} | = help: consider choosing a less ambiguous name = note: `-D clippy::wrong-self-convention` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:22:21 + --> $DIR/wrong_self_convention.rs:23:21 | LL | pub fn from_i64(self) {} | ^^^^ @@ -16,7 +17,7 @@ LL | pub fn from_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/wrong_self_convention.rs:34:15 + --> $DIR/wrong_self_convention.rs:36:15 | LL | fn as_i32(self) {} | ^^^^ @@ -24,7 +25,7 @@ LL | fn as_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:36:17 + --> $DIR/wrong_self_convention.rs:39:17 | LL | fn into_i32(&self) {} | ^^^^^ @@ -32,7 +33,7 @@ LL | fn into_i32(&self) {} = help: consider choosing a less ambiguous name error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self` - --> $DIR/wrong_self_convention.rs:38:15 + --> $DIR/wrong_self_convention.rs:42:15 | LL | fn is_i32(self) {} | ^^^^ @@ -40,7 +41,7 @@ LL | fn is_i32(self) {} = help: consider choosing a less ambiguous name error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference - --> $DIR/wrong_self_convention.rs:40:15 + --> $DIR/wrong_self_convention.rs:45:15 | LL | fn to_i32(self) {} | ^^^^ @@ -48,7 +49,7 @@ LL | fn to_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:42:17 + --> $DIR/wrong_self_convention.rs:48:17 | LL | fn from_i32(self) {} | ^^^^ @@ -56,7 +57,7 @@ LL | fn from_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/wrong_self_convention.rs:44:19 + --> $DIR/wrong_self_convention.rs:51:19 | LL | pub fn as_i64(self) {} | ^^^^ @@ -64,7 +65,7 @@ LL | pub fn as_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:45:21 + --> $DIR/wrong_self_convention.rs:53:21 | LL | pub fn into_i64(&self) {} | ^^^^^ @@ -72,7 +73,7 @@ LL | pub fn into_i64(&self) {} = help: consider choosing a less ambiguous name error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self` - --> $DIR/wrong_self_convention.rs:46:19 + --> $DIR/wrong_self_convention.rs:55:19 | LL | pub fn is_i64(self) {} | ^^^^ @@ -80,7 +81,7 @@ LL | pub fn is_i64(self) {} = help: consider choosing a less ambiguous name error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference - --> $DIR/wrong_self_convention.rs:47:19 + --> $DIR/wrong_self_convention.rs:57:19 | LL | pub fn to_i64(self) {} | ^^^^ @@ -88,7 +89,7 @@ LL | pub fn to_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:48:21 + --> $DIR/wrong_self_convention.rs:59:21 | LL | pub fn from_i64(self) {} | ^^^^ @@ -96,7 +97,7 @@ LL | pub fn from_i64(self) {} = help: consider choosing a less ambiguous name error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/wrong_self_convention.rs:93:19 + --> $DIR/wrong_self_convention.rs:105:19 | LL | fn as_i32(self) {} | ^^^^ @@ -104,7 +105,7 @@ LL | fn as_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:96:25 + --> $DIR/wrong_self_convention.rs:109:25 | LL | fn into_i32_ref(&self) {} | ^^^^^ @@ -112,7 +113,7 @@ LL | fn into_i32_ref(&self) {} = help: consider choosing a less ambiguous name error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self` - --> $DIR/wrong_self_convention.rs:98:19 + --> $DIR/wrong_self_convention.rs:112:19 | LL | fn is_i32(self) {} | ^^^^ @@ -120,7 +121,7 @@ LL | fn is_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:102:21 + --> $DIR/wrong_self_convention.rs:117:21 | LL | fn from_i32(self) {} | ^^^^ @@ -128,7 +129,7 @@ LL | fn from_i32(self) {} = help: consider choosing a less ambiguous name error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/wrong_self_convention.rs:117:19 + --> $DIR/wrong_self_convention.rs:133:19 | LL | fn as_i32(self); | ^^^^ @@ -136,7 +137,7 @@ LL | fn as_i32(self); = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:120:25 + --> $DIR/wrong_self_convention.rs:137:25 | LL | fn into_i32_ref(&self); | ^^^^^ @@ -144,7 +145,7 @@ LL | fn into_i32_ref(&self); = help: consider choosing a less ambiguous name error: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self` - --> $DIR/wrong_self_convention.rs:122:19 + --> $DIR/wrong_self_convention.rs:140:19 | LL | fn is_i32(self); | ^^^^ @@ -152,7 +153,7 @@ LL | fn is_i32(self); = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:126:21 + --> $DIR/wrong_self_convention.rs:145:21 | LL | fn from_i32(self); | ^^^^ @@ -160,7 +161,7 @@ LL | fn from_i32(self); = help: consider choosing a less ambiguous name error: methods called `into_*` usually take `self` by value - --> $DIR/wrong_self_convention.rs:144:25 + --> $DIR/wrong_self_convention.rs:164:25 | LL | fn into_i32_ref(&self); | ^^^^^ @@ -168,7 +169,7 @@ LL | fn into_i32_ref(&self); = help: consider choosing a less ambiguous name error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention.rs:150:21 + --> $DIR/wrong_self_convention.rs:171:21 | LL | fn from_i32(self); | ^^^^ @@ -176,7 +177,7 @@ LL | fn from_i32(self); = help: consider choosing a less ambiguous name error: methods with the following characteristics: (`to_*` and `self` type is `Copy`) usually take `self` by value - --> $DIR/wrong_self_convention.rs:174:22 + --> $DIR/wrong_self_convention.rs:196:22 | LL | fn to_u64_v2(&self) -> u64 { | ^^^^^ @@ -184,7 +185,7 @@ LL | fn to_u64_v2(&self) -> u64 { = help: consider choosing a less ambiguous name error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference - --> $DIR/wrong_self_convention.rs:183:19 + --> $DIR/wrong_self_convention.rs:206:19 | LL | fn to_u64(self) -> u64 { | ^^^^ diff --git a/src/tools/clippy/tests/ui/wrong_self_convention2.rs b/src/tools/clippy/tests/ui/wrong_self_convention2.rs index 0dcf4743e..44b70f877 100644 --- a/src/tools/clippy/tests/ui/wrong_self_convention2.rs +++ b/src/tools/clippy/tests/ui/wrong_self_convention2.rs @@ -52,6 +52,7 @@ mod issue7179 { // lint pub fn from_be_self(self) -> Self { + //~^ ERROR: methods called `from_*` usually take no `self` S(i32::from_be(self.0)) } } @@ -61,6 +62,7 @@ mod issue7179 { fn from_be(s: Self) -> Self; // lint fn from_be_self(self) -> Self; + //~^ ERROR: methods called `from_*` usually take no `self` } trait Foo: Sized { diff --git a/src/tools/clippy/tests/ui/wrong_self_convention2.stderr b/src/tools/clippy/tests/ui/wrong_self_convention2.stderr index 8de10e7be..dc12a8443 100644 --- a/src/tools/clippy/tests/ui/wrong_self_convention2.stderr +++ b/src/tools/clippy/tests/ui/wrong_self_convention2.stderr @@ -6,9 +6,10 @@ LL | pub fn from_be_self(self) -> Self { | = help: consider choosing a less ambiguous name = note: `-D clippy::wrong-self-convention` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` error: methods called `from_*` usually take no `self` - --> $DIR/wrong_self_convention2.rs:63:25 + --> $DIR/wrong_self_convention2.rs:64:25 | LL | fn from_be_self(self) -> Self; | ^^^^ diff --git a/src/tools/clippy/tests/ui/wrong_self_conventions_mut.rs b/src/tools/clippy/tests/ui/wrong_self_conventions_mut.rs index 5bb2116bd..9169fc6d7 100644 --- a/src/tools/clippy/tests/ui/wrong_self_conventions_mut.rs +++ b/src/tools/clippy/tests/ui/wrong_self_conventions_mut.rs @@ -12,6 +12,7 @@ mod issue6758 { impl Test { // If a method starts with `to_` and not ends with `_mut` it should expect `&self` pub fn to_many(&mut self) -> Option<&mut [T]> { + //~^ ERROR: methods with the following characteristics: (`to_*` and `self` type is match self { Self::Many(data) => Some(data), _ => None, @@ -20,6 +21,7 @@ mod issue6758 { // If a method starts with `to_` and ends with `_mut` it should expect `&mut self` pub fn to_many_mut(&self) -> Option<&[T]> { + //~^ ERROR: methods with the following characteristics: (`to_*` and `*_mut`) usual match self { Self::Many(data) => Some(data), _ => None, diff --git a/src/tools/clippy/tests/ui/wrong_self_conventions_mut.stderr b/src/tools/clippy/tests/ui/wrong_self_conventions_mut.stderr index 3d009083c..21255287d 100644 --- a/src/tools/clippy/tests/ui/wrong_self_conventions_mut.stderr +++ b/src/tools/clippy/tests/ui/wrong_self_conventions_mut.stderr @@ -6,9 +6,10 @@ LL | pub fn to_many(&mut self) -> Option<&mut [T]> { | = help: consider choosing a less ambiguous name = note: `-D clippy::wrong-self-convention` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::wrong_self_convention)]` error: methods with the following characteristics: (`to_*` and `*_mut`) usually take `self` by mutable reference - --> $DIR/wrong_self_conventions_mut.rs:22:28 + --> $DIR/wrong_self_conventions_mut.rs:23:28 | LL | pub fn to_many_mut(&self) -> Option<&[T]> { | ^^^^^ diff --git a/src/tools/clippy/tests/ui/zero_div_zero.rs b/src/tools/clippy/tests/ui/zero_div_zero.rs index 968c58f40..340ed5ef1 100644 --- a/src/tools/clippy/tests/ui/zero_div_zero.rs +++ b/src/tools/clippy/tests/ui/zero_div_zero.rs @@ -2,9 +2,13 @@ #[warn(clippy::zero_divided_by_zero)] fn main() { let nan = 0.0 / 0.0; + //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN let f64_nan = 0.0 / 0.0f64; + //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN let other_f64_nan = 0.0f64 / 0.0; + //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN let one_more_f64_nan = 0.0f64 / 0.0f64; + //~^ ERROR: constant division of `0.0` with `0.0` will always result in NaN let zero = 0.0; let other_zero = 0.0; let other_nan = zero / other_zero; // fine - this lint doesn't propagate constants. diff --git a/src/tools/clippy/tests/ui/zero_div_zero.stderr b/src/tools/clippy/tests/ui/zero_div_zero.stderr index 2793d1606..797ae2537 100644 --- a/src/tools/clippy/tests/ui/zero_div_zero.stderr +++ b/src/tools/clippy/tests/ui/zero_div_zero.stderr @@ -6,9 +6,10 @@ LL | let nan = 0.0 / 0.0; | = help: consider using `f64::NAN` if you would like a constant representing NaN = note: `-D clippy::zero-divided-by-zero` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::zero_divided_by_zero)]` error: constant division of `0.0` with `0.0` will always result in NaN - --> $DIR/zero_div_zero.rs:5:19 + --> $DIR/zero_div_zero.rs:6:19 | LL | let f64_nan = 0.0 / 0.0f64; | ^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | let f64_nan = 0.0 / 0.0f64; = help: consider using `f64::NAN` if you would like a constant representing NaN error: constant division of `0.0` with `0.0` will always result in NaN - --> $DIR/zero_div_zero.rs:6:25 + --> $DIR/zero_div_zero.rs:8:25 | LL | let other_f64_nan = 0.0f64 / 0.0; | ^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | let other_f64_nan = 0.0f64 / 0.0; = help: consider using `f64::NAN` if you would like a constant representing NaN error: constant division of `0.0` with `0.0` will always result in NaN - --> $DIR/zero_div_zero.rs:7:28 + --> $DIR/zero_div_zero.rs:10:28 | LL | let one_more_f64_nan = 0.0f64 / 0.0f64; | ^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/zero_offset.rs b/src/tools/clippy/tests/ui/zero_offset.rs index fd9ac1fa7..c7a69dee4 100644 --- a/src/tools/clippy/tests/ui/zero_offset.rs +++ b/src/tools/clippy/tests/ui/zero_offset.rs @@ -3,15 +3,24 @@ fn main() { unsafe { let m = &mut () as *mut (); m.offset(0); + //~^ ERROR: offset calculation on zero-sized value + //~| NOTE: `#[deny(clippy::zst_offset)]` on by default m.wrapping_add(0); + //~^ ERROR: offset calculation on zero-sized value m.sub(0); + //~^ ERROR: offset calculation on zero-sized value m.wrapping_sub(0); + //~^ ERROR: offset calculation on zero-sized value let c = &() as *const (); c.offset(0); + //~^ ERROR: offset calculation on zero-sized value c.wrapping_add(0); + //~^ ERROR: offset calculation on zero-sized value c.sub(0); + //~^ ERROR: offset calculation on zero-sized value c.wrapping_sub(0); + //~^ ERROR: offset calculation on zero-sized value let sized = &1 as *const i32; sized.offset(0); diff --git a/src/tools/clippy/tests/ui/zero_offset.stderr b/src/tools/clippy/tests/ui/zero_offset.stderr index 481a44657..bb616f456 100644 --- a/src/tools/clippy/tests/ui/zero_offset.stderr +++ b/src/tools/clippy/tests/ui/zero_offset.stderr @@ -7,43 +7,43 @@ LL | m.offset(0); = note: `#[deny(clippy::zst_offset)]` on by default error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:6:9 + --> $DIR/zero_offset.rs:8:9 | LL | m.wrapping_add(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:7:9 + --> $DIR/zero_offset.rs:10:9 | LL | m.sub(0); | ^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:8:9 + --> $DIR/zero_offset.rs:12:9 | LL | m.wrapping_sub(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:11:9 + --> $DIR/zero_offset.rs:16:9 | LL | c.offset(0); | ^^^^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:12:9 + --> $DIR/zero_offset.rs:18:9 | LL | c.wrapping_add(0); | ^^^^^^^^^^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:13:9 + --> $DIR/zero_offset.rs:20:9 | LL | c.sub(0); | ^^^^^^^^ error: offset calculation on zero-sized value - --> $DIR/zero_offset.rs:14:9 + --> $DIR/zero_offset.rs:22:9 | LL | c.wrapping_sub(0); | ^^^^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/zero_ptr.fixed b/src/tools/clippy/tests/ui/zero_ptr.fixed index bed38ecaf..5d99bc9b7 100644 --- a/src/tools/clippy/tests/ui/zero_ptr.fixed +++ b/src/tools/clippy/tests/ui/zero_ptr.fixed @@ -1,4 +1,3 @@ -//@run-rustfix pub fn foo(_const: *const f32, _mut: *mut i64) {} fn main() { diff --git a/src/tools/clippy/tests/ui/zero_ptr.rs b/src/tools/clippy/tests/ui/zero_ptr.rs index b7b778915..09d321c7a 100644 --- a/src/tools/clippy/tests/ui/zero_ptr.rs +++ b/src/tools/clippy/tests/ui/zero_ptr.rs @@ -1,4 +1,3 @@ -//@run-rustfix pub fn foo(_const: *const f32, _mut: *mut i64) {} fn main() { diff --git a/src/tools/clippy/tests/ui/zero_ptr.stderr b/src/tools/clippy/tests/ui/zero_ptr.stderr index 4ee5e9a26..57679a8ac 100644 --- a/src/tools/clippy/tests/ui/zero_ptr.stderr +++ b/src/tools/clippy/tests/ui/zero_ptr.stderr @@ -1,31 +1,32 @@ error: `0 as *const _` detected - --> $DIR/zero_ptr.rs:5:13 + --> $DIR/zero_ptr.rs:4:13 | LL | let _ = 0 as *const usize; | ^^^^^^^^^^^^^^^^^ help: try: `std::ptr::null::()` | = note: `-D clippy::zero-ptr` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::zero_ptr)]` error: `0 as *mut _` detected - --> $DIR/zero_ptr.rs:6:13 + --> $DIR/zero_ptr.rs:5:13 | LL | let _ = 0 as *mut f64; | ^^^^^^^^^^^^^ help: try: `std::ptr::null_mut::()` error: `0 as *const _` detected - --> $DIR/zero_ptr.rs:7:24 + --> $DIR/zero_ptr.rs:6:24 | LL | let _: *const u8 = 0 as *const _; | ^^^^^^^^^^^^^ help: try: `std::ptr::null()` error: `0 as *const _` detected - --> $DIR/zero_ptr.rs:10:9 + --> $DIR/zero_ptr.rs:9:9 | LL | foo(0 as *const _, 0 as *mut _); | ^^^^^^^^^^^^^ help: try: `std::ptr::null()` error: `0 as *mut _` detected - --> $DIR/zero_ptr.rs:10:24 + --> $DIR/zero_ptr.rs:9:24 | LL | foo(0 as *const _, 0 as *mut _); | ^^^^^^^^^^^ help: try: `std::ptr::null_mut()` diff --git a/src/tools/clippy/tests/ui/zero_ptr_no_std.fixed b/src/tools/clippy/tests/ui/zero_ptr_no_std.fixed index 7afd80cca..4f4d19e88 100644 --- a/src/tools/clippy/tests/ui/zero_ptr_no_std.fixed +++ b/src/tools/clippy/tests/ui/zero_ptr_no_std.fixed @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(lang_items, start, libc)] #![no_std] #![deny(clippy::zero_ptr)] diff --git a/src/tools/clippy/tests/ui/zero_ptr_no_std.rs b/src/tools/clippy/tests/ui/zero_ptr_no_std.rs index 05a0587d2..54954d8d1 100644 --- a/src/tools/clippy/tests/ui/zero_ptr_no_std.rs +++ b/src/tools/clippy/tests/ui/zero_ptr_no_std.rs @@ -1,5 +1,3 @@ -//@run-rustfix - #![feature(lang_items, start, libc)] #![no_std] #![deny(clippy::zero_ptr)] diff --git a/src/tools/clippy/tests/ui/zero_ptr_no_std.stderr b/src/tools/clippy/tests/ui/zero_ptr_no_std.stderr index d92bb4a65..915b9c477 100644 --- a/src/tools/clippy/tests/ui/zero_ptr_no_std.stderr +++ b/src/tools/clippy/tests/ui/zero_ptr_no_std.stderr @@ -1,23 +1,23 @@ error: `0 as *const _` detected - --> $DIR/zero_ptr_no_std.rs:9:13 + --> $DIR/zero_ptr_no_std.rs:7:13 | LL | let _ = 0 as *const usize; | ^^^^^^^^^^^^^^^^^ help: try: `core::ptr::null::()` | note: the lint level is defined here - --> $DIR/zero_ptr_no_std.rs:5:9 + --> $DIR/zero_ptr_no_std.rs:3:9 | LL | #![deny(clippy::zero_ptr)] | ^^^^^^^^^^^^^^^^ error: `0 as *mut _` detected - --> $DIR/zero_ptr_no_std.rs:10:13 + --> $DIR/zero_ptr_no_std.rs:8:13 | LL | let _ = 0 as *mut f64; | ^^^^^^^^^^^^^ help: try: `core::ptr::null_mut::()` error: `0 as *const _` detected - --> $DIR/zero_ptr_no_std.rs:11:24 + --> $DIR/zero_ptr_no_std.rs:9:24 | LL | let _: *const u8 = 0 as *const _; | ^^^^^^^^^^^^^ help: try: `core::ptr::null()` diff --git a/src/tools/clippy/tests/ui/zero_sized_btreemap_values.rs b/src/tools/clippy/tests/ui/zero_sized_btreemap_values.rs index 5cd254787..565f63920 100644 --- a/src/tools/clippy/tests/ui/zero_sized_btreemap_values.rs +++ b/src/tools/clippy/tests/ui/zero_sized_btreemap_values.rs @@ -3,23 +3,28 @@ use std::collections::BTreeMap; const CONST_OK: Option> = None; const CONST_NOT_OK: Option> = None; +//~^ ERROR: map with zero-sized value type static STATIC_OK: Option> = None; static STATIC_NOT_OK: Option> = None; +//~^ ERROR: map with zero-sized value type type OkMap = BTreeMap; type NotOkMap = BTreeMap; +//~^ ERROR: map with zero-sized value type enum TestEnum { Ok(BTreeMap), NotOk(BTreeMap), + //~^ ERROR: map with zero-sized value type } struct Test { ok: BTreeMap, not_ok: BTreeMap, - + //~^ ERROR: map with zero-sized value type also_not_ok: Vec>, + //~^ ERROR: map with zero-sized value type } trait TestTrait { @@ -28,6 +33,7 @@ trait TestTrait { fn produce_output() -> Self::Output; fn weird_map(&self, map: BTreeMap); + //~^ ERROR: map with zero-sized value type } impl Test { @@ -36,6 +42,7 @@ impl Test { } fn not_ok(&self) -> BTreeMap { + //~^ ERROR: map with zero-sized value type todo!() } } @@ -53,6 +60,8 @@ impl TestTrait for Test { } fn test(map: BTreeMap, key: &str) -> BTreeMap { + //~^ ERROR: map with zero-sized value type + //~| ERROR: map with zero-sized value type todo!(); } @@ -62,7 +71,10 @@ fn test2(map: BTreeMap, key: &str) -> BTreeMap { fn main() { let _: BTreeMap = BTreeMap::new(); + //~^ ERROR: map with zero-sized value type + //~| ERROR: map with zero-sized value type let _: BTreeMap = BTreeMap::new(); let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect(); + //~^ ERROR: map with zero-sized value type } diff --git a/src/tools/clippy/tests/ui/zero_sized_btreemap_values.stderr b/src/tools/clippy/tests/ui/zero_sized_btreemap_values.stderr index c6ba6fa76..c48e19a76 100644 --- a/src/tools/clippy/tests/ui/zero_sized_btreemap_values.stderr +++ b/src/tools/clippy/tests/ui/zero_sized_btreemap_values.stderr @@ -6,9 +6,10 @@ LL | const CONST_NOT_OK: Option> = None; | = help: consider using a set instead = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::zero_sized_map_values)]` error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:8:30 + --> $DIR/zero_sized_btreemap_values.rs:9:30 | LL | static STATIC_NOT_OK: Option> = None; | ^^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | static STATIC_NOT_OK: Option> = None; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:11:17 + --> $DIR/zero_sized_btreemap_values.rs:13:17 | LL | type NotOkMap = BTreeMap; | ^^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | type NotOkMap = BTreeMap; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:15:11 + --> $DIR/zero_sized_btreemap_values.rs:18:11 | LL | NotOk(BTreeMap), | ^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | NotOk(BTreeMap), = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:20:13 + --> $DIR/zero_sized_btreemap_values.rs:24:13 | LL | not_ok: BTreeMap, | ^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | not_ok: BTreeMap, = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:22:22 + --> $DIR/zero_sized_btreemap_values.rs:26:22 | LL | also_not_ok: Vec>, | ^^^^^^^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | also_not_ok: Vec>, = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:30:30 + --> $DIR/zero_sized_btreemap_values.rs:35:30 | LL | fn weird_map(&self, map: BTreeMap); | ^^^^^^^^^^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | fn weird_map(&self, map: BTreeMap); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:38:25 + --> $DIR/zero_sized_btreemap_values.rs:44:25 | LL | fn not_ok(&self) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +65,7 @@ LL | fn not_ok(&self) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:55:14 + --> $DIR/zero_sized_btreemap_values.rs:62:14 | LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:55:50 + --> $DIR/zero_sized_btreemap_values.rs:62:50 | LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { | ^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +81,7 @@ LL | fn test(map: BTreeMap, key: &str) -> BTreeMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:64:35 + --> $DIR/zero_sized_btreemap_values.rs:73:35 | LL | let _: BTreeMap = BTreeMap::new(); | ^^^^^^^^ @@ -88,7 +89,7 @@ LL | let _: BTreeMap = BTreeMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:64:12 + --> $DIR/zero_sized_btreemap_values.rs:73:12 | LL | let _: BTreeMap = BTreeMap::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -96,7 +97,7 @@ LL | let _: BTreeMap = BTreeMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_btreemap_values.rs:67:12 + --> $DIR/zero_sized_btreemap_values.rs:78:12 | LL | let _: BTreeMap<_, _> = std::iter::empty::<(String, ())>().collect(); | ^^^^^^^^^^^^^^ diff --git a/src/tools/clippy/tests/ui/zero_sized_hashmap_values.rs b/src/tools/clippy/tests/ui/zero_sized_hashmap_values.rs index a1608d863..5498261ee 100644 --- a/src/tools/clippy/tests/ui/zero_sized_hashmap_values.rs +++ b/src/tools/clippy/tests/ui/zero_sized_hashmap_values.rs @@ -3,23 +3,28 @@ use std::collections::HashMap; const CONST_OK: Option> = None; const CONST_NOT_OK: Option> = None; +//~^ ERROR: map with zero-sized value type static STATIC_OK: Option> = None; static STATIC_NOT_OK: Option> = None; +//~^ ERROR: map with zero-sized value type type OkMap = HashMap; type NotOkMap = HashMap; +//~^ ERROR: map with zero-sized value type enum TestEnum { Ok(HashMap), NotOk(HashMap), + //~^ ERROR: map with zero-sized value type } struct Test { ok: HashMap, not_ok: HashMap, - + //~^ ERROR: map with zero-sized value type also_not_ok: Vec>, + //~^ ERROR: map with zero-sized value type } trait TestTrait { @@ -28,6 +33,7 @@ trait TestTrait { fn produce_output() -> Self::Output; fn weird_map(&self, map: HashMap); + //~^ ERROR: map with zero-sized value type } impl Test { @@ -36,6 +42,7 @@ impl Test { } fn not_ok(&self) -> HashMap { + //~^ ERROR: map with zero-sized value type todo!() } } @@ -53,6 +60,8 @@ impl TestTrait for Test { } fn test(map: HashMap, key: &str) -> HashMap { + //~^ ERROR: map with zero-sized value type + //~| ERROR: map with zero-sized value type todo!(); } @@ -62,7 +71,10 @@ fn test2(map: HashMap, key: &str) -> HashMap { fn main() { let _: HashMap = HashMap::new(); + //~^ ERROR: map with zero-sized value type + //~| ERROR: map with zero-sized value type let _: HashMap = HashMap::new(); let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect(); + //~^ ERROR: map with zero-sized value type } diff --git a/src/tools/clippy/tests/ui/zero_sized_hashmap_values.stderr b/src/tools/clippy/tests/ui/zero_sized_hashmap_values.stderr index 75bdeb42e..08b1b58f3 100644 --- a/src/tools/clippy/tests/ui/zero_sized_hashmap_values.stderr +++ b/src/tools/clippy/tests/ui/zero_sized_hashmap_values.stderr @@ -6,9 +6,10 @@ LL | const CONST_NOT_OK: Option> = None; | = help: consider using a set instead = note: `-D clippy::zero-sized-map-values` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::zero_sized_map_values)]` error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:8:30 + --> $DIR/zero_sized_hashmap_values.rs:9:30 | LL | static STATIC_NOT_OK: Option> = None; | ^^^^^^^^^^^^^^^^^^^ @@ -16,7 +17,7 @@ LL | static STATIC_NOT_OK: Option> = None; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:11:17 + --> $DIR/zero_sized_hashmap_values.rs:13:17 | LL | type NotOkMap = HashMap; | ^^^^^^^^^^^^^^^^^^^ @@ -24,7 +25,7 @@ LL | type NotOkMap = HashMap; = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:15:11 + --> $DIR/zero_sized_hashmap_values.rs:18:11 | LL | NotOk(HashMap), | ^^^^^^^^^^^^^^^^^^^ @@ -32,7 +33,7 @@ LL | NotOk(HashMap), = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:20:13 + --> $DIR/zero_sized_hashmap_values.rs:24:13 | LL | not_ok: HashMap, | ^^^^^^^^^^^^^^^^^^^ @@ -40,7 +41,7 @@ LL | not_ok: HashMap, = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:22:22 + --> $DIR/zero_sized_hashmap_values.rs:26:22 | LL | also_not_ok: Vec>, | ^^^^^^^^^^^^^^^^^^ @@ -48,7 +49,7 @@ LL | also_not_ok: Vec>, = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:30:30 + --> $DIR/zero_sized_hashmap_values.rs:35:30 | LL | fn weird_map(&self, map: HashMap); | ^^^^^^^^^^^^^^^^^^ @@ -56,7 +57,7 @@ LL | fn weird_map(&self, map: HashMap); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:38:25 + --> $DIR/zero_sized_hashmap_values.rs:44:25 | LL | fn not_ok(&self) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -64,7 +65,7 @@ LL | fn not_ok(&self) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:55:14 + --> $DIR/zero_sized_hashmap_values.rs:62:14 | LL | fn test(map: HashMap, key: &str) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -72,7 +73,7 @@ LL | fn test(map: HashMap, key: &str) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:55:49 + --> $DIR/zero_sized_hashmap_values.rs:62:49 | LL | fn test(map: HashMap, key: &str) -> HashMap { | ^^^^^^^^^^^^^^^^^^^ @@ -80,7 +81,7 @@ LL | fn test(map: HashMap, key: &str) -> HashMap { = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:64:34 + --> $DIR/zero_sized_hashmap_values.rs:73:34 | LL | let _: HashMap = HashMap::new(); | ^^^^^^^ @@ -88,7 +89,7 @@ LL | let _: HashMap = HashMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:64:12 + --> $DIR/zero_sized_hashmap_values.rs:73:12 | LL | let _: HashMap = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^ @@ -96,7 +97,7 @@ LL | let _: HashMap = HashMap::new(); = help: consider using a set instead error: map with zero-sized value type - --> $DIR/zero_sized_hashmap_values.rs:67:12 + --> $DIR/zero_sized_hashmap_values.rs:78:12 | LL | let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect(); | ^^^^^^^^^^^^^ -- cgit v1.2.3