summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests/ui')
-rw-r--r--src/tools/clippy/tests/ui/allow_attributes.fixed20
-rw-r--r--src/tools/clippy/tests/ui/allow_attributes.rs20
-rw-r--r--src/tools/clippy/tests/ui/allow_attributes.stderr4
-rw-r--r--src/tools/clippy/tests/ui/allow_attributes_false_positive.rs5
-rw-r--r--src/tools/clippy/tests/ui/allow_attributes_without_reason.rs32
-rw-r--r--src/tools/clippy/tests/ui/allow_attributes_without_reason.stderr28
-rw-r--r--src/tools/clippy/tests/ui/almost_complete_range.fixed2
-rw-r--r--src/tools/clippy/tests/ui/almost_complete_range.rs2
-rw-r--r--src/tools/clippy/tests/ui/arc_with_non_send_sync.rs24
-rw-r--r--src/tools/clippy/tests/ui/arc_with_non_send_sync.stderr34
-rw-r--r--src/tools/clippy/tests/ui/arithmetic_side_effects.rs17
-rw-r--r--src/tools/clippy/tests/ui/as_conversions.rs13
-rw-r--r--src/tools/clippy/tests/ui/as_conversions.stderr6
-rw-r--r--src/tools/clippy/tests/ui/as_ptr_cast_mut.rs2
-rw-r--r--src/tools/clippy/tests/ui/asm_syntax.rs4
-rw-r--r--src/tools/clippy/tests/ui/assertions_on_result_states.fixed1
-rw-r--r--src/tools/clippy/tests/ui/assertions_on_result_states.rs1
-rw-r--r--src/tools/clippy/tests/ui/assertions_on_result_states.stderr14
-rw-r--r--src/tools/clippy/tests/ui/assign_ops.fixed2
-rw-r--r--src/tools/clippy/tests/ui/assign_ops.rs2
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/extern_fake_libc.rs10
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/macro_rules.rs8
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/macro_use_helper.rs2
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs4
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/proc_macro_derive.rs114
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/proc_macro_suspicious_else_formatting.rs5
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/proc_macro_unsafe.rs5
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/proc_macros.rs6
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/wildcard_imports_helper.rs6
-rw-r--r--src/tools/clippy/tests/ui/blocks_in_if_conditions.fixed2
-rw-r--r--src/tools/clippy/tests/ui/blocks_in_if_conditions.rs2
-rw-r--r--src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.rs7
-rw-r--r--src/tools/clippy/tests/ui/blocks_in_if_conditions_closure.stderr4
-rw-r--r--src/tools/clippy/tests/ui/bool_comparison.fixed1
-rw-r--r--src/tools/clippy/tests/ui/bool_comparison.rs1
-rw-r--r--src/tools/clippy/tests/ui/bool_comparison.stderr44
-rw-r--r--src/tools/clippy/tests/ui/borrow_as_ptr.fixed9
-rw-r--r--src/tools/clippy/tests/ui/borrow_as_ptr.rs9
-rw-r--r--src/tools/clippy/tests/ui/borrow_as_ptr.stderr4
-rw-r--r--src/tools/clippy/tests/ui/borrow_deref_ref.fixed2
-rw-r--r--src/tools/clippy/tests/ui/borrow_deref_ref.rs2
-rw-r--r--src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.rs26
-rw-r--r--src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.stderr24
-rw-r--r--src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.rs30
-rw-r--r--src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.stderr34
-rw-r--r--src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.rs32
-rw-r--r--src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.stderr36
-rw-r--r--src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.rs6
-rw-r--r--src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.stderr20
-rw-r--r--src/tools/clippy/tests/ui/builtin_type_shadow.rs2
-rw-r--r--src/tools/clippy/tests/ui/bytecount.rs2
-rw-r--r--src/tools/clippy/tests/ui/cast.rs8
-rw-r--r--src/tools/clippy/tests/ui/cast.stderr118
-rw-r--r--src/tools/clippy/tests/ui/cast_ref_to_mut.rs31
-rw-r--r--src/tools/clippy/tests/ui/cast_ref_to_mut.stderr22
-rw-r--r--src/tools/clippy/tests/ui/cast_slice_different_sizes.rs2
-rw-r--r--src/tools/clippy/tests/ui/cfg_features.rs12
-rw-r--r--src/tools/clippy/tests/ui/cfg_features.stderr28
-rw-r--r--src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.rs6
-rw-r--r--src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.stderr40
-rw-r--r--src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals_nested.rs6
-rw-r--r--src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals_nested.stderr4
-rw-r--r--src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.rs6
-rw-r--r--src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.stderr34
-rw-r--r--src/tools/clippy/tests/ui/clone_on_copy_impl.rs2
-rw-r--r--src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed1
-rw-r--r--src/tools/clippy/tests/ui/cloned_instead_of_copied.rs1
-rw-r--r--src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr16
-rw-r--r--src/tools/clippy/tests/ui/cmp_nan.rs34
-rw-r--r--src/tools/clippy/tests/ui/cmp_nan.stderr148
-rw-r--r--src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.fixed7
-rw-r--r--src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.rs7
-rw-r--r--src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.stderr12
-rw-r--r--src/tools/clippy/tests/ui/cmp_owned/with_suggestion.fixed2
-rw-r--r--src/tools/clippy/tests/ui/cognitive_complexity.stderr10
-rw-r--r--src/tools/clippy/tests/ui/collapsible_else_if.fixed2
-rw-r--r--src/tools/clippy/tests/ui/collapsible_else_if.rs2
-rw-r--r--src/tools/clippy/tests/ui/collapsible_if.fixed1
-rw-r--r--src/tools/clippy/tests/ui/collapsible_if.rs1
-rw-r--r--src/tools/clippy/tests/ui/collapsible_if.stderr18
-rw-r--r--src/tools/clippy/tests/ui/collection_is_never_read.rs2
-rw-r--r--src/tools/clippy/tests/ui/comparison_to_empty.fixed1
-rw-r--r--src/tools/clippy/tests/ui/comparison_to_empty.rs1
-rw-r--r--src/tools/clippy/tests/ui/comparison_to_empty.stderr8
-rw-r--r--src/tools/clippy/tests/ui/crashes/auxiliary/proc_macro_crash.rs8
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-10148.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-10645.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-10645.stderr4
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-10912.rs4
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-10912.stderr16
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-11065.rs19
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-1782.rs1
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-2774.stderr4
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-3462.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-3741.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-4968.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-5497.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-5579.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-6250.stderr16
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-6251.stderr10
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-6255.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-6256.rs4
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-6256.stderr2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-7169.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-7169.stderr2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-7410.rs5
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-9445.stderr12
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-96721.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-96721.stderr2
-rw-r--r--src/tools/clippy/tests/ui/crashes/mut_mut_macro.rs5
-rw-r--r--src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.stderr4
-rw-r--r--src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.rs2
-rw-r--r--src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.stderr11
-rw-r--r--src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs2
-rw-r--r--src/tools/clippy/tests/ui/dbg_macro.rs1
-rw-r--r--src/tools/clippy/tests/ui/dbg_macro.stderr36
-rw-r--r--src/tools/clippy/tests/ui/declare_interior_mutable_const/enums.rs27
-rw-r--r--src/tools/clippy/tests/ui/declare_interior_mutable_const/enums.stderr43
-rw-r--r--src/tools/clippy/tests/ui/declare_interior_mutable_const/others.rs16
-rw-r--r--src/tools/clippy/tests/ui/declare_interior_mutable_const/others.stderr8
-rw-r--r--src/tools/clippy/tests/ui/declare_interior_mutable_const/traits.rs22
-rw-r--r--src/tools/clippy/tests/ui/declare_interior_mutable_const/traits.stderr22
-rw-r--r--src/tools/clippy/tests/ui/def_id_nocore.rs2
-rw-r--r--src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed2
-rw-r--r--src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs2
-rw-r--r--src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed2
-rw-r--r--src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs2
-rw-r--r--src/tools/clippy/tests/ui/default_trait_access.fixed2
-rw-r--r--src/tools/clippy/tests/ui/default_trait_access.rs2
-rw-r--r--src/tools/clippy/tests/ui/deref_addrof.fixed4
-rw-r--r--src/tools/clippy/tests/ui/deref_addrof.rs4
-rw-r--r--src/tools/clippy/tests/ui/deref_addrof_macro.rs2
-rw-r--r--src/tools/clippy/tests/ui/derivable_impls.fixed21
-rw-r--r--src/tools/clippy/tests/ui/derivable_impls.rs21
-rw-r--r--src/tools/clippy/tests/ui/derive.rs2
-rw-r--r--src/tools/clippy/tests/ui/disallowed_names.rs1
-rw-r--r--src/tools/clippy/tests/ui/disallowed_names.stderr28
-rw-r--r--src/tools/clippy/tests/ui/diverging_sub_expression.rs16
-rw-r--r--src/tools/clippy/tests/ui/diverging_sub_expression.stderr46
-rw-r--r--src/tools/clippy/tests/ui/doc/doc-fixable.fixed1
-rw-r--r--src/tools/clippy/tests/ui/doc/doc-fixable.rs1
-rw-r--r--src/tools/clippy/tests/ui/doc/doc-fixable.stderr32
-rw-r--r--src/tools/clippy/tests/ui/doc/needless_doctest_main.rs20
-rw-r--r--src/tools/clippy/tests/ui/doc_unsafe.rs2
-rw-r--r--src/tools/clippy/tests/ui/double_comparison.fixed1
-rw-r--r--src/tools/clippy/tests/ui/double_comparison.rs1
-rw-r--r--src/tools/clippy/tests/ui/double_comparison.stderr16
-rw-r--r--src/tools/clippy/tests/ui/drain_collect.fixed77
-rw-r--r--src/tools/clippy/tests/ui/drain_collect.rs77
-rw-r--r--src/tools/clippy/tests/ui/drain_collect.stderr68
-rw-r--r--src/tools/clippy/tests/ui/else_if_without_else.rs4
-rw-r--r--src/tools/clippy/tests/ui/else_if_without_else.stderr4
-rw-r--r--src/tools/clippy/tests/ui/empty_line_after_doc_comments.rs5
-rw-r--r--src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs5
-rw-r--r--src/tools/clippy/tests/ui/empty_loop.rs2
-rw-r--r--src/tools/clippy/tests/ui/empty_loop_no_std.rs2
-rw-r--r--src/tools/clippy/tests/ui/endian_bytes.rs127
-rw-r--r--src/tools/clippy/tests/ui/endian_bytes.stderr1031
-rw-r--r--src/tools/clippy/tests/ui/enum_clike_unportable_variant.rs2
-rw-r--r--src/tools/clippy/tests/ui/eprint_with_newline.rs2
-rw-r--r--src/tools/clippy/tests/ui/eprint_with_newline.stderr12
-rw-r--r--src/tools/clippy/tests/ui/eq_op.rs4
-rw-r--r--src/tools/clippy/tests/ui/eq_op.stderr20
-rw-r--r--src/tools/clippy/tests/ui/eq_op_macros.rs1
-rw-r--r--src/tools/clippy/tests/ui/eq_op_macros.stderr24
-rw-r--r--src/tools/clippy/tests/ui/equatable_if_let.fixed11
-rw-r--r--src/tools/clippy/tests/ui/equatable_if_let.rs11
-rw-r--r--src/tools/clippy/tests/ui/equatable_if_let.stderr28
-rw-r--r--src/tools/clippy/tests/ui/err_expect.fixed2
-rw-r--r--src/tools/clippy/tests/ui/err_expect.rs2
-rw-r--r--src/tools/clippy/tests/ui/eta.fixed9
-rw-r--r--src/tools/clippy/tests/ui/eta.rs9
-rw-r--r--src/tools/clippy/tests/ui/eta.stderr52
-rw-r--r--src/tools/clippy/tests/ui/excessive_precision.fixed15
-rw-r--r--src/tools/clippy/tests/ui/excessive_precision.rs15
-rw-r--r--src/tools/clippy/tests/ui/excessive_precision.stderr30
-rw-r--r--src/tools/clippy/tests/ui/expect.rs1
-rw-r--r--src/tools/clippy/tests/ui/expect.stderr6
-rw-r--r--src/tools/clippy/tests/ui/expect_fun_call.fixed6
-rw-r--r--src/tools/clippy/tests/ui/expect_fun_call.rs6
-rw-r--r--src/tools/clippy/tests/ui/expect_fun_call.stderr30
-rw-r--r--src/tools/clippy/tests/ui/expect_tool_lint_rfc_2383.rs2
-rw-r--r--src/tools/clippy/tests/ui/explicit_counter_loop.rs50
-rw-r--r--src/tools/clippy/tests/ui/explicit_counter_loop.stderr10
-rw-r--r--src/tools/clippy/tests/ui/explicit_deref_methods.fixed33
-rw-r--r--src/tools/clippy/tests/ui/explicit_deref_methods.rs33
-rw-r--r--src/tools/clippy/tests/ui/explicit_deref_methods.stderr24
-rw-r--r--src/tools/clippy/tests/ui/explicit_into_iter_loop.fixed69
-rw-r--r--src/tools/clippy/tests/ui/explicit_into_iter_loop.rs69
-rw-r--r--src/tools/clippy/tests/ui/explicit_into_iter_loop.stderr40
-rw-r--r--src/tools/clippy/tests/ui/explicit_iter_loop.fixed154
-rw-r--r--src/tools/clippy/tests/ui/explicit_iter_loop.rs154
-rw-r--r--src/tools/clippy/tests/ui/explicit_iter_loop.stderr142
-rw-r--r--src/tools/clippy/tests/ui/extra_unused_lifetimes.rs2
-rw-r--r--src/tools/clippy/tests/ui/extra_unused_type_parameters.fixed12
-rw-r--r--src/tools/clippy/tests/ui/extra_unused_type_parameters.rs12
-rw-r--r--src/tools/clippy/tests/ui/extra_unused_type_parameters.stderr16
-rw-r--r--src/tools/clippy/tests/ui/field_reassign_with_default.rs4
-rw-r--r--src/tools/clippy/tests/ui/filetype_is_file.rs1
-rw-r--r--src/tools/clippy/tests/ui/filetype_is_file.stderr6
-rw-r--r--src/tools/clippy/tests/ui/find_map.rs1
-rw-r--r--src/tools/clippy/tests/ui/fn_null_check.rs1
-rw-r--r--src/tools/clippy/tests/ui/fn_null_check.stderr10
-rw-r--r--src/tools/clippy/tests/ui/for_loop_fixable.fixed309
-rw-r--r--src/tools/clippy/tests/ui/for_loop_fixable.rs309
-rw-r--r--src/tools/clippy/tests/ui/for_loop_fixable.stderr96
-rw-r--r--src/tools/clippy/tests/ui/for_loop_unfixable.rs16
-rw-r--r--src/tools/clippy/tests/ui/for_loop_unfixable.stderr10
-rw-r--r--src/tools/clippy/tests/ui/format.fixed4
-rw-r--r--src/tools/clippy/tests/ui/format.rs4
-rw-r--r--src/tools/clippy/tests/ui/format.stderr30
-rw-r--r--src/tools/clippy/tests/ui/format_push_string.rs29
-rw-r--r--src/tools/clippy/tests/ui/format_push_string.stderr37
-rw-r--r--src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed1
-rw-r--r--src/tools/clippy/tests/ui/from_iter_instead_of_collect.rs1
-rw-r--r--src/tools/clippy/tests/ui/from_iter_instead_of_collect.stderr30
-rw-r--r--src/tools/clippy/tests/ui/from_over_into.fixed15
-rw-r--r--src/tools/clippy/tests/ui/from_over_into.rs15
-rw-r--r--src/tools/clippy/tests/ui/from_over_into.stderr18
-rw-r--r--src/tools/clippy/tests/ui/from_over_into_unfixable.rs16
-rw-r--r--src/tools/clippy/tests/ui/from_over_into_unfixable.stderr10
-rw-r--r--src/tools/clippy/tests/ui/from_raw_with_void_ptr.rs1
-rw-r--r--src/tools/clippy/tests/ui/from_raw_with_void_ptr.stderr20
-rw-r--r--src/tools/clippy/tests/ui/get_first.fixed1
-rw-r--r--src/tools/clippy/tests/ui/get_first.rs1
-rw-r--r--src/tools/clippy/tests/ui/get_first.stderr6
-rw-r--r--src/tools/clippy/tests/ui/get_last_with_len.fixed2
-rw-r--r--src/tools/clippy/tests/ui/get_last_with_len.rs2
-rw-r--r--src/tools/clippy/tests/ui/get_unwrap.fixed46
-rw-r--r--src/tools/clippy/tests/ui/get_unwrap.rs46
-rw-r--r--src/tools/clippy/tests/ui/get_unwrap.stderr80
-rw-r--r--src/tools/clippy/tests/ui/if_same_then_else.rs10
-rw-r--r--src/tools/clippy/tests/ui/if_same_then_else.stderr24
-rw-r--r--src/tools/clippy/tests/ui/if_same_then_else2.rs12
-rw-r--r--src/tools/clippy/tests/ui/if_same_then_else2.stderr37
-rw-r--r--src/tools/clippy/tests/ui/ifs_same_cond.rs14
-rw-r--r--src/tools/clippy/tests/ui/ifs_same_cond.stderr16
-rw-r--r--src/tools/clippy/tests/ui/implicit_hasher.rs2
-rw-r--r--src/tools/clippy/tests/ui/inconsistent_struct_constructor.fixed2
-rw-r--r--src/tools/clippy/tests/ui/inconsistent_struct_constructor.rs2
-rw-r--r--src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.fixed97
-rw-r--r--src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.rs107
-rw-r--r--src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.stderr40
-rw-r--r--src/tools/clippy/tests/ui/indexing_slicing_index.rs7
-rw-r--r--src/tools/clippy/tests/ui/indexing_slicing_index.stderr26
-rw-r--r--src/tools/clippy/tests/ui/indexing_slicing_slice.rs2
-rw-r--r--src/tools/clippy/tests/ui/into_iter_on_ref.fixed54
-rw-r--r--src/tools/clippy/tests/ui/into_iter_on_ref.rs54
-rw-r--r--src/tools/clippy/tests/ui/into_iter_on_ref.stderr54
-rw-r--r--src/tools/clippy/tests/ui/invalid_utf8_in_unchecked.rs20
-rw-r--r--src/tools/clippy/tests/ui/invalid_utf8_in_unchecked.stderr22
-rw-r--r--src/tools/clippy/tests/ui/issue-3145.rs2
-rw-r--r--src/tools/clippy/tests/ui/issue-3145.stderr2
-rw-r--r--src/tools/clippy/tests/ui/issue_4266.stderr8
-rw-r--r--src/tools/clippy/tests/ui/items_after_test_module/block_module.stderr17
-rw-r--r--src/tools/clippy/tests/ui/iter_cloned_collect.fixed1
-rw-r--r--src/tools/clippy/tests/ui/iter_cloned_collect.rs1
-rw-r--r--src/tools/clippy/tests/ui/iter_cloned_collect.stderr10
-rw-r--r--src/tools/clippy/tests/ui/iter_count.fixed3
-rw-r--r--src/tools/clippy/tests/ui/iter_count.rs3
-rw-r--r--src/tools/clippy/tests/ui/iter_count.stderr50
-rw-r--r--src/tools/clippy/tests/ui/iter_next_loop.rs16
-rw-r--r--src/tools/clippy/tests/ui/iter_next_loop.stderr9
-rw-r--r--src/tools/clippy/tests/ui/iter_next_slice.fixed1
-rw-r--r--src/tools/clippy/tests/ui/iter_next_slice.rs1
-rw-r--r--src/tools/clippy/tests/ui/iter_next_slice.stderr8
-rw-r--r--src/tools/clippy/tests/ui/iter_nth.rs1
-rw-r--r--src/tools/clippy/tests/ui/iter_nth.stderr22
-rw-r--r--src/tools/clippy/tests/ui/iter_nth_zero.fixed15
-rw-r--r--src/tools/clippy/tests/ui/iter_nth_zero.rs15
-rw-r--r--src/tools/clippy/tests/ui/iter_overeager_cloned.fixed2
-rw-r--r--src/tools/clippy/tests/ui/iter_overeager_cloned.rs2
-rw-r--r--src/tools/clippy/tests/ui/iter_skip_next.fixed1
-rw-r--r--src/tools/clippy/tests/ui/iter_skip_next.rs1
-rw-r--r--src/tools/clippy/tests/ui/iter_skip_next.stderr14
-rw-r--r--src/tools/clippy/tests/ui/iter_with_drain.fixed2
-rw-r--r--src/tools/clippy/tests/ui/iter_with_drain.rs2
-rw-r--r--src/tools/clippy/tests/ui/iterator_step_by_zero.rs1
-rw-r--r--src/tools/clippy/tests/ui/iterator_step_by_zero.stderr14
-rw-r--r--src/tools/clippy/tests/ui/large_enum_variant.rs2
-rw-r--r--src/tools/clippy/tests/ui/large_futures.rs1
-rw-r--r--src/tools/clippy/tests/ui/large_futures.stderr16
-rw-r--r--src/tools/clippy/tests/ui/large_stack_arrays.rs13
-rw-r--r--src/tools/clippy/tests/ui/large_stack_arrays.stderr30
-rw-r--r--src/tools/clippy/tests/ui/large_stack_frames.rs44
-rw-r--r--src/tools/clippy/tests/ui/large_stack_frames.stderr37
-rw-r--r--src/tools/clippy/tests/ui/len_zero.fixed2
-rw-r--r--src/tools/clippy/tests/ui/len_zero.rs2
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_untyped.rs2
-rw-r--r--src/tools/clippy/tests/ui/let_with_type_underscore.rs2
-rw-r--r--src/tools/clippy/tests/ui/lossy_float_literal.fixed4
-rw-r--r--src/tools/clippy/tests/ui/lossy_float_literal.rs4
-rw-r--r--src/tools/clippy/tests/ui/lossy_float_literal.stderr22
-rw-r--r--src/tools/clippy/tests/ui/macro_use_imports.fixed2
-rw-r--r--src/tools/clippy/tests/ui/macro_use_imports.rs2
-rw-r--r--src/tools/clippy/tests/ui/macro_use_imports.stderr16
-rw-r--r--src/tools/clippy/tests/ui/macro_use_imports_expect.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.edition2018.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.edition2021.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_async_fn.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_async_fn.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_filter.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_filter.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_filter_map.fixed1
-rw-r--r--src/tools/clippy/tests/ui/manual_filter_map.rs1
-rw-r--r--src/tools/clippy/tests/ui/manual_filter_map.stderr54
-rw-r--r--src/tools/clippy/tests/ui/manual_find_map.fixed1
-rw-r--r--src/tools/clippy/tests/ui/manual_find_map.rs1
-rw-r--r--src/tools/clippy/tests/ui/manual_find_map.stderr60
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else.rs66
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else.stderr130
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else_match.rs13
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else_match.stderr31
-rw-r--r--src/tools/clippy/tests/ui/manual_memcpy/without_loop_counters.rs1
-rw-r--r--src/tools/clippy/tests/ui/manual_memcpy/without_loop_counters.stderr26
-rw-r--r--src/tools/clippy/tests/ui/manual_range_patterns.fixed35
-rw-r--r--src/tools/clippy/tests/ui/manual_range_patterns.rs35
-rw-r--r--src/tools/clippy/tests/ui/manual_range_patterns.stderr51
-rw-r--r--src/tools/clippy/tests/ui/manual_rem_euclid.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_rem_euclid.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_slice_size_calculation.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_slice_size_calculation.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_try_fold.rs100
-rw-r--r--src/tools/clippy/tests/ui/manual_try_fold.stderr28
-rw-r--r--src/tools/clippy/tests/ui/manual_unwrap_or.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_unwrap_or.rs2
-rw-r--r--src/tools/clippy/tests/ui/map_clone.fixed3
-rw-r--r--src/tools/clippy/tests/ui/map_clone.rs3
-rw-r--r--src/tools/clippy/tests/ui/map_clone.stderr12
-rw-r--r--src/tools/clippy/tests/ui/map_unwrap_or.rs47
-rw-r--r--src/tools/clippy/tests/ui/map_unwrap_or.stderr44
-rw-r--r--src/tools/clippy/tests/ui/match_on_vec_items.rs1
-rw-r--r--src/tools/clippy/tests/ui/match_on_vec_items.stderr16
-rw-r--r--src/tools/clippy/tests/ui/match_overlapping_arm.rs2
-rw-r--r--src/tools/clippy/tests/ui/match_same_arms.rs20
-rw-r--r--src/tools/clippy/tests/ui/match_same_arms.stderr24
-rw-r--r--src/tools/clippy/tests/ui/match_same_arms2.rs23
-rw-r--r--src/tools/clippy/tests/ui/match_same_arms2.stderr33
-rw-r--r--src/tools/clippy/tests/ui/match_same_arms_non_exhaustive.rs58
-rw-r--r--src/tools/clippy/tests/ui/match_same_arms_non_exhaustive.stderr29
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding.fixed3
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding.rs3
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding.stderr48
-rw-r--r--src/tools/clippy/tests/ui/match_wild_err_arm.rs15
-rw-r--r--src/tools/clippy/tests/ui/match_wild_err_arm.stderr8
-rw-r--r--src/tools/clippy/tests/ui/mem_forget.rs3
-rw-r--r--src/tools/clippy/tests/ui/mem_forget.stderr15
-rw-r--r--src/tools/clippy/tests/ui/mem_replace_macro.rs2
-rw-r--r--src/tools/clippy/tests/ui/methods.rs1
-rw-r--r--src/tools/clippy/tests/ui/methods.stderr4
-rw-r--r--src/tools/clippy/tests/ui/methods_fixable.fixed1
-rw-r--r--src/tools/clippy/tests/ui/methods_fixable.rs1
-rw-r--r--src/tools/clippy/tests/ui/methods_fixable.stderr2
-rw-r--r--src/tools/clippy/tests/ui/min_ident_chars.rs84
-rw-r--r--src/tools/clippy/tests/ui/min_ident_chars.stderr178
-rw-r--r--src/tools/clippy/tests/ui/missing_assert_message.rs11
-rw-r--r--src/tools/clippy/tests/ui/missing_assert_message.stderr32
-rw-r--r--src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs45
-rw-r--r--src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs13
-rw-r--r--src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr30
-rw-r--r--src/tools/clippy/tests/ui/missing_doc.rs2
-rw-r--r--src/tools/clippy/tests/ui/missing_doc_impl.rs2
-rw-r--r--src/tools/clippy/tests/ui/missing_fields_in_debug.rs191
-rw-r--r--src/tools/clippy/tests/ui/missing_fields_in_debug.stderr73
-rw-r--r--src/tools/clippy/tests/ui/missing_inline_proc_macro.rs1
-rw-r--r--src/tools/clippy/tests/ui/missing_panics_doc.rs80
-rw-r--r--src/tools/clippy/tests/ui/missing_panics_doc.stderr110
-rw-r--r--src/tools/clippy/tests/ui/mistyped_literal_suffix.fixed2
-rw-r--r--src/tools/clippy/tests/ui/mistyped_literal_suffix.rs2
-rw-r--r--src/tools/clippy/tests/ui/module_inception.rs12
-rw-r--r--src/tools/clippy/tests/ui/module_inception.stderr22
-rw-r--r--src/tools/clippy/tests/ui/modulo_one.stderr6
-rw-r--r--src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs2
-rw-r--r--src/tools/clippy/tests/ui/must_use_unit.fixed2
-rw-r--r--src/tools/clippy/tests/ui/must_use_unit.rs2
-rw-r--r--src/tools/clippy/tests/ui/mut_mut.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.rs5
-rw-r--r--src/tools/clippy/tests/ui/needless_bool/fixable.fixed1
-rw-r--r--src/tools/clippy/tests/ui/needless_bool/fixable.rs1
-rw-r--r--src/tools/clippy/tests/ui/needless_bool/fixable.stderr42
-rw-r--r--src/tools/clippy/tests/ui/needless_borrow.fixed15
-rw-r--r--src/tools/clippy/tests/ui/needless_borrow.rs15
-rw-r--r--src/tools/clippy/tests/ui/needless_borrow.stderr72
-rw-r--r--src/tools/clippy/tests/ui/needless_borrowed_ref.fixed3
-rw-r--r--src/tools/clippy/tests/ui/needless_borrowed_ref.rs3
-rw-r--r--src/tools/clippy/tests/ui/needless_borrowed_ref.stderr34
-rw-r--r--src/tools/clippy/tests/ui/needless_collect.fixed7
-rw-r--r--src/tools/clippy/tests/ui/needless_collect.rs7
-rw-r--r--src/tools/clippy/tests/ui/needless_collect_indirect.rs3
-rw-r--r--src/tools/clippy/tests/ui/needless_collect_indirect.stderr32
-rw-r--r--src/tools/clippy/tests/ui/needless_else.fixed57
-rw-r--r--src/tools/clippy/tests/ui/needless_else.rs58
-rw-r--r--src/tools/clippy/tests/ui/needless_else.stderr12
-rw-r--r--src/tools/clippy/tests/ui/needless_if.fixed93
-rw-r--r--src/tools/clippy/tests/ui/needless_if.rs94
-rw-r--r--src/tools/clippy/tests/ui/needless_if.stderr65
-rw-r--r--src/tools/clippy/tests/ui/needless_late_init.fixed5
-rw-r--r--src/tools/clippy/tests/ui/needless_late_init.rs5
-rw-r--r--src/tools/clippy/tests/ui/needless_late_init.stderr32
-rw-r--r--src/tools/clippy/tests/ui/needless_lifetimes.fixed2
-rw-r--r--src/tools/clippy/tests/ui/needless_lifetimes.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_lifetimes.stderr184
-rw-r--r--src/tools/clippy/tests/ui/needless_option_as_deref.fixed1
-rw-r--r--src/tools/clippy/tests/ui/needless_option_as_deref.rs1
-rw-r--r--src/tools/clippy/tests/ui/needless_option_as_deref.stderr6
-rw-r--r--src/tools/clippy/tests/ui/needless_pass_by_value_proc_macro.rs1
-rw-r--r--src/tools/clippy/tests/ui/needless_pub_self.fixed33
-rw-r--r--src/tools/clippy/tests/ui/needless_pub_self.rs33
-rw-r--r--src/tools/clippy/tests/ui/needless_pub_self.stderr22
-rw-r--r--src/tools/clippy/tests/ui/needless_range_loop.rs64
-rw-r--r--src/tools/clippy/tests/ui/needless_range_loop.stderr28
-rw-r--r--src/tools/clippy/tests/ui/needless_range_loop2.rs1
-rw-r--r--src/tools/clippy/tests/ui/needless_range_loop2.stderr16
-rw-r--r--src/tools/clippy/tests/ui/needless_raw_string.fixed17
-rw-r--r--src/tools/clippy/tests/ui/needless_raw_string.rs17
-rw-r--r--src/tools/clippy/tests/ui/needless_raw_string.stderr16
-rw-r--r--src/tools/clippy/tests/ui/needless_raw_string_hashes.fixed20
-rw-r--r--src/tools/clippy/tests/ui/needless_raw_string_hashes.rs20
-rw-r--r--src/tools/clippy/tests/ui/needless_raw_string_hashes.stderr40
-rw-r--r--src/tools/clippy/tests/ui/needless_return.fixed3
-rw-r--r--src/tools/clippy/tests/ui/needless_return.rs3
-rw-r--r--src/tools/clippy/tests/ui/needless_return.stderr426
-rw-r--r--src/tools/clippy/tests/ui/never_loop.rs38
-rw-r--r--src/tools/clippy/tests/ui/never_loop.stderr46
-rw-r--r--src/tools/clippy/tests/ui/new_ret_no_self.rs22
-rw-r--r--src/tools/clippy/tests/ui/new_ret_no_self.stderr18
-rw-r--r--src/tools/clippy/tests/ui/new_ret_no_self_overflow.rs26
-rw-r--r--src/tools/clippy/tests/ui/new_ret_no_self_overflow.stderr9
-rw-r--r--src/tools/clippy/tests/ui/no_effect.rs3
-rw-r--r--src/tools/clippy/tests/ui/no_effect.stderr58
-rw-r--r--src/tools/clippy/tests/ui/no_effect_return.rs81
-rw-r--r--src/tools/clippy/tests/ui/no_effect_return.stderr70
-rw-r--r--src/tools/clippy/tests/ui/non_expressive_names.rs12
-rw-r--r--src/tools/clippy/tests/ui/non_expressive_names.stderr6
-rw-r--r--src/tools/clippy/tests/ui/non_octal_unix_permissions.fixed2
-rw-r--r--src/tools/clippy/tests/ui/non_octal_unix_permissions.rs2
-rw-r--r--src/tools/clippy/tests/ui/nonminimal_bool.rs17
-rw-r--r--src/tools/clippy/tests/ui/nonminimal_bool.stderr26
-rw-r--r--src/tools/clippy/tests/ui/nonminimal_bool_methods.fixed2
-rw-r--r--src/tools/clippy/tests/ui/nonminimal_bool_methods.rs2
-rw-r--r--src/tools/clippy/tests/ui/octal_escapes.stderr6
-rw-r--r--src/tools/clippy/tests/ui/ok_expect.rs2
-rw-r--r--src/tools/clippy/tests/ui/ok_expect.stderr10
-rw-r--r--src/tools/clippy/tests/ui/option_as_ref_deref.fixed2
-rw-r--r--src/tools/clippy/tests/ui/option_as_ref_deref.rs2
-rw-r--r--src/tools/clippy/tests/ui/option_env_unwrap.rs2
-rw-r--r--src/tools/clippy/tests/ui/option_if_let_else.fixed16
-rw-r--r--src/tools/clippy/tests/ui/option_if_let_else.rs22
-rw-r--r--src/tools/clippy/tests/ui/option_if_let_else.stderr20
-rw-r--r--src/tools/clippy/tests/ui/or_fun_call.fixed8
-rw-r--r--src/tools/clippy/tests/ui/or_fun_call.rs8
-rw-r--r--src/tools/clippy/tests/ui/or_fun_call.stderr56
-rw-r--r--src/tools/clippy/tests/ui/or_then_unwrap.fixed2
-rw-r--r--src/tools/clippy/tests/ui/or_then_unwrap.rs2
-rw-r--r--src/tools/clippy/tests/ui/overflow_check_conditional.rs1
-rw-r--r--src/tools/clippy/tests/ui/overflow_check_conditional.stderr16
-rw-r--r--src/tools/clippy/tests/ui/partialeq_to_none.fixed2
-rw-r--r--src/tools/clippy/tests/ui/partialeq_to_none.rs2
-rw-r--r--src/tools/clippy/tests/ui/patterns.fixed11
-rw-r--r--src/tools/clippy/tests/ui/patterns.rs11
-rw-r--r--src/tools/clippy/tests/ui/patterns.stderr6
-rw-r--r--src/tools/clippy/tests/ui/print_with_newline.fixed58
-rw-r--r--src/tools/clippy/tests/ui/print_with_newline.rs2
-rw-r--r--src/tools/clippy/tests/ui/print_with_newline.stderr12
-rw-r--r--src/tools/clippy/tests/ui/proc_macro.rs1
-rw-r--r--src/tools/clippy/tests/ui/proc_macro.stderr2
-rw-r--r--src/tools/clippy/tests/ui/ptr_arg.rs33
-rw-r--r--src/tools/clippy/tests/ui/ptr_arg.stderr60
-rw-r--r--src/tools/clippy/tests/ui/ptr_as_ptr.fixed2
-rw-r--r--src/tools/clippy/tests/ui/ptr_as_ptr.rs2
-rw-r--r--src/tools/clippy/tests/ui/ptr_cast_constness.fixed62
-rw-r--r--src/tools/clippy/tests/ui/ptr_cast_constness.rs62
-rw-r--r--src/tools/clippy/tests/ui/ptr_cast_constness.stderr46
-rw-r--r--src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed2
-rw-r--r--src/tools/clippy/tests/ui/ptr_offset_with_cast.rs2
-rw-r--r--src/tools/clippy/tests/ui/pub_with_shorthand.fixed38
-rw-r--r--src/tools/clippy/tests/ui/pub_with_shorthand.rs38
-rw-r--r--src/tools/clippy/tests/ui/pub_with_shorthand.stderr28
-rw-r--r--src/tools/clippy/tests/ui/pub_without_shorthand.fixed38
-rw-r--r--src/tools/clippy/tests/ui/pub_without_shorthand.rs38
-rw-r--r--src/tools/clippy/tests/ui/pub_without_shorthand.stderr22
-rw-r--r--src/tools/clippy/tests/ui/question_mark.fixed22
-rw-r--r--src/tools/clippy/tests/ui/question_mark.rs26
-rw-r--r--src/tools/clippy/tests/ui/question_mark.stderr42
-rw-r--r--src/tools/clippy/tests/ui/range.rs1
-rw-r--r--src/tools/clippy/tests/ui/range.stderr2
-rw-r--r--src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.rs1
-rw-r--r--src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.stderr8
-rw-r--r--src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.rs1
-rw-r--r--src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.stderr8
-rw-r--r--src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.rs1
-rw-r--r--src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.stderr16
-rw-r--r--src/tools/clippy/tests/ui/redundant_at_rest_pattern.fixed27
-rw-r--r--src/tools/clippy/tests/ui/redundant_at_rest_pattern.rs27
-rw-r--r--src/tools/clippy/tests/ui/redundant_at_rest_pattern.stderr40
-rw-r--r--src/tools/clippy/tests/ui/redundant_clone.fixed7
-rw-r--r--src/tools/clippy/tests/ui/redundant_clone.rs7
-rw-r--r--src/tools/clippy/tests/ui/redundant_clone.stderr60
-rw-r--r--src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed47
-rw-r--r--src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs47
-rw-r--r--src/tools/clippy/tests/ui/redundant_closure_call_fixable.stderr62
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.fixed7
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.rs7
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.stderr44
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed1
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs1
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr36
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed13
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_option.rs13
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_option.stderr66
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_poll.fixed1
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_poll.rs1
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_poll.stderr36
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed16
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs16
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr66
-rw-r--r--src/tools/clippy/tests/ui/redundant_pub_crate.fixed8
-rw-r--r--src/tools/clippy/tests/ui/redundant_pub_crate.rs8
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed22
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes.rs22
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr24
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes_multiple.rs6
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes_multiple.stderr12
-rw-r--r--src/tools/clippy/tests/ui/redundant_type_annotations.rs190
-rw-r--r--src/tools/clippy/tests/ui/redundant_type_annotations.stderr106
-rw-r--r--src/tools/clippy/tests/ui/regex.rs14
-rw-r--r--src/tools/clippy/tests/ui/regex.stderr58
-rw-r--r--src/tools/clippy/tests/ui/rename.fixed9
-rw-r--r--src/tools/clippy/tests/ui/rename.rs9
-rw-r--r--src/tools/clippy/tests/ui/rename.stderr122
-rw-r--r--src/tools/clippy/tests/ui/same_functions_in_if_condition.rs16
-rw-r--r--src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr24
-rw-r--r--src/tools/clippy/tests/ui/search_is_some.rs1
-rw-r--r--src/tools/clippy/tests/ui/search_is_some.stderr16
-rw-r--r--src/tools/clippy/tests/ui/search_is_some_fixable_none.fixed2
-rw-r--r--src/tools/clippy/tests/ui/search_is_some_fixable_none.rs2
-rw-r--r--src/tools/clippy/tests/ui/search_is_some_fixable_some.fixed2
-rw-r--r--src/tools/clippy/tests/ui/search_is_some_fixable_some.rs2
-rw-r--r--src/tools/clippy/tests/ui/self_assignment.rs1
-rw-r--r--src/tools/clippy/tests/ui/self_assignment.stderr22
-rw-r--r--src/tools/clippy/tests/ui/shadow.rs4
-rw-r--r--src/tools/clippy/tests/ui/significant_drop_in_scrutinee.fixed627
-rw-r--r--src/tools/clippy/tests/ui/significant_drop_tightening.fixed12
-rw-r--r--src/tools/clippy/tests/ui/significant_drop_tightening.rs12
-rw-r--r--src/tools/clippy/tests/ui/significant_drop_tightening.stderr6
-rw-r--r--src/tools/clippy/tests/ui/single_call_fn.rs74
-rw-r--r--src/tools/clippy/tests/ui/single_call_fn.stderr55
-rw-r--r--src/tools/clippy/tests/ui/single_char_add_str.fixed1
-rw-r--r--src/tools/clippy/tests/ui/single_char_add_str.rs1
-rw-r--r--src/tools/clippy/tests/ui/single_char_add_str.stderr30
-rw-r--r--src/tools/clippy/tests/ui/single_char_pattern.fixed2
-rw-r--r--src/tools/clippy/tests/ui/single_char_pattern.rs2
-rw-r--r--src/tools/clippy/tests/ui/single_char_pattern.stderr4
-rw-r--r--src/tools/clippy/tests/ui/single_element_loop.fixed2
-rw-r--r--src/tools/clippy/tests/ui/single_element_loop.rs2
-rw-r--r--src/tools/clippy/tests/ui/single_element_loop.stderr14
-rw-r--r--src/tools/clippy/tests/ui/single_match.fixed254
-rw-r--r--src/tools/clippy/tests/ui/single_match.rs70
-rw-r--r--src/tools/clippy/tests/ui/single_match.stderr76
-rw-r--r--src/tools/clippy/tests/ui/single_match_else.fixed173
-rw-r--r--src/tools/clippy/tests/ui/single_match_else.rs90
-rw-r--r--src/tools/clippy/tests/ui/single_match_else.stderr98
-rw-r--r--src/tools/clippy/tests/ui/single_range_in_vec_init.rs58
-rw-r--r--src/tools/clippy/tests/ui/single_range_in_vec_init.stderr145
-rw-r--r--src/tools/clippy/tests/ui/skip_while_next.rs2
-rw-r--r--src/tools/clippy/tests/ui/stable_sort_primitive.fixed1
-rw-r--r--src/tools/clippy/tests/ui/stable_sort_primitive.rs1
-rw-r--r--src/tools/clippy/tests/ui/stable_sort_primitive.stderr14
-rw-r--r--src/tools/clippy/tests/ui/starts_ends_with.fixed2
-rw-r--r--src/tools/clippy/tests/ui/starts_ends_with.rs2
-rw-r--r--src/tools/clippy/tests/ui/string_add.rs2
-rw-r--r--src/tools/clippy/tests/ui/string_lit_as_bytes.fixed2
-rw-r--r--src/tools/clippy/tests/ui/string_lit_as_bytes.rs2
-rw-r--r--src/tools/clippy/tests/ui/suspicious_else_formatting.rs16
-rw-r--r--src/tools/clippy/tests/ui/suspicious_else_formatting.stderr18
-rw-r--r--src/tools/clippy/tests/ui/suspicious_unary_op_formatting.rs1
-rw-r--r--src/tools/clippy/tests/ui/suspicious_unary_op_formatting.stderr8
-rw-r--r--src/tools/clippy/tests/ui/swap.fixed3
-rw-r--r--src/tools/clippy/tests/ui/swap.rs3
-rw-r--r--src/tools/clippy/tests/ui/swap.stderr34
-rw-r--r--src/tools/clippy/tests/ui/tests_outside_test_module.rs1
-rw-r--r--src/tools/clippy/tests/ui/tests_outside_test_module.stderr2
-rw-r--r--src/tools/clippy/tests/ui/to_string_in_format_args_incremental.fixed9
-rw-r--r--src/tools/clippy/tests/ui/toplevel_ref_arg.fixed4
-rw-r--r--src/tools/clippy/tests/ui/toplevel_ref_arg.rs4
-rw-r--r--src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.rs2
-rw-r--r--src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs2
-rw-r--r--src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed2
-rw-r--r--src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs2
-rw-r--r--src/tools/clippy/tests/ui/try_err.fixed2
-rw-r--r--src/tools/clippy/tests/ui/try_err.rs2
-rw-r--r--src/tools/clippy/tests/ui/tuple_array_conversions.rs73
-rw-r--r--src/tools/clippy/tests/ui/tuple_array_conversions.stderr83
-rw-r--r--src/tools/clippy/tests/ui/type_complexity.rs2
-rw-r--r--src/tools/clippy/tests/ui/type_repetition_in_bounds.rs39
-rw-r--r--src/tools/clippy/tests/ui/type_repetition_in_bounds.stderr18
-rw-r--r--src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs24
-rw-r--r--src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr26
-rw-r--r--src/tools/clippy/tests/ui/undropped_manually_drops.rs26
-rw-r--r--src/tools/clippy/tests/ui/undropped_manually_drops.stderr19
-rw-r--r--src/tools/clippy/tests/ui/unicode.fixed1
-rw-r--r--src/tools/clippy/tests/ui/unicode.rs1
-rw-r--r--src/tools/clippy/tests/ui/unicode.stderr20
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args.fixed9
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args.rs9
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args.stderr142
-rw-r--r--src/tools/clippy/tests/ui/unit_arg.rs2
-rw-r--r--src/tools/clippy/tests/ui/unit_cmp.rs3
-rw-r--r--src/tools/clippy/tests/ui/unit_cmp.stderr12
-rw-r--r--src/tools/clippy/tests/ui/unit_return_expecting_ord.rs1
-rw-r--r--src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr12
-rw-r--r--src/tools/clippy/tests/ui/unknown_clippy_lints.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unknown_clippy_lints.rs2
-rw-r--r--src/tools/clippy/tests/ui/unknown_clippy_lints.stderr6
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast.fixed81
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast.rs81
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast.stderr110
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_fold.fixed24
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_fold.rs24
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_fold.stderr56
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_join.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_join.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed30
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs30
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr102
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.rs1
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.stderr6
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_literal_unwrap.fixed89
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_literal_unwrap.rs89
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_literal_unwrap.stderr521
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.rs118
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.stderr615
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_safety_comment.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_sort_by.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_sort_by.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_struct_initialization.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_struct_initialization.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.fixed33
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.rs33
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs2
-rw-r--r--src/tools/clippy/tests/ui/unneeded_field_pattern.rs14
-rw-r--r--src/tools/clippy/tests/ui/unneeded_field_pattern.stderr4
-rw-r--r--src/tools/clippy/tests/ui/unneeded_wildcard_pattern.fixed9
-rw-r--r--src/tools/clippy/tests/ui/unneeded_wildcard_pattern.rs9
-rw-r--r--src/tools/clippy/tests/ui/unneeded_wildcard_pattern.stderr30
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns.fixed8
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns.rs8
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns.stderr34
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns2.fixed7
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns2.rs7
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns2.stderr16
-rw-r--r--src/tools/clippy/tests/ui/unseparated_prefix_literals.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unseparated_prefix_literals.rs2
-rw-r--r--src/tools/clippy/tests/ui/unused_async.rs34
-rw-r--r--src/tools/clippy/tests/ui/unused_async.stderr25
-rw-r--r--src/tools/clippy/tests/ui/unwrap.rs1
-rw-r--r--src/tools/clippy/tests/ui/unwrap.stderr6
-rw-r--r--src/tools/clippy/tests/ui/unwrap_expect_used.rs1
-rw-r--r--src/tools/clippy/tests/ui/unwrap_expect_used.stderr12
-rw-r--r--src/tools/clippy/tests/ui/unwrap_or.rs1
-rw-r--r--src/tools/clippy/tests/ui/unwrap_or.stderr4
-rw-r--r--src/tools/clippy/tests/ui/unwrap_or_else_default.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unwrap_or_else_default.rs2
-rwxr-xr-xsrc/tools/clippy/tests/ui/update-all-references.sh2
-rw-r--r--src/tools/clippy/tests/ui/use_self.fixed2
-rw-r--r--src/tools/clippy/tests/ui/use_self.rs2
-rw-r--r--src/tools/clippy/tests/ui/used_underscore_binding.rs2
-rw-r--r--src/tools/clippy/tests/ui/useless_attribute.fixed2
-rw-r--r--src/tools/clippy/tests/ui/useless_attribute.rs2
-rw-r--r--src/tools/clippy/tests/ui/useless_conversion.fixed45
-rw-r--r--src/tools/clippy/tests/ui/useless_conversion.rs45
-rw-r--r--src/tools/clippy/tests/ui/useless_conversion.stderr62
-rw-r--r--src/tools/clippy/tests/ui/useless_conversion_try.rs1
-rw-r--r--src/tools/clippy/tests/ui/useless_conversion_try.stderr18
-rw-r--r--src/tools/clippy/tests/ui/vec.fixed82
-rw-r--r--src/tools/clippy/tests/ui/vec.rs82
-rw-r--r--src/tools/clippy/tests/ui/vec.stderr56
-rw-r--r--src/tools/clippy/tests/ui/vtable_address_comparisons.rs12
-rw-r--r--src/tools/clippy/tests/ui/vtable_address_comparisons.stderr18
-rw-r--r--src/tools/clippy/tests/ui/while_let_on_iterator.fixed4
-rw-r--r--src/tools/clippy/tests/ui/while_let_on_iterator.rs4
-rw-r--r--src/tools/clippy/tests/ui/while_let_on_iterator.stderr52
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports.fixed4
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports.rs4
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports.stderr34
-rw-r--r--src/tools/clippy/tests/ui/write_literal_2.rs2
-rw-r--r--src/tools/clippy/tests/ui/write_literal_2.stderr32
-rw-r--r--src/tools/clippy/tests/ui/write_with_newline.fixed63
-rw-r--r--src/tools/clippy/tests/ui/write_with_newline.stderr12
690 files changed, 14360 insertions, 3914 deletions
diff --git a/src/tools/clippy/tests/ui/allow_attributes.fixed b/src/tools/clippy/tests/ui/allow_attributes.fixed
index f0936b260..cc95a0681 100644
--- a/src/tools/clippy/tests/ui/allow_attributes.fixed
+++ b/src/tools/clippy/tests/ui/allow_attributes.fixed
@@ -1,9 +1,12 @@
//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
#![allow(unused)]
#![warn(clippy::allow_attributes)]
#![feature(lint_reasons)]
+#![no_main]
-fn main() {}
+extern crate proc_macros;
+use proc_macros::{external, with_span};
// Using clippy::needless_borrow just as a placeholder, it isn't relevant.
@@ -20,6 +23,21 @@ struct T4;
#[cfg_attr(panic = "unwind", expect(dead_code))]
struct CfgT;
+fn ignore_external() {
+ external! {
+ #[allow(clippy::needless_borrow)] // Should not lint
+ fn a() {}
+ }
+}
+
+fn ignore_proc_macro() {
+ with_span! {
+ span
+ #[allow(clippy::needless_borrow)] // Should not lint
+ fn a() {}
+ }
+}
+
fn ignore_inner_attr() {
#![allow(unused)] // Should not lint
}
diff --git a/src/tools/clippy/tests/ui/allow_attributes.rs b/src/tools/clippy/tests/ui/allow_attributes.rs
index 2fb9e8612..2eb6ad304 100644
--- a/src/tools/clippy/tests/ui/allow_attributes.rs
+++ b/src/tools/clippy/tests/ui/allow_attributes.rs
@@ -1,9 +1,12 @@
//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
#![allow(unused)]
#![warn(clippy::allow_attributes)]
#![feature(lint_reasons)]
+#![no_main]
-fn main() {}
+extern crate proc_macros;
+use proc_macros::{external, with_span};
// Using clippy::needless_borrow just as a placeholder, it isn't relevant.
@@ -20,6 +23,21 @@ struct T4;
#[cfg_attr(panic = "unwind", allow(dead_code))]
struct CfgT;
+fn ignore_external() {
+ external! {
+ #[allow(clippy::needless_borrow)] // Should not lint
+ fn a() {}
+ }
+}
+
+fn ignore_proc_macro() {
+ with_span! {
+ span
+ #[allow(clippy::needless_borrow)] // Should not lint
+ fn a() {}
+ }
+}
+
fn ignore_inner_attr() {
#![allow(unused)] // Should not lint
}
diff --git a/src/tools/clippy/tests/ui/allow_attributes.stderr b/src/tools/clippy/tests/ui/allow_attributes.stderr
index 681837e9e..d17fd86cb 100644
--- a/src/tools/clippy/tests/ui/allow_attributes.stderr
+++ b/src/tools/clippy/tests/ui/allow_attributes.stderr
@@ -1,5 +1,5 @@
error: #[allow] attribute found
- --> $DIR/allow_attributes.rs:11:3
+ --> $DIR/allow_attributes.rs:14:3
|
LL | #[allow(dead_code)]
| ^^^^^ help: replace it with: `expect`
@@ -7,7 +7,7 @@ LL | #[allow(dead_code)]
= note: `-D clippy::allow-attributes` implied by `-D warnings`
error: #[allow] attribute found
- --> $DIR/allow_attributes.rs:20:30
+ --> $DIR/allow_attributes.rs:23:30
|
LL | #[cfg_attr(panic = "unwind", allow(dead_code))]
| ^^^^^ help: replace it with: `expect`
diff --git a/src/tools/clippy/tests/ui/allow_attributes_false_positive.rs b/src/tools/clippy/tests/ui/allow_attributes_false_positive.rs
deleted file mode 100644
index 5c3407628..000000000
--- a/src/tools/clippy/tests/ui/allow_attributes_false_positive.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-#![warn(clippy::allow_attributes)]
-#![feature(lint_reasons)]
-#![crate_type = "proc-macro"]
-
-fn main() {}
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 1a0d4e886..d223d5642 100644
--- a/src/tools/clippy/tests/ui/allow_attributes_without_reason.rs
+++ b/src/tools/clippy/tests/ui/allow_attributes_without_reason.rs
@@ -1,9 +1,15 @@
+//@aux-build:proc_macros.rs:proc-macro
#![feature(lint_reasons)]
#![deny(clippy::allow_attributes_without_reason)]
+#![allow(unfulfilled_lint_expectations)]
+
+extern crate proc_macros;
+use proc_macros::{external, with_span};
// These should trigger the lint
#[allow(dead_code)]
#[allow(dead_code, deprecated)]
+#[expect(dead_code)]
// These should be fine
#[allow(dead_code, reason = "This should be allowed")]
#[warn(dyn_drop, reason = "Warnings can also have reasons")]
@@ -11,4 +17,28 @@
#[deny(deref_nullptr)]
#[forbid(deref_nullptr)]
-fn main() {}
+fn main() {
+ external! {
+ #[allow(dead_code)]
+ fn a() {}
+ }
+ with_span! {
+ span
+ #[allow(dead_code)]
+ fn b() {}
+ }
+}
+
+// Make sure this is not triggered on `?` desugaring
+
+pub fn trigger_fp_option() -> Option<()> {
+ Some(())?;
+ None?;
+ Some(())
+}
+
+pub fn trigger_fp_result() -> Result<(), &'static str> {
+ Ok(())?;
+ Err("asdf")?;
+ Ok(())
+}
diff --git a/src/tools/clippy/tests/ui/allow_attributes_without_reason.stderr b/src/tools/clippy/tests/ui/allow_attributes_without_reason.stderr
index 23f17e9a7..96f747d00 100644
--- a/src/tools/clippy/tests/ui/allow_attributes_without_reason.stderr
+++ b/src/tools/clippy/tests/ui/allow_attributes_without_reason.stderr
@@ -1,23 +1,39 @@
error: `allow` attribute without specifying a reason
- --> $DIR/allow_attributes_without_reason.rs:5:1
+ --> $DIR/allow_attributes_without_reason.rs:4:1
|
-LL | #[allow(dead_code)]
- | ^^^^^^^^^^^^^^^^^^^
+LL | #![allow(unfulfilled_lint_expectations)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try adding a reason at the end with `, reason = ".."`
note: the lint level is defined here
- --> $DIR/allow_attributes_without_reason.rs:2:9
+ --> $DIR/allow_attributes_without_reason.rs:3:9
|
LL | #![deny(clippy::allow_attributes_without_reason)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `allow` attribute without specifying a reason
- --> $DIR/allow_attributes_without_reason.rs:6:1
+ --> $DIR/allow_attributes_without_reason.rs:10:1
+ |
+LL | #[allow(dead_code)]
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = help: try adding a reason at the end with `, reason = ".."`
+
+error: `allow` attribute without specifying a reason
+ --> $DIR/allow_attributes_without_reason.rs:11:1
|
LL | #[allow(dead_code, deprecated)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try adding a reason at the end with `, reason = ".."`
-error: aborting due to 2 previous errors
+error: `expect` attribute without specifying a reason
+ --> $DIR/allow_attributes_without_reason.rs:12:1
+ |
+LL | #[expect(dead_code)]
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: try adding a reason at the end with `, reason = ".."`
+
+error: aborting due to 4 previous errors
diff --git a/src/tools/clippy/tests/ui/almost_complete_range.fixed b/src/tools/clippy/tests/ui/almost_complete_range.fixed
index 5cd0dcce6..50a13f16b 100644
--- a/src/tools/clippy/tests/ui/almost_complete_range.fixed
+++ b/src/tools/clippy/tests/ui/almost_complete_range.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
//@edition:2018
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![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 db0bfc8af..fd8223a23 100644
--- a/src/tools/clippy/tests/ui/almost_complete_range.rs
+++ b/src/tools/clippy/tests/ui/almost_complete_range.rs
@@ -1,6 +1,6 @@
//@run-rustfix
//@edition:2018
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![feature(exclusive_range_pattern)]
#![feature(stmt_expr_attributes)]
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
new file mode 100644
index 000000000..b6fcca0a7
--- /dev/null
+++ b/src/tools/clippy/tests/ui/arc_with_non_send_sync.rs
@@ -0,0 +1,24 @@
+#![warn(clippy::arc_with_non_send_sync)]
+#![allow(unused_variables)]
+use std::cell::RefCell;
+use std::sync::{Arc, Mutex};
+
+fn foo<T>(x: T) {
+ // Should not lint - purposefully ignoring generic args.
+ let a = Arc::new(x);
+}
+fn issue11076<T>() {
+ let a: Arc<Vec<T>> = Arc::new(Vec::new());
+}
+
+fn main() {
+ let _ = Arc::new(42);
+
+ // !Sync
+ let _ = Arc::new(RefCell::new(42));
+ let mutex = Mutex::new(1);
+ // !Send
+ let _ = Arc::new(mutex.lock().unwrap());
+ // !Send + !Sync
+ let _ = Arc::new(&42 as *const i32);
+}
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
new file mode 100644
index 000000000..7633b38df
--- /dev/null
+++ b/src/tools/clippy/tests/ui/arc_with_non_send_sync.stderr
@@ -0,0 +1,34 @@
+error: usage of an `Arc` that is not `Send` or `Sync`
+ --> $DIR/arc_with_non_send_sync.rs:18:13
+ |
+LL | let _ = Arc::new(RefCell::new(42));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the trait `Sync` is not implemented for `RefCell<i32>`
+ = note: required for `Arc<RefCell<i32>>` 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`
+
+error: usage of an `Arc` that is not `Send` or `Sync`
+ --> $DIR/arc_with_non_send_sync.rs:21:13
+ |
+LL | let _ = Arc::new(mutex.lock().unwrap());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the trait `Send` is not implemented for `MutexGuard<'_, i32>`
+ = note: required for `Arc<MutexGuard<'_, i32>>` to implement `Send` and `Sync`
+ = help: consider using an `Rc` instead or wrapping the inner type with a `Mutex`
+
+error: usage of an `Arc` that is not `Send` or `Sync`
+ --> $DIR/arc_with_non_send_sync.rs:23:13
+ |
+LL | let _ = Arc::new(&42 as *const i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the trait `Send` is not implemented for `*const i32`
+ = note: the trait `Sync` is not implemented for `*const i32`
+ = note: required for `Arc<*const i32>` to implement `Send` and `Sync`
+ = help: consider using an `Rc` instead or wrapping the inner type with a `Mutex`
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/arithmetic_side_effects.rs b/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
index f95af1017..4f38e50c8 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
+//@aux-build:proc_macro_derive.rs:proc-macro
#![allow(
clippy::assign_op_pattern,
@@ -466,4 +466,19 @@ pub fn issue_10767() {
&3.5_f32 + &1.3_f32;
}
+pub fn issue_10792() {
+ struct One {
+ a: u32,
+ }
+ struct Two {
+ b: u32,
+ c: u64,
+ }
+ const ONE: One = One { a: 1 };
+ const TWO: Two = Two { b: 2, c: 3 };
+ let _ = 10 / ONE.a;
+ let _ = 10 / TWO.b;
+ let _ = 10 / TWO.c;
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/as_conversions.rs b/src/tools/clippy/tests/ui/as_conversions.rs
index 890bf0b0a..427842a51 100644
--- a/src/tools/clippy/tests/ui/as_conversions.rs
+++ b/src/tools/clippy/tests/ui/as_conversions.rs
@@ -1,10 +1,11 @@
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::as_conversions)]
-#![allow(clippy::borrow_as_ptr)]
+#![allow(clippy::borrow_as_ptr, unused)]
extern crate proc_macros;
use proc_macros::external;
+use proc_macros::with_span;
fn main() {
let i = 0u32 as u64;
@@ -13,3 +14,11 @@ fn main() {
external!(0u32 as u64);
}
+
+with_span!(
+ span
+
+ fn coverting() {
+ let x = 0u32 as u64;
+ }
+);
diff --git a/src/tools/clippy/tests/ui/as_conversions.stderr b/src/tools/clippy/tests/ui/as_conversions.stderr
index 54037a649..ca41d1378 100644
--- a/src/tools/clippy/tests/ui/as_conversions.stderr
+++ b/src/tools/clippy/tests/ui/as_conversions.stderr
@@ -1,5 +1,5 @@
error: using a potentially dangerous silent `as` conversion
- --> $DIR/as_conversions.rs:10:13
+ --> $DIR/as_conversions.rs:11:13
|
LL | let i = 0u32 as u64;
| ^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | let i = 0u32 as u64;
= note: `-D clippy::as-conversions` implied by `-D warnings`
error: using a potentially dangerous silent `as` conversion
- --> $DIR/as_conversions.rs:12:13
+ --> $DIR/as_conversions.rs:13:13
|
LL | let j = &i as *const u64 as *mut u64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,7 +16,7 @@ LL | let j = &i as *const u64 as *mut u64;
= help: consider using a safe wrapper for this conversion
error: using a potentially dangerous silent `as` conversion
- --> $DIR/as_conversions.rs:12:13
+ --> $DIR/as_conversions.rs:13:13
|
LL | let j = &i as *const u64 as *mut u64;
| ^^^^^^^^^^^^^^^^
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 0d1d92584..7d71947e4 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,6 @@
#![allow(unused)]
#![warn(clippy::as_ptr_cast_mut)]
-#![allow(clippy::wrong_self_convention)]
+#![allow(clippy::wrong_self_convention, clippy::unnecessary_cast)]
struct MutPtrWrapper(Vec<u8>);
impl MutPtrWrapper {
diff --git a/src/tools/clippy/tests/ui/asm_syntax.rs b/src/tools/clippy/tests/ui/asm_syntax.rs
index c93995f93..af02e202b 100644
--- a/src/tools/clippy/tests/ui/asm_syntax.rs
+++ b/src/tools/clippy/tests/ui/asm_syntax.rs
@@ -1,5 +1,5 @@
-//@only-x86_64
-//@ignore-aarch64
+//@only-target-x86_64
+//@ignore-target-aarch64
#[warn(clippy::inline_asm_x86_intel_syntax)]
mod warn_intel {
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 ea8b89566..3152bd3ca 100644
--- a/src/tools/clippy/tests/ui/assertions_on_result_states.fixed
+++ b/src/tools/clippy/tests/ui/assertions_on_result_states.fixed
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::assertions_on_result_states)]
+#![allow(clippy::unnecessary_literal_unwrap)]
use std::result::Result;
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 6fc20f859..42755e935 100644
--- a/src/tools/clippy/tests/ui/assertions_on_result_states.rs
+++ b/src/tools/clippy/tests/ui/assertions_on_result_states.rs
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::assertions_on_result_states)]
+#![allow(clippy::unnecessary_literal_unwrap)]
use std::result::Result;
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 298d63c9c..be581030c 100644
--- a/src/tools/clippy/tests/ui/assertions_on_result_states.stderr
+++ b/src/tools/clippy/tests/ui/assertions_on_result_states.stderr
@@ -1,5 +1,5 @@
error: called `assert!` with `Result::is_ok`
- --> $DIR/assertions_on_result_states.rs:24:5
+ --> $DIR/assertions_on_result_states.rs:25:5
|
LL | assert!(r.is_ok());
| ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()`
@@ -7,37 +7,37 @@ LL | assert!(r.is_ok());
= note: `-D clippy::assertions-on-result-states` implied by `-D warnings`
error: called `assert!` with `Result::is_ok`
- --> $DIR/assertions_on_result_states.rs:42:5
+ --> $DIR/assertions_on_result_states.rs:43: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:45:5
+ --> $DIR/assertions_on_result_states.rs:46: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:58:5
+ --> $DIR/assertions_on_result_states.rs:59:5
|
LL | assert!(r.is_ok());
| ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()`
error: called `assert!` with `Result::is_ok`
- --> $DIR/assertions_on_result_states.rs:64:9
+ --> $DIR/assertions_on_result_states.rs:65:9
|
LL | assert!(r.is_ok());
| ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()`
error: called `assert!` with `Result::is_err`
- --> $DIR/assertions_on_result_states.rs:72:5
+ --> $DIR/assertions_on_result_states.rs:73:5
|
LL | assert!(r.is_err());
| ^^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap_err()`
error: called `assert!` with `Result::is_err`
- --> $DIR/assertions_on_result_states.rs:82:5
+ --> $DIR/assertions_on_result_states.rs:83:5
|
LL | assert!(res.is_err())
| ^^^^^^^^^^^^^^^^^^^^^ help: replace with: `res.unwrap_err();`
diff --git a/src/tools/clippy/tests/ui/assign_ops.fixed b/src/tools/clippy/tests/ui/assign_ops.fixed
index b50682ea0..ef45e97d1 100644
--- a/src/tools/clippy/tests/ui/assign_ops.fixed
+++ b/src/tools/clippy/tests/ui/assign_ops.fixed
@@ -2,7 +2,7 @@
use core::num::Wrapping;
-#[allow(dead_code, unused_assignments)]
+#[allow(dead_code, unused_assignments, clippy::useless_vec)]
#[warn(clippy::assign_op_pattern)]
fn main() {
let mut a = 5;
diff --git a/src/tools/clippy/tests/ui/assign_ops.rs b/src/tools/clippy/tests/ui/assign_ops.rs
index 780d2d040..ae87afc48 100644
--- a/src/tools/clippy/tests/ui/assign_ops.rs
+++ b/src/tools/clippy/tests/ui/assign_ops.rs
@@ -2,7 +2,7 @@
use core::num::Wrapping;
-#[allow(dead_code, unused_assignments)]
+#[allow(dead_code, unused_assignments, clippy::useless_vec)]
#[warn(clippy::assign_op_pattern)]
fn main() {
let mut a = 5;
diff --git a/src/tools/clippy/tests/ui/auxiliary/extern_fake_libc.rs b/src/tools/clippy/tests/ui/auxiliary/extern_fake_libc.rs
new file mode 100644
index 000000000..eb5a5d2b8
--- /dev/null
+++ b/src/tools/clippy/tests/ui/auxiliary/extern_fake_libc.rs
@@ -0,0 +1,10 @@
+#![allow(nonstandard_style)]
+#![allow(clippy::missing_safety_doc, unused)]
+
+type pid_t = i32;
+pub unsafe fn getpid() -> pid_t {
+ pid_t::from(0)
+}
+pub fn getpid_SAFE_TRUTH() -> pid_t {
+ unsafe { getpid() }
+}
diff --git a/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs b/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs
index e5bb90666..6b164967a 100644
--- a/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs
@@ -1,7 +1,6 @@
#![allow(dead_code)]
//! Used to test that certain lints don't trigger in imported external macros
-
#[macro_export]
macro_rules! try_err {
() => {
@@ -44,3 +43,10 @@ macro_rules! issue_10421 {
b = a;
};
}
+
+#[macro_export]
+macro_rules! macro_with_panic {
+ () => {
+ panic!()
+ };
+}
diff --git a/src/tools/clippy/tests/ui/auxiliary/macro_use_helper.rs b/src/tools/clippy/tests/ui/auxiliary/macro_use_helper.rs
index 7ed8a28db..cab216b51 100644
--- a/src/tools/clippy/tests/ui/auxiliary/macro_use_helper.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/macro_use_helper.rs
@@ -1,3 +1,5 @@
+//@aux-build:macro_rules.rs
+
extern crate macro_rules;
// STMT
diff --git a/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs b/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs
index d164dd0e5..fdfe5fc41 100644
--- a/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs
@@ -1,7 +1,3 @@
-//@compile-flags: --emit=link
-//@no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
#![feature(repr128, proc_macro_hygiene, proc_macro_quote, box_patterns)]
#![allow(incomplete_features)]
#![allow(clippy::useless_conversion, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/auxiliary/proc_macro_derive.rs b/src/tools/clippy/tests/ui/auxiliary/proc_macro_derive.rs
index 5a924ca18..37f0ec2b3 100644
--- a/src/tools/clippy/tests/ui/auxiliary/proc_macro_derive.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/proc_macro_derive.rs
@@ -1,7 +1,3 @@
-//@compile-flags: --emit=link
-//@no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
#![feature(repr128, proc_macro_quote)]
#![allow(incomplete_features)]
#![allow(clippy::field_reassign_with_default)]
@@ -90,70 +86,58 @@ pub fn extra_lifetime(_input: TokenStream) -> TokenStream {
#[allow(unused)]
#[proc_macro_derive(ArithmeticDerive)]
pub fn arithmetic_derive(_: TokenStream) -> TokenStream {
- <TokenStream as FromIterator<TokenTree>>::from_iter(
- [
- Ident::new("fn", Span::call_site()).into(),
- Ident::new("_foo", Span::call_site()).into(),
- Group::new(Delimiter::Parenthesis, TokenStream::new()).into(),
- Group::new(
- Delimiter::Brace,
- <TokenStream as FromIterator<TokenTree>>::from_iter(
- [
- Ident::new("let", Span::call_site()).into(),
- Ident::new("mut", Span::call_site()).into(),
- Ident::new("_n", Span::call_site()).into(),
- Punct::new('=', Spacing::Alone).into(),
- Literal::i32_unsuffixed(9).into(),
- Punct::new(';', Spacing::Alone).into(),
- Ident::new("_n", Span::call_site()).into(),
- Punct::new('=', Spacing::Alone).into(),
- Literal::i32_unsuffixed(9).into(),
- Punct::new('/', Spacing::Alone).into(),
- Literal::i32_unsuffixed(2).into(),
- Punct::new(';', Spacing::Alone).into(),
- Ident::new("_n", Span::call_site()).into(),
- Punct::new('=', Spacing::Alone).into(),
- Punct::new('-', Spacing::Alone).into(),
- Ident::new("_n", Span::call_site()).into(),
- Punct::new(';', Spacing::Alone).into(),
- ]
- .into_iter(),
- ),
- )
- .into(),
- ]
- .into_iter(),
- )
+ <TokenStream as FromIterator<TokenTree>>::from_iter([
+ Ident::new("fn", Span::call_site()).into(),
+ Ident::new("_foo", Span::call_site()).into(),
+ Group::new(Delimiter::Parenthesis, TokenStream::new()).into(),
+ Group::new(
+ Delimiter::Brace,
+ <TokenStream as FromIterator<TokenTree>>::from_iter([
+ Ident::new("let", Span::call_site()).into(),
+ Ident::new("mut", Span::call_site()).into(),
+ Ident::new("_n", Span::call_site()).into(),
+ Punct::new('=', Spacing::Alone).into(),
+ Literal::i32_unsuffixed(9).into(),
+ Punct::new(';', Spacing::Alone).into(),
+ Ident::new("_n", Span::call_site()).into(),
+ Punct::new('=', Spacing::Alone).into(),
+ Literal::i32_unsuffixed(9).into(),
+ Punct::new('/', Spacing::Alone).into(),
+ Literal::i32_unsuffixed(2).into(),
+ Punct::new(';', Spacing::Alone).into(),
+ Ident::new("_n", Span::call_site()).into(),
+ Punct::new('=', Spacing::Alone).into(),
+ Punct::new('-', Spacing::Alone).into(),
+ Ident::new("_n", Span::call_site()).into(),
+ Punct::new(';', Spacing::Alone).into(),
+ ]),
+ )
+ .into(),
+ ])
}
#[allow(unused)]
#[proc_macro_derive(ShadowDerive)]
pub fn shadow_derive(_: TokenStream) -> TokenStream {
- <TokenStream as FromIterator<TokenTree>>::from_iter(
- [
- Ident::new("fn", Span::call_site()).into(),
- Ident::new("_foo", Span::call_site()).into(),
- Group::new(Delimiter::Parenthesis, TokenStream::new()).into(),
- Group::new(
- Delimiter::Brace,
- <TokenStream as FromIterator<TokenTree>>::from_iter(
- [
- Ident::new("let", Span::call_site()).into(),
- Ident::new("_x", Span::call_site()).into(),
- Punct::new('=', Spacing::Alone).into(),
- Literal::i32_unsuffixed(2).into(),
- Punct::new(';', Spacing::Alone).into(),
- Ident::new("let", Span::call_site()).into(),
- Ident::new("_x", Span::call_site()).into(),
- Punct::new('=', Spacing::Alone).into(),
- Ident::new("_x", Span::call_site()).into(),
- Punct::new(';', Spacing::Alone).into(),
- ]
- .into_iter(),
- ),
- )
- .into(),
- ]
- .into_iter(),
- )
+ <TokenStream as FromIterator<TokenTree>>::from_iter([
+ Ident::new("fn", Span::call_site()).into(),
+ Ident::new("_foo", Span::call_site()).into(),
+ Group::new(Delimiter::Parenthesis, TokenStream::new()).into(),
+ Group::new(
+ Delimiter::Brace,
+ <TokenStream as FromIterator<TokenTree>>::from_iter([
+ Ident::new("let", Span::call_site()).into(),
+ Ident::new("_x", Span::call_site()).into(),
+ Punct::new('=', Spacing::Alone).into(),
+ Literal::i32_unsuffixed(2).into(),
+ Punct::new(';', Spacing::Alone).into(),
+ Ident::new("let", Span::call_site()).into(),
+ Ident::new("_x", Span::call_site()).into(),
+ Punct::new('=', Spacing::Alone).into(),
+ Ident::new("_x", Span::call_site()).into(),
+ Punct::new(';', Spacing::Alone).into(),
+ ]),
+ )
+ .into(),
+ ])
}
diff --git a/src/tools/clippy/tests/ui/auxiliary/proc_macro_suspicious_else_formatting.rs b/src/tools/clippy/tests/ui/auxiliary/proc_macro_suspicious_else_formatting.rs
index f13b76e44..79e8eff3a 100644
--- a/src/tools/clippy/tests/ui/auxiliary/proc_macro_suspicious_else_formatting.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/proc_macro_suspicious_else_formatting.rs
@@ -1,8 +1,3 @@
-//@compile-flags: --emit=link
-//@no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
extern crate proc_macro;
use proc_macro::{token_stream, Delimiter, Group, Ident, Span, TokenStream, TokenTree};
diff --git a/src/tools/clippy/tests/ui/auxiliary/proc_macro_unsafe.rs b/src/tools/clippy/tests/ui/auxiliary/proc_macro_unsafe.rs
index c2326678d..1c591fc76 100644
--- a/src/tools/clippy/tests/ui/auxiliary/proc_macro_unsafe.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/proc_macro_unsafe.rs
@@ -1,8 +1,3 @@
-//@compile-flags: --emit=link
-//@no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
extern crate proc_macro;
use proc_macro::{Delimiter, Group, Ident, TokenStream, TokenTree};
diff --git a/src/tools/clippy/tests/ui/auxiliary/proc_macros.rs b/src/tools/clippy/tests/ui/auxiliary/proc_macros.rs
index 94f075ed0..4d008c8cb 100644
--- a/src/tools/clippy/tests/ui/auxiliary/proc_macros.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/proc_macros.rs
@@ -1,10 +1,6 @@
-//@compile-flags: --emit=link
-//@no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
#![feature(let_chains)]
#![feature(proc_macro_span)]
-#![allow(dead_code)]
+#![allow(clippy::needless_if, dead_code)]
extern crate proc_macro;
diff --git a/src/tools/clippy/tests/ui/auxiliary/wildcard_imports_helper.rs b/src/tools/clippy/tests/ui/auxiliary/wildcard_imports_helper.rs
index d75cdd625..44f49c080 100644
--- a/src/tools/clippy/tests/ui/auxiliary/wildcard_imports_helper.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/wildcard_imports_helper.rs
@@ -25,3 +25,9 @@ pub mod prelude {
pub struct PreludeModAnywhere;
}
}
+
+pub mod extern_prelude {
+ pub mod v1 {
+ pub struct ExternPreludeModAnywhere;
+ }
+}
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 a9f18782e..2a3867ac8 100644
--- a/src/tools/clippy/tests/ui/blocks_in_if_conditions.fixed
+++ b/src/tools/clippy/tests/ui/blocks_in_if_conditions.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
#![warn(clippy::blocks_in_if_conditions)]
-#![allow(unused, clippy::let_and_return)]
+#![allow(unused, clippy::let_and_return, clippy::needless_if)]
#![warn(clippy::nonminimal_bool)]
macro_rules! blocky {
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 0a70317c4..704d09fba 100644
--- a/src/tools/clippy/tests/ui/blocks_in_if_conditions.rs
+++ b/src/tools/clippy/tests/ui/blocks_in_if_conditions.rs
@@ -1,6 +1,6 @@
//@run-rustfix
#![warn(clippy::blocks_in_if_conditions)]
-#![allow(unused, clippy::let_and_return)]
+#![allow(unused, clippy::let_and_return, clippy::needless_if)]
#![warn(clippy::nonminimal_bool)]
macro_rules! blocky {
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 169589f6d..d6d085d7f 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
@@ -1,5 +1,10 @@
#![warn(clippy::blocks_in_if_conditions)]
-#![allow(unused, clippy::let_and_return)]
+#![allow(
+ unused,
+ clippy::let_and_return,
+ clippy::needless_if,
+ clippy::unnecessary_literal_unwrap
+)]
fn predicate<F: FnOnce(T) -> bool, T>(pfn: F, val: T) -> bool {
pfn(val)
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 941d604dd..5ac02e750 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
@@ -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_closure.rs:18:17
+ --> $DIR/blocks_in_if_conditions_closure.rs:23:17
|
LL | |x| {
| _________________^
@@ -11,7 +11,7 @@ LL | | },
= note: `-D clippy::blocks-in-if-conditions` implied by `-D warnings`
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:27:13
+ --> $DIR/blocks_in_if_conditions_closure.rs:32:13
|
LL | |x| {
| _____________^
diff --git a/src/tools/clippy/tests/ui/bool_comparison.fixed b/src/tools/clippy/tests/ui/bool_comparison.fixed
index 670eef6a2..d6774c035 100644
--- a/src/tools/clippy/tests/ui/bool_comparison.fixed
+++ b/src/tools/clippy/tests/ui/bool_comparison.fixed
@@ -1,5 +1,6 @@
//@run-rustfix
+#![allow(clippy::needless_if)]
#![warn(clippy::bool_comparison)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/bool_comparison.rs b/src/tools/clippy/tests/ui/bool_comparison.rs
index 72851be63..c0483fd73 100644
--- a/src/tools/clippy/tests/ui/bool_comparison.rs
+++ b/src/tools/clippy/tests/ui/bool_comparison.rs
@@ -1,5 +1,6 @@
//@run-rustfix
+#![allow(clippy::needless_if)]
#![warn(clippy::bool_comparison)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/bool_comparison.stderr b/src/tools/clippy/tests/ui/bool_comparison.stderr
index 31522d4a5..f4dded365 100644
--- a/src/tools/clippy/tests/ui/bool_comparison.stderr
+++ b/src/tools/clippy/tests/ui/bool_comparison.stderr
@@ -1,5 +1,5 @@
error: equality checks against true are unnecessary
- --> $DIR/bool_comparison.rs:7:8
+ --> $DIR/bool_comparison.rs:8:8
|
LL | if x == true {
| ^^^^^^^^^ help: try simplifying it as shown: `x`
@@ -7,127 +7,127 @@ LL | if x == true {
= note: `-D clippy::bool-comparison` implied by `-D warnings`
error: equality checks against false can be replaced by a negation
- --> $DIR/bool_comparison.rs:12:8
+ --> $DIR/bool_comparison.rs:13:8
|
LL | if x == false {
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
error: equality checks against true are unnecessary
- --> $DIR/bool_comparison.rs:17:8
+ --> $DIR/bool_comparison.rs:18:8
|
LL | if true == x {
| ^^^^^^^^^ help: try simplifying it as shown: `x`
error: equality checks against false can be replaced by a negation
- --> $DIR/bool_comparison.rs:22:8
+ --> $DIR/bool_comparison.rs:23:8
|
LL | if false == x {
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
error: inequality checks against true can be replaced by a negation
- --> $DIR/bool_comparison.rs:27:8
+ --> $DIR/bool_comparison.rs:28:8
|
LL | if x != true {
| ^^^^^^^^^ help: try simplifying it as shown: `!x`
error: inequality checks against false are unnecessary
- --> $DIR/bool_comparison.rs:32:8
+ --> $DIR/bool_comparison.rs:33:8
|
LL | if x != false {
| ^^^^^^^^^^ help: try simplifying it as shown: `x`
error: inequality checks against true can be replaced by a negation
- --> $DIR/bool_comparison.rs:37:8
+ --> $DIR/bool_comparison.rs:38:8
|
LL | if true != x {
| ^^^^^^^^^ help: try simplifying it as shown: `!x`
error: inequality checks against false are unnecessary
- --> $DIR/bool_comparison.rs:42:8
+ --> $DIR/bool_comparison.rs:43:8
|
LL | if false != x {
| ^^^^^^^^^^ help: try simplifying it as shown: `x`
error: less than comparison against true can be replaced by a negation
- --> $DIR/bool_comparison.rs:47:8
+ --> $DIR/bool_comparison.rs:48:8
|
LL | if x < true {
| ^^^^^^^^ help: try simplifying it as shown: `!x`
error: greater than checks against false are unnecessary
- --> $DIR/bool_comparison.rs:52:8
+ --> $DIR/bool_comparison.rs:53:8
|
LL | if false < x {
| ^^^^^^^^^ help: try simplifying it as shown: `x`
error: greater than checks against false are unnecessary
- --> $DIR/bool_comparison.rs:57:8
+ --> $DIR/bool_comparison.rs:58:8
|
LL | if x > false {
| ^^^^^^^^^ help: try simplifying it as shown: `x`
error: less than comparison against true can be replaced by a negation
- --> $DIR/bool_comparison.rs:62:8
+ --> $DIR/bool_comparison.rs:63:8
|
LL | if true > x {
| ^^^^^^^^ help: try simplifying it as shown: `!x`
error: order comparisons between booleans can be simplified
- --> $DIR/bool_comparison.rs:68:8
+ --> $DIR/bool_comparison.rs:69:8
|
LL | if x < y {
| ^^^^^ help: try simplifying it as shown: `!x & y`
error: order comparisons between booleans can be simplified
- --> $DIR/bool_comparison.rs:73:8
+ --> $DIR/bool_comparison.rs:74:8
|
LL | if x > y {
| ^^^^^ help: try simplifying it as shown: `x & !y`
error: this comparison might be written more concisely
- --> $DIR/bool_comparison.rs:121:8
+ --> $DIR/bool_comparison.rs: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:122:8
+ --> $DIR/bool_comparison.rs:123:8
|
LL | if !a == b {};
| ^^^^^^^ help: try simplifying it as shown: `a != b`
error: this comparison might be written more concisely
- --> $DIR/bool_comparison.rs:126:8
+ --> $DIR/bool_comparison.rs:127:8
|
LL | if b == !a {};
| ^^^^^^^ help: try simplifying it as shown: `b != a`
error: this comparison might be written more concisely
- --> $DIR/bool_comparison.rs:127:8
+ --> $DIR/bool_comparison.rs:128:8
|
LL | if !b == a {};
| ^^^^^^^ help: try simplifying it as shown: `b != a`
error: equality checks against false can be replaced by a negation
- --> $DIR/bool_comparison.rs:151:8
+ --> $DIR/bool_comparison.rs:152:8
|
LL | if false == m!(func) {}
| ^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `!m!(func)`
error: equality checks against false can be replaced by a negation
- --> $DIR/bool_comparison.rs:152:8
+ --> $DIR/bool_comparison.rs:153:8
|
LL | if m!(func) == false {}
| ^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `!m!(func)`
error: equality checks against true are unnecessary
- --> $DIR/bool_comparison.rs:153:8
+ --> $DIR/bool_comparison.rs:154:8
|
LL | if true == m!(func) {}
| ^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `m!(func)`
error: equality checks against true are unnecessary
- --> $DIR/bool_comparison.rs:154:8
+ --> $DIR/bool_comparison.rs:155:8
|
LL | if m!(func) == true {}
| ^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `m!(func)`
diff --git a/src/tools/clippy/tests/ui/borrow_as_ptr.fixed b/src/tools/clippy/tests/ui/borrow_as_ptr.fixed
index 3f440ce00..996cc3650 100644
--- a/src/tools/clippy/tests/ui/borrow_as_ptr.fixed
+++ b/src/tools/clippy/tests/ui/borrow_as_ptr.fixed
@@ -1,9 +1,18 @@
//@run-rustfix
#![warn(clippy::borrow_as_ptr)]
+#![allow(clippy::useless_vec)]
+
+fn a() -> i32 {
+ 0
+}
fn main() {
let val = 1;
let _p = std::ptr::addr_of!(val);
+ let _p = &0 as *const i32;
+ let _p = &a() as *const i32;
+ let vec = vec![1];
+ let _p = &vec.len() as *const usize;
let mut val_mut = 1;
let _p_mut = std::ptr::addr_of_mut!(val_mut);
diff --git a/src/tools/clippy/tests/ui/borrow_as_ptr.rs b/src/tools/clippy/tests/ui/borrow_as_ptr.rs
index c1ca9180e..5eafaeb2f 100644
--- a/src/tools/clippy/tests/ui/borrow_as_ptr.rs
+++ b/src/tools/clippy/tests/ui/borrow_as_ptr.rs
@@ -1,9 +1,18 @@
//@run-rustfix
#![warn(clippy::borrow_as_ptr)]
+#![allow(clippy::useless_vec)]
+
+fn a() -> i32 {
+ 0
+}
fn main() {
let val = 1;
let _p = &val as *const i32;
+ let _p = &0 as *const i32;
+ let _p = &a() as *const i32;
+ let vec = vec![1];
+ let _p = &vec.len() as *const usize;
let mut val_mut = 1;
let _p_mut = &mut val_mut as *mut i32;
diff --git a/src/tools/clippy/tests/ui/borrow_as_ptr.stderr b/src/tools/clippy/tests/ui/borrow_as_ptr.stderr
index be1ed7330..c9990bb6f 100644
--- a/src/tools/clippy/tests/ui/borrow_as_ptr.stderr
+++ b/src/tools/clippy/tests/ui/borrow_as_ptr.stderr
@@ -1,5 +1,5 @@
error: borrow as raw pointer
- --> $DIR/borrow_as_ptr.rs:6:14
+ --> $DIR/borrow_as_ptr.rs:11:14
|
LL | let _p = &val as *const i32;
| ^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::addr_of!(val)`
@@ -7,7 +7,7 @@ LL | let _p = &val as *const i32;
= note: `-D clippy::borrow-as-ptr` implied by `-D warnings`
error: borrow as raw pointer
- --> $DIR/borrow_as_ptr.rs:9:18
+ --> $DIR/borrow_as_ptr.rs:18: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_deref_ref.fixed b/src/tools/clippy/tests/ui/borrow_deref_ref.fixed
index 755264617..b951ba04c 100644
--- a/src/tools/clippy/tests/ui/borrow_deref_ref.fixed
+++ b/src/tools/clippy/tests/ui/borrow_deref_ref.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build: proc_macros.rs
+//@aux-build: proc_macros.rs:proc-macro
#![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 e319d365f..52980e55f 100644
--- a/src/tools/clippy/tests/ui/borrow_deref_ref.rs
+++ b/src/tools/clippy/tests/ui/borrow_deref_ref.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build: proc_macros.rs
+//@aux-build: proc_macros.rs:proc-macro
#![allow(dead_code, unused_variables)]
diff --git a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.rs b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.rs
index 29b08ab36..da940a4cf 100644
--- a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.rs
+++ b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.rs
@@ -1,6 +1,6 @@
//@aux-build:helper.rs
-#![warn(clippy::borrow_interior_mutable_const)]
+#![deny(clippy::borrow_interior_mutable_const)]
#![allow(clippy::declare_interior_mutable_const)]
// this file (mostly) replicates its `declare` counterpart. Please see it for more discussions.
@@ -19,7 +19,7 @@ const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(true));
const FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen;
fn borrow_optional_cell() {
- let _ = &UNFROZEN_VARIANT; //~ ERROR interior mutability
+ let _ = &UNFROZEN_VARIANT; //~ ERROR: interior mutability
let _ = &FROZEN_VARIANT;
}
@@ -34,11 +34,11 @@ trait AssocConsts {
// This is the "suboptimal behavior" mentioned in `is_value_unfrozen`
// caused by a similar reason to unfrozen types without any default values
// get linted even if it has frozen variants'.
- let _ = &Self::TO_BE_FROZEN_VARIANT; //~ ERROR interior mutable
+ let _ = &Self::TO_BE_FROZEN_VARIANT; //~ ERROR: interior mutability
// The lint ignores default values because an impl of this trait can set
// an unfrozen variant to `DEFAULTED_ON_FROZEN_VARIANT` and use the default impl for `function`.
- let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT; //~ ERROR interior mutable
+ let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT; //~ ERROR: interior mutability
}
}
@@ -47,9 +47,9 @@ impl AssocConsts for u64 {
const TO_BE_FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen;
fn function() {
- let _ = &<Self as AssocConsts>::TO_BE_UNFROZEN_VARIANT; //~ ERROR interior mutable
+ let _ = &<Self as AssocConsts>::TO_BE_UNFROZEN_VARIANT; //~ ERROR: interior mutability
let _ = &<Self as AssocConsts>::TO_BE_FROZEN_VARIANT;
- let _ = &Self::DEFAULTED_ON_UNFROZEN_VARIANT; //~ ERROR interior mutable
+ let _ = &Self::DEFAULTED_ON_UNFROZEN_VARIANT; //~ ERROR: interior mutability
let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT;
}
}
@@ -67,11 +67,11 @@ trait AssocTypes {
impl AssocTypes for u64 {
type ToBeUnfrozen = AtomicUsize;
- const TO_BE_UNFROZEN_VARIANT: Option<Self::ToBeUnfrozen> = Some(Self::ToBeUnfrozen::new(4)); //~ ERROR interior mutable
+ const TO_BE_UNFROZEN_VARIANT: Option<Self::ToBeUnfrozen> = Some(Self::ToBeUnfrozen::new(4));
const TO_BE_FROZEN_VARIANT: Option<Self::ToBeUnfrozen> = None;
fn function() {
- let _ = &<Self as AssocTypes>::TO_BE_UNFROZEN_VARIANT; //~ ERROR interior mutable
+ let _ = &<Self as AssocTypes>::TO_BE_UNFROZEN_VARIANT; //~ ERROR: interior mutability
let _ = &<Self as AssocTypes>::TO_BE_FROZEN_VARIANT;
}
}
@@ -83,19 +83,19 @@ enum BothOfCellAndGeneric<T> {
}
impl<T> BothOfCellAndGeneric<T> {
- const UNFROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mutable
- const GENERIC_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mutable
+ const UNFROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null()));
+ const GENERIC_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Generic(std::ptr::null());
const FROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Frozen(5);
fn function() {
- let _ = &Self::UNFROZEN_VARIANT; //~ ERROR interior mutability
- let _ = &Self::GENERIC_VARIANT; //~ ERROR interior mutability
+ let _ = &Self::UNFROZEN_VARIANT; //~ ERROR: interior mutability
+ let _ = &Self::GENERIC_VARIANT; //~ ERROR: interior mutability
let _ = &Self::FROZEN_VARIANT;
}
}
fn main() {
// constants defined in foreign crates
- let _ = &helper::WRAPPED_PRIVATE_UNFROZEN_VARIANT; //~ ERROR interior mutability
+ let _ = &helper::WRAPPED_PRIVATE_UNFROZEN_VARIANT; //~ ERROR: interior mutability
let _ = &helper::WRAPPED_PRIVATE_FROZEN_VARIANT;
}
diff --git a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.stderr b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.stderr
index b0cab977a..b753ec926 100644
--- a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.stderr
+++ b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.stderr
@@ -1,16 +1,20 @@
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:22:14
|
-LL | let _ = &UNFROZEN_VARIANT; //~ ERROR interior mutability
+LL | let _ = &UNFROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
- = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
+note: the lint level is defined here
+ --> $DIR/enums.rs:3:9
+ |
+LL | #![deny(clippy::borrow_interior_mutable_const)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:37:18
|
-LL | let _ = &Self::TO_BE_FROZEN_VARIANT; //~ ERROR interior mutable
+LL | let _ = &Self::TO_BE_FROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -18,7 +22,7 @@ LL | let _ = &Self::TO_BE_FROZEN_VARIANT; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:41:18
|
-LL | let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT; //~ ERROR interior mutable
+LL | let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -26,7 +30,7 @@ LL | let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT; //~ ERROR interior muta
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:50:18
|
-LL | let _ = &<Self as AssocConsts>::TO_BE_UNFROZEN_VARIANT; //~ ERROR interior mutable
+LL | let _ = &<Self as AssocConsts>::TO_BE_UNFROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -34,7 +38,7 @@ LL | let _ = &<Self as AssocConsts>::TO_BE_UNFROZEN_VARIANT; //~ ERROR i
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:52:18
|
-LL | let _ = &Self::DEFAULTED_ON_UNFROZEN_VARIANT; //~ ERROR interior mutable
+LL | let _ = &Self::DEFAULTED_ON_UNFROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -42,7 +46,7 @@ LL | let _ = &Self::DEFAULTED_ON_UNFROZEN_VARIANT; //~ ERROR interior mu
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:74:18
|
-LL | let _ = &<Self as AssocTypes>::TO_BE_UNFROZEN_VARIANT; //~ ERROR interior mutable
+LL | let _ = &<Self as AssocTypes>::TO_BE_UNFROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -50,7 +54,7 @@ LL | let _ = &<Self as AssocTypes>::TO_BE_UNFROZEN_VARIANT; //~ ERROR in
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:91:18
|
-LL | let _ = &Self::UNFROZEN_VARIANT; //~ ERROR interior mutability
+LL | let _ = &Self::UNFROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -58,7 +62,7 @@ LL | let _ = &Self::UNFROZEN_VARIANT; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:92:18
|
-LL | let _ = &Self::GENERIC_VARIANT; //~ ERROR interior mutability
+LL | let _ = &Self::GENERIC_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -66,7 +70,7 @@ LL | let _ = &Self::GENERIC_VARIANT; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:99:14
|
-LL | let _ = &helper::WRAPPED_PRIVATE_UNFROZEN_VARIANT; //~ ERROR interior mutability
+LL | let _ = &helper::WRAPPED_PRIVATE_UNFROZEN_VARIANT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
diff --git a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.rs b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.rs
index 7c5786424..0ea93dd84 100644
--- a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.rs
+++ b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.rs
@@ -1,4 +1,4 @@
-#![warn(clippy::borrow_interior_mutable_const)]
+#![deny(clippy::borrow_interior_mutable_const)]
#![allow(clippy::declare_interior_mutable_const, clippy::needless_borrow)]
#![allow(const_item_mutation)]
@@ -51,14 +51,14 @@ impl<T> std::ops::Deref for StaticRef<T> {
const CELL_REF: StaticRef<(UnsafeCell<u32>,)> = unsafe { StaticRef::new(std::ptr::null()) };
fn main() {
- ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
- assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutability
+ ATOMIC.store(1, Ordering::SeqCst); //~ ERROR: interior mutability
+ assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR: interior mutability
let _once = ONCE_INIT;
- let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
- let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
- let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
- let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
+ let _once_ref = &ONCE_INIT; //~ ERROR: interior mutability
+ let _once_ref_2 = &&ONCE_INIT; //~ ERROR: interior mutability
+ let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR: interior mutability
+ let _once_mut = &mut ONCE_INIT; //~ ERROR: interior mutability
let _atomic_into_inner = ATOMIC.into_inner();
// these should be all fine.
let _twice = (ONCE_INIT, ONCE_INIT);
@@ -69,23 +69,23 @@ fn main() {
let _ref_array_once = &[ONCE_INIT, ONCE_INIT][0];
// referencing projection is still bad.
- let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
- let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
- let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
- let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
- let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability
+ let _ = &ATOMIC_TUPLE; //~ ERROR: interior mutability
+ let _ = &ATOMIC_TUPLE.0; //~ ERROR: interior mutability
+ let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR: interior mutability
+ let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR: interior mutability
+ let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR: interior mutability
let _ = &*ATOMIC_TUPLE.1;
let _ = &ATOMIC_TUPLE.2;
let _ = (&&&&ATOMIC_TUPLE).0;
let _ = (&&&&ATOMIC_TUPLE).2;
let _ = ATOMIC_TUPLE.0;
- let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
+ let _ = ATOMIC_TUPLE.0[0]; //~ ERROR: interior mutability
let _ = ATOMIC_TUPLE.1.into_iter();
let _ = ATOMIC_TUPLE.2;
let _ = &{ ATOMIC_TUPLE };
- CELL.set(2); //~ ERROR interior mutability
- assert_eq!(CELL.get(), 6); //~ ERROR interior mutability
+ CELL.set(2); //~ ERROR: interior mutability
+ assert_eq!(CELL.get(), 6); //~ ERROR: interior mutability
assert_eq!(INTEGER, 8);
assert!(STRING.is_empty());
diff --git a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.stderr b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.stderr
index c87ad206c..200e04b8f 100644
--- a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.stderr
+++ b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.stderr
@@ -1,16 +1,20 @@
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:54:5
|
-LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
+LL | ATOMIC.store(1, Ordering::SeqCst);
| ^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
- = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
+note: the lint level is defined here
+ --> $DIR/others.rs:1:9
+ |
+LL | #![deny(clippy::borrow_interior_mutable_const)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:55:16
|
-LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutability
+LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5);
| ^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -18,7 +22,7 @@ LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutabi
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:58:22
|
-LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
+LL | let _once_ref = &ONCE_INIT;
| ^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -26,7 +30,7 @@ LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:59:25
|
-LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
+LL | let _once_ref_2 = &&ONCE_INIT;
| ^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -34,7 +38,7 @@ LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:60:27
|
-LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
+LL | let _once_ref_4 = &&&&ONCE_INIT;
| ^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -42,7 +46,7 @@ LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:61:26
|
-LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
+LL | let _once_mut = &mut ONCE_INIT;
| ^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -50,7 +54,7 @@ LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:72:14
|
-LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
+LL | let _ = &ATOMIC_TUPLE;
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -58,7 +62,7 @@ LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:73:14
|
-LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
+LL | let _ = &ATOMIC_TUPLE.0;
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -66,7 +70,7 @@ LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:74:19
|
-LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
+LL | let _ = &(&&&&ATOMIC_TUPLE).0;
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -74,7 +78,7 @@ LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:75:14
|
-LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
+LL | let _ = &ATOMIC_TUPLE.0[0];
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -82,7 +86,7 @@ LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:76:13
|
-LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability
+LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst);
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -90,7 +94,7 @@ LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mu
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:82:13
|
-LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
+LL | let _ = ATOMIC_TUPLE.0[0];
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -98,7 +102,7 @@ LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:87:5
|
-LL | CELL.set(2); //~ ERROR interior mutability
+LL | CELL.set(2);
| ^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -106,7 +110,7 @@ LL | CELL.set(2); //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:88:16
|
-LL | assert_eq!(CELL.get(), 6); //~ ERROR interior mutability
+LL | assert_eq!(CELL.get(), 6);
| ^^^^
|
= help: assign this const to a local or static variable, and use the variable here
diff --git a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.rs b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.rs
index 06b5d62e8..4da3833cb 100644
--- a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.rs
+++ b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.rs
@@ -1,4 +1,4 @@
-#![warn(clippy::borrow_interior_mutable_const)]
+#![deny(clippy::borrow_interior_mutable_const)]
#![allow(clippy::declare_interior_mutable_const)]
// this file replicates its `declare` counterpart. Please see it for more discussions.
@@ -12,7 +12,7 @@ trait ConcreteTypes {
const STRING: String;
fn function() {
- let _ = &Self::ATOMIC; //~ ERROR interior mutable
+ let _ = &Self::ATOMIC; //~ ERROR: interior mutability
let _ = &Self::STRING;
}
}
@@ -23,7 +23,7 @@ impl ConcreteTypes for u64 {
fn function() {
// Lint this again since implementers can choose not to borrow it.
- let _ = &Self::ATOMIC; //~ ERROR interior mutable
+ let _ = &Self::ATOMIC; //~ ERROR: interior mutability
let _ = &Self::STRING;
}
}
@@ -48,7 +48,7 @@ impl<T: ConstDefault> GenericTypes<T, AtomicUsize> for Vec<T> {
fn function() {
let _ = &Self::TO_REMAIN_GENERIC;
- let _ = &Self::TO_BE_CONCRETE; //~ ERROR interior mutable
+ let _ = &Self::TO_BE_CONCRETE; //~ ERROR: interior mutability
}
}
@@ -83,8 +83,8 @@ impl<T: ConstDefault> AssocTypes for Vec<T> {
fn function() {
let _ = &Self::TO_BE_FROZEN;
- let _ = &Self::TO_BE_UNFROZEN; //~ ERROR interior mutable
- let _ = &Self::WRAPPED_TO_BE_UNFROZEN; //~ ERROR interior mutable
+ let _ = &Self::TO_BE_UNFROZEN; //~ ERROR: interior mutability
+ let _ = &Self::WRAPPED_TO_BE_UNFROZEN; //~ ERROR: interior mutability
let _ = &Self::WRAPPED_TO_BE_GENERIC_PARAM;
}
}
@@ -106,7 +106,7 @@ where
fn function() {
let _ = &Self::NOT_BOUNDED;
- let _ = &Self::BOUNDED; //~ ERROR interior mutable
+ let _ = &Self::BOUNDED; //~ ERROR: interior mutability
}
}
@@ -119,7 +119,7 @@ where
fn function() {
let _ = &Self::NOT_BOUNDED;
- let _ = &Self::BOUNDED; //~ ERROR interior mutable
+ let _ = &Self::BOUNDED; //~ ERROR: interior mutability
}
}
@@ -148,8 +148,8 @@ impl SelfType for AtomicUsize {
const WRAPPED_SELF: Option<Self> = Some(AtomicUsize::new(21));
fn function() {
- let _ = &Self::SELF; //~ ERROR interior mutable
- let _ = &Self::WRAPPED_SELF; //~ ERROR interior mutable
+ let _ = &Self::SELF; //~ ERROR: interior mutability
+ let _ = &Self::WRAPPED_SELF; //~ ERROR: interior mutability
}
}
@@ -159,7 +159,7 @@ trait BothOfCellAndGeneric<T> {
fn function() {
let _ = &Self::DIRECT;
- let _ = &Self::INDIRECT; //~ ERROR interior mutable
+ let _ = &Self::INDIRECT; //~ ERROR: interior mutability
}
}
@@ -169,7 +169,7 @@ impl<T: ConstDefault> BothOfCellAndGeneric<T> for Vec<T> {
fn function() {
let _ = &Self::DIRECT;
- let _ = &Self::INDIRECT; //~ ERROR interior mutable
+ let _ = &Self::INDIRECT; //~ ERROR: interior mutability
}
}
@@ -188,15 +188,15 @@ where
const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19);
fn function() {
- let _ = &Self::ATOMIC; //~ ERROR interior mutable
+ let _ = &Self::ATOMIC; //~ ERROR: interior mutability
let _ = &Self::COW;
let _ = &Self::GENERIC_TYPE;
let _ = &Self::ASSOC_TYPE;
- let _ = &Self::BOUNDED_ASSOC_TYPE; //~ ERROR interior mutable
+ let _ = &Self::BOUNDED_ASSOC_TYPE; //~ ERROR: interior mutability
}
}
fn main() {
- u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability
- assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR interior mutability
+ u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR: interior mutability
+ assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR: interior mutability
}
diff --git a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.stderr b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.stderr
index f34ae8814..add223acd 100644
--- a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.stderr
+++ b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.stderr
@@ -1,16 +1,20 @@
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:15:18
|
-LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
+LL | let _ = &Self::ATOMIC;
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
- = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
+note: the lint level is defined here
+ --> $DIR/traits.rs:1:9
+ |
+LL | #![deny(clippy::borrow_interior_mutable_const)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:26:18
|
-LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
+LL | let _ = &Self::ATOMIC;
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -18,7 +22,7 @@ LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:51:18
|
-LL | let _ = &Self::TO_BE_CONCRETE; //~ ERROR interior mutable
+LL | let _ = &Self::TO_BE_CONCRETE;
| ^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -26,7 +30,7 @@ LL | let _ = &Self::TO_BE_CONCRETE; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:86:18
|
-LL | let _ = &Self::TO_BE_UNFROZEN; //~ ERROR interior mutable
+LL | let _ = &Self::TO_BE_UNFROZEN;
| ^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -34,7 +38,7 @@ LL | let _ = &Self::TO_BE_UNFROZEN; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:87:18
|
-LL | let _ = &Self::WRAPPED_TO_BE_UNFROZEN; //~ ERROR interior mutable
+LL | let _ = &Self::WRAPPED_TO_BE_UNFROZEN;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -42,7 +46,7 @@ LL | let _ = &Self::WRAPPED_TO_BE_UNFROZEN; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:109:18
|
-LL | let _ = &Self::BOUNDED; //~ ERROR interior mutable
+LL | let _ = &Self::BOUNDED;
| ^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -50,7 +54,7 @@ LL | let _ = &Self::BOUNDED; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:122:18
|
-LL | let _ = &Self::BOUNDED; //~ ERROR interior mutable
+LL | let _ = &Self::BOUNDED;
| ^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -58,7 +62,7 @@ LL | let _ = &Self::BOUNDED; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:151:18
|
-LL | let _ = &Self::SELF; //~ ERROR interior mutable
+LL | let _ = &Self::SELF;
| ^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -66,7 +70,7 @@ LL | let _ = &Self::SELF; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:152:18
|
-LL | let _ = &Self::WRAPPED_SELF; //~ ERROR interior mutable
+LL | let _ = &Self::WRAPPED_SELF;
| ^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -74,7 +78,7 @@ LL | let _ = &Self::WRAPPED_SELF; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:162:18
|
-LL | let _ = &Self::INDIRECT; //~ ERROR interior mutable
+LL | let _ = &Self::INDIRECT;
| ^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -82,7 +86,7 @@ LL | let _ = &Self::INDIRECT; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:172:18
|
-LL | let _ = &Self::INDIRECT; //~ ERROR interior mutable
+LL | let _ = &Self::INDIRECT;
| ^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -90,7 +94,7 @@ LL | let _ = &Self::INDIRECT; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:191:18
|
-LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
+LL | let _ = &Self::ATOMIC;
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -98,7 +102,7 @@ LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:195:18
|
-LL | let _ = &Self::BOUNDED_ASSOC_TYPE; //~ ERROR interior mutable
+LL | let _ = &Self::BOUNDED_ASSOC_TYPE;
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -106,7 +110,7 @@ LL | let _ = &Self::BOUNDED_ASSOC_TYPE; //~ ERROR interior mutable
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:200:5
|
-LL | u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability
+LL | u64::ATOMIC.store(5, Ordering::SeqCst);
| ^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
@@ -114,7 +118,7 @@ LL | u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:201:16
|
-LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR interior mutability
+LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9);
| ^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
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 2d6055eb6..5780ea089 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
@@ -1,6 +1,10 @@
#![deny(clippy::branches_sharing_code, clippy::if_same_then_else)]
#![allow(dead_code)]
-#![allow(clippy::mixed_read_write_in_expression, clippy::uninlined_format_args)]
+#![allow(
+ clippy::mixed_read_write_in_expression,
+ clippy::uninlined_format_args,
+ clippy::needless_else
+)]
// This tests valid if blocks that shouldn't trigger the lint
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 ce7fff012..a7e72b780 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
@@ -1,5 +1,5 @@
error: this `if` has identical blocks
- --> $DIR/valid_if_blocks.rs:105:14
+ --> $DIR/valid_if_blocks.rs:109:14
|
LL | if false {
| ______________^
@@ -7,7 +7,7 @@ LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/valid_if_blocks.rs:106:12
+ --> $DIR/valid_if_blocks.rs:110:12
|
LL | } else {
| ____________^
@@ -20,7 +20,7 @@ LL | #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: this `if` has identical blocks
- --> $DIR/valid_if_blocks.rs:116:15
+ --> $DIR/valid_if_blocks.rs:120:15
|
LL | if x == 0 {
| _______________^
@@ -31,7 +31,7 @@ LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/valid_if_blocks.rs:120:12
+ --> $DIR/valid_if_blocks.rs:124:12
|
LL | } else {
| ____________^
@@ -42,19 +42,19 @@ LL | | }
| |_____^
error: this `if` has identical blocks
- --> $DIR/valid_if_blocks.rs:127:23
+ --> $DIR/valid_if_blocks.rs:131:23
|
LL | let _ = if x == 6 { 7 } else { 7 };
| ^^^^^
|
note: same as this
- --> $DIR/valid_if_blocks.rs:127:34
+ --> $DIR/valid_if_blocks.rs:131:34
|
LL | let _ = if x == 6 { 7 } else { 7 };
| ^^^^^
error: this `if` has identical blocks
- --> $DIR/valid_if_blocks.rs:133:23
+ --> $DIR/valid_if_blocks.rs:137:23
|
LL | } else if x == 68 {
| _______________________^
@@ -66,7 +66,7 @@ LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/valid_if_blocks.rs:138:12
+ --> $DIR/valid_if_blocks.rs:142:12
|
LL | } else {
| ____________^
@@ -78,7 +78,7 @@ LL | | };
| |_____^
error: this `if` has identical blocks
- --> $DIR/valid_if_blocks.rs:147:23
+ --> $DIR/valid_if_blocks.rs:151:23
|
LL | } else if x == 68 {
| _______________________^
@@ -88,7 +88,7 @@ LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/valid_if_blocks.rs:150:12
+ --> $DIR/valid_if_blocks.rs:154:12
|
LL | } else {
| ____________^
diff --git a/src/tools/clippy/tests/ui/builtin_type_shadow.rs b/src/tools/clippy/tests/ui/builtin_type_shadow.rs
index 69b8b6a0e..c5addd534 100644
--- a/src/tools/clippy/tests/ui/builtin_type_shadow.rs
+++ b/src/tools/clippy/tests/ui/builtin_type_shadow.rs
@@ -3,7 +3,7 @@
fn foo<u32>(a: u32) -> u32 {
42
- // ^ rustc's type error
+ //~^ ERROR: mismatched types
}
fn main() {}
diff --git a/src/tools/clippy/tests/ui/bytecount.rs b/src/tools/clippy/tests/ui/bytecount.rs
index d3ad26921..4d168bfea 100644
--- a/src/tools/clippy/tests/ui/bytecount.rs
+++ b/src/tools/clippy/tests/ui/bytecount.rs
@@ -1,4 +1,4 @@
-#![allow(clippy::needless_borrow)]
+#![allow(clippy::needless_borrow, clippy::useless_vec)]
#[deny(clippy::naive_bytecount)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/cast.rs b/src/tools/clippy/tests/ui/cast.rs
index a86b85706..60a0eabf5 100644
--- a/src/tools/clippy/tests/ui/cast.rs
+++ b/src/tools/clippy/tests/ui/cast.rs
@@ -41,6 +41,14 @@ fn main() {
1u32 as i32;
1u64 as i64;
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
// Test clippy::cast_sign_loss
1i32 as u32;
-1i32 as u32;
diff --git a/src/tools/clippy/tests/ui/cast.stderr b/src/tools/clippy/tests/ui/cast.stderr
index 65ecf1aa3..de29af78e 100644
--- a/src/tools/clippy/tests/ui/cast.stderr
+++ b/src/tools/clippy/tests/ui/cast.stderr
@@ -215,20 +215,110 @@ error: casting `usize` to `isize` may wrap around the value
LL | 1usize as isize;
| ^^^^^^^^^^^^^^^
-error: casting `i32` to `u32` may lose the sign of the value
+error: casting `usize` to `i8` may truncate the value
+ --> $DIR/cast.rs:44:5
+ |
+LL | 1usize as i8; // should not wrap, usize is never 8 bits
+ | ^^^^^^^^^^^^
+ |
+ = 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
+ | ~~~~~~~~~~~~~~~~~~~~
+
+error: casting `usize` to `i16` may truncate the value
+ --> $DIR/cast.rs:45:5
+ |
+LL | 1usize as i16; // wraps on 16 bit ptr size
+ | ^^^^^^^^^^^^^
+ |
+ = 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
+ | ~~~~~~~~~~~~~~~~~~~~~
+
+error: casting `usize` to `i16` may wrap around the value on targets with 16-bit wide pointers
+ --> $DIR/cast.rs:45:5
+ |
+LL | 1usize as i16; // wraps on 16 bit ptr size
+ | ^^^^^^^^^^^^^
+ |
+ = 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
|
+LL | 1usize as i32; // wraps on 32 bit ptr size
+ | ^^^^^^^^^^^^^
+ |
+ = 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
+ | ~~~~~~~~~~~~~~~~~~~~~
+
+error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers
+ --> $DIR/cast.rs:46:5
+ |
+LL | 1usize as i32; // wraps on 32 bit ptr size
+ | ^^^^^^^^^^^^^
+
+error: casting `usize` to `i64` may wrap around the value on targets with 64-bit wide pointers
+ --> $DIR/cast.rs:47:5
+ |
+LL | 1usize as i64; // wraps on 64 bit ptr size
+ | ^^^^^^^^^^^^^
+
+error: casting `u16` to `isize` may wrap around the value on targets with 16-bit wide pointers
+ --> $DIR/cast.rs:49:5
+ |
+LL | 1u16 as isize; // wraps on 16 bit ptr size
+ | ^^^^^^^^^^^^^
+ |
+ = 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
+ |
+LL | 1u32 as isize; // wraps on 32 bit ptr size
+ | ^^^^^^^^^^^^^
+
+error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers
+ --> $DIR/cast.rs:51:5
+ |
+LL | 1u64 as isize; // wraps on 64 bit ptr size
+ | ^^^^^^^^^^^^^
+ |
+ = 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
+ | ~~~~~~~~~~~~~~~~~~~~~
+
+error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers
+ --> $DIR/cast.rs:51:5
+ |
+LL | 1u64 as isize; // wraps on 64 bit ptr size
+ | ^^^^^^^^^^^^^
+
+error: casting `i32` to `u32` may lose the sign of the value
+ --> $DIR/cast.rs:54:5
+ |
LL | -1i32 as u32;
| ^^^^^^^^^^^^
error: casting `isize` to `usize` may lose the sign of the value
- --> $DIR/cast.rs:48:5
+ --> $DIR/cast.rs:56:5
|
LL | -1isize as usize;
| ^^^^^^^^^^^^^^^^
error: casting `i64` to `i8` may truncate the value
- --> $DIR/cast.rs:115:5
+ --> $DIR/cast.rs:123:5
|
LL | (-99999999999i64).min(1) as i8; // should be linted because signed
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -240,7 +330,7 @@ LL | i8::try_from((-99999999999i64).min(1)); // should be linted because sig
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: casting `u64` to `u8` may truncate the value
- --> $DIR/cast.rs:127:5
+ --> $DIR/cast.rs:135:5
|
LL | 999999u64.clamp(0, 256) as u8; // should still be linted
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -252,7 +342,7 @@ LL | u8::try_from(999999u64.clamp(0, 256)); // should still be linted
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: casting `main::E2` to `u8` may truncate the value
- --> $DIR/cast.rs:148:21
+ --> $DIR/cast.rs:156:21
|
LL | let _ = self as u8;
| ^^^^^^^^^^
@@ -264,7 +354,7 @@ LL | let _ = u8::try_from(self);
| ~~~~~~~~~~~~~~~~~~
error: casting `main::E2::B` to `u8` will truncate the value
- --> $DIR/cast.rs:149:21
+ --> $DIR/cast.rs:157:21
|
LL | let _ = Self::B as u8;
| ^^^^^^^^^^^^^
@@ -272,7 +362,7 @@ LL | let _ = Self::B as u8;
= note: `-D clippy::cast-enum-truncation` implied by `-D warnings`
error: casting `main::E5` to `i8` may truncate the value
- --> $DIR/cast.rs:185:21
+ --> $DIR/cast.rs:193:21
|
LL | let _ = self as i8;
| ^^^^^^^^^^
@@ -284,13 +374,13 @@ LL | let _ = i8::try_from(self);
| ~~~~~~~~~~~~~~~~~~
error: casting `main::E5::A` to `i8` will truncate the value
- --> $DIR/cast.rs:186:21
+ --> $DIR/cast.rs:194:21
|
LL | let _ = Self::A as i8;
| ^^^^^^^^^^^^^
error: casting `main::E6` to `i16` may truncate the value
- --> $DIR/cast.rs:200:21
+ --> $DIR/cast.rs:208:21
|
LL | let _ = self as i16;
| ^^^^^^^^^^^
@@ -302,7 +392,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:215:21
+ --> $DIR/cast.rs:223:21
|
LL | let _ = self as usize;
| ^^^^^^^^^^^^^
@@ -314,7 +404,7 @@ LL | let _ = usize::try_from(self);
| ~~~~~~~~~~~~~~~~~~~~~
error: casting `main::E10` to `u16` may truncate the value
- --> $DIR/cast.rs:256:21
+ --> $DIR/cast.rs:264:21
|
LL | let _ = self as u16;
| ^^^^^^^^^^^
@@ -326,7 +416,7 @@ LL | let _ = u16::try_from(self);
| ~~~~~~~~~~~~~~~~~~~
error: casting `u32` to `u8` may truncate the value
- --> $DIR/cast.rs:264:13
+ --> $DIR/cast.rs:272:13
|
LL | let c = (q >> 16) as u8;
| ^^^^^^^^^^^^^^^
@@ -338,7 +428,7 @@ LL | let c = u8::try_from(q >> 16);
| ~~~~~~~~~~~~~~~~~~~~~
error: casting `u32` to `u8` may truncate the value
- --> $DIR/cast.rs:267:13
+ --> $DIR/cast.rs:275:13
|
LL | let c = (q / 1000) as u8;
| ^^^^^^^^^^^^^^^^
@@ -349,5 +439,5 @@ help: ... or use `try_from` and handle the error accordingly
LL | let c = u8::try_from(q / 1000);
| ~~~~~~~~~~~~~~~~~~~~~~
-error: aborting due to 41 previous errors
+error: aborting due to 51 previous errors
diff --git a/src/tools/clippy/tests/ui/cast_ref_to_mut.rs b/src/tools/clippy/tests/ui/cast_ref_to_mut.rs
deleted file mode 100644
index c48a734ba..000000000
--- a/src/tools/clippy/tests/ui/cast_ref_to_mut.rs
+++ /dev/null
@@ -1,31 +0,0 @@
-#![warn(clippy::cast_ref_to_mut)]
-#![allow(clippy::no_effect, clippy::borrow_as_ptr)]
-
-extern "C" {
- // N.B., mutability can be easily incorrect in FFI calls -- as
- // in C, the default is mutable pointers.
- fn ffi(c: *mut u8);
- fn int_ffi(c: *mut i32);
-}
-
-fn main() {
- let s = String::from("Hello");
- let a = &s;
- unsafe {
- let num = &3i32;
- let mut_num = &mut 3i32;
- // Should be warned against
- (*(a as *const _ as *mut String)).push_str(" world");
- *(a as *const _ as *mut _) = String::from("Replaced");
- *(a as *const _ as *mut String) += " world";
- // Shouldn't be warned against
- println!("{}", *(num as *const _ as *const i16));
- println!("{}", *(mut_num as *mut _ as *mut i16));
- ffi(a.as_ptr() as *mut _);
- int_ffi(num as *const _ as *mut _);
- int_ffi(&3 as *const _ as *mut _);
- let mut value = 3;
- let value: *const i32 = &mut value;
- *(value as *const i16 as *mut i16) = 42;
- }
-}
diff --git a/src/tools/clippy/tests/ui/cast_ref_to_mut.stderr b/src/tools/clippy/tests/ui/cast_ref_to_mut.stderr
deleted file mode 100644
index aacd99437..000000000
--- a/src/tools/clippy/tests/ui/cast_ref_to_mut.stderr
+++ /dev/null
@@ -1,22 +0,0 @@
-error: casting `&T` to `&mut T` may cause undefined behavior, consider instead using an `UnsafeCell`
- --> $DIR/cast_ref_to_mut.rs:18:9
- |
-LL | (*(a as *const _ as *mut String)).push_str(" world");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: `-D clippy::cast-ref-to-mut` implied by `-D warnings`
-
-error: casting `&T` to `&mut T` may cause undefined behavior, consider instead using an `UnsafeCell`
- --> $DIR/cast_ref_to_mut.rs:19:9
- |
-LL | *(a as *const _ as *mut _) = String::from("Replaced");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: casting `&T` to `&mut T` may cause undefined behavior, consider instead using an `UnsafeCell`
- --> $DIR/cast_ref_to_mut.rs:20:9
- |
-LL | *(a as *const _ as *mut String) += " world";
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 3 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 b77f01883..27e03ebb7 100644
--- a/src/tools/clippy/tests/ui/cast_slice_different_sizes.rs
+++ b/src/tools/clippy/tests/ui/cast_slice_different_sizes.rs
@@ -1,4 +1,4 @@
-#![allow(clippy::let_unit_value)]
+#![allow(clippy::let_unit_value, clippy::unnecessary_cast)]
fn main() {
let x: [i32; 3] = [1_i32, 2, 3];
diff --git a/src/tools/clippy/tests/ui/cfg_features.rs b/src/tools/clippy/tests/ui/cfg_features.rs
new file mode 100644
index 000000000..bc4109c2c
--- /dev/null
+++ b/src/tools/clippy/tests/ui/cfg_features.rs
@@ -0,0 +1,12 @@
+#![warn(clippy::maybe_misused_cfg)]
+
+fn main() {
+ #[cfg(features = "not-really-a-feature")]
+ let _ = 1 + 2;
+
+ #[cfg(all(feature = "right", features = "wrong"))]
+ let _ = 1 + 2;
+
+ #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))]
+ let _ = 1 + 2;
+}
diff --git a/src/tools/clippy/tests/ui/cfg_features.stderr b/src/tools/clippy/tests/ui/cfg_features.stderr
new file mode 100644
index 000000000..00405985d
--- /dev/null
+++ b/src/tools/clippy/tests/ui/cfg_features.stderr
@@ -0,0 +1,28 @@
+error: feature may misspelled as features
+ --> $DIR/cfg_features.rs:4:11
+ |
+LL | #[cfg(features = "not-really-a-feature")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `feature = "not-really-a-feature"`
+ |
+ = note: `-D clippy::maybe-misused-cfg` implied by `-D warnings`
+
+error: feature may misspelled as features
+ --> $DIR/cfg_features.rs:7:34
+ |
+LL | #[cfg(all(feature = "right", features = "wrong"))]
+ | ^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong"`
+
+error: feature may misspelled as features
+ --> $DIR/cfg_features.rs:10: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
+ |
+LL | #[cfg(all(features = "wrong1", any(feature = "right", features = "wrong2", feature, features)))]
+ | ^^^^^^^^^^^^^^^^^^^ help: use: `feature = "wrong2"`
+
+error: aborting due to 4 previous errors
+
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 ec082c73b..16e54a7d9 100644
--- a/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.rs
+++ b/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.rs
@@ -1,5 +1,9 @@
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
-#![allow(clippy::if_same_then_else, clippy::branches_sharing_code)]
+#![allow(
+ clippy::if_same_then_else,
+ clippy::branches_sharing_code,
+ clippy::unnecessary_literal_unwrap
+)]
fn test_complex_conditions() {
let x: Result<(), ()> = Ok(());
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 d44d5072e..c395c5ba0 100644
--- a/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.stderr
+++ b/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.stderr
@@ -1,5 +1,5 @@
error: called `unwrap` on `x` after checking its variant with `is_ok`
- --> $DIR/complex_conditionals.rs:8:9
+ --> $DIR/complex_conditionals.rs:12:9
|
LL | if x.is_ok() && y.is_err() {
| --------- the check is happening here
@@ -14,7 +14,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this call to `unwrap_err()` will always panic
- --> $DIR/complex_conditionals.rs:9:9
+ --> $DIR/complex_conditionals.rs:13:9
|
LL | if x.is_ok() && y.is_err() {
| --------- because of this check
@@ -29,7 +29,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/complex_conditionals.rs:10:9
+ --> $DIR/complex_conditionals.rs:14:9
|
LL | if x.is_ok() && y.is_err() {
| ---------- because of this check
@@ -38,7 +38,7 @@ LL | y.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap_err` on `y` after checking its variant with `is_err`
- --> $DIR/complex_conditionals.rs:11:9
+ --> $DIR/complex_conditionals.rs:15:9
|
LL | if x.is_ok() && y.is_err() {
| ---------- the check is happening here
@@ -49,7 +49,7 @@ LL | y.unwrap_err(); // unnecessary
= help: try using `if let` or `match`
error: this call to `unwrap()` will always panic
- --> $DIR/complex_conditionals.rs:25:9
+ --> $DIR/complex_conditionals.rs:29:9
|
LL | if x.is_ok() || y.is_ok() {
| --------- because of this check
@@ -58,7 +58,7 @@ LL | x.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap_err` on `x` after checking its variant with `is_ok`
- --> $DIR/complex_conditionals.rs:26:9
+ --> $DIR/complex_conditionals.rs:30:9
|
LL | if x.is_ok() || y.is_ok() {
| --------- the check is happening here
@@ -69,7 +69,7 @@ LL | x.unwrap_err(); // unnecessary
= help: try using `if let` or `match`
error: this call to `unwrap()` will always panic
- --> $DIR/complex_conditionals.rs:27:9
+ --> $DIR/complex_conditionals.rs:31:9
|
LL | if x.is_ok() || y.is_ok() {
| --------- because of this check
@@ -78,7 +78,7 @@ LL | y.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap_err` on `y` after checking its variant with `is_ok`
- --> $DIR/complex_conditionals.rs:28:9
+ --> $DIR/complex_conditionals.rs:32:9
|
LL | if x.is_ok() || y.is_ok() {
| --------- the check is happening here
@@ -89,7 +89,7 @@ LL | y.unwrap_err(); // unnecessary
= help: try using `if let` or `match`
error: called `unwrap` on `x` after checking its variant with `is_ok`
- --> $DIR/complex_conditionals.rs:32:9
+ --> $DIR/complex_conditionals.rs:36:9
|
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
| --------- the check is happening here
@@ -99,7 +99,7 @@ LL | x.unwrap(); // unnecessary
= help: try using `if let` or `match`
error: this call to `unwrap_err()` will always panic
- --> $DIR/complex_conditionals.rs:33:9
+ --> $DIR/complex_conditionals.rs:37:9
|
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
| --------- because of this check
@@ -108,7 +108,7 @@ LL | x.unwrap_err(); // will panic
| ^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/complex_conditionals.rs:34:9
+ --> $DIR/complex_conditionals.rs:38:9
|
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
| --------- because of this check
@@ -117,7 +117,7 @@ LL | y.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap_err` on `y` after checking its variant with `is_ok`
- --> $DIR/complex_conditionals.rs:35:9
+ --> $DIR/complex_conditionals.rs:39:9
|
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
| --------- the check is happening here
@@ -128,7 +128,7 @@ LL | y.unwrap_err(); // unnecessary
= help: try using `if let` or `match`
error: called `unwrap` on `z` after checking its variant with `is_err`
- --> $DIR/complex_conditionals.rs:36:9
+ --> $DIR/complex_conditionals.rs:40:9
|
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
| ---------- the check is happening here
@@ -139,7 +139,7 @@ LL | z.unwrap(); // unnecessary
= 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:41:9
|
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
| ---------- because of this check
@@ -148,7 +148,7 @@ LL | z.unwrap_err(); // will panic
| ^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/complex_conditionals.rs:45:9
+ --> $DIR/complex_conditionals.rs:49:9
|
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
| --------- because of this check
@@ -157,7 +157,7 @@ LL | x.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap_err` on `x` after checking its variant with `is_ok`
- --> $DIR/complex_conditionals.rs:46:9
+ --> $DIR/complex_conditionals.rs:50:9
|
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
| --------- the check is happening here
@@ -168,7 +168,7 @@ LL | x.unwrap_err(); // unnecessary
= help: try using `if let` or `match`
error: called `unwrap` on `y` after checking its variant with `is_ok`
- --> $DIR/complex_conditionals.rs:47:9
+ --> $DIR/complex_conditionals.rs:51:9
|
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
| --------- the check is happening here
@@ -179,7 +179,7 @@ LL | y.unwrap(); // unnecessary
= help: try using `if let` or `match`
error: this call to `unwrap_err()` will always panic
- --> $DIR/complex_conditionals.rs:48:9
+ --> $DIR/complex_conditionals.rs:52:9
|
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
| --------- because of this check
@@ -188,7 +188,7 @@ LL | y.unwrap_err(); // will panic
| ^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/complex_conditionals.rs:49:9
+ --> $DIR/complex_conditionals.rs:53:9
|
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
| ---------- because of this check
@@ -197,7 +197,7 @@ LL | z.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap_err` on `z` after checking its variant with `is_err`
- --> $DIR/complex_conditionals.rs:50:9
+ --> $DIR/complex_conditionals.rs:54:9
|
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
| ---------- the check is happening here
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 043ea4148..e417cf833 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
@@ -1,5 +1,9 @@
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
-#![allow(clippy::if_same_then_else, clippy::branches_sharing_code)]
+#![allow(
+ clippy::if_same_then_else,
+ clippy::branches_sharing_code,
+ clippy::unnecessary_literal_unwrap
+)]
fn test_nested() {
fn nested() {
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 542ab5330..049a69d93 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,5 +1,5 @@
error: called `unwrap` on `x` after checking its variant with `is_some`
- --> $DIR/complex_conditionals_nested.rs:8:13
+ --> $DIR/complex_conditionals_nested.rs:12:13
|
LL | if x.is_some() {
| -------------- help: try: `if let Some(..) = x`
@@ -13,7 +13,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/complex_conditionals_nested.rs:10:13
+ --> $DIR/complex_conditionals_nested.rs:14:13
|
LL | if x.is_some() {
| ----------- because of this check
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 82dce8197..61042bb90 100644
--- a/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.rs
+++ b/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.rs
@@ -1,6 +1,10 @@
#![feature(lint_reasons)]
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
-#![allow(clippy::if_same_then_else, clippy::branches_sharing_code)]
+#![allow(
+ clippy::if_same_then_else,
+ clippy::branches_sharing_code,
+ clippy::unnecessary_literal_unwrap
+)]
macro_rules! m {
($a:expr) => {
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 ef6882742..93809f655 100644
--- a/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.stderr
+++ b/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.stderr
@@ -1,5 +1,5 @@
error: called `unwrap` on `x` after checking its variant with `is_some`
- --> $DIR/simple_conditionals.rs:40:9
+ --> $DIR/simple_conditionals.rs:44:9
|
LL | if x.is_some() {
| -------------- help: try: `if let Some(..) = x`
@@ -13,7 +13,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: called `expect` on `x` after checking its variant with `is_some`
- --> $DIR/simple_conditionals.rs:41:9
+ --> $DIR/simple_conditionals.rs:45:9
|
LL | if x.is_some() {
| -------------- help: try: `if let Some(..) = x`
@@ -22,7 +22,7 @@ LL | x.expect("an error message"); // unnecessary
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/simple_conditionals.rs:43:9
+ --> $DIR/simple_conditionals.rs:47:9
|
LL | if x.is_some() {
| ----------- because of this check
@@ -37,7 +37,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: this call to `expect()` will always panic
- --> $DIR/simple_conditionals.rs:44:9
+ --> $DIR/simple_conditionals.rs:48:9
|
LL | if x.is_some() {
| ----------- because of this check
@@ -46,7 +46,7 @@ LL | x.expect("an error message"); // will panic
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/simple_conditionals.rs:47:9
+ --> $DIR/simple_conditionals.rs:51:9
|
LL | if x.is_none() {
| ----------- because of this check
@@ -54,7 +54,7 @@ LL | x.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap` on `x` after checking its variant with `is_none`
- --> $DIR/simple_conditionals.rs:49:9
+ --> $DIR/simple_conditionals.rs:53:9
|
LL | if x.is_none() {
| -------------- help: try: `if let Some(..) = x`
@@ -63,7 +63,7 @@ LL | x.unwrap(); // unnecessary
| ^^^^^^^^^^
error: called `unwrap` on `x` after checking its variant with `is_some`
- --> $DIR/simple_conditionals.rs:8:13
+ --> $DIR/simple_conditionals.rs:12:13
|
LL | if $a.is_some() {
| --------------- help: try: `if let Some(..) = x`
@@ -76,7 +76,7 @@ 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:57:9
+ --> $DIR/simple_conditionals.rs:61:9
|
LL | if x.is_ok() {
| ------------ help: try: `if let Ok(..) = x`
@@ -84,7 +84,7 @@ LL | x.unwrap(); // unnecessary
| ^^^^^^^^^^
error: called `expect` on `x` after checking its variant with `is_ok`
- --> $DIR/simple_conditionals.rs:58:9
+ --> $DIR/simple_conditionals.rs:62:9
|
LL | if x.is_ok() {
| ------------ help: try: `if let Ok(..) = x`
@@ -93,7 +93,7 @@ LL | x.expect("an error message"); // unnecessary
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this call to `unwrap_err()` will always panic
- --> $DIR/simple_conditionals.rs:59:9
+ --> $DIR/simple_conditionals.rs:63:9
|
LL | if x.is_ok() {
| --------- because of this check
@@ -102,7 +102,7 @@ LL | x.unwrap_err(); // will panic
| ^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/simple_conditionals.rs:61:9
+ --> $DIR/simple_conditionals.rs:65:9
|
LL | if x.is_ok() {
| --------- because of this check
@@ -111,7 +111,7 @@ LL | x.unwrap(); // will panic
| ^^^^^^^^^^
error: this call to `expect()` will always panic
- --> $DIR/simple_conditionals.rs:62:9
+ --> $DIR/simple_conditionals.rs:66:9
|
LL | if x.is_ok() {
| --------- because of this check
@@ -120,7 +120,7 @@ LL | x.expect("an error message"); // will panic
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: called `unwrap_err` on `x` after checking its variant with `is_ok`
- --> $DIR/simple_conditionals.rs:63:9
+ --> $DIR/simple_conditionals.rs:67:9
|
LL | if x.is_ok() {
| ------------ help: try: `if let Err(..) = x`
@@ -129,7 +129,7 @@ LL | x.unwrap_err(); // unnecessary
| ^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/simple_conditionals.rs:66:9
+ --> $DIR/simple_conditionals.rs:70:9
|
LL | if x.is_err() {
| ---------- because of this check
@@ -137,7 +137,7 @@ LL | x.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap_err` on `x` after checking its variant with `is_err`
- --> $DIR/simple_conditionals.rs:67:9
+ --> $DIR/simple_conditionals.rs:71:9
|
LL | if x.is_err() {
| ------------- help: try: `if let Err(..) = x`
@@ -146,7 +146,7 @@ LL | x.unwrap_err(); // unnecessary
| ^^^^^^^^^^^^^^
error: called `unwrap` on `x` after checking its variant with `is_err`
- --> $DIR/simple_conditionals.rs:69:9
+ --> $DIR/simple_conditionals.rs:73:9
|
LL | if x.is_err() {
| ------------- help: try: `if let Ok(..) = x`
@@ -155,7 +155,7 @@ LL | x.unwrap(); // unnecessary
| ^^^^^^^^^^
error: this call to `unwrap_err()` will always panic
- --> $DIR/simple_conditionals.rs:70:9
+ --> $DIR/simple_conditionals.rs:74:9
|
LL | if x.is_err() {
| ---------- because of this check
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 8f9f2a0db..b7c186bef 100644
--- a/src/tools/clippy/tests/ui/clone_on_copy_impl.rs
+++ b/src/tools/clippy/tests/ui/clone_on_copy_impl.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::incorrect_clone_impl_on_copy_type)]
+
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 b6e09ab31..34bd22334 100644
--- a/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed
+++ b/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed
@@ -2,6 +2,7 @@
#![warn(clippy::cloned_instead_of_copied)]
#![allow(unused)]
+#![allow(clippy::useless_vec)]
fn main() {
// yay
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 fa9e1a996..fa8444937 100644
--- a/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs
+++ b/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs
@@ -2,6 +2,7 @@
#![warn(clippy::cloned_instead_of_copied)]
#![allow(unused)]
+#![allow(clippy::useless_vec)]
fn main() {
// yay
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 e0361acd9..3ce482006 100644
--- a/src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr
+++ b/src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr
@@ -1,5 +1,5 @@
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:8:24
+ --> $DIR/cloned_instead_of_copied.rs:9:24
|
LL | let _ = [1].iter().cloned();
| ^^^^^^ help: try: `copied`
@@ -7,43 +7,43 @@ LL | let _ = [1].iter().cloned();
= note: `-D clippy::cloned-instead-of-copied` implied by `-D warnings`
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:9:31
+ --> $DIR/cloned_instead_of_copied.rs:10: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:10:22
+ --> $DIR/cloned_instead_of_copied.rs:11:22
|
LL | let _ = Some(&1).cloned();
| ^^^^^^ help: try: `copied`
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:11:34
+ --> $DIR/cloned_instead_of_copied.rs:12: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:12:32
+ --> $DIR/cloned_instead_of_copied.rs:13: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:28:22
+ --> $DIR/cloned_instead_of_copied.rs:29: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:33:24
+ --> $DIR/cloned_instead_of_copied.rs:34: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:34:22
+ --> $DIR/cloned_instead_of_copied.rs:35:22
|
LL | let _ = Some(&1).cloned();
| ^^^^^^ help: try: `copied`
diff --git a/src/tools/clippy/tests/ui/cmp_nan.rs b/src/tools/clippy/tests/ui/cmp_nan.rs
deleted file mode 100644
index 64ca52b01..000000000
--- a/src/tools/clippy/tests/ui/cmp_nan.rs
+++ /dev/null
@@ -1,34 +0,0 @@
-const NAN_F32: f32 = f32::NAN;
-const NAN_F64: f64 = f64::NAN;
-
-#[warn(clippy::cmp_nan)]
-#[allow(clippy::float_cmp, clippy::no_effect, clippy::unnecessary_operation)]
-fn main() {
- let x = 5f32;
- x == f32::NAN;
- x != f32::NAN;
- x < f32::NAN;
- x > f32::NAN;
- x <= f32::NAN;
- x >= f32::NAN;
- x == NAN_F32;
- x != NAN_F32;
- x < NAN_F32;
- x > NAN_F32;
- x <= NAN_F32;
- x >= NAN_F32;
-
- let y = 0f64;
- y == f64::NAN;
- y != f64::NAN;
- y < f64::NAN;
- y > f64::NAN;
- y <= f64::NAN;
- y >= f64::NAN;
- y == NAN_F64;
- y != NAN_F64;
- y < NAN_F64;
- y > NAN_F64;
- y <= NAN_F64;
- y >= NAN_F64;
-}
diff --git a/src/tools/clippy/tests/ui/cmp_nan.stderr b/src/tools/clippy/tests/ui/cmp_nan.stderr
deleted file mode 100644
index 867516661..000000000
--- a/src/tools/clippy/tests/ui/cmp_nan.stderr
+++ /dev/null
@@ -1,148 +0,0 @@
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:8:5
- |
-LL | x == f32::NAN;
- | ^^^^^^^^^^^^^
- |
- = note: `-D clippy::cmp-nan` implied by `-D warnings`
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:9:5
- |
-LL | x != f32::NAN;
- | ^^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:10:5
- |
-LL | x < f32::NAN;
- | ^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:11:5
- |
-LL | x > f32::NAN;
- | ^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:12:5
- |
-LL | x <= f32::NAN;
- | ^^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:13:5
- |
-LL | x >= f32::NAN;
- | ^^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:14:5
- |
-LL | x == NAN_F32;
- | ^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:15:5
- |
-LL | x != NAN_F32;
- | ^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:16:5
- |
-LL | x < NAN_F32;
- | ^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:17:5
- |
-LL | x > NAN_F32;
- | ^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:18:5
- |
-LL | x <= NAN_F32;
- | ^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:19:5
- |
-LL | x >= NAN_F32;
- | ^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:22:5
- |
-LL | y == f64::NAN;
- | ^^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:23:5
- |
-LL | y != f64::NAN;
- | ^^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:24:5
- |
-LL | y < f64::NAN;
- | ^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:25:5
- |
-LL | y > f64::NAN;
- | ^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:26:5
- |
-LL | y <= f64::NAN;
- | ^^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:27:5
- |
-LL | y >= f64::NAN;
- | ^^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:28:5
- |
-LL | y == NAN_F64;
- | ^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:29:5
- |
-LL | y != NAN_F64;
- | ^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:30:5
- |
-LL | y < NAN_F64;
- | ^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:31:5
- |
-LL | y > NAN_F64;
- | ^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:32:5
- |
-LL | y <= NAN_F64;
- | ^^^^^^^^^^^^
-
-error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
- --> $DIR/cmp_nan.rs:33:5
- |
-LL | y >= NAN_F64;
- | ^^^^^^^^^^^^
-
-error: aborting due to 24 previous errors
-
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 3bf3deb9b..118346348 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,5 +1,10 @@
//@run-rustfix
-#![allow(unused, clippy::redundant_clone, clippy::derive_partial_eq_without_eq)] // See #5700
+#![allow(
+ unused,
+ clippy::needless_if,
+ clippy::redundant_clone,
+ clippy::derive_partial_eq_without_eq
+)] // See #5700
// Define the types in each module to avoid trait impls leaking between modules.
macro_rules! impl_types {
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 10107dc8f..3a25d53a5 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,5 +1,10 @@
//@run-rustfix
-#![allow(unused, clippy::redundant_clone, clippy::derive_partial_eq_without_eq)] // See #5700
+#![allow(
+ unused,
+ clippy::needless_if,
+ clippy::redundant_clone,
+ clippy::derive_partial_eq_without_eq
+)] // See #5700
// Define the types in each module to avoid trait impls leaking between modules.
macro_rules! impl_types {
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 43bf8851f..4714a0daa 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,5 +1,5 @@
error: this creates an owned instance just for comparison
- --> $DIR/asymmetric_partial_eq.rs:42:12
+ --> $DIR/asymmetric_partial_eq.rs:47:12
|
LL | if borrowed.to_owned() == owned {}
| ^^^^^^^^^^^^^^^^^^^ help: try: `borrowed`
@@ -7,7 +7,7 @@ LL | if borrowed.to_owned() == owned {}
= note: `-D clippy::cmp-owned` implied by `-D warnings`
error: this creates an owned instance just for comparison
- --> $DIR/asymmetric_partial_eq.rs:43:21
+ --> $DIR/asymmetric_partial_eq.rs:48:21
|
LL | if owned == borrowed.to_owned() {}
| ---------^^^^^^^^^^^^^^^^^^^
@@ -15,13 +15,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:61:21
+ --> $DIR/asymmetric_partial_eq.rs:66:21
|
LL | if owned == borrowed.to_owned() {}
| ^^^^^^^^^^^^^^^^^^^ help: try: `borrowed`
error: this creates an owned instance just for comparison
- --> $DIR/asymmetric_partial_eq.rs:62:12
+ --> $DIR/asymmetric_partial_eq.rs:67:12
|
LL | if borrowed.to_owned() == owned {}
| ^^^^^^^^^^^^^^^^^^^---------
@@ -29,7 +29,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:88:20
+ --> $DIR/asymmetric_partial_eq.rs:93:20
|
LL | if "Hi" == borrowed.to_string() {}
| --------^^^^^^^^^^^^^^^^^^^^
@@ -37,7 +37,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:89:12
+ --> $DIR/asymmetric_partial_eq.rs:94:12
|
LL | if borrowed.to_string() == "Hi" {}
| ^^^^^^^^^^^^^^^^^^^^ help: try: `borrowed`
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 76f90ab2a..bf1a58588 100644
--- a/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.fixed
+++ b/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.fixed
@@ -31,7 +31,7 @@ struct Foo;
impl PartialEq for Foo {
// Allow this here, because it emits the lint
// without a suggestion. This is tested in
- // `tests/ui/cmp_owned/without_suggestion.rs`
+ // `$DIR/without_suggestion.rs`
#[allow(clippy::cmp_owned)]
fn eq(&self, other: &Self) -> bool {
self.to_owned() == *other
diff --git a/src/tools/clippy/tests/ui/cognitive_complexity.stderr b/src/tools/clippy/tests/ui/cognitive_complexity.stderr
index 5824631fa..d86724630 100644
--- a/src/tools/clippy/tests/ui/cognitive_complexity.stderr
+++ b/src/tools/clippy/tests/ui/cognitive_complexity.stderr
@@ -40,6 +40,14 @@ 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
+ |
+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
|
LL | fn barr() {
@@ -151,5 +159,5 @@ LL | pub async fn async_method() {
|
= help: you could split it up into multiple smaller functions
-error: aborting due to 19 previous errors
+error: aborting due to 20 previous errors
diff --git a/src/tools/clippy/tests/ui/collapsible_else_if.fixed b/src/tools/clippy/tests/ui/collapsible_else_if.fixed
index 8302cec45..c4116cd85 100644
--- a/src/tools/clippy/tests/ui/collapsible_else_if.fixed
+++ b/src/tools/clippy/tests/ui/collapsible_else_if.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-#![allow(clippy::assertions_on_constants, clippy::equatable_if_let)]
+#![allow(clippy::assertions_on_constants, clippy::equatable_if_let, clippy::needless_if)]
#[rustfmt::skip]
#[warn(clippy::collapsible_if)]
diff --git a/src/tools/clippy/tests/ui/collapsible_else_if.rs b/src/tools/clippy/tests/ui/collapsible_else_if.rs
index 5913dcf41..8f51d0ee5 100644
--- a/src/tools/clippy/tests/ui/collapsible_else_if.rs
+++ b/src/tools/clippy/tests/ui/collapsible_else_if.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-#![allow(clippy::assertions_on_constants, clippy::equatable_if_let)]
+#![allow(clippy::assertions_on_constants, clippy::equatable_if_let, clippy::needless_if)]
#[rustfmt::skip]
#[warn(clippy::collapsible_if)]
diff --git a/src/tools/clippy/tests/ui/collapsible_if.fixed b/src/tools/clippy/tests/ui/collapsible_if.fixed
index c6514a559..e305e1d7a 100644
--- a/src/tools/clippy/tests/ui/collapsible_if.fixed
+++ b/src/tools/clippy/tests/ui/collapsible_if.fixed
@@ -2,6 +2,7 @@
#![allow(
clippy::assertions_on_constants,
clippy::equatable_if_let,
+ clippy::needless_if,
clippy::nonminimal_bool,
clippy::eq_op
)]
diff --git a/src/tools/clippy/tests/ui/collapsible_if.rs b/src/tools/clippy/tests/ui/collapsible_if.rs
index 2c85b68df..7c52959d3 100644
--- a/src/tools/clippy/tests/ui/collapsible_if.rs
+++ b/src/tools/clippy/tests/ui/collapsible_if.rs
@@ -2,6 +2,7 @@
#![allow(
clippy::assertions_on_constants,
clippy::equatable_if_let,
+ clippy::needless_if,
clippy::nonminimal_bool,
clippy::eq_op
)]
diff --git a/src/tools/clippy/tests/ui/collapsible_if.stderr b/src/tools/clippy/tests/ui/collapsible_if.stderr
index c687bae1a..4a1a9e8a6 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:14:5
+ --> $DIR/collapsible_if.rs:15:5
|
LL | / if x == "hello" {
LL | | if y == "world" {
@@ -17,7 +17,7 @@ LL + }
|
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:20:5
+ --> $DIR/collapsible_if.rs:21:5
|
LL | / if x == "hello" || x == "world" {
LL | | if y == "world" || y == "hello" {
@@ -34,7 +34,7 @@ LL + }
|
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:26:5
+ --> $DIR/collapsible_if.rs:27:5
|
LL | / if x == "hello" && x == "world" {
LL | | if y == "world" || y == "hello" {
@@ -51,7 +51,7 @@ LL + }
|
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:32:5
+ --> $DIR/collapsible_if.rs:33:5
|
LL | / if x == "hello" || x == "world" {
LL | | if y == "world" && y == "hello" {
@@ -68,7 +68,7 @@ LL + }
|
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:38:5
+ --> $DIR/collapsible_if.rs:39:5
|
LL | / if x == "hello" && x == "world" {
LL | | if y == "world" && y == "hello" {
@@ -85,7 +85,7 @@ LL + }
|
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:44:5
+ --> $DIR/collapsible_if.rs:45:5
|
LL | / if 42 == 1337 {
LL | | if 'a' != 'A' {
@@ -102,7 +102,7 @@ LL + }
|
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:100:5
+ --> $DIR/collapsible_if.rs:101:5
|
LL | / if x == "hello" {
LL | | if y == "world" { // Collapsible
@@ -119,7 +119,7 @@ LL + }
|
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:159:5
+ --> $DIR/collapsible_if.rs:160:5
|
LL | / if matches!(true, true) {
LL | | if matches!(true, true) {}
@@ -127,7 +127,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:164:5
+ --> $DIR/collapsible_if.rs:165:5
|
LL | / if matches!(true, true) && truth() {
LL | | if matches!(true, true) {}
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 2c1a42a72..e02c1c572 100644
--- a/src/tools/clippy/tests/ui/collection_is_never_read.rs
+++ b/src/tools/clippy/tests/ui/collection_is_never_read.rs
@@ -1,4 +1,4 @@
-#![allow(unused)]
+#![allow(unused, clippy::useless_vec)]
#![warn(clippy::collection_is_never_read)]
use std::collections::{HashMap, HashSet};
diff --git a/src/tools/clippy/tests/ui/comparison_to_empty.fixed b/src/tools/clippy/tests/ui/comparison_to_empty.fixed
index dd2615ab2..c92dd509e 100644
--- a/src/tools/clippy/tests/ui/comparison_to_empty.fixed
+++ b/src/tools/clippy/tests/ui/comparison_to_empty.fixed
@@ -1,6 +1,7 @@
//@run-rustfix
#![warn(clippy::comparison_to_empty)]
+#![allow(clippy::useless_vec)]
fn main() {
// Disallow comparisons to empty
diff --git a/src/tools/clippy/tests/ui/comparison_to_empty.rs b/src/tools/clippy/tests/ui/comparison_to_empty.rs
index 5462784c6..b34897143 100644
--- a/src/tools/clippy/tests/ui/comparison_to_empty.rs
+++ b/src/tools/clippy/tests/ui/comparison_to_empty.rs
@@ -1,6 +1,7 @@
//@run-rustfix
#![warn(clippy::comparison_to_empty)]
+#![allow(clippy::useless_vec)]
fn main() {
// Disallow comparisons to empty
diff --git a/src/tools/clippy/tests/ui/comparison_to_empty.stderr b/src/tools/clippy/tests/ui/comparison_to_empty.stderr
index f69d6bd52..cc09b17eb 100644
--- a/src/tools/clippy/tests/ui/comparison_to_empty.stderr
+++ b/src/tools/clippy/tests/ui/comparison_to_empty.stderr
@@ -1,5 +1,5 @@
error: comparison to empty slice
- --> $DIR/comparison_to_empty.rs:8:13
+ --> $DIR/comparison_to_empty.rs:9:13
|
LL | let _ = s == "";
| ^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
@@ -7,19 +7,19 @@ LL | let _ = s == "";
= note: `-D clippy::comparison-to-empty` implied by `-D warnings`
error: comparison to empty slice
- --> $DIR/comparison_to_empty.rs:9:13
+ --> $DIR/comparison_to_empty.rs:10: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:12: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
- --> $DIR/comparison_to_empty.rs:13:13
+ --> $DIR/comparison_to_empty.rs:14:13
|
LL | let _ = v != [];
| ^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!v.is_empty()`
diff --git a/src/tools/clippy/tests/ui/crashes/auxiliary/proc_macro_crash.rs b/src/tools/clippy/tests/ui/crashes/auxiliary/proc_macro_crash.rs
index 66419656a..5dffddc11 100644
--- a/src/tools/clippy/tests/ui/crashes/auxiliary/proc_macro_crash.rs
+++ b/src/tools/clippy/tests/ui/crashes/auxiliary/proc_macro_crash.rs
@@ -1,13 +1,5 @@
-//@compile-flags: --emit=link
-//@no-prefer-dynamic
-// ^ compiletest by default builds all aux files as dylibs, but we don't want that for proc-macro
-// crates. If we don't set this, compiletest will override the `crate_type` attribute below and
-// compile this as dylib. Removing this then causes the test to fail because a `dylib` crate can't
-// contain a proc-macro.
-
#![feature(repr128)]
#![allow(incomplete_features)]
-#![crate_type = "proc-macro"]
extern crate proc_macro;
diff --git a/src/tools/clippy/tests/ui/crashes/ice-10148.rs b/src/tools/clippy/tests/ui/crashes/ice-10148.rs
index c7f022482..0df22f413 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-10148.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-10148.rs
@@ -1,4 +1,4 @@
-//@aux-build:../../auxiliary/proc_macros.rs
+//@aux-build:../auxiliary/proc_macros.rs:proc-macro
extern crate proc_macros;
diff --git a/src/tools/clippy/tests/ui/crashes/ice-10645.rs b/src/tools/clippy/tests/ui/crashes/ice-10645.rs
index 4d8698d38..6e126aff7 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-10645.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-10645.rs
@@ -1,4 +1,4 @@
-// compile-flags: --cap-lints=warn
+//@compile-flags: --cap-lints=warn
// https://github.com/rust-lang/rust-clippy/issues/10645
#![warn(clippy::future_not_send)]
diff --git a/src/tools/clippy/tests/ui/crashes/ice-10645.stderr b/src/tools/clippy/tests/ui/crashes/ice-10645.stderr
index fc084e30d..0055fe061 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-10645.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-10645.stderr
@@ -1,4 +1,4 @@
-error: future cannot be sent between threads safely
+warning: future cannot be sent between threads safely
--> $DIR/ice-10645.rs:5:35
|
LL | pub async fn bar<'a, T: 'a>(_: T) {}
@@ -12,5 +12,5 @@ LL | pub async fn bar<'a, T: 'a>(_: T) {}
= note: `T` doesn't implement `std::marker::Send`
= note: `-D clippy::future-not-send` implied by `-D warnings`
-error: aborting due to previous error
+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
new file mode 100644
index 000000000..69d7f2f39
--- /dev/null
+++ b/src/tools/clippy/tests/ui/crashes/ice-10912.rs
@@ -0,0 +1,4 @@
+#![warn(clippy::unreadable_literal)]
+fn f2() -> impl Sized { && 3.14159265358979323846E }
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/crashes/ice-10912.stderr b/src/tools/clippy/tests/ui/crashes/ice-10912.stderr
new file mode 100644
index 000000000..a74ce7315
--- /dev/null
+++ b/src/tools/clippy/tests/ui/crashes/ice-10912.stderr
@@ -0,0 +1,16 @@
+error: expected at least one digit in exponent
+ --> $DIR/ice-10912.rs:2:28
+ |
+LL | fn f2() -> impl Sized { && 3.14159265358979323846E }
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+
+error: long literal lacking separators
+ --> $DIR/ice-10912.rs:2: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`
+
+error: aborting due to 2 previous errors
+
diff --git a/src/tools/clippy/tests/ui/crashes/ice-11065.rs b/src/tools/clippy/tests/ui/crashes/ice-11065.rs
new file mode 100644
index 000000000..f5cf6b1cd
--- /dev/null
+++ b/src/tools/clippy/tests/ui/crashes/ice-11065.rs
@@ -0,0 +1,19 @@
+#![warn(clippy::useless_conversion)]
+
+use std::iter::FromIterator;
+use std::option::IntoIter as OptionIter;
+
+fn eq<T: Eq>(a: T, b: T) -> bool {
+ a == b
+}
+
+macro_rules! tests {
+ ($($expr:expr, $ty:ty, ($($test:expr),*);)+) => (pub fn main() {$({
+ const C: $ty = $expr;
+ assert!(eq(C($($test),*), $expr($($test),*)));
+ })+})
+}
+
+tests! {
+ FromIterator::from_iter, fn(OptionIter<i32>) -> Vec<i32>, (Some(5).into_iter());
+}
diff --git a/src/tools/clippy/tests/ui/crashes/ice-1782.rs b/src/tools/clippy/tests/ui/crashes/ice-1782.rs
index 81af88962..19ab03418 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-1782.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-1782.rs
@@ -1,4 +1,5 @@
#![allow(dead_code, unused_variables)]
+#![allow(clippy::unnecessary_cast)]
/// Should not trigger an ICE in `SpanlessEq` / `consts::constant`
///
diff --git a/src/tools/clippy/tests/ui/crashes/ice-2774.stderr b/src/tools/clippy/tests/ui/crashes/ice-2774.stderr
index c5ea0b16d..a166ccb3e 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-2774.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-2774.stderr
@@ -1,8 +1,8 @@
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/ice-2774.rs:15:1
+ --> $DIR/ice-2774.rs:15:28
|
LL | pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
= note: `-D clippy::needless-lifetimes` implied by `-D warnings`
help: elide the lifetimes
diff --git a/src/tools/clippy/tests/ui/crashes/ice-3462.rs b/src/tools/clippy/tests/ui/crashes/ice-3462.rs
index b40205288..21cd9d337 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-3462.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-3462.rs
@@ -1,5 +1,5 @@
#![warn(clippy::all)]
-#![allow(clippy::disallowed_names, clippy::equatable_if_let)]
+#![allow(clippy::disallowed_names, clippy::equatable_if_let, clippy::needless_if)]
#![allow(unused)]
/// Test for https://github.com/rust-lang/rust-clippy/issues/3462
diff --git a/src/tools/clippy/tests/ui/crashes/ice-3741.rs b/src/tools/clippy/tests/ui/crashes/ice-3741.rs
index 3106a2e72..268c5ba0a 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
+//@aux-build:proc_macro_crash.rs:proc-macro
#![warn(clippy::suspicious_else_formatting)]
diff --git a/src/tools/clippy/tests/ui/crashes/ice-4968.rs b/src/tools/clippy/tests/ui/crashes/ice-4968.rs
index ac724ac93..504738680 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-4968.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-4968.rs
@@ -1,5 +1,3 @@
-//@check-pass
-
// Test for https://github.com/rust-lang/rust-clippy/issues/4968
#![warn(clippy::unsound_collection_transmute)]
diff --git a/src/tools/clippy/tests/ui/crashes/ice-5497.rs b/src/tools/clippy/tests/ui/crashes/ice-5497.rs
index 0769bce5f..f77f691c1 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-5497.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-5497.rs
@@ -7,5 +7,5 @@ pub trait Foo {
impl<T: Foo> Foo for Vec<T> {
const OOB: i32 = [1][1] + T::OOB;
- //~^ ERROR operation will panic
+ //~^ ERROR: operation will panic
}
diff --git a/src/tools/clippy/tests/ui/crashes/ice-5579.rs b/src/tools/clippy/tests/ui/crashes/ice-5579.rs
index e1842c73f..8ab36bbf9 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-5579.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-5579.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::unnecessary_literal_unwrap)]
+
trait IsErr {
fn is_err(&self, err: &str) -> bool;
}
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6250.stderr b/src/tools/clippy/tests/ui/crashes/ice-6250.stderr
index 4506d1550..97390af3e 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6250.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-6250.stderr
@@ -1,9 +1,3 @@
-error[E0601]: `main` function not found in crate `ice_6250`
- --> $DIR/ice-6250.rs:16:2
- |
-LL | }
- | ^ consider adding a `main` function to `$DIR/ice-6250.rs`
-
error[E0308]: mismatched types
--> $DIR/ice-6250.rs:12:14
|
@@ -12,11 +6,6 @@ LL | for reference in vec![1, 2, 3] {
...
LL | Some(reference) = cache.data.get(key) {
| ^^^^^^^^^ expected integer, found `&i32`
- |
-help: consider dereferencing the borrow
- |
-LL | Some(*reference) = cache.data.get(key) {
- | +
error[E0308]: mismatched types
--> $DIR/ice-6250.rs:12:9
@@ -29,7 +18,6 @@ help: consider adding `let`
LL | let Some(reference) = cache.data.get(key) {
| +++
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
-Some errors have detailed explanations: E0308, E0601.
-For more information about an error, try `rustc --explain E0308`.
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6251.stderr b/src/tools/clippy/tests/ui/crashes/ice-6251.stderr
index 8da2965c6..68a5766c9 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6251.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-6251.stderr
@@ -1,9 +1,3 @@
-error[E0601]: `main` function not found in crate `ice_6251`
- --> $DIR/ice-6251.rs:6:2
- |
-LL | }
- | ^ consider adding a `main` function to `$DIR/ice-6251.rs`
-
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/ice-6251.rs:4:45
|
@@ -35,7 +29,7 @@ LL | fn bug<T>() -> impl Iterator<Item = [(); { |x: [u8]| x }]> {
= note: expected type `usize`
found closure `[closure@$DIR/ice-6251.rs:4:44: 4:53]`
-error: aborting due to 4 previous errors
+error: aborting due to 3 previous errors
-Some errors have detailed explanations: E0277, E0308, E0601.
+Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6255.rs b/src/tools/clippy/tests/ui/crashes/ice-6255.rs
index ccde6aa2b..b6555ac5c 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6255.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-6255.rs
@@ -4,7 +4,6 @@
macro_rules! define_other_core {
( ) => {
extern crate std as core;
- //~^ ERROR macro-expanded `extern crate` items cannot shadow names passed with `--extern`
};
}
@@ -13,3 +12,4 @@ fn main() {
}
define_other_core!();
+//~^ ERROR: macro-expanded `extern crate` items cannot shadow names passed with `--extern`
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6256.rs b/src/tools/clippy/tests/ui/crashes/ice-6256.rs
index f9ee3e058..1d336b3cd 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6256.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-6256.rs
@@ -10,6 +10,6 @@ impl dyn TT {
#[rustfmt::skip]
fn main() {
- let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
- //[nll]~^ ERROR: borrowed data escapes outside of closure
+ let f = |x: &dyn TT| x.func();
+ //~^ ERROR: borrowed data escapes outside of closure
}
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6256.stderr b/src/tools/clippy/tests/ui/crashes/ice-6256.stderr
index 9cfcccf1e..671933157 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6256.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-6256.stderr
@@ -1,7 +1,7 @@
error[E0521]: borrowed data escapes outside of closure
--> $DIR/ice-6256.rs:13:26
|
-LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
+LL | let f = |x: &dyn TT| x.func();
| - - ^^^^^^^^
| | | |
| | | `x` escapes the closure body here
diff --git a/src/tools/clippy/tests/ui/crashes/ice-7169.rs b/src/tools/clippy/tests/ui/crashes/ice-7169.rs
index 82095febc..b203252f0 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-7169.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-7169.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::needless_if)]
+
#[derive(Default)]
struct A<T> {
a: Vec<A<T>>,
diff --git a/src/tools/clippy/tests/ui/crashes/ice-7169.stderr b/src/tools/clippy/tests/ui/crashes/ice-7169.stderr
index 5a9cd3238..84e0af3f0 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-7169.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-7169.stderr
@@ -1,5 +1,5 @@
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/ice-7169.rs:8:12
+ --> $DIR/ice-7169.rs:10:12
|
LL | if let Ok(_) = Ok::<_, ()>(A::<String>::default()) {}
| -------^^^^^-------------------------------------- help: try this: `if Ok::<_, ()>(A::<String>::default()).is_ok()`
diff --git a/src/tools/clippy/tests/ui/crashes/ice-7410.rs b/src/tools/clippy/tests/ui/crashes/ice-7410.rs
index ffe20ab1c..a2683b3ce 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-7410.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-7410.rs
@@ -1,11 +1,12 @@
//@compile-flags: -Clink-arg=-nostartfiles
-//@ignore-macos
-//@ignore-windows
+//@ignore-target-apple
+//@ignore-target-windows
#![feature(lang_items, start, libc)]
#![no_std]
#![allow(clippy::if_same_then_else)]
#![allow(clippy::redundant_pattern_matching)]
+#![allow(clippy::needless_else)]
use core::panic::PanicInfo;
diff --git a/src/tools/clippy/tests/ui/crashes/ice-9445.stderr b/src/tools/clippy/tests/ui/crashes/ice-9445.stderr
new file mode 100644
index 000000000..a59d098e5
--- /dev/null
+++ b/src/tools/clippy/tests/ui/crashes/ice-9445.stderr
@@ -0,0 +1,12 @@
+error: a `const` item should never be interior mutable
+ --> $DIR/ice-9445.rs:1:1
+ |
+LL | const UNINIT: core::mem::MaybeUninit<core::cell::Cell<&'static ()>> = core::mem::MaybeUninit::uninit();
+ | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | make this a static item (maybe with lazy_static)
+ |
+ = note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings`
+
+error: aborting due to previous error
+
diff --git a/src/tools/clippy/tests/ui/crashes/ice-96721.rs b/src/tools/clippy/tests/ui/crashes/ice-96721.rs
index 4b3fb7640..ca68ba3d0 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-96721.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-96721.rs
@@ -4,7 +4,7 @@ macro_rules! foo {
};
}
-#[path = foo!()] //~ ERROR malformed `path` attribute
+#[path = foo!()] //~ ERROR: malformed `path` attribute
mod abc {}
fn main() {}
diff --git a/src/tools/clippy/tests/ui/crashes/ice-96721.stderr b/src/tools/clippy/tests/ui/crashes/ice-96721.stderr
index 78c567b8e..712bd14c6 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-96721.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-96721.stderr
@@ -1,7 +1,7 @@
error: malformed `path` attribute input
--> $DIR/ice-96721.rs:7:1
|
-LL | #[path = foo!()] //~ ERROR malformed `path` attribute
+LL | #[path = foo!()]
| ^^^^^^^^^^^^^^^^ help: must be of the form: `#[path = "file"]`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/crashes/mut_mut_macro.rs b/src/tools/clippy/tests/ui/crashes/mut_mut_macro.rs
index a238e7896..92821b6ec 100644
--- a/src/tools/clippy/tests/ui/crashes/mut_mut_macro.rs
+++ b/src/tools/clippy/tests/ui/crashes/mut_mut_macro.rs
@@ -1,4 +1,4 @@
-#![deny(clippy::mut_mut, clippy::zero_ptr, clippy::cmp_nan)]
+#![deny(clippy::mut_mut, clippy::zero_ptr)]
#![allow(dead_code)]
// FIXME: compiletest + extern crates doesn't work together. To make this test work, it would need
@@ -8,13 +8,12 @@
// extern crate lazy_static;
// use std::collections::HashMap;
-/// ensure that we don't suggest `is_nan` and `is_null` inside constants
+/// ensure that we don't suggest `is_null` inside constants
/// FIXME: once const fn is stable, suggest these functions again in constants
const BAA: *const i32 = 0 as *const i32;
static mut BAR: *const i32 = BAA;
static mut FOO: *const i32 = 0 as *const i32;
-static mut BUH: bool = 42.0 < f32::NAN;
#[allow(unused_variables, unused_mut)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.stderr b/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.stderr
index 0b0e0ad26..37484f5eb 100644
--- a/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.stderr
+++ b/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.stderr
@@ -1,8 +1,8 @@
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes_impl_trait.rs:15:5
+ --> $DIR/needless_lifetimes_impl_trait.rs:15:12
|
LL | fn baz<'a>(&'a self) -> impl Foo + 'a {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
note: the lint level is defined here
--> $DIR/needless_lifetimes_impl_trait.rs:1:9
diff --git a/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.rs b/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.rs
index d6cd594d7..aa76688d8 100644
--- a/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.rs
+++ b/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.rs
@@ -1,4 +1,4 @@
-//@ignore-macos
+//@ignore-target-apple
#![feature(rustc_attrs)]
diff --git a/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.stderr b/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.stderr
deleted file mode 100644
index 3d79a115c..000000000
--- a/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.stderr
+++ /dev/null
@@ -1,11 +0,0 @@
-error: recursing into entrypoint `a`
- --> $DIR/entrypoint_recursion.rs:10:5
- |
-LL | a();
- | ^
- |
- = help: consider using another function for this recursion
- = note: `-D clippy::main-recursion` implied by `-D warnings`
-
-error: aborting due to previous error
-
diff --git a/src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs b/src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs
index a382135bb..32eba9695 100644
--- a/src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs
+++ b/src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs
@@ -1,5 +1,5 @@
//@compile-flags: -Clink-arg=-nostartfiles
-//@ignore-macos
+//@ignore-target-apple
#![feature(lang_items, start, libc)]
#![no_std]
diff --git a/src/tools/clippy/tests/ui/dbg_macro.rs b/src/tools/clippy/tests/ui/dbg_macro.rs
index 10788d404..6c63c0989 100644
--- a/src/tools/clippy/tests/ui/dbg_macro.rs
+++ b/src/tools/clippy/tests/ui/dbg_macro.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --test
#![warn(clippy::dbg_macro)]
fn foo(n: u32) -> u32 {
diff --git a/src/tools/clippy/tests/ui/dbg_macro.stderr b/src/tools/clippy/tests/ui/dbg_macro.stderr
index 530e76633..3d2926259 100644
--- a/src/tools/clippy/tests/ui/dbg_macro.stderr
+++ b/src/tools/clippy/tests/ui/dbg_macro.stderr
@@ -1,5 +1,5 @@
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:5:22
+ --> $DIR/dbg_macro.rs:4:22
|
LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n }
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -11,7 +11,7 @@ LL | if let Some(n) = n.checked_sub(4) { n } else { n }
| ~~~~~~~~~~~~~~~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:10:8
+ --> $DIR/dbg_macro.rs:9:8
|
LL | if dbg!(n <= 1) {
| ^^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL | if n <= 1 {
| ~~~~~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:11:9
+ --> $DIR/dbg_macro.rs:10:9
|
LL | dbg!(1)
| ^^^^^^^
@@ -33,7 +33,7 @@ LL | 1
|
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:13:9
+ --> $DIR/dbg_macro.rs:12:9
|
LL | dbg!(n * factorial(n - 1))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -44,7 +44,7 @@ LL | n * factorial(n - 1)
|
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:18:5
+ --> $DIR/dbg_macro.rs:17:5
|
LL | dbg!(42);
| ^^^^^^^^
@@ -55,7 +55,7 @@ LL | 42;
| ~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:19:5
+ --> $DIR/dbg_macro.rs:18:5
|
LL | dbg!(dbg!(dbg!(42)));
| ^^^^^^^^^^^^^^^^^^^^
@@ -66,7 +66,7 @@ LL | dbg!(dbg!(42));
| ~~~~~~~~~~~~~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:20:14
+ --> $DIR/dbg_macro.rs:19:14
|
LL | foo(3) + dbg!(factorial(4));
| ^^^^^^^^^^^^^^^^^^
@@ -77,7 +77,7 @@ LL | foo(3) + factorial(4);
| ~~~~~~~~~~~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:21:5
+ --> $DIR/dbg_macro.rs:20:5
|
LL | dbg!(1, 2, dbg!(3, 4));
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -88,7 +88,7 @@ LL | (1, 2, dbg!(3, 4));
| ~~~~~~~~~~~~~~~~~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:22:5
+ --> $DIR/dbg_macro.rs:21:5
|
LL | dbg!(1, 2, 3, 4, 5);
| ^^^^^^^^^^^^^^^^^^^
@@ -99,7 +99,7 @@ LL | (1, 2, 3, 4, 5);
| ~~~~~~~~~~~~~~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:42:5
+ --> $DIR/dbg_macro.rs:41:5
|
LL | dbg!();
| ^^^^^^^
@@ -111,7 +111,7 @@ LL +
|
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:44:13
+ --> $DIR/dbg_macro.rs:43:13
|
LL | let _ = dbg!();
| ^^^^^^
@@ -122,7 +122,7 @@ LL | let _ = ();
| ~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:45:9
+ --> $DIR/dbg_macro.rs:44:9
|
LL | bar(dbg!());
| ^^^^^^
@@ -133,7 +133,7 @@ LL | bar(());
| ~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:46:10
+ --> $DIR/dbg_macro.rs:45:10
|
LL | foo!(dbg!());
| ^^^^^^
@@ -144,7 +144,7 @@ LL | foo!(());
| ~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:47:16
+ --> $DIR/dbg_macro.rs:46:16
|
LL | foo2!(foo!(dbg!()));
| ^^^^^^
@@ -155,7 +155,7 @@ LL | foo2!(foo!(()));
| ~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:68:9
+ --> $DIR/dbg_macro.rs:67:9
|
LL | dbg!(2);
| ^^^^^^^
@@ -166,7 +166,7 @@ LL | 2;
| ~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:74:5
+ --> $DIR/dbg_macro.rs:73:5
|
LL | dbg!(1);
| ^^^^^^^
@@ -177,7 +177,7 @@ LL | 1;
| ~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:79:5
+ --> $DIR/dbg_macro.rs:78:5
|
LL | dbg!(1);
| ^^^^^^^
@@ -188,7 +188,7 @@ LL | 1;
| ~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:85:9
+ --> $DIR/dbg_macro.rs:84:9
|
LL | dbg!(1);
| ^^^^^^^
diff --git a/src/tools/clippy/tests/ui/declare_interior_mutable_const/enums.rs b/src/tools/clippy/tests/ui/declare_interior_mutable_const/enums.rs
index f44518694..a88bf7b21 100644
--- a/src/tools/clippy/tests/ui/declare_interior_mutable_const/enums.rs
+++ b/src/tools/clippy/tests/ui/declare_interior_mutable_const/enums.rs
@@ -9,7 +9,7 @@ enum OptionalCell {
}
// a constant with enums should be linted only when the used variant is unfrozen (#3962).
-const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(true)); //~ ERROR interior mutable
+const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(true)); //~ ERROR: interior mutable
const FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen;
const fn unfrozen_variant() -> OptionalCell {
@@ -20,7 +20,7 @@ const fn frozen_variant() -> OptionalCell {
OptionalCell::Frozen
}
-const UNFROZEN_VARIANT_FROM_FN: OptionalCell = unfrozen_variant(); //~ ERROR interior mutable
+const UNFROZEN_VARIANT_FROM_FN: OptionalCell = unfrozen_variant(); //~ ERROR: interior mutable
const FROZEN_VARIANT_FROM_FN: OptionalCell = frozen_variant();
enum NestedInnermost {
@@ -43,10 +43,11 @@ struct NestedOutermost {
// a constant with enums should be linted according to its value, no matter how structs involve.
const NESTED_UNFROZEN_VARIANT: NestedOutermost = NestedOutermost {
+ //~^ ERROR: interior mutable
outer: NestedOuter::NestedInner(NestedInner {
inner: NestedInnermost::Unfrozen(AtomicUsize::new(2)),
}),
-}; //~ ERROR interior mutable
+};
const NESTED_FROZEN_VARIANT: NestedOutermost = NestedOutermost {
outer: NestedOuter::NestedInner(NestedInner {
inner: NestedInnermost::Frozen,
@@ -56,11 +57,11 @@ const NESTED_FROZEN_VARIANT: NestedOutermost = NestedOutermost {
trait AssocConsts {
// When there's no default value, lint it only according to its type.
// Further details are on the corresponding code (`NonCopyConst::check_trait_item`).
- const TO_BE_UNFROZEN_VARIANT: OptionalCell; //~ ERROR interior mutable
- const TO_BE_FROZEN_VARIANT: OptionalCell; //~ ERROR interior mutable
+ const TO_BE_UNFROZEN_VARIANT: OptionalCell; //~ ERROR: interior mutable
+ const TO_BE_FROZEN_VARIANT: OptionalCell; //~ ERROR: interior mutable
// Lint default values accordingly.
- const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); //~ ERROR interior mutable
+ const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); //~ ERROR: interior mutable
const DEFAULTED_ON_FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen;
}
@@ -86,7 +87,7 @@ trait AssocTypes {
impl AssocTypes for u64 {
type ToBeUnfrozen = AtomicUsize;
- const TO_BE_UNFROZEN_VARIANT: Option<Self::ToBeUnfrozen> = Some(Self::ToBeUnfrozen::new(4)); //~ ERROR interior mutable
+ const TO_BE_UNFROZEN_VARIANT: Option<Self::ToBeUnfrozen> = Some(Self::ToBeUnfrozen::new(4)); //~ ERROR: interior mutable
const TO_BE_FROZEN_VARIANT: Option<Self::ToBeUnfrozen> = None;
}
@@ -98,25 +99,25 @@ enum BothOfCellAndGeneric<T> {
}
impl<T> BothOfCellAndGeneric<T> {
- const UNFROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mutable
+ const UNFROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR: interior mutable
// This is a false positive. The argument about this is on `is_value_unfrozen_raw`
- const GENERIC_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mutable
+ const GENERIC_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR: interior mutable
const FROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Frozen(5);
// This is what is likely to be a false negative when one tries to fix
// the `GENERIC_VARIANT` false positive.
- const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); //~ ERROR interior mutable
+ const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); //~ ERROR: interior mutable
}
// associated types here is basically the same as the one above.
trait BothOfCellAndGenericWithAssocType {
type AssocType;
- const UNFROZEN_VARIANT: BothOfCellAndGeneric<Self::AssocType> =
- BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mutable
- const GENERIC_VARIANT: BothOfCellAndGeneric<Self::AssocType> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mutable
+ const UNFROZEN_VARIANT: BothOfCellAndGeneric<Self::AssocType> = //~ ERROR: interior mutable
+ BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null()));
+ const GENERIC_VARIANT: BothOfCellAndGeneric<Self::AssocType> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR: interior mutable
const FROZEN_VARIANT: BothOfCellAndGeneric<Self::AssocType> = BothOfCellAndGeneric::Frozen(5);
}
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 84198d546..6070df749 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
@@ -1,7 +1,7 @@
error: a `const` item should never be interior mutable
--> $DIR/enums.rs:12:1
|
-LL | const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(true)); //~ ERROR interior mutable
+LL | const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(true));
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| make this a static item (maybe with lazy_static)
@@ -11,7 +11,7 @@ LL | const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(tru
error: a `const` item should never be interior mutable
--> $DIR/enums.rs:23:1
|
-LL | const UNFROZEN_VARIANT_FROM_FN: OptionalCell = unfrozen_variant(); //~ ERROR interior mutable
+LL | const UNFROZEN_VARIANT_FROM_FN: OptionalCell = unfrozen_variant();
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| make this a static item (maybe with lazy_static)
@@ -24,65 +24,66 @@ LL | const NESTED_UNFROZEN_VARIANT: NestedOutermost = NestedOutermost {
| |
| _make this a static item (maybe with lazy_static)
| |
+LL | |
LL | | outer: NestedOuter::NestedInner(NestedInner {
LL | | inner: NestedInnermost::Unfrozen(AtomicUsize::new(2)),
LL | | }),
-LL | | }; //~ ERROR interior mutable
+LL | | };
| |__^
error: a `const` item should never be interior mutable
- --> $DIR/enums.rs:59:5
+ --> $DIR/enums.rs:60:5
|
-LL | const TO_BE_UNFROZEN_VARIANT: OptionalCell; //~ ERROR interior mutable
+LL | const TO_BE_UNFROZEN_VARIANT: OptionalCell;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
- --> $DIR/enums.rs:60:5
+ --> $DIR/enums.rs:61:5
|
-LL | const TO_BE_FROZEN_VARIANT: OptionalCell; //~ ERROR interior mutable
+LL | const TO_BE_FROZEN_VARIANT: OptionalCell;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
- --> $DIR/enums.rs:63:5
+ --> $DIR/enums.rs:64:5
|
-LL | const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); //~ ERROR interior mutable
+LL | const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
- --> $DIR/enums.rs:89:5
+ --> $DIR/enums.rs:90:5
|
-LL | const TO_BE_UNFROZEN_VARIANT: Option<Self::ToBeUnfrozen> = Some(Self::ToBeUnfrozen::new(4)); //~ ERROR interior mutable
+LL | const TO_BE_UNFROZEN_VARIANT: Option<Self::ToBeUnfrozen> = Some(Self::ToBeUnfrozen::new(4));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
- --> $DIR/enums.rs:101:5
+ --> $DIR/enums.rs:102:5
|
-LL | const UNFROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mut...
+LL | const UNFROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
- --> $DIR/enums.rs:104:5
+ --> $DIR/enums.rs:105:5
|
-LL | const GENERIC_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mutable
+LL | const GENERIC_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Generic(std::ptr::null());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
- --> $DIR/enums.rs:110:5
+ --> $DIR/enums.rs:111:5
|
-LL | const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); //~ ERROR interior mutable
+LL | const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
- --> $DIR/enums.rs:117:5
+ --> $DIR/enums.rs:118:5
|
LL | / const UNFROZEN_VARIANT: BothOfCellAndGeneric<Self::AssocType> =
-LL | | BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mutable
+LL | | BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null()));
| |____________________________________________________________________^
error: a `const` item should never be interior mutable
- --> $DIR/enums.rs:119:5
+ --> $DIR/enums.rs:120:5
|
-LL | const GENERIC_VARIANT: BothOfCellAndGeneric<Self::AssocType> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mu...
+LL | const GENERIC_VARIANT: BothOfCellAndGeneric<Self::AssocType> = BothOfCellAndGeneric::Generic(std::ptr::null());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 12 previous errors
diff --git a/src/tools/clippy/tests/ui/declare_interior_mutable_const/others.rs b/src/tools/clippy/tests/ui/declare_interior_mutable_const/others.rs
index 896596b56..1cec29806 100644
--- a/src/tools/clippy/tests/ui/declare_interior_mutable_const/others.rs
+++ b/src/tools/clippy/tests/ui/declare_interior_mutable_const/others.rs
@@ -6,17 +6,17 @@ use std::fmt::Display;
use std::sync::atomic::AtomicUsize;
use std::sync::Once;
-const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable
-const CELL: Cell<usize> = Cell::new(6); //~ ERROR interior mutable
+const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR: interior mutable
+const CELL: Cell<usize> = Cell::new(6); //~ ERROR: interior mutable
const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec<AtomicUsize>, u8) = ([ATOMIC], Vec::new(), 7);
-//~^ ERROR interior mutable
+//~^ ERROR: interior mutable
macro_rules! declare_const {
($name:ident: $ty:ty = $e:expr) => {
const $name: $ty = $e;
};
}
-declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable
+declare_const!(_ONCE: Once = Once::new()); //~ ERROR: interior mutable
// const ATOMIC_REF: &AtomicUsize = &AtomicUsize::new(7); // This will simply trigger E0492.
@@ -24,12 +24,12 @@ const INTEGER: u8 = 8;
const STRING: String = String::new();
const STR: &str = "012345";
const COW: Cow<str> = Cow::Borrowed("abcdef");
-//^ note: a const item of Cow is used in the `postgres` package.
+// note: a const item of Cow is used in the `postgres` package.
const NO_ANN: &dyn Display = &70;
static STATIC_TUPLE: (AtomicUsize, String) = (ATOMIC, STRING);
-//^ there should be no lints on this line
+// there should be no lints on the line above line
mod issue_8493 {
use std::cell::Cell;
@@ -40,7 +40,7 @@ mod issue_8493 {
macro_rules! issue_8493 {
() => {
- const _BAZ: Cell<usize> = Cell::new(0); //~ ERROR interior mutable
+ const _BAZ: Cell<usize> = Cell::new(0);
static _FOOBAR: () = {
thread_local! {
static _VAR: Cell<i32> = const { Cell::new(0) };
@@ -49,7 +49,7 @@ mod issue_8493 {
};
}
- issue_8493!();
+ issue_8493!(); //~ ERROR: interior mutable
}
fn main() {}
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 1fd6d7322..0259f6a4a 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
@@ -1,7 +1,7 @@
error: a `const` item should never be interior mutable
--> $DIR/others.rs:9:1
|
-LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable
+LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5);
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| make this a static item (maybe with lazy_static)
@@ -11,7 +11,7 @@ LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable
error: a `const` item should never be interior mutable
--> $DIR/others.rs:10:1
|
-LL | const CELL: Cell<usize> = Cell::new(6); //~ ERROR interior mutable
+LL | const CELL: Cell<usize> = Cell::new(6);
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| make this a static item (maybe with lazy_static)
@@ -30,7 +30,7 @@ error: a `const` item should never be interior mutable
LL | const $name: $ty = $e;
| ^^^^^^^^^^^^^^^^^^^^^^
...
-LL | declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable
+LL | declare_const!(_ONCE: Once = Once::new());
| ----------------------------------------- in this macro invocation
|
= note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -38,7 +38,7 @@ LL | declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable
error: a `const` item should never be interior mutable
--> $DIR/others.rs:43:13
|
-LL | const _BAZ: Cell<usize> = Cell::new(0); //~ ERROR interior mutable
+LL | const _BAZ: Cell<usize> = Cell::new(0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | issue_8493!();
diff --git a/src/tools/clippy/tests/ui/declare_interior_mutable_const/traits.rs b/src/tools/clippy/tests/ui/declare_interior_mutable_const/traits.rs
index 256a336db..a6ccdd270 100644
--- a/src/tools/clippy/tests/ui/declare_interior_mutable_const/traits.rs
+++ b/src/tools/clippy/tests/ui/declare_interior_mutable_const/traits.rs
@@ -12,10 +12,10 @@ macro_rules! declare_const {
// a constant whose type is a concrete type should be linted at the definition site.
trait ConcreteTypes {
- const ATOMIC: AtomicUsize; //~ ERROR interior mutable
+ const ATOMIC: AtomicUsize; //~ ERROR: interior mutable
const INTEGER: u64;
const STRING: String;
- declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); //~ ERROR interior mutable
+ declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); //~ ERROR: interior mutable
}
impl ConcreteTypes for u64 {
@@ -40,7 +40,7 @@ trait GenericTypes<T, U> {
impl<T: ConstDefault> GenericTypes<T, AtomicUsize> for u64 {
const TO_REMAIN_GENERIC: T = T::DEFAULT;
- const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11); //~ ERROR interior mutable
+ const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11); //~ ERROR: interior mutable
}
// a helper type used below
@@ -65,8 +65,8 @@ impl<T: ConstDefault> AssocTypes for Vec<T> {
type ToBeGenericParam = T;
const TO_BE_FROZEN: Self::ToBeFrozen = 12;
- const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13); //~ ERROR interior mutable
- const WRAPPED_TO_BE_UNFROZEN: Wrapper<Self::ToBeUnfrozen> = Wrapper(AtomicUsize::new(14)); //~ ERROR interior mutable
+ const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13); //~ ERROR: interior mutable
+ const WRAPPED_TO_BE_UNFROZEN: Wrapper<Self::ToBeUnfrozen> = Wrapper(AtomicUsize::new(14)); //~ ERROR: interior mutable
const WRAPPED_TO_BE_GENERIC_PARAM: Wrapper<Self::ToBeGenericParam> = Wrapper(T::DEFAULT);
}
@@ -85,7 +85,7 @@ where
T: AssocTypesHelper<ToBeBounded = AtomicUsize>,
{
const NOT_BOUNDED: T::NotToBeBounded;
- const BOUNDED: T::ToBeBounded; //~ ERROR interior mutable
+ const BOUNDED: T::ToBeBounded; //~ ERROR: interior mutable
}
impl<T> AssocTypesFromGenericParam<T> for u64
@@ -113,8 +113,8 @@ impl SelfType for u64 {
impl SelfType for AtomicUsize {
// this (interior mutable `Self` const) exists in `parking_lot`.
// `const_trait_impl` will replace it in the future, hopefully.
- const SELF: Self = AtomicUsize::new(17); //~ ERROR interior mutable
- const WRAPPED_SELF: Option<Self> = Some(AtomicUsize::new(21)); //~ ERROR interior mutable
+ const SELF: Self = AtomicUsize::new(17); //~ ERROR: interior mutable
+ const WRAPPED_SELF: Option<Self> = Some(AtomicUsize::new(21)); //~ ERROR: interior mutable
}
// Even though a constant contains a generic type, if it also have an interior mutable type,
@@ -122,7 +122,7 @@ impl SelfType for AtomicUsize {
trait BothOfCellAndGeneric<T> {
// this is a false negative in the current implementation.
const DIRECT: Cell<T>;
- const INDIRECT: Cell<*const T>; //~ ERROR interior mutable
+ const INDIRECT: Cell<*const T>; //~ ERROR: interior mutable
}
impl<T: ConstDefault> BothOfCellAndGeneric<T> for u64 {
@@ -138,13 +138,13 @@ impl<T> Local<T>
where
T: ConstDefault + AssocTypesHelper<ToBeBounded = AtomicUsize>,
{
- const ATOMIC: AtomicUsize = AtomicUsize::new(18); //~ ERROR interior mutable
+ const ATOMIC: AtomicUsize = AtomicUsize::new(18); //~ ERROR: interior mutable
const COW: Cow<'static, str> = Cow::Borrowed("tuvwxy");
const GENERIC_TYPE: T = T::DEFAULT;
const ASSOC_TYPE: T::NotToBeBounded = T::NOT_TO_BE_BOUNDED;
- const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); //~ ERROR interior mutable
+ const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); //~ ERROR: interior mutable
}
fn main() {}
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 7debe059f..ef62919df 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
@@ -1,7 +1,7 @@
error: a `const` item should never be interior mutable
--> $DIR/traits.rs:15:5
|
-LL | const ATOMIC: AtomicUsize; //~ ERROR interior mutable
+LL | const ATOMIC: AtomicUsize;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings`
@@ -12,7 +12,7 @@ error: a `const` item should never be interior mutable
LL | const $name: $ty = $e;
| ^^^^^^^^^^^^^^^^^^^^^^
...
-LL | declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); //~ ERROR interior mutable
+LL | declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC);
| ---------------------------------------------------------- in this macro invocation
|
= note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -20,55 +20,55 @@ LL | declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); //~ ERROR i
error: a `const` item should never be interior mutable
--> $DIR/traits.rs:43:5
|
-LL | const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11); //~ ERROR interior mutable
+LL | const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/traits.rs:68:5
|
-LL | const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13); //~ ERROR interior mutable
+LL | const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/traits.rs:69:5
|
-LL | const WRAPPED_TO_BE_UNFROZEN: Wrapper<Self::ToBeUnfrozen> = Wrapper(AtomicUsize::new(14)); //~ ERROR interior mutable
+LL | const WRAPPED_TO_BE_UNFROZEN: Wrapper<Self::ToBeUnfrozen> = Wrapper(AtomicUsize::new(14));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/traits.rs:88:5
|
-LL | const BOUNDED: T::ToBeBounded; //~ ERROR interior mutable
+LL | const BOUNDED: T::ToBeBounded;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/traits.rs:116:5
|
-LL | const SELF: Self = AtomicUsize::new(17); //~ ERROR interior mutable
+LL | const SELF: Self = AtomicUsize::new(17);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/traits.rs:117:5
|
-LL | const WRAPPED_SELF: Option<Self> = Some(AtomicUsize::new(21)); //~ ERROR interior mutable
+LL | const WRAPPED_SELF: Option<Self> = Some(AtomicUsize::new(21));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/traits.rs:125:5
|
-LL | const INDIRECT: Cell<*const T>; //~ ERROR interior mutable
+LL | const INDIRECT: Cell<*const T>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/traits.rs:141:5
|
-LL | const ATOMIC: AtomicUsize = AtomicUsize::new(18); //~ ERROR interior mutable
+LL | const ATOMIC: AtomicUsize = AtomicUsize::new(18);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/traits.rs:147:5
|
-LL | const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); //~ ERROR interior mutable
+LL | const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 11 previous errors
diff --git a/src/tools/clippy/tests/ui/def_id_nocore.rs b/src/tools/clippy/tests/ui/def_id_nocore.rs
index f7819068a..da0816830 100644
--- a/src/tools/clippy/tests/ui/def_id_nocore.rs
+++ b/src/tools/clippy/tests/ui/def_id_nocore.rs
@@ -1,4 +1,4 @@
-//@ignore-macos
+//@ignore-target-apple
#![feature(no_core, lang_items, start)]
#![no_core]
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 9520efe63..02eb78060 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,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![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 cacbdb4a9..79a966983 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,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::default_numeric_fallback)]
#![allow(
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 fbabb8bcf..23272d07e 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,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![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 7bfc390e4..fb1491416 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,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![feature(lint_reasons)]
#![warn(clippy::default_numeric_fallback)]
diff --git a/src/tools/clippy/tests/ui/default_trait_access.fixed b/src/tools/clippy/tests/ui/default_trait_access.fixed
index bf5dca976..14eb6d572 100644
--- a/src/tools/clippy/tests/ui/default_trait_access.fixed
+++ b/src/tools/clippy/tests/ui/default_trait_access.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build: proc_macros.rs
+//@aux-build: proc_macros.rs:proc-macro
#![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 5e8e9ce85..aa2ced0a7 100644
--- a/src/tools/clippy/tests/ui/default_trait_access.rs
+++ b/src/tools/clippy/tests/ui/default_trait_access.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build: proc_macros.rs
+//@aux-build: proc_macros.rs:proc-macro
#![deny(clippy::default_trait_access)]
#![allow(dead_code, unused_imports)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/deref_addrof.fixed b/src/tools/clippy/tests/ui/deref_addrof.fixed
index b27d3bc10..0ecca1b8f 100644
--- a/src/tools/clippy/tests/ui/deref_addrof.fixed
+++ b/src/tools/clippy/tests/ui/deref_addrof.fixed
@@ -1,7 +1,7 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
-#![allow(clippy::return_self_not_must_use)]
+#![allow(clippy::return_self_not_must_use, clippy::useless_vec)]
#![warn(clippy::deref_addrof)]
extern crate proc_macros;
diff --git a/src/tools/clippy/tests/ui/deref_addrof.rs b/src/tools/clippy/tests/ui/deref_addrof.rs
index 825090c7c..9f91310e6 100644
--- a/src/tools/clippy/tests/ui/deref_addrof.rs
+++ b/src/tools/clippy/tests/ui/deref_addrof.rs
@@ -1,7 +1,7 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
-#![allow(clippy::return_self_not_must_use)]
+#![allow(clippy::return_self_not_must_use, clippy::useless_vec)]
#![warn(clippy::deref_addrof)]
extern crate proc_macros;
diff --git a/src/tools/clippy/tests/ui/deref_addrof_macro.rs b/src/tools/clippy/tests/ui/deref_addrof_macro.rs
index c7e60f365..ce4b94a73 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
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::deref_addrof)]
diff --git a/src/tools/clippy/tests/ui/derivable_impls.fixed b/src/tools/clippy/tests/ui/derivable_impls.fixed
index aa0efb85c..a10f3d010 100644
--- a/src/tools/clippy/tests/ui/derivable_impls.fixed
+++ b/src/tools/clippy/tests/ui/derivable_impls.fixed
@@ -268,4 +268,25 @@ impl Default for OtherGenericType {
}
}
+mod issue10158 {
+ pub trait T {}
+
+ #[derive(Default)]
+ pub struct S {}
+ impl T for S {}
+
+ pub struct Outer {
+ pub inner: Box<dyn T>,
+ }
+
+ impl Default for Outer {
+ fn default() -> Self {
+ Outer {
+ // Box::<S>::default() adjusts to Box<dyn T>
+ inner: Box::<S>::default(),
+ }
+ }
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/derivable_impls.rs b/src/tools/clippy/tests/ui/derivable_impls.rs
index 8dc999ad5..18cef1c5b 100644
--- a/src/tools/clippy/tests/ui/derivable_impls.rs
+++ b/src/tools/clippy/tests/ui/derivable_impls.rs
@@ -304,4 +304,25 @@ impl Default for OtherGenericType {
}
}
+mod issue10158 {
+ pub trait T {}
+
+ #[derive(Default)]
+ pub struct S {}
+ impl T for S {}
+
+ pub struct Outer {
+ pub inner: Box<dyn T>,
+ }
+
+ impl Default for Outer {
+ fn default() -> Self {
+ Outer {
+ // Box::<S>::default() adjusts to Box<dyn T>
+ inner: Box::<S>::default(),
+ }
+ }
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/derive.rs b/src/tools/clippy/tests/ui/derive.rs
index 6e0ce55f5..e01079bc9 100644
--- a/src/tools/clippy/tests/ui/derive.rs
+++ b/src/tools/clippy/tests/ui/derive.rs
@@ -1,4 +1,4 @@
-#![allow(dead_code)]
+#![allow(clippy::incorrect_clone_impl_on_copy_type, dead_code)]
#![warn(clippy::expl_impl_clone_on_copy)]
diff --git a/src/tools/clippy/tests/ui/disallowed_names.rs b/src/tools/clippy/tests/ui/disallowed_names.rs
index e937c49f3..5889f0443 100644
--- a/src/tools/clippy/tests/ui/disallowed_names.rs
+++ b/src/tools/clippy/tests/ui/disallowed_names.rs
@@ -1,5 +1,6 @@
#![allow(
dead_code,
+ clippy::needless_if,
clippy::similar_names,
clippy::single_match,
clippy::toplevel_ref_arg,
diff --git a/src/tools/clippy/tests/ui/disallowed_names.stderr b/src/tools/clippy/tests/ui/disallowed_names.stderr
index 78cb55096..9ab68b641 100644
--- a/src/tools/clippy/tests/ui/disallowed_names.stderr
+++ b/src/tools/clippy/tests/ui/disallowed_names.stderr
@@ -1,5 +1,5 @@
error: use of a disallowed/placeholder name `foo`
- --> $DIR/disallowed_names.rs:11:9
+ --> $DIR/disallowed_names.rs:12:9
|
LL | fn test(foo: ()) {}
| ^^^
@@ -7,79 +7,79 @@ LL | fn test(foo: ()) {}
= note: `-D clippy::disallowed-names` implied by `-D warnings`
error: use of a disallowed/placeholder name `foo`
- --> $DIR/disallowed_names.rs:14:9
+ --> $DIR/disallowed_names.rs:15:9
|
LL | let foo = 42;
| ^^^
error: use of a disallowed/placeholder name `baz`
- --> $DIR/disallowed_names.rs:15:9
+ --> $DIR/disallowed_names.rs:16:9
|
LL | let baz = 42;
| ^^^
error: use of a disallowed/placeholder name `quux`
- --> $DIR/disallowed_names.rs:16:9
+ --> $DIR/disallowed_names.rs:17:9
|
LL | let quux = 42;
| ^^^^
error: use of a disallowed/placeholder name `foo`
- --> $DIR/disallowed_names.rs:27:10
+ --> $DIR/disallowed_names.rs:28:10
|
LL | (foo, Some(baz), quux @ Some(_)) => (),
| ^^^
error: use of a disallowed/placeholder name `baz`
- --> $DIR/disallowed_names.rs:27:20
+ --> $DIR/disallowed_names.rs:28:20
|
LL | (foo, Some(baz), quux @ Some(_)) => (),
| ^^^
error: use of a disallowed/placeholder name `quux`
- --> $DIR/disallowed_names.rs:27:26
+ --> $DIR/disallowed_names.rs:28:26
|
LL | (foo, Some(baz), quux @ Some(_)) => (),
| ^^^^
error: use of a disallowed/placeholder name `foo`
- --> $DIR/disallowed_names.rs:32:19
+ --> $DIR/disallowed_names.rs:33:19
|
LL | fn issue_1647(mut foo: u8) {
| ^^^
error: use of a disallowed/placeholder name `baz`
- --> $DIR/disallowed_names.rs:33:13
+ --> $DIR/disallowed_names.rs:34:13
|
LL | let mut baz = 0;
| ^^^
error: use of a disallowed/placeholder name `quux`
- --> $DIR/disallowed_names.rs:34:21
+ --> $DIR/disallowed_names.rs:35:21
|
LL | if let Some(mut quux) = Some(42) {}
| ^^^^
error: use of a disallowed/placeholder name `baz`
- --> $DIR/disallowed_names.rs:38:13
+ --> $DIR/disallowed_names.rs:39:13
|
LL | let ref baz = 0;
| ^^^
error: use of a disallowed/placeholder name `quux`
- --> $DIR/disallowed_names.rs:39:21
+ --> $DIR/disallowed_names.rs:40:21
|
LL | if let Some(ref quux) = Some(42) {}
| ^^^^
error: use of a disallowed/placeholder name `baz`
- --> $DIR/disallowed_names.rs:43:17
+ --> $DIR/disallowed_names.rs:44:17
|
LL | let ref mut baz = 0;
| ^^^
error: use of a disallowed/placeholder name `quux`
- --> $DIR/disallowed_names.rs:44:25
+ --> $DIR/disallowed_names.rs:45:25
|
LL | if let Some(ref mut quux) = Some(42) {}
| ^^^^
diff --git a/src/tools/clippy/tests/ui/diverging_sub_expression.rs b/src/tools/clippy/tests/ui/diverging_sub_expression.rs
index e8f992e6d..9b1619baf 100644
--- a/src/tools/clippy/tests/ui/diverging_sub_expression.rs
+++ b/src/tools/clippy/tests/ui/diverging_sub_expression.rs
@@ -1,5 +1,6 @@
#![warn(clippy::diverging_sub_expression)]
#![allow(clippy::match_same_arms, clippy::overly_complex_bool_expr)]
+#![allow(clippy::nonminimal_bool)]
#[allow(clippy::empty_loop)]
fn diverge() -> ! {
loop {}
@@ -21,6 +22,7 @@ fn main() {
}
#[allow(dead_code, unused_variables)]
+#[rustfmt::skip]
fn foobar() {
loop {
let x = match 5 {
@@ -35,6 +37,20 @@ fn foobar() {
99 => return,
_ => true || panic!("boo"),
},
+ // lint blocks as well
+ 15 => true || { return; },
+ 16 => false || { return; },
+ // ... and when it's a single expression
+ 17 => true || { return },
+ 18 => false || { return },
+ // ... but not when there's both an expression and a statement
+ 19 => true || { _ = 1; return },
+ 20 => false || { _ = 1; return },
+ // ... or multiple statements
+ 21 => true || { _ = 1; return; },
+ 22 => false || { _ = 1; return; },
+ 23 => true || { return; true },
+ 24 => true || { return; true },
_ => true || break,
};
}
diff --git a/src/tools/clippy/tests/ui/diverging_sub_expression.stderr b/src/tools/clippy/tests/ui/diverging_sub_expression.stderr
index 51a3b0d97..243a5cf53 100644
--- a/src/tools/clippy/tests/ui/diverging_sub_expression.stderr
+++ b/src/tools/clippy/tests/ui/diverging_sub_expression.stderr
@@ -1,5 +1,5 @@
error: sub-expression diverges
- --> $DIR/diverging_sub_expression.rs:19:10
+ --> $DIR/diverging_sub_expression.rs:20:10
|
LL | b || diverge();
| ^^^^^^^^^
@@ -7,34 +7,66 @@ LL | b || diverge();
= note: `-D clippy::diverging-sub-expression` implied by `-D warnings`
error: sub-expression diverges
- --> $DIR/diverging_sub_expression.rs:20:10
+ --> $DIR/diverging_sub_expression.rs:21:10
|
LL | b || A.foo();
| ^^^^^^^
error: sub-expression diverges
- --> $DIR/diverging_sub_expression.rs:29:26
+ --> $DIR/diverging_sub_expression.rs:31:26
|
LL | 6 => true || return,
| ^^^^^^
error: sub-expression diverges
- --> $DIR/diverging_sub_expression.rs:30:26
+ --> $DIR/diverging_sub_expression.rs:32:26
|
LL | 7 => true || continue,
| ^^^^^^^^
error: sub-expression diverges
- --> $DIR/diverging_sub_expression.rs:33:26
+ --> $DIR/diverging_sub_expression.rs:35:26
|
LL | 3 => true || diverge(),
| ^^^^^^^^^
error: sub-expression diverges
- --> $DIR/diverging_sub_expression.rs:38:26
+ --> $DIR/diverging_sub_expression.rs:38:30
+ |
+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
+ |
+LL | 15 => true || { return; },
+ | ^^^^^^
+
+error: sub-expression diverges
+ --> $DIR/diverging_sub_expression.rs:42:30
+ |
+LL | 16 => false || { return; },
+ | ^^^^^^
+
+error: sub-expression diverges
+ --> $DIR/diverging_sub_expression.rs:44:29
+ |
+LL | 17 => true || { return },
+ | ^^^^^^
+
+error: sub-expression diverges
+ --> $DIR/diverging_sub_expression.rs:45:30
+ |
+LL | 18 => false || { return },
+ | ^^^^^^
+
+error: sub-expression diverges
+ --> $DIR/diverging_sub_expression.rs:54:26
|
LL | _ => true || break,
| ^^^^^
-error: aborting due to 6 previous errors
+error: aborting due to 11 previous errors
diff --git a/src/tools/clippy/tests/ui/doc/doc-fixable.fixed b/src/tools/clippy/tests/ui/doc/doc-fixable.fixed
index d3aa2816c..14444df4c 100644
--- a/src/tools/clippy/tests/ui/doc/doc-fixable.fixed
+++ b/src/tools/clippy/tests/ui/doc/doc-fixable.fixed
@@ -60,6 +60,7 @@ fn test_units() {
/// GitHub GitLab
/// IPv4 IPv6
/// ClojureScript CoffeeScript JavaScript PureScript TypeScript
+/// WebAssembly
/// NaN NaNs
/// OAuth GraphQL
/// OCaml
diff --git a/src/tools/clippy/tests/ui/doc/doc-fixable.rs b/src/tools/clippy/tests/ui/doc/doc-fixable.rs
index d1e7d8017..542d33b13 100644
--- a/src/tools/clippy/tests/ui/doc/doc-fixable.rs
+++ b/src/tools/clippy/tests/ui/doc/doc-fixable.rs
@@ -60,6 +60,7 @@ fn test_units() {
/// GitHub GitLab
/// IPv4 IPv6
/// ClojureScript CoffeeScript JavaScript PureScript TypeScript
+/// WebAssembly
/// NaN NaNs
/// OAuth GraphQL
/// OCaml
diff --git a/src/tools/clippy/tests/ui/doc/doc-fixable.stderr b/src/tools/clippy/tests/ui/doc/doc-fixable.stderr
index 6c67c903c..94ef43afc 100644
--- a/src/tools/clippy/tests/ui/doc/doc-fixable.stderr
+++ b/src/tools/clippy/tests/ui/doc/doc-fixable.stderr
@@ -132,7 +132,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it`
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:74:5
+ --> $DIR/doc-fixable.rs:75:5
|
LL | /// be_sure_we_got_to_the_end_of_it
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -143,7 +143,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it`
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:91:5
+ --> $DIR/doc-fixable.rs:92:5
|
LL | /// be_sure_we_got_to_the_end_of_it
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -154,7 +154,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it`
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:99:8
+ --> $DIR/doc-fixable.rs:100:8
|
LL | /// ## CamelCaseThing
| ^^^^^^^^^^^^^^
@@ -165,7 +165,7 @@ LL | /// ## `CamelCaseThing`
| ~~~~~~~~~~~~~~~~
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:102:7
+ --> $DIR/doc-fixable.rs:103:7
|
LL | /// # CamelCaseThing
| ^^^^^^^^^^^^^^
@@ -176,7 +176,7 @@ LL | /// # `CamelCaseThing`
| ~~~~~~~~~~~~~~~~
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:104:22
+ --> $DIR/doc-fixable.rs:105:22
|
LL | /// Not a title #897 CamelCaseThing
| ^^^^^^^^^^^^^^
@@ -187,7 +187,7 @@ LL | /// Not a title #897 `CamelCaseThing`
| ~~~~~~~~~~~~~~~~
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:105:5
+ --> $DIR/doc-fixable.rs:106:5
|
LL | /// be_sure_we_got_to_the_end_of_it
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -198,7 +198,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it`
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:112:5
+ --> $DIR/doc-fixable.rs:113:5
|
LL | /// be_sure_we_got_to_the_end_of_it
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -209,7 +209,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it`
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:125:5
+ --> $DIR/doc-fixable.rs:126:5
|
LL | /// be_sure_we_got_to_the_end_of_it
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -220,7 +220,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it`
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:136:43
+ --> $DIR/doc-fixable.rs:137:43
|
LL | /** E.g., serialization of an empty list: FooBar
| ^^^^^^
@@ -231,7 +231,7 @@ LL | /** E.g., serialization of an empty list: `FooBar`
| ~~~~~~~~
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:141:5
+ --> $DIR/doc-fixable.rs:142:5
|
LL | And BarQuz too.
| ^^^^^^
@@ -242,7 +242,7 @@ LL | And `BarQuz` too.
| ~~~~~~~~
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:142:1
+ --> $DIR/doc-fixable.rs:143:1
|
LL | be_sure_we_got_to_the_end_of_it
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -253,7 +253,7 @@ LL | `be_sure_we_got_to_the_end_of_it`
|
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:147:43
+ --> $DIR/doc-fixable.rs:148:43
|
LL | /** E.g., serialization of an empty list: FooBar
| ^^^^^^
@@ -264,7 +264,7 @@ LL | /** E.g., serialization of an empty list: `FooBar`
| ~~~~~~~~
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:152:5
+ --> $DIR/doc-fixable.rs:153:5
|
LL | And BarQuz too.
| ^^^^^^
@@ -275,7 +275,7 @@ LL | And `BarQuz` too.
| ~~~~~~~~
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:153:1
+ --> $DIR/doc-fixable.rs:154:1
|
LL | be_sure_we_got_to_the_end_of_it
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -286,7 +286,7 @@ LL | `be_sure_we_got_to_the_end_of_it`
|
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:164:5
+ --> $DIR/doc-fixable.rs:165:5
|
LL | /// be_sure_we_got_to_the_end_of_it
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -297,7 +297,7 @@ LL | /// `be_sure_we_got_to_the_end_of_it`
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: item in documentation is missing backticks
- --> $DIR/doc-fixable.rs:183:22
+ --> $DIR/doc-fixable.rs:184:22
|
LL | /// An iterator over mycrate::Collection's values.
| ^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/doc/needless_doctest_main.rs b/src/tools/clippy/tests/ui/doc/needless_doctest_main.rs
new file mode 100644
index 000000000..f1a2c0575
--- /dev/null
+++ b/src/tools/clippy/tests/ui/doc/needless_doctest_main.rs
@@ -0,0 +1,20 @@
+#![warn(clippy::needless_doctest_main)]
+//! issue 10491:
+//! ```rust,no_test
+//! use std::collections::HashMap;
+//!
+//! fn main() {
+//! let mut m = HashMap::new();
+//! m.insert(1u32, 2u32);
+//! }
+//! ```
+
+/// some description here
+/// ```rust,no_test
+/// fn main() {
+/// foo()
+/// }
+/// ```
+fn foo() {}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/doc_unsafe.rs b/src/tools/clippy/tests/ui/doc_unsafe.rs
index 0c8eac5cc..d21b046f1 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
+//@aux-build:proc_macros.rs:proc-macro
#![allow(clippy::let_unit_value)]
diff --git a/src/tools/clippy/tests/ui/double_comparison.fixed b/src/tools/clippy/tests/ui/double_comparison.fixed
index c80ff671a..f8ca92ef0 100644
--- a/src/tools/clippy/tests/ui/double_comparison.fixed
+++ b/src/tools/clippy/tests/ui/double_comparison.fixed
@@ -1,4 +1,5 @@
//@run-rustfix
+#![allow(clippy::needless_if)]
fn main() {
let x = 1;
diff --git a/src/tools/clippy/tests/ui/double_comparison.rs b/src/tools/clippy/tests/ui/double_comparison.rs
index bc78694aa..47ff87bea 100644
--- a/src/tools/clippy/tests/ui/double_comparison.rs
+++ b/src/tools/clippy/tests/ui/double_comparison.rs
@@ -1,4 +1,5 @@
//@run-rustfix
+#![allow(clippy::needless_if)]
fn main() {
let x = 1;
diff --git a/src/tools/clippy/tests/ui/double_comparison.stderr b/src/tools/clippy/tests/ui/double_comparison.stderr
index 05ef4e25f..4df1c28ac 100644
--- a/src/tools/clippy/tests/ui/double_comparison.stderr
+++ b/src/tools/clippy/tests/ui/double_comparison.stderr
@@ -1,5 +1,5 @@
error: this binary expression can be simplified
- --> $DIR/double_comparison.rs:6:8
+ --> $DIR/double_comparison.rs:7:8
|
LL | if x == y || x < y {
| ^^^^^^^^^^^^^^^ help: try: `x <= y`
@@ -7,43 +7,43 @@ LL | if x == y || x < y {
= note: `-D clippy::double-comparisons` implied by `-D warnings`
error: this binary expression can be simplified
- --> $DIR/double_comparison.rs:9:8
+ --> $DIR/double_comparison.rs:10:8
|
LL | if x < y || x == y {
| ^^^^^^^^^^^^^^^ help: try: `x <= y`
error: this binary expression can be simplified
- --> $DIR/double_comparison.rs:12:8
+ --> $DIR/double_comparison.rs:13:8
|
LL | if x == y || x > y {
| ^^^^^^^^^^^^^^^ help: try: `x >= y`
error: this binary expression can be simplified
- --> $DIR/double_comparison.rs:15:8
+ --> $DIR/double_comparison.rs:16:8
|
LL | if x > y || x == y {
| ^^^^^^^^^^^^^^^ help: try: `x >= y`
error: this binary expression can be simplified
- --> $DIR/double_comparison.rs:18:8
+ --> $DIR/double_comparison.rs:19:8
|
LL | if x < y || x > y {
| ^^^^^^^^^^^^^^ help: try: `x != y`
error: this binary expression can be simplified
- --> $DIR/double_comparison.rs:21:8
+ --> $DIR/double_comparison.rs:22:8
|
LL | if x > y || x < y {
| ^^^^^^^^^^^^^^ help: try: `x != y`
error: this binary expression can be simplified
- --> $DIR/double_comparison.rs:24:8
+ --> $DIR/double_comparison.rs:25:8
|
LL | if x <= y && x >= y {
| ^^^^^^^^^^^^^^^^ help: try: `x == y`
error: this binary expression can be simplified
- --> $DIR/double_comparison.rs:27:8
+ --> $DIR/double_comparison.rs:28:8
|
LL | if x >= y && x <= y {
| ^^^^^^^^^^^^^^^^ help: try: `x == y`
diff --git a/src/tools/clippy/tests/ui/drain_collect.fixed b/src/tools/clippy/tests/ui/drain_collect.fixed
new file mode 100644
index 000000000..11001bd31
--- /dev/null
+++ b/src/tools/clippy/tests/ui/drain_collect.fixed
@@ -0,0 +1,77 @@
+//@run-rustfix
+
+#![deny(clippy::drain_collect)]
+#![allow(dead_code)]
+
+use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
+
+fn binaryheap(b: &mut BinaryHeap<i32>) -> BinaryHeap<i32> {
+ std::mem::take(b)
+}
+
+fn binaryheap_dont_lint(b: &mut BinaryHeap<i32>) -> HashSet<i32> {
+ b.drain().collect()
+}
+
+fn hashmap(b: &mut HashMap<i32, i32>) -> HashMap<i32, i32> {
+ std::mem::take(b)
+}
+
+fn hashmap_dont_lint(b: &mut HashMap<i32, i32>) -> Vec<(i32, i32)> {
+ b.drain().collect()
+}
+
+fn hashset(b: &mut HashSet<i32>) -> HashSet<i32> {
+ std::mem::take(b)
+}
+
+fn hashset_dont_lint(b: &mut HashSet<i32>) -> Vec<i32> {
+ b.drain().collect()
+}
+
+fn vecdeque(b: &mut VecDeque<i32>) -> VecDeque<i32> {
+ std::mem::take(b)
+}
+
+fn vecdeque_dont_lint(b: &mut VecDeque<i32>) -> HashSet<i32> {
+ b.drain(..).collect()
+}
+
+fn vec(b: &mut Vec<i32>) -> Vec<i32> {
+ std::mem::take(b)
+}
+
+fn vec2(b: &mut Vec<i32>) -> Vec<i32> {
+ std::mem::take(b)
+}
+
+fn vec3(b: &mut Vec<i32>) -> Vec<i32> {
+ std::mem::take(b)
+}
+
+fn vec4(b: &mut Vec<i32>) -> Vec<i32> {
+ std::mem::take(b)
+}
+
+fn vec_no_reborrow() -> Vec<i32> {
+ let mut b = vec![1, 2, 3];
+ std::mem::take(&mut b)
+}
+
+fn vec_dont_lint(b: &mut Vec<i32>) -> HashSet<i32> {
+ b.drain(..).collect()
+}
+
+fn string(b: &mut String) -> String {
+ std::mem::take(b)
+}
+
+fn string_dont_lint(b: &mut String) -> HashSet<char> {
+ b.drain(..).collect()
+}
+
+fn not_whole_length(v: &mut Vec<i32>) -> Vec<i32> {
+ v.drain(1..).collect()
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/drain_collect.rs b/src/tools/clippy/tests/ui/drain_collect.rs
new file mode 100644
index 000000000..373a3ca35
--- /dev/null
+++ b/src/tools/clippy/tests/ui/drain_collect.rs
@@ -0,0 +1,77 @@
+//@run-rustfix
+
+#![deny(clippy::drain_collect)]
+#![allow(dead_code)]
+
+use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
+
+fn binaryheap(b: &mut BinaryHeap<i32>) -> BinaryHeap<i32> {
+ b.drain().collect()
+}
+
+fn binaryheap_dont_lint(b: &mut BinaryHeap<i32>) -> HashSet<i32> {
+ b.drain().collect()
+}
+
+fn hashmap(b: &mut HashMap<i32, i32>) -> HashMap<i32, i32> {
+ b.drain().collect()
+}
+
+fn hashmap_dont_lint(b: &mut HashMap<i32, i32>) -> Vec<(i32, i32)> {
+ b.drain().collect()
+}
+
+fn hashset(b: &mut HashSet<i32>) -> HashSet<i32> {
+ b.drain().collect()
+}
+
+fn hashset_dont_lint(b: &mut HashSet<i32>) -> Vec<i32> {
+ b.drain().collect()
+}
+
+fn vecdeque(b: &mut VecDeque<i32>) -> VecDeque<i32> {
+ b.drain(..).collect()
+}
+
+fn vecdeque_dont_lint(b: &mut VecDeque<i32>) -> HashSet<i32> {
+ b.drain(..).collect()
+}
+
+fn vec(b: &mut Vec<i32>) -> Vec<i32> {
+ b.drain(..).collect()
+}
+
+fn vec2(b: &mut Vec<i32>) -> Vec<i32> {
+ b.drain(0..).collect()
+}
+
+fn vec3(b: &mut Vec<i32>) -> Vec<i32> {
+ b.drain(..b.len()).collect()
+}
+
+fn vec4(b: &mut Vec<i32>) -> Vec<i32> {
+ b.drain(0..b.len()).collect()
+}
+
+fn vec_no_reborrow() -> Vec<i32> {
+ let mut b = vec![1, 2, 3];
+ b.drain(..).collect()
+}
+
+fn vec_dont_lint(b: &mut Vec<i32>) -> HashSet<i32> {
+ b.drain(..).collect()
+}
+
+fn string(b: &mut String) -> String {
+ b.drain(..).collect()
+}
+
+fn string_dont_lint(b: &mut String) -> HashSet<char> {
+ b.drain(..).collect()
+}
+
+fn not_whole_length(v: &mut Vec<i32>) -> Vec<i32> {
+ v.drain(1..).collect()
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/drain_collect.stderr b/src/tools/clippy/tests/ui/drain_collect.stderr
new file mode 100644
index 000000000..0792f0254
--- /dev/null
+++ b/src/tools/clippy/tests/ui/drain_collect.stderr
@@ -0,0 +1,68 @@
+error: you seem to be trying to move all elements into a new `BinaryHeap`
+ --> $DIR/drain_collect.rs:9: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
+ |
+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
+ |
+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
+ |
+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
+ |
+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
+ |
+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
+ |
+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
+ |
+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
+ |
+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
+ |
+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
+ |
+LL | b.drain(..).collect()
+ | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `std::mem::take(b)`
+
+error: aborting due to 10 previous errors
+
diff --git a/src/tools/clippy/tests/ui/else_if_without_else.rs b/src/tools/clippy/tests/ui/else_if_without_else.rs
index 879b3ac39..eb5e22665 100644
--- a/src/tools/clippy/tests/ui/else_if_without_else.rs
+++ b/src/tools/clippy/tests/ui/else_if_without_else.rs
@@ -43,7 +43,7 @@ fn main() {
if bla1() {
println!("if");
} else if bla2() {
- //~ ERROR else if without else
+ //~^ ERROR: `if` expression with an `else if`, but without a final `else`
println!("else if");
}
@@ -52,7 +52,7 @@ fn main() {
} else if bla2() {
println!("else if 1");
} else if bla3() {
- //~ ERROR else if without else
+ //~^ ERROR: `if` expression with an `else if`, but without a final `else`
println!("else if 2");
}
}
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 90ccfb4fa..11baf7544 100644
--- a/src/tools/clippy/tests/ui/else_if_without_else.stderr
+++ b/src/tools/clippy/tests/ui/else_if_without_else.stderr
@@ -3,7 +3,7 @@ error: `if` expression with an `else if`, but without a final `else`
|
LL | } else if bla2() {
| ____________^
-LL | | //~ ERROR else if without else
+LL | |
LL | | println!("else if");
LL | | }
| |_____^
@@ -16,7 +16,7 @@ error: `if` expression with an `else if`, but without a final `else`
|
LL | } else if bla3() {
| ____________^
-LL | | //~ ERROR else if without else
+LL | |
LL | | println!("else if 2");
LL | | }
| |_____^
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 e843770f5..cc36ce5f4 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,4 +1,7 @@
-//@aux-build:proc_macro_attr.rs
+//@aux-build:proc_macro_attr.rs:proc-macro
+// Flaky test, see https://github.com/rust-lang/rust/issues/113585.
+//@ignore-32bit
+//@ignore-64bit
#![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_outer_attribute.rs b/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs
index 269e66ea0..bc54e0fd2 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,4 +1,7 @@
-//@aux-build:proc_macro_attr.rs
+//@aux-build:proc_macro_attr.rs:proc-macro
+// Flaky test, see https://github.com/rust-lang/rust/issues/113585.
+//@ignore-32bit
+//@ignore-64bit
#![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_loop.rs b/src/tools/clippy/tests/ui/empty_loop.rs
index 54e8fb490..f1a55415c 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
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::empty_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 d564b2d24..f9ab443df 100644
--- a/src/tools/clippy/tests/ui/empty_loop_no_std.rs
+++ b/src/tools/clippy/tests/ui/empty_loop_no_std.rs
@@ -1,5 +1,5 @@
//@compile-flags: -Clink-arg=-nostartfiles
-//@ignore-macos
+//@ignore-target-apple
#![warn(clippy::empty_loop)]
#![feature(lang_items, start, libc)]
diff --git a/src/tools/clippy/tests/ui/endian_bytes.rs b/src/tools/clippy/tests/ui/endian_bytes.rs
new file mode 100644
index 000000000..6bf014fc8
--- /dev/null
+++ b/src/tools/clippy/tests/ui/endian_bytes.rs
@@ -0,0 +1,127 @@
+#![allow(unused)]
+#![allow(clippy::diverging_sub_expression)]
+#![no_main]
+
+macro_rules! fn_body {
+ () => {
+ 2u8.to_ne_bytes();
+ 2i8.to_ne_bytes();
+ 2u16.to_ne_bytes();
+ 2i16.to_ne_bytes();
+ 2u32.to_ne_bytes();
+ 2i32.to_ne_bytes();
+ 2u64.to_ne_bytes();
+ 2i64.to_ne_bytes();
+ 2u128.to_ne_bytes();
+ 2i128.to_ne_bytes();
+ 2.0f32.to_ne_bytes();
+ 2.0f64.to_ne_bytes();
+ 2usize.to_ne_bytes();
+ 2isize.to_ne_bytes();
+ u8::from_ne_bytes(todo!());
+ i8::from_ne_bytes(todo!());
+ u16::from_ne_bytes(todo!());
+ i16::from_ne_bytes(todo!());
+ u32::from_ne_bytes(todo!());
+ i32::from_ne_bytes(todo!());
+ u64::from_ne_bytes(todo!());
+ i64::from_ne_bytes(todo!());
+ u128::from_ne_bytes(todo!());
+ i128::from_ne_bytes(todo!());
+ usize::from_ne_bytes(todo!());
+ isize::from_ne_bytes(todo!());
+ f32::from_ne_bytes(todo!());
+ f64::from_ne_bytes(todo!());
+
+ 2u8.to_le_bytes();
+ 2i8.to_le_bytes();
+ 2u16.to_le_bytes();
+ 2i16.to_le_bytes();
+ 2u32.to_le_bytes();
+ 2i32.to_le_bytes();
+ 2u64.to_le_bytes();
+ 2i64.to_le_bytes();
+ 2u128.to_le_bytes();
+ 2i128.to_le_bytes();
+ 2.0f32.to_le_bytes();
+ 2.0f64.to_le_bytes();
+ 2usize.to_le_bytes();
+ 2isize.to_le_bytes();
+ u8::from_le_bytes(todo!());
+ i8::from_le_bytes(todo!());
+ u16::from_le_bytes(todo!());
+ i16::from_le_bytes(todo!());
+ u32::from_le_bytes(todo!());
+ i32::from_le_bytes(todo!());
+ u64::from_le_bytes(todo!());
+ i64::from_le_bytes(todo!());
+ u128::from_le_bytes(todo!());
+ i128::from_le_bytes(todo!());
+ usize::from_le_bytes(todo!());
+ isize::from_le_bytes(todo!());
+ f32::from_le_bytes(todo!());
+ f64::from_le_bytes(todo!());
+ };
+}
+
+// bless breaks if I use fn_body too much (oops)
+macro_rules! fn_body_smol {
+ () => {
+ 2u8.to_ne_bytes();
+ u8::from_ne_bytes(todo!());
+
+ 2u8.to_le_bytes();
+ u8::from_le_bytes(todo!());
+
+ 2u8.to_be_bytes();
+ u8::from_be_bytes(todo!());
+ };
+}
+
+#[rustfmt::skip]
+#[warn(clippy::host_endian_bytes)]
+fn host() { fn_body!(); }
+
+#[rustfmt::skip]
+#[warn(clippy::little_endian_bytes)]
+fn little() { fn_body!(); }
+
+#[rustfmt::skip]
+#[warn(clippy::big_endian_bytes)]
+fn big() { fn_body!(); }
+
+#[rustfmt::skip]
+#[warn(clippy::host_endian_bytes)]
+#[warn(clippy::big_endian_bytes)]
+fn host_encourage_little() { fn_body_smol!(); }
+
+#[rustfmt::skip]
+#[warn(clippy::host_endian_bytes)]
+#[warn(clippy::little_endian_bytes)]
+fn host_encourage_big() { fn_body_smol!(); }
+
+#[rustfmt::skip]
+#[warn(clippy::host_endian_bytes)]
+#[warn(clippy::little_endian_bytes)]
+#[warn(clippy::big_endian_bytes)]
+fn no_help() { fn_body_smol!(); }
+
+#[rustfmt::skip]
+#[warn(clippy::little_endian_bytes)]
+#[warn(clippy::big_endian_bytes)]
+fn little_encourage_host() { fn_body_smol!(); }
+
+#[rustfmt::skip]
+#[warn(clippy::host_endian_bytes)]
+#[warn(clippy::little_endian_bytes)]
+fn little_encourage_big() { fn_body_smol!(); }
+
+#[rustfmt::skip]
+#[warn(clippy::big_endian_bytes)]
+#[warn(clippy::little_endian_bytes)]
+fn big_encourage_host() { fn_body_smol!(); }
+
+#[rustfmt::skip]
+#[warn(clippy::host_endian_bytes)]
+#[warn(clippy::big_endian_bytes)]
+fn big_encourage_little() { fn_body_smol!(); }
diff --git a/src/tools/clippy/tests/ui/endian_bytes.stderr b/src/tools/clippy/tests/ui/endian_bytes.stderr
new file mode 100644
index 000000000..5e64ea5b5
--- /dev/null
+++ b/src/tools/clippy/tests/ui/endian_bytes.stderr
@@ -0,0 +1,1031 @@
+error: usage of the `u8::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:7:9
+ |
+LL | 2u8.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: `-D clippy::host-endian-bytes` implied by `-D warnings`
+ = 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
+ --> $DIR/endian_bytes.rs:8:9
+ |
+LL | 2i8.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u16::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:9:9
+ |
+LL | 2u16.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `i16::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:10:9
+ |
+LL | 2i16.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u32::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:11:9
+ |
+LL | 2u32.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `i32::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:12:9
+ |
+LL | 2i32.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u64::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:13:9
+ |
+LL | 2u64.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `i64::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:14:9
+ |
+LL | 2i64.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u128::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:15:9
+ |
+LL | 2u128.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `i128::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:16:9
+ |
+LL | 2i128.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `f32::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:17:9
+ |
+LL | 2.0f32.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `f64::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:18:9
+ |
+LL | 2.0f64.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `usize::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:19:9
+ |
+LL | 2usize.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `isize::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:20:9
+ |
+LL | 2isize.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:21:9
+ |
+LL | u8::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `i8::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:22:9
+ |
+LL | i8::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u16::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:23:9
+ |
+LL | u16::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `i16::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:24:9
+ |
+LL | i16::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u32::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:25:9
+ |
+LL | u32::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `i32::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:26:9
+ |
+LL | i32::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u64::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:27:9
+ |
+LL | u64::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `i64::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:28:9
+ |
+LL | i64::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u128::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:29:9
+ |
+LL | u128::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `i128::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:30:9
+ |
+LL | i128::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `usize::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:31:9
+ |
+LL | usize::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `isize::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:32:9
+ |
+LL | isize::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `f32::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:33:9
+ |
+LL | f32::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `f64::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:34:9
+ |
+LL | f64::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: specify the desired endianness explicitly
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:36:9
+ |
+LL | 2u8.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: `-D clippy::little-endian-bytes` implied by `-D warnings`
+ = 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
+ --> $DIR/endian_bytes.rs:37:9
+ |
+LL | 2i8.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u16::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:38:9
+ |
+LL | 2u16.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `i16::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:39:9
+ |
+LL | 2i16.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u32::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:40:9
+ |
+LL | 2u32.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `i32::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:41:9
+ |
+LL | 2i32.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u64::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:42:9
+ |
+LL | 2u64.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `i64::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:43:9
+ |
+LL | 2i64.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u128::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:44:9
+ |
+LL | 2u128.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `i128::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:45:9
+ |
+LL | 2i128.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `f32::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:46:9
+ |
+LL | 2.0f32.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `f64::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:47:9
+ |
+LL | 2.0f64.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `usize::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:48:9
+ |
+LL | 2usize.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `isize::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:49:9
+ |
+LL | 2isize.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_le_bytes`
+ --> $DIR/endian_bytes.rs:50:9
+ |
+LL | u8::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `i8::from_le_bytes`
+ --> $DIR/endian_bytes.rs:51:9
+ |
+LL | i8::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u16::from_le_bytes`
+ --> $DIR/endian_bytes.rs:52:9
+ |
+LL | u16::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `i16::from_le_bytes`
+ --> $DIR/endian_bytes.rs:53:9
+ |
+LL | i16::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u32::from_le_bytes`
+ --> $DIR/endian_bytes.rs:54:9
+ |
+LL | u32::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `i32::from_le_bytes`
+ --> $DIR/endian_bytes.rs:55:9
+ |
+LL | i32::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u64::from_le_bytes`
+ --> $DIR/endian_bytes.rs:56:9
+ |
+LL | u64::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `i64::from_le_bytes`
+ --> $DIR/endian_bytes.rs:57:9
+ |
+LL | i64::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u128::from_le_bytes`
+ --> $DIR/endian_bytes.rs:58:9
+ |
+LL | u128::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `i128::from_le_bytes`
+ --> $DIR/endian_bytes.rs:59:9
+ |
+LL | i128::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `usize::from_le_bytes`
+ --> $DIR/endian_bytes.rs:60:9
+ |
+LL | usize::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `isize::from_le_bytes`
+ --> $DIR/endian_bytes.rs:61:9
+ |
+LL | isize::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `f32::from_le_bytes`
+ --> $DIR/endian_bytes.rs:62:9
+ |
+LL | f32::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `f64::from_le_bytes`
+ --> $DIR/endian_bytes.rs:63:9
+ |
+LL | f64::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little() { fn_body!(); }
+ | ---------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:70:9
+ |
+LL | 2u8.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn host_encourage_little() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::to_le_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:71:9
+ |
+LL | u8::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host_encourage_little() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::from_le_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_be_bytes` method
+ --> $DIR/endian_bytes.rs:76:9
+ |
+LL | 2u8.to_be_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn host_encourage_little() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::to_le_bytes` instead
+ = note: `-D clippy::big-endian-bytes` implied by `-D warnings`
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_be_bytes`
+ --> $DIR/endian_bytes.rs:77:9
+ |
+LL | u8::from_be_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host_encourage_little() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::from_le_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:70:9
+ |
+LL | 2u8.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn host_encourage_big() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::to_be_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:71:9
+ |
+LL | u8::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host_encourage_big() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::from_be_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:73:9
+ |
+LL | 2u8.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn host_encourage_big() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::to_be_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_le_bytes`
+ --> $DIR/endian_bytes.rs:74:9
+ |
+LL | u8::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn host_encourage_big() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::from_be_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:70:9
+ |
+LL | 2u8.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn no_help() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:71:9
+ |
+LL | u8::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn no_help() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:73:9
+ |
+LL | 2u8.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn no_help() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_le_bytes`
+ --> $DIR/endian_bytes.rs:74:9
+ |
+LL | u8::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn no_help() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_be_bytes` method
+ --> $DIR/endian_bytes.rs:76:9
+ |
+LL | 2u8.to_be_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn no_help() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_be_bytes`
+ --> $DIR/endian_bytes.rs:77:9
+ |
+LL | u8::from_be_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn no_help() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:73:9
+ |
+LL | 2u8.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn little_encourage_host() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_le_bytes`
+ --> $DIR/endian_bytes.rs:74:9
+ |
+LL | u8::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little_encourage_host() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_be_bytes` method
+ --> $DIR/endian_bytes.rs:76:9
+ |
+LL | 2u8.to_be_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn little_encourage_host() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_be_bytes`
+ --> $DIR/endian_bytes.rs:77:9
+ |
+LL | u8::from_be_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little_encourage_host() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:70:9
+ |
+LL | 2u8.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn little_encourage_big() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::to_be_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:71:9
+ |
+LL | u8::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little_encourage_big() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::from_be_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:73:9
+ |
+LL | 2u8.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn little_encourage_big() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::to_be_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_le_bytes`
+ --> $DIR/endian_bytes.rs:74:9
+ |
+LL | u8::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn little_encourage_big() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::from_be_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_le_bytes` method
+ --> $DIR/endian_bytes.rs:73:9
+ |
+LL | 2u8.to_le_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn big_encourage_host() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_le_bytes`
+ --> $DIR/endian_bytes.rs:74:9
+ |
+LL | u8::from_le_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn big_encourage_host() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_be_bytes` method
+ --> $DIR/endian_bytes.rs:76:9
+ |
+LL | 2u8.to_be_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn big_encourage_host() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_be_bytes`
+ --> $DIR/endian_bytes.rs:77:9
+ |
+LL | u8::from_be_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn big_encourage_host() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use the native endianness instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_ne_bytes` method
+ --> $DIR/endian_bytes.rs:70:9
+ |
+LL | 2u8.to_ne_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn big_encourage_little() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::to_le_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_ne_bytes`
+ --> $DIR/endian_bytes.rs:71:9
+ |
+LL | u8::from_ne_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn big_encourage_little() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::from_le_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the `u8::to_be_bytes` method
+ --> $DIR/endian_bytes.rs:76:9
+ |
+LL | 2u8.to_be_bytes();
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | fn big_encourage_little() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::to_le_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: usage of the function `u8::from_be_bytes`
+ --> $DIR/endian_bytes.rs:77:9
+ |
+LL | u8::from_be_bytes(todo!());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn big_encourage_little() { fn_body_smol!(); }
+ | --------------- in this macro invocation
+ |
+ = help: use `u8::from_le_bytes` instead
+ = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 86 previous errors
+
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 f17556ea9..abe42a230 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-x86
+//@ignore-target-x86
#![warn(clippy::enum_clike_unportable_variant)]
#![allow(unused, non_upper_case_globals)]
diff --git a/src/tools/clippy/tests/ui/eprint_with_newline.rs b/src/tools/clippy/tests/ui/eprint_with_newline.rs
index de5e121be..8389806c8 100644
--- a/src/tools/clippy/tests/ui/eprint_with_newline.rs
+++ b/src/tools/clippy/tests/ui/eprint_with_newline.rs
@@ -44,7 +44,7 @@ fn main() {
// Don't warn on CRLF (#4208)
eprint!("\r\n");
eprint!("foo\r\n");
- eprint!("\\r\n"); //~ ERROR
+ eprint!("\\r\n");
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 0eefb9f0c..0a6bdf15d 100644
--- a/src/tools/clippy/tests/ui/eprint_with_newline.stderr
+++ b/src/tools/clippy/tests/ui/eprint_with_newline.stderr
@@ -62,13 +62,13 @@ LL + eprintln!();
error: using `eprint!()` with a format string that ends in a single newline
--> $DIR/eprint_with_newline.rs:28:5
|
-LL | eprint!("//n"); // should fail
+LL | eprint!("///n"); // should fail
| ^^^^^^^^^^^^^^^
|
help: use `eprintln!` instead
|
-LL - eprint!("//n"); // should fail
-LL + eprintln!("/"); // should fail
+LL - eprint!("///n"); // should fail
+LL + eprintln!("//"); // should fail
|
error: using `eprint!()` with a format string that ends in a single newline
@@ -104,13 +104,13 @@ LL ~
error: using `eprint!()` with a format string that ends in a single newline
--> $DIR/eprint_with_newline.rs:47:5
|
-LL | eprint!("/r/n"); //~ ERROR
+LL | eprint!("//r/n");
| ^^^^^^^^^^^^^^^^
|
help: use `eprintln!` instead
|
-LL - eprint!("/r/n"); //~ ERROR
-LL + eprintln!("/r"); //~ ERROR
+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 cdd33ebe5..e973e5ba2 100644
--- a/src/tools/clippy/tests/ui/eq_op.rs
+++ b/src/tools/clippy/tests/ui/eq_op.rs
@@ -1,5 +1,3 @@
-//@compile-flags: --test
-
#![warn(clippy::eq_op)]
#![allow(clippy::double_parens, clippy::identity_op, clippy::nonminimal_bool)]
#![allow(clippy::suspicious_xor_used_as_pow)]
@@ -12,6 +10,8 @@ fn main() {
let _ = false != false;
let _ = 1.5 < 1.5;
let _ = 1u64 >= 1u64;
+ let x = f32::NAN;
+ let _ = x != x;
// casts, methods, parentheses
let _ = (1u32 as u64) & (1u32 as u64);
diff --git a/src/tools/clippy/tests/ui/eq_op.stderr b/src/tools/clippy/tests/ui/eq_op.stderr
index d365ab27e..c7fa253bd 100644
--- a/src/tools/clippy/tests/ui/eq_op.stderr
+++ b/src/tools/clippy/tests/ui/eq_op.stderr
@@ -1,5 +1,5 @@
error: equal expressions as operands to `==`
- --> $DIR/eq_op.rs:9:13
+ --> $DIR/eq_op.rs:7:13
|
LL | let _ = 1 == 1;
| ^^^^^^
@@ -7,29 +7,37 @@ LL | let _ = 1 == 1;
= note: `-D clippy::eq-op` implied by `-D warnings`
error: equal expressions as operands to `==`
- --> $DIR/eq_op.rs:10:13
+ --> $DIR/eq_op.rs:8:13
|
LL | let _ = "no" == "no";
| ^^^^^^^^^^^^
error: equal expressions as operands to `!=`
- --> $DIR/eq_op.rs:12:13
+ --> $DIR/eq_op.rs:10:13
|
LL | let _ = false != false;
| ^^^^^^^^^^^^^^
error: equal expressions as operands to `<`
- --> $DIR/eq_op.rs:13:13
+ --> $DIR/eq_op.rs:11:13
|
LL | let _ = 1.5 < 1.5;
| ^^^^^^^^^
error: equal expressions as operands to `>=`
- --> $DIR/eq_op.rs:14:13
+ --> $DIR/eq_op.rs:12:13
|
LL | let _ = 1u64 >= 1u64;
| ^^^^^^^^^^^^
+error: equal expressions as operands to `!=`
+ --> $DIR/eq_op.rs:14:13
+ |
+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
|
@@ -168,5 +176,5 @@ error: equal expressions as operands to `==`
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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 28 previous errors
+error: aborting due to 29 previous errors
diff --git a/src/tools/clippy/tests/ui/eq_op_macros.rs b/src/tools/clippy/tests/ui/eq_op_macros.rs
index 6b5b31a1a..482406772 100644
--- a/src/tools/clippy/tests/ui/eq_op_macros.rs
+++ b/src/tools/clippy/tests/ui/eq_op_macros.rs
@@ -1,4 +1,5 @@
#![warn(clippy::eq_op)]
+#![allow(clippy::useless_vec)]
// lint also in macro definition
macro_rules! assert_in_macro_def {
diff --git a/src/tools/clippy/tests/ui/eq_op_macros.stderr b/src/tools/clippy/tests/ui/eq_op_macros.stderr
index cd9f1826e..cb9b0c018 100644
--- a/src/tools/clippy/tests/ui/eq_op_macros.stderr
+++ b/src/tools/clippy/tests/ui/eq_op_macros.stderr
@@ -1,5 +1,5 @@
error: identical args used in this `assert_eq!` macro call
- --> $DIR/eq_op_macros.rs:7:20
+ --> $DIR/eq_op_macros.rs:8:20
|
LL | assert_eq!(a, a);
| ^^^^
@@ -11,7 +11,7 @@ LL | assert_in_macro_def!();
= 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
- --> $DIR/eq_op_macros.rs:8:20
+ --> $DIR/eq_op_macros.rs:9:20
|
LL | assert_ne!(a, a);
| ^^^^
@@ -22,7 +22,7 @@ LL | assert_in_macro_def!();
= 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 `debug_assert_eq!` macro call
- --> $DIR/eq_op_macros.rs:9:26
+ --> $DIR/eq_op_macros.rs:10:26
|
LL | debug_assert_eq!(a, a);
| ^^^^
@@ -33,7 +33,7 @@ LL | assert_in_macro_def!();
= 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 `debug_assert_ne!` macro call
- --> $DIR/eq_op_macros.rs:10:26
+ --> $DIR/eq_op_macros.rs:11:26
|
LL | debug_assert_ne!(a, a);
| ^^^^
@@ -44,49 +44,49 @@ LL | assert_in_macro_def!();
= 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_eq!` macro call
- --> $DIR/eq_op_macros.rs:22:16
+ --> $DIR/eq_op_macros.rs:23:16
|
LL | assert_eq!(a, a);
| ^^^^
error: identical args used in this `assert_eq!` macro call
- --> $DIR/eq_op_macros.rs:23:16
+ --> $DIR/eq_op_macros.rs:24:16
|
LL | assert_eq!(a + 1, a + 1);
| ^^^^^^^^^^^^
error: identical args used in this `assert_ne!` macro call
- --> $DIR/eq_op_macros.rs:30:16
+ --> $DIR/eq_op_macros.rs:31:16
|
LL | assert_ne!(a, a);
| ^^^^
error: identical args used in this `assert_ne!` macro call
- --> $DIR/eq_op_macros.rs:31:16
+ --> $DIR/eq_op_macros.rs:32:16
|
LL | assert_ne!(a + 1, a + 1);
| ^^^^^^^^^^^^
error: identical args used in this `debug_assert_eq!` macro call
- --> $DIR/eq_op_macros.rs:38:22
+ --> $DIR/eq_op_macros.rs:39:22
|
LL | debug_assert_eq!(a, a);
| ^^^^
error: identical args used in this `debug_assert_eq!` macro call
- --> $DIR/eq_op_macros.rs:39:22
+ --> $DIR/eq_op_macros.rs:40: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:46:22
+ --> $DIR/eq_op_macros.rs:47:22
|
LL | debug_assert_ne!(a, a);
| ^^^^
error: identical args used in this `debug_assert_ne!` macro call
- --> $DIR/eq_op_macros.rs:47:22
+ --> $DIR/eq_op_macros.rs:48: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 53e62760b..6cc070fb5 100644
--- a/src/tools/clippy/tests/ui/equatable_if_let.fixed
+++ b/src/tools/clippy/tests/ui/equatable_if_let.fixed
@@ -1,7 +1,12 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
-
-#![allow(unused_variables, dead_code, clippy::derive_partial_eq_without_eq)]
+//@aux-build:proc_macros.rs:proc-macro
+
+#![allow(
+ unused_variables,
+ dead_code,
+ clippy::derive_partial_eq_without_eq,
+ clippy::needless_if
+)]
#![warn(clippy::equatable_if_let)]
extern crate proc_macros;
diff --git a/src/tools/clippy/tests/ui/equatable_if_let.rs b/src/tools/clippy/tests/ui/equatable_if_let.rs
index 55918a5bb..f00a129be 100644
--- a/src/tools/clippy/tests/ui/equatable_if_let.rs
+++ b/src/tools/clippy/tests/ui/equatable_if_let.rs
@@ -1,7 +1,12 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
-
-#![allow(unused_variables, dead_code, clippy::derive_partial_eq_without_eq)]
+//@aux-build:proc_macros.rs:proc-macro
+
+#![allow(
+ unused_variables,
+ dead_code,
+ clippy::derive_partial_eq_without_eq,
+ clippy::needless_if
+)]
#![warn(clippy::equatable_if_let)]
extern crate proc_macros;
diff --git a/src/tools/clippy/tests/ui/equatable_if_let.stderr b/src/tools/clippy/tests/ui/equatable_if_let.stderr
index a72d87bb7..649495dde 100644
--- a/src/tools/clippy/tests/ui/equatable_if_let.stderr
+++ b/src/tools/clippy/tests/ui/equatable_if_let.stderr
@@ -1,5 +1,5 @@
error: this pattern matching can be expressed using equality
- --> $DIR/equatable_if_let.rs:60:8
+ --> $DIR/equatable_if_let.rs:65:8
|
LL | if let 2 = a {}
| ^^^^^^^^^ help: try: `a == 2`
@@ -7,79 +7,79 @@ LL | if let 2 = a {}
= note: `-D clippy::equatable-if-let` implied by `-D warnings`
error: this pattern matching can be expressed using equality
- --> $DIR/equatable_if_let.rs:61:8
+ --> $DIR/equatable_if_let.rs:66: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:62:8
+ --> $DIR/equatable_if_let.rs:67: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:63:8
+ --> $DIR/equatable_if_let.rs:68: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:64:8
+ --> $DIR/equatable_if_let.rs:69: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:65:8
+ --> $DIR/equatable_if_let.rs:70: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:66:8
+ --> $DIR/equatable_if_let.rs:71:8
|
LL | if let Enum::UnitVariant = e {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == Enum::UnitVariant`
error: this pattern matching can be expressed using equality
- --> $DIR/equatable_if_let.rs:67:8
+ --> $DIR/equatable_if_let.rs:72:8
|
LL | if let (Enum::UnitVariant, &Struct { a: 2, b: false }) = (e, &d) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(e, &d) == (Enum::UnitVariant, &Struct { a: 2, b: false })`
error: this pattern matching can be expressed using `matches!`
- --> $DIR/equatable_if_let.rs:76:8
+ --> $DIR/equatable_if_let.rs:81: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:77:8
+ --> $DIR/equatable_if_let.rs:82: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:78:8
+ --> $DIR/equatable_if_let.rs:83: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:79:8
+ --> $DIR/equatable_if_let.rs:84: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:80:8
+ --> $DIR/equatable_if_let.rs:85: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:82:8
+ --> $DIR/equatable_if_let.rs:87:8
|
LL | if let inline!("abc") = "abc" {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"abc" == inline!("abc")`
diff --git a/src/tools/clippy/tests/ui/err_expect.fixed b/src/tools/clippy/tests/ui/err_expect.fixed
index 6ade6f546..46e2816da 100644
--- a/src/tools/clippy/tests/ui/err_expect.fixed
+++ b/src/tools/clippy/tests/ui/err_expect.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
-#![allow(unused)]
+#![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 a93fb5949..b9446034d 100644
--- a/src/tools/clippy/tests/ui/err_expect.rs
+++ b/src/tools/clippy/tests/ui/err_expect.rs
@@ -1,6 +1,6 @@
//@run-rustfix
-#![allow(unused)]
+#![allow(unused, clippy::unnecessary_literal_unwrap)]
struct MyTypeNonDebug;
diff --git a/src/tools/clippy/tests/ui/eta.fixed b/src/tools/clippy/tests/ui/eta.fixed
index b1baf462c..bf44bcb56 100644
--- a/src/tools/clippy/tests/ui/eta.fixed
+++ b/src/tools/clippy/tests/ui/eta.fixed
@@ -7,7 +7,8 @@
clippy::no_effect,
clippy::option_map_unit_fn,
clippy::redundant_closure_call,
- clippy::uninlined_format_args
+ clippy::uninlined_format_args,
+ clippy::useless_vec
)]
use std::path::{Path, PathBuf};
@@ -46,6 +47,12 @@ fn main() {
// issue #7224
let _: Option<Vec<u32>> = Some(0).map(|_| vec![]);
+
+ // issue #10684
+ fn test<T>(x: impl Fn(usize, usize) -> T) -> T {
+ x(1, 2)
+ }
+ test(|start, end| start..=end);
}
trait TestTrait {
diff --git a/src/tools/clippy/tests/ui/eta.rs b/src/tools/clippy/tests/ui/eta.rs
index e113c3d6c..b2af4bf09 100644
--- a/src/tools/clippy/tests/ui/eta.rs
+++ b/src/tools/clippy/tests/ui/eta.rs
@@ -7,7 +7,8 @@
clippy::no_effect,
clippy::option_map_unit_fn,
clippy::redundant_closure_call,
- clippy::uninlined_format_args
+ clippy::uninlined_format_args,
+ clippy::useless_vec
)]
use std::path::{Path, PathBuf};
@@ -46,6 +47,12 @@ fn main() {
// issue #7224
let _: Option<Vec<u32>> = Some(0).map(|_| vec![]);
+
+ // issue #10684
+ fn test<T>(x: impl Fn(usize, usize) -> T) -> T {
+ x(1, 2)
+ }
+ test(|start, end| start..=end);
}
trait TestTrait {
diff --git a/src/tools/clippy/tests/ui/eta.stderr b/src/tools/clippy/tests/ui/eta.stderr
index a521fb868..0ac0b901d 100644
--- a/src/tools/clippy/tests/ui/eta.stderr
+++ b/src/tools/clippy/tests/ui/eta.stderr
@@ -1,5 +1,5 @@
error: redundant closure
- --> $DIR/eta.rs:28:27
+ --> $DIR/eta.rs:29:27
|
LL | let a = Some(1u8).map(|a| foo(a));
| ^^^^^^^^^^ help: replace the closure with the function itself: `foo`
@@ -7,31 +7,31 @@ LL | let a = Some(1u8).map(|a| foo(a));
= note: `-D clippy::redundant-closure` implied by `-D warnings`
error: redundant closure
- --> $DIR/eta.rs:32:40
+ --> $DIR/eta.rs:33:40
|
LL | let _: Option<Vec<u8>> = true.then(|| vec![]); // special case vec!
| ^^^^^^^^^ help: replace the closure with `Vec::new`: `std::vec::Vec::new`
error: redundant closure
- --> $DIR/eta.rs:33:35
+ --> $DIR/eta.rs:34:35
|
LL | let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted?
| ^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo2`
error: redundant closure
- --> $DIR/eta.rs:34:26
+ --> $DIR/eta.rs:35:26
|
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
| ^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `below`
error: redundant closure
- --> $DIR/eta.rs:41:27
+ --> $DIR/eta.rs:42:27
|
LL | let e = Some(1u8).map(|a| generic(a));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic`
error: redundant closure
- --> $DIR/eta.rs:87:51
+ --> $DIR/eta.rs:94:51
|
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
| ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo`
@@ -39,121 +39,121 @@ LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
= note: `-D clippy::redundant-closure-for-method-calls` implied by `-D warnings`
error: redundant closure
- --> $DIR/eta.rs:88:51
+ --> $DIR/eta.rs:95:51
|
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo());
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `TestTrait::trait_foo`
error: redundant closure
- --> $DIR/eta.rs:90:42
+ --> $DIR/eta.rs:97:42
|
LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear());
| ^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::vec::Vec::clear`
error: redundant closure
- --> $DIR/eta.rs:94:29
+ --> $DIR/eta.rs:101:29
|
LL | let e = Some("str").map(|s| s.to_string());
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::string::ToString::to_string`
error: redundant closure
- --> $DIR/eta.rs:95:27
+ --> $DIR/eta.rs:102:27
|
LL | let e = Some('a').map(|s| s.to_uppercase());
| ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_uppercase`
error: redundant closure
- --> $DIR/eta.rs:97:65
+ --> $DIR/eta.rs:104:65
|
LL | let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_ascii_uppercase`
error: redundant closure
- --> $DIR/eta.rs:160:22
+ --> $DIR/eta.rs:167:22
|
LL | requires_fn_once(|| x());
| ^^^^^^ help: replace the closure with the function itself: `x`
error: redundant closure
- --> $DIR/eta.rs:167:27
+ --> $DIR/eta.rs:174:27
|
LL | let a = Some(1u8).map(|a| foo_ptr(a));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo_ptr`
error: redundant closure
- --> $DIR/eta.rs:172:27
+ --> $DIR/eta.rs:179:27
|
LL | let a = Some(1u8).map(|a| closure(a));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `closure`
error: redundant closure
- --> $DIR/eta.rs:204:28
+ --> $DIR/eta.rs:211:28
|
LL | x.into_iter().for_each(|x| add_to_res(x));
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut add_to_res`
error: redundant closure
- --> $DIR/eta.rs:205:28
+ --> $DIR/eta.rs:212:28
|
LL | y.into_iter().for_each(|x| add_to_res(x));
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut add_to_res`
error: redundant closure
- --> $DIR/eta.rs:206:28
+ --> $DIR/eta.rs:213:28
|
LL | z.into_iter().for_each(|x| add_to_res(x));
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `add_to_res`
error: redundant closure
- --> $DIR/eta.rs:213:21
+ --> $DIR/eta.rs:220:21
|
LL | Some(1).map(|n| closure(n));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut closure`
error: redundant closure
- --> $DIR/eta.rs:217:21
+ --> $DIR/eta.rs:224:21
|
LL | Some(1).map(|n| in_loop(n));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `in_loop`
error: redundant closure
- --> $DIR/eta.rs:310:18
+ --> $DIR/eta.rs:317:18
|
LL | takes_fn_mut(|| f());
| ^^^^^^ help: replace the closure with the function itself: `&mut f`
error: redundant closure
- --> $DIR/eta.rs:313:19
+ --> $DIR/eta.rs:320:19
|
LL | takes_fn_once(|| f());
| ^^^^^^ help: replace the closure with the function itself: `&mut f`
error: redundant closure
- --> $DIR/eta.rs:317:26
+ --> $DIR/eta.rs:324:26
|
LL | move || takes_fn_mut(|| f_used_once())
| ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once`
error: redundant closure
- --> $DIR/eta.rs:329:19
+ --> $DIR/eta.rs:336:19
|
LL | array_opt.map(|a| a.as_slice());
| ^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8; 3]>::as_slice`
error: redundant closure
- --> $DIR/eta.rs:332:19
+ --> $DIR/eta.rs:339:19
|
LL | slice_opt.map(|s| s.len());
| ^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8]>::len`
error: redundant closure
- --> $DIR/eta.rs:335:17
+ --> $DIR/eta.rs:342:17
|
LL | ptr_opt.map(|p| p.is_null());
| ^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<*const usize>::is_null`
error: redundant closure
- --> $DIR/eta.rs:339:17
+ --> $DIR/eta.rs:346:17
|
LL | dyn_opt.map(|d| d.method_on_dyn());
| ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<dyn TestTrait>::method_on_dyn`
diff --git a/src/tools/clippy/tests/ui/excessive_precision.fixed b/src/tools/clippy/tests/ui/excessive_precision.fixed
index 0a0795738..7bb4da453 100644
--- a/src/tools/clippy/tests/ui/excessive_precision.fixed
+++ b/src/tools/clippy/tests/ui/excessive_precision.fixed
@@ -1,6 +1,12 @@
//@run-rustfix
#![warn(clippy::excessive_precision)]
-#![allow(dead_code, unused_variables, clippy::print_literal)]
+#![allow(
+ dead_code,
+ overflowing_literals,
+ unused_variables,
+ clippy::print_literal,
+ clippy::useless_vec
+)]
fn main() {
// Consts
@@ -66,4 +72,11 @@ fn main() {
// issue #7745
let _ = 0_f64;
+
+ // issue #9910
+ const INF1: f32 = 1.0e+33f32;
+ const INF2: f64 = 1.0e+3300f64;
+ const NEG_INF1: f32 = -1.0e+33f32;
+ const NEG_INF2: f64 = -1.0e+3300f64;
+ const NEG_INF3: f32 = -3.40282357e+38_f32;
}
diff --git a/src/tools/clippy/tests/ui/excessive_precision.rs b/src/tools/clippy/tests/ui/excessive_precision.rs
index 62a832caa..e8d6ab687 100644
--- a/src/tools/clippy/tests/ui/excessive_precision.rs
+++ b/src/tools/clippy/tests/ui/excessive_precision.rs
@@ -1,6 +1,12 @@
//@run-rustfix
#![warn(clippy::excessive_precision)]
-#![allow(dead_code, unused_variables, clippy::print_literal)]
+#![allow(
+ dead_code,
+ overflowing_literals,
+ unused_variables,
+ clippy::print_literal,
+ clippy::useless_vec
+)]
fn main() {
// Consts
@@ -66,4 +72,11 @@ fn main() {
// issue #7745
let _ = 1.000_000_000_000_001e-324_f64;
+
+ // issue #9910
+ const INF1: f32 = 1.0e+33f32;
+ const INF2: f64 = 1.0e+3300f64;
+ const NEG_INF1: f32 = -1.0e+33f32;
+ const NEG_INF2: f64 = -1.0e+3300f64;
+ const NEG_INF3: f32 = -3.40282357e+38_f32;
}
diff --git a/src/tools/clippy/tests/ui/excessive_precision.stderr b/src/tools/clippy/tests/ui/excessive_precision.stderr
index 42d9d4de1..348ad183d 100644
--- a/src/tools/clippy/tests/ui/excessive_precision.stderr
+++ b/src/tools/clippy/tests/ui/excessive_precision.stderr
@@ -1,5 +1,5 @@
error: float has excessive precision
- --> $DIR/excessive_precision.rs:15:26
+ --> $DIR/excessive_precision.rs:21: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`
@@ -7,85 +7,85 @@ LL | const BAD32_1: f32 = 0.123_456_789_f32;
= note: `-D clippy::excessive-precision` implied by `-D warnings`
error: float has excessive precision
- --> $DIR/excessive_precision.rs:16:26
+ --> $DIR/excessive_precision.rs:22: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:17:26
+ --> $DIR/excessive_precision.rs:23: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:18:29
+ --> $DIR/excessive_precision.rs:24:29
|
LL | const BAD32_EDGE: f32 = 1.000_000_9;
| ^^^^^^^^^^^ help: consider changing the type or truncating it to: `1.000_001`
error: float has excessive precision
- --> $DIR/excessive_precision.rs:22:26
+ --> $DIR/excessive_precision.rs:28:26
|
LL | const BAD64_3: f64 = 0.100_000_000_000_000_000_1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.1`
error: float has excessive precision
- --> $DIR/excessive_precision.rs:25:22
+ --> $DIR/excessive_precision.rs:31: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:36:22
+ --> $DIR/excessive_precision.rs:42: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:37:26
+ --> $DIR/excessive_precision.rs:43: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:38:21
+ --> $DIR/excessive_precision.rs:44: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:48:36
+ --> $DIR/excessive_precision.rs:54:36
|
LL | let bad_vec32: Vec<f32> = vec![0.123_456_789];
| ^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_79`
error: float has excessive precision
- --> $DIR/excessive_precision.rs:49:36
+ --> $DIR/excessive_precision.rs:55:36
|
LL | let bad_vec64: Vec<f64> = vec![0.123_456_789_123_456_789];
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing the type or truncating it to: `0.123_456_789_123_456_78`
error: float has excessive precision
- --> $DIR/excessive_precision.rs:53:24
+ --> $DIR/excessive_precision.rs:59: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:56:27
+ --> $DIR/excessive_precision.rs:62: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:65:13
+ --> $DIR/excessive_precision.rs:71: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:68:13
+ --> $DIR/excessive_precision.rs:74: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/expect.rs b/src/tools/clippy/tests/ui/expect.rs
index d742595e1..1588579bb 100644
--- a/src/tools/clippy/tests/ui/expect.rs
+++ b/src/tools/clippy/tests/ui/expect.rs
@@ -1,4 +1,5 @@
#![warn(clippy::expect_used)]
+#![allow(clippy::unnecessary_literal_unwrap)]
fn expect_option() {
let opt = Some(0);
diff --git a/src/tools/clippy/tests/ui/expect.stderr b/src/tools/clippy/tests/ui/expect.stderr
index c08e0dbbf..be340340d 100644
--- a/src/tools/clippy/tests/ui/expect.stderr
+++ b/src/tools/clippy/tests/ui/expect.stderr
@@ -1,5 +1,5 @@
error: used `expect()` on an `Option` value
- --> $DIR/expect.rs:5:13
+ --> $DIR/expect.rs:6:13
|
LL | let _ = opt.expect("");
| ^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | let _ = opt.expect("");
= note: `-D clippy::expect-used` implied by `-D warnings`
error: used `expect()` on a `Result` value
- --> $DIR/expect.rs:10:13
+ --> $DIR/expect.rs:11:13
|
LL | let _ = res.expect("");
| ^^^^^^^^^^^^^^
@@ -16,7 +16,7 @@ LL | let _ = res.expect("");
= help: if this value is an `Err`, it will panic
error: used `expect_err()` on a `Result` value
- --> $DIR/expect.rs:11:13
+ --> $DIR/expect.rs:12: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 8e97054fb..73c6c97de 100644
--- a/src/tools/clippy/tests/ui/expect_fun_call.fixed
+++ b/src/tools/clippy/tests/ui/expect_fun_call.fixed
@@ -1,6 +1,10 @@
//@run-rustfix
#![warn(clippy::expect_fun_call)]
-#![allow(clippy::to_string_in_format_args, clippy::uninlined_format_args)]
+#![allow(
+ clippy::to_string_in_format_args,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_literal_unwrap
+)]
/// Checks implementation of the `EXPECT_FUN_CALL` lint
diff --git a/src/tools/clippy/tests/ui/expect_fun_call.rs b/src/tools/clippy/tests/ui/expect_fun_call.rs
index 31e6bcc7f..a78613863 100644
--- a/src/tools/clippy/tests/ui/expect_fun_call.rs
+++ b/src/tools/clippy/tests/ui/expect_fun_call.rs
@@ -1,6 +1,10 @@
//@run-rustfix
#![warn(clippy::expect_fun_call)]
-#![allow(clippy::to_string_in_format_args, clippy::uninlined_format_args)]
+#![allow(
+ clippy::to_string_in_format_args,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_literal_unwrap
+)]
/// Checks implementation of the `EXPECT_FUN_CALL` lint
diff --git a/src/tools/clippy/tests/ui/expect_fun_call.stderr b/src/tools/clippy/tests/ui/expect_fun_call.stderr
index cb55e32ae..36fb0e5de 100644
--- a/src/tools/clippy/tests/ui/expect_fun_call.stderr
+++ b/src/tools/clippy/tests/ui/expect_fun_call.stderr
@@ -1,5 +1,5 @@
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:34:26
+ --> $DIR/expect_fun_call.rs:38:26
|
LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
@@ -7,85 +7,85 @@ LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code
= note: `-D clippy::expect-fun-call` implied by `-D warnings`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:37:26
+ --> $DIR/expect_fun_call.rs:41:26
|
LL | with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:40:37
+ --> $DIR/expect_fun_call.rs:44:37
|
LL | with_none_and_format_with_macro.expect(format!("Error {}: fake error", one!()).as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", one!()))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:50:25
+ --> $DIR/expect_fun_call.rs:54:25
|
LL | with_err_and_format.expect(&format!("Error {}: fake error", error_code));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:53:25
+ --> $DIR/expect_fun_call.rs:57:25
|
LL | with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:65:17
+ --> $DIR/expect_fun_call.rs:69:17
|
LL | Some("foo").expect(format!("{} {}", 1, 2).as_ref());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{} {}", 1, 2))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:86:21
+ --> $DIR/expect_fun_call.rs:90:21
|
LL | Some("foo").expect(&get_string());
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:87:21
+ --> $DIR/expect_fun_call.rs:91:21
|
LL | Some("foo").expect(get_string().as_ref());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:88:21
+ --> $DIR/expect_fun_call.rs:92:21
|
LL | Some("foo").expect(get_string().as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:90:21
+ --> $DIR/expect_fun_call.rs:94:21
|
LL | Some("foo").expect(get_static_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_static_str()) })`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:91:21
+ --> $DIR/expect_fun_call.rs:95:21
|
LL | Some("foo").expect(get_non_static_str(&0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `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:95:16
+ --> $DIR/expect_fun_call.rs:99:16
|
LL | Some(true).expect(&format!("key {}, {}", 1, 2));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:101:17
+ --> $DIR/expect_fun_call.rs:105:17
|
LL | opt_ref.expect(&format!("{:?}", opt_ref));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{:?}", opt_ref))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:105:20
+ --> $DIR/expect_fun_call.rs:109:20
|
LL | format_capture.expect(&format!("{error_code}"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{error_code}"))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:108:30
+ --> $DIR/expect_fun_call.rs:112:30
|
LL | format_capture_and_value.expect(&format!("{error_code}, {}", 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `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 0415e33b3..2460f3343 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
@@ -1,4 +1,3 @@
-// check-pass
#![feature(lint_reasons)]
//! This file tests the `#[expect]` attribute implementation for tool lints. The same
//! file is used to test clippy and rustdoc. Any changes to this file should be synced
@@ -12,6 +11,7 @@
//! This test can't cover every lint from Clippy, rustdoc and potentially other
//! tools that will be developed. This therefore only tests a small subset of lints
#![expect(rustdoc::missing_crate_level_docs)]
+#![allow(clippy::needless_if)]
mod rustc_ok {
//! See <https://doc.rust-lang.org/rustc/lints/index.html>
diff --git a/src/tools/clippy/tests/ui/explicit_counter_loop.rs b/src/tools/clippy/tests/ui/explicit_counter_loop.rs
index 46565a97f..e02b8f62b 100644
--- a/src/tools/clippy/tests/ui/explicit_counter_loop.rs
+++ b/src/tools/clippy/tests/ui/explicit_counter_loop.rs
@@ -1,5 +1,5 @@
#![warn(clippy::explicit_counter_loop)]
-#![allow(clippy::uninlined_format_args)]
+#![allow(clippy::uninlined_format_args, clippy::useless_vec)]
fn main() {
let mut vec = vec![1, 2, 3, 4];
@@ -23,6 +23,54 @@ fn main() {
for _v in vec {
_index += 1;
}
+
+ let vec = [1, 2, 3, 4];
+ // Potential false positives
+ let mut _index = 0;
+ _index = 1;
+ for _v in &vec {
+ _index += 1
+ }
+
+ let mut _index = 0;
+ _index += 1;
+ for _v in &vec {
+ _index += 1
+ }
+
+ let mut _index = 0;
+ for _v in &vec {
+ _index = 1;
+ _index += 1
+ }
+
+ let mut _index = 0;
+ for _v in &vec {
+ let mut _index = 0;
+ _index += 1
+ }
+
+ let mut _index = 0;
+ for _v in &vec {
+ _index += 1;
+ _index = 0;
+ }
+
+ let mut _index = 0;
+ if true {
+ _index = 1
+ };
+ for _v in &vec {
+ _index += 1
+ }
+
+ let mut _index = 1;
+ if false {
+ _index = 0
+ };
+ for _v in &vec {
+ _index += 1
+ }
}
mod issue_1219 {
diff --git a/src/tools/clippy/tests/ui/explicit_counter_loop.stderr b/src/tools/clippy/tests/ui/explicit_counter_loop.stderr
index d3f3c626b..0677e4d78 100644
--- a/src/tools/clippy/tests/ui/explicit_counter_loop.stderr
+++ b/src/tools/clippy/tests/ui/explicit_counter_loop.stderr
@@ -25,31 +25,31 @@ 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:62:9
+ --> $DIR/explicit_counter_loop.rs:110: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:73:9
+ --> $DIR/explicit_counter_loop.rs:121: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:131:9
+ --> $DIR/explicit_counter_loop.rs:179: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:171:9
+ --> $DIR/explicit_counter_loop.rs:219: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:183:9
+ --> $DIR/explicit_counter_loop.rs:231: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 60482c66d..4d72b58cd 100644
--- a/src/tools/clippy/tests/ui/explicit_deref_methods.fixed
+++ b/src/tools/clippy/tests/ui/explicit_deref_methods.fixed
@@ -1,12 +1,14 @@
//@run-rustfix
#![warn(clippy::explicit_deref_methods)]
-#![allow(unused_variables)]
+#![allow(unused_variables, unused_must_use)]
#![allow(
clippy::borrow_deref_ref,
suspicious_double_ref_op,
clippy::explicit_auto_deref,
clippy::needless_borrow,
- clippy::uninlined_format_args
+ clippy::no_effect,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_literal_unwrap
)]
use std::ops::{Deref, DerefMut};
@@ -28,6 +30,22 @@ impl Deref for CustomVec {
}
}
+struct Aaa;
+
+impl Deref for Aaa {
+ type Target = ();
+
+ fn deref(&self) -> &Self::Target {
+ todo!();
+ }
+}
+
+impl DerefMut for Aaa {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ todo!();
+ }
+}
+
fn main() {
let a: &mut String = &mut String::from("foo");
@@ -58,6 +76,17 @@ fn main() {
let opt_a = Some(a.clone());
let b = &*opt_a.unwrap();
+ // make sure `Aaa::deref` instead of `aaa.deref()` is not linted, as well as fully qualified
+ // syntax
+
+ Aaa::deref(&Aaa);
+ Aaa::deref_mut(&mut Aaa);
+ <Aaa as Deref>::deref(&Aaa);
+ <Aaa as DerefMut>::deref_mut(&mut Aaa);
+ let mut aaa = Aaa;
+ Aaa::deref(&aaa);
+ Aaa::deref_mut(&mut aaa);
+
// following should not require linting
let cv = CustomVec(vec![0, 42]);
diff --git a/src/tools/clippy/tests/ui/explicit_deref_methods.rs b/src/tools/clippy/tests/ui/explicit_deref_methods.rs
index e3613e216..fcd945de3 100644
--- a/src/tools/clippy/tests/ui/explicit_deref_methods.rs
+++ b/src/tools/clippy/tests/ui/explicit_deref_methods.rs
@@ -1,12 +1,14 @@
//@run-rustfix
#![warn(clippy::explicit_deref_methods)]
-#![allow(unused_variables)]
+#![allow(unused_variables, unused_must_use)]
#![allow(
clippy::borrow_deref_ref,
suspicious_double_ref_op,
clippy::explicit_auto_deref,
clippy::needless_borrow,
- clippy::uninlined_format_args
+ clippy::no_effect,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_literal_unwrap
)]
use std::ops::{Deref, DerefMut};
@@ -28,6 +30,22 @@ impl Deref for CustomVec {
}
}
+struct Aaa;
+
+impl Deref for Aaa {
+ type Target = ();
+
+ fn deref(&self) -> &Self::Target {
+ todo!();
+ }
+}
+
+impl DerefMut for Aaa {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ todo!();
+ }
+}
+
fn main() {
let a: &mut String = &mut String::from("foo");
@@ -58,6 +76,17 @@ fn main() {
let opt_a = Some(a.clone());
let b = opt_a.unwrap().deref();
+ // make sure `Aaa::deref` instead of `aaa.deref()` is not linted, as well as fully qualified
+ // syntax
+
+ Aaa::deref(&Aaa);
+ Aaa::deref_mut(&mut Aaa);
+ <Aaa as Deref>::deref(&Aaa);
+ <Aaa as DerefMut>::deref_mut(&mut Aaa);
+ let mut aaa = Aaa;
+ Aaa::deref(&aaa);
+ Aaa::deref_mut(&mut aaa);
+
// following should not require linting
let cv = CustomVec(vec![0, 42]);
diff --git a/src/tools/clippy/tests/ui/explicit_deref_methods.stderr b/src/tools/clippy/tests/ui/explicit_deref_methods.stderr
index 4b10ed137..d025035b7 100644
--- a/src/tools/clippy/tests/ui/explicit_deref_methods.stderr
+++ b/src/tools/clippy/tests/ui/explicit_deref_methods.stderr
@@ -1,5 +1,5 @@
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:36:19
+ --> $DIR/explicit_deref_methods.rs:54:19
|
LL | let b: &str = a.deref();
| ^^^^^^^^^ help: try this: `&*a`
@@ -7,67 +7,67 @@ LL | let b: &str = a.deref();
= note: `-D clippy::explicit-deref-methods` implied by `-D warnings`
error: explicit `deref_mut` method call
- --> $DIR/explicit_deref_methods.rs:38:23
+ --> $DIR/explicit_deref_methods.rs:56:23
|
LL | let b: &mut str = a.deref_mut();
| ^^^^^^^^^^^^^ help: try this: `&mut **a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:41:39
+ --> $DIR/explicit_deref_methods.rs:59:39
|
LL | let b: String = format!("{}, {}", a.deref(), a.deref());
| ^^^^^^^^^ help: try this: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:41:50
+ --> $DIR/explicit_deref_methods.rs:59:50
|
LL | let b: String = format!("{}, {}", a.deref(), a.deref());
| ^^^^^^^^^ help: try this: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:43:20
+ --> $DIR/explicit_deref_methods.rs:61:20
|
LL | println!("{}", a.deref());
| ^^^^^^^^^ help: try this: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:46:11
+ --> $DIR/explicit_deref_methods.rs:64:11
|
LL | match a.deref() {
| ^^^^^^^^^ help: try this: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:50:28
+ --> $DIR/explicit_deref_methods.rs:68:28
|
LL | let b: String = concat(a.deref());
| ^^^^^^^^^ help: try this: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:52:13
+ --> $DIR/explicit_deref_methods.rs:70:13
|
LL | let b = just_return(a).deref();
| ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `just_return(a)`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:54:28
+ --> $DIR/explicit_deref_methods.rs:72:28
|
LL | let b: String = concat(just_return(a).deref());
| ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `just_return(a)`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:56:19
+ --> $DIR/explicit_deref_methods.rs:74:19
|
LL | let b: &str = a.deref().deref();
| ^^^^^^^^^^^^^^^^^ help: try this: `&**a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:59:13
+ --> $DIR/explicit_deref_methods.rs:77:13
|
LL | let b = opt_a.unwrap().deref();
| ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&*opt_a.unwrap()`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:85:31
+ --> $DIR/explicit_deref_methods.rs:114:31
|
LL | let b: &str = expr_deref!(a.deref());
| ^^^^^^^^^ help: try this: `&*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
new file mode 100644
index 000000000..dcef63403
--- /dev/null
+++ b/src/tools/clippy/tests/ui/explicit_into_iter_loop.fixed
@@ -0,0 +1,69 @@
+//@run-rustfix
+#![warn(clippy::explicit_into_iter_loop)]
+
+fn main() {
+ // Issue #4958
+ fn _takes_iterator<T>(iterator: &T)
+ where
+ for<'a> &'a T: IntoIterator<Item = &'a String>,
+ {
+ for _ in iterator {}
+ }
+
+ struct T;
+ impl IntoIterator for &T {
+ type Item = ();
+ type IntoIter = std::vec::IntoIter<Self::Item>;
+ fn into_iter(self) -> Self::IntoIter {
+ unimplemented!()
+ }
+ }
+
+ let mut t = T;
+ for _ in &t {}
+
+ let r = &t;
+ for _ in r {}
+
+ // No suggestion for this.
+ // We'd have to suggest `for _ in *rr {}` which is less clear.
+ let rr = &&t;
+ for _ in rr.into_iter() {}
+
+ let mr = &mut t;
+ for _ in &*mr {}
+
+ struct U;
+ impl IntoIterator for &mut U {
+ type Item = ();
+ type IntoIter = std::vec::IntoIter<Self::Item>;
+ fn into_iter(self) -> Self::IntoIter {
+ unimplemented!()
+ }
+ }
+
+ let mut u = U;
+ for _ in &mut u {}
+
+ let mr = &mut u;
+ for _ in &mut *mr {}
+
+ // Issue #6900
+ struct S;
+ impl S {
+ #[allow(clippy::should_implement_trait)]
+ pub fn into_iter<T>(self) -> I<T> {
+ unimplemented!()
+ }
+ }
+
+ struct I<T>(T);
+ impl<T> Iterator for I<T> {
+ type Item = T;
+ fn next(&mut self) -> Option<Self::Item> {
+ unimplemented!()
+ }
+ }
+
+ for _ in S.into_iter::<u32>() {}
+}
diff --git a/src/tools/clippy/tests/ui/explicit_into_iter_loop.rs b/src/tools/clippy/tests/ui/explicit_into_iter_loop.rs
new file mode 100644
index 000000000..bc048ed30
--- /dev/null
+++ b/src/tools/clippy/tests/ui/explicit_into_iter_loop.rs
@@ -0,0 +1,69 @@
+//@run-rustfix
+#![warn(clippy::explicit_into_iter_loop)]
+
+fn main() {
+ // Issue #4958
+ fn _takes_iterator<T>(iterator: &T)
+ where
+ for<'a> &'a T: IntoIterator<Item = &'a String>,
+ {
+ for _ in iterator.into_iter() {}
+ }
+
+ struct T;
+ impl IntoIterator for &T {
+ type Item = ();
+ type IntoIter = std::vec::IntoIter<Self::Item>;
+ fn into_iter(self) -> Self::IntoIter {
+ unimplemented!()
+ }
+ }
+
+ let mut t = T;
+ for _ in t.into_iter() {}
+
+ let r = &t;
+ for _ in r.into_iter() {}
+
+ // No suggestion for this.
+ // We'd have to suggest `for _ in *rr {}` which is less clear.
+ let rr = &&t;
+ for _ in rr.into_iter() {}
+
+ let mr = &mut t;
+ for _ in mr.into_iter() {}
+
+ struct U;
+ impl IntoIterator for &mut U {
+ type Item = ();
+ type IntoIter = std::vec::IntoIter<Self::Item>;
+ fn into_iter(self) -> Self::IntoIter {
+ unimplemented!()
+ }
+ }
+
+ let mut u = U;
+ for _ in u.into_iter() {}
+
+ let mr = &mut u;
+ for _ in mr.into_iter() {}
+
+ // Issue #6900
+ struct S;
+ impl S {
+ #[allow(clippy::should_implement_trait)]
+ pub fn into_iter<T>(self) -> I<T> {
+ unimplemented!()
+ }
+ }
+
+ struct I<T>(T);
+ impl<T> Iterator for I<T> {
+ type Item = T;
+ fn next(&mut self) -> Option<Self::Item> {
+ unimplemented!()
+ }
+ }
+
+ for _ in S.into_iter::<u32>() {}
+}
diff --git a/src/tools/clippy/tests/ui/explicit_into_iter_loop.stderr b/src/tools/clippy/tests/ui/explicit_into_iter_loop.stderr
new file mode 100644
index 000000000..fa89b884f
--- /dev/null
+++ b/src/tools/clippy/tests/ui/explicit_into_iter_loop.stderr
@@ -0,0 +1,40 @@
+error: it is more concise to loop over containers instead of using explicit iteration methods
+ --> $DIR/explicit_into_iter_loop.rs:10: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`
+
+error: it is more concise to loop over containers instead of using explicit iteration methods
+ --> $DIR/explicit_into_iter_loop.rs:23: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
+ |
+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
+ |
+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
+ |
+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
+ |
+LL | for _ in mr.into_iter() {}
+ | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut *mr`
+
+error: aborting due to 6 previous errors
+
diff --git a/src/tools/clippy/tests/ui/explicit_iter_loop.fixed b/src/tools/clippy/tests/ui/explicit_iter_loop.fixed
new file mode 100644
index 000000000..746ef813c
--- /dev/null
+++ b/src/tools/clippy/tests/ui/explicit_iter_loop.fixed
@@ -0,0 +1,154 @@
+//@run-rustfix
+#![deny(clippy::explicit_iter_loop)]
+#![allow(
+ clippy::linkedlist,
+ clippy::similar_names,
+ clippy::needless_borrow,
+ clippy::deref_addrof,
+ dead_code
+)]
+
+use core::slice;
+use std::collections::*;
+
+fn main() {
+ let mut vec = vec![1, 2, 3, 4];
+
+ for _ in &vec {}
+ for _ in &mut vec {}
+
+ let rvec = &vec;
+ for _ in rvec {}
+
+ let rmvec = &mut vec;
+ for _ in &*rmvec {}
+ for _ in &mut *rmvec {}
+
+ 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 &[0; 32] {}
+ for _ in &[0; 33] {}
+
+ let ll: LinkedList<()> = LinkedList::new();
+ for _ in &ll {}
+ let rll = &ll;
+ for _ in rll {}
+
+ let vd: VecDeque<()> = VecDeque::new();
+ for _ in &vd {}
+ let rvd = &vd;
+ for _ in rvd {}
+
+ let bh: BinaryHeap<()> = BinaryHeap::new();
+ for _ in &bh {}
+
+ let hm: HashMap<(), ()> = HashMap::new();
+ for _ in &hm {}
+
+ let bt: BTreeMap<(), ()> = BTreeMap::new();
+ for _ in &bt {}
+
+ let hs: HashSet<()> = HashSet::new();
+ for _ in &hs {}
+
+ let bs: BTreeSet<()> = BTreeSet::new();
+ for _ in &bs {}
+
+ struct NoIntoIter();
+ impl NoIntoIter {
+ fn iter(&self) -> slice::Iter<u8> {
+ unimplemented!()
+ }
+
+ fn iter_mut(&mut self) -> slice::IterMut<u8> {
+ unimplemented!()
+ }
+ }
+ let mut x = NoIntoIter();
+ for _ in x.iter() {} // no error
+ for _ in x.iter_mut() {} // no error
+
+ struct IntoIterDiffTy;
+ impl IntoIterator for &'_ IntoIterDiffTy {
+ type Item = &'static ();
+ type IntoIter = core::slice::Iter<'static, ()>;
+ fn into_iter(self) -> Self::IntoIter {
+ unimplemented!()
+ }
+ }
+ impl IntoIterDiffTy {
+ fn iter(&self) -> core::slice::Iter<'static, i32> {
+ unimplemented!()
+ }
+ }
+ let x = IntoIterDiffTy;
+ for _ in x.iter() {}
+
+ struct IntoIterDiffSig;
+ impl IntoIterator for &'_ IntoIterDiffSig {
+ type Item = &'static ();
+ type IntoIter = core::slice::Iter<'static, ()>;
+ fn into_iter(self) -> Self::IntoIter {
+ unimplemented!()
+ }
+ }
+ impl IntoIterDiffSig {
+ fn iter(&self, _: u32) -> core::slice::Iter<'static, ()> {
+ unimplemented!()
+ }
+ }
+ let x = IntoIterDiffSig;
+ for _ in x.iter(0) {}
+
+ struct IntoIterDiffLt<'a>(&'a ());
+ impl<'a> IntoIterator for &'a IntoIterDiffLt<'_> {
+ type Item = &'a ();
+ type IntoIter = core::slice::Iter<'a, ()>;
+ fn into_iter(self) -> Self::IntoIter {
+ unimplemented!()
+ }
+ }
+ impl<'a> IntoIterDiffLt<'a> {
+ fn iter(&self) -> core::slice::Iter<'a, ()> {
+ unimplemented!()
+ }
+ }
+ let x = IntoIterDiffLt(&());
+ for _ in x.iter() {}
+
+ struct CustomType;
+ impl<'a> IntoIterator for &'a CustomType {
+ type Item = &'a u32;
+ type IntoIter = core::slice::Iter<'a, u32>;
+ fn into_iter(self) -> Self::IntoIter {
+ unimplemented!()
+ }
+ }
+ impl<'a> IntoIterator for &'a mut CustomType {
+ type Item = &'a mut u32;
+ type IntoIter = core::slice::IterMut<'a, u32>;
+ fn into_iter(self) -> Self::IntoIter {
+ unimplemented!()
+ }
+ }
+ impl CustomType {
+ fn iter(&self) -> <&'_ Self as IntoIterator>::IntoIter {
+ panic!()
+ }
+
+ fn iter_mut(&mut self) -> core::slice::IterMut<'_, u32> {
+ panic!()
+ }
+ }
+ let mut x = CustomType;
+ for _ in &x {}
+ for _ in &mut x {}
+
+ let r = &x;
+ for _ in r {}
+}
diff --git a/src/tools/clippy/tests/ui/explicit_iter_loop.rs b/src/tools/clippy/tests/ui/explicit_iter_loop.rs
new file mode 100644
index 000000000..fba230ee0
--- /dev/null
+++ b/src/tools/clippy/tests/ui/explicit_iter_loop.rs
@@ -0,0 +1,154 @@
+//@run-rustfix
+#![deny(clippy::explicit_iter_loop)]
+#![allow(
+ clippy::linkedlist,
+ clippy::similar_names,
+ clippy::needless_borrow,
+ clippy::deref_addrof,
+ dead_code
+)]
+
+use core::slice;
+use std::collections::*;
+
+fn main() {
+ let mut vec = vec![1, 2, 3, 4];
+
+ for _ in vec.iter() {}
+ for _ in vec.iter_mut() {}
+
+ let rvec = &vec;
+ for _ in rvec.iter() {}
+
+ let rmvec = &mut vec;
+ 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].iter() {}
+
+ for _ in (&mut [1, 2, 3]).iter() {}
+
+ for _ in [0; 32].iter() {}
+ for _ in [0; 33].iter() {}
+
+ let ll: LinkedList<()> = LinkedList::new();
+ for _ in ll.iter() {}
+ let rll = &ll;
+ for _ in rll.iter() {}
+
+ let vd: VecDeque<()> = VecDeque::new();
+ for _ in vd.iter() {}
+ let rvd = &vd;
+ for _ in rvd.iter() {}
+
+ let bh: BinaryHeap<()> = BinaryHeap::new();
+ for _ in bh.iter() {}
+
+ let hm: HashMap<(), ()> = HashMap::new();
+ for _ in hm.iter() {}
+
+ let bt: BTreeMap<(), ()> = BTreeMap::new();
+ for _ in bt.iter() {}
+
+ let hs: HashSet<()> = HashSet::new();
+ for _ in hs.iter() {}
+
+ let bs: BTreeSet<()> = BTreeSet::new();
+ for _ in bs.iter() {}
+
+ struct NoIntoIter();
+ impl NoIntoIter {
+ fn iter(&self) -> slice::Iter<u8> {
+ unimplemented!()
+ }
+
+ fn iter_mut(&mut self) -> slice::IterMut<u8> {
+ unimplemented!()
+ }
+ }
+ let mut x = NoIntoIter();
+ for _ in x.iter() {} // no error
+ for _ in x.iter_mut() {} // no error
+
+ struct IntoIterDiffTy;
+ impl IntoIterator for &'_ IntoIterDiffTy {
+ type Item = &'static ();
+ type IntoIter = core::slice::Iter<'static, ()>;
+ fn into_iter(self) -> Self::IntoIter {
+ unimplemented!()
+ }
+ }
+ impl IntoIterDiffTy {
+ fn iter(&self) -> core::slice::Iter<'static, i32> {
+ unimplemented!()
+ }
+ }
+ let x = IntoIterDiffTy;
+ for _ in x.iter() {}
+
+ struct IntoIterDiffSig;
+ impl IntoIterator for &'_ IntoIterDiffSig {
+ type Item = &'static ();
+ type IntoIter = core::slice::Iter<'static, ()>;
+ fn into_iter(self) -> Self::IntoIter {
+ unimplemented!()
+ }
+ }
+ impl IntoIterDiffSig {
+ fn iter(&self, _: u32) -> core::slice::Iter<'static, ()> {
+ unimplemented!()
+ }
+ }
+ let x = IntoIterDiffSig;
+ for _ in x.iter(0) {}
+
+ struct IntoIterDiffLt<'a>(&'a ());
+ impl<'a> IntoIterator for &'a IntoIterDiffLt<'_> {
+ type Item = &'a ();
+ type IntoIter = core::slice::Iter<'a, ()>;
+ fn into_iter(self) -> Self::IntoIter {
+ unimplemented!()
+ }
+ }
+ impl<'a> IntoIterDiffLt<'a> {
+ fn iter(&self) -> core::slice::Iter<'a, ()> {
+ unimplemented!()
+ }
+ }
+ let x = IntoIterDiffLt(&());
+ for _ in x.iter() {}
+
+ struct CustomType;
+ impl<'a> IntoIterator for &'a CustomType {
+ type Item = &'a u32;
+ type IntoIter = core::slice::Iter<'a, u32>;
+ fn into_iter(self) -> Self::IntoIter {
+ unimplemented!()
+ }
+ }
+ impl<'a> IntoIterator for &'a mut CustomType {
+ type Item = &'a mut u32;
+ type IntoIter = core::slice::IterMut<'a, u32>;
+ fn into_iter(self) -> Self::IntoIter {
+ unimplemented!()
+ }
+ }
+ impl CustomType {
+ fn iter(&self) -> <&'_ Self as IntoIterator>::IntoIter {
+ panic!()
+ }
+
+ fn iter_mut(&mut self) -> core::slice::IterMut<'_, u32> {
+ panic!()
+ }
+ }
+ let mut x = CustomType;
+ for _ in x.iter() {}
+ for _ in x.iter_mut() {}
+
+ let r = &x;
+ for _ in r.iter() {}
+}
diff --git a/src/tools/clippy/tests/ui/explicit_iter_loop.stderr b/src/tools/clippy/tests/ui/explicit_iter_loop.stderr
new file mode 100644
index 000000000..94a264dce
--- /dev/null
+++ b/src/tools/clippy/tests/ui/explicit_iter_loop.stderr
@@ -0,0 +1,142 @@
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:17:14
+ |
+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
+ |
+LL | #![deny(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:18:14
+ |
+LL | for _ in vec.iter_mut() {}
+ | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec`
+
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:21:14
+ |
+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
+ |
+LL | for _ in [0; 32].iter() {}
+ | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]`
+
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:35:14
+ |
+LL | for _ in [0; 33].iter() {}
+ | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 33]`
+
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:38:14
+ |
+LL | for _ in ll.iter() {}
+ | ^^^^^^^^^ help: to write this more concisely, try: `&ll`
+
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:40:14
+ |
+LL | for _ in rll.iter() {}
+ | ^^^^^^^^^^ help: to write this more concisely, try: `rll`
+
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:43:14
+ |
+LL | for _ in vd.iter() {}
+ | ^^^^^^^^^ help: to write this more concisely, try: `&vd`
+
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:45:14
+ |
+LL | for _ in rvd.iter() {}
+ | ^^^^^^^^^^ help: to write this more concisely, try: `rvd`
+
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:48:14
+ |
+LL | for _ in bh.iter() {}
+ | ^^^^^^^^^ help: to write this more concisely, try: `&bh`
+
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:51:14
+ |
+LL | for _ in hm.iter() {}
+ | ^^^^^^^^^ help: to write this more concisely, try: `&hm`
+
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:54:14
+ |
+LL | for _ in bt.iter() {}
+ | ^^^^^^^^^ help: to write this more concisely, try: `&bt`
+
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:57:14
+ |
+LL | for _ in hs.iter() {}
+ | ^^^^^^^^^ help: to write this more concisely, try: `&hs`
+
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:60:14
+ |
+LL | for _ in bs.iter() {}
+ | ^^^^^^^^^ help: to write this more concisely, try: `&bs`
+
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:149:14
+ |
+LL | for _ in x.iter() {}
+ | ^^^^^^^^ help: to write this more concisely, try: `&x`
+
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:150:14
+ |
+LL | for _ in x.iter_mut() {}
+ | ^^^^^^^^^^^^ help: to write this more concisely, try: `&mut x`
+
+error: it is more concise to loop over references to containers instead of using explicit iteration methods
+ --> $DIR/explicit_iter_loop.rs:153:14
+ |
+LL | for _ in r.iter() {}
+ | ^^^^^^^^ help: to write this more concisely, try: `r`
+
+error: aborting due to 22 previous errors
+
diff --git a/src/tools/clippy/tests/ui/extra_unused_lifetimes.rs b/src/tools/clippy/tests/ui/extra_unused_lifetimes.rs
index cdfaf8d3a..50abe89da 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
+//@aux-build:proc_macro_derive.rs:proc-macro
#![allow(
unused,
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 adcd1f6d4..8420df663 100644
--- a/src/tools/clippy/tests/ui/extra_unused_type_parameters.fixed
+++ b/src/tools/clippy/tests/ui/extra_unused_type_parameters.fixed
@@ -1,8 +1,12 @@
//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
#![allow(unused, clippy::needless_lifetimes)]
#![warn(clippy::extra_unused_type_parameters)]
+extern crate proc_macros;
+use proc_macros::with_span;
+
fn unused_ty(x: u8) {
unimplemented!()
}
@@ -102,4 +106,12 @@ mod issue10319 {
}
}
+with_span!(
+ span
+
+ fn should_not_lint<T>(x: u8) {
+ unimplemented!()
+ }
+);
+
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 c4c5227ac..f63535d7a 100644
--- a/src/tools/clippy/tests/ui/extra_unused_type_parameters.rs
+++ b/src/tools/clippy/tests/ui/extra_unused_type_parameters.rs
@@ -1,8 +1,12 @@
//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
#![allow(unused, clippy::needless_lifetimes)]
#![warn(clippy::extra_unused_type_parameters)]
+extern crate proc_macros;
+use proc_macros::with_span;
+
fn unused_ty<T>(x: u8) {
unimplemented!()
}
@@ -102,4 +106,12 @@ mod issue10319 {
}
}
+with_span!(
+ span
+
+ fn should_not_lint<T>(x: u8) {
+ unimplemented!()
+ }
+);
+
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 c042a5a22..b5277d498 100644
--- a/src/tools/clippy/tests/ui/extra_unused_type_parameters.stderr
+++ b/src/tools/clippy/tests/ui/extra_unused_type_parameters.stderr
@@ -1,5 +1,5 @@
error: type parameter `T` goes unused in function definition
- --> $DIR/extra_unused_type_parameters.rs:6:13
+ --> $DIR/extra_unused_type_parameters.rs:10:13
|
LL | fn unused_ty<T>(x: u8) {
| ^^^ help: consider removing the parameter
@@ -7,19 +7,19 @@ LL | fn unused_ty<T>(x: u8) {
= note: `-D clippy::extra-unused-type-parameters` implied by `-D warnings`
error: type parameters go unused in function definition: T, U
- --> $DIR/extra_unused_type_parameters.rs:10:16
+ --> $DIR/extra_unused_type_parameters.rs:14:16
|
LL | fn unused_multi<T, U>(x: u8) {
| ^^^^^^ help: consider removing the parameters
error: type parameter `T` goes unused in function definition
- --> $DIR/extra_unused_type_parameters.rs:14:21
+ --> $DIR/extra_unused_type_parameters.rs:18: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:26:19
+ --> $DIR/extra_unused_type_parameters.rs:30:19
|
LL | fn unused_bounded<T: Default, U, V: Default>(x: U) {
| ^^^^^^^^^^^^ ^^^^^^^^^^^^
@@ -31,7 +31,7 @@ LL + fn unused_bounded<U>(x: U) {
|
error: type parameters go unused in function definition: A, D, E
- --> $DIR/extra_unused_type_parameters.rs:30:16
+ --> $DIR/extra_unused_type_parameters.rs:34:16
|
LL | fn some_unused<A, B, C, D: Iterator<Item = (B, C)>, E>(b: B, c: C) {
| ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -43,19 +43,19 @@ LL + fn some_unused<B, C>(b: B, c: C) {
|
error: type parameter `T` goes unused in function definition
- --> $DIR/extra_unused_type_parameters.rs:55:22
+ --> $DIR/extra_unused_type_parameters.rs:59:22
|
LL | fn unused_ty_impl<T>(&self) {
| ^^^ help: consider removing the parameter
error: type parameters go unused in function definition: A, B
- --> $DIR/extra_unused_type_parameters.rs:77:17
+ --> $DIR/extra_unused_type_parameters.rs:81:17
|
LL | fn unused_opaque<A, B>(dummy: impl Default) {
| ^^^^^^ help: consider removing the parameters
error: type parameter `U` goes unused in function definition
- --> $DIR/extra_unused_type_parameters.rs:90:56
+ --> $DIR/extra_unused_type_parameters.rs:94:56
|
LL | fn unused_with_priv_trait_bound<T: private::Private, U>() {
| ^^^ help: consider removing the parameter
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 2045b1eeb..d6df114b8 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
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macro_derive.rs:proc-macro
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::field_reassign_with_default)]
diff --git a/src/tools/clippy/tests/ui/filetype_is_file.rs b/src/tools/clippy/tests/ui/filetype_is_file.rs
index 5de8fe8cd..d3ad36e40 100644
--- a/src/tools/clippy/tests/ui/filetype_is_file.rs
+++ b/src/tools/clippy/tests/ui/filetype_is_file.rs
@@ -1,3 +1,4 @@
+#![allow(clippy::needless_if)]
#![warn(clippy::filetype_is_file)]
fn main() -> std::io::Result<()> {
diff --git a/src/tools/clippy/tests/ui/filetype_is_file.stderr b/src/tools/clippy/tests/ui/filetype_is_file.stderr
index e51a90d6c..36142deb3 100644
--- a/src/tools/clippy/tests/ui/filetype_is_file.stderr
+++ b/src/tools/clippy/tests/ui/filetype_is_file.stderr
@@ -1,5 +1,5 @@
error: `FileType::is_file()` only covers regular files
- --> $DIR/filetype_is_file.rs:8:8
+ --> $DIR/filetype_is_file.rs:9:8
|
LL | if fs::metadata("foo.txt")?.file_type().is_file() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | if fs::metadata("foo.txt")?.file_type().is_file() {
= note: `-D clippy::filetype-is-file` implied by `-D warnings`
error: `!FileType::is_file()` only denies regular files
- --> $DIR/filetype_is_file.rs:13:8
+ --> $DIR/filetype_is_file.rs:14:8
|
LL | if !fs::metadata("foo.txt")?.file_type().is_file() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,7 +16,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:18:9
+ --> $DIR/filetype_is_file.rs:19:9
|
LL | if !fs::metadata("foo.txt")?.file_type().is_file().bitor(true) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/find_map.rs b/src/tools/clippy/tests/ui/find_map.rs
index 88d3b0e74..bbd395d50 100644
--- a/src/tools/clippy/tests/ui/find_map.rs
+++ b/src/tools/clippy/tests/ui/find_map.rs
@@ -1,4 +1,5 @@
#![warn(clippy::all, clippy::pedantic)]
+#![allow(clippy::useless_vec)]
#[derive(Debug, Copy, Clone)]
enum Flavor {
diff --git a/src/tools/clippy/tests/ui/fn_null_check.rs b/src/tools/clippy/tests/ui/fn_null_check.rs
index df5bc8420..dfdea100c 100644
--- a/src/tools/clippy/tests/ui/fn_null_check.rs
+++ b/src/tools/clippy/tests/ui/fn_null_check.rs
@@ -1,6 +1,7 @@
#![allow(unused)]
#![warn(clippy::fn_null_check)]
#![allow(clippy::cmp_null)]
+#![allow(clippy::needless_if)]
#![allow(clippy::ptr_eq)]
#![allow(clippy::zero_ptr)]
diff --git a/src/tools/clippy/tests/ui/fn_null_check.stderr b/src/tools/clippy/tests/ui/fn_null_check.stderr
index 660dd3239..5b9f48a96 100644
--- a/src/tools/clippy/tests/ui/fn_null_check.stderr
+++ b/src/tools/clippy/tests/ui/fn_null_check.stderr
@@ -1,5 +1,5 @@
error: function pointer assumed to be nullable, even though it isn't
- --> $DIR/fn_null_check.rs:13:8
+ --> $DIR/fn_null_check.rs:14:8
|
LL | if (fn_ptr as *mut ()).is_null() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | if (fn_ptr as *mut ()).is_null() {}
= note: `-D clippy::fn-null-check` implied by `-D warnings`
error: function pointer assumed to be nullable, even though it isn't
- --> $DIR/fn_null_check.rs:14:8
+ --> $DIR/fn_null_check.rs:15:8
|
LL | if (fn_ptr as *const u8).is_null() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,7 +16,7 @@ LL | if (fn_ptr as *const u8).is_null() {}
= help: try wrapping your function pointer type in `Option<T>` instead, and using `is_none` to check for null pointer value
error: function pointer assumed to be nullable, even though it isn't
- --> $DIR/fn_null_check.rs:15:8
+ --> $DIR/fn_null_check.rs:16:8
|
LL | if (fn_ptr as *const ()) == std::ptr::null() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -24,7 +24,7 @@ LL | if (fn_ptr as *const ()) == std::ptr::null() {}
= help: try wrapping your function pointer type in `Option<T>` instead, and using `is_none` to check for null pointer value
error: function pointer assumed to be nullable, even though it isn't
- --> $DIR/fn_null_check.rs:16:8
+ --> $DIR/fn_null_check.rs:17:8
|
LL | if (fn_ptr as *const ()) == (0 as *const ()) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -32,7 +32,7 @@ LL | if (fn_ptr as *const ()) == (0 as *const ()) {}
= help: try wrapping your function pointer type in `Option<T>` instead, and using `is_none` to check for null pointer value
error: function pointer assumed to be nullable, even though it isn't
- --> $DIR/fn_null_check.rs:17:8
+ --> $DIR/fn_null_check.rs:18:8
|
LL | if (fn_ptr as *const ()) == ZPTR {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/for_loop_fixable.fixed b/src/tools/clippy/tests/ui/for_loop_fixable.fixed
deleted file mode 100644
index f578c98da..000000000
--- a/src/tools/clippy/tests/ui/for_loop_fixable.fixed
+++ /dev/null
@@ -1,309 +0,0 @@
-//@run-rustfix
-#![allow(dead_code, unused)]
-#![allow(clippy::uninlined_format_args)]
-
-use std::collections::*;
-
-#[warn(clippy::all)]
-struct Unrelated(Vec<u8>);
-impl Unrelated {
- fn next(&self) -> std::slice::Iter<u8> {
- self.0.iter()
- }
-
- fn iter(&self) -> std::slice::Iter<u8> {
- self.0.iter()
- }
-}
-
-#[warn(
- clippy::needless_range_loop,
- clippy::explicit_iter_loop,
- clippy::explicit_into_iter_loop,
- clippy::iter_next_loop,
- clippy::for_kv_map
-)]
-#[allow(
- clippy::linkedlist,
- clippy::unnecessary_mut_passed,
- clippy::similar_names,
- clippy::needless_borrow
-)]
-#[allow(unused_variables)]
-fn main() {
- let mut vec = vec![1, 2, 3, 4];
-
- // See #601
- for i in 0..10 {
- // no error, id_col does not exist outside the loop
- let mut id_col = vec![0f64; 10];
- id_col[i] = 1f64;
- }
-
- for _v in &vec {}
-
- for _v in &mut vec {}
-
- let out_vec = vec![1, 2, 3];
- for _v in out_vec {}
-
- for _v in &vec {} // these are fine
- for _v in &mut vec {} // these are fine
-
- for _v in &[1, 2, 3] {}
-
- for _v in (&mut [1, 2, 3]).iter() {} // no error
-
- for _v in &[0; 32] {}
-
- for _v in [0; 33].iter() {} // no error
-
- let ll: LinkedList<()> = LinkedList::new();
- for _v in &ll {}
-
- let vd: VecDeque<()> = VecDeque::new();
- for _v in &vd {}
-
- let bh: BinaryHeap<()> = BinaryHeap::new();
- for _v in &bh {}
-
- let hm: HashMap<(), ()> = HashMap::new();
- for _v in &hm {}
-
- let bt: BTreeMap<(), ()> = BTreeMap::new();
- for _v in &bt {}
-
- let hs: HashSet<()> = HashSet::new();
- for _v in &hs {}
-
- let bs: BTreeSet<()> = BTreeSet::new();
- for _v in &bs {}
-
- let u = Unrelated(vec![]);
- for _v in u.next() {} // no error
- for _v in u.iter() {} // no error
-
- let mut out = vec![];
- vec.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>();
- let _y = vec.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>(); // this is fine
-
- // Loop with explicit counter variable
-
- // Potential false positives
- let mut _index = 0;
- _index = 1;
- for _v in &vec {
- _index += 1
- }
-
- let mut _index = 0;
- _index += 1;
- for _v in &vec {
- _index += 1
- }
-
- let mut _index = 0;
- if true {
- _index = 1
- }
- for _v in &vec {
- _index += 1
- }
-
- let mut _index = 0;
- let mut _index = 1;
- for _v in &vec {
- _index += 1
- }
-
- let mut _index = 0;
- for _v in &vec {
- _index += 1;
- _index += 1
- }
-
- let mut _index = 0;
- for _v in &vec {
- _index *= 2;
- _index += 1
- }
-
- let mut _index = 0;
- for _v in &vec {
- _index = 1;
- _index += 1
- }
-
- let mut _index = 0;
-
- for _v in &vec {
- let mut _index = 0;
- _index += 1
- }
-
- let mut _index = 0;
- for _v in &vec {
- _index += 1;
- _index = 0;
- }
-
- let mut _index = 0;
- for _v in &vec {
- for _x in 0..1 {
- _index += 1;
- }
- _index += 1
- }
-
- let mut _index = 0;
- for x in &vec {
- if *x == 1 {
- _index += 1
- }
- }
-
- let mut _index = 0;
- if true {
- _index = 1
- };
- for _v in &vec {
- _index += 1
- }
-
- let mut _index = 1;
- if false {
- _index = 0
- };
- for _v in &vec {
- _index += 1
- }
-
- let mut index = 0;
- {
- let mut _x = &mut index;
- }
- for _v in &vec {
- _index += 1
- }
-
- let mut index = 0;
- for _v in &vec {
- index += 1
- }
- println!("index: {}", index);
-
- fn f<T>(_: &T, _: &T) -> bool {
- unimplemented!()
- }
- fn g<T>(_: &mut [T], _: usize, _: usize) {
- unimplemented!()
- }
- for i in 1..vec.len() {
- if f(&vec[i - 1], &vec[i]) {
- g(&mut vec, i - 1, i);
- }
- }
-
- for mid in 1..vec.len() {
- let (_, _) = vec.split_at(mid);
- }
-}
-
-fn partition<T: PartialOrd + Send>(v: &mut [T]) -> usize {
- let pivot = v.len() - 1;
- let mut i = 0;
- for j in 0..pivot {
- if v[j] <= v[pivot] {
- v.swap(i, j);
- i += 1;
- }
- }
- v.swap(i, pivot);
- i
-}
-
-#[warn(clippy::needless_range_loop)]
-pub fn manual_copy_same_destination(dst: &mut [i32], d: usize, s: usize) {
- // Same source and destination - don't trigger lint
- for i in 0..dst.len() {
- dst[d + i] = dst[s + i];
- }
-}
-
-mod issue_2496 {
- pub trait Handle {
- fn new_for_index(index: usize) -> Self;
- fn index(&self) -> usize;
- }
-
- pub fn test<H: Handle>() -> H {
- for x in 0..5 {
- let next_handle = H::new_for_index(x);
- println!("{}", next_handle.index());
- }
- unimplemented!()
- }
-}
-
-// explicit_into_iter_loop bad suggestions
-#[warn(clippy::explicit_into_iter_loop, clippy::explicit_iter_loop)]
-mod issue_4958 {
- fn takes_iterator<T>(iterator: &T)
- where
- for<'a> &'a T: IntoIterator<Item = &'a String>,
- {
- for i in iterator {
- println!("{}", i);
- }
- }
-
- struct T;
- impl IntoIterator for &T {
- type Item = ();
- type IntoIter = std::vec::IntoIter<Self::Item>;
- fn into_iter(self) -> Self::IntoIter {
- vec![].into_iter()
- }
- }
-
- fn more_tests() {
- let t = T;
- let r = &t;
- let rr = &&t;
-
- // This case is handled by `explicit_iter_loop`. No idea why.
- for _ in &t {}
-
- for _ in r {}
-
- // No suggestion for this.
- // We'd have to suggest `for _ in *rr {}` which is less clear.
- for _ in rr.into_iter() {}
- }
-}
-
-// explicit_into_iter_loop
-#[warn(clippy::explicit_into_iter_loop)]
-mod issue_6900 {
- struct S;
- impl S {
- #[allow(clippy::should_implement_trait)]
- pub fn into_iter<T>(self) -> I<T> {
- unimplemented!()
- }
- }
-
- struct I<T>(T);
- impl<T> Iterator for I<T> {
- type Item = T;
- fn next(&mut self) -> Option<Self::Item> {
- unimplemented!()
- }
- }
-
- fn f() {
- for _ in S.into_iter::<u32>() {
- unimplemented!()
- }
- }
-}
diff --git a/src/tools/clippy/tests/ui/for_loop_fixable.rs b/src/tools/clippy/tests/ui/for_loop_fixable.rs
deleted file mode 100644
index 42bc6de0c..000000000
--- a/src/tools/clippy/tests/ui/for_loop_fixable.rs
+++ /dev/null
@@ -1,309 +0,0 @@
-//@run-rustfix
-#![allow(dead_code, unused)]
-#![allow(clippy::uninlined_format_args)]
-
-use std::collections::*;
-
-#[warn(clippy::all)]
-struct Unrelated(Vec<u8>);
-impl Unrelated {
- fn next(&self) -> std::slice::Iter<u8> {
- self.0.iter()
- }
-
- fn iter(&self) -> std::slice::Iter<u8> {
- self.0.iter()
- }
-}
-
-#[warn(
- clippy::needless_range_loop,
- clippy::explicit_iter_loop,
- clippy::explicit_into_iter_loop,
- clippy::iter_next_loop,
- clippy::for_kv_map
-)]
-#[allow(
- clippy::linkedlist,
- clippy::unnecessary_mut_passed,
- clippy::similar_names,
- clippy::needless_borrow
-)]
-#[allow(unused_variables)]
-fn main() {
- let mut vec = vec![1, 2, 3, 4];
-
- // See #601
- for i in 0..10 {
- // no error, id_col does not exist outside the loop
- let mut id_col = vec![0f64; 10];
- id_col[i] = 1f64;
- }
-
- for _v in vec.iter() {}
-
- for _v in vec.iter_mut() {}
-
- let out_vec = vec![1, 2, 3];
- for _v in out_vec.into_iter() {}
-
- for _v in &vec {} // these are fine
- for _v in &mut vec {} // these are fine
-
- for _v in [1, 2, 3].iter() {}
-
- for _v in (&mut [1, 2, 3]).iter() {} // no error
-
- for _v in [0; 32].iter() {}
-
- for _v in [0; 33].iter() {} // no error
-
- let ll: LinkedList<()> = LinkedList::new();
- for _v in ll.iter() {}
-
- let vd: VecDeque<()> = VecDeque::new();
- for _v in vd.iter() {}
-
- let bh: BinaryHeap<()> = BinaryHeap::new();
- for _v in bh.iter() {}
-
- let hm: HashMap<(), ()> = HashMap::new();
- for _v in hm.iter() {}
-
- let bt: BTreeMap<(), ()> = BTreeMap::new();
- for _v in bt.iter() {}
-
- let hs: HashSet<()> = HashSet::new();
- for _v in hs.iter() {}
-
- let bs: BTreeSet<()> = BTreeSet::new();
- for _v in bs.iter() {}
-
- let u = Unrelated(vec![]);
- for _v in u.next() {} // no error
- for _v in u.iter() {} // no error
-
- let mut out = vec![];
- vec.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>();
- let _y = vec.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>(); // this is fine
-
- // Loop with explicit counter variable
-
- // Potential false positives
- let mut _index = 0;
- _index = 1;
- for _v in &vec {
- _index += 1
- }
-
- let mut _index = 0;
- _index += 1;
- for _v in &vec {
- _index += 1
- }
-
- let mut _index = 0;
- if true {
- _index = 1
- }
- for _v in &vec {
- _index += 1
- }
-
- let mut _index = 0;
- let mut _index = 1;
- for _v in &vec {
- _index += 1
- }
-
- let mut _index = 0;
- for _v in &vec {
- _index += 1;
- _index += 1
- }
-
- let mut _index = 0;
- for _v in &vec {
- _index *= 2;
- _index += 1
- }
-
- let mut _index = 0;
- for _v in &vec {
- _index = 1;
- _index += 1
- }
-
- let mut _index = 0;
-
- for _v in &vec {
- let mut _index = 0;
- _index += 1
- }
-
- let mut _index = 0;
- for _v in &vec {
- _index += 1;
- _index = 0;
- }
-
- let mut _index = 0;
- for _v in &vec {
- for _x in 0..1 {
- _index += 1;
- }
- _index += 1
- }
-
- let mut _index = 0;
- for x in &vec {
- if *x == 1 {
- _index += 1
- }
- }
-
- let mut _index = 0;
- if true {
- _index = 1
- };
- for _v in &vec {
- _index += 1
- }
-
- let mut _index = 1;
- if false {
- _index = 0
- };
- for _v in &vec {
- _index += 1
- }
-
- let mut index = 0;
- {
- let mut _x = &mut index;
- }
- for _v in &vec {
- _index += 1
- }
-
- let mut index = 0;
- for _v in &vec {
- index += 1
- }
- println!("index: {}", index);
-
- fn f<T>(_: &T, _: &T) -> bool {
- unimplemented!()
- }
- fn g<T>(_: &mut [T], _: usize, _: usize) {
- unimplemented!()
- }
- for i in 1..vec.len() {
- if f(&vec[i - 1], &vec[i]) {
- g(&mut vec, i - 1, i);
- }
- }
-
- for mid in 1..vec.len() {
- let (_, _) = vec.split_at(mid);
- }
-}
-
-fn partition<T: PartialOrd + Send>(v: &mut [T]) -> usize {
- let pivot = v.len() - 1;
- let mut i = 0;
- for j in 0..pivot {
- if v[j] <= v[pivot] {
- v.swap(i, j);
- i += 1;
- }
- }
- v.swap(i, pivot);
- i
-}
-
-#[warn(clippy::needless_range_loop)]
-pub fn manual_copy_same_destination(dst: &mut [i32], d: usize, s: usize) {
- // Same source and destination - don't trigger lint
- for i in 0..dst.len() {
- dst[d + i] = dst[s + i];
- }
-}
-
-mod issue_2496 {
- pub trait Handle {
- fn new_for_index(index: usize) -> Self;
- fn index(&self) -> usize;
- }
-
- pub fn test<H: Handle>() -> H {
- for x in 0..5 {
- let next_handle = H::new_for_index(x);
- println!("{}", next_handle.index());
- }
- unimplemented!()
- }
-}
-
-// explicit_into_iter_loop bad suggestions
-#[warn(clippy::explicit_into_iter_loop, clippy::explicit_iter_loop)]
-mod issue_4958 {
- fn takes_iterator<T>(iterator: &T)
- where
- for<'a> &'a T: IntoIterator<Item = &'a String>,
- {
- for i in iterator.into_iter() {
- println!("{}", i);
- }
- }
-
- struct T;
- impl IntoIterator for &T {
- type Item = ();
- type IntoIter = std::vec::IntoIter<Self::Item>;
- fn into_iter(self) -> Self::IntoIter {
- vec![].into_iter()
- }
- }
-
- fn more_tests() {
- let t = T;
- let r = &t;
- let rr = &&t;
-
- // This case is handled by `explicit_iter_loop`. No idea why.
- for _ in t.into_iter() {}
-
- for _ in r.into_iter() {}
-
- // No suggestion for this.
- // We'd have to suggest `for _ in *rr {}` which is less clear.
- for _ in rr.into_iter() {}
- }
-}
-
-// explicit_into_iter_loop
-#[warn(clippy::explicit_into_iter_loop)]
-mod issue_6900 {
- struct S;
- impl S {
- #[allow(clippy::should_implement_trait)]
- pub fn into_iter<T>(self) -> I<T> {
- unimplemented!()
- }
- }
-
- struct I<T>(T);
- impl<T> Iterator for I<T> {
- type Item = T;
- fn next(&mut self) -> Option<Self::Item> {
- unimplemented!()
- }
- }
-
- fn f() {
- for _ in S.into_iter::<u32>() {
- unimplemented!()
- }
- }
-}
diff --git a/src/tools/clippy/tests/ui/for_loop_fixable.stderr b/src/tools/clippy/tests/ui/for_loop_fixable.stderr
deleted file mode 100644
index ddfe66d67..000000000
--- a/src/tools/clippy/tests/ui/for_loop_fixable.stderr
+++ /dev/null
@@ -1,96 +0,0 @@
-error: it is more concise to loop over references to containers instead of using explicit iteration methods
- --> $DIR/for_loop_fixable.rs:43:15
- |
-LL | for _v in vec.iter() {}
- | ^^^^^^^^^^ help: to write this more concisely, try: `&vec`
- |
- = note: `-D clippy::explicit-iter-loop` implied by `-D warnings`
-
-error: it is more concise to loop over references to containers instead of using explicit iteration methods
- --> $DIR/for_loop_fixable.rs:45:15
- |
-LL | for _v in vec.iter_mut() {}
- | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec`
-
-error: it is more concise to loop over containers instead of using explicit iteration methods
- --> $DIR/for_loop_fixable.rs:48:15
- |
-LL | for _v in out_vec.into_iter() {}
- | ^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `out_vec`
- |
- = note: `-D clippy::explicit-into-iter-loop` implied by `-D warnings`
-
-error: it is more concise to loop over references to containers instead of using explicit iteration methods
- --> $DIR/for_loop_fixable.rs:53:15
- |
-LL | for _v 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/for_loop_fixable.rs:57:15
- |
-LL | for _v in [0; 32].iter() {}
- | ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]`
-
-error: it is more concise to loop over references to containers instead of using explicit iteration methods
- --> $DIR/for_loop_fixable.rs:62:15
- |
-LL | for _v in ll.iter() {}
- | ^^^^^^^^^ help: to write this more concisely, try: `&ll`
-
-error: it is more concise to loop over references to containers instead of using explicit iteration methods
- --> $DIR/for_loop_fixable.rs:65:15
- |
-LL | for _v in vd.iter() {}
- | ^^^^^^^^^ help: to write this more concisely, try: `&vd`
-
-error: it is more concise to loop over references to containers instead of using explicit iteration methods
- --> $DIR/for_loop_fixable.rs:68:15
- |
-LL | for _v in bh.iter() {}
- | ^^^^^^^^^ help: to write this more concisely, try: `&bh`
-
-error: it is more concise to loop over references to containers instead of using explicit iteration methods
- --> $DIR/for_loop_fixable.rs:71:15
- |
-LL | for _v in hm.iter() {}
- | ^^^^^^^^^ help: to write this more concisely, try: `&hm`
-
-error: it is more concise to loop over references to containers instead of using explicit iteration methods
- --> $DIR/for_loop_fixable.rs:74:15
- |
-LL | for _v in bt.iter() {}
- | ^^^^^^^^^ help: to write this more concisely, try: `&bt`
-
-error: it is more concise to loop over references to containers instead of using explicit iteration methods
- --> $DIR/for_loop_fixable.rs:77:15
- |
-LL | for _v in hs.iter() {}
- | ^^^^^^^^^ help: to write this more concisely, try: `&hs`
-
-error: it is more concise to loop over references to containers instead of using explicit iteration methods
- --> $DIR/for_loop_fixable.rs:80:15
- |
-LL | for _v in bs.iter() {}
- | ^^^^^^^^^ help: to write this more concisely, try: `&bs`
-
-error: it is more concise to loop over containers instead of using explicit iteration methods
- --> $DIR/for_loop_fixable.rs:255:18
- |
-LL | for i in iterator.into_iter() {
- | ^^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `iterator`
-
-error: it is more concise to loop over references to containers instead of using explicit iteration methods
- --> $DIR/for_loop_fixable.rs:275:18
- |
-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/for_loop_fixable.rs:277:18
- |
-LL | for _ in r.into_iter() {}
- | ^^^^^^^^^^^^^ help: to write this more concisely, try: `r`
-
-error: aborting due to 15 previous errors
-
diff --git a/src/tools/clippy/tests/ui/for_loop_unfixable.rs b/src/tools/clippy/tests/ui/for_loop_unfixable.rs
deleted file mode 100644
index 55fb3788a..000000000
--- a/src/tools/clippy/tests/ui/for_loop_unfixable.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-// Tests from for_loop.rs that don't have suggestions
-
-#[warn(
- clippy::needless_range_loop,
- clippy::explicit_iter_loop,
- clippy::explicit_into_iter_loop,
- clippy::iter_next_loop,
- clippy::for_kv_map
-)]
-#[allow(clippy::linkedlist, clippy::unnecessary_mut_passed, clippy::similar_names)]
-#[allow(for_loops_over_fallibles)]
-fn main() {
- let vec = vec![1, 2, 3, 4];
-
- for _v in vec.iter().next() {}
-}
diff --git a/src/tools/clippy/tests/ui/for_loop_unfixable.stderr b/src/tools/clippy/tests/ui/for_loop_unfixable.stderr
deleted file mode 100644
index 50a86eaa6..000000000
--- a/src/tools/clippy/tests/ui/for_loop_unfixable.stderr
+++ /dev/null
@@ -1,10 +0,0 @@
-error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
- --> $DIR/for_loop_unfixable.rs:15:15
- |
-LL | for _v in vec.iter().next() {}
- | ^^^^^^^^^^^^^^^^^
- |
- = note: `-D clippy::iter-next-loop` implied by `-D warnings`
-
-error: aborting due to previous error
-
diff --git a/src/tools/clippy/tests/ui/format.fixed b/src/tools/clippy/tests/ui/format.fixed
index 9288956f5..2e24e07ea 100644
--- a/src/tools/clippy/tests/ui/format.fixed
+++ b/src/tools/clippy/tests/ui/format.fixed
@@ -6,7 +6,9 @@
clippy::redundant_clone,
clippy::to_string_in_format_args,
clippy::needless_borrow,
- clippy::uninlined_format_args
+ clippy::uninlined_format_args,
+ clippy::needless_raw_string_hashes,
+ clippy::useless_vec
)]
struct Foo(pub String);
diff --git a/src/tools/clippy/tests/ui/format.rs b/src/tools/clippy/tests/ui/format.rs
index b2b817e0f..0e64a310b 100644
--- a/src/tools/clippy/tests/ui/format.rs
+++ b/src/tools/clippy/tests/ui/format.rs
@@ -6,7 +6,9 @@
clippy::redundant_clone,
clippy::to_string_in_format_args,
clippy::needless_borrow,
- clippy::uninlined_format_args
+ clippy::uninlined_format_args,
+ clippy::needless_raw_string_hashes,
+ clippy::useless_vec
)]
struct Foo(pub String);
diff --git a/src/tools/clippy/tests/ui/format.stderr b/src/tools/clippy/tests/ui/format.stderr
index 0ef0ac655..78a11a335 100644
--- a/src/tools/clippy/tests/ui/format.stderr
+++ b/src/tools/clippy/tests/ui/format.stderr
@@ -1,5 +1,5 @@
error: useless use of `format!`
- --> $DIR/format.rs:19:5
+ --> $DIR/format.rs:21:5
|
LL | format!("foo");
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
@@ -7,19 +7,19 @@ LL | format!("foo");
= note: `-D clippy::useless-format` implied by `-D warnings`
error: useless use of `format!`
- --> $DIR/format.rs:20:5
+ --> $DIR/format.rs:22:5
|
LL | format!("{{}}");
| ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:21:5
+ --> $DIR/format.rs:23:5
|
LL | format!("{{}} abc {{}}");
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:22:5
+ --> $DIR/format.rs:24:5
|
LL | / format!(
LL | | r##"foo {{}}
@@ -34,67 +34,67 @@ LL ~ " bar"##.to_string();
|
error: useless use of `format!`
- --> $DIR/format.rs:27:13
+ --> $DIR/format.rs:29:13
|
LL | let _ = format!("");
| ^^^^^^^^^^^ help: consider using `String::new()`: `String::new()`
error: useless use of `format!`
- --> $DIR/format.rs:29:5
+ --> $DIR/format.rs:31:5
|
LL | format!("{}", "foo");
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:37:5
+ --> $DIR/format.rs:39:5
|
LL | format!("{}", arg);
| ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:67:5
+ --> $DIR/format.rs:69:5
|
LL | format!("{}", 42.to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:69:5
+ --> $DIR/format.rs:71:5
|
LL | format!("{}", x.display().to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:73:18
+ --> $DIR/format.rs:75:18
|
LL | let _ = Some(format!("{}", a + "bar"));
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"`
error: useless use of `format!`
- --> $DIR/format.rs:77:22
+ --> $DIR/format.rs:79:22
|
LL | let _s: String = format!("{}", &*v.join("/n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("/n")).to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:83:13
+ --> $DIR/format.rs:85:13
|
LL | let _ = format!("{x}");
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:85:13
+ --> $DIR/format.rs:87:13
|
LL | let _ = format!("{y}", y = x);
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:89:13
+ --> $DIR/format.rs:91:13
|
LL | let _ = format!("{abc}");
| ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `abc.to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:91:13
+ --> $DIR/format.rs:93:13
|
LL | let _ = format!("{xx}");
| ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `xx.to_string()`
diff --git a/src/tools/clippy/tests/ui/format_push_string.rs b/src/tools/clippy/tests/ui/format_push_string.rs
index 4db13d650..89423ffe1 100644
--- a/src/tools/clippy/tests/ui/format_push_string.rs
+++ b/src/tools/clippy/tests/ui/format_push_string.rs
@@ -5,3 +5,32 @@ fn main() {
string += &format!("{:?}", 1234);
string.push_str(&format!("{:?}", 5678));
}
+
+mod issue9493 {
+ pub fn u8vec_to_hex(vector: &Vec<u8>, upper: bool) -> String {
+ let mut hex = String::with_capacity(vector.len() * 2);
+ for byte in vector {
+ hex += &(if upper {
+ format!("{byte:02X}")
+ } else {
+ format!("{byte:02x}")
+ });
+ }
+ hex
+ }
+
+ pub fn other_cases() {
+ let mut s = String::new();
+ // if let
+ s += &(if let Some(_a) = Some(1234) {
+ format!("{}", 1234)
+ } else {
+ format!("{}", 1234)
+ });
+ // match
+ s += &(match Some(1234) {
+ 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 d7be9a5f2..76762c4a1 100644
--- a/src/tools/clippy/tests/ui/format_push_string.stderr
+++ b/src/tools/clippy/tests/ui/format_push_string.stderr
@@ -15,5 +15,40 @@ LL | string.push_str(&format!("{:?}", 5678));
|
= help: consider using `write!` to avoid the extra allocation
-error: aborting due to 2 previous errors
+error: `format!(..)` appended to existing `String`
+ --> $DIR/format_push_string.rs:13:13
+ |
+LL | / hex += &(if upper {
+LL | | format!("{byte:02X}")
+LL | | } else {
+LL | | format!("{byte:02x}")
+LL | | });
+ | |______________^
+ |
+ = help: consider using `write!` to avoid the extra allocation
+
+error: `format!(..)` appended to existing `String`
+ --> $DIR/format_push_string.rs:25:9
+ |
+LL | / s += &(if let Some(_a) = Some(1234) {
+LL | | format!("{}", 1234)
+LL | | } else {
+LL | | format!("{}", 1234)
+LL | | });
+ | |__________^
+ |
+ = help: consider using `write!` to avoid the extra allocation
+
+error: `format!(..)` appended to existing `String`
+ --> $DIR/format_push_string.rs:31:9
+ |
+LL | / s += &(match Some(1234) {
+LL | | Some(_) => format!("{}", 1234),
+LL | | None => format!("{}", 1234),
+LL | | });
+ | |__________^
+ |
+ = help: consider using `write!` to avoid the extra allocation
+
+error: aborting due to 5 previous errors
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 915ff4fb0..1671987cb 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
@@ -2,6 +2,7 @@
#![warn(clippy::from_iter_instead_of_collect)]
#![allow(unused_imports, unused_tuple_struct_fields)]
+#![allow(clippy::useless_vec)]
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};
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 e926f8c52..48509b32f 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
@@ -2,6 +2,7 @@
#![warn(clippy::from_iter_instead_of_collect)]
#![allow(unused_imports, unused_tuple_struct_fields)]
+#![allow(clippy::useless_vec)]
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};
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 8aa3c3c01..8f08ac8c3 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,5 +1,5 @@
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:18:9
+ --> $DIR/from_iter_instead_of_collect.rs:19:9
|
LL | <Self as FromIterator<bool>>::from_iter(iter.into_iter().copied())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `iter.into_iter().copied().collect::<Self>()`
@@ -7,85 +7,85 @@ LL | <Self as FromIterator<bool>>::from_iter(iter.into_iter().copied())
= note: `-D clippy::from-iter-instead-of-collect` implied by `-D warnings`
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:24:13
+ --> $DIR/from_iter_instead_of_collect.rs:25:13
|
LL | let _ = Vec::from_iter(iter_expr);
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `iter_expr.collect::<Vec<_>>()`
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:26:13
+ --> $DIR/from_iter_instead_of_collect.rs:27:13
|
LL | let _ = HashMap::<usize, &i8>::from_iter(vec![5, 5, 5, 5].iter().enumerate());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `vec![5, 5, 5, 5].iter().enumerate().collect::<HashMap<usize, &i8>>()`
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:31:19
+ --> $DIR/from_iter_instead_of_collect.rs:32:19
|
LL | assert_eq!(a, Vec::from_iter(0..3));
| ^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<Vec<_>>()`
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:32:19
+ --> $DIR/from_iter_instead_of_collect.rs:33:19
|
LL | assert_eq!(a, Vec::<i32>::from_iter(0..3));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<Vec<i32>>()`
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:34:17
+ --> $DIR/from_iter_instead_of_collect.rs:35:17
|
LL | let mut b = VecDeque::from_iter(0..3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<VecDeque<_>>()`
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:37:17
+ --> $DIR/from_iter_instead_of_collect.rs:38:17
|
LL | let mut b = VecDeque::<i32>::from_iter(0..3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<VecDeque<i32>>()`
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:42:21
+ --> $DIR/from_iter_instead_of_collect.rs:43:21
|
LL | let mut b = collections::VecDeque::<i32>::from_iter(0..3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<collections::VecDeque<i32>>()`
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:47:14
+ --> $DIR/from_iter_instead_of_collect.rs:48:14
|
LL | let bm = BTreeMap::from_iter(values.iter().cloned());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `values.iter().cloned().collect::<BTreeMap<_, _>>()`
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:48:19
+ --> $DIR/from_iter_instead_of_collect.rs:49:19
|
LL | let mut bar = BTreeMap::from_iter(bm.range(0..2));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `bm.range(0..2).collect::<BTreeMap<_, _>>()`
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:51:19
+ --> $DIR/from_iter_instead_of_collect.rs:52:19
|
LL | let mut bts = BTreeSet::from_iter(0..3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<BTreeSet<_>>()`
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:55:17
+ --> $DIR/from_iter_instead_of_collect.rs:56:17
|
LL | let _ = collections::BTreeSet::from_iter(0..3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<collections::BTreeSet<_>>()`
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:56:17
+ --> $DIR/from_iter_instead_of_collect.rs:57:17
|
LL | let _ = collections::BTreeSet::<u32>::from_iter(0..3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<collections::BTreeSet<u32>>()`
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:59:15
+ --> $DIR/from_iter_instead_of_collect.rs:60:15
|
LL | for _i in Vec::from_iter([1, 2, 3].iter()) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `[1, 2, 3].iter().collect::<Vec<_>>()`
error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:60:15
+ --> $DIR/from_iter_instead_of_collect.rs:61:15
|
LL | for _i in Vec::<&i32>::from_iter([1, 2, 3].iter()) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `[1, 2, 3].iter().collect::<Vec<&i32>>()`
diff --git a/src/tools/clippy/tests/ui/from_over_into.fixed b/src/tools/clippy/tests/ui/from_over_into.fixed
index d18f93875..d96b68a91 100644
--- a/src/tools/clippy/tests/ui/from_over_into.fixed
+++ b/src/tools/clippy/tests/ui/from_over_into.fixed
@@ -60,6 +60,15 @@ impl From<String> for A {
}
}
+struct PathInExpansion;
+
+impl From<PathInExpansion> for String {
+ fn from(val: PathInExpansion) -> Self {
+ // non self/Self paths in expansions are fine
+ panic!()
+ }
+}
+
#[clippy::msrv = "1.40"]
fn msrv_1_40() {
struct FromOverInto<T>(Vec<T>);
@@ -82,10 +91,4 @@ fn msrv_1_41() {
}
}
-type Opaque = impl Sized;
-struct IntoOpaque;
-impl Into<Opaque> for IntoOpaque {
- fn into(self) -> Opaque {}
-}
-
fn main() {}
diff --git a/src/tools/clippy/tests/ui/from_over_into.rs b/src/tools/clippy/tests/ui/from_over_into.rs
index de8ff0b06..da8fe04f4 100644
--- a/src/tools/clippy/tests/ui/from_over_into.rs
+++ b/src/tools/clippy/tests/ui/from_over_into.rs
@@ -60,6 +60,15 @@ impl From<String> for A {
}
}
+struct PathInExpansion;
+
+impl Into<String> for PathInExpansion {
+ fn into(self) -> String {
+ // non self/Self paths in expansions are fine
+ panic!()
+ }
+}
+
#[clippy::msrv = "1.40"]
fn msrv_1_40() {
struct FromOverInto<T>(Vec<T>);
@@ -82,10 +91,4 @@ fn msrv_1_41() {
}
}
-type Opaque = impl Sized;
-struct IntoOpaque;
-impl Into<Opaque> for IntoOpaque {
- fn into(self) -> Opaque {}
-}
-
fn main() {}
diff --git a/src/tools/clippy/tests/ui/from_over_into.stderr b/src/tools/clippy/tests/ui/from_over_into.stderr
index 6039f86fe..498b00de5 100644
--- a/src/tools/clippy/tests/ui/from_over_into.stderr
+++ b/src/tools/clippy/tests/ui/from_over_into.stderr
@@ -59,7 +59,21 @@ 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:78:5
+ --> $DIR/from_over_into.rs:65:1
+ |
+LL | impl Into<String> for PathInExpansion {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
+ https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
+help: replace the `Into` implementation with `From<PathInExpansion>`
+ |
+LL ~ impl From<PathInExpansion> for String {
+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
|
LL | impl<T> Into<FromOverInto<T>> for Vec<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -71,5 +85,5 @@ LL ~ fn from(val: Vec<T>) -> Self {
LL ~ FromOverInto(val)
|
-error: aborting due to 5 previous errors
+error: aborting due to 6 previous errors
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 3b280b748..c769e38eb 100644
--- a/src/tools/clippy/tests/ui/from_over_into_unfixable.rs
+++ b/src/tools/clippy/tests/ui/from_over_into_unfixable.rs
@@ -3,14 +3,14 @@
struct InMacro(String);
macro_rules! in_macro {
- ($e:ident) => {
- $e
+ () => {
+ Self::new()
};
}
impl Into<InMacro> for String {
fn into(self) -> InMacro {
- InMacro(in_macro!(self))
+ InMacro(in_macro!())
}
}
@@ -32,4 +32,14 @@ impl Into<u8> for ContainsVal {
}
}
+pub struct Lval<T>(T);
+
+pub struct Rval<T>(T);
+
+impl<T> Into<Rval<Self>> for Lval<T> {
+ fn into(self) -> Rval<Self> {
+ Rval(self)
+ }
+}
+
fn main() {}
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 251f1d84e..2ab9b9d6b 100644
--- a/src/tools/clippy/tests/ui/from_over_into_unfixable.stderr
+++ b/src/tools/clippy/tests/ui/from_over_into_unfixable.stderr
@@ -25,5 +25,13 @@ LL | impl Into<u8> for ContainsVal {
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
= help: replace the `Into` implementation with `From<ContainsVal>`
-error: aborting due to 3 previous errors
+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
+ |
+LL | impl<T> Into<Rval<Self>> for Lval<T> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: replace the `Into` implementation with `From<Lval<T>>`
+
+error: aborting due to 4 previous errors
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 8484da241..95ef6425f 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
@@ -1,4 +1,5 @@
#![warn(clippy::from_raw_with_void_ptr)]
+#![allow(clippy::unnecessary_cast)]
use std::ffi::c_void;
use std::rc::Rc;
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 96e4af12b..1963d0801 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
@@ -1,60 +1,60 @@
error: creating a `Box` from a void raw pointer
- --> $DIR/from_raw_with_void_ptr.rs:10:22
+ --> $DIR/from_raw_with_void_ptr.rs:11:22
|
LL | let _ = unsafe { Box::from_raw(ptr) };
| ^^^^^^^^^^^^^^^^^^
|
help: cast this to a pointer of the appropriate type
- --> $DIR/from_raw_with_void_ptr.rs:10:36
+ --> $DIR/from_raw_with_void_ptr.rs:11:36
|
LL | let _ = unsafe { Box::from_raw(ptr) };
| ^^^
= note: `-D clippy::from-raw-with-void-ptr` implied by `-D warnings`
error: creating a `Rc` from a void raw pointer
- --> $DIR/from_raw_with_void_ptr.rs:21:22
+ --> $DIR/from_raw_with_void_ptr.rs:22: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:21:35
+ --> $DIR/from_raw_with_void_ptr.rs:22:35
|
LL | let _ = unsafe { Rc::from_raw(ptr) };
| ^^^
error: creating a `Arc` from a void raw pointer
- --> $DIR/from_raw_with_void_ptr.rs:25:22
+ --> $DIR/from_raw_with_void_ptr.rs:26: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:25:36
+ --> $DIR/from_raw_with_void_ptr.rs:26:36
|
LL | let _ = unsafe { Arc::from_raw(ptr) };
| ^^^
error: creating a `Weak` from a void raw pointer
- --> $DIR/from_raw_with_void_ptr.rs:29:22
+ --> $DIR/from_raw_with_void_ptr.rs:30: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:29:46
+ --> $DIR/from_raw_with_void_ptr.rs:30: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:33:22
+ --> $DIR/from_raw_with_void_ptr.rs:34: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:33:48
+ --> $DIR/from_raw_with_void_ptr.rs:34:48
|
LL | let _ = unsafe { std::sync::Weak::from_raw(ptr) };
| ^^^
diff --git a/src/tools/clippy/tests/ui/get_first.fixed b/src/tools/clippy/tests/ui/get_first.fixed
index ef132b796..a29c0918a 100644
--- a/src/tools/clippy/tests/ui/get_first.fixed
+++ b/src/tools/clippy/tests/ui/get_first.fixed
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::get_first)]
+#![allow(clippy::useless_vec)]
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::collections::VecDeque;
diff --git a/src/tools/clippy/tests/ui/get_first.rs b/src/tools/clippy/tests/ui/get_first.rs
index 4d8722356..2062f3ec2 100644
--- a/src/tools/clippy/tests/ui/get_first.rs
+++ b/src/tools/clippy/tests/ui/get_first.rs
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::get_first)]
+#![allow(clippy::useless_vec)]
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::collections::VecDeque;
diff --git a/src/tools/clippy/tests/ui/get_first.stderr b/src/tools/clippy/tests/ui/get_first.stderr
index 466beff9c..4e267ba9a 100644
--- a/src/tools/clippy/tests/ui/get_first.stderr
+++ b/src/tools/clippy/tests/ui/get_first.stderr
@@ -1,5 +1,5 @@
error: accessing first element with `x.get(0)`
- --> $DIR/get_first.rs:19:13
+ --> $DIR/get_first.rs:20:13
|
LL | let _ = x.get(0); // Use x.first()
| ^^^^^^^^ help: try: `x.first()`
@@ -7,13 +7,13 @@ LL | let _ = x.get(0); // Use x.first()
= note: `-D clippy::get-first` implied by `-D warnings`
error: accessing first element with `y.get(0)`
- --> $DIR/get_first.rs:24:13
+ --> $DIR/get_first.rs:25: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:29:13
+ --> $DIR/get_first.rs:30: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 a58dfda79..01a83e5bf 100644
--- a/src/tools/clippy/tests/ui/get_last_with_len.fixed
+++ b/src/tools/clippy/tests/ui/get_last_with_len.fixed
@@ -1,7 +1,7 @@
//@run-rustfix
#![warn(clippy::get_last_with_len)]
-#![allow(unused)]
+#![allow(unused, clippy::useless_vec)]
use std::collections::VecDeque;
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 d626656c7..d82484b46 100644
--- a/src/tools/clippy/tests/ui/get_last_with_len.rs
+++ b/src/tools/clippy/tests/ui/get_last_with_len.rs
@@ -1,7 +1,7 @@
//@run-rustfix
#![warn(clippy::get_last_with_len)]
-#![allow(unused)]
+#![allow(unused, clippy::useless_vec)]
use std::collections::VecDeque;
diff --git a/src/tools/clippy/tests/ui/get_unwrap.fixed b/src/tools/clippy/tests/ui/get_unwrap.fixed
index 4950c47dd..56ee37f02 100644
--- a/src/tools/clippy/tests/ui/get_unwrap.fixed
+++ b/src/tools/clippy/tests/ui/get_unwrap.fixed
@@ -1,6 +1,11 @@
//@run-rustfix
-#![allow(unused_mut, clippy::from_iter_instead_of_collect, clippy::get_first)]
+#![allow(
+ unused_mut,
+ clippy::from_iter_instead_of_collect,
+ clippy::get_first,
+ clippy::useless_vec
+)]
#![warn(clippy::unwrap_used)]
#![deny(clippy::get_unwrap)]
@@ -65,3 +70,42 @@ fn main() {
let _ = some_vec[0..1].to_vec();
}
}
+mod issue9909 {
+ #![allow(clippy::identity_op, clippy::unwrap_used, dead_code)]
+
+ fn reduced() {
+ let f = &[1, 2, 3];
+
+ // include a borrow in the suggestion, even if the argument is not just a numeric literal
+ let _x: &i32 = &f[1 + 2];
+
+ // don't include a borrow here
+ let _x = f[1 + 2].to_string();
+
+ // don't include a borrow here
+ let _x = f[1 + 2].abs();
+ }
+
+ // original code:
+ fn linidx(row: usize, col: usize) -> usize {
+ row * 1 + col * 3
+ }
+
+ fn main_() {
+ let mut mat = [1.0f32, 5.0, 9.0, 2.0, 6.0, 10.0, 3.0, 7.0, 11.0, 4.0, 8.0, 12.0];
+
+ for i in 0..2 {
+ for j in i + 1..3 {
+ if mat[linidx(j, 3)] > mat[linidx(i, 3)] {
+ for k in 0..4 {
+ let (x, rest) = mat.split_at_mut(linidx(i, k) + 1);
+ let a = x.last_mut().unwrap();
+ let b = &mut rest[linidx(j, k) - linidx(i, k) - 1];
+ ::std::mem::swap(a, b);
+ }
+ }
+ }
+ }
+ assert_eq!([9.0, 5.0, 1.0, 10.0, 6.0, 2.0, 11.0, 7.0, 3.0, 12.0, 8.0, 4.0], mat);
+ }
+}
diff --git a/src/tools/clippy/tests/ui/get_unwrap.rs b/src/tools/clippy/tests/ui/get_unwrap.rs
index 6b1e8edb7..af3a619ad 100644
--- a/src/tools/clippy/tests/ui/get_unwrap.rs
+++ b/src/tools/clippy/tests/ui/get_unwrap.rs
@@ -1,6 +1,11 @@
//@run-rustfix
-#![allow(unused_mut, clippy::from_iter_instead_of_collect, clippy::get_first)]
+#![allow(
+ unused_mut,
+ clippy::from_iter_instead_of_collect,
+ clippy::get_first,
+ clippy::useless_vec
+)]
#![warn(clippy::unwrap_used)]
#![deny(clippy::get_unwrap)]
@@ -65,3 +70,42 @@ fn main() {
let _ = some_vec.get_mut(0..1).unwrap().to_vec();
}
}
+mod issue9909 {
+ #![allow(clippy::identity_op, clippy::unwrap_used, dead_code)]
+
+ fn reduced() {
+ let f = &[1, 2, 3];
+
+ // include a borrow in the suggestion, even if the argument is not just a numeric literal
+ let _x: &i32 = f.get(1 + 2).unwrap();
+
+ // don't include a borrow here
+ let _x = f.get(1 + 2).unwrap().to_string();
+
+ // don't include a borrow here
+ let _x = f.get(1 + 2).unwrap().abs();
+ }
+
+ // original code:
+ fn linidx(row: usize, col: usize) -> usize {
+ row * 1 + col * 3
+ }
+
+ fn main_() {
+ let mut mat = [1.0f32, 5.0, 9.0, 2.0, 6.0, 10.0, 3.0, 7.0, 11.0, 4.0, 8.0, 12.0];
+
+ for i in 0..2 {
+ for j in i + 1..3 {
+ if mat[linidx(j, 3)] > mat[linidx(i, 3)] {
+ for k in 0..4 {
+ let (x, rest) = mat.split_at_mut(linidx(i, k) + 1);
+ let a = x.last_mut().unwrap();
+ let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap();
+ ::std::mem::swap(a, b);
+ }
+ }
+ }
+ }
+ assert_eq!([9.0, 5.0, 1.0, 10.0, 6.0, 2.0, 11.0, 7.0, 3.0, 12.0, 8.0, 4.0], mat);
+ }
+}
diff --git a/src/tools/clippy/tests/ui/get_unwrap.stderr b/src/tools/clippy/tests/ui/get_unwrap.stderr
index 6dee4d5b4..fd961420d 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:35:17
+ --> $DIR/get_unwrap.rs:40:17
|
LL | let _ = boxed_slice.get(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&boxed_slice[1]`
|
note: the lint level is defined here
- --> $DIR/get_unwrap.rs:5:9
+ --> $DIR/get_unwrap.rs:10:9
|
LL | #![deny(clippy::get_unwrap)]
| ^^^^^^^^^^^^^^^^^^
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:35:17
+ --> $DIR/get_unwrap.rs:40:17
|
LL | let _ = boxed_slice.get(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -20,13 +20,13 @@ LL | let _ = boxed_slice.get(1).unwrap();
= note: `-D clippy::unwrap-used` implied by `-D warnings`
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:36:17
+ --> $DIR/get_unwrap.rs:41:17
|
LL | let _ = some_slice.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_slice[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:36:17
+ --> $DIR/get_unwrap.rs:41:17
|
LL | let _ = some_slice.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -34,13 +34,13 @@ LL | let _ = some_slice.get(0).unwrap();
= help: if you don't want to handle the `None` case gracefully, 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:37:17
+ --> $DIR/get_unwrap.rs:42:17
|
LL | let _ = some_vec.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vec[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:37:17
+ --> $DIR/get_unwrap.rs:42:17
|
LL | let _ = some_vec.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -48,13 +48,13 @@ LL | let _ = some_vec.get(0).unwrap();
= help: if you don't want to handle the `None` case gracefully, 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:38:17
+ --> $DIR/get_unwrap.rs:43:17
|
LL | let _ = some_vecdeque.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vecdeque[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:38:17
+ --> $DIR/get_unwrap.rs:43:17
|
LL | let _ = some_vecdeque.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -62,13 +62,13 @@ LL | let _ = some_vecdeque.get(0).unwrap();
= help: if you don't want to handle the `None` case gracefully, 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:39:17
+ --> $DIR/get_unwrap.rs:44:17
|
LL | let _ = some_hashmap.get(&1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_hashmap[&1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:39:17
+ --> $DIR/get_unwrap.rs:44:17
|
LL | let _ = some_hashmap.get(&1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -76,13 +76,13 @@ LL | let _ = some_hashmap.get(&1).unwrap();
= help: if you don't want to handle the `None` case gracefully, 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:40:17
+ --> $DIR/get_unwrap.rs:45:17
|
LL | let _ = some_btreemap.get(&1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_btreemap[&1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:40:17
+ --> $DIR/get_unwrap.rs:45:17
|
LL | let _ = some_btreemap.get(&1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -90,13 +90,13 @@ LL | let _ = some_btreemap.get(&1).unwrap();
= help: if you don't want to handle the `None` case gracefully, 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:44:21
+ --> $DIR/get_unwrap.rs:49:21
|
LL | let _: u8 = *boxed_slice.get(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:44:22
+ --> $DIR/get_unwrap.rs:49:22
|
LL | let _: u8 = *boxed_slice.get(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -104,13 +104,13 @@ LL | let _: u8 = *boxed_slice.get(1).unwrap();
= help: if you don't want to handle the `None` case gracefully, 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:49:9
+ --> $DIR/get_unwrap.rs:54:9
|
LL | *boxed_slice.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:49:10
+ --> $DIR/get_unwrap.rs:54:10
|
LL | *boxed_slice.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -118,13 +118,13 @@ LL | *boxed_slice.get_mut(0).unwrap() = 1;
= help: if you don't want to handle the `None` case gracefully, 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:50:9
+ --> $DIR/get_unwrap.rs:55:9
|
LL | *some_slice.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_slice[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:50:10
+ --> $DIR/get_unwrap.rs:55:10
|
LL | *some_slice.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -132,13 +132,13 @@ LL | *some_slice.get_mut(0).unwrap() = 1;
= help: if you don't want to handle the `None` case gracefully, 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:51:9
+ --> $DIR/get_unwrap.rs:56:9
|
LL | *some_vec.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:51:10
+ --> $DIR/get_unwrap.rs:56:10
|
LL | *some_vec.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -146,13 +146,13 @@ LL | *some_vec.get_mut(0).unwrap() = 1;
= help: if you don't want to handle the `None` case gracefully, 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:52:9
+ --> $DIR/get_unwrap.rs:57:9
|
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vecdeque[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:52:10
+ --> $DIR/get_unwrap.rs:57:10
|
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -160,13 +160,13 @@ LL | *some_vecdeque.get_mut(0).unwrap() = 1;
= help: if you don't want to handle the `None` case gracefully, 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:64:17
+ --> $DIR/get_unwrap.rs:69:17
|
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:64:17
+ --> $DIR/get_unwrap.rs:69:17
|
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -174,18 +174,42 @@ LL | let _ = some_vec.get(0..1).unwrap().to_vec();
= help: if you don't want to handle the `None` case gracefully, 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:65:17
+ --> $DIR/get_unwrap.rs:70:17
|
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:65:17
+ --> $DIR/get_unwrap.rs:70:17
|
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
-error: aborting due to 26 previous errors
+error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
+ --> $DIR/get_unwrap.rs:80:24
+ |
+LL | let _x: &i32 = f.get(1 + 2).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `&f[1 + 2]`
+
+error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
+ --> $DIR/get_unwrap.rs:83:18
+ |
+LL | let _x = f.get(1 + 2).unwrap().to_string();
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `f[1 + 2]`
+
+error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
+ --> $DIR/get_unwrap.rs:86:18
+ |
+LL | let _x = f.get(1 + 2).unwrap().abs();
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `f[1 + 2]`
+
+error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
+ --> $DIR/get_unwrap.rs:103:33
+ |
+LL | let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&mut rest[linidx(j, k) - linidx(i, k) - 1]`
+
+error: aborting due to 30 previous errors
diff --git a/src/tools/clippy/tests/ui/if_same_then_else.rs b/src/tools/clippy/tests/ui/if_same_then_else.rs
index 07d2002eb..dad4543f8 100644
--- a/src/tools/clippy/tests/ui/if_same_then_else.rs
+++ b/src/tools/clippy/tests/ui/if_same_then_else.rs
@@ -21,6 +21,7 @@ fn foo() -> bool {
fn if_same_then_else() {
if true {
+ //~^ ERROR: this `if` has identical blocks
Foo { bar: 42 };
0..10;
..;
@@ -29,7 +30,6 @@ fn if_same_then_else() {
0..=10;
foo();
} else {
- //~ ERROR same body as `if` block
Foo { bar: 42 };
0..10;
..;
@@ -65,16 +65,16 @@ fn if_same_then_else() {
}
let _ = if true {
+ //~^ ERROR: this `if` has identical blocks
0.0
} else {
- //~ ERROR same body as `if` block
0.0
};
let _ = if true {
+ //~^ ERROR: this `if` has identical blocks
-0.0
} else {
- //~ ERROR same body as `if` block
-0.0
};
@@ -88,13 +88,14 @@ fn if_same_then_else() {
}
let _ = if true {
+ //~^ ERROR: this `if` has identical blocks
42
} else {
- //~ ERROR same body as `if` block
42
};
if true {
+ //~^ ERROR: this `if` has identical blocks
let bar = if true { 42 } else { 43 };
while foo() {
@@ -102,7 +103,6 @@ fn if_same_then_else() {
}
bar + 1;
} else {
- //~ ERROR same body as `if` block
let bar = if true { 42 } else { 43 };
while foo() {
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 fb23b81d3..a34fc5655 100644
--- a/src/tools/clippy/tests/ui/if_same_then_else.stderr
+++ b/src/tools/clippy/tests/ui/if_same_then_else.stderr
@@ -3,22 +3,22 @@ error: this `if` has identical blocks
|
LL | if true {
| _____________^
+LL | |
LL | | Foo { bar: 42 };
LL | | 0..10;
-LL | | ..;
... |
LL | | foo();
LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/if_same_then_else.rs:31:12
+ --> $DIR/if_same_then_else.rs:32:12
|
LL | } else {
| ____________^
-LL | | //~ ERROR same body as `if` block
LL | | Foo { bar: 42 };
LL | | 0..10;
+LL | | ..;
... |
LL | | foo();
LL | | }
@@ -30,16 +30,16 @@ error: this `if` has identical blocks
|
LL | let _ = if true {
| _____________________^
+LL | |
LL | | 0.0
LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/if_same_then_else.rs:69:12
+ --> $DIR/if_same_then_else.rs:70:12
|
LL | } else {
| ____________^
-LL | | //~ ERROR same body as `if` block
LL | | 0.0
LL | | };
| |_____^
@@ -49,16 +49,16 @@ error: this `if` has identical blocks
|
LL | let _ = if true {
| _____________________^
+LL | |
LL | | -0.0
LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/if_same_then_else.rs:76:12
+ --> $DIR/if_same_then_else.rs:77:12
|
LL | } else {
| ____________^
-LL | | //~ ERROR same body as `if` block
LL | | -0.0
LL | | };
| |_____^
@@ -68,16 +68,16 @@ error: this `if` has identical blocks
|
LL | let _ = if true {
| _____________________^
+LL | |
LL | | 42
LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/if_same_then_else.rs:92:12
+ --> $DIR/if_same_then_else.rs:93:12
|
LL | } else {
| ____________^
-LL | | //~ ERROR same body as `if` block
LL | | 42
LL | | };
| |_____^
@@ -87,22 +87,22 @@ error: this `if` has identical blocks
|
LL | if true {
| _____________^
+LL | |
LL | | let bar = if true { 42 } else { 43 };
LL | |
-LL | | while foo() {
... |
LL | | bar + 1;
LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/if_same_then_else.rs:104:12
+ --> $DIR/if_same_then_else.rs:105:12
|
LL | } else {
| ____________^
-LL | | //~ ERROR same body as `if` block
LL | | let bar = if true { 42 } else { 43 };
LL | |
+LL | | while foo() {
... |
LL | | bar + 1;
LL | | }
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 58167f444..0b171f21d 100644
--- a/src/tools/clippy/tests/ui/if_same_then_else2.rs
+++ b/src/tools/clippy/tests/ui/if_same_then_else2.rs
@@ -5,6 +5,7 @@
clippy::equatable_if_let,
clippy::collapsible_if,
clippy::ifs_same_cond,
+ clippy::needless_if,
clippy::needless_return,
clippy::single_element_loop,
clippy::branches_sharing_code
@@ -12,6 +13,7 @@
fn if_same_then_else2() -> Result<&'static str, ()> {
if true {
+ //~^ ERROR: this `if` has identical blocks
for _ in &[42] {
let foo: &Option<_> = &Some::<u8>(42);
if foo.is_some() {
@@ -21,7 +23,6 @@ fn if_same_then_else2() -> Result<&'static str, ()> {
}
}
} else {
- //~ ERROR same body as `if` block
for _ in &[42] {
let bar: &Option<_> = &Some::<u8>(42);
if bar.is_some() {
@@ -33,16 +34,16 @@ fn if_same_then_else2() -> Result<&'static str, ()> {
}
if true {
+ //~^ ERROR: this `if` has identical blocks
if let Some(a) = Some(42) {}
} else {
- //~ ERROR same body as `if` block
if let Some(a) = Some(42) {}
}
if true {
+ //~^ ERROR: this `if` has identical blocks
if let (1, .., 3) = (1, 2, 3) {}
} else {
- //~ ERROR same body as `if` block
if let (1, .., 3) = (1, 2, 3) {}
}
@@ -90,16 +91,16 @@ fn if_same_then_else2() -> Result<&'static str, ()> {
// Same NaNs
let _ = if true {
+ //~^ ERROR: this `if` has identical blocks
f32::NAN
} else {
- //~ ERROR same body as `if` block
f32::NAN
};
if true {
+ //~^ ERROR: this `if` has identical blocks
Ok("foo")?;
} else {
- //~ ERROR same body as `if` block
Ok("foo")?;
}
@@ -121,6 +122,7 @@ fn if_same_then_else2() -> Result<&'static str, ()> {
let foo = "bar";
return Ok(&foo[0..]);
} else if true {
+ //~^ ERROR: this `if` has identical blocks
let foo = "";
return Ok(&foo[0..]);
} else {
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 704cfd966..56e5f3e45 100644
--- a/src/tools/clippy/tests/ui/if_same_then_else2.stderr
+++ b/src/tools/clippy/tests/ui/if_same_then_else2.stderr
@@ -1,24 +1,24 @@
error: this `if` has identical blocks
- --> $DIR/if_same_then_else2.rs:14:13
+ --> $DIR/if_same_then_else2.rs:15:13
|
LL | if true {
| _____________^
+LL | |
LL | | for _ in &[42] {
LL | | let foo: &Option<_> = &Some::<u8>(42);
-LL | | if foo.is_some() {
... |
LL | | }
LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/if_same_then_else2.rs:23:12
+ --> $DIR/if_same_then_else2.rs:25:12
|
LL | } else {
| ____________^
-LL | | //~ ERROR same body as `if` block
LL | | for _ in &[42] {
LL | | let bar: &Option<_> = &Some::<u8>(42);
+LL | | if bar.is_some() {
... |
LL | | }
LL | | }
@@ -26,93 +26,94 @@ LL | | }
= note: `-D clippy::if-same-then-else` implied by `-D warnings`
error: this `if` has identical blocks
- --> $DIR/if_same_then_else2.rs:35:13
+ --> $DIR/if_same_then_else2.rs:36:13
|
LL | if true {
| _____________^
+LL | |
LL | | if let Some(a) = Some(42) {}
LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/if_same_then_else2.rs:37:12
+ --> $DIR/if_same_then_else2.rs:39:12
|
LL | } else {
| ____________^
-LL | | //~ ERROR same body as `if` block
LL | | if let Some(a) = Some(42) {}
LL | | }
| |_____^
error: this `if` has identical blocks
- --> $DIR/if_same_then_else2.rs:42:13
+ --> $DIR/if_same_then_else2.rs:43:13
|
LL | if true {
| _____________^
+LL | |
LL | | if let (1, .., 3) = (1, 2, 3) {}
LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/if_same_then_else2.rs:44:12
+ --> $DIR/if_same_then_else2.rs:46:12
|
LL | } else {
| ____________^
-LL | | //~ ERROR same body as `if` block
LL | | if let (1, .., 3) = (1, 2, 3) {}
LL | | }
| |_____^
error: this `if` has identical blocks
- --> $DIR/if_same_then_else2.rs:92:21
+ --> $DIR/if_same_then_else2.rs:93:21
|
LL | let _ = if true {
| _____________________^
+LL | |
LL | | f32::NAN
LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/if_same_then_else2.rs:94:12
+ --> $DIR/if_same_then_else2.rs:96:12
|
LL | } else {
| ____________^
-LL | | //~ ERROR same body as `if` block
LL | | f32::NAN
LL | | };
| |_____^
error: this `if` has identical blocks
- --> $DIR/if_same_then_else2.rs:99:13
+ --> $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:101:12
+ --> $DIR/if_same_then_else2.rs:103:12
|
LL | } else {
| ____________^
-LL | | //~ ERROR same body as `if` block
LL | | Ok("foo")?;
LL | | }
| |_____^
error: this `if` has identical blocks
- --> $DIR/if_same_then_else2.rs:123:20
+ --> $DIR/if_same_then_else2.rs:124:20
|
LL | } else if true {
| ____________________^
+LL | |
LL | | let foo = "";
LL | | return Ok(&foo[0..]);
LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/if_same_then_else2.rs:126:12
+ --> $DIR/if_same_then_else2.rs:128:12
|
LL | } else {
| ____________^
diff --git a/src/tools/clippy/tests/ui/ifs_same_cond.rs b/src/tools/clippy/tests/ui/ifs_same_cond.rs
index 9ce9a8762..5c338e3c5 100644
--- a/src/tools/clippy/tests/ui/ifs_same_cond.rs
+++ b/src/tools/clippy/tests/ui/ifs_same_cond.rs
@@ -1,5 +1,10 @@
#![warn(clippy::ifs_same_cond)]
-#![allow(clippy::if_same_then_else, clippy::comparison_chain)] // all empty blocks
+#![allow(
+ clippy::if_same_then_else,
+ clippy::comparison_chain,
+ clippy::needless_if,
+ clippy::needless_else
+)] // all empty blocks
fn ifs_same_cond() {
let a = 0;
@@ -7,18 +12,18 @@ fn ifs_same_cond() {
if b {
} else if b {
- //~ ERROR ifs same condition
+ //~^ ERROR: this `if` has the same condition as a previous `if`
}
if a == 1 {
} else if a == 1 {
- //~ ERROR ifs same condition
+ //~^ ERROR: this `if` has the same condition as a previous `if`
}
if 2 * a == 1 {
} else if 2 * a == 2 {
} else if 2 * a == 1 {
- //~ ERROR ifs same condition
+ //~^ ERROR: this `if` has the same condition as a previous `if`
} else if a == 1 {
}
@@ -47,6 +52,7 @@ fn issue10272() {
let a = String::from("ha");
if a.contains("ah") {
} else if a.contains("ah") {
+ //~^ ERROR: this `if` has the same condition as a previous `if`
// Trigger this lint
} else if a.contains("ha") {
} else if a == "wow" {
diff --git a/src/tools/clippy/tests/ui/ifs_same_cond.stderr b/src/tools/clippy/tests/ui/ifs_same_cond.stderr
index 9519f6904..8d7093447 100644
--- a/src/tools/clippy/tests/ui/ifs_same_cond.stderr
+++ b/src/tools/clippy/tests/ui/ifs_same_cond.stderr
@@ -1,48 +1,48 @@
error: this `if` has the same condition as a previous `if`
- --> $DIR/ifs_same_cond.rs:9:15
+ --> $DIR/ifs_same_cond.rs:14:15
|
LL | } else if b {
| ^
|
note: same as this
- --> $DIR/ifs_same_cond.rs:8:8
+ --> $DIR/ifs_same_cond.rs:13:8
|
LL | if b {
| ^
= note: `-D clippy::ifs-same-cond` implied by `-D warnings`
error: this `if` has the same condition as a previous `if`
- --> $DIR/ifs_same_cond.rs:14:15
+ --> $DIR/ifs_same_cond.rs:19:15
|
LL | } else if a == 1 {
| ^^^^^^
|
note: same as this
- --> $DIR/ifs_same_cond.rs:13:8
+ --> $DIR/ifs_same_cond.rs:18:8
|
LL | if a == 1 {
| ^^^^^^
error: this `if` has the same condition as a previous `if`
- --> $DIR/ifs_same_cond.rs:20:15
+ --> $DIR/ifs_same_cond.rs:25:15
|
LL | } else if 2 * a == 1 {
| ^^^^^^^^^^
|
note: same as this
- --> $DIR/ifs_same_cond.rs:18:8
+ --> $DIR/ifs_same_cond.rs:23:8
|
LL | if 2 * a == 1 {
| ^^^^^^^^^^
error: this `if` has the same condition as a previous `if`
- --> $DIR/ifs_same_cond.rs:49:15
+ --> $DIR/ifs_same_cond.rs:54:15
|
LL | } else if a.contains("ah") {
| ^^^^^^^^^^^^^^^^
|
note: same as this
- --> $DIR/ifs_same_cond.rs:48:8
+ --> $DIR/ifs_same_cond.rs:53:8
|
LL | if a.contains("ah") {
| ^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/implicit_hasher.rs b/src/tools/clippy/tests/ui/implicit_hasher.rs
index ca7c12213..7ed7bf94a 100644
--- a/src/tools/clippy/tests/ui/implicit_hasher.rs
+++ b/src/tools/clippy/tests/ui/implicit_hasher.rs
@@ -1,4 +1,4 @@
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![deny(clippy::implicit_hasher)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/inconsistent_struct_constructor.fixed b/src/tools/clippy/tests/ui/inconsistent_struct_constructor.fixed
index 620d45e68..d84346e87 100644
--- a/src/tools/clippy/tests/ui/inconsistent_struct_constructor.fixed
+++ b/src/tools/clippy/tests/ui/inconsistent_struct_constructor.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![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 10ffadcb2..87fba7448 100644
--- a/src/tools/clippy/tests/ui/inconsistent_struct_constructor.rs
+++ b/src/tools/clippy/tests/ui/inconsistent_struct_constructor.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::inconsistent_struct_constructor)]
#![allow(clippy::redundant_field_names)]
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
new file mode 100644
index 000000000..ac482dcda
--- /dev/null
+++ b/src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.fixed
@@ -0,0 +1,97 @@
+//@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: Copy>(A);
+
+impl<A: Copy> Clone for Uwu<A> {
+ fn clone(&self) -> Self {
+ Self(self.0)
+ }
+
+ fn clone_from(&mut self, source: &Self) {
+ source.clone();
+ *self = source.clone();
+ }
+}
+
+impl<A: std::fmt::Debug + Copy + Clone> Copy for Uwu<A> {}
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
new file mode 100644
index 000000000..00775874f
--- /dev/null
+++ b/src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.rs
@@ -0,0 +1,107 @@
+//@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: Copy>(A);
+
+impl<A: Copy> Clone for Uwu<A> {
+ fn clone(&self) -> Self {
+ Self(self.0)
+ }
+
+ fn clone_from(&mut self, source: &Self) {
+ source.clone();
+ *self = source.clone();
+ }
+}
+
+impl<A: std::fmt::Debug + Copy + Clone> Copy for Uwu<A> {}
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
new file mode 100644
index 000000000..0021841aa
--- /dev/null
+++ b/src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.stderr
@@ -0,0 +1,40 @@
+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 this
+
+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 this
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui/indexing_slicing_index.rs b/src/tools/clippy/tests/ui/indexing_slicing_index.rs
index 26abc9edb..16f9e47e8 100644
--- a/src/tools/clippy/tests/ui/indexing_slicing_index.rs
+++ b/src/tools/clippy/tests/ui/indexing_slicing_index.rs
@@ -3,7 +3,12 @@
// We also check the out_of_bounds_indexing lint here, because it lints similar things and
// we want to avoid false positives.
#![warn(clippy::out_of_bounds_indexing)]
-#![allow(unconditional_panic, clippy::no_effect, clippy::unnecessary_operation)]
+#![allow(
+ unconditional_panic,
+ clippy::no_effect,
+ clippy::unnecessary_operation,
+ clippy::useless_vec
+)]
const ARR: [i32; 2] = [1, 2];
const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
diff --git a/src/tools/clippy/tests/ui/indexing_slicing_index.stderr b/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
index 8fd77913a..f4357c1d5 100644
--- a/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
+++ b/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
@@ -1,5 +1,5 @@
error: indexing may panic
- --> $DIR/indexing_slicing_index.rs:9:20
+ --> $DIR/indexing_slicing_index.rs:14:20
|
LL | const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
| ^^^^^^^^^^
@@ -9,7 +9,7 @@ LL | const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-re
= note: `-D clippy::indexing-slicing` implied by `-D warnings`
error: indexing may panic
- --> $DIR/indexing_slicing_index.rs:10:24
+ --> $DIR/indexing_slicing_index.rs:15:24
|
LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
| ^^^^^^^^^^^
@@ -18,19 +18,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:31:14
+ --> $DIR/indexing_slicing_index.rs:36:14
|
LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
| ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
note: erroneous constant used
- --> $DIR/indexing_slicing_index.rs:31:5
+ --> $DIR/indexing_slicing_index.rs:36:5
|
LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
| ^^^^^^^^^^^^^^^^^^^^^^
error: indexing may panic
- --> $DIR/indexing_slicing_index.rs:22:5
+ --> $DIR/indexing_slicing_index.rs:27:5
|
LL | x[index];
| ^^^^^^^^
@@ -38,7 +38,7 @@ LL | x[index];
= help: consider using `.get(n)` or `.get_mut(n)` instead
error: indexing may panic
- --> $DIR/indexing_slicing_index.rs:30:14
+ --> $DIR/indexing_slicing_index.rs:35:14
|
LL | const { &ARR[idx()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
| ^^^^^^^^^^
@@ -47,7 +47,7 @@ LL | const { &ARR[idx()] }; // This should be linted, since `suppress-restri
= note: the suggestion might not be applicable in constant blocks
error: indexing may panic
- --> $DIR/indexing_slicing_index.rs:31:14
+ --> $DIR/indexing_slicing_index.rs:36:14
|
LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
| ^^^^^^^^^^^
@@ -56,7 +56,7 @@ LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restr
= note: the suggestion might not be applicable in constant blocks
error: indexing may panic
- --> $DIR/indexing_slicing_index.rs:38:5
+ --> $DIR/indexing_slicing_index.rs:43:5
|
LL | v[0];
| ^^^^
@@ -64,7 +64,7 @@ LL | v[0];
= help: consider using `.get(n)` or `.get_mut(n)` instead
error: indexing may panic
- --> $DIR/indexing_slicing_index.rs:39:5
+ --> $DIR/indexing_slicing_index.rs:44:5
|
LL | v[10];
| ^^^^^
@@ -72,7 +72,7 @@ LL | v[10];
= help: consider using `.get(n)` or `.get_mut(n)` instead
error: indexing may panic
- --> $DIR/indexing_slicing_index.rs:40:5
+ --> $DIR/indexing_slicing_index.rs:45:5
|
LL | v[1 << 3];
| ^^^^^^^^^
@@ -80,7 +80,7 @@ LL | v[1 << 3];
= help: consider using `.get(n)` or `.get_mut(n)` instead
error: indexing may panic
- --> $DIR/indexing_slicing_index.rs:46:5
+ --> $DIR/indexing_slicing_index.rs:51:5
|
LL | v[N];
| ^^^^
@@ -88,7 +88,7 @@ LL | v[N];
= help: consider using `.get(n)` or `.get_mut(n)` instead
error: indexing may panic
- --> $DIR/indexing_slicing_index.rs:47:5
+ --> $DIR/indexing_slicing_index.rs:52:5
|
LL | v[M];
| ^^^^
@@ -96,7 +96,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:10:24
+ --> $DIR/indexing_slicing_index.rs:15: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 7b107db39..939b6ac36 100644
--- a/src/tools/clippy/tests/ui/indexing_slicing_slice.rs
+++ b/src/tools/clippy/tests/ui/indexing_slicing_slice.rs
@@ -2,7 +2,7 @@
// We also check the out_of_bounds_indexing lint here, because it lints similar things and
// we want to avoid false positives.
#![warn(clippy::out_of_bounds_indexing)]
-#![allow(clippy::no_effect, clippy::unnecessary_operation)]
+#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::useless_vec)]
fn main() {
let x = [1, 2, 3, 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 9f550acb1..af197e33f 100644
--- a/src/tools/clippy/tests/ui/into_iter_on_ref.fixed
+++ b/src/tools/clippy/tests/ui/into_iter_on_ref.fixed
@@ -11,35 +11,35 @@ fn main() {
for _ in &vec![X, X] {}
let _ = vec![1, 2, 3].into_iter();
- let _ = (&vec![1, 2, 3]).iter(); //~ WARN equivalent to .iter()
- let _ = vec![1, 2, 3].into_boxed_slice().iter(); //~ WARN equivalent to .iter()
- let _ = std::rc::Rc::from(&[X][..]).iter(); //~ WARN equivalent to .iter()
- let _ = std::sync::Arc::from(&[X][..]).iter(); //~ WARN equivalent to .iter()
+ let _ = (&vec![1, 2, 3]).iter(); //~ ERROR: equivalent to `.iter()
+ let _ = vec![1, 2, 3].into_boxed_slice().iter(); //~ ERROR: equivalent to `.iter()
+ let _ = std::rc::Rc::from(&[X][..]).iter(); //~ ERROR: equivalent to `.iter()
+ let _ = std::sync::Arc::from(&[X][..]).iter(); //~ ERROR: equivalent to `.iter()
- let _ = (&&&&&&&[1, 2, 3]).iter(); //~ ERROR equivalent to .iter()
- let _ = (&&&&mut &&&[1, 2, 3]).iter(); //~ ERROR equivalent to .iter()
- let _ = (&mut &mut &mut [1, 2, 3]).iter_mut(); //~ ERROR equivalent to .iter_mut()
+ let _ = (&&&&&&&[1, 2, 3]).iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&&&&mut &&&[1, 2, 3]).iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut &mut &mut [1, 2, 3]).iter_mut(); //~ ERROR: equivalent to `.iter_mut()
- let _ = (&Some(4)).iter(); //~ WARN equivalent to .iter()
- let _ = (&mut Some(5)).iter_mut(); //~ WARN equivalent to .iter_mut()
- let _ = (&Ok::<_, i32>(6)).iter(); //~ WARN equivalent to .iter()
- let _ = (&mut Err::<i32, _>(7)).iter_mut(); //~ WARN equivalent to .iter_mut()
- let _ = (&Vec::<i32>::new()).iter(); //~ WARN equivalent to .iter()
- let _ = (&mut Vec::<i32>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
- let _ = (&BTreeMap::<i32, u64>::new()).iter(); //~ WARN equivalent to .iter()
- let _ = (&mut BTreeMap::<i32, u64>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
- let _ = (&VecDeque::<i32>::new()).iter(); //~ WARN equivalent to .iter()
- let _ = (&mut VecDeque::<i32>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
- let _ = (&LinkedList::<i32>::new()).iter(); //~ WARN equivalent to .iter()
- let _ = (&mut LinkedList::<i32>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
- let _ = (&HashMap::<i32, u64>::new()).iter(); //~ WARN equivalent to .iter()
- let _ = (&mut HashMap::<i32, u64>::new()).iter_mut(); //~ WARN equivalent to .iter_mut()
+ let _ = (&Some(4)).iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut Some(5)).iter_mut(); //~ ERROR: equivalent to `.iter_mut()
+ let _ = (&Ok::<_, i32>(6)).iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut Err::<i32, _>(7)).iter_mut(); //~ ERROR: equivalent to `.iter_mut()
+ let _ = (&Vec::<i32>::new()).iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut Vec::<i32>::new()).iter_mut(); //~ ERROR: equivalent to `.iter_mut()
+ let _ = (&BTreeMap::<i32, u64>::new()).iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut BTreeMap::<i32, u64>::new()).iter_mut(); //~ ERROR: equivalent to `.iter_mut()
+ let _ = (&VecDeque::<i32>::new()).iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut VecDeque::<i32>::new()).iter_mut(); //~ ERROR: equivalent to `.iter_mut()
+ let _ = (&LinkedList::<i32>::new()).iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut LinkedList::<i32>::new()).iter_mut(); //~ ERROR: equivalent to `.iter_mut()
+ let _ = (&HashMap::<i32, u64>::new()).iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut HashMap::<i32, u64>::new()).iter_mut(); //~ ERROR: equivalent to `.iter_mut()
- let _ = (&BTreeSet::<i32>::new()).iter(); //~ WARN equivalent to .iter()
- let _ = (&BinaryHeap::<i32>::new()).iter(); //~ WARN equivalent to .iter()
- let _ = (&HashSet::<i32>::new()).iter(); //~ WARN equivalent to .iter()
- let _ = std::path::Path::new("12/34").iter(); //~ WARN equivalent to .iter()
- let _ = std::path::PathBuf::from("12/34").iter(); //~ ERROR equivalent to .iter()
+ let _ = (&BTreeSet::<i32>::new()).iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&BinaryHeap::<i32>::new()).iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&HashSet::<i32>::new()).iter(); //~ ERROR: equivalent to `.iter()
+ let _ = std::path::Path::new("12/34").iter(); //~ ERROR: equivalent to `.iter()
+ let _ = std::path::PathBuf::from("12/34").iter(); //~ ERROR: equivalent to `.iter()
- let _ = (&[1, 2, 3]).iter().next(); //~ WARN equivalent to .iter()
+ let _ = (&[1, 2, 3]).iter().next(); //~ ERROR: equivalent to `.iter()
}
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 3381ae04d..3ac13d7dd 100644
--- a/src/tools/clippy/tests/ui/into_iter_on_ref.rs
+++ b/src/tools/clippy/tests/ui/into_iter_on_ref.rs
@@ -11,35 +11,35 @@ fn main() {
for _ in &vec![X, X] {}
let _ = vec![1, 2, 3].into_iter();
- let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter()
- let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); //~ WARN equivalent to .iter()
- let _ = std::rc::Rc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter()
- let _ = std::sync::Arc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter()
+ let _ = (&vec![1, 2, 3]).into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = std::rc::Rc::from(&[X][..]).into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = std::sync::Arc::from(&[X][..]).into_iter(); //~ ERROR: equivalent to `.iter()
- let _ = (&&&&&&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter()
- let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter()
- let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter_mut()
+ let _ = (&&&&&&&[1, 2, 3]).into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); //~ ERROR: equivalent to `.iter_mut()
- let _ = (&Some(4)).into_iter(); //~ WARN equivalent to .iter()
- let _ = (&mut Some(5)).into_iter(); //~ WARN equivalent to .iter_mut()
- let _ = (&Ok::<_, i32>(6)).into_iter(); //~ WARN equivalent to .iter()
- let _ = (&mut Err::<i32, _>(7)).into_iter(); //~ WARN equivalent to .iter_mut()
- let _ = (&Vec::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
- let _ = (&mut Vec::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
- let _ = (&BTreeMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter()
- let _ = (&mut BTreeMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
- let _ = (&VecDeque::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
- let _ = (&mut VecDeque::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
- let _ = (&LinkedList::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
- let _ = (&mut LinkedList::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
- let _ = (&HashMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter()
- let _ = (&mut HashMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
+ let _ = (&Some(4)).into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut Some(5)).into_iter(); //~ ERROR: equivalent to `.iter_mut()
+ let _ = (&Ok::<_, i32>(6)).into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut Err::<i32, _>(7)).into_iter(); //~ ERROR: equivalent to `.iter_mut()
+ let _ = (&Vec::<i32>::new()).into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut Vec::<i32>::new()).into_iter(); //~ ERROR: equivalent to `.iter_mut()
+ let _ = (&BTreeMap::<i32, u64>::new()).into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut BTreeMap::<i32, u64>::new()).into_iter(); //~ ERROR: equivalent to `.iter_mut()
+ let _ = (&VecDeque::<i32>::new()).into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut VecDeque::<i32>::new()).into_iter(); //~ ERROR: equivalent to `.iter_mut()
+ let _ = (&LinkedList::<i32>::new()).into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut LinkedList::<i32>::new()).into_iter(); //~ ERROR: equivalent to `.iter_mut()
+ let _ = (&HashMap::<i32, u64>::new()).into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&mut HashMap::<i32, u64>::new()).into_iter(); //~ ERROR: equivalent to `.iter_mut()
- let _ = (&BTreeSet::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
- let _ = (&BinaryHeap::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
- let _ = (&HashSet::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
- let _ = std::path::Path::new("12/34").into_iter(); //~ WARN equivalent to .iter()
- let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR equivalent to .iter()
+ let _ = (&BTreeSet::<i32>::new()).into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&BinaryHeap::<i32>::new()).into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = (&HashSet::<i32>::new()).into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = std::path::Path::new("12/34").into_iter(); //~ ERROR: equivalent to `.iter()
+ let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR: equivalent to `.iter()
- let _ = (&[1, 2, 3]).into_iter().next(); //~ WARN equivalent to .iter()
+ let _ = (&[1, 2, 3]).into_iter().next(); //~ ERROR: equivalent to `.iter()
}
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 28003b365..06014a93f 100644
--- a/src/tools/clippy/tests/ui/into_iter_on_ref.stderr
+++ b/src/tools/clippy/tests/ui/into_iter_on_ref.stderr
@@ -1,7 +1,7 @@
error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Vec`
--> $DIR/into_iter_on_ref.rs:14:30
|
-LL | let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter()
+LL | let _ = (&vec![1, 2, 3]).into_iter();
| ^^^^^^^^^ help: call directly: `iter`
|
= note: `-D clippy::into-iter-on-ref` implied by `-D warnings`
@@ -9,157 +9,157 @@ LL | let _ = (&vec![1, 2, 3]).into_iter(); //~ WARN equivalent to .iter()
error: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice`
--> $DIR/into_iter_on_ref.rs:15:46
|
-LL | let _ = vec![1, 2, 3].into_boxed_slice().into_iter(); //~ WARN equivalent to .iter()
+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
|
-LL | let _ = std::rc::Rc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter()
+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
|
-LL | let _ = std::sync::Arc::from(&[X][..]).into_iter(); //~ WARN equivalent to .iter()
+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
|
-LL | let _ = (&&&&&&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter()
+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
|
-LL | let _ = (&&&&mut &&&[1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter()
+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
|
-LL | let _ = (&mut &mut &mut [1, 2, 3]).into_iter(); //~ ERROR equivalent to .iter_mut()
+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
|
-LL | let _ = (&Some(4)).into_iter(); //~ WARN equivalent to .iter()
+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
|
-LL | let _ = (&mut Some(5)).into_iter(); //~ WARN equivalent to .iter_mut()
+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
|
-LL | let _ = (&Ok::<_, i32>(6)).into_iter(); //~ WARN equivalent to .iter()
+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
|
-LL | let _ = (&mut Err::<i32, _>(7)).into_iter(); //~ WARN equivalent to .iter_mut()
+LL | let _ = (&mut Err::<i32, _>(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
|
-LL | let _ = (&Vec::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
+LL | let _ = (&Vec::<i32>::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
|
-LL | let _ = (&mut Vec::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
+LL | let _ = (&mut Vec::<i32>::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
|
-LL | let _ = (&BTreeMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter()
+LL | let _ = (&BTreeMap::<i32, u64>::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
|
-LL | let _ = (&mut BTreeMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
+LL | let _ = (&mut BTreeMap::<i32, u64>::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
|
-LL | let _ = (&VecDeque::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
+LL | let _ = (&VecDeque::<i32>::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
|
-LL | let _ = (&mut VecDeque::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
+LL | let _ = (&mut VecDeque::<i32>::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
|
-LL | let _ = (&LinkedList::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
+LL | let _ = (&LinkedList::<i32>::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
|
-LL | let _ = (&mut LinkedList::<i32>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
+LL | let _ = (&mut LinkedList::<i32>::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
|
-LL | let _ = (&HashMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter()
+LL | let _ = (&HashMap::<i32, u64>::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
|
-LL | let _ = (&mut HashMap::<i32, u64>::new()).into_iter(); //~ WARN equivalent to .iter_mut()
+LL | let _ = (&mut HashMap::<i32, u64>::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
|
-LL | let _ = (&BTreeSet::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
+LL | let _ = (&BTreeSet::<i32>::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
|
-LL | let _ = (&BinaryHeap::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
+LL | let _ = (&BinaryHeap::<i32>::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
|
-LL | let _ = (&HashSet::<i32>::new()).into_iter(); //~ WARN equivalent to .iter()
+LL | let _ = (&HashSet::<i32>::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
|
-LL | let _ = std::path::Path::new("12/34").into_iter(); //~ WARN equivalent to .iter()
+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
|
-LL | let _ = std::path::PathBuf::from("12/34").into_iter(); //~ ERROR equivalent to .iter()
+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
|
-LL | let _ = (&[1, 2, 3]).into_iter().next(); //~ WARN equivalent to .iter()
+LL | let _ = (&[1, 2, 3]).into_iter().next();
| ^^^^^^^^^ help: call directly: `iter`
error: aborting due to 27 previous errors
diff --git a/src/tools/clippy/tests/ui/invalid_utf8_in_unchecked.rs b/src/tools/clippy/tests/ui/invalid_utf8_in_unchecked.rs
deleted file mode 100644
index 3dc096d31..000000000
--- a/src/tools/clippy/tests/ui/invalid_utf8_in_unchecked.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-#![warn(clippy::invalid_utf8_in_unchecked)]
-
-fn main() {
- // Valid
- unsafe {
- std::str::from_utf8_unchecked(&[99, 108, 105, 112, 112, 121]);
- std::str::from_utf8_unchecked(&[b'c', b'l', b'i', b'p', b'p', b'y']);
- std::str::from_utf8_unchecked(b"clippy");
-
- let x = 0xA0;
- std::str::from_utf8_unchecked(&[0xC0, x]);
- }
-
- // Invalid
- unsafe {
- std::str::from_utf8_unchecked(&[99, 108, 130, 105, 112, 112, 121]);
- std::str::from_utf8_unchecked(&[b'c', b'l', b'\x82', b'i', b'p', b'p', b'y']);
- std::str::from_utf8_unchecked(b"cl\x82ippy");
- }
-}
diff --git a/src/tools/clippy/tests/ui/invalid_utf8_in_unchecked.stderr b/src/tools/clippy/tests/ui/invalid_utf8_in_unchecked.stderr
deleted file mode 100644
index c89cd2758..000000000
--- a/src/tools/clippy/tests/ui/invalid_utf8_in_unchecked.stderr
+++ /dev/null
@@ -1,22 +0,0 @@
-error: non UTF-8 literal in `std::str::from_utf8_unchecked`
- --> $DIR/invalid_utf8_in_unchecked.rs:16:9
- |
-LL | std::str::from_utf8_unchecked(&[99, 108, 130, 105, 112, 112, 121]);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: `-D clippy::invalid-utf8-in-unchecked` implied by `-D warnings`
-
-error: non UTF-8 literal in `std::str::from_utf8_unchecked`
- --> $DIR/invalid_utf8_in_unchecked.rs:17:9
- |
-LL | std::str::from_utf8_unchecked(&[b'c', b'l', b'/x82', b'i', b'p', b'p', b'y']);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: non UTF-8 literal in `std::str::from_utf8_unchecked`
- --> $DIR/invalid_utf8_in_unchecked.rs:18:9
- |
-LL | std::str::from_utf8_unchecked(b"cl/x82ippy");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 3 previous errors
-
diff --git a/src/tools/clippy/tests/ui/issue-3145.rs b/src/tools/clippy/tests/ui/issue-3145.rs
index 586d13647..0b07de114 100644
--- a/src/tools/clippy/tests/ui/issue-3145.rs
+++ b/src/tools/clippy/tests/ui/issue-3145.rs
@@ -1,3 +1,3 @@
fn main() {
- println!("{}" a); //~ERROR expected `,`, found `a`
+ println!("{}" a); //~ERROR: expected `,`, found `a`
}
diff --git a/src/tools/clippy/tests/ui/issue-3145.stderr b/src/tools/clippy/tests/ui/issue-3145.stderr
index a35032aa1..d7c2c88a2 100644
--- a/src/tools/clippy/tests/ui/issue-3145.stderr
+++ b/src/tools/clippy/tests/ui/issue-3145.stderr
@@ -1,7 +1,7 @@
error: expected `,`, found `a`
--> $DIR/issue-3145.rs:2:19
|
-LL | println!("{}" a); //~ERROR expected `,`, found `a`
+LL | println!("{}" a);
| ^ expected `,`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/issue_4266.stderr b/src/tools/clippy/tests/ui/issue_4266.stderr
index fd553aa45..5b60646ef 100644
--- a/src/tools/clippy/tests/ui/issue_4266.stderr
+++ b/src/tools/clippy/tests/ui/issue_4266.stderr
@@ -1,16 +1,16 @@
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/issue_4266.rs:4:1
+ --> $DIR/issue_4266.rs:4:16
|
LL | async fn sink1<'a>(_: &'a str) {} // lint
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
= note: `-D clippy::needless-lifetimes` implied by `-D warnings`
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/issue_4266.rs:8:1
+ --> $DIR/issue_4266.rs:8: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
diff --git a/src/tools/clippy/tests/ui/items_after_test_module/block_module.stderr b/src/tools/clippy/tests/ui/items_after_test_module/block_module.stderr
index 597f1b951..1b6257471 100644
--- a/src/tools/clippy/tests/ui/items_after_test_module/block_module.stderr
+++ b/src/tools/clippy/tests/ui/items_after_test_module/block_module.stderr
@@ -1,17 +1,2 @@
-error: items were found after the testing module
- --> $DIR/block_module.rs:13:1
- |
-LL | / mod tests {
-LL | | #[test]
-LL | | fn hi() {}
-LL | | }
-... |
-LL | | () => {};
-LL | | }
- | |_^
- |
- = help: move the items to before the testing module was defined
- = note: `-D clippy::items-after-test-module` implied by `-D warnings`
-
-error: aborting due to previous error
+error: Option 'test' given more than once
diff --git a/src/tools/clippy/tests/ui/iter_cloned_collect.fixed b/src/tools/clippy/tests/ui/iter_cloned_collect.fixed
index 88f08bb99..2baea06f8 100644
--- a/src/tools/clippy/tests/ui/iter_cloned_collect.fixed
+++ b/src/tools/clippy/tests/ui/iter_cloned_collect.fixed
@@ -1,6 +1,7 @@
//@run-rustfix
#![allow(unused)]
+#![allow(clippy::useless_vec)]
use std::collections::HashSet;
use std::collections::VecDeque;
diff --git a/src/tools/clippy/tests/ui/iter_cloned_collect.rs b/src/tools/clippy/tests/ui/iter_cloned_collect.rs
index d3438b7f5..9eac94eb8 100644
--- a/src/tools/clippy/tests/ui/iter_cloned_collect.rs
+++ b/src/tools/clippy/tests/ui/iter_cloned_collect.rs
@@ -1,6 +1,7 @@
//@run-rustfix
#![allow(unused)]
+#![allow(clippy::useless_vec)]
use std::collections::HashSet;
use std::collections::VecDeque;
diff --git a/src/tools/clippy/tests/ui/iter_cloned_collect.stderr b/src/tools/clippy/tests/ui/iter_cloned_collect.stderr
index b2cc497bf..b38cf547d 100644
--- a/src/tools/clippy/tests/ui/iter_cloned_collect.stderr
+++ b/src/tools/clippy/tests/ui/iter_cloned_collect.stderr
@@ -1,5 +1,5 @@
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:11:27
|
LL | let v2: Vec<isize> = v.iter().cloned().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()`
@@ -7,13 +7,13 @@ LL | let v2: Vec<isize> = v.iter().cloned().collect();
= note: `-D clippy::iter-cloned-collect` implied by `-D warnings`
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:16:38
|
LL | let _: Vec<isize> = 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:21:24
|
LL | .to_bytes()
| ________________________^
@@ -23,13 +23,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:29:24
|
LL | let _: Vec<_> = arr.iter().cloned().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()`
error: called `iter().copied().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable
- --> $DIR/iter_cloned_collect.rs:31:26
+ --> $DIR/iter_cloned_collect.rs:32:26
|
LL | let _: Vec<isize> = 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 4367a12f8..b62082014 100644
--- a/src/tools/clippy/tests/ui/iter_count.fixed
+++ b/src/tools/clippy/tests/ui/iter_count.fixed
@@ -7,7 +7,8 @@
array_into_iter,
unused_mut,
clippy::into_iter_on_ref,
- clippy::unnecessary_operation
+ clippy::unnecessary_operation,
+ clippy::useless_vec
)]
extern crate option_helpers;
diff --git a/src/tools/clippy/tests/ui/iter_count.rs b/src/tools/clippy/tests/ui/iter_count.rs
index 8c7543cf0..fb2161312 100644
--- a/src/tools/clippy/tests/ui/iter_count.rs
+++ b/src/tools/clippy/tests/ui/iter_count.rs
@@ -7,7 +7,8 @@
array_into_iter,
unused_mut,
clippy::into_iter_on_ref,
- clippy::unnecessary_operation
+ clippy::unnecessary_operation,
+ clippy::useless_vec
)]
extern crate option_helpers;
diff --git a/src/tools/clippy/tests/ui/iter_count.stderr b/src/tools/clippy/tests/ui/iter_count.stderr
index 2e3d7fc35..f9aee0b78 100644
--- a/src/tools/clippy/tests/ui/iter_count.stderr
+++ b/src/tools/clippy/tests/ui/iter_count.stderr
@@ -1,5 +1,5 @@
error: called `.iter().count()` on a `slice`
- --> $DIR/iter_count.rs:54:6
+ --> $DIR/iter_count.rs:55:6
|
LL | &vec[..].iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()`
@@ -7,145 +7,145 @@ LL | &vec[..].iter().count();
= note: `-D clippy::iter-count` implied by `-D warnings`
error: called `.iter().count()` on a `Vec`
- --> $DIR/iter_count.rs:55:5
+ --> $DIR/iter_count.rs:56:5
|
LL | vec.iter().count();
| ^^^^^^^^^^^^^^^^^^ help: try: `vec.len()`
error: called `.iter().count()` on a `slice`
- --> $DIR/iter_count.rs:56:5
+ --> $DIR/iter_count.rs:57:5
|
LL | boxed_slice.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice.len()`
error: called `.iter().count()` on a `VecDeque`
- --> $DIR/iter_count.rs:57:5
+ --> $DIR/iter_count.rs:58:5
|
LL | vec_deque.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()`
error: called `.iter().count()` on a `HashSet`
- --> $DIR/iter_count.rs:58:5
+ --> $DIR/iter_count.rs:59:5
|
LL | hash_set.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()`
error: called `.iter().count()` on a `HashMap`
- --> $DIR/iter_count.rs:59:5
+ --> $DIR/iter_count.rs:60:5
|
LL | hash_map.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()`
error: called `.iter().count()` on a `BTreeMap`
- --> $DIR/iter_count.rs:60:5
+ --> $DIR/iter_count.rs:61:5
|
LL | b_tree_map.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()`
error: called `.iter().count()` on a `BTreeSet`
- --> $DIR/iter_count.rs:61:5
+ --> $DIR/iter_count.rs:62:5
|
LL | b_tree_set.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()`
error: called `.iter().count()` on a `LinkedList`
- --> $DIR/iter_count.rs:62:5
+ --> $DIR/iter_count.rs:63:5
|
LL | linked_list.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()`
error: called `.iter().count()` on a `BinaryHeap`
- --> $DIR/iter_count.rs:63:5
+ --> $DIR/iter_count.rs:64:5
|
LL | binary_heap.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()`
error: called `.iter_mut().count()` on a `Vec`
- --> $DIR/iter_count.rs:65:5
+ --> $DIR/iter_count.rs:66:5
|
LL | vec.iter_mut().count();
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()`
error: called `.iter_mut().count()` on a `slice`
- --> $DIR/iter_count.rs:66:6
+ --> $DIR/iter_count.rs:67:6
|
LL | &vec[..].iter_mut().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()`
error: called `.iter_mut().count()` on a `VecDeque`
- --> $DIR/iter_count.rs:67:5
+ --> $DIR/iter_count.rs:68:5
|
LL | vec_deque.iter_mut().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()`
error: called `.iter_mut().count()` on a `HashMap`
- --> $DIR/iter_count.rs:68:5
+ --> $DIR/iter_count.rs:69:5
|
LL | hash_map.iter_mut().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()`
error: called `.iter_mut().count()` on a `BTreeMap`
- --> $DIR/iter_count.rs:69:5
+ --> $DIR/iter_count.rs:70: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:70:5
+ --> $DIR/iter_count.rs:71:5
|
LL | linked_list.iter_mut().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()`
error: called `.into_iter().count()` on a `slice`
- --> $DIR/iter_count.rs:72:6
+ --> $DIR/iter_count.rs:73:6
|
LL | &vec[..].into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()`
error: called `.into_iter().count()` on a `Vec`
- --> $DIR/iter_count.rs:73:5
+ --> $DIR/iter_count.rs:74:5
|
LL | vec.into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()`
error: called `.into_iter().count()` on a `VecDeque`
- --> $DIR/iter_count.rs:74:5
+ --> $DIR/iter_count.rs:75:5
|
LL | vec_deque.into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()`
error: called `.into_iter().count()` on a `HashSet`
- --> $DIR/iter_count.rs:75:5
+ --> $DIR/iter_count.rs:76:5
|
LL | hash_set.into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()`
error: called `.into_iter().count()` on a `HashMap`
- --> $DIR/iter_count.rs:76:5
+ --> $DIR/iter_count.rs:77:5
|
LL | hash_map.into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()`
error: called `.into_iter().count()` on a `BTreeMap`
- --> $DIR/iter_count.rs:77:5
+ --> $DIR/iter_count.rs:78: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:78:5
+ --> $DIR/iter_count.rs:79: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:79:5
+ --> $DIR/iter_count.rs:80:5
|
LL | linked_list.into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()`
error: called `.into_iter().count()` on a `BinaryHeap`
- --> $DIR/iter_count.rs:80:5
+ --> $DIR/iter_count.rs:81:5
|
LL | binary_heap.into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()`
diff --git a/src/tools/clippy/tests/ui/iter_next_loop.rs b/src/tools/clippy/tests/ui/iter_next_loop.rs
new file mode 100644
index 000000000..548b799de
--- /dev/null
+++ b/src/tools/clippy/tests/ui/iter_next_loop.rs
@@ -0,0 +1,16 @@
+#![allow(dead_code, unused, for_loops_over_fallibles)]
+#![warn(clippy::iter_next_loop)]
+
+fn main() {
+ let x = [1, 2, 3, 4];
+ for _ in vec.iter().next() {}
+
+ struct Unrelated(&'static [u8]);
+ impl Unrelated {
+ fn next(&self) -> std::slice::Iter<u8> {
+ self.0.iter()
+ }
+ }
+ let u = Unrelated(&[0]);
+ for _v in u.next() {} // no error
+}
diff --git a/src/tools/clippy/tests/ui/iter_next_loop.stderr b/src/tools/clippy/tests/ui/iter_next_loop.stderr
new file mode 100644
index 000000000..5bba0e635
--- /dev/null
+++ b/src/tools/clippy/tests/ui/iter_next_loop.stderr
@@ -0,0 +1,9 @@
+error[E0423]: expected value, found macro `vec`
+ --> $DIR/iter_next_loop.rs:6:14
+ |
+LL | for _ in vec.iter().next() {}
+ | ^^^ not a value
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0423`.
diff --git a/src/tools/clippy/tests/ui/iter_next_slice.fixed b/src/tools/clippy/tests/ui/iter_next_slice.fixed
index d862abc34..702edccdb 100644
--- a/src/tools/clippy/tests/ui/iter_next_slice.fixed
+++ b/src/tools/clippy/tests/ui/iter_next_slice.fixed
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::iter_next_slice)]
+#![allow(clippy::useless_vec)]
fn main() {
// test code goes here
diff --git a/src/tools/clippy/tests/ui/iter_next_slice.rs b/src/tools/clippy/tests/ui/iter_next_slice.rs
index da6fc46e4..30bfc72de 100644
--- a/src/tools/clippy/tests/ui/iter_next_slice.rs
+++ b/src/tools/clippy/tests/ui/iter_next_slice.rs
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::iter_next_slice)]
+#![allow(clippy::useless_vec)]
fn main() {
// test code goes here
diff --git a/src/tools/clippy/tests/ui/iter_next_slice.stderr b/src/tools/clippy/tests/ui/iter_next_slice.stderr
index d8b89061f..0db8201a1 100644
--- a/src/tools/clippy/tests/ui/iter_next_slice.stderr
+++ b/src/tools/clippy/tests/ui/iter_next_slice.stderr
@@ -1,5 +1,5 @@
error: using `.iter().next()` on an array
- --> $DIR/iter_next_slice.rs:9:13
+ --> $DIR/iter_next_slice.rs:10:13
|
LL | let _ = s.iter().next();
| ^^^^^^^^^^^^^^^ help: try calling: `s.first()`
@@ -7,19 +7,19 @@ LL | let _ = s.iter().next();
= note: `-D clippy::iter-next-slice` implied by `-D warnings`
error: using `.iter().next()` on a Slice without end index
- --> $DIR/iter_next_slice.rs:12:13
+ --> $DIR/iter_next_slice.rs:13: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:15:13
+ --> $DIR/iter_next_slice.rs:16: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:18:13
+ --> $DIR/iter_next_slice.rs:19:13
|
LL | let _ = v.iter().next();
| ^^^^^^^^^^^^^^^ help: try calling: `v.first()`
diff --git a/src/tools/clippy/tests/ui/iter_nth.rs b/src/tools/clippy/tests/ui/iter_nth.rs
index e7fb97d4f..7c567bb81 100644
--- a/src/tools/clippy/tests/ui/iter_nth.rs
+++ b/src/tools/clippy/tests/ui/iter_nth.rs
@@ -1,6 +1,7 @@
//@aux-build:option_helpers.rs
#![warn(clippy::iter_nth)]
+#![allow(clippy::useless_vec)]
#[macro_use]
extern crate option_helpers;
diff --git a/src/tools/clippy/tests/ui/iter_nth.stderr b/src/tools/clippy/tests/ui/iter_nth.stderr
index a0fe353bc..24be81454 100644
--- a/src/tools/clippy/tests/ui/iter_nth.stderr
+++ b/src/tools/clippy/tests/ui/iter_nth.stderr
@@ -1,5 +1,5 @@
-error: called `.iter().nth()` on a Vec
- --> $DIR/iter_nth.rs:33:23
+error: called `.iter().nth()` on a `Vec`
+ --> $DIR/iter_nth.rs:34:23
|
LL | let bad_vec = some_vec.iter().nth(3);
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | let bad_vec = some_vec.iter().nth(3);
= note: `-D clippy::iter-nth` implied by `-D warnings`
error: called `.iter().nth()` on a slice
- --> $DIR/iter_nth.rs:34:26
+ --> $DIR/iter_nth.rs:35:26
|
LL | let bad_slice = &some_vec[..].iter().nth(3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,23 +16,23 @@ LL | let bad_slice = &some_vec[..].iter().nth(3);
= help: calling `.get()` is both faster and more readable
error: called `.iter().nth()` on a slice
- --> $DIR/iter_nth.rs:35:31
+ --> $DIR/iter_nth.rs:36:31
|
LL | let bad_boxed_slice = boxed_slice.iter().nth(3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: calling `.get()` is both faster and more readable
-error: called `.iter().nth()` on a VecDeque
- --> $DIR/iter_nth.rs:36:29
+error: called `.iter().nth()` on a `VecDeque`
+ --> $DIR/iter_nth.rs:37:29
|
LL | let bad_vec_deque = some_vec_deque.iter().nth(3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: calling `.get()` is both faster and more readable
-error: called `.iter_mut().nth()` on a Vec
- --> $DIR/iter_nth.rs:41:23
+error: called `.iter_mut().nth()` on a `Vec`
+ --> $DIR/iter_nth.rs:42:23
|
LL | let bad_vec = some_vec.iter_mut().nth(3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,15 +40,15 @@ LL | let bad_vec = some_vec.iter_mut().nth(3);
= help: calling `.get_mut()` is both faster and more readable
error: called `.iter_mut().nth()` on a slice
- --> $DIR/iter_nth.rs:44:26
+ --> $DIR/iter_nth.rs:45:26
|
LL | let bad_slice = &some_vec[..].iter_mut().nth(3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: calling `.get_mut()` is both faster and more readable
-error: called `.iter_mut().nth()` on a VecDeque
- --> $DIR/iter_nth.rs:47:29
+error: called `.iter_mut().nth()` on a `VecDeque`
+ --> $DIR/iter_nth.rs:48:29
|
LL | let bad_vec_deque = some_vec_deque.iter_mut().nth(3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/iter_nth_zero.fixed b/src/tools/clippy/tests/ui/iter_nth_zero.fixed
index 587b0d1d3..91f4a7ba0 100644
--- a/src/tools/clippy/tests/ui/iter_nth_zero.fixed
+++ b/src/tools/clippy/tests/ui/iter_nth_zero.fixed
@@ -29,3 +29,18 @@ fn main() {
let mut iter2 = s3.iter();
let _unwrapped = iter2.next().unwrap();
}
+
+struct Issue9820;
+
+impl Iterator for Issue9820 {
+ type Item = ();
+
+ fn nth(&mut self, _n: usize) -> Option<Self::Item> {
+ todo!()
+ }
+
+ // Don't lint in implementations of `next`, as calling `next` in `next` is incorrect
+ fn next(&mut self) -> Option<Self::Item> {
+ self.nth(0)
+ }
+}
diff --git a/src/tools/clippy/tests/ui/iter_nth_zero.rs b/src/tools/clippy/tests/ui/iter_nth_zero.rs
index 93b576ec5..160a895bb 100644
--- a/src/tools/clippy/tests/ui/iter_nth_zero.rs
+++ b/src/tools/clippy/tests/ui/iter_nth_zero.rs
@@ -29,3 +29,18 @@ fn main() {
let mut iter2 = s3.iter();
let _unwrapped = iter2.nth(0).unwrap();
}
+
+struct Issue9820;
+
+impl Iterator for Issue9820 {
+ type Item = ();
+
+ fn nth(&mut self, _n: usize) -> Option<Self::Item> {
+ todo!()
+ }
+
+ // Don't lint in implementations of `next`, as calling `next` in `next` is incorrect
+ fn next(&mut self) -> Option<Self::Item> {
+ self.nth(0)
+ }
+}
diff --git a/src/tools/clippy/tests/ui/iter_overeager_cloned.fixed b/src/tools/clippy/tests/ui/iter_overeager_cloned.fixed
index bf576e9cb..2874513c0 100644
--- a/src/tools/clippy/tests/ui/iter_overeager_cloned.fixed
+++ b/src/tools/clippy/tests/ui/iter_overeager_cloned.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
#![warn(clippy::iter_overeager_cloned, clippy::redundant_clone, clippy::filter_next)]
-#![allow(dead_code, clippy::let_unit_value)]
+#![allow(dead_code, clippy::let_unit_value, clippy::useless_vec)]
fn main() {
let vec = vec!["1".to_string(), "2".to_string(), "3".to_string()];
diff --git a/src/tools/clippy/tests/ui/iter_overeager_cloned.rs b/src/tools/clippy/tests/ui/iter_overeager_cloned.rs
index df42d88ef..26f39734a 100644
--- a/src/tools/clippy/tests/ui/iter_overeager_cloned.rs
+++ b/src/tools/clippy/tests/ui/iter_overeager_cloned.rs
@@ -1,6 +1,6 @@
//@run-rustfix
#![warn(clippy::iter_overeager_cloned, clippy::redundant_clone, clippy::filter_next)]
-#![allow(dead_code, clippy::let_unit_value)]
+#![allow(dead_code, clippy::let_unit_value, clippy::useless_vec)]
fn main() {
let vec = vec!["1".to_string(), "2".to_string(), "3".to_string()];
diff --git a/src/tools/clippy/tests/ui/iter_skip_next.fixed b/src/tools/clippy/tests/ui/iter_skip_next.fixed
index 8f2cefc43..b888d965e 100644
--- a/src/tools/clippy/tests/ui/iter_skip_next.fixed
+++ b/src/tools/clippy/tests/ui/iter_skip_next.fixed
@@ -4,6 +4,7 @@
#![warn(clippy::iter_skip_next)]
#![allow(clippy::disallowed_names)]
#![allow(clippy::iter_nth)]
+#![allow(clippy::useless_vec)]
#![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 71d83384f..e44efdebc 100644
--- a/src/tools/clippy/tests/ui/iter_skip_next.rs
+++ b/src/tools/clippy/tests/ui/iter_skip_next.rs
@@ -4,6 +4,7 @@
#![warn(clippy::iter_skip_next)]
#![allow(clippy::disallowed_names)]
#![allow(clippy::iter_nth)]
+#![allow(clippy::useless_vec)]
#![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 ca6970b27..4ee26e088 100644
--- a/src/tools/clippy/tests/ui/iter_skip_next.stderr
+++ b/src/tools/clippy/tests/ui/iter_skip_next.stderr
@@ -1,5 +1,5 @@
error: called `skip(..).next()` on an iterator
- --> $DIR/iter_skip_next.rs:16:28
+ --> $DIR/iter_skip_next.rs:17:28
|
LL | let _ = some_vec.iter().skip(42).next();
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)`
@@ -7,37 +7,37 @@ LL | let _ = some_vec.iter().skip(42).next();
= note: `-D clippy::iter-skip-next` implied by `-D warnings`
error: called `skip(..).next()` on an iterator
- --> $DIR/iter_skip_next.rs:17:36
+ --> $DIR/iter_skip_next.rs:18:36
|
LL | let _ = some_vec.iter().cycle().skip(42).next();
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(42)`
error: called `skip(..).next()` on an iterator
- --> $DIR/iter_skip_next.rs:18:20
+ --> $DIR/iter_skip_next.rs:19:20
|
LL | let _ = (1..10).skip(10).next();
| ^^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(10)`
error: called `skip(..).next()` on an iterator
- --> $DIR/iter_skip_next.rs:19:33
+ --> $DIR/iter_skip_next.rs:20:33
|
LL | let _ = &some_vec[..].iter().skip(3).next();
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(3)`
error: called `skip(..).next()` on an iterator
- --> $DIR/iter_skip_next.rs:27:26
+ --> $DIR/iter_skip_next.rs:28:26
|
LL | let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect();
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)`
error: called `skip(..).next()` on an iterator
- --> $DIR/iter_skip_next.rs:29:29
+ --> $DIR/iter_skip_next.rs:30:29
|
LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect();
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)`
error: called `skip(..).next()` on an iterator
- --> $DIR/iter_skip_next.rs:35:29
+ --> $DIR/iter_skip_next.rs:36:29
|
LL | let _: Vec<&str> = s.skip(1).next().unwrap().split(' ').collect();
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)`
diff --git a/src/tools/clippy/tests/ui/iter_with_drain.fixed b/src/tools/clippy/tests/ui/iter_with_drain.fixed
index 24a95c4d0..7a8c67701 100644
--- a/src/tools/clippy/tests/ui/iter_with_drain.fixed
+++ b/src/tools/clippy/tests/ui/iter_with_drain.fixed
@@ -2,7 +2,7 @@
// will emits unused mut warnings after fixing
#![allow(unused_mut)]
// will emits needless collect warnings after fixing
-#![allow(clippy::needless_collect)]
+#![allow(clippy::needless_collect, clippy::drain_collect)]
#![warn(clippy::iter_with_drain)]
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
diff --git a/src/tools/clippy/tests/ui/iter_with_drain.rs b/src/tools/clippy/tests/ui/iter_with_drain.rs
index a118c981e..cf3a935c3 100644
--- a/src/tools/clippy/tests/ui/iter_with_drain.rs
+++ b/src/tools/clippy/tests/ui/iter_with_drain.rs
@@ -2,7 +2,7 @@
// will emits unused mut warnings after fixing
#![allow(unused_mut)]
// will emits needless collect warnings after fixing
-#![allow(clippy::needless_collect)]
+#![allow(clippy::needless_collect, clippy::drain_collect)]
#![warn(clippy::iter_with_drain)]
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
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 13d1cfd42..33ec78e9a 100644
--- a/src/tools/clippy/tests/ui/iterator_step_by_zero.rs
+++ b/src/tools/clippy/tests/ui/iterator_step_by_zero.rs
@@ -1,3 +1,4 @@
+#![allow(clippy::useless_vec)]
#[warn(clippy::iterator_step_by_zero)]
fn main() {
let _ = vec!["A", "B", "B"].iter().step_by(0);
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 d792aea11..b470e2ed2 100644
--- a/src/tools/clippy/tests/ui/iterator_step_by_zero.stderr
+++ b/src/tools/clippy/tests/ui/iterator_step_by_zero.stderr
@@ -1,5 +1,5 @@
error: `Iterator::step_by(0)` will panic at runtime
- --> $DIR/iterator_step_by_zero.rs:3:13
+ --> $DIR/iterator_step_by_zero.rs:4:13
|
LL | let _ = vec!["A", "B", "B"].iter().step_by(0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -7,37 +7,37 @@ LL | let _ = vec!["A", "B", "B"].iter().step_by(0);
= note: `-D clippy::iterator-step-by-zero` implied by `-D warnings`
error: `Iterator::step_by(0)` will panic at runtime
- --> $DIR/iterator_step_by_zero.rs:4:13
+ --> $DIR/iterator_step_by_zero.rs:5:13
|
LL | let _ = "XXX".chars().step_by(0);
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: `Iterator::step_by(0)` will panic at runtime
- --> $DIR/iterator_step_by_zero.rs:5:13
+ --> $DIR/iterator_step_by_zero.rs:6:13
|
LL | let _ = (0..1).step_by(0);
| ^^^^^^^^^^^^^^^^^
error: `Iterator::step_by(0)` will panic at runtime
- --> $DIR/iterator_step_by_zero.rs:14:13
+ --> $DIR/iterator_step_by_zero.rs:15:13
|
LL | let _ = (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:16:13
|
LL | let _ = (1..=2).step_by(0);
| ^^^^^^^^^^^^^^^^^^
error: `Iterator::step_by(0)` will panic at runtime
- --> $DIR/iterator_step_by_zero.rs:18:13
+ --> $DIR/iterator_step_by_zero.rs:19:13
|
LL | let _ = x.step_by(0);
| ^^^^^^^^^^^^
error: `Iterator::step_by(0)` will panic at runtime
- --> $DIR/iterator_step_by_zero.rs:22:13
+ --> $DIR/iterator_step_by_zero.rs:23:13
|
LL | let _ = v1.iter().step_by(2 / 3);
| ^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/large_enum_variant.rs b/src/tools/clippy/tests/ui/large_enum_variant.rs
index ea8bc5b4a..e677cc9a7 100644
--- a/src/tools/clippy/tests/ui/large_enum_variant.rs
+++ b/src/tools/clippy/tests/ui/large_enum_variant.rs
@@ -1,4 +1,4 @@
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![allow(dead_code)]
#![allow(unused_variables)]
diff --git a/src/tools/clippy/tests/ui/large_futures.rs b/src/tools/clippy/tests/ui/large_futures.rs
index 4a8ba995d..e0f6b3d9d 100644
--- a/src/tools/clippy/tests/ui/large_futures.rs
+++ b/src/tools/clippy/tests/ui/large_futures.rs
@@ -1,5 +1,6 @@
#![feature(generators)]
#![warn(clippy::large_futures)]
+#![allow(clippy::never_loop)]
#![allow(clippy::future_not_send)]
#![allow(clippy::manual_async_fn)]
diff --git a/src/tools/clippy/tests/ui/large_futures.stderr b/src/tools/clippy/tests/ui/large_futures.stderr
index 67e0fceff..5bcf05488 100644
--- a/src/tools/clippy/tests/ui/large_futures.stderr
+++ b/src/tools/clippy/tests/ui/large_futures.stderr
@@ -1,5 +1,5 @@
error: large future with a size of 16385 bytes
- --> $DIR/large_futures.rs:10:9
+ --> $DIR/large_futures.rs:11:9
|
LL | big_fut([0u8; 1024 * 16]).await;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Box::pin` on it: `Box::pin(big_fut([0u8; 1024 * 16]))`
@@ -7,37 +7,37 @@ LL | big_fut([0u8; 1024 * 16]).await;
= note: `-D clippy::large-futures` implied by `-D warnings`
error: large future with a size of 16386 bytes
- --> $DIR/large_futures.rs:12:5
+ --> $DIR/large_futures.rs:13: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:16:9
+ --> $DIR/large_futures.rs:17: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:20:13
+ --> $DIR/large_futures.rs:21: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:27:5
+ --> $DIR/large_futures.rs:28: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:28:5
+ --> $DIR/large_futures.rs:29: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:40:5
+ --> $DIR/large_futures.rs:41:5
|
LL | / async {
LL | | let x = [0i32; 1024 * 16];
@@ -56,7 +56,7 @@ LL + })
|
error: large future with a size of 65540 bytes
- --> $DIR/large_futures.rs:51:13
+ --> $DIR/large_futures.rs:52: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 99787ffd3..3e9d5e6a4 100644
--- a/src/tools/clippy/tests/ui/large_stack_arrays.rs
+++ b/src/tools/clippy/tests/ui/large_stack_arrays.rs
@@ -18,6 +18,19 @@ pub static DOESNOTLINT2: [u8; 512_001] = {
[x; 512_001]
};
+fn issue_10741() {
+ #[derive(Copy, Clone)]
+ struct Large([u32; 100_000]);
+
+ fn build() -> Large {
+ Large([0; 100_000])
+ }
+
+ let _x = [build(); 3];
+
+ let _y = [build(), build(), build()];
+}
+
fn main() {
let bad = (
[0u32; 20_000_000],
diff --git a/src/tools/clippy/tests/ui/large_stack_arrays.stderr b/src/tools/clippy/tests/ui/large_stack_arrays.stderr
index 24e900949..118d39566 100644
--- a/src/tools/clippy/tests/ui/large_stack_arrays.stderr
+++ b/src/tools/clippy/tests/ui/large_stack_arrays.stderr
@@ -1,14 +1,30 @@
error: allocating a local array larger than 512000 bytes
- --> $DIR/large_stack_arrays.rs:23:9
+ --> $DIR/large_stack_arrays.rs:29:14
+ |
+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`
+
+error: allocating a local array larger than 512000 bytes
+ --> $DIR/large_stack_arrays.rs:31:14
+ |
+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
|
LL | [0u32; 20_000_000],
| ^^^^^^^^^^^^^^^^^^
|
= help: consider allocating on the heap with `vec![0u32; 20_000_000].into_boxed_slice()`
- = note: `-D clippy::large-stack-arrays` implied by `-D warnings`
error: allocating a local array larger than 512000 bytes
- --> $DIR/large_stack_arrays.rs:24:9
+ --> $DIR/large_stack_arrays.rs:37:9
|
LL | [S { data: [0; 32] }; 5000],
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,7 +32,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:25:9
+ --> $DIR/large_stack_arrays.rs:38:9
|
LL | [Some(""); 20_000_000],
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -24,7 +40,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:26:9
+ --> $DIR/large_stack_arrays.rs:39:9
|
LL | [E::T(0); 5000],
| ^^^^^^^^^^^^^^^
@@ -32,12 +48,12 @@ 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:27:9
+ --> $DIR/large_stack_arrays.rs:40:9
|
LL | [0u8; usize::MAX],
| ^^^^^^^^^^^^^^^^^
|
= help: consider allocating on the heap with `vec![0u8; usize::MAX].into_boxed_slice()`
-error: aborting due to 5 previous errors
+error: aborting due to 7 previous errors
diff --git a/src/tools/clippy/tests/ui/large_stack_frames.rs b/src/tools/clippy/tests/ui/large_stack_frames.rs
new file mode 100644
index 000000000..cd9d0c8a6
--- /dev/null
+++ b/src/tools/clippy/tests/ui/large_stack_frames.rs
@@ -0,0 +1,44 @@
+#![allow(unused, incomplete_features)]
+#![warn(clippy::large_stack_frames)]
+#![feature(unsized_locals)]
+
+use std::hint::black_box;
+
+fn generic<T: Default>() {
+ let x = T::default();
+ black_box(&x);
+}
+
+fn unsized_local() {
+ let x: dyn std::fmt::Display = *(Box::new(1) as Box<dyn std::fmt::Display>);
+ black_box(&x);
+}
+
+struct ArrayDefault<const N: usize>([u8; N]);
+
+impl<const N: usize> Default for ArrayDefault<N> {
+ fn default() -> Self {
+ Self([0; N])
+ }
+}
+
+fn many_small_arrays() {
+ let x = [0u8; 500_000];
+ let x2 = [0u8; 500_000];
+ let x3 = [0u8; 500_000];
+ let x4 = [0u8; 500_000];
+ let x5 = [0u8; 500_000];
+ black_box((&x, &x2, &x3, &x4, &x5));
+}
+
+fn large_return_value() -> ArrayDefault<1_000_000> {
+ Default::default()
+}
+
+fn large_fn_arg(x: ArrayDefault<1_000_000>) {
+ black_box(&x);
+}
+
+fn main() {
+ generic::<ArrayDefault<1_000_000>>();
+}
diff --git a/src/tools/clippy/tests/ui/large_stack_frames.stderr b/src/tools/clippy/tests/ui/large_stack_frames.stderr
new file mode 100644
index 000000000..d57df8596
--- /dev/null
+++ b/src/tools/clippy/tests/ui/large_stack_frames.stderr
@@ -0,0 +1,37 @@
+error: this function allocates a large amount of stack space
+ --> $DIR/large_stack_frames.rs:25:1
+ |
+LL | / fn many_small_arrays() {
+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 | | }
+ | |_^
+ |
+ = note: allocating large amounts of stack space can overflow the stack
+ = note: `-D clippy::large-stack-frames` implied by `-D warnings`
+
+error: this function allocates a large amount of stack space
+ --> $DIR/large_stack_frames.rs:34:1
+ |
+LL | / fn large_return_value() -> ArrayDefault<1_000_000> {
+LL | | Default::default()
+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
+ |
+LL | / fn large_fn_arg(x: ArrayDefault<1_000_000>) {
+LL | | black_box(&x);
+LL | | }
+ | |_^
+ |
+ = note: allocating large amounts of stack space can overflow the stack
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/len_zero.fixed b/src/tools/clippy/tests/ui/len_zero.fixed
index 2c22abd7e..fafee6a0d 100644
--- a/src/tools/clippy/tests/ui/len_zero.fixed
+++ b/src/tools/clippy/tests/ui/len_zero.fixed
@@ -1,7 +1,7 @@
//@run-rustfix
#![warn(clippy::len_zero)]
-#![allow(dead_code, unused, clippy::len_without_is_empty)]
+#![allow(dead_code, unused, clippy::needless_if, clippy::len_without_is_empty)]
extern crate core;
use core::ops::Deref;
diff --git a/src/tools/clippy/tests/ui/len_zero.rs b/src/tools/clippy/tests/ui/len_zero.rs
index a011ff976..6a9006c47 100644
--- a/src/tools/clippy/tests/ui/len_zero.rs
+++ b/src/tools/clippy/tests/ui/len_zero.rs
@@ -1,7 +1,7 @@
//@run-rustfix
#![warn(clippy::len_zero)]
-#![allow(dead_code, unused, clippy::len_without_is_empty)]
+#![allow(dead_code, unused, clippy::needless_if, clippy::len_without_is_empty)]
extern crate core;
use core::ops::Deref;
diff --git a/src/tools/clippy/tests/ui/let_underscore_untyped.rs b/src/tools/clippy/tests/ui/let_underscore_untyped.rs
index 2c313ff35..431d83778 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
+//@aux-build: proc_macros.rs:proc-macro
#![allow(unused)]
#![warn(clippy::let_underscore_untyped)]
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 ae1a480bc..8214176cf 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
+//@aux-build: proc_macros.rs:proc-macro
#![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/lossy_float_literal.fixed b/src/tools/clippy/tests/ui/lossy_float_literal.fixed
index a20885756..e19f4980c 100644
--- a/src/tools/clippy/tests/ui/lossy_float_literal.fixed
+++ b/src/tools/clippy/tests/ui/lossy_float_literal.fixed
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::lossy_float_literal)]
+#![allow(overflowing_literals, unused)]
fn main() {
// Lossy whole-number float literals
@@ -32,4 +33,7 @@ fn main() {
let _: f64 = 1e99;
let _: f64 = 1E99;
let _: f32 = 0.1;
+
+ const INF1: f32 = 1000000000000000000000000000000000f32;
+ const NEG_INF1: f32 = -340282357000000000000000000000000000001_f32;
}
diff --git a/src/tools/clippy/tests/ui/lossy_float_literal.rs b/src/tools/clippy/tests/ui/lossy_float_literal.rs
index 1a75f214c..a2a1cfb31 100644
--- a/src/tools/clippy/tests/ui/lossy_float_literal.rs
+++ b/src/tools/clippy/tests/ui/lossy_float_literal.rs
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::lossy_float_literal)]
+#![allow(overflowing_literals, unused)]
fn main() {
// Lossy whole-number float literals
@@ -32,4 +33,7 @@ fn main() {
let _: f64 = 1e99;
let _: f64 = 1E99;
let _: f32 = 0.1;
+
+ const INF1: f32 = 1000000000000000000000000000000000f32;
+ const NEG_INF1: f32 = -340282357000000000000000000000000000001_f32;
}
diff --git a/src/tools/clippy/tests/ui/lossy_float_literal.stderr b/src/tools/clippy/tests/ui/lossy_float_literal.stderr
index d2193c0c8..2d72b1643 100644
--- a/src/tools/clippy/tests/ui/lossy_float_literal.stderr
+++ b/src/tools/clippy/tests/ui/lossy_float_literal.stderr
@@ -1,5 +1,5 @@
error: literal cannot be represented as the underlying type without loss of precision
- --> $DIR/lossy_float_literal.rs:6:18
+ --> $DIR/lossy_float_literal.rs:7:18
|
LL | let _: f32 = 16_777_217.0;
| ^^^^^^^^^^^^ help: consider changing the type or replacing it with: `16_777_216.0`
@@ -7,61 +7,61 @@ LL | let _: f32 = 16_777_217.0;
= note: `-D clippy::lossy-float-literal` implied by `-D warnings`
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:8: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:8:18
+ --> $DIR/lossy_float_literal.rs:9: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:9:18
+ --> $DIR/lossy_float_literal.rs:10: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:10:13
+ --> $DIR/lossy_float_literal.rs:11: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:11:19
+ --> $DIR/lossy_float_literal.rs:12: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:12:18
+ --> $DIR/lossy_float_literal.rs:13: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:13:18
+ --> $DIR/lossy_float_literal.rs:14: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:14:18
+ --> $DIR/lossy_float_literal.rs:15: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:15:13
+ --> $DIR/lossy_float_literal.rs:16: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:16:19
+ --> $DIR/lossy_float_literal.rs:17: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 b4dabe3ca..53b6a0250 100644
--- a/src/tools/clippy/tests/ui/macro_use_imports.fixed
+++ b/src/tools/clippy/tests/ui/macro_use_imports.fixed
@@ -1,6 +1,6 @@
//@aux-build:macro_rules.rs
//@aux-build:macro_use_helper.rs
-//@aux-build:proc_macro_derive.rs
+//@aux-build:proc_macro_derive.rs:proc-macro
//@run-rustfix
//@ignore-32bit
diff --git a/src/tools/clippy/tests/ui/macro_use_imports.rs b/src/tools/clippy/tests/ui/macro_use_imports.rs
index 925a2c61f..a40fa3898 100644
--- a/src/tools/clippy/tests/ui/macro_use_imports.rs
+++ b/src/tools/clippy/tests/ui/macro_use_imports.rs
@@ -1,6 +1,6 @@
//@aux-build:macro_rules.rs
//@aux-build:macro_use_helper.rs
-//@aux-build:proc_macro_derive.rs
+//@aux-build:proc_macro_derive.rs:proc-macro
//@run-rustfix
//@ignore-32bit
diff --git a/src/tools/clippy/tests/ui/macro_use_imports.stderr b/src/tools/clippy/tests/ui/macro_use_imports.stderr
index 6fd338cef..67a833e85 100644
--- a/src/tools/clippy/tests/ui/macro_use_imports.stderr
+++ b/src/tools/clippy/tests/ui/macro_use_imports.stderr
@@ -1,28 +1,28 @@
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:19: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 mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};`
|
= note: `-D clippy::macro-use-imports` implied by `-D warnings`
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:23: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::{inner::mut_mut, inner::try_err};`
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
- --> $DIR/macro_use_imports.rs:23:5
+ --> $DIR/macro_use_imports.rs:25:5
|
LL | #[macro_use]
- | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::mut_mut, inner::try_err};`
+ | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;`
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:21: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 mini_mac::ClippyMiniMacroTest;`
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 b9677851b..3971aadbe 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
+//@aux-build:proc_macro_derive.rs:proc-macro
//@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 ab9b375dc..d8dde0236 100644
--- a/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed
+++ b/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed
@@ -5,7 +5,7 @@
#![warn(clippy::manual_assert)]
#![allow(dead_code, unused_doc_comments)]
-#![allow(clippy::nonminimal_bool, clippy::uninlined_format_args)]
+#![allow(clippy::nonminimal_bool, clippy::uninlined_format_args, clippy::useless_vec)]
macro_rules! one {
() => {
diff --git a/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed b/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed
index ab9b375dc..d8dde0236 100644
--- a/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed
+++ b/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed
@@ -5,7 +5,7 @@
#![warn(clippy::manual_assert)]
#![allow(dead_code, unused_doc_comments)]
-#![allow(clippy::nonminimal_bool, clippy::uninlined_format_args)]
+#![allow(clippy::nonminimal_bool, clippy::uninlined_format_args, clippy::useless_vec)]
macro_rules! one {
() => {
diff --git a/src/tools/clippy/tests/ui/manual_assert.rs b/src/tools/clippy/tests/ui/manual_assert.rs
index eac52d1b5..0f87d6e2d 100644
--- a/src/tools/clippy/tests/ui/manual_assert.rs
+++ b/src/tools/clippy/tests/ui/manual_assert.rs
@@ -5,7 +5,7 @@
#![warn(clippy::manual_assert)]
#![allow(dead_code, unused_doc_comments)]
-#![allow(clippy::nonminimal_bool, clippy::uninlined_format_args)]
+#![allow(clippy::nonminimal_bool, clippy::uninlined_format_args, clippy::useless_vec)]
macro_rules! one {
() => {
diff --git a/src/tools/clippy/tests/ui/manual_async_fn.fixed b/src/tools/clippy/tests/ui/manual_async_fn.fixed
index e458f0d25..e609b4b1b 100644
--- a/src/tools/clippy/tests/ui/manual_async_fn.fixed
+++ b/src/tools/clippy/tests/ui/manual_async_fn.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
#![warn(clippy::manual_async_fn)]
-#![allow(unused)]
+#![allow(clippy::needless_pub_self, unused)]
use std::future::Future;
diff --git a/src/tools/clippy/tests/ui/manual_async_fn.rs b/src/tools/clippy/tests/ui/manual_async_fn.rs
index dd5ca1c9b..6c1a9edaa 100644
--- a/src/tools/clippy/tests/ui/manual_async_fn.rs
+++ b/src/tools/clippy/tests/ui/manual_async_fn.rs
@@ -1,6 +1,6 @@
//@run-rustfix
#![warn(clippy::manual_async_fn)]
-#![allow(unused)]
+#![allow(clippy::needless_pub_self, unused)]
use std::future::Future;
diff --git a/src/tools/clippy/tests/ui/manual_filter.fixed b/src/tools/clippy/tests/ui/manual_filter.fixed
index 755caa664..5e3b12e51 100644
--- a/src/tools/clippy/tests/ui/manual_filter.fixed
+++ b/src/tools/clippy/tests/ui/manual_filter.fixed
@@ -1,7 +1,7 @@
//@run-rustfix
#![warn(clippy::manual_filter)]
-#![allow(unused_variables, dead_code)]
+#![allow(unused_variables, dead_code, clippy::useless_vec)]
fn main() {
Some(0).filter(|&x| x <= 0);
diff --git a/src/tools/clippy/tests/ui/manual_filter.rs b/src/tools/clippy/tests/ui/manual_filter.rs
index faccfe9db..b81604b03 100644
--- a/src/tools/clippy/tests/ui/manual_filter.rs
+++ b/src/tools/clippy/tests/ui/manual_filter.rs
@@ -1,7 +1,7 @@
//@run-rustfix
#![warn(clippy::manual_filter)]
-#![allow(unused_variables, dead_code)]
+#![allow(unused_variables, dead_code, clippy::useless_vec)]
fn main() {
match Some(0) {
diff --git a/src/tools/clippy/tests/ui/manual_filter_map.fixed b/src/tools/clippy/tests/ui/manual_filter_map.fixed
index 831323089..9dd376df2 100644
--- a/src/tools/clippy/tests/ui/manual_filter_map.fixed
+++ b/src/tools/clippy/tests/ui/manual_filter_map.fixed
@@ -2,6 +2,7 @@
#![allow(dead_code)]
#![warn(clippy::manual_filter_map)]
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure
+#![allow(clippy::useless_vec)]
fn main() {
// is_some(), unwrap()
diff --git a/src/tools/clippy/tests/ui/manual_filter_map.rs b/src/tools/clippy/tests/ui/manual_filter_map.rs
index 2692303d3..6dd1e066a 100644
--- a/src/tools/clippy/tests/ui/manual_filter_map.rs
+++ b/src/tools/clippy/tests/ui/manual_filter_map.rs
@@ -2,6 +2,7 @@
#![allow(dead_code)]
#![warn(clippy::manual_filter_map)]
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure
+#![allow(clippy::useless_vec)]
fn main() {
// is_some(), unwrap()
diff --git a/src/tools/clippy/tests/ui/manual_filter_map.stderr b/src/tools/clippy/tests/ui/manual_filter_map.stderr
index 6e5bbe8f2..882468b0f 100644
--- a/src/tools/clippy/tests/ui/manual_filter_map.stderr
+++ b/src/tools/clippy/tests/ui/manual_filter_map.stderr
@@ -1,5 +1,5 @@
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
- --> $DIR/manual_filter_map.rs:8:19
+ --> $DIR/manual_filter_map.rs:9: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))`
@@ -7,19 +7,19 @@ 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`
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
- --> $DIR/manual_filter_map.rs:11:19
+ --> $DIR/manual_filter_map.rs:12: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))`
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
- --> $DIR/manual_filter_map.rs:14:19
+ --> $DIR/manual_filter_map.rs:15: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())`
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
- --> $DIR/manual_filter_map.rs:17:10
+ --> $DIR/manual_filter_map.rs:18:10
|
LL | .filter(|&x| to_ref(to_opt(x)).is_some())
| __________^
@@ -27,7 +27,7 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap());
| |____________________________________________^ help: try: `filter_map(|y| *to_ref(to_opt(y)))`
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
- --> $DIR/manual_filter_map.rs:20:10
+ --> $DIR/manual_filter_map.rs:21:10
|
LL | .filter(|x| to_ref(to_opt(*x)).is_some())
| __________^
@@ -35,7 +35,7 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap());
| |____________________________________________^ help: try: `filter_map(|y| *to_ref(to_opt(y)))`
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
- --> $DIR/manual_filter_map.rs:24:10
+ --> $DIR/manual_filter_map.rs:25:10
|
LL | .filter(|&x| to_ref(to_res(x)).is_ok())
| __________^
@@ -43,7 +43,7 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap());
| |____________________________________________^ help: try: `filter_map(|y| to_ref(to_res(y)).ok())`
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
- --> $DIR/manual_filter_map.rs:27:10
+ --> $DIR/manual_filter_map.rs:28:10
|
LL | .filter(|x| to_ref(to_res(*x)).is_ok())
| __________^
@@ -51,7 +51,7 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap());
| |____________________________________________^ help: try: `filter_map(|y| to_ref(to_res(y)).ok())`
error: `find(..).map(..)` can be simplified as `find_map(..)`
- --> $DIR/manual_filter_map.rs:33:27
+ --> $DIR/manual_filter_map.rs:34:27
|
LL | iter::<Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())`
@@ -59,67 +59,67 @@ LL | iter::<Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()
= note: `-D clippy::manual-find-map` implied by `-D warnings`
error: `find(..).map(..)` can be simplified as `find_map(..)`
- --> $DIR/manual_filter_map.rs:34:28
+ --> $DIR/manual_filter_map.rs:35: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:35:31
+ --> $DIR/manual_filter_map.rs:36:31
|
LL | iter::<&Option<String>>().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:36:31
+ --> $DIR/manual_filter_map.rs:37:31
|
LL | iter::<Option<&String>>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned())`
error: `find(..).map(..)` can be simplified as `find_map(..)`
- --> $DIR/manual_filter_map.rs:38:30
+ --> $DIR/manual_filter_map.rs:39:30
|
LL | iter::<Result<u8, ()>>().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:39:31
+ --> $DIR/manual_filter_map.rs:40:31
|
LL | iter::<&Result<u8, ()>>().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:32
+ --> $DIR/manual_filter_map.rs:41:32
|
LL | iter::<&&Result<u8, ()>>().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:31
+ --> $DIR/manual_filter_map.rs:42:31
|
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:42:32
+ --> $DIR/manual_filter_map.rs:43: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:43:35
+ --> $DIR/manual_filter_map.rs:44:35
|
LL | iter::<&Result<String, ()>>().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:44:35
+ --> $DIR/manual_filter_map.rs:45:35
|
LL | iter::<Result<&String, ()>>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned().ok())`
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
- --> $DIR/manual_filter_map.rs:92:10
+ --> $DIR/manual_filter_map.rs:93:10
|
LL | .filter(|f| f.option_field.is_some())
| __________^
@@ -127,7 +127,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:97:10
+ --> $DIR/manual_filter_map.rs:98:10
|
LL | .filter(|f| f.ref_field.is_some())
| __________^
@@ -135,7 +135,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:102:10
+ --> $DIR/manual_filter_map.rs:103:10
|
LL | .filter(|f| f.ref_field.is_some())
| __________^
@@ -143,7 +143,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:107:10
+ --> $DIR/manual_filter_map.rs:108:10
|
LL | .filter(|f| f.result_field.is_ok())
| __________^
@@ -151,7 +151,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:112:10
+ --> $DIR/manual_filter_map.rs:113:10
|
LL | .filter(|f| f.result_field.is_ok())
| __________^
@@ -159,7 +159,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:117:10
+ --> $DIR/manual_filter_map.rs:118:10
|
LL | .filter(|f| f.result_field.is_ok())
| __________^
@@ -167,7 +167,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:122:10
+ --> $DIR/manual_filter_map.rs:123:10
|
LL | .filter(|f| f.result_field.is_ok())
| __________^
@@ -175,7 +175,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:127:10
+ --> $DIR/manual_filter_map.rs:128:10
|
LL | .filter(|f| f.result_field.is_ok())
| __________^
@@ -183,7 +183,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:132:10
+ --> $DIR/manual_filter_map.rs:133:10
|
LL | .filter(|f| f.result_field.is_ok())
| __________^
diff --git a/src/tools/clippy/tests/ui/manual_find_map.fixed b/src/tools/clippy/tests/ui/manual_find_map.fixed
index 554613a30..0c8eebf04 100644
--- a/src/tools/clippy/tests/ui/manual_find_map.fixed
+++ b/src/tools/clippy/tests/ui/manual_find_map.fixed
@@ -2,6 +2,7 @@
#![allow(dead_code)]
#![warn(clippy::manual_find_map)]
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure
+#![allow(clippy::useless_vec)]
fn main() {
// is_some(), unwrap()
diff --git a/src/tools/clippy/tests/ui/manual_find_map.rs b/src/tools/clippy/tests/ui/manual_find_map.rs
index d6245758f..b2feb48a8 100644
--- a/src/tools/clippy/tests/ui/manual_find_map.rs
+++ b/src/tools/clippy/tests/ui/manual_find_map.rs
@@ -2,6 +2,7 @@
#![allow(dead_code)]
#![warn(clippy::manual_find_map)]
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure
+#![allow(clippy::useless_vec)]
fn main() {
// is_some(), unwrap()
diff --git a/src/tools/clippy/tests/ui/manual_find_map.stderr b/src/tools/clippy/tests/ui/manual_find_map.stderr
index c1ac499f7..693a06bb5 100644
--- a/src/tools/clippy/tests/ui/manual_find_map.stderr
+++ b/src/tools/clippy/tests/ui/manual_find_map.stderr
@@ -1,5 +1,5 @@
error: `find(..).map(..)` can be simplified as `find_map(..)`
- --> $DIR/manual_find_map.rs:8:19
+ --> $DIR/manual_find_map.rs:9: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))`
@@ -7,19 +7,19 @@ 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`
error: `find(..).map(..)` can be simplified as `find_map(..)`
- --> $DIR/manual_find_map.rs:11:19
+ --> $DIR/manual_find_map.rs:12: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))`
error: `find(..).map(..)` can be simplified as `find_map(..)`
- --> $DIR/manual_find_map.rs:14:19
+ --> $DIR/manual_find_map.rs:15: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())`
error: `find(..).map(..)` can be simplified as `find_map(..)`
- --> $DIR/manual_find_map.rs:17:10
+ --> $DIR/manual_find_map.rs:18:10
|
LL | .find(|&x| to_ref(to_opt(x)).is_some())
| __________^
@@ -27,7 +27,7 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap());
| |____________________________________________^ help: try: `find_map(|y| *to_ref(to_opt(y)))`
error: `find(..).map(..)` can be simplified as `find_map(..)`
- --> $DIR/manual_find_map.rs:20:10
+ --> $DIR/manual_find_map.rs:21:10
|
LL | .find(|x| to_ref(to_opt(*x)).is_some())
| __________^
@@ -35,7 +35,7 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap());
| |____________________________________________^ help: try: `find_map(|y| *to_ref(to_opt(y)))`
error: `find(..).map(..)` can be simplified as `find_map(..)`
- --> $DIR/manual_find_map.rs:24:10
+ --> $DIR/manual_find_map.rs:25:10
|
LL | .find(|&x| to_ref(to_res(x)).is_ok())
| __________^
@@ -43,7 +43,7 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap());
| |____________________________________________^ help: try: `find_map(|y| to_ref(to_res(y)).ok())`
error: `find(..).map(..)` can be simplified as `find_map(..)`
- --> $DIR/manual_find_map.rs:27:10
+ --> $DIR/manual_find_map.rs:28:10
|
LL | .find(|x| to_ref(to_res(*x)).is_ok())
| __________^
@@ -51,91 +51,91 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap());
| |____________________________________________^ help: try: `find_map(|y| to_ref(to_res(y)).ok())`
error: `find(..).map(..)` can be simplified as `find_map(..)`
- --> $DIR/manual_find_map.rs:33:26
+ --> $DIR/manual_find_map.rs:34:26
|
LL | iter::<Option<u8>>().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:34:27
+ --> $DIR/manual_find_map.rs:35:27
|
LL | iter::<&Option<u8>>().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:28
+ --> $DIR/manual_find_map.rs:36:28
|
LL | iter::<&&Option<u8>>().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:27
+ --> $DIR/manual_find_map.rs:37:27
|
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:37:28
+ --> $DIR/manual_find_map.rs:38: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:38:31
+ --> $DIR/manual_find_map.rs:39:31
|
LL | iter::<&Option<String>>().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:39:31
+ --> $DIR/manual_find_map.rs:40:31
|
LL | iter::<Option<&String>>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned())`
error: `find(..).map(..)` can be simplified as `find_map(..)`
- --> $DIR/manual_find_map.rs:41:30
+ --> $DIR/manual_find_map.rs:42:30
|
LL | iter::<Result<u8, ()>>().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:42:31
+ --> $DIR/manual_find_map.rs:43:31
|
LL | iter::<&Result<u8, ()>>().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:32
+ --> $DIR/manual_find_map.rs:44:32
|
LL | iter::<&&Result<u8, ()>>().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:31
+ --> $DIR/manual_find_map.rs:45:31
|
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:45:32
+ --> $DIR/manual_find_map.rs:46: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:46:35
+ --> $DIR/manual_find_map.rs:47:35
|
LL | iter::<&Result<String, ()>>().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:47:35
+ --> $DIR/manual_find_map.rs:48:35
|
LL | iter::<Result<&String, ()>>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned().ok())`
error: `find(..).map(..)` can be simplified as `find_map(..)`
- --> $DIR/manual_find_map.rs:95:10
+ --> $DIR/manual_find_map.rs:96:10
|
LL | .find(|f| f.option_field.is_some())
| __________^
@@ -143,7 +143,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:100:10
+ --> $DIR/manual_find_map.rs:101:10
|
LL | .find(|f| f.ref_field.is_some())
| __________^
@@ -151,7 +151,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:105:10
+ --> $DIR/manual_find_map.rs:106:10
|
LL | .find(|f| f.ref_field.is_some())
| __________^
@@ -159,7 +159,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:110:10
+ --> $DIR/manual_find_map.rs:111:10
|
LL | .find(|f| f.result_field.is_ok())
| __________^
@@ -167,7 +167,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:115:10
+ --> $DIR/manual_find_map.rs:116:10
|
LL | .find(|f| f.result_field.is_ok())
| __________^
@@ -175,7 +175,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:120:10
+ --> $DIR/manual_find_map.rs:121:10
|
LL | .find(|f| f.result_field.is_ok())
| __________^
@@ -183,7 +183,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:125:10
+ --> $DIR/manual_find_map.rs:126:10
|
LL | .find(|f| f.result_field.is_ok())
| __________^
@@ -191,7 +191,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:130:10
+ --> $DIR/manual_find_map.rs:131:10
|
LL | .find(|f| f.result_field.is_ok())
| __________^
@@ -199,7 +199,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:135:10
+ --> $DIR/manual_find_map.rs:136:10
|
LL | .find(|f| f.result_field.is_ok())
| __________^
diff --git a/src/tools/clippy/tests/ui/manual_let_else.rs b/src/tools/clippy/tests/ui/manual_let_else.rs
index 3996d775f..46241afec 100644
--- a/src/tools/clippy/tests/ui/manual_let_else.rs
+++ b/src/tools/clippy/tests/ui/manual_let_else.rs
@@ -4,7 +4,8 @@
clippy::unused_unit,
clippy::let_unit_value,
clippy::match_single_binding,
- clippy::never_loop
+ clippy::never_loop,
+ clippy::needless_if
)]
#![warn(clippy::manual_let_else)]
@@ -127,8 +128,8 @@ fn fire() {
return;
};
- // Tuples supported for the identity block and pattern
- let v = if let (Some(v_some), w_some) = (g(), 0) {
+ // Tuples supported with multiple bindings
+ let (w, S { v }) = if let (Some(v_some), w_some) = (g().map(|_| S { v: 0 }), 0) {
(w_some, v_some)
} else {
return;
@@ -146,10 +147,44 @@ fn fire() {
Variant::A(0, 0)
}
- // Should not be renamed
let v = if let Variant::A(a, 0) = e() { a } else { return };
- // Should be renamed
- let v = if let Variant::B(b) = e() { b } else { return };
+
+ // `mut v` is inserted into the pattern
+ let mut v = if let Variant::B(b) = e() { b } else { return };
+
+ // Nesting works
+ let nested = Ok(Some(e()));
+ let v = if let Ok(Some(Variant::B(b))) | Err(Some(Variant::A(b, _))) = nested {
+ b
+ } else {
+ return;
+ };
+ // dot dot works
+ let v = if let Variant::A(.., a) = e() { a } else { return };
+
+ // () is preserved: a bit of an edge case but make sure it stays around
+ let w = if let (Some(v), ()) = (g(), ()) { v } else { return };
+
+ // Tuple structs work
+ let w = if let Some(S { v: x }) = Some(S { v: 0 }) {
+ x
+ } else {
+ return;
+ };
+
+ // Field init shorthand is suggested
+ let v = if let Some(S { v: x }) = Some(S { v: 0 }) {
+ x
+ } else {
+ return;
+ };
+
+ // Multi-field structs also work
+ let (x, S { v }, w) = if let Some(U { v, w, x }) = None::<U<S<()>>> {
+ (x, v, w)
+ } else {
+ return;
+ };
}
fn not_fire() {
@@ -274,4 +309,23 @@ fn not_fire() {
};
1
};
+
+ // This would require creation of a suggestion of the form
+ // let v @ (Some(_), _) = (...) else { return };
+ // Which is too advanced for our code, so we just bail.
+ let v = if let (Some(v_some), w_some) = (g(), 0) {
+ (w_some, v_some)
+ } else {
+ return;
+ };
+}
+
+struct S<T> {
+ v: T,
+}
+
+struct U<T> {
+ v: T,
+ w: T,
+ x: T,
}
diff --git a/src/tools/clippy/tests/ui/manual_let_else.stderr b/src/tools/clippy/tests/ui/manual_let_else.stderr
index f6f56f7b0..1eada4f99 100644
--- a/src/tools/clippy/tests/ui/manual_let_else.stderr
+++ b/src/tools/clippy/tests/ui/manual_let_else.stderr
@@ -1,5 +1,5 @@
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:24:5
+ --> $DIR/manual_let_else.rs:25:5
|
LL | let v = if let Some(v_some) = g() { v_some } else { return };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { return };`
@@ -7,7 +7,7 @@ LL | let v = if let Some(v_some) = g() { v_some } else { return };
= note: `-D clippy::manual-let-else` implied by `-D warnings`
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:25:5
+ --> $DIR/manual_let_else.rs:26:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -24,7 +24,7 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:31:5
+ --> $DIR/manual_let_else.rs:32:5
|
LL | / let v = if let Some(v) = g() {
LL | | // Blocks around the identity should have no impact
@@ -45,25 +45,25 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:44:9
+ --> $DIR/manual_let_else.rs:45: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:45:9
+ --> $DIR/manual_let_else.rs:46: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:49:5
+ --> $DIR/manual_let_else.rs:50: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:52:5
+ --> $DIR/manual_let_else.rs:53:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -80,7 +80,7 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:59:5
+ --> $DIR/manual_let_else.rs:60:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -97,7 +97,7 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:66:5
+ --> $DIR/manual_let_else.rs:67:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -116,7 +116,7 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:76:5
+ --> $DIR/manual_let_else.rs:77:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -138,13 +138,13 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:86:5
+ --> $DIR/manual_let_else.rs:87: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:89:5
+ --> $DIR/manual_let_else.rs:90:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -165,7 +165,7 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:98:5
+ --> $DIR/manual_let_else.rs:99:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -186,7 +186,7 @@ LL + } };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:107:5
+ --> $DIR/manual_let_else.rs:108:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -215,7 +215,7 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:124:5
+ --> $DIR/manual_let_else.rs:125:5
|
LL | / let (v, w) = if let Some(v_some) = g().map(|v| (v, 42)) {
LL | | v_some
@@ -232,9 +232,9 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:131:5
+ --> $DIR/manual_let_else.rs:132:5
|
-LL | / let v = if let (Some(v_some), w_some) = (g(), 0) {
+LL | / let (w, S { v }) = if let (Some(v_some), w_some) = (g().map(|_| S { v: 0 }), 0) {
LL | | (w_some, v_some)
LL | | } else {
LL | | return;
@@ -243,13 +243,13 @@ LL | | };
|
help: consider writing
|
-LL ~ let (Some(v_some), w_some) = (g(), 0) else {
+LL ~ let (Some(S { v }), w) = (g().map(|_| S { v: 0 }), 0) else {
LL + return;
LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:140:13
+ --> $DIR/manual_let_else.rs:141:13
|
LL | let $n = if let Some(v) = $e { v } else { return };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some($n) = g() else { return };`
@@ -263,16 +263,96 @@ error: this could be rewritten as `let...else`
--> $DIR/manual_let_else.rs:150:5
|
LL | let v = if let Variant::A(a, 0) = e() { a } else { return };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::A(a, 0) = e() 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
+ |
+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
+ |
+LL | / let v = if let Ok(Some(Variant::B(b))) | Err(Some(Variant::A(b, _))) = nested {
+LL | | b
+LL | | } else {
+LL | | return;
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let (Ok(Some(Variant::B(v))) | Err(Some(Variant::A(v, _)))) = nested else {
+LL + return;
+LL + };
+ |
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:163: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
+ |
+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
+ |
+LL | / let w = if let Some(S { v: x }) = Some(S { v: 0 }) {
+LL | | x
+LL | | } else {
+LL | | return;
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let Some(S { v: w }) = Some(S { v: 0 }) else {
+LL + return;
+LL + };
+ |
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:152:5
+ --> $DIR/manual_let_else.rs:176:5
+ |
+LL | / let v = if let Some(S { v: x }) = Some(S { v: 0 }) {
+LL | | x
+LL | | } else {
+LL | | return;
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let Some(S { v }) = Some(S { v: 0 }) else {
+LL + return;
+LL + };
+ |
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:183:5
+ |
+LL | / let (x, S { v }, w) = if let Some(U { v, w, x }) = None::<U<S<()>>> {
+LL | | (x, v, w)
+LL | | } else {
+LL | | return;
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let Some(U { v: S { v }, w, x }) = None::<U<S<()>>> else {
+LL + return;
+LL + };
|
-LL | let v = if let Variant::B(b) = e() { b } else { return };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::B(v) = e() else { return };`
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:262:5
+ --> $DIR/manual_let_else.rs:297:5
|
LL | / let _ = match ff {
LL | | Some(value) => value,
@@ -280,5 +360,5 @@ LL | | _ => macro_call!(),
LL | | };
| |______^ help: consider writing: `let Some(_) = ff else { macro_call!() };`
-error: aborting due to 20 previous errors
+error: aborting due to 26 previous errors
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 73b746791..73ff69eec 100644
--- a/src/tools/clippy/tests/ui/manual_let_else_match.rs
+++ b/src/tools/clippy/tests/ui/manual_let_else_match.rs
@@ -1,5 +1,9 @@
#![allow(unused_braces, unused_variables, dead_code)]
-#![allow(clippy::collapsible_else_if, clippy::let_unit_value)]
+#![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)]
@@ -68,7 +72,12 @@ fn fire() {
let f = Variant::Bar(1);
let _value = match f {
- Variant::Bar(_) | Variant::Baz(_) => (),
+ Variant::Bar(v) | Variant::Baz(v) => v,
+ _ => return,
+ };
+
+ let _value = match Some(build_enum()) {
+ Some(Variant::Bar(v) | Variant::Baz(v)) => v,
_ => 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 bacc14dc9..3fd9a6376 100644
--- a/src/tools/clippy/tests/ui/manual_let_else_match.stderr
+++ b/src/tools/clippy/tests/ui/manual_let_else_match.stderr
@@ -1,5 +1,5 @@
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else_match.rs:32:5
+ --> $DIR/manual_let_else_match.rs:36:5
|
LL | / let v = match g() {
LL | | Some(v_some) => v_some,
@@ -10,7 +10,7 @@ LL | | };
= note: `-D clippy::manual-let-else` implied by `-D warnings`
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else_match.rs:37:5
+ --> $DIR/manual_let_else_match.rs:41:5
|
LL | / let v = match g() {
LL | | Some(v_some) => v_some,
@@ -19,7 +19,7 @@ LL | | };
| |______^ help: consider writing: `let Some(v) = g() else { return };`
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else_match.rs:44:9
+ --> $DIR/manual_let_else_match.rs:48:9
|
LL | / let v = match h() {
LL | | (Some(v), None) | (None, Some(v)) => v,
@@ -28,7 +28,7 @@ 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:49:9
+ --> $DIR/manual_let_else_match.rs:53:9
|
LL | / let v = match build_enum() {
LL | | Variant::Bar(v) | Variant::Baz(v) => v,
@@ -37,7 +37,7 @@ 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:57:5
+ --> $DIR/manual_let_else_match.rs:61:5
|
LL | / let v = match f() {
LL | | Ok(v) => v,
@@ -46,7 +46,7 @@ LL | | };
| |______^ help: consider writing: `let Ok(v) = f() else { return };`
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else_match.rs:63:5
+ --> $DIR/manual_let_else_match.rs:67:5
|
LL | / let v = match f().map_err(|_| ()) {
LL | | Ok(v) => v,
@@ -55,16 +55,25 @@ 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:70:5
+ --> $DIR/manual_let_else_match.rs:74:5
|
LL | / let _value = match f {
-LL | | Variant::Bar(_) | Variant::Baz(_) => (),
+LL | | Variant::Bar(v) | Variant::Baz(v) => v,
LL | | _ => return,
LL | | };
- | |______^ help: consider writing: `let (Variant::Bar(_) | Variant::Baz(_)) = f else { return };`
+ | |______^ 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:76:5
+ --> $DIR/manual_let_else_match.rs:79:5
+ |
+LL | / let _value = match Some(build_enum()) {
+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
|
LL | / let data = match data.as_slice() {
LL | | [data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0] => data,
@@ -72,5 +81,5 @@ LL | | _ => return,
LL | | };
| |______^ help: consider writing: `let ([data @ .., 0, 0, 0, 0] | [data @ .., 0, 0] | [data @ .., 0]) = data.as_slice() else { return };`
-error: aborting due to 8 previous errors
+error: aborting due to 9 previous errors
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 ea0535d07..4d5c70f19 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,4 +1,5 @@
#![warn(clippy::needless_range_loop, clippy::manual_memcpy)]
+#![allow(clippy::useless_vec)]
const LOOP_OFFSET: usize = 5000;
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 c163ae061..1c6a7d5c0 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
@@ -1,5 +1,5 @@
error: it looks like you're manually copying between slices
- --> $DIR/without_loop_counters.rs:7:5
+ --> $DIR/without_loop_counters.rs:8:5
|
LL | / for i in 0..src.len() {
LL | | dst[i] = src[i];
@@ -9,7 +9,7 @@ LL | | }
= note: `-D clippy::manual-memcpy` implied by `-D warnings`
error: it looks like you're manually copying between slices
- --> $DIR/without_loop_counters.rs:12:5
+ --> $DIR/without_loop_counters.rs:13:5
|
LL | / for i in 0..src.len() {
LL | | dst[i + 10] = src[i];
@@ -17,7 +17,7 @@ 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:17:5
+ --> $DIR/without_loop_counters.rs:18:5
|
LL | / for i in 0..src.len() {
LL | | dst[i] = src[i + 10];
@@ -25,7 +25,7 @@ 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:22:5
+ --> $DIR/without_loop_counters.rs:23:5
|
LL | / for i in 11..src.len() {
LL | | dst[i] = src[i - 10];
@@ -33,7 +33,7 @@ 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:27:5
+ --> $DIR/without_loop_counters.rs:28:5
|
LL | / for i in 0..dst.len() {
LL | | dst[i] = src[i];
@@ -41,7 +41,7 @@ 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:40:5
+ --> $DIR/without_loop_counters.rs:41:5
|
LL | / for i in 10..256 {
LL | | dst[i] = src[i - 5];
@@ -56,7 +56,7 @@ 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:52:5
+ --> $DIR/without_loop_counters.rs:53:5
|
LL | / for i in 10..LOOP_OFFSET {
LL | | dst[i + LOOP_OFFSET] = src[i - some_var];
@@ -64,7 +64,7 @@ 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:65:5
+ --> $DIR/without_loop_counters.rs:66:5
|
LL | / for i in 0..src_vec.len() {
LL | | dst_vec[i] = src_vec[i];
@@ -72,7 +72,7 @@ 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:94:5
+ --> $DIR/without_loop_counters.rs:95:5
|
LL | / for i in from..from + src.len() {
LL | | dst[i] = src[i - from];
@@ -80,7 +80,7 @@ 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:98:5
+ --> $DIR/without_loop_counters.rs:99:5
|
LL | / for i in from..from + 3 {
LL | | dst[i] = src[i - from];
@@ -88,7 +88,7 @@ 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:103:5
+ --> $DIR/without_loop_counters.rs:104:5
|
LL | / for i in 0..5 {
LL | | dst[i - 0] = src[i];
@@ -96,7 +96,7 @@ 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:108:5
+ --> $DIR/without_loop_counters.rs:109:5
|
LL | / for i in 0..0 {
LL | | dst[i] = src[i];
@@ -104,7 +104,7 @@ 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:131:5
+ --> $DIR/without_loop_counters.rs:132:5
|
LL | / for i in 0..src.len() {
LL | | dst[i] = src[i].clone();
diff --git a/src/tools/clippy/tests/ui/manual_range_patterns.fixed b/src/tools/clippy/tests/ui/manual_range_patterns.fixed
new file mode 100644
index 000000000..9eee8f371
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_range_patterns.fixed
@@ -0,0 +1,35 @@
+//@run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::manual_range_patterns)]
+#![feature(exclusive_range_pattern)]
+
+fn main() {
+ let f = 6;
+
+ let _ = matches!(f, 1..=10);
+ let _ = matches!(f, 1..=10);
+ let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 8 | 10); // 7 is missing
+ let _ = matches!(f, | 4);
+ let _ = matches!(f, 4 | 5);
+ let _ = matches!(f, 1 | 2147483647);
+ let _ = matches!(f, 0 | 2147483647);
+ let _ = matches!(f, -2147483647 | 2147483647);
+ let _ = matches!(f, 1 | (2..=4));
+ let _ = matches!(f, 1 | (2..4));
+ let _ = matches!(f, 1..=48324729);
+ let _ = matches!(f, 0..=48324730);
+ let _ = matches!(f, 0..=3);
+ #[allow(clippy::match_like_matches_macro)]
+ let _ = match f {
+ 1..=10 => true,
+ _ => false,
+ };
+
+ macro_rules! mac {
+ ($e:expr) => {
+ matches!($e, 1..=10)
+ };
+ }
+ mac!(f);
+}
diff --git a/src/tools/clippy/tests/ui/manual_range_patterns.rs b/src/tools/clippy/tests/ui/manual_range_patterns.rs
new file mode 100644
index 000000000..10743a7d0
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_range_patterns.rs
@@ -0,0 +1,35 @@
+//@run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::manual_range_patterns)]
+#![feature(exclusive_range_pattern)]
+
+fn main() {
+ let f = 6;
+
+ let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10);
+ let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 7 | 8 | 10);
+ let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 8 | 10); // 7 is missing
+ let _ = matches!(f, | 4);
+ let _ = matches!(f, 4 | 5);
+ let _ = matches!(f, 1 | 2147483647);
+ let _ = matches!(f, 0 | 2147483647);
+ let _ = matches!(f, -2147483647 | 2147483647);
+ let _ = matches!(f, 1 | (2..=4));
+ let _ = matches!(f, 1 | (2..4));
+ let _ = matches!(f, (1..=10) | (2..=13) | (14..=48324728) | 48324729);
+ let _ = matches!(f, 0 | (1..=10) | 48324730 | (2..=13) | (14..=48324728) | 48324729);
+ let _ = matches!(f, 0..=1 | 0..=2 | 0..=3);
+ #[allow(clippy::match_like_matches_macro)]
+ let _ = match f {
+ 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 => true,
+ _ => false,
+ };
+
+ macro_rules! mac {
+ ($e:expr) => {
+ matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10)
+ };
+ }
+ mac!(f);
+}
diff --git a/src/tools/clippy/tests/ui/manual_range_patterns.stderr b/src/tools/clippy/tests/ui/manual_range_patterns.stderr
new file mode 100644
index 000000000..bc9e33501
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_range_patterns.stderr
@@ -0,0 +1,51 @@
+error: this OR pattern can be rewritten using a range
+ --> $DIR/manual_range_patterns.rs:10: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`
+
+error: this OR pattern can be rewritten using a range
+ --> $DIR/manual_range_patterns.rs:11: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
+ |
+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
+ |
+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
+ |
+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
+ |
+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:31:26
+ |
+LL | matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10)
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10`
+...
+LL | mac!(f);
+ | ------- in this macro invocation
+ |
+ = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 7 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 f2e44e56f..594a76897 100644
--- a/src/tools/clippy/tests/ui/manual_rem_euclid.fixed
+++ b/src/tools/clippy/tests/ui/manual_rem_euclid.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![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 b2329c33a..d5f98e715 100644
--- a/src/tools/clippy/tests/ui/manual_rem_euclid.rs
+++ b/src/tools/clippy/tests/ui/manual_rem_euclid.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::manual_rem_euclid)]
#![allow(clippy::let_with_type_underscore)]
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 ac85bd8d3..5b9629f4b 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,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![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 1f824b12b..297887a9c 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,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![allow(unused)]
#![warn(clippy::manual_slice_size_calculation)]
diff --git a/src/tools/clippy/tests/ui/manual_try_fold.rs b/src/tools/clippy/tests/ui/manual_try_fold.rs
new file mode 100644
index 000000000..4521e9fa1
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_try_fold.rs
@@ -0,0 +1,100 @@
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(clippy::unnecessary_fold, unused)]
+#![warn(clippy::manual_try_fold)]
+#![feature(try_trait_v2)]
+
+use std::ops::ControlFlow;
+use std::ops::FromResidual;
+use std::ops::Try;
+
+#[macro_use]
+extern crate proc_macros;
+
+// Test custom `Try` with more than 1 argument
+struct NotOption(i32, i32);
+
+impl<R> FromResidual<R> for NotOption {
+ fn from_residual(_: R) -> Self {
+ todo!()
+ }
+}
+
+impl Try for NotOption {
+ type Output = ();
+ type Residual = ();
+
+ fn from_output(_: Self::Output) -> Self {
+ todo!()
+ }
+
+ fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
+ todo!()
+ }
+}
+
+// Test custom `Try` with only 1 argument
+#[derive(Default)]
+struct NotOptionButWorse(i32);
+
+impl<R> FromResidual<R> for NotOptionButWorse {
+ fn from_residual(_: R) -> Self {
+ todo!()
+ }
+}
+
+impl Try for NotOptionButWorse {
+ type Output = ();
+ type Residual = ();
+
+ fn from_output(_: Self::Output) -> Self {
+ todo!()
+ }
+
+ fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
+ todo!()
+ }
+}
+
+fn main() {
+ [1, 2, 3]
+ .iter()
+ .fold(Some(0i32), |sum, i| sum?.checked_add(*i))
+ .unwrap();
+ [1, 2, 3]
+ .iter()
+ .fold(NotOption(0i32, 0i32), |sum, i| NotOption(0i32, 0i32));
+ [1, 2, 3]
+ .iter()
+ .fold(NotOptionButWorse(0i32), |sum, i| NotOptionButWorse(0i32));
+ // Do not lint
+ [1, 2, 3].iter().try_fold(0i32, |sum, i| sum.checked_add(*i)).unwrap();
+ [1, 2, 3].iter().fold(0i32, |sum, i| sum + i);
+ [1, 2, 3]
+ .iter()
+ .fold(NotOptionButWorse::default(), |sum, i| NotOptionButWorse::default());
+ external! {
+ [1, 2, 3].iter().fold(Some(0i32), |sum, i| sum?.checked_add(*i)).unwrap();
+ [1, 2, 3].iter().try_fold(0i32, |sum, i| sum.checked_add(*i)).unwrap();
+ }
+ with_span! {
+ span
+ [1, 2, 3].iter().fold(Some(0i32), |sum, i| sum?.checked_add(*i)).unwrap();
+ [1, 2, 3].iter().try_fold(0i32, |sum, i| sum.checked_add(*i)).unwrap();
+ }
+}
+
+#[clippy::msrv = "1.26.0"]
+fn msrv_too_low() {
+ [1, 2, 3]
+ .iter()
+ .fold(Some(0i32), |sum, i| sum?.checked_add(*i))
+ .unwrap();
+}
+
+#[clippy::msrv = "1.27.0"]
+fn msrv_juust_right() {
+ [1, 2, 3]
+ .iter()
+ .fold(Some(0i32), |sum, i| sum?.checked_add(*i))
+ .unwrap();
+}
diff --git a/src/tools/clippy/tests/ui/manual_try_fold.stderr b/src/tools/clippy/tests/ui/manual_try_fold.stderr
new file mode 100644
index 000000000..a0cf5b3b5
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_try_fold.stderr
@@ -0,0 +1,28 @@
+error: usage of `Iterator::fold` on a type that implements `Try`
+ --> $DIR/manual_try_fold.rs:61:10
+ |
+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`
+
+error: usage of `Iterator::fold` on a type that implements `Try`
+ --> $DIR/manual_try_fold.rs:65:10
+ |
+LL | .fold(NotOption(0i32, 0i32), |sum, i| NotOption(0i32, 0i32));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(..., |sum, i| ...)`
+
+error: usage of `Iterator::fold` on a type that implements `Try`
+ --> $DIR/manual_try_fold.rs:68:10
+ |
+LL | .fold(NotOptionButWorse(0i32), |sum, i| NotOptionButWorse(0i32));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(0i32, |sum, i| ...)`
+
+error: usage of `Iterator::fold` on a type that implements `Try`
+ --> $DIR/manual_try_fold.rs:98:10
+ |
+LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i))
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(0i32, |sum, i| ...)`
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or.fixed b/src/tools/clippy/tests/ui/manual_unwrap_or.fixed
index c17634bff..20560b87c 100644
--- a/src/tools/clippy/tests/ui/manual_unwrap_or.fixed
+++ b/src/tools/clippy/tests/ui/manual_unwrap_or.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
#![allow(dead_code)]
-#![allow(unused_variables, clippy::unnecessary_wraps)]
+#![allow(unused_variables, clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)]
fn option_unwrap_or() {
// int case
diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or.rs b/src/tools/clippy/tests/ui/manual_unwrap_or.rs
index 6d49a6949..5dbc57565 100644
--- a/src/tools/clippy/tests/ui/manual_unwrap_or.rs
+++ b/src/tools/clippy/tests/ui/manual_unwrap_or.rs
@@ -1,6 +1,6 @@
//@run-rustfix
#![allow(dead_code)]
-#![allow(unused_variables, clippy::unnecessary_wraps)]
+#![allow(unused_variables, clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)]
fn option_unwrap_or() {
// int case
diff --git a/src/tools/clippy/tests/ui/map_clone.fixed b/src/tools/clippy/tests/ui/map_clone.fixed
index d7474f357..50c0eb1a8 100644
--- a/src/tools/clippy/tests/ui/map_clone.fixed
+++ b/src/tools/clippy/tests/ui/map_clone.fixed
@@ -4,7 +4,8 @@
clippy::clone_on_copy,
clippy::iter_cloned_collect,
clippy::many_single_char_names,
- clippy::redundant_clone
+ clippy::redundant_clone,
+ clippy::useless_vec
)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/map_clone.rs b/src/tools/clippy/tests/ui/map_clone.rs
index 74978ae80..91a084f28 100644
--- a/src/tools/clippy/tests/ui/map_clone.rs
+++ b/src/tools/clippy/tests/ui/map_clone.rs
@@ -4,7 +4,8 @@
clippy::clone_on_copy,
clippy::iter_cloned_collect,
clippy::many_single_char_names,
- clippy::redundant_clone
+ clippy::redundant_clone,
+ clippy::useless_vec
)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/map_clone.stderr b/src/tools/clippy/tests/ui/map_clone.stderr
index d84a5bf8d..d768af1f4 100644
--- a/src/tools/clippy/tests/ui/map_clone.stderr
+++ b/src/tools/clippy/tests/ui/map_clone.stderr
@@ -1,5 +1,5 @@
error: you are using an explicit closure for copying elements
- --> $DIR/map_clone.rs:11:22
+ --> $DIR/map_clone.rs:12:22
|
LL | let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![5_i8; 6].iter().copied()`
@@ -7,31 +7,31 @@ LL | let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect();
= note: `-D clippy::map-clone` implied by `-D warnings`
error: you are using an explicit closure for cloning elements
- --> $DIR/map_clone.rs:12:26
+ --> $DIR/map_clone.rs:13:26
|
LL | let _: Vec<String> = 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:13:23
+ --> $DIR/map_clone.rs:14:23
|
LL | let _: Vec<u32> = 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:15:26
+ --> $DIR/map_clone.rs:16:26
|
LL | let _: Option<u64> = 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:16:25
+ --> $DIR/map_clone.rs:17:25
|
LL | let _: Option<u8> = 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:27:29
+ --> $DIR/map_clone.rs:28:29
|
LL | let _ = std::env::args().map(|v| v.clone());
| ^^^^^^^^^^^^^^^^^^^ help: remove the `map` call
diff --git a/src/tools/clippy/tests/ui/map_unwrap_or.rs b/src/tools/clippy/tests/ui/map_unwrap_or.rs
index cb25d8567..bb36cb2c5 100644
--- a/src/tools/clippy/tests/ui/map_unwrap_or.rs
+++ b/src/tools/clippy/tests/ui/map_unwrap_or.rs
@@ -56,6 +56,10 @@ fn option_methods() {
.unwrap_or_else(||
0
);
+
+ // Check for `map(f).unwrap_or(false)` use.
+ let _ = opt.map(|x| x > 5).unwrap_or(false);
+
}
#[rustfmt::skip]
@@ -94,3 +98,46 @@ fn msrv_1_41() {
let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
}
+
+#[clippy::msrv = "1.69"]
+fn msrv_1_69() {
+ let opt: Option<i32> = Some(1);
+
+ let _ = opt.map(|x| x > 5).unwrap_or(false);
+}
+
+#[clippy::msrv = "1.70"]
+fn msrv_1_70() {
+ let opt: Option<i32> = Some(1);
+
+ let _ = opt.map(|x| x > 5).unwrap_or(false);
+}
+
+mod issue_10579 {
+ // Different variations of the same issue.
+ fn v1() {
+ let x = vec![1, 2, 3, 0];
+ let y = x.strip_suffix(&[0]).map(|s| s.to_vec()).unwrap_or(x);
+ println!("{y:?}");
+ }
+ fn v2() {
+ let x = vec![1, 2, 3, 0];
+ let y = Some(()).map(|_| x.to_vec()).unwrap_or(x);
+ println!("{y:?}");
+ }
+ fn v3() {
+ let x = vec![1, 2, 3, 0];
+ let xref = &x;
+ let y = Some(()).map(|_| xref.to_vec()).unwrap_or(x);
+ println!("{y:?}");
+ }
+ fn v4() {
+ struct VecInStruct {
+ v: Vec<u8>,
+ }
+ let s = VecInStruct { v: vec![1, 2, 3, 0] };
+
+ let y = Some(()).map(|_| s.v.clone()).unwrap_or(s.v);
+ println!("{y:?}");
+ }
+}
diff --git a/src/tools/clippy/tests/ui/map_unwrap_or.stderr b/src/tools/clippy/tests/ui/map_unwrap_or.stderr
index 41781b050..9f4a4a9ae 100644
--- a/src/tools/clippy/tests/ui/map_unwrap_or.stderr
+++ b/src/tools/clippy/tests/ui/map_unwrap_or.stderr
@@ -126,8 +126,20 @@ LL | | 0
LL | | );
| |_________^
+error: called `map(<f>).unwrap_or(false)` on an `Option` value. This can be done more directly by calling `is_some_and(<f>)` instead
+ --> $DIR/map_unwrap_or.rs:61:13
+ |
+LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: use `is_some_and(<f>)` instead
+ |
+LL - let _ = opt.map(|x| x > 5).unwrap_or(false);
+LL + let _ = opt.is_some_and(|x| x > 5);
+ |
+
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:67:13
+ --> $DIR/map_unwrap_or.rs:71:13
|
LL | let _ = res.map(|x| {
| _____________^
@@ -137,7 +149,7 @@ LL | | ).unwrap_or_else(|_e| 0);
| |____________________________^
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:71:13
+ --> $DIR/map_unwrap_or.rs:75:13
|
LL | let _ = res.map(|x| x + 1)
| _____________^
@@ -147,10 +159,34 @@ LL | | });
| |__________^
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:95:13
+ --> $DIR/map_unwrap_or.rs:99:13
|
LL | let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `res.map_or_else(|_e| 0, |x| x + 1)`
-error: aborting due to 12 previous errors
+error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
+ --> $DIR/map_unwrap_or.rs:106:13
+ |
+LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: use `map_or(<a>, <f>)` instead
+ |
+LL - let _ = opt.map(|x| x > 5).unwrap_or(false);
+LL + let _ = opt.map_or(false, |x| x > 5);
+ |
+
+error: called `map(<f>).unwrap_or(false)` on an `Option` value. This can be done more directly by calling `is_some_and(<f>)` instead
+ --> $DIR/map_unwrap_or.rs:113:13
+ |
+LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: use `is_some_and(<f>)` instead
+ |
+LL - let _ = opt.map(|x| x > 5).unwrap_or(false);
+LL + let _ = opt.is_some_and(|x| x > 5);
+ |
+
+error: aborting due to 15 previous errors
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 30415e3b9..cf9c279cd 100644
--- a/src/tools/clippy/tests/ui/match_on_vec_items.rs
+++ b/src/tools/clippy/tests/ui/match_on_vec_items.rs
@@ -1,4 +1,5 @@
#![warn(clippy::match_on_vec_items)]
+#![allow(clippy::redundant_at_rest_pattern, clippy::useless_vec)]
fn match_with_wildcard() {
let arr = vec![0, 1, 2, 3];
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 49446d715..9b1f05286 100644
--- a/src/tools/clippy/tests/ui/match_on_vec_items.stderr
+++ b/src/tools/clippy/tests/ui/match_on_vec_items.stderr
@@ -1,5 +1,5 @@
error: indexing into a vector may panic
- --> $DIR/match_on_vec_items.rs:9:11
+ --> $DIR/match_on_vec_items.rs:10:11
|
LL | match arr[idx] {
| ^^^^^^^^ help: try this: `arr.get(idx)`
@@ -7,43 +7,43 @@ LL | match arr[idx] {
= note: `-D clippy::match-on-vec-items` implied by `-D warnings`
error: indexing into a vector may panic
- --> $DIR/match_on_vec_items.rs:16:11
+ --> $DIR/match_on_vec_items.rs:17:11
|
LL | match arr[range] {
| ^^^^^^^^^^ help: try this: `arr.get(range)`
error: indexing into a vector may panic
- --> $DIR/match_on_vec_items.rs:29:11
+ --> $DIR/match_on_vec_items.rs:30:11
|
LL | match arr[idx] {
| ^^^^^^^^ help: try this: `arr.get(idx)`
error: indexing into a vector may panic
- --> $DIR/match_on_vec_items.rs:36:11
+ --> $DIR/match_on_vec_items.rs:37:11
|
LL | match arr[range] {
| ^^^^^^^^^^ help: try this: `arr.get(range)`
error: indexing into a vector may panic
- --> $DIR/match_on_vec_items.rs:49:11
+ --> $DIR/match_on_vec_items.rs:50:11
|
LL | match arr[idx] {
| ^^^^^^^^ help: try this: `arr.get(idx)`
error: indexing into a vector may panic
- --> $DIR/match_on_vec_items.rs:56:11
+ --> $DIR/match_on_vec_items.rs:57:11
|
LL | match arr[range] {
| ^^^^^^^^^^ help: try this: `arr.get(range)`
error: indexing into a vector may panic
- --> $DIR/match_on_vec_items.rs:69:11
+ --> $DIR/match_on_vec_items.rs:70:11
|
LL | match arr[idx] {
| ^^^^^^^^ help: try this: `arr.get(idx)`
error: indexing into a vector may panic
- --> $DIR/match_on_vec_items.rs:76:11
+ --> $DIR/match_on_vec_items.rs:77:11
|
LL | match arr[range] {
| ^^^^^^^^^^ help: try this: `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 b4097fa96..b78c1fd06 100644
--- a/src/tools/clippy/tests/ui/match_overlapping_arm.rs
+++ b/src/tools/clippy/tests/ui/match_overlapping_arm.rs
@@ -1,7 +1,7 @@
#![feature(exclusive_range_pattern)]
#![warn(clippy::match_overlapping_arm)]
#![allow(clippy::redundant_pattern_matching)]
-#![allow(clippy::if_same_then_else, clippy::equatable_if_let)]
+#![allow(clippy::if_same_then_else, clippy::equatable_if_let, clippy::needless_if)]
/// Tests for match_overlapping_arm
diff --git a/src/tools/clippy/tests/ui/match_same_arms.rs b/src/tools/clippy/tests/ui/match_same_arms.rs
index 3914b4546..fad6a7db9 100644
--- a/src/tools/clippy/tests/ui/match_same_arms.rs
+++ b/src/tools/clippy/tests/ui/match_same_arms.rs
@@ -8,29 +8,30 @@ pub enum Abc {
fn match_same_arms() {
let _ = match Abc::A {
- Abc::A => 0,
+ Abc::A => 0, //~ ERROR: this match arm has an identical body to the `_` wildcard arm
Abc::B => 1,
- _ => 0, //~ ERROR match arms have same body
+ _ => 0,
};
match (1, 2, 3) {
- (1, .., 3) => 42,
- (.., 3) => 42, //~ ERROR match arms have same body
+ (1, .., 3) => 42, //~ ERROR: this match arm has an identical body to another arm
+ (.., 3) => 42,
_ => 0,
};
let _ = match 42 {
42 => 1,
- 51 => 1, //~ ERROR match arms have same body
- 41 => 2,
- 52 => 2, //~ ERROR match arms have same body
+ 51 => 1, //~ ERROR: this match arm has an identical body to another arm
+ 41 => 2, //~ ERROR: this match arm has an identical body to another arm
+ 52 => 2,
_ => 0,
};
let _ = match 42 {
1 => 2,
- 2 => 2, //~ ERROR 2nd matched arms have same body
- 3 => 2, //~ ERROR 3rd matched arms have same body
+ 2 => 2, //~ ERROR: this match arm has an identical body to another arm
+ //~^ ERROR: this match arm has an identical body to another arm
+ 3 => 2, //~ ERROR: this match arm has an identical body to another arm
4 => 3,
_ => 0,
};
@@ -48,6 +49,7 @@ mod issue4244 {
match self {
CommandInfo::BuiltIn { name, .. } => name.to_string(),
CommandInfo::External { name, .. } => name.to_string(),
+ //~^ ERROR: this match arm has an identical body to another arm
}
}
}
diff --git a/src/tools/clippy/tests/ui/match_same_arms.stderr b/src/tools/clippy/tests/ui/match_same_arms.stderr
index db85b5964..88b9a20a3 100644
--- a/src/tools/clippy/tests/ui/match_same_arms.stderr
+++ b/src/tools/clippy/tests/ui/match_same_arms.stderr
@@ -8,7 +8,7 @@ LL | Abc::A => 0,
note: `_` wildcard arm here
--> $DIR/match_same_arms.rs:13:9
|
-LL | _ => 0, //~ ERROR match arms have same body
+LL | _ => 0,
| ^^^^^^
= note: `-D clippy::match-same-arms` implied by `-D warnings`
@@ -24,13 +24,13 @@ LL | (1, .., 3) => 42,
note: other arm here
--> $DIR/match_same_arms.rs:18:9
|
-LL | (.., 3) => 42, //~ ERROR match arms have same body
+LL | (.., 3) => 42,
| ^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
--> $DIR/match_same_arms.rs:24:9
|
-LL | 51 => 1, //~ ERROR match arms have same body
+LL | 51 => 1,
| --^^^^^
| |
| help: try merging the arm patterns: `51 | 42`
@@ -54,13 +54,13 @@ LL | 41 => 2,
note: other arm here
--> $DIR/match_same_arms.rs:26:9
|
-LL | 52 => 2, //~ ERROR match arms have same body
+LL | 52 => 2,
| ^^^^^^^
error: this match arm has an identical body to another arm
--> $DIR/match_same_arms.rs:32:9
|
-LL | 2 => 2, //~ ERROR 2nd matched arms have same body
+LL | 2 => 2,
| -^^^^^
| |
| help: try merging the arm patterns: `2 | 1`
@@ -73,9 +73,9 @@ LL | 1 => 2,
| ^^^^^^
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms.rs:33:9
+ --> $DIR/match_same_arms.rs:34:9
|
-LL | 3 => 2, //~ ERROR 3rd matched arms have same body
+LL | 3 => 2,
| -^^^^^
| |
| help: try merging the arm patterns: `3 | 1`
@@ -90,20 +90,20 @@ LL | 1 => 2,
error: this match arm has an identical body to another arm
--> $DIR/match_same_arms.rs:32:9
|
-LL | 2 => 2, //~ ERROR 2nd matched arms have same body
+LL | 2 => 2,
| -^^^^^
| |
| help: try merging the arm patterns: `2 | 3`
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms.rs:33:9
+ --> $DIR/match_same_arms.rs:34:9
|
-LL | 3 => 2, //~ ERROR 3rd matched arms have same body
+LL | 3 => 2,
| ^^^^^^
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms.rs:50:17
+ --> $DIR/match_same_arms.rs:51:17
|
LL | CommandInfo::External { name, .. } => name.to_string(),
| ----------------------------------^^^^^^^^^^^^^^^^^^^^
@@ -112,7 +112,7 @@ LL | CommandInfo::External { name, .. } => name.to_string(),
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms.rs:49:17
+ --> $DIR/match_same_arms.rs:50: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 60b2975be..b1b9a6ae3 100644
--- a/src/tools/clippy/tests/ui/match_same_arms2.rs
+++ b/src/tools/clippy/tests/ui/match_same_arms2.rs
@@ -13,6 +13,7 @@ fn foo() -> bool {
fn match_same_arms() {
let _ = match 42 {
42 => {
+ //~^ ERROR: this match arm has an identical body to the `_` wildcard arm
foo();
let mut a = 42 + [23].len() as i32;
if true {
@@ -22,7 +23,6 @@ fn match_same_arms() {
a
},
_ => {
- //~ ERROR match arms have same body
foo();
let mut a = 42 + [23].len() as i32;
if true {
@@ -35,13 +35,13 @@ fn match_same_arms() {
let _ = match 42 {
42 => foo(),
- 51 => foo(), //~ ERROR match arms have same body
+ 51 => foo(), //~ ERROR: this match arm has an identical body to another arm
_ => true,
};
let _ = match Some(42) {
Some(_) => 24,
- None => 24, //~ ERROR match arms have same body
+ None => 24, //~ ERROR: this match arm has an identical body to another arm
};
let _ = match Some(42) {
@@ -63,13 +63,13 @@ fn match_same_arms() {
match (Some(42), Some(42)) {
(Some(a), None) => bar(a),
- (None, Some(a)) => bar(a), //~ ERROR match arms have same body
+ (None, Some(a)) => bar(a), //~ ERROR: this match arm has an identical body to another arm
_ => (),
}
match (Some(42), Some(42)) {
- (Some(a), ..) => bar(a),
- (.., Some(a)) => bar(a), //~ ERROR match arms have same body
+ (Some(a), ..) => bar(a), //~ ERROR: this match arm has an identical body to another arm
+ (.., Some(a)) => bar(a),
_ => (),
}
@@ -102,7 +102,7 @@ fn match_same_arms() {
}
match (x, Some(1i32)) {
- (Ok(x), Some(_)) => println!("ok {}", x),
+ (Ok(x), Some(_)) => println!("ok {}", x), //~ ERROR: this match arm has an identical body to another arm
(Ok(_), Some(x)) => println!("ok {}", x),
_ => println!("err"),
}
@@ -118,7 +118,7 @@ fn match_same_arms() {
match x {
Ok(_tmp) => println!("ok"),
Ok(3) => println!("ok"),
- Ok(_) => println!("ok"),
+ Ok(_) => println!("ok"), //~ ERROR: this match arm has an identical body to another arm
Err(_) => {
unreachable!();
},
@@ -146,6 +146,7 @@ fn match_same_arms() {
empty!(0);
},
1 => {
+ //~^ ERROR: this match arm has an identical body to another arm
empty!(0);
},
x => {
@@ -195,7 +196,7 @@ fn main() {
// Suggest moving `Foo::Z(_)` up.
let _ = match Foo::X(0) {
- Foo::X(0) => 1,
+ Foo::X(0) => 1, //~ ERROR: this match arm has an identical body to another arm
Foo::X(_) | Foo::Y(_) => 2,
Foo::Z(_) => 1,
_ => 0,
@@ -205,7 +206,7 @@ fn main() {
let _ = match Foo::X(0) {
Foo::X(0) => 1,
Foo::Y(_) | Foo::Z(0) => 2,
- Foo::Z(_) => 1,
+ Foo::Z(_) => 1, //~ ERROR: this match arm has an identical body to another arm
_ => 0,
};
@@ -228,7 +229,7 @@ fn main() {
Some(Bar { x: 0, y: 5, .. }) => 1,
Some(Bar { y: 10, z: 0, .. }) => 2,
None => 50,
- Some(Bar { y: 0, x: 5, .. }) => 1,
+ Some(Bar { y: 0, x: 5, .. }) => 1, //~ ERROR: this match arm has an identical body to another arm
_ => 200,
};
diff --git a/src/tools/clippy/tests/ui/match_same_arms2.stderr b/src/tools/clippy/tests/ui/match_same_arms2.stderr
index 8fb461bd2..7f0c70745 100644
--- a/src/tools/clippy/tests/ui/match_same_arms2.stderr
+++ b/src/tools/clippy/tests/ui/match_same_arms2.stderr
@@ -2,9 +2,9 @@ error: this match arm has an identical body to the `_` wildcard arm
--> $DIR/match_same_arms2.rs:15:9
|
LL | / 42 => {
+LL | |
LL | | foo();
LL | | let mut a = 42 + [23].len() as i32;
-LL | | if true {
... |
LL | | a
LL | | },
@@ -12,12 +12,12 @@ LL | | },
|
= help: or try changing either arm body
note: `_` wildcard arm here
- --> $DIR/match_same_arms2.rs:24:9
+ --> $DIR/match_same_arms2.rs:25:9
|
LL | / _ => {
-LL | | //~ ERROR match arms have same body
LL | | foo();
LL | | let mut a = 42 + [23].len() as i32;
+LL | | if true {
... |
LL | | a
LL | | },
@@ -27,7 +27,7 @@ LL | | },
error: this match arm has an identical body to another arm
--> $DIR/match_same_arms2.rs:38:9
|
-LL | 51 => foo(), //~ ERROR match arms have same body
+LL | 51 => foo(),
| --^^^^^^^^^
| |
| help: try merging the arm patterns: `51 | 42`
@@ -42,7 +42,7 @@ LL | 42 => foo(),
error: this match arm has an identical body to another arm
--> $DIR/match_same_arms2.rs:44:9
|
-LL | None => 24, //~ ERROR match arms have same body
+LL | None => 24,
| ----^^^^^^
| |
| help: try merging the arm patterns: `None | Some(_)`
@@ -57,7 +57,7 @@ LL | Some(_) => 24,
error: this match arm has an identical body to another arm
--> $DIR/match_same_arms2.rs:66:9
|
-LL | (None, Some(a)) => bar(a), //~ ERROR match arms have same body
+LL | (None, Some(a)) => bar(a),
| ---------------^^^^^^^^^^
| |
| help: try merging the arm patterns: `(None, Some(a)) | (Some(a), None)`
@@ -81,7 +81,7 @@ LL | (Some(a), ..) => bar(a),
note: other arm here
--> $DIR/match_same_arms2.rs:72:9
|
-LL | (.., Some(a)) => bar(a), //~ ERROR match arms have same body
+LL | (.., Some(a)) => bar(a),
| ^^^^^^^^^^^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
@@ -121,6 +121,7 @@ LL | 1 => {
| ^ help: try merging the arm patterns: `1 | 0`
| _________|
| |
+LL | |
LL | | empty!(0);
LL | | },
| |_________^
@@ -135,7 +136,7 @@ LL | | },
| |_________^
error: match expression looks like `matches!` macro
- --> $DIR/match_same_arms2.rs:166:16
+ --> $DIR/match_same_arms2.rs:167:16
|
LL | let _ans = match x {
| ________________^
@@ -148,7 +149,7 @@ LL | | };
= note: `-D clippy::match-like-matches-macro` implied by `-D warnings`
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms2.rs:198:9
+ --> $DIR/match_same_arms2.rs:199:9
|
LL | Foo::X(0) => 1,
| ---------^^^^^
@@ -157,13 +158,13 @@ LL | Foo::X(0) => 1,
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms2.rs:200:9
+ --> $DIR/match_same_arms2.rs:201:9
|
LL | Foo::Z(_) => 1,
| ^^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms2.rs:208:9
+ --> $DIR/match_same_arms2.rs:209:9
|
LL | Foo::Z(_) => 1,
| ---------^^^^^
@@ -172,13 +173,13 @@ LL | Foo::Z(_) => 1,
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms2.rs:206:9
+ --> $DIR/match_same_arms2.rs:207:9
|
LL | Foo::X(0) => 1,
| ^^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms2.rs:231:9
+ --> $DIR/match_same_arms2.rs:232:9
|
LL | Some(Bar { y: 0, x: 5, .. }) => 1,
| ----------------------------^^^^^
@@ -187,13 +188,13 @@ LL | Some(Bar { y: 0, x: 5, .. }) => 1,
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms2.rs:228:9
+ --> $DIR/match_same_arms2.rs:229:9
|
LL | Some(Bar { x: 0, y: 5, .. }) => 1,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms2.rs:245:9
+ --> $DIR/match_same_arms2.rs:246:9
|
LL | 1 => cfg!(not_enable),
| -^^^^^^^^^^^^^^^^^^^^
@@ -202,7 +203,7 @@ LL | 1 => cfg!(not_enable),
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms2.rs:244:9
+ --> $DIR/match_same_arms2.rs:245:9
|
LL | 0 => cfg!(not_enable),
| ^^^^^^^^^^^^^^^^^^^^^
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
new file mode 100644
index 000000000..07421173a
--- /dev/null
+++ b/src/tools/clippy/tests/ui/match_same_arms_non_exhaustive.rs
@@ -0,0 +1,58 @@
+#![feature(non_exhaustive_omitted_patterns_lint)]
+#![warn(clippy::match_same_arms)]
+#![no_main]
+
+use std::sync::atomic::Ordering; // #[non_exhaustive] enum
+
+pub fn f(x: Ordering) {
+ match x {
+ Ordering::Relaxed => println!("relaxed"),
+ Ordering::Release => println!("release"),
+ Ordering::Acquire => println!("acquire"),
+ Ordering::AcqRel | Ordering::SeqCst => panic!(),
+ #[deny(non_exhaustive_omitted_patterns)]
+ _ => panic!(),
+ }
+}
+
+mod f {
+ #![deny(non_exhaustive_omitted_patterns)]
+
+ use super::*;
+
+ pub fn f(x: Ordering) {
+ match x {
+ Ordering::Relaxed => println!("relaxed"),
+ Ordering::Release => println!("release"),
+ Ordering::Acquire => println!("acquire"),
+ Ordering::AcqRel | Ordering::SeqCst => panic!(),
+ _ => panic!(),
+ }
+ }
+}
+
+// Below should still lint
+
+pub fn g(x: Ordering) {
+ match x {
+ Ordering::Relaxed => println!("relaxed"),
+ Ordering::Release => println!("release"),
+ Ordering::Acquire => println!("acquire"),
+ Ordering::AcqRel | Ordering::SeqCst => panic!(),
+ _ => panic!(),
+ }
+}
+
+mod g {
+ use super::*;
+
+ pub fn g(x: Ordering) {
+ match x {
+ Ordering::Relaxed => println!("relaxed"),
+ Ordering::Release => println!("release"),
+ Ordering::Acquire => println!("acquire"),
+ Ordering::AcqRel | Ordering::SeqCst => panic!(),
+ _ => 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
new file mode 100644
index 000000000..088f7d5c0
--- /dev/null
+++ b/src/tools/clippy/tests/ui/match_same_arms_non_exhaustive.stderr
@@ -0,0 +1,29 @@
+error: this match arm has an identical body to the `_` wildcard arm
+ --> $DIR/match_same_arms_non_exhaustive.rs:41:9
+ |
+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:42:9
+ |
+LL | _ => panic!(),
+ | ^^^^^^^^^^^^^
+ = note: `-D clippy::match-same-arms` implied by `-D warnings`
+
+error: this match arm has an identical body to the `_` wildcard arm
+ --> $DIR/match_same_arms_non_exhaustive.rs:54: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
+ |
+LL | _ => panic!(),
+ | ^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
diff --git a/src/tools/clippy/tests/ui/match_single_binding.fixed b/src/tools/clippy/tests/ui/match_single_binding.fixed
index 7c29bb08e..f59ff456b 100644
--- a/src/tools/clippy/tests/ui/match_single_binding.fixed
+++ b/src/tools/clippy/tests/ui/match_single_binding.fixed
@@ -5,7 +5,8 @@
clippy::let_unit_value,
clippy::no_effect,
clippy::toplevel_ref_arg,
- clippy::uninlined_format_args
+ clippy::uninlined_format_args,
+ clippy::useless_vec
)]
struct Point {
diff --git a/src/tools/clippy/tests/ui/match_single_binding.rs b/src/tools/clippy/tests/ui/match_single_binding.rs
index c068d5e17..e293bc33c 100644
--- a/src/tools/clippy/tests/ui/match_single_binding.rs
+++ b/src/tools/clippy/tests/ui/match_single_binding.rs
@@ -5,7 +5,8 @@
clippy::let_unit_value,
clippy::no_effect,
clippy::toplevel_ref_arg,
- clippy::uninlined_format_args
+ clippy::uninlined_format_args,
+ clippy::useless_vec
)]
struct Point {
diff --git a/src/tools/clippy/tests/ui/match_single_binding.stderr b/src/tools/clippy/tests/ui/match_single_binding.stderr
index 9d16af76c..8998786de 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:33:5
+ --> $DIR/match_single_binding.rs:34:5
|
LL | / match (a, b, c) {
LL | | (x, y, z) => {
@@ -18,7 +18,7 @@ LL + }
|
error: this match could be written as a `let` statement
- --> $DIR/match_single_binding.rs:39:5
+ --> $DIR/match_single_binding.rs:40:5
|
LL | / match (a, b, c) {
LL | | (x, y, z) => println!("{} {} {}", x, y, z),
@@ -32,7 +32,7 @@ LL + println!("{} {} {}", x, y, z);
|
error: this match could be replaced by its body itself
- --> $DIR/match_single_binding.rs:56:5
+ --> $DIR/match_single_binding.rs:57:5
|
LL | / match a {
LL | | _ => println!("whatever"),
@@ -40,7 +40,7 @@ LL | | }
| |_____^ help: consider using the match body instead: `println!("whatever");`
error: this match could be replaced by its body itself
- --> $DIR/match_single_binding.rs:60:5
+ --> $DIR/match_single_binding.rs:61:5
|
LL | / match a {
LL | | _ => {
@@ -59,7 +59,7 @@ LL + }
|
error: this match could be replaced by its body itself
- --> $DIR/match_single_binding.rs:67:5
+ --> $DIR/match_single_binding.rs:68:5
|
LL | / match a {
LL | | _ => {
@@ -81,7 +81,7 @@ LL + }
|
error: this match could be written as a `let` statement
- --> $DIR/match_single_binding.rs:77:5
+ --> $DIR/match_single_binding.rs:78:5
|
LL | / match p {
LL | | Point { x, y } => println!("Coords: ({}, {})", x, y),
@@ -95,7 +95,7 @@ LL + println!("Coords: ({}, {})", x, y);
|
error: this match could be written as a `let` statement
- --> $DIR/match_single_binding.rs:81:5
+ --> $DIR/match_single_binding.rs:82:5
|
LL | / match p {
LL | | Point { x: x1, y: y1 } => println!("Coords: ({}, {})", x1, y1),
@@ -109,7 +109,7 @@ LL + println!("Coords: ({}, {})", x1, y1);
|
error: this match could be written as a `let` statement
- --> $DIR/match_single_binding.rs:86:5
+ --> $DIR/match_single_binding.rs:87:5
|
LL | / match x {
LL | | ref r => println!("Got a reference to {}", r),
@@ -123,7 +123,7 @@ LL + println!("Got a reference to {}", r);
|
error: this match could be written as a `let` statement
- --> $DIR/match_single_binding.rs:91:5
+ --> $DIR/match_single_binding.rs:92:5
|
LL | / match x {
LL | | ref mut mr => println!("Got a mutable reference to {}", mr),
@@ -137,7 +137,7 @@ LL + println!("Got a mutable reference to {}", mr);
|
error: this match could be written as a `let` statement
- --> $DIR/match_single_binding.rs:95:5
+ --> $DIR/match_single_binding.rs:96:5
|
LL | / let product = match coords() {
LL | | Point { x, y } => x * y,
@@ -151,7 +151,7 @@ LL + let product = x * y;
|
error: this match could be written as a `let` statement
- --> $DIR/match_single_binding.rs:103:18
+ --> $DIR/match_single_binding.rs:104:18
|
LL | .map(|i| match i.unwrap() {
| __________________^
@@ -168,7 +168,7 @@ LL ~ })
|
error: this match could be replaced by its body itself
- --> $DIR/match_single_binding.rs:129:5
+ --> $DIR/match_single_binding.rs:130:5
|
LL | / match x {
LL | | // =>
@@ -177,7 +177,7 @@ LL | | }
| |_____^ help: consider using the match body instead: `println!("Not an array index start")`
error: this assignment could be simplified
- --> $DIR/match_single_binding.rs:138:5
+ --> $DIR/match_single_binding.rs:139:5
|
LL | / val = match val.split_at(idx) {
LL | | (pre, suf) => {
@@ -197,7 +197,7 @@ LL ~ };
|
error: this match could be replaced by its scrutinee and body
- --> $DIR/match_single_binding.rs:151:16
+ --> $DIR/match_single_binding.rs:152:16
|
LL | let _ = || match side_effects() {
| ________________^
@@ -214,7 +214,7 @@ LL ~ };
|
error: this match could be written as a `let` statement
- --> $DIR/match_single_binding.rs:157:5
+ --> $DIR/match_single_binding.rs:158:5
|
LL | / match r {
LL | | x => match x {
@@ -239,7 +239,7 @@ LL ~ };
|
error: this match could be replaced by its body itself
- --> $DIR/match_single_binding.rs:170:5
+ --> $DIR/match_single_binding.rs:171:5
|
LL | / match 1 {
LL | | _ => (),
@@ -247,7 +247,7 @@ LL | | }
| |_____^ help: consider using the match body instead: `();`
error: this match could be replaced by its body itself
- --> $DIR/match_single_binding.rs:174:13
+ --> $DIR/match_single_binding.rs:175:13
|
LL | let a = match 1 {
| _____________^
@@ -256,7 +256,7 @@ LL | | };
| |_____^ help: consider using the match body instead: `()`
error: this match could be replaced by its body itself
- --> $DIR/match_single_binding.rs:178:5
+ --> $DIR/match_single_binding.rs:179:5
|
LL | / match 1 {
LL | | _ => side_effects(),
@@ -264,7 +264,7 @@ LL | | }
| |_____^ help: consider using the match body instead: `side_effects();`
error: this match could be replaced by its body itself
- --> $DIR/match_single_binding.rs:182:13
+ --> $DIR/match_single_binding.rs:183:13
|
LL | let b = match 1 {
| _____________^
@@ -273,7 +273,7 @@ LL | | };
| |_____^ help: consider using the match body instead: `side_effects()`
error: this match could be replaced by its body itself
- --> $DIR/match_single_binding.rs:186:5
+ --> $DIR/match_single_binding.rs:187:5
|
LL | / match 1 {
LL | | _ => println!("1"),
@@ -281,7 +281,7 @@ LL | | }
| |_____^ help: consider using the match body instead: `println!("1");`
error: this match could be replaced by its body itself
- --> $DIR/match_single_binding.rs:190:13
+ --> $DIR/match_single_binding.rs:191:13
|
LL | let c = match 1 {
| _____________^
@@ -290,7 +290,7 @@ LL | | };
| |_____^ help: consider using the match body instead: `println!("1")`
error: this match could be replaced by its body itself
- --> $DIR/match_single_binding.rs:195:9
+ --> $DIR/match_single_binding.rs:196:9
|
LL | / match 1 {
LL | | _ => (),
@@ -298,7 +298,7 @@ LL | | },
| |_________^ help: consider using the match body instead: `()`
error: this match could be replaced by its body itself
- --> $DIR/match_single_binding.rs:198:9
+ --> $DIR/match_single_binding.rs:199:9
|
LL | / match 1 {
LL | | _ => side_effects(),
@@ -306,7 +306,7 @@ LL | | },
| |_________^ help: consider using the match body instead: `side_effects()`
error: this match could be replaced by its body itself
- --> $DIR/match_single_binding.rs:201:9
+ --> $DIR/match_single_binding.rs:202:9
|
LL | / match 1 {
LL | | _ => println!("1"),
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 823be65ef..5a552e4ae 100644
--- a/src/tools/clippy/tests/ui/match_wild_err_arm.rs
+++ b/src/tools/clippy/tests/ui/match_wild_err_arm.rs
@@ -1,7 +1,20 @@
#![feature(exclusive_range_pattern)]
-#![allow(clippy::match_same_arms)]
+#![allow(clippy::match_same_arms, dead_code)]
#![warn(clippy::match_wild_err_arm)]
+fn issue_10635() {
+ enum Error {
+ A,
+ B,
+ }
+
+ // Don't trigger in const contexts. Const unwrap is not yet stable
+ const X: () = match Ok::<_, Error>(()) {
+ Ok(x) => x,
+ Err(_) => panic!(),
+ };
+}
+
fn match_wild_err_arm() {
let x: Result<i32, &str> = Ok(3);
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 b016d6826..a9f54feac 100644
--- a/src/tools/clippy/tests/ui/match_wild_err_arm.stderr
+++ b/src/tools/clippy/tests/ui/match_wild_err_arm.stderr
@@ -1,5 +1,5 @@
error: `Err(_)` matches all errors
- --> $DIR/match_wild_err_arm.rs:11:9
+ --> $DIR/match_wild_err_arm.rs:24:9
|
LL | Err(_) => panic!("err"),
| ^^^^^^
@@ -8,7 +8,7 @@ LL | Err(_) => panic!("err"),
= note: `-D clippy::match-wild-err-arm` implied by `-D warnings`
error: `Err(_)` matches all errors
- --> $DIR/match_wild_err_arm.rs:17:9
+ --> $DIR/match_wild_err_arm.rs:30:9
|
LL | Err(_) => panic!(),
| ^^^^^^
@@ -16,7 +16,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:23:9
+ --> $DIR/match_wild_err_arm.rs:36:9
|
LL | Err(_) => {
| ^^^^^^
@@ -24,7 +24,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:31:9
+ --> $DIR/match_wild_err_arm.rs:44:9
|
LL | Err(_e) => panic!(),
| ^^^^^^^
diff --git a/src/tools/clippy/tests/ui/mem_forget.rs b/src/tools/clippy/tests/ui/mem_forget.rs
index edb9d87d0..b6c8d9e53 100644
--- a/src/tools/clippy/tests/ui/mem_forget.rs
+++ b/src/tools/clippy/tests/ui/mem_forget.rs
@@ -19,5 +19,8 @@ fn main() {
let eight: Vec<i32> = vec![8];
forgetSomething(eight);
+ let string = String::new();
+ std::mem::forget(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 a90d8b165..8004b2aa8 100644
--- a/src/tools/clippy/tests/ui/mem_forget.stderr
+++ b/src/tools/clippy/tests/ui/mem_forget.stderr
@@ -4,6 +4,7 @@ error: usage of `mem::forget` on `Drop` type
LL | memstuff::forget(six);
| ^^^^^^^^^^^^^^^^^^^^^
|
+ = note: argument has type `std::sync::Arc<i32>`
= note: `-D clippy::mem-forget` implied by `-D warnings`
error: usage of `mem::forget` on `Drop` type
@@ -11,12 +12,24 @@ error: usage of `mem::forget` on `Drop` type
|
LL | std::mem::forget(seven);
| ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: argument has type `std::rc::Rc<i32>`
error: usage of `mem::forget` on `Drop` type
--> $DIR/mem_forget.rs:20:5
|
LL | forgetSomething(eight);
| ^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: argument has type `std::vec::Vec<i32>`
+
+error: usage of `mem::forget` on type with `Drop` fields
+ --> $DIR/mem_forget.rs:23:5
+ |
+LL | std::mem::forget(string);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: argument has type `std::string::String`
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
diff --git a/src/tools/clippy/tests/ui/mem_replace_macro.rs b/src/tools/clippy/tests/ui/mem_replace_macro.rs
index 132873858..e53342f2e 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
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::mem_replace_with_default)]
extern crate proc_macros;
diff --git a/src/tools/clippy/tests/ui/methods.rs b/src/tools/clippy/tests/ui/methods.rs
index e0e2cac30..589eab5cd 100644
--- a/src/tools/clippy/tests/ui/methods.rs
+++ b/src/tools/clippy/tests/ui/methods.rs
@@ -18,6 +18,7 @@
clippy::wrong_self_convention,
clippy::unused_async,
clippy::unused_self,
+ clippy::useless_vec,
unused
)]
diff --git a/src/tools/clippy/tests/ui/methods.stderr b/src/tools/clippy/tests/ui/methods.stderr
index 4643e09e2..73ec48643 100644
--- a/src/tools/clippy/tests/ui/methods.stderr
+++ b/src/tools/clippy/tests/ui/methods.stderr
@@ -1,5 +1,5 @@
error: methods called `new` usually return `Self`
- --> $DIR/methods.rs:105:5
+ --> $DIR/methods.rs:106:5
|
LL | / fn new() -> i32 {
LL | | 0
@@ -9,7 +9,7 @@ LL | | }
= note: `-D clippy::new-ret-no-self` implied by `-D warnings`
error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead
- --> $DIR/methods.rs:126:13
+ --> $DIR/methods.rs:127:13
|
LL | let _ = v.iter().filter(|&x| {
| _____________^
diff --git a/src/tools/clippy/tests/ui/methods_fixable.fixed b/src/tools/clippy/tests/ui/methods_fixable.fixed
index dcbed5a4d..ce5d19a8b 100644
--- a/src/tools/clippy/tests/ui/methods_fixable.fixed
+++ b/src/tools/clippy/tests/ui/methods_fixable.fixed
@@ -1,6 +1,7 @@
//@run-rustfix
#![warn(clippy::filter_next)]
+#![allow(clippy::useless_vec)]
/// Checks implementation of `FILTER_NEXT` lint.
fn main() {
diff --git a/src/tools/clippy/tests/ui/methods_fixable.rs b/src/tools/clippy/tests/ui/methods_fixable.rs
index 3a976d235..0615817ec 100644
--- a/src/tools/clippy/tests/ui/methods_fixable.rs
+++ b/src/tools/clippy/tests/ui/methods_fixable.rs
@@ -1,6 +1,7 @@
//@run-rustfix
#![warn(clippy::filter_next)]
+#![allow(clippy::useless_vec)]
/// Checks implementation of `FILTER_NEXT` lint.
fn main() {
diff --git a/src/tools/clippy/tests/ui/methods_fixable.stderr b/src/tools/clippy/tests/ui/methods_fixable.stderr
index 852f48e32..187714c75 100644
--- a/src/tools/clippy/tests/ui/methods_fixable.stderr
+++ b/src/tools/clippy/tests/ui/methods_fixable.stderr
@@ -1,5 +1,5 @@
error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead
- --> $DIR/methods_fixable.rs:10:13
+ --> $DIR/methods_fixable.rs:11:13
|
LL | let _ = v.iter().filter(|&x| *x < 0).next();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `v.iter().find(|&x| *x < 0)`
diff --git a/src/tools/clippy/tests/ui/min_ident_chars.rs b/src/tools/clippy/tests/ui/min_ident_chars.rs
new file mode 100644
index 000000000..b5b9e66aa
--- /dev/null
+++ b/src/tools/clippy/tests/ui/min_ident_chars.rs
@@ -0,0 +1,84 @@
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(irrefutable_let_patterns, nonstandard_style, unused)]
+#![warn(clippy::min_ident_chars)]
+
+extern crate proc_macros;
+use proc_macros::external;
+use proc_macros::with_span;
+
+struct A {
+ a: u32,
+ i: u32,
+ A: u32,
+ I: u32,
+}
+
+struct B(u32);
+
+struct O {
+ o: u32,
+}
+
+struct i;
+
+enum C {
+ D,
+ E,
+ F,
+ j,
+}
+
+struct Vec4 {
+ x: u32,
+ y: u32,
+ z: u32,
+ w: u32,
+}
+
+struct AA<T, E>(T, E);
+
+fn main() {
+ // Allowed idents
+ let w = 1;
+ // Ok, not this one
+ // let i = 1;
+ let j = 1;
+ let n = 1;
+ let z = 1;
+ let y = 1;
+ let z = 1;
+ // Implicitly disallowed idents
+ let h = 1;
+ let e = 2;
+ let l = 3;
+ let l = 4;
+ let o = 6;
+ // 2 len does not lint
+ let hi = 0;
+ // Lint
+ let (h, o, w) = (1, 2, 3);
+ for (a, (r, e)) in (0..1000).enumerate().enumerate() {}
+ let you = Vec4 { x: 1, y: 2, z: 3, w: 4 };
+ while let (d, o, _i, n, g) = (true, true, false, false, true) {}
+ let today = true;
+ // Ideally this wouldn't lint, but this would (likely) require global analysis, outta scope
+ // of this lint regardless
+ let o = 1;
+ let o = O { o };
+
+ for j in 0..1000 {}
+ for _ in 0..10 {}
+
+ // Do not lint code from external macros
+ external! { for j in 0..1000 {} }
+ // Do not lint code from procedural macros
+ with_span! {
+ span
+ for j in 0..1000 {}
+ }
+}
+
+fn b() {}
+fn wrong_pythagoras(a: f32, b: f32) -> f32 {
+ a * a + a * b
+}
diff --git a/src/tools/clippy/tests/ui/min_ident_chars.stderr b/src/tools/clippy/tests/ui/min_ident_chars.stderr
new file mode 100644
index 000000000..66a63f657
--- /dev/null
+++ b/src/tools/clippy/tests/ui/min_ident_chars.stderr
@@ -0,0 +1,178 @@
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:9:8
+ |
+LL | struct A {
+ | ^
+ |
+ = note: `-D clippy::min-ident-chars` implied by `-D warnings`
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:10:5
+ |
+LL | a: u32,
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:12:5
+ |
+LL | A: u32,
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:13:5
+ |
+LL | I: u32,
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:16:8
+ |
+LL | struct B(u32);
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:18:8
+ |
+LL | struct O {
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:19:5
+ |
+LL | o: u32,
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:24:6
+ |
+LL | enum C {
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:25:5
+ |
+LL | D,
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:26:5
+ |
+LL | E,
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:27:5
+ |
+LL | F,
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:51:9
+ |
+LL | let h = 1;
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:52:9
+ |
+LL | let e = 2;
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:53:9
+ |
+LL | let l = 3;
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:54:9
+ |
+LL | let l = 4;
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:55:9
+ |
+LL | let o = 6;
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:59:10
+ |
+LL | let (h, o, w) = (1, 2, 3);
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:59:13
+ |
+LL | let (h, o, w) = (1, 2, 3);
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:60:10
+ |
+LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {}
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:60:14
+ |
+LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {}
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:60:17
+ |
+LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {}
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:62:16
+ |
+LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {}
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:62:19
+ |
+LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {}
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:62:29
+ |
+LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {}
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:66:9
+ |
+LL | let o = 1;
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:67:9
+ |
+LL | let o = O { o };
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:81:4
+ |
+LL | fn b() {}
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:82:21
+ |
+LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 {
+ | ^
+
+error: this ident consists of a single char
+ --> $DIR/min_ident_chars.rs:82:29
+ |
+LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 {
+ | ^
+
+error: aborting due to 29 previous errors
+
diff --git a/src/tools/clippy/tests/ui/missing_assert_message.rs b/src/tools/clippy/tests/ui/missing_assert_message.rs
index 89404ca88..af1358f61 100644
--- a/src/tools/clippy/tests/ui/missing_assert_message.rs
+++ b/src/tools/clippy/tests/ui/missing_assert_message.rs
@@ -7,8 +7,6 @@ macro_rules! bar {
};
}
-fn main() {}
-
// Should trigger warning
fn asserts_without_message() {
assert!(foo());
@@ -66,9 +64,14 @@ fn asserts_without_message_but_inside_a_test_function() {
debug_assert_ne!(foo(), foo());
}
+fn foo() -> bool {
+ true
+}
+
// Should not trigger warning
#[cfg(test)]
mod tests {
+ use super::foo;
fn asserts_without_message_but_inside_a_test_module() {
assert!(foo());
assert_eq!(foo(), foo());
@@ -78,7 +81,3 @@ mod tests {
debug_assert_ne!(foo(), foo());
}
}
-
-fn foo() -> bool {
- true
-}
diff --git a/src/tools/clippy/tests/ui/missing_assert_message.stderr b/src/tools/clippy/tests/ui/missing_assert_message.stderr
index ecd038012..33a5c1f8e 100644
--- a/src/tools/clippy/tests/ui/missing_assert_message.stderr
+++ b/src/tools/clippy/tests/ui/missing_assert_message.stderr
@@ -1,5 +1,5 @@
error: assert without any message
- --> $DIR/missing_assert_message.rs:14:5
+ --> $DIR/missing_assert_message.rs:12:5
|
LL | assert!(foo());
| ^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | assert!(foo());
= note: `-D clippy::missing-assert-message` implied by `-D warnings`
error: assert without any message
- --> $DIR/missing_assert_message.rs:15:5
+ --> $DIR/missing_assert_message.rs:13:5
|
LL | assert_eq!(foo(), foo());
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,7 +16,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:16:5
+ --> $DIR/missing_assert_message.rs:14:5
|
LL | assert_ne!(foo(), foo());
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -24,7 +24,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:17:5
+ --> $DIR/missing_assert_message.rs:15:5
|
LL | debug_assert!(foo());
| ^^^^^^^^^^^^^^^^^^^^
@@ -32,7 +32,7 @@ LL | debug_assert!(foo());
= help: consider describing why the failing assert is problematic
error: assert without any message
- --> $DIR/missing_assert_message.rs:18:5
+ --> $DIR/missing_assert_message.rs:16:5
|
LL | debug_assert_eq!(foo(), foo());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,7 +40,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:19:5
+ --> $DIR/missing_assert_message.rs:17:5
|
LL | debug_assert_ne!(foo(), foo());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -48,7 +48,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:24:5
+ --> $DIR/missing_assert_message.rs:22:5
|
LL | assert!(bar!(true));
| ^^^^^^^^^^^^^^^^^^^
@@ -56,7 +56,7 @@ LL | assert!(bar!(true));
= 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:23:5
|
LL | assert!(bar!(true, false));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -64,7 +64,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:26:5
+ --> $DIR/missing_assert_message.rs:24:5
|
LL | assert_eq!(bar!(true), foo());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -72,7 +72,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:27:5
+ --> $DIR/missing_assert_message.rs:25:5
|
LL | assert_ne!(bar!(true, true), bar!(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -80,7 +80,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:32:5
+ --> $DIR/missing_assert_message.rs:30:5
|
LL | assert!(foo(),);
| ^^^^^^^^^^^^^^^
@@ -88,7 +88,7 @@ LL | assert!(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:31:5
|
LL | assert_eq!(foo(), foo(),);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -96,7 +96,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:34:5
+ --> $DIR/missing_assert_message.rs:32:5
|
LL | assert_ne!(foo(), foo(),);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -104,7 +104,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:35:5
+ --> $DIR/missing_assert_message.rs:33:5
|
LL | debug_assert!(foo(),);
| ^^^^^^^^^^^^^^^^^^^^^
@@ -112,7 +112,7 @@ LL | debug_assert!(foo(),);
= help: consider describing why the failing assert is problematic
error: assert without any message
- --> $DIR/missing_assert_message.rs:36:5
+ --> $DIR/missing_assert_message.rs:34:5
|
LL | debug_assert_eq!(foo(), foo(),);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -120,7 +120,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:37:5
+ --> $DIR/missing_assert_message.rs:35:5
|
LL | debug_assert_ne!(foo(), foo(),);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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 5db73a7b8..06e053524 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
+//@aux-build:../auxiliary/proc_macros.rs:proc-macro
#![warn(clippy::missing_const_for_fn)]
#![feature(start)]
@@ -13,7 +13,7 @@ extern crate proc_macros;
use proc_macros::with_span;
-struct Game;
+struct Game; // You just lost.
// This should not be linted because it's already const
const fn already_const() -> i32 {
@@ -44,7 +44,6 @@ static Y: u32 = 0;
// refer to a static variable
fn get_y() -> u32 {
Y
- //~^ ERROR E0013
}
// Don't lint entrypoint functions
@@ -126,3 +125,43 @@ with_span! {
span
fn dont_check_in_proc_macro() {}
}
+
+// Do not lint `String` has `Vec<u8>`, which cannot be dropped in const contexts
+fn a(this: String) {}
+
+enum A {
+ F(String),
+ N,
+}
+
+// Same here.
+fn b(this: A) {}
+
+// Minimized version of `a`.
+fn c(this: Vec<u16>) {}
+
+struct F(A);
+
+// Do not lint
+fn f(this: F) {}
+
+// Do not lint
+fn g<T>(this: T) {}
+
+struct Issue10617(String);
+
+impl Issue10617 {
+ // Do not lint
+ pub fn name(self) -> String {
+ self.0
+ }
+}
+
+union U {
+ f: u32,
+}
+
+// Do not lint because accessing union fields from const functions is unstable
+fn h(u: U) -> u32 {
+ unsafe { u.f }
+}
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 0246c8622..b1980b1b5 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
@@ -1,5 +1,7 @@
#![warn(clippy::missing_const_for_fn)]
#![allow(incomplete_features, clippy::let_and_return)]
+#![feature(const_mut_refs)]
+#![feature(const_trait_impl)]
use std::mem::transmute;
@@ -87,3 +89,14 @@ fn msrv_1_46() -> i32 {
// Should not be const
fn main() {}
+
+struct D;
+
+impl const Drop for D {
+ fn drop(&mut self) {
+ todo!();
+ }
+}
+
+// Lint this, since it can be dropped in const contexts
+fn d(this: D) {}
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 955e1ed26..7be2cc0ca 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
@@ -1,5 +1,5 @@
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:12:5
+ --> $DIR/could_be_const.rs:14:5
|
LL | / pub fn new() -> Self {
LL | | Self { guess: 42 }
@@ -9,7 +9,7 @@ LL | | }
= note: `-D clippy::missing-const-for-fn` implied by `-D warnings`
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:16:5
+ --> $DIR/could_be_const.rs:18:5
|
LL | / fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] {
LL | | b
@@ -17,7 +17,7 @@ LL | | }
| |_____^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:22:1
+ --> $DIR/could_be_const.rs:24:1
|
LL | / fn one() -> i32 {
LL | | 1
@@ -25,7 +25,7 @@ LL | | }
| |_^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:27:1
+ --> $DIR/could_be_const.rs:29:1
|
LL | / fn two() -> i32 {
LL | | let abc = 2;
@@ -34,7 +34,7 @@ LL | | }
| |_^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:33:1
+ --> $DIR/could_be_const.rs:35:1
|
LL | / fn string() -> String {
LL | | String::new()
@@ -42,7 +42,7 @@ LL | | }
| |_^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:38:1
+ --> $DIR/could_be_const.rs:40:1
|
LL | / unsafe fn four() -> i32 {
LL | | 4
@@ -50,7 +50,7 @@ LL | | }
| |_^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:43:1
+ --> $DIR/could_be_const.rs:45:1
|
LL | / fn generic<T>(t: T) -> T {
LL | | t
@@ -58,7 +58,7 @@ LL | | }
| |_^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:51:1
+ --> $DIR/could_be_const.rs:53:1
|
LL | / fn generic_arr<T: Copy>(t: [T; 1]) -> T {
LL | | t[0]
@@ -66,7 +66,7 @@ LL | | }
| |_^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:64:9
+ --> $DIR/could_be_const.rs:66:9
|
LL | / pub fn b(self, a: &A) -> B {
LL | | B
@@ -74,7 +74,7 @@ LL | | }
| |_________^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:73:5
+ --> $DIR/could_be_const.rs:75:5
|
LL | / fn const_fn_stabilized_before_msrv(byte: u8) {
LL | | byte.is_ascii_digit();
@@ -82,12 +82,18 @@ LL | | }
| |_____^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:84:1
+ --> $DIR/could_be_const.rs:86:1
|
LL | / fn msrv_1_46() -> i32 {
LL | | 46
LL | | }
| |_^
-error: aborting due to 11 previous errors
+error: this could be a `const fn`
+ --> $DIR/could_be_const.rs:102:1
+ |
+LL | fn d(this: D) {}
+ | ^^^^^^^^^^^^^^^^
+
+error: aborting due to 12 previous errors
diff --git a/src/tools/clippy/tests/ui/missing_doc.rs b/src/tools/clippy/tests/ui/missing_doc.rs
index bf587e774..cff1706a8 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
+//@aux-build: proc_macros.rs:proc-macro
#![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_impl.rs b/src/tools/clippy/tests/ui/missing_doc_impl.rs
index 520ddbe16..2d45132f9 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
+//@aux-build: proc_macros.rs:proc-macro
#![warn(clippy::missing_docs_in_private_items)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/missing_fields_in_debug.rs b/src/tools/clippy/tests/ui/missing_fields_in_debug.rs
new file mode 100644
index 000000000..c156d394e
--- /dev/null
+++ b/src/tools/clippy/tests/ui/missing_fields_in_debug.rs
@@ -0,0 +1,191 @@
+#![allow(unused)]
+#![warn(clippy::missing_fields_in_debug)]
+
+use std::fmt;
+use std::marker::PhantomData;
+use std::ops::Deref;
+
+struct NamedStruct1Ignored {
+ data: u8,
+ hidden: u32,
+}
+
+impl fmt::Debug for NamedStruct1Ignored {
+ // unused field: hidden
+ fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
+ formatter
+ .debug_struct("NamedStruct1Ignored")
+ .field("data", &self.data)
+ .finish()
+ }
+}
+
+struct NamedStructMultipleIgnored {
+ data: u8,
+ hidden: u32,
+ hidden2: String,
+ hidden3: Vec<Vec<i32>>,
+ hidden4: ((((u8), u16), u32), u64),
+}
+
+impl fmt::Debug for NamedStructMultipleIgnored {
+ // unused fields: hidden, hidden2, hidden4
+ fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
+ formatter
+ .debug_struct("NamedStructMultipleIgnored")
+ .field("data", &self.data)
+ .field("hidden3", &self.hidden3)
+ .finish()
+ }
+}
+
+struct Unit;
+
+// ok
+impl fmt::Debug for Unit {
+ fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
+ formatter.debug_struct("Unit").finish()
+ }
+}
+
+struct UnnamedStruct1Ignored(String);
+
+impl fmt::Debug for UnnamedStruct1Ignored {
+ fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
+ formatter.debug_tuple("UnnamedStruct1Ignored").finish()
+ }
+}
+
+struct UnnamedStructMultipleIgnored(String, Vec<u8>, i32);
+
+// tuple structs are not linted
+impl fmt::Debug for UnnamedStructMultipleIgnored {
+ fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
+ formatter
+ .debug_tuple("UnnamedStructMultipleIgnored")
+ .field(&self.1)
+ .finish()
+ }
+}
+
+struct NamedStructNonExhaustive {
+ a: u8,
+ b: String,
+}
+
+// ok
+impl fmt::Debug for NamedStructNonExhaustive {
+ fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
+ formatter
+ .debug_struct("NamedStructNonExhaustive")
+ .field("a", &self.a)
+ .finish_non_exhaustive() // should not warn here
+ }
+}
+
+struct MultiExprDebugImpl {
+ a: u8,
+ b: String,
+}
+
+// ok
+impl fmt::Debug for MultiExprDebugImpl {
+ fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let mut f = formatter.debug_struct("MultiExprDebugImpl");
+ f.field("a", &self.a);
+ f.finish()
+ }
+}
+
+#[derive(Debug)]
+struct DerivedStruct {
+ a: u8,
+ b: i32,
+}
+
+// https://github.com/rust-lang/rust-clippy/pull/10616#discussion_r1166846953
+
+struct Inner {
+ a: usize,
+ b: usize,
+}
+
+struct HasInner {
+ inner: Inner,
+}
+
+impl HasInner {
+ fn get(&self) -> &Inner {
+ &self.inner
+ }
+}
+
+impl fmt::Debug for HasInner {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let inner = self.get();
+
+ f.debug_struct("HasInner")
+ .field("a", &inner.a)
+ .field("b", &inner.b)
+ .finish()
+ }
+}
+
+// https://github.com/rust-lang/rust-clippy/pull/10616#discussion_r1170306053
+struct Foo {
+ a: u8,
+ b: u8,
+}
+
+impl fmt::Debug for Foo {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("Foo").field("a", &self.a).field("b", &()).finish()
+ }
+}
+
+// https://github.com/rust-lang/rust-clippy/pull/10616#discussion_r1175473620
+mod comment1175473620 {
+ use super::*;
+
+ struct Inner {
+ a: usize,
+ b: usize,
+ }
+ struct Wrapper(Inner);
+
+ impl Deref for Wrapper {
+ type Target = Inner;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+ }
+
+ impl fmt::Debug for Wrapper {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("Wrapper")
+ .field("a", &self.a)
+ .field("b", &self.b)
+ .finish()
+ }
+ }
+}
+
+// https://github.com/rust-lang/rust-clippy/pull/10616#discussion_r1175488757
+// PhantomData is an exception and does not need to be included
+struct WithPD {
+ a: u8,
+ b: u8,
+ c: PhantomData<String>,
+}
+
+impl fmt::Debug for WithPD {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("WithPD")
+ .field("a", &self.a)
+ .field("b", &self.b)
+ .finish()
+ }
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/missing_fields_in_debug.stderr b/src/tools/clippy/tests/ui/missing_fields_in_debug.stderr
new file mode 100644
index 000000000..ef9d02aba
--- /dev/null
+++ b/src/tools/clippy/tests/ui/missing_fields_in_debug.stderr
@@ -0,0 +1,73 @@
+error: manual `Debug` impl does not include all fields
+ --> $DIR/missing_fields_in_debug.rs:13:1
+ |
+LL | / impl fmt::Debug for NamedStruct1Ignored {
+LL | | // unused field: hidden
+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:10:5
+ |
+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`
+
+error: manual `Debug` impl does not include all fields
+ --> $DIR/missing_fields_in_debug.rs:31:1
+ |
+LL | / impl fmt::Debug for NamedStructMultipleIgnored {
+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
+ |
+LL | hidden: u32,
+ | ^^^^^^^^^^^
+note: this field is unused
+ --> $DIR/missing_fields_in_debug.rs:26:5
+ |
+LL | hidden2: String,
+ | ^^^^^^^^^^^^^^^
+note: this field is unused
+ --> $DIR/missing_fields_in_debug.rs:28:5
+ |
+LL | hidden4: ((((u8), u16), u32), u64),
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = help: consider including all fields in this `Debug` impl
+ = 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
+ |
+LL | / impl fmt::Debug for MultiExprDebugImpl {
+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
+ |
+LL | b: String,
+ | ^^^^^^^^^
+ = help: consider including all fields in this `Debug` impl
+ = help: consider calling `.finish_non_exhaustive()` if you intend to ignore fields
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/missing_inline_proc_macro.rs b/src/tools/clippy/tests/ui/missing_inline_proc_macro.rs
index 3c68fb905..e47a198c6 100644
--- a/src/tools/clippy/tests/ui/missing_inline_proc_macro.rs
+++ b/src/tools/clippy/tests/ui/missing_inline_proc_macro.rs
@@ -1,5 +1,4 @@
#![warn(clippy::missing_inline_in_public_items)]
-#![crate_type = "proc-macro"]
extern crate proc_macro;
diff --git a/src/tools/clippy/tests/ui/missing_panics_doc.rs b/src/tools/clippy/tests/ui/missing_panics_doc.rs
index 7dc445292..0e1533fc1 100644
--- a/src/tools/clippy/tests/ui/missing_panics_doc.rs
+++ b/src/tools/clippy/tests/ui/missing_panics_doc.rs
@@ -1,5 +1,12 @@
+//@aux-build:macro_rules.rs
#![warn(clippy::missing_panics_doc)]
-#![allow(clippy::option_map_unit_fn)]
+#![allow(clippy::option_map_unit_fn, clippy::unnecessary_literal_unwrap)]
+
+#[macro_use]
+extern crate macro_rules;
+
+use macro_rules::macro_with_panic;
+
fn main() {}
/// This needs to be documented
@@ -14,11 +21,6 @@ pub fn panic() {
}
/// This needs to be documented
-pub fn todo() {
- todo!()
-}
-
-/// This needs to be documented
pub fn inner_body(opt: Option<u32>) {
opt.map(|x| {
if x == 10 {
@@ -81,15 +83,6 @@ pub fn inner_body_documented(opt: Option<u32>) {
/// # Panics
///
/// We still need to do this part
-pub fn todo_documented() {
- todo!()
-}
-
-/// This is documented
-///
-/// # Panics
-///
-/// We still need to do this part
pub fn unreachable_amd_panic_documented() {
if true { unreachable!() } else { panic!() }
}
@@ -114,6 +107,11 @@ pub fn assert_ne_documented() {
assert_ne!(x, 0);
}
+/// `todo!()` is fine
+pub fn todo() {
+ todo!()
+}
+
/// This is okay because it is private
fn unwrap_private() {
let result = Err("Hi");
@@ -126,11 +124,6 @@ fn panic_private() {
}
/// This is okay because it is private
-fn todo_private() {
- todo!()
-}
-
-/// This is okay because it is private
fn inner_body_private(opt: Option<u32>) {
opt.map(|x| {
if x == 10 {
@@ -151,3 +144,50 @@ pub fn debug_assertions() {
debug_assert_eq!(1, 2);
debug_assert_ne!(1, 2);
}
+
+// all function must be triggered the lint.
+// `pub` is required, because the lint does not consider unreachable items
+pub mod issue10240 {
+ pub fn option_unwrap<T>(v: &[T]) -> &T {
+ let o: Option<&T> = v.last();
+ o.unwrap()
+ }
+
+ pub fn option_expect<T>(v: &[T]) -> &T {
+ let o: Option<&T> = v.last();
+ o.expect("passed an empty thing")
+ }
+
+ pub fn result_unwrap<T>(v: &[T]) -> &T {
+ let res: Result<&T, &str> = v.last().ok_or("oh noes");
+ res.unwrap()
+ }
+
+ pub fn result_expect<T>(v: &[T]) -> &T {
+ let res: Result<&T, &str> = v.last().ok_or("oh noes");
+ res.expect("passed an empty thing")
+ }
+
+ pub fn last_unwrap(v: &[u32]) -> u32 {
+ *v.last().unwrap()
+ }
+
+ pub fn last_expect(v: &[u32]) -> u32 {
+ *v.last().expect("passed an empty thing")
+ }
+}
+
+fn from_external_macro_should_not_lint() {
+ macro_with_panic!()
+}
+
+macro_rules! some_macro_that_panics {
+ () => {
+ panic!()
+ };
+}
+
+fn from_declared_macro_should_lint_at_macrosite() {
+ // Not here.
+ some_macro_that_panics!()
+}
diff --git a/src/tools/clippy/tests/ui/missing_panics_doc.stderr b/src/tools/clippy/tests/ui/missing_panics_doc.stderr
index 183c262ce..3dbe2dfbd 100644
--- a/src/tools/clippy/tests/ui/missing_panics_doc.stderr
+++ b/src/tools/clippy/tests/ui/missing_panics_doc.stderr
@@ -1,87 +1,147 @@
error: docs for function which may panic missing `# Panics` section
- --> $DIR/missing_panics_doc.rs:6:1
+ --> $DIR/missing_panics_doc.rs:13:1
|
LL | pub fn unwrap() {
| ^^^^^^^^^^^^^^^
|
note: first possible panic found here
- --> $DIR/missing_panics_doc.rs:8:5
+ --> $DIR/missing_panics_doc.rs:15:5
|
LL | result.unwrap()
| ^^^^^^^^^^^^^^^
= note: `-D clippy::missing-panics-doc` implied by `-D warnings`
error: docs for function which may panic missing `# Panics` section
- --> $DIR/missing_panics_doc.rs:12:1
+ --> $DIR/missing_panics_doc.rs:19:1
|
LL | pub fn panic() {
| ^^^^^^^^^^^^^^
|
note: first possible panic found here
- --> $DIR/missing_panics_doc.rs:13:5
+ --> $DIR/missing_panics_doc.rs:20:5
|
LL | panic!("This function panics")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: docs for function which may panic missing `# Panics` section
- --> $DIR/missing_panics_doc.rs:17:1
- |
-LL | pub fn todo() {
- | ^^^^^^^^^^^^^
- |
-note: first possible panic found here
- --> $DIR/missing_panics_doc.rs:18:5
- |
-LL | todo!()
- | ^^^^^^^
-
-error: docs for function which may panic missing `# Panics` section
- --> $DIR/missing_panics_doc.rs:22:1
+ --> $DIR/missing_panics_doc.rs:24:1
|
LL | pub fn inner_body(opt: Option<u32>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: first possible panic found here
- --> $DIR/missing_panics_doc.rs:25:13
+ --> $DIR/missing_panics_doc.rs:27:13
|
LL | panic!()
| ^^^^^^^^
error: docs for function which may panic missing `# Panics` section
- --> $DIR/missing_panics_doc.rs:31:1
+ --> $DIR/missing_panics_doc.rs:33:1
|
LL | pub fn unreachable_and_panic() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: first possible panic found here
- --> $DIR/missing_panics_doc.rs:32:39
+ --> $DIR/missing_panics_doc.rs:34:39
|
LL | if true { unreachable!() } else { panic!() }
| ^^^^^^^^
error: docs for function which may panic missing `# Panics` section
- --> $DIR/missing_panics_doc.rs:36:1
+ --> $DIR/missing_panics_doc.rs:38:1
|
LL | pub fn assert_eq() {
| ^^^^^^^^^^^^^^^^^^
|
note: first possible panic found here
- --> $DIR/missing_panics_doc.rs:38:5
+ --> $DIR/missing_panics_doc.rs:40:5
|
LL | assert_eq!(x, 0);
| ^^^^^^^^^^^^^^^^
error: docs for function which may panic missing `# Panics` section
- --> $DIR/missing_panics_doc.rs:42:1
+ --> $DIR/missing_panics_doc.rs:44:1
|
LL | pub fn assert_ne() {
| ^^^^^^^^^^^^^^^^^^
|
note: first possible panic found here
- --> $DIR/missing_panics_doc.rs:44:5
+ --> $DIR/missing_panics_doc.rs:46:5
|
LL | assert_ne!(x, 0);
| ^^^^^^^^^^^^^^^^
-error: aborting due to 7 previous errors
+error: docs for function which may panic missing `# Panics` section
+ --> $DIR/missing_panics_doc.rs:151:5
+ |
+LL | pub fn option_unwrap<T>(v: &[T]) -> &T {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: first possible panic found here
+ --> $DIR/missing_panics_doc.rs:153:9
+ |
+LL | o.unwrap()
+ | ^^^^^^^^^^
+
+error: docs for function which may panic missing `# Panics` section
+ --> $DIR/missing_panics_doc.rs:156:5
+ |
+LL | pub fn option_expect<T>(v: &[T]) -> &T {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: first possible panic found here
+ --> $DIR/missing_panics_doc.rs:158:9
+ |
+LL | o.expect("passed an empty thing")
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: docs for function which may panic missing `# Panics` section
+ --> $DIR/missing_panics_doc.rs:161:5
+ |
+LL | pub fn result_unwrap<T>(v: &[T]) -> &T {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: first possible panic found here
+ --> $DIR/missing_panics_doc.rs:163:9
+ |
+LL | res.unwrap()
+ | ^^^^^^^^^^^^
+
+error: docs for function which may panic missing `# Panics` section
+ --> $DIR/missing_panics_doc.rs:166:5
+ |
+LL | pub fn result_expect<T>(v: &[T]) -> &T {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: first possible panic found here
+ --> $DIR/missing_panics_doc.rs:168:9
+ |
+LL | res.expect("passed an empty thing")
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: docs for function which may panic missing `# Panics` section
+ --> $DIR/missing_panics_doc.rs:171:5
+ |
+LL | pub fn last_unwrap(v: &[u32]) -> u32 {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: first possible panic found here
+ --> $DIR/missing_panics_doc.rs:172:10
+ |
+LL | *v.last().unwrap()
+ | ^^^^^^^^^^^^^^^^^
+
+error: docs for function which may panic missing `# Panics` section
+ --> $DIR/missing_panics_doc.rs:175:5
+ |
+LL | pub fn last_expect(v: &[u32]) -> u32 {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: first possible panic found here
+ --> $DIR/missing_panics_doc.rs:176:10
+ |
+LL | *v.last().expect("passed an empty thing")
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 12 previous errors
diff --git a/src/tools/clippy/tests/ui/mistyped_literal_suffix.fixed b/src/tools/clippy/tests/ui/mistyped_literal_suffix.fixed
index 62cfeafdc..9c2ffcb02 100644
--- a/src/tools/clippy/tests/ui/mistyped_literal_suffix.fixed
+++ b/src/tools/clippy/tests/ui/mistyped_literal_suffix.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build: proc_macros.rs
+//@aux-build: proc_macros.rs:proc-macro
#![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 f83b7c3db..a0a1e96a7 100644
--- a/src/tools/clippy/tests/ui/mistyped_literal_suffix.rs
+++ b/src/tools/clippy/tests/ui/mistyped_literal_suffix.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build: proc_macros.rs
+//@aux-build: proc_macros.rs:proc-macro
#![allow(
dead_code,
diff --git a/src/tools/clippy/tests/ui/module_inception.rs b/src/tools/clippy/tests/ui/module_inception.rs
index a23aba916..802c3ec39 100644
--- a/src/tools/clippy/tests/ui/module_inception.rs
+++ b/src/tools/clippy/tests/ui/module_inception.rs
@@ -1,5 +1,17 @@
#![warn(clippy::module_inception)]
+pub mod foo2 {
+ pub mod bar2 {
+ pub mod bar2 {
+ pub mod foo2 {}
+ }
+ pub mod foo2 {}
+ }
+ pub mod foo2 {
+ pub mod bar2 {}
+ }
+}
+
mod foo {
mod bar {
mod bar {
diff --git a/src/tools/clippy/tests/ui/module_inception.stderr b/src/tools/clippy/tests/ui/module_inception.stderr
index 77564dce9..ebb8e296f 100644
--- a/src/tools/clippy/tests/ui/module_inception.stderr
+++ b/src/tools/clippy/tests/ui/module_inception.stderr
@@ -1,8 +1,8 @@
error: module has the same name as its containing module
--> $DIR/module_inception.rs:5:9
|
-LL | / mod bar {
-LL | | mod foo {}
+LL | / pub mod bar2 {
+LL | | pub mod foo2 {}
LL | | }
| |_________^
|
@@ -11,10 +11,26 @@ LL | | }
error: module has the same name as its containing module
--> $DIR/module_inception.rs:10:5
|
+LL | / pub mod foo2 {
+LL | | pub mod bar2 {}
+LL | | }
+ | |_____^
+
+error: module has the same name as its containing module
+ --> $DIR/module_inception.rs:17:9
+ |
+LL | / mod bar {
+LL | | mod foo {}
+LL | | }
+ | |_________^
+
+error: module has the same name as its containing module
+ --> $DIR/module_inception.rs:22:5
+ |
LL | / mod foo {
LL | | mod bar {}
LL | | }
| |_____^
-error: aborting due to 2 previous errors
+error: aborting due to 4 previous errors
diff --git a/src/tools/clippy/tests/ui/modulo_one.stderr b/src/tools/clippy/tests/ui/modulo_one.stderr
index 04ecdef5e..83a76f81d 100644
--- a/src/tools/clippy/tests/ui/modulo_one.stderr
+++ b/src/tools/clippy/tests/ui/modulo_one.stderr
@@ -2,7 +2,7 @@ error: this operation will panic at runtime
--> $DIR/modulo_one.rs:11:5
|
LL | i32::MIN % (-1); // also caught by rustc
- | ^^^^^^^^^^^^^^^ attempt to compute the remainder of `i32::MIN % -1_i32`, which would overflow
+ | ^^^^^^^^^^^^^^^ attempt to compute `i32::MIN % -1_i32`, which would overflow
|
= note: `#[deny(unconditional_panic)]` on by default
@@ -10,13 +10,13 @@ error: this operation will panic at runtime
--> $DIR/modulo_one.rs:21:5
|
LL | INT_MIN % NEG_ONE; // also caught by rustc
- | ^^^^^^^^^^^^^^^^^ attempt to compute the remainder of `i64::MIN % -1_i64`, which would overflow
+ | ^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow
error: this operation will panic at runtime
--> $DIR/modulo_one.rs:22:5
|
LL | INT_MIN % STATIC_NEG_ONE; // ONLY caught by rustc
- | ^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute the remainder of `i64::MIN % -1_i64`, which would overflow
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `i64::MIN % -1_i64`, which would overflow
error: any number modulo 1 will be 0
--> $DIR/modulo_one.rs:8:5
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 4ef6f0ca9..23ad36bb4 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
+//@aux-build:proc_macros.rs:proc-macro
#![allow(unused)]
#![allow(deref_nullptr)]
#![allow(clippy::unnecessary_operation)]
diff --git a/src/tools/clippy/tests/ui/must_use_unit.fixed b/src/tools/clippy/tests/ui/must_use_unit.fixed
index 4f7cf4e56..c460fd7c6 100644
--- a/src/tools/clippy/tests/ui/must_use_unit.fixed
+++ b/src/tools/clippy/tests/ui/must_use_unit.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![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 3a814ce16..fe95624f7 100644
--- a/src/tools/clippy/tests/ui/must_use_unit.rs
+++ b/src/tools/clippy/tests/ui/must_use_unit.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::must_use_unit)]
#![allow(clippy::unused_unit)]
diff --git a/src/tools/clippy/tests/ui/mut_mut.rs b/src/tools/clippy/tests/ui/mut_mut.rs
index d838098de..b72134283 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
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::mut_mut)]
#![allow(unused)]
#![allow(clippy::no_effect, clippy::uninlined_format_args, clippy::unnecessary_operation)]
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 00871f9f4..321aa69a1 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,4 +1,7 @@
-//@aux-build:proc_macro_attr.rs
+//@aux-build:proc_macro_attr.rs:proc-macro
+// Flaky test, see https://github.com/rust-lang/rust/issues/113585.
+//@ignore-32bit
+//@ignore-64bit
#![warn(clippy::needless_arbitrary_self_type)]
diff --git a/src/tools/clippy/tests/ui/needless_bool/fixable.fixed b/src/tools/clippy/tests/ui/needless_bool/fixable.fixed
index bf1911881..7d0e55652 100644
--- a/src/tools/clippy/tests/ui/needless_bool/fixable.fixed
+++ b/src/tools/clippy/tests/ui/needless_bool/fixable.fixed
@@ -7,6 +7,7 @@
clippy::no_effect,
clippy::if_same_then_else,
clippy::equatable_if_let,
+ clippy::needless_if,
clippy::needless_return,
clippy::self_named_constructors
)]
diff --git a/src/tools/clippy/tests/ui/needless_bool/fixable.rs b/src/tools/clippy/tests/ui/needless_bool/fixable.rs
index a6c465d4f..88bfe8af7 100644
--- a/src/tools/clippy/tests/ui/needless_bool/fixable.rs
+++ b/src/tools/clippy/tests/ui/needless_bool/fixable.rs
@@ -7,6 +7,7 @@
clippy::no_effect,
clippy::if_same_then_else,
clippy::equatable_if_let,
+ clippy::needless_if,
clippy::needless_return,
clippy::self_named_constructors
)]
diff --git a/src/tools/clippy/tests/ui/needless_bool/fixable.stderr b/src/tools/clippy/tests/ui/needless_bool/fixable.stderr
index fa906374f..1476aea43 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:41:5
+ --> $DIR/fixable.rs:42:5
|
LL | / if x {
LL | | true
@@ -11,7 +11,7 @@ LL | | };
= note: `-D clippy::needless-bool` implied by `-D warnings`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:46:5
+ --> $DIR/fixable.rs:47:5
|
LL | / if x {
LL | | false
@@ -21,7 +21,7 @@ LL | | };
| |_____^ help: you can reduce it to: `!x`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:51:5
+ --> $DIR/fixable.rs:52:5
|
LL | / if x && y {
LL | | false
@@ -31,7 +31,7 @@ LL | | };
| |_____^ help: you can reduce it to: `!(x && y)`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:59:5
+ --> $DIR/fixable.rs:60:5
|
LL | / if a == b {
LL | | false
@@ -41,7 +41,7 @@ LL | | };
| |_____^ help: you can reduce it to: `a != b`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:64:5
+ --> $DIR/fixable.rs:65:5
|
LL | / if a != b {
LL | | false
@@ -51,7 +51,7 @@ LL | | };
| |_____^ help: you can reduce it to: `a == b`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:69:5
+ --> $DIR/fixable.rs:70:5
|
LL | / if a < b {
LL | | false
@@ -61,7 +61,7 @@ LL | | };
| |_____^ help: you can reduce it to: `a >= b`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:74:5
+ --> $DIR/fixable.rs:75:5
|
LL | / if a <= b {
LL | | false
@@ -71,7 +71,7 @@ LL | | };
| |_____^ help: you can reduce it to: `a > b`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:79:5
+ --> $DIR/fixable.rs:80:5
|
LL | / if a > b {
LL | | false
@@ -81,7 +81,7 @@ LL | | };
| |_____^ help: you can reduce it to: `a <= b`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:84:5
+ --> $DIR/fixable.rs:85:5
|
LL | / if a >= b {
LL | | false
@@ -91,7 +91,7 @@ LL | | };
| |_____^ help: you can reduce it to: `a < b`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:112:5
+ --> $DIR/fixable.rs:113:5
|
LL | / if x {
LL | | return true;
@@ -101,7 +101,7 @@ LL | | };
| |_____^ help: you can reduce it to: `return x`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:120:5
+ --> $DIR/fixable.rs:121:5
|
LL | / if x {
LL | | return false;
@@ -111,7 +111,7 @@ LL | | };
| |_____^ help: you can reduce it to: `return !x`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:128:5
+ --> $DIR/fixable.rs:129:5
|
LL | / if x && y {
LL | | return true;
@@ -121,7 +121,7 @@ LL | | };
| |_____^ help: you can reduce it to: `return x && y`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:136:5
+ --> $DIR/fixable.rs:137:5
|
LL | / if x && y {
LL | | return false;
@@ -131,7 +131,7 @@ LL | | };
| |_____^ help: you can reduce it to: `return !(x && y)`
error: equality checks against true are unnecessary
- --> $DIR/fixable.rs:144:8
+ --> $DIR/fixable.rs:145:8
|
LL | if x == true {};
| ^^^^^^^^^ help: try simplifying it as shown: `x`
@@ -139,25 +139,25 @@ LL | if x == true {};
= note: `-D clippy::bool-comparison` implied by `-D warnings`
error: equality checks against false can be replaced by a negation
- --> $DIR/fixable.rs:148:8
+ --> $DIR/fixable.rs:149:8
|
LL | if x == false {};
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
error: equality checks against true are unnecessary
- --> $DIR/fixable.rs:158:8
+ --> $DIR/fixable.rs:159: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:159:8
+ --> $DIR/fixable.rs:160: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:168:12
+ --> $DIR/fixable.rs:169:12
|
LL | } else if returns_bool() {
| ____________^
@@ -168,7 +168,7 @@ LL | | };
| |_____^ help: you can reduce it to: `{ !returns_bool() }`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:181:5
+ --> $DIR/fixable.rs:182:5
|
LL | / if unsafe { no(4) } & 1 != 0 {
LL | | true
@@ -178,13 +178,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:186:30
+ --> $DIR/fixable.rs:187: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:189:9
+ --> $DIR/fixable.rs:190: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_borrow.fixed b/src/tools/clippy/tests/ui/needless_borrow.fixed
index 425e6eb62..1dfbee150 100644
--- a/src/tools/clippy/tests/ui/needless_borrow.fixed
+++ b/src/tools/clippy/tests/ui/needless_borrow.fixed
@@ -4,7 +4,8 @@
unused,
clippy::uninlined_format_args,
clippy::unnecessary_mut_passed,
- clippy::unnecessary_to_owned
+ clippy::unnecessary_to_owned,
+ clippy::unnecessary_literal_unwrap
)]
#![warn(clippy::needless_borrow)]
@@ -491,3 +492,15 @@ mod issue_9782_method_variant {
S.foo::<&[u8; 100]>(&a);
}
}
+
+mod issue_10535 {
+ static SOME_STATIC: String = String::new();
+
+ static UNIT: () = compute(&SOME_STATIC);
+
+ pub const fn compute<T>(_: T)
+ where
+ T: Copy,
+ {
+ }
+}
diff --git a/src/tools/clippy/tests/ui/needless_borrow.rs b/src/tools/clippy/tests/ui/needless_borrow.rs
index 3f7fa4a9d..3c0d73f5f 100644
--- a/src/tools/clippy/tests/ui/needless_borrow.rs
+++ b/src/tools/clippy/tests/ui/needless_borrow.rs
@@ -4,7 +4,8 @@
unused,
clippy::uninlined_format_args,
clippy::unnecessary_mut_passed,
- clippy::unnecessary_to_owned
+ clippy::unnecessary_to_owned,
+ clippy::unnecessary_literal_unwrap
)]
#![warn(clippy::needless_borrow)]
@@ -491,3 +492,15 @@ mod issue_9782_method_variant {
S.foo::<&[u8; 100]>(&a);
}
}
+
+mod issue_10535 {
+ static SOME_STATIC: String = String::new();
+
+ static UNIT: () = compute(&SOME_STATIC);
+
+ pub const fn compute<T>(_: T)
+ where
+ T: Copy,
+ {
+ }
+}
diff --git a/src/tools/clippy/tests/ui/needless_borrow.stderr b/src/tools/clippy/tests/ui/needless_borrow.stderr
index d26c31712..f85b4fb46 100644
--- a/src/tools/clippy/tests/ui/needless_borrow.stderr
+++ b/src/tools/clippy/tests/ui/needless_borrow.stderr
@@ -1,5 +1,5 @@
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:15:15
+ --> $DIR/needless_borrow.rs:16:15
|
LL | let _ = x(&&a); // warn
| ^^^ help: change this to: `&a`
@@ -7,211 +7,211 @@ LL | let _ = x(&&a); // warn
= note: `-D clippy::needless-borrow` implied by `-D warnings`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:19:13
+ --> $DIR/needless_borrow.rs:20:13
|
LL | mut_ref(&mut &mut b); // warn
| ^^^^^^^^^^^ help: change this to: `&mut b`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:31:13
+ --> $DIR/needless_borrow.rs:32:13
|
LL | &&a
| ^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:33:15
+ --> $DIR/needless_borrow.rs:34:15
|
LL | 46 => &&a,
| ^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:39:27
+ --> $DIR/needless_borrow.rs:40:27
|
LL | break &ref_a;
| ^^^^^^ help: change this to: `ref_a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:46:15
+ --> $DIR/needless_borrow.rs:47:15
|
LL | let _ = x(&&&a);
| ^^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:47:15
+ --> $DIR/needless_borrow.rs:48:15
|
LL | let _ = x(&mut &&a);
| ^^^^^^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:48:15
+ --> $DIR/needless_borrow.rs:49:15
|
LL | let _ = x(&&&mut b);
| ^^^^^^^^ help: change this to: `&mut b`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:49:15
+ --> $DIR/needless_borrow.rs:50:15
|
LL | let _ = x(&&ref_a);
| ^^^^^^^ help: change this to: `ref_a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:52:11
+ --> $DIR/needless_borrow.rs:53:11
|
LL | x(&b);
| ^^ help: change this to: `b`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:59:13
+ --> $DIR/needless_borrow.rs:60:13
|
LL | mut_ref(&mut x);
| ^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:60:13
+ --> $DIR/needless_borrow.rs:61:13
|
LL | mut_ref(&mut &mut x);
| ^^^^^^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:61:23
+ --> $DIR/needless_borrow.rs:62:23
|
LL | let y: &mut i32 = &mut x;
| ^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:62:23
+ --> $DIR/needless_borrow.rs:63:23
|
LL | let y: &mut i32 = &mut &mut x;
| ^^^^^^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:71:14
+ --> $DIR/needless_borrow.rs:72:14
|
LL | 0 => &mut x,
| ^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:77:14
+ --> $DIR/needless_borrow.rs:78:14
|
LL | 0 => &mut x,
| ^^^^^^ help: change this to: `x`
error: this expression borrows a value the compiler would automatically borrow
- --> $DIR/needless_borrow.rs:89:13
+ --> $DIR/needless_borrow.rs:90:13
|
LL | let _ = (&x).0;
| ^^^^ help: change this to: `x`
error: this expression borrows a value the compiler would automatically borrow
- --> $DIR/needless_borrow.rs:91:22
+ --> $DIR/needless_borrow.rs:92:22
|
LL | let _ = unsafe { (&*x).0 };
| ^^^^^ help: change this to: `(*x)`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:101:5
+ --> $DIR/needless_borrow.rs:102:5
|
LL | (&&()).foo();
| ^^^^^^ help: change this to: `(&())`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:110:5
+ --> $DIR/needless_borrow.rs:111:5
|
LL | (&&5).foo();
| ^^^^^ help: change this to: `(&5)`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:135:51
+ --> $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:136:44
+ --> $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:137:23
+ --> $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:138:26
+ --> $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:139:45
+ --> $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:140:32
+ --> $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:141:33
+ --> $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:190:13
+ --> $DIR/needless_borrow.rs:191: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:199:13
+ --> $DIR/needless_borrow.rs:200:13
|
LL | (&mut self.f)()
| ^^^^^^^^^^^^^ help: change this to: `(self.f)`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:283:20
+ --> $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:297:55
+ --> $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:335:37
+ --> $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:336:37
+ --> $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:354:15
+ --> $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:363:15
+ --> $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:457:13
+ --> $DIR/needless_borrow.rs:458:13
|
LL | foo(&a);
| ^^ help: change this to: `a`
diff --git a/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed b/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed
index 6663520da..59a38425b 100644
--- a/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed
+++ b/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed
@@ -5,7 +5,8 @@
unused,
irrefutable_let_patterns,
non_shorthand_field_patterns,
- clippy::needless_borrow
+ clippy::needless_borrow,
+ clippy::needless_if
)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui/needless_borrowed_ref.rs b/src/tools/clippy/tests/ui/needless_borrowed_ref.rs
index 6c8efd2ce..e48b19cb1 100644
--- a/src/tools/clippy/tests/ui/needless_borrowed_ref.rs
+++ b/src/tools/clippy/tests/ui/needless_borrowed_ref.rs
@@ -5,7 +5,8 @@
unused,
irrefutable_let_patterns,
non_shorthand_field_patterns,
- clippy::needless_borrow
+ clippy::needless_borrow,
+ clippy::needless_if
)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr b/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr
index 8d0f0c258..35497a01e 100644
--- a/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr
+++ b/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr
@@ -1,5 +1,5 @@
error: this pattern takes a reference on something that is being dereferenced
- --> $DIR/needless_borrowed_ref.rs:31:34
+ --> $DIR/needless_borrowed_ref.rs:32:34
|
LL | let _ = v.iter_mut().filter(|&ref a| a.is_empty());
| ^^^^^^
@@ -12,7 +12,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:35:17
+ --> $DIR/needless_borrowed_ref.rs:36:17
|
LL | if let Some(&ref v) = thingy {}
| ^^^^^^
@@ -24,7 +24,7 @@ LL + if let Some(v) = thingy {}
|
error: this pattern takes a reference on something that is being dereferenced
- --> $DIR/needless_borrowed_ref.rs:37:14
+ --> $DIR/needless_borrowed_ref.rs:38:14
|
LL | if let &[&ref a, ref b] = slice_of_refs {}
| ^^^^^^
@@ -36,7 +36,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:39:9
+ --> $DIR/needless_borrowed_ref.rs:40:9
|
LL | let &[ref a, ..] = &array;
| ^^^^^^^^^^^^
@@ -48,7 +48,7 @@ LL + let [a, ..] = &array;
|
error: dereferencing a slice pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:40:9
+ --> $DIR/needless_borrowed_ref.rs:41:9
|
LL | let &[ref a, ref b, ..] = &array;
| ^^^^^^^^^^^^^^^^^^^
@@ -60,7 +60,7 @@ LL + let [a, b, ..] = &array;
|
error: dereferencing a slice pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:42:12
+ --> $DIR/needless_borrowed_ref.rs:43:12
|
LL | if let &[ref a, ref b] = slice {}
| ^^^^^^^^^^^^^^^
@@ -72,7 +72,7 @@ LL + if let [a, b] = slice {}
|
error: dereferencing a slice pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:43:12
+ --> $DIR/needless_borrowed_ref.rs:44:12
|
LL | if let &[ref a, ref b] = &vec[..] {}
| ^^^^^^^^^^^^^^^
@@ -84,7 +84,7 @@ LL + if let [a, b] = &vec[..] {}
|
error: dereferencing a slice pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:45:12
+ --> $DIR/needless_borrowed_ref.rs:46:12
|
LL | if let &[ref a, ref b, ..] = slice {}
| ^^^^^^^^^^^^^^^^^^^
@@ -96,7 +96,7 @@ LL + if let [a, b, ..] = slice {}
|
error: dereferencing a slice pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:46:12
+ --> $DIR/needless_borrowed_ref.rs:47:12
|
LL | if let &[ref a, .., ref b] = slice {}
| ^^^^^^^^^^^^^^^^^^^
@@ -108,7 +108,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:48:12
|
LL | if let &[.., ref a, ref b] = slice {}
| ^^^^^^^^^^^^^^^^^^^
@@ -120,7 +120,7 @@ LL + if let [.., a, b] = slice {}
|
error: dereferencing a slice pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:49:12
+ --> $DIR/needless_borrowed_ref.rs:50:12
|
LL | if let &[ref a, _] = slice {}
| ^^^^^^^^^^^
@@ -132,7 +132,7 @@ LL + if let [a, _] = slice {}
|
error: dereferencing a tuple pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:51:12
+ --> $DIR/needless_borrowed_ref.rs:52:12
|
LL | if let &(ref a, ref b, ref c) = &tuple {}
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -144,7 +144,7 @@ LL + if let (a, b, c) = &tuple {}
|
error: dereferencing a tuple pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:52:12
+ --> $DIR/needless_borrowed_ref.rs:53:12
|
LL | if let &(ref a, _, ref c) = &tuple {}
| ^^^^^^^^^^^^^^^^^^
@@ -156,7 +156,7 @@ LL + if let (a, _, 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:54:12
|
LL | if let &(ref a, ..) = &tuple {}
| ^^^^^^^^^^^^
@@ -168,7 +168,7 @@ LL + if let (a, ..) = &tuple {}
|
error: dereferencing a tuple pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:55:12
+ --> $DIR/needless_borrowed_ref.rs:56:12
|
LL | if let &TupleStruct(ref a, ..) = &tuple_struct {}
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -180,7 +180,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:57:12
+ --> $DIR/needless_borrowed_ref.rs:58:12
|
LL | if let &Struct {
| ____________^
@@ -199,7 +199,7 @@ LL ~ c: renamed,
|
error: dereferencing a struct pattern where every field's pattern takes a reference
- --> $DIR/needless_borrowed_ref.rs:64:12
+ --> $DIR/needless_borrowed_ref.rs:65:12
|
LL | if let &Struct { ref a, b: _, .. } = &s {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/needless_collect.fixed b/src/tools/clippy/tests/ui/needless_collect.fixed
index b7e80af50..0f0aaad17 100644
--- a/src/tools/clippy/tests/ui/needless_collect.fixed
+++ b/src/tools/clippy/tests/ui/needless_collect.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
-#![allow(unused, clippy::suspicious_map, clippy::iter_count)]
+#![allow(unused, clippy::needless_if, clippy::suspicious_map, clippy::iter_count)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList};
@@ -70,6 +70,11 @@ fn main() {
bar((0..10).collect::<Vec<_>>(), (0..10));
baz((0..10), (), ('a'..='z'))
}
+
+ let values = [1, 2, 3, 4];
+ let mut out = vec![];
+ values.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>();
+ let _y = values.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>(); // this is fine
}
fn foo(_: impl IntoIterator<Item = usize>) {}
diff --git a/src/tools/clippy/tests/ui/needless_collect.rs b/src/tools/clippy/tests/ui/needless_collect.rs
index 680b6fa5b..4f48f24b1 100644
--- a/src/tools/clippy/tests/ui/needless_collect.rs
+++ b/src/tools/clippy/tests/ui/needless_collect.rs
@@ -1,6 +1,6 @@
//@run-rustfix
-#![allow(unused, clippy::suspicious_map, clippy::iter_count)]
+#![allow(unused, clippy::needless_if, clippy::suspicious_map, clippy::iter_count)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList};
@@ -70,6 +70,11 @@ fn main() {
bar((0..10).collect::<Vec<_>>(), (0..10).collect::<Vec<_>>());
baz((0..10), (), ('a'..='z').collect::<Vec<_>>())
}
+
+ let values = [1, 2, 3, 4];
+ let mut out = vec![];
+ values.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>();
+ let _y = values.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>(); // this is fine
}
fn foo(_: impl IntoIterator<Item = usize>) {}
diff --git a/src/tools/clippy/tests/ui/needless_collect_indirect.rs b/src/tools/clippy/tests/ui/needless_collect_indirect.rs
index fe4209e99..d3d856c2c 100644
--- a/src/tools/clippy/tests/ui/needless_collect_indirect.rs
+++ b/src/tools/clippy/tests/ui/needless_collect_indirect.rs
@@ -1,4 +1,5 @@
-#![allow(clippy::uninlined_format_args)]
+#![allow(clippy::uninlined_format_args, clippy::useless_vec)]
+#![allow(clippy::needless_if, clippy::uninlined_format_args)]
#![warn(clippy::needless_collect)]
use std::collections::{BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
diff --git a/src/tools/clippy/tests/ui/needless_collect_indirect.stderr b/src/tools/clippy/tests/ui/needless_collect_indirect.stderr
index 790d72590..8f84c5596 100644
--- a/src/tools/clippy/tests/ui/needless_collect_indirect.stderr
+++ b/src/tools/clippy/tests/ui/needless_collect_indirect.stderr
@@ -1,5 +1,5 @@
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:8:39
+ --> $DIR/needless_collect_indirect.rs:9:39
|
LL | let indirect_iter = sample.iter().collect::<Vec<_>>();
| ^^^^^^^
@@ -14,7 +14,7 @@ LL ~ sample.iter().map(|x| (x, x + 1)).collect::<HashMap<_, _>>();
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:10:38
+ --> $DIR/needless_collect_indirect.rs:11:38
|
LL | let indirect_len = sample.iter().collect::<VecDeque<_>>();
| ^^^^^^^
@@ -28,7 +28,7 @@ LL ~ sample.iter().count();
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:12:40
+ --> $DIR/needless_collect_indirect.rs:13:40
|
LL | let indirect_empty = sample.iter().collect::<VecDeque<_>>();
| ^^^^^^^
@@ -42,7 +42,7 @@ LL ~ sample.iter().next().is_none();
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:14:43
+ --> $DIR/needless_collect_indirect.rs:15:43
|
LL | let indirect_contains = sample.iter().collect::<VecDeque<_>>();
| ^^^^^^^
@@ -56,7 +56,7 @@ LL ~ sample.iter().any(|x| x == &5);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:26:48
+ --> $DIR/needless_collect_indirect.rs:27:48
|
LL | let non_copy_contains = sample.into_iter().collect::<Vec<_>>();
| ^^^^^^^
@@ -70,7 +70,7 @@ LL ~ sample.into_iter().any(|x| x == a);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:55:51
+ --> $DIR/needless_collect_indirect.rs:56:51
|
LL | let buffer: Vec<&str> = string.split('/').collect();
| ^^^^^^^
@@ -84,7 +84,7 @@ LL ~ string.split('/').count()
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:60:55
+ --> $DIR/needless_collect_indirect.rs:61:55
|
LL | let indirect_len: VecDeque<_> = sample.iter().collect();
| ^^^^^^^
@@ -98,7 +98,7 @@ LL ~ sample.iter().count()
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:65:57
+ --> $DIR/needless_collect_indirect.rs:66:57
|
LL | let indirect_len: LinkedList<_> = sample.iter().collect();
| ^^^^^^^
@@ -112,7 +112,7 @@ LL ~ sample.iter().count()
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:70:57
+ --> $DIR/needless_collect_indirect.rs:71:57
|
LL | let indirect_len: BinaryHeap<_> = sample.iter().collect();
| ^^^^^^^
@@ -126,7 +126,7 @@ LL ~ sample.iter().count()
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:130:59
+ --> $DIR/needless_collect_indirect.rs:131:59
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
@@ -143,7 +143,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == i);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:155:59
+ --> $DIR/needless_collect_indirect.rs:156:59
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
@@ -160,7 +160,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:184:63
+ --> $DIR/needless_collect_indirect.rs:185:63
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
@@ -177,7 +177,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:220:59
+ --> $DIR/needless_collect_indirect.rs:221:59
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
@@ -195,7 +195,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:245:26
+ --> $DIR/needless_collect_indirect.rs:246:26
|
LL | let w = v.iter().collect::<Vec<_>>();
| ^^^^^^^
@@ -211,7 +211,7 @@ LL ~ for _ in 0..v.iter().count() {
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:267:30
+ --> $DIR/needless_collect_indirect.rs:268:30
|
LL | let mut w = v.iter().collect::<Vec<_>>();
| ^^^^^^^
@@ -227,7 +227,7 @@ LL ~ while 1 == v.iter().count() {
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:289:30
+ --> $DIR/needless_collect_indirect.rs:290:30
|
LL | let mut w = v.iter().collect::<Vec<_>>();
| ^^^^^^^
diff --git a/src/tools/clippy/tests/ui/needless_else.fixed b/src/tools/clippy/tests/ui/needless_else.fixed
new file mode 100644
index 000000000..06a161627
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_else.fixed
@@ -0,0 +1,57 @@
+//@run-rustfix
+#![allow(unused)]
+#![warn(clippy::needless_else)]
+#![allow(clippy::suspicious_else_formatting)]
+
+macro_rules! mac {
+ ($test:expr) => {
+ if $test {
+ println!("Test successful!");
+ } else {
+ }
+ };
+}
+
+macro_rules! empty_expansion {
+ () => {};
+}
+
+fn main() {
+ let b = std::hint::black_box(true);
+
+ if b {
+ println!("Foobar");
+ }
+
+ if b {
+ println!("Foobar");
+ } else {
+ // Do not lint because this comment might be important
+ }
+
+ if b {
+ println!("Foobar");
+ } else
+ /* Do not lint because this comment might be important */
+ {
+ }
+
+ // Do not lint because of the expression
+ let _ = if b { 1 } else { 2 };
+
+ // Do not lint because inside a macro
+ mac!(b);
+
+ if b {
+ println!("Foobar");
+ } else {
+ #[cfg(foo)]
+ "Do not lint cfg'd out code"
+ }
+
+ if b {
+ println!("Foobar");
+ } else {
+ empty_expansion!();
+ }
+}
diff --git a/src/tools/clippy/tests/ui/needless_else.rs b/src/tools/clippy/tests/ui/needless_else.rs
new file mode 100644
index 000000000..728032c47
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_else.rs
@@ -0,0 +1,58 @@
+//@run-rustfix
+#![allow(unused)]
+#![warn(clippy::needless_else)]
+#![allow(clippy::suspicious_else_formatting)]
+
+macro_rules! mac {
+ ($test:expr) => {
+ if $test {
+ println!("Test successful!");
+ } else {
+ }
+ };
+}
+
+macro_rules! empty_expansion {
+ () => {};
+}
+
+fn main() {
+ let b = std::hint::black_box(true);
+
+ if b {
+ println!("Foobar");
+ } else {
+ }
+
+ if b {
+ println!("Foobar");
+ } else {
+ // Do not lint because this comment might be important
+ }
+
+ if b {
+ println!("Foobar");
+ } else
+ /* Do not lint because this comment might be important */
+ {
+ }
+
+ // Do not lint because of the expression
+ let _ = if b { 1 } else { 2 };
+
+ // Do not lint because inside a macro
+ mac!(b);
+
+ if b {
+ println!("Foobar");
+ } else {
+ #[cfg(foo)]
+ "Do not lint cfg'd out code"
+ }
+
+ if b {
+ println!("Foobar");
+ } else {
+ empty_expansion!();
+ }
+}
diff --git a/src/tools/clippy/tests/ui/needless_else.stderr b/src/tools/clippy/tests/ui/needless_else.stderr
new file mode 100644
index 000000000..ea6930851
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_else.stderr
@@ -0,0 +1,12 @@
+error: this else branch is empty
+ --> $DIR/needless_else.rs:24:7
+ |
+LL | } else {
+ | _______^
+LL | | }
+ | |_____^ help: you can remove it
+ |
+ = note: `-D clippy::needless-else` implied by `-D warnings`
+
+error: aborting due to previous error
+
diff --git a/src/tools/clippy/tests/ui/needless_if.fixed b/src/tools/clippy/tests/ui/needless_if.fixed
new file mode 100644
index 000000000..5e6e140c2
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_if.fixed
@@ -0,0 +1,93 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![feature(let_chains)]
+#![allow(
+ clippy::blocks_in_if_conditions,
+ clippy::if_same_then_else,
+ clippy::ifs_same_cond,
+ clippy::let_unit_value,
+ clippy::needless_else,
+ clippy::no_effect,
+ clippy::nonminimal_bool,
+ clippy::short_circuit_statement,
+ clippy::unnecessary_operation,
+ unused
+)]
+#![warn(clippy::needless_if)]
+
+extern crate proc_macros;
+use proc_macros::external;
+use proc_macros::with_span;
+
+fn maybe_side_effect() -> bool {
+ true
+}
+
+fn main() {
+ // Lint
+
+ // Do not remove the condition
+ maybe_side_effect();
+ // Do not lint
+ if (true) {
+ } else {
+ }
+ ({
+ return;
+ });
+ // Do not lint if `else if` is present
+ if (true) {
+ } else if (true) {
+ }
+ // Do not lint `if let` or let chains
+ if let true = true {}
+ if let true = true && true {}
+ if true && let true = true {}
+ // Can lint nested `if let`s
+ ({
+ if let true = true && true { true } else { false }
+ } && true);
+ external! { if (true) {} }
+ with_span! {
+ span
+ if (true) {}
+ }
+
+ if true {
+ // comment
+ }
+
+ if true {
+ #[cfg(any())]
+ foo;
+ }
+
+ macro_rules! empty_expansion {
+ () => {};
+ }
+
+ if true {
+ empty_expansion!();
+ }
+
+ macro_rules! empty_repetition {
+ ($($t:tt)*) => {
+ if true {
+ $($t)*
+ }
+ }
+ }
+
+ empty_repetition!();
+
+ // Must be placed into an expression context to not be interpreted as a block
+ ({ maybe_side_effect() });
+ // Would be a block followed by `&&true` - a double reference to `true`
+ ({ maybe_side_effect() } && true);
+
+ // Don't leave trailing attributes
+ #[allow(unused)]
+ true;
+
+ let () = if maybe_side_effect() {};
+}
diff --git a/src/tools/clippy/tests/ui/needless_if.rs b/src/tools/clippy/tests/ui/needless_if.rs
new file mode 100644
index 000000000..eb28ce73b
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_if.rs
@@ -0,0 +1,94 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![feature(let_chains)]
+#![allow(
+ clippy::blocks_in_if_conditions,
+ clippy::if_same_then_else,
+ clippy::ifs_same_cond,
+ clippy::let_unit_value,
+ clippy::needless_else,
+ clippy::no_effect,
+ clippy::nonminimal_bool,
+ clippy::short_circuit_statement,
+ clippy::unnecessary_operation,
+ unused
+)]
+#![warn(clippy::needless_if)]
+
+extern crate proc_macros;
+use proc_macros::external;
+use proc_macros::with_span;
+
+fn maybe_side_effect() -> bool {
+ true
+}
+
+fn main() {
+ // Lint
+ if (true) {}
+ // Do not remove the condition
+ if maybe_side_effect() {}
+ // Do not lint
+ if (true) {
+ } else {
+ }
+ if {
+ return;
+ } {}
+ // Do not lint if `else if` is present
+ if (true) {
+ } else if (true) {
+ }
+ // Do not lint `if let` or let chains
+ if let true = true {}
+ if let true = true && true {}
+ if true && let true = true {}
+ // Can lint nested `if let`s
+ if {
+ if let true = true && true { true } else { false }
+ } && true
+ {}
+ external! { if (true) {} }
+ with_span! {
+ span
+ if (true) {}
+ }
+
+ if true {
+ // comment
+ }
+
+ if true {
+ #[cfg(any())]
+ foo;
+ }
+
+ macro_rules! empty_expansion {
+ () => {};
+ }
+
+ if true {
+ empty_expansion!();
+ }
+
+ macro_rules! empty_repetition {
+ ($($t:tt)*) => {
+ if true {
+ $($t)*
+ }
+ }
+ }
+
+ empty_repetition!();
+
+ // Must be placed into an expression context to not be interpreted as a block
+ if { maybe_side_effect() } {}
+ // Would be a block followed by `&&true` - a double reference to `true`
+ if { maybe_side_effect() } && true {}
+
+ // Don't leave trailing attributes
+ #[allow(unused)]
+ if true {}
+
+ let () = if maybe_side_effect() {};
+}
diff --git a/src/tools/clippy/tests/ui/needless_if.stderr b/src/tools/clippy/tests/ui/needless_if.stderr
new file mode 100644
index 000000000..5cb42c369
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_if.stderr
@@ -0,0 +1,65 @@
+error: this `if` branch is empty
+ --> $DIR/needless_if.rs:28:5
+ |
+LL | if (true) {}
+ | ^^^^^^^^^^^^ help: you can remove it
+ |
+ = note: `-D clippy::needless-if` implied by `-D warnings`
+
+error: this `if` branch is empty
+ --> $DIR/needless_if.rs:30:5
+ |
+LL | if maybe_side_effect() {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `maybe_side_effect();`
+
+error: this `if` branch is empty
+ --> $DIR/needless_if.rs:35:5
+ |
+LL | / if {
+LL | | return;
+LL | | } {}
+ | |________^
+ |
+help: you can remove it
+ |
+LL ~ ({
+LL + return;
+LL + });
+ |
+
+error: this `if` branch is empty
+ --> $DIR/needless_if.rs:47:5
+ |
+LL | / if {
+LL | | if let true = true && true { true } else { false }
+LL | | } && true
+LL | | {}
+ | |______^
+ |
+help: you can remove it
+ |
+LL ~ ({
+LL + if let true = true && true { true } else { false }
+LL + } && true);
+ |
+
+error: this `if` branch is empty
+ --> $DIR/needless_if.rs:85:5
+ |
+LL | if { maybe_side_effect() } {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `({ maybe_side_effect() });`
+
+error: this `if` branch is empty
+ --> $DIR/needless_if.rs:87: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:91:5
+ |
+LL | if true {}
+ | ^^^^^^^^^^ help: you can remove it: `true;`
+
+error: aborting due to 7 previous errors
+
diff --git a/src/tools/clippy/tests/ui/needless_late_init.fixed b/src/tools/clippy/tests/ui/needless_late_init.fixed
index 92f7b3f77..933dd8bed 100644
--- a/src/tools/clippy/tests/ui/needless_late_init.fixed
+++ b/src/tools/clippy/tests/ui/needless_late_init.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![feature(let_chains)]
#![allow(unused)]
#![allow(
@@ -8,7 +8,8 @@
clippy::let_and_return,
clippy::let_unit_value,
clippy::nonminimal_bool,
- clippy::uninlined_format_args
+ clippy::uninlined_format_args,
+ clippy::useless_vec
)]
extern crate proc_macros;
diff --git a/src/tools/clippy/tests/ui/needless_late_init.rs b/src/tools/clippy/tests/ui/needless_late_init.rs
index be378c42f..ba3a04e08 100644
--- a/src/tools/clippy/tests/ui/needless_late_init.rs
+++ b/src/tools/clippy/tests/ui/needless_late_init.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![feature(let_chains)]
#![allow(unused)]
#![allow(
@@ -8,7 +8,8 @@
clippy::let_and_return,
clippy::let_unit_value,
clippy::nonminimal_bool,
- clippy::uninlined_format_args
+ clippy::uninlined_format_args,
+ clippy::useless_vec
)]
extern crate proc_macros;
diff --git a/src/tools/clippy/tests/ui/needless_late_init.stderr b/src/tools/clippy/tests/ui/needless_late_init.stderr
index eff782f8b..78ba8e11c 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:27:5
+ --> $DIR/needless_late_init.rs:28:5
|
LL | let a;
| ^^^^^^ created here
@@ -13,7 +13,7 @@ LL | let a = "zero";
| ~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:30:5
+ --> $DIR/needless_late_init.rs:31:5
|
LL | let b;
| ^^^^^^ created here
@@ -27,7 +27,7 @@ LL | let b = 1;
| ~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:31:5
+ --> $DIR/needless_late_init.rs:32:5
|
LL | let c;
| ^^^^^^ created here
@@ -41,7 +41,7 @@ LL | let c = 2;
| ~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:35:5
+ --> $DIR/needless_late_init.rs:36:5
|
LL | let d: usize;
| ^^^^^^^^^^^^^ created here
@@ -54,7 +54,7 @@ LL | let d: usize = 1;
| ~~~~~~~~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:38:5
+ --> $DIR/needless_late_init.rs:39:5
|
LL | let e;
| ^^^^^^ created here
@@ -67,7 +67,7 @@ LL | let e = format!("{}", d);
| ~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:43:5
+ --> $DIR/needless_late_init.rs:44:5
|
LL | let a;
| ^^^^^^
@@ -88,7 +88,7 @@ LL | };
| +
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:52:5
+ --> $DIR/needless_late_init.rs:53:5
|
LL | let b;
| ^^^^^^
@@ -109,7 +109,7 @@ LL | };
| +
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:59:5
+ --> $DIR/needless_late_init.rs:60:5
|
LL | let d;
| ^^^^^^
@@ -130,7 +130,7 @@ LL | };
| +
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:67:5
+ --> $DIR/needless_late_init.rs:68:5
|
LL | let e;
| ^^^^^^
@@ -151,7 +151,7 @@ LL | };
| +
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:74:5
+ --> $DIR/needless_late_init.rs:75:5
|
LL | let f;
| ^^^^^^
@@ -167,7 +167,7 @@ LL + 1 => "three",
|
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:80:5
+ --> $DIR/needless_late_init.rs:81:5
|
LL | let g: usize;
| ^^^^^^^^^^^^^
@@ -187,7 +187,7 @@ LL | };
| +
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:88:5
+ --> $DIR/needless_late_init.rs:89:5
|
LL | let x;
| ^^^^^^ created here
@@ -201,7 +201,7 @@ LL | let x = 1;
| ~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:92:5
+ --> $DIR/needless_late_init.rs:93:5
|
LL | let x;
| ^^^^^^ created here
@@ -215,7 +215,7 @@ LL | let x = SignificantDrop;
| ~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:96:5
+ --> $DIR/needless_late_init.rs:97:5
|
LL | let x;
| ^^^^^^ created here
@@ -229,7 +229,7 @@ LL | let x = SignificantDrop;
| ~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:115:5
+ --> $DIR/needless_late_init.rs:116:5
|
LL | let a;
| ^^^^^^
@@ -250,7 +250,7 @@ LL | };
| +
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:132:5
+ --> $DIR/needless_late_init.rs:133: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 7b99042f7..302a3f9ed 100644
--- a/src/tools/clippy/tests/ui/needless_lifetimes.fixed
+++ b/src/tools/clippy/tests/ui/needless_lifetimes.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![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 6fcf1efc2..b15477c92 100644
--- a/src/tools/clippy/tests/ui/needless_lifetimes.rs
+++ b/src/tools/clippy/tests/ui/needless_lifetimes.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![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 86acc4e00..0da67b600 100644
--- a/src/tools/clippy/tests/ui/needless_lifetimes.stderr
+++ b/src/tools/clippy/tests/ui/needless_lifetimes.stderr
@@ -1,8 +1,8 @@
error: the following explicit lifetimes could be elided: 'a, 'b
- --> $DIR/needless_lifetimes.rs:18:1
+ --> $DIR/needless_lifetimes.rs:18: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: elide the lifetimes
@@ -12,10 +12,10 @@ 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:1
+ --> $DIR/needless_lifetimes.rs:20:24
|
LL | fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {}
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -24,10 +24,10 @@ 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:1
+ --> $DIR/needless_lifetimes.rs:30:15
|
LL | fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -36,10 +36,10 @@ LL + fn in_and_out(x: &u8, _y: u8) -> &u8 {
|
error: the following explicit lifetimes could be elided: 'b
- --> $DIR/needless_lifetimes.rs:42:1
+ --> $DIR/needless_lifetimes.rs:42:31
|
LL | fn multiple_in_and_out_2a<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -48,10 +48,10 @@ 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:1
+ --> $DIR/needless_lifetimes.rs:49:27
|
LL | fn multiple_in_and_out_2b<'a, 'b>(_x: &'a u8, y: &'b u8) -> &'b u8 {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -60,10 +60,10 @@ 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:1
+ --> $DIR/needless_lifetimes.rs:66:26
|
LL | fn deep_reference_1a<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -72,10 +72,10 @@ 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:1
+ --> $DIR/needless_lifetimes.rs:73:22
|
LL | fn deep_reference_1b<'a, 'b>(_x: &'a u8, y: &'b u8) -> Result<&'b u8, ()> {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -84,10 +84,10 @@ 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:1
+ --> $DIR/needless_lifetimes.rs:82:21
|
LL | fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -96,10 +96,10 @@ 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:1
+ --> $DIR/needless_lifetimes.rs:87:28
|
LL | fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()>
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -108,10 +108,10 @@ LL + fn where_clause_without_lt<T>(x: &u8, _y: u8) -> Result<&u8, ()>
|
error: the following explicit lifetimes could be elided: 'a, 'b
- --> $DIR/needless_lifetimes.rs:99:1
+ --> $DIR/needless_lifetimes.rs:99:21
|
LL | fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {}
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -120,10 +120,10 @@ LL + fn lifetime_param_2(_x: Ref<'_>, _y: &u8) {}
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:123:1
+ --> $DIR/needless_lifetimes.rs:123:15
|
LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -132,10 +132,10 @@ LL + fn fn_bound_2<F, I>(_m: Lt<'_, I>, _f: F) -> Lt<'_, I>
|
error: the following explicit lifetimes could be elided: 's
- --> $DIR/needless_lifetimes.rs:153:5
+ --> $DIR/needless_lifetimes.rs:153:21
|
LL | fn self_and_out<'s>(&'s self) -> &'s u8 {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -144,10 +144,10 @@ LL + fn self_and_out(&self) -> &u8 {
|
error: the following explicit lifetimes could be elided: 't
- --> $DIR/needless_lifetimes.rs:160:5
+ --> $DIR/needless_lifetimes.rs:160:30
|
LL | fn self_and_in_out_1<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -156,10 +156,10 @@ 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:5
+ --> $DIR/needless_lifetimes.rs:167:26
|
LL | fn self_and_in_out_2<'s, 't>(&'s self, x: &'t u8) -> &'t u8 {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -168,10 +168,10 @@ 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:5
+ --> $DIR/needless_lifetimes.rs:171:29
|
LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {}
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -180,10 +180,10 @@ LL + fn distinct_self_and_in(&self, _x: &u8) {}
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:190:1
+ --> $DIR/needless_lifetimes.rs:190:19
|
LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -192,10 +192,10 @@ LL + fn struct_with_lt(_foo: Foo<'_>) -> &str {
|
error: the following explicit lifetimes could be elided: 'b
- --> $DIR/needless_lifetimes.rs:208:1
+ --> $DIR/needless_lifetimes.rs:208:25
|
LL | fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -204,10 +204,10 @@ 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:1
+ --> $DIR/needless_lifetimes.rs:216:21
|
LL | fn struct_with_lt4b<'a, 'b>(_foo: &'a Foo<'b>) -> &'b str {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -216,10 +216,10 @@ 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:1
+ --> $DIR/needless_lifetimes.rs:231:22
|
LL | fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -228,10 +228,10 @@ LL + fn trait_obj_elided2(_arg: &dyn Drop) -> &str {
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:237:1
+ --> $DIR/needless_lifetimes.rs:237:18
|
LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -240,10 +240,10 @@ LL + fn alias_with_lt(_foo: FooAlias<'_>) -> &str {
|
error: the following explicit lifetimes could be elided: 'b
- --> $DIR/needless_lifetimes.rs:255:1
+ --> $DIR/needless_lifetimes.rs:255:24
|
LL | fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -252,10 +252,10 @@ 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:1
+ --> $DIR/needless_lifetimes.rs:263:20
|
LL | fn alias_with_lt4b<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'b str {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -264,10 +264,10 @@ 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:1
+ --> $DIR/needless_lifetimes.rs:267:30
|
LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^
|
help: elide the lifetimes
|
@@ -276,10 +276,10 @@ LL + fn named_input_elided_output(_arg: &str) -> &str {
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:275:1
+ --> $DIR/needless_lifetimes.rs:275:19
|
LL | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -288,10 +288,10 @@ LL + fn trait_bound_ok<T: WithLifetime<'static>>(_: &u8, _: T) {
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:311:1
+ --> $DIR/needless_lifetimes.rs:311:24
|
LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -300,10 +300,10 @@ LL + fn out_return_type_lts(e: &str) -> Cow<'_> {
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:318:9
+ --> $DIR/needless_lifetimes.rs:318:24
|
LL | fn needless_lt<'a>(x: &'a u8) {}
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -312,10 +312,10 @@ LL + fn needless_lt(x: &u8) {}
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:322:9
+ --> $DIR/needless_lifetimes.rs:322:24
|
LL | fn needless_lt<'a>(_x: &'a u8) {}
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -324,10 +324,10 @@ LL + fn needless_lt(_x: &u8) {}
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:335:9
+ --> $DIR/needless_lifetimes.rs:335:16
|
LL | fn baz<'a>(&'a self) -> impl Foo + 'a {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -336,10 +336,10 @@ LL + fn baz(&self) -> impl Foo + '_ {
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:367:5
+ --> $DIR/needless_lifetimes.rs:367:55
|
LL | fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -348,10 +348,10 @@ 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:5
+ --> $DIR/needless_lifetimes.rs:376:26
|
LL | fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -360,10 +360,10 @@ LL + fn generics_elidable<T: Fn(&i32) -> &i32>(i: &i32, f: T) -> &i32 {
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:388:5
+ --> $DIR/needless_lifetimes.rs:388:32
|
LL | fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -372,10 +372,10 @@ LL + fn where_clause_elidadable<T>(i: &i32, f: T) -> &i32
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:403:5
+ --> $DIR/needless_lifetimes.rs:403:28
|
LL | fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -384,10 +384,10 @@ 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:5
+ --> $DIR/needless_lifetimes.rs:416:28
|
LL | fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -396,10 +396,10 @@ 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:5
+ --> $DIR/needless_lifetimes.rs:419:28
|
LL | fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -408,10 +408,10 @@ 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:9
+ --> $DIR/needless_lifetimes.rs:441:21
|
LL | fn implicit<'a>(&'a self) -> &'a () {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -420,10 +420,10 @@ LL + fn implicit(&self) -> &() {
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:444:9
+ --> $DIR/needless_lifetimes.rs:444:25
|
LL | fn implicit_mut<'a>(&'a mut self) -> &'a () {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -432,10 +432,10 @@ LL + fn implicit_mut(&mut self) -> &() {
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:455:9
+ --> $DIR/needless_lifetimes.rs:455:31
|
LL | fn lifetime_elsewhere<'a>(self: Box<Self>, here: &'a ()) -> &'a () {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -444,10 +444,10 @@ LL + fn lifetime_elsewhere(self: Box<Self>, here: &()) -> &() {
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:461:9
+ --> $DIR/needless_lifetimes.rs:461:21
|
LL | fn implicit<'a>(&'a self) -> &'a ();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -456,10 +456,10 @@ LL + fn implicit(&self) -> &();
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:462:9
+ --> $DIR/needless_lifetimes.rs:462:30
|
LL | fn implicit_provided<'a>(&'a self) -> &'a () {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -468,10 +468,10 @@ LL + fn implicit_provided(&self) -> &() {
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:471:9
+ --> $DIR/needless_lifetimes.rs:471:31
|
LL | fn lifetime_elsewhere<'a>(self: Box<Self>, here: &'a ()) -> &'a ();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -480,10 +480,10 @@ LL + fn lifetime_elsewhere(self: Box<Self>, here: &()) -> &();
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:472:9
+ --> $DIR/needless_lifetimes.rs:472:40
|
LL | fn lifetime_elsewhere_provided<'a>(self: Box<Self>, here: &'a ()) -> &'a () {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -492,10 +492,10 @@ LL + fn lifetime_elsewhere_provided(self: Box<Self>, here: &()) -> &() {
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:481:5
+ --> $DIR/needless_lifetimes.rs:481:12
|
LL | fn foo<'a>(x: &'a u8, y: &'_ u8) {}
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -504,10 +504,10 @@ LL + fn foo(x: &u8, y: &'_ u8) {}
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:483:5
+ --> $DIR/needless_lifetimes.rs:483:12
|
LL | fn bar<'a>(x: &'a u8, y: &'_ u8, z: &'_ u8) {}
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -516,10 +516,10 @@ LL + fn bar(x: &u8, y: &'_ u8, z: &'_ u8) {}
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:490:5
+ --> $DIR/needless_lifetimes.rs:490:18
|
LL | fn one_input<'a>(x: &'a u8) -> &'a u8 {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
help: elide the lifetimes
|
@@ -528,10 +528,10 @@ LL + fn one_input(x: &u8) -> &u8 {
|
error: the following explicit lifetimes could be elided: 'a
- --> $DIR/needless_lifetimes.rs:495:5
+ --> $DIR/needless_lifetimes.rs:495:42
|
LL | fn multiple_inputs_output_not_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'b u8 {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^
|
help: elide the lifetimes
|
@@ -540,10 +540,10 @@ 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:9
+ --> $DIR/needless_lifetimes.rs:511:22
|
LL | fn one_input<'a>(x: &'a u8) -> &'a u8 {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^ ^^ ^^
|
= note: this error originates in the macro `__inline_mac_mod_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
help: elide the lifetimes
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 70015fccf..ec981ad97 100644
--- a/src/tools/clippy/tests/ui/needless_option_as_deref.fixed
+++ b/src/tools/clippy/tests/ui/needless_option_as_deref.fixed
@@ -2,6 +2,7 @@
#![allow(unused)]
#![warn(clippy::needless_option_as_deref)]
+#![allow(clippy::useless_vec)]
fn main() {
// should lint
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 e2e35360c..6360874f6 100644
--- a/src/tools/clippy/tests/ui/needless_option_as_deref.rs
+++ b/src/tools/clippy/tests/ui/needless_option_as_deref.rs
@@ -2,6 +2,7 @@
#![allow(unused)]
#![warn(clippy::needless_option_as_deref)]
+#![allow(clippy::useless_vec)]
fn main() {
// should lint
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 bc07db5b3..20d28a968 100644
--- a/src/tools/clippy/tests/ui/needless_option_as_deref.stderr
+++ b/src/tools/clippy/tests/ui/needless_option_as_deref.stderr
@@ -1,5 +1,5 @@
error: derefed type is same as origin
- --> $DIR/needless_option_as_deref.rs:8:29
+ --> $DIR/needless_option_as_deref.rs:9:29
|
LL | let _: Option<&usize> = Some(&1).as_deref();
| ^^^^^^^^^^^^^^^^^^^ help: try this: `Some(&1)`
@@ -7,13 +7,13 @@ LL | let _: Option<&usize> = Some(&1).as_deref();
= note: `-D clippy::needless-option-as-deref` implied by `-D warnings`
error: derefed type is same as origin
- --> $DIR/needless_option_as_deref.rs:9:33
+ --> $DIR/needless_option_as_deref.rs:10:33
|
LL | let _: Option<&mut usize> = Some(&mut 1).as_deref_mut();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `Some(&mut 1)`
error: derefed type is same as origin
- --> $DIR/needless_option_as_deref.rs:13:13
+ --> $DIR/needless_option_as_deref.rs:14:13
|
LL | let _ = x.as_deref_mut();
| ^^^^^^^^^^^^^^^^ help: try this: `x`
diff --git a/src/tools/clippy/tests/ui/needless_pass_by_value_proc_macro.rs b/src/tools/clippy/tests/ui/needless_pass_by_value_proc_macro.rs
index 78a0e92d1..c603163c1 100644
--- a/src/tools/clippy/tests/ui/needless_pass_by_value_proc_macro.rs
+++ b/src/tools/clippy/tests/ui/needless_pass_by_value_proc_macro.rs
@@ -1,4 +1,3 @@
-#![crate_type = "proc-macro"]
#![warn(clippy::needless_pass_by_value)]
extern crate proc_macro;
diff --git a/src/tools/clippy/tests/ui/needless_pub_self.fixed b/src/tools/clippy/tests/ui/needless_pub_self.fixed
new file mode 100644
index 000000000..672b4c318
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_pub_self.fixed
@@ -0,0 +1,33 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![feature(custom_inner_attributes)]
+#![allow(unused)]
+#![warn(clippy::needless_pub_self)]
+#![no_main]
+#![rustfmt::skip] // rustfmt will remove `in`, understandable
+ // but very annoying for our purposes!
+
+#[macro_use]
+extern crate proc_macros;
+
+ fn a() {}
+ fn b() {}
+
+pub fn c() {}
+mod a {
+ pub(in super) fn d() {}
+ pub(super) fn e() {}
+ fn f() {}
+}
+
+external! {
+ pub(self) fn g() {}
+ pub(in self) fn h() {}
+}
+with_span! {
+ span
+ pub(self) fn i() {}
+ pub(in self) fn j() {}
+}
+
+// not really anything more to test. just a really simple lint overall
diff --git a/src/tools/clippy/tests/ui/needless_pub_self.rs b/src/tools/clippy/tests/ui/needless_pub_self.rs
new file mode 100644
index 000000000..5ac1edf8e
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_pub_self.rs
@@ -0,0 +1,33 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![feature(custom_inner_attributes)]
+#![allow(unused)]
+#![warn(clippy::needless_pub_self)]
+#![no_main]
+#![rustfmt::skip] // rustfmt will remove `in`, understandable
+ // but very annoying for our purposes!
+
+#[macro_use]
+extern crate proc_macros;
+
+pub(self) fn a() {}
+pub(in self) fn b() {}
+
+pub fn c() {}
+mod a {
+ pub(in super) fn d() {}
+ pub(super) fn e() {}
+ pub(self) fn f() {}
+}
+
+external! {
+ pub(self) fn g() {}
+ pub(in self) fn h() {}
+}
+with_span! {
+ span
+ pub(self) fn i() {}
+ pub(in self) fn j() {}
+}
+
+// not really anything more to test. just a really simple lint overall
diff --git a/src/tools/clippy/tests/ui/needless_pub_self.stderr b/src/tools/clippy/tests/ui/needless_pub_self.stderr
new file mode 100644
index 000000000..3aa2feb5e
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_pub_self.stderr
@@ -0,0 +1,22 @@
+error: unnecessary `pub(self)`
+ --> $DIR/needless_pub_self.rs:13:1
+ |
+LL | pub(self) fn a() {}
+ | ^^^^^^^^^ help: remove it
+ |
+ = note: `-D clippy::needless-pub-self` implied by `-D warnings`
+
+error: unnecessary `pub(in self)`
+ --> $DIR/needless_pub_self.rs:14:1
+ |
+LL | pub(in self) fn b() {}
+ | ^^^^^^^^^^^^ help: remove it
+
+error: unnecessary `pub(self)`
+ --> $DIR/needless_pub_self.rs:20:5
+ |
+LL | pub(self) fn f() {}
+ | ^^^^^^^^^ help: remove it
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/needless_range_loop.rs b/src/tools/clippy/tests/ui/needless_range_loop.rs
index 921801138..a16ef5a5b 100644
--- a/src/tools/clippy/tests/ui/needless_range_loop.rs
+++ b/src/tools/clippy/tests/ui/needless_range_loop.rs
@@ -1,5 +1,9 @@
#![warn(clippy::needless_range_loop)]
-#![allow(clippy::uninlined_format_args)]
+#![allow(
+ clippy::uninlined_format_args,
+ clippy::unnecessary_literal_unwrap,
+ clippy::useless_vec
+)]
static STATIC: [usize; 4] = [0, 1, 8, 16];
const CONST: [usize; 4] = [0, 1, 8, 16];
@@ -82,6 +86,29 @@ fn main() {
for i in 0..2 {
println!("{}", test[i]);
}
+
+ // See #601
+ for i in 0..10 {
+ // no error, id_col does not exist outside the loop
+ let mut id_col = [0f64; 10];
+ id_col[i] = 1f64;
+ }
+
+ fn f<T>(_: &T, _: &T) -> bool {
+ unimplemented!()
+ }
+ fn g<T>(_: &mut [T], _: usize, _: usize) {
+ unimplemented!()
+ }
+ for i in 1..vec.len() {
+ if f(&vec[i - 1], &vec[i]) {
+ g(&mut vec, i - 1, i);
+ }
+ }
+
+ for mid in 1..vec.len() {
+ let (_, _) = vec.split_at(mid);
+ }
}
struct Test {
@@ -94,3 +121,38 @@ impl std::ops::Index<usize> for Test {
&self.inner[index]
}
}
+
+fn partition<T: PartialOrd + Send>(v: &mut [T]) -> usize {
+ let pivot = v.len() - 1;
+ let mut i = 0;
+ for j in 0..pivot {
+ if v[j] <= v[pivot] {
+ v.swap(i, j);
+ i += 1;
+ }
+ }
+ v.swap(i, pivot);
+ i
+}
+
+pub fn manual_copy_same_destination(dst: &mut [i32], d: usize, s: usize) {
+ // Same source and destination - don't trigger lint
+ for i in 0..dst.len() {
+ dst[d + i] = dst[s + i];
+ }
+}
+
+mod issue_2496 {
+ pub trait Handle {
+ fn new_for_index(index: usize) -> Self;
+ fn index(&self) -> usize;
+ }
+
+ pub fn test<H: Handle>() -> H {
+ for x in 0..5 {
+ let next_handle = H::new_for_index(x);
+ println!("{}", next_handle.index());
+ }
+ unimplemented!()
+ }
+}
diff --git a/src/tools/clippy/tests/ui/needless_range_loop.stderr b/src/tools/clippy/tests/ui/needless_range_loop.stderr
index cffa19bec..8ca6b880c 100644
--- a/src/tools/clippy/tests/ui/needless_range_loop.stderr
+++ b/src/tools/clippy/tests/ui/needless_range_loop.stderr
@@ -1,5 +1,5 @@
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:11:14
+ --> $DIR/needless_range_loop.rs:15:14
|
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
@@ -11,7 +11,7 @@ LL | for <item> in &vec {
| ~~~~~~ ~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:20:14
+ --> $DIR/needless_range_loop.rs:24:14
|
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL | for <item> in &vec {
| ~~~~~~ ~~~~
error: the loop variable `j` is only used to index `STATIC`
- --> $DIR/needless_range_loop.rs:25:14
+ --> $DIR/needless_range_loop.rs:29:14
|
LL | for j in 0..4 {
| ^^^^
@@ -33,7 +33,7 @@ LL | for <item> in &STATIC {
| ~~~~~~ ~~~~~~~
error: the loop variable `j` is only used to index `CONST`
- --> $DIR/needless_range_loop.rs:29:14
+ --> $DIR/needless_range_loop.rs:33:14
|
LL | for j in 0..4 {
| ^^^^
@@ -44,7 +44,7 @@ LL | for <item> in &CONST {
| ~~~~~~ ~~~~~~
error: the loop variable `i` is used to index `vec`
- --> $DIR/needless_range_loop.rs:33:14
+ --> $DIR/needless_range_loop.rs:37:14
|
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
@@ -55,7 +55,7 @@ LL | for (i, <item>) in vec.iter().enumerate() {
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec2`
- --> $DIR/needless_range_loop.rs:41:14
+ --> $DIR/needless_range_loop.rs:45:14
|
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
@@ -66,7 +66,7 @@ LL | for <item> in vec2.iter().take(vec.len()) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:45:14
+ --> $DIR/needless_range_loop.rs:49:14
|
LL | for i in 5..vec.len() {
| ^^^^^^^^^^^^
@@ -77,7 +77,7 @@ LL | for <item> in vec.iter().skip(5) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:49:14
+ --> $DIR/needless_range_loop.rs:53:14
|
LL | for i in 0..MAX_LEN {
| ^^^^^^^^^^
@@ -88,7 +88,7 @@ LL | for <item> in vec.iter().take(MAX_LEN) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:53:14
+ --> $DIR/needless_range_loop.rs:57:14
|
LL | for i in 0..=MAX_LEN {
| ^^^^^^^^^^^
@@ -99,7 +99,7 @@ LL | for <item> in vec.iter().take(MAX_LEN + 1) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:57:14
+ --> $DIR/needless_range_loop.rs:61:14
|
LL | for i in 5..10 {
| ^^^^^
@@ -110,7 +110,7 @@ LL | for <item> in vec.iter().take(10).skip(5) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:61:14
+ --> $DIR/needless_range_loop.rs:65:14
|
LL | for i in 5..=10 {
| ^^^^^^
@@ -121,7 +121,7 @@ LL | for <item> in vec.iter().take(10 + 1).skip(5) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is used to index `vec`
- --> $DIR/needless_range_loop.rs:65:14
+ --> $DIR/needless_range_loop.rs:69:14
|
LL | for i in 5..vec.len() {
| ^^^^^^^^^^^^
@@ -132,7 +132,7 @@ LL | for (i, <item>) in vec.iter().enumerate().skip(5) {
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is used to index `vec`
- --> $DIR/needless_range_loop.rs:69:14
+ --> $DIR/needless_range_loop.rs:73:14
|
LL | for i in 5..10 {
| ^^^^^
@@ -143,7 +143,7 @@ LL | for (i, <item>) in vec.iter().enumerate().take(10).skip(5) {
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is used to index `vec`
- --> $DIR/needless_range_loop.rs:74:14
+ --> $DIR/needless_range_loop.rs:78: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 7633316e0..516d99a35 100644
--- a/src/tools/clippy/tests/ui/needless_range_loop2.rs
+++ b/src/tools/clippy/tests/ui/needless_range_loop2.rs
@@ -1,4 +1,5 @@
#![warn(clippy::needless_range_loop)]
+#![allow(clippy::useless_vec)]
fn calc_idx(i: usize) -> usize {
(i + i + 20) % 4
diff --git a/src/tools/clippy/tests/ui/needless_range_loop2.stderr b/src/tools/clippy/tests/ui/needless_range_loop2.stderr
index 1e6ec5e66..8c4f5d954 100644
--- a/src/tools/clippy/tests/ui/needless_range_loop2.stderr
+++ b/src/tools/clippy/tests/ui/needless_range_loop2.stderr
@@ -1,5 +1,5 @@
error: the loop variable `i` is only used to index `ns`
- --> $DIR/needless_range_loop2.rs:10:14
+ --> $DIR/needless_range_loop2.rs:11:14
|
LL | for i in 3..10 {
| ^^^^^
@@ -11,7 +11,7 @@ LL | for <item> in ns.iter().take(10).skip(3) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `ms`
- --> $DIR/needless_range_loop2.rs:31:14
+ --> $DIR/needless_range_loop2.rs:32:14
|
LL | for i in 0..ms.len() {
| ^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL | for <item> in &mut ms {
| ~~~~~~ ~~~~~~~
error: the loop variable `i` is only used to index `ms`
- --> $DIR/needless_range_loop2.rs:37:14
+ --> $DIR/needless_range_loop2.rs:38:14
|
LL | for i in 0..ms.len() {
| ^^^^^^^^^^^
@@ -33,7 +33,7 @@ LL | for <item> in &mut ms {
| ~~~~~~ ~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop2.rs:61:14
+ --> $DIR/needless_range_loop2.rs:62:14
|
LL | for i in x..x + 4 {
| ^^^^^^^^
@@ -44,7 +44,7 @@ LL | for <item> in vec.iter_mut().skip(x).take(4) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop2.rs:68:14
+ --> $DIR/needless_range_loop2.rs:69:14
|
LL | for i in x..=x + 4 {
| ^^^^^^^^^
@@ -55,7 +55,7 @@ LL | for <item> 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:74:14
+ --> $DIR/needless_range_loop2.rs:75:14
|
LL | for i in 0..3 {
| ^^^^
@@ -66,7 +66,7 @@ LL | for <item> in &arr {
| ~~~~~~ ~~~~
error: the loop variable `i` is only used to index `arr`
- --> $DIR/needless_range_loop2.rs:78:14
+ --> $DIR/needless_range_loop2.rs:79:14
|
LL | for i in 0..2 {
| ^^^^
@@ -77,7 +77,7 @@ LL | for <item> in arr.iter().take(2) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `arr`
- --> $DIR/needless_range_loop2.rs:82:14
+ --> $DIR/needless_range_loop2.rs:83: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
new file mode 100644
index 000000000..b36912efb
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_raw_string.fixed
@@ -0,0 +1,17 @@
+//@run-rustfix
+#![allow(clippy::needless_raw_string_hashes, clippy::no_effect, unused)]
+#![warn(clippy::needless_raw_strings)]
+#![feature(c_str_literals)]
+
+fn main() {
+ "aaa";
+ r#""aaa""#;
+ r#"\s"#;
+ b"aaa";
+ br#""aaa""#;
+ br#"\s"#;
+ // currently disabled: https://github.com/rust-lang/rust/issues/113333
+ // cr#"aaa"#;
+ // cr#""aaa""#;
+ // cr#"\s"#;
+}
diff --git a/src/tools/clippy/tests/ui/needless_raw_string.rs b/src/tools/clippy/tests/ui/needless_raw_string.rs
new file mode 100644
index 000000000..8f48e7dab
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_raw_string.rs
@@ -0,0 +1,17 @@
+//@run-rustfix
+#![allow(clippy::needless_raw_string_hashes, clippy::no_effect, unused)]
+#![warn(clippy::needless_raw_strings)]
+#![feature(c_str_literals)]
+
+fn main() {
+ r#"aaa"#;
+ r#""aaa""#;
+ r#"\s"#;
+ br#"aaa"#;
+ br#""aaa""#;
+ br#"\s"#;
+ // currently disabled: https://github.com/rust-lang/rust/issues/113333
+ // cr#"aaa"#;
+ // cr#""aaa""#;
+ // cr#"\s"#;
+}
diff --git a/src/tools/clippy/tests/ui/needless_raw_string.stderr b/src/tools/clippy/tests/ui/needless_raw_string.stderr
new file mode 100644
index 000000000..cfb07b647
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_raw_string.stderr
@@ -0,0 +1,16 @@
+error: unnecessary raw string literal
+ --> $DIR/needless_raw_string.rs:7:5
+ |
+LL | r#"aaa"#;
+ | ^^^^^^^^ help: try: `"aaa"`
+ |
+ = note: `-D clippy::needless-raw-strings` implied by `-D warnings`
+
+error: unnecessary raw string literal
+ --> $DIR/needless_raw_string.rs:10:5
+ |
+LL | br#"aaa"#;
+ | ^^^^^^^^^ help: try: `b"aaa"`
+
+error: aborting due to 2 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
new file mode 100644
index 000000000..c8507c727
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_raw_string_hashes.fixed
@@ -0,0 +1,20 @@
+//@run-rustfix
+#![allow(clippy::no_effect, unused)]
+#![warn(clippy::needless_raw_string_hashes)]
+#![feature(c_str_literals)]
+
+fn main() {
+ r#"aaa"#;
+ r#"Hello "world"!"#;
+ r####" "### "## "# "####;
+ r###" "aa" "# "## "###;
+ 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" "# "## "######;
+}
diff --git a/src/tools/clippy/tests/ui/needless_raw_string_hashes.rs b/src/tools/clippy/tests/ui/needless_raw_string_hashes.rs
new file mode 100644
index 000000000..912fbde16
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_raw_string_hashes.rs
@@ -0,0 +1,20 @@
+//@run-rustfix
+#![allow(clippy::no_effect, unused)]
+#![warn(clippy::needless_raw_string_hashes)]
+#![feature(c_str_literals)]
+
+fn main() {
+ r#"aaa"#;
+ r##"Hello "world"!"##;
+ r######" "### "## "# "######;
+ r######" "aa" "# "## "######;
+ 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" "# "## "######;
+}
diff --git a/src/tools/clippy/tests/ui/needless_raw_string_hashes.stderr b/src/tools/clippy/tests/ui/needless_raw_string_hashes.stderr
new file mode 100644
index 000000000..30e6783a3
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_raw_string_hashes.stderr
@@ -0,0 +1,40 @@
+error: unnecessary hashes around raw string literal
+ --> $DIR/needless_raw_string_hashes.rs:8:5
+ |
+LL | r##"Hello "world"!"##;
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `r#"Hello "world"!"#`
+ |
+ = note: `-D clippy::needless-raw-string-hashes` implied by `-D warnings`
+
+error: unnecessary hashes around raw string literal
+ --> $DIR/needless_raw_string_hashes.rs:9:5
+ |
+LL | r######" "### "## "# "######;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `r####" "### "## "# "####`
+
+error: unnecessary hashes around raw string literal
+ --> $DIR/needless_raw_string_hashes.rs:10:5
+ |
+LL | r######" "aa" "# "## "######;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `r###" "aa" "# "## "###`
+
+error: unnecessary hashes around raw string literal
+ --> $DIR/needless_raw_string_hashes.rs:12:5
+ |
+LL | br##"Hello "world"!"##;
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `br#"Hello "world"!"#`
+
+error: unnecessary hashes around raw string literal
+ --> $DIR/needless_raw_string_hashes.rs:13:5
+ |
+LL | br######" "### "## "# "######;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `br####" "### "## "# "####`
+
+error: unnecessary hashes around raw string literal
+ --> $DIR/needless_raw_string_hashes.rs:14:5
+ |
+LL | br######" "aa" "# "## "######;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `br###" "aa" "# "## "###`
+
+error: aborting due to 6 previous errors
+
diff --git a/src/tools/clippy/tests/ui/needless_return.fixed b/src/tools/clippy/tests/ui/needless_return.fixed
index d49ae5d86..4dabf3139 100644
--- a/src/tools/clippy/tests/ui/needless_return.fixed
+++ b/src/tools/clippy/tests/ui/needless_return.fixed
@@ -7,7 +7,8 @@
clippy::if_same_then_else,
clippy::single_match,
clippy::needless_bool,
- clippy::equatable_if_let
+ clippy::equatable_if_let,
+ clippy::needless_else
)]
#![warn(clippy::needless_return)]
diff --git a/src/tools/clippy/tests/ui/needless_return.rs b/src/tools/clippy/tests/ui/needless_return.rs
index 367638261..542f562b3 100644
--- a/src/tools/clippy/tests/ui/needless_return.rs
+++ b/src/tools/clippy/tests/ui/needless_return.rs
@@ -7,7 +7,8 @@
clippy::if_same_then_else,
clippy::single_match,
clippy::needless_bool,
- clippy::equatable_if_let
+ clippy::equatable_if_let,
+ clippy::needless_else
)]
#![warn(clippy::needless_return)]
diff --git a/src/tools/clippy/tests/ui/needless_return.stderr b/src/tools/clippy/tests/ui/needless_return.stderr
index 05f6038cd..1d9d23d30 100644
--- a/src/tools/clippy/tests/ui/needless_return.stderr
+++ b/src/tools/clippy/tests/ui/needless_return.stderr
@@ -1,390 +1,582 @@
error: unneeded `return` statement
- --> $DIR/needless_return.rs:27:5
+ --> $DIR/needless_return.rs:28:5
|
LL | return true;
| ^^^^^^^^^^^
|
= note: `-D clippy::needless-return` implied by `-D warnings`
- = help: remove `return`
+help: remove `return`
+ |
+LL - return true;
+LL + true
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:31:5
+ --> $DIR/needless_return.rs:32:5
|
LL | return true;
| ^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return true;
+LL + true
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:36:5
+ --> $DIR/needless_return.rs:37:5
|
LL | return true;;;
| ^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return true;;;
+LL + true
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:41:5
+ --> $DIR/needless_return.rs:42:5
|
LL | return true;; ; ;
| ^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return true;; ; ;
+LL + true
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:46:9
+ --> $DIR/needless_return.rs:47:9
|
LL | return true;
| ^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return true;
+LL + true
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:48:9
+ --> $DIR/needless_return.rs:49:9
|
LL | return false;
| ^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return false;
+LL + false
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:54:17
+ --> $DIR/needless_return.rs:55:17
|
LL | true => return false,
| ^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL | true => false,
+ | ~~~~~
error: unneeded `return` statement
- --> $DIR/needless_return.rs:56:13
+ --> $DIR/needless_return.rs:57:13
|
LL | return true;
| ^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return true;
+LL + true
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:63:9
+ --> $DIR/needless_return.rs:64:9
|
LL | return true;
| ^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return true;
+LL + true
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:65:16
+ --> $DIR/needless_return.rs:66:16
|
LL | let _ = || return true;
| ^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL | let _ = || true;
+ | ~~~~
error: unneeded `return` statement
- --> $DIR/needless_return.rs:69:5
+ --> $DIR/needless_return.rs:70:5
|
LL | return the_answer!();
| ^^^^^^^^^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return the_answer!();
+LL + the_answer!()
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:72:21
+ --> $DIR/needless_return.rs:73:21
|
LL | fn test_void_fun() {
| _____________________^
LL | | return;
| |__________^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - fn test_void_fun() {
+LL - return;
+LL + fn test_void_fun() {
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:77:11
+ --> $DIR/needless_return.rs:78:11
|
LL | if b {
| ___________^
LL | | return;
| |______________^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - if b {
+LL - return;
+LL + if b {
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:79:13
+ --> $DIR/needless_return.rs:80:13
|
LL | } else {
| _____________^
LL | | return;
| |______________^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - } else {
+LL - return;
+LL + } else {
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:87:14
+ --> $DIR/needless_return.rs:88:14
|
LL | _ => return,
| ^^^^^^
|
- = help: replace `return` with a unit value
+help: replace `return` with a unit value
+ |
+LL | _ => (),
+ | ~~
error: unneeded `return` statement
- --> $DIR/needless_return.rs:95:24
+ --> $DIR/needless_return.rs:96:24
|
LL | let _ = 42;
| ________________________^
LL | | return;
| |__________________^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - let _ = 42;
+LL - return;
+LL + let _ = 42;
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:98:14
+ --> $DIR/needless_return.rs:99:14
|
LL | _ => return,
| ^^^^^^
|
- = help: replace `return` with a unit value
+help: replace `return` with a unit value
+ |
+LL | _ => (),
+ | ~~
error: unneeded `return` statement
- --> $DIR/needless_return.rs:111:9
+ --> $DIR/needless_return.rs:112:9
|
LL | return String::from("test");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return String::from("test");
+LL + String::from("test")
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:113:9
+ --> $DIR/needless_return.rs:114:9
|
LL | return String::new();
| ^^^^^^^^^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return String::new();
+LL + String::new()
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:135:32
+ --> $DIR/needless_return.rs:136:32
|
LL | bar.unwrap_or_else(|_| return)
| ^^^^^^
|
- = help: replace `return` with an empty block
+help: replace `return` with an empty block
+ |
+LL | bar.unwrap_or_else(|_| {})
+ | ~~
error: unneeded `return` statement
- --> $DIR/needless_return.rs:139:21
+ --> $DIR/needless_return.rs:140:21
|
LL | let _ = || {
| _____________________^
LL | | return;
| |__________________^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - let _ = || {
+LL - return;
+LL + let _ = || {
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:142:20
+ --> $DIR/needless_return.rs:143:20
|
LL | let _ = || return;
| ^^^^^^
|
- = help: replace `return` with an empty block
+help: replace `return` with an empty block
+ |
+LL | let _ = || {};
+ | ~~
error: unneeded `return` statement
- --> $DIR/needless_return.rs:148:32
+ --> $DIR/needless_return.rs:149:32
|
LL | res.unwrap_or_else(|_| return Foo)
| ^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL | res.unwrap_or_else(|_| Foo)
+ | ~~~
error: unneeded `return` statement
- --> $DIR/needless_return.rs:157:5
+ --> $DIR/needless_return.rs:158:5
|
LL | return true;
| ^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return true;
+LL + true
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:161:5
+ --> $DIR/needless_return.rs:162:5
|
LL | return true;
| ^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return true;
+LL + true
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:166:9
+ --> $DIR/needless_return.rs:167:9
|
LL | return true;
| ^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return true;
+LL + true
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:168:9
+ --> $DIR/needless_return.rs:169:9
|
LL | return false;
| ^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return false;
+LL + false
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:174:17
+ --> $DIR/needless_return.rs:175:17
|
LL | true => return false,
| ^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL | true => false,
+ | ~~~~~
error: unneeded `return` statement
- --> $DIR/needless_return.rs:176:13
+ --> $DIR/needless_return.rs:177:13
|
LL | return true;
| ^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return true;
+LL + true
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:183:9
+ --> $DIR/needless_return.rs:184:9
|
LL | return true;
| ^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return true;
+LL + true
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:185:16
+ --> $DIR/needless_return.rs:186:16
|
LL | let _ = || return true;
| ^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL | let _ = || true;
+ | ~~~~
error: unneeded `return` statement
- --> $DIR/needless_return.rs:189:5
+ --> $DIR/needless_return.rs:190:5
|
LL | return the_answer!();
| ^^^^^^^^^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return the_answer!();
+LL + the_answer!()
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:192:33
+ --> $DIR/needless_return.rs:193:33
|
LL | async fn async_test_void_fun() {
| _________________________________^
LL | | return;
| |__________^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - async fn async_test_void_fun() {
+LL - return;
+LL + async fn async_test_void_fun() {
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:197:11
+ --> $DIR/needless_return.rs:198:11
|
LL | if b {
| ___________^
LL | | return;
| |______________^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - if b {
+LL - return;
+LL + if b {
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:199:13
+ --> $DIR/needless_return.rs:200:13
|
LL | } else {
| _____________^
LL | | return;
| |______________^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - } else {
+LL - return;
+LL + } else {
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:207:14
+ --> $DIR/needless_return.rs:208:14
|
LL | _ => return,
| ^^^^^^
|
- = help: replace `return` with a unit value
+help: replace `return` with a unit value
+ |
+LL | _ => (),
+ | ~~
error: unneeded `return` statement
- --> $DIR/needless_return.rs:220:9
+ --> $DIR/needless_return.rs:221:9
|
LL | return String::from("test");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return String::from("test");
+LL + String::from("test")
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:222:9
+ --> $DIR/needless_return.rs:223:9
|
LL | return String::new();
| ^^^^^^^^^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return String::new();
+LL + String::new()
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:238:5
+ --> $DIR/needless_return.rs:239:5
|
LL | return format!("Hello {}", "world!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return format!("Hello {}", "world!");
+LL + format!("Hello {}", "world!")
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:250:9
+ --> $DIR/needless_return.rs:251:9
|
LL | return true;
| ^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL ~ true
+LL | } else {
+LL | return false;
+LL ~ }
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:252:9
+ --> $DIR/needless_return.rs:253:9
|
LL | return false;
| ^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL ~ false
+LL ~ }
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:259:13
+ --> $DIR/needless_return.rs:260:13
|
LL | return 10;
| ^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL ~ 10
+LL | },
+ ...
+LL | },
+LL ~ }
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:262:13
+ --> $DIR/needless_return.rs:263:13
|
LL | return 100;
| ^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL ~ 100
+LL | },
+LL ~ }
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:270:9
+ --> $DIR/needless_return.rs:271:9
|
LL | return 0;
| ^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL ~ 0
+LL ~ }
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:277:13
+ --> $DIR/needless_return.rs:278:13
|
LL | return *(x as *const isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL ~ *(x as *const isize)
+LL | } else {
+LL | return !*(x as *const isize);
+LL ~ }
+LL ~ }
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:279:13
+ --> $DIR/needless_return.rs:280:13
|
LL | return !*(x as *const isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL ~ !*(x as *const isize)
+LL ~ }
+LL ~ }
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:286:20
+ --> $DIR/needless_return.rs:287:20
|
LL | let _ = 42;
| ____________________^
@@ -392,47 +584,73 @@ LL | |
LL | | return;
| |______________^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - let _ = 42;
+LL -
+LL - return;
+LL + let _ = 42;
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:293:20
+ --> $DIR/needless_return.rs:294:20
|
LL | let _ = 42; return;
| ^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - let _ = 42; return;
+LL + let _ = 42;
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:305:9
+ --> $DIR/needless_return.rs:306:9
|
LL | return Ok(format!("ok!"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return Ok(format!("ok!"));
+LL + Ok(format!("ok!"))
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:307:9
+ --> $DIR/needless_return.rs:308:9
|
LL | return Err(format!("err!"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return Err(format!("err!"));
+LL + Err(format!("err!"))
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:313:9
+ --> $DIR/needless_return.rs:314:9
|
LL | return if true { 1 } else { 2 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: remove `return`
+help: remove `return`
+ |
+LL - return if true { 1 } else { 2 };
+LL + if true { 1 } else { 2 }
+ |
error: unneeded `return` statement
- --> $DIR/needless_return.rs:317:9
+ --> $DIR/needless_return.rs:318:9
|
LL | return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: remove `return` and wrap the sequence with parentheses
+help: remove `return` and wrap the sequence with parentheses
+ |
+LL - return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 };
+LL + (if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 })
+ |
error: aborting due to 52 previous errors
diff --git a/src/tools/clippy/tests/ui/never_loop.rs b/src/tools/clippy/tests/ui/never_loop.rs
index 29821ff96..eb179f30e 100644
--- a/src/tools/clippy/tests/ui/never_loop.rs
+++ b/src/tools/clippy/tests/ui/never_loop.rs
@@ -1,4 +1,6 @@
+#![feature(inline_const)]
#![allow(
+ clippy::eq_op,
clippy::single_match,
unused_assignments,
unused_variables,
@@ -295,6 +297,42 @@ pub fn test24() {
}
}
+// Do not lint, we can evaluate `true` to always succeed thus can short-circuit before the `return`
+pub fn test25() {
+ loop {
+ 'label: {
+ if const { true } {
+ break 'label;
+ }
+ return;
+ }
+ }
+}
+
+pub fn test26() {
+ loop {
+ 'label: {
+ if 1 == 1 {
+ break 'label;
+ }
+ return;
+ }
+ }
+}
+
+pub fn test27() {
+ loop {
+ 'label: {
+ let x = true;
+ // Lints because we cannot prove it's always `true`
+ if x {
+ break 'label;
+ }
+ return;
+ }
+ }
+}
+
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 704d44864..0446c09cd 100644
--- a/src/tools/clippy/tests/ui/never_loop.stderr
+++ b/src/tools/clippy/tests/ui/never_loop.stderr
@@ -1,5 +1,5 @@
error: this loop never actually loops
- --> $DIR/never_loop.rs:10:5
+ --> $DIR/never_loop.rs:12:5
|
LL | / loop {
LL | | // clippy::never_loop
@@ -13,7 +13,7 @@ LL | | }
= note: `#[deny(clippy::never_loop)]` on by default
error: this loop never actually loops
- --> $DIR/never_loop.rs:32:5
+ --> $DIR/never_loop.rs:34:5
|
LL | / loop {
LL | | // never loops
@@ -23,7 +23,7 @@ LL | | }
| |_____^
error: this loop never actually loops
- --> $DIR/never_loop.rs:52:5
+ --> $DIR/never_loop.rs:54:5
|
LL | / loop {
LL | | // never loops
@@ -35,7 +35,7 @@ LL | | }
| |_____^
error: this loop never actually loops
- --> $DIR/never_loop.rs:54:9
+ --> $DIR/never_loop.rs:56:9
|
LL | / while i == 0 {
LL | | // never loops
@@ -44,7 +44,7 @@ LL | | }
| |_________^
error: this loop never actually loops
- --> $DIR/never_loop.rs:66:9
+ --> $DIR/never_loop.rs:68:9
|
LL | / loop {
LL | | // never loops
@@ -56,7 +56,7 @@ LL | | }
| |_________^
error: this loop never actually loops
- --> $DIR/never_loop.rs:102:5
+ --> $DIR/never_loop.rs:104:5
|
LL | / while let Some(y) = x {
LL | | // never loops
@@ -65,7 +65,7 @@ LL | | }
| |_____^
error: this loop never actually loops
- --> $DIR/never_loop.rs:109:5
+ --> $DIR/never_loop.rs:111:5
|
LL | / for x in 0..10 {
LL | | // never loops
@@ -82,7 +82,7 @@ LL | if let Some(x) = (0..10).next() {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: this loop never actually loops
- --> $DIR/never_loop.rs:157:5
+ --> $DIR/never_loop.rs:159:5
|
LL | / 'outer: while a {
LL | | // never loops
@@ -94,7 +94,7 @@ LL | | }
| |_____^
error: this loop never actually loops
- --> $DIR/never_loop.rs:172:9
+ --> $DIR/never_loop.rs:174:9
|
LL | / while false {
LL | | break 'label;
@@ -102,7 +102,7 @@ LL | | }
| |_________^
error: this loop never actually loops
- --> $DIR/never_loop.rs:223:13
+ --> $DIR/never_loop.rs:225:13
|
LL | let _ = loop {
| _____________^
@@ -115,7 +115,7 @@ LL | | };
| |_____^
error: this loop never actually loops
- --> $DIR/never_loop.rs:244:5
+ --> $DIR/never_loop.rs:246:5
|
LL | / 'a: loop {
LL | | 'b: {
@@ -126,8 +126,16 @@ LL | | }
LL | | }
| |_____^
+error: sub-expression diverges
+ --> $DIR/never_loop.rs:249:17
+ |
+LL | break 'a;
+ | ^^^^^^^^
+ |
+ = note: `-D clippy::diverging-sub-expression` implied by `-D warnings`
+
error: this loop never actually loops
- --> $DIR/never_loop.rs:278:13
+ --> $DIR/never_loop.rs:280:13
|
LL | / for _ in 0..20 {
LL | | break 'block;
@@ -139,5 +147,17 @@ help: if you need the first element of the iterator, try writing
LL | if let Some(_) = (0..20).next() {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-error: aborting due to 12 previous errors
+error: this loop never actually loops
+ --> $DIR/never_loop.rs:324:5
+ |
+LL | / loop {
+LL | | 'label: {
+LL | | let x = true;
+LL | | // Lints because we cannot prove it's always `true`
+... |
+LL | | }
+LL | | }
+ | |_____^
+
+error: aborting due to 14 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 a2a30c8b9..4eff62b85 100644
--- a/src/tools/clippy/tests/ui/new_ret_no_self.rs
+++ b/src/tools/clippy/tests/ui/new_ret_no_self.rs
@@ -401,25 +401,3 @@ mod issue7344 {
}
}
}
-
-mod issue10041 {
- struct Bomb;
-
- impl Bomb {
- // Hidden <Rhs = Self> default generic parameter.
- pub fn new() -> impl PartialOrd {
- 0i32
- }
- }
-
- // TAIT with self-referencing bounds
- type X = impl std::ops::Add<Output = X>;
-
- struct Bomb2;
-
- impl Bomb2 {
- pub fn new() -> X {
- 0i32
- }
- }
-}
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 2eaebfb5c..2b053b462 100644
--- a/src/tools/clippy/tests/ui/new_ret_no_self.stderr
+++ b/src/tools/clippy/tests/ui/new_ret_no_self.stderr
@@ -92,21 +92,5 @@ LL | | unimplemented!()
LL | | }
| |_________^
-error: methods called `new` usually return `Self`
- --> $DIR/new_ret_no_self.rs:410:9
- |
-LL | / pub fn new() -> impl PartialOrd {
-LL | | 0i32
-LL | | }
- | |_________^
-
-error: methods called `new` usually return `Self`
- --> $DIR/new_ret_no_self.rs:421:9
- |
-LL | / pub fn new() -> X {
-LL | | 0i32
-LL | | }
- | |_________^
-
-error: aborting due to 14 previous errors
+error: aborting due to 12 previous errors
diff --git a/src/tools/clippy/tests/ui/new_ret_no_self_overflow.rs b/src/tools/clippy/tests/ui/new_ret_no_self_overflow.rs
new file mode 100644
index 000000000..7bc6fec10
--- /dev/null
+++ b/src/tools/clippy/tests/ui/new_ret_no_self_overflow.rs
@@ -0,0 +1,26 @@
+#![feature(type_alias_impl_trait)]
+#![warn(clippy::new_ret_no_self)]
+
+mod issue10041 {
+ struct Bomb;
+
+ impl Bomb {
+ // Hidden <Rhs = Self> default generic parameter.
+ pub fn new() -> impl PartialOrd {
+ 0i32
+ }
+ }
+
+ // TAIT with self-referencing bounds
+ type X = impl std::ops::Add<Output = X>;
+
+ struct Bomb2;
+
+ impl Bomb2 {
+ pub fn new() -> X {
+ 0i32
+ }
+ }
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/new_ret_no_self_overflow.stderr b/src/tools/clippy/tests/ui/new_ret_no_self_overflow.stderr
new file mode 100644
index 000000000..babb634fd
--- /dev/null
+++ b/src/tools/clippy/tests/ui/new_ret_no_self_overflow.stderr
@@ -0,0 +1,9 @@
+error[E0275]: overflow evaluating the requirement `<i32 as std::ops::Add>::Output == issue10041::X`
+ --> $DIR/new_ret_no_self_overflow.rs:20:25
+ |
+LL | pub fn new() -> X {
+ | ^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0275`.
diff --git a/src/tools/clippy/tests/ui/no_effect.rs b/src/tools/clippy/tests/ui/no_effect.rs
index 1e42e1fba..6a726941b 100644
--- a/src/tools/clippy/tests/ui/no_effect.rs
+++ b/src/tools/clippy/tests/ui/no_effect.rs
@@ -5,7 +5,8 @@
clippy::deref_addrof,
clippy::redundant_field_names,
clippy::uninlined_format_args,
- clippy::unnecessary_struct_initialization
+ clippy::unnecessary_struct_initialization,
+ clippy::useless_vec
)]
struct Unit;
diff --git a/src/tools/clippy/tests/ui/no_effect.stderr b/src/tools/clippy/tests/ui/no_effect.stderr
index f10f2bcf2..64edfc325 100644
--- a/src/tools/clippy/tests/ui/no_effect.stderr
+++ b/src/tools/clippy/tests/ui/no_effect.stderr
@@ -1,5 +1,5 @@
error: statement with no effect
- --> $DIR/no_effect.rs:97:5
+ --> $DIR/no_effect.rs:98:5
|
LL | 0;
| ^^
@@ -7,151 +7,151 @@ LL | 0;
= note: `-D clippy::no-effect` implied by `-D warnings`
error: statement with no effect
- --> $DIR/no_effect.rs:98:5
+ --> $DIR/no_effect.rs:99:5
|
LL | s2;
| ^^^
error: statement with no effect
- --> $DIR/no_effect.rs:99:5
+ --> $DIR/no_effect.rs:100:5
|
LL | Unit;
| ^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:100:5
+ --> $DIR/no_effect.rs:101:5
|
LL | Tuple(0);
| ^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:101:5
+ --> $DIR/no_effect.rs:102:5
|
LL | Struct { field: 0 };
| ^^^^^^^^^^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:102:5
+ --> $DIR/no_effect.rs:103:5
|
LL | Struct { ..s };
| ^^^^^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:103:5
+ --> $DIR/no_effect.rs:104:5
|
LL | Union { a: 0 };
| ^^^^^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:104:5
+ --> $DIR/no_effect.rs:105:5
|
LL | Enum::Tuple(0);
| ^^^^^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:105:5
+ --> $DIR/no_effect.rs:106:5
|
LL | Enum::Struct { field: 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:106:5
+ --> $DIR/no_effect.rs:107:5
|
LL | 5 + 6;
| ^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:107:5
+ --> $DIR/no_effect.rs:108:5
|
LL | *&42;
| ^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:108:5
+ --> $DIR/no_effect.rs:109:5
|
LL | &6;
| ^^^
error: statement with no effect
- --> $DIR/no_effect.rs:109:5
+ --> $DIR/no_effect.rs:110:5
|
LL | (5, 6, 7);
| ^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:110:5
+ --> $DIR/no_effect.rs:111:5
|
LL | ..;
| ^^^
error: statement with no effect
- --> $DIR/no_effect.rs:111:5
+ --> $DIR/no_effect.rs:112:5
|
LL | 5..;
| ^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:112:5
+ --> $DIR/no_effect.rs:113:5
|
LL | ..5;
| ^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:113:5
+ --> $DIR/no_effect.rs:114:5
|
LL | 5..6;
| ^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:114:5
+ --> $DIR/no_effect.rs:115:5
|
LL | 5..=6;
| ^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:115:5
+ --> $DIR/no_effect.rs:116:5
|
LL | [42, 55];
| ^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:116:5
+ --> $DIR/no_effect.rs:117:5
|
LL | [42, 55][1];
| ^^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:117:5
+ --> $DIR/no_effect.rs:118:5
|
LL | (42, 55).1;
| ^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:118:5
+ --> $DIR/no_effect.rs:119:5
|
LL | [42; 55];
| ^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:119:5
+ --> $DIR/no_effect.rs:120:5
|
LL | [42; 55][13];
| ^^^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:121:5
+ --> $DIR/no_effect.rs:122:5
|
LL | || x += 5;
| ^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:123:5
+ --> $DIR/no_effect.rs:124:5
|
LL | FooString { s: s };
| ^^^^^^^^^^^^^^^^^^^
error: binding to `_` prefixed variable with no side-effect
- --> $DIR/no_effect.rs:124:5
+ --> $DIR/no_effect.rs:125:5
|
LL | let _unused = 1;
| ^^^^^^^^^^^^^^^^
@@ -159,19 +159,19 @@ LL | let _unused = 1;
= note: `-D clippy::no-effect-underscore-binding` implied by `-D warnings`
error: binding to `_` prefixed variable with no side-effect
- --> $DIR/no_effect.rs:125:5
+ --> $DIR/no_effect.rs:126:5
|
LL | let _penguin = || println!("Some helpful closure");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: binding to `_` prefixed variable with no side-effect
- --> $DIR/no_effect.rs:126:5
+ --> $DIR/no_effect.rs:127:5
|
LL | let _duck = Struct { field: 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: binding to `_` prefixed variable with no side-effect
- --> $DIR/no_effect.rs:127:5
+ --> $DIR/no_effect.rs:128:5
|
LL | let _cat = [2, 4, 6, 8][2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/no_effect_return.rs b/src/tools/clippy/tests/ui/no_effect_return.rs
new file mode 100644
index 000000000..231dd063a
--- /dev/null
+++ b/src/tools/clippy/tests/ui/no_effect_return.rs
@@ -0,0 +1,81 @@
+#![allow(clippy::unused_unit, dead_code, unused)]
+#![no_main]
+
+use std::ops::ControlFlow;
+
+fn a() -> u32 {
+ {
+ 0u32;
+ }
+ 0
+}
+
+async fn b() -> u32 {
+ {
+ 0u32;
+ }
+ 0
+}
+
+type C = i32;
+async fn c() -> C {
+ {
+ 0i32 as C;
+ }
+ 0
+}
+
+fn d() -> u128 {
+ {
+ // not last stmt
+ 0u128;
+ println!("lol");
+ }
+ 0
+}
+
+fn e() -> u32 {
+ {
+ // mismatched types
+ 0u16;
+ }
+ 0
+}
+
+fn f() -> [u16; 1] {
+ {
+ [1u16];
+ }
+ [1]
+}
+
+fn g() -> ControlFlow<()> {
+ {
+ ControlFlow::Break::<()>(());
+ }
+ ControlFlow::Continue(())
+}
+
+fn h() -> Vec<u16> {
+ {
+ // function call, so this won't trigger `no_effect`. not an issue with this change, but the
+ // lint itself (but also not really.)
+ vec![0u16];
+ }
+ vec![]
+}
+
+fn i() -> () {
+ {
+ ();
+ }
+ ()
+}
+
+fn j() {
+ {
+ // does not suggest on function without explicit return type
+ ();
+ }
+ ()
+}
diff --git a/src/tools/clippy/tests/ui/no_effect_return.stderr b/src/tools/clippy/tests/ui/no_effect_return.stderr
new file mode 100644
index 000000000..779900e18
--- /dev/null
+++ b/src/tools/clippy/tests/ui/no_effect_return.stderr
@@ -0,0 +1,70 @@
+error: statement with no effect
+ --> $DIR/no_effect_return.rs:8:9
+ |
+LL | 0u32;
+ | -^^^^
+ | |
+ | help: did you mean to return it?: `return`
+ |
+ = note: `-D clippy::no-effect` implied by `-D warnings`
+
+error: statement with no effect
+ --> $DIR/no_effect_return.rs:15:9
+ |
+LL | 0u32;
+ | -^^^^
+ | |
+ | help: did you mean to return it?: `return`
+
+error: statement with no effect
+ --> $DIR/no_effect_return.rs:23:9
+ |
+LL | 0i32 as C;
+ | -^^^^^^^^^
+ | |
+ | help: did you mean to return it?: `return`
+
+error: statement with no effect
+ --> $DIR/no_effect_return.rs:31:9
+ |
+LL | 0u128;
+ | ^^^^^^
+
+error: statement with no effect
+ --> $DIR/no_effect_return.rs:40:9
+ |
+LL | 0u16;
+ | ^^^^^
+
+error: statement with no effect
+ --> $DIR/no_effect_return.rs:47:9
+ |
+LL | [1u16];
+ | -^^^^^^
+ | |
+ | help: did you mean to return it?: `return`
+
+error: statement with no effect
+ --> $DIR/no_effect_return.rs:54:9
+ |
+LL | ControlFlow::Break::<()>(());
+ | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | help: did you mean to return it?: `return`
+
+error: statement with no effect
+ --> $DIR/no_effect_return.rs:70:9
+ |
+LL | ();
+ | -^^
+ | |
+ | help: did you mean to return it?: `return`
+
+error: statement with no effect
+ --> $DIR/no_effect_return.rs:78:9
+ |
+LL | ();
+ | ^^^
+
+error: aborting due to 9 previous errors
+
diff --git a/src/tools/clippy/tests/ui/non_expressive_names.rs b/src/tools/clippy/tests/ui/non_expressive_names.rs
index 583096ac0..987a4775e 100644
--- a/src/tools/clippy/tests/ui/non_expressive_names.rs
+++ b/src/tools/clippy/tests/ui/non_expressive_names.rs
@@ -25,9 +25,9 @@ impl MaybeInst {
}
fn underscores_and_numbers() {
- let _1 = 1; //~ERROR Consider a more descriptive name
- let ____1 = 1; //~ERROR Consider a more descriptive name
- let __1___2 = 12; //~ERROR Consider a more descriptive name
+ let _1 = 1; //~ERROR: consider choosing a more descriptive name
+ let ____1 = 1; //~ERROR: consider choosing a more descriptive name
+ let __1___2 = 12; //~ERROR: consider choosing a more descriptive name
let _1_ok = 1;
}
@@ -48,9 +48,9 @@ struct Bar;
impl Bar {
fn bar() {
- let _1 = 1;
- let ____1 = 1;
- let __1___2 = 12;
+ let _1 = 1; //~ERROR: consider choosing a more descriptive name
+ let ____1 = 1; //~ERROR: consider choosing a more descriptive name
+ let __1___2 = 12; //~ERROR: consider choosing a more descriptive name
let _1_ok = 1;
}
}
diff --git a/src/tools/clippy/tests/ui/non_expressive_names.stderr b/src/tools/clippy/tests/ui/non_expressive_names.stderr
index 116d5da87..b62748d49 100644
--- a/src/tools/clippy/tests/ui/non_expressive_names.stderr
+++ b/src/tools/clippy/tests/ui/non_expressive_names.stderr
@@ -1,7 +1,7 @@
error: consider choosing a more descriptive name
--> $DIR/non_expressive_names.rs:28:9
|
-LL | let _1 = 1; //~ERROR Consider a more descriptive name
+LL | let _1 = 1;
| ^^
|
= note: `-D clippy::just-underscores-and-digits` implied by `-D warnings`
@@ -9,13 +9,13 @@ LL | let _1 = 1; //~ERROR Consider a more descriptive name
error: consider choosing a more descriptive name
--> $DIR/non_expressive_names.rs:29:9
|
-LL | let ____1 = 1; //~ERROR Consider a more descriptive name
+LL | let ____1 = 1;
| ^^^^^
error: consider choosing a more descriptive name
--> $DIR/non_expressive_names.rs:30:9
|
-LL | let __1___2 = 12; //~ERROR Consider a more descriptive name
+LL | let __1___2 = 12;
| ^^^^^^^
error: consider choosing a more descriptive name
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 89d127528..5d0da8dce 100644
--- a/src/tools/clippy/tests/ui/non_octal_unix_permissions.fixed
+++ b/src/tools/clippy/tests/ui/non_octal_unix_permissions.fixed
@@ -1,4 +1,4 @@
-//@ignore-windows
+//@ignore-target-windows
//@run-rustfix
#![warn(clippy::non_octal_unix_permissions)]
use std::fs::{DirBuilder, File, OpenOptions, Permissions};
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 1b3a322d7..04a364305 100644
--- a/src/tools/clippy/tests/ui/non_octal_unix_permissions.rs
+++ b/src/tools/clippy/tests/ui/non_octal_unix_permissions.rs
@@ -1,4 +1,4 @@
-//@ignore-windows
+//@ignore-target-windows
//@run-rustfix
#![warn(clippy::non_octal_unix_permissions)]
use std::fs::{DirBuilder, File, OpenOptions, Permissions};
diff --git a/src/tools/clippy/tests/ui/nonminimal_bool.rs b/src/tools/clippy/tests/ui/nonminimal_bool.rs
index 80cc7c60f..e4aa0937b 100644
--- a/src/tools/clippy/tests/ui/nonminimal_bool.rs
+++ b/src/tools/clippy/tests/ui/nonminimal_bool.rs
@@ -1,6 +1,7 @@
#![feature(lint_reasons)]
-#![allow(unused, clippy::diverging_sub_expression)]
+#![allow(unused, clippy::diverging_sub_expression, clippy::needless_if)]
#![warn(clippy::nonminimal_bool)]
+#![allow(clippy::useless_vec)]
fn main() {
let a: bool = unimplemented!();
@@ -110,3 +111,17 @@ fn issue_10435() {
println!("{}", line!());
}
}
+
+fn issue10836() {
+ struct Foo(bool);
+ impl std::ops::Not for Foo {
+ type Output = bool;
+
+ fn not(self) -> Self::Output {
+ !self.0
+ }
+ }
+
+ // Should not lint
+ let _: bool = !!Foo(true);
+}
diff --git a/src/tools/clippy/tests/ui/nonminimal_bool.stderr b/src/tools/clippy/tests/ui/nonminimal_bool.stderr
index 91b5805aa..e2e4d6477 100644
--- a/src/tools/clippy/tests/ui/nonminimal_bool.stderr
+++ b/src/tools/clippy/tests/ui/nonminimal_bool.stderr
@@ -1,5 +1,5 @@
error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool.rs:11:13
+ --> $DIR/nonminimal_bool.rs:12:13
|
LL | let _ = !true;
| ^^^^^ help: try: `false`
@@ -7,43 +7,43 @@ LL | let _ = !true;
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`
error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool.rs:12:13
+ --> $DIR/nonminimal_bool.rs:13:13
|
LL | let _ = !false;
| ^^^^^^ help: try: `true`
error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool.rs:13:13
+ --> $DIR/nonminimal_bool.rs:14:13
|
LL | let _ = !!a;
| ^^^ help: try: `a`
error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool.rs:14:13
+ --> $DIR/nonminimal_bool.rs:15:13
|
LL | let _ = false || a;
| ^^^^^^^^^^ help: try: `a`
error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool.rs:18:13
+ --> $DIR/nonminimal_bool.rs:19:13
|
LL | let _ = !(!a && b);
| ^^^^^^^^^^ help: try: `a || !b`
error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool.rs:19:13
+ --> $DIR/nonminimal_bool.rs:20: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:21:13
|
LL | let _ = !a && !(b && c);
| ^^^^^^^^^^^^^^^ help: try: `!(a || b && c)`
error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool.rs:28:13
+ --> $DIR/nonminimal_bool.rs:29:13
|
LL | let _ = a == b && c == 5 && a == b;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -56,7 +56,7 @@ LL | let _ = a == b && c == 5;
| ~~~~~~~~~~~~~~~~
error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool.rs:29:13
+ --> $DIR/nonminimal_bool.rs:30:13
|
LL | let _ = a == b || c == 5 || a == b;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -69,7 +69,7 @@ LL | let _ = a == b || c == 5;
| ~~~~~~~~~~~~~~~~
error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool.rs:30:13
+ --> $DIR/nonminimal_bool.rs:31:13
|
LL | let _ = a == b && c == 5 && b == a;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -82,7 +82,7 @@ LL | let _ = a == b && c == 5;
| ~~~~~~~~~~~~~~~~
error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool.rs:31:13
+ --> $DIR/nonminimal_bool.rs:32:13
|
LL | let _ = a != b || !(a != b || c == d);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -95,7 +95,7 @@ LL | let _ = a != b || c != d;
| ~~~~~~~~~~~~~~~~
error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool.rs:32:13
+ --> $DIR/nonminimal_bool.rs:33:13
|
LL | let _ = a != b && !(a != b && c == d);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -108,7 +108,7 @@ LL | let _ = a != b && c != d;
| ~~~~~~~~~~~~~~~~
error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool.rs:62:8
+ --> $DIR/nonminimal_bool.rs:63: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 05802a2c8..294f2aa48 100644
--- a/src/tools/clippy/tests/ui/nonminimal_bool_methods.fixed
+++ b/src/tools/clippy/tests/ui/nonminimal_bool_methods.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-#![allow(unused, clippy::diverging_sub_expression)]
+#![allow(unused, clippy::diverging_sub_expression, clippy::needless_if)]
#![warn(clippy::nonminimal_bool)]
fn methods_with_negation() {
diff --git a/src/tools/clippy/tests/ui/nonminimal_bool_methods.rs b/src/tools/clippy/tests/ui/nonminimal_bool_methods.rs
index cd5b576fa..a165368ab 100644
--- a/src/tools/clippy/tests/ui/nonminimal_bool_methods.rs
+++ b/src/tools/clippy/tests/ui/nonminimal_bool_methods.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-#![allow(unused, clippy::diverging_sub_expression)]
+#![allow(unused, clippy::diverging_sub_expression, clippy::needless_if)]
#![warn(clippy::nonminimal_bool)]
fn methods_with_negation() {
diff --git a/src/tools/clippy/tests/ui/octal_escapes.stderr b/src/tools/clippy/tests/ui/octal_escapes.stderr
index aa362e963..63fdfe486 100644
--- a/src/tools/clippy/tests/ui/octal_escapes.stderr
+++ b/src/tools/clippy/tests/ui/octal_escapes.stderr
@@ -34,17 +34,17 @@ LL | let _bad2 = b"/x0033[0m";
error: octal-looking escape in string literal
--> $DIR/octal_escapes.rs:6:17
|
-LL | let _bad3 = "//033[0m";
+LL | let _bad3 = "///033[0m";
| ^^^^^^^^^^^
|
= 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
diff --git a/src/tools/clippy/tests/ui/ok_expect.rs b/src/tools/clippy/tests/ui/ok_expect.rs
index ff68d38c7..2047ee689 100644
--- a/src/tools/clippy/tests/ui/ok_expect.rs
+++ b/src/tools/clippy/tests/ui/ok_expect.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::unnecessary_literal_unwrap)]
+
use std::io;
struct MyError(()); // doesn't implement Debug
diff --git a/src/tools/clippy/tests/ui/ok_expect.stderr b/src/tools/clippy/tests/ui/ok_expect.stderr
index 6c40adbb5..ab9df26eb 100644
--- a/src/tools/clippy/tests/ui/ok_expect.stderr
+++ b/src/tools/clippy/tests/ui/ok_expect.stderr
@@ -1,5 +1,5 @@
error: called `ok().expect()` on a `Result` value
- --> $DIR/ok_expect.rs:14:5
+ --> $DIR/ok_expect.rs:16:5
|
LL | res.ok().expect("disaster!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | res.ok().expect("disaster!");
= note: `-D clippy::ok-expect` implied by `-D warnings`
error: called `ok().expect()` on a `Result` value
- --> $DIR/ok_expect.rs:20:5
+ --> $DIR/ok_expect.rs:22:5
|
LL | res3.ok().expect("whoof");
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,7 +16,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:22:5
+ --> $DIR/ok_expect.rs:24:5
|
LL | res4.ok().expect("argh");
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -24,7 +24,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:24:5
+ --> $DIR/ok_expect.rs:26:5
|
LL | res5.ok().expect("oops");
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -32,7 +32,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:26:5
+ --> $DIR/ok_expect.rs:28:5
|
LL | res6.ok().expect("meh");
| ^^^^^^^^^^^^^^^^^^^^^^^
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 e1c0fa3f7..4d1a6a1ab 100644
--- a/src/tools/clippy/tests/ui/option_as_ref_deref.fixed
+++ b/src/tools/clippy/tests/ui/option_as_ref_deref.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
-#![allow(unused, clippy::redundant_clone)]
+#![allow(unused, clippy::redundant_clone, clippy::useless_vec)]
#![warn(clippy::option_as_ref_deref)]
use std::ffi::{CString, OsString};
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 6f4917fd1..66d5a1250 100644
--- a/src/tools/clippy/tests/ui/option_as_ref_deref.rs
+++ b/src/tools/clippy/tests/ui/option_as_ref_deref.rs
@@ -1,6 +1,6 @@
//@run-rustfix
-#![allow(unused, clippy::redundant_clone)]
+#![allow(unused, clippy::redundant_clone, clippy::useless_vec)]
#![warn(clippy::option_as_ref_deref)]
use std::ffi::{CString, OsString};
diff --git a/src/tools/clippy/tests/ui/option_env_unwrap.rs b/src/tools/clippy/tests/ui/option_env_unwrap.rs
index ee1fe3f1f..65a1b467f 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
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::option_env_unwrap)]
#![allow(clippy::map_flatten)]
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 2b8ce5477..8e59e4375 100644
--- a/src/tools/clippy/tests/ui/option_if_let_else.fixed
+++ b/src/tools/clippy/tests/ui/option_if_let_else.fixed
@@ -208,3 +208,19 @@ fn issue9742() -> Option<&'static str> {
_ => None,
}
}
+
+mod issue10729 {
+ #![allow(clippy::unit_arg, dead_code)]
+
+ pub fn reproduce(initial: &Option<String>) {
+ // 👇 needs `.as_ref()` because initial is an `&Option<_>`
+ initial.as_ref().map_or({}, |value| do_something(value))
+ }
+
+ pub fn reproduce2(initial: &mut Option<String>) {
+ initial.as_mut().map_or({}, |value| do_something2(value))
+ }
+
+ fn do_something(_value: &str) {}
+ fn do_something2(_value: &mut str) {}
+}
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 cfbec8cb2..e72edf2a8 100644
--- a/src/tools/clippy/tests/ui/option_if_let_else.rs
+++ b/src/tools/clippy/tests/ui/option_if_let_else.rs
@@ -249,3 +249,25 @@ fn issue9742() -> Option<&'static str> {
_ => None,
}
}
+
+mod issue10729 {
+ #![allow(clippy::unit_arg, dead_code)]
+
+ pub fn reproduce(initial: &Option<String>) {
+ // 👇 needs `.as_ref()` because initial is an `&Option<_>`
+ match initial {
+ Some(value) => do_something(value),
+ None => {},
+ }
+ }
+
+ pub fn reproduce2(initial: &mut Option<String>) {
+ match initial {
+ Some(value) => do_something2(value),
+ None => {},
+ }
+ }
+
+ fn do_something(_value: &str) {}
+ fn do_something2(_value: &mut str) {}
+}
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 91d52fc79..aa2da2174 100644
--- a/src/tools/clippy/tests/ui/option_if_let_else.stderr
+++ b/src/tools/clippy/tests/ui/option_if_let_else.stderr
@@ -271,5 +271,23 @@ error: use Option::map_or instead of an if let/else
LL | let _ = if let Ok(a) = res { a + 1 } else { 5 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or(5, |a| a + 1)`
-error: aborting due to 21 previous errors
+error: use Option::map_or instead of an if let/else
+ --> $DIR/option_if_let_else.rs:258:9
+ |
+LL | / match initial {
+LL | | Some(value) => do_something(value),
+LL | | None => {},
+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:265:9
+ |
+LL | / match initial {
+LL | | Some(value) => do_something2(value),
+LL | | None => {},
+LL | | }
+ | |_________^ help: try: `initial.as_mut().map_or({}, |value| do_something2(value))`
+
+error: aborting due to 23 previous errors
diff --git a/src/tools/clippy/tests/ui/or_fun_call.fixed b/src/tools/clippy/tests/ui/or_fun_call.fixed
index f723a55f7..703debb7a 100644
--- a/src/tools/clippy/tests/ui/or_fun_call.fixed
+++ b/src/tools/clippy/tests/ui/or_fun_call.fixed
@@ -1,7 +1,13 @@
//@run-rustfix
#![warn(clippy::or_fun_call)]
#![allow(dead_code)]
-#![allow(clippy::borrow_as_ptr, clippy::uninlined_format_args, clippy::unnecessary_wraps)]
+#![allow(
+ clippy::borrow_as_ptr,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_wraps,
+ clippy::unnecessary_literal_unwrap,
+ clippy::useless_vec
+)]
use std::collections::BTreeMap;
use std::collections::HashMap;
diff --git a/src/tools/clippy/tests/ui/or_fun_call.rs b/src/tools/clippy/tests/ui/or_fun_call.rs
index 61ef6e27f..bb86fe0d4 100644
--- a/src/tools/clippy/tests/ui/or_fun_call.rs
+++ b/src/tools/clippy/tests/ui/or_fun_call.rs
@@ -1,7 +1,13 @@
//@run-rustfix
#![warn(clippy::or_fun_call)]
#![allow(dead_code)]
-#![allow(clippy::borrow_as_ptr, clippy::uninlined_format_args, clippy::unnecessary_wraps)]
+#![allow(
+ clippy::borrow_as_ptr,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_wraps,
+ clippy::unnecessary_literal_unwrap,
+ clippy::useless_vec
+)]
use std::collections::BTreeMap;
use std::collections::HashMap;
diff --git a/src/tools/clippy/tests/ui/or_fun_call.stderr b/src/tools/clippy/tests/ui/or_fun_call.stderr
index ba3001db7..0b5c686be 100644
--- a/src/tools/clippy/tests/ui/or_fun_call.stderr
+++ b/src/tools/clippy/tests/ui/or_fun_call.stderr
@@ -1,5 +1,5 @@
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:48:22
+ --> $DIR/or_fun_call.rs:54:22
|
LL | with_constructor.unwrap_or(make());
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(make)`
@@ -7,163 +7,163 @@ LL | with_constructor.unwrap_or(make());
= note: `-D clippy::or-fun-call` implied by `-D warnings`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:51:14
+ --> $DIR/or_fun_call.rs:57:14
|
LL | with_new.unwrap_or(Vec::new());
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:54:21
+ --> $DIR/or_fun_call.rs:60:21
|
LL | with_const_args.unwrap_or(Vec::with_capacity(12));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| Vec::with_capacity(12))`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:57:14
+ --> $DIR/or_fun_call.rs:63:14
|
LL | with_err.unwrap_or(make());
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| make())`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:60:19
+ --> $DIR/or_fun_call.rs:66:19
|
LL | with_err_args.unwrap_or(Vec::with_capacity(12));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| Vec::with_capacity(12))`
error: use of `unwrap_or` followed by a call to `default`
- --> $DIR/or_fun_call.rs:63:24
+ --> $DIR/or_fun_call.rs:69:24
|
LL | with_default_trait.unwrap_or(Default::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `default`
- --> $DIR/or_fun_call.rs:66:23
+ --> $DIR/or_fun_call.rs:72:23
|
LL | with_default_type.unwrap_or(u64::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:69:18
+ --> $DIR/or_fun_call.rs:75:18
|
LL | self_default.unwrap_or(<FakeDefault>::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(<FakeDefault>::default)`
error: use of `unwrap_or` followed by a call to `default`
- --> $DIR/or_fun_call.rs:72:18
+ --> $DIR/or_fun_call.rs:78:18
|
LL | real_default.unwrap_or(<FakeDefault as Default>::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:75:14
+ --> $DIR/or_fun_call.rs:81:14
|
LL | with_vec.unwrap_or(vec![]);
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:78:21
+ --> $DIR/or_fun_call.rs:84:21
|
LL | without_default.unwrap_or(Foo::new());
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(Foo::new)`
error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:81:19
+ --> $DIR/or_fun_call.rs:87:19
|
LL | map.entry(42).or_insert(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:84:23
+ --> $DIR/or_fun_call.rs:90:23
|
LL | map_vec.entry(42).or_insert(vec![]);
| ^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:87:21
+ --> $DIR/or_fun_call.rs:93:21
|
LL | btree.entry(42).or_insert(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:90:25
+ --> $DIR/or_fun_call.rs:96:25
|
LL | btree_vec.entry(42).or_insert(vec![]);
| ^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:93:21
+ --> $DIR/or_fun_call.rs:99:21
|
LL | let _ = stringy.unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:101:21
+ --> $DIR/or_fun_call.rs:107:21
|
LL | let _ = Some(1).unwrap_or(map[&1]);
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:103:21
+ --> $DIR/or_fun_call.rs:109:21
|
LL | let _ = Some(1).unwrap_or(map[&1]);
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`
error: use of `or` followed by a function call
- --> $DIR/or_fun_call.rs:127:35
+ --> $DIR/or_fun_call.rs:133:35
|
LL | let _ = Some("a".to_string()).or(Some("b".to_string()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:166:14
+ --> $DIR/or_fun_call.rs:172:14
|
LL | None.unwrap_or(ptr_to_ref(s));
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| ptr_to_ref(s))`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:172:14
+ --> $DIR/or_fun_call.rs:178:14
|
LL | None.unwrap_or(unsafe { ptr_to_ref(s) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:174:14
+ --> $DIR/or_fun_call.rs:180:14
|
LL | None.unwrap_or( unsafe { ptr_to_ref(s) } );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:188:14
+ --> $DIR/or_fun_call.rs:194:14
|
LL | .unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:201:14
+ --> $DIR/or_fun_call.rs:207:14
|
LL | .unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:213:14
+ --> $DIR/or_fun_call.rs:219:14
|
LL | .unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:224:10
+ --> $DIR/or_fun_call.rs:230:10
|
LL | .unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `map_or` followed by a function call
- --> $DIR/or_fun_call.rs:249:25
+ --> $DIR/or_fun_call.rs:255:25
|
LL | let _ = Some(4).map_or(g(), |v| v);
| ^^^^^^^^^^^^^^^^^^ help: try this: `map_or_else(g, |v| v)`
error: use of `map_or` followed by a function call
- --> $DIR/or_fun_call.rs:250:25
+ --> $DIR/or_fun_call.rs:256:25
|
LL | let _ = Some(4).map_or(g(), f);
| ^^^^^^^^^^^^^^ help: try this: `map_or_else(g, f)`
diff --git a/src/tools/clippy/tests/ui/or_then_unwrap.fixed b/src/tools/clippy/tests/ui/or_then_unwrap.fixed
index 40badac44..773dfc3c5 100644
--- a/src/tools/clippy/tests/ui/or_then_unwrap.fixed
+++ b/src/tools/clippy/tests/ui/or_then_unwrap.fixed
@@ -1,7 +1,7 @@
//@run-rustfix
#![warn(clippy::or_then_unwrap)]
-#![allow(clippy::map_identity, clippy::let_unit_value)]
+#![allow(clippy::map_identity, clippy::let_unit_value, clippy::unnecessary_literal_unwrap)]
struct SomeStruct;
impl SomeStruct {
diff --git a/src/tools/clippy/tests/ui/or_then_unwrap.rs b/src/tools/clippy/tests/ui/or_then_unwrap.rs
index 76c9942fe..5867e0148 100644
--- a/src/tools/clippy/tests/ui/or_then_unwrap.rs
+++ b/src/tools/clippy/tests/ui/or_then_unwrap.rs
@@ -1,7 +1,7 @@
//@run-rustfix
#![warn(clippy::or_then_unwrap)]
-#![allow(clippy::map_identity, clippy::let_unit_value)]
+#![allow(clippy::map_identity, clippy::let_unit_value, clippy::unnecessary_literal_unwrap)]
struct SomeStruct;
impl SomeStruct {
diff --git a/src/tools/clippy/tests/ui/overflow_check_conditional.rs b/src/tools/clippy/tests/ui/overflow_check_conditional.rs
index e1e301140..14a6b98d0 100644
--- a/src/tools/clippy/tests/ui/overflow_check_conditional.rs
+++ b/src/tools/clippy/tests/ui/overflow_check_conditional.rs
@@ -1,4 +1,5 @@
#![warn(clippy::overflow_check_conditional)]
+#![allow(clippy::needless_if)]
fn test(a: u32, b: u32, c: u32) {
if a + b < a {}
diff --git a/src/tools/clippy/tests/ui/overflow_check_conditional.stderr b/src/tools/clippy/tests/ui/overflow_check_conditional.stderr
index 92d1d8ef9..3ec2298f8 100644
--- a/src/tools/clippy/tests/ui/overflow_check_conditional.stderr
+++ b/src/tools/clippy/tests/ui/overflow_check_conditional.stderr
@@ -1,5 +1,5 @@
error: you are trying to use classic C overflow conditions that will fail in Rust
- --> $DIR/overflow_check_conditional.rs:4:8
+ --> $DIR/overflow_check_conditional.rs:5:8
|
LL | if a + b < a {}
| ^^^^^^^^^
@@ -7,43 +7,43 @@ LL | if a + b < a {}
= note: `-D clippy::overflow-check-conditional` implied by `-D warnings`
error: you are trying to use classic C overflow conditions that will fail in Rust
- --> $DIR/overflow_check_conditional.rs:5:8
+ --> $DIR/overflow_check_conditional.rs:6: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:6:8
+ --> $DIR/overflow_check_conditional.rs:7: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:7:8
+ --> $DIR/overflow_check_conditional.rs:8: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:8:8
+ --> $DIR/overflow_check_conditional.rs:9: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:9:8
+ --> $DIR/overflow_check_conditional.rs:10: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:10:8
+ --> $DIR/overflow_check_conditional.rs:11: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:11:8
+ --> $DIR/overflow_check_conditional.rs:12:8
|
LL | if a < a - b {}
| ^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/partialeq_to_none.fixed b/src/tools/clippy/tests/ui/partialeq_to_none.fixed
index 2df87a26d..95e184b1d 100644
--- a/src/tools/clippy/tests/ui/partialeq_to_none.fixed
+++ b/src/tools/clippy/tests/ui/partialeq_to_none.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
#![warn(clippy::partialeq_to_none)]
-#![allow(clippy::eq_op)]
+#![allow(clippy::eq_op, clippy::needless_if)]
struct Foobar;
diff --git a/src/tools/clippy/tests/ui/partialeq_to_none.rs b/src/tools/clippy/tests/ui/partialeq_to_none.rs
index df6233b9a..4fa50dcc1 100644
--- a/src/tools/clippy/tests/ui/partialeq_to_none.rs
+++ b/src/tools/clippy/tests/ui/partialeq_to_none.rs
@@ -1,6 +1,6 @@
//@run-rustfix
#![warn(clippy::partialeq_to_none)]
-#![allow(clippy::eq_op)]
+#![allow(clippy::eq_op, clippy::needless_if)]
struct Foobar;
diff --git a/src/tools/clippy/tests/ui/patterns.fixed b/src/tools/clippy/tests/ui/patterns.fixed
index a1da47d84..714143e75 100644
--- a/src/tools/clippy/tests/ui/patterns.fixed
+++ b/src/tools/clippy/tests/ui/patterns.fixed
@@ -1,8 +1,12 @@
//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::all)]
#![allow(unused)]
#![allow(clippy::uninlined_format_args)]
+#[macro_use]
+extern crate proc_macros;
+
fn main() {
let v = Some(true);
let s = [0, 1, 2, 3, 4];
@@ -34,4 +38,11 @@ fn main() {
ref x => println!("vec: {:?}", x),
ref y if y == &vec![0] => (),
}
+ external! {
+ let v = Some(true);
+ match v {
+ Some(x) => (),
+ y @ _ => (),
+ }
+ }
}
diff --git a/src/tools/clippy/tests/ui/patterns.rs b/src/tools/clippy/tests/ui/patterns.rs
index 399066b81..153e26407 100644
--- a/src/tools/clippy/tests/ui/patterns.rs
+++ b/src/tools/clippy/tests/ui/patterns.rs
@@ -1,8 +1,12 @@
//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::all)]
#![allow(unused)]
#![allow(clippy::uninlined_format_args)]
+#[macro_use]
+extern crate proc_macros;
+
fn main() {
let v = Some(true);
let s = [0, 1, 2, 3, 4];
@@ -34,4 +38,11 @@ fn main() {
ref x @ _ => println!("vec: {:?}", x),
ref y if y == &vec![0] => (),
}
+ external! {
+ let v = Some(true);
+ match v {
+ Some(x) => (),
+ y @ _ => (),
+ }
+ }
}
diff --git a/src/tools/clippy/tests/ui/patterns.stderr b/src/tools/clippy/tests/ui/patterns.stderr
index 2c46b4eb5..276330d21 100644
--- a/src/tools/clippy/tests/ui/patterns.stderr
+++ b/src/tools/clippy/tests/ui/patterns.stderr
@@ -1,5 +1,5 @@
error: the `y @ _` pattern can be written as just `y`
- --> $DIR/patterns.rs:11:9
+ --> $DIR/patterns.rs:15:9
|
LL | y @ _ => (),
| ^^^^^ help: try: `y`
@@ -7,13 +7,13 @@ LL | y @ _ => (),
= note: `-D clippy::redundant-pattern` implied by `-D warnings`
error: the `x @ _` pattern can be written as just `x`
- --> $DIR/patterns.rs:26:9
+ --> $DIR/patterns.rs:30:9
|
LL | ref mut x @ _ => {
| ^^^^^^^^^^^^^ help: try: `ref mut x`
error: the `x @ _` pattern can be written as just `x`
- --> $DIR/patterns.rs:34:9
+ --> $DIR/patterns.rs:38:9
|
LL | ref x @ _ => println!("vec: {:?}", x),
| ^^^^^^^^^ help: try: `ref x`
diff --git a/src/tools/clippy/tests/ui/print_with_newline.fixed b/src/tools/clippy/tests/ui/print_with_newline.fixed
new file mode 100644
index 000000000..6098dea39
--- /dev/null
+++ b/src/tools/clippy/tests/ui/print_with_newline.fixed
@@ -0,0 +1,58 @@
+// 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");
+ println!("Hello {}", "world");
+ println!("Hello {} {}", "world", "#2");
+ println!("{}", 1265);
+ println!();
+
+ // these are all fine
+ print!("");
+ print!("Hello");
+ println!("Hello");
+ println!("Hello\n");
+ println!("Hello {}\n", "world");
+ print!("Issue\n{}", 1265);
+ print!("{}", 1265);
+ print!("\n{}", 1275);
+ 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
+
+ // Escaping
+ print!("\\n"); // #3514
+ println!("\\"); // should fail
+ print!("\\\\n");
+
+ // Raw strings
+ print!(r"\n"); // #3778
+
+ // Literal newlines should also fail
+ println!(
+
+ );
+ println!(
+
+ );
+
+ // Don't warn on CRLF (#4208)
+ print!("\r\n");
+ print!("foo\r\n");
+ println!("\\r"); // should fail
+ print!("foo\rbar\n");
+
+ // Ignore expanded format strings
+ macro_rules! newline {
+ () => {
+ "\n"
+ };
+ }
+ print!(newline!());
+}
diff --git a/src/tools/clippy/tests/ui/print_with_newline.rs b/src/tools/clippy/tests/ui/print_with_newline.rs
index ff79ca75f..d9c7acc27 100644
--- a/src/tools/clippy/tests/ui/print_with_newline.rs
+++ b/src/tools/clippy/tests/ui/print_with_newline.rs
@@ -47,7 +47,7 @@ fn main() {
// Don't warn on CRLF (#4208)
print!("\r\n");
print!("foo\r\n");
- print!("\\r\n"); //~ ERROR
+ print!("\\r\n"); // should fail
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 b9f5675fa..b97711e77 100644
--- a/src/tools/clippy/tests/ui/print_with_newline.stderr
+++ b/src/tools/clippy/tests/ui/print_with_newline.stderr
@@ -62,13 +62,13 @@ LL + println!();
error: using `print!()` with a format string that ends in a single newline
--> $DIR/print_with_newline.rs:31:5
|
-LL | print!("//n"); // should fail
+LL | print!("///n"); // should fail
| ^^^^^^^^^^^^^^
|
help: use `println!` instead
|
-LL - print!("//n"); // should fail
-LL + println!("/"); // should fail
+LL - print!("///n"); // should fail
+LL + println!("//"); // should fail
|
error: using `print!()` with a format string that ends in a single newline
@@ -104,13 +104,13 @@ LL ~
error: using `print!()` with a format string that ends in a single newline
--> $DIR/print_with_newline.rs:50:5
|
-LL | print!("/r/n"); //~ ERROR
+LL | print!("//r/n"); // should fail
| ^^^^^^^^^^^^^^^
|
help: use `println!` instead
|
-LL - print!("/r/n"); //~ ERROR
-LL + println!("/r"); //~ ERROR
+LL - print!("//r/n"); // should fail
+LL + println!("//r"); // should fail
|
error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/proc_macro.rs b/src/tools/clippy/tests/ui/proc_macro.rs
index 59914b8b8..b77874034 100644
--- a/src/tools/clippy/tests/ui/proc_macro.rs
+++ b/src/tools/clippy/tests/ui/proc_macro.rs
@@ -1,5 +1,4 @@
//! Check that we correctly lint procedural macros.
-#![crate_type = "proc-macro"]
extern crate proc_macro;
diff --git a/src/tools/clippy/tests/ui/proc_macro.stderr b/src/tools/clippy/tests/ui/proc_macro.stderr
index c795f6ad0..d912b5027 100644
--- a/src/tools/clippy/tests/ui/proc_macro.stderr
+++ b/src/tools/clippy/tests/ui/proc_macro.stderr
@@ -1,5 +1,5 @@
error: approximate value of `f{32, 64}::consts::PI` found
- --> $DIR/proc_macro.rs:10:14
+ --> $DIR/proc_macro.rs:9:14
|
LL | let _x = 3.14;
| ^^^^
diff --git a/src/tools/clippy/tests/ui/ptr_arg.rs b/src/tools/clippy/tests/ui/ptr_arg.rs
index 5f54101ca..709f74ee6 100644
--- a/src/tools/clippy/tests/ui/ptr_arg.rs
+++ b/src/tools/clippy/tests/ui/ptr_arg.rs
@@ -1,5 +1,10 @@
#![feature(lint_reasons)]
-#![allow(unused, clippy::many_single_char_names, clippy::redundant_clone)]
+#![allow(
+ unused,
+ clippy::many_single_char_names,
+ clippy::needless_lifetimes,
+ clippy::redundant_clone
+)]
#![warn(clippy::ptr_arg)]
use std::borrow::Cow;
@@ -235,3 +240,29 @@ fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
takes_dyn(b);
takes_dyn(c);
}
+
+mod issue_9218 {
+ use std::borrow::Cow;
+
+ fn cow_non_elided_lifetime<'a>(input: &Cow<'a, str>) -> &'a str {
+ todo!()
+ }
+
+ // This one has an anonymous lifetime so it's not okay
+ fn cow_elided_lifetime<'a>(input: &'a Cow<str>) -> &'a str {
+ 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 {
+ todo!()
+ }
+ fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str {
+ todo!()
+ }
+
+ // Inferred to be `&'a str`, afaik.
+ fn cow_good_ret_ty<'a>(input: &'a Cow<'a, str>) -> &str {
+ todo!()
+ }
+}
diff --git a/src/tools/clippy/tests/ui/ptr_arg.stderr b/src/tools/clippy/tests/ui/ptr_arg.stderr
index 6b4de98ce..d663b070b 100644
--- a/src/tools/clippy/tests/ui/ptr_arg.stderr
+++ b/src/tools/clippy/tests/ui/ptr_arg.stderr
@@ -1,5 +1,5 @@
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
- --> $DIR/ptr_arg.rs:8:14
+ --> $DIR/ptr_arg.rs:13:14
|
LL | fn do_vec(x: &Vec<i64>) {
| ^^^^^^^^^ help: change this to: `&[i64]`
@@ -7,43 +7,43 @@ LL | fn do_vec(x: &Vec<i64>) {
= note: `-D clippy::ptr-arg` implied by `-D warnings`
error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
- --> $DIR/ptr_arg.rs:12:18
+ --> $DIR/ptr_arg.rs:17:18
|
LL | fn do_vec_mut(x: &mut Vec<i64>) {
| ^^^^^^^^^^^^^ 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:16:14
+ --> $DIR/ptr_arg.rs:21: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:20:18
+ --> $DIR/ptr_arg.rs:25: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:24:15
+ --> $DIR/ptr_arg.rs:29: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:28:19
+ --> $DIR/ptr_arg.rs:33: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:36:18
+ --> $DIR/ptr_arg.rs:41:18
|
LL | fn do_vec(x: &Vec<i64>);
| ^^^^^^^^^ help: change this to: `&[i64]`
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
- --> $DIR/ptr_arg.rs:49:14
+ --> $DIR/ptr_arg.rs:54:14
|
LL | fn cloned(x: &Vec<u8>) -> Vec<u8> {
| ^^^^^^^^
@@ -60,7 +60,7 @@ LL ~ x.to_owned()
|
error: writing `&String` instead of `&str` involves a new object where a slice will do
- --> $DIR/ptr_arg.rs:58:18
+ --> $DIR/ptr_arg.rs:63:18
|
LL | fn str_cloned(x: &String) -> String {
| ^^^^^^^
@@ -76,7 +76,7 @@ LL ~ x.to_owned()
|
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
- --> $DIR/ptr_arg.rs:66:19
+ --> $DIR/ptr_arg.rs:71:19
|
LL | fn path_cloned(x: &PathBuf) -> PathBuf {
| ^^^^^^^^
@@ -92,7 +92,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:74:44
+ --> $DIR/ptr_arg.rs:79:44
|
LL | fn false_positive_capacity(x: &Vec<u8>, y: &String) {
| ^^^^^^^
@@ -106,19 +106,19 @@ LL ~ let c = y;
|
error: using a reference to `Cow` is not recommended
- --> $DIR/ptr_arg.rs:88:25
+ --> $DIR/ptr_arg.rs:93: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:117:66
+ --> $DIR/ptr_arg.rs:122:66
|
LL | fn some_allowed(#[allow(clippy::ptr_arg)] _v: &Vec<u32>, _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:146:21
+ --> $DIR/ptr_arg.rs:151:21
|
LL | fn foo_vec(vec: &Vec<u8>) {
| ^^^^^^^^
@@ -131,7 +131,7 @@ 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:151:23
+ --> $DIR/ptr_arg.rs:156:23
|
LL | fn foo_path(path: &PathBuf) {
| ^^^^^^^^
@@ -144,7 +144,7 @@ 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:156:21
+ --> $DIR/ptr_arg.rs:161:21
|
LL | fn foo_str(str: &PathBuf) {
| ^^^^^^^^
@@ -157,28 +157,46 @@ 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:162:29
+ --> $DIR/ptr_arg.rs:167:29
|
LL | fn mut_vec_slice_methods(v: &mut Vec<u32>) {
| ^^^^^^^^^^^^^ 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:224:17
+ --> $DIR/ptr_arg.rs:229:17
|
LL | fn dyn_trait(a: &mut Vec<u32>, 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:224:35
+ --> $DIR/ptr_arg.rs:229:35
|
LL | fn dyn_trait(a: &mut Vec<u32>, 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:224:51
+ --> $DIR/ptr_arg.rs:229:51
|
LL | fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
| ^^^^^^^^^^^^ help: change this to: `&mut Path`
-error: aborting due to 20 previous errors
+error: using a reference to `Cow` is not recommended
+ --> $DIR/ptr_arg.rs:252:39
+ |
+LL | fn cow_elided_lifetime<'a>(input: &'a Cow<str>) -> &'a str {
+ | ^^^^^^^^^^^^ help: change this to: `&str`
+
+error: using a reference to `Cow` is not recommended
+ --> $DIR/ptr_arg.rs:257: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:260:40
+ |
+LL | fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str {
+ | ^^^^^^^^^^^^^^^^ help: change this to: `&str`
+
+error: aborting due to 23 previous errors
diff --git a/src/tools/clippy/tests/ui/ptr_as_ptr.fixed b/src/tools/clippy/tests/ui/ptr_as_ptr.fixed
index 2c2567d67..26a64c861 100644
--- a/src/tools/clippy/tests/ui/ptr_as_ptr.fixed
+++ b/src/tools/clippy/tests/ui/ptr_as_ptr.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![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 6000e5c08..ea40d4947 100644
--- a/src/tools/clippy/tests/ui/ptr_as_ptr.rs
+++ b/src/tools/clippy/tests/ui/ptr_as_ptr.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::ptr_as_ptr)]
diff --git a/src/tools/clippy/tests/ui/ptr_cast_constness.fixed b/src/tools/clippy/tests/ui/ptr_cast_constness.fixed
new file mode 100644
index 000000000..1ef1809d1
--- /dev/null
+++ b/src/tools/clippy/tests/ui/ptr_cast_constness.fixed
@@ -0,0 +1,62 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+
+#![warn(clippy::ptr_cast_constness)]
+#![allow(clippy::transmute_ptr_to_ref, clippy::unnecessary_cast, unused)]
+
+extern crate proc_macros;
+use proc_macros::{external, inline_macros};
+
+unsafe fn ptr_to_ref<T, U>(p: *const T, om: *mut U) {
+ let _: &mut T = std::mem::transmute(p.cast_mut());
+ let _ = &mut *p.cast_mut();
+ let _: &T = &*(om as *const T);
+}
+
+#[inline_macros]
+fn main() {
+ let ptr: *const u32 = &42_u32;
+ let mut_ptr: *mut u32 = &mut 42_u32;
+
+ let _ = ptr as *const u32;
+ let _ = mut_ptr as *mut u32;
+
+ // Make sure the lint can handle the difference in their operator precedences.
+ unsafe {
+ let ptr_ptr: *const *const u32 = &ptr;
+ let _ = (*ptr_ptr).cast_mut();
+ }
+
+ let _ = ptr.cast_mut();
+ let _ = mut_ptr.cast_const();
+
+ // Lint this, since pointer::cast_mut and pointer::cast_const have ?Sized
+ let ptr_of_array: *const [u32; 4] = &[1, 2, 3, 4];
+ let _ = ptr_of_array as *const [u32];
+ let _ = ptr_of_array as *const dyn std::fmt::Debug;
+
+ // Make sure the lint is triggered inside a macro
+ let _ = inline!($ptr as *const u32);
+
+ // Do not lint inside macros from external crates
+ let _ = external!($ptr as *const u32);
+}
+
+#[clippy::msrv = "1.64"]
+fn _msrv_1_64() {
+ let ptr: *const u32 = &42_u32;
+ let mut_ptr: *mut u32 = &mut 42_u32;
+
+ // `pointer::cast_const` and `pointer::cast_mut` were stabilized in 1.65. Do not lint this
+ let _ = ptr as *mut u32;
+ let _ = mut_ptr as *const u32;
+}
+
+#[clippy::msrv = "1.65"]
+fn _msrv_1_65() {
+ let ptr: *const u32 = &42_u32;
+ let mut_ptr: *mut u32 = &mut 42_u32;
+
+ let _ = ptr.cast_mut();
+ let _ = mut_ptr.cast_const();
+}
diff --git a/src/tools/clippy/tests/ui/ptr_cast_constness.rs b/src/tools/clippy/tests/ui/ptr_cast_constness.rs
new file mode 100644
index 000000000..2c15cd429
--- /dev/null
+++ b/src/tools/clippy/tests/ui/ptr_cast_constness.rs
@@ -0,0 +1,62 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+
+#![warn(clippy::ptr_cast_constness)]
+#![allow(clippy::transmute_ptr_to_ref, clippy::unnecessary_cast, unused)]
+
+extern crate proc_macros;
+use proc_macros::{external, inline_macros};
+
+unsafe fn ptr_to_ref<T, U>(p: *const T, om: *mut U) {
+ let _: &mut T = std::mem::transmute(p as *mut T);
+ let _ = &mut *(p as *mut T);
+ let _: &T = &*(om as *const T);
+}
+
+#[inline_macros]
+fn main() {
+ let ptr: *const u32 = &42_u32;
+ let mut_ptr: *mut u32 = &mut 42_u32;
+
+ let _ = ptr as *const u32;
+ let _ = mut_ptr as *mut u32;
+
+ // Make sure the lint can handle the difference in their operator precedences.
+ unsafe {
+ let ptr_ptr: *const *const u32 = &ptr;
+ let _ = *ptr_ptr as *mut u32;
+ }
+
+ let _ = ptr as *mut u32;
+ let _ = mut_ptr as *const u32;
+
+ // Lint this, since pointer::cast_mut and pointer::cast_const have ?Sized
+ let ptr_of_array: *const [u32; 4] = &[1, 2, 3, 4];
+ let _ = ptr_of_array as *const [u32];
+ let _ = ptr_of_array as *const dyn std::fmt::Debug;
+
+ // Make sure the lint is triggered inside a macro
+ let _ = inline!($ptr as *const u32);
+
+ // Do not lint inside macros from external crates
+ let _ = external!($ptr as *const u32);
+}
+
+#[clippy::msrv = "1.64"]
+fn _msrv_1_64() {
+ let ptr: *const u32 = &42_u32;
+ let mut_ptr: *mut u32 = &mut 42_u32;
+
+ // `pointer::cast_const` and `pointer::cast_mut` were stabilized in 1.65. Do not lint this
+ let _ = ptr as *mut u32;
+ let _ = mut_ptr as *const u32;
+}
+
+#[clippy::msrv = "1.65"]
+fn _msrv_1_65() {
+ let ptr: *const u32 = &42_u32;
+ let mut_ptr: *mut u32 = &mut 42_u32;
+
+ let _ = ptr as *mut u32;
+ let _ = mut_ptr as *const u32;
+}
diff --git a/src/tools/clippy/tests/ui/ptr_cast_constness.stderr b/src/tools/clippy/tests/ui/ptr_cast_constness.stderr
new file mode 100644
index 000000000..0c3ff8636
--- /dev/null
+++ b/src/tools/clippy/tests/ui/ptr_cast_constness.stderr
@@ -0,0 +1,46 @@
+error: `as` casting between raw pointers while changing only its constness
+ --> $DIR/ptr_cast_constness.rs:11: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`
+
+error: `as` casting between raw pointers while changing only its constness
+ --> $DIR/ptr_cast_constness.rs:12:19
+ |
+LL | let _ = &mut *(p as *mut T);
+ | ^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `p.cast_mut()`
+
+error: `as` casting between raw pointers while changing only its constness
+ --> $DIR/ptr_cast_constness.rs:27:17
+ |
+LL | let _ = *ptr_ptr as *mut u32;
+ | ^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `(*ptr_ptr).cast_mut()`
+
+error: `as` casting between raw pointers while changing only its constness
+ --> $DIR/ptr_cast_constness.rs:30:13
+ |
+LL | let _ = ptr as *mut u32;
+ | ^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `ptr.cast_mut()`
+
+error: `as` casting between raw pointers while changing only its constness
+ --> $DIR/ptr_cast_constness.rs:31:13
+ |
+LL | let _ = mut_ptr as *const u32;
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()`
+
+error: `as` casting between raw pointers while changing only its constness
+ --> $DIR/ptr_cast_constness.rs:60:13
+ |
+LL | let _ = ptr as *mut u32;
+ | ^^^^^^^^^^^^^^^ help: try `pointer::cast_mut`, a safer alternative: `ptr.cast_mut()`
+
+error: `as` casting between raw pointers while changing only its constness
+ --> $DIR/ptr_cast_constness.rs:61:13
+ |
+LL | let _ = mut_ptr as *const u32;
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `mut_ptr.cast_const()`
+
+error: aborting due to 7 previous errors
+
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 f69bc1318..6ffa401d7 100644
--- a/src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed
+++ b/src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-#![allow(clippy::unnecessary_cast)]
+#![allow(clippy::unnecessary_cast, clippy::useless_vec)]
fn main() {
let vec = vec![b'a', b'b', b'c'];
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 eae36c277..de1f86cb8 100644
--- a/src/tools/clippy/tests/ui/ptr_offset_with_cast.rs
+++ b/src/tools/clippy/tests/ui/ptr_offset_with_cast.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-#![allow(clippy::unnecessary_cast)]
+#![allow(clippy::unnecessary_cast, clippy::useless_vec)]
fn main() {
let vec = vec![b'a', b'b', b'c'];
diff --git a/src/tools/clippy/tests/ui/pub_with_shorthand.fixed b/src/tools/clippy/tests/ui/pub_with_shorthand.fixed
new file mode 100644
index 000000000..a774faa0a
--- /dev/null
+++ b/src/tools/clippy/tests/ui/pub_with_shorthand.fixed
@@ -0,0 +1,38 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![feature(custom_inner_attributes)]
+#![allow(clippy::needless_pub_self, unused)]
+#![warn(clippy::pub_with_shorthand)]
+#![no_main]
+#![rustfmt::skip] // rustfmt will remove `in`, understandable
+ // but very annoying for our purposes!
+
+#[macro_use]
+extern crate proc_macros;
+
+pub(in self) fn a() {}
+pub(in self) fn b() {}
+
+pub fn c() {}
+mod a {
+ pub(in super) fn d() {}
+ pub(in super) fn e() {}
+ pub(in self) fn f() {}
+ pub(in crate) fn k() {}
+ pub(in crate) fn m() {}
+ mod b {
+ pub(in crate::a) fn l() {}
+ }
+}
+
+external! {
+ pub(self) fn g() {}
+ pub(in self) fn h() {}
+}
+with_span! {
+ span
+ pub(self) fn i() {}
+ pub(in self) fn j() {}
+}
+
+// not really anything more to test. just a really simple lint overall
diff --git a/src/tools/clippy/tests/ui/pub_with_shorthand.rs b/src/tools/clippy/tests/ui/pub_with_shorthand.rs
new file mode 100644
index 000000000..4a4bbc187
--- /dev/null
+++ b/src/tools/clippy/tests/ui/pub_with_shorthand.rs
@@ -0,0 +1,38 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![feature(custom_inner_attributes)]
+#![allow(clippy::needless_pub_self, unused)]
+#![warn(clippy::pub_with_shorthand)]
+#![no_main]
+#![rustfmt::skip] // rustfmt will remove `in`, understandable
+ // but very annoying for our purposes!
+
+#[macro_use]
+extern crate proc_macros;
+
+pub(self) fn a() {}
+pub(in self) fn b() {}
+
+pub fn c() {}
+mod a {
+ pub(in super) fn d() {}
+ pub(super) fn e() {}
+ pub(self) fn f() {}
+ pub(crate) fn k() {}
+ pub(in crate) fn m() {}
+ mod b {
+ pub(in crate::a) fn l() {}
+ }
+}
+
+external! {
+ pub(self) fn g() {}
+ pub(in self) fn h() {}
+}
+with_span! {
+ span
+ pub(self) fn i() {}
+ pub(in self) fn j() {}
+}
+
+// not really anything more to test. just a really simple lint overall
diff --git a/src/tools/clippy/tests/ui/pub_with_shorthand.stderr b/src/tools/clippy/tests/ui/pub_with_shorthand.stderr
new file mode 100644
index 000000000..323b5a23b
--- /dev/null
+++ b/src/tools/clippy/tests/ui/pub_with_shorthand.stderr
@@ -0,0 +1,28 @@
+error: usage of `pub` without `in`
+ --> $DIR/pub_with_shorthand.rs:13:1
+ |
+LL | pub(self) fn a() {}
+ | ^^^^^^^^^ help: add it: `pub(in self)`
+ |
+ = note: `-D clippy::pub-with-shorthand` implied by `-D warnings`
+
+error: usage of `pub` without `in`
+ --> $DIR/pub_with_shorthand.rs:19:5
+ |
+LL | pub(super) fn e() {}
+ | ^^^^^^^^^^ help: add it: `pub(in super)`
+
+error: usage of `pub` without `in`
+ --> $DIR/pub_with_shorthand.rs:20:5
+ |
+LL | pub(self) fn f() {}
+ | ^^^^^^^^^ help: add it: `pub(in self)`
+
+error: usage of `pub` without `in`
+ --> $DIR/pub_with_shorthand.rs:21:5
+ |
+LL | pub(crate) fn k() {}
+ | ^^^^^^^^^^ help: add it: `pub(in crate)`
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui/pub_without_shorthand.fixed b/src/tools/clippy/tests/ui/pub_without_shorthand.fixed
new file mode 100644
index 000000000..fdb49ac4d
--- /dev/null
+++ b/src/tools/clippy/tests/ui/pub_without_shorthand.fixed
@@ -0,0 +1,38 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![feature(custom_inner_attributes)]
+#![allow(clippy::needless_pub_self, unused)]
+#![warn(clippy::pub_without_shorthand)]
+#![no_main]
+#![rustfmt::skip] // rustfmt will remove `in`, understandable
+ // but very annoying for our purposes!
+
+#[macro_use]
+extern crate proc_macros;
+
+pub(self) fn a() {}
+pub(self) fn b() {}
+
+pub fn c() {}
+mod a {
+ pub(super) fn d() {}
+ pub(super) fn e() {}
+ pub(self) fn f() {}
+ pub(crate) fn k() {}
+ pub(crate) fn m() {}
+ mod b {
+ pub(in crate::a) fn l() {}
+ }
+}
+
+external! {
+ pub(self) fn g() {}
+ pub(in self) fn h() {}
+}
+with_span! {
+ span
+ pub(self) fn i() {}
+ pub(in self) fn j() {}
+}
+
+// not really anything more to test. just a really simple lint overall
diff --git a/src/tools/clippy/tests/ui/pub_without_shorthand.rs b/src/tools/clippy/tests/ui/pub_without_shorthand.rs
new file mode 100644
index 000000000..1f2ef7ece
--- /dev/null
+++ b/src/tools/clippy/tests/ui/pub_without_shorthand.rs
@@ -0,0 +1,38 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![feature(custom_inner_attributes)]
+#![allow(clippy::needless_pub_self, unused)]
+#![warn(clippy::pub_without_shorthand)]
+#![no_main]
+#![rustfmt::skip] // rustfmt will remove `in`, understandable
+ // but very annoying for our purposes!
+
+#[macro_use]
+extern crate proc_macros;
+
+pub(self) fn a() {}
+pub(in self) fn b() {}
+
+pub fn c() {}
+mod a {
+ pub(in super) fn d() {}
+ pub(super) fn e() {}
+ pub(self) fn f() {}
+ pub(crate) fn k() {}
+ pub(in crate) fn m() {}
+ mod b {
+ pub(in crate::a) fn l() {}
+ }
+}
+
+external! {
+ pub(self) fn g() {}
+ pub(in self) fn h() {}
+}
+with_span! {
+ span
+ pub(self) fn i() {}
+ pub(in self) fn j() {}
+}
+
+// not really anything more to test. just a really simple lint overall
diff --git a/src/tools/clippy/tests/ui/pub_without_shorthand.stderr b/src/tools/clippy/tests/ui/pub_without_shorthand.stderr
new file mode 100644
index 000000000..a18c9bf89
--- /dev/null
+++ b/src/tools/clippy/tests/ui/pub_without_shorthand.stderr
@@ -0,0 +1,22 @@
+error: usage of `pub` with `in`
+ --> $DIR/pub_without_shorthand.rs:14:1
+ |
+LL | pub(in self) fn b() {}
+ | ^^^^^^^^^^^^ help: remove it: `pub(self)`
+ |
+ = note: `-D clippy::pub-without-shorthand` implied by `-D warnings`
+
+error: usage of `pub` with `in`
+ --> $DIR/pub_without_shorthand.rs:18:5
+ |
+LL | pub(in super) fn d() {}
+ | ^^^^^^^^^^^^^ help: remove it: `pub(super)`
+
+error: usage of `pub` with `in`
+ --> $DIR/pub_without_shorthand.rs:22:5
+ |
+LL | pub(in crate) fn m() {}
+ | ^^^^^^^^^^^^^ help: remove it: `pub(crate)`
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/question_mark.fixed b/src/tools/clippy/tests/ui/question_mark.fixed
index 7f1660f31..2d8920ccc 100644
--- a/src/tools/clippy/tests/ui/question_mark.fixed
+++ b/src/tools/clippy/tests/ui/question_mark.fixed
@@ -1,4 +1,5 @@
//@run-rustfix
+#![feature(try_blocks)]
#![allow(unreachable_code)]
#![allow(dead_code)]
#![allow(clippy::unnecessary_wraps)]
@@ -227,6 +228,27 @@ fn pattern() -> Result<(), PatternedError> {
fn main() {}
+// `?` is not the same as `return None;` if inside of a try block
+fn issue8628(a: Option<u32>) -> Option<u32> {
+ let b: Option<u32> = try {
+ if a.is_none() {
+ return None;
+ }
+ 32
+ };
+ b.or(Some(128))
+}
+
+fn issue6828_nested_body() -> Option<u32> {
+ try {
+ fn f2(a: Option<i32>) -> Option<i32> {
+ a?;
+ Some(32)
+ }
+ 123
+ }
+}
+
// should not lint, `?` operator not available in const context
const fn issue9175(option: Option<()>) -> Option<()> {
if option.is_none() {
diff --git a/src/tools/clippy/tests/ui/question_mark.rs b/src/tools/clippy/tests/ui/question_mark.rs
index a90eae50e..69451c17e 100644
--- a/src/tools/clippy/tests/ui/question_mark.rs
+++ b/src/tools/clippy/tests/ui/question_mark.rs
@@ -1,4 +1,5 @@
//@run-rustfix
+#![feature(try_blocks)]
#![allow(unreachable_code)]
#![allow(dead_code)]
#![allow(clippy::unnecessary_wraps)]
@@ -263,6 +264,31 @@ fn pattern() -> Result<(), PatternedError> {
fn main() {}
+// `?` is not the same as `return None;` if inside of a try block
+fn issue8628(a: Option<u32>) -> Option<u32> {
+ let b: Option<u32> = try {
+ if a.is_none() {
+ return None;
+ }
+ 32
+ };
+ b.or(Some(128))
+}
+
+fn issue6828_nested_body() -> Option<u32> {
+ try {
+ fn f2(a: Option<i32>) -> Option<i32> {
+ if a.is_none() {
+ return None;
+ // do lint here, the outer `try` is not relevant here
+ // https://github.com/rust-lang/rust-clippy/pull/11001#issuecomment-1610636867
+ }
+ Some(32)
+ }
+ 123
+ }
+}
+
// should not lint, `?` operator not available in const context
const fn issue9175(option: Option<()>) -> Option<()> {
if option.is_none() {
diff --git a/src/tools/clippy/tests/ui/question_mark.stderr b/src/tools/clippy/tests/ui/question_mark.stderr
index 23172d7e5..2cfd75863 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:7:5
+ --> $DIR/question_mark.rs:8:5
|
LL | / if a.is_none() {
LL | | return None;
@@ -9,7 +9,7 @@ LL | | }
= note: `-D clippy::question-mark` implied by `-D warnings`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:52:9
+ --> $DIR/question_mark.rs:53:9
|
LL | / if (self.opt).is_none() {
LL | | return None;
@@ -17,7 +17,7 @@ LL | | }
| |_________^ help: replace it with: `(self.opt)?;`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:56:9
+ --> $DIR/question_mark.rs:57:9
|
LL | / if self.opt.is_none() {
LL | | return None
@@ -25,7 +25,7 @@ LL | | }
| |_________^ help: replace it with: `self.opt?;`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:60:17
+ --> $DIR/question_mark.rs:61:17
|
LL | let _ = if self.opt.is_none() {
| _________________^
@@ -36,7 +36,7 @@ LL | | };
| |_________^ help: replace it with: `Some(self.opt?)`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:66:17
+ --> $DIR/question_mark.rs:67:17
|
LL | let _ = if let Some(x) = self.opt {
| _________________^
@@ -47,7 +47,7 @@ LL | | };
| |_________^ help: replace it with: `self.opt?`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:83:9
+ --> $DIR/question_mark.rs:84:9
|
LL | / if self.opt.is_none() {
LL | | return None;
@@ -55,7 +55,7 @@ LL | | }
| |_________^ help: replace it with: `self.opt.as_ref()?;`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:91:9
+ --> $DIR/question_mark.rs:92:9
|
LL | / if self.opt.is_none() {
LL | | return None;
@@ -63,7 +63,7 @@ LL | | }
| |_________^ help: replace it with: `self.opt.as_ref()?;`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:99:9
+ --> $DIR/question_mark.rs:100:9
|
LL | / if self.opt.is_none() {
LL | | return None;
@@ -71,7 +71,7 @@ LL | | }
| |_________^ help: replace it with: `self.opt.as_ref()?;`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:106:26
+ --> $DIR/question_mark.rs:107:26
|
LL | let v: &Vec<_> = if let Some(ref v) = self.opt {
| __________________________^
@@ -82,7 +82,7 @@ LL | | };
| |_________^ help: replace it with: `self.opt.as_ref()?`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:116:17
+ --> $DIR/question_mark.rs:117:17
|
LL | let v = if let Some(v) = self.opt {
| _________________^
@@ -93,7 +93,7 @@ LL | | };
| |_________^ help: replace it with: `self.opt?`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:131:5
+ --> $DIR/question_mark.rs:132:5
|
LL | / if f().is_none() {
LL | | return None;
@@ -101,13 +101,13 @@ LL | | }
| |_____^ help: replace it with: `f()?;`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:143:13
+ --> $DIR/question_mark.rs:144:13
|
LL | let _ = if let Ok(x) = x { x } else { return x };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x?`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:145:5
+ --> $DIR/question_mark.rs:146:5
|
LL | / if x.is_err() {
LL | | return x;
@@ -115,7 +115,7 @@ LL | | }
| |_____^ help: replace it with: `x?;`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:196:5
+ --> $DIR/question_mark.rs:197:5
|
LL | / if let Err(err) = func_returning_result() {
LL | | return Err(err);
@@ -123,12 +123,22 @@ LL | | }
| |_____^ help: replace it with: `func_returning_result()?;`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:203:5
+ --> $DIR/question_mark.rs:204:5
|
LL | / if let Err(err) = func_returning_result() {
LL | | return Err(err);
LL | | }
| |_____^ help: replace it with: `func_returning_result()?;`
-error: aborting due to 15 previous errors
+error: this block may be rewritten with the `?` operator
+ --> $DIR/question_mark.rs:281:13
+ |
+LL | / if a.is_none() {
+LL | | return None;
+LL | | // do lint here, the outer `try` is not relevant here
+LL | | // https://github.com/rust-lang/rust-clippy/pull/11001#issuecomment-1610636867
+LL | | }
+ | |_____________^ help: replace it with: `a?;`
+
+error: aborting due to 16 previous errors
diff --git a/src/tools/clippy/tests/ui/range.rs b/src/tools/clippy/tests/ui/range.rs
index 628282509..46edf0921 100644
--- a/src/tools/clippy/tests/ui/range.rs
+++ b/src/tools/clippy/tests/ui/range.rs
@@ -1,3 +1,4 @@
+#![allow(clippy::useless_vec)]
#[warn(clippy::range_zip_with_len)]
fn main() {
let v1 = vec![1, 2, 3];
diff --git a/src/tools/clippy/tests/ui/range.stderr b/src/tools/clippy/tests/ui/range.stderr
index dcb506137..ac83b67fd 100644
--- a/src/tools/clippy/tests/ui/range.stderr
+++ b/src/tools/clippy/tests/ui/range.stderr
@@ -1,5 +1,5 @@
error: it is more idiomatic to use `v1.iter().enumerate()`
- --> $DIR/range.rs:5:14
+ --> $DIR/range.rs:6:14
|
LL | let _x = v1.iter().zip(0..v1.len());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
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 384060e6e..53fcbf3c4 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,4 +1,5 @@
#![warn(clippy::rc_clone_in_vec_init)]
+#![allow(clippy::useless_vec)]
use std::sync::{Arc, Mutex};
fn main() {}
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 7814f5b54..a8fd28b84 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,5 +1,5 @@
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/arc.rs:7:13
+ --> $DIR/arc.rs:8:13
|
LL | let v = vec![Arc::new("x".to_string()); 2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -23,7 +23,7 @@ LL ~ };
|
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/arc.rs:15:21
+ --> $DIR/arc.rs:16:21
|
LL | let v = vec![Arc::new("x".to_string()); 2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -46,7 +46,7 @@ LL ~ };
|
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/arc.rs:21:13
+ --> $DIR/arc.rs:22:13
|
LL | let v = vec![
| _____________^
@@ -76,7 +76,7 @@ LL ~ };
|
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/arc.rs:30:14
+ --> $DIR/arc.rs:31:14
|
LL | let v1 = vec![
| ______________^
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 0394457fe..88ea39bf9 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,4 +1,5 @@
#![warn(clippy::rc_clone_in_vec_init)]
+#![allow(clippy::useless_vec)]
use std::rc::Rc;
use std::sync::Mutex;
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 80deb7cb9..eab464800 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,5 +1,5 @@
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/rc.rs:8:13
+ --> $DIR/rc.rs:9:13
|
LL | let v = vec![Rc::new("x".to_string()); 2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -23,7 +23,7 @@ LL ~ };
|
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/rc.rs:16:21
+ --> $DIR/rc.rs:17:21
|
LL | let v = vec![Rc::new("x".to_string()); 2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -46,7 +46,7 @@ LL ~ };
|
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/rc.rs:22:13
+ --> $DIR/rc.rs:23:13
|
LL | let v = vec![
| _____________^
@@ -76,7 +76,7 @@ LL ~ };
|
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/rc.rs:31:14
+ --> $DIR/rc.rs:32:14
|
LL | let v1 = vec![
| ______________^
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 693c9b553..031421650 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,4 +1,5 @@
#![warn(clippy::rc_clone_in_vec_init)]
+#![allow(clippy::useless_vec)]
use std::rc::{Rc, Weak as UnSyncWeak};
use std::sync::{Arc, Mutex, Weak as SyncWeak};
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 789e14a30..1f7a849b1 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,5 +1,5 @@
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/weak.rs:8:13
+ --> $DIR/weak.rs:9:13
|
LL | let v = vec![SyncWeak::<u32>::new(); 2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -23,7 +23,7 @@ LL ~ };
|
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/weak.rs:9:14
+ --> $DIR/weak.rs:10:14
|
LL | let v2 = vec![UnSyncWeak::<u32>::new(); 2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -46,7 +46,7 @@ LL ~ };
|
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/weak.rs:11:13
+ --> $DIR/weak.rs:12:13
|
LL | let v = vec![Rc::downgrade(&Rc::new("x".to_string())); 2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -69,7 +69,7 @@ LL ~ };
|
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/weak.rs:12:13
+ --> $DIR/weak.rs:13:13
|
LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -92,7 +92,7 @@ LL ~ };
|
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/weak.rs:20:21
+ --> $DIR/weak.rs:21:21
|
LL | let v = vec![Arc::downgrade(&Arc::new("x".to_string())); 2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -115,7 +115,7 @@ LL ~ };
|
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/weak.rs:21:22
+ --> $DIR/weak.rs:22:22
|
LL | let v2 = vec![Rc::downgrade(&Rc::new("x".to_string())); 2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -138,7 +138,7 @@ LL ~ };
|
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/weak.rs:27:13
+ --> $DIR/weak.rs:28:13
|
LL | let v = vec![
| _____________^
@@ -168,7 +168,7 @@ LL ~ };
|
error: initializing a reference-counted pointer in `vec![elem; len]`
- --> $DIR/weak.rs:36:14
+ --> $DIR/weak.rs:37:14
|
LL | let v1 = vec![
| ______________^
diff --git a/src/tools/clippy/tests/ui/redundant_at_rest_pattern.fixed b/src/tools/clippy/tests/ui/redundant_at_rest_pattern.fixed
new file mode 100644
index 000000000..080cf13b5
--- /dev/null
+++ b/src/tools/clippy/tests/ui/redundant_at_rest_pattern.fixed
@@ -0,0 +1,27 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(irrefutable_let_patterns, unused)]
+#![warn(clippy::redundant_at_rest_pattern)]
+
+#[macro_use]
+extern crate proc_macros;
+
+fn main() {
+ if let a = [()] {}
+ if let ref a = [()] {}
+ if let mut a = [()] {}
+ if let ref mut a = [()] {}
+ let v = vec![()];
+ if let a = &*v {}
+ let s = &[()];
+ if let a = s {}
+ // Don't lint
+ if let [..] = &*v {}
+ if let [a] = &*v {}
+ if let [()] = &*v {}
+ if let [first, rest @ ..] = &*v {}
+ if let a = [()] {}
+ external! {
+ if let [a @ ..] = [()] {}
+ }
+}
diff --git a/src/tools/clippy/tests/ui/redundant_at_rest_pattern.rs b/src/tools/clippy/tests/ui/redundant_at_rest_pattern.rs
new file mode 100644
index 000000000..a8a802829
--- /dev/null
+++ b/src/tools/clippy/tests/ui/redundant_at_rest_pattern.rs
@@ -0,0 +1,27 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(irrefutable_let_patterns, unused)]
+#![warn(clippy::redundant_at_rest_pattern)]
+
+#[macro_use]
+extern crate proc_macros;
+
+fn main() {
+ if let [a @ ..] = [()] {}
+ if let [ref a @ ..] = [()] {}
+ if let [mut a @ ..] = [()] {}
+ if let [ref mut a @ ..] = [()] {}
+ let v = vec![()];
+ if let [a @ ..] = &*v {}
+ let s = &[()];
+ if let [a @ ..] = s {}
+ // Don't lint
+ if let [..] = &*v {}
+ if let [a] = &*v {}
+ if let [()] = &*v {}
+ if let [first, rest @ ..] = &*v {}
+ if let a = [()] {}
+ external! {
+ if let [a @ ..] = [()] {}
+ }
+}
diff --git a/src/tools/clippy/tests/ui/redundant_at_rest_pattern.stderr b/src/tools/clippy/tests/ui/redundant_at_rest_pattern.stderr
new file mode 100644
index 000000000..e2a4d9ffd
--- /dev/null
+++ b/src/tools/clippy/tests/ui/redundant_at_rest_pattern.stderr
@@ -0,0 +1,40 @@
+error: using a rest pattern to bind an entire slice to a local
+ --> $DIR/redundant_at_rest_pattern.rs:10: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`
+
+error: using a rest pattern to bind an entire slice to a local
+ --> $DIR/redundant_at_rest_pattern.rs:11: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
+ |
+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
+ |
+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
+ |
+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
+ |
+LL | if let [a @ ..] = s {}
+ | ^^^^^^^^ help: this is better represented with just the binding: `a`
+
+error: aborting due to 6 previous errors
+
diff --git a/src/tools/clippy/tests/ui/redundant_clone.fixed b/src/tools/clippy/tests/ui/redundant_clone.fixed
index cb9583aa6..5037c08eb 100644
--- a/src/tools/clippy/tests/ui/redundant_clone.fixed
+++ b/src/tools/clippy/tests/ui/redundant_clone.fixed
@@ -2,7 +2,12 @@
// rustfix-only-machine-applicable
#![feature(lint_reasons)]
#![warn(clippy::redundant_clone)]
-#![allow(clippy::drop_non_drop, clippy::implicit_clone, clippy::uninlined_format_args)]
+#![allow(
+ clippy::drop_non_drop,
+ clippy::implicit_clone,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_literal_unwrap
+)]
use std::ffi::OsString;
use std::path::Path;
diff --git a/src/tools/clippy/tests/ui/redundant_clone.rs b/src/tools/clippy/tests/ui/redundant_clone.rs
index e5aeacbb5..501898bf1 100644
--- a/src/tools/clippy/tests/ui/redundant_clone.rs
+++ b/src/tools/clippy/tests/ui/redundant_clone.rs
@@ -2,7 +2,12 @@
// rustfix-only-machine-applicable
#![feature(lint_reasons)]
#![warn(clippy::redundant_clone)]
-#![allow(clippy::drop_non_drop, clippy::implicit_clone, clippy::uninlined_format_args)]
+#![allow(
+ clippy::drop_non_drop,
+ clippy::implicit_clone,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_literal_unwrap
+)]
use std::ffi::OsString;
use std::path::Path;
diff --git a/src/tools/clippy/tests/ui/redundant_clone.stderr b/src/tools/clippy/tests/ui/redundant_clone.stderr
index bb5c602d6..8660c0e1f 100644
--- a/src/tools/clippy/tests/ui/redundant_clone.stderr
+++ b/src/tools/clippy/tests/ui/redundant_clone.stderr
@@ -1,180 +1,180 @@
error: redundant clone
- --> $DIR/redundant_clone.rs:11:42
+ --> $DIR/redundant_clone.rs:16:42
|
LL | let _s = ["lorem", "ipsum"].join(" ").to_string();
| ^^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:11:14
+ --> $DIR/redundant_clone.rs:16:14
|
LL | let _s = ["lorem", "ipsum"].join(" ").to_string();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `-D clippy::redundant-clone` implied by `-D warnings`
error: redundant clone
- --> $DIR/redundant_clone.rs:14:15
+ --> $DIR/redundant_clone.rs:19:15
|
LL | let _s = s.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:14:14
+ --> $DIR/redundant_clone.rs:19:14
|
LL | let _s = s.clone();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:17:15
+ --> $DIR/redundant_clone.rs:22:15
|
LL | let _s = s.to_string();
| ^^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:17:14
+ --> $DIR/redundant_clone.rs:22:14
|
LL | let _s = s.to_string();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:20:15
+ --> $DIR/redundant_clone.rs:25:15
|
LL | let _s = s.to_owned();
| ^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:20:14
+ --> $DIR/redundant_clone.rs:25:14
|
LL | let _s = s.to_owned();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:22:42
+ --> $DIR/redundant_clone.rs:27:42
|
LL | let _s = Path::new("/a/b/").join("c").to_owned();
| ^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:22:14
+ --> $DIR/redundant_clone.rs:27:14
|
LL | let _s = Path::new("/a/b/").join("c").to_owned();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:24:42
+ --> $DIR/redundant_clone.rs:29: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:24:14
+ --> $DIR/redundant_clone.rs:29:14
|
LL | let _s = Path::new("/a/b/").join("c").to_path_buf();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:26:29
+ --> $DIR/redundant_clone.rs:31:29
|
LL | let _s = OsString::new().to_owned();
| ^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:26:14
+ --> $DIR/redundant_clone.rs:31:14
|
LL | let _s = OsString::new().to_owned();
| ^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:28:29
+ --> $DIR/redundant_clone.rs:33:29
|
LL | let _s = OsString::new().to_os_string();
| ^^^^^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:28:14
+ --> $DIR/redundant_clone.rs:33:14
|
LL | let _s = OsString::new().to_os_string();
| ^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:39:19
+ --> $DIR/redundant_clone.rs:44:19
|
LL | let _t = tup.0.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:39:14
+ --> $DIR/redundant_clone.rs:44:14
|
LL | let _t = tup.0.clone();
| ^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:71:25
+ --> $DIR/redundant_clone.rs:76: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:71:24
+ --> $DIR/redundant_clone.rs:76:24
|
LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) }
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:128:15
+ --> $DIR/redundant_clone.rs:133:15
|
LL | let _s = s.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:128:14
+ --> $DIR/redundant_clone.rs:133:14
|
LL | let _s = s.clone();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:129:15
+ --> $DIR/redundant_clone.rs:134:15
|
LL | let _t = t.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:129:14
+ --> $DIR/redundant_clone.rs:134:14
|
LL | let _t = t.clone();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:139:19
+ --> $DIR/redundant_clone.rs:144:19
|
LL | let _f = f.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:139:18
+ --> $DIR/redundant_clone.rs:144:18
|
LL | let _f = f.clone();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:151:14
+ --> $DIR/redundant_clone.rs:156:14
|
LL | let y = x.clone().join("matthias");
| ^^^^^^^^ help: remove this
|
note: cloned value is neither consumed nor mutated
- --> $DIR/redundant_clone.rs:151:13
+ --> $DIR/redundant_clone.rs:156:13
|
LL | let y = x.clone().join("matthias");
| ^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:205:11
+ --> $DIR/redundant_clone.rs:210:11
|
LL | foo(&x.clone(), move || {
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:205:10
+ --> $DIR/redundant_clone.rs:210:10
|
LL | foo(&x.clone(), move || {
| ^
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 61aed2733..f3669a669 100644
--- a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed
+++ b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed
@@ -3,6 +3,7 @@
#![feature(async_closure)]
#![warn(clippy::redundant_closure_call)]
#![allow(clippy::redundant_async_block)]
+#![allow(clippy::type_complexity)]
#![allow(unused)]
async fn something() -> u32 {
@@ -38,4 +39,50 @@ fn main() {
};
}
m2!();
+ issue9956();
+}
+
+fn issue9956() {
+ assert_eq!(43, 42);
+
+ // ... and some more interesting cases I've found while implementing the fix
+
+ // not actually immediately calling the closure:
+ let a = (|| 42);
+ dbg!(a());
+
+ // immediately calling it inside of a macro
+ dbg!(42);
+
+ // immediately calling only one closure, so we can't remove the other ones
+ let a = (|| || 123);
+ dbg!(a()());
+
+ // nested async closures
+ let a = async { 1 };
+ let h = async { a.await };
+
+ // macro expansion tests
+ macro_rules! echo {
+ ($e:expr) => {
+ $e
+ };
+ }
+ let a = 1;
+ assert_eq!(a, 1);
+ let a = 123;
+ assert_eq!(a, 123);
+
+ // chaining calls, but not closures
+ fn x() -> fn() -> fn() -> fn() -> i32 {
+ || || || 42
+ }
+ let _ = x()()()();
+
+ fn bar() -> fn(i32, i32) {
+ foo
+ }
+ fn foo(_: i32, _: i32) {}
+ bar()(42, 5);
+ foo(42, 5);
}
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 56b286635..db8c7f80d 100644
--- a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs
+++ b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs
@@ -3,6 +3,7 @@
#![feature(async_closure)]
#![warn(clippy::redundant_closure_call)]
#![allow(clippy::redundant_async_block)]
+#![allow(clippy::type_complexity)]
#![allow(unused)]
async fn something() -> u32 {
@@ -38,4 +39,50 @@ fn main() {
};
}
m2!();
+ issue9956();
+}
+
+fn issue9956() {
+ assert_eq!((|| || 43)()(), 42);
+
+ // ... and some more interesting cases I've found while implementing the fix
+
+ // not actually immediately calling the closure:
+ let a = (|| 42);
+ dbg!(a());
+
+ // immediately calling it inside of a macro
+ dbg!((|| 42)());
+
+ // immediately calling only one closure, so we can't remove the other ones
+ let a = (|| || || 123)();
+ dbg!(a()());
+
+ // nested async closures
+ let a = (|| || || || async || 1)()()()()();
+ let h = async { a.await };
+
+ // macro expansion tests
+ macro_rules! echo {
+ ($e:expr) => {
+ $e
+ };
+ }
+ let a = (|| echo!(|| echo!(|| 1)))()()();
+ assert_eq!(a, 1);
+ let a = (|| echo!((|| 123)))()();
+ assert_eq!(a, 123);
+
+ // chaining calls, but not closures
+ fn x() -> fn() -> fn() -> fn() -> i32 {
+ || || || 42
+ }
+ let _ = x()()()();
+
+ fn bar() -> fn(i32, i32) {
+ foo
+ }
+ fn foo(_: i32, _: i32) {}
+ bar()((|| || 42)()(), 5);
+ foo((|| || 42)()(), 5);
}
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 8a1f07716..618f5e071 100644
--- a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.stderr
+++ b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.stderr
@@ -1,5 +1,5 @@
error: try not to call a closure in the expression where it is declared
- --> $DIR/redundant_closure_call_fixable.rs:17:13
+ --> $DIR/redundant_closure_call_fixable.rs:18:13
|
LL | let a = (|| 42)();
| ^^^^^^^^^ help: try doing something like: `42`
@@ -7,7 +7,7 @@ LL | let a = (|| 42)();
= note: `-D clippy::redundant-closure-call` implied by `-D warnings`
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:19:13
|
LL | let b = (async || {
| _____________^
@@ -27,7 +27,7 @@ LL ~ };
|
error: try not to call a closure in the expression where it is declared
- --> $DIR/redundant_closure_call_fixable.rs:23:13
+ --> $DIR/redundant_closure_call_fixable.rs:24:13
|
LL | let c = (|| {
| _____________^
@@ -47,13 +47,13 @@ LL ~ };
|
error: try not to call a closure in the expression where it is declared
- --> $DIR/redundant_closure_call_fixable.rs:28:13
+ --> $DIR/redundant_closure_call_fixable.rs:29: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:37:13
+ --> $DIR/redundant_closure_call_fixable.rs:38:13
|
LL | (|| m!())()
| ^^^^^^^^^^^ help: try doing something like: `m!()`
@@ -64,7 +64,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:32:13
+ --> $DIR/redundant_closure_call_fixable.rs:33:13
|
LL | (|| 0)()
| ^^^^^^^^ help: try doing something like: `0`
@@ -74,5 +74,53 @@ 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: aborting due to 6 previous errors
+error: try not to call a closure in the expression where it is declared
+ --> $DIR/redundant_closure_call_fixable.rs:46: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
+ |
+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
+ |
+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
+ |
+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
+ |
+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
+ |
+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
+ |
+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
+ |
+LL | foo((|| || 42)()(), 5);
+ | ^^^^^^^^^^^^^^ help: try doing something like: `42`
+
+error: aborting due to 14 previous errors
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 bebdf8971..d1134de5a 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
@@ -2,7 +2,12 @@
// Issue #5746
#![warn(clippy::redundant_pattern_matching)]
-#![allow(clippy::if_same_then_else, clippy::equatable_if_let)]
+#![allow(
+ clippy::if_same_then_else,
+ clippy::equatable_if_let,
+ clippy::needless_if,
+ clippy::needless_else
+)]
use std::task::Poll::{Pending, Ready};
fn main() {
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 8fb6ed5f7..d144086e7 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
@@ -2,7 +2,12 @@
// Issue #5746
#![warn(clippy::redundant_pattern_matching)]
-#![allow(clippy::if_same_then_else, clippy::equatable_if_let)]
+#![allow(
+ clippy::if_same_then_else,
+ clippy::equatable_if_let,
+ clippy::needless_if,
+ clippy::needless_else
+)]
use std::task::Poll::{Pending, Ready};
fn main() {
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 23f08103f..e9ea3f2e6 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:12:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:17:12
|
LL | if let Ok(_) = m.lock() {}
| -------^^^^^----------- help: try this: `if m.lock().is_ok()`
@@ -9,7 +9,7 @@ LL | if let Ok(_) = m.lock() {}
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_drop_order.rs:13:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:18:12
|
LL | if let Err(_) = Err::<(), _>(m.lock().unwrap().0) {}
| -------^^^^^^------------------------------------ help: try this: `if Err::<(), _>(m.lock().unwrap().0).is_err()`
@@ -18,7 +18,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:16:16
+ --> $DIR/redundant_pattern_matching_drop_order.rs:21:16
|
LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {}
| -------^^^^^----------------------------------------- help: try this: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()`
@@ -27,7 +27,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:18:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:23:12
|
LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {
| -------^^^^^----------------------------------------- help: try this: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()`
@@ -36,31 +36,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:21:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:26:12
|
LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {}
| -------^^^^^----------------------------------------- help: try this: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_drop_order.rs:22:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:27:12
|
LL | if let Err(_) = Err::<std::sync::MutexGuard<()>, _>(()) {}
| -------^^^^^^------------------------------------------ help: try this: `if Err::<std::sync::MutexGuard<()>, _>(()).is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_drop_order.rs:24:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:29:12
|
LL | if let Ok(_) = Ok::<_, ()>(String::new()) {}
| -------^^^^^----------------------------- help: try this: `if Ok::<_, ()>(String::new()).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_drop_order.rs:25:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:30:12
|
LL | if let Err(_) = Err::<(), _>((String::new(), ())) {}
| -------^^^^^^------------------------------------ help: try this: `if Err::<(), _>((String::new(), ())).is_err()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_drop_order.rs:28:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:33:12
|
LL | if let Some(_) = Some(m.lock()) {}
| -------^^^^^^^----------------- help: try this: `if Some(m.lock()).is_some()`
@@ -69,7 +69,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:29:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:34:12
|
LL | if let Some(_) = Some(m.lock().unwrap().0) {}
| -------^^^^^^^---------------------------- help: try this: `if Some(m.lock().unwrap().0).is_some()`
@@ -78,7 +78,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:32:16
+ --> $DIR/redundant_pattern_matching_drop_order.rs:37:16
|
LL | if let None = None::<std::sync::MutexGuard<()>> {}
| -------^^^^------------------------------------ help: try this: `if None::<std::sync::MutexGuard<()>>.is_none()`
@@ -87,7 +87,7 @@ LL | if let None = None::<std::sync::MutexGuard<()>> {}
= 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:34:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:39:12
|
LL | if let None = None::<std::sync::MutexGuard<()>> {
| -------^^^^------------------------------------ help: try this: `if None::<std::sync::MutexGuard<()>>.is_none()`
@@ -96,25 +96,25 @@ LL | if let None = None::<std::sync::MutexGuard<()>> {
= 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:38:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:43:12
|
LL | if let None = None::<std::sync::MutexGuard<()>> {}
| -------^^^^------------------------------------ help: try this: `if None::<std::sync::MutexGuard<()>>.is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_drop_order.rs:40:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:45:12
|
LL | if let Some(_) = Some(String::new()) {}
| -------^^^^^^^---------------------- help: try this: `if Some(String::new()).is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_drop_order.rs:41:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:46:12
|
LL | if let Some(_) = Some((String::new(), ())) {}
| -------^^^^^^^---------------------------- help: try this: `if Some((String::new(), ())).is_some()`
error: redundant pattern matching, consider using `is_ready()`
- --> $DIR/redundant_pattern_matching_drop_order.rs:44:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:49:12
|
LL | if let Ready(_) = Ready(m.lock()) {}
| -------^^^^^^^^------------------ help: try this: `if Ready(m.lock()).is_ready()`
@@ -123,7 +123,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:45:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:50:12
|
LL | if let Ready(_) = Ready(m.lock().unwrap().0) {}
| -------^^^^^^^^----------------------------- help: try this: `if Ready(m.lock().unwrap().0).is_ready()`
@@ -132,7 +132,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:48:16
+ --> $DIR/redundant_pattern_matching_drop_order.rs:53:16
|
LL | if let Pending = Pending::<std::sync::MutexGuard<()>> {}
| -------^^^^^^^--------------------------------------- help: try this: `if Pending::<std::sync::MutexGuard<()>>.is_pending()`
@@ -141,7 +141,7 @@ LL | if let Pending = Pending::<std::sync::MutexGuard<()>> {}
= 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:50:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:55:12
|
LL | if let Pending = Pending::<std::sync::MutexGuard<()>> {
| -------^^^^^^^--------------------------------------- help: try this: `if Pending::<std::sync::MutexGuard<()>>.is_pending()`
@@ -150,19 +150,19 @@ LL | if let Pending = Pending::<std::sync::MutexGuard<()>> {
= 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:54:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:59:12
|
LL | if let Pending = Pending::<std::sync::MutexGuard<()>> {}
| -------^^^^^^^--------------------------------------- help: try this: `if Pending::<std::sync::MutexGuard<()>>.is_pending()`
error: redundant pattern matching, consider using `is_ready()`
- --> $DIR/redundant_pattern_matching_drop_order.rs:56:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:61:12
|
LL | if let Ready(_) = Ready(String::new()) {}
| -------^^^^^^^^----------------------- help: try this: `if Ready(String::new()).is_ready()`
error: redundant pattern matching, consider using `is_ready()`
- --> $DIR/redundant_pattern_matching_drop_order.rs:57:12
+ --> $DIR/redundant_pattern_matching_drop_order.rs:62:12
|
LL | if let Ready(_) = Ready((String::new(), ())) {}
| -------^^^^^^^^----------------------------- help: try this: `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 a9faf12cd..75ed14344 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed
@@ -4,6 +4,7 @@
#![allow(
clippy::match_like_matches_macro,
clippy::needless_bool,
+ clippy::needless_if,
clippy::uninlined_format_args
)]
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 574671d03..9ac77409f 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs
@@ -4,6 +4,7 @@
#![allow(
clippy::match_like_matches_macro,
clippy::needless_bool,
+ clippy::needless_if,
clippy::uninlined_format_args
)]
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 536b589de..6d1fb2964 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr
@@ -1,5 +1,5 @@
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:17:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:18:12
|
LL | if let V4(_) = &ipaddr {}
| -------^^^^^---------- help: try this: `if ipaddr.is_ipv4()`
@@ -7,31 +7,31 @@ LL | if let V4(_) = &ipaddr {}
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:19:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:20:12
|
LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
| -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:21:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:22:12
|
LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
| -------^^^^^-------------------------- help: try this: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:23:15
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:24:15
|
LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
| ----------^^^^^-------------------------- help: try this: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:25:15
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:26:15
|
LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
| ----------^^^^^-------------------------- help: try this: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:35:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:36:5
|
LL | / match V4(Ipv4Addr::LOCALHOST) {
LL | | V4(_) => true,
@@ -40,7 +40,7 @@ LL | | };
| |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:40:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:41:5
|
LL | / match V4(Ipv4Addr::LOCALHOST) {
LL | | V4(_) => false,
@@ -49,7 +49,7 @@ LL | | };
| |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:45:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:46:5
|
LL | / match V6(Ipv6Addr::LOCALHOST) {
LL | | V4(_) => false,
@@ -58,7 +58,7 @@ LL | | };
| |_____^ help: try this: `V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:50:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:51:5
|
LL | / match V6(Ipv6Addr::LOCALHOST) {
LL | | V4(_) => true,
@@ -67,49 +67,49 @@ LL | | };
| |_____^ help: try this: `V6(Ipv6Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:55:20
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:56:20
|
LL | let _ = if let V4(_) = V4(Ipv4Addr::LOCALHOST) {
| -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:63:20
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:64:20
|
LL | let _ = if let V4(_) = gen_ipaddr() {
| -------^^^^^--------------- help: try this: `if gen_ipaddr().is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:65:19
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:66:19
|
LL | } else if let V6(_) = gen_ipaddr() {
| -------^^^^^--------------- help: try this: `if gen_ipaddr().is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:77:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:78:12
|
LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
| -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:79:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:80:12
|
LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
| -------^^^^^-------------------------- help: try this: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:81:15
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:82:15
|
LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
| ----------^^^^^-------------------------- help: try this: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:83:15
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:84:15
|
LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
| ----------^^^^^-------------------------- help: try this: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:85:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:86:5
|
LL | / match V4(Ipv4Addr::LOCALHOST) {
LL | | V4(_) => true,
@@ -118,7 +118,7 @@ LL | | };
| |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:90:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:91: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 accdf1da9..a63ba5809 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed
@@ -5,6 +5,7 @@
#![allow(
unused_must_use,
clippy::needless_bool,
+ clippy::needless_if,
clippy::match_like_matches_macro,
clippy::equatable_if_let,
clippy::if_same_then_else
@@ -47,6 +48,7 @@ fn main() {
issue6067();
issue10726();
+ issue10803();
let _ = if gen_opt().is_some() {
1
@@ -107,3 +109,14 @@ fn issue10726() {
_ => false,
};
}
+
+fn issue10803() {
+ let x = Some(42);
+
+ let _ = x.is_some();
+
+ let _ = x.is_none();
+
+ // Don't lint
+ let _ = matches!(x, Some(16));
+}
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 ec684bdf7..631f90916 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.rs
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.rs
@@ -5,6 +5,7 @@
#![allow(
unused_must_use,
clippy::needless_bool,
+ clippy::needless_if,
clippy::match_like_matches_macro,
clippy::equatable_if_let,
clippy::if_same_then_else
@@ -56,6 +57,7 @@ fn main() {
issue6067();
issue10726();
+ issue10803();
let _ = if let Some(_) = gen_opt() {
1
@@ -134,3 +136,14 @@ fn issue10726() {
_ => false,
};
}
+
+fn issue10803() {
+ let x = Some(42);
+
+ let _ = matches!(x, Some(_));
+
+ let _ = matches!(x, None);
+
+ // Don't lint
+ let _ = matches!(x, Some(16));
+}
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 a69eb3905..717b603c4 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.stderr
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.stderr
@@ -1,5 +1,5 @@
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:14:12
+ --> $DIR/redundant_pattern_matching_option.rs:15:12
|
LL | if let None = None::<()> {}
| -------^^^^------------- help: try this: `if None::<()>.is_none()`
@@ -7,43 +7,43 @@ LL | if let None = None::<()> {}
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:16:12
+ --> $DIR/redundant_pattern_matching_option.rs:17:12
|
LL | if let Some(_) = Some(42) {}
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:18:12
+ --> $DIR/redundant_pattern_matching_option.rs:19:12
|
LL | if let Some(_) = Some(42) {
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:24:15
+ --> $DIR/redundant_pattern_matching_option.rs:25:15
|
LL | while let Some(_) = Some(42) {}
| ----------^^^^^^^----------- help: try this: `while Some(42).is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:26:15
+ --> $DIR/redundant_pattern_matching_option.rs:27:15
|
LL | while let None = Some(42) {}
| ----------^^^^----------- help: try this: `while Some(42).is_none()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:28:15
+ --> $DIR/redundant_pattern_matching_option.rs:29:15
|
LL | while let None = None::<()> {}
| ----------^^^^------------- help: try this: `while None::<()>.is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:31:15
+ --> $DIR/redundant_pattern_matching_option.rs:32:15
|
LL | while let Some(_) = v.pop() {
| ----------^^^^^^^---------- help: try this: `while v.pop().is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:39:5
+ --> $DIR/redundant_pattern_matching_option.rs:40:5
|
LL | / match Some(42) {
LL | | Some(_) => true,
@@ -52,7 +52,7 @@ LL | | };
| |_____^ help: try this: `Some(42).is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:44:5
+ --> $DIR/redundant_pattern_matching_option.rs:45:5
|
LL | / match None::<()> {
LL | | Some(_) => false,
@@ -61,7 +61,7 @@ LL | | };
| |_____^ help: try this: `None::<()>.is_none()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:49:13
+ --> $DIR/redundant_pattern_matching_option.rs:50:13
|
LL | let _ = match None::<()> {
| _____________^
@@ -71,55 +71,55 @@ LL | | };
| |_____^ help: try this: `None::<()>.is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:55:20
+ --> $DIR/redundant_pattern_matching_option.rs:56:20
|
LL | let _ = if let Some(_) = opt { true } else { false };
| -------^^^^^^^------ help: try this: `if opt.is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:60:20
+ --> $DIR/redundant_pattern_matching_option.rs:62:20
|
LL | let _ = if let Some(_) = gen_opt() {
| -------^^^^^^^------------ help: try this: `if gen_opt().is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:62:19
+ --> $DIR/redundant_pattern_matching_option.rs:64:19
|
LL | } else if let None = gen_opt() {
| -------^^^^------------ help: try this: `if gen_opt().is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:68:12
+ --> $DIR/redundant_pattern_matching_option.rs:70:12
|
LL | if let Some(..) = gen_opt() {}
| -------^^^^^^^^------------ help: try this: `if gen_opt().is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:83:12
+ --> $DIR/redundant_pattern_matching_option.rs:85:12
|
LL | if let Some(_) = Some(42) {}
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:85:12
+ --> $DIR/redundant_pattern_matching_option.rs:87:12
|
LL | if let None = None::<()> {}
| -------^^^^------------- help: try this: `if None::<()>.is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:87:15
+ --> $DIR/redundant_pattern_matching_option.rs:89:15
|
LL | while let Some(_) = Some(42) {}
| ----------^^^^^^^----------- help: try this: `while Some(42).is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:89:15
+ --> $DIR/redundant_pattern_matching_option.rs:91:15
|
LL | while let None = None::<()> {}
| ----------^^^^------------- help: try this: `while None::<()>.is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:91:5
+ --> $DIR/redundant_pattern_matching_option.rs:93:5
|
LL | / match Some(42) {
LL | | Some(_) => true,
@@ -128,7 +128,7 @@ LL | | };
| |_____^ help: try this: `Some(42).is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:96:5
+ --> $DIR/redundant_pattern_matching_option.rs:98:5
|
LL | / match None::<()> {
LL | | Some(_) => false,
@@ -137,19 +137,19 @@ LL | | };
| |_____^ help: try this: `None::<()>.is_none()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:104:12
+ --> $DIR/redundant_pattern_matching_option.rs:106:12
|
LL | if let None = *(&None::<()>) {}
| -------^^^^----------------- help: try this: `if (&None::<()>).is_none()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:105:12
+ --> $DIR/redundant_pattern_matching_option.rs:107:12
|
LL | if let None = *&None::<()> {}
| -------^^^^--------------- help: try this: `if (&None::<()>).is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:111:5
+ --> $DIR/redundant_pattern_matching_option.rs:113:5
|
LL | / match x {
LL | | Some(_) => true,
@@ -158,7 +158,7 @@ LL | | };
| |_____^ help: try this: `x.is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:116:5
+ --> $DIR/redundant_pattern_matching_option.rs:118:5
|
LL | / match x {
LL | | None => true,
@@ -167,7 +167,7 @@ LL | | };
| |_____^ help: try this: `x.is_none()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:121:5
+ --> $DIR/redundant_pattern_matching_option.rs:123:5
|
LL | / match x {
LL | | Some(_) => false,
@@ -176,7 +176,7 @@ LL | | };
| |_____^ help: try this: `x.is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:126:5
+ --> $DIR/redundant_pattern_matching_option.rs:128:5
|
LL | / match x {
LL | | None => false,
@@ -184,5 +184,17 @@ LL | | _ => true,
LL | | };
| |_____^ help: try this: `x.is_some()`
-error: aborting due to 26 previous errors
+error: redundant pattern matching, consider using `is_some()`
+ --> $DIR/redundant_pattern_matching_option.rs:143:13
+ |
+LL | let _ = matches!(x, Some(_));
+ | ^^^^^^^^^^^^^^^^^^^^ help: try this: `x.is_some()`
+
+error: redundant pattern matching, consider using `is_none()`
+ --> $DIR/redundant_pattern_matching_option.rs:145:13
+ |
+LL | let _ = matches!(x, None);
+ | ^^^^^^^^^^^^^^^^^ help: try this: `x.is_none()`
+
+error: aborting due to 28 previous errors
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 bf3e69220..f739deaf5 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.fixed
@@ -5,6 +5,7 @@
#![allow(
unused_must_use,
clippy::needless_bool,
+ clippy::needless_if,
clippy::match_like_matches_macro,
clippy::equatable_if_let,
clippy::if_same_then_else
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 892a21d9d..88dde02b3 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.rs
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.rs
@@ -5,6 +5,7 @@
#![allow(
unused_must_use,
clippy::needless_bool,
+ clippy::needless_if,
clippy::match_like_matches_macro,
clippy::equatable_if_let,
clippy::if_same_then_else
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 1b480f315..b89fde35f 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.stderr
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.stderr
@@ -1,5 +1,5 @@
error: redundant pattern matching, consider using `is_pending()`
- --> $DIR/redundant_pattern_matching_poll.rs:16:12
+ --> $DIR/redundant_pattern_matching_poll.rs:17:12
|
LL | if let Pending = Pending::<()> {}
| -------^^^^^^^---------------- help: try this: `if Pending::<()>.is_pending()`
@@ -7,37 +7,37 @@ LL | if let Pending = Pending::<()> {}
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: redundant pattern matching, consider using `is_ready()`
- --> $DIR/redundant_pattern_matching_poll.rs:18:12
+ --> $DIR/redundant_pattern_matching_poll.rs:19:12
|
LL | if let Ready(_) = Ready(42) {}
| -------^^^^^^^^------------ help: try this: `if Ready(42).is_ready()`
error: redundant pattern matching, consider using `is_ready()`
- --> $DIR/redundant_pattern_matching_poll.rs:20:12
+ --> $DIR/redundant_pattern_matching_poll.rs:21:12
|
LL | if let Ready(_) = Ready(42) {
| -------^^^^^^^^------------ help: try this: `if Ready(42).is_ready()`
error: redundant pattern matching, consider using `is_ready()`
- --> $DIR/redundant_pattern_matching_poll.rs:26:15
+ --> $DIR/redundant_pattern_matching_poll.rs:27:15
|
LL | while let Ready(_) = Ready(42) {}
| ----------^^^^^^^^------------ help: try this: `while Ready(42).is_ready()`
error: redundant pattern matching, consider using `is_pending()`
- --> $DIR/redundant_pattern_matching_poll.rs:28:15
+ --> $DIR/redundant_pattern_matching_poll.rs:29:15
|
LL | while let Pending = Ready(42) {}
| ----------^^^^^^^------------ help: try this: `while Ready(42).is_pending()`
error: redundant pattern matching, consider using `is_pending()`
- --> $DIR/redundant_pattern_matching_poll.rs:30:15
+ --> $DIR/redundant_pattern_matching_poll.rs:31:15
|
LL | while let Pending = Pending::<()> {}
| ----------^^^^^^^---------------- help: try this: `while Pending::<()>.is_pending()`
error: redundant pattern matching, consider using `is_ready()`
- --> $DIR/redundant_pattern_matching_poll.rs:36:5
+ --> $DIR/redundant_pattern_matching_poll.rs:37:5
|
LL | / match Ready(42) {
LL | | Ready(_) => true,
@@ -46,7 +46,7 @@ LL | | };
| |_____^ help: try this: `Ready(42).is_ready()`
error: redundant pattern matching, consider using `is_pending()`
- --> $DIR/redundant_pattern_matching_poll.rs:41:5
+ --> $DIR/redundant_pattern_matching_poll.rs:42:5
|
LL | / match Pending::<()> {
LL | | Ready(_) => false,
@@ -55,7 +55,7 @@ LL | | };
| |_____^ help: try this: `Pending::<()>.is_pending()`
error: redundant pattern matching, consider using `is_pending()`
- --> $DIR/redundant_pattern_matching_poll.rs:46:13
+ --> $DIR/redundant_pattern_matching_poll.rs:47:13
|
LL | let _ = match Pending::<()> {
| _____________^
@@ -65,49 +65,49 @@ LL | | };
| |_____^ help: try this: `Pending::<()>.is_pending()`
error: redundant pattern matching, consider using `is_ready()`
- --> $DIR/redundant_pattern_matching_poll.rs:52:20
+ --> $DIR/redundant_pattern_matching_poll.rs:53:20
|
LL | let _ = if let Ready(_) = poll { true } else { false };
| -------^^^^^^^^------- help: try this: `if poll.is_ready()`
error: redundant pattern matching, consider using `is_ready()`
- --> $DIR/redundant_pattern_matching_poll.rs:56:20
+ --> $DIR/redundant_pattern_matching_poll.rs:57:20
|
LL | let _ = if let Ready(_) = gen_poll() {
| -------^^^^^^^^------------- help: try this: `if gen_poll().is_ready()`
error: redundant pattern matching, consider using `is_pending()`
- --> $DIR/redundant_pattern_matching_poll.rs:58:19
+ --> $DIR/redundant_pattern_matching_poll.rs:59:19
|
LL | } else if let Pending = gen_poll() {
| -------^^^^^^^------------- help: try this: `if gen_poll().is_pending()`
error: redundant pattern matching, consider using `is_ready()`
- --> $DIR/redundant_pattern_matching_poll.rs:74:12
+ --> $DIR/redundant_pattern_matching_poll.rs:75:12
|
LL | if let Ready(_) = Ready(42) {}
| -------^^^^^^^^------------ help: try this: `if Ready(42).is_ready()`
error: redundant pattern matching, consider using `is_pending()`
- --> $DIR/redundant_pattern_matching_poll.rs:76:12
+ --> $DIR/redundant_pattern_matching_poll.rs:77:12
|
LL | if let Pending = Pending::<()> {}
| -------^^^^^^^---------------- help: try this: `if Pending::<()>.is_pending()`
error: redundant pattern matching, consider using `is_ready()`
- --> $DIR/redundant_pattern_matching_poll.rs:78:15
+ --> $DIR/redundant_pattern_matching_poll.rs:79:15
|
LL | while let Ready(_) = Ready(42) {}
| ----------^^^^^^^^------------ help: try this: `while Ready(42).is_ready()`
error: redundant pattern matching, consider using `is_pending()`
- --> $DIR/redundant_pattern_matching_poll.rs:80:15
+ --> $DIR/redundant_pattern_matching_poll.rs:81:15
|
LL | while let Pending = Pending::<()> {}
| ----------^^^^^^^---------------- help: try this: `while Pending::<()>.is_pending()`
error: redundant pattern matching, consider using `is_ready()`
- --> $DIR/redundant_pattern_matching_poll.rs:82:5
+ --> $DIR/redundant_pattern_matching_poll.rs:83:5
|
LL | / match Ready(42) {
LL | | Ready(_) => true,
@@ -116,7 +116,7 @@ LL | | };
| |_____^ help: try this: `Ready(42).is_ready()`
error: redundant pattern matching, consider using `is_pending()`
- --> $DIR/redundant_pattern_matching_poll.rs:87:5
+ --> $DIR/redundant_pattern_matching_poll.rs:88: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 e4032ae44..343e0d043 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed
@@ -6,6 +6,7 @@
clippy::if_same_then_else,
clippy::match_like_matches_macro,
clippy::needless_bool,
+ clippy::needless_if,
clippy::uninlined_format_args,
clippy::unnecessary_wraps
)]
@@ -44,6 +45,7 @@ fn main() {
issue6067();
issue6065();
issue10726();
+ issue10803();
let _ = if gen_res().is_ok() {
1
@@ -133,3 +135,17 @@ fn issue10726() {
_ => true,
};
}
+
+fn issue10803() {
+ let x: Result<i32, i32> = Ok(42);
+
+ let _ = x.is_ok();
+
+ let _ = x.is_err();
+
+ // Don't lint
+ let _ = matches!(x, Ok(16));
+
+ // Don't lint
+ let _ = matches!(x, Err(16));
+}
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 39eb10df8..4d64eafe5 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs
@@ -6,6 +6,7 @@
clippy::if_same_then_else,
clippy::match_like_matches_macro,
clippy::needless_bool,
+ clippy::needless_if,
clippy::uninlined_format_args,
clippy::unnecessary_wraps
)]
@@ -56,6 +57,7 @@ fn main() {
issue6067();
issue6065();
issue10726();
+ issue10803();
let _ = if let Ok(_) = gen_res() {
1
@@ -163,3 +165,17 @@ fn issue10726() {
_ => true,
};
}
+
+fn issue10803() {
+ let x: Result<i32, i32> = Ok(42);
+
+ let _ = matches!(x, Ok(_));
+
+ let _ = matches!(x, Err(_));
+
+ // Don't lint
+ let _ = matches!(x, Ok(16));
+
+ // Don't lint
+ let _ = matches!(x, Err(16));
+}
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 5893ae4dc..f6ce666bb 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr
@@ -1,5 +1,5 @@
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:15:12
+ --> $DIR/redundant_pattern_matching_result.rs:16:12
|
LL | if let Ok(_) = &result {}
| -------^^^^^---------- help: try this: `if result.is_ok()`
@@ -7,31 +7,31 @@ LL | if let Ok(_) = &result {}
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:17:12
+ --> $DIR/redundant_pattern_matching_result.rs:18:12
|
LL | if let Ok(_) = Ok::<i32, i32>(42) {}
| -------^^^^^--------------------- help: try this: `if Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:19:12
+ --> $DIR/redundant_pattern_matching_result.rs:20:12
|
LL | if let Err(_) = Err::<i32, i32>(42) {}
| -------^^^^^^---------------------- help: try this: `if Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:21:15
+ --> $DIR/redundant_pattern_matching_result.rs:22:15
|
LL | while let Ok(_) = Ok::<i32, i32>(10) {}
| ----------^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:23:15
+ --> $DIR/redundant_pattern_matching_result.rs:24:15
|
LL | while let Err(_) = Ok::<i32, i32>(10) {}
| ----------^^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:33:5
+ --> $DIR/redundant_pattern_matching_result.rs:34:5
|
LL | / match Ok::<i32, i32>(42) {
LL | | Ok(_) => true,
@@ -40,7 +40,7 @@ LL | | };
| |_____^ help: try this: `Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:38:5
+ --> $DIR/redundant_pattern_matching_result.rs:39:5
|
LL | / match Ok::<i32, i32>(42) {
LL | | Ok(_) => false,
@@ -49,7 +49,7 @@ LL | | };
| |_____^ help: try this: `Ok::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:43:5
+ --> $DIR/redundant_pattern_matching_result.rs:44:5
|
LL | / match Err::<i32, i32>(42) {
LL | | Ok(_) => false,
@@ -58,7 +58,7 @@ LL | | };
| |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:48:5
+ --> $DIR/redundant_pattern_matching_result.rs:49:5
|
LL | / match Err::<i32, i32>(42) {
LL | | Ok(_) => true,
@@ -67,73 +67,73 @@ LL | | };
| |_____^ help: try this: `Err::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:53:20
+ --> $DIR/redundant_pattern_matching_result.rs:54:20
|
LL | let _ = if let Ok(_) = Ok::<usize, ()>(4) { true } else { false };
| -------^^^^^--------------------- help: try this: `if Ok::<usize, ()>(4).is_ok()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:60:20
+ --> $DIR/redundant_pattern_matching_result.rs:62:20
|
LL | let _ = if let Ok(_) = gen_res() {
| -------^^^^^------------ help: try this: `if gen_res().is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:62:19
+ --> $DIR/redundant_pattern_matching_result.rs:64:19
|
LL | } else if let Err(_) = gen_res() {
| -------^^^^^^------------ help: try this: `if gen_res().is_err()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_result.rs:85:19
+ --> $DIR/redundant_pattern_matching_result.rs:87:19
|
LL | while let Some(_) = r#try!(result_opt()) {}
| ----------^^^^^^^----------------------- help: try this: `while r#try!(result_opt()).is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_result.rs:86:16
+ --> $DIR/redundant_pattern_matching_result.rs:88:16
|
LL | if let Some(_) = r#try!(result_opt()) {}
| -------^^^^^^^----------------------- help: try this: `if r#try!(result_opt()).is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_result.rs:92:12
+ --> $DIR/redundant_pattern_matching_result.rs:94:12
|
LL | if let Some(_) = m!() {}
| -------^^^^^^^------- help: try this: `if m!().is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_result.rs:93:15
+ --> $DIR/redundant_pattern_matching_result.rs:95:15
|
LL | while let Some(_) = m!() {}
| ----------^^^^^^^------- help: try this: `while m!().is_some()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:111:12
+ --> $DIR/redundant_pattern_matching_result.rs:113:12
|
LL | if let Ok(_) = Ok::<i32, i32>(42) {}
| -------^^^^^--------------------- help: try this: `if Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:113:12
+ --> $DIR/redundant_pattern_matching_result.rs:115:12
|
LL | if let Err(_) = Err::<i32, i32>(42) {}
| -------^^^^^^---------------------- help: try this: `if Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:115:15
+ --> $DIR/redundant_pattern_matching_result.rs:117:15
|
LL | while let Ok(_) = Ok::<i32, i32>(10) {}
| ----------^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:117:15
+ --> $DIR/redundant_pattern_matching_result.rs:119:15
|
LL | while let Err(_) = Ok::<i32, i32>(10) {}
| ----------^^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:119:5
+ --> $DIR/redundant_pattern_matching_result.rs:121:5
|
LL | / match Ok::<i32, i32>(42) {
LL | | Ok(_) => true,
@@ -142,7 +142,7 @@ LL | | };
| |_____^ help: try this: `Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:124:5
+ --> $DIR/redundant_pattern_matching_result.rs:126:5
|
LL | / match Err::<i32, i32>(42) {
LL | | Ok(_) => false,
@@ -151,7 +151,7 @@ LL | | };
| |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:134:5
+ --> $DIR/redundant_pattern_matching_result.rs:136:5
|
LL | / match x {
LL | | Ok(_) => true,
@@ -160,7 +160,7 @@ LL | | };
| |_____^ help: try this: `x.is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:139:5
+ --> $DIR/redundant_pattern_matching_result.rs:141:5
|
LL | / match x {
LL | | Ok(_) => false,
@@ -169,7 +169,7 @@ LL | | };
| |_____^ help: try this: `x.is_err()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:144:5
+ --> $DIR/redundant_pattern_matching_result.rs:146:5
|
LL | / match x {
LL | | Err(_) => true,
@@ -178,7 +178,7 @@ LL | | };
| |_____^ help: try this: `x.is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:149:5
+ --> $DIR/redundant_pattern_matching_result.rs:151:5
|
LL | / match x {
LL | | Err(_) => false,
@@ -186,5 +186,17 @@ LL | | _ => true,
LL | | };
| |_____^ help: try this: `x.is_ok()`
-error: aborting due to 26 previous errors
+error: redundant pattern matching, consider using `is_ok()`
+ --> $DIR/redundant_pattern_matching_result.rs:172:13
+ |
+LL | let _ = matches!(x, Ok(_));
+ | ^^^^^^^^^^^^^^^^^^ help: try this: `x.is_ok()`
+
+error: redundant pattern matching, consider using `is_err()`
+ --> $DIR/redundant_pattern_matching_result.rs:174:13
+ |
+LL | let _ = matches!(x, Err(_));
+ | ^^^^^^^^^^^^^^^^^^^ help: try this: `x.is_err()`
+
+error: aborting due to 28 previous errors
diff --git a/src/tools/clippy/tests/ui/redundant_pub_crate.fixed b/src/tools/clippy/tests/ui/redundant_pub_crate.fixed
index f65c0fdd3..a1ed491bb 100644
--- a/src/tools/clippy/tests/ui/redundant_pub_crate.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pub_crate.fixed
@@ -14,7 +14,7 @@ mod m1 {
}
pub mod m1_2 {
- // ^ private due to m1
+ //:^ private due to m1
fn f() {}
pub fn g() {} // private due to m1_2 and m1
pub fn h() {}
@@ -39,7 +39,7 @@ pub(crate) mod m2 {
}
pub mod m2_2 {
- // ^ already crate visible due to m2
+ //:^ already crate visible due to m2
fn f() {}
pub fn g() {} // already crate visible due to m2_2 and m2
pub fn h() {}
@@ -64,7 +64,7 @@ pub mod m3 {
}
pub(crate) mod m3_2 {
- // ^ ok
+ //:^ ok
fn f() {}
pub fn g() {} // already crate visible due to m3_2
pub fn h() {}
@@ -89,7 +89,7 @@ mod m4 {
}
pub mod m4_2 {
- // ^ private: not re-exported by `pub use m4::*`
+ //:^ private: not re-exported by `pub use m4::*`
fn f() {}
pub fn g() {} // private due to m4_2
pub fn h() {}
diff --git a/src/tools/clippy/tests/ui/redundant_pub_crate.rs b/src/tools/clippy/tests/ui/redundant_pub_crate.rs
index fb07fed98..9accd297f 100644
--- a/src/tools/clippy/tests/ui/redundant_pub_crate.rs
+++ b/src/tools/clippy/tests/ui/redundant_pub_crate.rs
@@ -14,7 +14,7 @@ mod m1 {
}
pub(crate) mod m1_2 {
- // ^ private due to m1
+ //:^ private due to m1
fn f() {}
pub(crate) fn g() {} // private due to m1_2 and m1
pub fn h() {}
@@ -39,7 +39,7 @@ pub(crate) mod m2 {
}
pub(crate) mod m2_2 {
- // ^ already crate visible due to m2
+ //:^ already crate visible due to m2
fn f() {}
pub(crate) fn g() {} // already crate visible due to m2_2 and m2
pub fn h() {}
@@ -64,7 +64,7 @@ pub mod m3 {
}
pub(crate) mod m3_2 {
- // ^ ok
+ //:^ ok
fn f() {}
pub(crate) fn g() {} // already crate visible due to m3_2
pub fn h() {}
@@ -89,7 +89,7 @@ mod m4 {
}
pub(crate) mod m4_2 {
- // ^ private: not re-exported by `pub use m4::*`
+ //:^ private: not re-exported by `pub use m4::*`
fn f() {}
pub(crate) fn g() {} // private due to m4_2
pub fn h() {}
diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed b/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
index 2651735d1..a83699ec6 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
@@ -5,39 +5,39 @@
#[derive(Debug)]
struct Foo;
-const VAR_ONE: &str = "Test constant #1"; // ERROR Consider removing 'static.
+const VAR_ONE: &str = "Test constant #1"; // ERROR: Consider removing 'static.
const VAR_TWO: &str = "Test constant #2"; // This line should not raise a warning.
-const VAR_THREE: &[&str] = &["one", "two"]; // ERROR Consider removing 'static
+const VAR_THREE: &[&str] = &["one", "two"]; // ERROR: Consider removing 'static
-const VAR_FOUR: (&str, (&str, &str), &str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
+const VAR_FOUR: (&str, (&str, &str), &str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static
const VAR_SIX: &u8 = &5;
const VAR_HEIGHT: &Foo = &Foo {};
-const VAR_SLICE: &[u8] = b"Test constant #1"; // ERROR Consider removing 'static.
+const VAR_SLICE: &[u8] = b"Test constant #1"; // ERROR: Consider removing 'static.
-const VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR Consider removing 'static.
+const VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR: Consider removing 'static.
-const VAR_ARRAY: &[u8; 1] = b"T"; // ERROR Consider removing 'static.
+const VAR_ARRAY: &[u8; 1] = b"T"; // ERROR: Consider removing 'static.
-static STATIC_VAR_ONE: &str = "Test static #1"; // ERROR Consider removing 'static.
+static STATIC_VAR_ONE: &str = "Test static #1"; // ERROR: Consider removing 'static.
static STATIC_VAR_TWO: &str = "Test static #2"; // This line should not raise a warning.
-static STATIC_VAR_THREE: &[&str] = &["one", "two"]; // ERROR Consider removing 'static
+static STATIC_VAR_THREE: &[&str] = &["one", "two"]; // ERROR: Consider removing 'static
static STATIC_VAR_SIX: &u8 = &5;
static STATIC_VAR_HEIGHT: &Foo = &Foo {};
-static STATIC_VAR_SLICE: &[u8] = b"Test static #3"; // ERROR Consider removing 'static.
+static STATIC_VAR_SLICE: &[u8] = b"Test static #3"; // ERROR: Consider removing 'static.
-static STATIC_VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR Consider removing 'static.
+static STATIC_VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR: Consider removing 'static.
-static STATIC_VAR_ARRAY: &[u8; 1] = b"T"; // ERROR Consider removing 'static.
+static STATIC_VAR_ARRAY: &[u8; 1] = b"T"; // ERROR: Consider removing 'static.
static mut STATIC_MUT_SLICE: &mut [u32] = &mut [0];
diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs b/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
index 728665289..b165cbaa3 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
@@ -5,39 +5,39 @@
#[derive(Debug)]
struct Foo;
-const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static.
+const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removing 'static.
const VAR_TWO: &str = "Test constant #2"; // This line should not raise a warning.
-const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
+const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR: Consider removing 'static
-const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
+const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static
const VAR_SIX: &'static u8 = &5;
const VAR_HEIGHT: &'static Foo = &Foo {};
-const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR Consider removing 'static.
+const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR: Consider removing 'static.
-const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static.
+const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR: Consider removing 'static.
-const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
+const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR: Consider removing 'static.
-static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR Consider removing 'static.
+static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR: Consider removing 'static.
static STATIC_VAR_TWO: &str = "Test static #2"; // This line should not raise a warning.
-static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
+static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR: Consider removing 'static
static STATIC_VAR_SIX: &'static u8 = &5;
static STATIC_VAR_HEIGHT: &'static Foo = &Foo {};
-static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR Consider removing 'static.
+static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR: Consider removing 'static.
-static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static.
+static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR: Consider removing 'static.
-static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
+static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR: Consider removing 'static.
static mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0];
diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr b/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr
index b2cbd2d9d..a13e5eadf 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr
@@ -1,7 +1,7 @@
error: constants have by default a `'static` lifetime
--> $DIR/redundant_static_lifetimes.rs:8:17
|
-LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static.
+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`
@@ -9,19 +9,19 @@ LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removin
error: constants have by default a `'static` lifetime
--> $DIR/redundant_static_lifetimes.rs:12:21
|
-LL | const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
+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
|
-LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
+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
|
-LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
+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
@@ -39,31 +39,31 @@ LL | const VAR_HEIGHT: &'static Foo = &Foo {};
error: constants have by default a `'static` lifetime
--> $DIR/redundant_static_lifetimes.rs:20:19
|
-LL | const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR Consider removing 'static.
+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
|
-LL | const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static.
+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
|
-LL | const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
+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
|
-LL | static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR Consider removing 'static.
+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
|
-LL | static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
+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
@@ -81,19 +81,19 @@ LL | static STATIC_VAR_HEIGHT: &'static Foo = &Foo {};
error: statics have by default a `'static` lifetime
--> $DIR/redundant_static_lifetimes.rs:36:27
|
-LL | static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR Consider removing 'static.
+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
|
-LL | static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static.
+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
|
-LL | static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
+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
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 f57dd58e2..b3f263a7d 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes_multiple.rs
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes_multiple.rs
@@ -1,12 +1,12 @@
// these are rustfixable, but run-rustfix tests cannot handle them
-const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
+const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static
const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
-static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
+static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static
-static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
+static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR: Consider removing 'static
static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
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 cc7e55a75..4e7500903 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes_multiple.stderr
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes_multiple.stderr
@@ -1,7 +1,7 @@
error: constants have by default a `'static` lifetime
--> $DIR/redundant_static_lifetimes_multiple.rs:3:18
|
-LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
+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`
@@ -9,7 +9,7 @@ LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]];
error: constants have by default a `'static` lifetime
--> $DIR/redundant_static_lifetimes_multiple.rs:3:30
|
-LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
+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
@@ -27,25 +27,25 @@ LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other
error: statics have by default a `'static` lifetime
--> $DIR/redundant_static_lifetimes_multiple.rs:7:40
|
-LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
+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
|
-LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
+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
|
-LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
+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
|
-LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
+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
diff --git a/src/tools/clippy/tests/ui/redundant_type_annotations.rs b/src/tools/clippy/tests/ui/redundant_type_annotations.rs
new file mode 100644
index 000000000..09dbd3c9b
--- /dev/null
+++ b/src/tools/clippy/tests/ui/redundant_type_annotations.rs
@@ -0,0 +1,190 @@
+#![allow(unused)]
+#![warn(clippy::redundant_type_annotations)]
+
+#[derive(Debug, Default)]
+struct Cake<T> {
+ _data: T,
+}
+
+fn make_something<T>() -> T {
+ unimplemented!()
+}
+
+fn make_cake<T: Default>() -> Cake<T> {
+ Cake::<T>::default()
+}
+
+fn plus_one<T: std::ops::Add<u8, Output = T>>(val: T) -> T {
+ val + 1
+}
+
+#[derive(Default)]
+struct Slice {
+ inner: u32,
+}
+
+#[derive(Default)]
+struct Pie {
+ inner: u32,
+ inner_struct: Slice,
+}
+
+enum Pizza {
+ One,
+ Two,
+}
+
+fn return_a_string() -> String {
+ String::new()
+}
+
+fn return_a_struct() -> Pie {
+ Pie::default()
+}
+
+fn return_an_enum() -> Pizza {
+ Pizza::One
+}
+
+fn return_an_int() -> u32 {
+ 5
+}
+
+impl Pie {
+ fn return_an_int(&self) -> u32 {
+ self.inner
+ }
+
+ fn return_a_ref(&self) -> &u32 {
+ &self.inner
+ }
+
+ fn return_a_ref_to_struct(&self) -> &Slice {
+ &self.inner_struct
+ }
+
+ fn associated_return_an_int() -> u32 {
+ 5
+ }
+
+ fn new() -> Self {
+ Self::default()
+ }
+
+ fn associated_return_a_string() -> String {
+ String::from("")
+ }
+
+ fn test_method_call(&self) {
+ // Everything here should be lint
+
+ let v: u32 = self.return_an_int();
+ let v: &u32 = self.return_a_ref();
+ let v: &Slice = self.return_a_ref_to_struct();
+ }
+}
+
+fn test_generics() {
+ // The type annotation is needed to determine T
+ let _c: Cake<i32> = make_something();
+
+ // The type annotation is needed to determine the topic
+ let _c: Cake<u8> = make_cake();
+
+ // This could be lint, but currently doesn't
+ let _c: Cake<u8> = make_cake::<u8>();
+
+ // This could be lint, but currently doesn't
+ let _c: u8 = make_something::<u8>();
+
+ // This could be lint, but currently doesn't
+ let _c: u8 = plus_one(5_u8);
+
+ // Annotation needed otherwise T is i32
+ let _c: u8 = plus_one(5);
+
+ // This could be lint, but currently doesn't
+ let _return: String = String::from("test");
+}
+
+fn test_non_locals() {
+ // This shouldn't be lint
+ fn _arg(x: u32) -> u32 {
+ x
+ }
+
+ // This could lint, but probably shouldn't
+ let _closure_arg = |x: u32| x;
+}
+
+trait Trait {
+ type AssocTy;
+}
+
+impl Trait for () {
+ type AssocTy = String;
+}
+
+fn test_complex_types<T>() {
+ // Shouldn't be lint, since the literal will be i32 otherwise
+ let _u8: u8 = 128;
+
+ // This could be lint, but currently doesn't
+ let _tuple_i32: (i32, i32) = (12, 13);
+
+ // Shouldn't be lint, since the tuple will be i32 otherwise
+ let _tuple_u32: (u32, u32) = (1, 2);
+
+ // Should be lint, since the type is determined by the init value, but currently doesn't
+ let _tuple_u32: (u32, u32) = (3_u32, 4_u32);
+
+ // This could be lint, but currently doesn't
+ let _array: [i32; 3] = [5, 6, 7];
+
+ // Shouldn't be lint
+ let _array: [u32; 2] = [8, 9];
+
+ let ty_param: T = make_something();
+
+ let assoc_ty: <() as Trait>::AssocTy = String::new();
+}
+
+fn test_functions() {
+ // Everything here should be lint
+
+ let _return: String = return_a_string();
+
+ let _return: Pie = return_a_struct();
+
+ let _return: Pizza = return_an_enum();
+
+ let _return: u32 = return_an_int();
+
+ let _return: String = String::new();
+
+ let new_pie: Pie = Pie::new();
+
+ let _return: u32 = new_pie.return_an_int();
+
+ let _return: u32 = Pie::associated_return_an_int();
+
+ let _return: String = Pie::associated_return_a_string();
+}
+
+fn test_simple_types() {
+ // Everything here should be lint
+
+ let _var: u32 = u32::MAX;
+
+ let _var: u32 = 5_u32;
+
+ let _var: &str = "test";
+
+ let _var: &[u8] = b"test";
+
+ let _var: bool = false;
+}
+
+fn issue11190() {}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/redundant_type_annotations.stderr b/src/tools/clippy/tests/ui/redundant_type_annotations.stderr
new file mode 100644
index 000000000..988ebe637
--- /dev/null
+++ b/src/tools/clippy/tests/ui/redundant_type_annotations.stderr
@@ -0,0 +1,106 @@
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:81:9
+ |
+LL | let v: u32 = self.return_an_int();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::redundant-type-annotations` implied by `-D warnings`
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:82:9
+ |
+LL | let v: &u32 = self.return_a_ref();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:83:9
+ |
+LL | let v: &Slice = self.return_a_ref_to_struct();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:155:5
+ |
+LL | let _return: String = return_a_string();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:157:5
+ |
+LL | let _return: Pie = return_a_struct();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:159:5
+ |
+LL | let _return: Pizza = return_an_enum();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:161:5
+ |
+LL | let _return: u32 = return_an_int();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:163:5
+ |
+LL | let _return: String = String::new();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:165:5
+ |
+LL | let new_pie: Pie = Pie::new();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:167:5
+ |
+LL | let _return: u32 = new_pie.return_an_int();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:169:5
+ |
+LL | let _return: u32 = Pie::associated_return_an_int();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:171:5
+ |
+LL | let _return: String = Pie::associated_return_a_string();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:177:5
+ |
+LL | let _var: u32 = u32::MAX;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:179:5
+ |
+LL | let _var: u32 = 5_u32;
+ | ^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:181:5
+ |
+LL | let _var: &str = "test";
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:183:5
+ |
+LL | let _var: &[u8] = b"test";
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: redundant type annotation
+ --> $DIR/redundant_type_annotations.rs:185:5
+ |
+LL | let _var: bool = false;
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 17 previous errors
+
diff --git a/src/tools/clippy/tests/ui/regex.rs b/src/tools/clippy/tests/ui/regex.rs
index a5f79b139..89d1d9494 100644
--- a/src/tools/clippy/tests/ui/regex.rs
+++ b/src/tools/clippy/tests/ui/regex.rs
@@ -1,4 +1,9 @@
-#![allow(unused, clippy::needless_borrow)]
+#![allow(
+ unused,
+ clippy::needless_raw_strings,
+ clippy::needless_raw_string_hashes,
+ clippy::needless_borrow
+)]
#![warn(clippy::invalid_regex, clippy::trivial_regex)]
extern crate regex;
@@ -42,6 +47,11 @@ fn syntax_error() {
let escaped_string_span = Regex::new("\\b\\c");
let aux_span = Regex::new("(?ixi)");
+
+ 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).");
}
fn trivial_regex() {
@@ -71,6 +81,8 @@ fn trivial_regex() {
// non-trivial regexes
let non_trivial_dot = Regex::new("a.b");
let non_trivial_dot_builder = RegexBuilder::new("a.b");
+ let non_trivial_dot = Regex::new(".");
+ let non_trivial_dot = BRegex::new(".");
let non_trivial_eq = Regex::new("^foo|bar$");
let non_trivial_starts_with = Regex::new("^foo|bar");
let non_trivial_ends_with = Regex::new("^foo|bar");
diff --git a/src/tools/clippy/tests/ui/regex.stderr b/src/tools/clippy/tests/ui/regex.stderr
index 6b8a772e7..21f1cb444 100644
--- a/src/tools/clippy/tests/ui/regex.stderr
+++ b/src/tools/clippy/tests/ui/regex.stderr
@@ -1,5 +1,5 @@
error: trivial regex
- --> $DIR/regex.rs:13:45
+ --> $DIR/regex.rs:18:45
|
LL | let pipe_in_wrong_position = Regex::new("|");
| ^^^
@@ -8,7 +8,7 @@ LL | let pipe_in_wrong_position = Regex::new("|");
= note: `-D clippy::trivial-regex` implied by `-D warnings`
error: trivial regex
- --> $DIR/regex.rs:14:60
+ --> $DIR/regex.rs:19:60
|
LL | let pipe_in_wrong_position_builder = RegexBuilder::new("|");
| ^^^
@@ -16,7 +16,7 @@ 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:15:42
+ --> $DIR/regex.rs:20:42
|
LL | let wrong_char_ranice = Regex::new("[z-a]");
| ^^^
@@ -24,7 +24,7 @@ LL | let wrong_char_ranice = Regex::new("[z-a]");
= note: `-D clippy::invalid-regex` implied by `-D warnings`
error: regex syntax error: invalid character class range, the start must be <= the end
- --> $DIR/regex.rs:16:37
+ --> $DIR/regex.rs:21:37
|
LL | let some_unicode = Regex::new("[é-è]");
| ^^^
@@ -33,13 +33,13 @@ error: regex parse error:
(
^
error: unclosed group
- --> $DIR/regex.rs:18:33
+ --> $DIR/regex.rs:23:33
|
LL | let some_regex = Regex::new(OPENING_PAREN);
| ^^^^^^^^^^^^^
error: trivial regex
- --> $DIR/regex.rs:20:53
+ --> $DIR/regex.rs:25:53
|
LL | let binary_pipe_in_wrong_position = BRegex::new("|");
| ^^^
@@ -50,7 +50,7 @@ error: regex parse error:
(
^
error: unclosed group
- --> $DIR/regex.rs:21:41
+ --> $DIR/regex.rs:26:41
|
LL | let some_binary_regex = BRegex::new(OPENING_PAREN);
| ^^^^^^^^^^^^^
@@ -59,7 +59,7 @@ error: regex parse error:
(
^
error: unclosed group
- --> $DIR/regex.rs:22:56
+ --> $DIR/regex.rs:27:56
|
LL | let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN);
| ^^^^^^^^^^^^^
@@ -68,7 +68,7 @@ error: regex parse error:
(
^
error: unclosed group
- --> $DIR/regex.rs:34:37
+ --> $DIR/regex.rs:39:37
|
LL | let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+/.(com|org|net)"]);
| ^^^^^^^^^^^^^
@@ -77,7 +77,7 @@ error: regex parse error:
(
^
error: unclosed group
- --> $DIR/regex.rs:35:39
+ --> $DIR/regex.rs:40:39
|
LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+/.(com|org|net)"]);
| ^^^^^^^^^^^^^
@@ -86,21 +86,27 @@ error: regex parse error:
/b/c
^^
error: unrecognized escape sequence
- --> $DIR/regex.rs:42:42
+ --> $DIR/regex.rs:47: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:44:34
+ --> $DIR/regex.rs:49:34
|
LL | let aux_span = Regex::new("(?ixi)");
| ^ ^
+error: regex syntax error: pattern can match invalid UTF-8
+ --> $DIR/regex.rs:54:53
+ |
+LL | let invalid_utf8_should_lint = Regex::new("(?-u).");
+ | ^
+
error: trivial regex
- --> $DIR/regex.rs:48:33
+ --> $DIR/regex.rs:58:33
|
LL | let trivial_eq = Regex::new("^foobar$");
| ^^^^^^^^^^
@@ -108,7 +114,7 @@ LL | let trivial_eq = Regex::new("^foobar$");
= help: consider using `==` on `str`s
error: trivial regex
- --> $DIR/regex.rs:50:48
+ --> $DIR/regex.rs:60:48
|
LL | let trivial_eq_builder = RegexBuilder::new("^foobar$");
| ^^^^^^^^^^
@@ -116,7 +122,7 @@ LL | let trivial_eq_builder = RegexBuilder::new("^foobar$");
= help: consider using `==` on `str`s
error: trivial regex
- --> $DIR/regex.rs:52:42
+ --> $DIR/regex.rs:62:42
|
LL | let trivial_starts_with = Regex::new("^foobar");
| ^^^^^^^^^
@@ -124,7 +130,7 @@ LL | let trivial_starts_with = Regex::new("^foobar");
= help: consider using `str::starts_with`
error: trivial regex
- --> $DIR/regex.rs:54:40
+ --> $DIR/regex.rs:64:40
|
LL | let trivial_ends_with = Regex::new("foobar$");
| ^^^^^^^^^
@@ -132,7 +138,7 @@ LL | let trivial_ends_with = Regex::new("foobar$");
= help: consider using `str::ends_with`
error: trivial regex
- --> $DIR/regex.rs:56:39
+ --> $DIR/regex.rs:66:39
|
LL | let trivial_contains = Regex::new("foobar");
| ^^^^^^^^
@@ -140,7 +146,7 @@ LL | let trivial_contains = Regex::new("foobar");
= help: consider using `str::contains`
error: trivial regex
- --> $DIR/regex.rs:58:39
+ --> $DIR/regex.rs:68:39
|
LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX);
| ^^^^^^^^^^^^^^^^
@@ -148,15 +154,15 @@ LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX);
= help: consider using `str::contains`
error: trivial regex
- --> $DIR/regex.rs:60:40
+ --> $DIR/regex.rs:70: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:63:36
+ --> $DIR/regex.rs:73:36
|
LL | let trivial_empty = Regex::new("");
| ^^
@@ -164,7 +170,7 @@ LL | let trivial_empty = Regex::new("");
= help: the regex is unlikely to be useful as it is
error: trivial regex
- --> $DIR/regex.rs:65:36
+ --> $DIR/regex.rs:75:36
|
LL | let trivial_empty = Regex::new("^");
| ^^^
@@ -172,7 +178,7 @@ LL | let trivial_empty = Regex::new("^");
= help: the regex is unlikely to be useful as it is
error: trivial regex
- --> $DIR/regex.rs:67:36
+ --> $DIR/regex.rs:77:36
|
LL | let trivial_empty = Regex::new("^$");
| ^^^^
@@ -180,12 +186,12 @@ LL | let trivial_empty = Regex::new("^$");
= help: consider using `str::is_empty`
error: trivial regex
- --> $DIR/regex.rs:69:44
+ --> $DIR/regex.rs:79:44
|
LL | let binary_trivial_empty = BRegex::new("^$");
| ^^^^
|
= help: consider using `str::is_empty`
-error: aborting due to 23 previous errors
+error: aborting due to 24 previous errors
diff --git a/src/tools/clippy/tests/ui/rename.fixed b/src/tools/clippy/tests/ui/rename.fixed
index dfe45dec8..cc2295ea5 100644
--- a/src/tools/clippy/tests/ui/rename.fixed
+++ b/src/tools/clippy/tests/ui/rename.fixed
@@ -29,6 +29,8 @@
#![allow(clippy::recursive_format_impl)]
#![allow(clippy::invisible_characters)]
#![allow(suspicious_double_ref_op)]
+#![allow(invalid_nan_comparisons)]
+#![allow(invalid_reference_casting)]
#![allow(drop_bounds)]
#![allow(dropping_copy_types)]
#![allow(dropping_references)]
@@ -38,12 +40,13 @@
#![allow(array_into_iter)]
#![allow(invalid_atomic_ordering)]
#![allow(invalid_value)]
+#![allow(invalid_from_utf8_unchecked)]
#![allow(let_underscore_drop)]
#![allow(enum_intrinsics_non_enums)]
#![allow(non_fmt_panics)]
#![allow(named_arguments_used_positionally)]
-#![allow(suspicious_double_ref_op)]
#![allow(temporary_cstring_as_ptr)]
+#![allow(undropped_manually_drops)]
#![allow(unknown_lints)]
#![allow(unused_labels)]
#![warn(clippy::almost_complete_range)]
@@ -75,7 +78,9 @@
#![warn(clippy::module_name_repetitions)]
#![warn(clippy::recursive_format_impl)]
#![warn(clippy::invisible_characters)]
+#![warn(invalid_reference_casting)]
#![warn(suspicious_double_ref_op)]
+#![warn(invalid_nan_comparisons)]
#![warn(drop_bounds)]
#![warn(dropping_copy_types)]
#![warn(dropping_references)]
@@ -87,11 +92,13 @@
#![warn(array_into_iter)]
#![warn(invalid_atomic_ordering)]
#![warn(invalid_value)]
+#![warn(invalid_from_utf8_unchecked)]
#![warn(let_underscore_drop)]
#![warn(enum_intrinsics_non_enums)]
#![warn(non_fmt_panics)]
#![warn(named_arguments_used_positionally)]
#![warn(temporary_cstring_as_ptr)]
+#![warn(undropped_manually_drops)]
#![warn(unknown_lints)]
#![warn(unused_labels)]
diff --git a/src/tools/clippy/tests/ui/rename.rs b/src/tools/clippy/tests/ui/rename.rs
index ce8eca5a3..399335aff 100644
--- a/src/tools/clippy/tests/ui/rename.rs
+++ b/src/tools/clippy/tests/ui/rename.rs
@@ -29,6 +29,8 @@
#![allow(clippy::recursive_format_impl)]
#![allow(clippy::invisible_characters)]
#![allow(suspicious_double_ref_op)]
+#![allow(invalid_nan_comparisons)]
+#![allow(invalid_reference_casting)]
#![allow(drop_bounds)]
#![allow(dropping_copy_types)]
#![allow(dropping_references)]
@@ -38,12 +40,13 @@
#![allow(array_into_iter)]
#![allow(invalid_atomic_ordering)]
#![allow(invalid_value)]
+#![allow(invalid_from_utf8_unchecked)]
#![allow(let_underscore_drop)]
#![allow(enum_intrinsics_non_enums)]
#![allow(non_fmt_panics)]
#![allow(named_arguments_used_positionally)]
-#![allow(suspicious_double_ref_op)]
#![allow(temporary_cstring_as_ptr)]
+#![allow(undropped_manually_drops)]
#![allow(unknown_lints)]
#![allow(unused_labels)]
#![warn(clippy::almost_complete_letter_range)]
@@ -75,7 +78,9 @@
#![warn(clippy::stutter)]
#![warn(clippy::to_string_in_display)]
#![warn(clippy::zero_width_space)]
+#![warn(clippy::cast_ref_to_mut)]
#![warn(clippy::clone_double_ref)]
+#![warn(clippy::cmp_nan)]
#![warn(clippy::drop_bounds)]
#![warn(clippy::drop_copy)]
#![warn(clippy::drop_ref)]
@@ -87,11 +92,13 @@
#![warn(clippy::into_iter_on_array)]
#![warn(clippy::invalid_atomic_ordering)]
#![warn(clippy::invalid_ref)]
+#![warn(clippy::invalid_utf8_in_unchecked)]
#![warn(clippy::let_underscore_drop)]
#![warn(clippy::mem_discriminant_non_enum)]
#![warn(clippy::panic_params)]
#![warn(clippy::positional_named_format_parameters)]
#![warn(clippy::temporary_cstring_as_ptr)]
+#![warn(clippy::undropped_manually_drops)]
#![warn(clippy::unknown_clippy_lints)]
#![warn(clippy::unused_label)]
diff --git a/src/tools/clippy/tests/ui/rename.stderr b/src/tools/clippy/tests/ui/rename.stderr
index 3fca60aa2..079371330 100644
--- a/src/tools/clippy/tests/ui/rename.stderr
+++ b/src/tools/clippy/tests/ui/rename.stderr
@@ -1,5 +1,5 @@
error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range`
- --> $DIR/rename.rs:49:9
+ --> $DIR/rename.rs:52:9
|
LL | #![warn(clippy::almost_complete_letter_range)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range`
@@ -7,286 +7,310 @@ LL | #![warn(clippy::almost_complete_letter_range)]
= note: `-D renamed-and-removed-lints` implied by `-D warnings`
error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names`
- --> $DIR/rename.rs:50:9
+ --> $DIR/rename.rs:53:9
|
LL | #![warn(clippy::blacklisted_name)]
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names`
error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions`
- --> $DIR/rename.rs:51:9
+ --> $DIR/rename.rs:54:9
|
LL | #![warn(clippy::block_in_if_condition_expr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions`
error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions`
- --> $DIR/rename.rs:52:9
+ --> $DIR/rename.rs:55:9
|
LL | #![warn(clippy::block_in_if_condition_stmt)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions`
error: lint `clippy::box_vec` has been renamed to `clippy::box_collection`
- --> $DIR/rename.rs:53:9
+ --> $DIR/rename.rs:56:9
|
LL | #![warn(clippy::box_vec)]
| ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection`
error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes`
- --> $DIR/rename.rs:54:9
+ --> $DIR/rename.rs:57:9
|
LL | #![warn(clippy::const_static_lifetime)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes`
error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity`
- --> $DIR/rename.rs:55:9
+ --> $DIR/rename.rs:58:9
|
LL | #![warn(clippy::cyclomatic_complexity)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity`
error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq`
- --> $DIR/rename.rs:56:9
+ --> $DIR/rename.rs:59:9
|
LL | #![warn(clippy::derive_hash_xor_eq)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq`
error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods`
- --> $DIR/rename.rs:57:9
+ --> $DIR/rename.rs:60:9
|
LL | #![warn(clippy::disallowed_method)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods`
error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types`
- --> $DIR/rename.rs:58:9
+ --> $DIR/rename.rs:61:9
|
LL | #![warn(clippy::disallowed_type)]
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types`
error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression`
- --> $DIR/rename.rs:59:9
+ --> $DIR/rename.rs:62:9
|
LL | #![warn(clippy::eval_order_dependence)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression`
error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion`
- --> $DIR/rename.rs:60:9
+ --> $DIR/rename.rs:63:9
|
LL | #![warn(clippy::identity_conversion)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion`
error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok`
- --> $DIR/rename.rs:61:9
+ --> $DIR/rename.rs:64:9
|
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`
- --> $DIR/rename.rs:62:9
+ --> $DIR/rename.rs:65: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:63:9
+ --> $DIR/rename.rs:66: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:64:9
+ --> $DIR/rename.rs:67: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:65:9
+ --> $DIR/rename.rs:68: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:66:9
+ --> $DIR/rename.rs:69: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:67:9
+ --> $DIR/rename.rs:70: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:68:9
+ --> $DIR/rename.rs:71: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:69:9
+ --> $DIR/rename.rs:72: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:70:9
+ --> $DIR/rename.rs:73: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:71:9
+ --> $DIR/rename.rs:74: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:72:9
+ --> $DIR/rename.rs:75: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:73:9
+ --> $DIR/rename.rs:76: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:74:9
+ --> $DIR/rename.rs:77: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:75:9
+ --> $DIR/rename.rs:78: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:76:9
+ --> $DIR/rename.rs:79:9
|
LL | #![warn(clippy::to_string_in_display)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl`
error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters`
- --> $DIR/rename.rs:77:9
+ --> $DIR/rename.rs:80: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:81: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:78:9
+ --> $DIR/rename.rs:82: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:83: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:79:9
+ --> $DIR/rename.rs:84: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:80:9
+ --> $DIR/rename.rs:85: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:81:9
+ --> $DIR/rename.rs:86:9
|
LL | #![warn(clippy::drop_ref)]
| ^^^^^^^^^^^^^^^^ help: use the new name: `dropping_references`
error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles`
- --> $DIR/rename.rs:82:9
+ --> $DIR/rename.rs:87: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:83:9
+ --> $DIR/rename.rs:88: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:84:9
+ --> $DIR/rename.rs:89: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:85:9
+ --> $DIR/rename.rs:90: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:86:9
+ --> $DIR/rename.rs:91:9
|
LL | #![warn(clippy::forget_ref)]
| ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references`
error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter`
- --> $DIR/rename.rs:87:9
+ --> $DIR/rename.rs:92: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:88:9
+ --> $DIR/rename.rs:93: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:89:9
+ --> $DIR/rename.rs:94: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:95: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:90:9
+ --> $DIR/rename.rs:96: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:91:9
+ --> $DIR/rename.rs:97: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:92:9
+ --> $DIR/rename.rs:98: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:93:9
+ --> $DIR/rename.rs:99: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:94:9
+ --> $DIR/rename.rs:100: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:101: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:95:9
+ --> $DIR/rename.rs:102: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:96:9
+ --> $DIR/rename.rs:103:9
|
LL | #![warn(clippy::unused_label)]
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels`
-error: aborting due to 48 previous errors
+error: aborting due to 52 previous errors
diff --git a/src/tools/clippy/tests/ui/same_functions_in_if_condition.rs b/src/tools/clippy/tests/ui/same_functions_in_if_condition.rs
index aea1507cc..a207e4221 100644
--- a/src/tools/clippy/tests/ui/same_functions_in_if_condition.rs
+++ b/src/tools/clippy/tests/ui/same_functions_in_if_condition.rs
@@ -10,6 +10,8 @@
clippy::uninlined_format_args
)]
+use std::marker::ConstParamTy;
+
fn function() -> bool {
true
}
@@ -35,33 +37,33 @@ fn ifs_same_cond_fn() {
if function() {
} else if function() {
- //~ ERROR ifs same condition
+ //~^ ERROR: `if` has the same function call as a previous `if`
}
if fn_arg(a) {
} else if fn_arg(a) {
- //~ ERROR ifs same condition
+ //~^ ERROR: `if` has the same function call as a previous `if`
}
if obj.method() {
} else if obj.method() {
- //~ ERROR ifs same condition
+ //~^ ERROR: `if` has the same function call as a previous `if`
}
if obj.method_arg(a) {
} else if obj.method_arg(a) {
- //~ ERROR ifs same condition
+ //~^ ERROR: `if` has the same function call as a previous `if`
}
let mut v = vec![1];
if v.pop().is_none() {
- //~ ERROR ifs same condition
} else if v.pop().is_none() {
+ //~^ ERROR: `if` has the same function call as a previous `if`
}
if v.len() == 42 {
- //~ ERROR ifs same condition
} else if v.len() == 42 {
+ //~^ ERROR: `if` has the same function call as a previous `if`
}
if v.len() == 1 {
@@ -96,7 +98,7 @@ fn main() {
};
println!("{}", os);
- #[derive(PartialEq, Eq)]
+ #[derive(PartialEq, Eq, ConstParamTy)]
enum E {
A,
B,
diff --git a/src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr b/src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr
index aade3b1fa..199e6769f 100644
--- a/src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr
+++ b/src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr
@@ -1,11 +1,11 @@
error: this `if` has the same function call as a previous `if`
- --> $DIR/same_functions_in_if_condition.rs:37:15
+ --> $DIR/same_functions_in_if_condition.rs:39:15
|
LL | } else if function() {
| ^^^^^^^^^^
|
note: same as this
- --> $DIR/same_functions_in_if_condition.rs:36:8
+ --> $DIR/same_functions_in_if_condition.rs:38:8
|
LL | if function() {
| ^^^^^^^^^^
@@ -16,61 +16,61 @@ LL | #![deny(clippy::same_functions_in_if_condition)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this `if` has the same function call as a previous `if`
- --> $DIR/same_functions_in_if_condition.rs:42:15
+ --> $DIR/same_functions_in_if_condition.rs:44:15
|
LL | } else if fn_arg(a) {
| ^^^^^^^^^
|
note: same as this
- --> $DIR/same_functions_in_if_condition.rs:41:8
+ --> $DIR/same_functions_in_if_condition.rs:43:8
|
LL | if fn_arg(a) {
| ^^^^^^^^^
error: this `if` has the same function call as a previous `if`
- --> $DIR/same_functions_in_if_condition.rs:47:15
+ --> $DIR/same_functions_in_if_condition.rs:49:15
|
LL | } else if obj.method() {
| ^^^^^^^^^^^^
|
note: same as this
- --> $DIR/same_functions_in_if_condition.rs:46:8
+ --> $DIR/same_functions_in_if_condition.rs:48:8
|
LL | if obj.method() {
| ^^^^^^^^^^^^
error: this `if` has the same function call as a previous `if`
- --> $DIR/same_functions_in_if_condition.rs:52:15
+ --> $DIR/same_functions_in_if_condition.rs:54:15
|
LL | } else if obj.method_arg(a) {
| ^^^^^^^^^^^^^^^^^
|
note: same as this
- --> $DIR/same_functions_in_if_condition.rs:51:8
+ --> $DIR/same_functions_in_if_condition.rs:53:8
|
LL | if obj.method_arg(a) {
| ^^^^^^^^^^^^^^^^^
error: this `if` has the same function call as a previous `if`
- --> $DIR/same_functions_in_if_condition.rs:59:15
+ --> $DIR/same_functions_in_if_condition.rs:60:15
|
LL | } else if v.pop().is_none() {
| ^^^^^^^^^^^^^^^^^
|
note: same as this
- --> $DIR/same_functions_in_if_condition.rs:57:8
+ --> $DIR/same_functions_in_if_condition.rs:59:8
|
LL | if v.pop().is_none() {
| ^^^^^^^^^^^^^^^^^
error: this `if` has the same function call as a previous `if`
- --> $DIR/same_functions_in_if_condition.rs:64:15
+ --> $DIR/same_functions_in_if_condition.rs:65:15
|
LL | } else if v.len() == 42 {
| ^^^^^^^^^^^^^
|
note: same as this
- --> $DIR/same_functions_in_if_condition.rs:62:8
+ --> $DIR/same_functions_in_if_condition.rs:64:8
|
LL | if v.len() == 42 {
| ^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/search_is_some.rs b/src/tools/clippy/tests/ui/search_is_some.rs
index 670599b0d..3cdbfaa16 100644
--- a/src/tools/clippy/tests/ui/search_is_some.rs
+++ b/src/tools/clippy/tests/ui/search_is_some.rs
@@ -1,5 +1,6 @@
//@aux-build:option_helpers.rs
#![warn(clippy::search_is_some)]
+#![allow(clippy::useless_vec)]
#![allow(dead_code)]
extern crate option_helpers;
use option_helpers::IteratorFalsePositives;
diff --git a/src/tools/clippy/tests/ui/search_is_some.stderr b/src/tools/clippy/tests/ui/search_is_some.stderr
index 6bea8c674..7eff614d1 100644
--- a/src/tools/clippy/tests/ui/search_is_some.stderr
+++ b/src/tools/clippy/tests/ui/search_is_some.stderr
@@ -1,5 +1,5 @@
error: called `is_some()` after searching an `Iterator` with `find`
- --> $DIR/search_is_some.rs:14:13
+ --> $DIR/search_is_some.rs:15:13
|
LL | let _ = v.iter().find(|&x| {
| _____________^
@@ -12,7 +12,7 @@ LL | | ).is_some();
= note: `-D clippy::search-is-some` implied by `-D warnings`
error: called `is_some()` after searching an `Iterator` with `position`
- --> $DIR/search_is_some.rs:20:13
+ --> $DIR/search_is_some.rs:21:13
|
LL | let _ = v.iter().position(|&x| {
| _____________^
@@ -24,7 +24,7 @@ LL | | ).is_some();
= help: this is more succinctly expressed by calling `any()`
error: called `is_some()` after searching an `Iterator` with `rposition`
- --> $DIR/search_is_some.rs:26:13
+ --> $DIR/search_is_some.rs:27:13
|
LL | let _ = v.iter().rposition(|&x| {
| _____________^
@@ -36,13 +36,13 @@ LL | | ).is_some();
= help: this is more succinctly expressed by calling `any()`
error: called `is_some()` after searching an `Iterator` with `find`
- --> $DIR/search_is_some.rs:41:20
+ --> $DIR/search_is_some.rs:42:20
|
LL | let _ = (0..1).find(some_closure).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(some_closure)`
error: called `is_none()` after searching an `Iterator` with `find`
- --> $DIR/search_is_some.rs:51:13
+ --> $DIR/search_is_some.rs:52:13
|
LL | let _ = v.iter().find(|&x| {
| _____________^
@@ -54,7 +54,7 @@ LL | | ).is_none();
= help: this is more succinctly expressed by calling `any()` with negation
error: called `is_none()` after searching an `Iterator` with `position`
- --> $DIR/search_is_some.rs:57:13
+ --> $DIR/search_is_some.rs:58:13
|
LL | let _ = v.iter().position(|&x| {
| _____________^
@@ -66,7 +66,7 @@ LL | | ).is_none();
= help: this is more succinctly expressed by calling `any()` with negation
error: called `is_none()` after searching an `Iterator` with `rposition`
- --> $DIR/search_is_some.rs:63:13
+ --> $DIR/search_is_some.rs:64:13
|
LL | let _ = v.iter().rposition(|&x| {
| _____________^
@@ -78,7 +78,7 @@ LL | | ).is_none();
= help: this is more succinctly expressed by calling `any()` with negation
error: called `is_none()` after searching an `Iterator` with `find`
- --> $DIR/search_is_some.rs:78:13
+ --> $DIR/search_is_some.rs:79:13
|
LL | let _ = (0..1).find(some_closure).is_none();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `!_.any()` instead: `!(0..1).any(some_closure)`
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 9386618c1..08fb87cb3 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,5 +1,5 @@
//@run-rustfix
-#![allow(dead_code, clippy::explicit_auto_deref)]
+#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)]
#![warn(clippy::search_is_some)]
fn main() {
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 6b2537a96..ec3386933 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,5 +1,5 @@
//@run-rustfix
-#![allow(dead_code, clippy::explicit_auto_deref)]
+#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)]
#![warn(clippy::search_is_some)]
fn main() {
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 e9116fc59..aa16f9da0 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,5 +1,5 @@
//@run-rustfix
-#![allow(dead_code, clippy::explicit_auto_deref)]
+#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)]
#![warn(clippy::search_is_some)]
fn main() {
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 b15283994..aeb6f118b 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,5 +1,5 @@
//@run-rustfix
-#![allow(dead_code, clippy::explicit_auto_deref)]
+#![allow(dead_code, clippy::explicit_auto_deref, clippy::useless_vec)]
#![warn(clippy::search_is_some)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/self_assignment.rs b/src/tools/clippy/tests/ui/self_assignment.rs
index ef6476229..ec3ae1209 100644
--- a/src/tools/clippy/tests/ui/self_assignment.rs
+++ b/src/tools/clippy/tests/ui/self_assignment.rs
@@ -1,4 +1,5 @@
#![warn(clippy::self_assignment)]
+#![allow(clippy::useless_vec)]
pub struct S<'a> {
a: i32,
diff --git a/src/tools/clippy/tests/ui/self_assignment.stderr b/src/tools/clippy/tests/ui/self_assignment.stderr
index 826e0d0ba..bed88244e 100644
--- a/src/tools/clippy/tests/ui/self_assignment.stderr
+++ b/src/tools/clippy/tests/ui/self_assignment.stderr
@@ -1,5 +1,5 @@
error: self-assignment of `a` to `a`
- --> $DIR/self_assignment.rs:12:5
+ --> $DIR/self_assignment.rs:13:5
|
LL | a = a;
| ^^^^^
@@ -7,61 +7,61 @@ LL | a = a;
= note: `-D clippy::self-assignment` implied by `-D warnings`
error: self-assignment of `*b` to `*b`
- --> $DIR/self_assignment.rs:13:5
+ --> $DIR/self_assignment.rs:14:5
|
LL | *b = *b;
| ^^^^^^^
error: self-assignment of `s` to `s`
- --> $DIR/self_assignment.rs:14:5
+ --> $DIR/self_assignment.rs:15:5
|
LL | s = s;
| ^^^^^
error: self-assignment of `s.a` to `s.a`
- --> $DIR/self_assignment.rs:15:5
+ --> $DIR/self_assignment.rs:16:5
|
LL | s.a = s.a;
| ^^^^^^^^^
error: self-assignment of `s.b[5 + 5]` to `s.b[10]`
- --> $DIR/self_assignment.rs:16:5
+ --> $DIR/self_assignment.rs:17:5
|
LL | s.b[10] = s.b[5 + 5];
| ^^^^^^^^^^^^^^^^^^^^
error: self-assignment of `s.c[0][1]` to `s.c[0][1]`
- --> $DIR/self_assignment.rs:17:5
+ --> $DIR/self_assignment.rs:18: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:18:5
+ --> $DIR/self_assignment.rs:19:5
|
LL | s.b[a] = s.b[a];
| ^^^^^^^^^^^^^^^
error: self-assignment of `*s.e` to `*s.e`
- --> $DIR/self_assignment.rs:19:5
+ --> $DIR/self_assignment.rs:20:5
|
LL | *s.e = *s.e;
| ^^^^^^^^^^^
error: self-assignment of `s.b[10 + a]` to `s.b[a + 10]`
- --> $DIR/self_assignment.rs:20:5
+ --> $DIR/self_assignment.rs:21:5
|
LL | s.b[a + 10] = s.b[10 + a];
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: self-assignment of `t.1` to `t.1`
- --> $DIR/self_assignment.rs:23:5
+ --> $DIR/self_assignment.rs:24:5
|
LL | t.1 = t.1;
| ^^^^^^^^^
error: self-assignment of `(t.0)` to `t.0`
- --> $DIR/self_assignment.rs:24:5
+ --> $DIR/self_assignment.rs:25:5
|
LL | t.0 = (t.0);
| ^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/shadow.rs b/src/tools/clippy/tests/ui/shadow.rs
index 2c0fc3e3f..9be8c5e59 100644
--- a/src/tools/clippy/tests/ui/shadow.rs
+++ b/src/tools/clippy/tests/ui/shadow.rs
@@ -1,7 +1,7 @@
-//@aux-build:proc_macro_derive.rs
+//@aux-build:proc_macro_derive.rs:proc-macro
#![warn(clippy::shadow_same, clippy::shadow_reuse, clippy::shadow_unrelated)]
-#![allow(clippy::let_unit_value)]
+#![allow(clippy::let_unit_value, clippy::needless_if)]
extern crate proc_macro_derive;
diff --git a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.fixed b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.fixed
new file mode 100644
index 000000000..acc78d6bb
--- /dev/null
+++ b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.fixed
@@ -0,0 +1,627 @@
+// 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<u64>,
+}
+
+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<CounterWrapper> {
+ 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<u64>,
+}
+
+impl StateWithBoxedMutexGuard {
+ fn new() -> StateWithBoxedMutexGuard {
+ StateWithBoxedMutexGuard { u: Mutex::new(42) }
+ }
+ fn lock(&self) -> Box<MutexGuard<u64>> {
+ 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<String>,
+}
+
+impl StateStringWithBoxedMutexGuard {
+ fn new() -> StateStringWithBoxedMutexGuard {
+ StateStringWithBoxedMutexGuard {
+ s: Mutex::new("A String".to_owned()),
+ }
+ }
+ fn lock(&self) -> Box<MutexGuard<String>> {
+ 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<Box<RecursiveEnum>>),
+}
+
+#[derive(Debug)]
+enum GenericRecursiveEnum<T> {
+ Foo(T, Option<Box<GenericRecursiveEnum<T>>>),
+}
+
+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<u64, ParseIntError> {
+ // 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::<u64>()?;
+ println!("{}", result);
+ rwlock.write().unwrap().push('2');
+ Ok(result)
+}
+
+struct ResultReturner {
+ s: String,
+}
+
+impl ResultReturner {
+ fn to_number(&self) -> Result<i64, ParseIntError> {
+ self.s.parse::<i64>()
+ }
+}
+
+fn should_trigger_lint_for_non_ref_move_and_clone_suggestion() {
+ let rwlock = RwLock::<ResultReturner>::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::<Vec<String>>::new(vec!["1".to_string()]);
+ for s in rwlock.read().unwrap().iter() {
+ println!("{}", s);
+ }
+}
+
+fn do_bar(mutex: &Mutex<State>) {
+ 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_tightening.fixed b/src/tools/clippy/tests/ui/significant_drop_tightening.fixed
index ee7f2b063..7b848ead7 100644
--- a/src/tools/clippy/tests/ui/significant_drop_tightening.fixed
+++ b/src/tools/clippy/tests/ui/significant_drop_tightening.fixed
@@ -16,6 +16,18 @@ pub fn complex_return_triggers_the_lint() -> i32 {
foo()
}
+pub fn issue_10413() {
+ let mutex = Mutex::new(Some(1));
+ let opt = Some(1);
+ if opt.is_some() {
+ let lock = mutex.lock().unwrap();
+ let _ = *lock;
+ if opt.is_some() {
+ let _ = *lock;
+ }
+ }
+}
+
pub fn path_return_can_be_ignored() -> i32 {
let mutex = Mutex::new(1);
let lock = mutex.lock().unwrap();
diff --git a/src/tools/clippy/tests/ui/significant_drop_tightening.rs b/src/tools/clippy/tests/ui/significant_drop_tightening.rs
index 9c139deb9..36f77cf1b 100644
--- a/src/tools/clippy/tests/ui/significant_drop_tightening.rs
+++ b/src/tools/clippy/tests/ui/significant_drop_tightening.rs
@@ -15,6 +15,18 @@ pub fn complex_return_triggers_the_lint() -> i32 {
foo()
}
+pub fn issue_10413() {
+ let mutex = Mutex::new(Some(1));
+ let opt = Some(1);
+ if opt.is_some() {
+ let lock = mutex.lock().unwrap();
+ let _ = *lock;
+ if opt.is_some() {
+ let _ = *lock;
+ }
+ }
+}
+
pub fn path_return_can_be_ignored() -> i32 {
let mutex = Mutex::new(1);
let lock = mutex.lock().unwrap();
diff --git a/src/tools/clippy/tests/ui/significant_drop_tightening.stderr b/src/tools/clippy/tests/ui/significant_drop_tightening.stderr
index ab8ce356e..3bdac0b0a 100644
--- a/src/tools/clippy/tests/ui/significant_drop_tightening.stderr
+++ b/src/tools/clippy/tests/ui/significant_drop_tightening.stderr
@@ -23,7 +23,7 @@ LL + drop(lock);
|
error: temporary with significant `Drop` can be early dropped
- --> $DIR/significant_drop_tightening.rs:44:13
+ --> $DIR/significant_drop_tightening.rs:56:13
|
LL | / {
LL | | let mutex = Mutex::new(1i32);
@@ -43,7 +43,7 @@ LL + drop(lock);
|
error: temporary with significant `Drop` can be early dropped
- --> $DIR/significant_drop_tightening.rs:65:13
+ --> $DIR/significant_drop_tightening.rs:77:13
|
LL | / {
LL | | let mutex = Mutex::new(1i32);
@@ -67,7 +67,7 @@ LL +
|
error: temporary with significant `Drop` can be early dropped
- --> $DIR/significant_drop_tightening.rs:71:17
+ --> $DIR/significant_drop_tightening.rs:83:17
|
LL | / {
LL | | let mutex = Mutex::new(vec![1i32]);
diff --git a/src/tools/clippy/tests/ui/single_call_fn.rs b/src/tools/clippy/tests/ui/single_call_fn.rs
new file mode 100644
index 000000000..76e175014
--- /dev/null
+++ b/src/tools/clippy/tests/ui/single_call_fn.rs
@@ -0,0 +1,74 @@
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(clippy::redundant_closure_call, unused)]
+#![warn(clippy::single_call_fn)]
+#![no_main]
+
+#[macro_use]
+extern crate proc_macros;
+
+// Do not lint since it's public
+pub fn f() {}
+
+fn i() {}
+fn j() {}
+
+fn h() {
+ // Linted
+ let a = i;
+ // Do not lint closures
+ let a = (|| {
+ // Not linted
+ a();
+ // Imo, it's reasonable to lint this as the function is still only being used once. Just in
+ // a closure.
+ j();
+ });
+ a();
+}
+
+fn g() {
+ f();
+}
+
+fn c() {
+ println!("really");
+ println!("long");
+ println!("function...");
+}
+
+fn d() {
+ c();
+}
+
+fn a() {}
+
+fn b() {
+ a();
+
+ external! {
+ fn lol() {
+ lol_inner();
+ }
+ fn lol_inner() {}
+ }
+ with_span! {
+ span
+ fn lol2() {
+ lol2_inner();
+ }
+ fn lol2_inner() {}
+ }
+}
+
+fn e() {
+ b();
+ b();
+}
+
+#[test]
+fn k() {}
+
+#[test]
+fn l() {
+ k();
+}
diff --git a/src/tools/clippy/tests/ui/single_call_fn.stderr b/src/tools/clippy/tests/ui/single_call_fn.stderr
new file mode 100644
index 000000000..9ef8c4878
--- /dev/null
+++ b/src/tools/clippy/tests/ui/single_call_fn.stderr
@@ -0,0 +1,55 @@
+error: this function is only used once
+ --> $DIR/single_call_fn.rs:33:1
+ |
+LL | / fn c() {
+LL | | println!("really");
+LL | | println!("long");
+LL | | println!("function...");
+LL | | }
+ | |_^
+ |
+help: used here
+ --> $DIR/single_call_fn.rs:40:5
+ |
+LL | c();
+ | ^
+ = note: `-D clippy::single-call-fn` implied by `-D warnings`
+
+error: this function is only used once
+ --> $DIR/single_call_fn.rs:12:1
+ |
+LL | fn i() {}
+ | ^^^^^^^^^
+ |
+help: used here
+ --> $DIR/single_call_fn.rs:17:13
+ |
+LL | let a = i;
+ | ^
+
+error: this function is only used once
+ --> $DIR/single_call_fn.rs:43:1
+ |
+LL | fn a() {}
+ | ^^^^^^^^^
+ |
+help: used here
+ --> $DIR/single_call_fn.rs:46:5
+ |
+LL | a();
+ | ^
+
+error: this function is only used once
+ --> $DIR/single_call_fn.rs:13:1
+ |
+LL | fn j() {}
+ | ^^^^^^^^^
+ |
+help: used here
+ --> $DIR/single_call_fn.rs:24:9
+ |
+LL | j();
+ | ^
+
+error: aborting due to 4 previous errors
+
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 cbcf1ab21..cb301c8bc 100644
--- a/src/tools/clippy/tests/ui/single_char_add_str.fixed
+++ b/src/tools/clippy/tests/ui/single_char_add_str.fixed
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::single_char_add_str)]
+#![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes)]
macro_rules! get_string {
() => {
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 a1f005cc8..99baf35ac 100644
--- a/src/tools/clippy/tests/ui/single_char_add_str.rs
+++ b/src/tools/clippy/tests/ui/single_char_add_str.rs
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::single_char_add_str)]
+#![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes)]
macro_rules! get_string {
() => {
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 55d91583a..3f93c1847 100644
--- a/src/tools/clippy/tests/ui/single_char_add_str.stderr
+++ b/src/tools/clippy/tests/ui/single_char_add_str.stderr
@@ -1,5 +1,5 @@
error: calling `push_str()` using a single-character string literal
- --> $DIR/single_char_add_str.rs:14:5
+ --> $DIR/single_char_add_str.rs:15:5
|
LL | string.push_str("R");
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `push` with a character literal: `string.push('R')`
@@ -7,85 +7,85 @@ LL | string.push_str("R");
= note: `-D clippy::single-char-add-str` implied by `-D warnings`
error: calling `push_str()` using a single-character string literal
- --> $DIR/single_char_add_str.rs:15:5
+ --> $DIR/single_char_add_str.rs:16:5
|
LL | string.push_str("'");
| ^^^^^^^^^^^^^^^^^^^^ 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:20:5
+ --> $DIR/single_char_add_str.rs:21:5
|
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:21:5
+ --> $DIR/single_char_add_str.rs:22:5
|
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:22:5
+ --> $DIR/single_char_add_str.rs:23: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:24:5
+ --> $DIR/single_char_add_str.rs:25: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:29:5
+ --> $DIR/single_char_add_str.rs:30: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:30:5
+ --> $DIR/single_char_add_str.rs:31:5
|
LL | string.insert_str(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:35:5
+ --> $DIR/single_char_add_str.rs:36:5
|
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:36:5
+ --> $DIR/single_char_add_str.rs:37:5
|
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:38:5
+ --> $DIR/single_char_add_str.rs:39: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:40:5
+ --> $DIR/single_char_add_str.rs:41: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:41: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, '"')`
error: calling `insert_str()` using a single-character string literal
- --> $DIR/single_char_add_str.rs:42:5
+ --> $DIR/single_char_add_str.rs:43: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:44:5
+ --> $DIR/single_char_add_str.rs:45: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_pattern.fixed b/src/tools/clippy/tests/ui/single_char_pattern.fixed
index dba898720..7ae62231a 100644
--- a/src/tools/clippy/tests/ui/single_char_pattern.fixed
+++ b/src/tools/clippy/tests/ui/single_char_pattern.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
-#![allow(unused_must_use)]
+#![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 6a145a14b..0604624e7 100644
--- a/src/tools/clippy/tests/ui/single_char_pattern.rs
+++ b/src/tools/clippy/tests/ui/single_char_pattern.rs
@@ -1,6 +1,6 @@
//@run-rustfix
-#![allow(unused_must_use)]
+#![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 5564aac67..5ae2450c2 100644
--- a/src/tools/clippy/tests/ui/single_char_pattern.stderr
+++ b/src/tools/clippy/tests/ui/single_char_pattern.stderr
@@ -226,13 +226,13 @@ error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:65: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:66:13
|
LL | x.split(r"/");
- | ^^^^ help: try using a `char` instead: `'/'`
+ | ^^^^ help: try using a `char` instead: `'//'`
error: aborting due to 39 previous errors
diff --git a/src/tools/clippy/tests/ui/single_element_loop.fixed b/src/tools/clippy/tests/ui/single_element_loop.fixed
index 1697a0cf2..598f25941 100644
--- a/src/tools/clippy/tests/ui/single_element_loop.fixed
+++ b/src/tools/clippy/tests/ui/single_element_loop.fixed
@@ -1,6 +1,8 @@
//@run-rustfix
// Tests from for_loop.rs that don't have suggestions
+#![allow(clippy::single_range_in_vec_init)]
+
#[warn(clippy::single_element_loop)]
fn main() {
let item1 = 2;
diff --git a/src/tools/clippy/tests/ui/single_element_loop.rs b/src/tools/clippy/tests/ui/single_element_loop.rs
index 860424f42..3fc461735 100644
--- a/src/tools/clippy/tests/ui/single_element_loop.rs
+++ b/src/tools/clippy/tests/ui/single_element_loop.rs
@@ -1,6 +1,8 @@
//@run-rustfix
// Tests from for_loop.rs that don't have suggestions
+#![allow(clippy::single_range_in_vec_init)]
+
#[warn(clippy::single_element_loop)]
fn main() {
let item1 = 2;
diff --git a/src/tools/clippy/tests/ui/single_element_loop.stderr b/src/tools/clippy/tests/ui/single_element_loop.stderr
index 14437a597..c40c61989 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:7:5
+ --> $DIR/single_element_loop.rs:9:5
|
LL | / for item in &[item1] {
LL | | dbg!(item);
@@ -16,7 +16,7 @@ LL + }
|
error: for loop over a single element
- --> $DIR/single_element_loop.rs:11:5
+ --> $DIR/single_element_loop.rs:13:5
|
LL | / for item in [item1].iter() {
LL | | dbg!(item);
@@ -32,7 +32,7 @@ LL + }
|
error: for loop over a single element
- --> $DIR/single_element_loop.rs:15:5
+ --> $DIR/single_element_loop.rs:17:5
|
LL | / for item in &[0..5] {
LL | | dbg!(item);
@@ -48,7 +48,7 @@ LL + }
|
error: for loop over a single element
- --> $DIR/single_element_loop.rs:19:5
+ --> $DIR/single_element_loop.rs:21:5
|
LL | / for item in [0..5].iter_mut() {
LL | | dbg!(item);
@@ -64,7 +64,7 @@ LL + }
|
error: for loop over a single element
- --> $DIR/single_element_loop.rs:23:5
+ --> $DIR/single_element_loop.rs:25:5
|
LL | / for item in [0..5] {
LL | | dbg!(item);
@@ -80,7 +80,7 @@ LL + }
|
error: for loop over a single element
- --> $DIR/single_element_loop.rs:27:5
+ --> $DIR/single_element_loop.rs:29:5
|
LL | / for item in [0..5].into_iter() {
LL | | dbg!(item);
@@ -96,7 +96,7 @@ LL + }
|
error: for loop over a single element
- --> $DIR/single_element_loop.rs:46:5
+ --> $DIR/single_element_loop.rs:48: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
new file mode 100644
index 000000000..e7b1fd6a8
--- /dev/null
+++ b/src/tools/clippy/tests/ui/single_match.fixed
@@ -0,0 +1,254 @@
+//@run-rustfix
+#![warn(clippy::single_match)]
+#![allow(
+ unused,
+ clippy::uninlined_format_args,
+ clippy::needless_if,
+ clippy::redundant_pattern_matching
+)]
+fn dummy() {}
+
+fn single_match() {
+ let x = Some(1u8);
+
+ if let Some(y) = x {
+ println!("{:?}", y);
+ };
+
+ let x = Some(1u8);
+ if let Some(y) = x { println!("{:?}", y) }
+
+ let z = (1u8, 1u8);
+ if let (2..=3, 7..=9) = z { dummy() };
+
+ // Not linted (pattern guards used)
+ match x {
+ Some(y) if y == 0 => println!("{:?}", y),
+ _ => (),
+ }
+
+ // Not linted (no block with statements in the single arm)
+ match z {
+ (2..=3, 7..=9) => println!("{:?}", z),
+ _ => println!("nope"),
+ }
+}
+
+enum Foo {
+ Bar,
+ Baz(u8),
+}
+use std::borrow::Cow;
+use Foo::*;
+
+fn single_match_know_enum() {
+ let x = Some(1u8);
+ let y: Result<_, i8> = Ok(1i8);
+
+ if let Some(y) = x { dummy() };
+
+ if let Ok(y) = y { dummy() };
+
+ let c = Cow::Borrowed("");
+
+ if let Cow::Borrowed(..) = c { dummy() };
+
+ let z = Foo::Bar;
+ // no warning
+ match z {
+ Bar => println!("42"),
+ Baz(_) => (),
+ }
+
+ match z {
+ Baz(_) => println!("42"),
+ Bar => (),
+ }
+}
+
+// issue #173
+fn if_suggestion() {
+ let x = "test";
+ if x == "test" { println!() }
+
+ #[derive(PartialEq, Eq)]
+ enum Foo {
+ A,
+ B,
+ C(u32),
+ }
+
+ let x = Foo::A;
+ if x == Foo::A { println!() }
+
+ const FOO_C: Foo = Foo::C(0);
+ if x == FOO_C { println!() }
+
+ if x == Foo::A { println!() }
+
+ let x = &x;
+ if x == &Foo::A { println!() }
+
+ enum Bar {
+ A,
+ B,
+ }
+ impl PartialEq for Bar {
+ fn eq(&self, rhs: &Self) -> bool {
+ matches!((self, rhs), (Self::A, Self::A) | (Self::B, Self::B))
+ }
+ }
+ impl Eq for Bar {}
+
+ let x = Bar::A;
+ if let Bar::A = x { println!() }
+
+ // issue #7038
+ struct X;
+ let x = Some(X);
+ if let None = x { println!() };
+}
+
+// See: issue #8282
+fn ranges() {
+ enum E {
+ V,
+ }
+ let x = (Some(E::V), Some(42));
+
+ // Don't lint, because the `E` enum can be extended with additional fields later. Thus, the
+ // proposed replacement to `if let Some(E::V)` may hide non-exhaustive warnings that appeared
+ // because of `match` construction.
+ match x {
+ (Some(E::V), _) => {},
+ (None, _) => {},
+ }
+
+ // lint
+ if let (Some(_), _) = x {}
+
+ // lint
+ if let (Some(E::V), _) = x { todo!() }
+
+ // lint
+ if let (.., Some(E::V), _) = (Some(42), Some(E::V), Some(42)) {}
+
+ // Don't lint, see above.
+ match (Some(E::V), Some(E::V), Some(E::V)) {
+ (.., Some(E::V), _) => {},
+ (.., None, _) => {},
+ }
+
+ // Don't lint, see above.
+ match (Some(E::V), Some(E::V), Some(E::V)) {
+ (Some(E::V), ..) => {},
+ (None, ..) => {},
+ }
+
+ // Don't lint, see above.
+ match (Some(E::V), Some(E::V), Some(E::V)) {
+ (_, Some(E::V), ..) => {},
+ (_, None, ..) => {},
+ }
+}
+
+fn skip_type_aliases() {
+ enum OptionEx {
+ Some(i32),
+ None,
+ }
+ enum ResultEx {
+ Err(i32),
+ Ok(i32),
+ }
+
+ use OptionEx::{None, Some};
+ use ResultEx::{Err, Ok};
+
+ // don't lint
+ match Err(42) {
+ Ok(_) => dummy(),
+ Err(_) => (),
+ };
+
+ // don't lint
+ match Some(1i32) {
+ Some(_) => dummy(),
+ None => (),
+ };
+}
+
+macro_rules! single_match {
+ ($num:literal) => {
+ match $num {
+ 15 => println!("15"),
+ _ => (),
+ }
+ };
+}
+
+fn main() {
+ single_match!(5);
+
+ // Don't lint
+ let _ = match Some(0) {
+ #[cfg(feature = "foo")]
+ Some(10) => 11,
+ Some(x) => x,
+ _ => 0,
+ };
+}
+
+fn issue_10808(bar: Option<i32>) {
+ if let Some(v) = bar { unsafe {
+ let r = &v as *const i32;
+ println!("{}", *r);
+ } }
+
+ if let Some(v) = bar {
+ unsafe {
+ let r = &v as *const i32;
+ println!("{}", *r);
+ }
+ }
+}
+
+mod issue8634 {
+ struct SomeError(i32, i32);
+
+ fn foo(x: Result<i32, ()>) {
+ match x {
+ Ok(y) => {
+ println!("Yay! {y}");
+ },
+ Err(()) => {
+ // Ignore this error because blah blah blah.
+ },
+ }
+ }
+
+ fn bar(x: Result<i32, SomeError>) {
+ match x {
+ Ok(y) => {
+ println!("Yay! {y}");
+ },
+ Err(_) => {
+ // TODO: Process the error properly.
+ },
+ }
+ }
+
+ fn block_comment(x: Result<i32, SomeError>) {
+ match x {
+ Ok(y) => {
+ println!("Yay! {y}");
+ },
+ Err(_) => {
+ /*
+ let's make sure that this also
+ does not lint block comments.
+ */
+ },
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/single_match.rs b/src/tools/clippy/tests/ui/single_match.rs
index d0c9b7b56..1515a7053 100644
--- a/src/tools/clippy/tests/ui/single_match.rs
+++ b/src/tools/clippy/tests/ui/single_match.rs
@@ -1,6 +1,11 @@
+//@run-rustfix
#![warn(clippy::single_match)]
-#![allow(clippy::uninlined_format_args)]
-
+#![allow(
+ unused,
+ clippy::uninlined_format_args,
+ clippy::needless_if,
+ clippy::redundant_pattern_matching
+)]
fn dummy() {}
fn single_match() {
@@ -244,3 +249,64 @@ fn main() {
_ => 0,
};
}
+
+fn issue_10808(bar: Option<i32>) {
+ match bar {
+ Some(v) => unsafe {
+ let r = &v as *const i32;
+ println!("{}", *r);
+ },
+ _ => {},
+ }
+
+ match bar {
+ #[rustfmt::skip]
+ Some(v) => {
+ unsafe {
+ let r = &v as *const i32;
+ println!("{}", *r);
+ }
+ },
+ _ => {},
+ }
+}
+
+mod issue8634 {
+ struct SomeError(i32, i32);
+
+ fn foo(x: Result<i32, ()>) {
+ match x {
+ Ok(y) => {
+ println!("Yay! {y}");
+ },
+ Err(()) => {
+ // Ignore this error because blah blah blah.
+ },
+ }
+ }
+
+ fn bar(x: Result<i32, SomeError>) {
+ match x {
+ Ok(y) => {
+ println!("Yay! {y}");
+ },
+ Err(_) => {
+ // TODO: Process the error properly.
+ },
+ }
+ }
+
+ fn block_comment(x: Result<i32, SomeError>) {
+ match x {
+ Ok(y) => {
+ println!("Yay! {y}");
+ },
+ Err(_) => {
+ /*
+ let's make sure that this also
+ does not lint block comments.
+ */
+ },
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/single_match.stderr b/src/tools/clippy/tests/ui/single_match.stderr
index 7cecc1b73..ef9015132 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:9:5
+ --> $DIR/single_match.rs:14:5
|
LL | / match x {
LL | | Some(y) => {
@@ -18,7 +18,7 @@ LL ~ };
|
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:17:5
+ --> $DIR/single_match.rs:22:5
|
LL | / match x {
LL | | // Note the missing block braces.
@@ -30,7 +30,7 @@ LL | | }
| |_____^ help: try this: `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:26:5
+ --> $DIR/single_match.rs:31:5
|
LL | / match z {
LL | | (2..=3, 7..=9) => dummy(),
@@ -39,7 +39,7 @@ LL | | };
| |_____^ help: try this: `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:55:5
+ --> $DIR/single_match.rs:60:5
|
LL | / match x {
LL | | Some(y) => dummy(),
@@ -48,7 +48,7 @@ LL | | };
| |_____^ help: try this: `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:60:5
+ --> $DIR/single_match.rs:65:5
|
LL | / match y {
LL | | Ok(y) => dummy(),
@@ -57,7 +57,7 @@ LL | | };
| |_____^ help: try this: `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:67:5
+ --> $DIR/single_match.rs:72:5
|
LL | / match c {
LL | | Cow::Borrowed(..) => dummy(),
@@ -66,7 +66,7 @@ LL | | };
| |_____^ help: try this: `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:88:5
+ --> $DIR/single_match.rs:93:5
|
LL | / match x {
LL | | "test" => println!(),
@@ -75,7 +75,7 @@ LL | | }
| |_____^ help: try this: `if x == "test" { println!() }`
error: you seem to be trying to use `match` for an equality check. Consider using `if`
- --> $DIR/single_match.rs:101:5
+ --> $DIR/single_match.rs:106:5
|
LL | / match x {
LL | | Foo::A => println!(),
@@ -84,7 +84,7 @@ LL | | }
| |_____^ help: try this: `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:107:5
+ --> $DIR/single_match.rs:112:5
|
LL | / match x {
LL | | FOO_C => println!(),
@@ -93,7 +93,7 @@ LL | | }
| |_____^ help: try this: `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:112:5
+ --> $DIR/single_match.rs:117:5
|
LL | / match &&x {
LL | | Foo::A => println!(),
@@ -102,7 +102,7 @@ LL | | }
| |_____^ help: try this: `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:118:5
+ --> $DIR/single_match.rs:123:5
|
LL | / match &x {
LL | | Foo::A => println!(),
@@ -111,7 +111,7 @@ LL | | }
| |_____^ help: try this: `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:135:5
+ --> $DIR/single_match.rs:140:5
|
LL | / match x {
LL | | Bar::A => println!(),
@@ -120,7 +120,7 @@ LL | | }
| |_____^ help: try this: `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:143:5
+ --> $DIR/single_match.rs:148:5
|
LL | / match x {
LL | | None => println!(),
@@ -129,7 +129,7 @@ LL | | };
| |_____^ help: try this: `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:165:5
+ --> $DIR/single_match.rs:170:5
|
LL | / match x {
LL | | (Some(_), _) => {},
@@ -138,7 +138,7 @@ LL | | }
| |_____^ help: try this: `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:171:5
+ --> $DIR/single_match.rs:176:5
|
LL | / match x {
LL | | (Some(E::V), _) => todo!(),
@@ -147,7 +147,7 @@ LL | | }
| |_____^ help: try this: `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:177:5
+ --> $DIR/single_match.rs:182:5
|
LL | / match (Some(42), Some(E::V), Some(42)) {
LL | | (.., Some(E::V), _) => {},
@@ -155,5 +155,47 @@ LL | | (..) => {},
LL | | }
| |_____^ help: try this: `if let (.., Some(E::V), _) = (Some(42), Some(E::V), Some(42)) {}`
-error: aborting due to 16 previous errors
+error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
+ --> $DIR/single_match.rs:254:5
+ |
+LL | / match bar {
+LL | | Some(v) => unsafe {
+LL | | let r = &v as *const i32;
+LL | | println!("{}", *r);
+LL | | },
+LL | | _ => {},
+LL | | }
+ | |_____^
+ |
+help: try this
+ |
+LL ~ if let Some(v) = bar { unsafe {
+LL + let r = &v as *const i32;
+LL + println!("{}", *r);
+LL + } }
+ |
+
+error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
+ --> $DIR/single_match.rs:262:5
+ |
+LL | / match bar {
+LL | | #[rustfmt::skip]
+LL | | Some(v) => {
+LL | | unsafe {
+... |
+LL | | _ => {},
+LL | | }
+ | |_____^
+ |
+help: try this
+ |
+LL ~ if let Some(v) = bar {
+LL + unsafe {
+LL + let r = &v as *const i32;
+LL + println!("{}", *r);
+LL + }
+LL + }
+ |
+
+error: aborting due to 18 previous errors
diff --git a/src/tools/clippy/tests/ui/single_match_else.fixed b/src/tools/clippy/tests/ui/single_match_else.fixed
new file mode 100644
index 000000000..fcc8f1480
--- /dev/null
+++ b/src/tools/clippy/tests/ui/single_match_else.fixed
@@ -0,0 +1,173 @@
+//@run-rustfix
+//@aux-build: proc_macros.rs:proc-macro
+#![warn(clippy::single_match_else)]
+#![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)]
+extern crate proc_macros;
+use proc_macros::with_span;
+
+enum ExprNode {
+ ExprAddrOf,
+ Butterflies,
+ Unicorns,
+}
+
+static NODE: ExprNode = ExprNode::Unicorns;
+
+fn unwrap_addr() -> Option<&'static ExprNode> {
+ let _ = if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else {
+ let x = 5;
+ None
+ };
+
+ // Don't lint
+ with_span!(span match ExprNode::Butterflies {
+ ExprNode::ExprAddrOf => Some(&NODE),
+ _ => {
+ let x = 5;
+ None
+ },
+ })
+}
+
+macro_rules! unwrap_addr {
+ ($expression:expr) => {
+ match $expression {
+ ExprNode::ExprAddrOf => Some(&NODE),
+ _ => {
+ let x = 5;
+ None
+ },
+ }
+ };
+}
+
+#[rustfmt::skip]
+fn main() {
+ unwrap_addr!(ExprNode::Unicorns);
+
+ //
+ // don't lint single exprs/statements
+ //
+
+ // don't lint here
+ match Some(1) {
+ Some(a) => println!("${:?}", a),
+ None => return,
+ }
+
+ // don't lint here
+ match Some(1) {
+ Some(a) => println!("${:?}", a),
+ None => {
+ return
+ },
+ }
+
+ // don't lint here
+ match Some(1) {
+ Some(a) => println!("${:?}", a),
+ None => {
+ return;
+ },
+ }
+
+ //
+ // lint multiple exprs/statements "else" blocks
+ //
+
+ // lint here
+ if let Some(a) = Some(1) { println!("${:?}", a) } else {
+ println!("else block");
+ return
+ }
+
+ // lint here
+ if let Some(a) = Some(1) { println!("${:?}", a) } else {
+ println!("else block");
+ return;
+ }
+
+ // lint here
+ use std::convert::Infallible;
+ if let Ok(a) = Result::<i32, Infallible>::Ok(1) { println!("${:?}", a) } else {
+ println!("else block");
+ return;
+ }
+
+ use std::borrow::Cow;
+ if let Cow::Owned(a) = Cow::from("moo") { println!("${:?}", a) } else {
+ println!("else block");
+ return;
+ }
+}
+
+fn issue_10808(bar: Option<i32>) {
+ if let Some(v) = bar { unsafe {
+ let r = &v as *const i32;
+ println!("{}", *r);
+ } } else {
+ println!("None1");
+ println!("None2");
+ }
+
+ if let Some(v) = bar {
+ println!("Some");
+ println!("{v}");
+ } else { unsafe {
+ let v = 0;
+ let r = &v as *const i32;
+ println!("{}", *r);
+ } }
+
+ if let Some(v) = bar { unsafe {
+ let r = &v as *const i32;
+ println!("{}", *r);
+ } } else { unsafe {
+ let v = 0;
+ let r = &v as *const i32;
+ println!("{}", *r);
+ } }
+
+ if let Some(v) = bar {
+ unsafe {
+ let r = &v as *const i32;
+ println!("{}", *r);
+ }
+ } else {
+ println!("None");
+ println!("None");
+ }
+
+ match bar {
+ Some(v) => {
+ println!("Some");
+ println!("{v}");
+ },
+ #[rustfmt::skip]
+ None => {
+ unsafe {
+ let v = 0;
+ let r = &v as *const i32;
+ println!("{}", *r);
+ }
+ },
+ }
+
+ match bar {
+ #[rustfmt::skip]
+ Some(v) => {
+ unsafe {
+ let r = &v as *const i32;
+ println!("{}", *r);
+ }
+ },
+ #[rustfmt::skip]
+ None => {
+ unsafe {
+ let v = 0;
+ let r = &v as *const i32;
+ println!("{}", *r);
+ }
+ },
+ }
+}
diff --git a/src/tools/clippy/tests/ui/single_match_else.rs b/src/tools/clippy/tests/ui/single_match_else.rs
index c8ac768b6..77afd58a0 100644
--- a/src/tools/clippy/tests/ui/single_match_else.rs
+++ b/src/tools/clippy/tests/ui/single_match_else.rs
@@ -1,7 +1,7 @@
-//@aux-build: proc_macros.rs
+//@run-rustfix
+//@aux-build: proc_macros.rs:proc-macro
#![warn(clippy::single_match_else)]
-#![allow(clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)]
-
+#![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)]
extern crate proc_macros;
use proc_macros::with_span;
@@ -115,3 +115,87 @@ fn main() {
}
}
}
+
+fn issue_10808(bar: Option<i32>) {
+ match bar {
+ Some(v) => unsafe {
+ let r = &v as *const i32;
+ println!("{}", *r);
+ },
+ None => {
+ println!("None1");
+ println!("None2");
+ },
+ }
+
+ match bar {
+ Some(v) => {
+ println!("Some");
+ println!("{v}");
+ },
+ None => unsafe {
+ let v = 0;
+ let r = &v as *const i32;
+ println!("{}", *r);
+ },
+ }
+
+ match bar {
+ Some(v) => unsafe {
+ let r = &v as *const i32;
+ println!("{}", *r);
+ },
+ None => unsafe {
+ let v = 0;
+ let r = &v as *const i32;
+ println!("{}", *r);
+ },
+ }
+
+ match bar {
+ #[rustfmt::skip]
+ Some(v) => {
+ unsafe {
+ let r = &v as *const i32;
+ println!("{}", *r);
+ }
+ },
+ None => {
+ println!("None");
+ println!("None");
+ },
+ }
+
+ match bar {
+ Some(v) => {
+ println!("Some");
+ println!("{v}");
+ },
+ #[rustfmt::skip]
+ None => {
+ unsafe {
+ let v = 0;
+ let r = &v as *const i32;
+ println!("{}", *r);
+ }
+ },
+ }
+
+ match bar {
+ #[rustfmt::skip]
+ Some(v) => {
+ unsafe {
+ let r = &v as *const i32;
+ println!("{}", *r);
+ }
+ },
+ #[rustfmt::skip]
+ None => {
+ unsafe {
+ let v = 0;
+ let r = &v as *const i32;
+ println!("{}", *r);
+ }
+ },
+ }
+}
diff --git a/src/tools/clippy/tests/ui/single_match_else.stderr b/src/tools/clippy/tests/ui/single_match_else.stderr
index 62876a55d..228236f3b 100644
--- a/src/tools/clippy/tests/ui/single_match_else.stderr
+++ b/src/tools/clippy/tests/ui/single_match_else.stderr
@@ -100,5 +100,101 @@ LL + return;
LL + }
|
-error: aborting due to 5 previous errors
+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
+ |
+LL | / match bar {
+LL | | Some(v) => unsafe {
+LL | | let r = &v as *const i32;
+LL | | println!("{}", *r);
+... |
+LL | | },
+LL | | }
+ | |_____^
+ |
+help: try this
+ |
+LL ~ if let Some(v) = bar { unsafe {
+LL + let r = &v as *const i32;
+LL + println!("{}", *r);
+LL + } } else {
+LL + println!("None1");
+LL + println!("None2");
+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
+ |
+LL | / match bar {
+LL | | Some(v) => {
+LL | | println!("Some");
+LL | | println!("{v}");
+... |
+LL | | },
+LL | | }
+ | |_____^
+ |
+help: try this
+ |
+LL ~ if let Some(v) = bar {
+LL + println!("Some");
+LL + println!("{v}");
+LL + } else { unsafe {
+LL + let v = 0;
+LL + let r = &v as *const i32;
+LL + println!("{}", *r);
+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
+ |
+LL | / match bar {
+LL | | Some(v) => unsafe {
+LL | | let r = &v as *const i32;
+LL | | println!("{}", *r);
+... |
+LL | | },
+LL | | }
+ | |_____^
+ |
+help: try this
+ |
+LL ~ if let Some(v) = bar { unsafe {
+LL + let r = &v as *const i32;
+LL + println!("{}", *r);
+LL + } } else { unsafe {
+LL + let v = 0;
+LL + let r = &v as *const i32;
+LL + println!("{}", *r);
+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
+ |
+LL | / match bar {
+LL | | #[rustfmt::skip]
+LL | | Some(v) => {
+LL | | unsafe {
+... |
+LL | | },
+LL | | }
+ | |_____^
+ |
+help: try this
+ |
+LL ~ if let Some(v) = bar {
+LL + unsafe {
+LL + let r = &v as *const i32;
+LL + println!("{}", *r);
+LL + }
+LL + } else {
+LL + println!("None");
+LL + println!("None");
+LL + }
+ |
+
+error: aborting due to 9 previous errors
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
new file mode 100644
index 000000000..833e1c43b
--- /dev/null
+++ b/src/tools/clippy/tests/ui/single_range_in_vec_init.rs
@@ -0,0 +1,58 @@
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(clippy::no_effect, clippy::useless_vec, unused)]
+#![warn(clippy::single_range_in_vec_init)]
+#![feature(generic_arg_infer)]
+
+#[macro_use]
+extern crate proc_macros;
+
+macro_rules! a {
+ () => {
+ vec![0..200];
+ };
+}
+
+fn awa<T: PartialOrd>(start: T, end: T) {
+ [start..end];
+}
+
+fn awa_vec<T: PartialOrd>(start: T, end: T) {
+ vec![start..end];
+}
+
+fn main() {
+ // Lint
+ [0..200];
+ vec![0..200];
+ [0u8..200];
+ [0usize..200];
+ [0..200usize];
+ vec![0u8..200];
+ vec![0usize..200];
+ vec![0..200usize];
+ // Only suggest collect
+ [0..200isize];
+ vec![0..200isize];
+ // Do not lint
+ [0..200, 0..100];
+ vec![0..200, 0..100];
+ [0.0..200.0];
+ vec![0.0..200.0];
+ // `Copy` is not implemented for `Range`, so this doesn't matter
+ // FIXME: [0..200; 2];
+ // FIXME: [vec!0..200; 2];
+
+ // Unfortunately skips any macros
+ a!();
+
+ // Skip external macros and procedural macros
+ external! {
+ [0..200];
+ vec![0..200];
+ }
+ with_span! {
+ span
+ [0..200];
+ vec![0..200];
+ }
+}
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
new file mode 100644
index 000000000..3e3d521f4
--- /dev/null
+++ b/src/tools/clippy/tests/ui/single_range_in_vec_init.stderr
@@ -0,0 +1,145 @@
+error: an array of `Range` that is only one element
+ --> $DIR/single_range_in_vec_init.rs:25:5
+ |
+LL | [0..200];
+ | ^^^^^^^^
+ |
+ = note: `-D clippy::single-range-in-vec-init` implied by `-D warnings`
+help: if you wanted a `Vec` that contains the entire range, try
+ |
+LL | (0..200).collect::<std::vec::Vec<i32>>();
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+help: if you wanted an array of len 200, try
+ |
+LL | [0; 200];
+ | ~~~~~~
+
+error: a `Vec` of `Range` that is only one element
+ --> $DIR/single_range_in_vec_init.rs:26:5
+ |
+LL | vec![0..200];
+ | ^^^^^^^^^^^^
+ |
+help: if you wanted a `Vec` that contains the entire range, try
+ |
+LL | (0..200).collect::<std::vec::Vec<i32>>();
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+help: if you wanted a `Vec` of len 200, try
+ |
+LL | vec![0; 200];
+ | ~~~~~~
+
+error: an array of `Range` that is only one element
+ --> $DIR/single_range_in_vec_init.rs:27:5
+ |
+LL | [0u8..200];
+ | ^^^^^^^^^^
+ |
+help: if you wanted a `Vec` that contains the entire range, try
+ |
+LL | (0u8..200).collect::<std::vec::Vec<u8>>();
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+help: if you wanted an array of len 200, try
+ |
+LL | [0u8; 200];
+ | ~~~~~~~~
+
+error: an array of `Range` that is only one element
+ --> $DIR/single_range_in_vec_init.rs:28:5
+ |
+LL | [0usize..200];
+ | ^^^^^^^^^^^^^
+ |
+help: if you wanted a `Vec` that contains the entire range, try
+ |
+LL | (0usize..200).collect::<std::vec::Vec<usize>>();
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+help: if you wanted an array of len 200, try
+ |
+LL | [0usize; 200];
+ | ~~~~~~~~~~~
+
+error: an array of `Range` that is only one element
+ --> $DIR/single_range_in_vec_init.rs:29:5
+ |
+LL | [0..200usize];
+ | ^^^^^^^^^^^^^
+ |
+help: if you wanted a `Vec` that contains the entire range, try
+ |
+LL | (0..200usize).collect::<std::vec::Vec<usize>>();
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+help: if you wanted an array of len 200usize, try
+ |
+LL | [0; 200usize];
+ | ~~~~~~~~~~~
+
+error: a `Vec` of `Range` that is only one element
+ --> $DIR/single_range_in_vec_init.rs:30:5
+ |
+LL | vec![0u8..200];
+ | ^^^^^^^^^^^^^^
+ |
+help: if you wanted a `Vec` that contains the entire range, try
+ |
+LL | (0u8..200).collect::<std::vec::Vec<u8>>();
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+help: if you wanted a `Vec` of len 200, try
+ |
+LL | vec![0u8; 200];
+ | ~~~~~~~~
+
+error: a `Vec` of `Range` that is only one element
+ --> $DIR/single_range_in_vec_init.rs:31:5
+ |
+LL | vec![0usize..200];
+ | ^^^^^^^^^^^^^^^^^
+ |
+help: if you wanted a `Vec` that contains the entire range, try
+ |
+LL | (0usize..200).collect::<std::vec::Vec<usize>>();
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+help: if you wanted a `Vec` of len 200, try
+ |
+LL | vec![0usize; 200];
+ | ~~~~~~~~~~~
+
+error: a `Vec` of `Range` that is only one element
+ --> $DIR/single_range_in_vec_init.rs:32:5
+ |
+LL | vec![0..200usize];
+ | ^^^^^^^^^^^^^^^^^
+ |
+help: if you wanted a `Vec` that contains the entire range, try
+ |
+LL | (0..200usize).collect::<std::vec::Vec<usize>>();
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+help: if you wanted a `Vec` of len 200usize, try
+ |
+LL | vec![0; 200usize];
+ | ~~~~~~~~~~~
+
+error: an array of `Range` that is only one element
+ --> $DIR/single_range_in_vec_init.rs:34:5
+ |
+LL | [0..200isize];
+ | ^^^^^^^^^^^^^
+ |
+help: if you wanted a `Vec` that contains the entire range, try
+ |
+LL | (0..200isize).collect::<std::vec::Vec<isize>>();
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+error: a `Vec` of `Range` that is only one element
+ --> $DIR/single_range_in_vec_init.rs:35:5
+ |
+LL | vec![0..200isize];
+ | ^^^^^^^^^^^^^^^^^
+ |
+help: if you wanted a `Vec` that contains the entire range, try
+ |
+LL | (0..200isize).collect::<std::vec::Vec<isize>>();
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+error: aborting due to 10 previous errors
+
diff --git a/src/tools/clippy/tests/ui/skip_while_next.rs b/src/tools/clippy/tests/ui/skip_while_next.rs
index 62574e2c8..8e4cd82ce 100644
--- a/src/tools/clippy/tests/ui/skip_while_next.rs
+++ b/src/tools/clippy/tests/ui/skip_while_next.rs
@@ -1,7 +1,7 @@
//@aux-build:option_helpers.rs
#![warn(clippy::skip_while_next)]
-#![allow(clippy::disallowed_names)]
+#![allow(clippy::disallowed_names, clippy::useless_vec)]
extern crate option_helpers;
use option_helpers::IteratorFalsePositives;
diff --git a/src/tools/clippy/tests/ui/stable_sort_primitive.fixed b/src/tools/clippy/tests/ui/stable_sort_primitive.fixed
index 1370dd2df..50c1fc71a 100644
--- a/src/tools/clippy/tests/ui/stable_sort_primitive.fixed
+++ b/src/tools/clippy/tests/ui/stable_sort_primitive.fixed
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::stable_sort_primitive)]
+#![allow(clippy::useless_vec)]
fn main() {
// positive examples
diff --git a/src/tools/clippy/tests/ui/stable_sort_primitive.rs b/src/tools/clippy/tests/ui/stable_sort_primitive.rs
index cd344dd12..bd1bb428f 100644
--- a/src/tools/clippy/tests/ui/stable_sort_primitive.rs
+++ b/src/tools/clippy/tests/ui/stable_sort_primitive.rs
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::stable_sort_primitive)]
+#![allow(clippy::useless_vec)]
fn main() {
// positive examples
diff --git a/src/tools/clippy/tests/ui/stable_sort_primitive.stderr b/src/tools/clippy/tests/ui/stable_sort_primitive.stderr
index 1432fdcff..aa5d7b7e4 100644
--- a/src/tools/clippy/tests/ui/stable_sort_primitive.stderr
+++ b/src/tools/clippy/tests/ui/stable_sort_primitive.stderr
@@ -1,5 +1,5 @@
error: used `sort` on primitive type `i32`
- --> $DIR/stable_sort_primitive.rs:7:5
+ --> $DIR/stable_sort_primitive.rs:8:5
|
LL | vec.sort();
| ^^^^^^^^^^ help: try: `vec.sort_unstable()`
@@ -8,7 +8,7 @@ LL | vec.sort();
= note: `-D clippy::stable-sort-primitive` implied by `-D warnings`
error: used `sort` on primitive type `bool`
- --> $DIR/stable_sort_primitive.rs:9:5
+ --> $DIR/stable_sort_primitive.rs:10:5
|
LL | vec.sort();
| ^^^^^^^^^^ help: try: `vec.sort_unstable()`
@@ -16,7 +16,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:11:5
+ --> $DIR/stable_sort_primitive.rs:12:5
|
LL | vec.sort();
| ^^^^^^^^^^ help: try: `vec.sort_unstable()`
@@ -24,7 +24,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:13:5
+ --> $DIR/stable_sort_primitive.rs:14:5
|
LL | vec.sort();
| ^^^^^^^^^^ help: try: `vec.sort_unstable()`
@@ -32,7 +32,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:15:5
+ --> $DIR/stable_sort_primitive.rs:16:5
|
LL | vec.sort();
| ^^^^^^^^^^ help: try: `vec.sort_unstable()`
@@ -40,7 +40,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:17:5
+ --> $DIR/stable_sort_primitive.rs:18:5
|
LL | vec.sort();
| ^^^^^^^^^^ help: try: `vec.sort_unstable()`
@@ -48,7 +48,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:19:5
+ --> $DIR/stable_sort_primitive.rs:20: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 29d56f852..b7237069d 100644
--- a/src/tools/clippy/tests/ui/starts_ends_with.fixed
+++ b/src/tools/clippy/tests/ui/starts_ends_with.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-#![allow(dead_code, unused_must_use)]
+#![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 56bbe2574..658312e87 100644
--- a/src/tools/clippy/tests/ui/starts_ends_with.rs
+++ b/src/tools/clippy/tests/ui/starts_ends_with.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-#![allow(dead_code, unused_must_use)]
+#![allow(clippy::needless_if, dead_code, unused_must_use)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui/string_add.rs b/src/tools/clippy/tests/ui/string_add.rs
index de78dfe4d..6980242ae 100644
--- a/src/tools/clippy/tests/ui/string_add.rs
+++ b/src/tools/clippy/tests/ui/string_add.rs
@@ -1,4 +1,4 @@
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
extern crate proc_macros;
use proc_macros::external;
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 3fc11b8b0..0edd81acc 100644
--- a/src/tools/clippy/tests/ui/string_lit_as_bytes.fixed
+++ b/src/tools/clippy/tests/ui/string_lit_as_bytes.fixed
@@ -1,7 +1,7 @@
//@run-rustfix
//@aux-build:macro_rules.rs
-#![allow(dead_code, unused_variables)]
+#![allow(clippy::needless_raw_string_hashes, dead_code, unused_variables)]
#![warn(clippy::string_lit_as_bytes)]
#[macro_use]
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 7d54acf63..2647f02f0 100644
--- a/src/tools/clippy/tests/ui/string_lit_as_bytes.rs
+++ b/src/tools/clippy/tests/ui/string_lit_as_bytes.rs
@@ -1,7 +1,7 @@
//@run-rustfix
//@aux-build:macro_rules.rs
-#![allow(dead_code, unused_variables)]
+#![allow(clippy::needless_raw_string_hashes, dead_code, unused_variables)]
#![warn(clippy::string_lit_as_bytes)]
#[macro_use]
diff --git a/src/tools/clippy/tests/ui/suspicious_else_formatting.rs b/src/tools/clippy/tests/ui/suspicious_else_formatting.rs
index e0153cdd8..0473ccdc3 100644
--- a/src/tools/clippy/tests/ui/suspicious_else_formatting.rs
+++ b/src/tools/clippy/tests/ui/suspicious_else_formatting.rs
@@ -1,7 +1,12 @@
-//@aux-build:proc_macro_suspicious_else_formatting.rs
+//@aux-build:proc_macro_suspicious_else_formatting.rs:proc-macro
#![warn(clippy::suspicious_else_formatting)]
-#![allow(clippy::if_same_then_else, clippy::let_unit_value)]
+#![allow(
+ clippy::if_same_then_else,
+ clippy::let_unit_value,
+ clippy::needless_if,
+ clippy::needless_else
+)]
extern crate proc_macro_suspicious_else_formatting;
use proc_macro_suspicious_else_formatting::DeriveBadSpan;
@@ -108,6 +113,13 @@ fn main() {
else
{
}
+
+ //#10273 This is fine. Don't warn
+ if foo() {
+ } else
+ /* whelp */
+ {
+ }
}
// #7650 - Don't lint. Proc-macro using bad spans for `if` expressions.
diff --git a/src/tools/clippy/tests/ui/suspicious_else_formatting.stderr b/src/tools/clippy/tests/ui/suspicious_else_formatting.stderr
index 2e512b47f..723fdd7e9 100644
--- a/src/tools/clippy/tests/ui/suspicious_else_formatting.stderr
+++ b/src/tools/clippy/tests/ui/suspicious_else_formatting.stderr
@@ -1,5 +1,5 @@
error: this looks like an `else {..}` but the `else` is missing
- --> $DIR/suspicious_else_formatting.rs:17:6
+ --> $DIR/suspicious_else_formatting.rs:22:6
|
LL | } {
| ^
@@ -8,7 +8,7 @@ LL | } {
= note: `-D clippy::suspicious-else-formatting` implied by `-D warnings`
error: this looks like an `else if` but the `else` is missing
- --> $DIR/suspicious_else_formatting.rs:21:6
+ --> $DIR/suspicious_else_formatting.rs:26:6
|
LL | } if foo() {
| ^
@@ -16,7 +16,7 @@ LL | } if foo() {
= note: to remove this lint, add the missing `else` or add a new line before the second `if`
error: this looks like an `else if` but the `else` is missing
- --> $DIR/suspicious_else_formatting.rs:28:10
+ --> $DIR/suspicious_else_formatting.rs:33:10
|
LL | } if foo() {
| ^
@@ -24,7 +24,7 @@ LL | } if foo() {
= note: to remove this lint, add the missing `else` or add a new line before the second `if`
error: this looks like an `else if` but the `else` is missing
- --> $DIR/suspicious_else_formatting.rs:36:10
+ --> $DIR/suspicious_else_formatting.rs:41:10
|
LL | } if foo() {
| ^
@@ -32,7 +32,7 @@ LL | } if foo() {
= note: to remove this lint, add the missing `else` or add a new line before the second `if`
error: this is an `else {..}` but the formatting might hide it
- --> $DIR/suspicious_else_formatting.rs:45:6
+ --> $DIR/suspicious_else_formatting.rs:50:6
|
LL | } else
| ______^
@@ -42,7 +42,7 @@ LL | | {
= note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}`
error: this is an `else if` but the formatting might hide it
- --> $DIR/suspicious_else_formatting.rs:57:6
+ --> $DIR/suspicious_else_formatting.rs:62:6
|
LL | } else
| ______^
@@ -52,7 +52,7 @@ LL | | if foo() { // the span of the above error should continue here
= note: to remove this lint, remove the `else` or remove the new line between `else` and `if`
error: this is an `else if` but the formatting might hide it
- --> $DIR/suspicious_else_formatting.rs:62:6
+ --> $DIR/suspicious_else_formatting.rs:67:6
|
LL | }
| ______^
@@ -63,7 +63,7 @@ LL | | if foo() { // the span of the above error should continue here
= note: to remove this lint, remove the `else` or remove the new line between `else` and `if`
error: this is an `else {..}` but the formatting might hide it
- --> $DIR/suspicious_else_formatting.rs:89:6
+ --> $DIR/suspicious_else_formatting.rs:94:6
|
LL | }
| ______^
@@ -75,7 +75,7 @@ LL | | {
= note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}`
error: this is an `else {..}` but the formatting might hide it
- --> $DIR/suspicious_else_formatting.rs:97:6
+ --> $DIR/suspicious_else_formatting.rs:102:6
|
LL | }
| ______^
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 9564e373c..3c5ca1762 100644
--- a/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.rs
+++ b/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.rs
@@ -1,4 +1,5 @@
#![warn(clippy::suspicious_unary_op_formatting)]
+#![allow(clippy::needless_if)]
#[rustfmt::skip]
fn main() {
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 9f1289ccb..52b0e99a1 100644
--- a/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.stderr
+++ b/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.stderr
@@ -1,5 +1,5 @@
error: by not having a space between `>` and `-` it looks like `>-` is a single operator
- --> $DIR/suspicious_unary_op_formatting.rs:8:9
+ --> $DIR/suspicious_unary_op_formatting.rs:9:9
|
LL | if a >- 30 {}
| ^^^^
@@ -8,7 +8,7 @@ LL | if a >- 30 {}
= note: `-D clippy::suspicious-unary-op-formatting` implied by `-D warnings`
error: by not having a space between `>=` and `-` it looks like `>=-` is a single operator
- --> $DIR/suspicious_unary_op_formatting.rs:9:9
+ --> $DIR/suspicious_unary_op_formatting.rs:10:9
|
LL | if a >=- 30 {}
| ^^^^^
@@ -16,7 +16,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:14:9
+ --> $DIR/suspicious_unary_op_formatting.rs:15:9
|
LL | if b &&! c {}
| ^^^^^
@@ -24,7 +24,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:16:9
+ --> $DIR/suspicious_unary_op_formatting.rs:17:9
|
LL | if a >- 30 {}
| ^^^^^^
diff --git a/src/tools/clippy/tests/ui/swap.fixed b/src/tools/clippy/tests/ui/swap.fixed
index fd3569cf3..22f904e3f 100644
--- a/src/tools/clippy/tests/ui/swap.fixed
+++ b/src/tools/clippy/tests/ui/swap.fixed
@@ -10,7 +10,8 @@
dead_code,
unused_assignments,
unused_variables,
- clippy::let_and_return
+ clippy::let_and_return,
+ clippy::useless_vec
)]
struct Foo(u32);
diff --git a/src/tools/clippy/tests/ui/swap.rs b/src/tools/clippy/tests/ui/swap.rs
index 34fbce052..ada64f89e 100644
--- a/src/tools/clippy/tests/ui/swap.rs
+++ b/src/tools/clippy/tests/ui/swap.rs
@@ -10,7 +10,8 @@
dead_code,
unused_assignments,
unused_variables,
- clippy::let_and_return
+ clippy::let_and_return,
+ clippy::useless_vec
)]
struct Foo(u32);
diff --git a/src/tools/clippy/tests/ui/swap.stderr b/src/tools/clippy/tests/ui/swap.stderr
index 0c2462684..a3b9c2b74 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:27:5
+ --> $DIR/swap.rs:28:5
|
LL | / let temp = bar.a;
LL | | bar.a = bar.b;
@@ -10,7 +10,7 @@ LL | | bar.b = temp;
= note: `-D clippy::manual-swap` implied by `-D warnings`
error: this looks like you are swapping elements of `foo` manually
- --> $DIR/swap.rs:39:5
+ --> $DIR/swap.rs:40:5
|
LL | / let temp = foo[0];
LL | | foo[0] = foo[1];
@@ -18,7 +18,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:48:5
+ --> $DIR/swap.rs:49:5
|
LL | / let temp = foo[0];
LL | | foo[0] = foo[1];
@@ -26,7 +26,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:67:5
+ --> $DIR/swap.rs:68:5
|
LL | / let temp = foo[0];
LL | | foo[0] = foo[1];
@@ -34,7 +34,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:78:5
+ --> $DIR/swap.rs:79:5
|
LL | / a ^= b;
LL | | b ^= a;
@@ -42,7 +42,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:86:5
+ --> $DIR/swap.rs:87:5
|
LL | / bar.a ^= bar.b;
LL | | bar.b ^= bar.a;
@@ -50,7 +50,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:94:5
+ --> $DIR/swap.rs:95:5
|
LL | / foo[0] ^= foo[1];
LL | | foo[1] ^= foo[0];
@@ -58,7 +58,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:123:5
+ --> $DIR/swap.rs:124:5
|
LL | / let temp = foo[0][1];
LL | | foo[0][1] = bar[1][0];
@@ -68,7 +68,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:137:7
+ --> $DIR/swap.rs:138:7
|
LL | ; let t = a;
| _______^
@@ -79,7 +79,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:146:7
+ --> $DIR/swap.rs:147:7
|
LL | ; let t = c.0;
| _______^
@@ -90,7 +90,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:172:5
+ --> $DIR/swap.rs:173:5
|
LL | / let t = b;
LL | | b = a;
@@ -100,7 +100,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:134:5
+ --> $DIR/swap.rs:135:5
|
LL | / a = b;
LL | | b = a;
@@ -110,7 +110,7 @@ LL | | b = a;
= note: `-D clippy::almost-swapped` implied by `-D warnings`
error: this looks like you are trying to swap `c.0` and `a`
- --> $DIR/swap.rs:143:5
+ --> $DIR/swap.rs:144:5
|
LL | / c.0 = a;
LL | | a = c.0;
@@ -119,7 +119,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:150:5
+ --> $DIR/swap.rs:151:5
|
LL | / let a = b;
LL | | let b = a;
@@ -128,7 +128,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:155:5
+ --> $DIR/swap.rs:156:5
|
LL | / d = c;
LL | | c = d;
@@ -137,7 +137,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:159:5
+ --> $DIR/swap.rs:160:5
|
LL | / let a = b;
LL | | b = a;
@@ -146,7 +146,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:207: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/tests_outside_test_module.rs b/src/tools/clippy/tests/ui/tests_outside_test_module.rs
index 21fdfdf90..d53c692b7 100644
--- a/src/tools/clippy/tests/ui/tests_outside_test_module.rs
+++ b/src/tools/clippy/tests/ui/tests_outside_test_module.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --test
#![allow(unused)]
#![warn(clippy::tests_outside_test_module)]
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 125a79d6e..71c649c5d 100644
--- a/src/tools/clippy/tests/ui/tests_outside_test_module.stderr
+++ b/src/tools/clippy/tests/ui/tests_outside_test_module.stderr
@@ -1,5 +1,5 @@
error: this function marked with #[test] is outside a #[cfg(test)] module
- --> $DIR/tests_outside_test_module.rs:11:1
+ --> $DIR/tests_outside_test_module.rs:10:1
|
LL | fn my_test() {}
| ^^^^^^^^^^^^^^^
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
new file mode 100644
index 000000000..9f75ad895
--- /dev/null
+++ b/src/tools/clippy/tests/ui/to_string_in_format_args_incremental.fixed
@@ -0,0 +1,9 @@
+//@run-rustfix
+//@compile-flags: -C incremental=target/debug/test/incr
+
+// see https://github.com/rust-lang/rust-clippy/issues/10969
+
+fn main() {
+ let s = "Hello, world!";
+ println!("{}", s);
+}
diff --git a/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed b/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed
index ea30c1fda..9ad45c7a8 100644
--- a/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed
+++ b/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed
@@ -1,7 +1,7 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::toplevel_ref_arg)]
-#![allow(clippy::uninlined_format_args, unused)]
+#![allow(clippy::uninlined_format_args, unused, clippy::useless_vec)]
extern crate proc_macros;
use proc_macros::{external, inline_macros};
diff --git a/src/tools/clippy/tests/ui/toplevel_ref_arg.rs b/src/tools/clippy/tests/ui/toplevel_ref_arg.rs
index 7a3d33e5b..45ccc024c 100644
--- a/src/tools/clippy/tests/ui/toplevel_ref_arg.rs
+++ b/src/tools/clippy/tests/ui/toplevel_ref_arg.rs
@@ -1,7 +1,7 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::toplevel_ref_arg)]
-#![allow(clippy::uninlined_format_args, unused)]
+#![allow(clippy::uninlined_format_args, unused, clippy::useless_vec)]
extern crate proc_macros;
use proc_macros::{external, inline_macros};
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 8aaf47b1b..464762af8 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
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::toplevel_ref_arg)]
#![allow(unused)]
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 f06ffab5d..61a6c98ed 100644
--- a/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs
+++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ptr.rs
@@ -32,7 +32,7 @@ fn transmute_ptr_to_ptr() {
// ref-ref transmutes; bad
let _: &f32 = std::mem::transmute(&1u32);
let _: &f64 = std::mem::transmute(&1f32);
- // ^ this test is here because both f32 and f64 are the same TypeVariant, but they are not
+ //:^ 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);
let _: &GenericParam<f32> = std::mem::transmute(&GenericParam { t: 1u32 });
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 575dadde9..215f0ac18 100644
--- a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed
+++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed
@@ -1,7 +1,7 @@
//@run-rustfix
#![warn(clippy::transmute_ptr_to_ref)]
-#![allow(clippy::match_single_binding)]
+#![allow(clippy::match_single_binding, clippy::unnecessary_cast)]
unsafe fn _ptr_to_ref<T, U>(p: *const T, m: *mut T, o: *const U, om: *mut U) {
let _: &T = &*p;
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 4238ff804..3528e1379 100644
--- a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs
+++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs
@@ -1,7 +1,7 @@
//@run-rustfix
#![warn(clippy::transmute_ptr_to_ref)]
-#![allow(clippy::match_single_binding)]
+#![allow(clippy::match_single_binding, clippy::unnecessary_cast)]
unsafe fn _ptr_to_ref<T, U>(p: *const T, m: *mut T, o: *const U, om: *mut U) {
let _: &T = std::mem::transmute(p);
diff --git a/src/tools/clippy/tests/ui/try_err.fixed b/src/tools/clippy/tests/ui/try_err.fixed
index dc773ad4b..181674087 100644
--- a/src/tools/clippy/tests/ui/try_err.fixed
+++ b/src/tools/clippy/tests/ui/try_err.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![deny(clippy::try_err)]
#![allow(clippy::unnecessary_wraps, clippy::needless_question_mark)]
diff --git a/src/tools/clippy/tests/ui/try_err.rs b/src/tools/clippy/tests/ui/try_err.rs
index 7a7433a7e..0e47c4d02 100644
--- a/src/tools/clippy/tests/ui/try_err.rs
+++ b/src/tools/clippy/tests/ui/try_err.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
#![deny(clippy::try_err)]
#![allow(clippy::unnecessary_wraps, clippy::needless_question_mark)]
diff --git a/src/tools/clippy/tests/ui/tuple_array_conversions.rs b/src/tools/clippy/tests/ui/tuple_array_conversions.rs
new file mode 100644
index 000000000..f96a7c97f
--- /dev/null
+++ b/src/tools/clippy/tests/ui/tuple_array_conversions.rs
@@ -0,0 +1,73 @@
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(clippy::no_effect, clippy::useless_vec, unused)]
+#![warn(clippy::tuple_array_conversions)]
+
+#[macro_use]
+extern crate proc_macros;
+
+fn main() {
+ let x = [1, 2];
+ let x = (x[0], x[1]);
+ let x = [x.0, x.1];
+ let x = &[1, 2];
+ let x = (x[0], x[1]);
+
+ let t1: &[(u32, u32)] = &[(1, 2), (3, 4)];
+ let v1: Vec<[u32; 2]> = t1.iter().map(|&(a, b)| [a, b]).collect();
+ t1.iter().for_each(|&(a, b)| _ = [a, b]);
+ let t2: Vec<(u32, u32)> = v1.iter().map(|&[a, b]| (a, b)).collect();
+ t1.iter().for_each(|&(a, b)| _ = [a, b]);
+ // Do not lint
+ let v2: Vec<[u32; 2]> = t1.iter().map(|&t| t.into()).collect();
+ let t3: Vec<(u32, u32)> = v2.iter().map(|&v| v.into()).collect();
+ let x = [1; 13];
+ let x = (
+ x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12],
+ );
+ let x = [x.0, x.1, x.2, x.3, x.4, x.5, x.6, x.7, x.8, x.9, x.10, x.11, x.12];
+ let x = (1, 2);
+ let x = (x.0, x.1);
+ let x = [1, 2];
+ let x = [x[0], x[1]];
+ let x = vec![1, 2];
+ let x = (x[0], x[1]);
+ let x = [1; 3];
+ let x = (x[0],);
+ let x = (1, 2, 3);
+ let x = [x.0];
+ let x = (1, 2);
+ let y = (1, 2);
+ [x.0, y.0];
+ [x.0, y.1];
+ let x = [x.0, x.0];
+ let x = (x[0], x[0]);
+ external! {
+ let t1: &[(u32, u32)] = &[(1, 2), (3, 4)];
+ let v1: Vec<[u32; 2]> = t1.iter().map(|&(a, b)| [a, b]).collect();
+ let t2: Vec<(u32, u32)> = v1.iter().map(|&[a, b]| (a, b)).collect();
+ }
+ with_span! {
+ span
+ let t1: &[(u32, u32)] = &[(1, 2), (3, 4)];
+ let v1: Vec<[u32; 2]> = t1.iter().map(|&(a, b)| [a, b]).collect();
+ let t2: Vec<(u32, u32)> = v1.iter().map(|&[a, b]| (a, b)).collect();
+ }
+}
+
+#[clippy::msrv = "1.70.0"]
+fn msrv_too_low() {
+ let x = [1, 2];
+ let x = (x[0], x[1]);
+ let x = [x.0, x.1];
+ let x = &[1, 2];
+ let x = (x[0], x[1]);
+}
+
+#[clippy::msrv = "1.71.0"]
+fn msrv_juust_right() {
+ let x = [1, 2];
+ let x = (x[0], x[1]);
+ let x = [x.0, x.1];
+ let x = &[1, 2];
+ let x = (x[0], x[1]);
+}
diff --git a/src/tools/clippy/tests/ui/tuple_array_conversions.stderr b/src/tools/clippy/tests/ui/tuple_array_conversions.stderr
new file mode 100644
index 000000000..be653e8ef
--- /dev/null
+++ b/src/tools/clippy/tests/ui/tuple_array_conversions.stderr
@@ -0,0 +1,83 @@
+error: it looks like you're trying to convert an array to a tuple
+ --> $DIR/tuple_array_conversions.rs:10:13
+ |
+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`
+
+error: it looks like you're trying to convert a tuple to an array
+ --> $DIR/tuple_array_conversions.rs:11:13
+ |
+LL | let x = [x.0, x.1];
+ | ^^^^^^^^^^
+ |
+ = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed
+
+error: it looks like you're trying to convert an array to a tuple
+ --> $DIR/tuple_array_conversions.rs:13:13
+ |
+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:16:53
+ |
+LL | let v1: Vec<[u32; 2]> = t1.iter().map(|&(a, b)| [a, b]).collect();
+ | ^^^^^^
+ |
+ = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed
+
+error: it looks like you're trying to convert a tuple to an array
+ --> $DIR/tuple_array_conversions.rs:17:38
+ |
+LL | t1.iter().for_each(|&(a, b)| _ = [a, b]);
+ | ^^^^^^
+ |
+ = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed
+
+error: it looks like you're trying to convert an array to a tuple
+ --> $DIR/tuple_array_conversions.rs:18:55
+ |
+LL | let t2: Vec<(u32, u32)> = v1.iter().map(|&[a, b]| (a, b)).collect();
+ | ^^^^^^
+ |
+ = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed
+
+error: it looks like you're trying to convert a tuple to an array
+ --> $DIR/tuple_array_conversions.rs:19:38
+ |
+LL | t1.iter().for_each(|&(a, b)| _ = [a, b]);
+ | ^^^^^^
+ |
+ = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed
+
+error: it looks like you're trying to convert an array to a tuple
+ --> $DIR/tuple_array_conversions.rs:69:13
+ |
+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:70:13
+ |
+LL | let x = [x.0, x.1];
+ | ^^^^^^^^^^
+ |
+ = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed
+
+error: it looks like you're trying to convert an array to a tuple
+ --> $DIR/tuple_array_conversions.rs:72:13
+ |
+LL | let x = (x[0], x[1]);
+ | ^^^^^^^^^^^^
+ |
+ = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed
+
+error: aborting due to 10 previous errors
+
diff --git a/src/tools/clippy/tests/ui/type_complexity.rs b/src/tools/clippy/tests/ui/type_complexity.rs
index 86a7bd7b6..816950110 100644
--- a/src/tools/clippy/tests/ui/type_complexity.rs
+++ b/src/tools/clippy/tests/ui/type_complexity.rs
@@ -1,5 +1,5 @@
#![warn(clippy::all)]
-#![allow(unused, clippy::needless_pass_by_value, clippy::vec_box)]
+#![allow(unused, clippy::needless_pass_by_value, clippy::vec_box, clippy::useless_vec)]
#![feature(associated_type_defaults)]
type Alias = Vec<Vec<Box<(u32, u32, u32, u32)>>>; // no warning here
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 8b4613b3f..874d97f7a 100644
--- a/src/tools/clippy/tests/ui/type_repetition_in_bounds.rs
+++ b/src/tools/clippy/tests/ui/type_repetition_in_bounds.rs
@@ -1,6 +1,7 @@
#![deny(clippy::type_repetition_in_bounds)]
#![allow(clippy::extra_unused_type_parameters)]
+use serde::Deserialize;
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
pub fn foo<T>(_t: T)
@@ -70,6 +71,20 @@ mod issue4326 {
}
}
+// Extern macros shouldn't lint, again (see #10504)
+mod issue10504 {
+ use serde::{Deserialize, Serialize};
+ use std::fmt::Debug;
+ use std::hash::Hash;
+
+ #[derive(Debug, Serialize, Deserialize)]
+ #[serde(bound(
+ serialize = "T: Serialize + Hash + Eq",
+ deserialize = "Box<T>: serde::de::DeserializeOwned + Hash + Eq"
+ ))]
+ struct OpaqueParams<T: ?Sized + Debug>(std::marker::PhantomData<T>);
+}
+
// Issue #7360
struct Foo<T, U>
where
@@ -95,4 +110,28 @@ where
// This should not lint
fn impl_trait(_: impl AsRef<str>, _: impl AsRef<str>) {}
+#[clippy::msrv = "1.14.0"]
+mod issue8772_fail {
+ pub trait Trait<X, Y, Z> {}
+
+ pub fn f<T: ?Sized, U>(arg: usize)
+ where
+ T: Trait<Option<usize>, Box<[String]>, bool> + 'static,
+ U: Clone + Sync + 'static,
+ {
+ }
+}
+
+#[clippy::msrv = "1.15.0"]
+mod issue8772_pass {
+ pub trait Trait<X, Y, Z> {}
+
+ pub fn f<T: ?Sized, U>(arg: usize)
+ where
+ T: Trait<Option<usize>, Box<[String]>, bool> + 'static,
+ U: Clone + Sync + 'static,
+ {
+ }
+}
+
fn main() {}
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 a90df03c0..54973c5bd 100644
--- a/src/tools/clippy/tests/ui/type_repetition_in_bounds.stderr
+++ b/src/tools/clippy/tests/ui/type_repetition_in_bounds.stderr
@@ -1,5 +1,5 @@
error: this type has already been used as a bound predicate
- --> $DIR/type_repetition_in_bounds.rs:9:5
+ --> $DIR/type_repetition_in_bounds.rs:10:5
|
LL | T: Clone,
| ^^^^^^^^
@@ -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:26:5
+ --> $DIR/type_repetition_in_bounds.rs:27: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:86:5
+ --> $DIR/type_repetition_in_bounds.rs:101:5
|
LL | T: Clone,
| ^^^^^^^^
@@ -28,12 +28,20 @@ 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:91:5
+ --> $DIR/type_repetition_in_bounds.rs:106:5
|
LL | T: ?Sized,
| ^^^^^^^^^
|
= help: consider combining the bounds: `T: Clone + ?Sized`
-error: aborting due to 4 previous errors
+error: this type has already been used as a bound predicate
+ --> $DIR/type_repetition_in_bounds.rs:131:9
+ |
+LL | T: Trait<Option<usize>, Box<[String]>, bool> + 'static,
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: consider combining the bounds: `T: ?Sized + Trait<Option<usize>, Box<[String]>, bool>`
+
+error: aborting due to 5 previous errors
diff --git a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs b/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs
index 229d15085..a9cc42954 100644
--- a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs
+++ b/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs
@@ -1,4 +1,4 @@
-//@aux-build:proc_macro_unsafe.rs
+//@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)]
@@ -509,4 +509,26 @@ fn issue_9142() {
};
}
+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
index d1c1bb5ff..ee1d3aa28 100644
--- a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr
+++ b/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr
@@ -318,5 +318,29 @@ LL | let bar = unsafe {};
|
= help: consider adding a safety comment on the preceding line
-error: aborting due to 36 previous errors
+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/undropped_manually_drops.rs b/src/tools/clippy/tests/ui/undropped_manually_drops.rs
deleted file mode 100644
index f4cfc92e1..000000000
--- a/src/tools/clippy/tests/ui/undropped_manually_drops.rs
+++ /dev/null
@@ -1,26 +0,0 @@
-#![warn(clippy::undropped_manually_drops)]
-
-struct S;
-
-fn main() {
- let f = std::mem::drop;
- let g = std::mem::ManuallyDrop::drop;
- let mut manual1 = std::mem::ManuallyDrop::new(S);
- let mut manual2 = std::mem::ManuallyDrop::new(S);
- let mut manual3 = std::mem::ManuallyDrop::new(S);
- let mut manual4 = std::mem::ManuallyDrop::new(S);
-
- // These lines will not drop `S` and should be linted
- drop(std::mem::ManuallyDrop::new(S));
- drop(manual1);
-
- // FIXME: this line is not linted, though it should be
- f(manual2);
-
- // These lines will drop `S` and should be okay.
- unsafe {
- std::mem::ManuallyDrop::drop(&mut std::mem::ManuallyDrop::new(S));
- std::mem::ManuallyDrop::drop(&mut manual3);
- g(&mut manual4);
- }
-}
diff --git a/src/tools/clippy/tests/ui/undropped_manually_drops.stderr b/src/tools/clippy/tests/ui/undropped_manually_drops.stderr
deleted file mode 100644
index 92611a9b7..000000000
--- a/src/tools/clippy/tests/ui/undropped_manually_drops.stderr
+++ /dev/null
@@ -1,19 +0,0 @@
-error: the inner value of this ManuallyDrop will not be dropped
- --> $DIR/undropped_manually_drops.rs:14:5
- |
-LL | drop(std::mem::ManuallyDrop::new(S));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = help: to drop a `ManuallyDrop<T>`, use std::mem::ManuallyDrop::drop
- = note: `-D clippy::undropped-manually-drops` implied by `-D warnings`
-
-error: the inner value of this ManuallyDrop will not be dropped
- --> $DIR/undropped_manually_drops.rs:15:5
- |
-LL | drop(manual1);
- | ^^^^^^^^^^^^^
- |
- = help: to drop a `ManuallyDrop<T>`, use std::mem::ManuallyDrop::drop
-
-error: aborting due to 2 previous errors
-
diff --git a/src/tools/clippy/tests/ui/unicode.fixed b/src/tools/clippy/tests/ui/unicode.fixed
index 910968afa..032040c48 100644
--- a/src/tools/clippy/tests/ui/unicode.fixed
+++ b/src/tools/clippy/tests/ui/unicode.fixed
@@ -1,5 +1,4 @@
//@run-rustfix
-//@compile-flags: --test
#![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 bc4b84d34..dd215bc60 100644
--- a/src/tools/clippy/tests/ui/unicode.rs
+++ b/src/tools/clippy/tests/ui/unicode.rs
@@ -1,5 +1,4 @@
//@run-rustfix
-//@compile-flags: --test
#![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 ea74a8145..21cc22a77 100644
--- a/src/tools/clippy/tests/ui/unicode.stderr
+++ b/src/tools/clippy/tests/ui/unicode.stderr
@@ -1,5 +1,5 @@
error: invisible character detected
- --> $DIR/unicode.rs:7:12
+ --> $DIR/unicode.rs:6: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"`
@@ -7,19 +7,19 @@ LL | print!("Here >​< is a ZWS, and ​another");
= note: `-D clippy::invisible-characters` implied by `-D warnings`
error: invisible character detected
- --> $DIR/unicode.rs:9:12
+ --> $DIR/unicode.rs:8:12
|
LL | print!("Here >­< is a SHY, and ­another");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >/u{AD}< is a SHY, and /u{AD}another"`
error: invisible character detected
- --> $DIR/unicode.rs:11:12
+ --> $DIR/unicode.rs:10:12
|
LL | print!("Here >⁠< is a WJ, and ⁠another");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >/u{2060}< is a WJ, and /u{2060}another"`
error: non-NFC Unicode sequence detected
- --> $DIR/unicode.rs:17:12
+ --> $DIR/unicode.rs:16:12
|
LL | print!("̀àh?");
| ^^^^^ help: consider replacing the string with: `"̀àh?"`
@@ -27,37 +27,37 @@ LL | print!("̀àh?");
= note: `-D clippy::unicode-not-nfc` implied by `-D warnings`
error: literal non-ASCII character detected
- --> $DIR/unicode.rs:25:16
+ --> $DIR/unicode.rs:24:16
|
LL | print!("Üben!");
| ^^^^^^^ help: consider replacing the string with: `"/u{dc}ben!"`
|
note: the lint level is defined here
- --> $DIR/unicode.rs:22:13
+ --> $DIR/unicode.rs:21:13
|
LL | #![deny(clippy::non_ascii_literal)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: literal non-ASCII character detected
- --> $DIR/unicode.rs:31:36
+ --> $DIR/unicode.rs:30:36
|
LL | const _EMPTY_BLOCK: char = '▱';
| ^^^ help: consider replacing the string with: `'/u{25b1}'`
error: literal non-ASCII character detected
- --> $DIR/unicode.rs:32:35
+ --> $DIR/unicode.rs:31:35
|
LL | const _FULL_BLOCK: char = '▰';
| ^^^ help: consider replacing the string with: `'/u{25b0}'`
error: literal non-ASCII character detected
- --> $DIR/unicode.rs:52:21
+ --> $DIR/unicode.rs:51:21
|
LL | let _ = "悲しいかな、ここに日本語を書くことはできない。";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"/u{60b2}/u{3057}/u{3044}/u{304b}/u{306a}/u{3001}/u{3053}/u{3053}/u{306b}/u{65e5}/u{672c}/u{8a9e}/u{3092}/u{66f8}/u{304f}/u{3053}/u{3068}/u{306f}/u{3067}/u{304d}/u{306a}/u{3044}/u{3002}"`
|
note: the lint level is defined here
- --> $DIR/unicode.rs:41:17
+ --> $DIR/unicode.rs:40:17
|
LL | #![deny(clippy::non_ascii_literal)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.fixed b/src/tools/clippy/tests/ui/uninlined_format_args.fixed
index e25d123dd..a042731a9 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args.fixed
+++ b/src/tools/clippy/tests/ui/uninlined_format_args.fixed
@@ -1,8 +1,13 @@
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
//@run-rustfix
#![warn(clippy::uninlined_format_args)]
#![allow(named_arguments_used_positionally, unused)]
-#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
+#![allow(
+ clippy::eq_op,
+ clippy::format_in_format_args,
+ clippy::print_literal,
+ clippy::unnecessary_literal_unwrap
+)]
extern crate proc_macros;
use proc_macros::with_span;
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.rs b/src/tools/clippy/tests/ui/uninlined_format_args.rs
index 6793ec244..d830b74d6 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args.rs
+++ b/src/tools/clippy/tests/ui/uninlined_format_args.rs
@@ -1,8 +1,13 @@
-//@aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs:proc-macro
//@run-rustfix
#![warn(clippy::uninlined_format_args)]
#![allow(named_arguments_used_positionally, unused)]
-#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
+#![allow(
+ clippy::eq_op,
+ clippy::format_in_format_args,
+ clippy::print_literal,
+ clippy::unnecessary_literal_unwrap
+)]
extern crate proc_macros;
use proc_macros::with_span;
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.stderr b/src/tools/clippy/tests/ui/uninlined_format_args.stderr
index dc4af6ef4..44ca61f00 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args.stderr
+++ b/src/tools/clippy/tests/ui/uninlined_format_args.stderr
@@ -1,5 +1,5 @@
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:40:5
+ --> $DIR/uninlined_format_args.rs:45:5
|
LL | println!("val='{}'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -12,7 +12,7 @@ LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:41:5
+ --> $DIR/uninlined_format_args.rs:46:5
|
LL | println!("val='{ }'", local_i32); // 3 spaces
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -24,7 +24,7 @@ LL + println!("val='{local_i32}'"); // 3 spaces
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:42:5
+ --> $DIR/uninlined_format_args.rs:47:5
|
LL | println!("val='{ }'", local_i32); // tab
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -36,7 +36,7 @@ LL + println!("val='{local_i32}'"); // tab
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:43:5
+ --> $DIR/uninlined_format_args.rs:48:5
|
LL | println!("val='{ }'", local_i32); // space+tab
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -48,7 +48,7 @@ LL + println!("val='{local_i32}'"); // space+tab
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:44:5
+ --> $DIR/uninlined_format_args.rs:49:5
|
LL | println!("val='{ }'", local_i32); // tab+space
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -60,7 +60,7 @@ LL + println!("val='{local_i32}'"); // tab+space
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:45:5
+ --> $DIR/uninlined_format_args.rs:50:5
|
LL | / println!(
LL | | "val='{
@@ -70,7 +70,7 @@ LL | | );
| |_____^
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:50:5
+ --> $DIR/uninlined_format_args.rs:55:5
|
LL | println!("{}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -82,7 +82,7 @@ LL + println!("{local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:51:5
+ --> $DIR/uninlined_format_args.rs:56:5
|
LL | println!("{}", fn_arg);
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -94,7 +94,7 @@ LL + println!("{fn_arg}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:52:5
+ --> $DIR/uninlined_format_args.rs:57:5
|
LL | println!("{:?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -106,7 +106,7 @@ LL + println!("{local_i32:?}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:53:5
+ --> $DIR/uninlined_format_args.rs:58:5
|
LL | println!("{:#?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -118,7 +118,7 @@ LL + println!("{local_i32:#?}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:54:5
+ --> $DIR/uninlined_format_args.rs:59:5
|
LL | println!("{:4}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -130,7 +130,7 @@ LL + println!("{local_i32:4}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:55:5
+ --> $DIR/uninlined_format_args.rs:60:5
|
LL | println!("{:04}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -142,7 +142,7 @@ LL + println!("{local_i32:04}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:56:5
+ --> $DIR/uninlined_format_args.rs:61:5
|
LL | println!("{:<3}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -154,7 +154,7 @@ LL + println!("{local_i32:<3}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:57:5
+ --> $DIR/uninlined_format_args.rs:62:5
|
LL | println!("{:#010x}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -166,7 +166,7 @@ LL + println!("{local_i32:#010x}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:58:5
+ --> $DIR/uninlined_format_args.rs:63:5
|
LL | println!("{:.1}", local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -178,7 +178,7 @@ LL + println!("{local_f64:.1}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:62:5
+ --> $DIR/uninlined_format_args.rs:67:5
|
LL | println!("{} {}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -190,7 +190,7 @@ LL + println!("{local_i32} {local_f64}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:64:5
+ --> $DIR/uninlined_format_args.rs:69:5
|
LL | println!("{}", val);
| ^^^^^^^^^^^^^^^^^^^
@@ -202,7 +202,7 @@ LL + println!("{val}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:65:5
+ --> $DIR/uninlined_format_args.rs:70:5
|
LL | println!("{}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -214,7 +214,7 @@ LL + println!("{val}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:67:5
+ --> $DIR/uninlined_format_args.rs:72:5
|
LL | println!("val='{/t }'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -226,7 +226,7 @@ LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:68:5
+ --> $DIR/uninlined_format_args.rs:73:5
|
LL | println!("val='{/n }'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -238,7 +238,7 @@ LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:69:5
+ --> $DIR/uninlined_format_args.rs:74:5
|
LL | println!("val='{local_i32}'", local_i32 = local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -250,7 +250,7 @@ LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:70:5
+ --> $DIR/uninlined_format_args.rs:75:5
|
LL | println!("val='{local_i32}'", local_i32 = fn_arg);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -262,7 +262,7 @@ LL + println!("val='{fn_arg}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:71:5
+ --> $DIR/uninlined_format_args.rs:76:5
|
LL | println!("{0}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -274,7 +274,7 @@ LL + println!("{local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:72:5
+ --> $DIR/uninlined_format_args.rs:77:5
|
LL | println!("{0:?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -286,7 +286,7 @@ LL + println!("{local_i32:?}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:73:5
+ --> $DIR/uninlined_format_args.rs:78:5
|
LL | println!("{0:#?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -298,7 +298,7 @@ LL + println!("{local_i32:#?}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:74:5
+ --> $DIR/uninlined_format_args.rs:79:5
|
LL | println!("{0:04}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -310,7 +310,7 @@ LL + println!("{local_i32:04}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:75:5
+ --> $DIR/uninlined_format_args.rs:80:5
|
LL | println!("{0:<3}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -322,7 +322,7 @@ LL + println!("{local_i32:<3}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:76:5
+ --> $DIR/uninlined_format_args.rs:81:5
|
LL | println!("{0:#010x}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -334,7 +334,7 @@ LL + println!("{local_i32:#010x}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:77:5
+ --> $DIR/uninlined_format_args.rs:82:5
|
LL | println!("{0:.1}", local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -346,7 +346,7 @@ LL + println!("{local_f64:.1}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:78:5
+ --> $DIR/uninlined_format_args.rs:83:5
|
LL | println!("{0} {0}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -358,7 +358,7 @@ LL + println!("{local_i32} {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:79:5
+ --> $DIR/uninlined_format_args.rs:84:5
|
LL | println!("{1} {} {0} {}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -370,7 +370,7 @@ LL + println!("{local_f64} {local_i32} {local_i32} {local_f64}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:80:5
+ --> $DIR/uninlined_format_args.rs:85:5
|
LL | println!("{0} {1}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -382,7 +382,7 @@ LL + println!("{local_i32} {local_f64}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:81:5
+ --> $DIR/uninlined_format_args.rs:86:5
|
LL | println!("{1} {0}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -394,7 +394,7 @@ LL + println!("{local_f64} {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:82:5
+ --> $DIR/uninlined_format_args.rs:87:5
|
LL | println!("{1} {0} {1} {0}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -406,7 +406,7 @@ LL + println!("{local_f64} {local_i32} {local_f64} {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:84:5
+ --> $DIR/uninlined_format_args.rs:89:5
|
LL | println!("{v}", v = local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -418,7 +418,7 @@ LL + println!("{local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:85:5
+ --> $DIR/uninlined_format_args.rs:90:5
|
LL | println!("{local_i32:0$}", width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -430,7 +430,7 @@ LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:86:5
+ --> $DIR/uninlined_format_args.rs:91:5
|
LL | println!("{local_i32:w$}", w = width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -442,7 +442,7 @@ LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:87:5
+ --> $DIR/uninlined_format_args.rs:92:5
|
LL | println!("{local_i32:.0$}", prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -454,7 +454,7 @@ LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:88:5
+ --> $DIR/uninlined_format_args.rs:93:5
|
LL | println!("{local_i32:.p$}", p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -466,7 +466,7 @@ LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:89:5
+ --> $DIR/uninlined_format_args.rs:94:5
|
LL | println!("{:0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -478,7 +478,7 @@ LL + println!("{val:val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:90:5
+ --> $DIR/uninlined_format_args.rs:95:5
|
LL | println!("{0:0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -490,7 +490,7 @@ LL + println!("{val:val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:91:5
+ --> $DIR/uninlined_format_args.rs:96:5
|
LL | println!("{:0$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -502,7 +502,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:92:5
+ --> $DIR/uninlined_format_args.rs:97:5
|
LL | println!("{0:0$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -514,7 +514,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:93:5
+ --> $DIR/uninlined_format_args.rs:98:5
|
LL | println!("{0:0$.v$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -526,7 +526,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:94:5
+ --> $DIR/uninlined_format_args.rs:99:5
|
LL | println!("{0:v$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -538,7 +538,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:95:5
+ --> $DIR/uninlined_format_args.rs:100:5
|
LL | println!("{v:0$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -550,7 +550,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:96:5
+ --> $DIR/uninlined_format_args.rs:101:5
|
LL | println!("{v:v$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -562,7 +562,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:97:5
+ --> $DIR/uninlined_format_args.rs:102:5
|
LL | println!("{v:0$.v$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -574,7 +574,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:98:5
+ --> $DIR/uninlined_format_args.rs:103:5
|
LL | println!("{v:v$.v$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -586,7 +586,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:99:5
+ --> $DIR/uninlined_format_args.rs:104:5
|
LL | println!("{:0$}", width);
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -598,7 +598,7 @@ LL + println!("{width:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:100:5
+ --> $DIR/uninlined_format_args.rs:105:5
|
LL | println!("{:1$}", local_i32, width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -610,7 +610,7 @@ LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:101:5
+ --> $DIR/uninlined_format_args.rs:106:5
|
LL | println!("{:w$}", w = width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -622,7 +622,7 @@ LL + println!("{width:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:102:5
+ --> $DIR/uninlined_format_args.rs:107:5
|
LL | println!("{:w$}", local_i32, w = width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -634,7 +634,7 @@ LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:103:5
+ --> $DIR/uninlined_format_args.rs:108:5
|
LL | println!("{:.0$}", prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -646,7 +646,7 @@ LL + println!("{prec:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:104:5
+ --> $DIR/uninlined_format_args.rs:109:5
|
LL | println!("{:.1$}", local_i32, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -658,7 +658,7 @@ LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:105:5
+ --> $DIR/uninlined_format_args.rs:110:5
|
LL | println!("{:.p$}", p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -670,7 +670,7 @@ LL + println!("{prec:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:106:5
+ --> $DIR/uninlined_format_args.rs:111:5
|
LL | println!("{:.p$}", local_i32, p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -682,7 +682,7 @@ LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:107:5
+ --> $DIR/uninlined_format_args.rs:112:5
|
LL | println!("{:0$.1$}", width, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -694,7 +694,7 @@ LL + println!("{width:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:108:5
+ --> $DIR/uninlined_format_args.rs:113:5
|
LL | println!("{:0$.w$}", width, w = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -706,7 +706,7 @@ LL + println!("{width:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:109:5
+ --> $DIR/uninlined_format_args.rs:114:5
|
LL | println!("{:1$.2$}", local_f64, width, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -718,7 +718,7 @@ LL + println!("{local_f64:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:110:5
+ --> $DIR/uninlined_format_args.rs:115:5
|
LL | println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -730,7 +730,7 @@ LL + println!("{local_f64:width$.prec$} {local_f64} {width} {prec}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:111:5
+ --> $DIR/uninlined_format_args.rs:116:5
|
LL | / println!(
LL | | "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
@@ -739,7 +739,7 @@ LL | | );
| |_____^
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:122:5
+ --> $DIR/uninlined_format_args.rs:127:5
|
LL | println!("Width = {}, value with width = {:0$}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -751,7 +751,7 @@ LL + println!("Width = {local_i32}, value with width = {local_f64:local_i32$
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:123:5
+ --> $DIR/uninlined_format_args.rs:128:5
|
LL | println!("{:w$.p$}", local_i32, w = width, p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -763,7 +763,7 @@ LL + println!("{local_i32:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:124:5
+ --> $DIR/uninlined_format_args.rs:129:5
|
LL | println!("{:w$.p$}", w = width, p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -775,7 +775,7 @@ LL + println!("{width:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:143:5
+ --> $DIR/uninlined_format_args.rs:148:5
|
LL | / println!(
LL | | "{}",
@@ -785,7 +785,7 @@ LL | | );
| |_____^
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:148:5
+ --> $DIR/uninlined_format_args.rs:153:5
|
LL | println!("{}", /* comment with a comma , in it */ val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -797,7 +797,7 @@ LL + println!("{val}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:154:9
+ --> $DIR/uninlined_format_args.rs:159:9
|
LL | panic!("p1 {}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -809,7 +809,7 @@ LL + panic!("p1 {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:157:9
+ --> $DIR/uninlined_format_args.rs:162:9
|
LL | panic!("p2 {0}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -821,7 +821,7 @@ LL + panic!("p2 {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:160:9
+ --> $DIR/uninlined_format_args.rs:165:9
|
LL | panic!("p3 {local_i32}", local_i32 = local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -833,7 +833,7 @@ LL + panic!("p3 {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:180:5
+ --> $DIR/uninlined_format_args.rs:185:5
|
LL | println!("expand='{}'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/unit_arg.rs b/src/tools/clippy/tests/ui/unit_arg.rs
index d082063c8..fded8db5d 100644
--- a/src/tools/clippy/tests/ui/unit_arg.rs
+++ b/src/tools/clippy/tests/ui/unit_arg.rs
@@ -1,4 +1,4 @@
-//@aux-build: proc_macros.rs
+//@aux-build: proc_macros.rs:proc-macro
#![warn(clippy::unit_arg)]
#![allow(unused_must_use, unused_variables)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/unit_cmp.rs b/src/tools/clippy/tests/ui/unit_cmp.rs
index 3d2711043..fc75f548a 100644
--- a/src/tools/clippy/tests/ui/unit_cmp.rs
+++ b/src/tools/clippy/tests/ui/unit_cmp.rs
@@ -2,7 +2,8 @@
#![allow(
clippy::no_effect,
clippy::unnecessary_operation,
- clippy::derive_partial_eq_without_eq
+ clippy::derive_partial_eq_without_eq,
+ clippy::needless_if
)]
#[derive(PartialEq)]
diff --git a/src/tools/clippy/tests/ui/unit_cmp.stderr b/src/tools/clippy/tests/ui/unit_cmp.stderr
index 41cf19ae6..79c890d64 100644
--- a/src/tools/clippy/tests/ui/unit_cmp.stderr
+++ b/src/tools/clippy/tests/ui/unit_cmp.stderr
@@ -1,5 +1,5 @@
error: ==-comparison of unit values detected. This will always be true
- --> $DIR/unit_cmp.rs:16:8
+ --> $DIR/unit_cmp.rs:17:8
|
LL | if {
| ________^
@@ -12,7 +12,7 @@ LL | | } {}
= note: `-D clippy::unit-cmp` implied by `-D warnings`
error: >-comparison of unit values detected. This will always be false
- --> $DIR/unit_cmp.rs:22:8
+ --> $DIR/unit_cmp.rs:23:8
|
LL | if {
| ________^
@@ -23,7 +23,7 @@ LL | | } {}
| |_____^
error: `assert_eq` of unit values detected. This will always succeed
- --> $DIR/unit_cmp.rs:28:5
+ --> $DIR/unit_cmp.rs:29:5
|
LL | / assert_eq!(
LL | | {
@@ -35,7 +35,7 @@ LL | | );
| |_____^
error: `debug_assert_eq` of unit values detected. This will always succeed
- --> $DIR/unit_cmp.rs:36:5
+ --> $DIR/unit_cmp.rs:37:5
|
LL | / debug_assert_eq!(
LL | | {
@@ -47,7 +47,7 @@ LL | | );
| |_____^
error: `assert_ne` of unit values detected. This will always fail
- --> $DIR/unit_cmp.rs:45:5
+ --> $DIR/unit_cmp.rs:46:5
|
LL | / assert_ne!(
LL | | {
@@ -59,7 +59,7 @@ LL | | );
| |_____^
error: `debug_assert_ne` of unit values detected. This will always fail
- --> $DIR/unit_cmp.rs:53:5
+ --> $DIR/unit_cmp.rs:54:5
|
LL | / debug_assert_ne!(
LL | | {
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 bdb4710cc..f2a9694f9 100644
--- a/src/tools/clippy/tests/ui/unit_return_expecting_ord.rs
+++ b/src/tools/clippy/tests/ui/unit_return_expecting_ord.rs
@@ -1,6 +1,7 @@
#![warn(clippy::unit_return_expecting_ord)]
#![allow(clippy::needless_return)]
#![allow(clippy::unused_unit)]
+#![allow(clippy::useless_vec)]
#![feature(is_sorted)]
struct Struct {
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 1d9564ce2..3a295af55 100644
--- a/src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr
+++ b/src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr
@@ -1,36 +1,36 @@
error: this closure returns the unit type which also implements Ord
- --> $DIR/unit_return_expecting_ord.rs:18:25
+ --> $DIR/unit_return_expecting_ord.rs:19:25
|
LL | structs.sort_by_key(|s| {
| ^^^
|
help: probably caused by this trailing semicolon
- --> $DIR/unit_return_expecting_ord.rs:19:24
+ --> $DIR/unit_return_expecting_ord.rs:20:24
|
LL | double(s.field);
| ^
= note: `-D clippy::unit-return-expecting-ord` implied by `-D warnings`
error: this closure returns the unit type which also implements PartialOrd
- --> $DIR/unit_return_expecting_ord.rs:22:30
+ --> $DIR/unit_return_expecting_ord.rs:23:30
|
LL | structs.is_sorted_by_key(|s| {
| ^^^
|
help: probably caused by this trailing semicolon
- --> $DIR/unit_return_expecting_ord.rs:23:24
+ --> $DIR/unit_return_expecting_ord.rs:24:24
|
LL | double(s.field);
| ^
error: this closure returns the unit type which also implements PartialOrd
- --> $DIR/unit_return_expecting_ord.rs:25:30
+ --> $DIR/unit_return_expecting_ord.rs:26: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:35:25
+ --> $DIR/unit_return_expecting_ord.rs:36:25
|
LL | structs.sort_by_key(|s| unit(s.field));
| ^^^
diff --git a/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed b/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed
index 49c0e4dc7..debc7e152 100644
--- a/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed
+++ b/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed
@@ -3,7 +3,7 @@
#![warn(clippy::pedantic)]
// Should suggest lowercase
#![allow(clippy::all)]
-#![warn(clippy::cmp_nan)]
+#![warn(clippy::cmp_owned)]
// Should suggest similar clippy lint name
#[warn(clippy::if_not_else)]
diff --git a/src/tools/clippy/tests/ui/unknown_clippy_lints.rs b/src/tools/clippy/tests/ui/unknown_clippy_lints.rs
index b60042923..16140fd10 100644
--- a/src/tools/clippy/tests/ui/unknown_clippy_lints.rs
+++ b/src/tools/clippy/tests/ui/unknown_clippy_lints.rs
@@ -3,7 +3,7 @@
#![warn(clippy::pedantic)]
// Should suggest lowercase
#![allow(clippy::All)]
-#![warn(clippy::CMP_NAN)]
+#![warn(clippy::CMP_OWNED)]
// Should suggest similar clippy lint name
#[warn(clippy::if_not_els)]
diff --git a/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr b/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr
index 584c42893..880673eef 100644
--- a/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr
+++ b/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr
@@ -6,11 +6,11 @@ LL | #![allow(clippy::All)]
|
= note: `-D unknown-lints` implied by `-D warnings`
-error: unknown lint: `clippy::CMP_NAN`
+error: unknown lint: `clippy::CMP_OWNED`
--> $DIR/unknown_clippy_lints.rs:6:9
|
-LL | #![warn(clippy::CMP_NAN)]
- | ^^^^^^^^^^^^^^^ help: did you mean: `clippy::cmp_nan`
+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
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.fixed b/src/tools/clippy/tests/ui/unnecessary_cast.fixed
index bcc231ea7..8efd44baf 100644
--- a/src/tools/clippy/tests/ui/unnecessary_cast.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_cast.fixed
@@ -1,13 +1,43 @@
//@run-rustfix
+//@aux-build:extern_fake_libc.rs
#![warn(clippy::unnecessary_cast)]
#![allow(
- unused_must_use,
clippy::borrow_as_ptr,
clippy::no_effect,
clippy::nonstandard_macro_braces,
- clippy::unnecessary_operation
+ clippy::unnecessary_operation,
+ nonstandard_style,
+ unused
)]
+extern crate extern_fake_libc;
+
+type PtrConstU8 = *const u8;
+type PtrMutU8 = *mut u8;
+
+fn owo<T>(ptr: *const T) -> *const T {
+ ptr
+}
+
+fn uwu<T, U>(ptr: *const T) -> *const U {
+ ptr as *const U
+}
+
+mod fake_libc {
+ type pid_t = i32;
+ pub unsafe fn getpid() -> pid_t {
+ pid_t::from(0)
+ }
+ // Make sure a where clause does not break it
+ pub fn getpid_SAFE_TRUTH<T: Clone>(t: &T) -> pid_t
+ where
+ T: Clone,
+ {
+ t;
+ unsafe { getpid() }
+ }
+}
+
#[rustfmt::skip]
fn main() {
// Test cast_unnecessary
@@ -22,6 +52,26 @@ fn main() {
1_i32;
1_f32;
+ let _: *mut u8 = [1u8, 2].as_ptr() as *mut u8;
+
+ [1u8, 2].as_ptr();
+ [1u8, 2].as_ptr() as *mut u8;
+ [1u8, 2].as_mut_ptr();
+ [1u8, 2].as_mut_ptr() as *const u8;
+ [1u8, 2].as_ptr() as PtrConstU8;
+ [1u8, 2].as_ptr() as PtrMutU8;
+ [1u8, 2].as_mut_ptr() as PtrMutU8;
+ [1u8, 2].as_mut_ptr() as PtrConstU8;
+ let _: *const u8 = [1u8, 2].as_ptr() as _;
+ let _: *mut u8 = [1u8, 2].as_mut_ptr() as _;
+ let _: *const u8 = [1u8, 2].as_ptr() as *const _;
+ let _: *mut u8 = [1u8, 2].as_mut_ptr() as *mut _;
+
+ owo::<u32>([1u32].as_ptr());
+ uwu::<u32, u8>([1u32].as_ptr());
+ // this will not lint in the function body even though they have the same type, instead here
+ uwu::<u32, u32>([1u32].as_ptr());
+
// macro version
macro_rules! foo {
($a:ident, $b:ident) => {
@@ -35,12 +85,37 @@ fn main() {
foo!(b, f32);
foo!(c, f64);
+ // do not lint cast from cfg-dependant type
+ let x = 0 as std::ffi::c_ulong;
+ let y = x as u64;
+ let x: std::ffi::c_ulong = 0;
+ let y = x as u64;
+
// do not lint cast to cfg-dependant type
- 1 as std::os::raw::c_char;
+ let x = 1 as std::os::raw::c_char;
+ let y = x as u64;
// do not lint cast to alias type
1 as I32Alias;
&1 as &I32Alias;
+ // or from
+ let x: I32Alias = 1;
+ let y = x as u64;
+ fake_libc::getpid_SAFE_TRUTH(&0u32) as i32;
+ extern_fake_libc::getpid_SAFE_TRUTH() as i32;
+ let pid = unsafe { fake_libc::getpid() };
+ pid as i32;
+
+ let i8_ptr: *const i8 = &1;
+ let u8_ptr: *const u8 = &1;
+
+ // cfg dependant pointees
+ i8_ptr as *const std::os::raw::c_char;
+ u8_ptr as *const std::os::raw::c_char;
+
+ // type aliased pointees
+ i8_ptr as *const std::ffi::c_char;
+ u8_ptr as *const std::ffi::c_char;
// issue #9960
macro_rules! bind_var {
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.rs b/src/tools/clippy/tests/ui/unnecessary_cast.rs
index 282b2f128..c7723ef51 100644
--- a/src/tools/clippy/tests/ui/unnecessary_cast.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_cast.rs
@@ -1,13 +1,43 @@
//@run-rustfix
+//@aux-build:extern_fake_libc.rs
#![warn(clippy::unnecessary_cast)]
#![allow(
- unused_must_use,
clippy::borrow_as_ptr,
clippy::no_effect,
clippy::nonstandard_macro_braces,
- clippy::unnecessary_operation
+ clippy::unnecessary_operation,
+ nonstandard_style,
+ unused
)]
+extern crate extern_fake_libc;
+
+type PtrConstU8 = *const u8;
+type PtrMutU8 = *mut u8;
+
+fn owo<T>(ptr: *const T) -> *const T {
+ ptr as *const T
+}
+
+fn uwu<T, U>(ptr: *const T) -> *const U {
+ ptr as *const U
+}
+
+mod fake_libc {
+ type pid_t = i32;
+ pub unsafe fn getpid() -> pid_t {
+ pid_t::from(0)
+ }
+ // Make sure a where clause does not break it
+ pub fn getpid_SAFE_TRUTH<T: Clone>(t: &T) -> pid_t
+ where
+ T: Clone,
+ {
+ t;
+ unsafe { getpid() }
+ }
+}
+
#[rustfmt::skip]
fn main() {
// Test cast_unnecessary
@@ -22,6 +52,26 @@ fn main() {
1_i32 as i32;
1_f32 as f32;
+ let _: *mut u8 = [1u8, 2].as_ptr() as *const u8 as *mut u8;
+
+ [1u8, 2].as_ptr() as *const u8;
+ [1u8, 2].as_ptr() as *mut u8;
+ [1u8, 2].as_mut_ptr() as *mut u8;
+ [1u8, 2].as_mut_ptr() as *const u8;
+ [1u8, 2].as_ptr() as PtrConstU8;
+ [1u8, 2].as_ptr() as PtrMutU8;
+ [1u8, 2].as_mut_ptr() as PtrMutU8;
+ [1u8, 2].as_mut_ptr() as PtrConstU8;
+ let _: *const u8 = [1u8, 2].as_ptr() as _;
+ let _: *mut u8 = [1u8, 2].as_mut_ptr() as _;
+ let _: *const u8 = [1u8, 2].as_ptr() as *const _;
+ let _: *mut u8 = [1u8, 2].as_mut_ptr() as *mut _;
+
+ owo::<u32>([1u32].as_ptr()) as *const u32;
+ uwu::<u32, u8>([1u32].as_ptr()) as *const u8;
+ // this will not lint in the function body even though they have the same type, instead here
+ uwu::<u32, u32>([1u32].as_ptr()) as *const u32;
+
// macro version
macro_rules! foo {
($a:ident, $b:ident) => {
@@ -35,12 +85,37 @@ fn main() {
foo!(b, f32);
foo!(c, f64);
+ // do not lint cast from cfg-dependant type
+ let x = 0 as std::ffi::c_ulong;
+ let y = x as u64;
+ let x: std::ffi::c_ulong = 0;
+ let y = x as u64;
+
// do not lint cast to cfg-dependant type
- 1 as std::os::raw::c_char;
+ let x = 1 as std::os::raw::c_char;
+ let y = x as u64;
// do not lint cast to alias type
1 as I32Alias;
&1 as &I32Alias;
+ // or from
+ let x: I32Alias = 1;
+ let y = x as u64;
+ fake_libc::getpid_SAFE_TRUTH(&0u32) as i32;
+ extern_fake_libc::getpid_SAFE_TRUTH() as i32;
+ let pid = unsafe { fake_libc::getpid() };
+ pid as i32;
+
+ let i8_ptr: *const i8 = &1;
+ let u8_ptr: *const u8 = &1;
+
+ // cfg dependant pointees
+ i8_ptr as *const std::os::raw::c_char;
+ u8_ptr as *const std::os::raw::c_char;
+
+ // type aliased pointees
+ i8_ptr as *const std::ffi::c_char;
+ u8_ptr as *const std::ffi::c_char;
// issue #9960
macro_rules! bind_var {
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.stderr b/src/tools/clippy/tests/ui/unnecessary_cast.stderr
index fcee4ee2a..f0443556f 100644
--- a/src/tools/clippy/tests/ui/unnecessary_cast.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_cast.stderr
@@ -1,190 +1,232 @@
+error: casting raw pointers to the same type and constness is unnecessary (`*const T` -> `*const T`)
+ --> $DIR/unnecessary_cast.rs:19:5
+ |
+LL | ptr as *const T
+ | ^^^^^^^^^^^^^^^ help: try: `ptr`
+ |
+ = note: `-D clippy::unnecessary-cast` implied by `-D warnings`
+
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:14:5
+ --> $DIR/unnecessary_cast.rs:44:5
|
LL | 1i32 as i32;
| ^^^^^^^^^^^ help: try: `1_i32`
- |
- = note: `-D clippy::unnecessary-cast` implied by `-D warnings`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:15:5
+ --> $DIR/unnecessary_cast.rs:45:5
|
LL | 1f32 as f32;
| ^^^^^^^^^^^ help: try: `1_f32`
error: casting to the same type is unnecessary (`bool` -> `bool`)
- --> $DIR/unnecessary_cast.rs:16:5
+ --> $DIR/unnecessary_cast.rs:46:5
|
LL | false as bool;
| ^^^^^^^^^^^^^ help: try: `false`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:19:5
+ --> $DIR/unnecessary_cast.rs:49:5
|
LL | -1_i32 as i32;
| ^^^^^^^^^^^^^ help: try: `-1_i32`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:20:5
+ --> $DIR/unnecessary_cast.rs:50:5
|
LL | - 1_i32 as i32;
| ^^^^^^^^^^^^^^ help: try: `- 1_i32`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:21:5
+ --> $DIR/unnecessary_cast.rs:51:5
|
LL | -1f32 as f32;
| ^^^^^^^^^^^^ help: try: `-1_f32`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:22:5
+ --> $DIR/unnecessary_cast.rs:52:5
|
LL | 1_i32 as i32;
| ^^^^^^^^^^^^ help: try: `1_i32`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:23:5
+ --> $DIR/unnecessary_cast.rs:53: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:55: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:57: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:59: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:70:5
+ |
+LL | owo::<u32>([1u32].as_ptr()) as *const u32;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `owo::<u32>([1u32].as_ptr())`
+
+error: casting raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`)
+ --> $DIR/unnecessary_cast.rs:71:5
+ |
+LL | uwu::<u32, u8>([1u32].as_ptr()) as *const u8;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `uwu::<u32, u8>([1u32].as_ptr())`
+
+error: casting raw pointers to the same type and constness is unnecessary (`*const u32` -> `*const u32`)
+ --> $DIR/unnecessary_cast.rs:73:5
+ |
+LL | uwu::<u32, u32>([1u32].as_ptr()) as *const u32;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `uwu::<u32, u32>([1u32].as_ptr())`
+
error: casting integer literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:64:9
+ --> $DIR/unnecessary_cast.rs:139:9
|
LL | 100 as f32;
| ^^^^^^^^^^ help: try: `100_f32`
error: casting integer literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:65:9
+ --> $DIR/unnecessary_cast.rs:140:9
|
LL | 100 as f64;
| ^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:66:9
+ --> $DIR/unnecessary_cast.rs:141:9
|
LL | 100_i32 as f64;
| ^^^^^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:67:17
+ --> $DIR/unnecessary_cast.rs:142:17
|
LL | let _ = -100 as f32;
| ^^^^^^^^^^^ help: try: `-100_f32`
error: casting integer literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:68:17
+ --> $DIR/unnecessary_cast.rs:143:17
|
LL | let _ = -100 as f64;
| ^^^^^^^^^^^ help: try: `-100_f64`
error: casting integer literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:69:17
+ --> $DIR/unnecessary_cast.rs:144:17
|
LL | let _ = -100_i32 as f64;
| ^^^^^^^^^^^^^^^ help: try: `-100_f64`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:70:9
+ --> $DIR/unnecessary_cast.rs:145:9
|
LL | 100. as f32;
| ^^^^^^^^^^^ help: try: `100_f32`
error: casting float literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:71:9
+ --> $DIR/unnecessary_cast.rs:146:9
|
LL | 100. as f64;
| ^^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `u32` is unnecessary
- --> $DIR/unnecessary_cast.rs:83:9
+ --> $DIR/unnecessary_cast.rs:158:9
|
LL | 1 as u32;
| ^^^^^^^^ help: try: `1_u32`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:84:9
+ --> $DIR/unnecessary_cast.rs:159:9
|
LL | 0x10 as i32;
| ^^^^^^^^^^^ help: try: `0x10_i32`
error: casting integer literal to `usize` is unnecessary
- --> $DIR/unnecessary_cast.rs:85:9
+ --> $DIR/unnecessary_cast.rs:160:9
|
LL | 0b10 as usize;
| ^^^^^^^^^^^^^ help: try: `0b10_usize`
error: casting integer literal to `u16` is unnecessary
- --> $DIR/unnecessary_cast.rs:86:9
+ --> $DIR/unnecessary_cast.rs:161:9
|
LL | 0o73 as u16;
| ^^^^^^^^^^^ help: try: `0o73_u16`
error: casting integer literal to `u32` is unnecessary
- --> $DIR/unnecessary_cast.rs:87:9
+ --> $DIR/unnecessary_cast.rs:162: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:89:9
+ --> $DIR/unnecessary_cast.rs:164:9
|
LL | 1.0 as f64;
| ^^^^^^^^^^ help: try: `1.0_f64`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:90:9
+ --> $DIR/unnecessary_cast.rs:165:9
|
LL | 0.5 as f32;
| ^^^^^^^^^^ help: try: `0.5_f32`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:94:17
+ --> $DIR/unnecessary_cast.rs:169:17
|
LL | let _ = -1 as i32;
| ^^^^^^^^^ help: try: `-1_i32`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:95:17
+ --> $DIR/unnecessary_cast.rs:170: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:101:18
+ --> $DIR/unnecessary_cast.rs:176:18
|
LL | let _ = &(x as i32);
| ^^^^^^^^^^ help: try: `{ x }`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:107:22
+ --> $DIR/unnecessary_cast.rs:182:22
|
LL | let _: i32 = -(1) as i32;
| ^^^^^^^^^^^ help: try: `-1_i32`
error: casting integer literal to `i64` is unnecessary
- --> $DIR/unnecessary_cast.rs:109:22
+ --> $DIR/unnecessary_cast.rs:184:22
|
LL | let _: i64 = -(1) as i64;
| ^^^^^^^^^^^ help: try: `-1_i64`
error: casting float literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:116:22
+ --> $DIR/unnecessary_cast.rs:191: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:118:23
+ --> $DIR/unnecessary_cast.rs:193: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:126:20
+ --> $DIR/unnecessary_cast.rs:201:20
|
LL | let _num = foo() as f32;
| ^^^^^^^^^^^^ help: try: `foo()`
-error: aborting due to 31 previous errors
+error: aborting due to 38 previous errors
diff --git a/src/tools/clippy/tests/ui/unnecessary_fold.fixed b/src/tools/clippy/tests/ui/unnecessary_fold.fixed
index 2bed14973..bd1d4a152 100644
--- a/src/tools/clippy/tests/ui/unnecessary_fold.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_fold.fixed
@@ -49,4 +49,28 @@ fn unnecessary_fold_over_multiple_lines() {
.any(|x| x > 2);
}
+fn issue10000() {
+ use std::collections::HashMap;
+ use std::hash::BuildHasher;
+
+ fn anything<T>(_: T) {}
+ fn num(_: i32) {}
+ fn smoketest_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
+ map.insert(0, 0);
+ assert_eq!(map.values().sum::<i32>(), 0);
+
+ // more cases:
+ let _ = map.values().sum::<i32>();
+ let _ = map.values().product::<i32>();
+ let _: i32 = map.values().sum();
+ let _: i32 = map.values().product();
+ anything(map.values().sum::<i32>());
+ anything(map.values().product::<i32>());
+ num(map.values().sum());
+ num(map.values().product());
+ }
+
+ smoketest_map(HashMap::new());
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/unnecessary_fold.rs b/src/tools/clippy/tests/ui/unnecessary_fold.rs
index a3cec8ea3..d27cc460c 100644
--- a/src/tools/clippy/tests/ui/unnecessary_fold.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_fold.rs
@@ -49,4 +49,28 @@ fn unnecessary_fold_over_multiple_lines() {
.fold(false, |acc, x| acc || x > 2);
}
+fn issue10000() {
+ use std::collections::HashMap;
+ use std::hash::BuildHasher;
+
+ fn anything<T>(_: T) {}
+ fn num(_: i32) {}
+ fn smoketest_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
+ map.insert(0, 0);
+ assert_eq!(map.values().fold(0, |x, y| x + y), 0);
+
+ // more cases:
+ let _ = map.values().fold(0, |x, y| x + y);
+ let _ = map.values().fold(1, |x, y| x * y);
+ let _: i32 = map.values().fold(0, |x, y| x + y);
+ let _: i32 = map.values().fold(1, |x, y| x * y);
+ anything(map.values().fold(0, |x, y| x + y));
+ anything(map.values().fold(1, |x, y| x * y));
+ num(map.values().fold(0, |x, y| x + y));
+ num(map.values().fold(1, |x, y| x * y));
+ }
+
+ smoketest_map(HashMap::new());
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/unnecessary_fold.stderr b/src/tools/clippy/tests/ui/unnecessary_fold.stderr
index 22c44588a..98979f747 100644
--- a/src/tools/clippy/tests/ui/unnecessary_fold.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_fold.stderr
@@ -36,5 +36,59 @@ error: this `.fold` can be written more succinctly using another method
LL | .fold(false, |acc, x| acc || x > 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `any(|x| x > 2)`
-error: aborting due to 6 previous errors
+error: this `.fold` can be written more succinctly using another method
+ --> $DIR/unnecessary_fold.rs:60:33
+ |
+LL | assert_eq!(map.values().fold(0, |x, y| x + y), 0);
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `sum::<i32>()`
+
+error: this `.fold` can be written more succinctly using another method
+ --> $DIR/unnecessary_fold.rs:63:30
+ |
+LL | let _ = map.values().fold(0, |x, y| x + y);
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `sum::<i32>()`
+
+error: this `.fold` can be written more succinctly using another method
+ --> $DIR/unnecessary_fold.rs:64:30
+ |
+LL | let _ = map.values().fold(1, |x, y| x * y);
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `product::<i32>()`
+
+error: this `.fold` can be written more succinctly using another method
+ --> $DIR/unnecessary_fold.rs:65: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
+ |
+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
+ |
+LL | anything(map.values().fold(0, |x, y| x + y));
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `sum::<i32>()`
+
+error: this `.fold` can be written more succinctly using another method
+ --> $DIR/unnecessary_fold.rs:68:31
+ |
+LL | anything(map.values().fold(1, |x, y| x * y));
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `product::<i32>()`
+
+error: this `.fold` can be written more succinctly using another method
+ --> $DIR/unnecessary_fold.rs:69: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
+ |
+LL | num(map.values().fold(1, |x, y| x * y));
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `product()`
+
+error: aborting due to 15 previous errors
diff --git a/src/tools/clippy/tests/ui/unnecessary_join.fixed b/src/tools/clippy/tests/ui/unnecessary_join.fixed
index e102df625..f13a5275e 100644
--- a/src/tools/clippy/tests/ui/unnecessary_join.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_join.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
#![warn(clippy::unnecessary_join)]
-#![allow(clippy::uninlined_format_args)]
+#![allow(clippy::uninlined_format_args, clippy::useless_vec)]
fn main() {
// should be linted
diff --git a/src/tools/clippy/tests/ui/unnecessary_join.rs b/src/tools/clippy/tests/ui/unnecessary_join.rs
index b87c15bc1..6014d723a 100644
--- a/src/tools/clippy/tests/ui/unnecessary_join.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_join.rs
@@ -1,6 +1,6 @@
//@run-rustfix
#![warn(clippy::unnecessary_join)]
-#![allow(clippy::uninlined_format_args)]
+#![allow(clippy::uninlined_format_args, clippy::useless_vec)]
fn main() {
// should be linted
diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
index c3728886e..dca380341 100644
--- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
@@ -1,9 +1,13 @@
//@run-rustfix
-//@aux-build: proc_macros.rs
+//@aux-build: proc_macros.rs:proc-macro
#![warn(clippy::unnecessary_lazy_evaluations)]
#![allow(clippy::redundant_closure)]
#![allow(clippy::bind_instead_of_map)]
#![allow(clippy::map_identity)]
+#![allow(clippy::needless_borrow)]
+#![allow(clippy::unnecessary_literal_unwrap)]
+
+use std::ops::Deref;
extern crate proc_macros;
use proc_macros::with_span;
@@ -41,6 +45,15 @@ impl Drop for Issue9427FollowUp {
}
}
+struct Issue10437;
+impl Deref for Issue10437 {
+ type Target = u32;
+ fn deref(&self) -> &Self::Target {
+ println!("side effect deref");
+ &0
+ }
+}
+
fn main() {
let astronomers_pi = 10;
let ext_arr: [usize; 1] = [2];
@@ -65,6 +78,15 @@ fn main() {
let _ = nested_tuple_opt.unwrap_or(Some((1, 2)));
let _ = cond.then_some(astronomers_pi);
+ // Should lint - Builtin deref
+ let r = &1;
+ let _ = Some(1).unwrap_or(*r);
+ let b = Box::new(1);
+ let _ = Some(1).unwrap_or(*b);
+ // Should lint - Builtin deref through autoderef
+ let _ = Some(1).as_ref().unwrap_or(&r);
+ let _ = Some(1).as_ref().unwrap_or(&b);
+
// Cases when unwrap is not called on a simple variable
let _ = Some(10).unwrap_or(2);
let _ = Some(10).and(ext_opt);
@@ -93,6 +115,12 @@ fn main() {
let _ = deep.0.or_else(|| some_call());
let _ = opt.ok_or_else(|| ext_arr[0]);
+ let _ = Some(1).unwrap_or_else(|| *Issue10437); // Issue10437 has a deref impl
+ let _ = Some(1).unwrap_or(*Issue10437);
+
+ let _ = Some(1).as_ref().unwrap_or_else(|| &Issue10437);
+ let _ = Some(1).as_ref().unwrap_or(&Issue10437);
+
// Should not lint - bool
let _ = (0 == 1).then(|| Issue9427(0)); // Issue9427 has a significant drop
let _ = false.then(|| Issue9427FollowUp); // Issue9427FollowUp has a significant drop
diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs
index 76e50fa5b..7fda719ed 100644
--- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs
@@ -1,9 +1,13 @@
//@run-rustfix
-//@aux-build: proc_macros.rs
+//@aux-build: proc_macros.rs:proc-macro
#![warn(clippy::unnecessary_lazy_evaluations)]
#![allow(clippy::redundant_closure)]
#![allow(clippy::bind_instead_of_map)]
#![allow(clippy::map_identity)]
+#![allow(clippy::needless_borrow)]
+#![allow(clippy::unnecessary_literal_unwrap)]
+
+use std::ops::Deref;
extern crate proc_macros;
use proc_macros::with_span;
@@ -41,6 +45,15 @@ impl Drop for Issue9427FollowUp {
}
}
+struct Issue10437;
+impl Deref for Issue10437 {
+ type Target = u32;
+ fn deref(&self) -> &Self::Target {
+ println!("side effect deref");
+ &0
+ }
+}
+
fn main() {
let astronomers_pi = 10;
let ext_arr: [usize; 1] = [2];
@@ -65,6 +78,15 @@ fn main() {
let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2)));
let _ = cond.then(|| astronomers_pi);
+ // Should lint - Builtin deref
+ let r = &1;
+ let _ = Some(1).unwrap_or_else(|| *r);
+ let b = Box::new(1);
+ let _ = Some(1).unwrap_or_else(|| *b);
+ // Should lint - Builtin deref through autoderef
+ let _ = Some(1).as_ref().unwrap_or_else(|| &r);
+ let _ = Some(1).as_ref().unwrap_or_else(|| &b);
+
// Cases when unwrap is not called on a simple variable
let _ = Some(10).unwrap_or_else(|| 2);
let _ = Some(10).and_then(|_| ext_opt);
@@ -93,6 +115,12 @@ fn main() {
let _ = deep.0.or_else(|| some_call());
let _ = opt.ok_or_else(|| ext_arr[0]);
+ let _ = Some(1).unwrap_or_else(|| *Issue10437); // Issue10437 has a deref impl
+ let _ = Some(1).unwrap_or(*Issue10437);
+
+ let _ = Some(1).as_ref().unwrap_or_else(|| &Issue10437);
+ let _ = Some(1).as_ref().unwrap_or(&Issue10437);
+
// Should not lint - bool
let _ = (0 == 1).then(|| Issue9427(0)); // Issue9427 has a significant drop
let _ = false.then(|| Issue9427FollowUp); // Issue9427FollowUp has a significant drop
diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr
index 033975544..458eed1f3 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:56:13
+ --> $DIR/unnecessary_lazy_eval.rs:69:13
|
LL | let _ = opt.unwrap_or_else(|| 2);
| ^^^^--------------------
@@ -9,7 +9,7 @@ LL | let _ = opt.unwrap_or_else(|| 2);
= note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:57:13
+ --> $DIR/unnecessary_lazy_eval.rs:70:13
|
LL | let _ = opt.unwrap_or_else(|| astronomers_pi);
| ^^^^---------------------------------
@@ -17,7 +17,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:58:13
+ --> $DIR/unnecessary_lazy_eval.rs:71:13
|
LL | let _ = opt.unwrap_or_else(|| ext_str.some_field);
| ^^^^-------------------------------------
@@ -25,7 +25,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:60:13
+ --> $DIR/unnecessary_lazy_eval.rs:73:13
|
LL | let _ = opt.and_then(|_| ext_opt);
| ^^^^---------------------
@@ -33,7 +33,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:61:13
+ --> $DIR/unnecessary_lazy_eval.rs:74:13
|
LL | let _ = opt.or_else(|| ext_opt);
| ^^^^-------------------
@@ -41,7 +41,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:62:13
+ --> $DIR/unnecessary_lazy_eval.rs:75:13
|
LL | let _ = opt.or_else(|| None);
| ^^^^----------------
@@ -49,7 +49,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:63:13
+ --> $DIR/unnecessary_lazy_eval.rs:76:13
|
LL | let _ = opt.get_or_insert_with(|| 2);
| ^^^^------------------------
@@ -57,7 +57,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:64:13
+ --> $DIR/unnecessary_lazy_eval.rs:77:13
|
LL | let _ = opt.ok_or_else(|| 2);
| ^^^^----------------
@@ -65,7 +65,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:65:13
+ --> $DIR/unnecessary_lazy_eval.rs:78:13
|
LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2)));
| ^^^^^^^^^^^^^^^^^-------------------------------
@@ -73,7 +73,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:66:13
+ --> $DIR/unnecessary_lazy_eval.rs:79:13
|
LL | let _ = cond.then(|| astronomers_pi);
| ^^^^^-----------------------
@@ -81,7 +81,39 @@ 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:69:13
+ --> $DIR/unnecessary_lazy_eval.rs:83:13
+ |
+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
+ |
+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
+ |
+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
+ |
+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
|
LL | let _ = Some(10).unwrap_or_else(|| 2);
| ^^^^^^^^^--------------------
@@ -89,7 +121,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:70:13
+ --> $DIR/unnecessary_lazy_eval.rs:92:13
|
LL | let _ = Some(10).and_then(|_| ext_opt);
| ^^^^^^^^^---------------------
@@ -97,7 +129,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:71:28
+ --> $DIR/unnecessary_lazy_eval.rs:93:28
|
LL | let _: Option<usize> = None.or_else(|| ext_opt);
| ^^^^^-------------------
@@ -105,7 +137,7 @@ LL | let _: Option<usize> = 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:72:13
+ --> $DIR/unnecessary_lazy_eval.rs:94:13
|
LL | let _ = None.get_or_insert_with(|| 2);
| ^^^^^------------------------
@@ -113,7 +145,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:73:35
+ --> $DIR/unnecessary_lazy_eval.rs:95:35
|
LL | let _: Result<usize, usize> = None.ok_or_else(|| 2);
| ^^^^^----------------
@@ -121,7 +153,7 @@ LL | let _: Result<usize, usize> = 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:74:28
+ --> $DIR/unnecessary_lazy_eval.rs:96:28
|
LL | let _: Option<usize> = None.or_else(|| None);
| ^^^^^----------------
@@ -129,7 +161,7 @@ LL | let _: Option<usize> = 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:77:13
+ --> $DIR/unnecessary_lazy_eval.rs:99:13
|
LL | let _ = deep.0.unwrap_or_else(|| 2);
| ^^^^^^^--------------------
@@ -137,7 +169,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:78:13
+ --> $DIR/unnecessary_lazy_eval.rs:100:13
|
LL | let _ = deep.0.and_then(|_| ext_opt);
| ^^^^^^^---------------------
@@ -145,7 +177,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:79:13
+ --> $DIR/unnecessary_lazy_eval.rs:101:13
|
LL | let _ = deep.0.or_else(|| None);
| ^^^^^^^----------------
@@ -153,7 +185,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:80:13
+ --> $DIR/unnecessary_lazy_eval.rs:102:13
|
LL | let _ = deep.0.get_or_insert_with(|| 2);
| ^^^^^^^------------------------
@@ -161,7 +193,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:81:13
+ --> $DIR/unnecessary_lazy_eval.rs:103:13
|
LL | let _ = deep.0.ok_or_else(|| 2);
| ^^^^^^^----------------
@@ -169,7 +201,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:105:28
+ --> $DIR/unnecessary_lazy_eval.rs:133:28
|
LL | let _: Option<usize> = None.or_else(|| Some(3));
| ^^^^^-------------------
@@ -177,7 +209,7 @@ LL | let _: Option<usize> = 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:106:13
+ --> $DIR/unnecessary_lazy_eval.rs:134:13
|
LL | let _ = deep.0.or_else(|| Some(3));
| ^^^^^^^-------------------
@@ -185,7 +217,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:107:13
+ --> $DIR/unnecessary_lazy_eval.rs:135:13
|
LL | let _ = opt.or_else(|| Some(3));
| ^^^^-------------------
@@ -193,7 +225,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:113:13
+ --> $DIR/unnecessary_lazy_eval.rs:141:13
|
LL | let _ = res2.unwrap_or_else(|_| 2);
| ^^^^^---------------------
@@ -201,7 +233,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:114:13
+ --> $DIR/unnecessary_lazy_eval.rs:142:13
|
LL | let _ = res2.unwrap_or_else(|_| astronomers_pi);
| ^^^^^----------------------------------
@@ -209,7 +241,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:115:13
+ --> $DIR/unnecessary_lazy_eval.rs:143:13
|
LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field);
| ^^^^^--------------------------------------
@@ -217,7 +249,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:137:35
+ --> $DIR/unnecessary_lazy_eval.rs:165:35
|
LL | let _: Result<usize, usize> = res.and_then(|_| Err(2));
| ^^^^--------------------
@@ -225,7 +257,7 @@ LL | let _: Result<usize, usize> = 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:138:35
+ --> $DIR/unnecessary_lazy_eval.rs:166:35
|
LL | let _: Result<usize, usize> = res.and_then(|_| Err(astronomers_pi));
| ^^^^---------------------------------
@@ -233,7 +265,7 @@ LL | let _: Result<usize, usize> = 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:139:35
+ --> $DIR/unnecessary_lazy_eval.rs:167:35
|
LL | let _: Result<usize, usize> = res.and_then(|_| Err(ext_str.some_field));
| ^^^^-------------------------------------
@@ -241,7 +273,7 @@ LL | let _: Result<usize, usize> = 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:141:35
+ --> $DIR/unnecessary_lazy_eval.rs:169:35
|
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(2));
| ^^^^------------------
@@ -249,7 +281,7 @@ LL | let _: Result<usize, usize> = 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:142:35
+ --> $DIR/unnecessary_lazy_eval.rs:170:35
|
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(astronomers_pi));
| ^^^^-------------------------------
@@ -257,7 +289,7 @@ LL | let _: Result<usize, usize> = 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:143:35
+ --> $DIR/unnecessary_lazy_eval.rs:171:35
|
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(ext_str.some_field));
| ^^^^-----------------------------------
@@ -265,7 +297,7 @@ LL | let _: Result<usize, usize> = 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:144:35
+ --> $DIR/unnecessary_lazy_eval.rs:172:35
|
LL | let _: Result<usize, usize> = res.
| ___________________________________^
@@ -279,5 +311,5 @@ LL | | or_else(|_| Ok(ext_str.some_field));
| |
| help: use `or(..)` instead: `or(Ok(ext_str.some_field))`
-error: aborting due to 34 previous errors
+error: aborting due to 38 previous errors
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 b05dd143b..b4a1f8167 100644
--- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.rs
@@ -1,4 +1,5 @@
#![warn(clippy::unnecessary_lazy_evaluations)]
+#![allow(clippy::unnecessary_literal_unwrap)]
struct Deep(Option<usize>);
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 20acab6e8..7f353ba06 100644
--- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.stderr
@@ -1,5 +1,5 @@
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval_unfixable.rs:12:13
+ --> $DIR/unnecessary_lazy_eval_unfixable.rs:13:13
|
LL | let _ = Ok(1).unwrap_or_else(|()| 2);
| ^^^^^^----------------------
@@ -9,7 +9,7 @@ LL | let _ = Ok(1).unwrap_or_else(|()| 2);
= note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval_unfixable.rs:16:13
+ --> $DIR/unnecessary_lazy_eval_unfixable.rs:17:13
|
LL | let _ = Ok(1).unwrap_or_else(|e::E| 2);
| ^^^^^^------------------------
@@ -17,7 +17,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:17:13
+ --> $DIR/unnecessary_lazy_eval_unfixable.rs:18: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
new file mode 100644
index 000000000..44530d8b1
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.fixed
@@ -0,0 +1,89 @@
+//@run-rustfix
+#![warn(clippy::unnecessary_literal_unwrap)]
+#![allow(unreachable_code)]
+#![allow(
+ clippy::unnecessary_lazy_evaluations,
+ clippy::diverging_sub_expression,
+ clippy::let_unit_value,
+ clippy::no_effect
+)]
+
+fn unwrap_option_some() {
+ let _val = 1;
+ let _val = 1;
+
+ 1;
+ 1;
+}
+
+#[rustfmt::skip] // force rustfmt not to remove braces in `|| { 234 }`
+fn unwrap_option_none() {
+ let _val = panic!();
+ let _val = panic!("this always happens");
+ let _val: String = String::default();
+ let _val: u16 = 234;
+ let _val: u16 = 234;
+ let _val: u16 = { 234 };
+ let _val: u16 = { 234 };
+
+ panic!();
+ panic!("this always happens");
+ String::default();
+ 234;
+ 234;
+ { 234 };
+ { 234 };
+}
+
+fn unwrap_result_ok() {
+ let _val = 1;
+ let _val = 1;
+ let _val = panic!("{:?}", 1);
+ let _val = panic!("{1}: {:?}", 1, "this always happens");
+
+ 1;
+ 1;
+ panic!("{:?}", 1);
+ panic!("{1}: {:?}", 1, "this always happens");
+}
+
+fn unwrap_result_err() {
+ let _val = 1;
+ let _val = 1;
+ let _val = panic!("{:?}", 1);
+ let _val = panic!("{1}: {:?}", 1, "this always happens");
+
+ 1;
+ 1;
+ panic!("{:?}", 1);
+ panic!("{1}: {:?}", 1, "this always happens");
+}
+
+fn unwrap_methods_option() {
+ let _val = 1;
+ let _val = 1;
+ let _val = 1;
+
+ 1;
+ 1;
+ 1;
+}
+
+fn unwrap_methods_result() {
+ let _val = 1;
+ let _val = 1;
+ let _val = 1;
+
+ 1;
+ 1;
+ 1;
+}
+
+fn main() {
+ unwrap_option_some();
+ unwrap_option_none();
+ unwrap_result_ok();
+ unwrap_result_err();
+ unwrap_methods_option();
+ unwrap_methods_result();
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.rs b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.rs
new file mode 100644
index 000000000..b43e4d3a3
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.rs
@@ -0,0 +1,89 @@
+//@run-rustfix
+#![warn(clippy::unnecessary_literal_unwrap)]
+#![allow(unreachable_code)]
+#![allow(
+ clippy::unnecessary_lazy_evaluations,
+ clippy::diverging_sub_expression,
+ clippy::let_unit_value,
+ clippy::no_effect
+)]
+
+fn unwrap_option_some() {
+ let _val = Some(1).unwrap();
+ let _val = Some(1).expect("this never happens");
+
+ Some(1).unwrap();
+ Some(1).expect("this never happens");
+}
+
+#[rustfmt::skip] // force rustfmt not to remove braces in `|| { 234 }`
+fn unwrap_option_none() {
+ let _val = None::<()>.unwrap();
+ let _val = None::<()>.expect("this always happens");
+ let _val: String = None.unwrap_or_default();
+ let _val: u16 = None.unwrap_or(234);
+ let _val: u16 = None.unwrap_or_else(|| 234);
+ let _val: u16 = None.unwrap_or_else(|| { 234 });
+ let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 });
+
+ None::<()>.unwrap();
+ None::<()>.expect("this always happens");
+ None::<String>.unwrap_or_default();
+ None::<u16>.unwrap_or(234);
+ None::<u16>.unwrap_or_else(|| 234);
+ None::<u16>.unwrap_or_else(|| { 234 });
+ None::<u16>.unwrap_or_else(|| -> u16 { 234 });
+}
+
+fn unwrap_result_ok() {
+ let _val = Ok::<_, ()>(1).unwrap();
+ let _val = Ok::<_, ()>(1).expect("this never happens");
+ let _val = Ok::<_, ()>(1).unwrap_err();
+ let _val = Ok::<_, ()>(1).expect_err("this always happens");
+
+ Ok::<_, ()>(1).unwrap();
+ Ok::<_, ()>(1).expect("this never happens");
+ Ok::<_, ()>(1).unwrap_err();
+ Ok::<_, ()>(1).expect_err("this always happens");
+}
+
+fn unwrap_result_err() {
+ let _val = Err::<(), _>(1).unwrap_err();
+ let _val = Err::<(), _>(1).expect_err("this never happens");
+ let _val = Err::<(), _>(1).unwrap();
+ let _val = Err::<(), _>(1).expect("this always happens");
+
+ Err::<(), _>(1).unwrap_err();
+ Err::<(), _>(1).expect_err("this never happens");
+ Err::<(), _>(1).unwrap();
+ Err::<(), _>(1).expect("this always happens");
+}
+
+fn unwrap_methods_option() {
+ let _val = Some(1).unwrap_or(2);
+ let _val = Some(1).unwrap_or_default();
+ let _val = Some(1).unwrap_or_else(|| 2);
+
+ Some(1).unwrap_or(2);
+ Some(1).unwrap_or_default();
+ Some(1).unwrap_or_else(|| 2);
+}
+
+fn unwrap_methods_result() {
+ let _val = Ok::<_, ()>(1).unwrap_or(2);
+ let _val = Ok::<_, ()>(1).unwrap_or_default();
+ let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2);
+
+ Ok::<_, ()>(1).unwrap_or(2);
+ Ok::<_, ()>(1).unwrap_or_default();
+ Ok::<_, ()>(1).unwrap_or_else(|_| 2);
+}
+
+fn main() {
+ unwrap_option_some();
+ unwrap_option_none();
+ unwrap_result_ok();
+ unwrap_result_err();
+ unwrap_methods_option();
+ unwrap_methods_result();
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.stderr b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.stderr
new file mode 100644
index 000000000..905384bc8
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.stderr
@@ -0,0 +1,521 @@
+error: used `unwrap()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:12:16
+ |
+LL | let _val = Some(1).unwrap();
+ | ^^^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings`
+help: remove the `Some` and `unwrap()`
+ |
+LL - let _val = Some(1).unwrap();
+LL + let _val = 1;
+ |
+
+error: used `expect()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:13:16
+ |
+LL | let _val = Some(1).expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `expect()`
+ |
+LL - let _val = Some(1).expect("this never happens");
+LL + let _val = 1;
+ |
+
+error: used `unwrap()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:15:5
+ |
+LL | Some(1).unwrap();
+ | ^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap()`
+ |
+LL - Some(1).unwrap();
+LL + 1;
+ |
+
+error: used `expect()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:16:5
+ |
+LL | Some(1).expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `expect()`
+ |
+LL - Some(1).expect("this never happens");
+LL + 1;
+ |
+
+error: used `unwrap()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap.rs:21: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
+ |
+LL | let _val = None::<()>.expect("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `None` and `expect()`
+ |
+LL | let _val = panic!("this always happens");
+ | ~~~~~~~ ~
+
+error: used `unwrap_or_default()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap.rs:23: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
+ |
+LL | let _val: u16 = None.unwrap_or(234);
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `None` and `unwrap_or()`
+ |
+LL - let _val: u16 = None.unwrap_or(234);
+LL + let _val: u16 = 234;
+ |
+
+error: used `unwrap_or_else()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap.rs:25:21
+ |
+LL | let _val: u16 = None.unwrap_or_else(|| 234);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `None` and `unwrap_or_else()`
+ |
+LL - let _val: u16 = None.unwrap_or_else(|| 234);
+LL + let _val: u16 = 234;
+ |
+
+error: used `unwrap_or_else()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap.rs:26:21
+ |
+LL | let _val: u16 = None.unwrap_or_else(|| { 234 });
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `None` and `unwrap_or_else()`
+ |
+LL - let _val: u16 = None.unwrap_or_else(|| { 234 });
+LL + let _val: u16 = { 234 };
+ |
+
+error: used `unwrap_or_else()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap.rs:27:21
+ |
+LL | let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 });
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `None` and `unwrap_or_else()`
+ |
+LL - let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 });
+LL + let _val: u16 = { 234 };
+ |
+
+error: used `unwrap()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap.rs:29:5
+ |
+LL | None::<()>.unwrap();
+ | ^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()`
+
+error: used `expect()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap.rs:30:5
+ |
+LL | None::<()>.expect("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `None` and `expect()`
+ |
+LL | panic!("this always happens");
+ | ~~~~~~~ ~
+
+error: used `unwrap_or_default()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap.rs:31:5
+ |
+LL | None::<String>.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
+ |
+LL | None::<u16>.unwrap_or(234);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `None` and `unwrap_or()`
+ |
+LL - None::<u16>.unwrap_or(234);
+LL + 234;
+ |
+
+error: used `unwrap_or_else()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap.rs:33:5
+ |
+LL | None::<u16>.unwrap_or_else(|| 234);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `None` and `unwrap_or_else()`
+ |
+LL - None::<u16>.unwrap_or_else(|| 234);
+LL + 234;
+ |
+
+error: used `unwrap_or_else()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap.rs:34:5
+ |
+LL | None::<u16>.unwrap_or_else(|| { 234 });
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `None` and `unwrap_or_else()`
+ |
+LL - None::<u16>.unwrap_or_else(|| { 234 });
+LL + { 234 };
+ |
+
+error: used `unwrap_or_else()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap.rs:35:5
+ |
+LL | None::<u16>.unwrap_or_else(|| -> u16 { 234 });
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `None` and `unwrap_or_else()`
+ |
+LL - None::<u16>.unwrap_or_else(|| -> u16 { 234 });
+LL + { 234 };
+ |
+
+error: used `unwrap()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:39:16
+ |
+LL | let _val = Ok::<_, ()>(1).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap()`
+ |
+LL - let _val = Ok::<_, ()>(1).unwrap();
+LL + let _val = 1;
+ |
+
+error: used `expect()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:40:16
+ |
+LL | let _val = Ok::<_, ()>(1).expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `expect()`
+ |
+LL - let _val = Ok::<_, ()>(1).expect("this never happens");
+LL + let _val = 1;
+ |
+
+error: used `unwrap_err()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:41:16
+ |
+LL | let _val = Ok::<_, ()>(1).unwrap_err();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_err()`
+ |
+LL | let _val = panic!("{:?}", 1);
+ | ~~~~~~~~~~~~~~ ~
+
+error: used `expect_err()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:42:16
+ |
+LL | let _val = Ok::<_, ()>(1).expect_err("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `expect_err()`
+ |
+LL | let _val = panic!("{1}: {:?}", 1, "this always happens");
+ | ~~~~~~~~~~~~~~~~~~~ ~
+
+error: used `unwrap()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:44:5
+ |
+LL | Ok::<_, ()>(1).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap()`
+ |
+LL - Ok::<_, ()>(1).unwrap();
+LL + 1;
+ |
+
+error: used `expect()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:45:5
+ |
+LL | Ok::<_, ()>(1).expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `expect()`
+ |
+LL - Ok::<_, ()>(1).expect("this never happens");
+LL + 1;
+ |
+
+error: used `unwrap_err()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:46:5
+ |
+LL | Ok::<_, ()>(1).unwrap_err();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_err()`
+ |
+LL | panic!("{:?}", 1);
+ | ~~~~~~~~~~~~~~ ~
+
+error: used `expect_err()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:47:5
+ |
+LL | Ok::<_, ()>(1).expect_err("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `expect_err()`
+ |
+LL | panic!("{1}: {:?}", 1, "this always happens");
+ | ~~~~~~~~~~~~~~~~~~~ ~
+
+error: used `unwrap_err()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap.rs:51:16
+ |
+LL | let _val = Err::<(), _>(1).unwrap_err();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `unwrap_err()`
+ |
+LL - let _val = Err::<(), _>(1).unwrap_err();
+LL + let _val = 1;
+ |
+
+error: used `expect_err()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap.rs:52:16
+ |
+LL | let _val = Err::<(), _>(1).expect_err("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `expect_err()`
+ |
+LL - let _val = Err::<(), _>(1).expect_err("this never happens");
+LL + let _val = 1;
+ |
+
+error: used `unwrap()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap.rs:53:16
+ |
+LL | let _val = Err::<(), _>(1).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `unwrap()`
+ |
+LL | let _val = panic!("{:?}", 1);
+ | ~~~~~~~~~~~~~~ ~
+
+error: used `expect()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap.rs:54:16
+ |
+LL | let _val = Err::<(), _>(1).expect("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `expect()`
+ |
+LL | let _val = panic!("{1}: {:?}", 1, "this always happens");
+ | ~~~~~~~~~~~~~~~~~~~ ~
+
+error: used `unwrap_err()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap.rs:56:5
+ |
+LL | Err::<(), _>(1).unwrap_err();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `unwrap_err()`
+ |
+LL - Err::<(), _>(1).unwrap_err();
+LL + 1;
+ |
+
+error: used `expect_err()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap.rs:57:5
+ |
+LL | Err::<(), _>(1).expect_err("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `expect_err()`
+ |
+LL - Err::<(), _>(1).expect_err("this never happens");
+LL + 1;
+ |
+
+error: used `unwrap()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap.rs:58:5
+ |
+LL | Err::<(), _>(1).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `unwrap()`
+ |
+LL | panic!("{:?}", 1);
+ | ~~~~~~~~~~~~~~ ~
+
+error: used `expect()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap.rs:59:5
+ |
+LL | Err::<(), _>(1).expect("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `expect()`
+ |
+LL | panic!("{1}: {:?}", 1, "this always happens");
+ | ~~~~~~~~~~~~~~~~~~~ ~
+
+error: used `unwrap_or()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:63:16
+ |
+LL | let _val = Some(1).unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or()`
+ |
+LL - let _val = Some(1).unwrap_or(2);
+LL + let _val = 1;
+ |
+
+error: used `unwrap_or_default()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:64:16
+ |
+LL | let _val = Some(1).unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or_default()`
+ |
+LL - let _val = Some(1).unwrap_or_default();
+LL + let _val = 1;
+ |
+
+error: used `unwrap_or_else()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:65:16
+ |
+LL | let _val = Some(1).unwrap_or_else(|| 2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or_else()`
+ |
+LL - let _val = Some(1).unwrap_or_else(|| 2);
+LL + let _val = 1;
+ |
+
+error: used `unwrap_or()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:67:5
+ |
+LL | Some(1).unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or()`
+ |
+LL - Some(1).unwrap_or(2);
+LL + 1;
+ |
+
+error: used `unwrap_or_default()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:68:5
+ |
+LL | Some(1).unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or_default()`
+ |
+LL - Some(1).unwrap_or_default();
+LL + 1;
+ |
+
+error: used `unwrap_or_else()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:69:5
+ |
+LL | Some(1).unwrap_or_else(|| 2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or_else()`
+ |
+LL - Some(1).unwrap_or_else(|| 2);
+LL + 1;
+ |
+
+error: used `unwrap_or()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:73:16
+ |
+LL | let _val = Ok::<_, ()>(1).unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or()`
+ |
+LL - let _val = Ok::<_, ()>(1).unwrap_or(2);
+LL + let _val = 1;
+ |
+
+error: used `unwrap_or_default()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:74:16
+ |
+LL | let _val = Ok::<_, ()>(1).unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or_default()`
+ |
+LL - let _val = Ok::<_, ()>(1).unwrap_or_default();
+LL + let _val = 1;
+ |
+
+error: used `unwrap_or_else()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:75:16
+ |
+LL | let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or_else()`
+ |
+LL - let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2);
+LL + let _val = 1;
+ |
+
+error: used `unwrap_or()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:77:5
+ |
+LL | Ok::<_, ()>(1).unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or()`
+ |
+LL - Ok::<_, ()>(1).unwrap_or(2);
+LL + 1;
+ |
+
+error: used `unwrap_or_default()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:78:5
+ |
+LL | Ok::<_, ()>(1).unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or_default()`
+ |
+LL - Ok::<_, ()>(1).unwrap_or_default();
+LL + 1;
+ |
+
+error: used `unwrap_or_else()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:79:5
+ |
+LL | Ok::<_, ()>(1).unwrap_or_else(|_| 2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or_else()`
+ |
+LL - Ok::<_, ()>(1).unwrap_or_else(|_| 2);
+LL + 1;
+ |
+
+error: aborting due to 46 previous errors
+
diff --git a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.rs b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.rs
new file mode 100644
index 000000000..41300aceb
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.rs
@@ -0,0 +1,118 @@
+#![warn(clippy::unnecessary_literal_unwrap)]
+#![allow(unreachable_code)]
+#![allow(clippy::unnecessary_lazy_evaluations, clippy::let_unit_value)]
+
+fn unwrap_option_some() {
+ let val = Some(1);
+ let _val2 = val.unwrap();
+ let _val2 = val.expect("this never happens");
+}
+
+fn unwrap_option_some_context() {
+ let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap();
+ let _val = Some::<usize>([1, 2, 3].iter().sum()).expect("this never happens");
+
+ let val = Some::<usize>([1, 2, 3].iter().sum());
+ let _val2 = val.unwrap();
+ let _val2 = val.expect("this never happens");
+}
+
+fn unwrap_option_none() {
+ let val = None::<()>;
+ let _val2 = val.unwrap();
+ let _val2 = val.expect("this always happens");
+ let _val3: u8 = None.unwrap_or_default();
+ None::<()>.unwrap_or_default();
+}
+
+fn unwrap_result_ok() {
+ let val = Ok::<_, ()>(1);
+ let _val2 = val.unwrap();
+ let _val2 = val.expect("this never happens");
+ let _val2 = val.unwrap_err();
+ let _val2 = val.expect_err("this always happens");
+}
+
+fn unwrap_result_ok_context() {
+ let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap();
+ let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect("this never happens");
+ let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_err();
+ let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect_err("this always happens");
+
+ let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
+ let _val2 = val.unwrap();
+ let _val2 = val.expect("this never happens");
+ let _val2 = val.unwrap_err();
+ let _val2 = val.expect_err("this always happens");
+}
+
+fn unwrap_result_err() {
+ let val = Err::<(), _>(1);
+ let _val2 = val.unwrap_err();
+ let _val2 = val.expect_err("this never happens");
+ let _val2 = val.unwrap();
+ let _val2 = val.expect("this always happens");
+}
+
+fn unwrap_result_err_context() {
+ let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err();
+ let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens");
+ let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap();
+ let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens");
+
+ let val = Err::<(), usize>([1, 2, 3].iter().sum());
+ let _val2 = val.unwrap_err();
+ let _val2 = val.expect_err("this never happens");
+ let _val2 = val.unwrap();
+ let _val2 = val.expect("this always happens");
+}
+
+fn unwrap_methods_option() {
+ let val = Some(1);
+ let _val2 = val.unwrap_or(2);
+ let _val2 = val.unwrap_or_default();
+ let _val2 = val.unwrap_or_else(|| 2);
+}
+
+fn unwrap_methods_option_context() {
+ let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or(2);
+ let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_default();
+ let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_else(|| 2);
+
+ let val = Some::<usize>([1, 2, 3].iter().sum());
+ let _val2 = val.unwrap_or(2);
+ let _val2 = val.unwrap_or_default();
+ let _val2 = val.unwrap_or_else(|| 2);
+}
+
+fn unwrap_methods_result() {
+ let val = Ok::<_, ()>(1);
+ let _val2 = val.unwrap_or(2);
+ let _val2 = val.unwrap_or_default();
+ let _val2 = val.unwrap_or_else(|_| 2);
+}
+
+fn unwrap_methods_result_context() {
+ let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or(2);
+ let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_default();
+ let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2);
+
+ let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
+ let _val2 = val.unwrap_or(2);
+ let _val2 = val.unwrap_or_default();
+ let _val2 = val.unwrap_or_else(|_| 2);
+}
+
+fn main() {
+ unwrap_option_some();
+ unwrap_option_some_context();
+ unwrap_option_none();
+ unwrap_result_ok();
+ unwrap_result_ok_context();
+ unwrap_result_err();
+ unwrap_result_err_context();
+ unwrap_methods_option();
+ unwrap_methods_option_context();
+ unwrap_methods_result();
+ unwrap_methods_result_context();
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.stderr b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.stderr
new file mode 100644
index 000000000..2d1270d47
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap_unfixable.stderr
@@ -0,0 +1,615 @@
+error: used `unwrap()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:7:17
+ |
+LL | let _val2 = val.unwrap();
+ | ^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:6:15
+ |
+LL | let val = Some(1);
+ | ^^^^^^^
+ = note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings`
+
+error: used `expect()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:8:17
+ |
+LL | let _val2 = val.expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `expect()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:6:15
+ |
+LL | let val = Some(1);
+ | ^^^^^^^
+
+error: used `unwrap()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:16
+ |
+LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:16
+ |
+LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `expect()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:13:16
+ |
+LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `expect()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:13:16
+ |
+LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:16:17
+ |
+LL | let _val2 = val.unwrap();
+ | ^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:15:15
+ |
+LL | let val = Some::<usize>([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `expect()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:17:17
+ |
+LL | let _val2 = val.expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `expect()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:15:15
+ |
+LL | let val = Some::<usize>([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:22:17
+ |
+LL | let _val2 = val.unwrap();
+ | ^^^^^^^^^^^^
+ |
+help: remove the `None` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:21:15
+ |
+LL | let val = None::<()>;
+ | ^^^^^^^^^^
+
+error: used `expect()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:23:17
+ |
+LL | let _val2 = val.expect("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `None` and `expect()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:21:15
+ |
+LL | let val = None::<()>;
+ | ^^^^^^^^^^
+
+error: used `unwrap_or_default()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:24: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
+ |
+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
+ |
+LL | let _val2 = val.unwrap();
+ | ^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15
+ |
+LL | let val = Ok::<_, ()>(1);
+ | ^^^^^^^^^^^^^^
+
+error: used `expect()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:31:17
+ |
+LL | let _val2 = val.expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `expect()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15
+ |
+LL | let val = Ok::<_, ()>(1);
+ | ^^^^^^^^^^^^^^
+
+error: used `unwrap_err()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:32:17
+ |
+LL | let _val2 = val.unwrap_err();
+ | ^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_err()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15
+ |
+LL | let val = Ok::<_, ()>(1);
+ | ^^^^^^^^^^^^^^
+
+error: used `expect_err()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:33: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
+ |
+LL | let val = Ok::<_, ()>(1);
+ | ^^^^^^^^^^^^^^
+
+error: used `unwrap()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:16
+ |
+LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:16
+ |
+LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `expect()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:38:16
+ |
+LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `expect()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:38:16
+ |
+LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_err()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:16
+ |
+LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_err();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_err()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:16
+ |
+LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_err();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `expect_err()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:16
+ |
+LL | let _val = Ok::<usize, ()>([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
+ |
+LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect_err("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:43:17
+ |
+LL | let _val2 = val.unwrap();
+ | ^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15
+ |
+LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `expect()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:44:17
+ |
+LL | let _val2 = val.expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `expect()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15
+ |
+LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_err()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:45:17
+ |
+LL | let _val2 = val.unwrap_err();
+ | ^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_err()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15
+ |
+LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `expect_err()` on `Ok` value
+ --> $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:42:15
+ |
+LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_err()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:51:17
+ |
+LL | let _val2 = val.unwrap_err();
+ | ^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `unwrap_err()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15
+ |
+LL | let val = Err::<(), _>(1);
+ | ^^^^^^^^^^^^^^^
+
+error: used `expect_err()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:52: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
+ |
+LL | let val = Err::<(), _>(1);
+ | ^^^^^^^^^^^^^^^
+
+error: used `unwrap()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:53:17
+ |
+LL | let _val2 = val.unwrap();
+ | ^^^^^^^^^^^^
+ |
+help: remove the `Err` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15
+ |
+LL | let val = Err::<(), _>(1);
+ | ^^^^^^^^^^^^^^^
+
+error: used `expect()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:54:17
+ |
+LL | let _val2 = val.expect("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `expect()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15
+ |
+LL | let val = Err::<(), _>(1);
+ | ^^^^^^^^^^^^^^^
+
+error: used `unwrap_err()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:58: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
+ |
+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
+ |
+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
+ |
+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
+ |
+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
+ |
+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
+ |
+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
+ |
+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
+ |
+LL | let _val2 = val.unwrap_err();
+ | ^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `unwrap_err()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63: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
+ |
+LL | let _val2 = val.expect_err("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `expect_err()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63: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
+ |
+LL | let _val2 = val.unwrap();
+ | ^^^^^^^^^^^^
+ |
+help: remove the `Err` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63: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
+ |
+LL | let _val2 = val.expect("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `expect()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:63: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
+ |
+LL | let _val2 = val.unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:15
+ |
+LL | let val = Some(1);
+ | ^^^^^^^
+
+error: used `unwrap_or_default()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:73:17
+ |
+LL | let _val2 = val.unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or_default()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:15
+ |
+LL | let val = Some(1);
+ | ^^^^^^^
+
+error: used `unwrap_or_else()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:74: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
+ |
+LL | let val = Some(1);
+ | ^^^^^^^
+
+error: used `unwrap_or()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:78:16
+ |
+LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:78:16
+ |
+LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_or_default()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:79:16
+ |
+LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or_default()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:79:16
+ |
+LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_or_else()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:80:16
+ |
+LL | let _val = Some::<usize>([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
+ |
+LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_else(|| 2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_or()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:83:17
+ |
+LL | let _val2 = val.unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:15
+ |
+LL | let val = Some::<usize>([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_or_default()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:84:17
+ |
+LL | let _val2 = val.unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or_default()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:15
+ |
+LL | let val = Some::<usize>([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_or_else()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:85: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
+ |
+LL | let val = Some::<usize>([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_or()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:90:17
+ |
+LL | let _val2 = val.unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:15
+ |
+LL | let val = Ok::<_, ()>(1);
+ | ^^^^^^^^^^^^^^
+
+error: used `unwrap_or_default()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:91:17
+ |
+LL | let _val2 = val.unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or_default()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:15
+ |
+LL | let val = Ok::<_, ()>(1);
+ | ^^^^^^^^^^^^^^
+
+error: used `unwrap_or_else()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:92: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
+ |
+LL | let val = Ok::<_, ()>(1);
+ | ^^^^^^^^^^^^^^
+
+error: used `unwrap_or()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:16
+ |
+LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:16
+ |
+LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_or_default()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:97:16
+ |
+LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or_default()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:97:16
+ |
+LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_or_else()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:16
+ |
+LL | let _val = Ok::<usize, ()>([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
+ |
+LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_or()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:101:17
+ |
+LL | let _val2 = val.unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:15
+ |
+LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_or_default()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:102:17
+ |
+LL | let _val2 = val.unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or_default()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:15
+ |
+LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_or_else()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:103: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
+ |
+LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 52 previous errors
+
diff --git a/src/tools/clippy/tests/ui/unnecessary_safety_comment.rs b/src/tools/clippy/tests/ui/unnecessary_safety_comment.rs
index 89fedb145..d858701ae 100644
--- a/src/tools/clippy/tests/ui/unnecessary_safety_comment.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_safety_comment.rs
@@ -1,5 +1,5 @@
#![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)]
-#![allow(clippy::let_unit_value, clippy::missing_safety_doc)]
+#![allow(clippy::let_unit_value, clippy::missing_safety_doc, clippy::needless_if)]
mod unsafe_items_invalid_comment {
// SAFETY:
diff --git a/src/tools/clippy/tests/ui/unnecessary_sort_by.fixed b/src/tools/clippy/tests/ui/unnecessary_sort_by.fixed
index 165cabd82..19380ad00 100644
--- a/src/tools/clippy/tests/ui/unnecessary_sort_by.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_sort_by.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
-#![allow(clippy::stable_sort_primitive)]
+#![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 8a2158d5a..cea1b65b5 100644
--- a/src/tools/clippy/tests/ui/unnecessary_sort_by.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_sort_by.rs
@@ -1,6 +1,6 @@
//@run-rustfix
-#![allow(clippy::stable_sort_primitive)]
+#![allow(clippy::stable_sort_primitive, clippy::useless_vec)]
use std::cell::Ref;
diff --git a/src/tools/clippy/tests/ui/unnecessary_struct_initialization.fixed b/src/tools/clippy/tests/ui/unnecessary_struct_initialization.fixed
index bdf746cf2..eae1271d1 100644
--- a/src/tools/clippy/tests/ui/unnecessary_struct_initialization.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_struct_initialization.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
-#![allow(unused)]
+#![allow(clippy::incorrect_clone_impl_on_copy_type, 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 7271e2f95..4abd560f8 100644
--- a/src/tools/clippy/tests/ui/unnecessary_struct_initialization.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_struct_initialization.rs
@@ -1,6 +1,6 @@
//@run-rustfix
-#![allow(unused)]
+#![allow(clippy::incorrect_clone_impl_on_copy_type, unused)]
#![warn(clippy::unnecessary_struct_initialization)]
struct S {
diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
index 08733906b..592a53f3a 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
@@ -474,3 +474,36 @@ mod issue_10021 {
Ok(())
}
}
+
+mod issue_10033 {
+ #![allow(dead_code)]
+ use std::{fmt::Display, ops::Deref};
+
+ fn _main() {
+ let f = Foo;
+
+ // Not actually unnecessary - this calls `Foo`'s `Display` impl, not `str`'s (even though `Foo` does
+ // deref to `str`)
+ foo(&f.to_string());
+ }
+
+ fn foo(s: &str) {
+ println!("{}", s);
+ }
+
+ struct Foo;
+
+ impl Deref for Foo {
+ type Target = str;
+
+ fn deref(&self) -> &Self::Target {
+ "str"
+ }
+ }
+
+ impl Display for Foo {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "Foo")
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
index e3589ea0d..f2e48b1c4 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
@@ -474,3 +474,36 @@ mod issue_10021 {
Ok(())
}
}
+
+mod issue_10033 {
+ #![allow(dead_code)]
+ use std::{fmt::Display, ops::Deref};
+
+ fn _main() {
+ let f = Foo;
+
+ // Not actually unnecessary - this calls `Foo`'s `Display` impl, not `str`'s (even though `Foo` does
+ // deref to `str`)
+ foo(&f.to_string());
+ }
+
+ fn foo(s: &str) {
+ println!("{}", s);
+ }
+
+ struct Foo;
+
+ impl Deref for Foo {
+ type Target = str;
+
+ fn deref(&self) -> &Self::Target {
+ "str"
+ }
+ }
+
+ impl Display for Foo {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "Foo")
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs b/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs
index 373b18470..2d55dc664 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
+//@aux-build:proc_macros.rs:proc-macro
#![allow(clippy::let_unit_value)]
#![warn(clippy::unnecessary_safety_doc)]
diff --git a/src/tools/clippy/tests/ui/unneeded_field_pattern.rs b/src/tools/clippy/tests/ui/unneeded_field_pattern.rs
index fa639aa70..48ae1cf66 100644
--- a/src/tools/clippy/tests/ui/unneeded_field_pattern.rs
+++ b/src/tools/clippy/tests/ui/unneeded_field_pattern.rs
@@ -1,5 +1,9 @@
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::unneeded_field_pattern)]
-#[allow(dead_code, unused)]
+#![allow(dead_code, unused)]
+
+#[macro_use]
+extern crate proc_macros;
struct Foo {
a: i32,
@@ -19,4 +23,12 @@ fn main() {
Foo { b: 0, .. } => {}, // should be OK
Foo { .. } => {}, // and the Force might be with this one
}
+ external! {
+ let f = Foo { a: 0, b: 0, c: 0 };
+ match f {
+ Foo { a: _, b: 0, .. } => {},
+
+ Foo { a: _, b: _, c: _ } => {},
+ }
+ }
}
diff --git a/src/tools/clippy/tests/ui/unneeded_field_pattern.stderr b/src/tools/clippy/tests/ui/unneeded_field_pattern.stderr
index 6f7c31545..3f1568498 100644
--- a/src/tools/clippy/tests/ui/unneeded_field_pattern.stderr
+++ b/src/tools/clippy/tests/ui/unneeded_field_pattern.stderr
@@ -1,5 +1,5 @@
error: you matched a field with a wildcard pattern, consider using `..` instead
- --> $DIR/unneeded_field_pattern.rs:14:15
+ --> $DIR/unneeded_field_pattern.rs:18:15
|
LL | Foo { a: _, b: 0, .. } => {},
| ^^^^
@@ -8,7 +8,7 @@ LL | Foo { a: _, b: 0, .. } => {},
= note: `-D clippy::unneeded-field-pattern` implied by `-D warnings`
error: all the struct fields are matched to a wildcard pattern, consider using `..`
- --> $DIR/unneeded_field_pattern.rs:16:9
+ --> $DIR/unneeded_field_pattern.rs:20:9
|
LL | Foo { a: _, b: _, c: _ } => {},
| ^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.fixed b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.fixed
index 16c2de760..2eeba509e 100644
--- a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.fixed
+++ b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.fixed
@@ -1,6 +1,11 @@
//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
#![feature(stmt_expr_attributes)]
#![deny(clippy::unneeded_wildcard_pattern)]
+#![allow(clippy::needless_if)]
+
+#[macro_use]
+extern crate proc_macros;
fn main() {
let t = (0, 1, 2, 3);
@@ -42,4 +47,8 @@ fn main() {
{
if let S(0, ..,) = s {};
}
+ external! {
+ let t = (0, 1, 2, 3);
+ if let (0, _, ..) = t {};
+ }
}
diff --git a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.rs b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.rs
index 9d9eae1d9..5416cfaa5 100644
--- a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.rs
+++ b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.rs
@@ -1,6 +1,11 @@
//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
#![feature(stmt_expr_attributes)]
#![deny(clippy::unneeded_wildcard_pattern)]
+#![allow(clippy::needless_if)]
+
+#[macro_use]
+extern crate proc_macros;
fn main() {
let t = (0, 1, 2, 3);
@@ -42,4 +47,8 @@ fn main() {
{
if let S(0, .., _, _,) = s {};
}
+ external! {
+ let t = (0, 1, 2, 3);
+ if let (0, _, ..) = t {};
+ }
}
diff --git a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.stderr b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.stderr
index 716d9ecff..ffbdc0495 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:8:18
+ --> $DIR/unneeded_wildcard_pattern.rs:13:18
|
LL | if let (0, .., _) = t {};
| ^^^ help: remove it
|
note: the lint level is defined here
- --> $DIR/unneeded_wildcard_pattern.rs:3:9
+ --> $DIR/unneeded_wildcard_pattern.rs:4:9
|
LL | #![deny(clippy::unneeded_wildcard_pattern)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this pattern is unneeded as the `..` pattern can match that element
- --> $DIR/unneeded_wildcard_pattern.rs:9:16
+ --> $DIR/unneeded_wildcard_pattern.rs:14: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:10:13
+ --> $DIR/unneeded_wildcard_pattern.rs:15: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:11:15
+ --> $DIR/unneeded_wildcard_pattern.rs:16: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:12:16
+ --> $DIR/unneeded_wildcard_pattern.rs:17: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:13:18
+ --> $DIR/unneeded_wildcard_pattern.rs:18: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:22:22
+ --> $DIR/unneeded_wildcard_pattern.rs:27: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:29:19
+ --> $DIR/unneeded_wildcard_pattern.rs:34: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:30:17
+ --> $DIR/unneeded_wildcard_pattern.rs:35: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:31:14
+ --> $DIR/unneeded_wildcard_pattern.rs:36: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:32:16
+ --> $DIR/unneeded_wildcard_pattern.rs:37: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:33:17
+ --> $DIR/unneeded_wildcard_pattern.rs:38: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:34:19
+ --> $DIR/unneeded_wildcard_pattern.rs:39: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:43:23
+ --> $DIR/unneeded_wildcard_pattern.rs:48: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 8ec35ba4e..738045595 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns.fixed
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns.fixed
@@ -2,7 +2,13 @@
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
-#![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)]
+#![allow(
+ clippy::cognitive_complexity,
+ clippy::match_ref_pats,
+ clippy::upper_case_acronyms,
+ clippy::needless_if,
+ clippy::manual_range_patterns
+)]
#![allow(unreachable_patterns, irrefutable_let_patterns, unused)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns.rs b/src/tools/clippy/tests/ui/unnested_or_patterns.rs
index efdb91b24..9e0e7b5de 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns.rs
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns.rs
@@ -2,7 +2,13 @@
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
-#![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)]
+#![allow(
+ clippy::cognitive_complexity,
+ clippy::match_ref_pats,
+ clippy::upper_case_acronyms,
+ clippy::needless_if,
+ clippy::manual_range_patterns
+)]
#![allow(unreachable_patterns, irrefutable_let_patterns, unused)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns.stderr b/src/tools/clippy/tests/ui/unnested_or_patterns.stderr
index a1f193db5..b997e4ce8 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns.stderr
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns.stderr
@@ -1,5 +1,5 @@
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:12:12
+ --> $DIR/unnested_or_patterns.rs:18:12
|
LL | if let box 0 | box 2 = Box::new(0) {}
| ^^^^^^^^^^^^^
@@ -11,7 +11,7 @@ LL | if let box (0 | 2) = Box::new(0) {}
| ~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:13:12
+ --> $DIR/unnested_or_patterns.rs:19:12
|
LL | if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {}
| ~~~~~~~~~~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:15:12
+ --> $DIR/unnested_or_patterns.rs:21:12
|
LL | if let Some(1) | C0 | Some(2) = None {}
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -33,7 +33,7 @@ LL | if let Some(1 | 2) | C0 = None {}
| ~~~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:16:12
+ --> $DIR/unnested_or_patterns.rs:22:12
|
LL | if let &mut 0 | &mut 2 = &mut 0 {}
| ^^^^^^^^^^^^^^^
@@ -44,7 +44,7 @@ LL | if let &mut (0 | 2) = &mut 0 {}
| ~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:17:12
+ --> $DIR/unnested_or_patterns.rs:23:12
|
LL | if let x @ 0 | x @ 2 = 0 {}
| ^^^^^^^^^^^^^
@@ -55,7 +55,7 @@ LL | if let x @ (0 | 2) = 0 {}
| ~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:18:12
+ --> $DIR/unnested_or_patterns.rs:24:12
|
LL | if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -66,7 +66,7 @@ LL | if let (0, 1 | 2 | 3) = (0, 0) {}
| ~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:19:12
+ --> $DIR/unnested_or_patterns.rs:25:12
|
LL | if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -77,7 +77,7 @@ LL | if let (1 | 2 | 3, 0) = (0, 0) {}
| ~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:20:12
+ --> $DIR/unnested_or_patterns.rs:26:12
|
LL | if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -88,7 +88,7 @@ LL | if let (x, ..) | (x, 1 | 2) = (0, 1) {}
| ~~~~~~~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:21:12
+ --> $DIR/unnested_or_patterns.rs:27:12
|
LL | if let [0] | [1] = [0] {}
| ^^^^^^^^^
@@ -99,7 +99,7 @@ LL | if let [0 | 1] = [0] {}
| ~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:22:12
+ --> $DIR/unnested_or_patterns.rs:28:12
|
LL | if let [x, 0] | [x, 1] = [0, 1] {}
| ^^^^^^^^^^^^^^^
@@ -110,7 +110,7 @@ LL | if let [x, 0 | 1] = [0, 1] {}
| ~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:23:12
+ --> $DIR/unnested_or_patterns.rs:29:12
|
LL | if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -121,7 +121,7 @@ LL | if let [x, 0 | 1 | 2] = [0, 1] {}
| ~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:24:12
+ --> $DIR/unnested_or_patterns.rs:30:12
|
LL | if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -132,7 +132,7 @@ LL | if let [x, ..] | [x, 1 | 2] = [0, 1] {}
| ~~~~~~~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:26:12
+ --> $DIR/unnested_or_patterns.rs:32:12
|
LL | if let TS(0, x) | TS(1, x) = TS(0, 0) {}
| ^^^^^^^^^^^^^^^^^^^
@@ -143,7 +143,7 @@ LL | if let TS(0 | 1, x) = TS(0, 0) {}
| ~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:27:12
+ --> $DIR/unnested_or_patterns.rs:33:12
|
LL | if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -154,7 +154,7 @@ LL | if let TS(1 | 2 | 3, 0) = TS(0, 0) {}
| ~~~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:28:12
+ --> $DIR/unnested_or_patterns.rs:34:12
|
LL | if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -165,7 +165,7 @@ LL | if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {}
| ~~~~~~~~~~~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:33:12
+ --> $DIR/unnested_or_patterns.rs:39:12
|
LL | if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -176,7 +176,7 @@ LL | if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {}
| ~~~~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:44:12
+ --> $DIR/unnested_or_patterns.rs:50: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 de40e9367..11dc34378 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns2.fixed
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns2.fixed
@@ -2,7 +2,12 @@
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
-#![allow(clippy::cognitive_complexity, clippy::match_ref_pats)]
+#![allow(
+ clippy::cognitive_complexity,
+ clippy::match_ref_pats,
+ clippy::needless_if,
+ clippy::manual_range_patterns
+)]
#![allow(unreachable_patterns, irrefutable_let_patterns, unused_variables)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns2.rs b/src/tools/clippy/tests/ui/unnested_or_patterns2.rs
index 87f66d26c..b25560827 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns2.rs
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns2.rs
@@ -2,7 +2,12 @@
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
-#![allow(clippy::cognitive_complexity, clippy::match_ref_pats)]
+#![allow(
+ clippy::cognitive_complexity,
+ clippy::match_ref_pats,
+ clippy::needless_if,
+ clippy::manual_range_patterns
+)]
#![allow(unreachable_patterns, irrefutable_let_patterns, unused_variables)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns2.stderr b/src/tools/clippy/tests/ui/unnested_or_patterns2.stderr
index 41e8d3fc7..76e890b3a 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns2.stderr
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns2.stderr
@@ -1,5 +1,5 @@
error: unnested or-patterns
- --> $DIR/unnested_or_patterns2.rs:9:12
+ --> $DIR/unnested_or_patterns2.rs:14:12
|
LL | if let Some(Some(0)) | Some(Some(1)) = None {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -11,7 +11,7 @@ LL | if let Some(Some(0 | 1)) = None {}
| ~~~~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns2.rs:10:12
+ --> $DIR/unnested_or_patterns2.rs:15:12
|
LL | if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {}
| ~~~~~~~~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns2.rs:11:12
+ --> $DIR/unnested_or_patterns2.rs:16:12
|
LL | if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -33,7 +33,7 @@ LL | if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {}
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns2.rs:12:12
+ --> $DIR/unnested_or_patterns2.rs:17:12
|
LL | if let Some(Some(0) | Some(1 | 2)) = None {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -44,7 +44,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {}
| ~~~~~~~~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns2.rs:13:12
+ --> $DIR/unnested_or_patterns2.rs:18:12
|
LL | if let ((0,),) | ((1,) | (2,),) = ((0,),) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -55,7 +55,7 @@ LL | if let ((0 | 1 | 2,),) = ((0,),) {}
| ~~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns2.rs:14:12
+ --> $DIR/unnested_or_patterns2.rs:19:12
|
LL | if let 0 | (1 | 2) = 0 {}
| ^^^^^^^^^^^
@@ -66,7 +66,7 @@ LL | if let 0 | 1 | 2 = 0 {}
| ~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns2.rs:15:12
+ --> $DIR/unnested_or_patterns2.rs:20:12
|
LL | if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -77,7 +77,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {}
| ~~~~~~~~~~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns2.rs:16:12
+ --> $DIR/unnested_or_patterns2.rs:21: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/unseparated_prefix_literals.fixed b/src/tools/clippy/tests/ui/unseparated_prefix_literals.fixed
index b6241612d..125120872 100644
--- a/src/tools/clippy/tests/ui/unseparated_prefix_literals.fixed
+++ b/src/tools/clippy/tests/ui/unseparated_prefix_literals.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macro_derive.rs
+//@aux-build:proc_macro_derive.rs:proc-macro
#![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 ae583f4bd..0a3ffc478 100644
--- a/src/tools/clippy/tests/ui/unseparated_prefix_literals.rs
+++ b/src/tools/clippy/tests/ui/unseparated_prefix_literals.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macro_derive.rs
+//@aux-build:proc_macro_derive.rs:proc-macro
#![warn(clippy::unseparated_literal_suffix)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/unused_async.rs b/src/tools/clippy/tests/ui/unused_async.rs
index 4ca7f29b3..69e46ab47 100644
--- a/src/tools/clippy/tests/ui/unused_async.rs
+++ b/src/tools/clippy/tests/ui/unused_async.rs
@@ -1,8 +1,42 @@
#![warn(clippy::unused_async)]
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
use std::future::Future;
use std::pin::Pin;
+mod issue10800 {
+ #![allow(dead_code, unused_must_use, clippy::no_effect)]
+
+ use std::future::ready;
+
+ async fn async_block_await() {
+ async {
+ ready(()).await;
+ };
+ }
+
+ async fn normal_block_await() {
+ {
+ {
+ ready(()).await;
+ }
+ }
+ }
+}
+
+mod issue10459 {
+ trait HasAsyncMethod {
+ async fn do_something() -> u32;
+ }
+
+ impl HasAsyncMethod for () {
+ async fn do_something() -> u32 {
+ 1
+ }
+ }
+}
+
async fn foo() -> i32 {
4
}
diff --git a/src/tools/clippy/tests/ui/unused_async.stderr b/src/tools/clippy/tests/ui/unused_async.stderr
index cff3eccbd..ffae8366b 100644
--- a/src/tools/clippy/tests/ui/unused_async.stderr
+++ b/src/tools/clippy/tests/ui/unused_async.stderr
@@ -1,5 +1,23 @@
error: unused `async` for function with no await statements
- --> $DIR/unused_async.rs:6:1
+ --> $DIR/unused_async.rs:13:5
+ |
+LL | / async fn async_block_await() {
+LL | | async {
+LL | | ready(()).await;
+LL | | };
+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
+ |
+LL | ready(()).await;
+ | ^^^^^
+ = note: `-D clippy::unused-async` implied by `-D warnings`
+
+error: unused `async` for function with no await statements
+ --> $DIR/unused_async.rs:40:1
|
LL | / async fn foo() -> i32 {
LL | | 4
@@ -7,10 +25,9 @@ LL | | }
| |_^
|
= help: consider removing the `async` from this function
- = note: `-D clippy::unused-async` implied by `-D warnings`
error: unused `async` for function with no await statements
- --> $DIR/unused_async.rs:17:5
+ --> $DIR/unused_async.rs:51:5
|
LL | / async fn unused(&self) -> i32 {
LL | | 1
@@ -19,5 +36,5 @@ LL | | }
|
= help: consider removing the `async` from this function
-error: aborting due to 2 previous errors
+error: aborting due to 3 previous errors
diff --git a/src/tools/clippy/tests/ui/unwrap.rs b/src/tools/clippy/tests/ui/unwrap.rs
index d9fd402e7..64d643783 100644
--- a/src/tools/clippy/tests/ui/unwrap.rs
+++ b/src/tools/clippy/tests/ui/unwrap.rs
@@ -1,4 +1,5 @@
#![warn(clippy::unwrap_used)]
+#![allow(clippy::unnecessary_literal_unwrap)]
fn unwrap_option() {
let opt = Some(0);
diff --git a/src/tools/clippy/tests/ui/unwrap.stderr b/src/tools/clippy/tests/ui/unwrap.stderr
index d49bf2b32..3796d942f 100644
--- a/src/tools/clippy/tests/ui/unwrap.stderr
+++ b/src/tools/clippy/tests/ui/unwrap.stderr
@@ -1,5 +1,5 @@
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap.rs:5:13
+ --> $DIR/unwrap.rs:6:13
|
LL | let _ = opt.unwrap();
| ^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | let _ = opt.unwrap();
= note: `-D clippy::unwrap-used` implied by `-D warnings`
error: used `unwrap()` on a `Result` value
- --> $DIR/unwrap.rs:10:13
+ --> $DIR/unwrap.rs:11:13
|
LL | let _ = res.unwrap();
| ^^^^^^^^^^^^
@@ -16,7 +16,7 @@ LL | let _ = res.unwrap();
= help: if you don't want to handle the `Err` case gracefully, consider using `expect()` to provide a better panic message
error: used `unwrap_err()` on a `Result` value
- --> $DIR/unwrap.rs:11:13
+ --> $DIR/unwrap.rs:12: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 9f27fef82..7f57efc53 100644
--- a/src/tools/clippy/tests/ui/unwrap_expect_used.rs
+++ b/src/tools/clippy/tests/ui/unwrap_expect_used.rs
@@ -1,4 +1,5 @@
#![warn(clippy::unwrap_used, clippy::expect_used)]
+#![allow(clippy::unnecessary_literal_unwrap)]
trait OptionExt {
type Item;
diff --git a/src/tools/clippy/tests/ui/unwrap_expect_used.stderr b/src/tools/clippy/tests/ui/unwrap_expect_used.stderr
index fe4ecef11..1a551ab5a 100644
--- a/src/tools/clippy/tests/ui/unwrap_expect_used.stderr
+++ b/src/tools/clippy/tests/ui/unwrap_expect_used.stderr
@@ -1,5 +1,5 @@
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_expect_used.rs:23:5
+ --> $DIR/unwrap_expect_used.rs:24:5
|
LL | Some(3).unwrap();
| ^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | Some(3).unwrap();
= note: `-D clippy::unwrap-used` implied by `-D warnings`
error: used `expect()` on an `Option` value
- --> $DIR/unwrap_expect_used.rs:24:5
+ --> $DIR/unwrap_expect_used.rs:25:5
|
LL | Some(3).expect("Hello world!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -17,7 +17,7 @@ LL | Some(3).expect("Hello world!");
= note: `-D clippy::expect-used` implied by `-D warnings`
error: used `unwrap()` on a `Result` value
- --> $DIR/unwrap_expect_used.rs:31:5
+ --> $DIR/unwrap_expect_used.rs:32:5
|
LL | a.unwrap();
| ^^^^^^^^^^
@@ -25,7 +25,7 @@ LL | a.unwrap();
= help: if this value is an `Err`, it will panic
error: used `expect()` on a `Result` value
- --> $DIR/unwrap_expect_used.rs:32:5
+ --> $DIR/unwrap_expect_used.rs:33:5
|
LL | a.expect("Hello world!");
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -33,7 +33,7 @@ LL | a.expect("Hello world!");
= help: if this value is an `Err`, it will panic
error: used `unwrap_err()` on a `Result` value
- --> $DIR/unwrap_expect_used.rs:33:5
+ --> $DIR/unwrap_expect_used.rs:34:5
|
LL | a.unwrap_err();
| ^^^^^^^^^^^^^^
@@ -41,7 +41,7 @@ LL | a.unwrap_err();
= help: if this value is an `Ok`, it will panic
error: used `expect_err()` on a `Result` value
- --> $DIR/unwrap_expect_used.rs:34:5
+ --> $DIR/unwrap_expect_used.rs:35:5
|
LL | a.expect_err("Hello error!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/unwrap_or.rs b/src/tools/clippy/tests/ui/unwrap_or.rs
index a0c003f5b..5bea85e66 100644
--- a/src/tools/clippy/tests/ui/unwrap_or.rs
+++ b/src/tools/clippy/tests/ui/unwrap_or.rs
@@ -1,4 +1,5 @@
#![warn(clippy::all, clippy::or_fun_call)]
+#![allow(clippy::unnecessary_literal_unwrap)]
fn main() {
let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len();
diff --git a/src/tools/clippy/tests/ui/unwrap_or.stderr b/src/tools/clippy/tests/ui/unwrap_or.stderr
index c3a7464fd..cf720eaaf 100644
--- a/src/tools/clippy/tests/ui/unwrap_or.stderr
+++ b/src/tools/clippy/tests/ui/unwrap_or.stderr
@@ -1,5 +1,5 @@
error: use of `unwrap_or` followed by a function call
- --> $DIR/unwrap_or.rs:4:47
+ --> $DIR/unwrap_or.rs:5:47
|
LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| "Fail".to_string())`
@@ -7,7 +7,7 @@ LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string())
= note: `-D clippy::or-fun-call` implied by `-D warnings`
error: use of `unwrap_or` followed by a function call
- --> $DIR/unwrap_or.rs:8:47
+ --> $DIR/unwrap_or.rs:9:47
|
LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `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 59a0ca3f1..08b89a18b 100644
--- a/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed
+++ b/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed
@@ -2,7 +2,7 @@
#![warn(clippy::unwrap_or_else_default)]
#![allow(dead_code)]
-#![allow(clippy::unnecessary_wraps)]
+#![allow(clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)]
/// Checks implementation of the `UNWRAP_OR_ELSE_DEFAULT` lint.
fn unwrap_or_else_default() {
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 97cafa336..ad2a74490 100644
--- a/src/tools/clippy/tests/ui/unwrap_or_else_default.rs
+++ b/src/tools/clippy/tests/ui/unwrap_or_else_default.rs
@@ -2,7 +2,7 @@
#![warn(clippy::unwrap_or_else_default)]
#![allow(dead_code)]
-#![allow(clippy::unnecessary_wraps)]
+#![allow(clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)]
/// Checks implementation of the `UNWRAP_OR_ELSE_DEFAULT` lint.
fn unwrap_or_else_default() {
diff --git a/src/tools/clippy/tests/ui/update-all-references.sh b/src/tools/clippy/tests/ui/update-all-references.sh
index 4391499a1..d42043070 100755
--- a/src/tools/clippy/tests/ui/update-all-references.sh
+++ b/src/tools/clippy/tests/ui/update-all-references.sh
@@ -1,3 +1,3 @@
#!/bin/bash
-echo "Please use 'cargo dev bless' instead."
+echo "Please use 'cargo bless' instead."
diff --git a/src/tools/clippy/tests/ui/use_self.fixed b/src/tools/clippy/tests/ui/use_self.fixed
index 89ea14759..4179f21c5 100644
--- a/src/tools/clippy/tests/ui/use_self.fixed
+++ b/src/tools/clippy/tests/ui/use_self.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macro_derive.rs
+//@aux-build:proc_macro_derive.rs:proc-macro
#![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 49e5bcb7e..01a36def9 100644
--- a/src/tools/clippy/tests/ui/use_self.rs
+++ b/src/tools/clippy/tests/ui/use_self.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macro_derive.rs
+//@aux-build:proc_macro_derive.rs:proc-macro
#![warn(clippy::use_self)]
#![allow(dead_code, unreachable_code)]
diff --git a/src/tools/clippy/tests/ui/used_underscore_binding.rs b/src/tools/clippy/tests/ui/used_underscore_binding.rs
index c672eff1c..879e2e24a 100644
--- a/src/tools/clippy/tests/ui/used_underscore_binding.rs
+++ b/src/tools/clippy/tests/ui/used_underscore_binding.rs
@@ -1,4 +1,4 @@
-//@aux-build:proc_macro_derive.rs
+//@aux-build:proc_macro_derive.rs:proc-macro
#![feature(rustc_private)]
#![warn(clippy::all)]
#![warn(clippy::used_underscore_binding)]
diff --git a/src/tools/clippy/tests/ui/useless_attribute.fixed b/src/tools/clippy/tests/ui/useless_attribute.fixed
index de6660c95..8e77ec444 100644
--- a/src/tools/clippy/tests/ui/useless_attribute.fixed
+++ b/src/tools/clippy/tests/ui/useless_attribute.fixed
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macro_derive.rs
+//@aux-build:proc_macro_derive.rs:proc-macro
#![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 8de4331e8..27498d9bc 100644
--- a/src/tools/clippy/tests/ui/useless_attribute.rs
+++ b/src/tools/clippy/tests/ui/useless_attribute.rs
@@ -1,5 +1,5 @@
//@run-rustfix
-//@aux-build:proc_macro_derive.rs
+//@aux-build:proc_macro_derive.rs:proc-macro
#![allow(unused)]
#![warn(clippy::useless_attribute)]
diff --git a/src/tools/clippy/tests/ui/useless_conversion.fixed b/src/tools/clippy/tests/ui/useless_conversion.fixed
index c16caa38f..53d8a5a9f 100644
--- a/src/tools/clippy/tests/ui/useless_conversion.fixed
+++ b/src/tools/clippy/tests/ui/useless_conversion.fixed
@@ -1,7 +1,7 @@
//@run-rustfix
#![deny(clippy::useless_conversion)]
-#![allow(clippy::unnecessary_wraps)]
+#![allow(clippy::needless_if, clippy::unnecessary_wraps)]
fn test_generic<T: Copy>(val: T) -> T {
let _ = val;
@@ -155,6 +155,49 @@ fn main() {
let _ = vec![s4, s4, s4].into_iter();
}
+#[allow(dead_code)]
+fn issue11065_fp() {
+ use std::option::IntoIter;
+ fn takes_into_iter(_: impl IntoIterator<Item = i32>) {}
+
+ macro_rules! x {
+ ($e:expr) => {
+ takes_into_iter($e);
+ let _: IntoIter<i32> = $e; // removing `.into_iter()` leads to a type error here
+ };
+ }
+ x!(Some(5).into_iter());
+}
+
+#[allow(dead_code)]
+fn explicit_into_iter_fn_arg() {
+ fn a<T>(_: T) {}
+ fn b<T: IntoIterator<Item = i32>>(_: T) {}
+ fn c(_: impl IntoIterator<Item = i32>) {}
+ fn d<T>(_: T)
+ where
+ T: IntoIterator<Item = i32>,
+ {
+ }
+ fn f(_: std::vec::IntoIter<i32>) {}
+
+ a(vec![1, 2].into_iter());
+ b(vec![1, 2]);
+ c(vec![1, 2]);
+ d(vec![1, 2]);
+ b([&1, &2, &3].into_iter().cloned());
+
+ b(vec![1, 2]);
+ b(vec![1, 2]);
+
+ macro_rules! macro_generated {
+ () => {
+ vec![1, 2].into_iter()
+ };
+ }
+ b(macro_generated!());
+}
+
#[derive(Copy, Clone)]
struct Foo<const C: char>;
diff --git a/src/tools/clippy/tests/ui/useless_conversion.rs b/src/tools/clippy/tests/ui/useless_conversion.rs
index c75a2bce4..51ba49873 100644
--- a/src/tools/clippy/tests/ui/useless_conversion.rs
+++ b/src/tools/clippy/tests/ui/useless_conversion.rs
@@ -1,7 +1,7 @@
//@run-rustfix
#![deny(clippy::useless_conversion)]
-#![allow(clippy::unnecessary_wraps)]
+#![allow(clippy::needless_if, clippy::unnecessary_wraps)]
fn test_generic<T: Copy>(val: T) -> T {
let _ = T::from(val);
@@ -155,6 +155,49 @@ fn main() {
let _ = vec![s4, s4, s4].into_iter().into_iter();
}
+#[allow(dead_code)]
+fn issue11065_fp() {
+ use std::option::IntoIter;
+ fn takes_into_iter(_: impl IntoIterator<Item = i32>) {}
+
+ macro_rules! x {
+ ($e:expr) => {
+ takes_into_iter($e);
+ let _: IntoIter<i32> = $e; // removing `.into_iter()` leads to a type error here
+ };
+ }
+ x!(Some(5).into_iter());
+}
+
+#[allow(dead_code)]
+fn explicit_into_iter_fn_arg() {
+ fn a<T>(_: T) {}
+ fn b<T: IntoIterator<Item = i32>>(_: T) {}
+ fn c(_: impl IntoIterator<Item = i32>) {}
+ fn d<T>(_: T)
+ where
+ T: IntoIterator<Item = i32>,
+ {
+ }
+ fn f(_: std::vec::IntoIter<i32>) {}
+
+ a(vec![1, 2].into_iter());
+ b(vec![1, 2].into_iter());
+ c(vec![1, 2].into_iter());
+ d(vec![1, 2].into_iter());
+ b([&1, &2, &3].into_iter().cloned());
+
+ b(vec![1, 2].into_iter().into_iter());
+ b(vec![1, 2].into_iter().into_iter().into_iter());
+
+ macro_rules! macro_generated {
+ () => {
+ vec![1, 2].into_iter()
+ };
+ }
+ b(macro_generated!());
+}
+
#[derive(Copy, Clone)]
struct Foo<const C: char>;
diff --git a/src/tools/clippy/tests/ui/useless_conversion.stderr b/src/tools/clippy/tests/ui/useless_conversion.stderr
index 4dca3aac5..6f7dc01d2 100644
--- a/src/tools/clippy/tests/ui/useless_conversion.stderr
+++ b/src/tools/clippy/tests/ui/useless_conversion.stderr
@@ -118,5 +118,65 @@ error: useless conversion to the same type: `std::vec::IntoIter<Foo<'a'>>`
LL | let _ = vec![s4, s4, s4].into_iter().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![s4, s4, s4].into_iter()`
-error: aborting due to 19 previous errors
+error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
+ --> $DIR/useless_conversion.rs:185:7
+ |
+LL | b(vec![1, 2].into_iter());
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]`
+ |
+note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
+ --> $DIR/useless_conversion.rs:175:13
+ |
+LL | fn b<T: IntoIterator<Item = i32>>(_: T) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
+ --> $DIR/useless_conversion.rs:186:7
+ |
+LL | c(vec![1, 2].into_iter());
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]`
+ |
+note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
+ --> $DIR/useless_conversion.rs:176:18
+ |
+LL | fn c(_: impl IntoIterator<Item = i32>) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
+ --> $DIR/useless_conversion.rs:187:7
+ |
+LL | d(vec![1, 2].into_iter());
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]`
+ |
+note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
+ --> $DIR/useless_conversion.rs:179:12
+ |
+LL | T: IntoIterator<Item = i32>,
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
+ --> $DIR/useless_conversion.rs:190:7
+ |
+LL | b(vec![1, 2].into_iter().into_iter());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]`
+ |
+note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
+ --> $DIR/useless_conversion.rs:175:13
+ |
+LL | fn b<T: IntoIterator<Item = i32>>(_: T) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
+ --> $DIR/useless_conversion.rs:191:7
+ |
+LL | b(vec![1, 2].into_iter().into_iter().into_iter());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]`
+ |
+note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
+ --> $DIR/useless_conversion.rs:175:13
+ |
+LL | fn b<T: IntoIterator<Item = i32>>(_: T) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 24 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 4acf5b5fa..ec0512ce2 100644
--- a/src/tools/clippy/tests/ui/useless_conversion_try.rs
+++ b/src/tools/clippy/tests/ui/useless_conversion_try.rs
@@ -1,4 +1,5 @@
#![deny(clippy::useless_conversion)]
+#![allow(clippy::needless_if)]
fn test_generic<T: Copy>(val: T) -> T {
let _ = T::try_from(val).unwrap();
diff --git a/src/tools/clippy/tests/ui/useless_conversion_try.stderr b/src/tools/clippy/tests/ui/useless_conversion_try.stderr
index 9aef9dda6..54189f8d2 100644
--- a/src/tools/clippy/tests/ui/useless_conversion_try.stderr
+++ b/src/tools/clippy/tests/ui/useless_conversion_try.stderr
@@ -1,5 +1,5 @@
error: useless conversion to the same type: `T`
- --> $DIR/useless_conversion_try.rs:4:13
+ --> $DIR/useless_conversion_try.rs:5:13
|
LL | let _ = T::try_from(val).unwrap();
| ^^^^^^^^^^^^^^^^
@@ -12,7 +12,7 @@ LL | #![deny(clippy::useless_conversion)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: useless conversion to the same type: `T`
- --> $DIR/useless_conversion_try.rs:5:5
+ --> $DIR/useless_conversion_try.rs:6: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:27:21
+ --> $DIR/useless_conversion_try.rs:28: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:28:21
+ --> $DIR/useless_conversion_try.rs:29: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:29:13
+ --> $DIR/useless_conversion_try.rs:30: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:30:13
+ --> $DIR/useless_conversion_try.rs:31: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:31:21
+ --> $DIR/useless_conversion_try.rs:32: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:32:21
+ --> $DIR/useless_conversion_try.rs:33: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:33:27
+ --> $DIR/useless_conversion_try.rs:34: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 d77a4dd8e..fcdc917c1 100644
--- a/src/tools/clippy/tests/ui/vec.fixed
+++ b/src/tools/clippy/tests/ui/vec.fixed
@@ -1,9 +1,12 @@
//@run-rustfix
#![warn(clippy::useless_vec)]
-#![allow(clippy::nonstandard_macro_braces, clippy::uninlined_format_args)]
+#![allow(clippy::nonstandard_macro_braces, clippy::uninlined_format_args, unused)]
-#[derive(Debug)]
-struct NonCopy;
+use std::rc::Rc;
+
+struct StructWithVec {
+ _x: Vec<i32>,
+}
fn on_slice(_: &[u8]) {}
@@ -60,14 +63,6 @@ fn main() {
on_mut_slice(&mut vec![2; line.length]);
on_mut_slice(&mut vec![2; line.length()]);
- for a in &[1, 2, 3] {
- println!("{:?}", a);
- }
-
- for a in vec![NonCopy, NonCopy] {
- println!("{:?}", a);
- }
-
on_vec(&vec![1; 201]); // Ok, size of `vec` higher than `too_large_for_stack`
on_mut_vec(&mut vec![1; 201]); // Ok, size of `vec` higher than `too_large_for_stack`
@@ -75,4 +70,69 @@ fn main() {
for a in vec![1; 201] {
println!("{:?}", a);
}
+
+ // https://github.com/rust-lang/rust-clippy/issues/2262#issuecomment-783979246
+ let _x: i32 = [1, 2, 3].iter().sum();
+
+ // Do lint
+ let mut x = [1, 2, 3];
+ x.fill(123);
+ dbg!(x[0]);
+ dbg!(x.len());
+ dbg!(x.iter().sum::<i32>());
+
+ let _x: &[i32] = &[1, 2, 3];
+
+ for _ in [1, 2, 3] {}
+
+ // Don't lint
+ let x = vec![1, 2, 3];
+ let _v: Vec<i32> = x;
+
+ let x = vec![1, 2, 3];
+ let _s = StructWithVec { _x: x };
+
+ // Explicit type annotation would make the change to [1, 2, 3]
+ // a compile error.
+ let _x: Vec<i32> = vec![1, 2, 3];
+
+ // Calling a Vec method through a mutable reference
+ let mut x = vec![1, 2, 3];
+ let re = &mut x;
+ re.push(4);
+
+ // Comparing arrays whose length is not equal is a compile error
+ let x = vec![1, 2, 3];
+ let y = vec![1, 2, 3, 4];
+ dbg!(x == y);
+
+ // Non-copy types
+ let _x = vec![String::new(); 10];
+ #[allow(clippy::rc_clone_in_vec_init)]
+ let _x = vec![Rc::new(1); 10];
+
+ // Too large
+ let _x = vec![1; 201];
+}
+
+#[clippy::msrv = "1.53"]
+fn above() {
+ for a in [1, 2, 3] {
+ let _: usize = a;
+ }
+
+ for a in [String::new(), String::new()] {
+ let _: String = a;
+ }
+}
+
+#[clippy::msrv = "1.52"]
+fn below() {
+ for a in vec![1, 2, 3] {
+ let _: usize = a;
+ }
+
+ for a in vec![String::new(), String::new()] {
+ let _: String = a;
+ }
}
diff --git a/src/tools/clippy/tests/ui/vec.rs b/src/tools/clippy/tests/ui/vec.rs
index dfed3a29a..0404d8cdb 100644
--- a/src/tools/clippy/tests/ui/vec.rs
+++ b/src/tools/clippy/tests/ui/vec.rs
@@ -1,9 +1,12 @@
//@run-rustfix
#![warn(clippy::useless_vec)]
-#![allow(clippy::nonstandard_macro_braces, clippy::uninlined_format_args)]
+#![allow(clippy::nonstandard_macro_braces, clippy::uninlined_format_args, unused)]
-#[derive(Debug)]
-struct NonCopy;
+use std::rc::Rc;
+
+struct StructWithVec {
+ _x: Vec<i32>,
+}
fn on_slice(_: &[u8]) {}
@@ -60,14 +63,6 @@ fn main() {
on_mut_slice(&mut vec![2; line.length]);
on_mut_slice(&mut vec![2; line.length()]);
- for a in vec![1, 2, 3] {
- println!("{:?}", a);
- }
-
- for a in vec![NonCopy, NonCopy] {
- println!("{:?}", a);
- }
-
on_vec(&vec![1; 201]); // Ok, size of `vec` higher than `too_large_for_stack`
on_mut_vec(&mut vec![1; 201]); // Ok, size of `vec` higher than `too_large_for_stack`
@@ -75,4 +70,69 @@ fn main() {
for a in vec![1; 201] {
println!("{:?}", a);
}
+
+ // https://github.com/rust-lang/rust-clippy/issues/2262#issuecomment-783979246
+ let _x: i32 = vec![1, 2, 3].iter().sum();
+
+ // Do lint
+ let mut x = vec![1, 2, 3];
+ x.fill(123);
+ dbg!(x[0]);
+ dbg!(x.len());
+ dbg!(x.iter().sum::<i32>());
+
+ let _x: &[i32] = &vec![1, 2, 3];
+
+ for _ in vec![1, 2, 3] {}
+
+ // Don't lint
+ let x = vec![1, 2, 3];
+ let _v: Vec<i32> = x;
+
+ let x = vec![1, 2, 3];
+ let _s = StructWithVec { _x: x };
+
+ // Explicit type annotation would make the change to [1, 2, 3]
+ // a compile error.
+ let _x: Vec<i32> = vec![1, 2, 3];
+
+ // Calling a Vec method through a mutable reference
+ let mut x = vec![1, 2, 3];
+ let re = &mut x;
+ re.push(4);
+
+ // Comparing arrays whose length is not equal is a compile error
+ let x = vec![1, 2, 3];
+ let y = vec![1, 2, 3, 4];
+ dbg!(x == y);
+
+ // Non-copy types
+ let _x = vec![String::new(); 10];
+ #[allow(clippy::rc_clone_in_vec_init)]
+ let _x = vec![Rc::new(1); 10];
+
+ // Too large
+ let _x = vec![1; 201];
+}
+
+#[clippy::msrv = "1.53"]
+fn above() {
+ for a in vec![1, 2, 3] {
+ let _: usize = a;
+ }
+
+ for a in vec![String::new(), String::new()] {
+ let _: String = a;
+ }
+}
+
+#[clippy::msrv = "1.52"]
+fn below() {
+ for a in vec![1, 2, 3] {
+ let _: usize = a;
+ }
+
+ for a in vec![String::new(), String::new()] {
+ let _: String = a;
+ }
}
diff --git a/src/tools/clippy/tests/ui/vec.stderr b/src/tools/clippy/tests/ui/vec.stderr
index 7d1de05a5..33d565b2d 100644
--- a/src/tools/clippy/tests/ui/vec.stderr
+++ b/src/tools/clippy/tests/ui/vec.stderr
@@ -1,5 +1,5 @@
error: useless use of `vec!`
- --> $DIR/vec.rs:28:14
+ --> $DIR/vec.rs:31:14
|
LL | on_slice(&vec![]);
| ^^^^^^^ help: you can use a slice directly: `&[]`
@@ -7,64 +7,94 @@ LL | on_slice(&vec![]);
= note: `-D clippy::useless-vec` implied by `-D warnings`
error: useless use of `vec!`
- --> $DIR/vec.rs:30:18
+ --> $DIR/vec.rs:33:18
|
LL | on_mut_slice(&mut vec![]);
| ^^^^^^^^^^^ help: you can use a slice directly: `&mut []`
error: useless use of `vec!`
- --> $DIR/vec.rs:32:14
+ --> $DIR/vec.rs:35:14
|
LL | on_slice(&vec![1, 2]);
| ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]`
error: useless use of `vec!`
- --> $DIR/vec.rs:34:18
+ --> $DIR/vec.rs:37: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:36:14
+ --> $DIR/vec.rs:39:14
|
LL | on_slice(&vec![1, 2]);
| ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]`
error: useless use of `vec!`
- --> $DIR/vec.rs:38:18
+ --> $DIR/vec.rs:41: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:40:14
+ --> $DIR/vec.rs:43:14
|
LL | on_slice(&vec!(1, 2));
| ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]`
error: useless use of `vec!`
- --> $DIR/vec.rs:42:18
+ --> $DIR/vec.rs:45: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:44:14
+ --> $DIR/vec.rs:47:14
|
LL | on_slice(&vec![1; 2]);
| ^^^^^^^^^^^ help: you can use a slice directly: `&[1; 2]`
error: useless use of `vec!`
- --> $DIR/vec.rs:46:18
+ --> $DIR/vec.rs:49: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:63:14
+ --> $DIR/vec.rs:75: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
+ |
+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
+ |
+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
+ |
+LL | for _ in vec![1, 2, 3] {}
+ | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]`
+
+error: useless use of `vec!`
+ --> $DIR/vec.rs:120:14
|
LL | for a in vec![1, 2, 3] {
- | ^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2, 3]`
+ | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]`
+
+error: useless use of `vec!`
+ --> $DIR/vec.rs:124:14
+ |
+LL | for a in vec![String::new(), String::new()] {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]`
-error: aborting due to 11 previous errors
+error: aborting due to 16 previous errors
diff --git a/src/tools/clippy/tests/ui/vtable_address_comparisons.rs b/src/tools/clippy/tests/ui/vtable_address_comparisons.rs
index a9a4a0f5a..99c3f468f 100644
--- a/src/tools/clippy/tests/ui/vtable_address_comparisons.rs
+++ b/src/tools/clippy/tests/ui/vtable_address_comparisons.rs
@@ -23,12 +23,6 @@ fn main() {
let b = &1 as &dyn Debug;
ptr::eq(a, b);
- let a: Rc<dyn Debug> = Rc::new(1);
- Rc::ptr_eq(&a, &a);
-
- let a: Arc<dyn Debug> = Arc::new(1);
- Arc::ptr_eq(&a, &a);
-
// These should be fine:
let a = &1;
ptr::eq(a, a);
@@ -39,6 +33,12 @@ fn main() {
let a = Arc::new(1);
Arc::ptr_eq(&a, &a);
+ let a: Rc<dyn Debug> = Rc::new(1);
+ Rc::ptr_eq(&a, &a);
+
+ let a: Arc<dyn Debug> = Arc::new(1);
+ Arc::ptr_eq(&a, &a);
+
let a: &[u8] = b"";
ptr::eq(a, a);
}
diff --git a/src/tools/clippy/tests/ui/vtable_address_comparisons.stderr b/src/tools/clippy/tests/ui/vtable_address_comparisons.stderr
index 14748f583..7b866d274 100644
--- a/src/tools/clippy/tests/ui/vtable_address_comparisons.stderr
+++ b/src/tools/clippy/tests/ui/vtable_address_comparisons.stderr
@@ -63,21 +63,5 @@ 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:27:5
- |
-LL | Rc::ptr_eq(&a, &a);
- | ^^^^^^^^^^^^^^^^^^
- |
- = help: consider extracting and comparing data pointers only
-
-error: comparing trait object pointers compares a non-unique vtable address
- --> $DIR/vtable_address_comparisons.rs:30:5
- |
-LL | Arc::ptr_eq(&a, &a);
- | ^^^^^^^^^^^^^^^^^^^
- |
- = help: consider extracting and comparing data pointers only
-
-error: aborting due to 10 previous errors
+error: aborting due to 8 previous errors
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 c2f216a89..41a380ab8 100644
--- a/src/tools/clippy/tests/ui/while_let_on_iterator.fixed
+++ b/src/tools/clippy/tests/ui/while_let_on_iterator.fixed
@@ -6,7 +6,9 @@
clippy::manual_find,
clippy::never_loop,
clippy::redundant_closure_call,
- clippy::uninlined_format_args
+ clippy::single_range_in_vec_init,
+ clippy::uninlined_format_args,
+ clippy::useless_vec
)]
fn base() {
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 971bd5f0c..4c6433880 100644
--- a/src/tools/clippy/tests/ui/while_let_on_iterator.rs
+++ b/src/tools/clippy/tests/ui/while_let_on_iterator.rs
@@ -6,7 +6,9 @@
clippy::manual_find,
clippy::never_loop,
clippy::redundant_closure_call,
- clippy::uninlined_format_args
+ clippy::single_range_in_vec_init,
+ clippy::uninlined_format_args,
+ clippy::useless_vec
)]
fn base() {
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 4d9866619..3236765e1 100644
--- a/src/tools/clippy/tests/ui/while_let_on_iterator.stderr
+++ b/src/tools/clippy/tests/ui/while_let_on_iterator.stderr
@@ -1,5 +1,5 @@
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:14:5
+ --> $DIR/while_let_on_iterator.rs:16:5
|
LL | while let Option::Some(x) = iter.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter`
@@ -7,151 +7,151 @@ LL | while let Option::Some(x) = iter.next() {
= note: `-D clippy::while-let-on-iterator` implied by `-D warnings`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:19:5
+ --> $DIR/while_let_on_iterator.rs:21: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:24:5
+ --> $DIR/while_let_on_iterator.rs:26: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:100:9
+ --> $DIR/while_let_on_iterator.rs:102: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:107:9
+ --> $DIR/while_let_on_iterator.rs:109: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:120:9
+ --> $DIR/while_let_on_iterator.rs:122: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:140:9
+ --> $DIR/while_let_on_iterator.rs:142: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:197:9
+ --> $DIR/while_let_on_iterator.rs:199: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:208:5
+ --> $DIR/while_let_on_iterator.rs:210: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:210:9
+ --> $DIR/while_let_on_iterator.rs:212: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:219:9
+ --> $DIR/while_let_on_iterator.rs:221: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:228:9
+ --> $DIR/while_let_on_iterator.rs:230: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:245:9
+ --> $DIR/while_let_on_iterator.rs:247: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:260:13
+ --> $DIR/while_let_on_iterator.rs:262: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:292:13
+ --> $DIR/while_let_on_iterator.rs:294: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:321:5
+ --> $DIR/while_let_on_iterator.rs:323: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:333:9
+ --> $DIR/while_let_on_iterator.rs:335: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:347:5
+ --> $DIR/while_let_on_iterator.rs:349: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:358:5
+ --> $DIR/while_let_on_iterator.rs:360: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:393:5
+ --> $DIR/while_let_on_iterator.rs:395: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:400:5
+ --> $DIR/while_let_on_iterator.rs:402: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:408:9
+ --> $DIR/while_let_on_iterator.rs:410: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:418:9
+ --> $DIR/while_let_on_iterator.rs:420: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:428:9
+ --> $DIR/while_let_on_iterator.rs:430:9
|
LL | while let Some(x) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it.by_ref()`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:438:9
+ --> $DIR/while_let_on_iterator.rs:440: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:448:5
+ --> $DIR/while_let_on_iterator.rs:450:5
|
LL | while let Some(..) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in it`
diff --git a/src/tools/clippy/tests/ui/wildcard_imports.fixed b/src/tools/clippy/tests/ui/wildcard_imports.fixed
index bd845361f..2961b062e 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports.fixed
+++ b/src/tools/clippy/tests/ui/wildcard_imports.fixed
@@ -24,6 +24,7 @@ use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
use wildcard_imports_helper::{ExternA, extern_foo};
use std::io::prelude::*;
+use wildcard_imports_helper::extern_prelude::v1::*;
use wildcard_imports_helper::prelude::v1::*;
struct ReadFoo;
@@ -81,6 +82,7 @@ fn main() {
let _ = inner_struct_mod::C;
let _ = ExternA;
let _ = PreludeModAnywhere;
+ let _ = ExternPreludeModAnywhere;
double_struct_import_test!();
double_struct_import_test!();
@@ -209,7 +211,7 @@ mod super_imports {
}
mod use_explicit_should_be_replaced {
- use super_imports::foofoo;
+ use crate::super_imports::foofoo;
fn with_explicit() {
let _ = foofoo();
diff --git a/src/tools/clippy/tests/ui/wildcard_imports.rs b/src/tools/clippy/tests/ui/wildcard_imports.rs
index fb51f7bdf..28508a253 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports.rs
+++ b/src/tools/clippy/tests/ui/wildcard_imports.rs
@@ -24,6 +24,7 @@ use wildcard_imports_helper::inner::inner_for_self_import::*;
use wildcard_imports_helper::*;
use std::io::prelude::*;
+use wildcard_imports_helper::extern_prelude::v1::*;
use wildcard_imports_helper::prelude::v1::*;
struct ReadFoo;
@@ -81,6 +82,7 @@ fn main() {
let _ = inner_struct_mod::C;
let _ = ExternA;
let _ = PreludeModAnywhere;
+ let _ = ExternPreludeModAnywhere;
double_struct_import_test!();
double_struct_import_test!();
@@ -210,7 +212,7 @@ mod super_imports {
}
mod use_explicit_should_be_replaced {
- use super_imports::*;
+ use crate::super_imports::*;
fn with_explicit() {
let _ = foofoo();
diff --git a/src/tools/clippy/tests/ui/wildcard_imports.stderr b/src/tools/clippy/tests/ui/wildcard_imports.stderr
index 6b469cdfc..c96b3041a 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports.stderr
+++ b/src/tools/clippy/tests/ui/wildcard_imports.stderr
@@ -37,55 +37,55 @@ LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:95:13
+ --> $DIR/wildcard_imports.rs:97:13
|
LL | use crate::fn_mod::*;
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:101:75
+ --> $DIR/wildcard_imports.rs:103:75
|
LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
| ^ help: try: `inner_extern_foo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:102:13
+ --> $DIR/wildcard_imports.rs:104:13
|
LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:113:20
+ --> $DIR/wildcard_imports.rs:115:20
|
LL | use self::{inner::*, inner2::*};
| ^^^^^^^^ help: try: `inner::inner_foo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:113:30
+ --> $DIR/wildcard_imports.rs:115:30
|
LL | use self::{inner::*, inner2::*};
| ^^^^^^^^^ help: try: `inner2::inner_bar`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:120:13
+ --> $DIR/wildcard_imports.rs:122:13
|
LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:149:9
+ --> $DIR/wildcard_imports.rs:151:9
|
LL | use crate::in_fn_test::*;
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:158:9
+ --> $DIR/wildcard_imports.rs:160:9
|
LL | use crate:: in_fn_test:: * ;
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:159:9
+ --> $DIR/wildcard_imports.rs:161:9
|
LL | use crate:: fn_mod::
| _________^
@@ -93,37 +93,37 @@ LL | | *;
| |_________^ help: try: `crate:: fn_mod::foo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:170:13
+ --> $DIR/wildcard_imports.rs:172:13
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:205:17
+ --> $DIR/wildcard_imports.rs:207:17
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::insidefoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:213:13
+ --> $DIR/wildcard_imports.rs:215:13
|
-LL | use super_imports::*;
- | ^^^^^^^^^^^^^^^^ help: try: `super_imports::foofoo`
+LL | use crate::super_imports::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:222:17
+ --> $DIR/wildcard_imports.rs:224:17
|
LL | use super::super::*;
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:231:13
+ --> $DIR/wildcard_imports.rs:233:13
|
LL | use super::super::super_imports::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:239:13
+ --> $DIR/wildcard_imports.rs:241:13
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::foofoo`
diff --git a/src/tools/clippy/tests/ui/write_literal_2.rs b/src/tools/clippy/tests/ui/write_literal_2.rs
index 55a11daa1..805127e27 100644
--- a/src/tools/clippy/tests/ui/write_literal_2.rs
+++ b/src/tools/clippy/tests/ui/write_literal_2.rs
@@ -1,5 +1,5 @@
#![allow(unused_must_use)]
-#![warn(clippy::write_literal)]
+#![warn(clippy::needless_raw_strings, clippy::write_literal)]
use std::io::Write;
diff --git a/src/tools/clippy/tests/ui/write_literal_2.stderr b/src/tools/clippy/tests/ui/write_literal_2.stderr
index d5956db9f..18591250a 100644
--- a/src/tools/clippy/tests/ui/write_literal_2.stderr
+++ b/src/tools/clippy/tests/ui/write_literal_2.stderr
@@ -1,3 +1,11 @@
+error: unnecessary raw string literal
+ --> $DIR/write_literal_2.rs:10:24
+ |
+LL | writeln!(v, r"{}", r"{hello}");
+ | ^^^^^^^^^^ help: try: `"{hello}"`
+ |
+ = note: `-D clippy::needless-raw-strings` implied by `-D warnings`
+
error: literal with an empty format string
--> $DIR/write_literal_2.rs:9:23
|
@@ -87,7 +95,7 @@ LL | "1", "2", "3",
help: try this
|
LL ~ "some 1/
-LL ~ {} / {}", "2", "3",
+LL ~ {} // {}", "2", "3",
|
error: literal with an empty format string
@@ -98,7 +106,7 @@ LL | "1", "2", "3",
|
help: try this
|
-LL ~ 2 / {}",
+LL ~ 2 // {}",
LL ~ "1", "3",
|
@@ -110,43 +118,43 @@ LL | "1", "2", "3",
|
help: try this
|
-LL ~ {} / 3",
+LL ~ {} // 3",
LL ~ "1", "2",
|
error: literal with an empty format string
--> $DIR/write_literal_2.rs:27:23
|
-LL | writeln!(v, "{}", "/");
+LL | writeln!(v, "{}", "//");
| ^^^^
|
help: try this
|
-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
|
-LL | writeln!(v, r"{}", "/");
+LL | writeln!(v, r"{}", "//");
| ^^^^
|
help: try this
|
-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
|
-LL | writeln!(v, r#"{}"#, "/");
+LL | writeln!(v, r#"{}"#, "//");
| ^^^^
|
help: try this
|
-LL - writeln!(v, r#"{}"#, "/");
+LL - writeln!(v, r#"{}"#, "//");
LL + writeln!(v, r#"/"#);
|
@@ -159,7 +167,7 @@ LL | writeln!(v, "{}", r"/");
help: try this
|
LL - writeln!(v, "{}", r"/");
-LL + writeln!(v, "/");
+LL + writeln!(v, "//");
|
error: literal with an empty format string
@@ -186,5 +194,5 @@ error: literal with an empty format string
LL | writeln!(v, r#"{}{}"#, '#', '"'); // hard mode
| ^^^
-error: aborting due to 17 previous errors
+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
new file mode 100644
index 000000000..0a10e526a
--- /dev/null
+++ b/src/tools/clippy/tests/ui/write_with_newline.fixed
@@ -0,0 +1,63 @@
+// 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)]
+
+use std::io::Write;
+
+fn main() {
+ let mut v = Vec::new();
+
+ // These should fail
+ writeln!(v, "Hello");
+ writeln!(v, "Hello {}", "world");
+ writeln!(v, "Hello {} {}", "world", "#2");
+ writeln!(v, "{}", 1265);
+ writeln!(v);
+
+ // These should be fine
+ write!(v, "");
+ write!(v, "Hello");
+ writeln!(v, "Hello");
+ writeln!(v, "Hello\n");
+ writeln!(v, "Hello {}\n", "world");
+ write!(v, "Issue\n{}", 1265);
+ write!(v, "{}", 1265);
+ write!(v, "\n{}", 1275);
+ 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
+
+ // Escaping
+ write!(v, "\\n"); // #3514
+ writeln!(v, "\\"); // should fail
+ write!(v, "\\\\n");
+
+ // Raw strings
+ write!(v, r"\n"); // #3778
+
+ // Literal newlines should also fail
+ writeln!(
+ v
+ );
+ writeln!(
+ v
+ );
+
+ // Don't warn on CRLF (#4208)
+ write!(v, "\r\n");
+ write!(v, "foo\r\n");
+ writeln!(v, "\\r"); // warns
+ write!(v, "foo\rbar\n");
+
+ // Ignore expanded format strings
+ macro_rules! newline {
+ () => {
+ "\n"
+ };
+ }
+ write!(v, newline!());
+}
diff --git a/src/tools/clippy/tests/ui/write_with_newline.stderr b/src/tools/clippy/tests/ui/write_with_newline.stderr
index 9035275b2..03a18a4dc 100644
--- a/src/tools/clippy/tests/ui/write_with_newline.stderr
+++ b/src/tools/clippy/tests/ui/write_with_newline.stderr
@@ -62,13 +62,13 @@ LL + writeln!(v);
error: using `write!()` with a format string that ends in a single newline
--> $DIR/write_with_newline.rs:36:5
|
-LL | write!(v, "//n"); // should fail
+LL | write!(v, "///n"); // should fail
| ^^^^^^^^^^^^^^^^^
|
help: use `writeln!` instead
|
-LL - write!(v, "//n"); // should fail
-LL + writeln!(v, "/"); // should fail
+LL - write!(v, "///n"); // should fail
+LL + writeln!(v, "//"); // should fail
|
error: using `write!()` with a format string that ends in a single newline
@@ -106,13 +106,13 @@ LL ~ v
error: using `write!()` with a format string that ends in a single newline
--> $DIR/write_with_newline.rs:57: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