summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests')
-rw-r--r--src/tools/clippy/tests/compile-test.rs199
-rw-r--r--src/tools/clippy/tests/integration.rs24
-rw-r--r--src/tools/clippy/tests/lint_message_convention.rs6
-rw-r--r--src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail/src/main.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish/src/main.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish_true/src/main.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass/src/main.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass_publish_empty/src/main.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass_publish_false/src/main.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/feature_name/fail/src/main.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/feature_name/pass/src/main.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/main.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/multiple_crate_versions/5041_allow_dev_build/src/main.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/multiple_crate_versions/fail/src/main.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/multiple_crate_versions/pass/src/main.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/wildcard_dependencies/fail/src/main.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/wildcard_dependencies/pass/src/main.rs1
-rw-r--r--src/tools/clippy/tests/ui-internal/custom_ice_message.stderr5
-rw-r--r--src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr28
-rw-r--r--src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr70
-rw-r--r--src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.rs97
-rw-r--r--src/tools/clippy/tests/ui-toml/absolute_paths/allow_crates/clippy.toml2
-rw-r--r--src/tools/clippy/tests/ui-toml/absolute_paths/auxiliary/helper.rs11
-rw-r--r--src/tools/clippy/tests/ui-toml/absolute_paths/disallow_crates/clippy.toml1
-rw-r--r--src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr2
-rw-r--r--src/tools/clippy/tests/ui-toml/excessive_nesting/auxiliary/proc_macros.rs11
-rw-r--r--src/tools/clippy/tests/ui-toml/expect_used/expect_used.stderr4
-rw-r--r--src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.rs1
-rw-r--r--src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.stderr4
-rw-r--r--src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr4
-rw-r--r--src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs4
-rw-r--r--src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr125
-rw-r--r--src/tools/clippy/tests/ui/arc_with_non_send_sync.rs30
-rw-r--r--src/tools/clippy/tests/ui/arc_with_non_send_sync.stderr6
-rw-r--r--src/tools/clippy/tests/ui/arithmetic_side_effects.rs12
-rw-r--r--src/tools/clippy/tests/ui/as_conversions.rs3
-rw-r--r--src/tools/clippy/tests/ui/as_conversions.stderr6
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/macro_use_helper.rs3
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs4
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/proc_macros.rs11
-rw-r--r--src/tools/clippy/tests/ui/bind_instead_of_map.stderr2
-rw-r--r--src/tools/clippy/tests/ui/bind_instead_of_map_multipart.stderr10
-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_box.rs6
-rw-r--r--src/tools/clippy/tests/ui/borrow_box.stderr20
-rw-r--r--src/tools/clippy/tests/ui/comparison_to_empty.fixed12
-rw-r--r--src/tools/clippy/tests/ui/comparison_to_empty.rs12
-rw-r--r--src/tools/clippy/tests/ui/comparison_to_empty.stderr40
-rw-r--r--src/tools/clippy/tests/ui/const_comparisons.rs93
-rw-r--r--src/tools/clippy/tests/ui/const_comparisons.stderr228
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-6256.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-7169.stderr2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-8250.stderr2
-rw-r--r--src/tools/clippy/tests/ui/default_trait_access.fixed3
-rw-r--r--src/tools/clippy/tests/ui/default_trait_access.rs3
-rw-r--r--src/tools/clippy/tests/ui/default_trait_access.stderr16
-rw-r--r--src/tools/clippy/tests/ui/deref_addrof.stderr20
-rw-r--r--src/tools/clippy/tests/ui/deref_addrof_double_trigger.stderr6
-rw-r--r--src/tools/clippy/tests/ui/derive.rs6
-rw-r--r--src/tools/clippy/tests/ui/derive.stderr20
-rw-r--r--src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.rs1
-rw-r--r--src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr16
-rw-r--r--src/tools/clippy/tests/ui/entry.stderr20
-rw-r--r--src/tools/clippy/tests/ui/entry_btree.stderr2
-rw-r--r--src/tools/clippy/tests/ui/entry_with_else.stderr14
-rw-r--r--src/tools/clippy/tests/ui/error_impl_error.rs90
-rw-r--r--src/tools/clippy/tests/ui/error_impl_error.stderr45
-rw-r--r--src/tools/clippy/tests/ui/eta.fixed57
-rw-r--r--src/tools/clippy/tests/ui/eta.rs57
-rw-r--r--src/tools/clippy/tests/ui/eta.stderr8
-rw-r--r--src/tools/clippy/tests/ui/expect.stderr6
-rw-r--r--src/tools/clippy/tests/ui/expect_fun_call.stderr30
-rw-r--r--src/tools/clippy/tests/ui/explicit_auto_deref.stderr78
-rw-r--r--src/tools/clippy/tests/ui/explicit_deref_methods.fixed1
-rw-r--r--src/tools/clippy/tests/ui/explicit_deref_methods.rs1
-rw-r--r--src/tools/clippy/tests/ui/explicit_deref_methods.stderr48
-rw-r--r--src/tools/clippy/tests/ui/explicit_write.stderr26
-rw-r--r--src/tools/clippy/tests/ui/extend_with_drain.stderr8
-rw-r--r--src/tools/clippy/tests/ui/filter_map_bool_then.fixed58
-rw-r--r--src/tools/clippy/tests/ui/filter_map_bool_then.rs58
-rw-r--r--src/tools/clippy/tests/ui/filter_map_bool_then.stderr40
-rw-r--r--src/tools/clippy/tests/ui/filter_map_next_fixable.stderr4
-rw-r--r--src/tools/clippy/tests/ui/fn_null_check.rs22
-rw-r--r--src/tools/clippy/tests/ui/fn_null_check.stderr43
-rw-r--r--src/tools/clippy/tests/ui/format_collect.rs31
-rw-r--r--src/tools/clippy/tests/ui/format_collect.stderr62
-rw-r--r--src/tools/clippy/tests/ui/four_forward_slashes.fixed48
-rw-r--r--src/tools/clippy/tests/ui/four_forward_slashes.rs48
-rw-r--r--src/tools/clippy/tests/ui/four_forward_slashes.stderr68
-rw-r--r--src/tools/clippy/tests/ui/four_forward_slashes_first_line.fixed7
-rw-r--r--src/tools/clippy/tests/ui/four_forward_slashes_first_line.rs7
-rw-r--r--src/tools/clippy/tests/ui/four_forward_slashes_first_line.stderr15
-rw-r--r--src/tools/clippy/tests/ui/get_first.fixed4
-rw-r--r--src/tools/clippy/tests/ui/get_first.rs4
-rw-r--r--src/tools/clippy/tests/ui/get_first.stderr6
-rw-r--r--src/tools/clippy/tests/ui/get_unwrap.fixed4
-rw-r--r--src/tools/clippy/tests/ui/get_unwrap.rs4
-rw-r--r--src/tools/clippy/tests/ui/get_unwrap.stderr133
-rw-r--r--src/tools/clippy/tests/ui/if_same_then_else.rs41
-rw-r--r--src/tools/clippy/tests/ui/if_same_then_else.stderr20
-rw-r--r--src/tools/clippy/tests/ui/if_same_then_else2.rs2
-rw-r--r--src/tools/clippy/tests/ui/if_same_then_else2.stderr21
-rw-r--r--src/tools/clippy/tests/ui/ifs_same_cond.rs4
-rw-r--r--src/tools/clippy/tests/ui/ifs_same_cond.stderr4
-rw-r--r--src/tools/clippy/tests/ui/ignored_unit_patterns.fixed17
-rw-r--r--src/tools/clippy/tests/ui/ignored_unit_patterns.rs17
-rw-r--r--src/tools/clippy/tests/ui/ignored_unit_patterns.stderr28
-rw-r--r--src/tools/clippy/tests/ui/incorrect_clone_impl_on_copy_type.stderr4
-rw-r--r--src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.fixed145
-rw-r--r--src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.rs149
-rw-r--r--src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.stderr31
-rw-r--r--src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs51
-rw-r--r--src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr31
-rw-r--r--src/tools/clippy/tests/ui/infallible_destructuring_match.stderr8
-rw-r--r--src/tools/clippy/tests/ui/inherent_to_string.rs26
-rw-r--r--src/tools/clippy/tests/ui/inherent_to_string.stderr10
-rw-r--r--src/tools/clippy/tests/ui/issue-7447.rs5
-rw-r--r--src/tools/clippy/tests/ui/issue-7447.stderr4
-rw-r--r--src/tools/clippy/tests/ui/iter_cloned_collect.fixed3
-rw-r--r--src/tools/clippy/tests/ui/iter_cloned_collect.rs3
-rw-r--r--src/tools/clippy/tests/ui/iter_cloned_collect.stderr10
-rw-r--r--src/tools/clippy/tests/ui/iter_overeager_cloned.stderr14
-rw-r--r--src/tools/clippy/tests/ui/iter_skip_zero.fixed25
-rw-r--r--src/tools/clippy/tests/ui/iter_skip_zero.rs25
-rw-r--r--src/tools/clippy/tests/ui/iter_skip_zero.stderr43
-rw-r--r--src/tools/clippy/tests/ui/iter_with_drain.stderr12
-rw-r--r--src/tools/clippy/tests/ui/let_and_return.rs71
-rw-r--r--src/tools/clippy/tests/ui/let_and_return.stderr22
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_lock.rs3
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_lock.stderr8
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_untyped.rs3
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_untyped.stderr20
-rw-r--r--src/tools/clippy/tests/ui/manual_filter.stderr30
-rw-r--r--src/tools/clippy/tests/ui/manual_filter_map.fixed24
-rw-r--r--src/tools/clippy/tests/ui/manual_filter_map.rs28
-rw-r--r--src/tools/clippy/tests/ui/manual_filter_map.stderr73
-rw-r--r--src/tools/clippy/tests/ui/manual_find_map.stderr53
-rw-r--r--src/tools/clippy/tests/ui/manual_float_methods.rs55
-rw-r--r--src/tools/clippy/tests/ui/manual_float_methods.stderr80
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else.rs8
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else.stderr2
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else_question_mark.fixed63
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else_question_mark.rs68
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else_question_mark.stderr55
-rw-r--r--src/tools/clippy/tests/ui/manual_map_option.stderr42
-rw-r--r--src/tools/clippy/tests/ui/manual_map_option_2.stderr10
-rw-r--r--src/tools/clippy/tests/ui/manual_range_patterns.fixed4
-rw-r--r--src/tools/clippy/tests/ui/manual_range_patterns.rs4
-rw-r--r--src/tools/clippy/tests/ui/manual_range_patterns.stderr16
-rw-r--r--src/tools/clippy/tests/ui/manual_retain.fixed7
-rw-r--r--src/tools/clippy/tests/ui/manual_retain.rs7
-rw-r--r--src/tools/clippy/tests/ui/manual_retain.stderr38
-rw-r--r--src/tools/clippy/tests/ui/manual_split_once.stderr28
-rw-r--r--src/tools/clippy/tests/ui/manual_str_repeat.stderr20
-rw-r--r--src/tools/clippy/tests/ui/manual_try_fold.rs4
-rw-r--r--src/tools/clippy/tests/ui/manual_try_fold.stderr8
-rw-r--r--src/tools/clippy/tests/ui/map_collect_result_unit.stderr4
-rw-r--r--src/tools/clippy/tests/ui/map_unwrap_or.stderr2
-rw-r--r--src/tools/clippy/tests/ui/map_unwrap_or_fixable.stderr4
-rw-r--r--src/tools/clippy/tests/ui/match_as_ref.fixed4
-rw-r--r--src/tools/clippy/tests/ui/match_as_ref.rs4
-rw-r--r--src/tools/clippy/tests/ui/match_as_ref.stderr8
-rw-r--r--src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed3
-rw-r--r--src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs3
-rw-r--r--src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr56
-rw-r--r--src/tools/clippy/tests/ui/match_on_vec_items.stderr16
-rw-r--r--src/tools/clippy/tests/ui/match_ref_pats.stderr4
-rw-r--r--src/tools/clippy/tests/ui/match_same_arms2.stderr2
-rw-r--r--src/tools/clippy/tests/ui/match_wildcard_for_single_variants.stderr20
-rw-r--r--src/tools/clippy/tests/ui/methods.rs5
-rw-r--r--src/tools/clippy/tests/ui/methods.stderr4
-rw-r--r--src/tools/clippy/tests/ui/methods_fixable.stderr2
-rw-r--r--src/tools/clippy/tests/ui/methods_unfixable.rs10
-rw-r--r--src/tools/clippy/tests/ui/methods_unfixable.stderr15
-rw-r--r--src/tools/clippy/tests/ui/min_ident_chars.rs7
-rw-r--r--src/tools/clippy/tests/ui/min_ident_chars.stderr58
-rw-r--r--src/tools/clippy/tests/ui/min_max.rs4
-rw-r--r--src/tools/clippy/tests/ui/min_max.stderr26
-rw-r--r--src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs1
-rw-r--r--src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr8
-rw-r--r--src/tools/clippy/tests/ui/missing_doc.rs4
-rw-r--r--src/tools/clippy/tests/ui/missing_spin_loop.stderr12
-rw-r--r--src/tools/clippy/tests/ui/missing_spin_loop_no_std.stderr2
-rw-r--r--src/tools/clippy/tests/ui/must_use_candidates.fixed7
-rw-r--r--src/tools/clippy/tests/ui/must_use_candidates.rs7
-rw-r--r--src/tools/clippy/tests/ui/must_use_candidates.stderr10
-rw-r--r--src/tools/clippy/tests/ui/mut_from_ref.rs2
-rw-r--r--src/tools/clippy/tests/ui/mut_key.rs3
-rw-r--r--src/tools/clippy/tests/ui/mut_key.stderr34
-rw-r--r--src/tools/clippy/tests/ui/mut_mut.rs7
-rw-r--r--src/tools/clippy/tests/ui/mut_mut.stderr18
-rw-r--r--src/tools/clippy/tests/ui/mut_reference.rs15
-rw-r--r--src/tools/clippy/tests/ui/mut_reference.stderr6
-rw-r--r--src/tools/clippy/tests/ui/needless_borrow_pat.stderr24
-rw-r--r--src/tools/clippy/tests/ui/needless_else.stderr2
-rw-r--r--src/tools/clippy/tests/ui/needless_if.fixed3
-rw-r--r--src/tools/clippy/tests/ui/needless_if.rs3
-rw-r--r--src/tools/clippy/tests/ui/needless_if.stderr14
-rw-r--r--src/tools/clippy/tests/ui/needless_option_as_deref.stderr6
-rw-r--r--src/tools/clippy/tests/ui/needless_pass_by_ref_mut.rs254
-rw-r--r--src/tools/clippy/tests/ui/needless_pass_by_ref_mut.stderr110
-rw-r--r--src/tools/clippy/tests/ui/needless_return_with_question_mark.fixed40
-rw-r--r--src/tools/clippy/tests/ui/needless_return_with_question_mark.rs40
-rw-r--r--src/tools/clippy/tests/ui/needless_return_with_question_mark.stderr10
-rw-r--r--src/tools/clippy/tests/ui/needless_splitn.stderr26
-rw-r--r--src/tools/clippy/tests/ui/numbered_fields.stderr4
-rw-r--r--src/tools/clippy/tests/ui/option_env_unwrap.rs1
-rw-r--r--src/tools/clippy/tests/ui/option_env_unwrap.stderr18
-rw-r--r--src/tools/clippy/tests/ui/option_if_let_else.fixed3
-rw-r--r--src/tools/clippy/tests/ui/option_if_let_else.rs3
-rw-r--r--src/tools/clippy/tests/ui/option_if_let_else.stderr46
-rw-r--r--src/tools/clippy/tests/ui/option_map_unit_fn_fixable.stderr38
-rw-r--r--src/tools/clippy/tests/ui/or_fun_call.fixed66
-rw-r--r--src/tools/clippy/tests/ui/or_fun_call.rs58
-rw-r--r--src/tools/clippy/tests/ui/or_fun_call.stderr178
-rw-r--r--src/tools/clippy/tests/ui/or_then_unwrap.stderr6
-rw-r--r--src/tools/clippy/tests/ui/panic_in_result_fn.stderr74
-rw-r--r--src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr12
-rw-r--r--src/tools/clippy/tests/ui/print_literal.stderr24
-rw-r--r--src/tools/clippy/tests/ui/ptr_arg.rs16
-rw-r--r--src/tools/clippy/tests/ui/ptr_arg.stderr46
-rw-r--r--src/tools/clippy/tests/ui/ptr_as_ptr.fixed16
-rw-r--r--src/tools/clippy/tests/ui/ptr_as_ptr.rs16
-rw-r--r--src/tools/clippy/tests/ui/ptr_as_ptr.stderr28
-rw-r--r--src/tools/clippy/tests/ui/question_mark.fixed17
-rw-r--r--src/tools/clippy/tests/ui/question_mark.rs17
-rw-r--r--src/tools/clippy/tests/ui/question_mark.stderr6
-rw-r--r--src/tools/clippy/tests/ui/range_contains.fixed2
-rw-r--r--src/tools/clippy/tests/ui/range_contains.rs2
-rw-r--r--src/tools/clippy/tests/ui/range_contains.stderr42
-rw-r--r--src/tools/clippy/tests/ui/read_line_without_trim.fixed36
-rw-r--r--src/tools/clippy/tests/ui/read_line_without_trim.rs36
-rw-r--r--src/tools/clippy/tests/ui/read_line_without_trim.stderr73
-rw-r--r--src/tools/clippy/tests/ui/read_zero_byte_vec.rs6
-rw-r--r--src/tools/clippy/tests/ui/read_zero_byte_vec.stderr20
-rw-r--r--src/tools/clippy/tests/ui/readonly_write_lock.rs42
-rw-r--r--src/tools/clippy/tests/ui/readonly_write_lock.stderr16
-rw-r--r--src/tools/clippy/tests/ui/redundant_allocation.rs9
-rw-r--r--src/tools/clippy/tests/ui/redundant_allocation.stderr40
-rw-r--r--src/tools/clippy/tests/ui/redundant_allocation_fixable.fixed12
-rw-r--r--src/tools/clippy/tests/ui/redundant_allocation_fixable.rs12
-rw-r--r--src/tools/clippy/tests/ui/redundant_allocation_fixable.stderr24
-rw-r--r--src/tools/clippy/tests/ui/redundant_guards.fixed146
-rw-r--r--src/tools/clippy/tests/ui/redundant_guards.rs146
-rw-r--r--src/tools/clippy/tests/ui/redundant_guards.stderr98
-rw-r--r--src/tools/clippy/tests/ui/redundant_locals.rs120
-rw-r--r--src/tools/clippy/tests/ui/redundant_locals.stderr136
-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.fixed6
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs6
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr72
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed14
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_option.rs14
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_option.stderr128
-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.stderr56
-rw-r--r--src/tools/clippy/tests/ui/ref_binding_to_reference.stderr14
-rw-r--r--src/tools/clippy/tests/ui/rename.fixed6
-rw-r--r--src/tools/clippy/tests/ui/rename.rs6
-rw-r--r--src/tools/clippy/tests/ui/rename.stderr118
-rw-r--r--src/tools/clippy/tests/ui/result_map_or_into_option.fixed2
-rw-r--r--src/tools/clippy/tests/ui/result_map_or_into_option.rs2
-rw-r--r--src/tools/clippy/tests/ui/result_map_unit_fn_fixable.stderr36
-rw-r--r--src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr12
-rw-r--r--src/tools/clippy/tests/ui/self_assignment.rs4
-rw-r--r--src/tools/clippy/tests/ui/self_assignment.stderr6
-rw-r--r--src/tools/clippy/tests/ui/semicolon_if_nothing_returned.fixed123
-rw-r--r--src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs7
-rw-r--r--src/tools/clippy/tests/ui/semicolon_if_nothing_returned.stderr10
-rw-r--r--src/tools/clippy/tests/ui/shadow.rs7
-rw-r--r--src/tools/clippy/tests/ui/shadow.stderr92
-rw-r--r--src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs3
-rw-r--r--src/tools/clippy/tests/ui/significant_drop_in_scrutinee.stderr52
-rw-r--r--src/tools/clippy/tests/ui/significant_drop_tightening.fixed50
-rw-r--r--src/tools/clippy/tests/ui/significant_drop_tightening.rs50
-rw-r--r--src/tools/clippy/tests/ui/significant_drop_tightening.stderr6
-rw-r--r--src/tools/clippy/tests/ui/single_component_path_imports.fixed4
-rw-r--r--src/tools/clippy/tests/ui/single_component_path_imports.rs4
-rw-r--r--src/tools/clippy/tests/ui/single_component_path_imports.stderr4
-rw-r--r--src/tools/clippy/tests/ui/single_component_path_imports_nested_first.rs2
-rw-r--r--src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr4
-rw-r--r--src/tools/clippy/tests/ui/single_component_path_imports_self_after.rs1
-rw-r--r--src/tools/clippy/tests/ui/single_component_path_imports_self_before.rs1
-rw-r--r--src/tools/clippy/tests/ui/single_match.fixed1
-rw-r--r--src/tools/clippy/tests/ui/single_match.rs1
-rw-r--r--src/tools/clippy/tests/ui/single_match.stderr72
-rw-r--r--src/tools/clippy/tests/ui/single_match_else.stderr18
-rw-r--r--src/tools/clippy/tests/ui/slow_vector_initialization.rs16
-rw-r--r--src/tools/clippy/tests/ui/slow_vector_initialization.stderr62
-rw-r--r--src/tools/clippy/tests/ui/string_extend.stderr8
-rw-r--r--src/tools/clippy/tests/ui/string_lit_chars_any.fixed50
-rw-r--r--src/tools/clippy/tests/ui/string_lit_chars_any.rs50
-rw-r--r--src/tools/clippy/tests/ui/string_lit_chars_any.stderr58
-rw-r--r--src/tools/clippy/tests/ui/strlen_on_c_strings.stderr14
-rw-r--r--src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr10
-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/to_digit_is_some.stderr4
-rw-r--r--src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs3
-rw-r--r--src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr36
-rw-r--r--src/tools/clippy/tests/ui/try_err.fixed6
-rw-r--r--src/tools/clippy/tests/ui/try_err.rs6
-rw-r--r--src/tools/clippy/tests/ui/try_err.stderr44
-rw-r--r--src/tools/clippy/tests/ui/tuple_array_conversions.rs30
-rw-r--r--src/tools/clippy/tests/ui/tuple_array_conversions.stderr36
-rw-r--r--src/tools/clippy/tests/ui/type_id_on_box.fixed40
-rw-r--r--src/tools/clippy/tests/ui/type_id_on_box.rs40
-rw-r--r--src/tools/clippy/tests/ui/type_id_on_box.stderr36
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast.fixed17
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast.rs17
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast.stderr88
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast_unfixable.rs22
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast_unfixable.stderr16
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_clone.stderr12
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_filter_map.rs6
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_filter_map.stderr8
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_find_map.rs6
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_find_map.stderr8
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_literal_unwrap.fixed21
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_literal_unwrap.rs21
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_literal_unwrap.stderr86
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.fixed3
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.rs3
-rw-r--r--src/tools/clippy/tests/ui/unsafe_removed_from_name.rs8
-rw-r--r--src/tools/clippy/tests/ui/unsafe_removed_from_name.stderr16
-rw-r--r--src/tools/clippy/tests/ui/unused_async.rs17
-rw-r--r--src/tools/clippy/tests/ui/unused_async.stderr14
-rw-r--r--src/tools/clippy/tests/ui/unused_io_amount.rs2
-rw-r--r--src/tools/clippy/tests/ui/unused_peekable.rs3
-rw-r--r--src/tools/clippy/tests/ui/unused_peekable.stderr16
-rw-r--r--src/tools/clippy/tests/ui/unwrap.stderr9
-rw-r--r--src/tools/clippy/tests/ui/unwrap_expect_used.rs11
-rw-r--r--src/tools/clippy/tests/ui/unwrap_expect_used.stderr24
-rw-r--r--src/tools/clippy/tests/ui/unwrap_or.stderr4
-rw-r--r--src/tools/clippy/tests/ui/unwrap_or_else_default.fixed62
-rw-r--r--src/tools/clippy/tests/ui/unwrap_or_else_default.rs62
-rw-r--r--src/tools/clippy/tests/ui/unwrap_or_else_default.stderr100
-rw-r--r--src/tools/clippy/tests/ui/useless_asref.fixed6
-rw-r--r--src/tools/clippy/tests/ui/useless_asref.rs6
-rw-r--r--src/tools/clippy/tests/ui/useless_asref.stderr44
-rw-r--r--src/tools/clippy/tests/ui/vec.fixed40
-rw-r--r--src/tools/clippy/tests/ui/vec.rs40
-rw-r--r--src/tools/clippy/tests/ui/vec.stderr24
-rw-r--r--src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr12
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports.fixed1
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports.rs1
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports.stderr24
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed1
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.stderr24
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed1
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.stderr24
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.rs1
-rw-r--r--src/tools/clippy/tests/ui/write_literal.stderr24
-rw-r--r--src/tools/clippy/tests/ui/write_literal_2.stderr28
357 files changed, 7322 insertions, 2001 deletions
diff --git a/src/tools/clippy/tests/compile-test.rs b/src/tools/clippy/tests/compile-test.rs
index 0fd37c640..e46f8bf6f 100644
--- a/src/tools/clippy/tests/compile-test.rs
+++ b/src/tools/clippy/tests/compile-test.rs
@@ -3,17 +3,108 @@
#![feature(is_sorted)]
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2018_idioms, unused_lifetimes)]
+#![allow(unused_extern_crates)]
-use compiletest::{status_emitter, CommandBuilder};
+use compiletest::{status_emitter, CommandBuilder, OutputConflictHandling};
use ui_test as compiletest;
use ui_test::Mode as TestMode;
+use std::collections::BTreeMap;
use std::env::{self, remove_var, set_var, var_os};
use std::ffi::{OsStr, OsString};
use std::fs;
use std::path::{Path, PathBuf};
+use std::sync::LazyLock;
use test_utils::IS_RUSTC_TEST_SUITE;
+// Test dependencies may need an `extern crate` here to ensure that they show up
+// in the depinfo file (otherwise cargo thinks they are unused)
+extern crate clippy_lints;
+extern crate clippy_utils;
+extern crate derive_new;
+extern crate futures;
+extern crate if_chain;
+extern crate itertools;
+extern crate parking_lot;
+extern crate quote;
+extern crate syn;
+extern crate tokio;
+
+/// All crates used in UI tests are listed here
+static TEST_DEPENDENCIES: &[&str] = &[
+ "clippy_lints",
+ "clippy_utils",
+ "derive_new",
+ "futures",
+ "if_chain",
+ "itertools",
+ "parking_lot",
+ "quote",
+ "regex",
+ "serde_derive",
+ "serde",
+ "syn",
+ "tokio",
+];
+
+/// Produces a string with an `--extern` flag for all UI test crate
+/// dependencies.
+///
+/// The dependency files are located by parsing the depinfo file for this test
+/// module. This assumes the `-Z binary-dep-depinfo` flag is enabled. All test
+/// dependencies must be added to Cargo.toml at the project root. Test
+/// dependencies that are not *directly* used by this test module require an
+/// `extern crate` declaration.
+static EXTERN_FLAGS: LazyLock<Vec<String>> = LazyLock::new(|| {
+ let current_exe_depinfo = {
+ let mut path = env::current_exe().unwrap();
+ path.set_extension("d");
+ fs::read_to_string(path).unwrap()
+ };
+ let mut crates = BTreeMap::<&str, &str>::new();
+ for line in current_exe_depinfo.lines() {
+ // each dependency is expected to have a Makefile rule like `/path/to/crate-hash.rlib:`
+ let parse_name_path = || {
+ if line.starts_with(char::is_whitespace) {
+ return None;
+ }
+ let path_str = line.strip_suffix(':')?;
+ let path = Path::new(path_str);
+ if !matches!(path.extension()?.to_str()?, "rlib" | "so" | "dylib" | "dll") {
+ return None;
+ }
+ let (name, _hash) = path.file_stem()?.to_str()?.rsplit_once('-')?;
+ // the "lib" prefix is not present for dll files
+ let name = name.strip_prefix("lib").unwrap_or(name);
+ Some((name, path_str))
+ };
+ if let Some((name, path)) = parse_name_path() {
+ if TEST_DEPENDENCIES.contains(&name) {
+ // A dependency may be listed twice if it is available in sysroot,
+ // and the sysroot dependencies are listed first. As of the writing,
+ // this only seems to apply to if_chain.
+ crates.insert(name, path);
+ }
+ }
+ }
+ let not_found: Vec<&str> = TEST_DEPENDENCIES
+ .iter()
+ .copied()
+ .filter(|n| !crates.contains_key(n))
+ .collect();
+ assert!(
+ not_found.is_empty(),
+ "dependencies not found in depinfo: {not_found:?}\n\
+ help: Make sure the `-Z binary-dep-depinfo` rust flag is enabled\n\
+ help: Try adding to dev-dependencies in Cargo.toml\n\
+ help: Be sure to also add `extern crate ...;` to tests/compile-test.rs",
+ );
+ crates
+ .into_iter()
+ .map(|(name, path)| format!("--extern={name}={path}"))
+ .collect()
+});
+
mod test_utils;
// whether to run internal tests or not
@@ -24,12 +115,13 @@ fn base_config(test_dir: &str) -> compiletest::Config {
mode: TestMode::Yolo,
stderr_filters: vec![],
stdout_filters: vec![],
- output_conflict_handling: if var_os("BLESS").is_some() || env::args().any(|arg| arg == "--bless") {
- compiletest::OutputConflictHandling::Bless
+ output_conflict_handling: if var_os("RUSTC_BLESS").is_some_and(|v| v != "0")
+ || env::args().any(|arg| arg == "--bless")
+ {
+ OutputConflictHandling::Bless
} else {
- compiletest::OutputConflictHandling::Error("cargo test -- -- --bless".into())
+ OutputConflictHandling::Error("cargo uibless".into())
},
- dependencies_crate_manifest_path: Some("clippy_test_deps/Cargo.toml".into()),
target: None,
out_dir: PathBuf::from(std::env::var_os("CARGO_TARGET_DIR").unwrap_or("target".into())).join("ui_test"),
..compiletest::Config::rustc(Path::new("tests").join(test_dir))
@@ -44,10 +136,24 @@ fn base_config(test_dir: &str) -> compiletest::Config {
let deps_path = current_exe_path.parent().unwrap();
let profile_path = deps_path.parent().unwrap();
- config.program.args.push("--emit=metadata".into());
- config.program.args.push("-Aunused".into());
- config.program.args.push("-Zui-testing".into());
- config.program.args.push("-Dwarnings".into());
+ config.program.args.extend(
+ [
+ "--emit=metadata",
+ "-Aunused",
+ "-Ainternal_features",
+ "-Zui-testing",
+ "-Dwarnings",
+ &format!("-Ldependency={}", deps_path.display()),
+ ]
+ .map(OsString::from),
+ );
+
+ config.program.args.extend(EXTERN_FLAGS.iter().map(OsString::from));
+
+ if let Some(host_libs) = option_env!("HOST_LIBS") {
+ let dep = format!("-Ldependency={}", Path::new(host_libs).join("deps").display());
+ config.program.args.push(dep.into());
+ }
// Normalize away slashes in windows paths.
config.stderr_filter(r"\\", "/");
@@ -84,9 +190,6 @@ fn run_ui() {
.to_string()
}),
);
- eprintln!(" Compiler: {}", config.program.display());
-
- let name = config.root_dir.display().to_string();
let test_filter = test_filter();
@@ -94,7 +197,7 @@ fn run_ui() {
config,
move |path| compiletest::default_file_filter(path) && test_filter(path),
compiletest::default_per_file_config,
- (status_emitter::Text, status_emitter::Gha::<true> { name }),
+ status_emitter::Text,
)
.unwrap();
check_rustfix_coverage();
@@ -106,9 +209,18 @@ fn run_internal_tests() {
return;
}
let mut config = base_config("ui-internal");
- config.dependency_builder.args.push("--features".into());
- config.dependency_builder.args.push("internal".into());
- compiletest::run_tests(config).unwrap();
+ if let OutputConflictHandling::Error(err) = &mut config.output_conflict_handling {
+ *err = "cargo uitest --features internal -- -- --bless".into();
+ }
+ let test_filter = test_filter();
+
+ compiletest::run_tests_generic(
+ config,
+ move |path| compiletest::default_file_filter(path) && test_filter(path),
+ compiletest::default_per_file_config,
+ status_emitter::Text,
+ )
+ .unwrap();
}
fn run_ui_toml() {
@@ -127,13 +239,11 @@ fn run_ui_toml() {
"$$DIR",
);
- let name = config.root_dir.display().to_string();
-
let test_filter = test_filter();
ui_test::run_tests_generic(
config,
- |path| test_filter(path) && path.extension() == Some("rs".as_ref()),
+ |path| compiletest::default_file_filter(path) && test_filter(path),
|config, path| {
let mut config = config.clone();
config
@@ -142,7 +252,7 @@ fn run_ui_toml() {
.push(("CLIPPY_CONF_DIR".into(), Some(path.parent().unwrap().into())));
Some(config)
},
- (status_emitter::Text, status_emitter::Gha::<true> { name }),
+ status_emitter::Text,
)
.unwrap();
}
@@ -183,8 +293,6 @@ fn run_ui_cargo() {
"$$DIR",
);
- let name = config.root_dir.display().to_string();
-
let test_filter = test_filter();
ui_test::run_tests_generic(
@@ -195,7 +303,7 @@ fn run_ui_cargo() {
config.out_dir = PathBuf::from("target/ui_test_cargo/").join(path.parent().unwrap());
Some(config)
},
- (status_emitter::Text, status_emitter::Gha::<true> { name }),
+ status_emitter::Text,
)
.unwrap();
}
@@ -211,12 +319,45 @@ fn main() {
}
set_var("CLIPPY_DISABLE_DOCS_LINKS", "true");
- run_ui();
- run_ui_toml();
- run_ui_cargo();
- run_internal_tests();
- rustfix_coverage_known_exceptions_accuracy();
- ui_cargo_toml_metadata();
+ // The SPEEDTEST_* env variables can be used to check Clippy's performance on your PR. It runs the
+ // affected test 1000 times and gets the average.
+ if let Ok(speedtest) = std::env::var("SPEEDTEST") {
+ println!("----------- STARTING SPEEDTEST -----------");
+ let f = match speedtest.as_str() {
+ "ui" => run_ui as fn(),
+ "cargo" => run_ui_cargo as fn(),
+ "toml" => run_ui_toml as fn(),
+ "internal" => run_internal_tests as fn(),
+ "rustfix-coverage-known-exceptions-accuracy" => rustfix_coverage_known_exceptions_accuracy as fn(),
+ "ui-cargo-toml-metadata" => ui_cargo_toml_metadata as fn(),
+
+ _ => panic!("unknown speedtest: {speedtest} || accepted speedtests are: [ui, cargo, toml, internal]"),
+ };
+
+ let iterations;
+ if let Ok(iterations_str) = std::env::var("SPEEDTEST_ITERATIONS") {
+ iterations = iterations_str
+ .parse::<u64>()
+ .unwrap_or_else(|_| panic!("Couldn't parse `{iterations_str}`, please use a valid u64"));
+ } else {
+ iterations = 1000;
+ }
+
+ let mut sum = 0;
+ for _ in 0..iterations {
+ let start = std::time::Instant::now();
+ f();
+ sum += start.elapsed().as_millis();
+ }
+ println!("average {} time: {} millis.", speedtest.to_uppercase(), sum / 1000);
+ } else {
+ run_ui();
+ run_ui_toml();
+ run_ui_cargo();
+ run_internal_tests();
+ rustfix_coverage_known_exceptions_accuracy();
+ ui_cargo_toml_metadata();
+ }
}
const RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS: &[&str] = &[
diff --git a/src/tools/clippy/tests/integration.rs b/src/tools/clippy/tests/integration.rs
index a771d8b87..031982edb 100644
--- a/src/tools/clippy/tests/integration.rs
+++ b/src/tools/clippy/tests/integration.rs
@@ -65,6 +65,30 @@ fn integration_test() {
.expect("unable to run clippy");
let stderr = String::from_utf8_lossy(&output.stderr);
+
+ // debug:
+ eprintln!("{stderr}");
+
+ // this is an internal test to make sure we would correctly panic on a delay_span_bug
+ if repo_name == "matthiaskrgr/clippy_ci_panic_test" {
+ // we need to kind of switch around our logic here:
+ // if we find a panic, everything is fine, if we don't panic, SOMETHING is broken about our testing
+
+ // the repo basically just contains a delay_span_bug that forces rustc/clippy to panic:
+ /*
+ #![feature(rustc_attrs)]
+ #[rustc_error(delay_span_bug_from_inside_query)]
+ fn main() {}
+ */
+
+ if stderr.find("error: internal compiler error").is_some() {
+ eprintln!("we saw that we intentionally panicked, yay");
+ return;
+ }
+
+ panic!("panic caused by delay_span_bug was NOT detected! Something is broken!");
+ }
+
if let Some(backtrace_start) = stderr.find("error: internal compiler error") {
static BACKTRACE_END_MSG: &str = "end of query stack";
let backtrace_end = stderr[backtrace_start..]
diff --git a/src/tools/clippy/tests/lint_message_convention.rs b/src/tools/clippy/tests/lint_message_convention.rs
index 15e5cdd69..98019c755 100644
--- a/src/tools/clippy/tests/lint_message_convention.rs
+++ b/src/tools/clippy/tests/lint_message_convention.rs
@@ -18,18 +18,20 @@ impl Message {
fn new(path: PathBuf) -> Self {
// we don't want the first letter after "error: ", "help: " ... to be capitalized
// also no punctuation (except for "?" ?) at the end of a line
+ // Prefer "try" over "try this".
static REGEX_SET: LazyLock<RegexSet> = LazyLock::new(|| {
RegexSet::new([
"error: [A-Z]",
"help: [A-Z]",
"warning: [A-Z]",
"note: [A-Z]",
- "try this: [A-Z]",
+ "try: [A-Z]",
"error: .*[.!]$",
"help: .*[.!]$",
"warning: .*[.!]$",
"note: .*[.!]$",
- "try this: .*[.!]$",
+ "try: .*[.!]$",
+ "try this",
])
.unwrap()
});
diff --git a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail/src/main.rs b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail/src/main.rs
index 1a69bb241..c67166fc4 100644
--- a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail/src/main.rs
+++ b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail/src/main.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --crate-name=cargo_common_metadata
#![warn(clippy::cargo_common_metadata)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish/src/main.rs b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish/src/main.rs
index 1a69bb241..c67166fc4 100644
--- a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish/src/main.rs
+++ b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish/src/main.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --crate-name=cargo_common_metadata
#![warn(clippy::cargo_common_metadata)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish_true/src/main.rs b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish_true/src/main.rs
index 1a69bb241..c67166fc4 100644
--- a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish_true/src/main.rs
+++ b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish_true/src/main.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --crate-name=cargo_common_metadata
#![warn(clippy::cargo_common_metadata)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass/src/main.rs b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass/src/main.rs
index 1a69bb241..c67166fc4 100644
--- a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass/src/main.rs
+++ b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass/src/main.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --crate-name=cargo_common_metadata
#![warn(clippy::cargo_common_metadata)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass_publish_empty/src/main.rs b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass_publish_empty/src/main.rs
index 1a69bb241..c67166fc4 100644
--- a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass_publish_empty/src/main.rs
+++ b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass_publish_empty/src/main.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --crate-name=cargo_common_metadata
#![warn(clippy::cargo_common_metadata)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass_publish_false/src/main.rs b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass_publish_false/src/main.rs
index 1a69bb241..c67166fc4 100644
--- a/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass_publish_false/src/main.rs
+++ b/src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass_publish_false/src/main.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --crate-name=cargo_common_metadata
#![warn(clippy::cargo_common_metadata)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui-cargo/feature_name/fail/src/main.rs b/src/tools/clippy/tests/ui-cargo/feature_name/fail/src/main.rs
index 4dd9582af..74e40c09e 100644
--- a/src/tools/clippy/tests/ui-cargo/feature_name/fail/src/main.rs
+++ b/src/tools/clippy/tests/ui-cargo/feature_name/fail/src/main.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --crate-name=feature_name
#![warn(clippy::redundant_feature_names)]
#![warn(clippy::negative_feature_names)]
diff --git a/src/tools/clippy/tests/ui-cargo/feature_name/pass/src/main.rs b/src/tools/clippy/tests/ui-cargo/feature_name/pass/src/main.rs
index 4dd9582af..74e40c09e 100644
--- a/src/tools/clippy/tests/ui-cargo/feature_name/pass/src/main.rs
+++ b/src/tools/clippy/tests/ui-cargo/feature_name/pass/src/main.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --crate-name=feature_name
#![warn(clippy::redundant_feature_names)]
#![warn(clippy::negative_feature_names)]
diff --git a/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/main.rs b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/main.rs
index c70d92e35..ac21b3a44 100644
--- a/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/main.rs
+++ b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/main.rs
@@ -1,3 +1,4 @@
+// FIXME: find a way to add rustflags to ui-cargo tests
//@compile-flags: --remap-path-prefix {{src-base}}=/remapped
#![warn(clippy::self_named_module_files)]
diff --git a/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/5041_allow_dev_build/src/main.rs b/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/5041_allow_dev_build/src/main.rs
index ece260b74..4bc61dd62 100644
--- a/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/5041_allow_dev_build/src/main.rs
+++ b/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/5041_allow_dev_build/src/main.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --crate-name=multiple_crate_versions
#![warn(clippy::multiple_crate_versions)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/fail/src/main.rs b/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/fail/src/main.rs
index ece260b74..4bc61dd62 100644
--- a/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/fail/src/main.rs
+++ b/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/fail/src/main.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --crate-name=multiple_crate_versions
#![warn(clippy::multiple_crate_versions)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/pass/src/main.rs b/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/pass/src/main.rs
index ece260b74..4bc61dd62 100644
--- a/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/pass/src/main.rs
+++ b/src/tools/clippy/tests/ui-cargo/multiple_crate_versions/pass/src/main.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --crate-name=multiple_crate_versions
#![warn(clippy::multiple_crate_versions)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui-cargo/wildcard_dependencies/fail/src/main.rs b/src/tools/clippy/tests/ui-cargo/wildcard_dependencies/fail/src/main.rs
index bb3a39d07..3491ccb0d 100644
--- a/src/tools/clippy/tests/ui-cargo/wildcard_dependencies/fail/src/main.rs
+++ b/src/tools/clippy/tests/ui-cargo/wildcard_dependencies/fail/src/main.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --crate-name=wildcard_dependencies
#![warn(clippy::wildcard_dependencies)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui-cargo/wildcard_dependencies/pass/src/main.rs b/src/tools/clippy/tests/ui-cargo/wildcard_dependencies/pass/src/main.rs
index bb3a39d07..3491ccb0d 100644
--- a/src/tools/clippy/tests/ui-cargo/wildcard_dependencies/pass/src/main.rs
+++ b/src/tools/clippy/tests/ui-cargo/wildcard_dependencies/pass/src/main.rs
@@ -1,4 +1,3 @@
-//@compile-flags: --crate-name=wildcard_dependencies
#![warn(clippy::wildcard_dependencies)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui-internal/custom_ice_message.stderr b/src/tools/clippy/tests/ui-internal/custom_ice_message.stderr
index b88aeae2a..d8b158816 100644
--- a/src/tools/clippy/tests/ui-internal/custom_ice_message.stderr
+++ b/src/tools/clippy/tests/ui-internal/custom_ice_message.stderr
@@ -1,9 +1,10 @@
-thread '<unnamed>' panicked at 'Would you like some help with that?', clippy_lints/src/utils/internal_lints/produce_ice.rs
+thread '<unnamed>' panicked at clippy_lints/src/utils/internal_lints/produce_ice.rs:
+Would you like some help with that?
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: the compiler unexpectedly panicked. this is a bug.
-note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new
+note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml
note: rustc <version> running on <target>
diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr
new file mode 100644
index 000000000..a8900da4e
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr
@@ -0,0 +1,28 @@
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:40:5
+ |
+LL | std::f32::MAX;
+ | ^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::absolute-paths` implied by `-D warnings`
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:41:5
+ |
+LL | core::f32::MAX;
+ | ^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:42:5
+ |
+LL | ::core::f32::MAX;
+ | ^^^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:58:5
+ |
+LL | ::std::f32::MAX;
+ | ^^^^^^^^^^^^^^^
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr
new file mode 100644
index 000000000..41b70644b
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.disallow_crates.stderr
@@ -0,0 +1,70 @@
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:40:5
+ |
+LL | std::f32::MAX;
+ | ^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::absolute-paths` implied by `-D warnings`
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:41:5
+ |
+LL | core::f32::MAX;
+ | ^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:42:5
+ |
+LL | ::core::f32::MAX;
+ | ^^^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:43:5
+ |
+LL | crate::a::b::c::C;
+ | ^^^^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:44:5
+ |
+LL | crate::a::b::c::d::e::f::F;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:45:5
+ |
+LL | crate::a::A;
+ | ^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:46:5
+ |
+LL | crate::a::b::B;
+ | ^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:47:5
+ |
+LL | crate::a::b::c::C::ZERO;
+ | ^^^^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:48:5
+ |
+LL | helper::b::c::d::e::f();
+ | ^^^^^^^^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:49:5
+ |
+LL | ::helper::b::c::d::e::f();
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+
+error: consider bringing this path into scope with the `use` keyword
+ --> $DIR/absolute_paths.rs:58:5
+ |
+LL | ::std::f32::MAX;
+ | ^^^^^^^^^^^^^^^
+
+error: aborting due to 11 previous errors
+
diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.rs b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.rs
new file mode 100644
index 000000000..d4c250a8f
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/absolute_paths/absolute_paths.rs
@@ -0,0 +1,97 @@
+//@aux-build:../../ui/auxiliary/proc_macros.rs:proc-macro
+//@aux-build:helper.rs
+//@revisions: allow_crates disallow_crates
+//@[allow_crates] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/absolute_paths/allow_crates
+//@[disallow_crates] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/absolute_paths/disallow_crates
+#![allow(clippy::no_effect, unused)]
+#![warn(clippy::absolute_paths)]
+#![feature(decl_macro)]
+
+extern crate helper;
+#[macro_use]
+extern crate proc_macros;
+
+pub mod a {
+ pub mod b {
+ pub mod c {
+ pub struct C;
+
+ impl C {
+ pub const ZERO: u32 = 0;
+ }
+
+ pub mod d {
+ pub mod e {
+ pub mod f {
+ pub struct F;
+ }
+ }
+ }
+ }
+
+ pub struct B;
+ }
+
+ pub struct A;
+}
+
+fn main() {
+ f32::max(1.0, 2.0);
+ std::f32::MAX;
+ core::f32::MAX;
+ ::core::f32::MAX;
+ crate::a::b::c::C;
+ crate::a::b::c::d::e::f::F;
+ crate::a::A;
+ crate::a::b::B;
+ crate::a::b::c::C::ZERO;
+ helper::b::c::d::e::f();
+ ::helper::b::c::d::e::f();
+ fn b() -> a::b::B {
+ todo!()
+ }
+ std::println!("a");
+ let x = 1;
+ std::ptr::addr_of!(x);
+ // Test we handle max segments with `PathRoot` properly; this has 4 segments but we should say it
+ // has 3
+ ::std::f32::MAX;
+ // Do not lint due to the above
+ ::helper::a();
+ // Do not lint
+ helper::a();
+ use crate::a::b::c::C;
+ use a::b;
+ use std::f32::MAX;
+ a::b::c::d::e::f::F;
+ b::c::C;
+ fn a() -> a::A {
+ todo!()
+ }
+ use a::b::c;
+
+ fn c() -> c::C {
+ todo!()
+ }
+ fn d() -> Result<(), ()> {
+ todo!()
+ }
+ external! {
+ crate::a::b::c::C::ZERO;
+ }
+ // For some reason, `path.span.from_expansion()` takes care of this for us
+ with_span! {
+ span
+ crate::a::b::c::C::ZERO;
+ }
+ macro_rules! local_crate {
+ () => {
+ crate::a::b::c::C::ZERO;
+ };
+ }
+ macro local_crate_2_0() {
+ crate::a::b::c::C::ZERO;
+ }
+ local_crate!();
+ local_crate_2_0!();
+}
diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/allow_crates/clippy.toml b/src/tools/clippy/tests/ui-toml/absolute_paths/allow_crates/clippy.toml
new file mode 100644
index 000000000..59a621e9d
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/absolute_paths/allow_crates/clippy.toml
@@ -0,0 +1,2 @@
+absolute-paths-max-segments = 2
+absolute-paths-allowed-crates = ["crate", "helper"]
diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/auxiliary/helper.rs b/src/tools/clippy/tests/ui-toml/absolute_paths/auxiliary/helper.rs
new file mode 100644
index 000000000..8e2678f5f
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/absolute_paths/auxiliary/helper.rs
@@ -0,0 +1,11 @@
+pub fn a() {}
+
+pub mod b {
+ pub mod c {
+ pub mod d {
+ pub mod e {
+ pub fn f() {}
+ }
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui-toml/absolute_paths/disallow_crates/clippy.toml b/src/tools/clippy/tests/ui-toml/absolute_paths/disallow_crates/clippy.toml
new file mode 100644
index 000000000..d44d648c6
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/absolute_paths/disallow_crates/clippy.toml
@@ -0,0 +1 @@
+absolute-paths-max-segments = 2
diff --git a/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr b/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr
index 6ec79a618..eb1180e60 100644
--- a/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr
+++ b/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr
@@ -30,7 +30,7 @@ LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64);
| ^^^
|
= note: `-D clippy::print-literal` implied by `-D warnings`
-help: try this
+help: try
|
LL - println!("Hello {} is {:.*}", "x", local_i32, local_f64);
LL + println!("Hello x is {:.*}", local_i32, local_f64);
diff --git a/src/tools/clippy/tests/ui-toml/excessive_nesting/auxiliary/proc_macros.rs b/src/tools/clippy/tests/ui-toml/excessive_nesting/auxiliary/proc_macros.rs
index ebadd4e44..60fbaaea3 100644
--- a/src/tools/clippy/tests/ui-toml/excessive_nesting/auxiliary/proc_macros.rs
+++ b/src/tools/clippy/tests/ui-toml/excessive_nesting/auxiliary/proc_macros.rs
@@ -7,13 +7,10 @@
extern crate proc_macro;
use core::mem;
-use proc_macro::{
- token_stream::IntoIter,
- Delimiter::{self, Brace, Parenthesis},
- Group, Ident, Literal, Punct,
- Spacing::{self, Alone, Joint},
- Span, TokenStream, TokenTree as TT,
-};
+use proc_macro::token_stream::IntoIter;
+use proc_macro::Delimiter::{self, Brace, Parenthesis};
+use proc_macro::Spacing::{self, Alone, Joint};
+use proc_macro::{Group, Ident, Literal, Punct, Span, TokenStream, TokenTree as TT};
type Result<T> = core::result::Result<T, TokenStream>;
diff --git a/src/tools/clippy/tests/ui-toml/expect_used/expect_used.stderr b/src/tools/clippy/tests/ui-toml/expect_used/expect_used.stderr
index 9eef0e1bf..815d00935 100644
--- a/src/tools/clippy/tests/ui-toml/expect_used/expect_used.stderr
+++ b/src/tools/clippy/tests/ui-toml/expect_used/expect_used.stderr
@@ -4,7 +4,7 @@ error: used `expect()` on an `Option` value
LL | let _ = opt.expect("");
| ^^^^^^^^^^^^^^
|
- = help: if this value is `None`, it will panic
+ = note: if this value is `None`, it will panic
= note: `-D clippy::expect-used` implied by `-D warnings`
error: used `expect()` on a `Result` value
@@ -13,7 +13,7 @@ error: used `expect()` on a `Result` value
LL | let _ = res.expect("");
| ^^^^^^^^^^^^^^
|
- = help: if this value is an `Err`, it will panic
+ = note: if this value is an `Err`, it will panic
error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.rs b/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.rs
index f267a67f4..78784bfff 100644
--- a/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.rs
+++ b/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.rs
@@ -2,6 +2,7 @@
//@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)"
#![warn(clippy::trivially_copy_pass_by_ref)]
+#![allow(clippy::needless_pass_by_ref_mut)]
#[derive(Copy, Clone)]
struct Foo(u8);
diff --git a/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.stderr b/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.stderr
index d2b55eff1..db5d68053 100644
--- a/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.stderr
+++ b/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.stderr
@@ -1,5 +1,5 @@
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/test.rs:14:11
+ --> $DIR/test.rs:15:11
|
LL | fn bad(x: &u16, y: &Foo) {}
| ^^^^ help: consider passing by value instead: `u16`
@@ -7,7 +7,7 @@ LL | fn bad(x: &u16, y: &Foo) {}
= note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/test.rs:14:20
+ --> $DIR/test.rs:15:20
|
LL | fn bad(x: &u16, y: &Foo) {}
| ^^^^ help: consider passing by value instead: `Foo`
diff --git a/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
index 6ba26e977..cdabe6460 100644
--- a/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
+++ b/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
@@ -1,4 +1,6 @@
error: error reading Clippy's configuration file: unknown field `foobar`, expected one of
+ absolute-paths-allowed-crates
+ absolute-paths-max-segments
accept-comment-above-attributes
accept-comment-above-statement
allow-dbg-in-tests
@@ -68,6 +70,8 @@ LL | foobar = 42
| ^^^^^^
error: error reading Clippy's configuration file: unknown field `barfoo`, expected one of
+ absolute-paths-allowed-crates
+ absolute-paths-max-segments
accept-comment-above-attributes
accept-comment-above-statement
allow-dbg-in-tests
diff --git a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs
index dde1c6d7c..e300ba18c 100644
--- a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs
+++ b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs
@@ -9,9 +9,7 @@
#![warn(clippy::unwrap_used)]
#![warn(clippy::get_unwrap)]
-use std::collections::BTreeMap;
-use std::collections::HashMap;
-use std::collections::VecDeque;
+use std::collections::{BTreeMap, HashMap, VecDeque};
struct GetFalsePositive {
arr: [u32; 3],
diff --git a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr
index eb66a5cf5..10219beaf 100644
--- a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr
+++ b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr
@@ -1,199 +1,212 @@
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:40:17
+ --> $DIR/unwrap_used.rs:38:17
|
LL | let _ = boxed_slice.get(1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&boxed_slice[1]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&boxed_slice[1]`
|
= note: `-D clippy::get-unwrap` implied by `-D warnings`
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_used.rs:40:17
+ --> $DIR/unwrap_used.rs:38:17
|
LL | let _ = 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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
= note: `-D clippy::unwrap-used` implied by `-D warnings`
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:41:17
+ --> $DIR/unwrap_used.rs:39:17
|
LL | let _ = some_slice.get(0).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_slice[0]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_slice[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_used.rs:41:17
+ --> $DIR/unwrap_used.rs:39:17
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:42:17
+ --> $DIR/unwrap_used.rs:40:17
|
LL | let _ = some_vec.get(0).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vec[0]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vec[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_used.rs:42:17
+ --> $DIR/unwrap_used.rs:40:17
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:43:17
+ --> $DIR/unwrap_used.rs:41:17
|
LL | let _ = some_vecdeque.get(0).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vecdeque[0]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vecdeque[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_used.rs:43:17
+ --> $DIR/unwrap_used.rs:41:17
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:44:17
+ --> $DIR/unwrap_used.rs:42:17
|
LL | let _ = some_hashmap.get(&1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_hashmap[&1]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_hashmap[&1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_used.rs:44:17
+ --> $DIR/unwrap_used.rs:42:17
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:45:17
+ --> $DIR/unwrap_used.rs:43:17
|
LL | let _ = some_btreemap.get(&1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_btreemap[&1]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_btreemap[&1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_used.rs:45:17
+ --> $DIR/unwrap_used.rs:43:17
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:49:21
+ --> $DIR/unwrap_used.rs:47:21
|
LL | let _: u8 = *boxed_slice.get(1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[1]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice[1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_used.rs:49:22
+ --> $DIR/unwrap_used.rs:47:22
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:54:9
+ --> $DIR/unwrap_used.rs:52:9
|
LL | *boxed_slice.get_mut(0).unwrap() = 1;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[0]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_used.rs:54:10
+ --> $DIR/unwrap_used.rs:52:10
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:55:9
+ --> $DIR/unwrap_used.rs:53:9
|
LL | *some_slice.get_mut(0).unwrap() = 1;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_slice[0]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_slice[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_used.rs:55:10
+ --> $DIR/unwrap_used.rs:53:10
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:56:9
+ --> $DIR/unwrap_used.rs:54:9
|
LL | *some_vec.get_mut(0).unwrap() = 1;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_used.rs:56:10
+ --> $DIR/unwrap_used.rs:54:10
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:57:9
+ --> $DIR/unwrap_used.rs:55:9
|
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vecdeque[0]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vecdeque[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_used.rs:57:10
+ --> $DIR/unwrap_used.rs:55:10
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:69:17
+ --> $DIR/unwrap_used.rs:67:17
|
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0..1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_used.rs:69:17
+ --> $DIR/unwrap_used.rs:67:17
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:70:17
+ --> $DIR/unwrap_used.rs:68:17
|
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0..1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_used.rs:70:17
+ --> $DIR/unwrap_used.rs:68: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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:77:13
+ --> $DIR/unwrap_used.rs:75:13
|
LL | let _ = boxed_slice.get(1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&boxed_slice[1]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&boxed_slice[1]`
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:95:17
+ --> $DIR/unwrap_used.rs:93:17
|
LL | let _ = Box::new([0]).get(1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&Box::new([0])[1]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&Box::new([0])[1]`
error: aborting due to 28 previous errors
diff --git a/src/tools/clippy/tests/ui/arc_with_non_send_sync.rs b/src/tools/clippy/tests/ui/arc_with_non_send_sync.rs
index b6fcca0a7..2940c2732 100644
--- a/src/tools/clippy/tests/ui/arc_with_non_send_sync.rs
+++ b/src/tools/clippy/tests/ui/arc_with_non_send_sync.rs
@@ -1,6 +1,12 @@
+//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::arc_with_non_send_sync)]
#![allow(unused_variables)]
+
+#[macro_use]
+extern crate proc_macros;
+
use std::cell::RefCell;
+use std::ptr::{null, null_mut};
use std::sync::{Arc, Mutex};
fn foo<T>(x: T) {
@@ -11,14 +17,32 @@ fn issue11076<T>() {
let a: Arc<Vec<T>> = Arc::new(Vec::new());
}
+fn issue11232() {
+ external! {
+ let a: Arc<*const u8> = Arc::new(null());
+ let a: Arc<*mut u8> = Arc::new(null_mut());
+ }
+ with_span! {
+ span
+ let a: Arc<*const u8> = Arc::new(null());
+ let a: Arc<*mut u8> = Arc::new(null_mut());
+ }
+}
+
fn main() {
let _ = Arc::new(42);
- // !Sync
let _ = Arc::new(RefCell::new(42));
+ //~^ ERROR: usage of an `Arc` that is not `Send` or `Sync`
+ //~| NOTE: the trait `Sync` is not implemented for `RefCell<i32>`
+
let mutex = Mutex::new(1);
- // !Send
let _ = Arc::new(mutex.lock().unwrap());
- // !Send + !Sync
+ //~^ ERROR: usage of an `Arc` that is not `Send` or `Sync`
+ //~| NOTE: the trait `Send` is not implemented for `MutexGuard<'_, i32>`
+
let _ = Arc::new(&42 as *const i32);
+ //~^ ERROR: usage of an `Arc` that is not `Send` or `Sync`
+ //~| NOTE: the trait `Send` is not implemented for `*const i32`
+ //~| NOTE: the trait `Sync` is not implemented for `*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
index 7633b38df..de3f2fb9e 100644
--- a/src/tools/clippy/tests/ui/arc_with_non_send_sync.stderr
+++ b/src/tools/clippy/tests/ui/arc_with_non_send_sync.stderr
@@ -1,5 +1,5 @@
error: usage of an `Arc` that is not `Send` or `Sync`
- --> $DIR/arc_with_non_send_sync.rs:18:13
+ --> $DIR/arc_with_non_send_sync.rs:35:13
|
LL | let _ = Arc::new(RefCell::new(42));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -10,7 +10,7 @@ LL | let _ = Arc::new(RefCell::new(42));
= 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
+ --> $DIR/arc_with_non_send_sync.rs:40:13
|
LL | let _ = Arc::new(mutex.lock().unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -20,7 +20,7 @@ LL | let _ = Arc::new(mutex.lock().unwrap());
= 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
+ --> $DIR/arc_with_non_send_sync.rs:44:13
|
LL | let _ = Arc::new(&42 as *const i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/arithmetic_side_effects.rs b/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
index 4f38e50c8..2ac2fa220 100644
--- a/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
+++ b/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
@@ -481,4 +481,16 @@ pub fn issue_10792() {
let _ = 10 / TWO.c;
}
+pub fn issue_11145() {
+ let mut x: Wrapping<u32> = Wrapping(0_u32);
+ x += 1;
+}
+
+pub fn issue_11262() {
+ let one = 1;
+ let zero = 0;
+ let _ = 2 / one;
+ let _ = 2 / zero;
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/as_conversions.rs b/src/tools/clippy/tests/ui/as_conversions.rs
index 427842a51..69f1c541c 100644
--- a/src/tools/clippy/tests/ui/as_conversions.rs
+++ b/src/tools/clippy/tests/ui/as_conversions.rs
@@ -4,8 +4,7 @@
#![allow(clippy::borrow_as_ptr, unused)]
extern crate proc_macros;
-use proc_macros::external;
-use proc_macros::with_span;
+use proc_macros::{external, with_span};
fn main() {
let i = 0u32 as u64;
diff --git a/src/tools/clippy/tests/ui/as_conversions.stderr b/src/tools/clippy/tests/ui/as_conversions.stderr
index ca41d1378..54037a649 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:11:13
+ --> $DIR/as_conversions.rs:10: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:13:13
+ --> $DIR/as_conversions.rs:12: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:13:13
+ --> $DIR/as_conversions.rs:12:13
|
LL | let j = &i as *const u64 as *mut u64;
| ^^^^^^^^^^^^^^^^
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 cab216b51..f20df6f0f 100644
--- a/src/tools/clippy/tests/ui/auxiliary/macro_use_helper.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/macro_use_helper.rs
@@ -15,8 +15,7 @@ pub mod inner {
// RE-EXPORT
// this will stick in `inner` module
- pub use macro_rules::mut_mut;
- pub use macro_rules::try_err;
+ pub use macro_rules::{mut_mut, try_err};
pub mod nested {
pub use macro_rules::string_add;
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 fdfe5fc41..c58795575 100644
--- a/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs
@@ -8,11 +8,11 @@ extern crate syn;
use proc_macro::TokenStream;
use quote::{quote, quote_spanned};
-use syn::parse_macro_input;
use syn::spanned::Spanned;
use syn::token::Star;
use syn::{
- parse_quote, FnArg, ImplItem, ItemImpl, ItemTrait, Lifetime, Pat, PatIdent, PatType, Signature, TraitItem, Type,
+ parse_macro_input, parse_quote, FnArg, ImplItem, ItemImpl, ItemTrait, Lifetime, Pat, PatIdent, PatType, Signature,
+ TraitItem, Type,
};
#[proc_macro_attribute]
diff --git a/src/tools/clippy/tests/ui/auxiliary/proc_macros.rs b/src/tools/clippy/tests/ui/auxiliary/proc_macros.rs
index 4d008c8cb..43df65438 100644
--- a/src/tools/clippy/tests/ui/auxiliary/proc_macros.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/proc_macros.rs
@@ -5,13 +5,10 @@
extern crate proc_macro;
use core::mem;
-use proc_macro::{
- token_stream::IntoIter,
- Delimiter::{self, Brace, Parenthesis},
- Group, Ident, Literal, Punct,
- Spacing::{self, Alone, Joint},
- Span, TokenStream, TokenTree as TT,
-};
+use proc_macro::token_stream::IntoIter;
+use proc_macro::Delimiter::{self, Brace, Parenthesis};
+use proc_macro::Spacing::{self, Alone, Joint};
+use proc_macro::{Group, Ident, Literal, Punct, Span, TokenStream, TokenTree as TT};
type Result<T> = core::result::Result<T, TokenStream>;
diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map.stderr b/src/tools/clippy/tests/ui/bind_instead_of_map.stderr
index b6a81d21b..f17fee746 100644
--- a/src/tools/clippy/tests/ui/bind_instead_of_map.stderr
+++ b/src/tools/clippy/tests/ui/bind_instead_of_map.stderr
@@ -14,7 +14,7 @@ error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed
--> $DIR/bind_instead_of_map.rs:10:13
|
LL | let _ = x.and_then(|o| Some(o + 1));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `x.map(|o| o + 1)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.map(|o| o + 1)`
error: using `Result.and_then(Ok)`, which is a no-op
--> $DIR/bind_instead_of_map.rs:16:13
diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.stderr b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.stderr
index 0152a93fe..cedbca785 100644
--- a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.stderr
+++ b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.stderr
@@ -9,7 +9,7 @@ note: the lint level is defined here
|
LL | #![deny(clippy::bind_instead_of_map)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
-help: try this
+help: try
|
LL | let _ = Some("42").map(|s| if s.len() < 42 { 0 } else { s.len() });
| ~~~ ~ ~~~~~~~
@@ -20,7 +20,7 @@ error: using `Result.and_then(|x| Ok(y))`, which is more succinctly expressed as
LL | let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Ok(0) } else { Ok(s.len()) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-help: try this
+help: try
|
LL | let _ = Ok::<_, ()>("42").map(|s| if s.len() < 42 { 0 } else { s.len() });
| ~~~ ~ ~~~~~~~
@@ -31,7 +31,7 @@ error: using `Result.or_else(|x| Err(y))`, which is more succinctly expressed as
LL | let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Err(s.len() + 20) } else { Err(s.len()) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-help: try this
+help: try
|
LL | let _ = Err::<(), _>("42").map_err(|s| if s.len() < 42 { s.len() + 20 } else { s.len() });
| ~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~
@@ -48,7 +48,7 @@ LL | | }
LL | | });
| |______^
|
-help: try this
+help: try
|
LL ~ Some("42").map(|s| {
LL | if {
@@ -82,7 +82,7 @@ error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed
LL | let _ = Some("").and_then(|s| if s.len() == 20 { Some(m!()) } else { Some(Some(20)) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-help: try this
+help: try
|
LL | let _ = Some("").map(|s| if s.len() == 20 { m!() } else { Some(20) });
| ~~~ ~~~~ ~~~~~~~~
diff --git a/src/tools/clippy/tests/ui/bool_comparison.fixed b/src/tools/clippy/tests/ui/bool_comparison.fixed
index d6774c035..8689f89d2 100644
--- a/src/tools/clippy/tests/ui/bool_comparison.fixed
+++ b/src/tools/clippy/tests/ui/bool_comparison.fixed
@@ -2,6 +2,7 @@
#![allow(clippy::needless_if)]
#![warn(clippy::bool_comparison)]
+#![allow(clippy::incorrect_partial_ord_impl_on_ord_type)]
fn main() {
let x = true;
diff --git a/src/tools/clippy/tests/ui/bool_comparison.rs b/src/tools/clippy/tests/ui/bool_comparison.rs
index c0483fd73..a1c94aff9 100644
--- a/src/tools/clippy/tests/ui/bool_comparison.rs
+++ b/src/tools/clippy/tests/ui/bool_comparison.rs
@@ -2,6 +2,7 @@
#![allow(clippy::needless_if)]
#![warn(clippy::bool_comparison)]
+#![allow(clippy::incorrect_partial_ord_impl_on_ord_type)]
fn main() {
let x = true;
diff --git a/src/tools/clippy/tests/ui/bool_comparison.stderr b/src/tools/clippy/tests/ui/bool_comparison.stderr
index f4dded365..19bdf3013 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:8:8
+ --> $DIR/bool_comparison.rs:9: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:13:8
+ --> $DIR/bool_comparison.rs:14:8
|
LL | if x == false {
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
error: equality checks against true are unnecessary
- --> $DIR/bool_comparison.rs:18:8
+ --> $DIR/bool_comparison.rs:19: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:23:8
+ --> $DIR/bool_comparison.rs:24: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:28:8
+ --> $DIR/bool_comparison.rs:29:8
|
LL | if x != true {
| ^^^^^^^^^ help: try simplifying it as shown: `!x`
error: inequality checks against false are unnecessary
- --> $DIR/bool_comparison.rs:33:8
+ --> $DIR/bool_comparison.rs:34: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:38:8
+ --> $DIR/bool_comparison.rs:39:8
|
LL | if true != x {
| ^^^^^^^^^ help: try simplifying it as shown: `!x`
error: inequality checks against false are unnecessary
- --> $DIR/bool_comparison.rs:43:8
+ --> $DIR/bool_comparison.rs:44: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:48:8
+ --> $DIR/bool_comparison.rs:49:8
|
LL | if x < true {
| ^^^^^^^^ help: try simplifying it as shown: `!x`
error: greater than checks against false are unnecessary
- --> $DIR/bool_comparison.rs:53:8
+ --> $DIR/bool_comparison.rs:54:8
|
LL | if false < x {
| ^^^^^^^^^ help: try simplifying it as shown: `x`
error: greater than checks against false are unnecessary
- --> $DIR/bool_comparison.rs:58:8
+ --> $DIR/bool_comparison.rs:59: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:63:8
+ --> $DIR/bool_comparison.rs:64:8
|
LL | if true > x {
| ^^^^^^^^ help: try simplifying it as shown: `!x`
error: order comparisons between booleans can be simplified
- --> $DIR/bool_comparison.rs:69:8
+ --> $DIR/bool_comparison.rs:70: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:74:8
+ --> $DIR/bool_comparison.rs:75: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: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:123:8
+ --> $DIR/bool_comparison.rs:124: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:127:8
+ --> $DIR/bool_comparison.rs:128: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:128:8
+ --> $DIR/bool_comparison.rs:129: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:152:8
+ --> $DIR/bool_comparison.rs:153: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:153:8
+ --> $DIR/bool_comparison.rs:154: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:154:8
+ --> $DIR/bool_comparison.rs:155: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:155:8
+ --> $DIR/bool_comparison.rs:156:8
|
LL | if m!(func) == true {}
| ^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `m!(func)`
diff --git a/src/tools/clippy/tests/ui/borrow_box.rs b/src/tools/clippy/tests/ui/borrow_box.rs
index 3b5b6bf4c..95b6b0f50 100644
--- a/src/tools/clippy/tests/ui/borrow_box.rs
+++ b/src/tools/clippy/tests/ui/borrow_box.rs
@@ -1,6 +1,10 @@
#![deny(clippy::borrowed_box)]
#![allow(dead_code, unused_variables)]
-#![allow(clippy::uninlined_format_args, clippy::disallowed_names)]
+#![allow(
+ clippy::uninlined_format_args,
+ clippy::disallowed_names,
+ clippy::needless_pass_by_ref_mut
+)]
use std::fmt::Display;
diff --git a/src/tools/clippy/tests/ui/borrow_box.stderr b/src/tools/clippy/tests/ui/borrow_box.stderr
index 99cb60a1e..90e752211 100644
--- a/src/tools/clippy/tests/ui/borrow_box.stderr
+++ b/src/tools/clippy/tests/ui/borrow_box.stderr
@@ -1,5 +1,5 @@
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:20:14
+ --> $DIR/borrow_box.rs:24:14
|
LL | let foo: &Box<bool>;
| ^^^^^^^^^^ help: try: `&bool`
@@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)]
| ^^^^^^^^^^^^^^^^^^^^
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:24:10
+ --> $DIR/borrow_box.rs:28:10
|
LL | foo: &'a Box<bool>,
| ^^^^^^^^^^^^^ help: try: `&'a bool`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:28:17
+ --> $DIR/borrow_box.rs:32:17
|
LL | fn test4(a: &Box<bool>);
| ^^^^^^^^^^ help: try: `&bool`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:94:25
+ --> $DIR/borrow_box.rs:98:25
|
LL | pub fn test14(_display: &Box<dyn Display>) {}
| ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:95:25
+ --> $DIR/borrow_box.rs:99:25
|
LL | pub fn test15(_display: &Box<dyn Display + Send>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:96:29
+ --> $DIR/borrow_box.rs:100:29
|
LL | pub fn test16<'a>(_display: &'a Box<dyn Display + 'a>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:98:25
+ --> $DIR/borrow_box.rs:102:25
|
LL | pub fn test17(_display: &Box<impl Display>) {}
| ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:99:25
+ --> $DIR/borrow_box.rs:103:25
|
LL | pub fn test18(_display: &Box<impl Display + Send>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:100:29
+ --> $DIR/borrow_box.rs:104:29
|
LL | pub fn test19<'a>(_display: &'a Box<impl Display + 'a>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:105:25
+ --> $DIR/borrow_box.rs:109:25
|
LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`
diff --git a/src/tools/clippy/tests/ui/comparison_to_empty.fixed b/src/tools/clippy/tests/ui/comparison_to_empty.fixed
index c92dd509e..af219eed0 100644
--- a/src/tools/clippy/tests/ui/comparison_to_empty.fixed
+++ b/src/tools/clippy/tests/ui/comparison_to_empty.fixed
@@ -1,7 +1,8 @@
//@run-rustfix
#![warn(clippy::comparison_to_empty)]
-#![allow(clippy::useless_vec)]
+#![allow(clippy::borrow_deref_ref, clippy::needless_if, clippy::useless_vec)]
+#![feature(let_chains)]
fn main() {
// Disallow comparisons to empty
@@ -12,6 +13,11 @@ fn main() {
let v = vec![0];
let _ = v.is_empty();
let _ = !v.is_empty();
+ if (*v).is_empty() {}
+ let s = [0].as_slice();
+ if s.is_empty() {}
+ if s.is_empty() {}
+ if s.is_empty() && s.is_empty() {}
// Allow comparisons to non-empty
let s = String::new();
@@ -21,4 +27,8 @@ fn main() {
let v = vec![0];
let _ = v == [0];
let _ = v != [0];
+ if let [0] = &*v {}
+ let s = [0].as_slice();
+ if let [0] = s {}
+ if let [0] = &*s && s == [0] {}
}
diff --git a/src/tools/clippy/tests/ui/comparison_to_empty.rs b/src/tools/clippy/tests/ui/comparison_to_empty.rs
index b34897143..21e65184d 100644
--- a/src/tools/clippy/tests/ui/comparison_to_empty.rs
+++ b/src/tools/clippy/tests/ui/comparison_to_empty.rs
@@ -1,7 +1,8 @@
//@run-rustfix
#![warn(clippy::comparison_to_empty)]
-#![allow(clippy::useless_vec)]
+#![allow(clippy::borrow_deref_ref, clippy::needless_if, clippy::useless_vec)]
+#![feature(let_chains)]
fn main() {
// Disallow comparisons to empty
@@ -12,6 +13,11 @@ fn main() {
let v = vec![0];
let _ = v == [];
let _ = v != [];
+ if let [] = &*v {}
+ let s = [0].as_slice();
+ if let [] = s {}
+ if let [] = &*s {}
+ if let [] = &*s && s == [] {}
// Allow comparisons to non-empty
let s = String::new();
@@ -21,4 +27,8 @@ fn main() {
let v = vec![0];
let _ = v == [0];
let _ = v != [0];
+ if let [0] = &*v {}
+ let s = [0].as_slice();
+ if let [0] = s {}
+ if let [0] = &*s && s == [0] {}
}
diff --git a/src/tools/clippy/tests/ui/comparison_to_empty.stderr b/src/tools/clippy/tests/ui/comparison_to_empty.stderr
index cc09b17eb..f29782ed8 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:9:13
+ --> $DIR/comparison_to_empty.rs:10:13
|
LL | let _ = s == "";
| ^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
@@ -7,22 +7,52 @@ LL | let _ = s == "";
= note: `-D clippy::comparison-to-empty` implied by `-D warnings`
error: comparison to empty slice
- --> $DIR/comparison_to_empty.rs:10:13
+ --> $DIR/comparison_to_empty.rs:11: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:13:13
+ --> $DIR/comparison_to_empty.rs:14: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:14:13
+ --> $DIR/comparison_to_empty.rs:15:13
|
LL | let _ = v != [];
| ^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!v.is_empty()`
-error: aborting due to 4 previous errors
+error: comparison to empty slice using `if let`
+ --> $DIR/comparison_to_empty.rs:16:8
+ |
+LL | if let [] = &*v {}
+ | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(*v).is_empty()`
+
+error: comparison to empty slice using `if let`
+ --> $DIR/comparison_to_empty.rs:18:8
+ |
+LL | if let [] = s {}
+ | ^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
+
+error: comparison to empty slice using `if let`
+ --> $DIR/comparison_to_empty.rs:19:8
+ |
+LL | if let [] = &*s {}
+ | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
+
+error: comparison to empty slice using `if let`
+ --> $DIR/comparison_to_empty.rs:20:8
+ |
+LL | if let [] = &*s && s == [] {}
+ | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
+
+error: comparison to empty slice
+ --> $DIR/comparison_to_empty.rs:20:24
+ |
+LL | if let [] = &*s && s == [] {}
+ | ^^^^^^^ help: using `is_empty` is clearer and more explicit: `s.is_empty()`
+
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/const_comparisons.rs b/src/tools/clippy/tests/ui/const_comparisons.rs
new file mode 100644
index 000000000..8e265c914
--- /dev/null
+++ b/src/tools/clippy/tests/ui/const_comparisons.rs
@@ -0,0 +1,93 @@
+#![allow(unused)]
+#![warn(clippy::impossible_comparisons)]
+#![warn(clippy::redundant_comparisons)]
+#![allow(clippy::no_effect)]
+#![allow(clippy::short_circuit_statement)]
+#![allow(clippy::manual_range_contains)]
+
+const STATUS_BAD_REQUEST: u16 = 400;
+const STATUS_SERVER_ERROR: u16 = 500;
+
+struct Status {
+ code: u16,
+}
+
+impl PartialEq<u16> for Status {
+ fn eq(&self, other: &u16) -> bool {
+ self.code == *other
+ }
+}
+
+impl PartialOrd<u16> for Status {
+ fn partial_cmp(&self, other: &u16) -> Option<std::cmp::Ordering> {
+ self.code.partial_cmp(other)
+ }
+}
+
+impl PartialEq<Status> for u16 {
+ fn eq(&self, other: &Status) -> bool {
+ *self == other.code
+ }
+}
+
+impl PartialOrd<Status> for u16 {
+ fn partial_cmp(&self, other: &Status) -> Option<std::cmp::Ordering> {
+ self.partial_cmp(&other.code)
+ }
+}
+
+fn main() {
+ let status_code = 500; // Value doesn't matter for the lint
+ let status = Status { code: status_code };
+
+ status_code >= 400 && status_code < 500; // Correct
+ status_code <= 400 && status_code > 500;
+ status_code > 500 && status_code < 400;
+ status_code < 500 && status_code > 500;
+
+ // More complex expressions
+ status_code < { 400 } && status_code > { 500 };
+ status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR;
+ status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR;
+ status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR;
+
+ // Comparing two different types, via the `impl PartialOrd<u16> for Status`
+ status < { 400 } && status > { 500 };
+ status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR;
+ status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR;
+ status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR;
+
+ // Yoda conditions
+ 500 <= status_code && 600 > status_code; // Correct
+ 500 <= status_code && status_code <= 600; // Correct
+ 500 >= status_code && 600 < status_code; // Incorrect
+ 500 >= status_code && status_code > 600; // Incorrect
+
+ // Yoda conditions, comparing two different types
+ 500 <= status && 600 > status; // Correct
+ 500 <= status && status <= 600; // Correct
+ 500 >= status && 600 < status; // Incorrect
+ 500 >= status && status > 600; // Incorrect
+
+ // Expressions where one of the sides has no effect
+ status_code < 200 && status_code <= 299;
+ status_code > 200 && status_code >= 299;
+
+ status_code >= 500 && status_code > 500; // Useless left
+ status_code > 500 && status_code >= 500; // Useless right
+ status_code <= 500 && status_code < 500; // Useless left
+ status_code < 500 && status_code <= 500; // Useless right
+
+ // Other types
+ let name = "Steve";
+ name < "Jennifer" && name > "Shannon";
+
+ let numbers = [1, 2];
+ numbers < [3, 4] && numbers > [5, 6];
+
+ let letter = 'a';
+ letter < 'b' && letter > 'c';
+
+ let area = 42.0;
+ area < std::f32::consts::E && area > std::f32::consts::PI;
+}
diff --git a/src/tools/clippy/tests/ui/const_comparisons.stderr b/src/tools/clippy/tests/ui/const_comparisons.stderr
new file mode 100644
index 000000000..90e6db647
--- /dev/null
+++ b/src/tools/clippy/tests/ui/const_comparisons.stderr
@@ -0,0 +1,228 @@
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:44:5
+ |
+LL | status_code <= 400 && status_code > 500;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `400` < `500`, the expression evaluates to false for any value of `status_code`
+ = note: `-D clippy::impossible-comparisons` implied by `-D warnings`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:45:5
+ |
+LL | status_code > 500 && status_code < 400;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `500` > `400`, the expression evaluates to false for any value of `status_code`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:46:5
+ |
+LL | status_code < 500 && status_code > 500;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `status_code` cannot simultaneously be greater than and less than `500`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:49:5
+ |
+LL | status_code < { 400 } && status_code > { 500 };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status_code`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:50:5
+ |
+LL | status_code < STATUS_BAD_REQUEST && status_code > STATUS_SERVER_ERROR;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:51:5
+ |
+LL | status_code <= u16::MIN + 1 && status_code > STATUS_SERVER_ERROR;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status_code`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:52:5
+ |
+LL | status_code < STATUS_SERVER_ERROR && status_code > STATUS_SERVER_ERROR;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `status_code` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:55:5
+ |
+LL | status < { 400 } && status > { 500 };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `{ 400 }` < `{ 500 }`, the expression evaluates to false for any value of `status`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:56:5
+ |
+LL | status < STATUS_BAD_REQUEST && status > STATUS_SERVER_ERROR;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `STATUS_BAD_REQUEST` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:57:5
+ |
+LL | status <= u16::MIN + 1 && status > STATUS_SERVER_ERROR;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `u16::MIN + 1` < `STATUS_SERVER_ERROR`, the expression evaluates to false for any value of `status`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:58:5
+ |
+LL | status < STATUS_SERVER_ERROR && status > STATUS_SERVER_ERROR;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `status` cannot simultaneously be greater than and less than `STATUS_SERVER_ERROR`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:63:5
+ |
+LL | 500 >= status_code && 600 < status_code; // Incorrect
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `500` < `600`, the expression evaluates to false for any value of `status_code`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:64:5
+ |
+LL | 500 >= status_code && status_code > 600; // Incorrect
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `500` < `600`, the expression evaluates to false for any value of `status_code`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:69:5
+ |
+LL | 500 >= status && 600 < status; // Incorrect
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `500` < `600`, the expression evaluates to false for any value of `status`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:70:5
+ |
+LL | 500 >= status && status > 600; // Incorrect
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `500` < `600`, the expression evaluates to false for any value of `status`
+
+error: right-hand side of `&&` operator has no effect
+ --> $DIR/const_comparisons.rs:73:5
+ |
+LL | status_code < 200 && status_code <= 299;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: `if `status_code < 200` evaluates to true, status_code <= 299` will always evaluate to true as well
+ --> $DIR/const_comparisons.rs:73:23
+ |
+LL | status_code < 200 && status_code <= 299;
+ | ^^^^^^^^^^^^^^^^^^^^^
+ = note: `-D clippy::redundant-comparisons` implied by `-D warnings`
+
+error: left-hand side of `&&` operator has no effect
+ --> $DIR/const_comparisons.rs:74:5
+ |
+LL | status_code > 200 && status_code >= 299;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: `if `status_code >= 299` evaluates to true, status_code > 200` will always evaluate to true as well
+ --> $DIR/const_comparisons.rs:74:5
+ |
+LL | status_code > 200 && status_code >= 299;
+ | ^^^^^^^^^^^^^^^^^^^^^
+
+error: left-hand side of `&&` operator has no effect
+ --> $DIR/const_comparisons.rs:76:5
+ |
+LL | status_code >= 500 && status_code > 500; // Useless left
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well
+ --> $DIR/const_comparisons.rs:76:5
+ |
+LL | status_code >= 500 && status_code > 500; // Useless left
+ | ^^^^^^^^^^^^^^^^^^^^^^
+
+error: right-hand side of `&&` operator has no effect
+ --> $DIR/const_comparisons.rs:77:5
+ |
+LL | status_code > 500 && status_code >= 500; // Useless right
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: `if `status_code > 500` evaluates to true, status_code >= 500` will always evaluate to true as well
+ --> $DIR/const_comparisons.rs:77:23
+ |
+LL | status_code > 500 && status_code >= 500; // Useless right
+ | ^^^^^^^^^^^^^^^^^^^^^
+
+error: left-hand side of `&&` operator has no effect
+ --> $DIR/const_comparisons.rs:78:5
+ |
+LL | status_code <= 500 && status_code < 500; // Useless left
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well
+ --> $DIR/const_comparisons.rs:78:5
+ |
+LL | status_code <= 500 && status_code < 500; // Useless left
+ | ^^^^^^^^^^^^^^^^^^^^^^
+
+error: right-hand side of `&&` operator has no effect
+ --> $DIR/const_comparisons.rs:79:5
+ |
+LL | status_code < 500 && status_code <= 500; // Useless right
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: `if `status_code < 500` evaluates to true, status_code <= 500` will always evaluate to true as well
+ --> $DIR/const_comparisons.rs:79:23
+ |
+LL | status_code < 500 && status_code <= 500; // Useless right
+ | ^^^^^^^^^^^^^^^^^^^^^
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:83:5
+ |
+LL | name < "Jennifer" && name > "Shannon";
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `"Jennifer"` < `"Shannon"`, the expression evaluates to false for any value of `name`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:86:5
+ |
+LL | numbers < [3, 4] && numbers > [5, 6];
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `[3, 4]` < `[5, 6]`, the expression evaluates to false for any value of `numbers`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:89:5
+ |
+LL | letter < 'b' && letter > 'c';
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `'b'` < `'c'`, the expression evaluates to false for any value of `letter`
+
+error: boolean expression will never evaluate to 'true'
+ --> $DIR/const_comparisons.rs:92:5
+ |
+LL | area < std::f32::consts::E && area > std::f32::consts::PI;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: since `std::f32::consts::E` < `std::f32::consts::PI`, the expression evaluates to false for any value of `area`
+
+error: aborting due to 25 previous errors
+
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6256.rs b/src/tools/clippy/tests/ui/crashes/ice-6256.rs
index 1d336b3cd..bb488c2dc 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6256.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-6256.rs
@@ -1,5 +1,5 @@
// originally from rustc ./tests/ui/regions/issue-78262.rs
-// ICE: to get the signature of a closure, use substs.as_closure().sig() not fn_sig()
+// ICE: to get the signature of a closure, use args.as_closure().sig() not fn_sig()
#![allow(clippy::upper_case_acronyms)]
trait TT {}
diff --git a/src/tools/clippy/tests/ui/crashes/ice-7169.stderr b/src/tools/clippy/tests/ui/crashes/ice-7169.stderr
index 84e0af3f0..0cd028516 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-7169.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-7169.stderr
@@ -2,7 +2,7 @@ error: redundant pattern matching, consider using `is_ok()`
--> $DIR/ice-7169.rs:10:12
|
LL | if let Ok(_) = Ok::<_, ()>(A::<String>::default()) {}
- | -------^^^^^-------------------------------------- help: try this: `if Ok::<_, ()>(A::<String>::default()).is_ok()`
+ | -------^^^^^-------------------------------------- help: try: `if Ok::<_, ()>(A::<String>::default()).is_ok()`
|
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
diff --git a/src/tools/clippy/tests/ui/crashes/ice-8250.stderr b/src/tools/clippy/tests/ui/crashes/ice-8250.stderr
index 8ed8f3b3a..e6f3644ef 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-8250.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-8250.stderr
@@ -2,7 +2,7 @@ error: unnecessary use of `splitn`
--> $DIR/ice-8250.rs:2:13
|
LL | let _ = s[1..].splitn(2, '.').next()?;
- | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s[1..].split('.')`
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `s[1..].split('.')`
|
= note: `-D clippy::needless-splitn` implied by `-D warnings`
diff --git a/src/tools/clippy/tests/ui/default_trait_access.fixed b/src/tools/clippy/tests/ui/default_trait_access.fixed
index 14eb6d572..6e541473c 100644
--- a/src/tools/clippy/tests/ui/default_trait_access.fixed
+++ b/src/tools/clippy/tests/ui/default_trait_access.fixed
@@ -7,9 +7,8 @@
extern crate proc_macros;
use proc_macros::with_span;
-use std::default;
use std::default::Default as D2;
-use std::string;
+use std::{default, string};
fn main() {
let s1: String = String::default();
diff --git a/src/tools/clippy/tests/ui/default_trait_access.rs b/src/tools/clippy/tests/ui/default_trait_access.rs
index aa2ced0a7..2ffeb32fb 100644
--- a/src/tools/clippy/tests/ui/default_trait_access.rs
+++ b/src/tools/clippy/tests/ui/default_trait_access.rs
@@ -7,9 +7,8 @@
extern crate proc_macros;
use proc_macros::with_span;
-use std::default;
use std::default::Default as D2;
-use std::string;
+use std::{default, string};
fn main() {
let s1: String = Default::default();
diff --git a/src/tools/clippy/tests/ui/default_trait_access.stderr b/src/tools/clippy/tests/ui/default_trait_access.stderr
index e4f73c08d..103fccf6a 100644
--- a/src/tools/clippy/tests/ui/default_trait_access.stderr
+++ b/src/tools/clippy/tests/ui/default_trait_access.stderr
@@ -1,5 +1,5 @@
error: calling `String::default()` is more clear than this expression
- --> $DIR/default_trait_access.rs:15:22
+ --> $DIR/default_trait_access.rs:14:22
|
LL | let s1: String = Default::default();
| ^^^^^^^^^^^^^^^^^^ help: try: `String::default()`
@@ -11,43 +11,43 @@ LL | #![deny(clippy::default_trait_access)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: calling `String::default()` is more clear than this expression
- --> $DIR/default_trait_access.rs:19:22
+ --> $DIR/default_trait_access.rs:18:22
|
LL | let s3: String = D2::default();
| ^^^^^^^^^^^^^ help: try: `String::default()`
error: calling `String::default()` is more clear than this expression
- --> $DIR/default_trait_access.rs:21:22
+ --> $DIR/default_trait_access.rs:20:22
|
LL | let s4: String = std::default::Default::default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `String::default()`
error: calling `String::default()` is more clear than this expression
- --> $DIR/default_trait_access.rs:25:22
+ --> $DIR/default_trait_access.rs:24:22
|
LL | let s6: String = default::Default::default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `String::default()`
error: calling `GenericDerivedDefault::default()` is more clear than this expression
- --> $DIR/default_trait_access.rs:35:46
+ --> $DIR/default_trait_access.rs:34:46
|
LL | let s11: GenericDerivedDefault<String> = Default::default();
| ^^^^^^^^^^^^^^^^^^ help: try: `GenericDerivedDefault::default()`
error: calling `TupleDerivedDefault::default()` is more clear than this expression
- --> $DIR/default_trait_access.rs:41:36
+ --> $DIR/default_trait_access.rs:40:36
|
LL | let s14: TupleDerivedDefault = Default::default();
| ^^^^^^^^^^^^^^^^^^ help: try: `TupleDerivedDefault::default()`
error: calling `ArrayDerivedDefault::default()` is more clear than this expression
- --> $DIR/default_trait_access.rs:43:36
+ --> $DIR/default_trait_access.rs:42:36
|
LL | let s15: ArrayDerivedDefault = Default::default();
| ^^^^^^^^^^^^^^^^^^ help: try: `ArrayDerivedDefault::default()`
error: calling `TupleStructDerivedDefault::default()` is more clear than this expression
- --> $DIR/default_trait_access.rs:47:42
+ --> $DIR/default_trait_access.rs:46:42
|
LL | let s17: TupleStructDerivedDefault = Default::default();
| ^^^^^^^^^^^^^^^^^^ help: try: `TupleStructDerivedDefault::default()`
diff --git a/src/tools/clippy/tests/ui/deref_addrof.stderr b/src/tools/clippy/tests/ui/deref_addrof.stderr
index e0287522f..9dd1e246b 100644
--- a/src/tools/clippy/tests/ui/deref_addrof.stderr
+++ b/src/tools/clippy/tests/ui/deref_addrof.stderr
@@ -2,7 +2,7 @@ error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:24:13
|
LL | let b = *&a;
- | ^^^ help: try this: `a`
+ | ^^^ help: try: `a`
|
= note: `-D clippy::deref-addrof` implied by `-D warnings`
@@ -10,49 +10,49 @@ error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:26:13
|
LL | let b = *&get_number();
- | ^^^^^^^^^^^^^^ help: try this: `get_number()`
+ | ^^^^^^^^^^^^^^ help: try: `get_number()`
error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:31:13
|
LL | let b = *&bytes[1..2][0];
- | ^^^^^^^^^^^^^^^^ help: try this: `bytes[1..2][0]`
+ | ^^^^^^^^^^^^^^^^ help: try: `bytes[1..2][0]`
error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:35:13
|
LL | let b = *&(a);
- | ^^^^^ help: try this: `(a)`
+ | ^^^^^ help: try: `(a)`
error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:37:13
|
LL | let b = *(&a);
- | ^^^^^ help: try this: `a`
+ | ^^^^^ help: try: `a`
error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:40:13
|
LL | let b = *((&a));
- | ^^^^^^^ help: try this: `a`
+ | ^^^^^^^ help: try: `a`
error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:42:13
|
LL | let b = *&&a;
- | ^^^^ help: try this: `&a`
+ | ^^^^ help: try: `&a`
error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:44:14
|
LL | let b = **&aref;
- | ^^^^^^ help: try this: `aref`
+ | ^^^^^^ help: try: `aref`
error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:54:17
|
LL | inline!(*& $(@expr self))
- | ^^^^^^^^^^^^^^^^ help: try this: `$(@expr self)`
+ | ^^^^^^^^^^^^^^^^ help: try: `$(@expr self)`
|
= note: this error originates in the macro `__inline_mac_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -60,7 +60,7 @@ error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:58:17
|
LL | inline!(*&mut $(@expr self))
- | ^^^^^^^^^^^^^^^^^^^ help: try this: `$(@expr self)`
+ | ^^^^^^^^^^^^^^^^^^^ help: try: `$(@expr self)`
|
= note: this error originates in the macro `__inline_mac_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/src/tools/clippy/tests/ui/deref_addrof_double_trigger.stderr b/src/tools/clippy/tests/ui/deref_addrof_double_trigger.stderr
index 2c55a4ed6..6fa5069b6 100644
--- a/src/tools/clippy/tests/ui/deref_addrof_double_trigger.stderr
+++ b/src/tools/clippy/tests/ui/deref_addrof_double_trigger.stderr
@@ -2,7 +2,7 @@ error: immediately dereferencing a reference
--> $DIR/deref_addrof_double_trigger.rs:10:14
|
LL | let b = **&&a;
- | ^^^^ help: try this: `&a`
+ | ^^^^ help: try: `&a`
|
= note: `-D clippy::deref-addrof` implied by `-D warnings`
@@ -10,13 +10,13 @@ error: immediately dereferencing a reference
--> $DIR/deref_addrof_double_trigger.rs:14:17
|
LL | let y = *&mut x;
- | ^^^^^^^ help: try this: `x`
+ | ^^^^^^^ help: try: `x`
error: immediately dereferencing a reference
--> $DIR/deref_addrof_double_trigger.rs:21:18
|
LL | let y = **&mut &mut x;
- | ^^^^^^^^^^^^ help: try this: `&mut x`
+ | ^^^^^^^^^^^^ help: try: `&mut x`
error: aborting due to 3 previous errors
diff --git a/src/tools/clippy/tests/ui/derive.rs b/src/tools/clippy/tests/ui/derive.rs
index e01079bc9..c76711312 100644
--- a/src/tools/clippy/tests/ui/derive.rs
+++ b/src/tools/clippy/tests/ui/derive.rs
@@ -1,4 +1,8 @@
-#![allow(clippy::incorrect_clone_impl_on_copy_type, dead_code)]
+#![allow(
+ clippy::incorrect_clone_impl_on_copy_type,
+ clippy::incorrect_partial_ord_impl_on_ord_type,
+ dead_code
+)]
#![warn(clippy::expl_impl_clone_on_copy)]
diff --git a/src/tools/clippy/tests/ui/derive.stderr b/src/tools/clippy/tests/ui/derive.stderr
index e1fbb8dcd..5d7ed0918 100644
--- a/src/tools/clippy/tests/ui/derive.stderr
+++ b/src/tools/clippy/tests/ui/derive.stderr
@@ -1,5 +1,5 @@
error: you are implementing `Clone` explicitly on a `Copy` type
- --> $DIR/derive.rs:8:1
+ --> $DIR/derive.rs:12:1
|
LL | / impl Clone for Qux {
LL | | fn clone(&self) -> Self {
@@ -9,7 +9,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
- --> $DIR/derive.rs:8:1
+ --> $DIR/derive.rs:12:1
|
LL | / impl Clone for Qux {
LL | | fn clone(&self) -> Self {
@@ -20,7 +20,7 @@ LL | | }
= note: `-D clippy::expl-impl-clone-on-copy` implied by `-D warnings`
error: you are implementing `Clone` explicitly on a `Copy` type
- --> $DIR/derive.rs:32:1
+ --> $DIR/derive.rs:36:1
|
LL | / impl<'a> Clone for Lt<'a> {
LL | | fn clone(&self) -> Self {
@@ -30,7 +30,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
- --> $DIR/derive.rs:32:1
+ --> $DIR/derive.rs:36:1
|
LL | / impl<'a> Clone for Lt<'a> {
LL | | fn clone(&self) -> Self {
@@ -40,7 +40,7 @@ LL | | }
| |_^
error: you are implementing `Clone` explicitly on a `Copy` type
- --> $DIR/derive.rs:43:1
+ --> $DIR/derive.rs:47:1
|
LL | / impl Clone for BigArray {
LL | | fn clone(&self) -> Self {
@@ -50,7 +50,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
- --> $DIR/derive.rs:43:1
+ --> $DIR/derive.rs:47:1
|
LL | / impl Clone for BigArray {
LL | | fn clone(&self) -> Self {
@@ -60,7 +60,7 @@ LL | | }
| |_^
error: you are implementing `Clone` explicitly on a `Copy` type
- --> $DIR/derive.rs:54:1
+ --> $DIR/derive.rs:58:1
|
LL | / impl Clone for FnPtr {
LL | | fn clone(&self) -> Self {
@@ -70,7 +70,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
- --> $DIR/derive.rs:54:1
+ --> $DIR/derive.rs:58:1
|
LL | / impl Clone for FnPtr {
LL | | fn clone(&self) -> Self {
@@ -80,7 +80,7 @@ LL | | }
| |_^
error: you are implementing `Clone` explicitly on a `Copy` type
- --> $DIR/derive.rs:74:1
+ --> $DIR/derive.rs:78:1
|
LL | / impl<T: Clone> Clone for Generic2<T> {
LL | | fn clone(&self) -> Self {
@@ -90,7 +90,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
- --> $DIR/derive.rs:74:1
+ --> $DIR/derive.rs:78:1
|
LL | / impl<T: Clone> Clone for Generic2<T> {
LL | | fn clone(&self) -> Self {
diff --git a/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.rs b/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.rs
index 6f12d36d7..1fb3d51c4 100644
--- a/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.rs
+++ b/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.rs
@@ -1,5 +1,6 @@
#![warn(clippy::derive_ord_xor_partial_ord)]
#![allow(clippy::unnecessary_wraps)]
+#![allow(clippy::incorrect_partial_ord_impl_on_ord_type)]
use std::cmp::Ordering;
diff --git a/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr b/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr
index 58efbb854..bd1488348 100644
--- a/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr
+++ b/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr
@@ -1,11 +1,11 @@
error: you are deriving `Ord` but have implemented `PartialOrd` explicitly
- --> $DIR/derive_ord_xor_partial_ord.rs:21:10
+ --> $DIR/derive_ord_xor_partial_ord.rs:22:10
|
LL | #[derive(Ord, PartialEq, Eq)]
| ^^^
|
note: `PartialOrd` implemented here
- --> $DIR/derive_ord_xor_partial_ord.rs:24:1
+ --> $DIR/derive_ord_xor_partial_ord.rs:25:1
|
LL | impl PartialOrd for DeriveOrd {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -13,20 +13,20 @@ LL | impl PartialOrd for DeriveOrd {
= note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info)
error: you are deriving `Ord` but have implemented `PartialOrd` explicitly
- --> $DIR/derive_ord_xor_partial_ord.rs:30:10
+ --> $DIR/derive_ord_xor_partial_ord.rs:31:10
|
LL | #[derive(Ord, PartialEq, Eq)]
| ^^^
|
note: `PartialOrd` implemented here
- --> $DIR/derive_ord_xor_partial_ord.rs:33:1
+ --> $DIR/derive_ord_xor_partial_ord.rs:34:1
|
LL | impl PartialOrd<DeriveOrdWithExplicitTypeVariable> for DeriveOrdWithExplicitTypeVariable {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info)
error: you are implementing `Ord` explicitly but have derived `PartialOrd`
- --> $DIR/derive_ord_xor_partial_ord.rs:42:1
+ --> $DIR/derive_ord_xor_partial_ord.rs:43:1
|
LL | / impl std::cmp::Ord for DerivePartialOrd {
LL | | fn cmp(&self, other: &Self) -> Ordering {
@@ -36,14 +36,14 @@ LL | | }
| |_^
|
note: `PartialOrd` implemented here
- --> $DIR/derive_ord_xor_partial_ord.rs:39:10
+ --> $DIR/derive_ord_xor_partial_ord.rs:40:10
|
LL | #[derive(PartialOrd, PartialEq, Eq)]
| ^^^^^^^^^^
= note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info)
error: you are implementing `Ord` explicitly but have derived `PartialOrd`
- --> $DIR/derive_ord_xor_partial_ord.rs:62:5
+ --> $DIR/derive_ord_xor_partial_ord.rs:63:5
|
LL | / impl Ord for DerivePartialOrdInUseOrd {
LL | | fn cmp(&self, other: &Self) -> Ordering {
@@ -53,7 +53,7 @@ LL | | }
| |_____^
|
note: `PartialOrd` implemented here
- --> $DIR/derive_ord_xor_partial_ord.rs:59:14
+ --> $DIR/derive_ord_xor_partial_ord.rs:60:14
|
LL | #[derive(PartialOrd, PartialEq, Eq)]
| ^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/entry.stderr b/src/tools/clippy/tests/ui/entry.stderr
index 2c4c49d25..e8a003e9c 100644
--- a/src/tools/clippy/tests/ui/entry.stderr
+++ b/src/tools/clippy/tests/ui/entry.stderr
@@ -4,7 +4,7 @@ error: usage of `contains_key` followed by `insert` on a `HashMap`
LL | / if !m.contains_key(&k) {
LL | | m.insert(k, v);
LL | | }
- | |_____^ help: try this: `m.entry(k).or_insert(v);`
+ | |_____^ help: try: `m.entry(k).or_insert(v);`
|
= note: `-D clippy::map-entry` implied by `-D warnings`
@@ -20,7 +20,7 @@ LL | | }
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ m.entry(k).or_insert_with(|| {
LL + if true {
@@ -43,7 +43,7 @@ LL | | };
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ m.entry(k).or_insert_with(|| {
LL + if true {
@@ -66,7 +66,7 @@ LL | | }
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) {
LL + if true {
@@ -87,7 +87,7 @@ LL | | m.insert(k, v);
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ m.entry(k).or_insert_with(|| {
LL + foo();
@@ -107,7 +107,7 @@ LL | | };
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ m.entry(k).or_insert_with(|| {
LL + match 0 {
@@ -133,7 +133,7 @@ LL | | };
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) {
LL + match 0 {
@@ -157,7 +157,7 @@ LL | | }
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ m.entry(k).or_insert_with(|| {
LL + foo();
@@ -192,7 +192,7 @@ error: usage of `contains_key` followed by `insert` on a `HashMap`
LL | / if !m.contains_key(&m!(k)) {
LL | | m.insert(m!(k), m!(v));
LL | | }
- | |_____^ help: try this: `m.entry(m!(k)).or_insert_with(|| m!(v));`
+ | |_____^ help: try: `m.entry(m!(k)).or_insert_with(|| m!(v));`
error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:152:5
@@ -204,7 +204,7 @@ LL | | m.insert(k, v);
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ m.entry(k).or_insert_with(|| {
LL + let x = (String::new(), String::new());
diff --git a/src/tools/clippy/tests/ui/entry_btree.stderr b/src/tools/clippy/tests/ui/entry_btree.stderr
index 5c6fcdf1a..8f41581d6 100644
--- a/src/tools/clippy/tests/ui/entry_btree.stderr
+++ b/src/tools/clippy/tests/ui/entry_btree.stderr
@@ -8,7 +8,7 @@ LL | | }
| |_____^
|
= note: `-D clippy::map-entry` implied by `-D warnings`
-help: try this
+help: try
|
LL ~ if let std::collections::btree_map::Entry::Vacant(e) = m.entry(k) {
LL + e.insert(v);
diff --git a/src/tools/clippy/tests/ui/entry_with_else.stderr b/src/tools/clippy/tests/ui/entry_with_else.stderr
index e0f6671b4..0d0eb9649 100644
--- a/src/tools/clippy/tests/ui/entry_with_else.stderr
+++ b/src/tools/clippy/tests/ui/entry_with_else.stderr
@@ -9,7 +9,7 @@ LL | | }
| |_____^
|
= note: `-D clippy::map-entry` implied by `-D warnings`
-help: try this
+help: try
|
LL ~ match m.entry(k) {
LL + std::collections::hash_map::Entry::Vacant(e) => {
@@ -31,7 +31,7 @@ LL | | m.insert(k, v2);
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ match m.entry(k) {
LL + std::collections::hash_map::Entry::Occupied(mut e) => {
@@ -53,7 +53,7 @@ LL | | foo();
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ if let std::collections::hash_map::Entry::Vacant(e) = m.entry(k) {
LL + e.insert(v);
@@ -72,7 +72,7 @@ LL | | m.insert(k, v);
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) {
LL + e.insert(v);
@@ -91,7 +91,7 @@ LL | | m.insert(k, v2);
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ match m.entry(k) {
LL + std::collections::hash_map::Entry::Vacant(e) => {
@@ -113,7 +113,7 @@ LL | | m.insert(k, v)
LL | | };
| |_____^
|
-help: try this
+help: try
|
LL ~ match m.entry(k) {
LL + std::collections::hash_map::Entry::Occupied(mut e) => {
@@ -137,7 +137,7 @@ LL | | None
LL | | };
| |_____^
|
-help: try this
+help: try
|
LL ~ if let std::collections::hash_map::Entry::Occupied(mut e) = m.entry(k) {
LL + foo();
diff --git a/src/tools/clippy/tests/ui/error_impl_error.rs b/src/tools/clippy/tests/ui/error_impl_error.rs
new file mode 100644
index 000000000..40ce4181b
--- /dev/null
+++ b/src/tools/clippy/tests/ui/error_impl_error.rs
@@ -0,0 +1,90 @@
+#![allow(unused)]
+#![warn(clippy::error_impl_error)]
+#![no_main]
+
+pub mod a {
+ #[derive(Debug)]
+ pub struct Error;
+
+ impl std::fmt::Display for Error {
+ fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ todo!()
+ }
+ }
+
+ impl std::error::Error for Error {}
+}
+
+mod b {
+ #[derive(Debug)]
+ pub(super) enum Error {}
+
+ impl std::fmt::Display for Error {
+ fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ todo!()
+ }
+ }
+
+ impl std::error::Error for Error {}
+}
+
+pub mod c {
+ pub union Error {
+ a: u32,
+ b: u32,
+ }
+
+ impl std::fmt::Debug for Error {
+ fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ todo!()
+ }
+ }
+
+ impl std::fmt::Display for Error {
+ fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ todo!()
+ }
+ }
+
+ impl std::error::Error for Error {}
+}
+
+pub mod d {
+ pub type Error = std::fmt::Error;
+}
+
+mod e {
+ #[derive(Debug)]
+ pub(super) struct MyError;
+
+ impl std::fmt::Display for MyError {
+ fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ todo!()
+ }
+ }
+
+ impl std::error::Error for MyError {}
+}
+
+pub mod f {
+ pub type MyError = std::fmt::Error;
+}
+
+// Do not lint module-private types
+
+mod g {
+ #[derive(Debug)]
+ enum Error {}
+
+ impl std::fmt::Display for Error {
+ fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ todo!()
+ }
+ }
+
+ impl std::error::Error for Error {}
+}
+
+mod h {
+ type Error = std::fmt::Error;
+}
diff --git a/src/tools/clippy/tests/ui/error_impl_error.stderr b/src/tools/clippy/tests/ui/error_impl_error.stderr
new file mode 100644
index 000000000..f3e04b641
--- /dev/null
+++ b/src/tools/clippy/tests/ui/error_impl_error.stderr
@@ -0,0 +1,45 @@
+error: exported type named `Error` that implements `Error`
+ --> $DIR/error_impl_error.rs:7:16
+ |
+LL | pub struct Error;
+ | ^^^^^
+ |
+note: `Error` was implemented here
+ --> $DIR/error_impl_error.rs:15:5
+ |
+LL | impl std::error::Error for Error {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: `-D clippy::error-impl-error` implied by `-D warnings`
+
+error: exported type named `Error` that implements `Error`
+ --> $DIR/error_impl_error.rs:20:21
+ |
+LL | pub(super) enum Error {}
+ | ^^^^^
+ |
+note: `Error` was implemented here
+ --> $DIR/error_impl_error.rs:28:5
+ |
+LL | impl std::error::Error for Error {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: exported type named `Error` that implements `Error`
+ --> $DIR/error_impl_error.rs:32:15
+ |
+LL | pub union Error {
+ | ^^^^^
+ |
+note: `Error` was implemented here
+ --> $DIR/error_impl_error.rs:49:5
+ |
+LL | impl std::error::Error for Error {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: exported type alias named `Error` that implements `Error`
+ --> $DIR/error_impl_error.rs:53:14
+ |
+LL | pub type Error = std::fmt::Error;
+ | ^^^^^
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui/eta.fixed b/src/tools/clippy/tests/ui/eta.fixed
index bf44bcb56..ddabe7616 100644
--- a/src/tools/clippy/tests/ui/eta.fixed
+++ b/src/tools/clippy/tests/ui/eta.fixed
@@ -331,7 +331,7 @@ impl dyn TestTrait + '_ {
}
// https://github.com/rust-lang/rust-clippy/issues/7746
-fn angle_brackets_and_substs() {
+fn angle_brackets_and_args() {
let array_opt: Option<&[u8; 3]> = Some(&[4, 8, 7]);
array_opt.map(<[u8; 3]>::as_slice);
@@ -345,3 +345,58 @@ fn angle_brackets_and_substs() {
let dyn_opt: Option<&dyn TestTrait> = Some(&test_struct);
dyn_opt.map(<dyn TestTrait>::method_on_dyn);
}
+
+fn _late_bound_to_early_bound_regions() {
+ struct Foo<'a>(&'a u32);
+ impl<'a> Foo<'a> {
+ fn f(x: &'a u32) -> Self {
+ Foo(x)
+ }
+ }
+ fn f(f: impl for<'a> Fn(&'a u32) -> Foo<'a>) -> Foo<'static> {
+ f(&0)
+ }
+
+ let _ = f(|x| Foo::f(x));
+
+ struct Bar;
+ impl<'a> From<&'a u32> for Bar {
+ fn from(x: &'a u32) -> Bar {
+ Bar
+ }
+ }
+ fn f2(f: impl for<'a> Fn(&'a u32) -> Bar) -> Bar {
+ f(&0)
+ }
+
+ let _ = f2(|x| <Bar>::from(x));
+
+ struct Baz<'a>(&'a u32);
+ fn f3(f: impl Fn(&u32) -> Baz<'_>) -> Baz<'static> {
+ f(&0)
+ }
+
+ let _ = f3(|x| Baz(x));
+}
+
+fn _mixed_late_bound_and_early_bound_regions() {
+ fn f<T>(t: T, f: impl Fn(T, &u32) -> u32) -> u32 {
+ f(t, &0)
+ }
+ fn f2<'a, T: 'a>(_: &'a T, y: &u32) -> u32 {
+ *y
+ }
+ let _ = f(&0, f2);
+}
+
+fn _closure_with_types() {
+ fn f<T>(x: T) -> T {
+ x
+ }
+ fn f2<T: Default>(f: impl Fn(T) -> T) -> T {
+ f(T::default())
+ }
+
+ let _ = f2(|x: u32| f(x));
+ let _ = f2(|x| -> u32 { f(x) });
+}
diff --git a/src/tools/clippy/tests/ui/eta.rs b/src/tools/clippy/tests/ui/eta.rs
index b2af4bf09..92ecff6eb 100644
--- a/src/tools/clippy/tests/ui/eta.rs
+++ b/src/tools/clippy/tests/ui/eta.rs
@@ -331,7 +331,7 @@ impl dyn TestTrait + '_ {
}
// https://github.com/rust-lang/rust-clippy/issues/7746
-fn angle_brackets_and_substs() {
+fn angle_brackets_and_args() {
let array_opt: Option<&[u8; 3]> = Some(&[4, 8, 7]);
array_opt.map(|a| a.as_slice());
@@ -345,3 +345,58 @@ fn angle_brackets_and_substs() {
let dyn_opt: Option<&dyn TestTrait> = Some(&test_struct);
dyn_opt.map(|d| d.method_on_dyn());
}
+
+fn _late_bound_to_early_bound_regions() {
+ struct Foo<'a>(&'a u32);
+ impl<'a> Foo<'a> {
+ fn f(x: &'a u32) -> Self {
+ Foo(x)
+ }
+ }
+ fn f(f: impl for<'a> Fn(&'a u32) -> Foo<'a>) -> Foo<'static> {
+ f(&0)
+ }
+
+ let _ = f(|x| Foo::f(x));
+
+ struct Bar;
+ impl<'a> From<&'a u32> for Bar {
+ fn from(x: &'a u32) -> Bar {
+ Bar
+ }
+ }
+ fn f2(f: impl for<'a> Fn(&'a u32) -> Bar) -> Bar {
+ f(&0)
+ }
+
+ let _ = f2(|x| <Bar>::from(x));
+
+ struct Baz<'a>(&'a u32);
+ fn f3(f: impl Fn(&u32) -> Baz<'_>) -> Baz<'static> {
+ f(&0)
+ }
+
+ let _ = f3(|x| Baz(x));
+}
+
+fn _mixed_late_bound_and_early_bound_regions() {
+ fn f<T>(t: T, f: impl Fn(T, &u32) -> u32) -> u32 {
+ f(t, &0)
+ }
+ fn f2<'a, T: 'a>(_: &'a T, y: &u32) -> u32 {
+ *y
+ }
+ let _ = f(&0, |x, y| f2(x, y));
+}
+
+fn _closure_with_types() {
+ fn f<T>(x: T) -> T {
+ x
+ }
+ fn f2<T: Default>(f: impl Fn(T) -> T) -> T {
+ f(T::default())
+ }
+
+ let _ = f2(|x: u32| f(x));
+ let _ = f2(|x| -> u32 { f(x) });
+}
diff --git a/src/tools/clippy/tests/ui/eta.stderr b/src/tools/clippy/tests/ui/eta.stderr
index 0ac0b901d..ff40a2074 100644
--- a/src/tools/clippy/tests/ui/eta.stderr
+++ b/src/tools/clippy/tests/ui/eta.stderr
@@ -158,5 +158,11 @@ error: redundant closure
LL | dyn_opt.map(|d| d.method_on_dyn());
| ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<dyn TestTrait>::method_on_dyn`
-error: aborting due to 26 previous errors
+error: redundant closure
+ --> $DIR/eta.rs:389:19
+ |
+LL | let _ = f(&0, |x, y| f2(x, y));
+ | ^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `f2`
+
+error: aborting due to 27 previous errors
diff --git a/src/tools/clippy/tests/ui/expect.stderr b/src/tools/clippy/tests/ui/expect.stderr
index be340340d..f787fa973 100644
--- a/src/tools/clippy/tests/ui/expect.stderr
+++ b/src/tools/clippy/tests/ui/expect.stderr
@@ -4,7 +4,7 @@ error: used `expect()` on an `Option` value
LL | let _ = opt.expect("");
| ^^^^^^^^^^^^^^
|
- = help: if this value is `None`, it will panic
+ = note: if this value is `None`, it will panic
= note: `-D clippy::expect-used` implied by `-D warnings`
error: used `expect()` on a `Result` value
@@ -13,7 +13,7 @@ error: used `expect()` on a `Result` value
LL | let _ = res.expect("");
| ^^^^^^^^^^^^^^
|
- = help: if this value is an `Err`, it will panic
+ = note: if this value is an `Err`, it will panic
error: used `expect_err()` on a `Result` value
--> $DIR/expect.rs:12:13
@@ -21,7 +21,7 @@ error: used `expect_err()` on a `Result` value
LL | let _ = res.expect_err("");
| ^^^^^^^^^^^^^^^^^^
|
- = help: if this value is an `Ok`, it will panic
+ = note: if this value is an `Ok`, it will panic
error: aborting due to 3 previous errors
diff --git a/src/tools/clippy/tests/ui/expect_fun_call.stderr b/src/tools/clippy/tests/ui/expect_fun_call.stderr
index 36fb0e5de..a621f681d 100644
--- a/src/tools/clippy/tests/ui/expect_fun_call.stderr
+++ b/src/tools/clippy/tests/ui/expect_fun_call.stderr
@@ -2,7 +2,7 @@ error: use of `expect` followed by a function call
--> $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))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
|
= note: `-D clippy::expect-fun-call` implied by `-D warnings`
@@ -10,85 +10,85 @@ error: use of `expect` followed by a function call
--> $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))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:44:37
|
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!()))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("Error {}: fake error", one!()))`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:54:25
|
LL | with_err_and_format.expect(&format!("Error {}: fake error", error_code));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:57:25
|
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))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:69:17
|
LL | Some("foo").expect(format!("{} {}", 1, 2).as_ref());
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{} {}", 1, 2))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{} {}", 1, 2))`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:90:21
|
LL | Some("foo").expect(&get_string());
- | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:91:21
|
LL | Some("foo").expect(get_string().as_ref());
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:92:21
|
LL | Some("foo").expect(get_string().as_str());
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:94:21
|
LL | Some("foo").expect(get_static_str());
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_static_str()) })`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_static_str()) })`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:95:21
|
LL | Some("foo").expect(get_non_static_str(&0));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:99:16
|
LL | Some(true).expect(&format!("key {}, {}", 1, 2));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:105:17
|
LL | opt_ref.expect(&format!("{:?}", opt_ref));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{:?}", opt_ref))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{:?}", opt_ref))`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:109:20
|
LL | format_capture.expect(&format!("{error_code}"));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{error_code}"))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{error_code}"))`
error: use of `expect` followed by a function call
--> $DIR/expect_fun_call.rs:112:30
|
LL | format_capture_and_value.expect(&format!("{error_code}, {}", 1));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{error_code}, {}", 1))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{error_code}, {}", 1))`
error: aborting due to 15 previous errors
diff --git a/src/tools/clippy/tests/ui/explicit_auto_deref.stderr b/src/tools/clippy/tests/ui/explicit_auto_deref.stderr
index 91863abcc..afc311e3f 100644
--- a/src/tools/clippy/tests/ui/explicit_auto_deref.stderr
+++ b/src/tools/clippy/tests/ui/explicit_auto_deref.stderr
@@ -2,7 +2,7 @@ error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:70:19
|
LL | let _: &str = &*s;
- | ^^^ help: try this: `&s`
+ | ^^^ help: try: `&s`
|
= note: `-D clippy::explicit-auto-deref` implied by `-D warnings`
@@ -10,229 +10,229 @@ error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:71:19
|
LL | let _: &str = &*{ String::new() };
- | ^^^^^^^^^^^^^^^^^^^ help: try this: `&{ String::new() }`
+ | ^^^^^^^^^^^^^^^^^^^ help: try: `&{ String::new() }`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:72:19
|
LL | let _: &str = &mut *{ String::new() };
- | ^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&mut { String::new() }`
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut { String::new() }`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:76:11
|
LL | f_str(&*s);
- | ^^^ help: try this: `&s`
+ | ^^^ help: try: `&s`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:80:13
|
LL | f_str_t(&*s, &*s); // Don't lint second param.
- | ^^^ help: try this: `&s`
+ | ^^^ help: try: `&s`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:83:24
|
LL | let _: &Box<i32> = &**b;
- | ^^^^ help: try this: `&b`
+ | ^^^^ help: try: `&b`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:89:7
|
LL | c(&*s);
- | ^^^ help: try this: `&s`
+ | ^^^ help: try: `&s`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:95:9
|
LL | &**x
- | ^^^^ help: try this: `x`
+ | ^^^^ help: try: `x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:99:11
|
LL | { &**x }
- | ^^^^ help: try this: `x`
+ | ^^^^ help: try: `x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:103:9
|
LL | &**{ x }
- | ^^^^^^^^ help: try this: `{ x }`
+ | ^^^^^^^^ help: try: `{ x }`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:107:9
|
LL | &***x
- | ^^^^^ help: try this: `x`
+ | ^^^^^ help: try: `x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:124:12
|
LL | f1(&*x);
- | ^^^ help: try this: `&x`
+ | ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:125:12
|
LL | f2(&*x);
- | ^^^ help: try this: `&x`
+ | ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:126:12
|
LL | f3(&*x);
- | ^^^ help: try this: `&x`
+ | ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:127:27
|
LL | f4.callable_str()(&*x);
- | ^^^ help: try this: `&x`
+ | ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:128:12
|
LL | f5(&*x);
- | ^^^ help: try this: `&x`
+ | ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:129:12
|
LL | f6(&*x);
- | ^^^ help: try this: `&x`
+ | ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:130:27
|
LL | f7.callable_str()(&*x);
- | ^^^ help: try this: `&x`
+ | ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:131:25
|
LL | f8.callable_t()(&*x);
- | ^^^ help: try this: `&x`
+ | ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:132:12
|
LL | f9(&*x);
- | ^^^ help: try this: `&x`
+ | ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:133:13
|
LL | f10(&*x);
- | ^^^ help: try this: `&x`
+ | ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:134:26
|
LL | f11.callable_t()(&*x);
- | ^^^ help: try this: `&x`
+ | ^^^ help: try: `&x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:138:16
|
LL | let _ = S1(&*s);
- | ^^^ help: try this: `&s`
+ | ^^^ help: try: `&s`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:143:21
|
LL | let _ = S2 { s: &*s };
- | ^^^ help: try this: `&s`
+ | ^^^ help: try: `&s`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:159:30
|
LL | let _ = Self::S1(&**s);
- | ^^^^ help: try this: `s`
+ | ^^^^ help: try: `s`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:160:35
|
LL | let _ = Self::S2 { s: &**s };
- | ^^^^ help: try this: `s`
+ | ^^^^ help: try: `s`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:163:20
|
LL | let _ = E1::S1(&*s);
- | ^^^ help: try this: `&s`
+ | ^^^ help: try: `&s`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:164:25
|
LL | let _ = E1::S2 { s: &*s };
- | ^^^ help: try this: `&s`
+ | ^^^ help: try: `&s`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:182:13
|
LL | let _ = (*b).foo;
- | ^^^^ help: try this: `b`
+ | ^^^^ help: try: `b`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:183:13
|
LL | let _ = (**b).foo;
- | ^^^^^ help: try this: `b`
+ | ^^^^^ help: try: `b`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:198:19
|
LL | let _ = f_str(*ref_str);
- | ^^^^^^^^ help: try this: `ref_str`
+ | ^^^^^^^^ help: try: `ref_str`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:200:19
|
LL | let _ = f_str(**ref_ref_str);
- | ^^^^^^^^^^^^^ help: try this: `ref_ref_str`
+ | ^^^^^^^^^^^^^ help: try: `ref_ref_str`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:210:13
|
LL | f_str(&&*ref_str); // `needless_borrow` will suggest removing both references
- | ^^^^^^^^ help: try this: `ref_str`
+ | ^^^^^^^^ help: try: `ref_str`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:211:12
|
LL | f_str(&&**ref_str); // `needless_borrow` will suggest removing only one reference
- | ^^^^^^^^^^ help: try this: `ref_str`
+ | ^^^^^^^^^^ help: try: `ref_str`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:220:41
|
LL | let _ = || -> &'static str { return *s };
- | ^^ help: try this: `s`
+ | ^^ help: try: `s`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:239:9
|
LL | &**x
- | ^^^^ help: try this: `x`
+ | ^^^^ help: try: `x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:262:8
|
LL | c1(*x);
- | ^^ help: try this: `x`
+ | ^^ help: try: `x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:265:20
|
LL | return *x;
- | ^^ help: try this: `x`
+ | ^^ help: try: `x`
error: deref which would be done by auto-deref
--> $DIR/explicit_auto_deref.rs:267:9
|
LL | *x
- | ^^ help: try this: `x`
+ | ^^ help: try: `x`
error: aborting due to 39 previous errors
diff --git a/src/tools/clippy/tests/ui/explicit_deref_methods.fixed b/src/tools/clippy/tests/ui/explicit_deref_methods.fixed
index 4d72b58cd..4c0b0d8f2 100644
--- a/src/tools/clippy/tests/ui/explicit_deref_methods.fixed
+++ b/src/tools/clippy/tests/ui/explicit_deref_methods.fixed
@@ -4,6 +4,7 @@
#![allow(
clippy::borrow_deref_ref,
suspicious_double_ref_op,
+ noop_method_call,
clippy::explicit_auto_deref,
clippy::needless_borrow,
clippy::no_effect,
diff --git a/src/tools/clippy/tests/ui/explicit_deref_methods.rs b/src/tools/clippy/tests/ui/explicit_deref_methods.rs
index fcd945de3..bc5da35e5 100644
--- a/src/tools/clippy/tests/ui/explicit_deref_methods.rs
+++ b/src/tools/clippy/tests/ui/explicit_deref_methods.rs
@@ -4,6 +4,7 @@
#![allow(
clippy::borrow_deref_ref,
suspicious_double_ref_op,
+ noop_method_call,
clippy::explicit_auto_deref,
clippy::needless_borrow,
clippy::no_effect,
diff --git a/src/tools/clippy/tests/ui/explicit_deref_methods.stderr b/src/tools/clippy/tests/ui/explicit_deref_methods.stderr
index d025035b7..e4d2fe3a1 100644
--- a/src/tools/clippy/tests/ui/explicit_deref_methods.stderr
+++ b/src/tools/clippy/tests/ui/explicit_deref_methods.stderr
@@ -1,76 +1,76 @@
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:54:19
+ --> $DIR/explicit_deref_methods.rs:55:19
|
LL | let b: &str = a.deref();
- | ^^^^^^^^^ help: try this: `&*a`
+ | ^^^^^^^^^ help: try: `&*a`
|
= note: `-D clippy::explicit-deref-methods` implied by `-D warnings`
error: explicit `deref_mut` method call
- --> $DIR/explicit_deref_methods.rs:56:23
+ --> $DIR/explicit_deref_methods.rs:57:23
|
LL | let b: &mut str = a.deref_mut();
- | ^^^^^^^^^^^^^ help: try this: `&mut **a`
+ | ^^^^^^^^^^^^^ help: try: `&mut **a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:59:39
+ --> $DIR/explicit_deref_methods.rs:60:39
|
LL | let b: String = format!("{}, {}", a.deref(), a.deref());
- | ^^^^^^^^^ help: try this: `&*a`
+ | ^^^^^^^^^ help: try: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:59:50
+ --> $DIR/explicit_deref_methods.rs:60:50
|
LL | let b: String = format!("{}, {}", a.deref(), a.deref());
- | ^^^^^^^^^ help: try this: `&*a`
+ | ^^^^^^^^^ help: try: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:61:20
+ --> $DIR/explicit_deref_methods.rs:62:20
|
LL | println!("{}", a.deref());
- | ^^^^^^^^^ help: try this: `&*a`
+ | ^^^^^^^^^ help: try: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:64:11
+ --> $DIR/explicit_deref_methods.rs:65:11
|
LL | match a.deref() {
- | ^^^^^^^^^ help: try this: `&*a`
+ | ^^^^^^^^^ help: try: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:68:28
+ --> $DIR/explicit_deref_methods.rs:69:28
|
LL | let b: String = concat(a.deref());
- | ^^^^^^^^^ help: try this: `&*a`
+ | ^^^^^^^^^ help: try: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:70:13
+ --> $DIR/explicit_deref_methods.rs:71:13
|
LL | let b = just_return(a).deref();
- | ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `just_return(a)`
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `just_return(a)`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:72:28
+ --> $DIR/explicit_deref_methods.rs:73:28
|
LL | let b: String = concat(just_return(a).deref());
- | ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `just_return(a)`
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `just_return(a)`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:74:19
+ --> $DIR/explicit_deref_methods.rs:75:19
|
LL | let b: &str = a.deref().deref();
- | ^^^^^^^^^^^^^^^^^ help: try this: `&**a`
+ | ^^^^^^^^^^^^^^^^^ help: try: `&**a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:77:13
+ --> $DIR/explicit_deref_methods.rs:78:13
|
LL | let b = opt_a.unwrap().deref();
- | ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&*opt_a.unwrap()`
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*opt_a.unwrap()`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:114:31
+ --> $DIR/explicit_deref_methods.rs:115:31
|
LL | let b: &str = expr_deref!(a.deref());
- | ^^^^^^^^^ help: try this: `&*a`
+ | ^^^^^^^^^ help: try: `&*a`
error: aborting due to 12 previous errors
diff --git a/src/tools/clippy/tests/ui/explicit_write.stderr b/src/tools/clippy/tests/ui/explicit_write.stderr
index 457e9c627..b3aa7274c 100644
--- a/src/tools/clippy/tests/ui/explicit_write.stderr
+++ b/src/tools/clippy/tests/ui/explicit_write.stderr
@@ -2,7 +2,7 @@ error: use of `write!(stdout(), ...).unwrap()`
--> $DIR/explicit_write.rs:24:9
|
LL | write!(std::io::stdout(), "test").unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `print!("test")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `print!("test")`
|
= note: `-D clippy::explicit-write` implied by `-D warnings`
@@ -10,73 +10,73 @@ error: use of `write!(stderr(), ...).unwrap()`
--> $DIR/explicit_write.rs:25:9
|
LL | write!(std::io::stderr(), "test").unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprint!("test")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprint!("test")`
error: use of `writeln!(stdout(), ...).unwrap()`
--> $DIR/explicit_write.rs:26:9
|
LL | writeln!(std::io::stdout(), "test").unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `println!("test")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `println!("test")`
error: use of `writeln!(stderr(), ...).unwrap()`
--> $DIR/explicit_write.rs:27:9
|
LL | writeln!(std::io::stderr(), "test").unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("test")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("test")`
error: use of `stdout().write_fmt(...).unwrap()`
--> $DIR/explicit_write.rs:28:9
|
LL | std::io::stdout().write_fmt(format_args!("test")).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `print!("test")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `print!("test")`
error: use of `stderr().write_fmt(...).unwrap()`
--> $DIR/explicit_write.rs:29:9
|
LL | std::io::stderr().write_fmt(format_args!("test")).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprint!("test")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprint!("test")`
error: use of `writeln!(stdout(), ...).unwrap()`
--> $DIR/explicit_write.rs:32:9
|
LL | writeln!(std::io::stdout(), "test/ntest").unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `println!("test/ntest")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `println!("test/ntest")`
error: use of `writeln!(stderr(), ...).unwrap()`
--> $DIR/explicit_write.rs:33:9
|
LL | writeln!(std::io::stderr(), "test/ntest").unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("test/ntest")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("test/ntest")`
error: use of `writeln!(stderr(), ...).unwrap()`
--> $DIR/explicit_write.rs:36:9
|
LL | writeln!(std::io::stderr(), "with {}", value).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("with {}", value)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("with {}", value)`
error: use of `writeln!(stderr(), ...).unwrap()`
--> $DIR/explicit_write.rs:37:9
|
LL | writeln!(std::io::stderr(), "with {} {}", 2, value).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("with {} {}", 2, value)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("with {} {}", 2, value)`
error: use of `writeln!(stderr(), ...).unwrap()`
--> $DIR/explicit_write.rs:38:9
|
LL | writeln!(std::io::stderr(), "with {value}").unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("with {value}")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("with {value}")`
error: use of `writeln!(stderr(), ...).unwrap()`
--> $DIR/explicit_write.rs:39:9
|
LL | writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("macro arg {}", one!())`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("macro arg {}", one!())`
error: use of `writeln!(stderr(), ...).unwrap()`
--> $DIR/explicit_write.rs:41:9
|
LL | writeln!(std::io::stderr(), "{:w$}", value, w = width).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("{:w$}", value, w = width)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `eprintln!("{:w$}", value, w = width)`
error: aborting due to 13 previous errors
diff --git a/src/tools/clippy/tests/ui/extend_with_drain.stderr b/src/tools/clippy/tests/ui/extend_with_drain.stderr
index da14ddb25..eb2dd304d 100644
--- a/src/tools/clippy/tests/ui/extend_with_drain.stderr
+++ b/src/tools/clippy/tests/ui/extend_with_drain.stderr
@@ -2,7 +2,7 @@ error: use of `extend` instead of `append` for adding the full range of a second
--> $DIR/extend_with_drain.rs:9:5
|
LL | vec2.extend(vec1.drain(..));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `vec2.append(&mut vec1)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec2.append(&mut vec1)`
|
= note: `-D clippy::extend-with-drain` implied by `-D warnings`
@@ -10,19 +10,19 @@ error: use of `extend` instead of `append` for adding the full range of a second
--> $DIR/extend_with_drain.rs:14:5
|
LL | vec4.extend(vec3.drain(..));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `vec4.append(&mut vec3)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec4.append(&mut vec3)`
error: use of `extend` instead of `append` for adding the full range of a second vector
--> $DIR/extend_with_drain.rs:18:5
|
LL | vec11.extend(return_vector().drain(..));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `vec11.append(&mut return_vector())`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec11.append(&mut return_vector())`
error: use of `extend` instead of `append` for adding the full range of a second vector
--> $DIR/extend_with_drain.rs:49:5
|
LL | y.extend(ref_x.drain(..));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `y.append(ref_x)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `y.append(ref_x)`
error: aborting due to 4 previous errors
diff --git a/src/tools/clippy/tests/ui/filter_map_bool_then.fixed b/src/tools/clippy/tests/ui/filter_map_bool_then.fixed
new file mode 100644
index 000000000..e5c9f783f
--- /dev/null
+++ b/src/tools/clippy/tests/ui/filter_map_bool_then.fixed
@@ -0,0 +1,58 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(
+ clippy::clone_on_copy,
+ clippy::map_identity,
+ clippy::unnecessary_lazy_evaluations,
+ clippy::unnecessary_filter_map,
+ unused
+)]
+#![warn(clippy::filter_map_bool_then)]
+
+#[macro_use]
+extern crate proc_macros;
+
+#[derive(Clone, PartialEq)]
+struct NonCopy;
+
+fn main() {
+ let v = vec![1, 2, 3, 4, 5, 6];
+ v.clone().iter().filter(|&i| (i % 2 == 0)).map(|i| i + 1);
+ v.clone().into_iter().filter(|&i| (i % 2 == 0)).map(|i| i + 1);
+ v.clone()
+ .into_iter()
+ .filter(|&i| (i % 2 == 0)).map(|i| i + 1);
+ v.clone()
+ .into_iter()
+ .filter(|&i| i != 1000)
+ .filter(|&i| (i % 2 == 0)).map(|i| i + 1);
+ v.iter()
+ .copied()
+ .filter(|&i| i != 1000)
+ .filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1);
+ // Despite this is non-copy, `is_copy` still returns true (at least now) because it's `&NonCopy`,
+ // and any `&` is `Copy`. So since we can dereference it in `filter` (since it's then `&&NonCopy`),
+ // we can lint this and still get the same input type.
+ // See: <https://doc.rust-lang.org/std/primitive.reference.html#trait-implementations-1>
+ let v = vec![NonCopy, NonCopy];
+ v.clone().iter().filter(|&i| (i == &NonCopy)).map(|i| i);
+ // Do not lint
+ let v = vec![NonCopy, NonCopy];
+ v.clone().into_iter().filter_map(|i| (i == NonCopy).then(|| i));
+ // `&mut` is `!Copy`.
+ let v = vec![NonCopy, NonCopy];
+ v.clone().iter_mut().filter_map(|i| (i == &mut NonCopy).then(|| i));
+ external! {
+ let v = vec![1, 2, 3, 4, 5, 6];
+ v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1));
+ }
+ with_span! {
+ span
+ let v = vec![1, 2, 3, 4, 5, 6];
+ v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1));
+ }
+}
+
+fn issue11309<'a>(iter: impl Iterator<Item = (&'a str, &'a str)>) -> Vec<&'a str> {
+ iter.filter_map(|(_, s): (&str, _)| Some(s)).collect()
+}
diff --git a/src/tools/clippy/tests/ui/filter_map_bool_then.rs b/src/tools/clippy/tests/ui/filter_map_bool_then.rs
new file mode 100644
index 000000000..7c9b99df7
--- /dev/null
+++ b/src/tools/clippy/tests/ui/filter_map_bool_then.rs
@@ -0,0 +1,58 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(
+ clippy::clone_on_copy,
+ clippy::map_identity,
+ clippy::unnecessary_lazy_evaluations,
+ clippy::unnecessary_filter_map,
+ unused
+)]
+#![warn(clippy::filter_map_bool_then)]
+
+#[macro_use]
+extern crate proc_macros;
+
+#[derive(Clone, PartialEq)]
+struct NonCopy;
+
+fn main() {
+ let v = vec![1, 2, 3, 4, 5, 6];
+ v.clone().iter().filter_map(|i| (i % 2 == 0).then(|| i + 1));
+ v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1));
+ v.clone()
+ .into_iter()
+ .filter_map(|i| -> Option<_> { (i % 2 == 0).then(|| i + 1) });
+ v.clone()
+ .into_iter()
+ .filter(|&i| i != 1000)
+ .filter_map(|i| (i % 2 == 0).then(|| i + 1));
+ v.iter()
+ .copied()
+ .filter(|&i| i != 1000)
+ .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1));
+ // Despite this is non-copy, `is_copy` still returns true (at least now) because it's `&NonCopy`,
+ // and any `&` is `Copy`. So since we can dereference it in `filter` (since it's then `&&NonCopy`),
+ // we can lint this and still get the same input type.
+ // See: <https://doc.rust-lang.org/std/primitive.reference.html#trait-implementations-1>
+ let v = vec![NonCopy, NonCopy];
+ v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i));
+ // Do not lint
+ let v = vec![NonCopy, NonCopy];
+ v.clone().into_iter().filter_map(|i| (i == NonCopy).then(|| i));
+ // `&mut` is `!Copy`.
+ let v = vec![NonCopy, NonCopy];
+ v.clone().iter_mut().filter_map(|i| (i == &mut NonCopy).then(|| i));
+ external! {
+ let v = vec![1, 2, 3, 4, 5, 6];
+ v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1));
+ }
+ with_span! {
+ span
+ let v = vec![1, 2, 3, 4, 5, 6];
+ v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1));
+ }
+}
+
+fn issue11309<'a>(iter: impl Iterator<Item = (&'a str, &'a str)>) -> Vec<&'a str> {
+ iter.filter_map(|(_, s): (&str, _)| Some(s)).collect()
+}
diff --git a/src/tools/clippy/tests/ui/filter_map_bool_then.stderr b/src/tools/clippy/tests/ui/filter_map_bool_then.stderr
new file mode 100644
index 000000000..fffa5252e
--- /dev/null
+++ b/src/tools/clippy/tests/ui/filter_map_bool_then.stderr
@@ -0,0 +1,40 @@
+error: usage of `bool::then` in `filter_map`
+ --> $DIR/filter_map_bool_then.rs:20:22
+ |
+LL | v.clone().iter().filter_map(|i| (i % 2 == 0).then(|| i + 1));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)`
+ |
+ = note: `-D clippy::filter-map-bool-then` implied by `-D warnings`
+
+error: usage of `bool::then` in `filter_map`
+ --> $DIR/filter_map_bool_then.rs:21:27
+ |
+LL | v.clone().into_iter().filter_map(|i| (i % 2 == 0).then(|| i + 1));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)`
+
+error: usage of `bool::then` in `filter_map`
+ --> $DIR/filter_map_bool_then.rs:24:10
+ |
+LL | .filter_map(|i| -> Option<_> { (i % 2 == 0).then(|| i + 1) });
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)`
+
+error: usage of `bool::then` in `filter_map`
+ --> $DIR/filter_map_bool_then.rs:28:10
+ |
+LL | .filter_map(|i| (i % 2 == 0).then(|| i + 1));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i % 2 == 0)).map(|i| i + 1)`
+
+error: usage of `bool::then` in `filter_map`
+ --> $DIR/filter_map_bool_then.rs:32:10
+ |
+LL | .filter_map(|i| (i.clone() % 2 == 0).then(|| i + 1));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i.clone() % 2 == 0)).map(|i| i + 1)`
+
+error: usage of `bool::then` in `filter_map`
+ --> $DIR/filter_map_bool_then.rs:38:22
+ |
+LL | v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i == &NonCopy)).map(|i| i)`
+
+error: aborting due to 6 previous errors
+
diff --git a/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr b/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr
index a9fc6abe8..26d9c5e19 100644
--- a/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr
+++ b/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr
@@ -2,7 +2,7 @@ error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly
--> $DIR/filter_map_next_fixable.rs:9:32
|
LL | let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `a.iter().find_map(|s| s.parse().ok())`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.iter().find_map(|s| s.parse().ok())`
|
= note: `-D clippy::filter-map-next` implied by `-D warnings`
@@ -10,7 +10,7 @@ error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly
--> $DIR/filter_map_next_fixable.rs:22:26
|
LL | let _: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `a.iter().find_map(|s| s.parse().ok())`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.iter().find_map(|s| s.parse().ok())`
error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui/fn_null_check.rs b/src/tools/clippy/tests/ui/fn_null_check.rs
deleted file mode 100644
index dfdea100c..000000000
--- a/src/tools/clippy/tests/ui/fn_null_check.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-#![allow(unused)]
-#![warn(clippy::fn_null_check)]
-#![allow(clippy::cmp_null)]
-#![allow(clippy::needless_if)]
-#![allow(clippy::ptr_eq)]
-#![allow(clippy::zero_ptr)]
-
-pub const ZPTR: *const () = 0 as *const _;
-pub const NOT_ZPTR: *const () = 1 as *const _;
-
-fn main() {
- let fn_ptr = main;
-
- if (fn_ptr as *mut ()).is_null() {}
- if (fn_ptr as *const u8).is_null() {}
- if (fn_ptr as *const ()) == std::ptr::null() {}
- if (fn_ptr as *const ()) == (0 as *const ()) {}
- if (fn_ptr as *const ()) == ZPTR {}
-
- // no lint
- if (fn_ptr as *const ()) == NOT_ZPTR {}
-}
diff --git a/src/tools/clippy/tests/ui/fn_null_check.stderr b/src/tools/clippy/tests/ui/fn_null_check.stderr
deleted file mode 100644
index 5b9f48a96..000000000
--- a/src/tools/clippy/tests/ui/fn_null_check.stderr
+++ /dev/null
@@ -1,43 +0,0 @@
-error: function pointer assumed to be nullable, even though it isn't
- --> $DIR/fn_null_check.rs:14:8
- |
-LL | if (fn_ptr as *mut ()).is_null() {}
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = help: try wrapping your function pointer type in `Option<T>` instead, and using `is_none` to check for null pointer value
- = 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:15:8
- |
-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:16:8
- |
-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:17:8
- |
-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:18:8
- |
-LL | if (fn_ptr as *const ()) == ZPTR {}
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = help: try wrapping your function pointer type in `Option<T>` instead, and using `is_none` to check for null pointer value
-
-error: aborting due to 5 previous errors
-
diff --git a/src/tools/clippy/tests/ui/format_collect.rs b/src/tools/clippy/tests/ui/format_collect.rs
new file mode 100644
index 000000000..c7f2b7b69
--- /dev/null
+++ b/src/tools/clippy/tests/ui/format_collect.rs
@@ -0,0 +1,31 @@
+#![allow(unused, dead_code)]
+#![warn(clippy::format_collect)]
+
+fn hex_encode(bytes: &[u8]) -> String {
+ bytes.iter().map(|b| format!("{b:02X}")).collect()
+}
+
+#[rustfmt::skip]
+fn hex_encode_deep(bytes: &[u8]) -> String {
+ bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect()
+}
+
+macro_rules! fmt {
+ ($x:ident) => {
+ format!("{x:02X}", x = $x)
+ };
+}
+
+fn from_macro(bytes: &[u8]) -> String {
+ bytes.iter().map(|x| fmt!(x)).collect()
+}
+
+fn with_block() -> String {
+ (1..10)
+ .map(|s| {
+ let y = 1;
+ format!("{s} {y}")
+ })
+ .collect()
+}
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/format_collect.stderr b/src/tools/clippy/tests/ui/format_collect.stderr
new file mode 100644
index 000000000..d918f1ed4
--- /dev/null
+++ b/src/tools/clippy/tests/ui/format_collect.stderr
@@ -0,0 +1,62 @@
+error: use of `format!` to build up a string from an iterator
+ --> $DIR/format_collect.rs:5:5
+ |
+LL | bytes.iter().map(|b| format!("{b:02X}")).collect()
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: call `fold` instead
+ --> $DIR/format_collect.rs:5:18
+ |
+LL | bytes.iter().map(|b| format!("{b:02X}")).collect()
+ | ^^^
+help: ... and use the `write!` macro here
+ --> $DIR/format_collect.rs:5:26
+ |
+LL | bytes.iter().map(|b| format!("{b:02X}")).collect()
+ | ^^^^^^^^^^^^^^^^^^
+ = note: this can be written more efficiently by appending to a `String` directly
+ = note: `-D clippy::format-collect` implied by `-D warnings`
+
+error: use of `format!` to build up a string from an iterator
+ --> $DIR/format_collect.rs:10:5
+ |
+LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect()
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: call `fold` instead
+ --> $DIR/format_collect.rs:10:18
+ |
+LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect()
+ | ^^^
+help: ... and use the `write!` macro here
+ --> $DIR/format_collect.rs:10:32
+ |
+LL | bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect()
+ | ^^^^^^^^^^^^^^^^^^
+ = note: this can be written more efficiently by appending to a `String` directly
+
+error: use of `format!` to build up a string from an iterator
+ --> $DIR/format_collect.rs:24:5
+ |
+LL | / (1..10)
+LL | | .map(|s| {
+LL | | let y = 1;
+LL | | format!("{s} {y}")
+LL | | })
+LL | | .collect()
+ | |__________________^
+ |
+help: call `fold` instead
+ --> $DIR/format_collect.rs:25:10
+ |
+LL | .map(|s| {
+ | ^^^
+help: ... and use the `write!` macro here
+ --> $DIR/format_collect.rs:27:13
+ |
+LL | format!("{s} {y}")
+ | ^^^^^^^^^^^^^^^^^^
+ = note: this can be written more efficiently by appending to a `String` directly
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/four_forward_slashes.fixed b/src/tools/clippy/tests/ui/four_forward_slashes.fixed
new file mode 100644
index 000000000..54b2c414b
--- /dev/null
+++ b/src/tools/clippy/tests/ui/four_forward_slashes.fixed
@@ -0,0 +1,48 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![feature(custom_inner_attributes)]
+#![allow(unused)]
+#![warn(clippy::four_forward_slashes)]
+#![no_main]
+#![rustfmt::skip]
+
+#[macro_use]
+extern crate proc_macros;
+
+/// whoops
+fn a() {}
+
+/// whoops
+#[allow(dead_code)]
+fn b() {}
+
+/// whoops
+/// two borked comments!
+#[track_caller]
+fn c() {}
+
+fn d() {}
+
+#[test]
+/// between attributes
+#[allow(dead_code)]
+fn g() {}
+
+/// not very start of contents
+fn h() {}
+
+fn i() {
+ //// don't lint me bozo
+ todo!()
+}
+
+external! {
+ //// don't lint me bozo
+ fn e() {}
+}
+
+with_span! {
+ span
+ //// don't lint me bozo
+ fn f() {}
+}
diff --git a/src/tools/clippy/tests/ui/four_forward_slashes.rs b/src/tools/clippy/tests/ui/four_forward_slashes.rs
new file mode 100644
index 000000000..facdc8cb1
--- /dev/null
+++ b/src/tools/clippy/tests/ui/four_forward_slashes.rs
@@ -0,0 +1,48 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![feature(custom_inner_attributes)]
+#![allow(unused)]
+#![warn(clippy::four_forward_slashes)]
+#![no_main]
+#![rustfmt::skip]
+
+#[macro_use]
+extern crate proc_macros;
+
+//// whoops
+fn a() {}
+
+//// whoops
+#[allow(dead_code)]
+fn b() {}
+
+//// whoops
+//// two borked comments!
+#[track_caller]
+fn c() {}
+
+fn d() {}
+
+#[test]
+//// between attributes
+#[allow(dead_code)]
+fn g() {}
+
+ //// not very start of contents
+fn h() {}
+
+fn i() {
+ //// don't lint me bozo
+ todo!()
+}
+
+external! {
+ //// don't lint me bozo
+ fn e() {}
+}
+
+with_span! {
+ span
+ //// don't lint me bozo
+ fn f() {}
+}
diff --git a/src/tools/clippy/tests/ui/four_forward_slashes.stderr b/src/tools/clippy/tests/ui/four_forward_slashes.stderr
new file mode 100644
index 000000000..89162e6b0
--- /dev/null
+++ b/src/tools/clippy/tests/ui/four_forward_slashes.stderr
@@ -0,0 +1,68 @@
+error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't
+ --> $DIR/four_forward_slashes.rs:12:1
+ |
+LL | / //// whoops
+LL | | fn a() {}
+ | |_
+ |
+ = note: `-D clippy::four-forward-slashes` implied by `-D warnings`
+help: make this a doc comment by removing one `/`
+ |
+LL + /// whoops
+ |
+
+error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't
+ --> $DIR/four_forward_slashes.rs:15:1
+ |
+LL | / //// whoops
+LL | | #[allow(dead_code)]
+LL | | fn b() {}
+ | |_
+ |
+help: make this a doc comment by removing one `/`
+ |
+LL + /// whoops
+ |
+
+error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't
+ --> $DIR/four_forward_slashes.rs:19:1
+ |
+LL | / //// whoops
+LL | | //// two borked comments!
+LL | | #[track_caller]
+LL | | fn c() {}
+ | |_
+ |
+help: turn these into doc comments by removing one `/`
+ |
+LL + /// whoops
+LL ~ /// two borked comments!
+ |
+
+error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't
+ --> $DIR/four_forward_slashes.rs:27:1
+ |
+LL | / //// between attributes
+LL | | #[allow(dead_code)]
+LL | | fn g() {}
+ | |_
+ |
+help: make this a doc comment by removing one `/`
+ |
+LL + /// between attributes
+ |
+
+error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't
+ --> $DIR/four_forward_slashes.rs:31:1
+ |
+LL | / //// not very start of contents
+LL | | fn h() {}
+ | |_
+ |
+help: make this a doc comment by removing one `/`
+ |
+LL + /// not very start of contents
+ |
+
+error: aborting due to 5 previous errors
+
diff --git a/src/tools/clippy/tests/ui/four_forward_slashes_first_line.fixed b/src/tools/clippy/tests/ui/four_forward_slashes_first_line.fixed
new file mode 100644
index 000000000..ce272b4c6
--- /dev/null
+++ b/src/tools/clippy/tests/ui/four_forward_slashes_first_line.fixed
@@ -0,0 +1,7 @@
+/// borked doc comment on the first line. doesn't combust!
+fn a() {}
+
+//@run-rustfix
+// This test's entire purpose is to make sure we don't panic if the comment with four slashes
+// extends to the first line of the file. This is likely pretty rare in production, but an ICE is an
+// ICE.
diff --git a/src/tools/clippy/tests/ui/four_forward_slashes_first_line.rs b/src/tools/clippy/tests/ui/four_forward_slashes_first_line.rs
new file mode 100644
index 000000000..d8f82d441
--- /dev/null
+++ b/src/tools/clippy/tests/ui/four_forward_slashes_first_line.rs
@@ -0,0 +1,7 @@
+//// borked doc comment on the first line. doesn't combust!
+fn a() {}
+
+//@run-rustfix
+// This test's entire purpose is to make sure we don't panic if the comment with four slashes
+// extends to the first line of the file. This is likely pretty rare in production, but an ICE is an
+// ICE.
diff --git a/src/tools/clippy/tests/ui/four_forward_slashes_first_line.stderr b/src/tools/clippy/tests/ui/four_forward_slashes_first_line.stderr
new file mode 100644
index 000000000..7944da14f
--- /dev/null
+++ b/src/tools/clippy/tests/ui/four_forward_slashes_first_line.stderr
@@ -0,0 +1,15 @@
+error: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't
+ --> $DIR/four_forward_slashes_first_line.rs:1:1
+ |
+LL | / //// borked doc comment on the first line. doesn't combust!
+LL | | fn a() {}
+ | |_
+ |
+ = note: `-D clippy::four-forward-slashes` implied by `-D warnings`
+help: make this a doc comment by removing one `/`
+ |
+LL + /// borked doc comment on the first line. doesn't combust!
+ |
+
+error: aborting due to previous error
+
diff --git a/src/tools/clippy/tests/ui/get_first.fixed b/src/tools/clippy/tests/ui/get_first.fixed
index a29c0918a..bc2f86566 100644
--- a/src/tools/clippy/tests/ui/get_first.fixed
+++ b/src/tools/clippy/tests/ui/get_first.fixed
@@ -1,9 +1,7 @@
//@run-rustfix
#![warn(clippy::get_first)]
#![allow(clippy::useless_vec)]
-use std::collections::BTreeMap;
-use std::collections::HashMap;
-use std::collections::VecDeque;
+use std::collections::{BTreeMap, HashMap, VecDeque};
struct Bar {
arr: [u32; 3],
diff --git a/src/tools/clippy/tests/ui/get_first.rs b/src/tools/clippy/tests/ui/get_first.rs
index 2062f3ec2..bc0e233fd 100644
--- a/src/tools/clippy/tests/ui/get_first.rs
+++ b/src/tools/clippy/tests/ui/get_first.rs
@@ -1,9 +1,7 @@
//@run-rustfix
#![warn(clippy::get_first)]
#![allow(clippy::useless_vec)]
-use std::collections::BTreeMap;
-use std::collections::HashMap;
-use std::collections::VecDeque;
+use std::collections::{BTreeMap, HashMap, VecDeque};
struct Bar {
arr: [u32; 3],
diff --git a/src/tools/clippy/tests/ui/get_first.stderr b/src/tools/clippy/tests/ui/get_first.stderr
index 4e267ba9a..0899a5905 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:20:13
+ --> $DIR/get_first.rs:18: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:25:13
+ --> $DIR/get_first.rs:23: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:30:13
+ --> $DIR/get_first.rs:28:13
|
LL | let _ = z.get(0); // Use z.first()
| ^^^^^^^^ help: try: `z.first()`
diff --git a/src/tools/clippy/tests/ui/get_unwrap.fixed b/src/tools/clippy/tests/ui/get_unwrap.fixed
index 56ee37f02..fda334407 100644
--- a/src/tools/clippy/tests/ui/get_unwrap.fixed
+++ b/src/tools/clippy/tests/ui/get_unwrap.fixed
@@ -9,9 +9,7 @@
#![warn(clippy::unwrap_used)]
#![deny(clippy::get_unwrap)]
-use std::collections::BTreeMap;
-use std::collections::HashMap;
-use std::collections::VecDeque;
+use std::collections::{BTreeMap, HashMap, VecDeque};
struct GetFalsePositive {
arr: [u32; 3],
diff --git a/src/tools/clippy/tests/ui/get_unwrap.rs b/src/tools/clippy/tests/ui/get_unwrap.rs
index af3a619ad..eaf6b005a 100644
--- a/src/tools/clippy/tests/ui/get_unwrap.rs
+++ b/src/tools/clippy/tests/ui/get_unwrap.rs
@@ -9,9 +9,7 @@
#![warn(clippy::unwrap_used)]
#![deny(clippy::get_unwrap)]
-use std::collections::BTreeMap;
-use std::collections::HashMap;
-use std::collections::VecDeque;
+use std::collections::{BTreeMap, HashMap, VecDeque};
struct GetFalsePositive {
arr: [u32; 3],
diff --git a/src/tools/clippy/tests/ui/get_unwrap.stderr b/src/tools/clippy/tests/ui/get_unwrap.stderr
index fd961420d..19dc9071f 100644
--- a/src/tools/clippy/tests/ui/get_unwrap.stderr
+++ b/src/tools/clippy/tests/ui/get_unwrap.stderr
@@ -1,8 +1,8 @@
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:40:17
+ --> $DIR/get_unwrap.rs:38:17
|
LL | let _ = boxed_slice.get(1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&boxed_slice[1]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&boxed_slice[1]`
|
note: the lint level is defined here
--> $DIR/get_unwrap.rs:10:9
@@ -11,205 +11,218 @@ LL | #![deny(clippy::get_unwrap)]
| ^^^^^^^^^^^^^^^^^^
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:40:17
+ --> $DIR/get_unwrap.rs:38:17
|
LL | let _ = 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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
= note: `-D clippy::unwrap-used` implied by `-D warnings`
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:41:17
+ --> $DIR/get_unwrap.rs:39:17
|
LL | let _ = some_slice.get(0).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_slice[0]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_slice[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:41:17
+ --> $DIR/get_unwrap.rs:39:17
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:42:17
+ --> $DIR/get_unwrap.rs:40:17
|
LL | let _ = some_vec.get(0).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vec[0]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vec[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:42:17
+ --> $DIR/get_unwrap.rs:40:17
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:43:17
+ --> $DIR/get_unwrap.rs:41:17
|
LL | let _ = some_vecdeque.get(0).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vecdeque[0]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_vecdeque[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:43:17
+ --> $DIR/get_unwrap.rs:41:17
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:44:17
+ --> $DIR/get_unwrap.rs:42:17
|
LL | let _ = some_hashmap.get(&1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_hashmap[&1]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_hashmap[&1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:44:17
+ --> $DIR/get_unwrap.rs:42:17
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:45:17
+ --> $DIR/get_unwrap.rs:43:17
|
LL | let _ = some_btreemap.get(&1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_btreemap[&1]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&some_btreemap[&1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:45:17
+ --> $DIR/get_unwrap.rs:43:17
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:49:21
+ --> $DIR/get_unwrap.rs:47:21
|
LL | let _: u8 = *boxed_slice.get(1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[1]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice[1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:49:22
+ --> $DIR/get_unwrap.rs:47:22
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:54:9
+ --> $DIR/get_unwrap.rs:52:9
|
LL | *boxed_slice.get_mut(0).unwrap() = 1;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[0]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:54:10
+ --> $DIR/get_unwrap.rs:52:10
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:55:9
+ --> $DIR/get_unwrap.rs:53:9
|
LL | *some_slice.get_mut(0).unwrap() = 1;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_slice[0]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_slice[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:55:10
+ --> $DIR/get_unwrap.rs:53:10
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:56:9
+ --> $DIR/get_unwrap.rs:54:9
|
LL | *some_vec.get_mut(0).unwrap() = 1;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:56:10
+ --> $DIR/get_unwrap.rs:54:10
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:57:9
+ --> $DIR/get_unwrap.rs:55:9
|
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vecdeque[0]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vecdeque[0]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:57:10
+ --> $DIR/get_unwrap.rs:55:10
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:69:17
+ --> $DIR/get_unwrap.rs:67:17
|
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0..1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:69:17
+ --> $DIR/get_unwrap.rs:67:17
|
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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:70:17
+ --> $DIR/get_unwrap.rs:68:17
|
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `some_vec[0..1]`
error: used `unwrap()` on an `Option` value
- --> $DIR/get_unwrap.rs:70:17
+ --> $DIR/get_unwrap.rs:68: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
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:80:24
+ --> $DIR/get_unwrap.rs:78:24
|
LL | let _x: &i32 = f.get(1 + 2).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `&f[1 + 2]`
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `&f[1 + 2]`
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:83:18
+ --> $DIR/get_unwrap.rs:81:18
|
LL | let _x = f.get(1 + 2).unwrap().to_string();
- | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `f[1 + 2]`
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `f[1 + 2]`
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:86:18
+ --> $DIR/get_unwrap.rs:84:18
|
LL | let _x = f.get(1 + 2).unwrap().abs();
- | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `f[1 + 2]`
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `f[1 + 2]`
error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/get_unwrap.rs:103:33
+ --> $DIR/get_unwrap.rs:101: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]`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&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 dad4543f8..e84b20e9f 100644
--- a/src/tools/clippy/tests/ui/if_same_then_else.rs
+++ b/src/tools/clippy/tests/ui/if_same_then_else.rs
@@ -214,4 +214,45 @@ mod issue_8836 {
}
}
+mod issue_11213 {
+ fn reproducer(x: bool) -> bool {
+ if x {
+ 0_u8.is_power_of_two()
+ } else {
+ 0_u16.is_power_of_two()
+ }
+ }
+
+ // a more obvious reproducer that shows
+ // why the code above is problematic:
+ fn v2(x: bool) -> bool {
+ trait Helper {
+ fn is_u8(&self) -> bool;
+ }
+ impl Helper for u8 {
+ fn is_u8(&self) -> bool {
+ true
+ }
+ }
+ impl Helper for u16 {
+ fn is_u8(&self) -> bool {
+ false
+ }
+ }
+
+ // this is certainly not the same code in both branches
+ // it returns a different bool depending on the branch.
+ if x { 0_u8.is_u8() } else { 0_u16.is_u8() }
+ }
+
+ fn do_lint(x: bool) -> bool {
+ // but do lint if the type of the literal is the same
+ if x {
+ 0_u8.is_power_of_two()
+ } else {
+ 0_u8.is_power_of_two()
+ }
+ }
+}
+
fn main() {}
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 a34fc5655..774cc0868 100644
--- a/src/tools/clippy/tests/ui/if_same_then_else.stderr
+++ b/src/tools/clippy/tests/ui/if_same_then_else.stderr
@@ -108,5 +108,23 @@ LL | | bar + 1;
LL | | }
| |_____^
-error: aborting due to 5 previous errors
+error: this `if` has identical blocks
+ --> $DIR/if_same_then_else.rs:250:14
+ |
+LL | if x {
+ | ______________^
+LL | | 0_u8.is_power_of_two()
+LL | | } else {
+ | |_________^
+ |
+note: same as this
+ --> $DIR/if_same_then_else.rs:252:16
+ |
+LL | } else {
+ | ________________^
+LL | | 0_u8.is_power_of_two()
+LL | | }
+ | |_________^
+
+error: aborting due to 6 previous errors
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 0b171f21d..c545434ef 100644
--- a/src/tools/clippy/tests/ui/if_same_then_else2.rs
+++ b/src/tools/clippy/tests/ui/if_same_then_else2.rs
@@ -98,7 +98,7 @@ fn if_same_then_else2() -> Result<&'static str, ()> {
};
if true {
- //~^ ERROR: this `if` has identical blocks
+ // FIXME: should emit "this `if` has identical blocks"
Ok("foo")?;
} else {
Ok("foo")?;
diff --git a/src/tools/clippy/tests/ui/if_same_then_else2.stderr b/src/tools/clippy/tests/ui/if_same_then_else2.stderr
index 56e5f3e45..37fe787d1 100644
--- a/src/tools/clippy/tests/ui/if_same_then_else2.stderr
+++ b/src/tools/clippy/tests/ui/if_same_then_else2.stderr
@@ -83,25 +83,6 @@ LL | | };
| |_____^
error: this `if` has identical blocks
- --> $DIR/if_same_then_else2.rs:100:13
- |
-LL | if true {
- | _____________^
-LL | |
-LL | | Ok("foo")?;
-LL | | } else {
- | |_____^
- |
-note: same as this
- --> $DIR/if_same_then_else2.rs:103:12
- |
-LL | } else {
- | ____________^
-LL | | Ok("foo")?;
-LL | | }
- | |_____^
-
-error: this `if` has identical blocks
--> $DIR/if_same_then_else2.rs:124:20
|
LL | } else if true {
@@ -122,5 +103,5 @@ LL | | return Ok(&foo[0..]);
LL | | }
| |_____^
-error: aborting due to 6 previous errors
+error: aborting due to 5 previous errors
diff --git a/src/tools/clippy/tests/ui/ifs_same_cond.rs b/src/tools/clippy/tests/ui/ifs_same_cond.rs
index 5c338e3c5..ad77346b7 100644
--- a/src/tools/clippy/tests/ui/ifs_same_cond.rs
+++ b/src/tools/clippy/tests/ui/ifs_same_cond.rs
@@ -46,6 +46,10 @@ fn ifs_same_cond() {
// ok, functions
} else if v.len() == 42 {
}
+
+ if let Some(env1) = option_env!("ENV1") {
+ } else if let Some(env2) = option_env!("ENV2") {
+ }
}
fn issue10272() {
diff --git a/src/tools/clippy/tests/ui/ifs_same_cond.stderr b/src/tools/clippy/tests/ui/ifs_same_cond.stderr
index 8d7093447..3f52c10b7 100644
--- a/src/tools/clippy/tests/ui/ifs_same_cond.stderr
+++ b/src/tools/clippy/tests/ui/ifs_same_cond.stderr
@@ -36,13 +36,13 @@ LL | if 2 * a == 1 {
| ^^^^^^^^^^
error: this `if` has the same condition as a previous `if`
- --> $DIR/ifs_same_cond.rs:54:15
+ --> $DIR/ifs_same_cond.rs:58:15
|
LL | } else if a.contains("ah") {
| ^^^^^^^^^^^^^^^^
|
note: same as this
- --> $DIR/ifs_same_cond.rs:53:8
+ --> $DIR/ifs_same_cond.rs:57:8
|
LL | if a.contains("ah") {
| ^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/ignored_unit_patterns.fixed b/src/tools/clippy/tests/ui/ignored_unit_patterns.fixed
new file mode 100644
index 000000000..492219fe4
--- /dev/null
+++ b/src/tools/clippy/tests/ui/ignored_unit_patterns.fixed
@@ -0,0 +1,17 @@
+//@run-rustfix
+
+#![warn(clippy::ignored_unit_patterns)]
+#![allow(clippy::redundant_pattern_matching, clippy::single_match)]
+
+fn foo() -> Result<(), ()> {
+ unimplemented!()
+}
+
+fn main() {
+ match foo() {
+ Ok(()) => {},
+ Err(()) => {},
+ }
+ if let Ok(()) = foo() {}
+ let _ = foo().map_err(|()| todo!());
+}
diff --git a/src/tools/clippy/tests/ui/ignored_unit_patterns.rs b/src/tools/clippy/tests/ui/ignored_unit_patterns.rs
new file mode 100644
index 000000000..90af36f8e
--- /dev/null
+++ b/src/tools/clippy/tests/ui/ignored_unit_patterns.rs
@@ -0,0 +1,17 @@
+//@run-rustfix
+
+#![warn(clippy::ignored_unit_patterns)]
+#![allow(clippy::redundant_pattern_matching, clippy::single_match)]
+
+fn foo() -> Result<(), ()> {
+ unimplemented!()
+}
+
+fn main() {
+ match foo() {
+ Ok(_) => {},
+ Err(_) => {},
+ }
+ if let Ok(_) = foo() {}
+ let _ = foo().map_err(|_| todo!());
+}
diff --git a/src/tools/clippy/tests/ui/ignored_unit_patterns.stderr b/src/tools/clippy/tests/ui/ignored_unit_patterns.stderr
new file mode 100644
index 000000000..8feea3cc2
--- /dev/null
+++ b/src/tools/clippy/tests/ui/ignored_unit_patterns.stderr
@@ -0,0 +1,28 @@
+error: matching over `()` is more explicit
+ --> $DIR/ignored_unit_patterns.rs:12:12
+ |
+LL | Ok(_) => {},
+ | ^ help: use `()` instead of `_`: `()`
+ |
+ = note: `-D clippy::ignored-unit-patterns` implied by `-D warnings`
+
+error: matching over `()` is more explicit
+ --> $DIR/ignored_unit_patterns.rs:13:13
+ |
+LL | Err(_) => {},
+ | ^ help: use `()` instead of `_`: `()`
+
+error: matching over `()` is more explicit
+ --> $DIR/ignored_unit_patterns.rs:15:15
+ |
+LL | if let Ok(_) = foo() {}
+ | ^ help: use `()` instead of `_`: `()`
+
+error: matching over `()` is more explicit
+ --> $DIR/ignored_unit_patterns.rs:16:28
+ |
+LL | let _ = foo().map_err(|_| todo!());
+ | ^ help: use `()` instead of `_`: `()`
+
+error: aborting due to 4 previous errors
+
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
index 0021841aa..7bcba8ba4 100644
--- 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
@@ -16,7 +16,7 @@ LL | / fn clone_from(&mut self, source: &Self) {
LL | | source.clone();
LL | | *self = source.clone();
LL | | }
- | |_____^ help: remove this
+ | |_____^ help: remove it
error: incorrect implementation of `clone` on a `Copy` type
--> $DIR/incorrect_clone_impl_on_copy_type.rs:81:29
@@ -34,7 +34,7 @@ LL | / fn clone_from(&mut self, source: &Self) {
LL | | source.clone();
LL | | *self = source.clone();
LL | | }
- | |_____^ help: remove this
+ | |_____^ help: remove it
error: aborting due to 4 previous errors
diff --git a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.fixed b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.fixed
new file mode 100644
index 000000000..2f51bf274
--- /dev/null
+++ b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.fixed
@@ -0,0 +1,145 @@
+//@run-rustfix
+#![no_main]
+
+use std::cmp::Ordering;
+
+// lint
+
+#[derive(Eq, PartialEq)]
+struct A(u32);
+
+impl Ord for A {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl PartialOrd for A {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
+}
+
+// do not lint
+
+#[derive(Eq, PartialEq)]
+struct B(u32);
+
+impl Ord for B {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl PartialOrd for B {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
+// lint, and give `_` a name
+
+#[derive(Eq, PartialEq)]
+struct C(u32);
+
+impl Ord for C {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl PartialOrd for C {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
+}
+
+// do not lint derived
+
+#[derive(Eq, Ord, PartialEq, PartialOrd)]
+struct D(u32);
+
+// do not lint if ord is not manually implemented
+
+#[derive(Eq, PartialEq)]
+struct E(u32);
+
+impl PartialOrd for E {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ todo!();
+ }
+}
+
+// do not lint since ord has more restrictive bounds
+
+#[derive(Eq, PartialEq)]
+struct Uwu<A>(A);
+
+impl<A: std::fmt::Debug + Ord + PartialOrd> Ord for Uwu<A> {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl<A: Ord + PartialOrd> PartialOrd for Uwu<A> {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ todo!();
+ }
+}
+
+// do not lint since `Rhs` is not `Self`
+
+#[derive(Eq, PartialEq)]
+struct F(u32);
+
+impl Ord for F {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl PartialOrd for F {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
+impl PartialEq<u32> for F {
+ fn eq(&self, other: &u32) -> bool {
+ todo!();
+ }
+}
+
+impl PartialOrd<u32> for F {
+ fn partial_cmp(&self, other: &u32) -> Option<Ordering> {
+ todo!();
+ }
+}
+
+// #11178, do not lint
+
+#[derive(Eq, PartialEq)]
+struct G(u32);
+
+impl Ord for G {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl PartialOrd for G {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(Self::cmp(self, other))
+ }
+}
+
+#[derive(Eq, PartialEq)]
+struct H(u32);
+
+impl Ord for H {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl PartialOrd for H {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(Ord::cmp(self, other))
+ }
+}
diff --git a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.rs b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.rs
new file mode 100644
index 000000000..47127bdae
--- /dev/null
+++ b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.rs
@@ -0,0 +1,149 @@
+//@run-rustfix
+#![no_main]
+
+use std::cmp::Ordering;
+
+// lint
+
+#[derive(Eq, PartialEq)]
+struct A(u32);
+
+impl Ord for A {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl PartialOrd for A {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ todo!();
+ }
+}
+
+// do not lint
+
+#[derive(Eq, PartialEq)]
+struct B(u32);
+
+impl Ord for B {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl PartialOrd for B {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
+// lint, and give `_` a name
+
+#[derive(Eq, PartialEq)]
+struct C(u32);
+
+impl Ord for C {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl PartialOrd for C {
+ fn partial_cmp(&self, _: &Self) -> Option<Ordering> {
+ todo!();
+ }
+}
+
+// do not lint derived
+
+#[derive(Eq, Ord, PartialEq, PartialOrd)]
+struct D(u32);
+
+// do not lint if ord is not manually implemented
+
+#[derive(Eq, PartialEq)]
+struct E(u32);
+
+impl PartialOrd for E {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ todo!();
+ }
+}
+
+// do not lint since ord has more restrictive bounds
+
+#[derive(Eq, PartialEq)]
+struct Uwu<A>(A);
+
+impl<A: std::fmt::Debug + Ord + PartialOrd> Ord for Uwu<A> {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl<A: Ord + PartialOrd> PartialOrd for Uwu<A> {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ todo!();
+ }
+}
+
+// do not lint since `Rhs` is not `Self`
+
+#[derive(Eq, PartialEq)]
+struct F(u32);
+
+impl Ord for F {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl PartialOrd for F {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
+impl PartialEq<u32> for F {
+ fn eq(&self, other: &u32) -> bool {
+ todo!();
+ }
+}
+
+impl PartialOrd<u32> for F {
+ fn partial_cmp(&self, other: &u32) -> Option<Ordering> {
+ todo!();
+ }
+}
+
+// #11178, do not lint
+
+#[derive(Eq, PartialEq)]
+struct G(u32);
+
+impl Ord for G {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl PartialOrd for G {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(Self::cmp(self, other))
+ }
+}
+
+#[derive(Eq, PartialEq)]
+struct H(u32);
+
+impl Ord for H {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl PartialOrd for H {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ Some(Ord::cmp(self, other))
+ }
+}
diff --git a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.stderr b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.stderr
new file mode 100644
index 000000000..66048fc90
--- /dev/null
+++ b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type.stderr
@@ -0,0 +1,31 @@
+error: incorrect implementation of `partial_cmp` on an `Ord` type
+ --> $DIR/incorrect_partial_ord_impl_on_ord_type.rs:17:1
+ |
+LL | / impl PartialOrd for A {
+LL | | fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ | | _____________________________________________________________-
+LL | || todo!();
+LL | || }
+ | ||_____- help: change this to: `{ Some(self.cmp(other)) }`
+LL | | }
+ | |__^
+ |
+ = note: `#[deny(clippy::incorrect_partial_ord_impl_on_ord_type)]` on by default
+
+error: incorrect implementation of `partial_cmp` on an `Ord` type
+ --> $DIR/incorrect_partial_ord_impl_on_ord_type.rs:51:1
+ |
+LL | / impl PartialOrd for C {
+LL | | fn partial_cmp(&self, _: &Self) -> Option<Ordering> {
+LL | | todo!();
+LL | | }
+LL | | }
+ | |_^
+ |
+help: change this to
+ |
+LL | fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
+ | ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
+
+error: aborting due to 2 previous errors
+
diff --git a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs
new file mode 100644
index 000000000..3a3b84f93
--- /dev/null
+++ b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs
@@ -0,0 +1,51 @@
+// This test's filename is... a bit verbose. But it ensures we suggest the correct code when `Ord`
+// is not in scope.
+#![no_main]
+#![no_implicit_prelude]
+
+extern crate std;
+
+use std::cmp::{self, Eq, Ordering, PartialEq, PartialOrd};
+use std::option::Option::{self, Some};
+use std::todo;
+
+// lint
+
+#[derive(Eq, PartialEq)]
+struct A(u32);
+
+impl cmp::Ord for A {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl PartialOrd for A {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ // NOTE: This suggestion is wrong, as `Ord` is not in scope. But this should be fine as it isn't
+ // automatically applied
+ todo!();
+ }
+}
+
+#[derive(Eq, PartialEq)]
+struct B(u32);
+
+impl B {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl cmp::Ord for B {
+ fn cmp(&self, other: &Self) -> Ordering {
+ todo!();
+ }
+}
+
+impl PartialOrd for B {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ // This calls `B.cmp`, not `Ord::cmp`!
+ Some(self.cmp(other))
+ }
+}
diff --git a/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr
new file mode 100644
index 000000000..f4374c281
--- /dev/null
+++ b/src/tools/clippy/tests/ui/incorrect_partial_ord_impl_on_ord_type_fully_qual.stderr
@@ -0,0 +1,31 @@
+error: incorrect implementation of `partial_cmp` on an `Ord` type
+ --> $DIR/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs:23:1
+ |
+LL | / impl PartialOrd for A {
+LL | | fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ | | _____________________________________________________________-
+LL | || // NOTE: This suggestion is wrong, as `Ord` is not in scope. But this should be fine as it isn't
+LL | || // automatically applied
+LL | || todo!();
+LL | || }
+ | ||_____- help: change this to: `{ Some(self.cmp(other)) }`
+LL | | }
+ | |__^
+ |
+ = note: `#[deny(clippy::incorrect_partial_ord_impl_on_ord_type)]` on by default
+
+error: incorrect implementation of `partial_cmp` on an `Ord` type
+ --> $DIR/incorrect_partial_ord_impl_on_ord_type_fully_qual.rs:46:1
+ |
+LL | / impl PartialOrd for B {
+LL | | fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ | | _____________________________________________________________-
+LL | || // This calls `B.cmp`, not `Ord::cmp`!
+LL | || Some(self.cmp(other))
+LL | || }
+ | ||_____- help: change this to: `{ Some(std::cmp::Ord::cmp(self, other)) }`
+LL | | }
+ | |__^
+
+error: aborting due to 2 previous errors
+
diff --git a/src/tools/clippy/tests/ui/infallible_destructuring_match.stderr b/src/tools/clippy/tests/ui/infallible_destructuring_match.stderr
index f8a50f022..004260a1d 100644
--- a/src/tools/clippy/tests/ui/infallible_destructuring_match.stderr
+++ b/src/tools/clippy/tests/ui/infallible_destructuring_match.stderr
@@ -4,7 +4,7 @@ error: you seem to be trying to use `match` to destructure a single infallible p
LL | / let data = match wrapper {
LL | | SingleVariantEnum::Variant(i) => i,
LL | | };
- | |______^ help: try this: `let SingleVariantEnum::Variant(data) = wrapper;`
+ | |______^ help: try: `let SingleVariantEnum::Variant(data) = wrapper;`
|
= note: `-D clippy::infallible-destructuring-match` implied by `-D warnings`
@@ -14,7 +14,7 @@ error: you seem to be trying to use `match` to destructure a single infallible p
LL | / let data = match wrapper {
LL | | TupleStruct(i) => i,
LL | | };
- | |______^ help: try this: `let TupleStruct(data) = wrapper;`
+ | |______^ help: try: `let TupleStruct(data) = wrapper;`
error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let`
--> $DIR/infallible_destructuring_match.rs:85:5
@@ -22,7 +22,7 @@ error: you seem to be trying to use `match` to destructure a single infallible p
LL | / let data = match wrapper {
LL | | TupleStructWithNonCopy(ref n) => n,
LL | | };
- | |______^ help: try this: `let TupleStructWithNonCopy(ref data) = wrapper;`
+ | |______^ help: try: `let TupleStructWithNonCopy(ref data) = wrapper;`
error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let`
--> $DIR/infallible_destructuring_match.rs:104:5
@@ -30,7 +30,7 @@ error: you seem to be trying to use `match` to destructure a single infallible p
LL | / let data = match wrapper {
LL | | Ok(i) => i,
LL | | };
- | |______^ help: try this: `let Ok(data) = wrapper;`
+ | |______^ help: try: `let Ok(data) = wrapper;`
error: aborting due to 4 previous errors
diff --git a/src/tools/clippy/tests/ui/inherent_to_string.rs b/src/tools/clippy/tests/ui/inherent_to_string.rs
index aeb0a0c1e..adb0389a0 100644
--- a/src/tools/clippy/tests/ui/inherent_to_string.rs
+++ b/src/tools/clippy/tests/ui/inherent_to_string.rs
@@ -1,5 +1,4 @@
-#![warn(clippy::inherent_to_string)]
-#![deny(clippy::inherent_to_string_shadow_display)]
+#![allow(improper_ctypes_definitions)]
use std::fmt;
@@ -14,6 +13,9 @@ struct D;
struct E;
struct F;
struct G;
+struct H;
+struct I;
+struct J;
impl A {
// Should be detected; emit warning
@@ -80,6 +82,26 @@ impl G {
}
}
+// Issue #11201
+
+impl H {
+ unsafe fn to_string(&self) -> String {
+ "G.to_string()".to_string()
+ }
+}
+
+impl I {
+ extern "C" fn to_string(&self) -> String {
+ "G.to_string()".to_string()
+ }
+}
+
+impl J {
+ unsafe extern "C" fn to_string(&self) -> String {
+ "G.to_string()".to_string()
+ }
+}
+
fn main() {
let a = A;
a.to_string();
diff --git a/src/tools/clippy/tests/ui/inherent_to_string.stderr b/src/tools/clippy/tests/ui/inherent_to_string.stderr
index 443fecae1..579b3c8c5 100644
--- a/src/tools/clippy/tests/ui/inherent_to_string.stderr
+++ b/src/tools/clippy/tests/ui/inherent_to_string.stderr
@@ -1,5 +1,5 @@
error: implementation of inherent method `to_string(&self) -> String` for type `A`
- --> $DIR/inherent_to_string.rs:20:5
+ --> $DIR/inherent_to_string.rs:22:5
|
LL | / fn to_string(&self) -> String {
LL | | "A.to_string()".to_string()
@@ -10,7 +10,7 @@ LL | | }
= note: `-D clippy::inherent-to-string` implied by `-D warnings`
error: type `C` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`
- --> $DIR/inherent_to_string.rs:44:5
+ --> $DIR/inherent_to_string.rs:46:5
|
LL | / fn to_string(&self) -> String {
LL | | "C.to_string()".to_string()
@@ -18,11 +18,7 @@ LL | | }
| |_____^
|
= help: remove the inherent method from type `C`
-note: the lint level is defined here
- --> $DIR/inherent_to_string.rs:2:9
- |
-LL | #![deny(clippy::inherent_to_string_shadow_display)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: `#[deny(clippy::inherent_to_string_shadow_display)]` on by default
error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui/issue-7447.rs b/src/tools/clippy/tests/ui/issue-7447.rs
index fdb77f322..de4362c4d 100644
--- a/src/tools/clippy/tests/ui/issue-7447.rs
+++ b/src/tools/clippy/tests/ui/issue-7447.rs
@@ -1,4 +1,7 @@
-use std::{borrow::Cow, collections::BTreeMap, marker::PhantomData, sync::Arc};
+use std::borrow::Cow;
+use std::collections::BTreeMap;
+use std::marker::PhantomData;
+use std::sync::Arc;
fn byte_view<'a>(s: &'a ByteView<'_>) -> BTreeMap<&'a str, ByteView<'a>> {
panic!()
diff --git a/src/tools/clippy/tests/ui/issue-7447.stderr b/src/tools/clippy/tests/ui/issue-7447.stderr
index 8d8c29f13..7a113740c 100644
--- a/src/tools/clippy/tests/ui/issue-7447.stderr
+++ b/src/tools/clippy/tests/ui/issue-7447.stderr
@@ -1,5 +1,5 @@
error: sub-expression diverges
- --> $DIR/issue-7447.rs:23:15
+ --> $DIR/issue-7447.rs:26:15
|
LL | byte_view(panic!());
| ^^^^^^^^
@@ -8,7 +8,7 @@ LL | byte_view(panic!());
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error: sub-expression diverges
- --> $DIR/issue-7447.rs:24:19
+ --> $DIR/issue-7447.rs:27:19
|
LL | group_entries(panic!());
| ^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/iter_cloned_collect.fixed b/src/tools/clippy/tests/ui/iter_cloned_collect.fixed
index 2baea06f8..636f572a3 100644
--- a/src/tools/clippy/tests/ui/iter_cloned_collect.fixed
+++ b/src/tools/clippy/tests/ui/iter_cloned_collect.fixed
@@ -3,8 +3,7 @@
#![allow(unused)]
#![allow(clippy::useless_vec)]
-use std::collections::HashSet;
-use std::collections::VecDeque;
+use std::collections::{HashSet, VecDeque};
fn main() {
let v = [1, 2, 3, 4, 5];
diff --git a/src/tools/clippy/tests/ui/iter_cloned_collect.rs b/src/tools/clippy/tests/ui/iter_cloned_collect.rs
index 9eac94eb8..518cb75af 100644
--- a/src/tools/clippy/tests/ui/iter_cloned_collect.rs
+++ b/src/tools/clippy/tests/ui/iter_cloned_collect.rs
@@ -3,8 +3,7 @@
#![allow(unused)]
#![allow(clippy::useless_vec)]
-use std::collections::HashSet;
-use std::collections::VecDeque;
+use std::collections::{HashSet, VecDeque};
fn main() {
let v = [1, 2, 3, 4, 5];
diff --git a/src/tools/clippy/tests/ui/iter_cloned_collect.stderr b/src/tools/clippy/tests/ui/iter_cloned_collect.stderr
index b38cf547d..b2cc497bf 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:11:27
+ --> $DIR/iter_cloned_collect.rs:10: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:16:38
+ --> $DIR/iter_cloned_collect.rs:15: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:21:24
+ --> $DIR/iter_cloned_collect.rs:20: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:29:24
+ --> $DIR/iter_cloned_collect.rs:28: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:32:26
+ --> $DIR/iter_cloned_collect.rs:31:26
|
LL | let _: Vec<isize> = v.iter().copied().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.to_vec()`
diff --git a/src/tools/clippy/tests/ui/iter_overeager_cloned.stderr b/src/tools/clippy/tests/ui/iter_overeager_cloned.stderr
index dcae7cecd..eaac48be8 100644
--- a/src/tools/clippy/tests/ui/iter_overeager_cloned.stderr
+++ b/src/tools/clippy/tests/ui/iter_overeager_cloned.stderr
@@ -4,7 +4,7 @@ error: unnecessarily eager cloning of iterator items
LL | let _: Option<String> = vec.iter().cloned().last();
| ^^^^^^^^^^----------------
| |
- | help: try this: `.last().cloned()`
+ | help: try: `.last().cloned()`
|
= note: `-D clippy::iter-overeager-cloned` implied by `-D warnings`
@@ -14,7 +14,7 @@ error: unnecessarily eager cloning of iterator items
LL | let _: Option<String> = vec.iter().chain(vec.iter()).cloned().next();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------
| |
- | help: try this: `.next().cloned()`
+ | help: try: `.next().cloned()`
error: unneeded cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:12:20
@@ -22,7 +22,7 @@ error: unneeded cloning of iterator items
LL | let _: usize = vec.iter().filter(|x| x == &"2").cloned().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------
| |
- | help: try this: `.count()`
+ | help: try: `.count()`
|
= note: `-D clippy::redundant-clone` implied by `-D warnings`
@@ -32,7 +32,7 @@ error: unnecessarily eager cloning of iterator items
LL | let _: Vec<_> = vec.iter().cloned().take(2).collect();
| ^^^^^^^^^^-----------------
| |
- | help: try this: `.take(2).cloned()`
+ | help: try: `.take(2).cloned()`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:16:21
@@ -40,7 +40,7 @@ error: unnecessarily eager cloning of iterator items
LL | let _: Vec<_> = vec.iter().cloned().skip(2).collect();
| ^^^^^^^^^^-----------------
| |
- | help: try this: `.skip(2).cloned()`
+ | help: try: `.skip(2).cloned()`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:18:13
@@ -48,7 +48,7 @@ error: unnecessarily eager cloning of iterator items
LL | let _ = vec.iter().filter(|x| x == &"2").cloned().nth(2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------
| |
- | help: try this: `.nth(2).cloned()`
+ | help: try: `.nth(2).cloned()`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:20:13
@@ -60,7 +60,7 @@ LL | | .cloned()
LL | | .flatten();
| |__________________^
|
-help: try this
+help: try
|
LL ~ .iter()
LL ~ .flatten().cloned();
diff --git a/src/tools/clippy/tests/ui/iter_skip_zero.fixed b/src/tools/clippy/tests/ui/iter_skip_zero.fixed
new file mode 100644
index 000000000..1eb0984fe
--- /dev/null
+++ b/src/tools/clippy/tests/ui/iter_skip_zero.fixed
@@ -0,0 +1,25 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(clippy::useless_vec, unused)]
+#![warn(clippy::iter_skip_zero)]
+
+#[macro_use]
+extern crate proc_macros;
+
+use std::iter::once;
+
+fn main() {
+ let _ = [1, 2, 3].iter().skip(1);
+ let _ = vec![1, 2, 3].iter().skip(1);
+ let _ = once([1, 2, 3]).skip(1);
+ let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(1)).skip(1);
+ // Don't lint
+ let _ = [1, 2, 3].iter().skip(1);
+ let _ = vec![1, 2, 3].iter().skip(1);
+ external! {
+ let _ = [1, 2, 3].iter().skip(0);
+ }
+ with_span! {
+ let _ = [1, 2, 3].iter().skip(0);
+ }
+}
diff --git a/src/tools/clippy/tests/ui/iter_skip_zero.rs b/src/tools/clippy/tests/ui/iter_skip_zero.rs
new file mode 100644
index 000000000..8c103ab1d
--- /dev/null
+++ b/src/tools/clippy/tests/ui/iter_skip_zero.rs
@@ -0,0 +1,25 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(clippy::useless_vec, unused)]
+#![warn(clippy::iter_skip_zero)]
+
+#[macro_use]
+extern crate proc_macros;
+
+use std::iter::once;
+
+fn main() {
+ let _ = [1, 2, 3].iter().skip(0);
+ let _ = vec![1, 2, 3].iter().skip(0);
+ let _ = once([1, 2, 3]).skip(0);
+ let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(0)).skip(0);
+ // Don't lint
+ let _ = [1, 2, 3].iter().skip(1);
+ let _ = vec![1, 2, 3].iter().skip(1);
+ external! {
+ let _ = [1, 2, 3].iter().skip(0);
+ }
+ with_span! {
+ let _ = [1, 2, 3].iter().skip(0);
+ }
+}
diff --git a/src/tools/clippy/tests/ui/iter_skip_zero.stderr b/src/tools/clippy/tests/ui/iter_skip_zero.stderr
new file mode 100644
index 000000000..80fecd59e
--- /dev/null
+++ b/src/tools/clippy/tests/ui/iter_skip_zero.stderr
@@ -0,0 +1,43 @@
+error: usage of `.skip(0)`
+ --> $DIR/iter_skip_zero.rs:12:35
+ |
+LL | let _ = [1, 2, 3].iter().skip(0);
+ | ^ help: if you meant to skip the first element, use: `1`
+ |
+ = note: this call to `skip` does nothing and is useless; remove it
+ = note: `-D clippy::iter-skip-zero` implied by `-D warnings`
+
+error: usage of `.skip(0)`
+ --> $DIR/iter_skip_zero.rs:13:39
+ |
+LL | let _ = vec![1, 2, 3].iter().skip(0);
+ | ^ help: if you meant to skip the first element, use: `1`
+ |
+ = note: this call to `skip` does nothing and is useless; remove it
+
+error: usage of `.skip(0)`
+ --> $DIR/iter_skip_zero.rs:14:34
+ |
+LL | let _ = once([1, 2, 3]).skip(0);
+ | ^ help: if you meant to skip the first element, use: `1`
+ |
+ = note: this call to `skip` does nothing and is useless; remove it
+
+error: usage of `.skip(0)`
+ --> $DIR/iter_skip_zero.rs:15:71
+ |
+LL | let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(0)).skip(0);
+ | ^ help: if you meant to skip the first element, use: `1`
+ |
+ = note: this call to `skip` does nothing and is useless; remove it
+
+error: usage of `.skip(0)`
+ --> $DIR/iter_skip_zero.rs:15:62
+ |
+LL | let _ = vec![1, 2, 3].iter().chain([1, 2, 3].iter().skip(0)).skip(0);
+ | ^ help: if you meant to skip the first element, use: `1`
+ |
+ = note: this call to `skip` does nothing and is useless; remove it
+
+error: aborting due to 5 previous errors
+
diff --git a/src/tools/clippy/tests/ui/iter_with_drain.stderr b/src/tools/clippy/tests/ui/iter_with_drain.stderr
index aa394439f..bfaed29a0 100644
--- a/src/tools/clippy/tests/ui/iter_with_drain.stderr
+++ b/src/tools/clippy/tests/ui/iter_with_drain.stderr
@@ -2,7 +2,7 @@ error: `drain(..)` used on a `Vec`
--> $DIR/iter_with_drain.rs:11:34
|
LL | let mut a: BinaryHeap<_> = a.drain(..).collect();
- | ^^^^^^^^^ help: try this: `into_iter()`
+ | ^^^^^^^^^ help: try: `into_iter()`
|
= note: `-D clippy::iter-with-drain` implied by `-D warnings`
@@ -10,31 +10,31 @@ error: `drain(..)` used on a `VecDeque`
--> $DIR/iter_with_drain.rs:14:27
|
LL | let mut a: Vec<_> = a.drain(..).collect();
- | ^^^^^^^^^ help: try this: `into_iter()`
+ | ^^^^^^^^^ help: try: `into_iter()`
error: `drain(..)` used on a `Vec`
--> $DIR/iter_with_drain.rs:15:34
|
LL | let mut a: HashMap<_, _> = a.drain(..).map(|x| (x.clone(), x)).collect();
- | ^^^^^^^^^ help: try this: `into_iter()`
+ | ^^^^^^^^^ help: try: `into_iter()`
error: `drain(..)` used on a `Vec`
--> $DIR/iter_with_drain.rs:21:34
|
LL | let mut a: BinaryHeap<_> = a.drain(0..).collect();
- | ^^^^^^^^^^ help: try this: `into_iter()`
+ | ^^^^^^^^^^ help: try: `into_iter()`
error: `drain(..)` used on a `VecDeque`
--> $DIR/iter_with_drain.rs:24:27
|
LL | let mut a: Vec<_> = a.drain(..a.len()).collect();
- | ^^^^^^^^^^^^^^^^ help: try this: `into_iter()`
+ | ^^^^^^^^^^^^^^^^ help: try: `into_iter()`
error: `drain(..)` used on a `Vec`
--> $DIR/iter_with_drain.rs:25:34
|
LL | let mut a: HashMap<_, _> = a.drain(0..a.len()).map(|x| (x.clone(), x)).collect();
- | ^^^^^^^^^^^^^^^^^ help: try this: `into_iter()`
+ | ^^^^^^^^^^^^^^^^^ help: try: `into_iter()`
error: aborting due to 6 previous errors
diff --git a/src/tools/clippy/tests/ui/let_and_return.rs b/src/tools/clippy/tests/ui/let_and_return.rs
index bb162adc9..64665cc90 100644
--- a/src/tools/clippy/tests/ui/let_and_return.rs
+++ b/src/tools/clippy/tests/ui/let_and_return.rs
@@ -1,6 +1,8 @@
#![allow(unused)]
#![warn(clippy::let_and_return)]
+use std::cell::RefCell;
+
fn test() -> i32 {
let _y = 0; // no warning
let x = 5;
@@ -65,45 +67,46 @@ macro_rules! tuple_encode {
);
}
+fn issue_3792() -> String {
+ use std::io::{self, BufRead, Stdin};
+
+ let stdin = io::stdin();
+ // `Stdin::lock` returns `StdinLock<'static>` so `line` doesn't borrow from `stdin`
+ // https://github.com/rust-lang/rust/pull/93965
+ let line = stdin.lock().lines().next().unwrap().unwrap();
+ line
+}
+
tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7);
mod no_lint_if_stmt_borrows {
- mod issue_3792 {
- use std::io::{self, BufRead, Stdin};
+ use std::cell::RefCell;
+ use std::rc::{Rc, Weak};
+ struct Bar;
- fn read_line() -> String {
- let stdin = io::stdin();
- let line = stdin.lock().lines().next().unwrap().unwrap();
- line
+ impl Bar {
+ fn new() -> Self {
+ Bar {}
}
- }
-
- mod issue_3324 {
- use std::cell::RefCell;
- use std::rc::{Rc, Weak};
-
- fn test(value: Weak<RefCell<Bar>>) -> u32 {
- let value = value.upgrade().unwrap();
- let ret = value.borrow().baz();
- ret
+ fn baz(&self) -> u32 {
+ 0
}
+ }
- struct Bar;
+ fn issue_3324(value: Weak<RefCell<Bar>>) -> u32 {
+ let value = value.upgrade().unwrap();
+ let ret = value.borrow().baz();
+ ret
+ }
- impl Bar {
- fn new() -> Self {
- Bar {}
- }
- fn baz(&self) -> u32 {
- 0
- }
+ fn borrows_in_closure(value: Weak<RefCell<Bar>>) -> u32 {
+ fn f(mut x: impl FnMut() -> u32) -> impl FnMut() -> u32 {
+ x
}
- fn main() {
- let a = Rc::new(RefCell::new(Bar::new()));
- let b = Rc::downgrade(&a);
- test(b);
- }
+ let value = value.upgrade().unwrap();
+ let ret = f(|| value.borrow().baz())();
+ ret
}
mod free_function {
@@ -166,4 +169,14 @@ mod issue_5729 {
}
}
+// https://github.com/rust-lang/rust-clippy/issues/11167
+macro_rules! fn_in_macro {
+ ($b:block) => {
+ fn f() -> usize $b
+ }
+}
+fn_in_macro!({
+ return 1;
+});
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/let_and_return.stderr b/src/tools/clippy/tests/ui/let_and_return.stderr
index 17fd694bf..4ca0a05c8 100644
--- a/src/tools/clippy/tests/ui/let_and_return.stderr
+++ b/src/tools/clippy/tests/ui/let_and_return.stderr
@@ -1,5 +1,5 @@
error: returning the result of a `let` binding from a block
- --> $DIR/let_and_return.rs:7:5
+ --> $DIR/let_and_return.rs:9:5
|
LL | let x = 5;
| ---------- unnecessary `let` binding
@@ -14,7 +14,7 @@ LL ~ 5
|
error: returning the result of a `let` binding from a block
- --> $DIR/let_and_return.rs:13:9
+ --> $DIR/let_and_return.rs:15:9
|
LL | let x = 5;
| ---------- unnecessary `let` binding
@@ -28,7 +28,21 @@ LL ~ 5
|
error: returning the result of a `let` binding from a block
- --> $DIR/let_and_return.rs:164:13
+ --> $DIR/let_and_return.rs:77:5
+ |
+LL | let line = stdin.lock().lines().next().unwrap().unwrap();
+ | --------------------------------------------------------- unnecessary `let` binding
+LL | line
+ | ^^^^
+ |
+help: return the expression directly
+ |
+LL ~
+LL ~ stdin.lock().lines().next().unwrap().unwrap()
+ |
+
+error: returning the result of a `let` binding from a block
+ --> $DIR/let_and_return.rs:167:13
|
LL | let clone = Arc::clone(&self.foo);
| ---------------------------------- unnecessary `let` binding
@@ -41,5 +55,5 @@ LL ~
LL ~ Arc::clone(&self.foo) as _
|
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
diff --git a/src/tools/clippy/tests/ui/let_underscore_lock.rs b/src/tools/clippy/tests/ui/let_underscore_lock.rs
index 4dff4d766..87f12e278 100644
--- a/src/tools/clippy/tests/ui/let_underscore_lock.rs
+++ b/src/tools/clippy/tests/ui/let_underscore_lock.rs
@@ -3,7 +3,8 @@
extern crate parking_lot;
fn main() {
- use parking_lot::{lock_api::RawMutex, Mutex, RwLock};
+ use parking_lot::lock_api::RawMutex;
+ use parking_lot::{Mutex, RwLock};
let p_m: Mutex<()> = Mutex::const_new(RawMutex::INIT, ());
let _ = p_m.lock();
diff --git a/src/tools/clippy/tests/ui/let_underscore_lock.stderr b/src/tools/clippy/tests/ui/let_underscore_lock.stderr
index f137d4112..5027e6b3c 100644
--- a/src/tools/clippy/tests/ui/let_underscore_lock.stderr
+++ b/src/tools/clippy/tests/ui/let_underscore_lock.stderr
@@ -1,5 +1,5 @@
error: non-binding `let` on a synchronization lock
- --> $DIR/let_underscore_lock.rs:9:5
+ --> $DIR/let_underscore_lock.rs:10:5
|
LL | let _ = p_m.lock();
| ^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | let _ = p_m.lock();
= note: `-D clippy::let-underscore-lock` implied by `-D warnings`
error: non-binding `let` on a synchronization lock
- --> $DIR/let_underscore_lock.rs:12:5
+ --> $DIR/let_underscore_lock.rs:13:5
|
LL | let _ = p_m1.lock();
| ^^^^^^^^^^^^^^^^^^^^
@@ -16,7 +16,7 @@ LL | let _ = p_m1.lock();
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
error: non-binding `let` on a synchronization lock
- --> $DIR/let_underscore_lock.rs:15:5
+ --> $DIR/let_underscore_lock.rs:16:5
|
LL | let _ = p_rw.read();
| ^^^^^^^^^^^^^^^^^^^^
@@ -24,7 +24,7 @@ LL | let _ = p_rw.read();
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
error: non-binding `let` on a synchronization lock
- --> $DIR/let_underscore_lock.rs:16:5
+ --> $DIR/let_underscore_lock.rs:17:5
|
LL | let _ = p_rw.write();
| ^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/let_underscore_untyped.rs b/src/tools/clippy/tests/ui/let_underscore_untyped.rs
index 431d83778..18630c27f 100644
--- a/src/tools/clippy/tests/ui/let_underscore_untyped.rs
+++ b/src/tools/clippy/tests/ui/let_underscore_untyped.rs
@@ -7,8 +7,9 @@ extern crate proc_macros;
use proc_macros::with_span;
use clippy_utils::is_from_proc_macro;
+use std::boxed::Box;
+use std::fmt::Display;
use std::future::Future;
-use std::{boxed::Box, fmt::Display};
fn a() -> u32 {
1
diff --git a/src/tools/clippy/tests/ui/let_underscore_untyped.stderr b/src/tools/clippy/tests/ui/let_underscore_untyped.stderr
index bbf2508af..e0c39b6ee 100644
--- a/src/tools/clippy/tests/ui/let_underscore_untyped.stderr
+++ b/src/tools/clippy/tests/ui/let_underscore_untyped.stderr
@@ -1,60 +1,60 @@
error: non-binding `let` without a type annotation
- --> $DIR/let_underscore_untyped.rs:50:5
+ --> $DIR/let_underscore_untyped.rs:51:5
|
LL | let _ = a();
| ^^^^^^^^^^^^
|
help: consider adding a type annotation
- --> $DIR/let_underscore_untyped.rs:50:10
+ --> $DIR/let_underscore_untyped.rs:51:10
|
LL | let _ = a();
| ^
= note: `-D clippy::let-underscore-untyped` implied by `-D warnings`
error: non-binding `let` without a type annotation
- --> $DIR/let_underscore_untyped.rs:51:5
+ --> $DIR/let_underscore_untyped.rs:52:5
|
LL | let _ = b(1);
| ^^^^^^^^^^^^^
|
help: consider adding a type annotation
- --> $DIR/let_underscore_untyped.rs:51:10
+ --> $DIR/let_underscore_untyped.rs:52:10
|
LL | let _ = b(1);
| ^
error: non-binding `let` without a type annotation
- --> $DIR/let_underscore_untyped.rs:53:5
+ --> $DIR/let_underscore_untyped.rs:54:5
|
LL | let _ = d(&1);
| ^^^^^^^^^^^^^^
|
help: consider adding a type annotation
- --> $DIR/let_underscore_untyped.rs:53:10
+ --> $DIR/let_underscore_untyped.rs:54:10
|
LL | let _ = d(&1);
| ^
error: non-binding `let` without a type annotation
- --> $DIR/let_underscore_untyped.rs:54:5
+ --> $DIR/let_underscore_untyped.rs:55:5
|
LL | let _ = e();
| ^^^^^^^^^^^^
|
help: consider adding a type annotation
- --> $DIR/let_underscore_untyped.rs:54:10
+ --> $DIR/let_underscore_untyped.rs:55:10
|
LL | let _ = e();
| ^
error: non-binding `let` without a type annotation
- --> $DIR/let_underscore_untyped.rs:55:5
+ --> $DIR/let_underscore_untyped.rs:56:5
|
LL | let _ = f();
| ^^^^^^^^^^^^
|
help: consider adding a type annotation
- --> $DIR/let_underscore_untyped.rs:55:10
+ --> $DIR/let_underscore_untyped.rs:56:10
|
LL | let _ = f();
| ^
diff --git a/src/tools/clippy/tests/ui/manual_filter.stderr b/src/tools/clippy/tests/ui/manual_filter.stderr
index 53dea9229..f62d3e960 100644
--- a/src/tools/clippy/tests/ui/manual_filter.stderr
+++ b/src/tools/clippy/tests/ui/manual_filter.stderr
@@ -8,7 +8,7 @@ LL | | if x > 0 {
... |
LL | | },
LL | | };
- | |_____^ help: try this: `Some(0).filter(|&x| x <= 0)`
+ | |_____^ help: try: `Some(0).filter(|&x| x <= 0)`
|
= note: `-D clippy::manual-filter` implied by `-D warnings`
@@ -22,7 +22,7 @@ LL | | None
... |
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some(1).filter(|&x| x <= 0)`
+ | |_____^ help: try: `Some(1).filter(|&x| x <= 0)`
error: manual implementation of `Option::filter`
--> $DIR/manual_filter.rs:29:5
@@ -34,7 +34,7 @@ LL | | None
... |
LL | | _ => None,
LL | | };
- | |_____^ help: try this: `Some(2).filter(|&x| x <= 0)`
+ | |_____^ help: try: `Some(2).filter(|&x| x <= 0)`
error: manual implementation of `Option::filter`
--> $DIR/manual_filter.rs:40:5
@@ -46,7 +46,7 @@ LL | | Some(x)
... |
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some(3).filter(|&x| x > 0)`
+ | |_____^ help: try: `Some(3).filter(|&x| x > 0)`
error: manual implementation of `Option::filter`
--> $DIR/manual_filter.rs:52:5
@@ -58,7 +58,7 @@ LL | | Some(x) => {
... |
LL | | },
LL | | };
- | |_____^ help: try this: `y.filter(|&x| x <= 0)`
+ | |_____^ help: try: `y.filter(|&x| x <= 0)`
error: manual implementation of `Option::filter`
--> $DIR/manual_filter.rs:64:5
@@ -70,7 +70,7 @@ LL | | Some(x)
... |
LL | | _ => None,
LL | | };
- | |_____^ help: try this: `Some(5).filter(|&x| x > 0)`
+ | |_____^ help: try: `Some(5).filter(|&x| x > 0)`
error: manual implementation of `Option::filter`
--> $DIR/manual_filter.rs:75:5
@@ -82,7 +82,7 @@ LL | | Some(x)
... |
LL | | _ => None,
LL | | };
- | |_____^ help: try this: `Some(6).as_ref().filter(|&x| x > &0)`
+ | |_____^ help: try: `Some(6).as_ref().filter(|&x| x > &0)`
error: manual implementation of `Option::filter`
--> $DIR/manual_filter.rs:87:5
@@ -94,7 +94,7 @@ LL | | Some(x)
... |
LL | | _ => None,
LL | | };
- | |_____^ help: try this: `Some(String::new()).filter(|x| external_cond)`
+ | |_____^ help: try: `Some(String::new()).filter(|x| external_cond)`
error: manual implementation of `Option::filter`
--> $DIR/manual_filter.rs:98:5
@@ -104,7 +104,7 @@ LL | | if external_cond { Some(x) } else { None }
LL | | } else {
LL | | None
LL | | };
- | |_____^ help: try this: `Some(7).filter(|&x| external_cond)`
+ | |_____^ help: try: `Some(7).filter(|&x| external_cond)`
error: manual implementation of `Option::filter`
--> $DIR/manual_filter.rs:104:5
@@ -116,7 +116,7 @@ LL | | Some(x)
... |
LL | | _ => None,
LL | | };
- | |_____^ help: try this: `Some(8).filter(|&x| x != 0)`
+ | |_____^ help: try: `Some(8).filter(|&x| x != 0)`
error: manual implementation of `Option::filter`
--> $DIR/manual_filter.rs:115:5
@@ -128,7 +128,7 @@ LL | | Some(x)
... |
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some(9).filter(|&x| x > 10 && x < 100)`
+ | |_____^ help: try: `Some(9).filter(|&x| x > 10 && x < 100)`
error: manual implementation of `Option::filter`
--> $DIR/manual_filter.rs:141:5
@@ -142,7 +142,7 @@ LL | | None => None,
LL | | };
| |_____^
|
-help: try this
+help: try
|
LL ~ Some(11).filter(|&x| {
LL + println!("foo");
@@ -161,7 +161,7 @@ LL | | Some(x)
... |
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some(14).filter(|&x| unsafe { f(x) })`
+ | |_____^ help: try: `Some(14).filter(|&x| unsafe { f(x) })`
error: manual implementation of `Option::filter`
--> $DIR/manual_filter.rs:195:13
@@ -173,7 +173,7 @@ LL | | if f(x) { Some(x) } else { None }
LL | | },
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some(15).filter(|&x| unsafe { f(x) })`
+ | |_____^ help: try: `Some(15).filter(|&x| unsafe { f(x) })`
error: manual implementation of `Option::filter`
--> $DIR/manual_filter.rs:205:12
@@ -185,7 +185,7 @@ LL | | if x % 2 == 0 { Some(x) } else { None }
LL | | } else {
LL | | None
LL | | };
- | |_____^ help: try this: `{ Some(16).filter(|&x| x % 2 == 0) }`
+ | |_____^ help: try: `{ Some(16).filter(|&x| x % 2 == 0) }`
error: aborting due to 15 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_filter_map.fixed b/src/tools/clippy/tests/ui/manual_filter_map.fixed
index 9dd376df2..35872a39a 100644
--- a/src/tools/clippy/tests/ui/manual_filter_map.fixed
+++ b/src/tools/clippy/tests/ui/manual_filter_map.fixed
@@ -120,3 +120,27 @@ fn issue_8920() {
.iter()
.filter_map(|f| f.result_field.to_owned().ok());
}
+
+fn issue8010() {
+ #[derive(Clone)]
+ enum Enum {
+ A(i32),
+ B,
+ }
+
+ let iter = [Enum::A(123), Enum::B].into_iter();
+
+ let _x = iter.clone().filter_map(|x| match x { Enum::A(s) => Some(s), _ => None });
+ let _x = iter.clone().filter(|x| matches!(x, Enum::B)).map(|x| match x {
+ Enum::A(s) => s,
+ _ => unreachable!(),
+ });
+ let _x = iter
+ .clone()
+ .filter_map(|x| match x { Enum::A(s) => Some(s), _ => None });
+ #[allow(clippy::unused_unit)]
+ let _x = iter
+ .clone()
+ .filter(|x| matches!(x, Enum::B))
+ .map(|x| if let Enum::B = x { () } else { unreachable!() });
+}
diff --git a/src/tools/clippy/tests/ui/manual_filter_map.rs b/src/tools/clippy/tests/ui/manual_filter_map.rs
index 6dd1e066a..50d8d2722 100644
--- a/src/tools/clippy/tests/ui/manual_filter_map.rs
+++ b/src/tools/clippy/tests/ui/manual_filter_map.rs
@@ -133,3 +133,31 @@ fn issue_8920() {
.filter(|f| f.result_field.is_ok())
.map(|f| f.result_field.to_owned().unwrap());
}
+
+fn issue8010() {
+ #[derive(Clone)]
+ enum Enum {
+ A(i32),
+ B,
+ }
+
+ let iter = [Enum::A(123), Enum::B].into_iter();
+
+ let _x = iter.clone().filter(|x| matches!(x, Enum::A(_))).map(|x| match x {
+ Enum::A(s) => s,
+ _ => unreachable!(),
+ });
+ let _x = iter.clone().filter(|x| matches!(x, Enum::B)).map(|x| match x {
+ Enum::A(s) => s,
+ _ => unreachable!(),
+ });
+ let _x = iter
+ .clone()
+ .filter(|x| matches!(x, Enum::A(_)))
+ .map(|x| if let Enum::A(s) = x { s } else { unreachable!() });
+ #[allow(clippy::unused_unit)]
+ let _x = iter
+ .clone()
+ .filter(|x| matches!(x, Enum::B))
+ .map(|x| if let Enum::B = x { () } else { unreachable!() });
+}
diff --git a/src/tools/clippy/tests/ui/manual_filter_map.stderr b/src/tools/clippy/tests/ui/manual_filter_map.stderr
index 882468b0f..0e8672c02 100644
--- a/src/tools/clippy/tests/ui/manual_filter_map.stderr
+++ b/src/tools/clippy/tests/ui/manual_filter_map.stderr
@@ -4,6 +4,11 @@ error: `filter(..).map(..)` can be simplified as `filter_map(..)`
LL | let _ = (0..).filter(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `filter_map(|a| to_opt(a))`
|
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_filter_map.rs:9:30
+ |
+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(..)`
@@ -11,12 +16,24 @@ error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
LL | let _ = (0..).filter(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `filter_map(|a| to_opt(a))`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_filter_map.rs:12:31
+ |
+LL | let _ = (0..).filter(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi"));
+ | ^^^^^^^^^
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
--> $DIR/manual_filter_map.rs:15:19
|
LL | let _ = (0..).filter(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `filter_map(|a| to_res(a).ok())`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_filter_map.rs:15:31
+ |
+LL | let _ = (0..).filter(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1));
+ | ^^^^^^^^^
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
--> $DIR/manual_filter_map.rs:18:10
@@ -25,6 +42,12 @@ LL | .filter(|&x| to_ref(to_opt(x)).is_some())
| __________^
LL | | .map(|y| to_ref(to_opt(y)).unwrap());
| |____________________________________________^ help: try: `filter_map(|y| *to_ref(to_opt(y)))`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_filter_map.rs:18:22
+ |
+LL | .filter(|&x| to_ref(to_opt(x)).is_some())
+ | ^^^^^^^^^^^^^^^^^
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
--> $DIR/manual_filter_map.rs:21:10
@@ -33,6 +56,12 @@ LL | .filter(|x| to_ref(to_opt(*x)).is_some())
| __________^
LL | | .map(|y| to_ref(to_opt(y)).unwrap());
| |____________________________________________^ help: try: `filter_map(|y| *to_ref(to_opt(y)))`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_filter_map.rs:21:21
+ |
+LL | .filter(|x| to_ref(to_opt(*x)).is_some())
+ | ^^^^^^^^^^^^^^^^^^
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
--> $DIR/manual_filter_map.rs:25:10
@@ -41,6 +70,12 @@ LL | .filter(|&x| to_ref(to_res(x)).is_ok())
| __________^
LL | | .map(|y| to_ref(to_res(y)).unwrap());
| |____________________________________________^ help: try: `filter_map(|y| to_ref(to_res(y)).ok())`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_filter_map.rs:25:22
+ |
+LL | .filter(|&x| to_ref(to_res(x)).is_ok())
+ | ^^^^^^^^^^^^^^^^^
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
--> $DIR/manual_filter_map.rs:28:10
@@ -49,6 +84,12 @@ LL | .filter(|x| to_ref(to_res(*x)).is_ok())
| __________^
LL | | .map(|y| to_ref(to_res(y)).unwrap());
| |____________________________________________^ help: try: `filter_map(|y| to_ref(to_res(y)).ok())`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_filter_map.rs:28:21
+ |
+LL | .filter(|x| to_ref(to_res(*x)).is_ok())
+ | ^^^^^^^^^^^^^^^^^^
error: `find(..).map(..)` can be simplified as `find_map(..)`
--> $DIR/manual_filter_map.rs:34:27
@@ -75,6 +116,12 @@ error: `find(..).map(..)` can be simplified as `find_map(..)`
|
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())`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_filter_map.rs:37:41
+ |
+LL | iter::<Option<&String>>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap());
+ | ^^^^^^^^^
error: `find(..).map(..)` can be simplified as `find_map(..)`
--> $DIR/manual_filter_map.rs:39:30
@@ -117,6 +164,12 @@ error: `find(..).map(..)` can be simplified as `find_map(..)`
|
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())`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_filter_map.rs:45:45
+ |
+LL | iter::<Result<&String, ()>>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap());
+ | ^^^^^^^^^
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
--> $DIR/manual_filter_map.rs:93:10
@@ -190,5 +243,23 @@ LL | .filter(|f| f.result_field.is_ok())
LL | | .map(|f| f.result_field.to_owned().unwrap());
| |____________________________________________________^ help: try: `filter_map(|f| f.result_field.to_owned().ok())`
-error: aborting due to 27 previous errors
+error: `filter(..).map(..)` can be simplified as `filter_map(..)`
+ --> $DIR/manual_filter_map.rs:146:27
+ |
+LL | let _x = iter.clone().filter(|x| matches!(x, Enum::A(_))).map(|x| match x {
+ | ___________________________^
+LL | | Enum::A(s) => s,
+LL | | _ => unreachable!(),
+LL | | });
+ | |______^ help: try: `filter_map(|x| match x { Enum::A(s) => Some(s), _ => None })`
+
+error: `filter(..).map(..)` can be simplified as `filter_map(..)`
+ --> $DIR/manual_filter_map.rs:156:10
+ |
+LL | .filter(|x| matches!(x, Enum::A(_)))
+ | __________^
+LL | | .map(|x| if let Enum::A(s) = x { s } else { unreachable!() });
+ | |_____________________________________________________________________^ help: try: `filter_map(|x| match x { Enum::A(s) => Some(s), _ => None })`
+
+error: aborting due to 29 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_find_map.stderr b/src/tools/clippy/tests/ui/manual_find_map.stderr
index 693a06bb5..4e52b5efa 100644
--- a/src/tools/clippy/tests/ui/manual_find_map.stderr
+++ b/src/tools/clippy/tests/ui/manual_find_map.stderr
@@ -4,6 +4,11 @@ error: `find(..).map(..)` can be simplified as `find_map(..)`
LL | let _ = (0..).find(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|a| to_opt(a))`
|
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_find_map.rs:9:28
+ |
+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(..)`
@@ -11,12 +16,24 @@ error: `find(..).map(..)` can be simplified as `find_map(..)`
|
LL | let _ = (0..).find(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|a| to_opt(a))`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_find_map.rs:12:29
+ |
+LL | let _ = (0..).find(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi"));
+ | ^^^^^^^^^
error: `find(..).map(..)` can be simplified as `find_map(..)`
--> $DIR/manual_find_map.rs:15:19
|
LL | let _ = (0..).find(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|a| to_res(a).ok())`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_find_map.rs:15:29
+ |
+LL | let _ = (0..).find(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1));
+ | ^^^^^^^^^
error: `find(..).map(..)` can be simplified as `find_map(..)`
--> $DIR/manual_find_map.rs:18:10
@@ -25,6 +42,12 @@ LL | .find(|&x| to_ref(to_opt(x)).is_some())
| __________^
LL | | .map(|y| to_ref(to_opt(y)).unwrap());
| |____________________________________________^ help: try: `find_map(|y| *to_ref(to_opt(y)))`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_find_map.rs:18:20
+ |
+LL | .find(|&x| to_ref(to_opt(x)).is_some())
+ | ^^^^^^^^^^^^^^^^^
error: `find(..).map(..)` can be simplified as `find_map(..)`
--> $DIR/manual_find_map.rs:21:10
@@ -33,6 +56,12 @@ LL | .find(|x| to_ref(to_opt(*x)).is_some())
| __________^
LL | | .map(|y| to_ref(to_opt(y)).unwrap());
| |____________________________________________^ help: try: `find_map(|y| *to_ref(to_opt(y)))`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_find_map.rs:21:19
+ |
+LL | .find(|x| to_ref(to_opt(*x)).is_some())
+ | ^^^^^^^^^^^^^^^^^^
error: `find(..).map(..)` can be simplified as `find_map(..)`
--> $DIR/manual_find_map.rs:25:10
@@ -41,6 +70,12 @@ LL | .find(|&x| to_ref(to_res(x)).is_ok())
| __________^
LL | | .map(|y| to_ref(to_res(y)).unwrap());
| |____________________________________________^ help: try: `find_map(|y| to_ref(to_res(y)).ok())`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_find_map.rs:25:20
+ |
+LL | .find(|&x| to_ref(to_res(x)).is_ok())
+ | ^^^^^^^^^^^^^^^^^
error: `find(..).map(..)` can be simplified as `find_map(..)`
--> $DIR/manual_find_map.rs:28:10
@@ -49,6 +84,12 @@ LL | .find(|x| to_ref(to_res(*x)).is_ok())
| __________^
LL | | .map(|y| to_ref(to_res(y)).unwrap());
| |____________________________________________^ help: try: `find_map(|y| to_ref(to_res(y)).ok())`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_find_map.rs:28:19
+ |
+LL | .find(|x| to_ref(to_res(*x)).is_ok())
+ | ^^^^^^^^^^^^^^^^^^
error: `find(..).map(..)` can be simplified as `find_map(..)`
--> $DIR/manual_find_map.rs:34:26
@@ -91,6 +132,12 @@ error: `find(..).map(..)` can be simplified as `find_map(..)`
|
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())`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_find_map.rs:40:41
+ |
+LL | iter::<Option<&String>>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap());
+ | ^^^^^^^^^
error: `find(..).map(..)` can be simplified as `find_map(..)`
--> $DIR/manual_find_map.rs:42:30
@@ -133,6 +180,12 @@ error: `find(..).map(..)` can be simplified as `find_map(..)`
|
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())`
+ |
+note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
+ --> $DIR/manual_find_map.rs:48:45
+ |
+LL | iter::<Result<&String, ()>>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap());
+ | ^^^^^^^^^
error: `find(..).map(..)` can be simplified as `find_map(..)`
--> $DIR/manual_find_map.rs:96:10
diff --git a/src/tools/clippy/tests/ui/manual_float_methods.rs b/src/tools/clippy/tests/ui/manual_float_methods.rs
new file mode 100644
index 000000000..af9076cfb
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_float_methods.rs
@@ -0,0 +1,55 @@
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(clippy::needless_if, unused)]
+#![warn(clippy::manual_is_infinite, clippy::manual_is_finite)]
+#![feature(inline_const)]
+
+#[macro_use]
+extern crate proc_macros;
+
+const INFINITE: f32 = f32::INFINITY;
+const NEG_INFINITE: f32 = f32::NEG_INFINITY;
+
+fn fn_test() -> f64 {
+ f64::NEG_INFINITY
+}
+
+fn fn_test_not_inf() -> f64 {
+ 112.0
+}
+
+fn main() {
+ let x = 1.0f32;
+ if x == f32::INFINITY || x == f32::NEG_INFINITY {}
+ if x != f32::INFINITY && x != f32::NEG_INFINITY {}
+ if x == INFINITE || x == NEG_INFINITE {}
+ if x != INFINITE && x != NEG_INFINITE {}
+ let x = 1.0f64;
+ if x == f64::INFINITY || x == f64::NEG_INFINITY {}
+ if x != f64::INFINITY && x != f64::NEG_INFINITY {}
+ // Don't lint
+ if x.is_infinite() {}
+ if x.is_finite() {}
+ if x.abs() < f64::INFINITY {}
+ if f64::INFINITY > x.abs() {}
+ if f64::abs(x) < f64::INFINITY {}
+ if f64::INFINITY > f64::abs(x) {}
+ // Is not evaluated by `clippy_utils::constant`
+ if x != f64::INFINITY && x != fn_test() {}
+ // Not -inf
+ if x != f64::INFINITY && x != fn_test_not_inf() {}
+ const X: f64 = 1.0f64;
+ // Will be linted if `const_float_classify` is enabled
+ if const { X == f64::INFINITY || X == f64::NEG_INFINITY } {}
+ if const { X != f64::INFINITY && X != f64::NEG_INFINITY } {}
+ external! {
+ let x = 1.0;
+ if x == f32::INFINITY || x == f32::NEG_INFINITY {}
+ if x != f32::INFINITY && x != f32::NEG_INFINITY {}
+ }
+ with_span! {
+ span
+ let x = 1.0;
+ if x == f32::INFINITY || x == f32::NEG_INFINITY {}
+ if x != f32::INFINITY && x != f32::NEG_INFINITY {}
+ }
+}
diff --git a/src/tools/clippy/tests/ui/manual_float_methods.stderr b/src/tools/clippy/tests/ui/manual_float_methods.stderr
new file mode 100644
index 000000000..a56118b31
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_float_methods.stderr
@@ -0,0 +1,80 @@
+error: manually checking if a float is infinite
+ --> $DIR/manual_float_methods.rs:22:8
+ |
+LL | if x == f32::INFINITY || x == f32::NEG_INFINITY {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()`
+ |
+ = note: `-D clippy::manual-is-infinite` implied by `-D warnings`
+
+error: manually checking if a float is finite
+ --> $DIR/manual_float_methods.rs:23:8
+ |
+LL | if x != f32::INFINITY && x != f32::NEG_INFINITY {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::manual-is-finite` implied by `-D warnings`
+help: use the dedicated method instead
+ |
+LL | if x.is_finite() {}
+ | ~~~~~~~~~~~~~
+help: this will alter how it handles NaN; if that is a problem, use instead
+ |
+LL | if x.is_finite() || x.is_nan() {}
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+help: or, for conciseness
+ |
+LL | if !x.is_infinite() {}
+ | ~~~~~~~~~~~~~~~~
+
+error: manually checking if a float is infinite
+ --> $DIR/manual_float_methods.rs:24:8
+ |
+LL | if x == INFINITE || x == NEG_INFINITE {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()`
+
+error: manually checking if a float is finite
+ --> $DIR/manual_float_methods.rs:25:8
+ |
+LL | if x != INFINITE && x != NEG_INFINITE {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: use the dedicated method instead
+ |
+LL | if x.is_finite() {}
+ | ~~~~~~~~~~~~~
+help: this will alter how it handles NaN; if that is a problem, use instead
+ |
+LL | if x.is_finite() || x.is_nan() {}
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+help: or, for conciseness
+ |
+LL | if !x.is_infinite() {}
+ | ~~~~~~~~~~~~~~~~
+
+error: manually checking if a float is infinite
+ --> $DIR/manual_float_methods.rs:27:8
+ |
+LL | if x == f64::INFINITY || x == f64::NEG_INFINITY {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()`
+
+error: manually checking if a float is finite
+ --> $DIR/manual_float_methods.rs:28:8
+ |
+LL | if x != f64::INFINITY && x != f64::NEG_INFINITY {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: use the dedicated method instead
+ |
+LL | if x.is_finite() {}
+ | ~~~~~~~~~~~~~
+help: this will alter how it handles NaN; if that is a problem, use instead
+ |
+LL | if x.is_finite() || x.is_nan() {}
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+help: or, for conciseness
+ |
+LL | if !x.is_infinite() {}
+ | ~~~~~~~~~~~~~~~~
+
+error: aborting due to 6 previous errors
+
diff --git a/src/tools/clippy/tests/ui/manual_let_else.rs b/src/tools/clippy/tests/ui/manual_let_else.rs
index 46241afec..381b83409 100644
--- a/src/tools/clippy/tests/ui/manual_let_else.rs
+++ b/src/tools/clippy/tests/ui/manual_let_else.rs
@@ -279,7 +279,9 @@ fn not_fire() {
create_binding_if_some_nf!(v, g());
// Already a let-else
- let Some(a) = (if let Some(b) = Some(Some(())) { b } else { return }) else { panic!() };
+ let Some(a) = (if let Some(b) = Some(Some(())) { b } else { return }) else {
+ panic!()
+ };
// If a type annotation is present, don't lint as
// expressing the type might be too hard
@@ -304,9 +306,7 @@ fn not_fire() {
let _x = if let Some(x) = Some(1) {
x
} else {
- let Some(_z) = Some(3) else {
- return
- };
+ let Some(_z) = Some(3) else { return };
1
};
diff --git a/src/tools/clippy/tests/ui/manual_let_else.stderr b/src/tools/clippy/tests/ui/manual_let_else.stderr
index 1eada4f99..912302b17 100644
--- a/src/tools/clippy/tests/ui/manual_let_else.stderr
+++ b/src/tools/clippy/tests/ui/manual_let_else.stderr
@@ -352,7 +352,7 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:297:5
+ --> $DIR/manual_let_else.rs:299:5
|
LL | / let _ = match ff {
LL | | Some(value) => value,
diff --git a/src/tools/clippy/tests/ui/manual_let_else_question_mark.fixed b/src/tools/clippy/tests/ui/manual_let_else_question_mark.fixed
new file mode 100644
index 000000000..02308bc7c
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_let_else_question_mark.fixed
@@ -0,0 +1,63 @@
+//@run-rustfix
+#![allow(unused_braces, unused_variables, dead_code)]
+#![allow(
+ clippy::collapsible_else_if,
+ clippy::unused_unit,
+ clippy::let_unit_value,
+ clippy::match_single_binding,
+ clippy::never_loop
+)]
+#![warn(clippy::manual_let_else, clippy::question_mark)]
+
+enum Variant {
+ A(usize, usize),
+ B(usize),
+ C,
+}
+
+fn g() -> Option<(u8, u8)> {
+ None
+}
+
+fn e() -> Variant {
+ Variant::A(0, 0)
+}
+
+fn main() {}
+
+fn foo() -> Option<()> {
+ // Fire here, normal case
+ let v = g()?;
+
+ // Don't fire here, the pattern is refutable
+ let Variant::A(v, w) = e() else { return None };
+
+ // Fire here, the pattern is irrefutable
+ let (v, w) = g()?;
+
+ // Don't fire manual_let_else in this instance: question mark can be used instead.
+ let v = g()?;
+
+ // Do fire manual_let_else in this instance: question mark cannot be used here due to the return
+ // body.
+ let Some(v) = g() else {
+ return Some(());
+ };
+
+ // Here we could also fire the question_mark lint, but we don't (as it's a match and not an if let).
+ // So we still emit manual_let_else here. For the *resulting* code, we *do* emit the question_mark
+ // lint, so for rustfix reasons, we allow the question_mark lint here.
+ #[allow(clippy::question_mark)]
+ {
+ let Some(v) = g() else { return None };
+ }
+
+ // This is a copy of the case above where we'd fire the question_mark lint, but here we have allowed
+ // it. Make sure that manual_let_else is fired as the fallback.
+ #[allow(clippy::question_mark)]
+ {
+ let Some(v) = g() else { return None };
+ }
+
+ Some(())
+}
diff --git a/src/tools/clippy/tests/ui/manual_let_else_question_mark.rs b/src/tools/clippy/tests/ui/manual_let_else_question_mark.rs
new file mode 100644
index 000000000..9c7ad386d
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_let_else_question_mark.rs
@@ -0,0 +1,68 @@
+//@run-rustfix
+#![allow(unused_braces, unused_variables, dead_code)]
+#![allow(
+ clippy::collapsible_else_if,
+ clippy::unused_unit,
+ clippy::let_unit_value,
+ clippy::match_single_binding,
+ clippy::never_loop
+)]
+#![warn(clippy::manual_let_else, clippy::question_mark)]
+
+enum Variant {
+ A(usize, usize),
+ B(usize),
+ C,
+}
+
+fn g() -> Option<(u8, u8)> {
+ None
+}
+
+fn e() -> Variant {
+ Variant::A(0, 0)
+}
+
+fn main() {}
+
+fn foo() -> Option<()> {
+ // Fire here, normal case
+ let Some(v) = g() else { return None };
+
+ // Don't fire here, the pattern is refutable
+ let Variant::A(v, w) = e() else { return None };
+
+ // Fire here, the pattern is irrefutable
+ let Some((v, w)) = g() else { return None };
+
+ // Don't fire manual_let_else in this instance: question mark can be used instead.
+ let v = if let Some(v_some) = g() { v_some } else { return None };
+
+ // Do fire manual_let_else in this instance: question mark cannot be used here due to the return
+ // body.
+ let v = if let Some(v_some) = g() {
+ v_some
+ } else {
+ return Some(());
+ };
+
+ // Here we could also fire the question_mark lint, but we don't (as it's a match and not an if let).
+ // So we still emit manual_let_else here. For the *resulting* code, we *do* emit the question_mark
+ // lint, so for rustfix reasons, we allow the question_mark lint here.
+ #[allow(clippy::question_mark)]
+ {
+ let v = match g() {
+ Some(v_some) => v_some,
+ _ => return None,
+ };
+ }
+
+ // This is a copy of the case above where we'd fire the question_mark lint, but here we have allowed
+ // it. Make sure that manual_let_else is fired as the fallback.
+ #[allow(clippy::question_mark)]
+ {
+ let v = if let Some(v_some) = g() { v_some } else { return None };
+ }
+
+ Some(())
+}
diff --git a/src/tools/clippy/tests/ui/manual_let_else_question_mark.stderr b/src/tools/clippy/tests/ui/manual_let_else_question_mark.stderr
new file mode 100644
index 000000000..d7d2e127e
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_let_else_question_mark.stderr
@@ -0,0 +1,55 @@
+error: this `let...else` may be rewritten with the `?` operator
+ --> $DIR/manual_let_else_question_mark.rs:30:5
+ |
+LL | let Some(v) = g() else { return None };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `let v = g()?;`
+ |
+ = note: `-D clippy::question-mark` implied by `-D warnings`
+
+error: this `let...else` may be rewritten with the `?` operator
+ --> $DIR/manual_let_else_question_mark.rs:36:5
+ |
+LL | let Some((v, w)) = g() else { return None };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `let (v, w) = g()?;`
+
+error: this block may be rewritten with the `?` operator
+ --> $DIR/manual_let_else_question_mark.rs:39:13
+ |
+LL | let v = if let Some(v_some) = g() { v_some } else { return None };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `g()?`
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else_question_mark.rs:43:5
+ |
+LL | / let v = if let Some(v_some) = g() {
+LL | | v_some
+LL | | } else {
+LL | | return Some(());
+LL | | };
+ | |______^
+ |
+ = note: `-D clippy::manual-let-else` implied by `-D warnings`
+help: consider writing
+ |
+LL ~ let Some(v) = g() else {
+LL + return Some(());
+LL + };
+ |
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else_question_mark.rs:54:9
+ |
+LL | / let v = match g() {
+LL | | Some(v_some) => v_some,
+LL | | _ => return None,
+LL | | };
+ | |__________^ help: consider writing: `let Some(v) = g() else { return None };`
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else_question_mark.rs:64:9
+ |
+LL | let v = if let Some(v_some) = g() { v_some } else { return None };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { return None };`
+
+error: aborting due to 6 previous errors
+
diff --git a/src/tools/clippy/tests/ui/manual_map_option.stderr b/src/tools/clippy/tests/ui/manual_map_option.stderr
index cdc2c0e62..3f9caad4e 100644
--- a/src/tools/clippy/tests/ui/manual_map_option.stderr
+++ b/src/tools/clippy/tests/ui/manual_map_option.stderr
@@ -5,7 +5,7 @@ LL | / match Some(0) {
LL | | Some(_) => Some(2),
LL | | None::<u32> => None,
LL | | };
- | |_____^ help: try this: `Some(0).map(|_| 2)`
+ | |_____^ help: try: `Some(0).map(|_| 2)`
|
= note: `-D clippy::manual-map` implied by `-D warnings`
@@ -16,7 +16,7 @@ LL | / match Some(0) {
LL | | Some(x) => Some(x + 1),
LL | | _ => None,
LL | | };
- | |_____^ help: try this: `Some(0).map(|x| x + 1)`
+ | |_____^ help: try: `Some(0).map(|x| x + 1)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:25:5
@@ -25,7 +25,7 @@ LL | / match Some("") {
LL | | Some(x) => Some(x.is_empty()),
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some("").map(|x| x.is_empty())`
+ | |_____^ help: try: `Some("").map(|x| x.is_empty())`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:30:5
@@ -35,7 +35,7 @@ LL | | Some(!x)
LL | | } else {
LL | | None
LL | | };
- | |_____^ help: try this: `Some(0).map(|x| !x)`
+ | |_____^ help: try: `Some(0).map(|x| !x)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:37:5
@@ -44,7 +44,7 @@ LL | / match Some(0) {
LL | | Some(x) => { Some(std::convert::identity(x)) }
LL | | None => { None }
LL | | };
- | |_____^ help: try this: `Some(0).map(std::convert::identity)`
+ | |_____^ help: try: `Some(0).map(std::convert::identity)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:42:5
@@ -53,7 +53,7 @@ LL | / match Some(&String::new()) {
LL | | Some(x) => Some(str::len(x)),
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some(&String::new()).map(|x| str::len(x))`
+ | |_____^ help: try: `Some(&String::new()).map(|x| str::len(x))`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:52:5
@@ -62,7 +62,7 @@ LL | / match &Some([0, 1]) {
LL | | Some(x) => Some(x[0]),
LL | | &None => None,
LL | | };
- | |_____^ help: try this: `Some([0, 1]).as_ref().map(|x| x[0])`
+ | |_____^ help: try: `Some([0, 1]).as_ref().map(|x| x[0])`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:57:5
@@ -71,7 +71,7 @@ LL | / match &Some(0) {
LL | | &Some(x) => Some(x * 2),
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some(0).map(|x| x * 2)`
+ | |_____^ help: try: `Some(0).map(|x| x * 2)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:62:5
@@ -80,7 +80,7 @@ LL | / match Some(String::new()) {
LL | | Some(ref x) => Some(x.is_empty()),
LL | | _ => None,
LL | | };
- | |_____^ help: try this: `Some(String::new()).as_ref().map(|x| x.is_empty())`
+ | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.is_empty())`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:67:5
@@ -89,7 +89,7 @@ LL | / match &&Some(String::new()) {
LL | | Some(x) => Some(x.len()),
LL | | _ => None,
LL | | };
- | |_____^ help: try this: `Some(String::new()).as_ref().map(|x| x.len())`
+ | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.len())`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:72:5
@@ -98,7 +98,7 @@ LL | / match &&Some(0) {
LL | | &&Some(x) => Some(x + x),
LL | | &&_ => None,
LL | | };
- | |_____^ help: try this: `Some(0).map(|x| x + x)`
+ | |_____^ help: try: `Some(0).map(|x| x + x)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:85:9
@@ -107,7 +107,7 @@ LL | / match &mut Some(String::new()) {
LL | | Some(x) => Some(x.push_str("")),
LL | | None => None,
LL | | };
- | |_________^ help: try this: `Some(String::new()).as_mut().map(|x| x.push_str(""))`
+ | |_________^ help: try: `Some(String::new()).as_mut().map(|x| x.push_str(""))`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:91:5
@@ -116,7 +116,7 @@ LL | / match &mut Some(String::new()) {
LL | | Some(ref x) => Some(x.len()),
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some(String::new()).as_ref().map(|x| x.len())`
+ | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.len())`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:96:5
@@ -125,7 +125,7 @@ LL | / match &mut &Some(String::new()) {
LL | | Some(x) => Some(x.is_empty()),
LL | | &mut _ => None,
LL | | };
- | |_____^ help: try this: `Some(String::new()).as_ref().map(|x| x.is_empty())`
+ | |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.is_empty())`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:101:5
@@ -134,7 +134,7 @@ LL | / match Some((0, 1, 2)) {
LL | | Some((x, y, z)) => Some(x + y + z),
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some((0, 1, 2)).map(|(x, y, z)| x + y + z)`
+ | |_____^ help: try: `Some((0, 1, 2)).map(|(x, y, z)| x + y + z)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:106:5
@@ -143,7 +143,7 @@ LL | / match Some([1, 2, 3]) {
LL | | Some([first, ..]) => Some(first),
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some([1, 2, 3]).map(|[first, ..]| first)`
+ | |_____^ help: try: `Some([1, 2, 3]).map(|[first, ..]| first)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:111:5
@@ -152,7 +152,7 @@ LL | / match &Some((String::new(), "test")) {
LL | | Some((x, y)) => Some((y, x)),
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some((String::new(), "test")).as_ref().map(|(x, y)| (y, x))`
+ | |_____^ help: try: `Some((String::new(), "test")).as_ref().map(|(x, y)| (y, x))`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:169:5
@@ -161,7 +161,7 @@ LL | / match Some(0) {
LL | | Some(x) => Some(vec![x]),
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some(0).map(|x| vec![x])`
+ | |_____^ help: try: `Some(0).map(|x| vec![x])`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:174:5
@@ -170,7 +170,7 @@ LL | / match option_env!("") {
LL | | Some(x) => Some(String::from(x)),
LL | | None => None,
LL | | };
- | |_____^ help: try this: `option_env!("").map(String::from)`
+ | |_____^ help: try: `option_env!("").map(String::from)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:194:12
@@ -181,7 +181,7 @@ LL | | Some(x + 1)
LL | | } else {
LL | | None
LL | | };
- | |_____^ help: try this: `{ Some(0).map(|x| x + 1) }`
+ | |_____^ help: try: `{ Some(0).map(|x| x + 1) }`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:202:12
@@ -192,7 +192,7 @@ LL | | Some(x + 1)
LL | | } else {
LL | | None
LL | | };
- | |_____^ help: try this: `{ Some(0).map(|x| x + 1) }`
+ | |_____^ help: try: `{ Some(0).map(|x| x + 1) }`
error: aborting due to 21 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_map_option_2.stderr b/src/tools/clippy/tests/ui/manual_map_option_2.stderr
index d35b6252f..8c78fcffc 100644
--- a/src/tools/clippy/tests/ui/manual_map_option_2.stderr
+++ b/src/tools/clippy/tests/ui/manual_map_option_2.stderr
@@ -12,7 +12,7 @@ LL | | };
| |_____^
|
= note: `-D clippy::manual-map` implied by `-D warnings`
-help: try this
+help: try
|
LL ~ let _ = Some(0).map(|x| {
LL + let y = (String::new(), String::new());
@@ -32,7 +32,7 @@ LL | | None => None,
LL | | };
| |_____^
|
-help: try this
+help: try
|
LL ~ let _ = s.as_ref().map(|x| {
LL + if let Some(ref s) = s { (x.clone(), s) } else { panic!() }
@@ -47,7 +47,7 @@ LL | let _ = match Some(0) {
LL | | Some(x) => Some(f(x)),
LL | | None => None,
LL | | };
- | |_________^ help: try this: `Some(0).map(|x| f(x))`
+ | |_________^ help: try: `Some(0).map(|x| f(x))`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option_2.rs:67:13
@@ -57,7 +57,7 @@ LL | let _ = match Some(0) {
LL | | Some(x) => unsafe { Some(f(x)) },
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some(0).map(|x| unsafe { f(x) })`
+ | |_____^ help: try: `Some(0).map(|x| unsafe { f(x) })`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option_2.rs:71:13
@@ -67,7 +67,7 @@ LL | let _ = match Some(0) {
LL | | Some(x) => Some(unsafe { f(x) }),
LL | | None => None,
LL | | };
- | |_____^ help: try this: `Some(0).map(|x| unsafe { f(x) })`
+ | |_____^ help: try: `Some(0).map(|x| unsafe { f(x) })`
error: aborting due to 5 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_range_patterns.fixed b/src/tools/clippy/tests/ui/manual_range_patterns.fixed
index 9eee8f371..6bfcf263a 100644
--- a/src/tools/clippy/tests/ui/manual_range_patterns.fixed
+++ b/src/tools/clippy/tests/ui/manual_range_patterns.fixed
@@ -25,6 +25,10 @@ fn main() {
1..=10 => true,
_ => false,
};
+ let _ = matches!(f, -5..=3);
+ let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1); // 2 is missing
+ let _ = matches!(f, -1000001..=1000001);
+ let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_002);
macro_rules! mac {
($e:expr) => {
diff --git a/src/tools/clippy/tests/ui/manual_range_patterns.rs b/src/tools/clippy/tests/ui/manual_range_patterns.rs
index 10743a7d0..4a429bb2a 100644
--- a/src/tools/clippy/tests/ui/manual_range_patterns.rs
+++ b/src/tools/clippy/tests/ui/manual_range_patterns.rs
@@ -25,6 +25,10 @@ fn main() {
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 => true,
_ => false,
};
+ let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1 | 2);
+ let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1); // 2 is missing
+ let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001);
+ let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_002);
macro_rules! mac {
($e:expr) => {
diff --git a/src/tools/clippy/tests/ui/manual_range_patterns.stderr b/src/tools/clippy/tests/ui/manual_range_patterns.stderr
index bc9e33501..b1b55d483 100644
--- a/src/tools/clippy/tests/ui/manual_range_patterns.stderr
+++ b/src/tools/clippy/tests/ui/manual_range_patterns.stderr
@@ -37,7 +37,19 @@ 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
+ --> $DIR/manual_range_patterns.rs:28:25
+ |
+LL | let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1 | 2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-5..=3`
+
+error: this OR pattern can be rewritten using a range
+ --> $DIR/manual_range_patterns.rs:30:25
+ |
+LL | let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1000001..=1000001`
+
+error: this OR pattern can be rewritten using a range
+ --> $DIR/manual_range_patterns.rs:35:26
|
LL | matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10`
@@ -47,5 +59,5 @@ LL | mac!(f);
|
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: aborting due to 7 previous errors
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_retain.fixed b/src/tools/clippy/tests/ui/manual_retain.fixed
index 09fb0d758..c95d40fec 100644
--- a/src/tools/clippy/tests/ui/manual_retain.fixed
+++ b/src/tools/clippy/tests/ui/manual_retain.fixed
@@ -1,12 +1,7 @@
//@run-rustfix
#![warn(clippy::manual_retain)]
#![allow(unused, clippy::redundant_clone)]
-use std::collections::BTreeMap;
-use std::collections::BTreeSet;
-use std::collections::BinaryHeap;
-use std::collections::HashMap;
-use std::collections::HashSet;
-use std::collections::VecDeque;
+use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
fn main() {
binary_heap_retain();
diff --git a/src/tools/clippy/tests/ui/manual_retain.rs b/src/tools/clippy/tests/ui/manual_retain.rs
index 7fee4c95c..9a3434f48 100644
--- a/src/tools/clippy/tests/ui/manual_retain.rs
+++ b/src/tools/clippy/tests/ui/manual_retain.rs
@@ -1,12 +1,7 @@
//@run-rustfix
#![warn(clippy::manual_retain)]
#![allow(unused, clippy::redundant_clone)]
-use std::collections::BTreeMap;
-use std::collections::BTreeSet;
-use std::collections::BinaryHeap;
-use std::collections::HashMap;
-use std::collections::HashSet;
-use std::collections::VecDeque;
+use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
fn main() {
binary_heap_retain();
diff --git a/src/tools/clippy/tests/ui/manual_retain.stderr b/src/tools/clippy/tests/ui/manual_retain.stderr
index 89316ce1d..0936a2384 100644
--- a/src/tools/clippy/tests/ui/manual_retain.stderr
+++ b/src/tools/clippy/tests/ui/manual_retain.stderr
@@ -1,5 +1,5 @@
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:51:5
+ --> $DIR/manual_retain.rs:46:5
|
LL | btree_map = btree_map.into_iter().filter(|(k, _)| k % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_map.retain(|k, _| k % 2 == 0)`
@@ -7,13 +7,13 @@ LL | btree_map = btree_map.into_iter().filter(|(k, _)| k % 2 == 0).collect()
= note: `-D clippy::manual-retain` implied by `-D warnings`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:52:5
+ --> $DIR/manual_retain.rs:47:5
|
LL | btree_map = btree_map.into_iter().filter(|(_, v)| v % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_map.retain(|_, &mut v| v % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:53:5
+ --> $DIR/manual_retain.rs:48:5
|
LL | / btree_map = btree_map
LL | | .into_iter()
@@ -22,37 +22,37 @@ LL | | .collect();
| |__________________^ help: consider calling `.retain()` instead: `btree_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0))`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:75:5
+ --> $DIR/manual_retain.rs:70:5
|
LL | btree_set = btree_set.iter().filter(|&x| x % 2 == 0).copied().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:76:5
+ --> $DIR/manual_retain.rs:71:5
|
LL | btree_set = btree_set.iter().filter(|&x| x % 2 == 0).cloned().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:77:5
+ --> $DIR/manual_retain.rs:72:5
|
LL | btree_set = btree_set.into_iter().filter(|x| x % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:107:5
+ --> $DIR/manual_retain.rs:102:5
|
LL | hash_map = hash_map.into_iter().filter(|(k, _)| k % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_map.retain(|k, _| k % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:108:5
+ --> $DIR/manual_retain.rs:103:5
|
LL | hash_map = hash_map.into_iter().filter(|(_, v)| v % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_map.retain(|_, &mut v| v % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:109:5
+ --> $DIR/manual_retain.rs:104:5
|
LL | / hash_map = hash_map
LL | | .into_iter()
@@ -61,61 +61,61 @@ LL | | .collect();
| |__________________^ help: consider calling `.retain()` instead: `hash_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0))`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:130:5
+ --> $DIR/manual_retain.rs:125:5
|
LL | hash_set = hash_set.into_iter().filter(|x| x % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:131:5
+ --> $DIR/manual_retain.rs:126:5
|
LL | hash_set = hash_set.iter().filter(|&x| x % 2 == 0).copied().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:132:5
+ --> $DIR/manual_retain.rs:127:5
|
LL | hash_set = hash_set.iter().filter(|&x| x % 2 == 0).cloned().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:161:5
+ --> $DIR/manual_retain.rs:156:5
|
LL | s = s.chars().filter(|&c| c != 'o').to_owned().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `s.retain(|c| c != 'o')`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:173:5
+ --> $DIR/manual_retain.rs:168:5
|
LL | vec = vec.iter().filter(|&x| x % 2 == 0).copied().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:174:5
+ --> $DIR/manual_retain.rs:169:5
|
LL | vec = vec.iter().filter(|&x| x % 2 == 0).cloned().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:175:5
+ --> $DIR/manual_retain.rs:170:5
|
LL | vec = vec.into_iter().filter(|x| x % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:197:5
+ --> $DIR/manual_retain.rs:192:5
|
LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).copied().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:198:5
+ --> $DIR/manual_retain.rs:193:5
|
LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).cloned().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:199:5
+ --> $DIR/manual_retain.rs:194:5
|
LL | vec_deque = vec_deque.into_iter().filter(|x| x % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)`
diff --git a/src/tools/clippy/tests/ui/manual_split_once.stderr b/src/tools/clippy/tests/ui/manual_split_once.stderr
index 78da5a16c..f454f95b4 100644
--- a/src/tools/clippy/tests/ui/manual_split_once.stderr
+++ b/src/tools/clippy/tests/ui/manual_split_once.stderr
@@ -2,7 +2,7 @@ error: manual implementation of `split_once`
--> $DIR/manual_split_once.rs:13:13
|
LL | let _ = "key=value".splitn(2, '=').nth(1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"key=value".split_once('=').unwrap().1`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=').unwrap().1`
|
= note: `-D clippy::manual-split-once` implied by `-D warnings`
@@ -10,73 +10,73 @@ error: manual implementation of `split_once`
--> $DIR/manual_split_once.rs:14:13
|
LL | let _ = "key=value".splitn(2, '=').skip(1).next().unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"key=value".split_once('=').unwrap().1`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=').unwrap().1`
error: manual implementation of `split_once`
--> $DIR/manual_split_once.rs:15:18
|
LL | let (_, _) = "key=value".splitn(2, '=').next_tuple().unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"key=value".split_once('=')`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=')`
error: manual implementation of `split_once`
--> $DIR/manual_split_once.rs:18:13
|
LL | let _ = s.splitn(2, '=').nth(1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.split_once('=').unwrap().1`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=').unwrap().1`
error: manual implementation of `split_once`
--> $DIR/manual_split_once.rs:21:13
|
LL | let _ = s.splitn(2, '=').nth(1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.split_once('=').unwrap().1`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=').unwrap().1`
error: manual implementation of `split_once`
--> $DIR/manual_split_once.rs:24:13
|
LL | let _ = s.splitn(2, '=').skip(1).next().unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.split_once('=').unwrap().1`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=').unwrap().1`
error: manual implementation of `split_once`
--> $DIR/manual_split_once.rs:27:17
|
LL | let _ = s.splitn(2, '=').nth(1)?;
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.split_once('=')?.1`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=')?.1`
error: manual implementation of `split_once`
--> $DIR/manual_split_once.rs:28:17
|
LL | let _ = s.splitn(2, '=').skip(1).next()?;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.split_once('=')?.1`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.split_once('=')?.1`
error: manual implementation of `rsplit_once`
--> $DIR/manual_split_once.rs:29:17
|
LL | let _ = s.rsplitn(2, '=').nth(1)?;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.rsplit_once('=')?.0`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.rsplit_once('=')?.0`
error: manual implementation of `rsplit_once`
--> $DIR/manual_split_once.rs:30:17
|
LL | let _ = s.rsplitn(2, '=').skip(1).next()?;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.rsplit_once('=')?.0`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.rsplit_once('=')?.0`
error: manual implementation of `rsplit_once`
--> $DIR/manual_split_once.rs:38:13
|
LL | let _ = "key=value".rsplitn(2, '=').nth(1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"key=value".rsplit_once('=').unwrap().0`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".rsplit_once('=').unwrap().0`
error: manual implementation of `rsplit_once`
--> $DIR/manual_split_once.rs:39:18
|
LL | let (_, _) = "key=value".rsplitn(2, '=').next_tuple().unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"key=value".rsplit_once('=').map(|(x, y)| (y, x))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".rsplit_once('=').map(|(x, y)| (y, x))`
error: manual implementation of `rsplit_once`
--> $DIR/manual_split_once.rs:40:13
|
LL | let _ = s.rsplitn(2, '=').nth(1);
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.rsplit_once('=').map(|x| x.0)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.rsplit_once('=').map(|x| x.0)`
error: manual implementation of `split_once`
--> $DIR/manual_split_once.rs:44:5
@@ -182,7 +182,7 @@ error: manual implementation of `split_once`
--> $DIR/manual_split_once.rs:141:13
|
LL | let _ = "key=value".splitn(2, '=').nth(1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"key=value".split_once('=').unwrap().1`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split_once('=').unwrap().1`
error: manual implementation of `split_once`
--> $DIR/manual_split_once.rs:143:5
diff --git a/src/tools/clippy/tests/ui/manual_str_repeat.stderr b/src/tools/clippy/tests/ui/manual_str_repeat.stderr
index bdfee7cab..331bb6ea5 100644
--- a/src/tools/clippy/tests/ui/manual_str_repeat.stderr
+++ b/src/tools/clippy/tests/ui/manual_str_repeat.stderr
@@ -2,7 +2,7 @@ error: manual implementation of `str::repeat` using iterators
--> $DIR/manual_str_repeat.rs:9:21
|
LL | let _: String = std::iter::repeat("test").take(10).collect();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"test".repeat(10)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"test".repeat(10)`
|
= note: `-D clippy::manual-str-repeat` implied by `-D warnings`
@@ -10,55 +10,55 @@ error: manual implementation of `str::repeat` using iterators
--> $DIR/manual_str_repeat.rs:10:21
|
LL | let _: String = std::iter::repeat('x').take(10).collect();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"x".repeat(10)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"x".repeat(10)`
error: manual implementation of `str::repeat` using iterators
--> $DIR/manual_str_repeat.rs:11:21
|
LL | let _: String = std::iter::repeat('/'').take(10).collect();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"'".repeat(10)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"'".repeat(10)`
error: manual implementation of `str::repeat` using iterators
--> $DIR/manual_str_repeat.rs:12:21
|
LL | let _: String = std::iter::repeat('"').take(10).collect();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"/"".repeat(10)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"/"".repeat(10)`
error: manual implementation of `str::repeat` using iterators
--> $DIR/manual_str_repeat.rs:16:13
|
LL | let _ = repeat(x).take(count + 2).collect::<String>();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `x.repeat(count + 2)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count + 2)`
error: manual implementation of `str::repeat` using iterators
--> $DIR/manual_str_repeat.rs:25:21
|
LL | let _: String = repeat(*x).take(count).collect();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `(*x).repeat(count)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*x).repeat(count)`
error: manual implementation of `str::repeat` using iterators
--> $DIR/manual_str_repeat.rs:34:21
|
LL | let _: String = repeat(x).take(count).collect();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `x.repeat(count)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count)`
error: manual implementation of `str::repeat` using iterators
--> $DIR/manual_str_repeat.rs:46:21
|
LL | let _: String = repeat(Cow::Borrowed("test")).take(count).collect();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `Cow::Borrowed("test").repeat(count)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Cow::Borrowed("test").repeat(count)`
error: manual implementation of `str::repeat` using iterators
--> $DIR/manual_str_repeat.rs:49:21
|
LL | let _: String = repeat(x).take(count).collect();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `x.repeat(count)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count)`
error: manual implementation of `str::repeat` using iterators
--> $DIR/manual_str_repeat.rs:64:21
|
LL | let _: String = std::iter::repeat("test").take(10).collect();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"test".repeat(10)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"test".repeat(10)`
error: aborting due to 10 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_try_fold.rs b/src/tools/clippy/tests/ui/manual_try_fold.rs
index 4521e9fa1..05c658579 100644
--- a/src/tools/clippy/tests/ui/manual_try_fold.rs
+++ b/src/tools/clippy/tests/ui/manual_try_fold.rs
@@ -3,9 +3,7 @@
#![warn(clippy::manual_try_fold)]
#![feature(try_trait_v2)]
-use std::ops::ControlFlow;
-use std::ops::FromResidual;
-use std::ops::Try;
+use std::ops::{ControlFlow, FromResidual, Try};
#[macro_use]
extern crate proc_macros;
diff --git a/src/tools/clippy/tests/ui/manual_try_fold.stderr b/src/tools/clippy/tests/ui/manual_try_fold.stderr
index a0cf5b3b5..f1bb97c6d 100644
--- a/src/tools/clippy/tests/ui/manual_try_fold.stderr
+++ b/src/tools/clippy/tests/ui/manual_try_fold.stderr
@@ -1,5 +1,5 @@
error: usage of `Iterator::fold` on a type that implements `Try`
- --> $DIR/manual_try_fold.rs:61:10
+ --> $DIR/manual_try_fold.rs:59:10
|
LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(0i32, |sum, i| ...)`
@@ -7,19 +7,19 @@ LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*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
+ --> $DIR/manual_try_fold.rs:63: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
+ --> $DIR/manual_try_fold.rs:66: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
+ --> $DIR/manual_try_fold.rs:96:10
|
LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(0i32, |sum, i| ...)`
diff --git a/src/tools/clippy/tests/ui/map_collect_result_unit.stderr b/src/tools/clippy/tests/ui/map_collect_result_unit.stderr
index 8b06e13ba..596e51e57 100644
--- a/src/tools/clippy/tests/ui/map_collect_result_unit.stderr
+++ b/src/tools/clippy/tests/ui/map_collect_result_unit.stderr
@@ -2,7 +2,7 @@ error: `.map().collect()` can be replaced with `.try_for_each()`
--> $DIR/map_collect_result_unit.rs:6:17
|
LL | let _ = (0..3).map(|t| Err(t + 1)).collect::<Result<(), _>>();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `(0..3).try_for_each(|t| Err(t + 1))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(0..3).try_for_each(|t| Err(t + 1))`
|
= note: `-D clippy::map-collect-result-unit` implied by `-D warnings`
@@ -10,7 +10,7 @@ error: `.map().collect()` can be replaced with `.try_for_each()`
--> $DIR/map_collect_result_unit.rs:7:32
|
LL | let _: Result<(), _> = (0..3).map(|t| Err(t + 1)).collect();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `(0..3).try_for_each(|t| Err(t + 1))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(0..3).try_for_each(|t| Err(t + 1))`
error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui/map_unwrap_or.stderr b/src/tools/clippy/tests/ui/map_unwrap_or.stderr
index 9f4a4a9ae..5b3c61acf 100644
--- a/src/tools/clippy/tests/ui/map_unwrap_or.stderr
+++ b/src/tools/clippy/tests/ui/map_unwrap_or.stderr
@@ -162,7 +162,7 @@ error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be do
--> $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)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or_else(|_e| 0, |x| x + 1)`
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
diff --git a/src/tools/clippy/tests/ui/map_unwrap_or_fixable.stderr b/src/tools/clippy/tests/ui/map_unwrap_or_fixable.stderr
index 1837bc2ca..71dc009f2 100644
--- a/src/tools/clippy/tests/ui/map_unwrap_or_fixable.stderr
+++ b/src/tools/clippy/tests/ui/map_unwrap_or_fixable.stderr
@@ -5,7 +5,7 @@ LL | let _ = opt.map(|x| x + 1)
| _____________^
LL | | // Should lint even though this call is on a separate line.
LL | | .unwrap_or_else(|| 0);
- | |_____________________________^ help: try this: `opt.map_or_else(|| 0, |x| x + 1)`
+ | |_____________________________^ help: try: `opt.map_or_else(|| 0, |x| x + 1)`
|
= note: `-D clippy::map-unwrap-or` implied by `-D warnings`
@@ -16,7 +16,7 @@ LL | let _ = res.map(|x| x + 1)
| _____________^
LL | | // should lint even though this call is on a separate line
LL | | .unwrap_or_else(|_e| 0);
- | |_______________________________^ help: try this: `res.map_or_else(|_e| 0, |x| x + 1)`
+ | |_______________________________^ help: try: `res.map_or_else(|_e| 0, |x| x + 1)`
error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui/match_as_ref.fixed b/src/tools/clippy/tests/ui/match_as_ref.fixed
index 8fa3f5325..61d414bdf 100644
--- a/src/tools/clippy/tests/ui/match_as_ref.fixed
+++ b/src/tools/clippy/tests/ui/match_as_ref.fixed
@@ -12,7 +12,9 @@ fn match_as_ref() {
}
mod issue4437 {
- use std::{error::Error, fmt, num::ParseIntError};
+ use std::error::Error;
+ use std::fmt;
+ use std::num::ParseIntError;
#[derive(Debug)]
struct E {
diff --git a/src/tools/clippy/tests/ui/match_as_ref.rs b/src/tools/clippy/tests/ui/match_as_ref.rs
index 02a177914..cd39514c5 100644
--- a/src/tools/clippy/tests/ui/match_as_ref.rs
+++ b/src/tools/clippy/tests/ui/match_as_ref.rs
@@ -18,7 +18,9 @@ fn match_as_ref() {
}
mod issue4437 {
- use std::{error::Error, fmt, num::ParseIntError};
+ use std::error::Error;
+ use std::fmt;
+ use std::num::ParseIntError;
#[derive(Debug)]
struct E {
diff --git a/src/tools/clippy/tests/ui/match_as_ref.stderr b/src/tools/clippy/tests/ui/match_as_ref.stderr
index c3b62849c..2e6955eb8 100644
--- a/src/tools/clippy/tests/ui/match_as_ref.stderr
+++ b/src/tools/clippy/tests/ui/match_as_ref.stderr
@@ -6,7 +6,7 @@ LL | let borrowed: Option<&()> = match owned {
LL | | None => None,
LL | | Some(ref v) => Some(v),
LL | | };
- | |_____^ help: try this: `owned.as_ref()`
+ | |_____^ help: try: `owned.as_ref()`
|
= note: `-D clippy::match-as-ref` implied by `-D warnings`
@@ -18,16 +18,16 @@ LL | let borrow_mut: Option<&mut ()> = match mut_owned {
LL | | None => None,
LL | | Some(ref mut v) => Some(v),
LL | | };
- | |_____^ help: try this: `mut_owned.as_mut()`
+ | |_____^ help: try: `mut_owned.as_mut()`
error: use `as_ref()` instead
- --> $DIR/match_as_ref.rs:30:13
+ --> $DIR/match_as_ref.rs:32:13
|
LL | / match self.source {
LL | | Some(ref s) => Some(s),
LL | | None => None,
LL | | }
- | |_____________^ help: try this: `self.source.as_ref().map(|x| x as _)`
+ | |_____________^ help: try: `self.source.as_ref().map(|x| x as _)`
error: aborting due to 3 previous errors
diff --git a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed
index 60f590661..f19149cf9 100644
--- a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed
+++ b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed
@@ -5,7 +5,8 @@
unreachable_patterns,
dead_code,
clippy::equatable_if_let,
- clippy::needless_borrowed_reference
+ clippy::needless_borrowed_reference,
+ clippy::redundant_guards
)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs
index afdf1069f..8f4e58981 100644
--- a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs
+++ b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs
@@ -5,7 +5,8 @@
unreachable_patterns,
dead_code,
clippy::equatable_if_let,
- clippy::needless_borrowed_reference
+ clippy::needless_borrowed_reference,
+ clippy::redundant_guards
)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr
index b72fe10b7..b57b26284 100644
--- a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr
+++ b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr
@@ -1,55 +1,55 @@
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:15:14
+ --> $DIR/match_expr_like_matches_macro.rs:16:14
|
LL | let _y = match x {
| ______________^
LL | | Some(0) => true,
LL | | _ => false,
LL | | };
- | |_____^ help: try this: `matches!(x, Some(0))`
+ | |_____^ help: try: `matches!(x, Some(0))`
|
= note: `-D clippy::match-like-matches-macro` implied by `-D warnings`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/match_expr_like_matches_macro.rs:21:14
+ --> $DIR/match_expr_like_matches_macro.rs:22:14
|
LL | let _w = match x {
| ______________^
LL | | Some(_) => true,
LL | | _ => false,
LL | | };
- | |_____^ help: try this: `x.is_some()`
+ | |_____^ help: try: `x.is_some()`
|
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/match_expr_like_matches_macro.rs:27:14
+ --> $DIR/match_expr_like_matches_macro.rs:28:14
|
LL | let _z = match x {
| ______________^
LL | | Some(_) => false,
LL | | None => true,
LL | | };
- | |_____^ help: try this: `x.is_none()`
+ | |_____^ help: try: `x.is_none()`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:33:15
+ --> $DIR/match_expr_like_matches_macro.rs:34:15
|
LL | let _zz = match x {
| _______________^
LL | | Some(r) if r == 0 => false,
LL | | _ => true,
LL | | };
- | |_____^ help: try this: `!matches!(x, Some(r) if r == 0)`
+ | |_____^ help: try: `!matches!(x, Some(r) if r == 0)`
error: if let .. else expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:39:16
+ --> $DIR/match_expr_like_matches_macro.rs:40:16
|
LL | let _zzz = if let Some(5) = x { true } else { false };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `matches!(x, Some(5))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(x, Some(5))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:63:20
+ --> $DIR/match_expr_like_matches_macro.rs:64:20
|
LL | let _ans = match x {
| ____________________^
@@ -57,10 +57,10 @@ LL | | E::A(_) => true,
LL | | E::B(_) => true,
LL | | _ => false,
LL | | };
- | |_________^ help: try this: `matches!(x, E::A(_) | E::B(_))`
+ | |_________^ help: try: `matches!(x, E::A(_) | E::B(_))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:73:20
+ --> $DIR/match_expr_like_matches_macro.rs:74:20
|
LL | let _ans = match x {
| ____________________^
@@ -70,10 +70,10 @@ LL | | }
LL | | E::B(_) => true,
LL | | _ => false,
LL | | };
- | |_________^ help: try this: `matches!(x, E::A(_) | E::B(_))`
+ | |_________^ help: try: `matches!(x, E::A(_) | E::B(_))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:83:20
+ --> $DIR/match_expr_like_matches_macro.rs:84:20
|
LL | let _ans = match x {
| ____________________^
@@ -81,67 +81,67 @@ LL | | E::B(_) => false,
LL | | E::C => false,
LL | | _ => true,
LL | | };
- | |_________^ help: try this: `!matches!(x, E::B(_) | E::C)`
+ | |_________^ help: try: `!matches!(x, E::B(_) | E::C)`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:143:18
+ --> $DIR/match_expr_like_matches_macro.rs:144:18
|
LL | let _z = match &z {
| __________________^
LL | | Some(3) => true,
LL | | _ => false,
LL | | };
- | |_________^ help: try this: `matches!(z, Some(3))`
+ | |_________^ help: try: `matches!(z, Some(3))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:152:18
+ --> $DIR/match_expr_like_matches_macro.rs:153:18
|
LL | let _z = match &z {
| __________________^
LL | | Some(3) => true,
LL | | _ => false,
LL | | };
- | |_________^ help: try this: `matches!(&z, Some(3))`
+ | |_________^ help: try: `matches!(&z, Some(3))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:169:21
+ --> $DIR/match_expr_like_matches_macro.rs:170:21
|
LL | let _ = match &z {
| _____________________^
LL | | AnEnum::X => true,
LL | | _ => false,
LL | | };
- | |_____________^ help: try this: `matches!(&z, AnEnum::X)`
+ | |_____________^ help: try: `matches!(&z, AnEnum::X)`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:183:20
+ --> $DIR/match_expr_like_matches_macro.rs:184:20
|
LL | let _res = match &val {
| ____________________^
LL | | &Some(ref _a) => true,
LL | | _ => false,
LL | | };
- | |_________^ help: try this: `matches!(&val, &Some(ref _a))`
+ | |_________^ help: try: `matches!(&val, &Some(ref _a))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:195:20
+ --> $DIR/match_expr_like_matches_macro.rs:196:20
|
LL | let _res = match &val {
| ____________________^
LL | | &Some(ref _a) => true,
LL | | _ => false,
LL | | };
- | |_________^ help: try this: `matches!(&val, &Some(ref _a))`
+ | |_________^ help: try: `matches!(&val, &Some(ref _a))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:253:14
+ --> $DIR/match_expr_like_matches_macro.rs:254:14
|
LL | let _y = match Some(5) {
| ______________^
LL | | Some(0) => true,
LL | | _ => false,
LL | | };
- | |_____^ help: try this: `matches!(Some(5), Some(0))`
+ | |_____^ help: try: `matches!(Some(5), Some(0))`
error: aborting due to 14 previous errors
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 9b1f05286..fc4a3ce19 100644
--- a/src/tools/clippy/tests/ui/match_on_vec_items.stderr
+++ b/src/tools/clippy/tests/ui/match_on_vec_items.stderr
@@ -2,7 +2,7 @@ error: indexing into a vector may panic
--> $DIR/match_on_vec_items.rs:10:11
|
LL | match arr[idx] {
- | ^^^^^^^^ help: try this: `arr.get(idx)`
+ | ^^^^^^^^ help: try: `arr.get(idx)`
|
= note: `-D clippy::match-on-vec-items` implied by `-D warnings`
@@ -10,43 +10,43 @@ error: indexing into a vector may panic
--> $DIR/match_on_vec_items.rs:17:11
|
LL | match arr[range] {
- | ^^^^^^^^^^ help: try this: `arr.get(range)`
+ | ^^^^^^^^^^ help: try: `arr.get(range)`
error: indexing into a vector may panic
--> $DIR/match_on_vec_items.rs:30:11
|
LL | match arr[idx] {
- | ^^^^^^^^ help: try this: `arr.get(idx)`
+ | ^^^^^^^^ help: try: `arr.get(idx)`
error: indexing into a vector may panic
--> $DIR/match_on_vec_items.rs:37:11
|
LL | match arr[range] {
- | ^^^^^^^^^^ help: try this: `arr.get(range)`
+ | ^^^^^^^^^^ help: try: `arr.get(range)`
error: indexing into a vector may panic
--> $DIR/match_on_vec_items.rs:50:11
|
LL | match arr[idx] {
- | ^^^^^^^^ help: try this: `arr.get(idx)`
+ | ^^^^^^^^ help: try: `arr.get(idx)`
error: indexing into a vector may panic
--> $DIR/match_on_vec_items.rs:57:11
|
LL | match arr[range] {
- | ^^^^^^^^^^ help: try this: `arr.get(range)`
+ | ^^^^^^^^^^ help: try: `arr.get(range)`
error: indexing into a vector may panic
--> $DIR/match_on_vec_items.rs:70:11
|
LL | match arr[idx] {
- | ^^^^^^^^ help: try this: `arr.get(idx)`
+ | ^^^^^^^^ help: try: `arr.get(idx)`
error: indexing into a vector may panic
--> $DIR/match_on_vec_items.rs:77:11
|
LL | match arr[range] {
- | ^^^^^^^^^^ help: try this: `arr.get(range)`
+ | ^^^^^^^^^^ help: try: `arr.get(range)`
error: aborting due to 8 previous errors
diff --git a/src/tools/clippy/tests/ui/match_ref_pats.stderr b/src/tools/clippy/tests/ui/match_ref_pats.stderr
index 7d9646c84..1294e0fe5 100644
--- a/src/tools/clippy/tests/ui/match_ref_pats.stderr
+++ b/src/tools/clippy/tests/ui/match_ref_pats.stderr
@@ -35,7 +35,7 @@ error: redundant pattern matching, consider using `is_none()`
--> $DIR/match_ref_pats.rs:38:12
|
LL | if let &None = a {
- | -------^^^^^---- help: try this: `if a.is_none()`
+ | -------^^^^^---- help: try: `if a.is_none()`
|
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
@@ -43,7 +43,7 @@ error: redundant pattern matching, consider using `is_none()`
--> $DIR/match_ref_pats.rs:43:12
|
LL | if let &None = &b {
- | -------^^^^^----- help: try this: `if b.is_none()`
+ | -------^^^^^----- help: try: `if b.is_none()`
error: you don't need to add `&` to all patterns
--> $DIR/match_ref_pats.rs:103:9
diff --git a/src/tools/clippy/tests/ui/match_same_arms2.stderr b/src/tools/clippy/tests/ui/match_same_arms2.stderr
index 7f0c70745..a73481875 100644
--- a/src/tools/clippy/tests/ui/match_same_arms2.stderr
+++ b/src/tools/clippy/tests/ui/match_same_arms2.stderr
@@ -144,7 +144,7 @@ LL | | E::A => false,
LL | | E::B => false,
LL | | _ => true,
LL | | };
- | |_____^ help: try this: `!matches!(x, E::A | E::B)`
+ | |_____^ help: try: `!matches!(x, E::A | E::B)`
|
= note: `-D clippy::match-like-matches-macro` implied by `-D warnings`
diff --git a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.stderr b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.stderr
index 105b4c4b4..40ff4fbd3 100644
--- a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.stderr
+++ b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.stderr
@@ -2,7 +2,7 @@ error: wildcard matches only a single variant and will also match any future add
--> $DIR/match_wildcard_for_single_variants.rs:24:13
|
LL | _ => (),
- | ^ help: try this: `Self::Rgb(..)`
+ | ^ help: try: `Self::Rgb(..)`
|
= note: `-D clippy::match-wildcard-for-single-variants` implied by `-D warnings`
@@ -10,55 +10,55 @@ error: wildcard matches only a single variant and will also match any future add
--> $DIR/match_wildcard_for_single_variants.rs:34:9
|
LL | _ => {},
- | ^ help: try this: `Foo::C`
+ | ^ help: try: `Foo::C`
error: wildcard matches only a single variant and will also match any future added variants
--> $DIR/match_wildcard_for_single_variants.rs:44:9
|
LL | _ => {},
- | ^ help: try this: `Color::Blue`
+ | ^ help: try: `Color::Blue`
error: wildcard matches only a single variant and will also match any future added variants
--> $DIR/match_wildcard_for_single_variants.rs:52:9
|
LL | _ => {},
- | ^ help: try this: `Color::Blue`
+ | ^ help: try: `Color::Blue`
error: wildcard matches only a single variant and will also match any future added variants
--> $DIR/match_wildcard_for_single_variants.rs:58:9
|
LL | _ => {},
- | ^ help: try this: `Color::Blue`
+ | ^ help: try: `Color::Blue`
error: wildcard matches only a single variant and will also match any future added variants
--> $DIR/match_wildcard_for_single_variants.rs:75:9
|
LL | &_ => (),
- | ^^ help: try this: `Color::Blue`
+ | ^^ help: try: `Color::Blue`
error: wildcard matches only a single variant and will also match any future added variants
--> $DIR/match_wildcard_for_single_variants.rs:84:9
|
LL | _ => (),
- | ^ help: try this: `C::Blue`
+ | ^ help: try: `C::Blue`
error: wildcard matches only a single variant and will also match any future added variants
--> $DIR/match_wildcard_for_single_variants.rs:91:9
|
LL | _ => (),
- | ^ help: try this: `Color::Blue`
+ | ^ help: try: `Color::Blue`
error: wildcard matches only a single variant and will also match any future added variants
--> $DIR/match_wildcard_for_single_variants.rs:126:13
|
LL | _ => (),
- | ^ help: try this: `Enum::__Private`
+ | ^ help: try: `Enum::__Private`
error: wildcard matches only a single variant and will also match any future added variants
--> $DIR/match_wildcard_for_single_variants.rs:153:13
|
LL | _ => 2,
- | ^ help: try this: `Foo::B`
+ | ^ help: try: `Foo::B`
error: aborting due to 10 previous errors
diff --git a/src/tools/clippy/tests/ui/methods.rs b/src/tools/clippy/tests/ui/methods.rs
index 589eab5cd..cb1f695c6 100644
--- a/src/tools/clippy/tests/ui/methods.rs
+++ b/src/tools/clippy/tests/ui/methods.rs
@@ -25,10 +25,7 @@
#[macro_use]
extern crate option_helpers;
-use std::collections::BTreeMap;
-use std::collections::HashMap;
-use std::collections::HashSet;
-use std::collections::VecDeque;
+use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
use std::ops::Mul;
use std::rc::{self, Rc};
use std::sync::{self, Arc};
diff --git a/src/tools/clippy/tests/ui/methods.stderr b/src/tools/clippy/tests/ui/methods.stderr
index 73ec48643..6be38b24f 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:106:5
+ --> $DIR/methods.rs:103: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:127:13
+ --> $DIR/methods.rs:124:13
|
LL | let _ = v.iter().filter(|&x| {
| _____________^
diff --git a/src/tools/clippy/tests/ui/methods_fixable.stderr b/src/tools/clippy/tests/ui/methods_fixable.stderr
index 187714c75..6f45d100d 100644
--- a/src/tools/clippy/tests/ui/methods_fixable.stderr
+++ b/src/tools/clippy/tests/ui/methods_fixable.stderr
@@ -2,7 +2,7 @@ error: called `filter(..).next()` on an `Iterator`. This is more succinctly expr
--> $DIR/methods_fixable.rs:11:13
|
LL | let _ = v.iter().filter(|&x| *x < 0).next();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `v.iter().find(|&x| *x < 0)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `v.iter().find(|&x| *x < 0)`
|
= note: `-D clippy::filter-next` implied by `-D warnings`
diff --git a/src/tools/clippy/tests/ui/methods_unfixable.rs b/src/tools/clippy/tests/ui/methods_unfixable.rs
new file mode 100644
index 000000000..3d88ce4b6
--- /dev/null
+++ b/src/tools/clippy/tests/ui/methods_unfixable.rs
@@ -0,0 +1,10 @@
+#![warn(clippy::filter_next)]
+
+fn main() {
+ issue10029();
+}
+
+pub fn issue10029() {
+ let iter = (0..10);
+ let _ = iter.filter(|_| true).next();
+}
diff --git a/src/tools/clippy/tests/ui/methods_unfixable.stderr b/src/tools/clippy/tests/ui/methods_unfixable.stderr
new file mode 100644
index 000000000..6e101fe16
--- /dev/null
+++ b/src/tools/clippy/tests/ui/methods_unfixable.stderr
@@ -0,0 +1,15 @@
+error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead
+ --> $DIR/methods_unfixable.rs:9:13
+ |
+LL | let _ = iter.filter(|_| true).next();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `iter.find(|_| true)`
+ |
+help: you will also need to make `iter` mutable, because `find` takes `&mut self`
+ --> $DIR/methods_unfixable.rs:8:9
+ |
+LL | let iter = (0..10);
+ | ^^^^
+ = note: `-D clippy::filter-next` implied by `-D warnings`
+
+error: aborting due to previous error
+
diff --git a/src/tools/clippy/tests/ui/min_ident_chars.rs b/src/tools/clippy/tests/ui/min_ident_chars.rs
index b5b9e66aa..03784442e 100644
--- a/src/tools/clippy/tests/ui/min_ident_chars.rs
+++ b/src/tools/clippy/tests/ui/min_ident_chars.rs
@@ -3,8 +3,7 @@
#![warn(clippy::min_ident_chars)]
extern crate proc_macros;
-use proc_macros::external;
-use proc_macros::with_span;
+use proc_macros::{external, with_span};
struct A {
a: u32,
@@ -82,3 +81,7 @@ fn b() {}
fn wrong_pythagoras(a: f32, b: f32) -> f32 {
a * a + a * b
}
+
+mod issue_11163 {
+ struct Array<T, const N: usize>([T; N]);
+}
diff --git a/src/tools/clippy/tests/ui/min_ident_chars.stderr b/src/tools/clippy/tests/ui/min_ident_chars.stderr
index 66a63f657..4dff6588b 100644
--- a/src/tools/clippy/tests/ui/min_ident_chars.stderr
+++ b/src/tools/clippy/tests/ui/min_ident_chars.stderr
@@ -1,5 +1,5 @@
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:9:8
+ --> $DIR/min_ident_chars.rs:8:8
|
LL | struct A {
| ^
@@ -7,169 +7,169 @@ 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
+ --> $DIR/min_ident_chars.rs:9:5
|
LL | a: u32,
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:12:5
+ --> $DIR/min_ident_chars.rs:11:5
|
LL | A: u32,
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:13:5
+ --> $DIR/min_ident_chars.rs:12:5
|
LL | I: u32,
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:16:8
+ --> $DIR/min_ident_chars.rs:15:8
|
LL | struct B(u32);
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:18:8
+ --> $DIR/min_ident_chars.rs:17:8
|
LL | struct O {
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:19:5
+ --> $DIR/min_ident_chars.rs:18:5
|
LL | o: u32,
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:24:6
+ --> $DIR/min_ident_chars.rs:23:6
|
LL | enum C {
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:25:5
+ --> $DIR/min_ident_chars.rs:24:5
|
LL | D,
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:26:5
+ --> $DIR/min_ident_chars.rs:25:5
|
LL | E,
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:27:5
+ --> $DIR/min_ident_chars.rs:26:5
|
LL | F,
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:51:9
+ --> $DIR/min_ident_chars.rs:50:9
|
LL | let h = 1;
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:52:9
+ --> $DIR/min_ident_chars.rs:51:9
|
LL | let e = 2;
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:53:9
+ --> $DIR/min_ident_chars.rs:52:9
|
LL | let l = 3;
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:54:9
+ --> $DIR/min_ident_chars.rs:53:9
|
LL | let l = 4;
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:55:9
+ --> $DIR/min_ident_chars.rs:54:9
|
LL | let o = 6;
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:59:10
+ --> $DIR/min_ident_chars.rs:58:10
|
LL | let (h, o, w) = (1, 2, 3);
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:59:13
+ --> $DIR/min_ident_chars.rs:58:13
|
LL | let (h, o, w) = (1, 2, 3);
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:60:10
+ --> $DIR/min_ident_chars.rs:59: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
+ --> $DIR/min_ident_chars.rs:59: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
+ --> $DIR/min_ident_chars.rs:59: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
+ --> $DIR/min_ident_chars.rs:61: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
+ --> $DIR/min_ident_chars.rs:61: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
+ --> $DIR/min_ident_chars.rs:61: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
+ --> $DIR/min_ident_chars.rs:65:9
|
LL | let o = 1;
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:67:9
+ --> $DIR/min_ident_chars.rs:66:9
|
LL | let o = O { o };
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:81:4
+ --> $DIR/min_ident_chars.rs:80:4
|
LL | fn b() {}
| ^
error: this ident consists of a single char
- --> $DIR/min_ident_chars.rs:82:21
+ --> $DIR/min_ident_chars.rs:81: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
+ --> $DIR/min_ident_chars.rs:81:29
|
LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 {
| ^
diff --git a/src/tools/clippy/tests/ui/min_max.rs b/src/tools/clippy/tests/ui/min_max.rs
index 24e52afd6..1215a0228 100644
--- a/src/tools/clippy/tests/ui/min_max.rs
+++ b/src/tools/clippy/tests/ui/min_max.rs
@@ -1,9 +1,7 @@
#![warn(clippy::all)]
#![allow(clippy::manual_clamp)]
-use std::cmp::max as my_max;
-use std::cmp::min as my_min;
-use std::cmp::{max, min};
+use std::cmp::{max as my_max, max, min as my_min, min};
const LARGE: usize = 3;
diff --git a/src/tools/clippy/tests/ui/min_max.stderr b/src/tools/clippy/tests/ui/min_max.stderr
index 069d90686..402b094f4 100644
--- a/src/tools/clippy/tests/ui/min_max.stderr
+++ b/src/tools/clippy/tests/ui/min_max.stderr
@@ -1,5 +1,5 @@
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:24:5
+ --> $DIR/min_max.rs:22:5
|
LL | min(1, max(3, x));
| ^^^^^^^^^^^^^^^^^
@@ -7,73 +7,73 @@ LL | min(1, max(3, x));
= note: `-D clippy::min-max` implied by `-D warnings`
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:25:5
+ --> $DIR/min_max.rs:23:5
|
LL | min(max(3, x), 1);
| ^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:26:5
+ --> $DIR/min_max.rs:24:5
|
LL | max(min(x, 1), 3);
| ^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:27:5
+ --> $DIR/min_max.rs:25:5
|
LL | max(3, min(x, 1));
| ^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:29:5
+ --> $DIR/min_max.rs:27:5
|
LL | my_max(3, my_min(x, 1));
| ^^^^^^^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:39:5
+ --> $DIR/min_max.rs:37:5
|
LL | min("Apple", max("Zoo", s));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:40:5
+ --> $DIR/min_max.rs:38:5
|
LL | max(min(s, "Apple"), "Zoo");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:45:5
+ --> $DIR/min_max.rs:43:5
|
LL | x.min(1).max(3);
| ^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:46:5
+ --> $DIR/min_max.rs:44:5
|
LL | x.max(3).min(1);
| ^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:47:5
+ --> $DIR/min_max.rs:45:5
|
LL | f.max(3f32).min(1f32);
| ^^^^^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:53:5
+ --> $DIR/min_max.rs:51:5
|
LL | max(x.min(1), 3);
| ^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:56:5
+ --> $DIR/min_max.rs:54:5
|
LL | s.max("Zoo").min("Apple");
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:57:5
+ --> $DIR/min_max.rs:55:5
|
LL | s.min("Apple").max("Zoo");
| ^^^^^^^^^^^^^^^^^^^^^^^^^
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 b1980b1b5..3aaee67e1 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
@@ -99,4 +99,5 @@ impl const Drop for D {
}
// Lint this, since it can be dropped in const contexts
+// FIXME(effects)
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 7be2cc0ca..66cf4e315 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
@@ -89,11 +89,5 @@ LL | | 46
LL | | }
| |_^
-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
+error: aborting due to 11 previous errors
diff --git a/src/tools/clippy/tests/ui/missing_doc.rs b/src/tools/clippy/tests/ui/missing_doc.rs
index cff1706a8..83ebf09c8 100644
--- a/src/tools/clippy/tests/ui/missing_doc.rs
+++ b/src/tools/clippy/tests/ui/missing_doc.rs
@@ -96,10 +96,8 @@ mod internal_impl {
}
/// dox
pub mod public_interface {
- pub use crate::internal_impl::documented as foo;
pub use crate::internal_impl::globbed::*;
- pub use crate::internal_impl::undocumented1 as bar;
- pub use crate::internal_impl::{documented, undocumented2};
+ pub use crate::internal_impl::{documented as foo, documented, undocumented1 as bar, undocumented2};
}
fn main() {}
diff --git a/src/tools/clippy/tests/ui/missing_spin_loop.stderr b/src/tools/clippy/tests/ui/missing_spin_loop.stderr
index 485da00dc..5795c2c21 100644
--- a/src/tools/clippy/tests/ui/missing_spin_loop.stderr
+++ b/src/tools/clippy/tests/ui/missing_spin_loop.stderr
@@ -2,7 +2,7 @@ error: busy-waiting loop should at least have a spin loop hint
--> $DIR/missing_spin_loop.rs:11:37
|
LL | while b.load(Ordering::Acquire) {}
- | ^^ help: try this: `{ std::hint::spin_loop() }`
+ | ^^ help: try: `{ std::hint::spin_loop() }`
|
= note: `-D clippy::missing-spin-loop` implied by `-D warnings`
@@ -10,31 +10,31 @@ error: busy-waiting loop should at least have a spin loop hint
--> $DIR/missing_spin_loop.rs:13:37
|
LL | while !b.load(Ordering::SeqCst) {}
- | ^^ help: try this: `{ std::hint::spin_loop() }`
+ | ^^ help: try: `{ std::hint::spin_loop() }`
error: busy-waiting loop should at least have a spin loop hint
--> $DIR/missing_spin_loop.rs:15:46
|
LL | while b.load(Ordering::Acquire) == false {}
- | ^^ help: try this: `{ std::hint::spin_loop() }`
+ | ^^ help: try: `{ std::hint::spin_loop() }`
error: busy-waiting loop should at least have a spin loop hint
--> $DIR/missing_spin_loop.rs:17:49
|
LL | while { true == b.load(Ordering::Acquire) } {}
- | ^^ help: try this: `{ std::hint::spin_loop() }`
+ | ^^ help: try: `{ std::hint::spin_loop() }`
error: busy-waiting loop should at least have a spin loop hint
--> $DIR/missing_spin_loop.rs:19:93
|
LL | while b.compare_exchange(true, false, Ordering::Acquire, Ordering::Relaxed) != Ok(true) {}
- | ^^ help: try this: `{ std::hint::spin_loop() }`
+ | ^^ help: try: `{ std::hint::spin_loop() }`
error: busy-waiting loop should at least have a spin loop hint
--> $DIR/missing_spin_loop.rs:21:94
|
LL | while Ok(false) != b.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed) {}
- | ^^ help: try this: `{ std::hint::spin_loop() }`
+ | ^^ help: try: `{ std::hint::spin_loop() }`
error: aborting due to 6 previous errors
diff --git a/src/tools/clippy/tests/ui/missing_spin_loop_no_std.stderr b/src/tools/clippy/tests/ui/missing_spin_loop_no_std.stderr
index 2b3b6873c..3322a7aae 100644
--- a/src/tools/clippy/tests/ui/missing_spin_loop_no_std.stderr
+++ b/src/tools/clippy/tests/ui/missing_spin_loop_no_std.stderr
@@ -2,7 +2,7 @@ error: busy-waiting loop should at least have a spin loop hint
--> $DIR/missing_spin_loop_no_std.rs:13:37
|
LL | while b.load(Ordering::Acquire) {}
- | ^^ help: try this: `{ core::hint::spin_loop() }`
+ | ^^ help: try: `{ core::hint::spin_loop() }`
|
= note: `-D clippy::missing-spin-loop` implied by `-D warnings`
diff --git a/src/tools/clippy/tests/ui/must_use_candidates.fixed b/src/tools/clippy/tests/ui/must_use_candidates.fixed
index 0c275504d..3ca20c07d 100644
--- a/src/tools/clippy/tests/ui/must_use_candidates.fixed
+++ b/src/tools/clippy/tests/ui/must_use_candidates.fixed
@@ -1,6 +1,11 @@
//@run-rustfix
#![feature(never_type)]
-#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
+#![allow(
+ unused_mut,
+ unused_tuple_struct_fields,
+ clippy::redundant_allocation,
+ clippy::needless_pass_by_ref_mut
+)]
#![warn(clippy::must_use_candidate)]
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};
diff --git a/src/tools/clippy/tests/ui/must_use_candidates.rs b/src/tools/clippy/tests/ui/must_use_candidates.rs
index d1c926773..dc4e0118e 100644
--- a/src/tools/clippy/tests/ui/must_use_candidates.rs
+++ b/src/tools/clippy/tests/ui/must_use_candidates.rs
@@ -1,6 +1,11 @@
//@run-rustfix
#![feature(never_type)]
-#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
+#![allow(
+ unused_mut,
+ unused_tuple_struct_fields,
+ clippy::redundant_allocation,
+ clippy::needless_pass_by_ref_mut
+)]
#![warn(clippy::must_use_candidate)]
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};
diff --git a/src/tools/clippy/tests/ui/must_use_candidates.stderr b/src/tools/clippy/tests/ui/must_use_candidates.stderr
index 0fa3849d0..5fb302ccb 100644
--- a/src/tools/clippy/tests/ui/must_use_candidates.stderr
+++ b/src/tools/clippy/tests/ui/must_use_candidates.stderr
@@ -1,5 +1,5 @@
error: this function could have a `#[must_use]` attribute
- --> $DIR/must_use_candidates.rs:12:1
+ --> $DIR/must_use_candidates.rs:17:1
|
LL | pub fn pure(i: u8) -> u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn pure(i: u8) -> u8`
@@ -7,25 +7,25 @@ LL | pub fn pure(i: u8) -> u8 {
= note: `-D clippy::must-use-candidate` implied by `-D warnings`
error: this method could have a `#[must_use]` attribute
- --> $DIR/must_use_candidates.rs:17:5
+ --> $DIR/must_use_candidates.rs:22:5
|
LL | pub fn inherent_pure(&self) -> u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn inherent_pure(&self) -> u8`
error: this function could have a `#[must_use]` attribute
- --> $DIR/must_use_candidates.rs:48:1
+ --> $DIR/must_use_candidates.rs:53:1
|
LL | pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool`
error: this function could have a `#[must_use]` attribute
- --> $DIR/must_use_candidates.rs:60:1
+ --> $DIR/must_use_candidates.rs:65:1
|
LL | pub fn rcd(_x: Rc<u32>) -> bool {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn rcd(_x: Rc<u32>) -> bool`
error: this function could have a `#[must_use]` attribute
- --> $DIR/must_use_candidates.rs:68:1
+ --> $DIR/must_use_candidates.rs:73:1
|
LL | pub fn arcd(_x: Arc<u32>) -> bool {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn arcd(_x: Arc<u32>) -> bool`
diff --git a/src/tools/clippy/tests/ui/mut_from_ref.rs b/src/tools/clippy/tests/ui/mut_from_ref.rs
index 7de153305..8c0c23b65 100644
--- a/src/tools/clippy/tests/ui/mut_from_ref.rs
+++ b/src/tools/clippy/tests/ui/mut_from_ref.rs
@@ -1,4 +1,4 @@
-#![allow(unused, clippy::needless_lifetimes)]
+#![allow(unused, clippy::needless_lifetimes, clippy::needless_pass_by_ref_mut)]
#![warn(clippy::mut_from_ref)]
struct Foo;
diff --git a/src/tools/clippy/tests/ui/mut_key.rs b/src/tools/clippy/tests/ui/mut_key.rs
index 1c0ba6645..15d68c089 100644
--- a/src/tools/clippy/tests/ui/mut_key.rs
+++ b/src/tools/clippy/tests/ui/mut_key.rs
@@ -2,7 +2,8 @@ use std::cell::Cell;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::hash::{Hash, Hasher};
use std::rc::Rc;
-use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};
+use std::sync::atomic::AtomicUsize;
+use std::sync::atomic::Ordering::Relaxed;
use std::sync::Arc;
struct Key(AtomicUsize);
diff --git a/src/tools/clippy/tests/ui/mut_key.stderr b/src/tools/clippy/tests/ui/mut_key.stderr
index 25dd029b1..95b9546bf 100644
--- a/src/tools/clippy/tests/ui/mut_key.stderr
+++ b/src/tools/clippy/tests/ui/mut_key.stderr
@@ -1,5 +1,5 @@
error: mutable key type
- --> $DIR/mut_key.rs:30:32
+ --> $DIR/mut_key.rs:31:32
|
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -7,97 +7,97 @@ LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> Hash
= note: `-D clippy::mutable-key-type` implied by `-D warnings`
error: mutable key type
- --> $DIR/mut_key.rs:30:72
+ --> $DIR/mut_key.rs:31:72
|
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
| ^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:31:5
+ --> $DIR/mut_key.rs:32:5
|
LL | let _other: HashMap<Key, bool> = HashMap::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:58:22
+ --> $DIR/mut_key.rs:59:22
|
LL | fn tuples_bad<U>(_m: &mut HashMap<(Key, U), bool>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:70:5
+ --> $DIR/mut_key.rs:71:5
|
LL | let _map = HashMap::<Cell<usize>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:71:5
+ --> $DIR/mut_key.rs:72:5
|
LL | let _map = HashMap::<&mut Cell<usize>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:72:5
+ --> $DIR/mut_key.rs:73:5
|
LL | let _map = HashMap::<&mut usize, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:74:5
+ --> $DIR/mut_key.rs:75:5
|
LL | let _map = HashMap::<Vec<Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:75:5
+ --> $DIR/mut_key.rs:76:5
|
LL | let _map = HashMap::<BTreeMap<Cell<usize>, ()>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:76:5
+ --> $DIR/mut_key.rs:77:5
|
LL | let _map = HashMap::<BTreeMap<(), Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:77:5
+ --> $DIR/mut_key.rs:78:5
|
LL | let _map = HashMap::<BTreeSet<Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:78:5
+ --> $DIR/mut_key.rs:79:5
|
LL | let _map = HashMap::<Option<Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:79:5
+ --> $DIR/mut_key.rs:80:5
|
LL | let _map = HashMap::<Option<Vec<Cell<usize>>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:80:5
+ --> $DIR/mut_key.rs:81:5
|
LL | let _map = HashMap::<Result<&mut usize, ()>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:82:5
+ --> $DIR/mut_key.rs:83:5
|
LL | let _map = HashMap::<Box<Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:83:5
+ --> $DIR/mut_key.rs:84:5
|
LL | let _map = HashMap::<Rc<Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable key type
- --> $DIR/mut_key.rs:84:5
+ --> $DIR/mut_key.rs:85:5
|
LL | let _map = HashMap::<Arc<Cell<usize>>, usize>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/mut_mut.rs b/src/tools/clippy/tests/ui/mut_mut.rs
index b72134283..fe7d53e8e 100644
--- a/src/tools/clippy/tests/ui/mut_mut.rs
+++ b/src/tools/clippy/tests/ui/mut_mut.rs
@@ -1,7 +1,12 @@
//@aux-build:proc_macros.rs:proc-macro
#![warn(clippy::mut_mut)]
#![allow(unused)]
-#![allow(clippy::no_effect, clippy::uninlined_format_args, clippy::unnecessary_operation)]
+#![allow(
+ clippy::no_effect,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_operation,
+ clippy::needless_pass_by_ref_mut
+)]
extern crate proc_macros;
use proc_macros::{external, inline_macros};
diff --git a/src/tools/clippy/tests/ui/mut_mut.stderr b/src/tools/clippy/tests/ui/mut_mut.stderr
index 93b857eb2..58a1c4e68 100644
--- a/src/tools/clippy/tests/ui/mut_mut.stderr
+++ b/src/tools/clippy/tests/ui/mut_mut.stderr
@@ -1,5 +1,5 @@
error: generally you want to avoid `&mut &mut _` if possible
- --> $DIR/mut_mut.rs:9:11
+ --> $DIR/mut_mut.rs:14:11
|
LL | fn fun(x: &mut &mut u32) -> bool {
| ^^^^^^^^^^^^^
@@ -7,13 +7,13 @@ LL | fn fun(x: &mut &mut u32) -> bool {
= note: `-D clippy::mut-mut` implied by `-D warnings`
error: generally you want to avoid `&mut &mut _` if possible
- --> $DIR/mut_mut.rs:26:17
+ --> $DIR/mut_mut.rs:31:17
|
LL | let mut x = &mut &mut 1u32;
| ^^^^^^^^^^^^^^
error: generally you want to avoid `&mut &mut _` if possible
- --> $DIR/mut_mut.rs:41:25
+ --> $DIR/mut_mut.rs:46:25
|
LL | let mut z = inline!(&mut $(&mut 3u32));
| ^
@@ -21,37 +21,37 @@ LL | let mut z = inline!(&mut $(&mut 3u32));
= note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this expression mutably borrows a mutable reference. Consider reborrowing
- --> $DIR/mut_mut.rs:28:21
+ --> $DIR/mut_mut.rs:33:21
|
LL | let mut y = &mut x;
| ^^^^^^
error: generally you want to avoid `&mut &mut _` if possible
- --> $DIR/mut_mut.rs:32:32
+ --> $DIR/mut_mut.rs:37:32
|
LL | let y: &mut &mut u32 = &mut &mut 2;
| ^^^^^^^^^^^
error: generally you want to avoid `&mut &mut _` if possible
- --> $DIR/mut_mut.rs:32:16
+ --> $DIR/mut_mut.rs:37:16
|
LL | let y: &mut &mut u32 = &mut &mut 2;
| ^^^^^^^^^^^^^
error: generally you want to avoid `&mut &mut _` if possible
- --> $DIR/mut_mut.rs:37:37
+ --> $DIR/mut_mut.rs:42:37
|
LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2;
| ^^^^^^^^^^^^^^^^
error: generally you want to avoid `&mut &mut _` if possible
- --> $DIR/mut_mut.rs:37:16
+ --> $DIR/mut_mut.rs:42:16
|
LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2;
| ^^^^^^^^^^^^^^^^^^
error: generally you want to avoid `&mut &mut _` if possible
- --> $DIR/mut_mut.rs:37:21
+ --> $DIR/mut_mut.rs:42:21
|
LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2;
| ^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/mut_reference.rs b/src/tools/clippy/tests/ui/mut_reference.rs
index 73906121c..00661c51a 100644
--- a/src/tools/clippy/tests/ui/mut_reference.rs
+++ b/src/tools/clippy/tests/ui/mut_reference.rs
@@ -1,8 +1,21 @@
-#![allow(unused_variables)]
+#![allow(unused_variables, dead_code)]
fn takes_an_immutable_reference(a: &i32) {}
fn takes_a_mutable_reference(a: &mut i32) {}
+mod issue11268 {
+ macro_rules! x {
+ ($f:expr) => {
+ $f(&mut 1);
+ };
+ }
+
+ fn f() {
+ x!(super::takes_an_immutable_reference);
+ x!(super::takes_a_mutable_reference);
+ }
+}
+
struct MyStruct;
impl MyStruct {
diff --git a/src/tools/clippy/tests/ui/mut_reference.stderr b/src/tools/clippy/tests/ui/mut_reference.stderr
index 062d30b26..4ce1cfa4f 100644
--- a/src/tools/clippy/tests/ui/mut_reference.stderr
+++ b/src/tools/clippy/tests/ui/mut_reference.stderr
@@ -1,5 +1,5 @@
error: the function `takes_an_immutable_reference` doesn't need a mutable reference
- --> $DIR/mut_reference.rs:17:34
+ --> $DIR/mut_reference.rs:30:34
|
LL | takes_an_immutable_reference(&mut 42);
| ^^^^^^^
@@ -7,13 +7,13 @@ LL | takes_an_immutable_reference(&mut 42);
= note: `-D clippy::unnecessary-mut-passed` implied by `-D warnings`
error: the function `as_ptr` doesn't need a mutable reference
- --> $DIR/mut_reference.rs:19:12
+ --> $DIR/mut_reference.rs:32:12
|
LL | as_ptr(&mut 42);
| ^^^^^^^
error: the method `takes_an_immutable_reference` doesn't need a mutable reference
- --> $DIR/mut_reference.rs:23:44
+ --> $DIR/mut_reference.rs:36:44
|
LL | my_struct.takes_an_immutable_reference(&mut 42);
| ^^^^^^^
diff --git a/src/tools/clippy/tests/ui/needless_borrow_pat.stderr b/src/tools/clippy/tests/ui/needless_borrow_pat.stderr
index db3b52b88..2d9b8f159 100644
--- a/src/tools/clippy/tests/ui/needless_borrow_pat.stderr
+++ b/src/tools/clippy/tests/ui/needless_borrow_pat.stderr
@@ -2,7 +2,7 @@ error: this pattern creates a reference to a reference
--> $DIR/needless_borrow_pat.rs:59:14
|
LL | Some(ref x) => x,
- | ^^^^^ help: try this: `x`
+ | ^^^^^ help: try: `x`
|
= note: `-D clippy::needless-borrow` implied by `-D warnings`
@@ -12,7 +12,7 @@ error: this pattern creates a reference to a reference
LL | Some(ref x) => *x,
| ^^^^^
|
-help: try this
+help: try
|
LL | Some(x) => x,
| ~ ~
@@ -23,7 +23,7 @@ error: this pattern creates a reference to a reference
LL | Some(ref x) => {
| ^^^^^
|
-help: try this
+help: try
|
LL ~ Some(x) => {
LL | f1(x);
@@ -34,13 +34,13 @@ error: this pattern creates a reference to a reference
--> $DIR/needless_borrow_pat.rs:81:14
|
LL | Some(ref x) => m1!(x),
- | ^^^^^ help: try this: `x`
+ | ^^^^^ help: try: `x`
error: this pattern creates a reference to a reference
--> $DIR/needless_borrow_pat.rs:86:15
|
LL | let _ = |&ref x: &&String| {
- | ^^^^^ help: try this: `x`
+ | ^^^^^ help: try: `x`
error: this pattern creates a reference to a reference
--> $DIR/needless_borrow_pat.rs:91:10
@@ -48,7 +48,7 @@ error: this pattern creates a reference to a reference
LL | let (ref y,) = (&x,);
| ^^^^^
|
-help: try this
+help: try
|
LL ~ let (y,) = (&x,);
LL ~ let _: &String = y;
@@ -58,7 +58,7 @@ error: this pattern creates a reference to a reference
--> $DIR/needless_borrow_pat.rs:101:14
|
LL | Some(ref x) => x.0,
- | ^^^^^ help: try this: `x`
+ | ^^^^^ help: try: `x`
error: this pattern creates a reference to a reference
--> $DIR/needless_borrow_pat.rs:111:14
@@ -66,7 +66,7 @@ error: this pattern creates a reference to a reference
LL | E::A(ref x) | E::B(ref x) => *x,
| ^^^^^ ^^^^^
|
-help: try this
+help: try
|
LL | E::A(x) | E::B(x) => x,
| ~ ~ ~
@@ -75,7 +75,7 @@ error: this pattern creates a reference to a reference
--> $DIR/needless_borrow_pat.rs:117:21
|
LL | if let Some(ref x) = Some(&String::new());
- | ^^^^^ help: try this: `x`
+ | ^^^^^ help: try: `x`
error: this pattern creates a reference to a reference
--> $DIR/needless_borrow_pat.rs:125:12
@@ -83,7 +83,7 @@ error: this pattern creates a reference to a reference
LL | fn f2<'a>(&ref x: &&'a String) -> &'a String {
| ^^^^^
|
-help: try this
+help: try
|
LL ~ fn f2<'a>(&x: &&'a String) -> &'a String {
LL | let _: &String = x;
@@ -94,7 +94,7 @@ error: this pattern creates a reference to a reference
--> $DIR/needless_borrow_pat.rs:132:11
|
LL | fn f(&ref x: &&String) {
- | ^^^^^ help: try this: `x`
+ | ^^^^^ help: try: `x`
error: this pattern creates a reference to a reference
--> $DIR/needless_borrow_pat.rs:140:11
@@ -102,7 +102,7 @@ error: this pattern creates a reference to a reference
LL | fn f(&ref x: &&String) {
| ^^^^^
|
-help: try this
+help: try
|
LL ~ fn f(&x: &&String) {
LL ~ let _: &String = x;
diff --git a/src/tools/clippy/tests/ui/needless_else.stderr b/src/tools/clippy/tests/ui/needless_else.stderr
index ea6930851..49cd78501 100644
--- a/src/tools/clippy/tests/ui/needless_else.stderr
+++ b/src/tools/clippy/tests/ui/needless_else.stderr
@@ -1,4 +1,4 @@
-error: this else branch is empty
+error: this `else` branch is empty
--> $DIR/needless_else.rs:24:7
|
LL | } else {
diff --git a/src/tools/clippy/tests/ui/needless_if.fixed b/src/tools/clippy/tests/ui/needless_if.fixed
index 5e6e140c2..6001c9e93 100644
--- a/src/tools/clippy/tests/ui/needless_if.fixed
+++ b/src/tools/clippy/tests/ui/needless_if.fixed
@@ -16,8 +16,7 @@
#![warn(clippy::needless_if)]
extern crate proc_macros;
-use proc_macros::external;
-use proc_macros::with_span;
+use proc_macros::{external, with_span};
fn maybe_side_effect() -> bool {
true
diff --git a/src/tools/clippy/tests/ui/needless_if.rs b/src/tools/clippy/tests/ui/needless_if.rs
index eb28ce73b..c6be4766d 100644
--- a/src/tools/clippy/tests/ui/needless_if.rs
+++ b/src/tools/clippy/tests/ui/needless_if.rs
@@ -16,8 +16,7 @@
#![warn(clippy::needless_if)]
extern crate proc_macros;
-use proc_macros::external;
-use proc_macros::with_span;
+use proc_macros::{external, with_span};
fn maybe_side_effect() -> bool {
true
diff --git a/src/tools/clippy/tests/ui/needless_if.stderr b/src/tools/clippy/tests/ui/needless_if.stderr
index 5cb42c369..14de40095 100644
--- a/src/tools/clippy/tests/ui/needless_if.stderr
+++ b/src/tools/clippy/tests/ui/needless_if.stderr
@@ -1,5 +1,5 @@
error: this `if` branch is empty
- --> $DIR/needless_if.rs:28:5
+ --> $DIR/needless_if.rs:27:5
|
LL | if (true) {}
| ^^^^^^^^^^^^ help: you can remove it
@@ -7,13 +7,13 @@ LL | if (true) {}
= note: `-D clippy::needless-if` implied by `-D warnings`
error: this `if` branch is empty
- --> $DIR/needless_if.rs:30:5
+ --> $DIR/needless_if.rs:29: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
+ --> $DIR/needless_if.rs:34:5
|
LL | / if {
LL | | return;
@@ -28,7 +28,7 @@ LL + });
|
error: this `if` branch is empty
- --> $DIR/needless_if.rs:47:5
+ --> $DIR/needless_if.rs:46:5
|
LL | / if {
LL | | if let true = true && true { true } else { false }
@@ -44,19 +44,19 @@ LL + } && true);
|
error: this `if` branch is empty
- --> $DIR/needless_if.rs:85:5
+ --> $DIR/needless_if.rs:84: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
+ --> $DIR/needless_if.rs:86: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
+ --> $DIR/needless_if.rs:90:5
|
LL | if true {}
| ^^^^^^^^^^ help: you can remove it: `true;`
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 20d28a968..4c0d502a2 100644
--- a/src/tools/clippy/tests/ui/needless_option_as_deref.stderr
+++ b/src/tools/clippy/tests/ui/needless_option_as_deref.stderr
@@ -2,7 +2,7 @@ error: derefed type is same as origin
--> $DIR/needless_option_as_deref.rs:9:29
|
LL | let _: Option<&usize> = Some(&1).as_deref();
- | ^^^^^^^^^^^^^^^^^^^ help: try this: `Some(&1)`
+ | ^^^^^^^^^^^^^^^^^^^ help: try: `Some(&1)`
|
= note: `-D clippy::needless-option-as-deref` implied by `-D warnings`
@@ -10,13 +10,13 @@ error: derefed type is same as origin
--> $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)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(&mut 1)`
error: derefed type is same as origin
--> $DIR/needless_option_as_deref.rs:14:13
|
LL | let _ = x.as_deref_mut();
- | ^^^^^^^^^^^^^^^^ help: try this: `x`
+ | ^^^^^^^^^^^^^^^^ help: try: `x`
error: aborting due to 3 previous errors
diff --git a/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.rs b/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.rs
new file mode 100644
index 000000000..4e79e5f53
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.rs
@@ -0,0 +1,254 @@
+#![allow(clippy::if_same_then_else, clippy::no_effect)]
+#![feature(lint_reasons)]
+
+// just ignore everywhere for now
+//@ignore-32bit
+//@ignore-64bit
+
+use std::ptr::NonNull;
+
+fn foo(s: &mut Vec<u32>, b: &u32, x: &mut u32) {
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ *x += *b + s.len() as u32;
+}
+
+// Should not warn.
+fn foo2(s: &mut Vec<u32>) {
+ s.push(8);
+}
+
+// Should not warn because we return it.
+fn foo3(s: &mut Vec<u32>) -> &mut Vec<u32> {
+ s
+}
+
+// Should not warn because `s` is used as mutable.
+fn foo4(s: &mut Vec<u32>) {
+ Vec::push(s, 4);
+}
+
+// Should not warn.
+fn foo5(s: &mut Vec<u32>) {
+ foo2(s);
+}
+
+fn foo6(s: &mut Vec<u32>) {
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ non_mut_ref(s);
+}
+
+fn non_mut_ref(_: &Vec<u32>) {}
+
+struct Bar;
+
+impl Bar {
+ // Should not warn on `&mut self`.
+ fn bar(&mut self) {}
+
+ fn mushroom(&self, vec: &mut Vec<i32>) -> usize {
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ vec.len()
+ }
+
+ fn badger(&mut self, vec: &mut Vec<i32>) -> usize {
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ vec.len()
+ }
+}
+
+trait Babar {
+ // Should not warn here since it's a trait method.
+ fn method(arg: &mut u32);
+}
+
+impl Babar for Bar {
+ // Should not warn here since it's a trait method.
+ fn method(a: &mut u32) {}
+}
+
+// Should not warn (checking variable aliasing).
+fn alias_check(s: &mut Vec<u32>) {
+ let mut alias = s;
+ let mut alias2 = alias;
+ let mut alias3 = alias2;
+ alias3.push(0);
+}
+
+// Should not warn (checking variable aliasing).
+fn alias_check2(mut s: &mut Vec<u32>) {
+ let mut alias = &mut s;
+ alias.push(0);
+}
+
+struct Mut<T> {
+ ptr: NonNull<T>,
+}
+
+impl<T> Mut<T> {
+ // Should not warn because `NonNull::from` also accepts `&mut`.
+ fn new(ptr: &mut T) -> Self {
+ Mut {
+ ptr: NonNull::from(ptr),
+ }
+ }
+}
+
+// Should not warn.
+fn unused(_: &mut u32, _b: &mut u8) {}
+
+// Should not warn.
+async fn f1(x: &mut i32) {
+ *x += 1;
+}
+// Should not warn.
+async fn f2(x: &mut i32, y: String) {
+ *x += 1;
+}
+// Should not warn.
+async fn f3(x: &mut i32, y: String, z: String) {
+ *x += 1;
+}
+// Should not warn.
+async fn f4(x: &mut i32, y: i32) {
+ *x += 1;
+}
+// Should not warn.
+async fn f5(x: i32, y: &mut i32) {
+ *y += 1;
+}
+// Should not warn.
+async fn f6(x: i32, y: &mut i32, z: &mut i32) {
+ *y += 1;
+ *z += 1;
+}
+// Should not warn.
+async fn f7(x: &mut i32, y: i32, z: &mut i32, a: i32) {
+ *x += 1;
+ *z += 1;
+}
+
+async fn a1(x: &mut i32) {
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ println!("{:?}", x);
+}
+async fn a2(x: &mut i32, y: String) {
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ println!("{:?}", x);
+}
+async fn a3(x: &mut i32, y: String, z: String) {
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ println!("{:?}", x);
+}
+async fn a4(x: &mut i32, y: i32) {
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ println!("{:?}", x);
+}
+async fn a5(x: i32, y: &mut i32) {
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ println!("{:?}", x);
+}
+async fn a6(x: i32, y: &mut i32) {
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ println!("{:?}", x);
+}
+async fn a7(x: i32, y: i32, z: &mut i32) {
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ println!("{:?}", z);
+}
+async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) {
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ println!("{:?}", z);
+}
+
+// Should not warn (passed as closure which takes `&mut`).
+fn passed_as_closure(s: &mut u32) {}
+
+// Should not warn.
+fn passed_as_local(s: &mut u32) {}
+
+// Should not warn.
+fn ty_unify_1(s: &mut u32) {}
+
+// Should not warn.
+fn ty_unify_2(s: &mut u32) {}
+
+// Should not warn.
+fn passed_as_field(s: &mut u32) {}
+
+fn closure_takes_mut(s: fn(&mut u32)) {}
+
+struct A {
+ s: fn(&mut u32),
+}
+
+// Should warn.
+fn used_as_path(s: &mut u32) {}
+
+// Make sure lint attributes work fine
+#[expect(clippy::needless_pass_by_ref_mut)]
+fn lint_attr(s: &mut u32) {}
+
+#[cfg(not(feature = "a"))]
+fn cfg_warn(s: &mut u32) {}
+//~^ ERROR: this argument is a mutable reference, but not used mutably
+//~| NOTE: this is cfg-gated and may require further changes
+
+#[cfg(not(feature = "a"))]
+mod foo {
+ fn cfg_warn(s: &mut u32) {}
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ //~| NOTE: this is cfg-gated and may require further changes
+}
+
+// Should not warn.
+async fn inner_async(x: &mut i32, y: &mut u32) {
+ async {
+ *y += 1;
+ *x += 1;
+ }
+ .await;
+}
+
+async fn inner_async2(x: &mut i32, y: &mut u32) {
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ async {
+ *x += 1;
+ }
+ .await;
+}
+
+async fn inner_async3(x: &mut i32, y: &mut u32) {
+ //~^ ERROR: this argument is a mutable reference, but not used mutably
+ async {
+ *y += 1;
+ }
+ .await;
+}
+
+// Should not warn.
+async fn async_vec(b: &mut Vec<bool>) {
+ b.append(&mut vec![]);
+}
+
+// Should not warn.
+async fn async_vec2(b: &mut Vec<bool>) {
+ b.push(true);
+}
+
+fn main() {
+ let mut u = 0;
+ let mut v = vec![0];
+ foo(&mut v, &0, &mut u);
+ foo2(&mut v);
+ foo3(&mut v);
+ foo4(&mut v);
+ foo5(&mut v);
+ alias_check(&mut v);
+ alias_check2(&mut v);
+ println!("{u}");
+ closure_takes_mut(passed_as_closure);
+ A { s: passed_as_field };
+ used_as_path;
+ let _: fn(&mut u32) = passed_as_local;
+ let _ = if v[0] == 0 { ty_unify_1 } else { ty_unify_2 };
+}
diff --git a/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.stderr b/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.stderr
new file mode 100644
index 000000000..2e06e7252
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_pass_by_ref_mut.stderr
@@ -0,0 +1,110 @@
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:6:11
+ |
+LL | fn foo(s: &mut Vec<u32>, b: &u32, x: &mut u32) {
+ | ^^^^^^^^^^^^^ help: consider changing to: `&Vec<u32>`
+ |
+ = note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:31:12
+ |
+LL | fn foo6(s: &mut Vec<u32>) {
+ | ^^^^^^^^^^^^^ help: consider changing to: `&Vec<u32>`
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:44:29
+ |
+LL | fn mushroom(&self, vec: &mut Vec<i32>) -> usize {
+ | ^^^^^^^^^^^^^ help: consider changing to: `&Vec<i32>`
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:49:31
+ |
+LL | fn badger(&mut self, vec: &mut Vec<i32>) -> usize {
+ | ^^^^^^^^^^^^^ help: consider changing to: `&Vec<i32>`
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:126:16
+ |
+LL | async fn a1(x: &mut i32) {
+ | ^^^^^^^^ help: consider changing to: `&i32`
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:130:16
+ |
+LL | async fn a2(x: &mut i32, y: String) {
+ | ^^^^^^^^ help: consider changing to: `&i32`
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:134:16
+ |
+LL | async fn a3(x: &mut i32, y: String, z: String) {
+ | ^^^^^^^^ help: consider changing to: `&i32`
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:138:16
+ |
+LL | async fn a4(x: &mut i32, y: i32) {
+ | ^^^^^^^^ help: consider changing to: `&i32`
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:142:24
+ |
+LL | async fn a5(x: i32, y: &mut i32) {
+ | ^^^^^^^^ help: consider changing to: `&i32`
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:146:24
+ |
+LL | async fn a6(x: i32, y: &mut i32) {
+ | ^^^^^^^^ help: consider changing to: `&i32`
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:150:32
+ |
+LL | async fn a7(x: i32, y: i32, z: &mut i32) {
+ | ^^^^^^^^ help: consider changing to: `&i32`
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:154:24
+ |
+LL | async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) {
+ | ^^^^^^^^ help: consider changing to: `&i32`
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:154:45
+ |
+LL | async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) {
+ | ^^^^^^^^ help: consider changing to: `&i32`
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:188:16
+ |
+LL | fn cfg_warn(s: &mut u32) {}
+ | ^^^^^^^^ help: consider changing to: `&u32`
+ |
+ = note: this is cfg-gated and may require further changes
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:194:20
+ |
+LL | fn cfg_warn(s: &mut u32) {}
+ | ^^^^^^^^ help: consider changing to: `&u32`
+ |
+ = note: this is cfg-gated and may require further changes
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:208:39
+ |
+LL | async fn inner_async2(x: &mut i32, y: &mut u32) {
+ | ^^^^^^^^ help: consider changing to: `&u32`
+
+error: this argument is a mutable reference, but not used mutably
+ --> $DIR/needless_pass_by_ref_mut.rs:216:26
+ |
+LL | async fn inner_async3(x: &mut i32, y: &mut u32) {
+ | ^^^^^^^^ help: consider changing to: `&i32`
+
+error: aborting due to 17 previous errors
+
diff --git a/src/tools/clippy/tests/ui/needless_return_with_question_mark.fixed b/src/tools/clippy/tests/ui/needless_return_with_question_mark.fixed
new file mode 100644
index 000000000..d6e47d07b
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_return_with_question_mark.fixed
@@ -0,0 +1,40 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(
+ clippy::needless_return,
+ clippy::no_effect,
+ clippy::unit_arg,
+ clippy::useless_conversion,
+ unused
+)]
+
+#[macro_use]
+extern crate proc_macros;
+
+fn a() -> u32 {
+ return 0;
+}
+
+fn b() -> Result<u32, u32> {
+ return Err(0);
+}
+
+// Do not lint
+fn c() -> Option<()> {
+ return None?;
+}
+
+fn main() -> Result<(), ()> {
+ Err(())?;
+ return Ok::<(), ()>(());
+ Err(())?;
+ Ok::<(), ()>(());
+ return Err(().into());
+ external! {
+ return Err(())?;
+ }
+ with_span! {
+ return Err(())?;
+ }
+ Err(())
+}
diff --git a/src/tools/clippy/tests/ui/needless_return_with_question_mark.rs b/src/tools/clippy/tests/ui/needless_return_with_question_mark.rs
new file mode 100644
index 000000000..4fc04d363
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_return_with_question_mark.rs
@@ -0,0 +1,40 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(
+ clippy::needless_return,
+ clippy::no_effect,
+ clippy::unit_arg,
+ clippy::useless_conversion,
+ unused
+)]
+
+#[macro_use]
+extern crate proc_macros;
+
+fn a() -> u32 {
+ return 0;
+}
+
+fn b() -> Result<u32, u32> {
+ return Err(0);
+}
+
+// Do not lint
+fn c() -> Option<()> {
+ return None?;
+}
+
+fn main() -> Result<(), ()> {
+ return Err(())?;
+ return Ok::<(), ()>(());
+ Err(())?;
+ Ok::<(), ()>(());
+ return Err(().into());
+ external! {
+ return Err(())?;
+ }
+ with_span! {
+ return Err(())?;
+ }
+ Err(())
+}
diff --git a/src/tools/clippy/tests/ui/needless_return_with_question_mark.stderr b/src/tools/clippy/tests/ui/needless_return_with_question_mark.stderr
new file mode 100644
index 000000000..e1d91638d
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_return_with_question_mark.stderr
@@ -0,0 +1,10 @@
+error: unneeded `return` statement with `?` operator
+ --> $DIR/needless_return_with_question_mark.rs:28:5
+ |
+LL | return Err(())?;
+ | ^^^^^^^ help: remove it
+ |
+ = note: `-D clippy::needless-return-with-question-mark` implied by `-D warnings`
+
+error: aborting due to previous error
+
diff --git a/src/tools/clippy/tests/ui/needless_splitn.stderr b/src/tools/clippy/tests/ui/needless_splitn.stderr
index f607d8e1a..0005f7581 100644
--- a/src/tools/clippy/tests/ui/needless_splitn.stderr
+++ b/src/tools/clippy/tests/ui/needless_splitn.stderr
@@ -2,7 +2,7 @@ error: unnecessary use of `splitn`
--> $DIR/needless_splitn.rs:14:13
|
LL | let _ = str.splitn(2, '=').next();
- | ^^^^^^^^^^^^^^^^^^ help: try this: `str.split('=')`
+ | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')`
|
= note: `-D clippy::needless-splitn` implied by `-D warnings`
@@ -10,73 +10,73 @@ error: unnecessary use of `splitn`
--> $DIR/needless_splitn.rs:15:13
|
LL | let _ = str.splitn(2, '=').nth(0);
- | ^^^^^^^^^^^^^^^^^^ help: try this: `str.split('=')`
+ | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')`
error: unnecessary use of `splitn`
--> $DIR/needless_splitn.rs:18:18
|
LL | let (_, _) = str.splitn(3, '=').next_tuple().unwrap();
- | ^^^^^^^^^^^^^^^^^^ help: try this: `str.split('=')`
+ | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')`
error: unnecessary use of `rsplitn`
--> $DIR/needless_splitn.rs:21:13
|
LL | let _ = str.rsplitn(2, '=').next();
- | ^^^^^^^^^^^^^^^^^^^ help: try this: `str.rsplit('=')`
+ | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')`
error: unnecessary use of `rsplitn`
--> $DIR/needless_splitn.rs:22:13
|
LL | let _ = str.rsplitn(2, '=').nth(0);
- | ^^^^^^^^^^^^^^^^^^^ help: try this: `str.rsplit('=')`
+ | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')`
error: unnecessary use of `rsplitn`
--> $DIR/needless_splitn.rs:25:18
|
LL | let (_, _) = str.rsplitn(3, '=').next_tuple().unwrap();
- | ^^^^^^^^^^^^^^^^^^^ help: try this: `str.rsplit('=')`
+ | ^^^^^^^^^^^^^^^^^^^ help: try: `str.rsplit('=')`
error: unnecessary use of `splitn`
--> $DIR/needless_splitn.rs:27:13
|
LL | let _ = str.splitn(5, '=').next();
- | ^^^^^^^^^^^^^^^^^^ help: try this: `str.split('=')`
+ | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')`
error: unnecessary use of `splitn`
--> $DIR/needless_splitn.rs:28:13
|
LL | let _ = str.splitn(5, '=').nth(3);
- | ^^^^^^^^^^^^^^^^^^ help: try this: `str.split('=')`
+ | ^^^^^^^^^^^^^^^^^^ help: try: `str.split('=')`
error: unnecessary use of `splitn`
--> $DIR/needless_splitn.rs:34:13
|
LL | let _ = s.splitn(2, '=').next()?;
- | ^^^^^^^^^^^^^^^^ help: try this: `s.split('=')`
+ | ^^^^^^^^^^^^^^^^ help: try: `s.split('=')`
error: unnecessary use of `splitn`
--> $DIR/needless_splitn.rs:35:13
|
LL | let _ = s.splitn(2, '=').nth(0)?;
- | ^^^^^^^^^^^^^^^^ help: try this: `s.split('=')`
+ | ^^^^^^^^^^^^^^^^ help: try: `s.split('=')`
error: unnecessary use of `rsplitn`
--> $DIR/needless_splitn.rs:36:13
|
LL | let _ = s.rsplitn(2, '=').next()?;
- | ^^^^^^^^^^^^^^^^^ help: try this: `s.rsplit('=')`
+ | ^^^^^^^^^^^^^^^^^ help: try: `s.rsplit('=')`
error: unnecessary use of `rsplitn`
--> $DIR/needless_splitn.rs:37:13
|
LL | let _ = s.rsplitn(2, '=').nth(0)?;
- | ^^^^^^^^^^^^^^^^^ help: try this: `s.rsplit('=')`
+ | ^^^^^^^^^^^^^^^^^ help: try: `s.rsplit('=')`
error: unnecessary use of `splitn`
--> $DIR/needless_splitn.rs:45:13
|
LL | let _ = "key=value".splitn(2, '=').nth(0).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"key=value".split('=')`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"key=value".split('=')`
error: aborting due to 13 previous errors
diff --git a/src/tools/clippy/tests/ui/numbered_fields.stderr b/src/tools/clippy/tests/ui/numbered_fields.stderr
index 60c0d7898..26f7ad904 100644
--- a/src/tools/clippy/tests/ui/numbered_fields.stderr
+++ b/src/tools/clippy/tests/ui/numbered_fields.stderr
@@ -7,7 +7,7 @@ LL | | 0: 1u32,
LL | | 1: 42,
LL | | 2: 23u8,
LL | | };
- | |_____^ help: try this instead: `TupleStruct(1u32, 42, 23u8)`
+ | |_____^ help: try: `TupleStruct(1u32, 42, 23u8)`
|
= note: `-D clippy::init-numbered-fields` implied by `-D warnings`
@@ -20,7 +20,7 @@ LL | | 0: 1u32,
LL | | 2: 2u8,
LL | | 1: 3u32,
LL | | };
- | |_____^ help: try this instead: `TupleStruct(1u32, 3u32, 2u8)`
+ | |_____^ help: try: `TupleStruct(1u32, 3u32, 2u8)`
error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui/option_env_unwrap.rs b/src/tools/clippy/tests/ui/option_env_unwrap.rs
index 65a1b467f..61dbad939 100644
--- a/src/tools/clippy/tests/ui/option_env_unwrap.rs
+++ b/src/tools/clippy/tests/ui/option_env_unwrap.rs
@@ -9,6 +9,7 @@ use proc_macros::{external, inline_macros};
fn main() {
let _ = option_env!("PATH").unwrap();
let _ = option_env!("PATH").expect("environment variable PATH isn't set");
+ let _ = option_env!("__Y__do_not_use").unwrap(); // This test only works if you don't have a __Y__do_not_use env variable in your environment.
let _ = inline!(option_env!($"PATH").unwrap());
let _ = inline!(option_env!($"PATH").expect($"environment variable PATH isn't set"));
let _ = external!(option_env!($"PATH").unwrap());
diff --git a/src/tools/clippy/tests/ui/option_env_unwrap.stderr b/src/tools/clippy/tests/ui/option_env_unwrap.stderr
index 7bba62686..cfa9dd58a 100644
--- a/src/tools/clippy/tests/ui/option_env_unwrap.stderr
+++ b/src/tools/clippy/tests/ui/option_env_unwrap.stderr
@@ -16,7 +16,15 @@ LL | let _ = option_env!("PATH").expect("environment variable PATH isn't set
= help: consider using the `env!` macro instead
error: this will panic at run-time if the environment variable doesn't exist at compile-time
- --> $DIR/option_env_unwrap.rs:12:21
+ --> $DIR/option_env_unwrap.rs:12:13
+ |
+LL | let _ = option_env!("__Y__do_not_use").unwrap(); // This test only works if you don't have a __Y__do_not_use env variable in your env...
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: consider using the `env!` macro instead
+
+error: this will panic at run-time if the environment variable doesn't exist at compile-time
+ --> $DIR/option_env_unwrap.rs:13:21
|
LL | let _ = inline!(option_env!($"PATH").unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -25,7 +33,7 @@ LL | let _ = inline!(option_env!($"PATH").unwrap());
= note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this will panic at run-time if the environment variable doesn't exist at compile-time
- --> $DIR/option_env_unwrap.rs:13:21
+ --> $DIR/option_env_unwrap.rs:14:21
|
LL | let _ = inline!(option_env!($"PATH").expect($"environment variable PATH isn't set"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -34,7 +42,7 @@ LL | let _ = inline!(option_env!($"PATH").expect($"environment variable PATH
= note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this will panic at run-time if the environment variable doesn't exist at compile-time
- --> $DIR/option_env_unwrap.rs:14:13
+ --> $DIR/option_env_unwrap.rs:15:13
|
LL | let _ = external!(option_env!($"PATH").unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -43,7 +51,7 @@ LL | let _ = external!(option_env!($"PATH").unwrap());
= note: this error originates in the macro `external` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this will panic at run-time if the environment variable doesn't exist at compile-time
- --> $DIR/option_env_unwrap.rs:15:13
+ --> $DIR/option_env_unwrap.rs:16:13
|
LL | let _ = external!(option_env!($"PATH").expect($"environment variable PATH isn't set"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -51,5 +59,5 @@ LL | let _ = external!(option_env!($"PATH").expect($"environment variable PA
= help: consider using the `env!` macro instead
= note: this error originates in the macro `external` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: aborting due to 6 previous errors
+error: aborting due to 7 previous errors
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 8e59e4375..6fee3cce6 100644
--- a/src/tools/clippy/tests/ui/option_if_let_else.fixed
+++ b/src/tools/clippy/tests/ui/option_if_let_else.fixed
@@ -5,7 +5,8 @@
clippy::redundant_closure,
clippy::ref_option_ref,
clippy::equatable_if_let,
- clippy::let_unit_value
+ clippy::let_unit_value,
+ clippy::redundant_locals
)]
fn bad1(string: Option<&str>) -> (bool, &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 e72edf2a8..4b3cf948a 100644
--- a/src/tools/clippy/tests/ui/option_if_let_else.rs
+++ b/src/tools/clippy/tests/ui/option_if_let_else.rs
@@ -5,7 +5,8 @@
clippy::redundant_closure,
clippy::ref_option_ref,
clippy::equatable_if_let,
- clippy::let_unit_value
+ clippy::let_unit_value,
+ clippy::redundant_locals
)]
fn bad1(string: Option<&str>) -> (bool, &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 aa2da2174..350f0f07e 100644
--- a/src/tools/clippy/tests/ui/option_if_let_else.stderr
+++ b/src/tools/clippy/tests/ui/option_if_let_else.stderr
@@ -1,5 +1,5 @@
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:12:5
+ --> $DIR/option_if_let_else.rs:13:5
|
LL | / if let Some(x) = string {
LL | | (true, x)
@@ -11,19 +11,19 @@ LL | | }
= note: `-D clippy::option-if-let-else` implied by `-D warnings`
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:30:13
+ --> $DIR/option_if_let_else.rs:31:13
|
LL | let _ = if let Some(s) = *string { s.len() } else { 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())`
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:31:13
+ --> $DIR/option_if_let_else.rs:32:13
|
LL | let _ = if let Some(s) = &num { s } else { &0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:32:13
+ --> $DIR/option_if_let_else.rs:33:13
|
LL | let _ = if let Some(s) = &mut num {
| _____________^
@@ -43,13 +43,13 @@ LL ~ });
|
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:38:13
+ --> $DIR/option_if_let_else.rs:39:13
|
LL | let _ = if let Some(ref s) = num { s } else { &0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:39:13
+ --> $DIR/option_if_let_else.rs:40:13
|
LL | let _ = if let Some(mut s) = num {
| _____________^
@@ -69,7 +69,7 @@ LL ~ });
|
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:45:13
+ --> $DIR/option_if_let_else.rs:46:13
|
LL | let _ = if let Some(ref mut s) = num {
| _____________^
@@ -89,7 +89,7 @@ LL ~ });
|
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:54:5
+ --> $DIR/option_if_let_else.rs:55:5
|
LL | / if let Some(x) = arg {
LL | | let y = x * x;
@@ -108,7 +108,7 @@ LL + })
|
error: use Option::map_or_else instead of an if let/else
- --> $DIR/option_if_let_else.rs:67:13
+ --> $DIR/option_if_let_else.rs:68:13
|
LL | let _ = if let Some(x) = arg {
| _____________^
@@ -120,7 +120,7 @@ LL | | };
| |_____^ help: try: `arg.map_or_else(|| side_effect(), |x| x)`
error: use Option::map_or_else instead of an if let/else
- --> $DIR/option_if_let_else.rs:76:13
+ --> $DIR/option_if_let_else.rs:77:13
|
LL | let _ = if let Some(x) = arg {
| _____________^
@@ -143,7 +143,7 @@ LL ~ }, |x| x * x * x * x);
|
error: use Option::map_or_else instead of an if let/else
- --> $DIR/option_if_let_else.rs:109:13
+ --> $DIR/option_if_let_else.rs:110:13
|
LL | / if let Some(idx) = s.find('.') {
LL | | vec![s[..idx].to_string(), s[idx..].to_string()]
@@ -153,7 +153,7 @@ LL | | }
| |_____________^ help: try: `s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()])`
error: use Option::map_or_else instead of an if let/else
- --> $DIR/option_if_let_else.rs:120:5
+ --> $DIR/option_if_let_else.rs:121:5
|
LL | / if let Ok(binding) = variable {
LL | | println!("Ok {binding}");
@@ -172,13 +172,13 @@ LL + })
|
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:142:13
+ --> $DIR/option_if_let_else.rs:143:13
|
LL | let _ = if let Some(x) = optional { x + 2 } else { 5 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)`
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:152:13
+ --> $DIR/option_if_let_else.rs:153:13
|
LL | let _ = if let Some(x) = Some(0) {
| _____________^
@@ -200,13 +200,13 @@ LL ~ });
|
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:180:13
+ --> $DIR/option_if_let_else.rs:181:13
|
LL | let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(0).map_or(s.len(), |x| s.len() + x)`
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:184:13
+ --> $DIR/option_if_let_else.rs:185:13
|
LL | let _ = if let Some(x) = Some(0) {
| _____________^
@@ -226,7 +226,7 @@ LL ~ });
|
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:223:13
+ --> $DIR/option_if_let_else.rs:224:13
|
LL | let _ = match s {
| _____________^
@@ -236,7 +236,7 @@ LL | | };
| |_____^ help: try: `s.map_or(1, |string| string.len())`
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:227:13
+ --> $DIR/option_if_let_else.rs:228:13
|
LL | let _ = match Some(10) {
| _____________^
@@ -246,7 +246,7 @@ LL | | };
| |_____^ help: try: `Some(10).map_or(5, |a| a + 1)`
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:233:13
+ --> $DIR/option_if_let_else.rs:234:13
|
LL | let _ = match res {
| _____________^
@@ -256,7 +256,7 @@ LL | | };
| |_____^ help: try: `res.map_or(1, |a| a + 1)`
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:237:13
+ --> $DIR/option_if_let_else.rs:238:13
|
LL | let _ = match res {
| _____________^
@@ -266,13 +266,13 @@ LL | | };
| |_____^ help: try: `res.map_or(1, |a| a + 1)`
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:241:13
+ --> $DIR/option_if_let_else.rs:242:13
|
LL | let _ = if let Ok(a) = res { a + 1 } else { 5 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or(5, |a| a + 1)`
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:258:9
+ --> $DIR/option_if_let_else.rs:259:9
|
LL | / match initial {
LL | | Some(value) => do_something(value),
@@ -281,7 +281,7 @@ LL | | }
| |_________^ help: try: `initial.as_ref().map_or({}, |value| do_something(value))`
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:265:9
+ --> $DIR/option_if_let_else.rs:266:9
|
LL | / match initial {
LL | | Some(value) => do_something2(value),
diff --git a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.stderr b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.stderr
index 0305387b9..5be5f10b0 100644
--- a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.stderr
+++ b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.stderr
@@ -4,7 +4,7 @@ error: called `map(f)` on an `Option` value where `f` is a function that returns
LL | x.field.map(do_nothing);
| ^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(x_field) = x.field { do_nothing(x_field) }`
+ | help: try: `if let Some(x_field) = x.field { do_nothing(x_field) }`
|
= note: `-D clippy::option-map-unit-fn` implied by `-D warnings`
@@ -14,7 +14,7 @@ error: called `map(f)` on an `Option` value where `f` is a function that returns
LL | x.field.map(do_nothing);
| ^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(x_field) = x.field { do_nothing(x_field) }`
+ | help: try: `if let Some(x_field) = x.field { do_nothing(x_field) }`
error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:42:5
@@ -22,7 +22,7 @@ error: called `map(f)` on an `Option` value where `f` is a function that returns
LL | x.field.map(diverge);
| ^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(x_field) = x.field { diverge(x_field) }`
+ | help: try: `if let Some(x_field) = x.field { diverge(x_field) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:48:5
@@ -30,7 +30,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | x.field.map(|value| x.do_option_nothing(value + captured));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(value) = x.field { x.do_option_nothing(value + captured) }`
+ | help: try: `if let Some(value) = x.field { x.do_option_nothing(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:50:5
@@ -38,7 +38,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | x.field.map(|value| { x.do_option_plus_one(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(value) = x.field { x.do_option_plus_one(value + captured); }`
+ | help: try: `if let Some(value) = x.field { x.do_option_plus_one(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:53:5
@@ -46,7 +46,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | x.field.map(|value| do_nothing(value + captured));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
+ | help: try: `if let Some(value) = x.field { do_nothing(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:55:5
@@ -54,7 +54,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | x.field.map(|value| { do_nothing(value + captured) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
+ | help: try: `if let Some(value) = x.field { do_nothing(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:57:5
@@ -62,7 +62,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | x.field.map(|value| { do_nothing(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }`
+ | help: try: `if let Some(value) = x.field { do_nothing(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:59:5
@@ -70,7 +70,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | x.field.map(|value| { { do_nothing(value + captured); } });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }`
+ | help: try: `if let Some(value) = x.field { do_nothing(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:62:5
@@ -78,7 +78,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | x.field.map(|value| diverge(value + captured));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
+ | help: try: `if let Some(value) = x.field { diverge(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:64:5
@@ -86,7 +86,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | x.field.map(|value| { diverge(value + captured) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
+ | help: try: `if let Some(value) = x.field { diverge(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:66:5
@@ -94,7 +94,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | x.field.map(|value| { diverge(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(value) = x.field { diverge(value + captured); }`
+ | help: try: `if let Some(value) = x.field { diverge(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:68:5
@@ -102,7 +102,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | x.field.map(|value| { { diverge(value + captured); } });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(value) = x.field { diverge(value + captured); }`
+ | help: try: `if let Some(value) = x.field { diverge(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:73:5
@@ -110,7 +110,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | x.field.map(|value| { let y = plus_one(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(value) = x.field { let y = plus_one(value + captured); }`
+ | help: try: `if let Some(value) = x.field { let y = plus_one(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:75:5
@@ -118,7 +118,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | x.field.map(|value| { plus_one(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(value) = x.field { plus_one(value + captured); }`
+ | help: try: `if let Some(value) = x.field { plus_one(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:77:5
@@ -126,7 +126,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | x.field.map(|value| { { plus_one(value + captured); } });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(value) = x.field { plus_one(value + captured); }`
+ | help: try: `if let Some(value) = x.field { plus_one(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:80:5
@@ -134,7 +134,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | x.field.map(|ref value| { do_nothing(value + captured) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(ref value) = x.field { do_nothing(value + captured) }`
+ | help: try: `if let Some(ref value) = x.field { do_nothing(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:82:5
@@ -142,7 +142,7 @@ error: called `map(f)` on an `Option` value where `f` is a function that returns
LL | option().map(do_nothing);
| ^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(a) = option() { do_nothing(a) }`
+ | help: try: `if let Some(a) = option() { do_nothing(a) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:84:5
@@ -150,7 +150,7 @@ error: called `map(f)` on an `Option` value where `f` is a closure that returns
LL | option().map(|value| println!("{:?}", value));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Some(value) = option() { println!("{:?}", value) }`
+ | help: try: `if let Some(value) = option() { println!("{:?}", value) }`
error: aborting due to 19 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 703debb7a..581f3ad45 100644
--- a/src/tools/clippy/tests/ui/or_fun_call.fixed
+++ b/src/tools/clippy/tests/ui/or_fun_call.fixed
@@ -9,8 +9,7 @@
clippy::useless_vec
)]
-use std::collections::BTreeMap;
-use std::collections::HashMap;
+use std::collections::{BTreeMap, HashMap};
use std::time::Duration;
/// Checks implementation of the `OR_FUN_CALL` lint.
@@ -191,7 +190,7 @@ mod issue8239 {
acc.push_str(&f);
acc
})
- .unwrap_or_default();
+ .unwrap_or(String::new());
}
fn more_to_max_suggestion_highest_lines_1() {
@@ -204,7 +203,7 @@ mod issue8239 {
acc.push_str(&f);
acc
})
- .unwrap_or_default();
+ .unwrap_or(String::new());
}
fn equal_to_max_suggestion_highest_lines() {
@@ -216,7 +215,7 @@ mod issue8239 {
acc.push_str(&f);
acc
})
- .unwrap_or_default();
+ .unwrap_or(String::new());
}
fn less_than_max_suggestion_highest_lines() {
@@ -227,7 +226,7 @@ mod issue8239 {
acc.push_str(&f);
acc
})
- .unwrap_or_default();
+ .unwrap_or(String::new());
}
}
@@ -258,4 +257,59 @@ mod issue8993 {
}
}
+mod lazy {
+ use super::*;
+
+ fn foo() {
+ struct Foo;
+
+ impl Foo {
+ fn new() -> Foo {
+ Foo
+ }
+ }
+
+ struct FakeDefault;
+ impl FakeDefault {
+ fn default() -> Self {
+ FakeDefault
+ }
+ }
+
+ impl Default for FakeDefault {
+ fn default() -> Self {
+ FakeDefault
+ }
+ }
+
+ let with_new = Some(vec![1]);
+ with_new.unwrap_or_default();
+
+ let with_default_trait = Some(1);
+ with_default_trait.unwrap_or_default();
+
+ let with_default_type = Some(1);
+ with_default_type.unwrap_or_default();
+
+ let real_default = None::<FakeDefault>;
+ real_default.unwrap_or_default();
+
+ let mut map = HashMap::<u64, String>::new();
+ map.entry(42).or_default();
+
+ let mut btree = BTreeMap::<u64, String>::new();
+ btree.entry(42).or_default();
+
+ let stringy = Some(String::new());
+ let _ = stringy.unwrap_or_default();
+
+ // negative tests
+ let self_default = None::<FakeDefault>;
+ self_default.unwrap_or_else(<FakeDefault>::default);
+
+ let without_default = Some(Foo);
+ without_default.unwrap_or_else(Foo::new);
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/or_fun_call.rs b/src/tools/clippy/tests/ui/or_fun_call.rs
index bb86fe0d4..1f3987eb8 100644
--- a/src/tools/clippy/tests/ui/or_fun_call.rs
+++ b/src/tools/clippy/tests/ui/or_fun_call.rs
@@ -9,8 +9,7 @@
clippy::useless_vec
)]
-use std::collections::BTreeMap;
-use std::collections::HashMap;
+use std::collections::{BTreeMap, HashMap};
use std::time::Duration;
/// Checks implementation of the `OR_FUN_CALL` lint.
@@ -258,4 +257,59 @@ mod issue8993 {
}
}
+mod lazy {
+ use super::*;
+
+ fn foo() {
+ struct Foo;
+
+ impl Foo {
+ fn new() -> Foo {
+ Foo
+ }
+ }
+
+ struct FakeDefault;
+ impl FakeDefault {
+ fn default() -> Self {
+ FakeDefault
+ }
+ }
+
+ impl Default for FakeDefault {
+ fn default() -> Self {
+ FakeDefault
+ }
+ }
+
+ let with_new = Some(vec![1]);
+ with_new.unwrap_or_else(Vec::new);
+
+ let with_default_trait = Some(1);
+ with_default_trait.unwrap_or_else(Default::default);
+
+ let with_default_type = Some(1);
+ with_default_type.unwrap_or_else(u64::default);
+
+ let real_default = None::<FakeDefault>;
+ real_default.unwrap_or_else(<FakeDefault as Default>::default);
+
+ let mut map = HashMap::<u64, String>::new();
+ map.entry(42).or_insert_with(String::new);
+
+ let mut btree = BTreeMap::<u64, String>::new();
+ btree.entry(42).or_insert_with(String::new);
+
+ let stringy = Some(String::new());
+ let _ = stringy.unwrap_or_else(String::new);
+
+ // negative tests
+ let self_default = None::<FakeDefault>;
+ self_default.unwrap_or_else(<FakeDefault>::default);
+
+ let without_default = Some(Foo);
+ without_default.unwrap_or_else(Foo::new);
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/or_fun_call.stderr b/src/tools/clippy/tests/ui/or_fun_call.stderr
index 0b5c686be..519f09165 100644
--- a/src/tools/clippy/tests/ui/or_fun_call.stderr
+++ b/src/tools/clippy/tests/ui/or_fun_call.stderr
@@ -1,172 +1,192 @@
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:54:22
+ --> $DIR/or_fun_call.rs:53:22
|
LL | with_constructor.unwrap_or(make());
- | ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(make)`
+ | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(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:57:14
+error: use of `unwrap_or` to construct default value
+ --> $DIR/or_fun_call.rs:56:14
|
LL | with_new.unwrap_or(Vec::new());
- | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
+ |
+ = note: `-D clippy::unwrap-or-default` implied by `-D warnings`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:60:21
+ --> $DIR/or_fun_call.rs:59:21
|
LL | with_const_args.unwrap_or(Vec::with_capacity(12));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| Vec::with_capacity(12))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Vec::with_capacity(12))`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:63:14
+ --> $DIR/or_fun_call.rs:62:14
|
LL | with_err.unwrap_or(make());
- | ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| make())`
+ | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| make())`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:66:19
+ --> $DIR/or_fun_call.rs:65:19
|
LL | with_err_args.unwrap_or(Vec::with_capacity(12));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| Vec::with_capacity(12))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| Vec::with_capacity(12))`
-error: use of `unwrap_or` followed by a call to `default`
- --> $DIR/or_fun_call.rs:69:24
+error: use of `unwrap_or` to construct default value
+ --> $DIR/or_fun_call.rs:68:24
|
LL | with_default_trait.unwrap_or(Default::default());
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
-error: use of `unwrap_or` followed by a call to `default`
- --> $DIR/or_fun_call.rs:72:23
+error: use of `unwrap_or` to construct default value
+ --> $DIR/or_fun_call.rs:71:23
|
LL | with_default_type.unwrap_or(u64::default());
- | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:75:18
+ --> $DIR/or_fun_call.rs:74:18
|
LL | self_default.unwrap_or(<FakeDefault>::default());
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(<FakeDefault>::default)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(<FakeDefault>::default)`
-error: use of `unwrap_or` followed by a call to `default`
- --> $DIR/or_fun_call.rs:78:18
+error: use of `unwrap_or` to construct default value
+ --> $DIR/or_fun_call.rs:77:18
|
LL | real_default.unwrap_or(<FakeDefault as Default>::default());
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
-error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:81:14
+error: use of `unwrap_or` to construct default value
+ --> $DIR/or_fun_call.rs:80:14
|
LL | with_vec.unwrap_or(vec![]);
- | ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
+ | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:84:21
+ --> $DIR/or_fun_call.rs:83:21
|
LL | without_default.unwrap_or(Foo::new());
- | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(Foo::new)`
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(Foo::new)`
-error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:87:19
+error: use of `or_insert` to construct default value
+ --> $DIR/or_fun_call.rs:86:19
|
LL | map.entry(42).or_insert(String::new());
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()`
-error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:90:23
+error: use of `or_insert` to construct default value
+ --> $DIR/or_fun_call.rs:89:23
|
LL | map_vec.entry(42).or_insert(vec![]);
- | ^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
+ | ^^^^^^^^^^^^^^^^^ help: try: `or_default()`
-error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:93:21
+error: use of `or_insert` to construct default value
+ --> $DIR/or_fun_call.rs:92:21
|
LL | btree.entry(42).or_insert(String::new());
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()`
-error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:96:25
+error: use of `or_insert` to construct default value
+ --> $DIR/or_fun_call.rs:95:25
|
LL | btree_vec.entry(42).or_insert(vec![]);
- | ^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
+ | ^^^^^^^^^^^^^^^^^ help: try: `or_default()`
-error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:99:21
+error: use of `unwrap_or` to construct default value
+ --> $DIR/or_fun_call.rs:98:21
|
LL | let _ = stringy.unwrap_or(String::new());
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:107:21
+ --> $DIR/or_fun_call.rs:106:21
|
LL | let _ = Some(1).unwrap_or(map[&1]);
- | ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`
+ | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:109:21
+ --> $DIR/or_fun_call.rs:108:21
|
LL | let _ = Some(1).unwrap_or(map[&1]);
- | ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`
+ | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])`
error: use of `or` followed by a function call
- --> $DIR/or_fun_call.rs:133:35
+ --> $DIR/or_fun_call.rs:132:35
|
LL | let _ = Some("a".to_string()).or(Some("b".to_string()));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_else(|| Some("b".to_string()))`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:172:14
+ --> $DIR/or_fun_call.rs:171:14
|
LL | None.unwrap_or(ptr_to_ref(s));
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| ptr_to_ref(s))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| ptr_to_ref(s))`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:178:14
+ --> $DIR/or_fun_call.rs:177:14
|
LL | None.unwrap_or(unsafe { ptr_to_ref(s) });
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:180:14
+ --> $DIR/or_fun_call.rs:179:14
|
LL | None.unwrap_or( unsafe { ptr_to_ref(s) } );
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })`
-error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:194:14
+error: use of `map_or` followed by a function call
+ --> $DIR/or_fun_call.rs:254:25
|
-LL | .unwrap_or(String::new());
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
+LL | let _ = Some(4).map_or(g(), |v| v);
+ | ^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(g, |v| v)`
-error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:207:14
+error: use of `map_or` followed by a function call
+ --> $DIR/or_fun_call.rs:255:25
|
-LL | .unwrap_or(String::new());
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
+LL | let _ = Some(4).map_or(g(), f);
+ | ^^^^^^^^^^^^^^ help: try: `map_or_else(g, f)`
-error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:219:14
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/or_fun_call.rs:286:18
|
-LL | .unwrap_or(String::new());
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
+LL | with_new.unwrap_or_else(Vec::new);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
-error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:230:10
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/or_fun_call.rs:289:28
|
-LL | .unwrap_or(String::new());
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
+LL | with_default_trait.unwrap_or_else(Default::default);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
-error: use of `map_or` followed by a function call
- --> $DIR/or_fun_call.rs:255:25
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/or_fun_call.rs:292:27
|
-LL | let _ = Some(4).map_or(g(), |v| v);
- | ^^^^^^^^^^^^^^^^^^ help: try this: `map_or_else(g, |v| v)`
+LL | with_default_type.unwrap_or_else(u64::default);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
-error: use of `map_or` followed by a function call
- --> $DIR/or_fun_call.rs:256:25
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/or_fun_call.rs:295:22
|
-LL | let _ = Some(4).map_or(g(), f);
- | ^^^^^^^^^^^^^^ help: try this: `map_or_else(g, f)`
+LL | real_default.unwrap_or_else(<FakeDefault as Default>::default);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
+
+error: use of `or_insert_with` to construct default value
+ --> $DIR/or_fun_call.rs:298:23
+ |
+LL | map.entry(42).or_insert_with(String::new);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()`
+
+error: use of `or_insert_with` to construct default value
+ --> $DIR/or_fun_call.rs:301:25
+ |
+LL | btree.entry(42).or_insert_with(String::new);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()`
+
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/or_fun_call.rs:304:25
+ |
+LL | let _ = stringy.unwrap_or_else(String::new);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
-error: aborting due to 28 previous errors
+error: aborting due to 31 previous errors
diff --git a/src/tools/clippy/tests/ui/or_then_unwrap.stderr b/src/tools/clippy/tests/ui/or_then_unwrap.stderr
index da88154c5..2a1a52407 100644
--- a/src/tools/clippy/tests/ui/or_then_unwrap.stderr
+++ b/src/tools/clippy/tests/ui/or_then_unwrap.stderr
@@ -2,7 +2,7 @@ error: found `.or(Some(…)).unwrap()`
--> $DIR/or_then_unwrap.rs:24:20
|
LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or("fallback")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")`
|
= note: `-D clippy::or-then-unwrap` implied by `-D warnings`
@@ -10,13 +10,13 @@ error: found `.or(Ok(…)).unwrap()`
--> $DIR/or_then_unwrap.rs:27:20
|
LL | let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or("fallback")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")`
error: found `.or(Some(…)).unwrap()`
--> $DIR/or_then_unwrap.rs:31:31
|
LL | let _ = option.map(|v| v).or(Some("fallback")).unwrap().to_string().chars(); // should trigger lint
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or("fallback")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or("fallback")`
error: aborting due to 3 previous errors
diff --git a/src/tools/clippy/tests/ui/panic_in_result_fn.stderr b/src/tools/clippy/tests/ui/panic_in_result_fn.stderr
index 97787bc84..b758fc238 100644
--- a/src/tools/clippy/tests/ui/panic_in_result_fn.stderr
+++ b/src/tools/clippy/tests/ui/panic_in_result_fn.stderr
@@ -1,4 +1,4 @@
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
+error: used `panic!()` or assertion in a function that returns `Result`
--> $DIR/panic_in_result_fn.rs:6:5
|
LL | / fn result_with_panic() -> Result<bool, String> // should emit lint
@@ -7,7 +7,7 @@ LL | | panic!("error");
LL | | }
| |_____^
|
- = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
+ = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
note: return Err() instead of panicking
--> $DIR/panic_in_result_fn.rs:8:9
|
@@ -15,55 +15,7 @@ LL | panic!("error");
| ^^^^^^^^^^^^^^^
= note: `-D clippy::panic-in-result-fn` implied by `-D warnings`
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
- --> $DIR/panic_in_result_fn.rs:11:5
- |
-LL | / fn result_with_unimplemented() -> Result<bool, String> // should emit lint
-LL | | {
-LL | | unimplemented!();
-LL | | }
- | |_____^
- |
- = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
-note: return Err() instead of panicking
- --> $DIR/panic_in_result_fn.rs:13:9
- |
-LL | unimplemented!();
- | ^^^^^^^^^^^^^^^^
-
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
- --> $DIR/panic_in_result_fn.rs:16:5
- |
-LL | / fn result_with_unreachable() -> Result<bool, String> // should emit lint
-LL | | {
-LL | | unreachable!();
-LL | | }
- | |_____^
- |
- = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
-note: return Err() instead of panicking
- --> $DIR/panic_in_result_fn.rs:18:9
- |
-LL | unreachable!();
- | ^^^^^^^^^^^^^^
-
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
- --> $DIR/panic_in_result_fn.rs:21:5
- |
-LL | / fn result_with_todo() -> Result<bool, String> // should emit lint
-LL | | {
-LL | | todo!("Finish this");
-LL | | }
- | |_____^
- |
- = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
-note: return Err() instead of panicking
- --> $DIR/panic_in_result_fn.rs:23:9
- |
-LL | todo!("Finish this");
- | ^^^^^^^^^^^^^^^^^^^^
-
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
+error: used `panic!()` or assertion in a function that returns `Result`
--> $DIR/panic_in_result_fn.rs:52:1
|
LL | / fn function_result_with_panic() -> Result<bool, String> // should emit lint
@@ -72,28 +24,12 @@ LL | | panic!("error");
LL | | }
| |_^
|
- = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
+ = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
note: return Err() instead of panicking
--> $DIR/panic_in_result_fn.rs:54:5
|
LL | panic!("error");
| ^^^^^^^^^^^^^^^
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
- --> $DIR/panic_in_result_fn.rs:67:1
- |
-LL | / fn main() -> Result<(), String> {
-LL | | todo!("finish main method");
-LL | | Ok(())
-LL | | }
- | |_^
- |
- = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
-note: return Err() instead of panicking
- --> $DIR/panic_in_result_fn.rs:68:5
- |
-LL | todo!("finish main method");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 6 previous errors
+error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr b/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr
index eb0aacbb6..0dd213a7e 100644
--- a/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr
+++ b/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr
@@ -1,4 +1,4 @@
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
+error: used `panic!()` or assertion in a function that returns `Result`
--> $DIR/panic_in_result_fn_assertions.rs:7:5
|
LL | / fn result_with_assert_with_message(x: i32) -> Result<bool, String> // should emit lint
@@ -8,7 +8,7 @@ LL | | Ok(true)
LL | | }
| |_____^
|
- = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
+ = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
note: return Err() instead of panicking
--> $DIR/panic_in_result_fn_assertions.rs:9:9
|
@@ -16,7 +16,7 @@ LL | assert!(x == 5, "wrong argument");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `-D clippy::panic-in-result-fn` implied by `-D warnings`
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
+error: used `panic!()` or assertion in a function that returns `Result`
--> $DIR/panic_in_result_fn_assertions.rs:13:5
|
LL | / fn result_with_assert_eq(x: i32) -> Result<bool, String> // should emit lint
@@ -26,14 +26,14 @@ LL | | Ok(true)
LL | | }
| |_____^
|
- = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
+ = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
note: return Err() instead of panicking
--> $DIR/panic_in_result_fn_assertions.rs:15:9
|
LL | assert_eq!(x, 5);
| ^^^^^^^^^^^^^^^^
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
+error: used `panic!()` or assertion in a function that returns `Result`
--> $DIR/panic_in_result_fn_assertions.rs:19:5
|
LL | / fn result_with_assert_ne(x: i32) -> Result<bool, String> // should emit lint
@@ -43,7 +43,7 @@ LL | | Ok(true)
LL | | }
| |_____^
|
- = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
+ = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
note: return Err() instead of panicking
--> $DIR/panic_in_result_fn_assertions.rs:21:9
|
diff --git a/src/tools/clippy/tests/ui/print_literal.stderr b/src/tools/clippy/tests/ui/print_literal.stderr
index 6404dacda..71c8d188f 100644
--- a/src/tools/clippy/tests/ui/print_literal.stderr
+++ b/src/tools/clippy/tests/ui/print_literal.stderr
@@ -5,7 +5,7 @@ LL | print!("Hello {}", "world");
| ^^^^^^^
|
= note: `-D clippy::print-literal` implied by `-D warnings`
-help: try this
+help: try
|
LL - print!("Hello {}", "world");
LL + print!("Hello world");
@@ -17,7 +17,7 @@ error: literal with an empty format string
LL | println!("Hello {} {}", world, "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - println!("Hello {} {}", world, "world");
LL + println!("Hello {} world", world);
@@ -29,7 +29,7 @@ error: literal with an empty format string
LL | println!("Hello {}", "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - println!("Hello {}", "world");
LL + println!("Hello world");
@@ -41,7 +41,7 @@ error: literal with an empty format string
LL | println!("{} {:.4}", "a literal", 5);
| ^^^^^^^^^^^
|
-help: try this
+help: try
|
LL - println!("{} {:.4}", "a literal", 5);
LL + println!("a literal {:.4}", 5);
@@ -53,7 +53,7 @@ error: literal with an empty format string
LL | println!("{0} {1}", "hello", "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - println!("{0} {1}", "hello", "world");
LL + println!("hello {1}", "world");
@@ -65,7 +65,7 @@ error: literal with an empty format string
LL | println!("{0} {1}", "hello", "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - println!("{0} {1}", "hello", "world");
LL + println!("{0} world", "hello");
@@ -77,7 +77,7 @@ error: literal with an empty format string
LL | println!("{1} {0}", "hello", "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - println!("{1} {0}", "hello", "world");
LL + println!("world {0}", "hello");
@@ -89,7 +89,7 @@ error: literal with an empty format string
LL | println!("{1} {0}", "hello", "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - println!("{1} {0}", "hello", "world");
LL + println!("{1} hello", "world");
@@ -101,7 +101,7 @@ error: literal with an empty format string
LL | println!("{foo} {bar}", foo = "hello", bar = "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - println!("{foo} {bar}", foo = "hello", bar = "world");
LL + println!("hello {bar}", bar = "world");
@@ -113,7 +113,7 @@ error: literal with an empty format string
LL | println!("{foo} {bar}", foo = "hello", bar = "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - println!("{foo} {bar}", foo = "hello", bar = "world");
LL + println!("{foo} world", foo = "hello");
@@ -125,7 +125,7 @@ error: literal with an empty format string
LL | println!("{bar} {foo}", foo = "hello", bar = "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - println!("{bar} {foo}", foo = "hello", bar = "world");
LL + println!("world {foo}", foo = "hello");
@@ -137,7 +137,7 @@ error: literal with an empty format string
LL | println!("{bar} {foo}", foo = "hello", bar = "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - println!("{bar} {foo}", foo = "hello", bar = "world");
LL + println!("{bar} hello", bar = "world");
diff --git a/src/tools/clippy/tests/ui/ptr_arg.rs b/src/tools/clippy/tests/ui/ptr_arg.rs
index 709f74ee6..08075c382 100644
--- a/src/tools/clippy/tests/ui/ptr_arg.rs
+++ b/src/tools/clippy/tests/ui/ptr_arg.rs
@@ -3,7 +3,8 @@
unused,
clippy::many_single_char_names,
clippy::needless_lifetimes,
- clippy::redundant_clone
+ clippy::redundant_clone,
+ clippy::needless_pass_by_ref_mut
)]
#![warn(clippy::ptr_arg)]
@@ -266,3 +267,16 @@ mod issue_9218 {
todo!()
}
}
+
+mod issue_11181 {
+ extern "C" fn allowed(_v: &Vec<u32>) {}
+
+ struct S;
+ impl S {
+ extern "C" fn allowed(_v: &Vec<u32>) {}
+ }
+
+ trait T {
+ extern "C" fn allowed(_v: &Vec<u32>) {}
+ }
+}
diff --git a/src/tools/clippy/tests/ui/ptr_arg.stderr b/src/tools/clippy/tests/ui/ptr_arg.stderr
index d663b070b..0e9dd760f 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:13:14
+ --> $DIR/ptr_arg.rs:14: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:17:18
+ --> $DIR/ptr_arg.rs:18: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:21:14
+ --> $DIR/ptr_arg.rs:22: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:25:18
+ --> $DIR/ptr_arg.rs:26: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:29:15
+ --> $DIR/ptr_arg.rs:30: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:33:19
+ --> $DIR/ptr_arg.rs:34: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:41:18
+ --> $DIR/ptr_arg.rs:42: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:54:14
+ --> $DIR/ptr_arg.rs:55: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:63:18
+ --> $DIR/ptr_arg.rs:64: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:71:19
+ --> $DIR/ptr_arg.rs:72: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:79:44
+ --> $DIR/ptr_arg.rs:80: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:93:25
+ --> $DIR/ptr_arg.rs:94: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:122:66
+ --> $DIR/ptr_arg.rs:123: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:151:21
+ --> $DIR/ptr_arg.rs:152: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:156:23
+ --> $DIR/ptr_arg.rs:157: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:161:21
+ --> $DIR/ptr_arg.rs:162:21
|
LL | fn foo_str(str: &PathBuf) {
| ^^^^^^^^
@@ -157,43 +157,43 @@ 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:167:29
+ --> $DIR/ptr_arg.rs:168: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:229:17
+ --> $DIR/ptr_arg.rs:230: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:229:35
+ --> $DIR/ptr_arg.rs:230: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:229:51
+ --> $DIR/ptr_arg.rs:230:51
|
LL | fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
| ^^^^^^^^^^^^ help: change this to: `&mut Path`
error: using a reference to `Cow` is not recommended
- --> $DIR/ptr_arg.rs:252:39
+ --> $DIR/ptr_arg.rs:253: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
+ --> $DIR/ptr_arg.rs:258: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
+ --> $DIR/ptr_arg.rs:261:40
|
LL | fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str {
| ^^^^^^^^^^^^^^^^ help: change this to: `&str`
diff --git a/src/tools/clippy/tests/ui/ptr_as_ptr.fixed b/src/tools/clippy/tests/ui/ptr_as_ptr.fixed
index 26a64c861..84babb974 100644
--- a/src/tools/clippy/tests/ui/ptr_as_ptr.fixed
+++ b/src/tools/clippy/tests/ui/ptr_as_ptr.fixed
@@ -3,8 +3,22 @@
#![warn(clippy::ptr_as_ptr)]
+#[macro_use]
extern crate proc_macros;
-use proc_macros::{external, inline_macros};
+
+mod issue_11278_a {
+ #[derive(Debug)]
+ pub struct T<D: std::fmt::Debug + ?Sized> {
+ pub p: D,
+ }
+}
+
+mod issue_11278_b {
+ pub fn f(o: &mut super::issue_11278_a::T<dyn std::fmt::Debug>) -> super::issue_11278_a::T<String> {
+ // Retain `super`
+ *unsafe { Box::from_raw(Box::into_raw(Box::new(o)).cast::<super::issue_11278_a::T<String>>()) }
+ }
+}
#[inline_macros]
fn main() {
diff --git a/src/tools/clippy/tests/ui/ptr_as_ptr.rs b/src/tools/clippy/tests/ui/ptr_as_ptr.rs
index ea40d4947..34fd76428 100644
--- a/src/tools/clippy/tests/ui/ptr_as_ptr.rs
+++ b/src/tools/clippy/tests/ui/ptr_as_ptr.rs
@@ -3,8 +3,22 @@
#![warn(clippy::ptr_as_ptr)]
+#[macro_use]
extern crate proc_macros;
-use proc_macros::{external, inline_macros};
+
+mod issue_11278_a {
+ #[derive(Debug)]
+ pub struct T<D: std::fmt::Debug + ?Sized> {
+ pub p: D,
+ }
+}
+
+mod issue_11278_b {
+ pub fn f(o: &mut super::issue_11278_a::T<dyn std::fmt::Debug>) -> super::issue_11278_a::T<String> {
+ // Retain `super`
+ *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::issue_11278_a::T<String>) }
+ }
+}
#[inline_macros]
fn main() {
diff --git a/src/tools/clippy/tests/ui/ptr_as_ptr.stderr b/src/tools/clippy/tests/ui/ptr_as_ptr.stderr
index 78d733994..e64f33515 100644
--- a/src/tools/clippy/tests/ui/ptr_as_ptr.stderr
+++ b/src/tools/clippy/tests/ui/ptr_as_ptr.stderr
@@ -1,37 +1,43 @@
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:14:13
+ --> $DIR/ptr_as_ptr.rs:19:33
|
-LL | let _ = ptr as *const i32;
- | ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::<i32>()`
+LL | *unsafe { Box::from_raw(Box::into_raw(Box::new(o)) as *mut super::issue_11278_a::T<String>) }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `Box::into_raw(Box::new(o)).cast::<super::issue_11278_a::T<String>>()`
|
= note: `-D clippy::ptr-as-ptr` implied by `-D warnings`
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:15:13
+ --> $DIR/ptr_as_ptr.rs:28:13
+ |
+LL | let _ = ptr as *const i32;
+ | ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::<i32>()`
+
+error: `as` casting between raw pointers without changing its mutability
+ --> $DIR/ptr_as_ptr.rs:29:13
|
LL | let _ = mut_ptr as *mut i32;
| ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::<i32>()`
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:20:17
+ --> $DIR/ptr_as_ptr.rs:34:17
|
LL | let _ = *ptr_ptr as *const i32;
| ^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `(*ptr_ptr).cast::<i32>()`
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:33:25
+ --> $DIR/ptr_as_ptr.rs:47:25
|
LL | let _: *const i32 = ptr as *const _;
| ^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast()`
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:34:23
+ --> $DIR/ptr_as_ptr.rs:48:23
|
LL | let _: *mut i32 = mut_ptr as _;
| ^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast()`
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:37:21
+ --> $DIR/ptr_as_ptr.rs:51:21
|
LL | let _ = inline!($ptr as *const i32);
| ^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `$ptr.cast::<i32>()`
@@ -39,16 +45,16 @@ LL | let _ = inline!($ptr as *const i32);
= note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info)
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:58:13
+ --> $DIR/ptr_as_ptr.rs:72:13
|
LL | let _ = ptr as *const i32;
| ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::<i32>()`
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:59:13
+ --> $DIR/ptr_as_ptr.rs:73:13
|
LL | let _ = mut_ptr as *mut i32;
| ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::<i32>()`
-error: aborting due to 8 previous errors
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/question_mark.fixed b/src/tools/clippy/tests/ui/question_mark.fixed
index 2d8920ccc..20b9e42a7 100644
--- a/src/tools/clippy/tests/ui/question_mark.fixed
+++ b/src/tools/clippy/tests/ui/question_mark.fixed
@@ -138,6 +138,23 @@ fn result_func(x: Result<i32, i32>) -> Result<i32, i32> {
// no warning
let _ = if let Err(e) = x { Err(e) } else { Ok(0) };
+ // issue #11283
+ // no warning
+ #[warn(clippy::question_mark_used)]
+ {
+ if let Err(err) = Ok(()) {
+ return Err(err);
+ }
+
+ if Err::<i32, _>(0).is_err() {
+ return Err(0);
+ } else {
+ return Ok(0);
+ }
+
+ unreachable!()
+ }
+
Ok(y)
}
diff --git a/src/tools/clippy/tests/ui/question_mark.rs b/src/tools/clippy/tests/ui/question_mark.rs
index 69451c17e..8bdafd46e 100644
--- a/src/tools/clippy/tests/ui/question_mark.rs
+++ b/src/tools/clippy/tests/ui/question_mark.rs
@@ -170,6 +170,23 @@ fn result_func(x: Result<i32, i32>) -> Result<i32, i32> {
// no warning
let _ = if let Err(e) = x { Err(e) } else { Ok(0) };
+ // issue #11283
+ // no warning
+ #[warn(clippy::question_mark_used)]
+ {
+ if let Err(err) = Ok(()) {
+ return Err(err);
+ }
+
+ if Err::<i32, _>(0).is_err() {
+ return Err(0);
+ } else {
+ return Ok(0);
+ }
+
+ unreachable!()
+ }
+
Ok(y)
}
diff --git a/src/tools/clippy/tests/ui/question_mark.stderr b/src/tools/clippy/tests/ui/question_mark.stderr
index 2cfd75863..62489c8c8 100644
--- a/src/tools/clippy/tests/ui/question_mark.stderr
+++ b/src/tools/clippy/tests/ui/question_mark.stderr
@@ -115,7 +115,7 @@ LL | | }
| |_____^ help: replace it with: `x?;`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:197:5
+ --> $DIR/question_mark.rs:214:5
|
LL | / if let Err(err) = func_returning_result() {
LL | | return Err(err);
@@ -123,7 +123,7 @@ LL | | }
| |_____^ help: replace it with: `func_returning_result()?;`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:204:5
+ --> $DIR/question_mark.rs:221:5
|
LL | / if let Err(err) = func_returning_result() {
LL | | return Err(err);
@@ -131,7 +131,7 @@ LL | | }
| |_____^ help: replace it with: `func_returning_result()?;`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:281:13
+ --> $DIR/question_mark.rs:298:13
|
LL | / if a.is_none() {
LL | | return None;
diff --git a/src/tools/clippy/tests/ui/range_contains.fixed b/src/tools/clippy/tests/ui/range_contains.fixed
index 0a92ee7c8..47c524811 100644
--- a/src/tools/clippy/tests/ui/range_contains.fixed
+++ b/src/tools/clippy/tests/ui/range_contains.fixed
@@ -5,6 +5,8 @@
#![allow(clippy::no_effect)]
#![allow(clippy::short_circuit_statement)]
#![allow(clippy::unnecessary_operation)]
+#![allow(clippy::impossible_comparisons)]
+#![allow(clippy::redundant_comparisons)]
fn main() {
let x = 9_i32;
diff --git a/src/tools/clippy/tests/ui/range_contains.rs b/src/tools/clippy/tests/ui/range_contains.rs
index 7a83be609..a35315a64 100644
--- a/src/tools/clippy/tests/ui/range_contains.rs
+++ b/src/tools/clippy/tests/ui/range_contains.rs
@@ -5,6 +5,8 @@
#![allow(clippy::no_effect)]
#![allow(clippy::short_circuit_statement)]
#![allow(clippy::unnecessary_operation)]
+#![allow(clippy::impossible_comparisons)]
+#![allow(clippy::redundant_comparisons)]
fn main() {
let x = 9_i32;
diff --git a/src/tools/clippy/tests/ui/range_contains.stderr b/src/tools/clippy/tests/ui/range_contains.stderr
index ea34023a4..1265db695 100644
--- a/src/tools/clippy/tests/ui/range_contains.stderr
+++ b/src/tools/clippy/tests/ui/range_contains.stderr
@@ -1,5 +1,5 @@
error: manual `Range::contains` implementation
- --> $DIR/range_contains.rs:13:5
+ --> $DIR/range_contains.rs:15:5
|
LL | x >= 8 && x < 12;
| ^^^^^^^^^^^^^^^^ help: use: `(8..12).contains(&x)`
@@ -7,121 +7,121 @@ LL | x >= 8 && x < 12;
= note: `-D clippy::manual-range-contains` implied by `-D warnings`
error: manual `Range::contains` implementation
- --> $DIR/range_contains.rs:14:5
+ --> $DIR/range_contains.rs:16:5
|
LL | x < 42 && x >= 21;
| ^^^^^^^^^^^^^^^^^ help: use: `(21..42).contains(&x)`
error: manual `Range::contains` implementation
- --> $DIR/range_contains.rs:15:5
+ --> $DIR/range_contains.rs:17:5
|
LL | 100 > x && 1 <= x;
| ^^^^^^^^^^^^^^^^^ help: use: `(1..100).contains(&x)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:18:5
+ --> $DIR/range_contains.rs:20:5
|
LL | x >= 9 && x <= 99;
| ^^^^^^^^^^^^^^^^^ help: use: `(9..=99).contains(&x)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:19:5
+ --> $DIR/range_contains.rs:21:5
|
LL | x <= 33 && x >= 1;
| ^^^^^^^^^^^^^^^^^ help: use: `(1..=33).contains(&x)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:20:5
+ --> $DIR/range_contains.rs:22:5
|
LL | 999 >= x && 1 <= x;
| ^^^^^^^^^^^^^^^^^^ help: use: `(1..=999).contains(&x)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:23:5
+ --> $DIR/range_contains.rs:25:5
|
LL | x < 8 || x >= 12;
| ^^^^^^^^^^^^^^^^ help: use: `!(8..12).contains(&x)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:24:5
+ --> $DIR/range_contains.rs:26:5
|
LL | x >= 42 || x < 21;
| ^^^^^^^^^^^^^^^^^ help: use: `!(21..42).contains(&x)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:25:5
+ --> $DIR/range_contains.rs:27:5
|
LL | 100 <= x || 1 > x;
| ^^^^^^^^^^^^^^^^^ help: use: `!(1..100).contains(&x)`
error: manual `!RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:28:5
+ --> $DIR/range_contains.rs:30:5
|
LL | x < 9 || x > 99;
| ^^^^^^^^^^^^^^^ help: use: `!(9..=99).contains(&x)`
error: manual `!RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:29:5
+ --> $DIR/range_contains.rs:31:5
|
LL | x > 33 || x < 1;
| ^^^^^^^^^^^^^^^ help: use: `!(1..=33).contains(&x)`
error: manual `!RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:30:5
+ --> $DIR/range_contains.rs:32:5
|
LL | 999 < x || 1 > x;
| ^^^^^^^^^^^^^^^^ help: use: `!(1..=999).contains(&x)`
error: manual `Range::contains` implementation
- --> $DIR/range_contains.rs:45:5
+ --> $DIR/range_contains.rs:47:5
|
LL | y >= 0. && y < 1.;
| ^^^^^^^^^^^^^^^^^ help: use: `(0. ..1.).contains(&y)`
error: manual `!RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:46:5
+ --> $DIR/range_contains.rs:48:5
|
LL | y < 0. || y > 1.;
| ^^^^^^^^^^^^^^^^ help: use: `!(0. ..=1.).contains(&y)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:49:5
+ --> $DIR/range_contains.rs:51:5
|
LL | x >= -10 && x <= 10;
| ^^^^^^^^^^^^^^^^^^^ help: use: `(-10..=10).contains(&x)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:51:5
+ --> $DIR/range_contains.rs:53:5
|
LL | y >= -3. && y <= 3.;
| ^^^^^^^^^^^^^^^^^^^ help: use: `(-3. ..=3.).contains(&y)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:56:30
+ --> $DIR/range_contains.rs:58:30
|
LL | (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10);
| ^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=10).contains(&z)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:56:5
+ --> $DIR/range_contains.rs:58:5
|
LL | (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10);
| ^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=10).contains(&x)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:57:29
+ --> $DIR/range_contains.rs:59:29
|
LL | (x < 0) || (x >= 10) || (z < 0) || (z >= 10);
| ^^^^^^^^^^^^^^^^^^^^ help: use: `!(0..10).contains(&z)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:57:5
+ --> $DIR/range_contains.rs:59:5
|
LL | (x < 0) || (x >= 10) || (z < 0) || (z >= 10);
| ^^^^^^^^^^^^^^^^^^^^ help: use: `!(0..10).contains(&x)`
error: manual `Range::contains` implementation
- --> $DIR/range_contains.rs:76:5
+ --> $DIR/range_contains.rs:78:5
|
LL | x >= 8 && x < 35;
| ^^^^^^^^^^^^^^^^ help: use: `(8..35).contains(&x)`
diff --git a/src/tools/clippy/tests/ui/read_line_without_trim.fixed b/src/tools/clippy/tests/ui/read_line_without_trim.fixed
new file mode 100644
index 000000000..cb6aab84e
--- /dev/null
+++ b/src/tools/clippy/tests/ui/read_line_without_trim.fixed
@@ -0,0 +1,36 @@
+//@run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::read_line_without_trim)]
+
+fn main() {
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ input.pop();
+ let _x: i32 = input.parse().unwrap(); // don't trigger here, newline character is popped
+
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ let _x: i32 = input.trim_end().parse().unwrap();
+
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ let _x = input.trim_end().parse::<i32>().unwrap();
+
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ let _x = input.trim_end().parse::<u32>().unwrap();
+
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ let _x = input.trim_end().parse::<f32>().unwrap();
+
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ let _x = input.trim_end().parse::<bool>().unwrap();
+
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ // this is actually ok, so don't lint here
+ let _x = input.parse::<String>().unwrap();
+}
diff --git a/src/tools/clippy/tests/ui/read_line_without_trim.rs b/src/tools/clippy/tests/ui/read_line_without_trim.rs
new file mode 100644
index 000000000..bdc409a70
--- /dev/null
+++ b/src/tools/clippy/tests/ui/read_line_without_trim.rs
@@ -0,0 +1,36 @@
+//@run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::read_line_without_trim)]
+
+fn main() {
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ input.pop();
+ let _x: i32 = input.parse().unwrap(); // don't trigger here, newline character is popped
+
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ let _x: i32 = input.parse().unwrap();
+
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ let _x = input.parse::<i32>().unwrap();
+
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ let _x = input.parse::<u32>().unwrap();
+
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ let _x = input.parse::<f32>().unwrap();
+
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ let _x = input.parse::<bool>().unwrap();
+
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ // this is actually ok, so don't lint here
+ let _x = input.parse::<String>().unwrap();
+}
diff --git a/src/tools/clippy/tests/ui/read_line_without_trim.stderr b/src/tools/clippy/tests/ui/read_line_without_trim.stderr
new file mode 100644
index 000000000..f3d7b6042
--- /dev/null
+++ b/src/tools/clippy/tests/ui/read_line_without_trim.stderr
@@ -0,0 +1,73 @@
+error: calling `.parse()` without trimming the trailing newline character
+ --> $DIR/read_line_without_trim.rs:14:25
+ |
+LL | let _x: i32 = input.parse().unwrap();
+ | ----- ^^^^^^^
+ | |
+ | help: try: `input.trim_end()`
+ |
+note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause `.parse()` to fail
+ --> $DIR/read_line_without_trim.rs:13:5
+ |
+LL | std::io::stdin().read_line(&mut input).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: `-D clippy::read-line-without-trim` implied by `-D warnings`
+
+error: calling `.parse()` without trimming the trailing newline character
+ --> $DIR/read_line_without_trim.rs:18:20
+ |
+LL | let _x = input.parse::<i32>().unwrap();
+ | ----- ^^^^^^^^^^^^^^
+ | |
+ | help: try: `input.trim_end()`
+ |
+note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause `.parse()` to fail
+ --> $DIR/read_line_without_trim.rs:17:5
+ |
+LL | std::io::stdin().read_line(&mut input).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: calling `.parse()` without trimming the trailing newline character
+ --> $DIR/read_line_without_trim.rs:22:20
+ |
+LL | let _x = input.parse::<u32>().unwrap();
+ | ----- ^^^^^^^^^^^^^^
+ | |
+ | help: try: `input.trim_end()`
+ |
+note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause `.parse()` to fail
+ --> $DIR/read_line_without_trim.rs:21:5
+ |
+LL | std::io::stdin().read_line(&mut input).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: calling `.parse()` without trimming the trailing newline character
+ --> $DIR/read_line_without_trim.rs:26:20
+ |
+LL | let _x = input.parse::<f32>().unwrap();
+ | ----- ^^^^^^^^^^^^^^
+ | |
+ | help: try: `input.trim_end()`
+ |
+note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause `.parse()` to fail
+ --> $DIR/read_line_without_trim.rs:25:5
+ |
+LL | std::io::stdin().read_line(&mut input).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: calling `.parse()` without trimming the trailing newline character
+ --> $DIR/read_line_without_trim.rs:30:20
+ |
+LL | let _x = input.parse::<bool>().unwrap();
+ | ----- ^^^^^^^^^^^^^^^
+ | |
+ | help: try: `input.trim_end()`
+ |
+note: call to `.read_line()` here, which leaves a trailing newline character in the buffer, which in turn will cause `.parse()` to fail
+ --> $DIR/read_line_without_trim.rs:29:5
+ |
+LL | std::io::stdin().read_line(&mut input).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 5 previous errors
+
diff --git a/src/tools/clippy/tests/ui/read_zero_byte_vec.rs b/src/tools/clippy/tests/ui/read_zero_byte_vec.rs
index 30807e0f8..ff2ad8644 100644
--- a/src/tools/clippy/tests/ui/read_zero_byte_vec.rs
+++ b/src/tools/clippy/tests/ui/read_zero_byte_vec.rs
@@ -1,5 +1,9 @@
#![warn(clippy::read_zero_byte_vec)]
-#![allow(clippy::unused_io_amount)]
+#![allow(
+ clippy::unused_io_amount,
+ clippy::needless_pass_by_ref_mut,
+ clippy::slow_vector_initialization
+)]
use std::fs::File;
use std::io;
use std::io::prelude::*;
diff --git a/src/tools/clippy/tests/ui/read_zero_byte_vec.stderr b/src/tools/clippy/tests/ui/read_zero_byte_vec.stderr
index 08ba9753d..4c7f605f4 100644
--- a/src/tools/clippy/tests/ui/read_zero_byte_vec.stderr
+++ b/src/tools/clippy/tests/ui/read_zero_byte_vec.stderr
@@ -1,5 +1,5 @@
error: reading zero byte data to `Vec`
- --> $DIR/read_zero_byte_vec.rs:17:5
+ --> $DIR/read_zero_byte_vec.rs:21:5
|
LL | f.read_exact(&mut data).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `data.resize(20, 0); f.read_exact(&mut data).unwrap();`
@@ -7,55 +7,55 @@ LL | f.read_exact(&mut data).unwrap();
= note: `-D clippy::read-zero-byte-vec` implied by `-D warnings`
error: reading zero byte data to `Vec`
- --> $DIR/read_zero_byte_vec.rs:21:5
+ --> $DIR/read_zero_byte_vec.rs:25:5
|
LL | f.read_exact(&mut data2)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `data2.resize(cap, 0); f.read_exact(&mut data2)?;`
error: reading zero byte data to `Vec`
- --> $DIR/read_zero_byte_vec.rs:25:5
+ --> $DIR/read_zero_byte_vec.rs:29:5
|
LL | f.read_exact(&mut data3)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: reading zero byte data to `Vec`
- --> $DIR/read_zero_byte_vec.rs:29:5
+ --> $DIR/read_zero_byte_vec.rs:33:5
|
LL | let _ = f.read(&mut data4)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: reading zero byte data to `Vec`
- --> $DIR/read_zero_byte_vec.rs:34:9
+ --> $DIR/read_zero_byte_vec.rs:38:9
|
LL | f.read(&mut data5)
| ^^^^^^^^^^^^^^^^^^
error: reading zero byte data to `Vec`
- --> $DIR/read_zero_byte_vec.rs:40:9
+ --> $DIR/read_zero_byte_vec.rs:44:9
|
LL | f.read(&mut data6)
| ^^^^^^^^^^^^^^^^^^
error: reading zero byte data to `Vec`
- --> $DIR/read_zero_byte_vec.rs:70:5
+ --> $DIR/read_zero_byte_vec.rs:74:5
|
LL | r.read(&mut data).await.unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: reading zero byte data to `Vec`
- --> $DIR/read_zero_byte_vec.rs:74:5
+ --> $DIR/read_zero_byte_vec.rs:78:5
|
LL | r.read_exact(&mut data2).await.unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: reading zero byte data to `Vec`
- --> $DIR/read_zero_byte_vec.rs:80:5
+ --> $DIR/read_zero_byte_vec.rs:84:5
|
LL | r.read(&mut data).await.unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: reading zero byte data to `Vec`
- --> $DIR/read_zero_byte_vec.rs:84:5
+ --> $DIR/read_zero_byte_vec.rs:88:5
|
LL | r.read_exact(&mut data2).await.unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/readonly_write_lock.rs b/src/tools/clippy/tests/ui/readonly_write_lock.rs
new file mode 100644
index 000000000..656b45787
--- /dev/null
+++ b/src/tools/clippy/tests/ui/readonly_write_lock.rs
@@ -0,0 +1,42 @@
+#![warn(clippy::readonly_write_lock)]
+
+use std::sync::RwLock;
+
+fn mutate_i32(x: &mut i32) {
+ *x += 1;
+}
+
+fn accept_i32(_: i32) {}
+
+fn main() {
+ let lock = RwLock::new(42);
+ let lock2 = RwLock::new(1234);
+
+ {
+ let writer = lock.write().unwrap();
+ dbg!(&writer);
+ }
+
+ {
+ let writer = lock.write().unwrap();
+ accept_i32(*writer);
+ }
+
+ {
+ let mut writer = lock.write().unwrap();
+ mutate_i32(&mut writer);
+ dbg!(&writer);
+ }
+
+ {
+ let mut writer = lock.write().unwrap();
+ *writer += 1;
+ }
+
+ {
+ let mut writer1 = lock.write().unwrap();
+ let mut writer2 = lock2.write().unwrap();
+ *writer2 += 1;
+ *writer1 = *writer2;
+ }
+}
diff --git a/src/tools/clippy/tests/ui/readonly_write_lock.stderr b/src/tools/clippy/tests/ui/readonly_write_lock.stderr
new file mode 100644
index 000000000..e3d8fce7b
--- /dev/null
+++ b/src/tools/clippy/tests/ui/readonly_write_lock.stderr
@@ -0,0 +1,16 @@
+error: this write lock is used only for reading
+ --> $DIR/readonly_write_lock.rs:16:22
+ |
+LL | let writer = lock.write().unwrap();
+ | ^^^^^^^^^^^^ help: consider using a read lock instead: `lock.read()`
+ |
+ = note: `-D clippy::readonly-write-lock` implied by `-D warnings`
+
+error: this write lock is used only for reading
+ --> $DIR/readonly_write_lock.rs:21:22
+ |
+LL | let writer = lock.write().unwrap();
+ | ^^^^^^^^^^^^ help: consider using a read lock instead: `lock.read()`
+
+error: aborting due to 2 previous errors
+
diff --git a/src/tools/clippy/tests/ui/redundant_allocation.rs b/src/tools/clippy/tests/ui/redundant_allocation.rs
index 574d34aed..9eb58a3e5 100644
--- a/src/tools/clippy/tests/ui/redundant_allocation.rs
+++ b/src/tools/clippy/tests/ui/redundant_allocation.rs
@@ -8,8 +8,7 @@ pub struct SubT<T> {
}
mod outer_box {
- use crate::MyStruct;
- use crate::SubT;
+ use crate::{MyStruct, SubT};
use std::boxed::Box;
use std::rc::Rc;
use std::sync::Arc;
@@ -28,8 +27,7 @@ mod outer_box {
}
mod outer_rc {
- use crate::MyStruct;
- use crate::SubT;
+ use crate::{MyStruct, SubT};
use std::boxed::Box;
use std::rc::Rc;
use std::sync::Arc;
@@ -48,8 +46,7 @@ mod outer_rc {
}
mod outer_arc {
- use crate::MyStruct;
- use crate::SubT;
+ use crate::{MyStruct, SubT};
use std::boxed::Box;
use std::rc::Rc;
use std::sync::Arc;
diff --git a/src/tools/clippy/tests/ui/redundant_allocation.stderr b/src/tools/clippy/tests/ui/redundant_allocation.stderr
index e0826fefa..a9a1eed70 100644
--- a/src/tools/clippy/tests/ui/redundant_allocation.stderr
+++ b/src/tools/clippy/tests/ui/redundant_allocation.stderr
@@ -1,5 +1,5 @@
error: usage of `Box<Rc<T>>`
- --> $DIR/redundant_allocation.rs:17:30
+ --> $DIR/redundant_allocation.rs:16:30
|
LL | pub fn box_test6<T>(foo: Box<Rc<T>>) {}
| ^^^^^^^^^^
@@ -9,7 +9,7 @@ LL | pub fn box_test6<T>(foo: Box<Rc<T>>) {}
= note: `-D clippy::redundant-allocation` implied by `-D warnings`
error: usage of `Box<Arc<T>>`
- --> $DIR/redundant_allocation.rs:19:30
+ --> $DIR/redundant_allocation.rs:18:30
|
LL | pub fn box_test7<T>(foo: Box<Arc<T>>) {}
| ^^^^^^^^^^^
@@ -18,7 +18,7 @@ LL | pub fn box_test7<T>(foo: Box<Arc<T>>) {}
= help: consider using just `Box<T>` or `Arc<T>`
error: usage of `Box<Rc<SubT<usize>>>`
- --> $DIR/redundant_allocation.rs:21:27
+ --> $DIR/redundant_allocation.rs:20:27
|
LL | pub fn box_test8() -> Box<Rc<SubT<usize>>> {
| ^^^^^^^^^^^^^^^^^^^^
@@ -27,7 +27,7 @@ LL | pub fn box_test8() -> Box<Rc<SubT<usize>>> {
= help: consider using just `Box<SubT<usize>>` or `Rc<SubT<usize>>`
error: usage of `Box<Arc<T>>`
- --> $DIR/redundant_allocation.rs:25:30
+ --> $DIR/redundant_allocation.rs:24:30
|
LL | pub fn box_test9<T>(foo: Box<Arc<T>>) -> Box<Arc<SubT<T>>> {
| ^^^^^^^^^^^
@@ -36,7 +36,7 @@ LL | pub fn box_test9<T>(foo: Box<Arc<T>>) -> Box<Arc<SubT<T>>> {
= help: consider using just `Box<T>` or `Arc<T>`
error: usage of `Box<Arc<SubT<T>>>`
- --> $DIR/redundant_allocation.rs:25:46
+ --> $DIR/redundant_allocation.rs:24:46
|
LL | pub fn box_test9<T>(foo: Box<Arc<T>>) -> Box<Arc<SubT<T>>> {
| ^^^^^^^^^^^^^^^^^
@@ -45,7 +45,7 @@ LL | pub fn box_test9<T>(foo: Box<Arc<T>>) -> Box<Arc<SubT<T>>> {
= help: consider using just `Box<SubT<T>>` or `Arc<SubT<T>>`
error: usage of `Rc<Box<bool>>`
- --> $DIR/redundant_allocation.rs:37:24
+ --> $DIR/redundant_allocation.rs:35:24
|
LL | pub fn rc_test5(a: Rc<Box<bool>>) {}
| ^^^^^^^^^^^^^
@@ -54,7 +54,7 @@ LL | pub fn rc_test5(a: Rc<Box<bool>>) {}
= help: consider using just `Rc<bool>` or `Box<bool>`
error: usage of `Rc<Arc<bool>>`
- --> $DIR/redundant_allocation.rs:39:24
+ --> $DIR/redundant_allocation.rs:37:24
|
LL | pub fn rc_test7(a: Rc<Arc<bool>>) {}
| ^^^^^^^^^^^^^
@@ -63,7 +63,7 @@ LL | pub fn rc_test7(a: Rc<Arc<bool>>) {}
= help: consider using just `Rc<bool>` or `Arc<bool>`
error: usage of `Rc<Box<SubT<usize>>>`
- --> $DIR/redundant_allocation.rs:41:26
+ --> $DIR/redundant_allocation.rs:39:26
|
LL | pub fn rc_test8() -> Rc<Box<SubT<usize>>> {
| ^^^^^^^^^^^^^^^^^^^^
@@ -72,7 +72,7 @@ LL | pub fn rc_test8() -> Rc<Box<SubT<usize>>> {
= help: consider using just `Rc<SubT<usize>>` or `Box<SubT<usize>>`
error: usage of `Rc<Arc<T>>`
- --> $DIR/redundant_allocation.rs:45:29
+ --> $DIR/redundant_allocation.rs:43:29
|
LL | pub fn rc_test9<T>(foo: Rc<Arc<T>>) -> Rc<Arc<SubT<T>>> {
| ^^^^^^^^^^
@@ -81,7 +81,7 @@ LL | pub fn rc_test9<T>(foo: Rc<Arc<T>>) -> Rc<Arc<SubT<T>>> {
= help: consider using just `Rc<T>` or `Arc<T>`
error: usage of `Rc<Arc<SubT<T>>>`
- --> $DIR/redundant_allocation.rs:45:44
+ --> $DIR/redundant_allocation.rs:43:44
|
LL | pub fn rc_test9<T>(foo: Rc<Arc<T>>) -> Rc<Arc<SubT<T>>> {
| ^^^^^^^^^^^^^^^^
@@ -90,7 +90,7 @@ LL | pub fn rc_test9<T>(foo: Rc<Arc<T>>) -> Rc<Arc<SubT<T>>> {
= help: consider using just `Rc<SubT<T>>` or `Arc<SubT<T>>`
error: usage of `Arc<Box<bool>>`
- --> $DIR/redundant_allocation.rs:57:25
+ --> $DIR/redundant_allocation.rs:54:25
|
LL | pub fn arc_test5(a: Arc<Box<bool>>) {}
| ^^^^^^^^^^^^^^
@@ -99,7 +99,7 @@ LL | pub fn arc_test5(a: Arc<Box<bool>>) {}
= help: consider using just `Arc<bool>` or `Box<bool>`
error: usage of `Arc<Rc<bool>>`
- --> $DIR/redundant_allocation.rs:59:25
+ --> $DIR/redundant_allocation.rs:56:25
|
LL | pub fn arc_test6(a: Arc<Rc<bool>>) {}
| ^^^^^^^^^^^^^
@@ -108,7 +108,7 @@ LL | pub fn arc_test6(a: Arc<Rc<bool>>) {}
= help: consider using just `Arc<bool>` or `Rc<bool>`
error: usage of `Arc<Box<SubT<usize>>>`
- --> $DIR/redundant_allocation.rs:61:27
+ --> $DIR/redundant_allocation.rs:58:27
|
LL | pub fn arc_test8() -> Arc<Box<SubT<usize>>> {
| ^^^^^^^^^^^^^^^^^^^^^
@@ -117,7 +117,7 @@ LL | pub fn arc_test8() -> Arc<Box<SubT<usize>>> {
= help: consider using just `Arc<SubT<usize>>` or `Box<SubT<usize>>`
error: usage of `Arc<Rc<T>>`
- --> $DIR/redundant_allocation.rs:65:30
+ --> $DIR/redundant_allocation.rs:62:30
|
LL | pub fn arc_test9<T>(foo: Arc<Rc<T>>) -> Arc<Rc<SubT<T>>> {
| ^^^^^^^^^^
@@ -126,7 +126,7 @@ LL | pub fn arc_test9<T>(foo: Arc<Rc<T>>) -> Arc<Rc<SubT<T>>> {
= help: consider using just `Arc<T>` or `Rc<T>`
error: usage of `Arc<Rc<SubT<T>>>`
- --> $DIR/redundant_allocation.rs:65:45
+ --> $DIR/redundant_allocation.rs:62:45
|
LL | pub fn arc_test9<T>(foo: Arc<Rc<T>>) -> Arc<Rc<SubT<T>>> {
| ^^^^^^^^^^^^^^^^
@@ -135,7 +135,7 @@ LL | pub fn arc_test9<T>(foo: Arc<Rc<T>>) -> Arc<Rc<SubT<T>>> {
= help: consider using just `Arc<SubT<T>>` or `Rc<SubT<T>>`
error: usage of `Rc<Box<Box<dyn T>>>`
- --> $DIR/redundant_allocation.rs:87:27
+ --> $DIR/redundant_allocation.rs:84:27
|
LL | pub fn test_rc_box(_: Rc<Box<Box<dyn T>>>) {}
| ^^^^^^^^^^^^^^^^^^^
@@ -144,7 +144,7 @@ LL | pub fn test_rc_box(_: Rc<Box<Box<dyn T>>>) {}
= help: consider using just `Rc<Box<dyn T>>` or `Box<Box<dyn T>>`
error: usage of `Rc<Box<Box<str>>>`
- --> $DIR/redundant_allocation.rs:119:31
+ --> $DIR/redundant_allocation.rs:116:31
|
LL | pub fn test_rc_box_str(_: Rc<Box<Box<str>>>) {}
| ^^^^^^^^^^^^^^^^^
@@ -153,7 +153,7 @@ LL | pub fn test_rc_box_str(_: Rc<Box<Box<str>>>) {}
= help: consider using just `Rc<Box<str>>` or `Box<Box<str>>`
error: usage of `Rc<Box<Box<[usize]>>>`
- --> $DIR/redundant_allocation.rs:120:33
+ --> $DIR/redundant_allocation.rs:117:33
|
LL | pub fn test_rc_box_slice(_: Rc<Box<Box<[usize]>>>) {}
| ^^^^^^^^^^^^^^^^^^^^^
@@ -162,7 +162,7 @@ LL | pub fn test_rc_box_slice(_: Rc<Box<Box<[usize]>>>) {}
= help: consider using just `Rc<Box<[usize]>>` or `Box<Box<[usize]>>`
error: usage of `Rc<Box<Box<Path>>>`
- --> $DIR/redundant_allocation.rs:121:32
+ --> $DIR/redundant_allocation.rs:118:32
|
LL | pub fn test_rc_box_path(_: Rc<Box<Box<Path>>>) {}
| ^^^^^^^^^^^^^^^^^^
@@ -171,7 +171,7 @@ LL | pub fn test_rc_box_path(_: Rc<Box<Box<Path>>>) {}
= help: consider using just `Rc<Box<Path>>` or `Box<Box<Path>>`
error: usage of `Rc<Box<Box<DynSized>>>`
- --> $DIR/redundant_allocation.rs:122:34
+ --> $DIR/redundant_allocation.rs:119:34
|
LL | pub fn test_rc_box_custom(_: Rc<Box<Box<DynSized>>>) {}
| ^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/redundant_allocation_fixable.fixed b/src/tools/clippy/tests/ui/redundant_allocation_fixable.fixed
index edb7715f4..b97863daf 100644
--- a/src/tools/clippy/tests/ui/redundant_allocation_fixable.fixed
+++ b/src/tools/clippy/tests/ui/redundant_allocation_fixable.fixed
@@ -16,9 +16,7 @@ pub enum MyEnum {
}
mod outer_box {
- use crate::MyEnum;
- use crate::MyStruct;
- use crate::SubT;
+ use crate::{MyEnum, MyStruct, SubT};
use std::boxed::Box;
use std::rc::Rc;
use std::sync::Arc;
@@ -35,9 +33,7 @@ mod outer_box {
}
mod outer_rc {
- use crate::MyEnum;
- use crate::MyStruct;
- use crate::SubT;
+ use crate::{MyEnum, MyStruct, SubT};
use std::boxed::Box;
use std::rc::Rc;
use std::sync::Arc;
@@ -54,9 +50,7 @@ mod outer_rc {
}
mod outer_arc {
- use crate::MyEnum;
- use crate::MyStruct;
- use crate::SubT;
+ use crate::{MyEnum, MyStruct, SubT};
use std::boxed::Box;
use std::rc::Rc;
use std::sync::Arc;
diff --git a/src/tools/clippy/tests/ui/redundant_allocation_fixable.rs b/src/tools/clippy/tests/ui/redundant_allocation_fixable.rs
index c59422dd9..bffb6f8c0 100644
--- a/src/tools/clippy/tests/ui/redundant_allocation_fixable.rs
+++ b/src/tools/clippy/tests/ui/redundant_allocation_fixable.rs
@@ -16,9 +16,7 @@ pub enum MyEnum {
}
mod outer_box {
- use crate::MyEnum;
- use crate::MyStruct;
- use crate::SubT;
+ use crate::{MyEnum, MyStruct, SubT};
use std::boxed::Box;
use std::rc::Rc;
use std::sync::Arc;
@@ -35,9 +33,7 @@ mod outer_box {
}
mod outer_rc {
- use crate::MyEnum;
- use crate::MyStruct;
- use crate::SubT;
+ use crate::{MyEnum, MyStruct, SubT};
use std::boxed::Box;
use std::rc::Rc;
use std::sync::Arc;
@@ -54,9 +50,7 @@ mod outer_rc {
}
mod outer_arc {
- use crate::MyEnum;
- use crate::MyStruct;
- use crate::SubT;
+ use crate::{MyEnum, MyStruct, SubT};
use std::boxed::Box;
use std::rc::Rc;
use std::sync::Arc;
diff --git a/src/tools/clippy/tests/ui/redundant_allocation_fixable.stderr b/src/tools/clippy/tests/ui/redundant_allocation_fixable.stderr
index 8dd4a6a26..524ca5bf4 100644
--- a/src/tools/clippy/tests/ui/redundant_allocation_fixable.stderr
+++ b/src/tools/clippy/tests/ui/redundant_allocation_fixable.stderr
@@ -1,5 +1,5 @@
error: usage of `Box<&T>`
- --> $DIR/redundant_allocation_fixable.rs:26:30
+ --> $DIR/redundant_allocation_fixable.rs:24:30
|
LL | pub fn box_test1<T>(foo: Box<&T>) {}
| ^^^^^^^ help: try: `&T`
@@ -8,7 +8,7 @@ LL | pub fn box_test1<T>(foo: Box<&T>) {}
= note: `-D clippy::redundant-allocation` implied by `-D warnings`
error: usage of `Box<&MyStruct>`
- --> $DIR/redundant_allocation_fixable.rs:28:27
+ --> $DIR/redundant_allocation_fixable.rs:26:27
|
LL | pub fn box_test2(foo: Box<&MyStruct>) {}
| ^^^^^^^^^^^^^^ help: try: `&MyStruct`
@@ -16,7 +16,7 @@ LL | pub fn box_test2(foo: Box<&MyStruct>) {}
= note: `&MyStruct` is already a pointer, `Box<&MyStruct>` allocates a pointer on the heap
error: usage of `Box<&MyEnum>`
- --> $DIR/redundant_allocation_fixable.rs:30:27
+ --> $DIR/redundant_allocation_fixable.rs:28:27
|
LL | pub fn box_test3(foo: Box<&MyEnum>) {}
| ^^^^^^^^^^^^ help: try: `&MyEnum`
@@ -24,7 +24,7 @@ LL | pub fn box_test3(foo: Box<&MyEnum>) {}
= note: `&MyEnum` is already a pointer, `Box<&MyEnum>` allocates a pointer on the heap
error: usage of `Box<Box<T>>`
- --> $DIR/redundant_allocation_fixable.rs:34:30
+ --> $DIR/redundant_allocation_fixable.rs:32:30
|
LL | pub fn box_test5<T>(foo: Box<Box<T>>) {}
| ^^^^^^^^^^^ help: try: `Box<T>`
@@ -32,7 +32,7 @@ LL | pub fn box_test5<T>(foo: Box<Box<T>>) {}
= note: `Box<T>` is already on the heap, `Box<Box<T>>` makes an extra allocation
error: usage of `Rc<&T>`
- --> $DIR/redundant_allocation_fixable.rs:45:29
+ --> $DIR/redundant_allocation_fixable.rs:41:29
|
LL | pub fn rc_test1<T>(foo: Rc<&T>) {}
| ^^^^^^ help: try: `&T`
@@ -40,7 +40,7 @@ LL | pub fn rc_test1<T>(foo: Rc<&T>) {}
= note: `&T` is already a pointer, `Rc<&T>` allocates a pointer on the heap
error: usage of `Rc<&MyStruct>`
- --> $DIR/redundant_allocation_fixable.rs:47:26
+ --> $DIR/redundant_allocation_fixable.rs:43:26
|
LL | pub fn rc_test2(foo: Rc<&MyStruct>) {}
| ^^^^^^^^^^^^^ help: try: `&MyStruct`
@@ -48,7 +48,7 @@ LL | pub fn rc_test2(foo: Rc<&MyStruct>) {}
= note: `&MyStruct` is already a pointer, `Rc<&MyStruct>` allocates a pointer on the heap
error: usage of `Rc<&MyEnum>`
- --> $DIR/redundant_allocation_fixable.rs:49:26
+ --> $DIR/redundant_allocation_fixable.rs:45:26
|
LL | pub fn rc_test3(foo: Rc<&MyEnum>) {}
| ^^^^^^^^^^^ help: try: `&MyEnum`
@@ -56,7 +56,7 @@ LL | pub fn rc_test3(foo: Rc<&MyEnum>) {}
= note: `&MyEnum` is already a pointer, `Rc<&MyEnum>` allocates a pointer on the heap
error: usage of `Rc<Rc<bool>>`
- --> $DIR/redundant_allocation_fixable.rs:53:24
+ --> $DIR/redundant_allocation_fixable.rs:49:24
|
LL | pub fn rc_test6(a: Rc<Rc<bool>>) {}
| ^^^^^^^^^^^^ help: try: `Rc<bool>`
@@ -64,7 +64,7 @@ LL | pub fn rc_test6(a: Rc<Rc<bool>>) {}
= note: `Rc<bool>` is already on the heap, `Rc<Rc<bool>>` makes an extra allocation
error: usage of `Arc<&T>`
- --> $DIR/redundant_allocation_fixable.rs:64:30
+ --> $DIR/redundant_allocation_fixable.rs:58:30
|
LL | pub fn arc_test1<T>(foo: Arc<&T>) {}
| ^^^^^^^ help: try: `&T`
@@ -72,7 +72,7 @@ LL | pub fn arc_test1<T>(foo: Arc<&T>) {}
= note: `&T` is already a pointer, `Arc<&T>` allocates a pointer on the heap
error: usage of `Arc<&MyStruct>`
- --> $DIR/redundant_allocation_fixable.rs:66:27
+ --> $DIR/redundant_allocation_fixable.rs:60:27
|
LL | pub fn arc_test2(foo: Arc<&MyStruct>) {}
| ^^^^^^^^^^^^^^ help: try: `&MyStruct`
@@ -80,7 +80,7 @@ LL | pub fn arc_test2(foo: Arc<&MyStruct>) {}
= note: `&MyStruct` is already a pointer, `Arc<&MyStruct>` allocates a pointer on the heap
error: usage of `Arc<&MyEnum>`
- --> $DIR/redundant_allocation_fixable.rs:68:27
+ --> $DIR/redundant_allocation_fixable.rs:62:27
|
LL | pub fn arc_test3(foo: Arc<&MyEnum>) {}
| ^^^^^^^^^^^^ help: try: `&MyEnum`
@@ -88,7 +88,7 @@ LL | pub fn arc_test3(foo: Arc<&MyEnum>) {}
= note: `&MyEnum` is already a pointer, `Arc<&MyEnum>` allocates a pointer on the heap
error: usage of `Arc<Arc<bool>>`
- --> $DIR/redundant_allocation_fixable.rs:72:25
+ --> $DIR/redundant_allocation_fixable.rs:66:25
|
LL | pub fn arc_test7(a: Arc<Arc<bool>>) {}
| ^^^^^^^^^^^^^^ help: try: `Arc<bool>`
diff --git a/src/tools/clippy/tests/ui/redundant_guards.fixed b/src/tools/clippy/tests/ui/redundant_guards.fixed
new file mode 100644
index 000000000..49d7336ee
--- /dev/null
+++ b/src/tools/clippy/tests/ui/redundant_guards.fixed
@@ -0,0 +1,146 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![feature(if_let_guard)]
+#![allow(clippy::no_effect, unused)]
+#![warn(clippy::redundant_guards)]
+
+#[macro_use]
+extern crate proc_macros;
+
+struct A(u32);
+
+struct B {
+ e: Option<A>,
+}
+
+struct C(u32, u32);
+
+#[derive(PartialEq)]
+struct FloatWrapper(f32);
+fn issue11304() {
+ match 0.1 {
+ x if x == 0.0 => todo!(),
+ _ => todo!(),
+ }
+ match FloatWrapper(0.1) {
+ x if x == FloatWrapper(0.0) => todo!(),
+ _ => todo!(),
+ }
+}
+
+fn main() {
+ let c = C(1, 2);
+ match c {
+ C(x, 1) => ..,
+ _ => todo!(),
+ };
+
+ let x = Some(Some(1));
+ match x {
+ Some(Some(1)) if true => ..,
+ Some(Some(1)) => {
+ println!("a");
+ ..
+ },
+ Some(Some(1)) => ..,
+ Some(Some(2)) => ..,
+ // Don't lint, since x is used in the body
+ Some(x) if let Some(1) = x => {
+ x;
+ ..
+ }
+ _ => todo!(),
+ };
+ let y = 1;
+ match x {
+ // Don't inline these, since y is not from the pat
+ Some(x) if matches!(y, 1 if true) => ..,
+ Some(x) if let 1 = y => ..,
+ Some(x) if y == 2 => ..,
+ _ => todo!(),
+ };
+ let a = A(1);
+ match a {
+ _ if a.0 == 1 => {},
+ _ => todo!(),
+ }
+ let b = B { e: Some(A(0)) };
+ match b {
+ B { e: Some(A(2)) } => ..,
+ _ => todo!(),
+ };
+ // Do not lint, since we cannot represent this as a pattern (at least, without a conversion)
+ let v = Some(vec![1u8, 2, 3]);
+ match v {
+ Some(x) if x == [1] => {},
+ _ => {},
+ }
+
+ external! {
+ let x = Some(Some(1));
+ match x {
+ Some(x) if let Some(1) = x => ..,
+ _ => todo!(),
+ };
+ }
+ with_span! {
+ span
+ let x = Some(Some(1));
+ match x {
+ Some(x) if let Some(1) = x => ..,
+ _ => todo!(),
+ };
+ }
+}
+
+enum E {
+ A(&'static str),
+ B(&'static str),
+ C(&'static str),
+}
+
+fn i() {
+ match E::A("") {
+ // Do not lint
+ E::A(x) | E::B(x) | E::C(x) if x == "from an or pattern" => {},
+ E::A("not from an or pattern") => {},
+ _ => {},
+ };
+}
+
+fn h(v: Option<u32>) {
+ match v {
+ Some(0) => ..,
+ _ => ..,
+ };
+}
+
+// Do not lint
+
+fn f(s: Option<std::ffi::OsString>) {
+ match s {
+ Some(x) if x == "a" => {},
+ _ => {},
+ }
+}
+
+struct S {
+ a: usize,
+}
+
+impl PartialEq for S {
+ fn eq(&self, _: &Self) -> bool {
+ true
+ }
+}
+
+impl Eq for S {}
+
+static CONST_S: S = S { a: 1 };
+
+fn g(opt_s: Option<S>) {
+ match opt_s {
+ Some(x) if x == CONST_S => {},
+ _ => {},
+ }
+}
diff --git a/src/tools/clippy/tests/ui/redundant_guards.rs b/src/tools/clippy/tests/ui/redundant_guards.rs
new file mode 100644
index 000000000..87761010d
--- /dev/null
+++ b/src/tools/clippy/tests/ui/redundant_guards.rs
@@ -0,0 +1,146 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![feature(if_let_guard)]
+#![allow(clippy::no_effect, unused)]
+#![warn(clippy::redundant_guards)]
+
+#[macro_use]
+extern crate proc_macros;
+
+struct A(u32);
+
+struct B {
+ e: Option<A>,
+}
+
+struct C(u32, u32);
+
+#[derive(PartialEq)]
+struct FloatWrapper(f32);
+fn issue11304() {
+ match 0.1 {
+ x if x == 0.0 => todo!(),
+ _ => todo!(),
+ }
+ match FloatWrapper(0.1) {
+ x if x == FloatWrapper(0.0) => todo!(),
+ _ => todo!(),
+ }
+}
+
+fn main() {
+ let c = C(1, 2);
+ match c {
+ C(x, y) if let 1 = y => ..,
+ _ => todo!(),
+ };
+
+ let x = Some(Some(1));
+ match x {
+ Some(x) if matches!(x, Some(1) if true) => ..,
+ Some(x) if matches!(x, Some(1)) => {
+ println!("a");
+ ..
+ },
+ Some(x) if let Some(1) = x => ..,
+ Some(x) if x == Some(2) => ..,
+ // Don't lint, since x is used in the body
+ Some(x) if let Some(1) = x => {
+ x;
+ ..
+ }
+ _ => todo!(),
+ };
+ let y = 1;
+ match x {
+ // Don't inline these, since y is not from the pat
+ Some(x) if matches!(y, 1 if true) => ..,
+ Some(x) if let 1 = y => ..,
+ Some(x) if y == 2 => ..,
+ _ => todo!(),
+ };
+ let a = A(1);
+ match a {
+ _ if a.0 == 1 => {},
+ _ => todo!(),
+ }
+ let b = B { e: Some(A(0)) };
+ match b {
+ B { e } if matches!(e, Some(A(2))) => ..,
+ _ => todo!(),
+ };
+ // Do not lint, since we cannot represent this as a pattern (at least, without a conversion)
+ let v = Some(vec![1u8, 2, 3]);
+ match v {
+ Some(x) if x == [1] => {},
+ _ => {},
+ }
+
+ external! {
+ let x = Some(Some(1));
+ match x {
+ Some(x) if let Some(1) = x => ..,
+ _ => todo!(),
+ };
+ }
+ with_span! {
+ span
+ let x = Some(Some(1));
+ match x {
+ Some(x) if let Some(1) = x => ..,
+ _ => todo!(),
+ };
+ }
+}
+
+enum E {
+ A(&'static str),
+ B(&'static str),
+ C(&'static str),
+}
+
+fn i() {
+ match E::A("") {
+ // Do not lint
+ E::A(x) | E::B(x) | E::C(x) if x == "from an or pattern" => {},
+ E::A(y) if y == "not from an or pattern" => {},
+ _ => {},
+ };
+}
+
+fn h(v: Option<u32>) {
+ match v {
+ x if matches!(x, Some(0)) => ..,
+ _ => ..,
+ };
+}
+
+// Do not lint
+
+fn f(s: Option<std::ffi::OsString>) {
+ match s {
+ Some(x) if x == "a" => {},
+ _ => {},
+ }
+}
+
+struct S {
+ a: usize,
+}
+
+impl PartialEq for S {
+ fn eq(&self, _: &Self) -> bool {
+ true
+ }
+}
+
+impl Eq for S {}
+
+static CONST_S: S = S { a: 1 };
+
+fn g(opt_s: Option<S>) {
+ match opt_s {
+ Some(x) if x == CONST_S => {},
+ _ => {},
+ }
+}
diff --git a/src/tools/clippy/tests/ui/redundant_guards.stderr b/src/tools/clippy/tests/ui/redundant_guards.stderr
new file mode 100644
index 000000000..5bdf43d23
--- /dev/null
+++ b/src/tools/clippy/tests/ui/redundant_guards.stderr
@@ -0,0 +1,98 @@
+error: redundant guard
+ --> $DIR/redundant_guards.rs:34:20
+ |
+LL | C(x, y) if let 1 = y => ..,
+ | ^^^^^^^^^
+ |
+ = note: `-D clippy::redundant-guards` implied by `-D warnings`
+help: try
+ |
+LL - C(x, y) if let 1 = y => ..,
+LL + C(x, 1) => ..,
+ |
+
+error: redundant guard
+ --> $DIR/redundant_guards.rs:40:20
+ |
+LL | Some(x) if matches!(x, Some(1) if true) => ..,
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: try
+ |
+LL | Some(Some(1)) if true => ..,
+ | ~~~~~~~ ~~~~~~~
+
+error: redundant guard
+ --> $DIR/redundant_guards.rs:41:20
+ |
+LL | Some(x) if matches!(x, Some(1)) => {
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+help: try
+ |
+LL - Some(x) if matches!(x, Some(1)) => {
+LL + Some(Some(1)) => {
+ |
+
+error: redundant guard
+ --> $DIR/redundant_guards.rs:45:20
+ |
+LL | Some(x) if let Some(1) = x => ..,
+ | ^^^^^^^^^^^^^^^
+ |
+help: try
+ |
+LL - Some(x) if let Some(1) = x => ..,
+LL + Some(Some(1)) => ..,
+ |
+
+error: redundant guard
+ --> $DIR/redundant_guards.rs:46:20
+ |
+LL | Some(x) if x == Some(2) => ..,
+ | ^^^^^^^^^^^^
+ |
+help: try
+ |
+LL - Some(x) if x == Some(2) => ..,
+LL + Some(Some(2)) => ..,
+ |
+
+error: redundant guard
+ --> $DIR/redundant_guards.rs:69:20
+ |
+LL | B { e } if matches!(e, Some(A(2))) => ..,
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: try
+ |
+LL - B { e } if matches!(e, Some(A(2))) => ..,
+LL + B { e: Some(A(2)) } => ..,
+ |
+
+error: redundant guard
+ --> $DIR/redundant_guards.rs:106:20
+ |
+LL | E::A(y) if y == "not from an or pattern" => {},
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: try
+ |
+LL - E::A(y) if y == "not from an or pattern" => {},
+LL + E::A("not from an or pattern") => {},
+ |
+
+error: redundant guard
+ --> $DIR/redundant_guards.rs:113:14
+ |
+LL | x if matches!(x, Some(0)) => ..,
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+help: try
+ |
+LL - x if matches!(x, Some(0)) => ..,
+LL + Some(0) => ..,
+ |
+
+error: aborting due to 8 previous errors
+
diff --git a/src/tools/clippy/tests/ui/redundant_locals.rs b/src/tools/clippy/tests/ui/redundant_locals.rs
new file mode 100644
index 000000000..80af38f47
--- /dev/null
+++ b/src/tools/clippy/tests/ui/redundant_locals.rs
@@ -0,0 +1,120 @@
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(unused, clippy::no_effect, clippy::needless_pass_by_ref_mut)]
+#![warn(clippy::redundant_locals)]
+
+extern crate proc_macros;
+use proc_macros::{external, with_span};
+
+fn main() {}
+
+fn immutable() {
+ let x = 1;
+ let x = x;
+}
+
+fn mutable() {
+ let mut x = 1;
+ let mut x = x;
+}
+
+fn upgraded_mutability() {
+ let x = 1;
+ let mut x = x;
+}
+
+fn downgraded_mutability() {
+ let mut x = 1;
+ let x = x;
+}
+
+// see #11290
+fn shadow_mutation() {
+ let mut x = 1;
+ {
+ let mut x = x;
+ x = 2;
+ }
+}
+
+fn coercion(par: &mut i32) {
+ let par: &i32 = par;
+
+ let x: &mut i32 = &mut 1;
+ let x: &i32 = x;
+}
+
+fn parameter(x: i32) {
+ let x = x;
+}
+
+fn many() {
+ let x = 1;
+ let x = x;
+ let x = x;
+ let x = x;
+ let x = x;
+}
+
+fn interleaved() {
+ let a = 1;
+ let b = 2;
+ let a = a;
+ let b = b;
+}
+
+fn block() {
+ {
+ let x = 1;
+ let x = x;
+ }
+}
+
+fn closure() {
+ || {
+ let x = 1;
+ let x = x;
+ };
+ |x: i32| {
+ let x = x;
+ };
+}
+
+fn consequential_drop_order() {
+ use std::sync::Mutex;
+
+ let mutex = Mutex::new(1);
+ let guard = mutex.lock().unwrap();
+
+ {
+ let guard = guard;
+ }
+}
+
+fn inconsequential_drop_order() {
+ let x = 1;
+
+ {
+ let x = x;
+ }
+}
+
+fn macros() {
+ macro_rules! rebind {
+ ($x:ident) => {
+ let $x = 1;
+ let $x = $x;
+ };
+ }
+
+ rebind!(x);
+
+ external! {
+ let x = 1;
+ let x = x;
+ }
+ with_span! {
+ span
+ let x = 1;
+ let x = x;
+ }
+}
diff --git a/src/tools/clippy/tests/ui/redundant_locals.stderr b/src/tools/clippy/tests/ui/redundant_locals.stderr
new file mode 100644
index 000000000..587de0575
--- /dev/null
+++ b/src/tools/clippy/tests/ui/redundant_locals.stderr
@@ -0,0 +1,136 @@
+error: redundant redefinition of a binding
+ --> $DIR/redundant_locals.rs:11:9
+ |
+LL | let x = 1;
+ | ^
+LL | let x = x;
+ | ^^^^^^^^^^
+ |
+ = help: remove the redefinition of `x`
+ = note: `-D clippy::redundant-locals` implied by `-D warnings`
+
+error: redundant redefinition of a binding
+ --> $DIR/redundant_locals.rs:16:9
+ |
+LL | let mut x = 1;
+ | ^^^^^
+LL | let mut x = x;
+ | ^^^^^^^^^^^^^^
+ |
+ = help: remove the redefinition of `x`
+
+error: redundant redefinition of a binding
+ --> $DIR/redundant_locals.rs:46:14
+ |
+LL | fn parameter(x: i32) {
+ | ^
+LL | let x = x;
+ | ^^^^^^^^^^
+ |
+ = help: remove the redefinition of `x`
+
+error: redundant redefinition of a binding
+ --> $DIR/redundant_locals.rs:51:9
+ |
+LL | let x = 1;
+ | ^
+LL | let x = x;
+ | ^^^^^^^^^^
+ |
+ = help: remove the redefinition of `x`
+
+error: redundant redefinition of a binding
+ --> $DIR/redundant_locals.rs:52:9
+ |
+LL | let x = x;
+ | ^
+LL | let x = x;
+ | ^^^^^^^^^^
+ |
+ = help: remove the redefinition of `x`
+
+error: redundant redefinition of a binding
+ --> $DIR/redundant_locals.rs:53:9
+ |
+LL | let x = x;
+ | ^
+LL | let x = x;
+ | ^^^^^^^^^^
+ |
+ = help: remove the redefinition of `x`
+
+error: redundant redefinition of a binding
+ --> $DIR/redundant_locals.rs:54:9
+ |
+LL | let x = x;
+ | ^
+LL | let x = x;
+ | ^^^^^^^^^^
+ |
+ = help: remove the redefinition of `x`
+
+error: redundant redefinition of a binding
+ --> $DIR/redundant_locals.rs:59:9
+ |
+LL | let a = 1;
+ | ^
+LL | let b = 2;
+LL | let a = a;
+ | ^^^^^^^^^^
+ |
+ = help: remove the redefinition of `a`
+
+error: redundant redefinition of a binding
+ --> $DIR/redundant_locals.rs:60:9
+ |
+LL | let b = 2;
+ | ^
+LL | let a = a;
+LL | let b = b;
+ | ^^^^^^^^^^
+ |
+ = help: remove the redefinition of `b`
+
+error: redundant redefinition of a binding
+ --> $DIR/redundant_locals.rs:67:13
+ |
+LL | let x = 1;
+ | ^
+LL | let x = x;
+ | ^^^^^^^^^^
+ |
+ = help: remove the redefinition of `x`
+
+error: redundant redefinition of a binding
+ --> $DIR/redundant_locals.rs:74:13
+ |
+LL | let x = 1;
+ | ^
+LL | let x = x;
+ | ^^^^^^^^^^
+ |
+ = help: remove the redefinition of `x`
+
+error: redundant redefinition of a binding
+ --> $DIR/redundant_locals.rs:77:6
+ |
+LL | |x: i32| {
+ | ^
+LL | let x = x;
+ | ^^^^^^^^^^
+ |
+ = help: remove the redefinition of `x`
+
+error: redundant redefinition of a binding
+ --> $DIR/redundant_locals.rs:94:9
+ |
+LL | let x = 1;
+ | ^
+...
+LL | let x = x;
+ | ^^^^^^^^^^
+ |
+ = help: remove the redefinition of `x`
+
+error: aborting due to 13 previous errors
+
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 e9ea3f2e6..28f33f0c9 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
@@ -2,7 +2,7 @@ error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching_drop_order.rs:17:12
|
LL | if let Ok(_) = m.lock() {}
- | -------^^^^^----------- help: try this: `if m.lock().is_ok()`
+ | -------^^^^^----------- help: try: `if m.lock().is_ok()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
@@ -12,7 +12,7 @@ error: redundant pattern matching, consider using `is_err()`
--> $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()`
+ | -------^^^^^^------------------------------------ help: try: `if Err::<(), _>(m.lock().unwrap().0).is_err()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
@@ -21,7 +21,7 @@ error: redundant pattern matching, consider using `is_ok()`
--> $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()`
+ | -------^^^^^----------------------------------------- help: try: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
@@ -30,7 +30,7 @@ error: redundant pattern matching, consider using `is_ok()`
--> $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()`
+ | -------^^^^^----------------------------------------- help: try: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
@@ -39,31 +39,31 @@ error: redundant pattern matching, consider using `is_ok()`
--> $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()`
+ | -------^^^^^----------------------------------------- help: try: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching_drop_order.rs:27:12
|
LL | if let Err(_) = Err::<std::sync::MutexGuard<()>, _>(()) {}
- | -------^^^^^^------------------------------------------ help: try this: `if Err::<std::sync::MutexGuard<()>, _>(()).is_err()`
+ | -------^^^^^^------------------------------------------ help: try: `if Err::<std::sync::MutexGuard<()>, _>(()).is_err()`
error: redundant pattern matching, consider using `is_ok()`
--> $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()`
+ | -------^^^^^----------------------------- help: try: `if Ok::<_, ()>(String::new()).is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching_drop_order.rs:30:12
|
LL | if let Err(_) = Err::<(), _>((String::new(), ())) {}
- | -------^^^^^^------------------------------------ help: try this: `if Err::<(), _>((String::new(), ())).is_err()`
+ | -------^^^^^^------------------------------------ help: try: `if Err::<(), _>((String::new(), ())).is_err()`
error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching_drop_order.rs:33:12
|
LL | if let Some(_) = Some(m.lock()) {}
- | -------^^^^^^^----------------- help: try this: `if Some(m.lock()).is_some()`
+ | -------^^^^^^^----------------- help: try: `if Some(m.lock()).is_some()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
@@ -72,7 +72,7 @@ error: redundant pattern matching, consider using `is_some()`
--> $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()`
+ | -------^^^^^^^---------------------------- help: try: `if Some(m.lock().unwrap().0).is_some()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
@@ -81,7 +81,7 @@ error: redundant pattern matching, consider using `is_none()`
--> $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()`
+ | -------^^^^------------------------------------ help: try: `if None::<std::sync::MutexGuard<()>>.is_none()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
@@ -90,7 +90,7 @@ error: redundant pattern matching, consider using `is_none()`
--> $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()`
+ | -------^^^^------------------------------------ help: try: `if None::<std::sync::MutexGuard<()>>.is_none()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
@@ -99,25 +99,25 @@ error: redundant pattern matching, consider using `is_none()`
--> $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()`
+ | -------^^^^------------------------------------ help: try: `if None::<std::sync::MutexGuard<()>>.is_none()`
error: redundant pattern matching, consider using `is_some()`
--> $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()`
+ | -------^^^^^^^---------------------- help: try: `if Some(String::new()).is_some()`
error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching_drop_order.rs:46:12
|
LL | if let Some(_) = Some((String::new(), ())) {}
- | -------^^^^^^^---------------------------- help: try this: `if Some((String::new(), ())).is_some()`
+ | -------^^^^^^^---------------------------- help: try: `if Some((String::new(), ())).is_some()`
error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_drop_order.rs:49:12
|
LL | if let Ready(_) = Ready(m.lock()) {}
- | -------^^^^^^^^------------------ help: try this: `if Ready(m.lock()).is_ready()`
+ | -------^^^^^^^^------------------ help: try: `if Ready(m.lock()).is_ready()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
@@ -126,7 +126,7 @@ error: redundant pattern matching, consider using `is_ready()`
--> $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()`
+ | -------^^^^^^^^----------------------------- help: try: `if Ready(m.lock().unwrap().0).is_ready()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
@@ -135,7 +135,7 @@ error: redundant pattern matching, consider using `is_pending()`
--> $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()`
+ | -------^^^^^^^--------------------------------------- help: try: `if Pending::<std::sync::MutexGuard<()>>.is_pending()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
@@ -144,7 +144,7 @@ error: redundant pattern matching, consider using `is_pending()`
--> $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()`
+ | -------^^^^^^^--------------------------------------- help: try: `if Pending::<std::sync::MutexGuard<()>>.is_pending()`
|
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
@@ -153,19 +153,19 @@ error: redundant pattern matching, consider using `is_pending()`
--> $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()`
+ | -------^^^^^^^--------------------------------------- help: try: `if Pending::<std::sync::MutexGuard<()>>.is_pending()`
error: redundant pattern matching, consider using `is_ready()`
--> $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()`
+ | -------^^^^^^^^----------------------- help: try: `if Ready(String::new()).is_ready()`
error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_drop_order.rs:62:12
|
LL | if let Ready(_) = Ready((String::new(), ())) {}
- | -------^^^^^^^^----------------------------- help: try this: `if Ready((String::new(), ())).is_ready()`
+ | -------^^^^^^^^----------------------------- help: try: `if Ready((String::new(), ())).is_ready()`
error: aborting due to 22 previous errors
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 75ed14344..02f197aa2 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed
@@ -8,10 +8,8 @@
clippy::uninlined_format_args
)]
-use std::net::{
- IpAddr::{self, V4, V6},
- Ipv4Addr, Ipv6Addr,
-};
+use std::net::IpAddr::{self, V4, V6};
+use std::net::{Ipv4Addr, Ipv6Addr};
fn main() {
let ipaddr: IpAddr = V4(Ipv4Addr::LOCALHOST);
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 9ac77409f..5c1e1810f 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs
@@ -8,10 +8,8 @@
clippy::uninlined_format_args
)]
-use std::net::{
- IpAddr::{self, V4, V6},
- Ipv4Addr, Ipv6Addr,
-};
+use std::net::IpAddr::{self, V4, V6};
+use std::net::{Ipv4Addr, Ipv6Addr};
fn main() {
let ipaddr: IpAddr = V4(Ipv4Addr::LOCALHOST);
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 6d1fb2964..bec8d3088 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr
@@ -1,130 +1,130 @@
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:18:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:16:12
|
LL | if let V4(_) = &ipaddr {}
- | -------^^^^^---------- help: try this: `if ipaddr.is_ipv4()`
+ | -------^^^^^---------- help: try: `if ipaddr.is_ipv4()`
|
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:20:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:18:12
|
LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
- | -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
+ | -------^^^^^-------------------------- help: try: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:22:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:20:12
|
LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
- | -------^^^^^-------------------------- help: try this: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()`
+ | -------^^^^^-------------------------- help: try: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:24:15
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:22:15
|
LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
- | ----------^^^^^-------------------------- help: try this: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()`
+ | ----------^^^^^-------------------------- help: try: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:26:15
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:24:15
|
LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
- | ----------^^^^^-------------------------- help: try this: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()`
+ | ----------^^^^^-------------------------- help: try: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:36:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:34:5
|
LL | / match V4(Ipv4Addr::LOCALHOST) {
LL | | V4(_) => true,
LL | | V6(_) => false,
LL | | };
- | |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv4()`
+ | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:41:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:39:5
|
LL | / match V4(Ipv4Addr::LOCALHOST) {
LL | | V4(_) => false,
LL | | V6(_) => true,
LL | | };
- | |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv6()`
+ | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:46:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:44:5
|
LL | / match V6(Ipv6Addr::LOCALHOST) {
LL | | V4(_) => false,
LL | | V6(_) => true,
LL | | };
- | |_____^ help: try this: `V6(Ipv6Addr::LOCALHOST).is_ipv6()`
+ | |_____^ help: try: `V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:51:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:49:5
|
LL | / match V6(Ipv6Addr::LOCALHOST) {
LL | | V4(_) => true,
LL | | V6(_) => false,
LL | | };
- | |_____^ help: try this: `V6(Ipv6Addr::LOCALHOST).is_ipv4()`
+ | |_____^ help: try: `V6(Ipv6Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:56:20
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:54:20
|
LL | let _ = if let V4(_) = V4(Ipv4Addr::LOCALHOST) {
- | -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
+ | -------^^^^^-------------------------- help: try: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:64:20
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:62:20
|
LL | let _ = if let V4(_) = gen_ipaddr() {
- | -------^^^^^--------------- help: try this: `if gen_ipaddr().is_ipv4()`
+ | -------^^^^^--------------- help: try: `if gen_ipaddr().is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:66:19
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:64:19
|
LL | } else if let V6(_) = gen_ipaddr() {
- | -------^^^^^--------------- help: try this: `if gen_ipaddr().is_ipv6()`
+ | -------^^^^^--------------- help: try: `if gen_ipaddr().is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:78:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:76:12
|
LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
- | -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
+ | -------^^^^^-------------------------- help: try: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:80:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:78:12
|
LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
- | -------^^^^^-------------------------- help: try this: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()`
+ | -------^^^^^-------------------------- help: try: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:82:15
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:80:15
|
LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
- | ----------^^^^^-------------------------- help: try this: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()`
+ | ----------^^^^^-------------------------- help: try: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:84:15
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:82:15
|
LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
- | ----------^^^^^-------------------------- help: try this: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()`
+ | ----------^^^^^-------------------------- help: try: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:86:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:84:5
|
LL | / match V4(Ipv4Addr::LOCALHOST) {
LL | | V4(_) => true,
LL | | V6(_) => false,
LL | | };
- | |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv4()`
+ | |_____^ help: try: `V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:91:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:89:5
|
LL | / match V6(Ipv6Addr::LOCALHOST) {
LL | | V4(_) => false,
LL | | V6(_) => true,
LL | | };
- | |_____^ help: try this: `V6(Ipv6Addr::LOCALHOST).is_ipv6()`
+ | |_____^ help: try: `V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: aborting due to 18 previous errors
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 a63ba5809..d9fcd98c5 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed
@@ -10,6 +10,20 @@
clippy::equatable_if_let,
clippy::if_same_then_else
)]
+#![feature(let_chains, if_let_guard)]
+
+fn issue_11174<T>(boolean: bool, maybe_some: Option<T>) -> bool {
+ maybe_some.is_none() && (!boolean)
+}
+
+fn issue_11174_edge_cases<T>(boolean: bool, boolean2: bool, maybe_some: Option<T>) {
+ let _ = maybe_some.is_none() && (boolean || boolean2); // guard needs parentheses
+ let _ = match maybe_some { // can't use `matches!` here
+ // because `expr` metavars in macros don't allow let exprs
+ None if let Some(x) = Some(0) && x > 5 => true,
+ _ => false
+ };
+}
fn main() {
if None::<()>.is_none() {}
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 631f90916..cbd9494f1 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.rs
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.rs
@@ -10,6 +10,20 @@
clippy::equatable_if_let,
clippy::if_same_then_else
)]
+#![feature(let_chains, if_let_guard)]
+
+fn issue_11174<T>(boolean: bool, maybe_some: Option<T>) -> bool {
+ matches!(maybe_some, None if !boolean)
+}
+
+fn issue_11174_edge_cases<T>(boolean: bool, boolean2: bool, maybe_some: Option<T>) {
+ let _ = matches!(maybe_some, None if boolean || boolean2); // guard needs parentheses
+ let _ = match maybe_some { // can't use `matches!` here
+ // because `expr` metavars in macros don't allow let exprs
+ None if let Some(x) = Some(0) && x > 5 => true,
+ _ => false
+ };
+}
fn main() {
if let None = None::<()> {}
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 717b603c4..b0e43924d 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.stderr
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.stderr
@@ -1,200 +1,212 @@
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:15:12
+ --> $DIR/redundant_pattern_matching_option.rs:16:5
|
-LL | if let None = None::<()> {}
- | -------^^^^------------- help: try this: `if None::<()>.is_none()`
+LL | matches!(maybe_some, None if !boolean)
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `maybe_some.is_none() && (!boolean)`
|
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
+error: redundant pattern matching, consider using `is_none()`
+ --> $DIR/redundant_pattern_matching_option.rs:20:13
+ |
+LL | let _ = matches!(maybe_some, None if boolean || boolean2); // guard needs parentheses
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `maybe_some.is_none() && (boolean || boolean2)`
+
+error: redundant pattern matching, consider using `is_none()`
+ --> $DIR/redundant_pattern_matching_option.rs:29:12
+ |
+LL | if let None = None::<()> {}
+ | -------^^^^------------- help: try: `if None::<()>.is_none()`
+
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:17:12
+ --> $DIR/redundant_pattern_matching_option.rs:31:12
|
LL | if let Some(_) = Some(42) {}
- | -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
+ | -------^^^^^^^----------- help: try: `if Some(42).is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:19:12
+ --> $DIR/redundant_pattern_matching_option.rs:33:12
|
LL | if let Some(_) = Some(42) {
- | -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
+ | -------^^^^^^^----------- help: try: `if Some(42).is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:25:15
+ --> $DIR/redundant_pattern_matching_option.rs:39:15
|
LL | while let Some(_) = Some(42) {}
- | ----------^^^^^^^----------- help: try this: `while Some(42).is_some()`
+ | ----------^^^^^^^----------- help: try: `while Some(42).is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:27:15
+ --> $DIR/redundant_pattern_matching_option.rs:41:15
|
LL | while let None = Some(42) {}
- | ----------^^^^----------- help: try this: `while Some(42).is_none()`
+ | ----------^^^^----------- help: try: `while Some(42).is_none()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:29:15
+ --> $DIR/redundant_pattern_matching_option.rs:43:15
|
LL | while let None = None::<()> {}
- | ----------^^^^------------- help: try this: `while None::<()>.is_none()`
+ | ----------^^^^------------- help: try: `while None::<()>.is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:32:15
+ --> $DIR/redundant_pattern_matching_option.rs:46:15
|
LL | while let Some(_) = v.pop() {
- | ----------^^^^^^^---------- help: try this: `while v.pop().is_some()`
+ | ----------^^^^^^^---------- help: try: `while v.pop().is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:40:5
+ --> $DIR/redundant_pattern_matching_option.rs:54:5
|
LL | / match Some(42) {
LL | | Some(_) => true,
LL | | None => false,
LL | | };
- | |_____^ help: try this: `Some(42).is_some()`
+ | |_____^ help: try: `Some(42).is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:45:5
+ --> $DIR/redundant_pattern_matching_option.rs:59:5
|
LL | / match None::<()> {
LL | | Some(_) => false,
LL | | None => true,
LL | | };
- | |_____^ help: try this: `None::<()>.is_none()`
+ | |_____^ help: try: `None::<()>.is_none()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:50:13
+ --> $DIR/redundant_pattern_matching_option.rs:64:13
|
LL | let _ = match None::<()> {
| _____________^
LL | | Some(_) => false,
LL | | None => true,
LL | | };
- | |_____^ help: try this: `None::<()>.is_none()`
+ | |_____^ help: try: `None::<()>.is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:56:20
+ --> $DIR/redundant_pattern_matching_option.rs:70:20
|
LL | let _ = if let Some(_) = opt { true } else { false };
- | -------^^^^^^^------ help: try this: `if opt.is_some()`
+ | -------^^^^^^^------ help: try: `if opt.is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:62:20
+ --> $DIR/redundant_pattern_matching_option.rs:76:20
|
LL | let _ = if let Some(_) = gen_opt() {
- | -------^^^^^^^------------ help: try this: `if gen_opt().is_some()`
+ | -------^^^^^^^------------ help: try: `if gen_opt().is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:64:19
+ --> $DIR/redundant_pattern_matching_option.rs:78:19
|
LL | } else if let None = gen_opt() {
- | -------^^^^------------ help: try this: `if gen_opt().is_none()`
+ | -------^^^^------------ help: try: `if gen_opt().is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:70:12
+ --> $DIR/redundant_pattern_matching_option.rs:84:12
|
LL | if let Some(..) = gen_opt() {}
- | -------^^^^^^^^------------ help: try this: `if gen_opt().is_some()`
+ | -------^^^^^^^^------------ help: try: `if gen_opt().is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:85:12
+ --> $DIR/redundant_pattern_matching_option.rs:99:12
|
LL | if let Some(_) = Some(42) {}
- | -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
+ | -------^^^^^^^----------- help: try: `if Some(42).is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:87:12
+ --> $DIR/redundant_pattern_matching_option.rs:101:12
|
LL | if let None = None::<()> {}
- | -------^^^^------------- help: try this: `if None::<()>.is_none()`
+ | -------^^^^------------- help: try: `if None::<()>.is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:89:15
+ --> $DIR/redundant_pattern_matching_option.rs:103:15
|
LL | while let Some(_) = Some(42) {}
- | ----------^^^^^^^----------- help: try this: `while Some(42).is_some()`
+ | ----------^^^^^^^----------- help: try: `while Some(42).is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:91:15
+ --> $DIR/redundant_pattern_matching_option.rs:105:15
|
LL | while let None = None::<()> {}
- | ----------^^^^------------- help: try this: `while None::<()>.is_none()`
+ | ----------^^^^------------- help: try: `while None::<()>.is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:93:5
+ --> $DIR/redundant_pattern_matching_option.rs:107:5
|
LL | / match Some(42) {
LL | | Some(_) => true,
LL | | None => false,
LL | | };
- | |_____^ help: try this: `Some(42).is_some()`
+ | |_____^ help: try: `Some(42).is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:98:5
+ --> $DIR/redundant_pattern_matching_option.rs:112:5
|
LL | / match None::<()> {
LL | | Some(_) => false,
LL | | None => true,
LL | | };
- | |_____^ help: try this: `None::<()>.is_none()`
+ | |_____^ help: try: `None::<()>.is_none()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:106:12
+ --> $DIR/redundant_pattern_matching_option.rs:120:12
|
LL | if let None = *(&None::<()>) {}
- | -------^^^^----------------- help: try this: `if (&None::<()>).is_none()`
+ | -------^^^^----------------- help: try: `if (&None::<()>).is_none()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:107:12
+ --> $DIR/redundant_pattern_matching_option.rs:121:12
|
LL | if let None = *&None::<()> {}
- | -------^^^^--------------- help: try this: `if (&None::<()>).is_none()`
+ | -------^^^^--------------- help: try: `if (&None::<()>).is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:113:5
+ --> $DIR/redundant_pattern_matching_option.rs:127:5
|
LL | / match x {
LL | | Some(_) => true,
LL | | _ => false,
LL | | };
- | |_____^ help: try this: `x.is_some()`
+ | |_____^ help: try: `x.is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:118:5
+ --> $DIR/redundant_pattern_matching_option.rs:132:5
|
LL | / match x {
LL | | None => true,
LL | | _ => false,
LL | | };
- | |_____^ help: try this: `x.is_none()`
+ | |_____^ help: try: `x.is_none()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:123:5
+ --> $DIR/redundant_pattern_matching_option.rs:137:5
|
LL | / match x {
LL | | Some(_) => false,
LL | | _ => true,
LL | | };
- | |_____^ help: try this: `x.is_none()`
+ | |_____^ help: try: `x.is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:128:5
+ --> $DIR/redundant_pattern_matching_option.rs:142:5
|
LL | / match x {
LL | | None => false,
LL | | _ => true,
LL | | };
- | |_____^ help: try this: `x.is_some()`
+ | |_____^ help: try: `x.is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:143:13
+ --> $DIR/redundant_pattern_matching_option.rs:157:13
|
LL | let _ = matches!(x, Some(_));
- | ^^^^^^^^^^^^^^^^^^^^ help: try this: `x.is_some()`
+ | ^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:145:13
+ --> $DIR/redundant_pattern_matching_option.rs:159:13
|
LL | let _ = matches!(x, None);
- | ^^^^^^^^^^^^^^^^^ help: try this: `x.is_none()`
+ | ^^^^^^^^^^^^^^^^^ help: try: `x.is_none()`
-error: aborting due to 28 previous errors
+error: aborting due to 30 previous errors
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 b89fde35f..28d3606c4 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.stderr
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.stderr
@@ -2,7 +2,7 @@ error: redundant pattern matching, consider using `is_pending()`
--> $DIR/redundant_pattern_matching_poll.rs:17:12
|
LL | if let Pending = Pending::<()> {}
- | -------^^^^^^^---------------- help: try this: `if Pending::<()>.is_pending()`
+ | -------^^^^^^^---------------- help: try: `if Pending::<()>.is_pending()`
|
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
@@ -10,31 +10,31 @@ error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_poll.rs:19:12
|
LL | if let Ready(_) = Ready(42) {}
- | -------^^^^^^^^------------ help: try this: `if Ready(42).is_ready()`
+ | -------^^^^^^^^------------ help: try: `if Ready(42).is_ready()`
error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_poll.rs:21:12
|
LL | if let Ready(_) = Ready(42) {
- | -------^^^^^^^^------------ help: try this: `if Ready(42).is_ready()`
+ | -------^^^^^^^^------------ help: try: `if Ready(42).is_ready()`
error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_poll.rs:27:15
|
LL | while let Ready(_) = Ready(42) {}
- | ----------^^^^^^^^------------ help: try this: `while Ready(42).is_ready()`
+ | ----------^^^^^^^^------------ help: try: `while Ready(42).is_ready()`
error: redundant pattern matching, consider using `is_pending()`
--> $DIR/redundant_pattern_matching_poll.rs:29:15
|
LL | while let Pending = Ready(42) {}
- | ----------^^^^^^^------------ help: try this: `while Ready(42).is_pending()`
+ | ----------^^^^^^^------------ help: try: `while Ready(42).is_pending()`
error: redundant pattern matching, consider using `is_pending()`
--> $DIR/redundant_pattern_matching_poll.rs:31:15
|
LL | while let Pending = Pending::<()> {}
- | ----------^^^^^^^---------------- help: try this: `while Pending::<()>.is_pending()`
+ | ----------^^^^^^^---------------- help: try: `while Pending::<()>.is_pending()`
error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_poll.rs:37:5
@@ -43,7 +43,7 @@ LL | / match Ready(42) {
LL | | Ready(_) => true,
LL | | Pending => false,
LL | | };
- | |_____^ help: try this: `Ready(42).is_ready()`
+ | |_____^ help: try: `Ready(42).is_ready()`
error: redundant pattern matching, consider using `is_pending()`
--> $DIR/redundant_pattern_matching_poll.rs:42:5
@@ -52,7 +52,7 @@ LL | / match Pending::<()> {
LL | | Ready(_) => false,
LL | | Pending => true,
LL | | };
- | |_____^ help: try this: `Pending::<()>.is_pending()`
+ | |_____^ help: try: `Pending::<()>.is_pending()`
error: redundant pattern matching, consider using `is_pending()`
--> $DIR/redundant_pattern_matching_poll.rs:47:13
@@ -62,49 +62,49 @@ LL | let _ = match Pending::<()> {
LL | | Ready(_) => false,
LL | | Pending => true,
LL | | };
- | |_____^ help: try this: `Pending::<()>.is_pending()`
+ | |_____^ help: try: `Pending::<()>.is_pending()`
error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_poll.rs:53:20
|
LL | let _ = if let Ready(_) = poll { true } else { false };
- | -------^^^^^^^^------- help: try this: `if poll.is_ready()`
+ | -------^^^^^^^^------- help: try: `if poll.is_ready()`
error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_poll.rs:57:20
|
LL | let _ = if let Ready(_) = gen_poll() {
- | -------^^^^^^^^------------- help: try this: `if gen_poll().is_ready()`
+ | -------^^^^^^^^------------- help: try: `if gen_poll().is_ready()`
error: redundant pattern matching, consider using `is_pending()`
--> $DIR/redundant_pattern_matching_poll.rs:59:19
|
LL | } else if let Pending = gen_poll() {
- | -------^^^^^^^------------- help: try this: `if gen_poll().is_pending()`
+ | -------^^^^^^^------------- help: try: `if gen_poll().is_pending()`
error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_poll.rs:75:12
|
LL | if let Ready(_) = Ready(42) {}
- | -------^^^^^^^^------------ help: try this: `if Ready(42).is_ready()`
+ | -------^^^^^^^^------------ help: try: `if Ready(42).is_ready()`
error: redundant pattern matching, consider using `is_pending()`
--> $DIR/redundant_pattern_matching_poll.rs:77:12
|
LL | if let Pending = Pending::<()> {}
- | -------^^^^^^^---------------- help: try this: `if Pending::<()>.is_pending()`
+ | -------^^^^^^^---------------- help: try: `if Pending::<()>.is_pending()`
error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_poll.rs:79:15
|
LL | while let Ready(_) = Ready(42) {}
- | ----------^^^^^^^^------------ help: try this: `while Ready(42).is_ready()`
+ | ----------^^^^^^^^------------ help: try: `while Ready(42).is_ready()`
error: redundant pattern matching, consider using `is_pending()`
--> $DIR/redundant_pattern_matching_poll.rs:81:15
|
LL | while let Pending = Pending::<()> {}
- | ----------^^^^^^^---------------- help: try this: `while Pending::<()>.is_pending()`
+ | ----------^^^^^^^---------------- help: try: `while Pending::<()>.is_pending()`
error: redundant pattern matching, consider using `is_ready()`
--> $DIR/redundant_pattern_matching_poll.rs:83:5
@@ -113,7 +113,7 @@ LL | / match Ready(42) {
LL | | Ready(_) => true,
LL | | Pending => false,
LL | | };
- | |_____^ help: try this: `Ready(42).is_ready()`
+ | |_____^ help: try: `Ready(42).is_ready()`
error: redundant pattern matching, consider using `is_pending()`
--> $DIR/redundant_pattern_matching_poll.rs:88:5
@@ -122,7 +122,7 @@ LL | / match Pending::<()> {
LL | | Ready(_) => false,
LL | | Pending => true,
LL | | };
- | |_____^ help: try this: `Pending::<()>.is_pending()`
+ | |_____^ help: try: `Pending::<()>.is_pending()`
error: aborting due to 18 previous errors
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 f6ce666bb..2b1ce9f54 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr
@@ -2,7 +2,7 @@ error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching_result.rs:16:12
|
LL | if let Ok(_) = &result {}
- | -------^^^^^---------- help: try this: `if result.is_ok()`
+ | -------^^^^^---------- help: try: `if result.is_ok()`
|
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
@@ -10,25 +10,25 @@ error: redundant pattern matching, consider using `is_ok()`
--> $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()`
+ | -------^^^^^--------------------- help: try: `if Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $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()`
+ | -------^^^^^^---------------------- help: try: `if Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
--> $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()`
+ | ----------^^^^^--------------------- help: try: `while Ok::<i32, i32>(10).is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $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()`
+ | ----------^^^^^^--------------------- help: try: `while Ok::<i32, i32>(10).is_err()`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching_result.rs:34:5
@@ -37,7 +37,7 @@ LL | / match Ok::<i32, i32>(42) {
LL | | Ok(_) => true,
LL | | Err(_) => false,
LL | | };
- | |_____^ help: try this: `Ok::<i32, i32>(42).is_ok()`
+ | |_____^ help: try: `Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching_result.rs:39:5
@@ -46,7 +46,7 @@ LL | / match Ok::<i32, i32>(42) {
LL | | Ok(_) => false,
LL | | Err(_) => true,
LL | | };
- | |_____^ help: try this: `Ok::<i32, i32>(42).is_err()`
+ | |_____^ help: try: `Ok::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching_result.rs:44:5
@@ -55,7 +55,7 @@ LL | / match Err::<i32, i32>(42) {
LL | | Ok(_) => false,
LL | | Err(_) => true,
LL | | };
- | |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
+ | |_____^ help: try: `Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching_result.rs:49:5
@@ -64,73 +64,73 @@ LL | / match Err::<i32, i32>(42) {
LL | | Ok(_) => true,
LL | | Err(_) => false,
LL | | };
- | |_____^ help: try this: `Err::<i32, i32>(42).is_ok()`
+ | |_____^ help: try: `Err::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_ok()`
--> $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()`
+ | -------^^^^^--------------------- help: try: `if Ok::<usize, ()>(4).is_ok()`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching_result.rs:62:20
|
LL | let _ = if let Ok(_) = gen_res() {
- | -------^^^^^------------ help: try this: `if gen_res().is_ok()`
+ | -------^^^^^------------ help: try: `if gen_res().is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching_result.rs:64:19
|
LL | } else if let Err(_) = gen_res() {
- | -------^^^^^^------------ help: try this: `if gen_res().is_err()`
+ | -------^^^^^^------------ help: try: `if gen_res().is_err()`
error: redundant pattern matching, consider using `is_some()`
--> $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()`
+ | ----------^^^^^^^----------------------- help: try: `while r#try!(result_opt()).is_some()`
error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching_result.rs:88:16
|
LL | if let Some(_) = r#try!(result_opt()) {}
- | -------^^^^^^^----------------------- help: try this: `if r#try!(result_opt()).is_some()`
+ | -------^^^^^^^----------------------- help: try: `if r#try!(result_opt()).is_some()`
error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching_result.rs:94:12
|
LL | if let Some(_) = m!() {}
- | -------^^^^^^^------- help: try this: `if m!().is_some()`
+ | -------^^^^^^^------- help: try: `if m!().is_some()`
error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching_result.rs:95:15
|
LL | while let Some(_) = m!() {}
- | ----------^^^^^^^------- help: try this: `while m!().is_some()`
+ | ----------^^^^^^^------- help: try: `while m!().is_some()`
error: redundant pattern matching, consider using `is_ok()`
--> $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()`
+ | -------^^^^^--------------------- help: try: `if Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $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()`
+ | -------^^^^^^---------------------- help: try: `if Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
--> $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()`
+ | ----------^^^^^--------------------- help: try: `while Ok::<i32, i32>(10).is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $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()`
+ | ----------^^^^^^--------------------- help: try: `while Ok::<i32, i32>(10).is_err()`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching_result.rs:121:5
@@ -139,7 +139,7 @@ LL | / match Ok::<i32, i32>(42) {
LL | | Ok(_) => true,
LL | | Err(_) => false,
LL | | };
- | |_____^ help: try this: `Ok::<i32, i32>(42).is_ok()`
+ | |_____^ help: try: `Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching_result.rs:126:5
@@ -148,7 +148,7 @@ LL | / match Err::<i32, i32>(42) {
LL | | Ok(_) => false,
LL | | Err(_) => true,
LL | | };
- | |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
+ | |_____^ help: try: `Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching_result.rs:136:5
@@ -157,7 +157,7 @@ LL | / match x {
LL | | Ok(_) => true,
LL | | _ => false,
LL | | };
- | |_____^ help: try this: `x.is_ok()`
+ | |_____^ help: try: `x.is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching_result.rs:141:5
@@ -166,7 +166,7 @@ LL | / match x {
LL | | Ok(_) => false,
LL | | _ => true,
LL | | };
- | |_____^ help: try this: `x.is_err()`
+ | |_____^ help: try: `x.is_err()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching_result.rs:146:5
@@ -175,7 +175,7 @@ LL | / match x {
LL | | Err(_) => true,
LL | | _ => false,
LL | | };
- | |_____^ help: try this: `x.is_err()`
+ | |_____^ help: try: `x.is_err()`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching_result.rs:151:5
@@ -184,19 +184,19 @@ LL | / match x {
LL | | Err(_) => false,
LL | | _ => true,
LL | | };
- | |_____^ help: try this: `x.is_ok()`
+ | |_____^ help: try: `x.is_ok()`
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()`
+ | ^^^^^^^^^^^^^^^^^^ help: try: `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()`
+ | ^^^^^^^^^^^^^^^^^^^ help: try: `x.is_err()`
error: aborting due to 28 previous errors
diff --git a/src/tools/clippy/tests/ui/ref_binding_to_reference.stderr b/src/tools/clippy/tests/ui/ref_binding_to_reference.stderr
index eb36cd516..016feb103 100644
--- a/src/tools/clippy/tests/ui/ref_binding_to_reference.stderr
+++ b/src/tools/clippy/tests/ui/ref_binding_to_reference.stderr
@@ -5,7 +5,7 @@ LL | Some(ref x) => x,
| ^^^^^
|
= note: `-D clippy::ref-binding-to-reference` implied by `-D warnings`
-help: try this
+help: try
|
LL | Some(x) => &x,
| ~ ~~
@@ -16,7 +16,7 @@ error: this pattern creates a reference to a reference
LL | Some(ref x) => {
| ^^^^^
|
-help: try this
+help: try
|
LL ~ Some(x) => {
LL | f1(x);
@@ -30,7 +30,7 @@ error: this pattern creates a reference to a reference
LL | Some(ref x) => m2!(x),
| ^^^^^
|
-help: try this
+help: try
|
LL | Some(x) => m2!(&x),
| ~ ~~
@@ -41,7 +41,7 @@ error: this pattern creates a reference to a reference
LL | let _ = |&ref x: &&String| {
| ^^^^^
|
-help: try this
+help: try
|
LL ~ let _ = |&x: &&String| {
LL ~ let _: &&String = &x;
@@ -53,7 +53,7 @@ error: this pattern creates a reference to a reference
LL | fn f2<'a>(&ref x: &&'a String) -> &'a String {
| ^^^^^
|
-help: try this
+help: try
|
LL ~ fn f2<'a>(&x: &&'a String) -> &'a String {
LL ~ let _: &&String = &x;
@@ -66,7 +66,7 @@ error: this pattern creates a reference to a reference
LL | fn f(&ref x: &&String) {
| ^^^^^
|
-help: try this
+help: try
|
LL ~ fn f(&x: &&String) {
LL ~ let _: &&String = &x;
@@ -78,7 +78,7 @@ error: this pattern creates a reference to a reference
LL | fn f(&ref x: &&String) {
| ^^^^^
|
-help: try this
+help: try
|
LL ~ fn f(&x: &&String) {
LL ~ let _: &&String = &x;
diff --git a/src/tools/clippy/tests/ui/rename.fixed b/src/tools/clippy/tests/ui/rename.fixed
index cc2295ea5..e78b9e5c9 100644
--- a/src/tools/clippy/tests/ui/rename.fixed
+++ b/src/tools/clippy/tests/ui/rename.fixed
@@ -27,16 +27,18 @@
#![allow(clippy::single_char_add_str)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::recursive_format_impl)]
+#![allow(clippy::unwrap_or_default)]
#![allow(clippy::invisible_characters)]
+#![allow(invalid_reference_casting)]
#![allow(suspicious_double_ref_op)]
#![allow(invalid_nan_comparisons)]
-#![allow(invalid_reference_casting)]
#![allow(drop_bounds)]
#![allow(dropping_copy_types)]
#![allow(dropping_references)]
#![allow(for_loops_over_fallibles)]
#![allow(forgetting_copy_types)]
#![allow(forgetting_references)]
+#![allow(useless_ptr_null_checks)]
#![allow(array_into_iter)]
#![allow(invalid_atomic_ordering)]
#![allow(invalid_value)]
@@ -77,6 +79,7 @@
#![warn(clippy::single_char_add_str)]
#![warn(clippy::module_name_repetitions)]
#![warn(clippy::recursive_format_impl)]
+#![warn(clippy::unwrap_or_default)]
#![warn(clippy::invisible_characters)]
#![warn(invalid_reference_casting)]
#![warn(suspicious_double_ref_op)]
@@ -89,6 +92,7 @@
#![warn(for_loops_over_fallibles)]
#![warn(forgetting_copy_types)]
#![warn(forgetting_references)]
+#![warn(useless_ptr_null_checks)]
#![warn(array_into_iter)]
#![warn(invalid_atomic_ordering)]
#![warn(invalid_value)]
diff --git a/src/tools/clippy/tests/ui/rename.rs b/src/tools/clippy/tests/ui/rename.rs
index 399335aff..2e6ef60cb 100644
--- a/src/tools/clippy/tests/ui/rename.rs
+++ b/src/tools/clippy/tests/ui/rename.rs
@@ -27,16 +27,18 @@
#![allow(clippy::single_char_add_str)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::recursive_format_impl)]
+#![allow(clippy::unwrap_or_default)]
#![allow(clippy::invisible_characters)]
+#![allow(invalid_reference_casting)]
#![allow(suspicious_double_ref_op)]
#![allow(invalid_nan_comparisons)]
-#![allow(invalid_reference_casting)]
#![allow(drop_bounds)]
#![allow(dropping_copy_types)]
#![allow(dropping_references)]
#![allow(for_loops_over_fallibles)]
#![allow(forgetting_copy_types)]
#![allow(forgetting_references)]
+#![allow(useless_ptr_null_checks)]
#![allow(array_into_iter)]
#![allow(invalid_atomic_ordering)]
#![allow(invalid_value)]
@@ -77,6 +79,7 @@
#![warn(clippy::single_char_push_str)]
#![warn(clippy::stutter)]
#![warn(clippy::to_string_in_display)]
+#![warn(clippy::unwrap_or_else_default)]
#![warn(clippy::zero_width_space)]
#![warn(clippy::cast_ref_to_mut)]
#![warn(clippy::clone_double_ref)]
@@ -89,6 +92,7 @@
#![warn(clippy::for_loops_over_fallibles)]
#![warn(clippy::forget_copy)]
#![warn(clippy::forget_ref)]
+#![warn(clippy::fn_null_check)]
#![warn(clippy::into_iter_on_array)]
#![warn(clippy::invalid_atomic_ordering)]
#![warn(clippy::invalid_ref)]
diff --git a/src/tools/clippy/tests/ui/rename.stderr b/src/tools/clippy/tests/ui/rename.stderr
index 079371330..57e991e56 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:52:9
+ --> $DIR/rename.rs:54:9
|
LL | #![warn(clippy::almost_complete_letter_range)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range`
@@ -7,310 +7,322 @@ 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:53:9
+ --> $DIR/rename.rs:55: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:54:9
+ --> $DIR/rename.rs:56: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:55:9
+ --> $DIR/rename.rs:57: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:56:9
+ --> $DIR/rename.rs:58: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:57:9
+ --> $DIR/rename.rs:59: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:58:9
+ --> $DIR/rename.rs:60: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:59:9
+ --> $DIR/rename.rs:61: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:60:9
+ --> $DIR/rename.rs:62: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:61:9
+ --> $DIR/rename.rs:63: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:62:9
+ --> $DIR/rename.rs:64: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:63:9
+ --> $DIR/rename.rs:65: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:64:9
+ --> $DIR/rename.rs:66: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:65:9
+ --> $DIR/rename.rs:67: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:66:9
+ --> $DIR/rename.rs:68: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:67:9
+ --> $DIR/rename.rs:69: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:68:9
+ --> $DIR/rename.rs:70: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:69:9
+ --> $DIR/rename.rs:71: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:70:9
+ --> $DIR/rename.rs:72: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:71:9
+ --> $DIR/rename.rs:73: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:72:9
+ --> $DIR/rename.rs:74: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:73:9
+ --> $DIR/rename.rs:75: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:74:9
+ --> $DIR/rename.rs:76: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:75:9
+ --> $DIR/rename.rs:77: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:76:9
+ --> $DIR/rename.rs:78: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:77:9
+ --> $DIR/rename.rs:79: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:78:9
+ --> $DIR/rename.rs:80: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:79:9
+ --> $DIR/rename.rs:81:9
|
LL | #![warn(clippy::to_string_in_display)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl`
+error: lint `clippy::unwrap_or_else_default` has been renamed to `clippy::unwrap_or_default`
+ --> $DIR/rename.rs:82:9
+ |
+LL | #![warn(clippy::unwrap_or_else_default)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_or_default`
+
error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters`
- --> $DIR/rename.rs:80:9
+ --> $DIR/rename.rs:83: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
+ --> $DIR/rename.rs:84: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:82:9
+ --> $DIR/rename.rs:85: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
+ --> $DIR/rename.rs:86: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:84:9
+ --> $DIR/rename.rs:87: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:85:9
+ --> $DIR/rename.rs:88: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:86:9
+ --> $DIR/rename.rs:89: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:87:9
+ --> $DIR/rename.rs:90: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:88:9
+ --> $DIR/rename.rs:91: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:89:9
+ --> $DIR/rename.rs:92: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:90:9
+ --> $DIR/rename.rs:93: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:91:9
+ --> $DIR/rename.rs:94:9
|
LL | #![warn(clippy::forget_ref)]
| ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references`
+error: lint `clippy::fn_null_check` has been renamed to `useless_ptr_null_checks`
+ --> $DIR/rename.rs:95:9
+ |
+LL | #![warn(clippy::fn_null_check)]
+ | ^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `useless_ptr_null_checks`
+
error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter`
- --> $DIR/rename.rs:92:9
+ --> $DIR/rename.rs:96: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:93:9
+ --> $DIR/rename.rs:97: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:94:9
+ --> $DIR/rename.rs:98: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
+ --> $DIR/rename.rs:99: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:96:9
+ --> $DIR/rename.rs:100: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:97:9
+ --> $DIR/rename.rs:101: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:98:9
+ --> $DIR/rename.rs:102: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:99:9
+ --> $DIR/rename.rs:103: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:100:9
+ --> $DIR/rename.rs:104: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
+ --> $DIR/rename.rs:105: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:102:9
+ --> $DIR/rename.rs:106: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:103:9
+ --> $DIR/rename.rs:107:9
|
LL | #![warn(clippy::unused_label)]
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels`
-error: aborting due to 52 previous errors
+error: aborting due to 54 previous errors
diff --git a/src/tools/clippy/tests/ui/result_map_or_into_option.fixed b/src/tools/clippy/tests/ui/result_map_or_into_option.fixed
index 119ff2591..6850eeb7a 100644
--- a/src/tools/clippy/tests/ui/result_map_or_into_option.fixed
+++ b/src/tools/clippy/tests/ui/result_map_or_into_option.fixed
@@ -15,5 +15,5 @@ fn main() {
// A non-Some `f` closure where the argument is not used as the
// return should not emit the lint
let opt: Result<u32, &str> = Ok(1);
- opt.map_or(None, |_x| Some(1));
+ _ = opt.map_or(None, |_x| Some(1));
}
diff --git a/src/tools/clippy/tests/ui/result_map_or_into_option.rs b/src/tools/clippy/tests/ui/result_map_or_into_option.rs
index eeeef830a..8e1518144 100644
--- a/src/tools/clippy/tests/ui/result_map_or_into_option.rs
+++ b/src/tools/clippy/tests/ui/result_map_or_into_option.rs
@@ -15,5 +15,5 @@ fn main() {
// A non-Some `f` closure where the argument is not used as the
// return should not emit the lint
let opt: Result<u32, &str> = Ok(1);
- opt.map_or(None, |_x| Some(1));
+ _ = opt.map_or(None, |_x| Some(1));
}
diff --git a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.stderr b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.stderr
index 782febd52..ad941fa8b 100644
--- a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.stderr
+++ b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.stderr
@@ -4,7 +4,7 @@ error: called `map(f)` on an `Result` value where `f` is a function that returns
LL | x.field.map(do_nothing);
| ^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(x_field) = x.field { do_nothing(x_field) }`
+ | help: try: `if let Ok(x_field) = x.field { do_nothing(x_field) }`
|
= note: `-D clippy::result-map-unit-fn` implied by `-D warnings`
@@ -14,7 +14,7 @@ error: called `map(f)` on an `Result` value where `f` is a function that returns
LL | x.field.map(do_nothing);
| ^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(x_field) = x.field { do_nothing(x_field) }`
+ | help: try: `if let Ok(x_field) = x.field { do_nothing(x_field) }`
error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:39:5
@@ -22,7 +22,7 @@ error: called `map(f)` on an `Result` value where `f` is a function that returns
LL | x.field.map(diverge);
| ^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(x_field) = x.field { diverge(x_field) }`
+ | help: try: `if let Ok(x_field) = x.field { diverge(x_field) }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:45:5
@@ -30,7 +30,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| x.do_result_nothing(value + captured));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { x.do_result_nothing(value + captured) }`
+ | help: try: `if let Ok(value) = x.field { x.do_result_nothing(value + captured) }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:47:5
@@ -38,7 +38,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| { x.do_result_plus_one(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { x.do_result_plus_one(value + captured); }`
+ | help: try: `if let Ok(value) = x.field { x.do_result_plus_one(value + captured); }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:50:5
@@ -46,7 +46,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| do_nothing(value + captured));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { do_nothing(value + captured) }`
+ | help: try: `if let Ok(value) = x.field { do_nothing(value + captured) }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:52:5
@@ -54,7 +54,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| { do_nothing(value + captured) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { do_nothing(value + captured) }`
+ | help: try: `if let Ok(value) = x.field { do_nothing(value + captured) }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:54:5
@@ -62,7 +62,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| { do_nothing(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { do_nothing(value + captured); }`
+ | help: try: `if let Ok(value) = x.field { do_nothing(value + captured); }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:56:5
@@ -70,7 +70,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| { { do_nothing(value + captured); } });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { do_nothing(value + captured); }`
+ | help: try: `if let Ok(value) = x.field { do_nothing(value + captured); }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:59:5
@@ -78,7 +78,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| diverge(value + captured));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { diverge(value + captured) }`
+ | help: try: `if let Ok(value) = x.field { diverge(value + captured) }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:61:5
@@ -86,7 +86,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| { diverge(value + captured) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { diverge(value + captured) }`
+ | help: try: `if let Ok(value) = x.field { diverge(value + captured) }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:63:5
@@ -94,7 +94,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| { diverge(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { diverge(value + captured); }`
+ | help: try: `if let Ok(value) = x.field { diverge(value + captured); }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:65:5
@@ -102,7 +102,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| { { diverge(value + captured); } });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { diverge(value + captured); }`
+ | help: try: `if let Ok(value) = x.field { diverge(value + captured); }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:70:5
@@ -110,7 +110,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| { let y = plus_one(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { let y = plus_one(value + captured); }`
+ | help: try: `if let Ok(value) = x.field { let y = plus_one(value + captured); }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:72:5
@@ -118,7 +118,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| { plus_one(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { plus_one(value + captured); }`
+ | help: try: `if let Ok(value) = x.field { plus_one(value + captured); }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:74:5
@@ -126,7 +126,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| { { plus_one(value + captured); } });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { plus_one(value + captured); }`
+ | help: try: `if let Ok(value) = x.field { plus_one(value + captured); }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:77:5
@@ -134,7 +134,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|ref value| { do_nothing(value + captured) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(ref value) = x.field { do_nothing(value + captured) }`
+ | help: try: `if let Ok(ref value) = x.field { do_nothing(value + captured) }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_fixable.rs:79:5
@@ -142,7 +142,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| println!("{:?}", value));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { println!("{:?}", value) }`
+ | help: try: `if let Ok(value) = x.field { println!("{:?}", value) }`
error: aborting due to 18 previous errors
diff --git a/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr b/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr
index d0e534f63..75ec1ba80 100644
--- a/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr
+++ b/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr
@@ -4,7 +4,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| { do_nothing(value); do_nothing(value) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { ... }`
+ | help: try: `if let Ok(value) = x.field { ... }`
|
= note: `-D clippy::result-map-unit-fn` implied by `-D warnings`
@@ -14,7 +14,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { ... }`
+ | help: try: `if let Ok(value) = x.field { ... }`
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_unfixable.rs:29:5
@@ -23,7 +23,7 @@ LL | // x.field.map(|value| {
LL | || do_nothing(value);
LL | || do_nothing(value)
LL | || });
- | ||______^- help: try this: `if let Ok(value) = x.field { ... }`
+ | ||______^- help: try: `if let Ok(value) = x.field { ... }`
| |______|
|
@@ -33,7 +33,7 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
LL | x.field.map(|value| { do_nothing(value); do_nothing(value); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(value) = x.field { ... }`
+ | help: try: `if let Ok(value) = x.field { ... }`
error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()`
--> $DIR/result_map_unit_fn_unfixable.rs:37:5
@@ -41,7 +41,7 @@ error: called `map(f)` on an `Result` value where `f` is a function that returns
LL | "12".parse::<i32>().map(diverge);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(a) = "12".parse::<i32>() { diverge(a) }`
+ | help: try: `if let Ok(a) = "12".parse::<i32>() { diverge(a) }`
error: called `map(f)` on an `Result` value where `f` is a function that returns the unit type `()`
--> $DIR/result_map_unit_fn_unfixable.rs:43:5
@@ -49,7 +49,7 @@ error: called `map(f)` on an `Result` value where `f` is a function that returns
LL | y.map(do_nothing);
| ^^^^^^^^^^^^^^^^^-
| |
- | help: try this: `if let Ok(_y) = y { do_nothing(_y) }`
+ | help: try: `if let Ok(_y) = y { do_nothing(_y) }`
error: aborting due to 6 previous errors
diff --git a/src/tools/clippy/tests/ui/self_assignment.rs b/src/tools/clippy/tests/ui/self_assignment.rs
index ec3ae1209..a7f9fbaae 100644
--- a/src/tools/clippy/tests/ui/self_assignment.rs
+++ b/src/tools/clippy/tests/ui/self_assignment.rs
@@ -1,5 +1,5 @@
#![warn(clippy::self_assignment)]
-#![allow(clippy::useless_vec)]
+#![allow(clippy::useless_vec, clippy::needless_pass_by_ref_mut)]
pub struct S<'a> {
a: i32,
@@ -14,7 +14,7 @@ pub fn positives(mut a: usize, b: &mut u32, mut s: S) {
*b = *b;
s = s;
s.a = s.a;
- s.b[10] = s.b[5 + 5];
+ s.b[9] = s.b[5 + 4];
s.c[0][1] = s.c[0][1];
s.b[a] = s.b[a];
*s.e = *s.e;
diff --git a/src/tools/clippy/tests/ui/self_assignment.stderr b/src/tools/clippy/tests/ui/self_assignment.stderr
index bed88244e..25b8569fa 100644
--- a/src/tools/clippy/tests/ui/self_assignment.stderr
+++ b/src/tools/clippy/tests/ui/self_assignment.stderr
@@ -24,11 +24,11 @@ error: self-assignment of `s.a` to `s.a`
LL | s.a = s.a;
| ^^^^^^^^^
-error: self-assignment of `s.b[5 + 5]` to `s.b[10]`
+error: self-assignment of `s.b[5 + 4]` to `s.b[9]`
--> $DIR/self_assignment.rs:17:5
|
-LL | s.b[10] = s.b[5 + 5];
- | ^^^^^^^^^^^^^^^^^^^^
+LL | s.b[9] = s.b[5 + 4];
+ | ^^^^^^^^^^^^^^^^^^^
error: self-assignment of `s.c[0][1]` to `s.c[0][1]`
--> $DIR/self_assignment.rs:18:5
diff --git a/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.fixed b/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.fixed
new file mode 100644
index 000000000..653f4533b
--- /dev/null
+++ b/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.fixed
@@ -0,0 +1,123 @@
+//@run-rustfix
+#![warn(clippy::semicolon_if_nothing_returned)]
+#![allow(clippy::redundant_closure, clippy::uninlined_format_args, clippy::needless_late_init)]
+
+fn get_unit() {}
+
+// the functions below trigger the lint
+fn main() {
+ println!("Hello");
+}
+
+fn hello() {
+ get_unit();
+}
+
+fn basic101(x: i32) {
+ let y: i32;
+ y = x + 1;
+}
+
+#[rustfmt::skip]
+fn closure_error() {
+ let _d = || {
+ hello();
+ };
+}
+
+#[rustfmt::skip]
+fn unsafe_checks_error() {
+ use std::mem::MaybeUninit;
+ use std::ptr;
+
+ let mut s = MaybeUninit::<String>::uninit();
+ let _d = || unsafe {
+ ptr::drop_in_place(s.as_mut_ptr());
+ };
+}
+
+// this is fine
+fn print_sum(a: i32, b: i32) {
+ println!("{}", a + b);
+ assert_eq!(true, false);
+}
+
+fn foo(x: i32) {
+ let y: i32;
+ if x < 1 {
+ y = 4;
+ } else {
+ y = 5;
+ }
+}
+
+fn bar(x: i32) {
+ let y: i32;
+ match x {
+ 1 => y = 4,
+ _ => y = 32,
+ }
+}
+
+fn foobar(x: i32) {
+ let y: i32;
+ 'label: {
+ y = x + 1;
+ }
+}
+
+fn loop_test(x: i32) {
+ let y: i32;
+ for &ext in &["stdout", "stderr", "fixed"] {
+ println!("{}", ext);
+ }
+}
+
+fn closure() {
+ let _d = || hello();
+}
+
+#[rustfmt::skip]
+fn closure_block() {
+ let _d = || { hello() };
+}
+
+unsafe fn some_unsafe_op() {}
+unsafe fn some_other_unsafe_fn() {}
+
+fn do_something() {
+ unsafe { some_unsafe_op() };
+
+ unsafe { some_other_unsafe_fn() };
+}
+
+fn unsafe_checks() {
+ use std::mem::MaybeUninit;
+ use std::ptr;
+
+ let mut s = MaybeUninit::<String>::uninit();
+ let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()) };
+}
+
+// Issue #7768
+#[rustfmt::skip]
+fn macro_with_semicolon() {
+ macro_rules! repro {
+ () => {
+ while false {
+ }
+ };
+ }
+ repro!();
+}
+
+fn function_returning_option() -> Option<i32> {
+ Some(1)
+}
+
+// No warning
+fn let_else_stmts() {
+ let Some(x) = function_returning_option() else {
+ return;
+ };
+}
diff --git a/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs b/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs
index 4ab7dbab5..9db038219 100644
--- a/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs
+++ b/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs
@@ -1,5 +1,6 @@
+//@run-rustfix
#![warn(clippy::semicolon_if_nothing_returned)]
-#![allow(clippy::redundant_closure, clippy::uninlined_format_args)]
+#![allow(clippy::redundant_closure, clippy::uninlined_format_args, clippy::needless_late_init)]
fn get_unit() {}
@@ -116,5 +117,7 @@ fn function_returning_option() -> Option<i32> {
// No warning
fn let_else_stmts() {
- let Some(x) = function_returning_option() else { return; };
+ let Some(x) = function_returning_option() else {
+ return;
+ };
}
diff --git a/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.stderr b/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.stderr
index 8d9a67585..78813e7cc 100644
--- a/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.stderr
+++ b/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.stderr
@@ -1,5 +1,5 @@
error: consider adding a `;` to the last statement for consistent formatting
- --> $DIR/semicolon_if_nothing_returned.rs:8:5
+ --> $DIR/semicolon_if_nothing_returned.rs:9:5
|
LL | println!("Hello")
| ^^^^^^^^^^^^^^^^^ help: add a `;` here: `println!("Hello");`
@@ -7,25 +7,25 @@ LL | println!("Hello")
= note: `-D clippy::semicolon-if-nothing-returned` implied by `-D warnings`
error: consider adding a `;` to the last statement for consistent formatting
- --> $DIR/semicolon_if_nothing_returned.rs:12:5
+ --> $DIR/semicolon_if_nothing_returned.rs:13:5
|
LL | get_unit()
| ^^^^^^^^^^ help: add a `;` here: `get_unit();`
error: consider adding a `;` to the last statement for consistent formatting
- --> $DIR/semicolon_if_nothing_returned.rs:17:5
+ --> $DIR/semicolon_if_nothing_returned.rs:18:5
|
LL | y = x + 1
| ^^^^^^^^^ help: add a `;` here: `y = x + 1;`
error: consider adding a `;` to the last statement for consistent formatting
- --> $DIR/semicolon_if_nothing_returned.rs:23:9
+ --> $DIR/semicolon_if_nothing_returned.rs:24:9
|
LL | hello()
| ^^^^^^^ help: add a `;` here: `hello();`
error: consider adding a `;` to the last statement for consistent formatting
- --> $DIR/semicolon_if_nothing_returned.rs:34:9
+ --> $DIR/semicolon_if_nothing_returned.rs:35:9
|
LL | ptr::drop_in_place(s.as_mut_ptr())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `ptr::drop_in_place(s.as_mut_ptr());`
diff --git a/src/tools/clippy/tests/ui/shadow.rs b/src/tools/clippy/tests/ui/shadow.rs
index 9be8c5e59..1b40a43d0 100644
--- a/src/tools/clippy/tests/ui/shadow.rs
+++ b/src/tools/clippy/tests/ui/shadow.rs
@@ -1,7 +1,12 @@
//@aux-build:proc_macro_derive.rs:proc-macro
#![warn(clippy::shadow_same, clippy::shadow_reuse, clippy::shadow_unrelated)]
-#![allow(clippy::let_unit_value, clippy::needless_if)]
+#![allow(
+ clippy::let_unit_value,
+ clippy::needless_if,
+ clippy::redundant_guards,
+ clippy::redundant_locals
+)]
extern crate proc_macro_derive;
diff --git a/src/tools/clippy/tests/ui/shadow.stderr b/src/tools/clippy/tests/ui/shadow.stderr
index 8321f6df2..88b02f53b 100644
--- a/src/tools/clippy/tests/ui/shadow.stderr
+++ b/src/tools/clippy/tests/ui/shadow.stderr
@@ -1,278 +1,278 @@
error: `x` is shadowed by itself in `x`
- --> $DIR/shadow.rs:19:9
+ --> $DIR/shadow.rs:24:9
|
LL | let x = x;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:18:9
+ --> $DIR/shadow.rs:23:9
|
LL | let x = 1;
| ^
= note: `-D clippy::shadow-same` implied by `-D warnings`
error: `mut x` is shadowed by itself in `&x`
- --> $DIR/shadow.rs:20:13
+ --> $DIR/shadow.rs:25:13
|
LL | let mut x = &x;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:19:9
+ --> $DIR/shadow.rs:24:9
|
LL | let x = x;
| ^
error: `x` is shadowed by itself in `&mut x`
- --> $DIR/shadow.rs:21:9
+ --> $DIR/shadow.rs:26:9
|
LL | let x = &mut x;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:20:9
+ --> $DIR/shadow.rs:25:9
|
LL | let mut x = &x;
| ^^^^^
error: `x` is shadowed by itself in `*x`
- --> $DIR/shadow.rs:22:9
+ --> $DIR/shadow.rs:27:9
|
LL | let x = *x;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:21:9
+ --> $DIR/shadow.rs:26:9
|
LL | let x = &mut x;
| ^
error: `x` is shadowed
- --> $DIR/shadow.rs:27:9
+ --> $DIR/shadow.rs:32:9
|
LL | let x = x.0;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:26:9
+ --> $DIR/shadow.rs:31:9
|
LL | let x = ([[0]], ());
| ^
= note: `-D clippy::shadow-reuse` implied by `-D warnings`
error: `x` is shadowed
- --> $DIR/shadow.rs:28:9
+ --> $DIR/shadow.rs:33:9
|
LL | let x = x[0];
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:27:9
+ --> $DIR/shadow.rs:32:9
|
LL | let x = x.0;
| ^
error: `x` is shadowed
- --> $DIR/shadow.rs:29:10
+ --> $DIR/shadow.rs:34:10
|
LL | let [x] = x;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:28:9
+ --> $DIR/shadow.rs:33:9
|
LL | let x = x[0];
| ^
error: `x` is shadowed
- --> $DIR/shadow.rs:30:9
+ --> $DIR/shadow.rs:35:9
|
LL | let x = Some(x);
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:29:10
+ --> $DIR/shadow.rs:34:10
|
LL | let [x] = x;
| ^
error: `x` is shadowed
- --> $DIR/shadow.rs:31:9
+ --> $DIR/shadow.rs:36:9
|
LL | let x = foo(x);
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:30:9
+ --> $DIR/shadow.rs:35:9
|
LL | let x = Some(x);
| ^
error: `x` is shadowed
- --> $DIR/shadow.rs:32:9
+ --> $DIR/shadow.rs:37:9
|
LL | let x = || x;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:31:9
+ --> $DIR/shadow.rs:36:9
|
LL | let x = foo(x);
| ^
error: `x` is shadowed
- --> $DIR/shadow.rs:33:9
+ --> $DIR/shadow.rs:38:9
|
LL | let x = Some(1).map(|_| x)?;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:32:9
+ --> $DIR/shadow.rs:37:9
|
LL | let x = || x;
| ^
error: `y` is shadowed
- --> $DIR/shadow.rs:35:9
+ --> $DIR/shadow.rs:40:9
|
LL | let y = match y {
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:34:9
+ --> $DIR/shadow.rs:39:9
|
LL | let y = 1;
| ^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:50:9
+ --> $DIR/shadow.rs:55:9
|
LL | let x = 2;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:49:9
+ --> $DIR/shadow.rs:54:9
|
LL | let x = 1;
| ^
= note: `-D clippy::shadow-unrelated` implied by `-D warnings`
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:55:13
+ --> $DIR/shadow.rs:60:13
|
LL | let x = 1;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:54:10
+ --> $DIR/shadow.rs:59:10
|
LL | fn f(x: u32) {
| ^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:60:14
+ --> $DIR/shadow.rs:65:14
|
LL | Some(x) => {
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:57:9
+ --> $DIR/shadow.rs:62:9
|
LL | let x = 1;
| ^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:61:17
+ --> $DIR/shadow.rs:66:17
|
LL | let x = 1;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:60:14
+ --> $DIR/shadow.rs:65:14
|
LL | Some(x) => {
| ^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:65:17
+ --> $DIR/shadow.rs:70:17
|
LL | if let Some(x) = Some(1) {}
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:57:9
+ --> $DIR/shadow.rs:62:9
|
LL | let x = 1;
| ^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:66:20
+ --> $DIR/shadow.rs:71:20
|
LL | while let Some(x) = Some(1) {}
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:57:9
+ --> $DIR/shadow.rs:62:9
|
LL | let x = 1;
| ^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:67:15
+ --> $DIR/shadow.rs:72:15
|
LL | let _ = |[x]: [u32; 1]| {
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:57:9
+ --> $DIR/shadow.rs:62:9
|
LL | let x = 1;
| ^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:68:13
+ --> $DIR/shadow.rs:73:13
|
LL | let x = 1;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:67:15
+ --> $DIR/shadow.rs:72:15
|
LL | let _ = |[x]: [u32; 1]| {
| ^
error: `y` is shadowed
- --> $DIR/shadow.rs:71:17
+ --> $DIR/shadow.rs:76:17
|
LL | if let Some(y) = y {}
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:70:9
+ --> $DIR/shadow.rs:75:9
|
LL | let y = Some(1);
| ^
error: `_b` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:107:9
+ --> $DIR/shadow.rs:112:9
|
LL | let _b = _a;
| ^^
|
note: previous binding is here
- --> $DIR/shadow.rs:106:28
+ --> $DIR/shadow.rs:111:28
|
LL | pub async fn foo2(_a: i32, _b: i64) {
| ^^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:113:21
+ --> $DIR/shadow.rs:118:21
|
LL | if let Some(x) = Some(1) { x } else { 1 }
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:112:13
+ --> $DIR/shadow.rs:117:13
|
LL | let x = 1;
| ^
diff --git a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs
index 8c48b21f1..17df9f88f 100644
--- a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs
+++ b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs
@@ -7,8 +7,7 @@
use std::num::ParseIntError;
use std::ops::Deref;
use std::sync::atomic::{AtomicU64, Ordering};
-use std::sync::RwLock;
-use std::sync::{Mutex, MutexGuard};
+use std::sync::{Mutex, MutexGuard, RwLock};
struct State {}
diff --git a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.stderr b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.stderr
index 75063a8c9..b56ace200 100644
--- a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.stderr
+++ b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.stderr
@@ -1,5 +1,5 @@
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:56:11
+ --> $DIR/significant_drop_in_scrutinee.rs:55:11
|
LL | match mutex.lock().unwrap().foo() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -19,7 +19,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:142:11
+ --> $DIR/significant_drop_in_scrutinee.rs:141:11
|
LL | match s.lock_m().get_the_value() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -38,7 +38,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:163:11
+ --> $DIR/significant_drop_in_scrutinee.rs:162:11
|
LL | match s.lock_m_m().get_the_value() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -57,7 +57,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:211:11
+ --> $DIR/significant_drop_in_scrutinee.rs:210:11
|
LL | match counter.temp_increment().len() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -73,7 +73,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:234:16
+ --> $DIR/significant_drop_in_scrutinee.rs:233:16
|
LL | match (mutex1.lock().unwrap().s.len(), true) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -92,7 +92,7 @@ LL ~ match (value, true) {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:243:22
+ --> $DIR/significant_drop_in_scrutinee.rs:242:22
|
LL | match (true, mutex1.lock().unwrap().s.len(), true) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -111,7 +111,7 @@ LL ~ match (true, value, true) {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:253:16
+ --> $DIR/significant_drop_in_scrutinee.rs:252:16
|
LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -132,7 +132,7 @@ LL ~ match (value, true, mutex2.lock().unwrap().s.len()) {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:253:54
+ --> $DIR/significant_drop_in_scrutinee.rs:252:54
|
LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -153,7 +153,7 @@ LL ~ match (mutex1.lock().unwrap().s.len(), true, value) {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:264:15
+ --> $DIR/significant_drop_in_scrutinee.rs:263:15
|
LL | match mutex3.lock().unwrap().s.as_str() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -169,7 +169,7 @@ LL | };
= note: this might lead to deadlocks or other unexpected behavior
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:274:22
+ --> $DIR/significant_drop_in_scrutinee.rs:273:22
|
LL | match (true, mutex3.lock().unwrap().s.as_str()) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -185,7 +185,7 @@ LL | };
= note: this might lead to deadlocks or other unexpected behavior
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:293:11
+ --> $DIR/significant_drop_in_scrutinee.rs:292:11
|
LL | match mutex.lock().unwrap().s.len() > 1 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -204,7 +204,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:300:11
+ --> $DIR/significant_drop_in_scrutinee.rs:299:11
|
LL | match 1 < mutex.lock().unwrap().s.len() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -223,7 +223,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:318:11
+ --> $DIR/significant_drop_in_scrutinee.rs:317:11
|
LL | match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -244,7 +244,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:329:11
+ --> $DIR/significant_drop_in_scrutinee.rs:328:11
|
LL | match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -265,7 +265,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:364:11
+ --> $DIR/significant_drop_in_scrutinee.rs:363:11
|
LL | match get_mutex_guard().s.len() > 1 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -284,7 +284,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:381:11
+ --> $DIR/significant_drop_in_scrutinee.rs:380:11
|
LL | match match i {
| ___________^
@@ -316,7 +316,7 @@ LL ~ match value
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:407:11
+ --> $DIR/significant_drop_in_scrutinee.rs:406:11
|
LL | match if i > 1 {
| ___________^
@@ -349,7 +349,7 @@ LL ~ match value
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:461:11
+ --> $DIR/significant_drop_in_scrutinee.rs:460:11
|
LL | match s.lock().deref().deref() {
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -367,7 +367,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:489:11
+ --> $DIR/significant_drop_in_scrutinee.rs:488:11
|
LL | match s.lock().deref().deref() {
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -380,7 +380,7 @@ LL | };
= note: this might lead to deadlocks or other unexpected behavior
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:508:11
+ --> $DIR/significant_drop_in_scrutinee.rs:507:11
|
LL | match mutex.lock().unwrap().i = i {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -399,7 +399,7 @@ LL ~ match () {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:514:11
+ --> $DIR/significant_drop_in_scrutinee.rs:513:11
|
LL | match i = mutex.lock().unwrap().i {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -418,7 +418,7 @@ LL ~ match () {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:520:11
+ --> $DIR/significant_drop_in_scrutinee.rs:519:11
|
LL | match mutex.lock().unwrap().i += 1 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -437,7 +437,7 @@ LL ~ match () {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:526:11
+ --> $DIR/significant_drop_in_scrutinee.rs:525:11
|
LL | match i += mutex.lock().unwrap().i {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -456,7 +456,7 @@ LL ~ match () {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:589:11
+ --> $DIR/significant_drop_in_scrutinee.rs:588:11
|
LL | match rwlock.read().unwrap().to_number() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -467,7 +467,7 @@ LL | };
= note: this might lead to deadlocks or other unexpected behavior
error: temporary with significant `Drop` in `for` loop condition will live until the end of the `for` expression
- --> $DIR/significant_drop_in_scrutinee.rs:599:14
+ --> $DIR/significant_drop_in_scrutinee.rs:598:14
|
LL | for s in rwlock.read().unwrap().iter() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -478,7 +478,7 @@ LL | }
= note: this might lead to deadlocks or other unexpected behavior
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:614:11
+ --> $DIR/significant_drop_in_scrutinee.rs:613:11
|
LL | match mutex.lock().unwrap().foo() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/significant_drop_tightening.fixed b/src/tools/clippy/tests/ui/significant_drop_tightening.fixed
index 7b848ead7..8065e9e5f 100644
--- a/src/tools/clippy/tests/ui/significant_drop_tightening.fixed
+++ b/src/tools/clippy/tests/ui/significant_drop_tightening.fixed
@@ -28,6 +28,56 @@ pub fn issue_10413() {
}
}
+pub fn issue_11128() {
+ use std::mem::drop as unlock;
+
+ struct Foo {
+ droppable: Option<Vec<i32>>,
+ mutex: Mutex<Vec<i32>>,
+ }
+
+ impl Drop for Foo {
+ fn drop(&mut self) {
+ if let Some(droppable) = self.droppable.take() {
+ let lock = self.mutex.lock().unwrap();
+ let idx_opt = lock.iter().copied().find(|el| Some(el) == droppable.first());
+ if let Some(idx) = idx_opt {
+ let local_droppable = vec![lock.first().copied().unwrap_or_default()];
+ unlock(lock);
+ drop(local_droppable);
+ }
+ }
+ }
+ }
+}
+
+pub fn issue_11160() -> bool {
+ let mutex = Mutex::new(1i32);
+ let lock = mutex.lock().unwrap();
+ let _ = lock.abs();
+ true
+}
+
+pub fn issue_11189() {
+ struct Number {
+ pub value: u32,
+ }
+
+ fn do_something() -> Result<(), ()> {
+ let number = Mutex::new(Number { value: 1 });
+ let number2 = Mutex::new(Number { value: 2 });
+ let number3 = Mutex::new(Number { value: 3 });
+ let mut lock = number.lock().unwrap();
+ let mut lock2 = number2.lock().unwrap();
+ let mut lock3 = number3.lock().unwrap();
+ lock.value += 1;
+ lock2.value += 1;
+ lock3.value += 1;
+ drop((lock, lock2, lock3));
+ Ok(())
+ }
+}
+
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 36f77cf1b..1620b7684 100644
--- a/src/tools/clippy/tests/ui/significant_drop_tightening.rs
+++ b/src/tools/clippy/tests/ui/significant_drop_tightening.rs
@@ -27,6 +27,56 @@ pub fn issue_10413() {
}
}
+pub fn issue_11128() {
+ use std::mem::drop as unlock;
+
+ struct Foo {
+ droppable: Option<Vec<i32>>,
+ mutex: Mutex<Vec<i32>>,
+ }
+
+ impl Drop for Foo {
+ fn drop(&mut self) {
+ if let Some(droppable) = self.droppable.take() {
+ let lock = self.mutex.lock().unwrap();
+ let idx_opt = lock.iter().copied().find(|el| Some(el) == droppable.first());
+ if let Some(idx) = idx_opt {
+ let local_droppable = vec![lock.first().copied().unwrap_or_default()];
+ unlock(lock);
+ drop(local_droppable);
+ }
+ }
+ }
+ }
+}
+
+pub fn issue_11160() -> bool {
+ let mutex = Mutex::new(1i32);
+ let lock = mutex.lock().unwrap();
+ let _ = lock.abs();
+ true
+}
+
+pub fn issue_11189() {
+ struct Number {
+ pub value: u32,
+ }
+
+ fn do_something() -> Result<(), ()> {
+ let number = Mutex::new(Number { value: 1 });
+ let number2 = Mutex::new(Number { value: 2 });
+ let number3 = Mutex::new(Number { value: 3 });
+ let mut lock = number.lock().unwrap();
+ let mut lock2 = number2.lock().unwrap();
+ let mut lock3 = number3.lock().unwrap();
+ lock.value += 1;
+ lock2.value += 1;
+ lock3.value += 1;
+ drop((lock, lock2, lock3));
+ Ok(())
+ }
+}
+
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 3bdac0b0a..b5cad88ad 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:56:13
+ --> $DIR/significant_drop_tightening.rs:106: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:77:13
+ --> $DIR/significant_drop_tightening.rs:127: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:83:17
+ --> $DIR/significant_drop_tightening.rs:133:17
|
LL | / {
LL | | let mutex = Mutex::new(vec![1i32]);
diff --git a/src/tools/clippy/tests/ui/single_component_path_imports.fixed b/src/tools/clippy/tests/ui/single_component_path_imports.fixed
index d4d2cbbe5..b6b6b0288 100644
--- a/src/tools/clippy/tests/ui/single_component_path_imports.fixed
+++ b/src/tools/clippy/tests/ui/single_component_path_imports.fixed
@@ -4,8 +4,12 @@
use core;
+
+
use serde as edres;
+
pub use serde;
+
use std;
macro_rules! m {
diff --git a/src/tools/clippy/tests/ui/single_component_path_imports.rs b/src/tools/clippy/tests/ui/single_component_path_imports.rs
index 80d72115f..a8c4d8990 100644
--- a/src/tools/clippy/tests/ui/single_component_path_imports.rs
+++ b/src/tools/clippy/tests/ui/single_component_path_imports.rs
@@ -3,9 +3,13 @@
#![allow(unused_imports)]
use core;
+
use regex;
+
use serde as edres;
+
pub use serde;
+
use std;
macro_rules! m {
diff --git a/src/tools/clippy/tests/ui/single_component_path_imports.stderr b/src/tools/clippy/tests/ui/single_component_path_imports.stderr
index d69a86470..853a2fe0e 100644
--- a/src/tools/clippy/tests/ui/single_component_path_imports.stderr
+++ b/src/tools/clippy/tests/ui/single_component_path_imports.stderr
@@ -1,5 +1,5 @@
error: this import is redundant
- --> $DIR/single_component_path_imports.rs:6:1
+ --> $DIR/single_component_path_imports.rs:7:1
|
LL | use regex;
| ^^^^^^^^^^ help: remove it entirely
@@ -7,7 +7,7 @@ LL | use regex;
= note: `-D clippy::single-component-path-imports` implied by `-D warnings`
error: this import is redundant
- --> $DIR/single_component_path_imports.rs:29:5
+ --> $DIR/single_component_path_imports.rs:33:5
|
LL | use regex;
| ^^^^^^^^^^ help: remove it entirely
diff --git a/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.rs b/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.rs
index c75beb747..d6243c19f 100644
--- a/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.rs
+++ b/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.rs
@@ -2,7 +2,9 @@
#![allow(unused_imports)]
use regex;
+
use serde as edres;
+
pub use serde;
fn main() {
diff --git a/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr b/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr
index 330f28520..ff148355e 100644
--- a/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr
+++ b/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr
@@ -7,7 +7,7 @@ LL | use regex;
= note: `-D clippy::single-component-path-imports` implied by `-D warnings`
error: this import is redundant
- --> $DIR/single_component_path_imports_nested_first.rs:13:10
+ --> $DIR/single_component_path_imports_nested_first.rs:15:10
|
LL | use {regex, serde};
| ^^^^^
@@ -15,7 +15,7 @@ LL | use {regex, serde};
= help: remove this import
error: this import is redundant
- --> $DIR/single_component_path_imports_nested_first.rs:13:17
+ --> $DIR/single_component_path_imports_nested_first.rs:15:17
|
LL | use {regex, serde};
| ^^^^^
diff --git a/src/tools/clippy/tests/ui/single_component_path_imports_self_after.rs b/src/tools/clippy/tests/ui/single_component_path_imports_self_after.rs
index 48e8e5302..5723d480a 100644
--- a/src/tools/clippy/tests/ui/single_component_path_imports_self_after.rs
+++ b/src/tools/clippy/tests/ui/single_component_path_imports_self_after.rs
@@ -2,6 +2,7 @@
#![allow(unused_imports)]
use self::regex::{Regex as xeger, RegexSet as tesxeger};
+#[rustfmt::skip]
pub use self::{
regex::{Regex, RegexSet},
some_mod::SomeType,
diff --git a/src/tools/clippy/tests/ui/single_component_path_imports_self_before.rs b/src/tools/clippy/tests/ui/single_component_path_imports_self_before.rs
index 4fb0cf40b..8a4fbf0dc 100644
--- a/src/tools/clippy/tests/ui/single_component_path_imports_self_before.rs
+++ b/src/tools/clippy/tests/ui/single_component_path_imports_self_before.rs
@@ -4,6 +4,7 @@
use regex;
use self::regex::{Regex as xeger, RegexSet as tesxeger};
+#[rustfmt::skip]
pub use self::{
regex::{Regex, RegexSet},
some_mod::SomeType,
diff --git a/src/tools/clippy/tests/ui/single_match.fixed b/src/tools/clippy/tests/ui/single_match.fixed
index e7b1fd6a8..163ba94af 100644
--- a/src/tools/clippy/tests/ui/single_match.fixed
+++ b/src/tools/clippy/tests/ui/single_match.fixed
@@ -4,6 +4,7 @@
unused,
clippy::uninlined_format_args,
clippy::needless_if,
+ clippy::redundant_guards,
clippy::redundant_pattern_matching
)]
fn dummy() {}
diff --git a/src/tools/clippy/tests/ui/single_match.rs b/src/tools/clippy/tests/ui/single_match.rs
index 1515a7053..0dcdb125f 100644
--- a/src/tools/clippy/tests/ui/single_match.rs
+++ b/src/tools/clippy/tests/ui/single_match.rs
@@ -4,6 +4,7 @@
unused,
clippy::uninlined_format_args,
clippy::needless_if,
+ clippy::redundant_guards,
clippy::redundant_pattern_matching
)]
fn dummy() {}
diff --git a/src/tools/clippy/tests/ui/single_match.stderr b/src/tools/clippy/tests/ui/single_match.stderr
index ef9015132..d35361599 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:14:5
+ --> $DIR/single_match.rs:15:5
|
LL | / match x {
LL | | Some(y) => {
@@ -10,7 +10,7 @@ LL | | };
| |_____^
|
= note: `-D clippy::single-match` implied by `-D warnings`
-help: try this
+help: try
|
LL ~ if let Some(y) = x {
LL + println!("{:?}", 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:22:5
+ --> $DIR/single_match.rs:23:5
|
LL | / match x {
LL | | // Note the missing block braces.
@@ -27,136 +27,136 @@ LL | | // is expanded before we can do anything.
LL | | Some(y) => println!("{:?}", y),
LL | | _ => (),
LL | | }
- | |_____^ help: try this: `if let Some(y) = x { println!("{:?}", y) }`
+ | |_____^ help: try: `if let Some(y) = x { println!("{:?}", y) }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:31:5
+ --> $DIR/single_match.rs:32:5
|
LL | / match z {
LL | | (2..=3, 7..=9) => dummy(),
LL | | _ => {},
LL | | };
- | |_____^ help: try this: `if let (2..=3, 7..=9) = z { dummy() }`
+ | |_____^ help: try: `if let (2..=3, 7..=9) = z { dummy() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:60:5
+ --> $DIR/single_match.rs:61:5
|
LL | / match x {
LL | | Some(y) => dummy(),
LL | | None => (),
LL | | };
- | |_____^ help: try this: `if let Some(y) = x { dummy() }`
+ | |_____^ help: try: `if let Some(y) = x { dummy() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:65:5
+ --> $DIR/single_match.rs:66:5
|
LL | / match y {
LL | | Ok(y) => dummy(),
LL | | Err(..) => (),
LL | | };
- | |_____^ help: try this: `if let Ok(y) = y { dummy() }`
+ | |_____^ help: try: `if let Ok(y) = y { dummy() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:72:5
+ --> $DIR/single_match.rs:73:5
|
LL | / match c {
LL | | Cow::Borrowed(..) => dummy(),
LL | | Cow::Owned(..) => (),
LL | | };
- | |_____^ help: try this: `if let Cow::Borrowed(..) = c { dummy() }`
+ | |_____^ help: try: `if let Cow::Borrowed(..) = c { dummy() }`
error: you seem to be trying to use `match` for an equality check. Consider using `if`
- --> $DIR/single_match.rs:93:5
+ --> $DIR/single_match.rs:94:5
|
LL | / match x {
LL | | "test" => println!(),
LL | | _ => (),
LL | | }
- | |_____^ help: try this: `if x == "test" { println!() }`
+ | |_____^ help: try: `if x == "test" { println!() }`
error: you seem to be trying to use `match` for an equality check. Consider using `if`
- --> $DIR/single_match.rs:106:5
+ --> $DIR/single_match.rs:107:5
|
LL | / match x {
LL | | Foo::A => println!(),
LL | | _ => (),
LL | | }
- | |_____^ help: try this: `if x == Foo::A { println!() }`
+ | |_____^ help: try: `if x == Foo::A { println!() }`
error: you seem to be trying to use `match` for an equality check. Consider using `if`
- --> $DIR/single_match.rs:112:5
+ --> $DIR/single_match.rs:113:5
|
LL | / match x {
LL | | FOO_C => println!(),
LL | | _ => (),
LL | | }
- | |_____^ help: try this: `if x == FOO_C { println!() }`
+ | |_____^ help: try: `if x == FOO_C { println!() }`
error: you seem to be trying to use `match` for an equality check. Consider using `if`
- --> $DIR/single_match.rs:117:5
+ --> $DIR/single_match.rs:118:5
|
LL | / match &&x {
LL | | Foo::A => println!(),
LL | | _ => (),
LL | | }
- | |_____^ help: try this: `if x == Foo::A { println!() }`
+ | |_____^ help: try: `if x == Foo::A { println!() }`
error: you seem to be trying to use `match` for an equality check. Consider using `if`
- --> $DIR/single_match.rs:123:5
+ --> $DIR/single_match.rs:124:5
|
LL | / match &x {
LL | | Foo::A => println!(),
LL | | _ => (),
LL | | }
- | |_____^ help: try this: `if x == &Foo::A { println!() }`
+ | |_____^ help: try: `if x == &Foo::A { println!() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:140:5
+ --> $DIR/single_match.rs:141:5
|
LL | / match x {
LL | | Bar::A => println!(),
LL | | _ => (),
LL | | }
- | |_____^ help: try this: `if let Bar::A = x { println!() }`
+ | |_____^ help: try: `if let Bar::A = x { println!() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:148:5
+ --> $DIR/single_match.rs:149:5
|
LL | / match x {
LL | | None => println!(),
LL | | _ => (),
LL | | };
- | |_____^ help: try this: `if let None = x { println!() }`
+ | |_____^ help: try: `if let None = x { println!() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:170:5
+ --> $DIR/single_match.rs:171:5
|
LL | / match x {
LL | | (Some(_), _) => {},
LL | | (None, _) => {},
LL | | }
- | |_____^ help: try this: `if let (Some(_), _) = x {}`
+ | |_____^ help: try: `if let (Some(_), _) = x {}`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:176:5
+ --> $DIR/single_match.rs:177:5
|
LL | / match x {
LL | | (Some(E::V), _) => todo!(),
LL | | (_, _) => {},
LL | | }
- | |_____^ help: try this: `if let (Some(E::V), _) = x { todo!() }`
+ | |_____^ help: try: `if let (Some(E::V), _) = x { todo!() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:182:5
+ --> $DIR/single_match.rs:183:5
|
LL | / match (Some(42), Some(E::V), Some(42)) {
LL | | (.., Some(E::V), _) => {},
LL | | (..) => {},
LL | | }
- | |_____^ help: try this: `if let (.., Some(E::V), _) = (Some(42), Some(E::V), Some(42)) {}`
+ | |_____^ help: try: `if let (.., Some(E::V), _) = (Some(42), Some(E::V), Some(42)) {}`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:254:5
+ --> $DIR/single_match.rs:255:5
|
LL | / match bar {
LL | | Some(v) => unsafe {
@@ -167,7 +167,7 @@ LL | | _ => {},
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ if let Some(v) = bar { unsafe {
LL + let r = &v as *const i32;
@@ -176,7 +176,7 @@ LL + } }
|
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:262:5
+ --> $DIR/single_match.rs:263:5
|
LL | / match bar {
LL | | #[rustfmt::skip]
@@ -187,7 +187,7 @@ LL | | _ => {},
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ if let Some(v) = bar {
LL + unsafe {
diff --git a/src/tools/clippy/tests/ui/single_match_else.stderr b/src/tools/clippy/tests/ui/single_match_else.stderr
index 228236f3b..5e7d4062e 100644
--- a/src/tools/clippy/tests/ui/single_match_else.stderr
+++ b/src/tools/clippy/tests/ui/single_match_else.stderr
@@ -12,7 +12,7 @@ LL | | };
| |_____^
|
= note: `-D clippy::single-match-else` implied by `-D warnings`
-help: try this
+help: try
|
LL ~ let _ = if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else {
LL + let x = 5;
@@ -32,7 +32,7 @@ LL | | },
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ if let Some(a) = Some(1) { println!("${:?}", a) } else {
LL + println!("else block");
@@ -52,7 +52,7 @@ LL | | },
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ if let Some(a) = Some(1) { println!("${:?}", a) } else {
LL + println!("else block");
@@ -72,7 +72,7 @@ LL | | }
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ if let Ok(a) = Result::<i32, Infallible>::Ok(1) { println!("${:?}", a) } else {
LL + println!("else block");
@@ -92,7 +92,7 @@ LL | | }
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ if let Cow::Owned(a) = Cow::from("moo") { println!("${:?}", a) } else {
LL + println!("else block");
@@ -112,7 +112,7 @@ LL | | },
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ if let Some(v) = bar { unsafe {
LL + let r = &v as *const i32;
@@ -135,7 +135,7 @@ LL | | },
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ if let Some(v) = bar {
LL + println!("Some");
@@ -159,7 +159,7 @@ LL | | },
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ if let Some(v) = bar { unsafe {
LL + let r = &v as *const i32;
@@ -183,7 +183,7 @@ LL | | },
LL | | }
| |_____^
|
-help: try this
+help: try
|
LL ~ if let Some(v) = bar {
LL + unsafe {
diff --git a/src/tools/clippy/tests/ui/slow_vector_initialization.rs b/src/tools/clippy/tests/ui/slow_vector_initialization.rs
index 16be9f6d2..cfb856861 100644
--- a/src/tools/clippy/tests/ui/slow_vector_initialization.rs
+++ b/src/tools/clippy/tests/ui/slow_vector_initialization.rs
@@ -4,6 +4,7 @@ fn main() {
resize_vector();
extend_vector();
mixed_extend_resize_vector();
+ from_empty_vec();
}
fn extend_vector() {
@@ -59,6 +60,21 @@ fn resize_vector() {
vec1.resize(10, 0);
}
+fn from_empty_vec() {
+ // Resize with constant expression
+ let len = 300;
+ let mut vec1 = Vec::new();
+ vec1.resize(len, 0);
+
+ // Resize with len expression
+ let mut vec3 = Vec::new();
+ vec3.resize(len - 10, 0);
+
+ // Reinitialization should be warned
+ vec1 = Vec::new();
+ vec1.resize(10, 0);
+}
+
fn do_stuff(vec: &mut [u8]) {}
fn extend_vector_with_manipulations_between() {
diff --git a/src/tools/clippy/tests/ui/slow_vector_initialization.stderr b/src/tools/clippy/tests/ui/slow_vector_initialization.stderr
index cb3ce3e95..c88c97a55 100644
--- a/src/tools/clippy/tests/ui/slow_vector_initialization.stderr
+++ b/src/tools/clippy/tests/ui/slow_vector_initialization.stderr
@@ -1,76 +1,100 @@
error: slow zero-filling initialization
- --> $DIR/slow_vector_initialization.rs:13:5
+ --> $DIR/slow_vector_initialization.rs:14:5
|
LL | let mut vec1 = Vec::with_capacity(len);
- | ----------------------- help: consider replace allocation with: `vec![0; len]`
+ | ----------------------- help: consider replacing this with: `vec![0; len]`
LL | vec1.extend(repeat(0).take(len));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::slow-vector-initialization` implied by `-D warnings`
error: slow zero-filling initialization
- --> $DIR/slow_vector_initialization.rs:17:5
+ --> $DIR/slow_vector_initialization.rs:18:5
|
LL | let mut vec2 = Vec::with_capacity(len - 10);
- | ---------------------------- help: consider replace allocation with: `vec![0; len - 10]`
+ | ---------------------------- help: consider replacing this with: `vec![0; len - 10]`
LL | vec2.extend(repeat(0).take(len - 10));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: slow zero-filling initialization
- --> $DIR/slow_vector_initialization.rs:24:5
+ --> $DIR/slow_vector_initialization.rs:25:5
|
LL | let mut vec4 = Vec::with_capacity(len);
- | ----------------------- help: consider replace allocation with: `vec![0; len]`
+ | ----------------------- help: consider replacing this with: `vec![0; len]`
LL | vec4.extend(repeat(0).take(vec4.capacity()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: slow zero-filling initialization
- --> $DIR/slow_vector_initialization.rs:34:5
+ --> $DIR/slow_vector_initialization.rs:35:5
|
LL | let mut resized_vec = Vec::with_capacity(30);
- | ---------------------- help: consider replace allocation with: `vec![0; 30]`
+ | ---------------------- help: consider replacing this with: `vec![0; 30]`
LL | resized_vec.resize(30, 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: slow zero-filling initialization
- --> $DIR/slow_vector_initialization.rs:37:5
+ --> $DIR/slow_vector_initialization.rs:38:5
|
LL | let mut extend_vec = Vec::with_capacity(30);
- | ---------------------- help: consider replace allocation with: `vec![0; 30]`
+ | ---------------------- help: consider replacing this with: `vec![0; 30]`
LL | extend_vec.extend(repeat(0).take(30));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: slow zero-filling initialization
- --> $DIR/slow_vector_initialization.rs:44:5
+ --> $DIR/slow_vector_initialization.rs:45:5
|
LL | let mut vec1 = Vec::with_capacity(len);
- | ----------------------- help: consider replace allocation with: `vec![0; len]`
+ | ----------------------- help: consider replacing this with: `vec![0; len]`
LL | vec1.resize(len, 0);
| ^^^^^^^^^^^^^^^^^^^
error: slow zero-filling initialization
- --> $DIR/slow_vector_initialization.rs:52:5
+ --> $DIR/slow_vector_initialization.rs:53:5
|
LL | let mut vec3 = Vec::with_capacity(len - 10);
- | ---------------------------- help: consider replace allocation with: `vec![0; len - 10]`
+ | ---------------------------- help: consider replacing this with: `vec![0; len - 10]`
LL | vec3.resize(len - 10, 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: slow zero-filling initialization
- --> $DIR/slow_vector_initialization.rs:55:5
+ --> $DIR/slow_vector_initialization.rs:56:5
|
LL | let mut vec4 = Vec::with_capacity(len);
- | ----------------------- help: consider replace allocation with: `vec![0; len]`
+ | ----------------------- help: consider replacing this with: `vec![0; len]`
LL | vec4.resize(vec4.capacity(), 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: slow zero-filling initialization
- --> $DIR/slow_vector_initialization.rs:59:5
+ --> $DIR/slow_vector_initialization.rs:60:5
|
LL | vec1 = Vec::with_capacity(10);
- | ---------------------- help: consider replace allocation with: `vec![0; 10]`
+ | ---------------------- help: consider replacing this with: `vec![0; 10]`
LL | vec1.resize(10, 0);
| ^^^^^^^^^^^^^^^^^^
-error: aborting due to 9 previous errors
+error: slow zero-filling initialization
+ --> $DIR/slow_vector_initialization.rs:67:5
+ |
+LL | let mut vec1 = Vec::new();
+ | ---------- help: consider replacing this with: `vec![0; len]`
+LL | vec1.resize(len, 0);
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: slow zero-filling initialization
+ --> $DIR/slow_vector_initialization.rs:71:5
+ |
+LL | let mut vec3 = Vec::new();
+ | ---------- help: consider replacing this with: `vec![0; len - 10]`
+LL | vec3.resize(len - 10, 0);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: slow zero-filling initialization
+ --> $DIR/slow_vector_initialization.rs:75:5
+ |
+LL | vec1 = Vec::new();
+ | ---------- help: consider replacing this with: `vec![0; 10]`
+LL | vec1.resize(10, 0);
+ | ^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 12 previous errors
diff --git a/src/tools/clippy/tests/ui/string_extend.stderr b/src/tools/clippy/tests/ui/string_extend.stderr
index b35c77fd9..34b432901 100644
--- a/src/tools/clippy/tests/ui/string_extend.stderr
+++ b/src/tools/clippy/tests/ui/string_extend.stderr
@@ -2,7 +2,7 @@ error: calling `.extend(_.chars())`
--> $DIR/string_extend.rs:18:5
|
LL | s.extend(abc.chars());
- | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(abc)`
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str(abc)`
|
= note: `-D clippy::string-extend-chars` implied by `-D warnings`
@@ -10,19 +10,19 @@ error: calling `.extend(_.chars())`
--> $DIR/string_extend.rs:21:5
|
LL | s.extend("abc".chars());
- | ^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str("abc")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str("abc")`
error: calling `.extend(_.chars())`
--> $DIR/string_extend.rs:24:5
|
LL | s.extend(def.chars());
- | ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(&def)`
+ | ^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str(&def)`
error: calling `.extend(_.chars())`
--> $DIR/string_extend.rs:34:5
|
LL | s.extend(abc[0..2].chars());
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(&abc[0..2])`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `s.push_str(&abc[0..2])`
error: aborting due to 4 previous errors
diff --git a/src/tools/clippy/tests/ui/string_lit_chars_any.fixed b/src/tools/clippy/tests/ui/string_lit_chars_any.fixed
new file mode 100644
index 000000000..d7ab9c339
--- /dev/null
+++ b/src/tools/clippy/tests/ui/string_lit_chars_any.fixed
@@ -0,0 +1,50 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(clippy::eq_op, clippy::needless_raw_string_hashes, clippy::no_effect, unused)]
+#![warn(clippy::string_lit_chars_any)]
+
+#[macro_use]
+extern crate proc_macros;
+
+struct NotStringLit;
+
+impl NotStringLit {
+ fn chars(&self) -> impl Iterator<Item = char> {
+ "c".chars()
+ }
+}
+
+fn main() {
+ let c = 'c';
+ matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~');
+ matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~');
+ matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~');
+ matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~');
+ #[rustfmt::skip]
+ matches!(c, '\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~');
+ // Do not lint
+ NotStringLit.chars().any(|x| x == c);
+ "\\.+*?()|[]{}^$#&-~".chars().any(|x| {
+ let c = 'c';
+ x == c
+ });
+ "\\.+*?()|[]{}^$#&-~".chars().any(|x| {
+ 1;
+ x == c
+ });
+ "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == x);
+ "\\.+*?()|[]{}^$#&-~".chars().any(|_x| c == c);
+ matches!(
+ c,
+ '\\' | '.' | '+' | '*' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'
+ );
+ external! {
+ let c = 'c';
+ "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c);
+ }
+ with_span! {
+ span
+ let c = 'c';
+ "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c);
+ }
+}
diff --git a/src/tools/clippy/tests/ui/string_lit_chars_any.rs b/src/tools/clippy/tests/ui/string_lit_chars_any.rs
new file mode 100644
index 000000000..9408d7bb2
--- /dev/null
+++ b/src/tools/clippy/tests/ui/string_lit_chars_any.rs
@@ -0,0 +1,50 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs:proc-macro
+#![allow(clippy::eq_op, clippy::needless_raw_string_hashes, clippy::no_effect, unused)]
+#![warn(clippy::string_lit_chars_any)]
+
+#[macro_use]
+extern crate proc_macros;
+
+struct NotStringLit;
+
+impl NotStringLit {
+ fn chars(&self) -> impl Iterator<Item = char> {
+ "c".chars()
+ }
+}
+
+fn main() {
+ let c = 'c';
+ "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c);
+ r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c);
+ "\\.+*?()|[]{}^$#&-~".chars().any(|x| c == x);
+ r#"\.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x);
+ #[rustfmt::skip]
+ "\\.+*?()|[]{}^$#&-~".chars().any(|x| { x == c });
+ // Do not lint
+ NotStringLit.chars().any(|x| x == c);
+ "\\.+*?()|[]{}^$#&-~".chars().any(|x| {
+ let c = 'c';
+ x == c
+ });
+ "\\.+*?()|[]{}^$#&-~".chars().any(|x| {
+ 1;
+ x == c
+ });
+ "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == x);
+ "\\.+*?()|[]{}^$#&-~".chars().any(|_x| c == c);
+ matches!(
+ c,
+ '\\' | '.' | '+' | '*' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~'
+ );
+ external! {
+ let c = 'c';
+ "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c);
+ }
+ with_span! {
+ span
+ let c = 'c';
+ "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c);
+ }
+}
diff --git a/src/tools/clippy/tests/ui/string_lit_chars_any.stderr b/src/tools/clippy/tests/ui/string_lit_chars_any.stderr
new file mode 100644
index 000000000..ff951b73d
--- /dev/null
+++ b/src/tools/clippy/tests/ui/string_lit_chars_any.stderr
@@ -0,0 +1,58 @@
+error: usage of `.chars().any(...)` to check if a char matches any from a string literal
+ --> $DIR/string_lit_chars_any.rs:19:5
+ |
+LL | "//.+*?()|[]{}^$#&-~".chars().any(|x| x == c);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::string-lit-chars-any` implied by `-D warnings`
+help: use `matches!(...)` instead
+ |
+LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~');
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+error: usage of `.chars().any(...)` to check if a char matches any from a string literal
+ --> $DIR/string_lit_chars_any.rs:20:5
+ |
+LL | r#"/.+*?()|[]{}^$#&-~"#.chars().any(|x| x == c);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: use `matches!(...)` instead
+ |
+LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~');
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+error: usage of `.chars().any(...)` to check if a char matches any from a string literal
+ --> $DIR/string_lit_chars_any.rs:21:5
+ |
+LL | "//.+*?()|[]{}^$#&-~".chars().any(|x| c == x);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: use `matches!(...)` instead
+ |
+LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~');
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+error: usage of `.chars().any(...)` to check if a char matches any from a string literal
+ --> $DIR/string_lit_chars_any.rs:22:5
+ |
+LL | r#"/.+*?()|[]{}^$#&-~"#.chars().any(|x| c == x);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: use `matches!(...)` instead
+ |
+LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~');
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+error: usage of `.chars().any(...)` to check if a char matches any from a string literal
+ --> $DIR/string_lit_chars_any.rs:24:5
+ |
+LL | "//.+*?()|[]{}^$#&-~".chars().any(|x| { x == c });
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: use `matches!(...)` instead
+ |
+LL | matches!(c, '//' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~');
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+error: aborting due to 5 previous errors
+
diff --git a/src/tools/clippy/tests/ui/strlen_on_c_strings.stderr b/src/tools/clippy/tests/ui/strlen_on_c_strings.stderr
index 296268a5f..fcd17f689 100644
--- a/src/tools/clippy/tests/ui/strlen_on_c_strings.stderr
+++ b/src/tools/clippy/tests/ui/strlen_on_c_strings.stderr
@@ -2,7 +2,7 @@ error: using `libc::strlen` on a `CString` or `CStr` value
--> $DIR/strlen_on_c_strings.rs:15:13
|
LL | let _ = unsafe { libc::strlen(cstring.as_ptr()) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `cstring.as_bytes().len()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cstring.as_bytes().len()`
|
= note: `-D clippy::strlen-on-c-strings` implied by `-D warnings`
@@ -10,37 +10,37 @@ error: using `libc::strlen` on a `CString` or `CStr` value
--> $DIR/strlen_on_c_strings.rs:19:13
|
LL | let _ = unsafe { libc::strlen(cstr.as_ptr()) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `cstr.to_bytes().len()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cstr.to_bytes().len()`
error: using `libc::strlen` on a `CString` or `CStr` value
--> $DIR/strlen_on_c_strings.rs:21:13
|
LL | let _ = unsafe { strlen(cstr.as_ptr()) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `cstr.to_bytes().len()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cstr.to_bytes().len()`
error: using `libc::strlen` on a `CString` or `CStr` value
--> $DIR/strlen_on_c_strings.rs:24:22
|
LL | let _ = unsafe { strlen((*pcstr).as_ptr()) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `(*pcstr).to_bytes().len()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*pcstr).to_bytes().len()`
error: using `libc::strlen` on a `CString` or `CStr` value
--> $DIR/strlen_on_c_strings.rs:29:22
|
LL | let _ = unsafe { strlen(unsafe_identity(cstr).as_ptr()) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unsafe_identity(cstr).to_bytes().len()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unsafe_identity(cstr).to_bytes().len()`
error: using `libc::strlen` on a `CString` or `CStr` value
--> $DIR/strlen_on_c_strings.rs:30:13
|
LL | let _ = unsafe { strlen(unsafe { unsafe_identity(cstr) }.as_ptr()) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unsafe { unsafe_identity(cstr) }.to_bytes().len()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unsafe { unsafe_identity(cstr) }.to_bytes().len()`
error: using `libc::strlen` on a `CString` or `CStr` value
--> $DIR/strlen_on_c_strings.rs:33:22
|
LL | let _ = unsafe { strlen(f(cstr).as_ptr()) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `f(cstr).to_bytes().len()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `f(cstr).to_bytes().len()`
error: aborting due to 7 previous errors
diff --git a/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr b/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr
index 8bb3c8fbe..d93a55ba9 100644
--- a/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr
+++ b/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr
@@ -10,31 +10,31 @@ error: `^` is not the exponentiation operator
--> $DIR/suspicious_xor_used_as_pow.rs:20:13
|
LL | let _ = 2i32 ^ 9i32;
- | ^^^^^^^^^^^ help: did you mean to write: `2_i32.pow(9_i32)`
+ | ^^^^^^^^^^^ help: did you mean to write: `2i32.pow(9i32)`
error: `^` is not the exponentiation operator
--> $DIR/suspicious_xor_used_as_pow.rs:21:13
|
LL | let _ = 2i32 ^ 2i32;
- | ^^^^^^^^^^^ help: did you mean to write: `2_i32.pow(2_i32)`
+ | ^^^^^^^^^^^ help: did you mean to write: `2i32.pow(2i32)`
error: `^` is not the exponentiation operator
--> $DIR/suspicious_xor_used_as_pow.rs:22:13
|
LL | let _ = 50i32 ^ 3i32;
- | ^^^^^^^^^^^^ help: did you mean to write: `50_i32.pow(3_i32)`
+ | ^^^^^^^^^^^^ help: did you mean to write: `50i32.pow(3i32)`
error: `^` is not the exponentiation operator
--> $DIR/suspicious_xor_used_as_pow.rs:23:13
|
LL | let _ = 5i32 ^ 8i32;
- | ^^^^^^^^^^^ help: did you mean to write: `5_i32.pow(8_i32)`
+ | ^^^^^^^^^^^ help: did you mean to write: `5i32.pow(8i32)`
error: `^` is not the exponentiation operator
--> $DIR/suspicious_xor_used_as_pow.rs:24:13
|
LL | let _ = 2i32 ^ 32i32;
- | ^^^^^^^^^^^^ help: did you mean to write: `2_i32.pow(32_i32)`
+ | ^^^^^^^^^^^^ help: did you mean to write: `2i32.pow(32i32)`
error: `^` is not the exponentiation operator
--> $DIR/suspicious_xor_used_as_pow.rs:13:9
diff --git a/src/tools/clippy/tests/ui/swap.fixed b/src/tools/clippy/tests/ui/swap.fixed
index 22f904e3f..7b74a83b6 100644
--- a/src/tools/clippy/tests/ui/swap.fixed
+++ b/src/tools/clippy/tests/ui/swap.fixed
@@ -11,7 +11,8 @@
unused_assignments,
unused_variables,
clippy::let_and_return,
- clippy::useless_vec
+ clippy::useless_vec,
+ clippy::redundant_locals
)]
struct Foo(u32);
diff --git a/src/tools/clippy/tests/ui/swap.rs b/src/tools/clippy/tests/ui/swap.rs
index ada64f89e..93855cd7b 100644
--- a/src/tools/clippy/tests/ui/swap.rs
+++ b/src/tools/clippy/tests/ui/swap.rs
@@ -11,7 +11,8 @@
unused_assignments,
unused_variables,
clippy::let_and_return,
- clippy::useless_vec
+ clippy::useless_vec,
+ clippy::redundant_locals
)]
struct Foo(u32);
diff --git a/src/tools/clippy/tests/ui/swap.stderr b/src/tools/clippy/tests/ui/swap.stderr
index a3b9c2b74..1097b29bb 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:28:5
+ --> $DIR/swap.rs:29: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:40:5
+ --> $DIR/swap.rs:41: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:49:5
+ --> $DIR/swap.rs:50: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:68:5
+ --> $DIR/swap.rs:69: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:79:5
+ --> $DIR/swap.rs:80: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:87:5
+ --> $DIR/swap.rs:88: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:95:5
+ --> $DIR/swap.rs:96: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:124:5
+ --> $DIR/swap.rs:125: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:138:7
+ --> $DIR/swap.rs:139: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:147:7
+ --> $DIR/swap.rs:148: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:173:5
+ --> $DIR/swap.rs:174: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:135:5
+ --> $DIR/swap.rs:136: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:144:5
+ --> $DIR/swap.rs:145: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:151:5
+ --> $DIR/swap.rs:152: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:156:5
+ --> $DIR/swap.rs:157: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:160:5
+ --> $DIR/swap.rs:161: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:208:5
+ --> $DIR/swap.rs:209:5
|
LL | / let t = s.0.x;
LL | | s.0.x = s.0.y;
diff --git a/src/tools/clippy/tests/ui/to_digit_is_some.stderr b/src/tools/clippy/tests/ui/to_digit_is_some.stderr
index 10a1b393a..c4718825d 100644
--- a/src/tools/clippy/tests/ui/to_digit_is_some.stderr
+++ b/src/tools/clippy/tests/ui/to_digit_is_some.stderr
@@ -2,7 +2,7 @@ error: use of `.to_digit(..).is_some()`
--> $DIR/to_digit_is_some.rs:9:13
|
LL | let _ = d.to_digit(8).is_some();
- | ^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `d.is_digit(8)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `d.is_digit(8)`
|
= note: `-D clippy::to-digit-is-some` implied by `-D warnings`
@@ -10,7 +10,7 @@ error: use of `.to_digit(..).is_some()`
--> $DIR/to_digit_is_some.rs:10:13
|
LL | let _ = char::to_digit(c, 8).is_some();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `char::is_digit(c, 8)`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `char::is_digit(c, 8)`
error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs
index 486155831..86f5cc937 100644
--- a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs
+++ b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs
@@ -5,7 +5,8 @@
clippy::disallowed_names,
clippy::needless_lifetimes,
clippy::redundant_field_names,
- clippy::uninlined_format_args
+ clippy::uninlined_format_args,
+ clippy::needless_pass_by_ref_mut
)]
#[derive(Copy, Clone)]
diff --git a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr
index 8c5cfa8a0..2af668537 100644
--- a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr
+++ b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr
@@ -1,5 +1,5 @@
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:51:11
+ --> $DIR/trivially_copy_pass_by_ref.rs:52:11
|
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
@@ -11,103 +11,103 @@ LL | #![deny(clippy::trivially_copy_pass_by_ref)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:51:20
+ --> $DIR/trivially_copy_pass_by_ref.rs:52:20
|
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:51:29
+ --> $DIR/trivially_copy_pass_by_ref.rs:52:29
|
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:58:12
+ --> $DIR/trivially_copy_pass_by_ref.rs:59:12
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^^ help: consider passing by value instead: `self`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:58:22
+ --> $DIR/trivially_copy_pass_by_ref.rs:59:22
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:58:31
+ --> $DIR/trivially_copy_pass_by_ref.rs:59:31
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:58:40
+ --> $DIR/trivially_copy_pass_by_ref.rs:59:40
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:60:16
+ --> $DIR/trivially_copy_pass_by_ref.rs:61:16
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:60:25
+ --> $DIR/trivially_copy_pass_by_ref.rs:61:25
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:60:34
+ --> $DIR/trivially_copy_pass_by_ref.rs:61:34
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:62:35
+ --> $DIR/trivially_copy_pass_by_ref.rs:63:35
|
LL | fn bad_issue7518(self, other: &Self) {}
| ^^^^^ help: consider passing by value instead: `Self`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:74:16
+ --> $DIR/trivially_copy_pass_by_ref.rs:75:16
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:74:25
+ --> $DIR/trivially_copy_pass_by_ref.rs:75:25
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:74:34
+ --> $DIR/trivially_copy_pass_by_ref.rs:75:34
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:78:34
+ --> $DIR/trivially_copy_pass_by_ref.rs:79:34
|
LL | fn trait_method(&self, _foo: &Foo);
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:110:21
+ --> $DIR/trivially_copy_pass_by_ref.rs:111:21
|
LL | fn foo_never(x: &i32) {
| ^^^^ help: consider passing by value instead: `i32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:115:15
+ --> $DIR/trivially_copy_pass_by_ref.rs:116:15
|
LL | fn foo(x: &i32) {
| ^^^^ help: consider passing by value instead: `i32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:142:37
+ --> $DIR/trivially_copy_pass_by_ref.rs:143:37
|
LL | fn _unrelated_lifetimes<'a, 'b>(_x: &'a u32, y: &'b u32) -> &'b u32 {
| ^^^^^^^ help: consider passing by value instead: `u32`
diff --git a/src/tools/clippy/tests/ui/try_err.fixed b/src/tools/clippy/tests/ui/try_err.fixed
index 181674087..930489fab 100644
--- a/src/tools/clippy/tests/ui/try_err.fixed
+++ b/src/tools/clippy/tests/ui/try_err.fixed
@@ -2,7 +2,11 @@
//@aux-build:proc_macros.rs:proc-macro
#![deny(clippy::try_err)]
-#![allow(clippy::unnecessary_wraps, clippy::needless_question_mark)]
+#![allow(
+ clippy::unnecessary_wraps,
+ clippy::needless_question_mark,
+ clippy::needless_return_with_question_mark
+)]
extern crate proc_macros;
use proc_macros::{external, inline_macros};
diff --git a/src/tools/clippy/tests/ui/try_err.rs b/src/tools/clippy/tests/ui/try_err.rs
index 0e47c4d02..f5baf3d8f 100644
--- a/src/tools/clippy/tests/ui/try_err.rs
+++ b/src/tools/clippy/tests/ui/try_err.rs
@@ -2,7 +2,11 @@
//@aux-build:proc_macros.rs:proc-macro
#![deny(clippy::try_err)]
-#![allow(clippy::unnecessary_wraps, clippy::needless_question_mark)]
+#![allow(
+ clippy::unnecessary_wraps,
+ clippy::needless_question_mark,
+ clippy::needless_return_with_question_mark
+)]
extern crate proc_macros;
use proc_macros::{external, inline_macros};
diff --git a/src/tools/clippy/tests/ui/try_err.stderr b/src/tools/clippy/tests/ui/try_err.stderr
index 4ad0e2e56..9968b383e 100644
--- a/src/tools/clippy/tests/ui/try_err.stderr
+++ b/src/tools/clippy/tests/ui/try_err.stderr
@@ -1,8 +1,8 @@
error: returning an `Err(_)` with the `?` operator
- --> $DIR/try_err.rs:19:9
+ --> $DIR/try_err.rs:23:9
|
LL | Err(err)?;
- | ^^^^^^^^^ help: try this: `return Err(err)`
+ | ^^^^^^^^^ help: try: `return Err(err)`
|
note: the lint level is defined here
--> $DIR/try_err.rs:4:9
@@ -11,68 +11,68 @@ LL | #![deny(clippy::try_err)]
| ^^^^^^^^^^^^^^^
error: returning an `Err(_)` with the `?` operator
- --> $DIR/try_err.rs:29:9
+ --> $DIR/try_err.rs:33:9
|
LL | Err(err)?;
- | ^^^^^^^^^ help: try this: `return Err(err.into())`
+ | ^^^^^^^^^ help: try: `return Err(err.into())`
error: returning an `Err(_)` with the `?` operator
- --> $DIR/try_err.rs:49:17
+ --> $DIR/try_err.rs:53:17
|
LL | Err(err)?;
- | ^^^^^^^^^ help: try this: `return Err(err)`
+ | ^^^^^^^^^ help: try: `return Err(err)`
error: returning an `Err(_)` with the `?` operator
- --> $DIR/try_err.rs:68:17
+ --> $DIR/try_err.rs:72:17
|
LL | Err(err)?;
- | ^^^^^^^^^ help: try this: `return Err(err.into())`
+ | ^^^^^^^^^ help: try: `return Err(err.into())`
error: returning an `Err(_)` with the `?` operator
- --> $DIR/try_err.rs:88:23
+ --> $DIR/try_err.rs:92:23
|
LL | Err(_) => Err(1)?,
- | ^^^^^^^ help: try this: `return Err(1)`
+ | ^^^^^^^ help: try: `return Err(1)`
|
= note: this error originates in the macro `__inline_mac_fn_calling_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
error: returning an `Err(_)` with the `?` operator
- --> $DIR/try_err.rs:95:23
+ --> $DIR/try_err.rs:99:23
|
LL | Err(_) => Err(inline!(1))?,
- | ^^^^^^^^^^^^^^^^ help: try this: `return Err(inline!(1))`
+ | ^^^^^^^^^^^^^^^^ help: try: `return Err(inline!(1))`
|
= note: this error originates in the macro `__inline_mac_fn_calling_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
error: returning an `Err(_)` with the `?` operator
- --> $DIR/try_err.rs:122:9
+ --> $DIR/try_err.rs:126:9
|
LL | Err(inline!(inline!(String::from("aasdfasdfasdfa"))))?;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Err(inline!(inline!(String::from("aasdfasdfasdfa"))))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Err(inline!(inline!(String::from("aasdfasdfasdfa"))))`
error: returning an `Err(_)` with the `?` operator
- --> $DIR/try_err.rs:129:9
+ --> $DIR/try_err.rs:133:9
|
LL | Err(io::ErrorKind::WriteZero)?
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Err(io::ErrorKind::WriteZero.into()))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Poll::Ready(Err(io::ErrorKind::WriteZero.into()))`
error: returning an `Err(_)` with the `?` operator
- --> $DIR/try_err.rs:131:9
+ --> $DIR/try_err.rs:135:9
|
LL | Err(io::Error::new(io::ErrorKind::InvalidInput, "error"))?
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Err(io::Error::new(io::ErrorKind::InvalidInput, "error")))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Poll::Ready(Err(io::Error::new(io::ErrorKind::InvalidInput, "error")))`
error: returning an `Err(_)` with the `?` operator
- --> $DIR/try_err.rs:139:9
+ --> $DIR/try_err.rs:143:9
|
LL | Err(io::ErrorKind::NotFound)?
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into())))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into())))`
error: returning an `Err(_)` with the `?` operator
- --> $DIR/try_err.rs:148:16
+ --> $DIR/try_err.rs:152:16
|
LL | return Err(42)?;
- | ^^^^^^^^ help: try this: `Err(42)`
+ | ^^^^^^^^ help: try: `Err(42)`
error: aborting due to 11 previous errors
diff --git a/src/tools/clippy/tests/ui/tuple_array_conversions.rs b/src/tools/clippy/tests/ui/tuple_array_conversions.rs
index f96a7c97f..569415acb 100644
--- a/src/tools/clippy/tests/ui/tuple_array_conversions.rs
+++ b/src/tools/clippy/tests/ui/tuple_array_conversions.rs
@@ -52,6 +52,36 @@ fn main() {
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();
}
+ // FP #11082; needs discussion
+ let (a, b) = (1.0f64, 2.0f64);
+ let _: &[f64] = &[a, b];
+ // FP #11085; impossible to fix
+ let [src, dest]: [_; 2] = [1, 2];
+ (src, dest);
+ // FP #11100
+ fn issue_11100_array_to_tuple(this: [&mut i32; 2]) -> (&i32, &mut i32) {
+ let [input, output] = this;
+ (input, output)
+ }
+
+ fn issue_11100_tuple_to_array<'a>(this: (&'a mut i32, &'a mut i32)) -> [&'a i32; 2] {
+ let (input, output) = this;
+ [input, output]
+ }
+ // FP #11124
+ // tuple=>array
+ let (a, b) = (1, 2);
+ [a, b];
+ let x = a;
+ // array=>tuple
+ let [a, b] = [1, 2];
+ (a, b);
+ let x = a;
+ // FP #11144
+ let (a, (b, c)) = (1, (2, 3));
+ [a, c];
+ let [[a, b], [c, d]] = [[1, 2], [3, 4]];
+ (a, c);
}
#[clippy::msrv = "1.70.0"]
diff --git a/src/tools/clippy/tests/ui/tuple_array_conversions.stderr b/src/tools/clippy/tests/ui/tuple_array_conversions.stderr
index be653e8ef..50bdcf29d 100644
--- a/src/tools/clippy/tests/ui/tuple_array_conversions.stderr
+++ b/src/tools/clippy/tests/ui/tuple_array_conversions.stderr
@@ -15,14 +15,6 @@ 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
|
@@ -55,8 +47,24 @@ LL | t1.iter().for_each(|&(a, b)| _ = [a, b]);
|
= help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed
+error: it looks like you're trying to convert a tuple to an array
+ --> $DIR/tuple_array_conversions.rs:57:22
+ |
+LL | let _: &[f64] = &[a, b];
+ | ^^^^^^
+ |
+ = help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed
+
error: it looks like you're trying to convert an array to a tuple
- --> $DIR/tuple_array_conversions.rs:69:13
+ --> $DIR/tuple_array_conversions.rs:60:5
+ |
+LL | (src, dest);
+ | ^^^^^^^^^^^
+ |
+ = help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed
+
+error: it looks like you're trying to convert an array to a tuple
+ --> $DIR/tuple_array_conversions.rs:99:13
|
LL | let x = (x[0], x[1]);
| ^^^^^^^^^^^^
@@ -64,20 +72,12 @@ 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
+ --> $DIR/tuple_array_conversions.rs:100: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_id_on_box.fixed b/src/tools/clippy/tests/ui/type_id_on_box.fixed
new file mode 100644
index 000000000..615d809c8
--- /dev/null
+++ b/src/tools/clippy/tests/ui/type_id_on_box.fixed
@@ -0,0 +1,40 @@
+//@run-rustfix
+
+#![warn(clippy::type_id_on_box)]
+
+use std::any::{Any, TypeId};
+use std::ops::Deref;
+
+type SomeBox = Box<dyn Any>;
+
+struct BadBox(Box<dyn Any>);
+
+impl Deref for BadBox {
+ type Target = Box<dyn Any>;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+fn existential() -> impl Any {
+ Box::new(1) as Box<dyn Any>
+}
+
+fn main() {
+ let any_box: Box<dyn Any> = Box::new(0usize);
+ let _ = (*any_box).type_id();
+ let _ = TypeId::of::<Box<dyn Any>>(); // Don't lint. We explicitly say "do this instead" if this is intentional
+ let _ = (*any_box).type_id();
+ let any_box: &Box<dyn Any> = &(Box::new(0usize) as Box<dyn Any>);
+ let _ = (**any_box).type_id(); // 2 derefs are needed here to get to the `dyn Any`
+
+ let b = existential();
+ let _ = b.type_id(); // Don't lint.
+
+ let b: SomeBox = Box::new(0usize);
+ let _ = (*b).type_id();
+
+ let b = BadBox(Box::new(0usize));
+ let _ = b.type_id(); // Don't lint. This is a call to `<BadBox as Any>::type_id`. Not `std::boxed::Box`!
+}
diff --git a/src/tools/clippy/tests/ui/type_id_on_box.rs b/src/tools/clippy/tests/ui/type_id_on_box.rs
new file mode 100644
index 000000000..74b6c74ae
--- /dev/null
+++ b/src/tools/clippy/tests/ui/type_id_on_box.rs
@@ -0,0 +1,40 @@
+//@run-rustfix
+
+#![warn(clippy::type_id_on_box)]
+
+use std::any::{Any, TypeId};
+use std::ops::Deref;
+
+type SomeBox = Box<dyn Any>;
+
+struct BadBox(Box<dyn Any>);
+
+impl Deref for BadBox {
+ type Target = Box<dyn Any>;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+fn existential() -> impl Any {
+ Box::new(1) as Box<dyn Any>
+}
+
+fn main() {
+ let any_box: Box<dyn Any> = Box::new(0usize);
+ let _ = any_box.type_id();
+ let _ = TypeId::of::<Box<dyn Any>>(); // Don't lint. We explicitly say "do this instead" if this is intentional
+ let _ = (*any_box).type_id();
+ let any_box: &Box<dyn Any> = &(Box::new(0usize) as Box<dyn Any>);
+ let _ = any_box.type_id(); // 2 derefs are needed here to get to the `dyn Any`
+
+ let b = existential();
+ let _ = b.type_id(); // Don't lint.
+
+ let b: SomeBox = Box::new(0usize);
+ let _ = b.type_id();
+
+ let b = BadBox(Box::new(0usize));
+ let _ = b.type_id(); // Don't lint. This is a call to `<BadBox as Any>::type_id`. Not `std::boxed::Box`!
+}
diff --git a/src/tools/clippy/tests/ui/type_id_on_box.stderr b/src/tools/clippy/tests/ui/type_id_on_box.stderr
new file mode 100644
index 000000000..1525328c0
--- /dev/null
+++ b/src/tools/clippy/tests/ui/type_id_on_box.stderr
@@ -0,0 +1,36 @@
+error: calling `.type_id()` on a `Box<dyn Any>`
+ --> $DIR/type_id_on_box.rs:26:13
+ |
+LL | let _ = any_box.type_id();
+ | -------^^^^^^^^^^
+ | |
+ | help: consider dereferencing first: `(*any_box)`
+ |
+ = note: this returns the type id of the literal type `Box<dyn Any>` instead of the type id of the boxed value, which is most likely not what you want
+ = note: if this is intentional, use `TypeId::of::<Box<dyn Any>>()` instead, which makes it more clear
+ = note: `-D clippy::type-id-on-box` implied by `-D warnings`
+
+error: calling `.type_id()` on a `Box<dyn Any>`
+ --> $DIR/type_id_on_box.rs:30:13
+ |
+LL | let _ = any_box.type_id(); // 2 derefs are needed here to get to the `dyn Any`
+ | -------^^^^^^^^^^
+ | |
+ | help: consider dereferencing first: `(**any_box)`
+ |
+ = note: this returns the type id of the literal type `Box<dyn Any>` instead of the type id of the boxed value, which is most likely not what you want
+ = note: if this is intentional, use `TypeId::of::<Box<dyn Any>>()` instead, which makes it more clear
+
+error: calling `.type_id()` on a `Box<dyn Any>`
+ --> $DIR/type_id_on_box.rs:36:13
+ |
+LL | let _ = b.type_id();
+ | -^^^^^^^^^^
+ | |
+ | help: consider dereferencing first: `(*b)`
+ |
+ = note: this returns the type id of the literal type `Box<dyn Any>` instead of the type id of the boxed value, which is most likely not what you want
+ = note: if this is intentional, use `TypeId::of::<Box<dyn Any>>()` instead, which makes it more clear
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.fixed b/src/tools/clippy/tests/ui/unnecessary_cast.fixed
index 8efd44baf..2bf02f134 100644
--- a/src/tools/clippy/tests/ui/unnecessary_cast.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_cast.fixed
@@ -38,6 +38,16 @@ mod fake_libc {
}
}
+fn aaa() -> ::std::primitive::u32 {
+ 0
+}
+
+use std::primitive::u32 as UnsignedThirtyTwoBitInteger;
+
+fn bbb() -> UnsignedThirtyTwoBitInteger {
+ 0
+}
+
#[rustfmt::skip]
fn main() {
// Test cast_unnecessary
@@ -105,6 +115,13 @@ fn main() {
extern_fake_libc::getpid_SAFE_TRUTH() as i32;
let pid = unsafe { fake_libc::getpid() };
pid as i32;
+ aaa();
+ let x = aaa();
+ aaa();
+ // Will not lint currently.
+ bbb() as u32;
+ let x = bbb();
+ bbb() as u32;
let i8_ptr: *const i8 = &1;
let u8_ptr: *const u8 = &1;
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.rs b/src/tools/clippy/tests/ui/unnecessary_cast.rs
index c7723ef51..25b6b0f9b 100644
--- a/src/tools/clippy/tests/ui/unnecessary_cast.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_cast.rs
@@ -38,6 +38,16 @@ mod fake_libc {
}
}
+fn aaa() -> ::std::primitive::u32 {
+ 0
+}
+
+use std::primitive::u32 as UnsignedThirtyTwoBitInteger;
+
+fn bbb() -> UnsignedThirtyTwoBitInteger {
+ 0
+}
+
#[rustfmt::skip]
fn main() {
// Test cast_unnecessary
@@ -105,6 +115,13 @@ fn main() {
extern_fake_libc::getpid_SAFE_TRUTH() as i32;
let pid = unsafe { fake_libc::getpid() };
pid as i32;
+ aaa() as u32;
+ let x = aaa();
+ aaa() as u32;
+ // Will not lint currently.
+ bbb() as u32;
+ let x = bbb();
+ bbb() as u32;
let i8_ptr: *const i8 = &1;
let u8_ptr: *const u8 = &1;
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.stderr b/src/tools/clippy/tests/ui/unnecessary_cast.stderr
index f0443556f..19411a01b 100644
--- a/src/tools/clippy/tests/ui/unnecessary_cast.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_cast.stderr
@@ -7,226 +7,238 @@ LL | ptr as *const T
= note: `-D clippy::unnecessary-cast` implied by `-D warnings`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:44:5
+ --> $DIR/unnecessary_cast.rs:54:5
|
LL | 1i32 as i32;
| ^^^^^^^^^^^ help: try: `1_i32`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:45:5
+ --> $DIR/unnecessary_cast.rs:55:5
|
LL | 1f32 as f32;
| ^^^^^^^^^^^ help: try: `1_f32`
error: casting to the same type is unnecessary (`bool` -> `bool`)
- --> $DIR/unnecessary_cast.rs:46:5
+ --> $DIR/unnecessary_cast.rs:56:5
|
LL | false as bool;
| ^^^^^^^^^^^^^ help: try: `false`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:49:5
+ --> $DIR/unnecessary_cast.rs:59:5
|
LL | -1_i32 as i32;
| ^^^^^^^^^^^^^ help: try: `-1_i32`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:50:5
+ --> $DIR/unnecessary_cast.rs:60:5
|
LL | - 1_i32 as i32;
| ^^^^^^^^^^^^^^ help: try: `- 1_i32`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:51:5
+ --> $DIR/unnecessary_cast.rs:61:5
|
LL | -1f32 as f32;
| ^^^^^^^^^^^^ help: try: `-1_f32`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:52:5
+ --> $DIR/unnecessary_cast.rs:62:5
|
LL | 1_i32 as i32;
| ^^^^^^^^^^^^ help: try: `1_i32`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:53:5
+ --> $DIR/unnecessary_cast.rs:63: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
+ --> $DIR/unnecessary_cast.rs:65: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
+ --> $DIR/unnecessary_cast.rs:67:5
|
LL | [1u8, 2].as_ptr() as *const u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[1u8, 2].as_ptr()`
error: casting raw pointers to the same type and constness is unnecessary (`*mut u8` -> `*mut u8`)
- --> $DIR/unnecessary_cast.rs:59:5
+ --> $DIR/unnecessary_cast.rs:69:5
|
LL | [1u8, 2].as_mut_ptr() as *mut u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[1u8, 2].as_mut_ptr()`
error: casting raw pointers to the same type and constness is unnecessary (`*const u32` -> `*const u32`)
- --> $DIR/unnecessary_cast.rs:70:5
+ --> $DIR/unnecessary_cast.rs:80: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
+ --> $DIR/unnecessary_cast.rs:81: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
+ --> $DIR/unnecessary_cast.rs:83:5
|
LL | uwu::<u32, u32>([1u32].as_ptr()) as *const u32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `uwu::<u32, u32>([1u32].as_ptr())`
+error: casting to the same type is unnecessary (`u32` -> `u32`)
+ --> $DIR/unnecessary_cast.rs:118:5
+ |
+LL | aaa() as u32;
+ | ^^^^^^^^^^^^ help: try: `aaa()`
+
+error: casting to the same type is unnecessary (`u32` -> `u32`)
+ --> $DIR/unnecessary_cast.rs:120:5
+ |
+LL | aaa() as u32;
+ | ^^^^^^^^^^^^ help: try: `aaa()`
+
error: casting integer literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:139:9
+ --> $DIR/unnecessary_cast.rs:156:9
|
LL | 100 as f32;
| ^^^^^^^^^^ help: try: `100_f32`
error: casting integer literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:140:9
+ --> $DIR/unnecessary_cast.rs:157:9
|
LL | 100 as f64;
| ^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:141:9
+ --> $DIR/unnecessary_cast.rs:158:9
|
LL | 100_i32 as f64;
| ^^^^^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:142:17
+ --> $DIR/unnecessary_cast.rs:159:17
|
LL | let _ = -100 as f32;
| ^^^^^^^^^^^ help: try: `-100_f32`
error: casting integer literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:143:17
+ --> $DIR/unnecessary_cast.rs:160:17
|
LL | let _ = -100 as f64;
| ^^^^^^^^^^^ help: try: `-100_f64`
error: casting integer literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:144:17
+ --> $DIR/unnecessary_cast.rs:161:17
|
LL | let _ = -100_i32 as f64;
| ^^^^^^^^^^^^^^^ help: try: `-100_f64`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:145:9
+ --> $DIR/unnecessary_cast.rs:162:9
|
LL | 100. as f32;
| ^^^^^^^^^^^ help: try: `100_f32`
error: casting float literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:146:9
+ --> $DIR/unnecessary_cast.rs:163:9
|
LL | 100. as f64;
| ^^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `u32` is unnecessary
- --> $DIR/unnecessary_cast.rs:158:9
+ --> $DIR/unnecessary_cast.rs:175:9
|
LL | 1 as u32;
| ^^^^^^^^ help: try: `1_u32`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:159:9
+ --> $DIR/unnecessary_cast.rs:176:9
|
LL | 0x10 as i32;
| ^^^^^^^^^^^ help: try: `0x10_i32`
error: casting integer literal to `usize` is unnecessary
- --> $DIR/unnecessary_cast.rs:160:9
+ --> $DIR/unnecessary_cast.rs:177:9
|
LL | 0b10 as usize;
| ^^^^^^^^^^^^^ help: try: `0b10_usize`
error: casting integer literal to `u16` is unnecessary
- --> $DIR/unnecessary_cast.rs:161:9
+ --> $DIR/unnecessary_cast.rs:178:9
|
LL | 0o73 as u16;
| ^^^^^^^^^^^ help: try: `0o73_u16`
error: casting integer literal to `u32` is unnecessary
- --> $DIR/unnecessary_cast.rs:162:9
+ --> $DIR/unnecessary_cast.rs:179: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:164:9
+ --> $DIR/unnecessary_cast.rs:181:9
|
LL | 1.0 as f64;
| ^^^^^^^^^^ help: try: `1.0_f64`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:165:9
+ --> $DIR/unnecessary_cast.rs:182:9
|
LL | 0.5 as f32;
| ^^^^^^^^^^ help: try: `0.5_f32`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:169:17
+ --> $DIR/unnecessary_cast.rs:186:17
|
LL | let _ = -1 as i32;
| ^^^^^^^^^ help: try: `-1_i32`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:170:17
+ --> $DIR/unnecessary_cast.rs:187: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:176:18
+ --> $DIR/unnecessary_cast.rs:193:18
|
LL | let _ = &(x as i32);
| ^^^^^^^^^^ help: try: `{ x }`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:182:22
+ --> $DIR/unnecessary_cast.rs:199:22
|
LL | let _: i32 = -(1) as i32;
| ^^^^^^^^^^^ help: try: `-1_i32`
error: casting integer literal to `i64` is unnecessary
- --> $DIR/unnecessary_cast.rs:184:22
+ --> $DIR/unnecessary_cast.rs:201:22
|
LL | let _: i64 = -(1) as i64;
| ^^^^^^^^^^^ help: try: `-1_i64`
error: casting float literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:191:22
+ --> $DIR/unnecessary_cast.rs:208: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:193:23
+ --> $DIR/unnecessary_cast.rs:210: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:201:20
+ --> $DIR/unnecessary_cast.rs:218:20
|
LL | let _num = foo() as f32;
| ^^^^^^^^^^^^ help: try: `foo()`
-error: aborting due to 38 previous errors
+error: aborting due to 40 previous errors
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast_unfixable.rs b/src/tools/clippy/tests/ui/unnecessary_cast_unfixable.rs
new file mode 100644
index 000000000..0e027f604
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unnecessary_cast_unfixable.rs
@@ -0,0 +1,22 @@
+#![warn(clippy::unnecessary_cast)]
+
+fn main() {
+ let _ = std::ptr::null() as *const u8;
+}
+
+mod issue11113 {
+ #[repr(C)]
+ struct Vtbl {
+ query: unsafe extern "system" fn(),
+ }
+
+ struct TearOff {
+ object: *mut std::ffi::c_void,
+ }
+
+ impl TearOff {
+ unsafe fn query(&self) {
+ ((*(*(self.object as *mut *mut _) as *mut Vtbl)).query)()
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast_unfixable.stderr b/src/tools/clippy/tests/ui/unnecessary_cast_unfixable.stderr
new file mode 100644
index 000000000..eecf24568
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unnecessary_cast_unfixable.stderr
@@ -0,0 +1,16 @@
+error: casting raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`)
+ --> $DIR/unnecessary_cast_unfixable.rs:4:13
+ |
+LL | let _ = std::ptr::null() as *const u8;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::null()`
+ |
+ = note: `-D clippy::unnecessary-cast` implied by `-D warnings`
+
+error: casting raw pointers to the same type and constness is unnecessary (`*mut issue11113::Vtbl` -> `*mut issue11113::Vtbl`)
+ --> $DIR/unnecessary_cast_unfixable.rs:19:16
+ |
+LL | ((*(*(self.object as *mut *mut _) as *mut Vtbl)).query)()
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `*(self.object as *mut *mut _)`
+
+error: aborting due to 2 previous errors
+
diff --git a/src/tools/clippy/tests/ui/unnecessary_clone.stderr b/src/tools/clippy/tests/ui/unnecessary_clone.stderr
index 5686ab6b4..23639f6d4 100644
--- a/src/tools/clippy/tests/ui/unnecessary_clone.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_clone.stderr
@@ -2,7 +2,7 @@ error: using `.clone()` on a ref-counted pointer
--> $DIR/unnecessary_clone.rs:23:5
|
LL | rc.clone();
- | ^^^^^^^^^^ help: try this: `Rc::<bool>::clone(&rc)`
+ | ^^^^^^^^^^ help: try: `Rc::<bool>::clone(&rc)`
|
= note: `-D clippy::clone-on-ref-ptr` implied by `-D warnings`
@@ -10,25 +10,25 @@ error: using `.clone()` on a ref-counted pointer
--> $DIR/unnecessary_clone.rs:26:5
|
LL | arc.clone();
- | ^^^^^^^^^^^ help: try this: `Arc::<bool>::clone(&arc)`
+ | ^^^^^^^^^^^ help: try: `Arc::<bool>::clone(&arc)`
error: using `.clone()` on a ref-counted pointer
--> $DIR/unnecessary_clone.rs:29:5
|
LL | rcweak.clone();
- | ^^^^^^^^^^^^^^ help: try this: `Weak::<bool>::clone(&rcweak)`
+ | ^^^^^^^^^^^^^^ help: try: `Weak::<bool>::clone(&rcweak)`
error: using `.clone()` on a ref-counted pointer
--> $DIR/unnecessary_clone.rs:32:5
|
LL | arc_weak.clone();
- | ^^^^^^^^^^^^^^^^ help: try this: `Weak::<bool>::clone(&arc_weak)`
+ | ^^^^^^^^^^^^^^^^ help: try: `Weak::<bool>::clone(&arc_weak)`
error: using `.clone()` on a ref-counted pointer
--> $DIR/unnecessary_clone.rs:36:33
|
LL | let _: Arc<dyn SomeTrait> = x.clone();
- | ^^^^^^^^^ help: try this: `Arc::<SomeImpl>::clone(&x)`
+ | ^^^^^^^^^ help: try: `Arc::<SomeImpl>::clone(&x)`
error: using `clone` on type `T` which implements the `Copy` trait
--> $DIR/unnecessary_clone.rs:40:5
@@ -54,7 +54,7 @@ error: using `.clone()` on a ref-counted pointer
--> $DIR/unnecessary_clone.rs:95:14
|
LL | Some(try_opt!(Some(rc)).clone())
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `Rc::<u8>::clone(&try_opt!(Some(rc)))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Rc::<u8>::clone(&try_opt!(Some(rc)))`
error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/unnecessary_filter_map.rs b/src/tools/clippy/tests/ui/unnecessary_filter_map.rs
index 8e01c2674..3c8c6ec94 100644
--- a/src/tools/clippy/tests/ui/unnecessary_filter_map.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_filter_map.rs
@@ -148,3 +148,9 @@ mod comment_1052978898 {
})
}
}
+
+fn issue11260() {
+ // #11260 is about unnecessary_find_map, but the fix also kind of applies to
+ // unnecessary_filter_map
+ let _x = std::iter::once(1).filter_map(|n| (n > 1).then_some(n));
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_filter_map.stderr b/src/tools/clippy/tests/ui/unnecessary_filter_map.stderr
index 5585b10ab..2d5403ce3 100644
--- a/src/tools/clippy/tests/ui/unnecessary_filter_map.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_filter_map.stderr
@@ -34,5 +34,11 @@ error: this `.filter_map` can be written more simply using `.map`
LL | let _ = (0..4).filter_map(|x| Some(x + 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 4 previous errors
+error: this `.filter_map` can be written more simply using `.filter`
+ --> $DIR/unnecessary_filter_map.rs:155:14
+ |
+LL | let _x = std::iter::once(1).filter_map(|n| (n > 1).then_some(n));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 5 previous errors
diff --git a/src/tools/clippy/tests/ui/unnecessary_find_map.rs b/src/tools/clippy/tests/ui/unnecessary_find_map.rs
index a52390861..2c228fbbc 100644
--- a/src/tools/clippy/tests/ui/unnecessary_find_map.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_find_map.rs
@@ -21,3 +21,9 @@ fn main() {
fn find_map_none_changes_item_type() -> Option<bool> {
"".chars().find_map(|_| None)
}
+
+fn issue11260() {
+ let y = Some(1);
+ let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n));
+ let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(y)); // different option, so can't be just `.find()`
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_find_map.stderr b/src/tools/clippy/tests/ui/unnecessary_find_map.stderr
index fb33c122f..3a995b41b 100644
--- a/src/tools/clippy/tests/ui/unnecessary_find_map.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_find_map.stderr
@@ -34,5 +34,11 @@ error: this `.find_map` can be written more simply using `.map(..).next()`
LL | let _ = (0..4).find_map(|x| Some(x + 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 4 previous errors
+error: this `.find_map` can be written more simply using `.find`
+ --> $DIR/unnecessary_find_map.rs:27:14
+ |
+LL | let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 5 previous errors
diff --git a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.fixed b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.fixed
index 44530d8b1..72d52c623 100644
--- a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.fixed
@@ -79,6 +79,26 @@ fn unwrap_methods_result() {
1;
}
+fn unwrap_from_binding() {
+ macro_rules! from_macro {
+ () => {
+ Some("")
+ };
+ }
+ let val = from_macro!();
+ let _ = val.unwrap_or("");
+}
+
+fn unwrap_unchecked() {
+ let _ = 1;
+ let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe block
+ let _ = 1 + 1;
+ let _ = 1;
+ let _ = unsafe { 1 + *(&1 as *const i32) };
+ let _ = 1 + 1;
+ let _ = 123;
+}
+
fn main() {
unwrap_option_some();
unwrap_option_none();
@@ -86,4 +106,5 @@ fn main() {
unwrap_result_err();
unwrap_methods_option();
unwrap_methods_result();
+ unwrap_unchecked();
}
diff --git a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.rs b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.rs
index b43e4d3a3..7d713ea20 100644
--- a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.rs
@@ -79,6 +79,26 @@ fn unwrap_methods_result() {
Ok::<_, ()>(1).unwrap_or_else(|_| 2);
}
+fn unwrap_from_binding() {
+ macro_rules! from_macro {
+ () => {
+ Some("")
+ };
+ }
+ let val = from_macro!();
+ let _ = val.unwrap_or("");
+}
+
+fn unwrap_unchecked() {
+ let _ = unsafe { Some(1).unwrap_unchecked() };
+ let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block
+ let _ = unsafe { Some(1).unwrap_unchecked() } + 1;
+ let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() };
+ let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) };
+ let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1;
+ let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() };
+}
+
fn main() {
unwrap_option_some();
unwrap_option_none();
@@ -86,4 +106,5 @@ fn main() {
unwrap_result_err();
unwrap_methods_option();
unwrap_methods_result();
+ unwrap_unchecked();
}
diff --git a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.stderr b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.stderr
index 905384bc8..7f603d6ef 100644
--- a/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_literal_unwrap.stderr
@@ -517,5 +517,89 @@ LL - Ok::<_, ()>(1).unwrap_or_else(|_| 2);
LL + 1;
|
-error: aborting due to 46 previous errors
+error: used `unwrap_unchecked()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:93:22
+ |
+LL | let _ = unsafe { Some(1).unwrap_unchecked() };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_unchecked()`
+ |
+LL - let _ = unsafe { Some(1).unwrap_unchecked() };
+LL + let _ = 1;
+ |
+
+error: used `unwrap_unchecked()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:94:22
+ |
+LL | let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_unchecked()`
+ |
+LL - let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block
+LL + let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe block
+ |
+
+error: used `unwrap_unchecked()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:95:22
+ |
+LL | let _ = unsafe { Some(1).unwrap_unchecked() } + 1;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_unchecked()`
+ |
+LL - let _ = unsafe { Some(1).unwrap_unchecked() } + 1;
+LL + let _ = 1 + 1;
+ |
+
+error: used `unwrap_unchecked()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:96:22
+ |
+LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_unchecked()`
+ |
+LL - let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() };
+LL + let _ = 1;
+ |
+
+error: used `unwrap_unchecked()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:97:22
+ |
+LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_unchecked()`
+ |
+LL - let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) };
+LL + let _ = unsafe { 1 + *(&1 as *const i32) };
+ |
+
+error: used `unwrap_unchecked()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:98:22
+ |
+LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_unchecked()`
+ |
+LL - let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1;
+LL + let _ = 1 + 1;
+ |
+
+error: used `unwrap_err_unchecked()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap.rs:99:22
+ |
+LL | let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `unwrap_err_unchecked()`
+ |
+LL - let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() };
+LL + let _ = 123;
+ |
+
+error: aborting due to 53 previous errors
diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
index 592a53f3a..cb7562351 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
@@ -477,7 +477,8 @@ mod issue_10021 {
mod issue_10033 {
#![allow(dead_code)]
- use std::{fmt::Display, ops::Deref};
+ use std::fmt::Display;
+ use std::ops::Deref;
fn _main() {
let 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 f2e48b1c4..f82ddb2d2 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
@@ -477,7 +477,8 @@ mod issue_10021 {
mod issue_10033 {
#![allow(dead_code)]
- use std::{fmt::Display, ops::Deref};
+ use std::fmt::Display;
+ use std::ops::Deref;
fn _main() {
let f = Foo;
diff --git a/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs b/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs
index d29888ac6..04f6ef29a 100644
--- a/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs
+++ b/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs
@@ -8,9 +8,13 @@ use std::cell::UnsafeCell as TotallySafeCellAgain;
// Shouldn't error
use std::cell::RefCell as ProbablyNotUnsafe;
+
use std::cell::RefCell as RefCellThatCantBeUnsafe;
+
use std::cell::UnsafeCell as SuperDangerousUnsafeCell;
+
use std::cell::UnsafeCell as Dangerunsafe;
+
use std::cell::UnsafeCell as Bombsawayunsafe;
mod mod_with_some_unsafe_things {
@@ -20,8 +24,12 @@ mod mod_with_some_unsafe_things {
use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety;
+// merged imports
+use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B};
+
// Shouldn't error
use mod_with_some_unsafe_things::Safe as IPromiseItsSafeThisTime;
+
use mod_with_some_unsafe_things::Unsafe as SuperUnsafeModThing;
#[allow(clippy::unsafe_removed_from_name)]
diff --git a/src/tools/clippy/tests/ui/unsafe_removed_from_name.stderr b/src/tools/clippy/tests/ui/unsafe_removed_from_name.stderr
index 4f871cbe4..090d917bd 100644
--- a/src/tools/clippy/tests/ui/unsafe_removed_from_name.stderr
+++ b/src/tools/clippy/tests/ui/unsafe_removed_from_name.stderr
@@ -13,10 +13,22 @@ LL | use std::cell::UnsafeCell as TotallySafeCellAgain;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: removed `unsafe` from the name of `Unsafe` in use as `LieAboutModSafety`
- --> $DIR/unsafe_removed_from_name.rs:21:1
+ --> $DIR/unsafe_removed_from_name.rs:25:1
|
LL | use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 3 previous errors
+error: removed `unsafe` from the name of `Unsafe` in use as `A`
+ --> $DIR/unsafe_removed_from_name.rs:28:1
+ |
+LL | use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B};
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: removed `unsafe` from the name of `Unsafe` in use as `B`
+ --> $DIR/unsafe_removed_from_name.rs:28:1
+ |
+LL | use mod_with_some_unsafe_things::{Unsafe as A, Unsafe as B};
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 5 previous errors
diff --git a/src/tools/clippy/tests/ui/unused_async.rs b/src/tools/clippy/tests/ui/unused_async.rs
index 69e46ab47..1d188025e 100644
--- a/src/tools/clippy/tests/ui/unused_async.rs
+++ b/src/tools/clippy/tests/ui/unused_async.rs
@@ -37,6 +37,23 @@ mod issue10459 {
}
}
+mod issue9695 {
+ use std::future::Future;
+
+ async fn f() {}
+ async fn f2() {}
+ async fn f3() {}
+
+ fn needs_async_fn<F: Future<Output = ()>>(_: fn() -> F) {}
+
+ fn test() {
+ let x = f;
+ needs_async_fn(x); // async needed in f
+ needs_async_fn(f2); // async needed in f2
+ f3(); // async not needed in f3
+ }
+}
+
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 ffae8366b..8d9b72c48 100644
--- a/src/tools/clippy/tests/ui/unused_async.stderr
+++ b/src/tools/clippy/tests/ui/unused_async.stderr
@@ -17,7 +17,15 @@ 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
+ --> $DIR/unused_async.rs:45:5
+ |
+LL | async fn f3() {}
+ | ^^^^^^^^^^^^^^^^
+ |
+ = help: consider removing the `async` from this function
+
+error: unused `async` for function with no await statements
+ --> $DIR/unused_async.rs:57:1
|
LL | / async fn foo() -> i32 {
LL | | 4
@@ -27,7 +35,7 @@ LL | | }
= help: consider removing the `async` from this function
error: unused `async` for function with no await statements
- --> $DIR/unused_async.rs:51:5
+ --> $DIR/unused_async.rs:68:5
|
LL | / async fn unused(&self) -> i32 {
LL | | 1
@@ -36,5 +44,5 @@ LL | | }
|
= help: consider removing the `async` from this function
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
diff --git a/src/tools/clippy/tests/ui/unused_io_amount.rs b/src/tools/clippy/tests/ui/unused_io_amount.rs
index 8d3e094b7..e9d1eeb31 100644
--- a/src/tools/clippy/tests/ui/unused_io_amount.rs
+++ b/src/tools/clippy/tests/ui/unused_io_amount.rs
@@ -1,4 +1,4 @@
-#![allow(dead_code)]
+#![allow(dead_code, clippy::needless_pass_by_ref_mut)]
#![warn(clippy::unused_io_amount)]
extern crate futures;
diff --git a/src/tools/clippy/tests/ui/unused_peekable.rs b/src/tools/clippy/tests/ui/unused_peekable.rs
index 7374dfdf9..b227f8660 100644
--- a/src/tools/clippy/tests/ui/unused_peekable.rs
+++ b/src/tools/clippy/tests/ui/unused_peekable.rs
@@ -1,8 +1,7 @@
#![warn(clippy::unused_peekable)]
#![allow(clippy::no_effect)]
-use std::iter::Empty;
-use std::iter::Peekable;
+use std::iter::{Empty, Peekable};
fn main() {
invalid();
diff --git a/src/tools/clippy/tests/ui/unused_peekable.stderr b/src/tools/clippy/tests/ui/unused_peekable.stderr
index 54788f2fa..d969232fd 100644
--- a/src/tools/clippy/tests/ui/unused_peekable.stderr
+++ b/src/tools/clippy/tests/ui/unused_peekable.stderr
@@ -1,5 +1,5 @@
error: `peek` never called on `Peekable` iterator
- --> $DIR/unused_peekable.rs:14:9
+ --> $DIR/unused_peekable.rs:13:9
|
LL | let peekable = std::iter::empty::<u32>().peekable();
| ^^^^^^^^
@@ -8,7 +8,7 @@ LL | let peekable = std::iter::empty::<u32>().peekable();
= note: `-D clippy::unused-peekable` implied by `-D warnings`
error: `peek` never called on `Peekable` iterator
- --> $DIR/unused_peekable.rs:18:9
+ --> $DIR/unused_peekable.rs:17:9
|
LL | let new_local = old_local;
| ^^^^^^^^^
@@ -16,7 +16,7 @@ LL | let new_local = old_local;
= help: consider removing the call to `peekable`
error: `peek` never called on `Peekable` iterator
- --> $DIR/unused_peekable.rs:22:9
+ --> $DIR/unused_peekable.rs:21:9
|
LL | let by_mut_ref = &mut by_mut_ref_test;
| ^^^^^^^^^^
@@ -24,7 +24,7 @@ LL | let by_mut_ref = &mut by_mut_ref_test;
= help: consider removing the call to `peekable`
error: `peek` never called on `Peekable` iterator
- --> $DIR/unused_peekable.rs:29:9
+ --> $DIR/unused_peekable.rs:28:9
|
LL | let peekable_from_fn = returns_peekable();
| ^^^^^^^^^^^^^^^^
@@ -32,7 +32,7 @@ LL | let peekable_from_fn = returns_peekable();
= help: consider removing the call to `peekable`
error: `peek` never called on `Peekable` iterator
- --> $DIR/unused_peekable.rs:32:13
+ --> $DIR/unused_peekable.rs:31:13
|
LL | let mut peekable_using_iterator_method = std::iter::empty::<u32>().peekable();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,7 +40,7 @@ LL | let mut peekable_using_iterator_method = std::iter::empty::<u32>().peek
= help: consider removing the call to `peekable`
error: `peek` never called on `Peekable` iterator
- --> $DIR/unused_peekable.rs:37:9
+ --> $DIR/unused_peekable.rs:36:9
|
LL | let passed_along_ref = std::iter::empty::<u32>().peekable();
| ^^^^^^^^^^^^^^^^
@@ -48,7 +48,7 @@ LL | let passed_along_ref = std::iter::empty::<u32>().peekable();
= help: consider removing the call to `peekable`
error: `peek` never called on `Peekable` iterator
- --> $DIR/unused_peekable.rs:42:9
+ --> $DIR/unused_peekable.rs:41:9
|
LL | let _by_ref = by_ref_test.by_ref();
| ^^^^^^^
@@ -56,7 +56,7 @@ LL | let _by_ref = by_ref_test.by_ref();
= help: consider removing the call to `peekable`
error: `peek` never called on `Peekable` iterator
- --> $DIR/unused_peekable.rs:44:13
+ --> $DIR/unused_peekable.rs:43:13
|
LL | let mut peekable_in_for_loop = std::iter::empty::<u32>().peekable();
| ^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/unwrap.stderr b/src/tools/clippy/tests/ui/unwrap.stderr
index 3796d942f..41db819f6 100644
--- a/src/tools/clippy/tests/ui/unwrap.stderr
+++ b/src/tools/clippy/tests/ui/unwrap.stderr
@@ -4,7 +4,8 @@ error: used `unwrap()` on an `Option` value
LL | let _ = opt.unwrap();
| ^^^^^^^^^^^^
|
- = help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
+ = note: if this value is `None`, it will panic
+ = help: consider using `expect()` to provide a better panic message
= note: `-D clippy::unwrap-used` implied by `-D warnings`
error: used `unwrap()` on a `Result` value
@@ -13,7 +14,8 @@ error: used `unwrap()` on a `Result` value
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
+ = note: if this value is an `Err`, it will panic
+ = help: consider using `expect()` to provide a better panic message
error: used `unwrap_err()` on a `Result` value
--> $DIR/unwrap.rs:12:13
@@ -21,7 +23,8 @@ error: used `unwrap_err()` on a `Result` value
LL | let _ = res.unwrap_err();
| ^^^^^^^^^^^^^^^^
|
- = help: if you don't want to handle the `Ok` case gracefully, consider using `expect_err()` to provide a better panic message
+ = note: if this value is an `Ok`, it will panic
+ = help: consider using `expect_err()` to provide a better panic message
error: aborting due to 3 previous errors
diff --git a/src/tools/clippy/tests/ui/unwrap_expect_used.rs b/src/tools/clippy/tests/ui/unwrap_expect_used.rs
index 7f57efc53..26f92ccde 100644
--- a/src/tools/clippy/tests/ui/unwrap_expect_used.rs
+++ b/src/tools/clippy/tests/ui/unwrap_expect_used.rs
@@ -1,5 +1,8 @@
#![warn(clippy::unwrap_used, clippy::expect_used)]
#![allow(clippy::unnecessary_literal_unwrap)]
+#![feature(never_type)]
+
+use std::convert::Infallible;
trait OptionExt {
type Item;
@@ -28,6 +31,14 @@ fn main() {
Some(3).unwrap_err();
Some(3).expect_err("Hellow none!");
+ // Issue #11245: The `Err` variant can never be constructed so do not lint this.
+ let x: Result<(), !> = Ok(());
+ x.unwrap();
+ x.expect("is `!` (never)");
+ let x: Result<(), Infallible> = Ok(());
+ x.unwrap();
+ x.expect("is never-like (0 variants)");
+
let a: Result<i32, i32> = Ok(3);
a.unwrap();
a.expect("Hello world!");
diff --git a/src/tools/clippy/tests/ui/unwrap_expect_used.stderr b/src/tools/clippy/tests/ui/unwrap_expect_used.stderr
index 1a551ab5a..f66e47612 100644
--- a/src/tools/clippy/tests/ui/unwrap_expect_used.stderr
+++ b/src/tools/clippy/tests/ui/unwrap_expect_used.stderr
@@ -1,52 +1,52 @@
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_expect_used.rs:24:5
+ --> $DIR/unwrap_expect_used.rs:27:5
|
LL | Some(3).unwrap();
| ^^^^^^^^^^^^^^^^
|
- = help: if this value is `None`, it will panic
+ = note: if this value is `None`, it will panic
= note: `-D clippy::unwrap-used` implied by `-D warnings`
error: used `expect()` on an `Option` value
- --> $DIR/unwrap_expect_used.rs:25:5
+ --> $DIR/unwrap_expect_used.rs:28:5
|
LL | Some(3).expect("Hello world!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: if this value is `None`, it will panic
+ = note: if this value is `None`, it will panic
= note: `-D clippy::expect-used` implied by `-D warnings`
error: used `unwrap()` on a `Result` value
- --> $DIR/unwrap_expect_used.rs:32:5
+ --> $DIR/unwrap_expect_used.rs:43:5
|
LL | a.unwrap();
| ^^^^^^^^^^
|
- = help: if this value is an `Err`, it will panic
+ = note: if this value is an `Err`, it will panic
error: used `expect()` on a `Result` value
- --> $DIR/unwrap_expect_used.rs:33:5
+ --> $DIR/unwrap_expect_used.rs:44:5
|
LL | a.expect("Hello world!");
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: if this value is an `Err`, it will panic
+ = note: if this value is an `Err`, it will panic
error: used `unwrap_err()` on a `Result` value
- --> $DIR/unwrap_expect_used.rs:34:5
+ --> $DIR/unwrap_expect_used.rs:45:5
|
LL | a.unwrap_err();
| ^^^^^^^^^^^^^^
|
- = help: if this value is an `Ok`, it will panic
+ = note: if this value is an `Ok`, it will panic
error: used `expect_err()` on a `Result` value
- --> $DIR/unwrap_expect_used.rs:35:5
+ --> $DIR/unwrap_expect_used.rs:46:5
|
LL | a.expect_err("Hello error!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: if this value is an `Ok`, it will panic
+ = note: if this value is an `Ok`, it will panic
error: aborting due to 6 previous errors
diff --git a/src/tools/clippy/tests/ui/unwrap_or.stderr b/src/tools/clippy/tests/ui/unwrap_or.stderr
index cf720eaaf..e384bbbb0 100644
--- a/src/tools/clippy/tests/ui/unwrap_or.stderr
+++ b/src/tools/clippy/tests/ui/unwrap_or.stderr
@@ -2,7 +2,7 @@ error: use of `unwrap_or` followed by a function call
--> $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())`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| "Fail".to_string())`
|
= note: `-D clippy::or-fun-call` implied by `-D warnings`
@@ -10,7 +10,7 @@ error: use of `unwrap_or` followed by a function call
--> $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())`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| "Fail".to_string())`
error: aborting due to 2 previous errors
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 08b89a18b..acdb96942 100644
--- a/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed
+++ b/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed
@@ -1,10 +1,10 @@
//@run-rustfix
-#![warn(clippy::unwrap_or_else_default)]
+#![warn(clippy::unwrap_or_default)]
#![allow(dead_code)]
#![allow(clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)]
-/// Checks implementation of the `UNWRAP_OR_ELSE_DEFAULT` lint.
+/// Checks implementation of the `UNWRAP_OR_DEFAULT` lint.
fn unwrap_or_else_default() {
struct Foo;
@@ -74,4 +74,62 @@ fn unwrap_or_else_default() {
empty_string.unwrap_or_default();
}
+fn type_certainty(option: Option<Vec<u64>>) {
+ option.unwrap_or_default().push(1);
+
+ let option: std::option::Option<std::vec::Vec<u64>> = None;
+ option.unwrap_or_default().push(1);
+
+ let option: Option<Vec<u64>> = None;
+ option.unwrap_or_default().push(1);
+
+ let option = std::option::Option::<std::vec::Vec<u64>>::None;
+ option.unwrap_or_default().push(1);
+
+ let option = Option::<Vec<u64>>::None;
+ option.unwrap_or_default().push(1);
+
+ let option = std::option::Option::None::<std::vec::Vec<u64>>;
+ option.unwrap_or_default().push(1);
+
+ let option = Option::None::<Vec<u64>>;
+ option.unwrap_or_default().push(1);
+
+ let option = None::<Vec<u64>>;
+ option.unwrap_or_default().push(1);
+
+ // should not be changed: type annotation with infer, unconcretized initializer
+ let option: Option<Vec<_>> = None;
+ option.unwrap_or_else(Vec::new).push(1);
+
+ // should not be changed: no type annotation, unconcretized initializer
+ let option = Option::None;
+ option.unwrap_or_else(Vec::new).push(1);
+
+ // should not be changed: no type annotation, unconcretized initializer
+ let option = None;
+ option.unwrap_or_else(Vec::new).push(1);
+
+ type Alias = Option<Vec<u32>>;
+ let option: Alias = Option::<Vec<u32>>::Some(Vec::new());
+ option.unwrap_or_default().push(1);
+}
+
+fn method_call_with_deref() {
+ use std::cell::RefCell;
+ use std::collections::HashMap;
+
+ let cell = RefCell::new(HashMap::<u64, HashMap<u64, String>>::new());
+
+ let mut outer_map = cell.borrow_mut();
+
+ #[allow(unused_assignments)]
+ let mut option = None;
+ option = Some(0);
+
+ let inner_map = outer_map.get_mut(&option.unwrap()).unwrap();
+
+ let _ = inner_map.entry(0).or_default();
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/unwrap_or_else_default.rs b/src/tools/clippy/tests/ui/unwrap_or_else_default.rs
index ad2a74490..55ccd00e1 100644
--- a/src/tools/clippy/tests/ui/unwrap_or_else_default.rs
+++ b/src/tools/clippy/tests/ui/unwrap_or_else_default.rs
@@ -1,10 +1,10 @@
//@run-rustfix
-#![warn(clippy::unwrap_or_else_default)]
+#![warn(clippy::unwrap_or_default)]
#![allow(dead_code)]
#![allow(clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)]
-/// Checks implementation of the `UNWRAP_OR_ELSE_DEFAULT` lint.
+/// Checks implementation of the `UNWRAP_OR_DEFAULT` lint.
fn unwrap_or_else_default() {
struct Foo;
@@ -74,4 +74,62 @@ fn unwrap_or_else_default() {
empty_string.unwrap_or_else(|| "".to_string());
}
+fn type_certainty(option: Option<Vec<u64>>) {
+ option.unwrap_or_else(Vec::new).push(1);
+
+ let option: std::option::Option<std::vec::Vec<u64>> = None;
+ option.unwrap_or_else(Vec::new).push(1);
+
+ let option: Option<Vec<u64>> = None;
+ option.unwrap_or_else(Vec::new).push(1);
+
+ let option = std::option::Option::<std::vec::Vec<u64>>::None;
+ option.unwrap_or_else(Vec::new).push(1);
+
+ let option = Option::<Vec<u64>>::None;
+ option.unwrap_or_else(Vec::new).push(1);
+
+ let option = std::option::Option::None::<std::vec::Vec<u64>>;
+ option.unwrap_or_else(Vec::new).push(1);
+
+ let option = Option::None::<Vec<u64>>;
+ option.unwrap_or_else(Vec::new).push(1);
+
+ let option = None::<Vec<u64>>;
+ option.unwrap_or_else(Vec::new).push(1);
+
+ // should not be changed: type annotation with infer, unconcretized initializer
+ let option: Option<Vec<_>> = None;
+ option.unwrap_or_else(Vec::new).push(1);
+
+ // should not be changed: no type annotation, unconcretized initializer
+ let option = Option::None;
+ option.unwrap_or_else(Vec::new).push(1);
+
+ // should not be changed: no type annotation, unconcretized initializer
+ let option = None;
+ option.unwrap_or_else(Vec::new).push(1);
+
+ type Alias = Option<Vec<u32>>;
+ let option: Alias = Option::<Vec<u32>>::Some(Vec::new());
+ option.unwrap_or_else(Vec::new).push(1);
+}
+
+fn method_call_with_deref() {
+ use std::cell::RefCell;
+ use std::collections::HashMap;
+
+ let cell = RefCell::new(HashMap::<u64, HashMap<u64, String>>::new());
+
+ let mut outer_map = cell.borrow_mut();
+
+ #[allow(unused_assignments)]
+ let mut option = None;
+ option = Some(0);
+
+ let inner_map = outer_map.get_mut(&option.unwrap()).unwrap();
+
+ let _ = inner_map.entry(0).or_insert_with(Default::default);
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/unwrap_or_else_default.stderr b/src/tools/clippy/tests/ui/unwrap_or_else_default.stderr
index d2b921222..af662c6de 100644
--- a/src/tools/clippy/tests/ui/unwrap_or_else_default.stderr
+++ b/src/tools/clippy/tests/ui/unwrap_or_else_default.stderr
@@ -1,40 +1,100 @@
-error: use of `.unwrap_or_else(..)` to construct default value
- --> $DIR/unwrap_or_else_default.rs:48:5
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:48:14
|
LL | with_new.unwrap_or_else(Vec::new);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `with_new.unwrap_or_default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
|
- = note: `-D clippy::unwrap-or-else-default` implied by `-D warnings`
+ = note: `-D clippy::unwrap-or-default` implied by `-D warnings`
-error: use of `.unwrap_or_else(..)` to construct default value
- --> $DIR/unwrap_or_else_default.rs:62:5
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:62:23
|
LL | with_real_default.unwrap_or_else(<HasDefaultAndDuplicate as Default>::default);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `with_real_default.unwrap_or_default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
-error: use of `.unwrap_or_else(..)` to construct default value
- --> $DIR/unwrap_or_else_default.rs:65:5
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:65:24
|
LL | with_default_trait.unwrap_or_else(Default::default);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `with_default_trait.unwrap_or_default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
-error: use of `.unwrap_or_else(..)` to construct default value
- --> $DIR/unwrap_or_else_default.rs:68:5
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:68:23
|
LL | with_default_type.unwrap_or_else(u64::default);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `with_default_type.unwrap_or_default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
-error: use of `.unwrap_or_else(..)` to construct default value
- --> $DIR/unwrap_or_else_default.rs:71:5
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:71:23
|
LL | with_default_type.unwrap_or_else(Vec::new);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `with_default_type.unwrap_or_default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
-error: use of `.unwrap_or_else(..)` to construct default value
- --> $DIR/unwrap_or_else_default.rs:74:5
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:74:18
|
LL | empty_string.unwrap_or_else(|| "".to_string());
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `empty_string.unwrap_or_default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
-error: aborting due to 6 previous errors
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:78:12
+ |
+LL | option.unwrap_or_else(Vec::new).push(1);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
+
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:81:12
+ |
+LL | option.unwrap_or_else(Vec::new).push(1);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
+
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:84:12
+ |
+LL | option.unwrap_or_else(Vec::new).push(1);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
+
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:87:12
+ |
+LL | option.unwrap_or_else(Vec::new).push(1);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
+
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:90:12
+ |
+LL | option.unwrap_or_else(Vec::new).push(1);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
+
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:93:12
+ |
+LL | option.unwrap_or_else(Vec::new).push(1);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
+
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:96:12
+ |
+LL | option.unwrap_or_else(Vec::new).push(1);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
+
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:99:12
+ |
+LL | option.unwrap_or_else(Vec::new).push(1);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
+
+error: use of `unwrap_or_else` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:115:12
+ |
+LL | option.unwrap_or_else(Vec::new).push(1);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
+
+error: use of `or_insert_with` to construct default value
+ --> $DIR/unwrap_or_else_default.rs:132:32
+ |
+LL | let _ = inner_map.entry(0).or_insert_with(Default::default);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()`
+
+error: aborting due to 16 previous errors
diff --git a/src/tools/clippy/tests/ui/useless_asref.fixed b/src/tools/clippy/tests/ui/useless_asref.fixed
index 490d36ae6..e42731f9b 100644
--- a/src/tools/clippy/tests/ui/useless_asref.fixed
+++ b/src/tools/clippy/tests/ui/useless_asref.fixed
@@ -1,6 +1,10 @@
//@run-rustfix
#![deny(clippy::useless_asref)]
-#![allow(clippy::explicit_auto_deref, clippy::uninlined_format_args)]
+#![allow(
+ clippy::explicit_auto_deref,
+ clippy::uninlined_format_args,
+ clippy::needless_pass_by_ref_mut
+)]
use std::fmt::Debug;
diff --git a/src/tools/clippy/tests/ui/useless_asref.rs b/src/tools/clippy/tests/ui/useless_asref.rs
index f2681af92..50c9990bb 100644
--- a/src/tools/clippy/tests/ui/useless_asref.rs
+++ b/src/tools/clippy/tests/ui/useless_asref.rs
@@ -1,6 +1,10 @@
//@run-rustfix
#![deny(clippy::useless_asref)]
-#![allow(clippy::explicit_auto_deref, clippy::uninlined_format_args)]
+#![allow(
+ clippy::explicit_auto_deref,
+ clippy::uninlined_format_args,
+ clippy::needless_pass_by_ref_mut
+)]
use std::fmt::Debug;
diff --git a/src/tools/clippy/tests/ui/useless_asref.stderr b/src/tools/clippy/tests/ui/useless_asref.stderr
index 67ce8b64e..c97851ac6 100644
--- a/src/tools/clippy/tests/ui/useless_asref.stderr
+++ b/src/tools/clippy/tests/ui/useless_asref.stderr
@@ -1,8 +1,8 @@
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:43:18
+ --> $DIR/useless_asref.rs:47:18
|
LL | foo_rstr(rstr.as_ref());
- | ^^^^^^^^^^^^^ help: try this: `rstr`
+ | ^^^^^^^^^^^^^ help: try: `rstr`
|
note: the lint level is defined here
--> $DIR/useless_asref.rs:2:9
@@ -11,64 +11,64 @@ LL | #![deny(clippy::useless_asref)]
| ^^^^^^^^^^^^^^^^^^^^^
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:45:20
+ --> $DIR/useless_asref.rs:49:20
|
LL | foo_rslice(rslice.as_ref());
- | ^^^^^^^^^^^^^^^ help: try this: `rslice`
+ | ^^^^^^^^^^^^^^^ help: try: `rslice`
error: this call to `as_mut` does nothing
- --> $DIR/useless_asref.rs:49:21
+ --> $DIR/useless_asref.rs:53:21
|
LL | foo_mrslice(mrslice.as_mut());
- | ^^^^^^^^^^^^^^^^ help: try this: `mrslice`
+ | ^^^^^^^^^^^^^^^^ help: try: `mrslice`
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:51:20
+ --> $DIR/useless_asref.rs:55:20
|
LL | foo_rslice(mrslice.as_ref());
- | ^^^^^^^^^^^^^^^^ help: try this: `mrslice`
+ | ^^^^^^^^^^^^^^^^ help: try: `mrslice`
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:58:20
+ --> $DIR/useless_asref.rs:62:20
|
LL | foo_rslice(rrrrrslice.as_ref());
- | ^^^^^^^^^^^^^^^^^^^ help: try this: `rrrrrslice`
+ | ^^^^^^^^^^^^^^^^^^^ help: try: `rrrrrslice`
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:60:18
+ --> $DIR/useless_asref.rs:64:18
|
LL | foo_rstr(rrrrrstr.as_ref());
- | ^^^^^^^^^^^^^^^^^ help: try this: `rrrrrstr`
+ | ^^^^^^^^^^^^^^^^^ help: try: `rrrrrstr`
error: this call to `as_mut` does nothing
- --> $DIR/useless_asref.rs:65:21
+ --> $DIR/useless_asref.rs:69:21
|
LL | foo_mrslice(mrrrrrslice.as_mut());
- | ^^^^^^^^^^^^^^^^^^^^ help: try this: `mrrrrrslice`
+ | ^^^^^^^^^^^^^^^^^^^^ help: try: `mrrrrrslice`
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:67:20
+ --> $DIR/useless_asref.rs:71:20
|
LL | foo_rslice(mrrrrrslice.as_ref());
- | ^^^^^^^^^^^^^^^^^^^^ help: try this: `mrrrrrslice`
+ | ^^^^^^^^^^^^^^^^^^^^ help: try: `mrrrrrslice`
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:71:16
+ --> $DIR/useless_asref.rs:75:16
|
LL | foo_rrrrmr((&&&&MoreRef).as_ref());
- | ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `(&&&&MoreRef)`
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `(&&&&MoreRef)`
error: this call to `as_mut` does nothing
- --> $DIR/useless_asref.rs:121:13
+ --> $DIR/useless_asref.rs:125:13
|
LL | foo_mrt(mrt.as_mut());
- | ^^^^^^^^^^^^ help: try this: `mrt`
+ | ^^^^^^^^^^^^ help: try: `mrt`
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:123:12
+ --> $DIR/useless_asref.rs:127:12
|
LL | foo_rt(mrt.as_ref());
- | ^^^^^^^^^^^^ help: try this: `mrt`
+ | ^^^^^^^^^^^^ help: try: `mrt`
error: aborting due to 11 previous errors
diff --git a/src/tools/clippy/tests/ui/vec.fixed b/src/tools/clippy/tests/ui/vec.fixed
index fcdc917c1..7a7d0026f 100644
--- a/src/tools/clippy/tests/ui/vec.fixed
+++ b/src/tools/clippy/tests/ui/vec.fixed
@@ -115,6 +115,46 @@ fn main() {
let _x = vec![1; 201];
}
+fn issue11075() {
+ macro_rules! repro {
+ ($e:expr) => {
+ stringify!($e)
+ };
+ }
+ for _string in [repro!(true), repro!(null)] {
+ unimplemented!();
+ }
+
+ macro_rules! in_macro {
+ ($e:expr, $vec:expr, $vec2:expr) => {{
+ vec![1; 2].fill(3);
+ vec![1, 2].fill(3);
+ for _ in vec![1, 2] {}
+ for _ in vec![1; 2] {}
+ for _ in vec![$e, $e] {}
+ for _ in vec![$e; 2] {}
+ for _ in $vec {}
+ for _ in $vec2 {}
+ }};
+ }
+
+ in_macro!(1, [1, 2], [1; 2]);
+
+ macro_rules! from_macro {
+ () => {
+ vec![1, 2, 3]
+ };
+ }
+ macro_rules! from_macro_repeat {
+ () => {
+ vec![1; 3]
+ };
+ }
+
+ for _ in from_macro!() {}
+ for _ in from_macro_repeat!() {}
+}
+
#[clippy::msrv = "1.53"]
fn above() {
for a in [1, 2, 3] {
diff --git a/src/tools/clippy/tests/ui/vec.rs b/src/tools/clippy/tests/ui/vec.rs
index 0404d8cdb..cbe7685b4 100644
--- a/src/tools/clippy/tests/ui/vec.rs
+++ b/src/tools/clippy/tests/ui/vec.rs
@@ -115,6 +115,46 @@ fn main() {
let _x = vec![1; 201];
}
+fn issue11075() {
+ macro_rules! repro {
+ ($e:expr) => {
+ stringify!($e)
+ };
+ }
+ for _string in vec![repro!(true), repro!(null)] {
+ unimplemented!();
+ }
+
+ macro_rules! in_macro {
+ ($e:expr, $vec:expr, $vec2:expr) => {{
+ vec![1; 2].fill(3);
+ vec![1, 2].fill(3);
+ for _ in vec![1, 2] {}
+ for _ in vec![1; 2] {}
+ for _ in vec![$e, $e] {}
+ for _ in vec![$e; 2] {}
+ for _ in $vec {}
+ for _ in $vec2 {}
+ }};
+ }
+
+ in_macro!(1, vec![1, 2], vec![1; 2]);
+
+ macro_rules! from_macro {
+ () => {
+ vec![1, 2, 3]
+ };
+ }
+ macro_rules! from_macro_repeat {
+ () => {
+ vec![1; 3]
+ };
+ }
+
+ for _ in from_macro!() {}
+ for _ in from_macro_repeat!() {}
+}
+
#[clippy::msrv = "1.53"]
fn above() {
for a in vec![1, 2, 3] {
diff --git a/src/tools/clippy/tests/ui/vec.stderr b/src/tools/clippy/tests/ui/vec.stderr
index 33d565b2d..8f6d2a1df 100644
--- a/src/tools/clippy/tests/ui/vec.stderr
+++ b/src/tools/clippy/tests/ui/vec.stderr
@@ -85,16 +85,34 @@ 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
+ --> $DIR/vec.rs:124:20
+ |
+LL | for _string in vec![repro!(true), repro!(null)] {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[repro!(true), repro!(null)]`
+
+error: useless use of `vec!`
+ --> $DIR/vec.rs:141:18
+ |
+LL | in_macro!(1, vec![1, 2], vec![1; 2]);
+ | ^^^^^^^^^^ help: you can use an array directly: `[1, 2]`
+
+error: useless use of `vec!`
+ --> $DIR/vec.rs:141:30
+ |
+LL | in_macro!(1, vec![1, 2], vec![1; 2]);
+ | ^^^^^^^^^^ help: you can use an array directly: `[1; 2]`
+
+error: useless use of `vec!`
+ --> $DIR/vec.rs:160:14
|
LL | for a in vec![1, 2, 3] {
| ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]`
error: useless use of `vec!`
- --> $DIR/vec.rs:124:14
+ --> $DIR/vec.rs:164: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 16 previous errors
+error: aborting due to 19 previous errors
diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr
index 30d29aa4e..5b88ae4ab 100644
--- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr
+++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr
@@ -2,7 +2,7 @@ error: wildcard match will also match any future added variants
--> $DIR/wildcard_enum_match_arm.rs:40:9
|
LL | _ => eprintln!("Not red"),
- | ^ help: try this: `Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan`
+ | ^ help: try: `Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan`
|
note: the lint level is defined here
--> $DIR/wildcard_enum_match_arm.rs:3:9
@@ -14,31 +14,31 @@ error: wildcard match will also match any future added variants
--> $DIR/wildcard_enum_match_arm.rs:44:9
|
LL | _not_red => eprintln!("Not red"),
- | ^^^^^^^^ help: try this: `_not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan`
+ | ^^^^^^^^ help: try: `_not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan`
error: wildcard match will also match any future added variants
--> $DIR/wildcard_enum_match_arm.rs:48:9
|
LL | not_red => format!("{:?}", not_red),
- | ^^^^^^^ help: try this: `not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan`
+ | ^^^^^^^ help: try: `not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan`
error: wildcard match will also match any future added variants
--> $DIR/wildcard_enum_match_arm.rs:64:9
|
LL | _ => "No red",
- | ^ help: try this: `Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan`
+ | ^ help: try: `Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan`
error: wildcard matches known variants and will also match future added variants
--> $DIR/wildcard_enum_match_arm.rs:81:9
|
LL | _ => {},
- | ^ help: try this: `ErrorKind::PermissionDenied | _`
+ | ^ help: try: `ErrorKind::PermissionDenied | _`
error: wildcard match will also match any future added variants
--> $DIR/wildcard_enum_match_arm.rs:99:13
|
LL | _ => (),
- | ^ help: try this: `Enum::B | Enum::__Private`
+ | ^ help: try: `Enum::B | Enum::__Private`
error: aborting due to 6 previous errors
diff --git a/src/tools/clippy/tests/ui/wildcard_imports.fixed b/src/tools/clippy/tests/ui/wildcard_imports.fixed
index 2961b062e..67173f406 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports.fixed
+++ b/src/tools/clippy/tests/ui/wildcard_imports.fixed
@@ -112,6 +112,7 @@ mod in_fn_test {
}
fn test_inner_nested() {
+ #[rustfmt::skip]
use self::{inner::inner_foo, inner2::inner_bar};
inner_foo();
diff --git a/src/tools/clippy/tests/ui/wildcard_imports.rs b/src/tools/clippy/tests/ui/wildcard_imports.rs
index 28508a253..8223b6930 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports.rs
+++ b/src/tools/clippy/tests/ui/wildcard_imports.rs
@@ -112,6 +112,7 @@ mod in_fn_test {
}
fn test_inner_nested() {
+ #[rustfmt::skip]
use self::{inner::*, inner2::*};
inner_foo();
diff --git a/src/tools/clippy/tests/ui/wildcard_imports.stderr b/src/tools/clippy/tests/ui/wildcard_imports.stderr
index c96b3041a..f7baf234c 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports.stderr
+++ b/src/tools/clippy/tests/ui/wildcard_imports.stderr
@@ -55,37 +55,37 @@ LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:115:20
+ --> $DIR/wildcard_imports.rs:116:20
|
LL | use self::{inner::*, inner2::*};
| ^^^^^^^^ help: try: `inner::inner_foo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:115:30
+ --> $DIR/wildcard_imports.rs:116:30
|
LL | use self::{inner::*, inner2::*};
| ^^^^^^^^^ help: try: `inner2::inner_bar`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:122:13
+ --> $DIR/wildcard_imports.rs:123:13
|
LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:151:9
+ --> $DIR/wildcard_imports.rs:152: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:160:9
+ --> $DIR/wildcard_imports.rs:161:9
|
LL | use crate:: in_fn_test:: * ;
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:161:9
+ --> $DIR/wildcard_imports.rs:162: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:172:13
+ --> $DIR/wildcard_imports.rs:173:13
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:207:17
+ --> $DIR/wildcard_imports.rs:208:17
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::insidefoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:215:13
+ --> $DIR/wildcard_imports.rs:216:13
|
LL | use crate::super_imports::*;
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:224:17
+ --> $DIR/wildcard_imports.rs:225:17
|
LL | use super::super::*;
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:233:13
+ --> $DIR/wildcard_imports.rs:234:13
|
LL | use super::super::super_imports::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:241:13
+ --> $DIR/wildcard_imports.rs:242:13
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::foofoo`
diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed
index 3aea013fb..8a6337567 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed
+++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed
@@ -106,6 +106,7 @@ mod in_fn_test {
}
fn test_inner_nested() {
+ #[rustfmt::skip]
use self::{inner::inner_foo, inner2::inner_bar};
inner_foo();
diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.stderr b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.stderr
index acca9f651..af9ae6e78 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.stderr
+++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.stderr
@@ -55,37 +55,37 @@ LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:109:20
+ --> $DIR/wildcard_imports_2021.rs:110:20
|
LL | use self::{inner::*, inner2::*};
| ^^^^^^^^ help: try: `inner::inner_foo`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:109:30
+ --> $DIR/wildcard_imports_2021.rs:110:30
|
LL | use self::{inner::*, inner2::*};
| ^^^^^^^^^ help: try: `inner2::inner_bar`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:116:13
+ --> $DIR/wildcard_imports_2021.rs:117:13
|
LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:145:9
+ --> $DIR/wildcard_imports_2021.rs:146:9
|
LL | use crate::in_fn_test::*;
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:154:9
+ --> $DIR/wildcard_imports_2021.rs:155:9
|
LL | use crate:: in_fn_test:: * ;
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:155:9
+ --> $DIR/wildcard_imports_2021.rs:156: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_2021.rs:166:13
+ --> $DIR/wildcard_imports_2021.rs:167:13
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:201:17
+ --> $DIR/wildcard_imports_2021.rs:202:17
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::insidefoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:209:13
+ --> $DIR/wildcard_imports_2021.rs:210:13
|
LL | use crate::super_imports::*;
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:218:17
+ --> $DIR/wildcard_imports_2021.rs:219:17
|
LL | use super::super::*;
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:227:13
+ --> $DIR/wildcard_imports_2021.rs:228:13
|
LL | use super::super::super_imports::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:235:13
+ --> $DIR/wildcard_imports_2021.rs:236:13
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::foofoo`
diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed
index 3aea013fb..8a6337567 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed
+++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed
@@ -106,6 +106,7 @@ mod in_fn_test {
}
fn test_inner_nested() {
+ #[rustfmt::skip]
use self::{inner::inner_foo, inner2::inner_bar};
inner_foo();
diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.stderr b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.stderr
index acca9f651..af9ae6e78 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.stderr
+++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.stderr
@@ -55,37 +55,37 @@ LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:109:20
+ --> $DIR/wildcard_imports_2021.rs:110:20
|
LL | use self::{inner::*, inner2::*};
| ^^^^^^^^ help: try: `inner::inner_foo`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:109:30
+ --> $DIR/wildcard_imports_2021.rs:110:30
|
LL | use self::{inner::*, inner2::*};
| ^^^^^^^^^ help: try: `inner2::inner_bar`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:116:13
+ --> $DIR/wildcard_imports_2021.rs:117:13
|
LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:145:9
+ --> $DIR/wildcard_imports_2021.rs:146:9
|
LL | use crate::in_fn_test::*;
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:154:9
+ --> $DIR/wildcard_imports_2021.rs:155:9
|
LL | use crate:: in_fn_test:: * ;
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:155:9
+ --> $DIR/wildcard_imports_2021.rs:156: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_2021.rs:166:13
+ --> $DIR/wildcard_imports_2021.rs:167:13
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:201:17
+ --> $DIR/wildcard_imports_2021.rs:202:17
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::insidefoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:209:13
+ --> $DIR/wildcard_imports_2021.rs:210:13
|
LL | use crate::super_imports::*;
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:218:17
+ --> $DIR/wildcard_imports_2021.rs:219:17
|
LL | use super::super::*;
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:227:13
+ --> $DIR/wildcard_imports_2021.rs:228:13
|
LL | use super::super::super_imports::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:235:13
+ --> $DIR/wildcard_imports_2021.rs:236:13
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::foofoo`
diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.rs b/src/tools/clippy/tests/ui/wildcard_imports_2021.rs
index 40c2d0752..52cd2c828 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports_2021.rs
+++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.rs
@@ -106,6 +106,7 @@ mod in_fn_test {
}
fn test_inner_nested() {
+ #[rustfmt::skip]
use self::{inner::*, inner2::*};
inner_foo();
diff --git a/src/tools/clippy/tests/ui/write_literal.stderr b/src/tools/clippy/tests/ui/write_literal.stderr
index 1e306ae28..8b72c8bd2 100644
--- a/src/tools/clippy/tests/ui/write_literal.stderr
+++ b/src/tools/clippy/tests/ui/write_literal.stderr
@@ -5,7 +5,7 @@ LL | write!(v, "Hello {}", "world");
| ^^^^^^^
|
= note: `-D clippy::write-literal` implied by `-D warnings`
-help: try this
+help: try
|
LL - write!(v, "Hello {}", "world");
LL + write!(v, "Hello world");
@@ -17,7 +17,7 @@ error: literal with an empty format string
LL | writeln!(v, "Hello {} {}", world, "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "Hello {} {}", world, "world");
LL + writeln!(v, "Hello {} world", world);
@@ -29,7 +29,7 @@ error: literal with an empty format string
LL | writeln!(v, "Hello {}", "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "Hello {}", "world");
LL + writeln!(v, "Hello world");
@@ -41,7 +41,7 @@ error: literal with an empty format string
LL | writeln!(v, "{} {:.4}", "a literal", 5);
| ^^^^^^^^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "{} {:.4}", "a literal", 5);
LL + writeln!(v, "a literal {:.4}", 5);
@@ -53,7 +53,7 @@ error: literal with an empty format string
LL | writeln!(v, "{0} {1}", "hello", "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "{0} {1}", "hello", "world");
LL + writeln!(v, "hello {1}", "world");
@@ -65,7 +65,7 @@ error: literal with an empty format string
LL | writeln!(v, "{0} {1}", "hello", "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "{0} {1}", "hello", "world");
LL + writeln!(v, "{0} world", "hello");
@@ -77,7 +77,7 @@ error: literal with an empty format string
LL | writeln!(v, "{1} {0}", "hello", "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "{1} {0}", "hello", "world");
LL + writeln!(v, "world {0}", "hello");
@@ -89,7 +89,7 @@ error: literal with an empty format string
LL | writeln!(v, "{1} {0}", "hello", "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "{1} {0}", "hello", "world");
LL + writeln!(v, "{1} hello", "world");
@@ -101,7 +101,7 @@ error: literal with an empty format string
LL | writeln!(v, "{foo} {bar}", foo = "hello", bar = "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "{foo} {bar}", foo = "hello", bar = "world");
LL + writeln!(v, "hello {bar}", bar = "world");
@@ -113,7 +113,7 @@ error: literal with an empty format string
LL | writeln!(v, "{foo} {bar}", foo = "hello", bar = "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "{foo} {bar}", foo = "hello", bar = "world");
LL + writeln!(v, "{foo} world", foo = "hello");
@@ -125,7 +125,7 @@ error: literal with an empty format string
LL | writeln!(v, "{bar} {foo}", foo = "hello", bar = "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "{bar} {foo}", foo = "hello", bar = "world");
LL + writeln!(v, "world {foo}", foo = "hello");
@@ -137,7 +137,7 @@ error: literal with an empty format string
LL | writeln!(v, "{bar} {foo}", foo = "hello", bar = "world");
| ^^^^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "{bar} {foo}", foo = "hello", bar = "world");
LL + writeln!(v, "{bar} hello", bar = "world");
diff --git a/src/tools/clippy/tests/ui/write_literal_2.stderr b/src/tools/clippy/tests/ui/write_literal_2.stderr
index 18591250a..c30ec385b 100644
--- a/src/tools/clippy/tests/ui/write_literal_2.stderr
+++ b/src/tools/clippy/tests/ui/write_literal_2.stderr
@@ -13,7 +13,7 @@ LL | writeln!(v, "{}", "{hello}");
| ^^^^^^^^^
|
= note: `-D clippy::write-literal` implied by `-D warnings`
-help: try this
+help: try
|
LL - writeln!(v, "{}", "{hello}");
LL + writeln!(v, "{{hello}}");
@@ -25,7 +25,7 @@ error: literal with an empty format string
LL | writeln!(v, r"{}", r"{hello}");
| ^^^^^^^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, r"{}", r"{hello}");
LL + writeln!(v, r"{{hello}}");
@@ -37,7 +37,7 @@ error: literal with an empty format string
LL | writeln!(v, "{}", '/'');
| ^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "{}", '/'');
LL + writeln!(v, "'");
@@ -49,7 +49,7 @@ error: literal with an empty format string
LL | writeln!(v, "{}", '"');
| ^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "{}", '"');
LL + writeln!(v, "/"");
@@ -67,7 +67,7 @@ error: literal with an empty format string
LL | writeln!(v, r"{}", '/'');
| ^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, r"{}", '/'');
LL + writeln!(v, r"'");
@@ -80,7 +80,7 @@ LL | / "hello /
LL | | world!"
| |_______________^
|
-help: try this
+help: try
|
LL ~ "some hello /
LL ~ world!"
@@ -92,7 +92,7 @@ error: literal with an empty format string
LL | "1", "2", "3",
| ^^^
|
-help: try this
+help: try
|
LL ~ "some 1/
LL ~ {} // {}", "2", "3",
@@ -104,7 +104,7 @@ error: literal with an empty format string
LL | "1", "2", "3",
| ^^^
|
-help: try this
+help: try
|
LL ~ 2 // {}",
LL ~ "1", "3",
@@ -116,7 +116,7 @@ error: literal with an empty format string
LL | "1", "2", "3",
| ^^^
|
-help: try this
+help: try
|
LL ~ {} // 3",
LL ~ "1", "2",
@@ -128,7 +128,7 @@ error: literal with an empty format string
LL | writeln!(v, "{}", "//");
| ^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "{}", "//");
LL + writeln!(v, "//");
@@ -140,7 +140,7 @@ error: literal with an empty format string
LL | writeln!(v, r"{}", "//");
| ^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, r"{}", "//");
LL + writeln!(v, r"/");
@@ -152,7 +152,7 @@ error: literal with an empty format string
LL | writeln!(v, r#"{}"#, "//");
| ^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, r#"{}"#, "//");
LL + writeln!(v, r#"/"#);
@@ -164,7 +164,7 @@ error: literal with an empty format string
LL | writeln!(v, "{}", r"/");
| ^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "{}", r"/");
LL + writeln!(v, "//");
@@ -176,7 +176,7 @@ error: literal with an empty format string
LL | writeln!(v, "{}", "/r");
| ^^^^
|
-help: try this
+help: try
|
LL - writeln!(v, "{}", "/r");
LL + writeln!(v, "/r");