summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy')
-rw-r--r--src/tools/clippy/.github/workflows/clippy.yml2
-rw-r--r--src/tools/clippy/.github/workflows/clippy_bors.yml10
-rw-r--r--src/tools/clippy/.github/workflows/clippy_dev.yml2
-rw-r--r--src/tools/clippy/.github/workflows/deploy.yml4
-rw-r--r--src/tools/clippy/.github/workflows/remark.yml10
-rw-r--r--src/tools/clippy/CHANGELOG.md127
-rw-r--r--src/tools/clippy/Cargo.toml7
-rw-r--r--src/tools/clippy/README.md5
-rw-r--r--src/tools/clippy/book/src/SUMMARY.md2
-rw-r--r--src/tools/clippy/book/src/development/README.md22
-rw-r--r--src/tools/clippy/book/src/development/adding_lints.md2
-rw-r--r--src/tools/clippy/book/src/development/lint_passes.md114
-rw-r--r--src/tools/clippy/book/src/development/macro_expansions.md158
-rw-r--r--src/tools/clippy/book/src/development/proposals/syntax-tree-patterns.md2
-rw-r--r--src/tools/clippy/book/src/development/type_checking.md31
-rw-r--r--src/tools/clippy/book/src/lint_configuration.md27
-rw-r--r--src/tools/clippy/book/src/usage.md3
-rw-r--r--src/tools/clippy/clippy_dev/src/dogfood.rs8
-rw-r--r--src/tools/clippy/clippy_dev/src/lib.rs13
-rw-r--r--src/tools/clippy/clippy_dev/src/lint.rs17
-rw-r--r--src/tools/clippy/clippy_dev/src/update_lints.rs56
-rw-r--r--src/tools/clippy/clippy_lints/Cargo.toml4
-rw-r--r--src/tools/clippy/clippy_lints/src/allow_attributes.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/assertions_on_constants.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/attrs.rs144
-rw-r--r--src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/box_default.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/cast_nan_to_int.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/cast_sign_loss.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/mod.rs12
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/copies.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/crate_in_macro_def.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/dbg_macro.rs57
-rw-r--r--src/tools/clippy/clippy_lints/src/declared_lints.rs14
-rw-r--r--src/tools/clippy/clippy_lints/src/default_constructed_unit_structs.rs84
-rw-r--r--src/tools/clippy/clippy_lints/src/default_union_representation.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/dereference.rs1
-rw-r--r--src/tools/clippy/clippy_lints/src/derive.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/drop_forget_ref.rs117
-rw-r--r--src/tools/clippy/clippy_lints/src/entry.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/enum_variants.rs8
-rw-r--r--src/tools/clippy/clippy_lints/src/escape.rs7
-rw-r--r--src/tools/clippy/clippy_lints/src/float_literal.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs47
-rw-r--r--src/tools/clippy/clippy_lints/src/fn_null_check.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/format_impl.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/formatting.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/from_over_into.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/functions/misnamed_getters.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/functions/mod.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/future_not_send.rs7
-rw-r--r--src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/index_refutable_slice.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/indexing_slicing.rs10
-rw-r--r--src/tools/clippy/clippy_lints/src/items_after_test_module.rs85
-rw-r--r--src/tools/clippy/clippy_lints/src/large_futures.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/len_zero.rs24
-rw-r--r--src/tools/clippy/clippy_lints/src/let_underscore.rs29
-rw-r--r--src/tools/clippy/clippy_lints/src/let_with_type_underscore.rs12
-rw-r--r--src/tools/clippy/clippy_lints/src/lib.rs41
-rw-r--r--src/tools/clippy/clippy_lints/src/lines_filter_map_ok.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/manual_while_let_some.rs110
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/mod.rs35
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/never_loop.rs3
-rw-r--r--src/tools/clippy/clippy_lints/src/manual_assert.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/manual_bits.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/manual_let_else.rs63
-rw-r--r--src/tools/clippy/clippy_lints/src/manual_retain.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/manual_slice_size_calculation.rs28
-rw-r--r--src/tools/clippy/clippy_lints/src/manual_strip.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/match_bool.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs24
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/mod.rs19
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/overlapping_arms.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs233
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs1
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/chars_cmp_with_unwrap.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs40
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/iter_next_slice.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/iter_nth_zero.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/iterator_step_by_zero.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/manual_next_back.rs38
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/mod.rs101
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/needless_collect.rs68
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/obfuscated_if_else.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/open_options.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/path_buf_push_overwrite.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/repeat_once.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/seek_from_current.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/seek_to_start_instead_of_rewind.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/str_splitn.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/unnecessary_fold.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/misc.rs11
-rw-r--r--src/tools/clippy/clippy_lints/src/missing_trait_methods.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/mutex_atomic.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/needless_bool.rs74
-rw-r--r--src/tools/clippy/clippy_lints/src/needless_parens_on_range_literals.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/neg_multiply.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/non_copy_const.rs10
-rw-r--r--src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/octal_escapes.rs94
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/absurd_extreme_comparisons.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs56
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/bit_mask.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/cmp_nan.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/duration_subsec.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/float_cmp.rs57
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/mod.rs29
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/modulo_arithmetic.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs39
-rw-r--r--src/tools/clippy/clippy_lints/src/option_if_let_else.rs12
-rw-r--r--src/tools/clippy/clippy_lints/src/question_mark_used.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/ranges.rs8
-rw-r--r--src/tools/clippy/clippy_lints/src/redundant_clone.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/ref_patterns.rs44
-rw-r--r--src/tools/clippy/clippy_lints/src/regex.rs27
-rw-r--r--src/tools/clippy/clippy_lints/src/renamed_lints.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/semicolon_block.rs125
-rw-r--r--src/tools/clippy/clippy_lints/src/shadow.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/slow_vector_initialization.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/strings.rs3
-rw-r--r--src/tools/clippy/clippy_lints/src/strlen_on_c_strings.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/trailing_empty_array.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/trait_bounds.rs59
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/transmute_null_to_fn.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/transmuting_null.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/types/mod.rs14
-rw-r--r--src/tools/clippy/clippy_lints/src/unicode.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/unnecessary_box_returns.rs17
-rw-r--r--src/tools/clippy/clippy_lints/src/useless_conversion.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/author.rs13
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/conf.rs17
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs111
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/mod.rs140
-rw-r--r--src/tools/clippy/clippy_lints/src/vec.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/wildcard_imports.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/write.rs2
-rw-r--r--src/tools/clippy/clippy_utils/Cargo.toml2
-rw-r--r--src/tools/clippy/clippy_utils/src/ast_utils.rs2
-rw-r--r--src/tools/clippy/clippy_utils/src/attrs.rs2
-rw-r--r--src/tools/clippy/clippy_utils/src/check_proc_macro.rs2
-rw-r--r--src/tools/clippy/clippy_utils/src/consts.rs117
-rw-r--r--src/tools/clippy/clippy_utils/src/eager_or_lazy.rs3
-rw-r--r--src/tools/clippy/clippy_utils/src/higher.rs6
-rw-r--r--src/tools/clippy/clippy_utils/src/hir_utils.rs217
-rw-r--r--src/tools/clippy/clippy_utils/src/lib.rs101
-rw-r--r--src/tools/clippy/clippy_utils/src/macros.rs2
-rw-r--r--src/tools/clippy/clippy_utils/src/paths.rs4
-rw-r--r--src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs4
-rw-r--r--src/tools/clippy/clippy_utils/src/source.rs52
-rw-r--r--src/tools/clippy/clippy_utils/src/sugg.rs23
-rw-r--r--src/tools/clippy/clippy_utils/src/ty.rs16
-rw-r--r--src/tools/clippy/clippy_utils/src/visitors.rs1
-rw-r--r--src/tools/clippy/declare_clippy_lint/Cargo.toml4
-rw-r--r--src/tools/clippy/declare_clippy_lint/src/lib.rs8
-rw-r--r--src/tools/clippy/lintcheck/README.md4
-rw-r--r--src/tools/clippy/lintcheck/src/main.rs2
-rw-r--r--src/tools/clippy/rust-toolchain2
-rw-r--r--src/tools/clippy/src/driver.rs73
-rw-r--r--src/tools/clippy/src/main.rs2
-rw-r--r--src/tools/clippy/tests/compile-test.rs3
-rw-r--r--src/tools/clippy/tests/dogfood.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail/src/main.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish/src/main.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/cargo_common_metadata/fail_publish_true/src/main.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass/src/main.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass_publish_empty/src/main.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/cargo_common_metadata/pass_publish_false/src/main.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/feature_name/fail/src/main.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/feature_name/pass/src/main.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/main.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/multiple_crate_versions/5041_allow_dev_build/src/main.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/multiple_crate_versions/fail/src/main.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/multiple_crate_versions/pass/src/main.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/wildcard_dependencies/fail/src/main.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/wildcard_dependencies/pass/src/main.rs2
-rw-r--r--src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.fixed2
-rw-r--r--src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.rs2
-rw-r--r--src/tools/clippy/tests/ui-internal/custom_ice_message.rs13
-rw-r--r--src/tools/clippy/tests/ui-internal/custom_ice_message.stderr8
-rw-r--r--src/tools/clippy/tests/ui-internal/interning_defined_symbol.fixed2
-rw-r--r--src/tools/clippy/tests/ui-internal/interning_defined_symbol.rs2
-rw-r--r--src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.fixed2
-rw-r--r--src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.rs2
-rw-r--r--src/tools/clippy/tests/ui-internal/outer_expn_data.fixed2
-rw-r--r--src/tools/clippy/tests/ui-internal/outer_expn_data.rs2
-rw-r--r--src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed4
-rw-r--r--src/tools/clippy/tests/ui-internal/unnecessary_def_path.rs4
-rw-r--r--src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.fixed2
-rw-r--r--src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.rs2
-rw-r--r--src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed2
-rw-r--r--src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs2
-rw-r--r--src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.rs2
-rw-r--r--src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.rs2
-rw-r--r--src/tools/clippy/tests/ui-toml/expect_used/expect_used.rs2
-rw-r--r--src/tools/clippy/tests/ui-toml/mut_key/mut_key.rs2
-rw-r--r--src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/auxiliary/proc_macro_derive.rs4
-rw-r--r--src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed4
-rw-r--r--src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs4
-rw-r--r--src/tools/clippy/tests/ui-toml/print_macro/print_macro.rs2
-rw-r--r--src/tools/clippy/tests/ui-toml/semicolon_block/both.fixed86
-rw-r--r--src/tools/clippy/tests/ui-toml/semicolon_block/both.rs86
-rw-r--r--src/tools/clippy/tests/ui-toml/semicolon_block/both.stderr55
-rw-r--r--src/tools/clippy/tests/ui-toml/semicolon_block/clippy.toml2
-rw-r--r--src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed85
-rw-r--r--src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.rs85
-rw-r--r--src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr18
-rw-r--r--src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed85
-rw-r--r--src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.rs85
-rw-r--r--src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr39
-rw-r--r--src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs2
-rw-r--r--src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.rs4
-rw-r--r--src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.rs2
-rw-r--r--src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr3
-rw-r--r--src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs2
-rw-r--r--src/tools/clippy/tests/ui/allow_attributes.fixed2
-rw-r--r--src/tools/clippy/tests/ui/allow_attributes.rs2
-rw-r--r--src/tools/clippy/tests/ui/allow_attributes_false_positive.rs5
-rw-r--r--src/tools/clippy/tests/ui/almost_complete_range.fixed6
-rw-r--r--src/tools/clippy/tests/ui/almost_complete_range.rs6
-rw-r--r--src/tools/clippy/tests/ui/arithmetic_side_effects.rs37
-rw-r--r--src/tools/clippy/tests/ui/arithmetic_side_effects.stderr268
-rw-r--r--src/tools/clippy/tests/ui/as_conversions.rs2
-rw-r--r--src/tools/clippy/tests/ui/as_underscore.fixed2
-rw-r--r--src/tools/clippy/tests/ui/as_underscore.rs2
-rw-r--r--src/tools/clippy/tests/ui/asm_syntax.rs4
-rw-r--r--src/tools/clippy/tests/ui/assertions_on_result_states.fixed2
-rw-r--r--src/tools/clippy/tests/ui/assertions_on_result_states.rs2
-rw-r--r--src/tools/clippy/tests/ui/assign_ops.fixed2
-rw-r--r--src/tools/clippy/tests/ui/assign_ops.rs2
-rw-r--r--src/tools/clippy/tests/ui/async_yields_async.fixed2
-rw-r--r--src/tools/clippy/tests/ui/async_yields_async.rs2
-rw-r--r--src/tools/clippy/tests/ui/author/blocks.rs2
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/macro_rules.rs7
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs10
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/proc_macro_derive.rs77
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/proc_macro_suspicious_else_formatting.rs4
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/proc_macro_unsafe.rs4
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/proc_macros.rs4
-rw-r--r--src/tools/clippy/tests/ui/bind_instead_of_map.fixed2
-rw-r--r--src/tools/clippy/tests/ui/bind_instead_of_map.rs2
-rw-r--r--src/tools/clippy/tests/ui/bind_instead_of_map_multipart.fixed2
-rw-r--r--src/tools/clippy/tests/ui/bind_instead_of_map_multipart.rs2
-rw-r--r--src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.rs2
-rw-r--r--src/tools/clippy/tests/ui/blocks_in_if_conditions.fixed2
-rw-r--r--src/tools/clippy/tests/ui/blocks_in_if_conditions.rs2
-rw-r--r--src/tools/clippy/tests/ui/bool_assert_comparison.fixed2
-rw-r--r--src/tools/clippy/tests/ui/bool_assert_comparison.rs2
-rw-r--r--src/tools/clippy/tests/ui/bool_comparison.fixed2
-rw-r--r--src/tools/clippy/tests/ui/bool_comparison.rs2
-rw-r--r--src/tools/clippy/tests/ui/bool_to_int_with_if.fixed11
-rw-r--r--src/tools/clippy/tests/ui/bool_to_int_with_if.rs11
-rw-r--r--src/tools/clippy/tests/ui/bool_to_int_with_if.stderr2
-rw-r--r--src/tools/clippy/tests/ui/borrow_as_ptr.fixed2
-rw-r--r--src/tools/clippy/tests/ui/borrow_as_ptr.rs2
-rw-r--r--src/tools/clippy/tests/ui/borrow_as_ptr_no_std.fixed2
-rw-r--r--src/tools/clippy/tests/ui/borrow_as_ptr_no_std.rs2
-rw-r--r--src/tools/clippy/tests/ui/borrow_deref_ref.fixed17
-rw-r--r--src/tools/clippy/tests/ui/borrow_deref_ref.rs17
-rw-r--r--src/tools/clippy/tests/ui/borrow_deref_ref.stderr6
-rw-r--r--src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.rs2
-rw-r--r--src/tools/clippy/tests/ui/box_default.fixed10
-rw-r--r--src/tools/clippy/tests/ui/box_default.rs10
-rw-r--r--src/tools/clippy/tests/ui/box_default.stderr32
-rw-r--r--src/tools/clippy/tests/ui/bytes_count_to_len.fixed2
-rw-r--r--src/tools/clippy/tests/ui/bytes_count_to_len.rs2
-rw-r--r--src/tools/clippy/tests/ui/bytes_nth.fixed2
-rw-r--r--src/tools/clippy/tests/ui/bytes_nth.rs2
-rw-r--r--src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed2
-rw-r--r--src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs2
-rw-r--r--src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed2
-rw-r--r--src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs2
-rw-r--r--src/tools/clippy/tests/ui/cast_lossless_bool.fixed2
-rw-r--r--src/tools/clippy/tests/ui/cast_lossless_bool.rs2
-rw-r--r--src/tools/clippy/tests/ui/cast_lossless_float.fixed2
-rw-r--r--src/tools/clippy/tests/ui/cast_lossless_float.rs2
-rw-r--r--src/tools/clippy/tests/ui/cast_lossless_integer.fixed2
-rw-r--r--src/tools/clippy/tests/ui/cast_lossless_integer.rs2
-rw-r--r--src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.fixed2
-rw-r--r--src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs2
-rw-r--r--src/tools/clippy/tests/ui/cast_size.rs2
-rw-r--r--src/tools/clippy/tests/ui/cast_size_32bit.rs2
-rw-r--r--src/tools/clippy/tests/ui/cast_size_32bit.stderr53
-rw-r--r--src/tools/clippy/tests/ui/cast_slice_different_sizes.rs2
-rw-r--r--src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed2
-rw-r--r--src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs2
-rw-r--r--src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.fixed2
-rw-r--r--src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.rs2
-rw-r--r--src/tools/clippy/tests/ui/checked_conversions.fixed2
-rw-r--r--src/tools/clippy/tests/ui/checked_conversions.rs2
-rw-r--r--src/tools/clippy/tests/ui/clear_with_drain.fixed2
-rw-r--r--src/tools/clippy/tests/ui/clear_with_drain.rs2
-rw-r--r--src/tools/clippy/tests/ui/clone_on_copy.fixed2
-rw-r--r--src/tools/clippy/tests/ui/clone_on_copy.rs2
-rw-r--r--src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed2
-rw-r--r--src/tools/clippy/tests/ui/cloned_instead_of_copied.rs2
-rw-r--r--src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.fixed2
-rw-r--r--src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.rs2
-rw-r--r--src/tools/clippy/tests/ui/cmp_owned/comparison_flip.fixed2
-rw-r--r--src/tools/clippy/tests/ui/cmp_owned/comparison_flip.rs2
-rw-r--r--src/tools/clippy/tests/ui/cmp_owned/with_suggestion.fixed2
-rw-r--r--src/tools/clippy/tests/ui/cmp_owned/with_suggestion.rs2
-rw-r--r--src/tools/clippy/tests/ui/collapsible_else_if.fixed2
-rw-r--r--src/tools/clippy/tests/ui/collapsible_else_if.rs2
-rw-r--r--src/tools/clippy/tests/ui/collapsible_if.fixed9
-rw-r--r--src/tools/clippy/tests/ui/collapsible_if.rs9
-rw-r--r--src/tools/clippy/tests/ui/collapsible_if.stderr18
-rw-r--r--src/tools/clippy/tests/ui/collapsible_str_replace.fixed2
-rw-r--r--src/tools/clippy/tests/ui/collapsible_str_replace.rs2
-rw-r--r--src/tools/clippy/tests/ui/collection_is_never_read.rs49
-rw-r--r--src/tools/clippy/tests/ui/collection_is_never_read.stderr62
-rw-r--r--src/tools/clippy/tests/ui/comparison_to_empty.fixed2
-rw-r--r--src/tools/clippy/tests/ui/comparison_to_empty.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/auxiliary/proc_macro_crash.rs4
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-10148.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-10645.rs7
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-10645.stderr16
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-3741.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-4968.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-5207.rs1
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-7272.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-7410.rs6
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-8681.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice_exact_size.rs (renamed from src/tools/clippy/tests/ui/crashes/ice_exacte_size.rs)0
-rw-r--r--src/tools/clippy/tests/ui/crate_in_macro_def.fixed2
-rw-r--r--src/tools/clippy/tests/ui/crate_in_macro_def.rs2
-rw-r--r--src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.rs2
-rw-r--r--src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs4
-rw-r--r--src/tools/clippy/tests/ui/create_dir.fixed2
-rw-r--r--src/tools/clippy/tests/ui/create_dir.rs2
-rw-r--r--src/tools/clippy/tests/ui/dbg_macro.rs29
-rw-r--r--src/tools/clippy/tests/ui/dbg_macro.stderr82
-rw-r--r--src/tools/clippy/tests/ui/decimal_literal_representation.fixed2
-rw-r--r--src/tools/clippy/tests/ui/decimal_literal_representation.rs2
-rw-r--r--src/tools/clippy/tests/ui/def_id_nocore.rs2
-rw-r--r--src/tools/clippy/tests/ui/default_constructed_unit_structs.fixed159
-rw-r--r--src/tools/clippy/tests/ui/default_constructed_unit_structs.rs159
-rw-r--r--src/tools/clippy/tests/ui/default_constructed_unit_structs.stderr40
-rw-r--r--src/tools/clippy/tests/ui/default_instead_of_iter_empty.fixed2
-rw-r--r--src/tools/clippy/tests/ui/default_instead_of_iter_empty.rs2
-rw-r--r--src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed4
-rw-r--r--src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs4
-rw-r--r--src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed4
-rw-r--r--src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs4
-rw-r--r--src/tools/clippy/tests/ui/default_trait_access.fixed4
-rw-r--r--src/tools/clippy/tests/ui/default_trait_access.rs4
-rw-r--r--src/tools/clippy/tests/ui/deref_addrof.fixed4
-rw-r--r--src/tools/clippy/tests/ui/deref_addrof.rs4
-rw-r--r--src/tools/clippy/tests/ui/deref_addrof_macro.rs2
-rw-r--r--src/tools/clippy/tests/ui/deref_by_slicing.fixed2
-rw-r--r--src/tools/clippy/tests/ui/deref_by_slicing.rs2
-rw-r--r--src/tools/clippy/tests/ui/derivable_impls.fixed2
-rw-r--r--src/tools/clippy/tests/ui/derivable_impls.rs2
-rw-r--r--src/tools/clippy/tests/ui/derive_partial_eq_without_eq.fixed2
-rw-r--r--src/tools/clippy/tests/ui/derive_partial_eq_without_eq.rs2
-rw-r--r--src/tools/clippy/tests/ui/diverging_sub_expression.stderr10
-rw-r--r--src/tools/clippy/tests/ui/doc/doc-fixable.fixed2
-rw-r--r--src/tools/clippy/tests/ui/doc/doc-fixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/doc_unsafe.rs2
-rw-r--r--src/tools/clippy/tests/ui/double_comparison.fixed2
-rw-r--r--src/tools/clippy/tests/ui/double_comparison.rs2
-rw-r--r--src/tools/clippy/tests/ui/drop_forget_copy.rs86
-rw-r--r--src/tools/clippy/tests/ui/drop_forget_copy.stderr112
-rw-r--r--src/tools/clippy/tests/ui/drop_ref.rs97
-rw-r--r--src/tools/clippy/tests/ui/drop_ref.stderr147
-rw-r--r--src/tools/clippy/tests/ui/duration_subsec.fixed2
-rw-r--r--src/tools/clippy/tests/ui/duration_subsec.rs2
-rw-r--r--src/tools/clippy/tests/ui/empty_drop.fixed2
-rw-r--r--src/tools/clippy/tests/ui/empty_drop.rs2
-rw-r--r--src/tools/clippy/tests/ui/empty_line_after_doc_comments.rs132
-rw-r--r--src/tools/clippy/tests/ui/empty_line_after_doc_comments.stderr36
-rw-r--r--src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs2
-rw-r--r--src/tools/clippy/tests/ui/empty_loop.rs2
-rw-r--r--src/tools/clippy/tests/ui/empty_loop_no_std.rs4
-rw-r--r--src/tools/clippy/tests/ui/empty_structs_with_brackets.fixed2
-rw-r--r--src/tools/clippy/tests/ui/empty_structs_with_brackets.rs2
-rw-r--r--src/tools/clippy/tests/ui/entry.fixed4
-rw-r--r--src/tools/clippy/tests/ui/entry.rs4
-rw-r--r--src/tools/clippy/tests/ui/entry_btree.fixed2
-rw-r--r--src/tools/clippy/tests/ui/entry_btree.rs2
-rw-r--r--src/tools/clippy/tests/ui/entry_with_else.fixed2
-rw-r--r--src/tools/clippy/tests/ui/entry_with_else.rs2
-rw-r--r--src/tools/clippy/tests/ui/enum_clike_unportable_variant.rs2
-rw-r--r--src/tools/clippy/tests/ui/enum_glob_use.fixed2
-rw-r--r--src/tools/clippy/tests/ui/enum_glob_use.rs2
-rw-r--r--src/tools/clippy/tests/ui/enum_variants.rs10
-rw-r--r--src/tools/clippy/tests/ui/eq_op.rs2
-rw-r--r--src/tools/clippy/tests/ui/equatable_if_let.fixed4
-rw-r--r--src/tools/clippy/tests/ui/equatable_if_let.rs4
-rw-r--r--src/tools/clippy/tests/ui/err_expect.fixed2
-rw-r--r--src/tools/clippy/tests/ui/err_expect.rs2
-rw-r--r--src/tools/clippy/tests/ui/eta.fixed2
-rw-r--r--src/tools/clippy/tests/ui/eta.rs2
-rw-r--r--src/tools/clippy/tests/ui/excessive_precision.fixed2
-rw-r--r--src/tools/clippy/tests/ui/excessive_precision.rs2
-rw-r--r--src/tools/clippy/tests/ui/exhaustive_items.fixed2
-rw-r--r--src/tools/clippy/tests/ui/exhaustive_items.rs2
-rw-r--r--src/tools/clippy/tests/ui/expect_fun_call.fixed2
-rw-r--r--src/tools/clippy/tests/ui/expect_fun_call.rs2
-rw-r--r--src/tools/clippy/tests/ui/explicit_auto_deref.fixed2
-rw-r--r--src/tools/clippy/tests/ui/explicit_auto_deref.rs2
-rw-r--r--src/tools/clippy/tests/ui/explicit_deref_methods.fixed4
-rw-r--r--src/tools/clippy/tests/ui/explicit_deref_methods.rs4
-rw-r--r--src/tools/clippy/tests/ui/explicit_write.fixed2
-rw-r--r--src/tools/clippy/tests/ui/explicit_write.rs2
-rw-r--r--src/tools/clippy/tests/ui/extend_with_drain.fixed2
-rw-r--r--src/tools/clippy/tests/ui/extend_with_drain.rs2
-rw-r--r--src/tools/clippy/tests/ui/extra_unused_lifetimes.rs2
-rw-r--r--src/tools/clippy/tests/ui/extra_unused_type_parameters.fixed2
-rw-r--r--src/tools/clippy/tests/ui/extra_unused_type_parameters.rs2
-rw-r--r--src/tools/clippy/tests/ui/field_reassign_with_default.rs4
-rw-r--r--src/tools/clippy/tests/ui/filter_map_identity.fixed2
-rw-r--r--src/tools/clippy/tests/ui/filter_map_identity.rs2
-rw-r--r--src/tools/clippy/tests/ui/filter_map_next_fixable.fixed2
-rw-r--r--src/tools/clippy/tests/ui/filter_map_next_fixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/flat_map_identity.fixed2
-rw-r--r--src/tools/clippy/tests/ui/flat_map_identity.rs2
-rw-r--r--src/tools/clippy/tests/ui/flat_map_option.fixed2
-rw-r--r--src/tools/clippy/tests/ui/flat_map_option.rs2
-rw-r--r--src/tools/clippy/tests/ui/float_arithmetic.rs2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_abs.fixed2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_abs.rs2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_arithmetic_nostd.rs31
-rw-r--r--src/tools/clippy/tests/ui/floating_point_exp.fixed2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_exp.rs2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_hypot.fixed2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_hypot.rs2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_log.fixed2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_log.rs2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_logbase.fixed2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_logbase.rs2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_mul_add.fixed2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_mul_add.rs2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_powf.fixed2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_powf.rs2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_powi.fixed2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_powi.rs2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_rad.fixed2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_rad.rs2
-rw-r--r--src/tools/clippy/tests/ui/fn_to_numeric_cast.rs2
-rw-r--r--src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs2
-rw-r--r--src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.stderr14
-rw-r--r--src/tools/clippy/tests/ui/for_loop_fixable.fixed2
-rw-r--r--src/tools/clippy/tests/ui/for_loop_fixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/forget_ref.rs50
-rw-r--r--src/tools/clippy/tests/ui/forget_ref.stderr111
-rw-r--r--src/tools/clippy/tests/ui/format.fixed2
-rw-r--r--src/tools/clippy/tests/ui/format.rs2
-rw-r--r--src/tools/clippy/tests/ui/format_args.fixed2
-rw-r--r--src/tools/clippy/tests/ui/format_args.rs2
-rw-r--r--src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed2
-rw-r--r--src/tools/clippy/tests/ui/from_iter_instead_of_collect.rs2
-rw-r--r--src/tools/clippy/tests/ui/from_over_into.fixed4
-rw-r--r--src/tools/clippy/tests/ui/from_over_into.rs4
-rw-r--r--src/tools/clippy/tests/ui/from_over_into.stderr12
-rw-r--r--src/tools/clippy/tests/ui/from_over_into_unfixable.stderr6
-rw-r--r--src/tools/clippy/tests/ui/future_not_send.stderr24
-rw-r--r--src/tools/clippy/tests/ui/get_first.fixed2
-rw-r--r--src/tools/clippy/tests/ui/get_first.rs2
-rw-r--r--src/tools/clippy/tests/ui/get_last_with_len.fixed2
-rw-r--r--src/tools/clippy/tests/ui/get_last_with_len.rs2
-rw-r--r--src/tools/clippy/tests/ui/get_unwrap.fixed2
-rw-r--r--src/tools/clippy/tests/ui/get_unwrap.rs2
-rw-r--r--src/tools/clippy/tests/ui/identity_op.fixed2
-rw-r--r--src/tools/clippy/tests/ui/identity_op.rs2
-rw-r--r--src/tools/clippy/tests/ui/implicit_clone.fixed2
-rw-r--r--src/tools/clippy/tests/ui/implicit_clone.rs2
-rw-r--r--src/tools/clippy/tests/ui/implicit_hasher.rs2
-rw-r--r--src/tools/clippy/tests/ui/implicit_return.fixed2
-rw-r--r--src/tools/clippy/tests/ui/implicit_return.rs2
-rw-r--r--src/tools/clippy/tests/ui/implicit_saturating_add.fixed2
-rw-r--r--src/tools/clippy/tests/ui/implicit_saturating_add.rs2
-rw-r--r--src/tools/clippy/tests/ui/implicit_saturating_sub.fixed2
-rw-r--r--src/tools/clippy/tests/ui/implicit_saturating_sub.rs2
-rw-r--r--src/tools/clippy/tests/ui/inconsistent_digit_grouping.fixed2
-rw-r--r--src/tools/clippy/tests/ui/inconsistent_digit_grouping.rs2
-rw-r--r--src/tools/clippy/tests/ui/inconsistent_struct_constructor.fixed4
-rw-r--r--src/tools/clippy/tests/ui/inconsistent_struct_constructor.rs4
-rw-r--r--src/tools/clippy/tests/ui/inefficient_to_string.fixed2
-rw-r--r--src/tools/clippy/tests/ui/inefficient_to_string.rs2
-rw-r--r--src/tools/clippy/tests/ui/infallible_destructuring_match.fixed2
-rw-r--r--src/tools/clippy/tests/ui/infallible_destructuring_match.rs2
-rw-r--r--src/tools/clippy/tests/ui/inline_fn_without_body.fixed2
-rw-r--r--src/tools/clippy/tests/ui/inline_fn_without_body.rs2
-rw-r--r--src/tools/clippy/tests/ui/int_plus_one.fixed2
-rw-r--r--src/tools/clippy/tests/ui/int_plus_one.rs2
-rw-r--r--src/tools/clippy/tests/ui/integer_arithmetic.rs102
-rw-r--r--src/tools/clippy/tests/ui/integer_arithmetic.stderr169
-rw-r--r--src/tools/clippy/tests/ui/into_iter_on_ref.fixed2
-rw-r--r--src/tools/clippy/tests/ui/into_iter_on_ref.rs2
-rw-r--r--src/tools/clippy/tests/ui/invalid_null_ptr_usage.fixed2
-rw-r--r--src/tools/clippy/tests/ui/invalid_null_ptr_usage.rs2
-rw-r--r--src/tools/clippy/tests/ui/is_digit_ascii_radix.fixed2
-rw-r--r--src/tools/clippy/tests/ui/is_digit_ascii_radix.rs2
-rw-r--r--src/tools/clippy/tests/ui/issue-111399.rs13
-rw-r--r--src/tools/clippy/tests/ui/issue_2356.fixed2
-rw-r--r--src/tools/clippy/tests/ui/issue_2356.rs2
-rw-r--r--src/tools/clippy/tests/ui/items_after_test_module/auxiliary/tests.rs1
-rw-r--r--src/tools/clippy/tests/ui/items_after_test_module/block_module.rs23
-rw-r--r--src/tools/clippy/tests/ui/items_after_test_module/block_module.stderr17
-rw-r--r--src/tools/clippy/tests/ui/items_after_test_module/imported_module.rs20
-rw-r--r--src/tools/clippy/tests/ui/iter_cloned_collect.fixed2
-rw-r--r--src/tools/clippy/tests/ui/iter_cloned_collect.rs2
-rw-r--r--src/tools/clippy/tests/ui/iter_count.fixed4
-rw-r--r--src/tools/clippy/tests/ui/iter_count.rs4
-rw-r--r--src/tools/clippy/tests/ui/iter_kv_map.fixed2
-rw-r--r--src/tools/clippy/tests/ui/iter_kv_map.rs2
-rw-r--r--src/tools/clippy/tests/ui/iter_next_slice.fixed2
-rw-r--r--src/tools/clippy/tests/ui/iter_next_slice.rs2
-rw-r--r--src/tools/clippy/tests/ui/iter_nth.rs2
-rw-r--r--src/tools/clippy/tests/ui/iter_nth_zero.fixed2
-rw-r--r--src/tools/clippy/tests/ui/iter_nth_zero.rs2
-rw-r--r--src/tools/clippy/tests/ui/iter_on_empty_collections.fixed2
-rw-r--r--src/tools/clippy/tests/ui/iter_on_empty_collections.rs2
-rw-r--r--src/tools/clippy/tests/ui/iter_on_single_items.fixed2
-rw-r--r--src/tools/clippy/tests/ui/iter_on_single_items.rs2
-rw-r--r--src/tools/clippy/tests/ui/iter_overeager_cloned.fixed2
-rw-r--r--src/tools/clippy/tests/ui/iter_overeager_cloned.rs2
-rw-r--r--src/tools/clippy/tests/ui/iter_skip_next.fixed4
-rw-r--r--src/tools/clippy/tests/ui/iter_skip_next.rs4
-rw-r--r--src/tools/clippy/tests/ui/iter_with_drain.fixed2
-rw-r--r--src/tools/clippy/tests/ui/iter_with_drain.rs2
-rw-r--r--src/tools/clippy/tests/ui/large_const_arrays.fixed2
-rw-r--r--src/tools/clippy/tests/ui/large_const_arrays.rs2
-rw-r--r--src/tools/clippy/tests/ui/large_digit_groups.fixed2
-rw-r--r--src/tools/clippy/tests/ui/large_digit_groups.rs2
-rw-r--r--src/tools/clippy/tests/ui/large_enum_variant.rs2
-rw-r--r--src/tools/clippy/tests/ui/large_types_passed_by_value.rs4
-rw-r--r--src/tools/clippy/tests/ui/len_zero.fixed6
-rw-r--r--src/tools/clippy/tests/ui/len_zero.rs6
-rw-r--r--src/tools/clippy/tests/ui/len_zero.stderr16
-rw-r--r--src/tools/clippy/tests/ui/len_zero_ranges.fixed2
-rw-r--r--src/tools/clippy/tests/ui/len_zero_ranges.rs2
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_untyped.rs20
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_untyped.stderr48
-rw-r--r--src/tools/clippy/tests/ui/let_unit.fixed2
-rw-r--r--src/tools/clippy/tests/ui/let_unit.rs2
-rw-r--r--src/tools/clippy/tests/ui/let_with_type_underscore.rs27
-rw-r--r--src/tools/clippy/tests/ui/let_with_type_underscore.stderr38
-rw-r--r--src/tools/clippy/tests/ui/lines_filter_map_ok.fixed2
-rw-r--r--src/tools/clippy/tests/ui/lines_filter_map_ok.rs2
-rw-r--r--src/tools/clippy/tests/ui/lossy_float_literal.fixed2
-rw-r--r--src/tools/clippy/tests/ui/lossy_float_literal.rs2
-rw-r--r--src/tools/clippy/tests/ui/macro_use_imports.fixed10
-rw-r--r--src/tools/clippy/tests/ui/macro_use_imports.rs10
-rw-r--r--src/tools/clippy/tests/ui/macro_use_imports_expect.rs8
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.edition2018.fixed8
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.edition2021.fixed8
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.rs8
-rw-r--r--src/tools/clippy/tests/ui/manual_async_fn.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_async_fn.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_bits.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_bits.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_filter.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_filter.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_filter_map.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_filter_map.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_find_fixable.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_find_fixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_find_map.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_find_map.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_instant_elapsed.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_instant_elapsed.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_is_ascii_check.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_is_ascii_check.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else.rs15
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else.stderr82
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else_match.stderr4
-rw-r--r--src/tools/clippy/tests/ui/manual_main_separator_str.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_main_separator_str.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_map_option.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_map_option.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_map_option_2.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_map_option_2.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_next_back.fixed36
-rw-r--r--src/tools/clippy/tests/ui/manual_next_back.rs36
-rw-r--r--src/tools/clippy/tests/ui/manual_next_back.stderr16
-rw-r--r--src/tools/clippy/tests/ui/manual_ok_or.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_ok_or.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_rem_euclid.fixed4
-rw-r--r--src/tools/clippy/tests/ui/manual_rem_euclid.rs4
-rw-r--r--src/tools/clippy/tests/ui/manual_retain.fixed6
-rw-r--r--src/tools/clippy/tests/ui/manual_retain.rs6
-rw-r--r--src/tools/clippy/tests/ui/manual_saturating_arithmetic.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_saturating_arithmetic.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_slice_size_calculation.fixed46
-rw-r--r--src/tools/clippy/tests/ui/manual_slice_size_calculation.rs10
-rw-r--r--src/tools/clippy/tests/ui/manual_slice_size_calculation.stderr41
-rw-r--r--src/tools/clippy/tests/ui/manual_split_once.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_split_once.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_str_repeat.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_str_repeat.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_string_new.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_string_new.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_unwrap_or.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_unwrap_or.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_while_let_some.fixed93
-rw-r--r--src/tools/clippy/tests/ui/manual_while_let_some.rs93
-rw-r--r--src/tools/clippy/tests/ui/manual_while_let_some.stderr87
-rw-r--r--src/tools/clippy/tests/ui/map_clone.fixed2
-rw-r--r--src/tools/clippy/tests/ui/map_clone.rs2
-rw-r--r--src/tools/clippy/tests/ui/map_collect_result_unit.fixed2
-rw-r--r--src/tools/clippy/tests/ui/map_collect_result_unit.rs2
-rw-r--r--src/tools/clippy/tests/ui/map_flatten_fixable.fixed2
-rw-r--r--src/tools/clippy/tests/ui/map_flatten_fixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/map_identity.fixed2
-rw-r--r--src/tools/clippy/tests/ui/map_identity.rs2
-rw-r--r--src/tools/clippy/tests/ui/map_unwrap_or.rs2
-rw-r--r--src/tools/clippy/tests/ui/map_unwrap_or_fixable.fixed4
-rw-r--r--src/tools/clippy/tests/ui/map_unwrap_or_fixable.rs4
-rw-r--r--src/tools/clippy/tests/ui/match_as_ref.fixed2
-rw-r--r--src/tools/clippy/tests/ui/match_as_ref.rs2
-rw-r--r--src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed4
-rw-r--r--src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs2
-rw-r--r--src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr8
-rw-r--r--src/tools/clippy/tests/ui/match_ref_pats.fixed2
-rw-r--r--src/tools/clippy/tests/ui/match_ref_pats.rs2
-rw-r--r--src/tools/clippy/tests/ui/match_result_ok.fixed2
-rw-r--r--src/tools/clippy/tests/ui/match_result_ok.rs2
-rw-r--r--src/tools/clippy/tests/ui/match_same_arms.rs82
-rw-r--r--src/tools/clippy/tests/ui/match_same_arms2.rs6
-rw-r--r--src/tools/clippy/tests/ui/match_same_arms2.stderr17
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding.fixed2
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding.rs2
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding2.fixed2
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding2.rs2
-rw-r--r--src/tools/clippy/tests/ui/match_str_case_mismatch.fixed2
-rw-r--r--src/tools/clippy/tests/ui/match_str_case_mismatch.rs2
-rw-r--r--src/tools/clippy/tests/ui/match_wildcard_for_single_variants.fixed2
-rw-r--r--src/tools/clippy/tests/ui/match_wildcard_for_single_variants.rs2
-rw-r--r--src/tools/clippy/tests/ui/mem_forget.rs2
-rw-r--r--src/tools/clippy/tests/ui/mem_replace.fixed2
-rw-r--r--src/tools/clippy/tests/ui/mem_replace.rs2
-rw-r--r--src/tools/clippy/tests/ui/mem_replace_macro.rs2
-rw-r--r--src/tools/clippy/tests/ui/methods.rs2
-rw-r--r--src/tools/clippy/tests/ui/methods_fixable.fixed2
-rw-r--r--src/tools/clippy/tests/ui/methods_fixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/mismatched_target_os_non_unix.fixed2
-rw-r--r--src/tools/clippy/tests/ui/mismatched_target_os_non_unix.rs2
-rw-r--r--src/tools/clippy/tests/ui/mismatched_target_os_unix.fixed2
-rw-r--r--src/tools/clippy/tests/ui/mismatched_target_os_unix.rs2
-rw-r--r--src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs4
-rw-r--r--src/tools/clippy/tests/ui/missing_doc.rs4
-rw-r--r--src/tools/clippy/tests/ui/missing_doc_impl.rs2
-rw-r--r--src/tools/clippy/tests/ui/missing_spin_loop.fixed2
-rw-r--r--src/tools/clippy/tests/ui/missing_spin_loop.rs2
-rw-r--r--src/tools/clippy/tests/ui/missing_spin_loop_no_std.fixed2
-rw-r--r--src/tools/clippy/tests/ui/missing_spin_loop_no_std.rs2
-rw-r--r--src/tools/clippy/tests/ui/mistyped_literal_suffix.fixed4
-rw-r--r--src/tools/clippy/tests/ui/mistyped_literal_suffix.rs4
-rw-r--r--src/tools/clippy/tests/ui/module_name_repetitions.rs2
-rw-r--r--src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs4
-rw-r--r--src/tools/clippy/tests/ui/must_use_candidates.fixed2
-rw-r--r--src/tools/clippy/tests/ui/must_use_candidates.rs2
-rw-r--r--src/tools/clippy/tests/ui/must_use_unit.fixed4
-rw-r--r--src/tools/clippy/tests/ui/must_use_unit.rs4
-rw-r--r--src/tools/clippy/tests/ui/mut_mut.rs2
-rw-r--r--src/tools/clippy/tests/ui/mut_mutex_lock.fixed2
-rw-r--r--src/tools/clippy/tests/ui/mut_mutex_lock.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_arbitrary_self_type.fixed2
-rw-r--r--src/tools/clippy/tests/ui/needless_arbitrary_self_type.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.stderr2
-rw-r--r--src/tools/clippy/tests/ui/needless_bitwise_bool.fixed2
-rw-r--r--src/tools/clippy/tests/ui/needless_bitwise_bool.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_bool/fixable.fixed9
-rw-r--r--src/tools/clippy/tests/ui/needless_bool/fixable.rs9
-rw-r--r--src/tools/clippy/tests/ui/needless_bool/fixable.stderr24
-rw-r--r--src/tools/clippy/tests/ui/needless_bool_assign.fixed33
-rw-r--r--src/tools/clippy/tests/ui/needless_bool_assign.rs45
-rw-r--r--src/tools/clippy/tests/ui/needless_bool_assign.stderr53
-rw-r--r--src/tools/clippy/tests/ui/needless_borrow.fixed2
-rw-r--r--src/tools/clippy/tests/ui/needless_borrow.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_borrowed_ref.fixed2
-rw-r--r--src/tools/clippy/tests/ui/needless_borrowed_ref.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_collect.fixed14
-rw-r--r--src/tools/clippy/tests/ui/needless_collect.rs14
-rw-r--r--src/tools/clippy/tests/ui/needless_collect.stderr26
-rw-r--r--src/tools/clippy/tests/ui/needless_for_each_fixable.fixed4
-rw-r--r--src/tools/clippy/tests/ui/needless_for_each_fixable.rs4
-rw-r--r--src/tools/clippy/tests/ui/needless_late_init.fixed4
-rw-r--r--src/tools/clippy/tests/ui/needless_late_init.rs4
-rw-r--r--src/tools/clippy/tests/ui/needless_lifetimes.fixed4
-rw-r--r--src/tools/clippy/tests/ui/needless_lifetimes.rs4
-rw-r--r--src/tools/clippy/tests/ui/needless_match.fixed2
-rw-r--r--src/tools/clippy/tests/ui/needless_match.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_option_as_deref.fixed2
-rw-r--r--src/tools/clippy/tests/ui/needless_option_as_deref.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_option_take.fixed2
-rw-r--r--src/tools/clippy/tests/ui/needless_option_take.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_parens_on_range_literals.fixed4
-rw-r--r--src/tools/clippy/tests/ui/needless_parens_on_range_literals.rs4
-rw-r--r--src/tools/clippy/tests/ui/needless_question_mark.fixed2
-rw-r--r--src/tools/clippy/tests/ui/needless_question_mark.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_return.fixed7
-rw-r--r--src/tools/clippy/tests/ui/needless_return.rs7
-rw-r--r--src/tools/clippy/tests/ui/needless_return.stderr26
-rw-r--r--src/tools/clippy/tests/ui/needless_splitn.fixed4
-rw-r--r--src/tools/clippy/tests/ui/needless_splitn.rs4
-rw-r--r--src/tools/clippy/tests/ui/neg_multiply.fixed2
-rw-r--r--src/tools/clippy/tests/ui/neg_multiply.rs2
-rw-r--r--src/tools/clippy/tests/ui/no_mangle_with_rust_abi.rs2
-rw-r--r--src/tools/clippy/tests/ui/non_minimal_cfg.fixed17
-rw-r--r--src/tools/clippy/tests/ui/non_minimal_cfg.rs17
-rw-r--r--src/tools/clippy/tests/ui/non_minimal_cfg.stderr28
-rw-r--r--src/tools/clippy/tests/ui/non_minimal_cfg2.rs6
-rw-r--r--src/tools/clippy/tests/ui/non_minimal_cfg2.stderr10
-rw-r--r--src/tools/clippy/tests/ui/non_octal_unix_permissions.fixed4
-rw-r--r--src/tools/clippy/tests/ui/non_octal_unix_permissions.rs4
-rw-r--r--src/tools/clippy/tests/ui/nonminimal_bool_methods.fixed2
-rw-r--r--src/tools/clippy/tests/ui/nonminimal_bool_methods.rs2
-rw-r--r--src/tools/clippy/tests/ui/numbered_fields.fixed2
-rw-r--r--src/tools/clippy/tests/ui/numbered_fields.rs2
-rw-r--r--src/tools/clippy/tests/ui/obfuscated_if_else.fixed2
-rw-r--r--src/tools/clippy/tests/ui/obfuscated_if_else.rs2
-rw-r--r--src/tools/clippy/tests/ui/octal_escapes.rs1
-rw-r--r--src/tools/clippy/tests/ui/octal_escapes.stderr18
-rw-r--r--src/tools/clippy/tests/ui/option_as_ref_deref.fixed2
-rw-r--r--src/tools/clippy/tests/ui/option_as_ref_deref.rs2
-rw-r--r--src/tools/clippy/tests/ui/option_env_unwrap.rs2
-rw-r--r--src/tools/clippy/tests/ui/option_filter_map.fixed2
-rw-r--r--src/tools/clippy/tests/ui/option_filter_map.rs2
-rw-r--r--src/tools/clippy/tests/ui/option_if_let_else.fixed18
-rw-r--r--src/tools/clippy/tests/ui/option_if_let_else.rs18
-rw-r--r--src/tools/clippy/tests/ui/option_if_let_else.stderr47
-rw-r--r--src/tools/clippy/tests/ui/option_map_or_none.fixed2
-rw-r--r--src/tools/clippy/tests/ui/option_map_or_none.rs2
-rw-r--r--src/tools/clippy/tests/ui/option_map_unit_fn_fixable.fixed2
-rw-r--r--src/tools/clippy/tests/ui/option_map_unit_fn_fixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/or_fun_call.fixed2
-rw-r--r--src/tools/clippy/tests/ui/or_fun_call.rs2
-rw-r--r--src/tools/clippy/tests/ui/or_then_unwrap.fixed2
-rw-r--r--src/tools/clippy/tests/ui/or_then_unwrap.rs2
-rw-r--r--src/tools/clippy/tests/ui/partialeq_to_none.fixed3
-rw-r--r--src/tools/clippy/tests/ui/partialeq_to_none.rs3
-rw-r--r--src/tools/clippy/tests/ui/partialeq_to_none.stderr30
-rw-r--r--src/tools/clippy/tests/ui/path_buf_push_overwrite.fixed2
-rw-r--r--src/tools/clippy/tests/ui/path_buf_push_overwrite.rs2
-rw-r--r--src/tools/clippy/tests/ui/patterns.fixed2
-rw-r--r--src/tools/clippy/tests/ui/patterns.rs2
-rw-r--r--src/tools/clippy/tests/ui/precedence.fixed2
-rw-r--r--src/tools/clippy/tests/ui/precedence.rs2
-rw-r--r--src/tools/clippy/tests/ui/print_stdout_build_script.rs2
-rw-r--r--src/tools/clippy/tests/ui/print_with_newline.rs2
-rw-r--r--src/tools/clippy/tests/ui/println_empty_string.fixed2
-rw-r--r--src/tools/clippy/tests/ui/println_empty_string.rs2
-rw-r--r--src/tools/clippy/tests/ui/ptr_as_ptr.fixed4
-rw-r--r--src/tools/clippy/tests/ui/ptr_as_ptr.rs4
-rw-r--r--src/tools/clippy/tests/ui/ptr_eq.fixed2
-rw-r--r--src/tools/clippy/tests/ui/ptr_eq.rs2
-rw-r--r--src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed2
-rw-r--r--src/tools/clippy/tests/ui/ptr_offset_with_cast.rs2
-rw-r--r--src/tools/clippy/tests/ui/question_mark.fixed2
-rw-r--r--src/tools/clippy/tests/ui/question_mark.rs2
-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_plus_minus_one.fixed2
-rw-r--r--src/tools/clippy/tests/ui/range_plus_minus_one.rs2
-rw-r--r--src/tools/clippy/tests/ui/rc_buffer.fixed2
-rw-r--r--src/tools/clippy/tests/ui/rc_buffer.rs2
-rw-r--r--src/tools/clippy/tests/ui/rc_buffer_arc.fixed2
-rw-r--r--src/tools/clippy/tests/ui/rc_buffer_arc.rs2
-rw-r--r--src/tools/clippy/tests/ui/redundant_allocation_fixable.fixed2
-rw-r--r--src/tools/clippy/tests/ui/redundant_allocation_fixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/redundant_async_block.fixed2
-rw-r--r--src/tools/clippy/tests/ui/redundant_async_block.rs2
-rw-r--r--src/tools/clippy/tests/ui/redundant_clone.fixed3
-rw-r--r--src/tools/clippy/tests/ui/redundant_clone.rs3
-rw-r--r--src/tools/clippy/tests/ui/redundant_clone.stderr60
-rw-r--r--src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed2
-rw-r--r--src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/redundant_field_names.fixed2
-rw-r--r--src/tools/clippy/tests/ui/redundant_field_names.rs2
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.fixed2
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.rs2
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed2
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs2
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed23
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_option.rs35
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_option.stderr64
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_poll.fixed2
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_poll.rs2
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed28
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs40
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr62
-rw-r--r--src/tools/clippy/tests/ui/redundant_pub_crate.fixed2
-rw-r--r--src/tools/clippy/tests/ui/redundant_pub_crate.rs2
-rw-r--r--src/tools/clippy/tests/ui/redundant_slicing.fixed2
-rw-r--r--src/tools/clippy/tests/ui/redundant_slicing.rs2
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed2
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes.rs2
-rw-r--r--src/tools/clippy/tests/ui/ref_patterns.rs19
-rw-r--r--src/tools/clippy/tests/ui/ref_patterns.stderr27
-rw-r--r--src/tools/clippy/tests/ui/regex.rs2
-rw-r--r--src/tools/clippy/tests/ui/regex.stderr40
-rw-r--r--src/tools/clippy/tests/ui/rename.fixed15
-rw-r--r--src/tools/clippy/tests/ui/rename.rs15
-rw-r--r--src/tools/clippy/tests/ui/rename.stderr122
-rw-r--r--src/tools/clippy/tests/ui/renamed_builtin_attr.fixed2
-rw-r--r--src/tools/clippy/tests/ui/renamed_builtin_attr.rs2
-rw-r--r--src/tools/clippy/tests/ui/repeat_once.fixed2
-rw-r--r--src/tools/clippy/tests/ui/repeat_once.rs2
-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.fixed2
-rw-r--r--src/tools/clippy/tests/ui/result_map_unit_fn_fixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed2
-rw-r--r--src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed2
-rw-r--r--src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/same_functions_in_if_condition.rs2
-rw-r--r--src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr6
-rw-r--r--src/tools/clippy/tests/ui/same_name_method.rs2
-rw-r--r--src/tools/clippy/tests/ui/search_is_some.rs2
-rw-r--r--src/tools/clippy/tests/ui/search_is_some_fixable_none.fixed2
-rw-r--r--src/tools/clippy/tests/ui/search_is_some_fixable_none.rs2
-rw-r--r--src/tools/clippy/tests/ui/search_is_some_fixable_some.fixed2
-rw-r--r--src/tools/clippy/tests/ui/search_is_some_fixable_some.rs2
-rw-r--r--src/tools/clippy/tests/ui/seek_from_current.fixed2
-rw-r--r--src/tools/clippy/tests/ui/seek_from_current.rs2
-rw-r--r--src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed2
-rw-r--r--src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs2
-rw-r--r--src/tools/clippy/tests/ui/semicolon_inside_block.fixed2
-rw-r--r--src/tools/clippy/tests/ui/semicolon_inside_block.rs2
-rw-r--r--src/tools/clippy/tests/ui/semicolon_outside_block.fixed2
-rw-r--r--src/tools/clippy/tests/ui/semicolon_outside_block.rs2
-rw-r--r--src/tools/clippy/tests/ui/shadow.rs19
-rw-r--r--src/tools/clippy/tests/ui/shadow.stderr92
-rw-r--r--src/tools/clippy/tests/ui/short_circuit_statement.fixed2
-rw-r--r--src/tools/clippy/tests/ui/short_circuit_statement.rs2
-rw-r--r--src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs2
-rw-r--r--src/tools/clippy/tests/ui/significant_drop_tightening.fixed2
-rw-r--r--src/tools/clippy/tests/ui/significant_drop_tightening.rs2
-rw-r--r--src/tools/clippy/tests/ui/single_char_add_str.fixed2
-rw-r--r--src/tools/clippy/tests/ui/single_char_add_str.rs2
-rw-r--r--src/tools/clippy/tests/ui/single_char_pattern.fixed2
-rw-r--r--src/tools/clippy/tests/ui/single_char_pattern.rs2
-rw-r--r--src/tools/clippy/tests/ui/single_component_path_imports.fixed2
-rw-r--r--src/tools/clippy/tests/ui/single_component_path_imports.rs2
-rw-r--r--src/tools/clippy/tests/ui/single_element_loop.fixed2
-rw-r--r--src/tools/clippy/tests/ui/single_element_loop.rs2
-rw-r--r--src/tools/clippy/tests/ui/single_match_else.rs2
-rw-r--r--src/tools/clippy/tests/ui/skip_while_next.rs2
-rw-r--r--src/tools/clippy/tests/ui/stable_sort_primitive.fixed2
-rw-r--r--src/tools/clippy/tests/ui/stable_sort_primitive.rs2
-rw-r--r--src/tools/clippy/tests/ui/starts_ends_with.fixed2
-rw-r--r--src/tools/clippy/tests/ui/starts_ends_with.rs2
-rw-r--r--src/tools/clippy/tests/ui/string_add.rs2
-rw-r--r--src/tools/clippy/tests/ui/string_add_assign.fixed2
-rw-r--r--src/tools/clippy/tests/ui/string_add_assign.rs2
-rw-r--r--src/tools/clippy/tests/ui/string_extend.fixed2
-rw-r--r--src/tools/clippy/tests/ui/string_extend.rs2
-rw-r--r--src/tools/clippy/tests/ui/string_from_utf8_as_bytes.fixed2
-rw-r--r--src/tools/clippy/tests/ui/string_from_utf8_as_bytes.rs2
-rw-r--r--src/tools/clippy/tests/ui/string_lit_as_bytes.fixed16
-rw-r--r--src/tools/clippy/tests/ui/string_lit_as_bytes.rs16
-rw-r--r--src/tools/clippy/tests/ui/string_lit_as_bytes.stderr25
-rw-r--r--src/tools/clippy/tests/ui/strlen_on_c_strings.fixed2
-rw-r--r--src/tools/clippy/tests/ui/strlen_on_c_strings.rs2
-rw-r--r--src/tools/clippy/tests/ui/suspicious_doc_comments.fixed2
-rw-r--r--src/tools/clippy/tests/ui/suspicious_doc_comments.rs2
-rw-r--r--src/tools/clippy/tests/ui/suspicious_else_formatting.rs2
-rw-r--r--src/tools/clippy/tests/ui/suspicious_operation_groupings.fixed2
-rw-r--r--src/tools/clippy/tests/ui/suspicious_operation_groupings.rs2
-rw-r--r--src/tools/clippy/tests/ui/swap.fixed4
-rw-r--r--src/tools/clippy/tests/ui/swap.rs4
-rw-r--r--src/tools/clippy/tests/ui/swap_ptr_to_ref.fixed2
-rw-r--r--src/tools/clippy/tests/ui/swap_ptr_to_ref.rs2
-rw-r--r--src/tools/clippy/tests/ui/tabs_in_doc_comments.fixed2
-rw-r--r--src/tools/clippy/tests/ui/tabs_in_doc_comments.rs2
-rw-r--r--src/tools/clippy/tests/ui/tests_outside_test_module.rs2
-rw-r--r--src/tools/clippy/tests/ui/to_digit_is_some.fixed2
-rw-r--r--src/tools/clippy/tests/ui/to_digit_is_some.rs2
-rw-r--r--src/tools/clippy/tests/ui/toplevel_ref_arg.fixed4
-rw-r--r--src/tools/clippy/tests/ui/toplevel_ref_arg.rs4
-rw-r--r--src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.rs2
-rw-r--r--src/tools/clippy/tests/ui/track-diagnostics.rs5
-rw-r--r--src/tools/clippy/tests/ui/trailing_empty_array.rs2
-rw-r--r--src/tools/clippy/tests/ui/trait_duplication_in_bounds.fixed12
-rw-r--r--src/tools/clippy/tests/ui/trait_duplication_in_bounds.rs12
-rw-r--r--src/tools/clippy/tests/ui/trait_duplication_in_bounds.stderr24
-rw-r--r--src/tools/clippy/tests/ui/transmute_32bit.rs2
-rw-r--r--src/tools/clippy/tests/ui/transmute_32bit.stderr29
-rw-r--r--src/tools/clippy/tests/ui/transmute_64bit.rs2
-rw-r--r--src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed2
-rw-r--r--src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs2
-rw-r--r--src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed2
-rw-r--r--src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs2
-rw-r--r--src/tools/clippy/tests/ui/trim_split_whitespace.fixed2
-rw-r--r--src/tools/clippy/tests/ui/trim_split_whitespace.rs2
-rw-r--r--src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs4
-rw-r--r--src/tools/clippy/tests/ui/try_err.fixed4
-rw-r--r--src/tools/clippy/tests/ui/try_err.rs4
-rw-r--r--src/tools/clippy/tests/ui/types.fixed2
-rw-r--r--src/tools/clippy/tests/ui/types.rs2
-rw-r--r--src/tools/clippy/tests/ui/unchecked_duration_subtraction.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unchecked_duration_subtraction.rs2
-rw-r--r--src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs2
-rw-r--r--src/tools/clippy/tests/ui/unicode.fixed4
-rw-r--r--src/tools/clippy/tests/ui/unicode.rs4
-rw-r--r--src/tools/clippy/tests/ui/uninit.rs4
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args.fixed4
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args.rs4
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed8
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed8
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args_panic.rs8
-rw-r--r--src/tools/clippy/tests/ui/unit_arg.rs2
-rw-r--r--src/tools/clippy/tests/ui/unit_arg_empty_blocks.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs2
-rw-r--r--src/tools/clippy/tests/ui/unknown_clippy_lints.fixed4
-rw-r--r--src/tools/clippy/tests/ui/unknown_clippy_lints.rs2
-rw-r--r--src/tools/clippy/tests/ui/unknown_clippy_lints.stderr2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_box_returns.rs10
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_clone.rs13
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_clone.stderr52
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_fold.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_fold.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_iter_cloned.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_iter_cloned.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_join.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_join.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed4
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs4
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_operation.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_operation.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_self_imports.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_self_imports.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_sort_by.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_sort_by.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_struct_initialization.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_struct_initialization.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.fixed4
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.rs4
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs2
-rw-r--r--src/tools/clippy/tests/ui/unneeded_wildcard_pattern.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unneeded_wildcard_pattern.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns2.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns2.rs2
-rw-r--r--src/tools/clippy/tests/ui/unreadable_literal.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unreadable_literal.rs2
-rw-r--r--src/tools/clippy/tests/ui/unseparated_prefix_literals.fixed4
-rw-r--r--src/tools/clippy/tests/ui/unseparated_prefix_literals.rs4
-rw-r--r--src/tools/clippy/tests/ui/unused_rounding.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unused_rounding.rs2
-rw-r--r--src/tools/clippy/tests/ui/unused_unit.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unused_unit.rs2
-rw-r--r--src/tools/clippy/tests/ui/unwrap_or_else_default.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unwrap_or_else_default.rs2
-rw-r--r--src/tools/clippy/tests/ui/use_self.fixed4
-rw-r--r--src/tools/clippy/tests/ui/use_self.rs4
-rw-r--r--src/tools/clippy/tests/ui/use_self_trait.fixed6
-rw-r--r--src/tools/clippy/tests/ui/use_self_trait.rs6
-rw-r--r--src/tools/clippy/tests/ui/use_self_trait.stderr2
-rw-r--r--src/tools/clippy/tests/ui/used_underscore_binding.rs2
-rw-r--r--src/tools/clippy/tests/ui/useless_asref.fixed2
-rw-r--r--src/tools/clippy/tests/ui/useless_asref.rs2
-rw-r--r--src/tools/clippy/tests/ui/useless_attribute.fixed4
-rw-r--r--src/tools/clippy/tests/ui/useless_attribute.rs4
-rw-r--r--src/tools/clippy/tests/ui/useless_conversion.fixed8
-rw-r--r--src/tools/clippy/tests/ui/useless_conversion.rs8
-rw-r--r--src/tools/clippy/tests/ui/useless_conversion.stderr32
-rw-r--r--src/tools/clippy/tests/ui/vec.fixed2
-rw-r--r--src/tools/clippy/tests/ui/vec.rs2
-rw-r--r--src/tools/clippy/tests/ui/vec_box_sized.fixed2
-rw-r--r--src/tools/clippy/tests/ui/vec_box_sized.rs2
-rw-r--r--src/tools/clippy/tests/ui/while_let_on_iterator.fixed2
-rw-r--r--src/tools/clippy/tests/ui/while_let_on_iterator.rs2
-rw-r--r--src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed4
-rw-r--r--src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs4
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports.fixed6
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports.rs6
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed10
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed10
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.rs10
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.stderr132
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_cfgtest.rs19
-rw-r--r--src/tools/clippy/tests/ui/write_with_newline.rs4
-rw-r--r--src/tools/clippy/tests/ui/write_with_newline.stderr6
-rw-r--r--src/tools/clippy/tests/ui/writeln_empty_string.fixed2
-rw-r--r--src/tools/clippy/tests/ui/writeln_empty_string.rs2
-rw-r--r--src/tools/clippy/tests/ui/zero_ptr.fixed2
-rw-r--r--src/tools/clippy/tests/ui/zero_ptr.rs2
-rw-r--r--src/tools/clippy/tests/ui/zero_ptr_no_std.fixed2
-rw-r--r--src/tools/clippy/tests/ui/zero_ptr_no_std.rs2
-rw-r--r--src/tools/clippy/triagebot.toml2
1003 files changed, 7312 insertions, 3782 deletions
diff --git a/src/tools/clippy/.github/workflows/clippy.yml b/src/tools/clippy/.github/workflows/clippy.yml
index b99213011..a9d42159c 100644
--- a/src/tools/clippy/.github/workflows/clippy.yml
+++ b/src/tools/clippy/.github/workflows/clippy.yml
@@ -39,7 +39,7 @@ jobs:
github_token: "${{ secrets.github_token }}"
- name: Checkout
- uses: actions/checkout@v3.0.2
+ uses: actions/checkout@v3
- name: Install toolchain
run: rustup show active-toolchain
diff --git a/src/tools/clippy/.github/workflows/clippy_bors.yml b/src/tools/clippy/.github/workflows/clippy_bors.yml
index 93198aabd..30a156c92 100644
--- a/src/tools/clippy/.github/workflows/clippy_bors.yml
+++ b/src/tools/clippy/.github/workflows/clippy_bors.yml
@@ -27,7 +27,7 @@ jobs:
github_token: "${{ secrets.github_token }}"
- name: Checkout
- uses: actions/checkout@v3.0.2
+ uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
@@ -83,7 +83,7 @@ jobs:
github_token: "${{ secrets.github_token }}"
- name: Checkout
- uses: actions/checkout@v3.0.2
+ uses: actions/checkout@v3
- name: Install toolchain
run: rustup show active-toolchain
@@ -149,7 +149,7 @@ jobs:
github_token: "${{ secrets.github_token }}"
- name: Checkout
- uses: actions/checkout@v3.0.2
+ uses: actions/checkout@v3
- name: Install toolchain
run: rustup show active-toolchain
@@ -173,7 +173,7 @@ jobs:
github_token: "${{ secrets.github_token }}"
- name: Checkout
- uses: actions/checkout@v3.0.2
+ uses: actions/checkout@v3
- name: Install toolchain
run: rustup show active-toolchain
@@ -233,7 +233,7 @@ jobs:
github_token: "${{ secrets.github_token }}"
- name: Checkout
- uses: actions/checkout@v3.0.2
+ uses: actions/checkout@v3
- name: Install toolchain
run: rustup show active-toolchain
diff --git a/src/tools/clippy/.github/workflows/clippy_dev.yml b/src/tools/clippy/.github/workflows/clippy_dev.yml
index 14f20212a..514706d64 100644
--- a/src/tools/clippy/.github/workflows/clippy_dev.yml
+++ b/src/tools/clippy/.github/workflows/clippy_dev.yml
@@ -25,7 +25,7 @@ jobs:
steps:
# Setup
- name: Checkout
- uses: actions/checkout@v3.0.2
+ uses: actions/checkout@v3
# Run
- name: Build
diff --git a/src/tools/clippy/.github/workflows/deploy.yml b/src/tools/clippy/.github/workflows/deploy.yml
index 71d71d103..f42928c2c 100644
--- a/src/tools/clippy/.github/workflows/deploy.yml
+++ b/src/tools/clippy/.github/workflows/deploy.yml
@@ -21,10 +21,10 @@ jobs:
steps:
# Setup
- name: Checkout
- uses: actions/checkout@v3.0.2
+ uses: actions/checkout@v3
- name: Checkout
- uses: actions/checkout@v3.0.2
+ uses: actions/checkout@v3
with:
ref: ${{ env.TARGET_BRANCH }}
path: 'out'
diff --git a/src/tools/clippy/.github/workflows/remark.yml b/src/tools/clippy/.github/workflows/remark.yml
index 116058b7c..7d25b6a2b 100644
--- a/src/tools/clippy/.github/workflows/remark.yml
+++ b/src/tools/clippy/.github/workflows/remark.yml
@@ -16,10 +16,10 @@ jobs:
steps:
# Setup
- name: Checkout
- uses: actions/checkout@v3.0.2
+ uses: actions/checkout@v3
- name: Setup Node.js
- uses: actions/setup-node@v1.4.4
+ uses: actions/setup-node@v3
with:
node-version: '14.x'
@@ -36,6 +36,12 @@ jobs:
- name: Check *.md files
run: git ls-files -z '*.md' | xargs -0 -n 1 -I {} ./node_modules/.bin/remark {} -u lint -f > /dev/null
+ - name: Linkcheck book
+ run: |
+ rustup toolchain install nightly --component rust-docs
+ curl https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh -o linkcheck.sh
+ sh linkcheck.sh clippy --path ./book
+
- name: Build mdbook
run: mdbook build book
diff --git a/src/tools/clippy/CHANGELOG.md b/src/tools/clippy/CHANGELOG.md
index 559b560dd..79f2a4711 100644
--- a/src/tools/clippy/CHANGELOG.md
+++ b/src/tools/clippy/CHANGELOG.md
@@ -6,11 +6,126 @@ document.
## Unreleased / Beta / In Rust Nightly
-[7f27e2e7...master](https://github.com/rust-lang/rust-clippy/compare/7f27e2e7...master)
+[149392b0...master](https://github.com/rust-lang/rust-clippy/compare/149392b0...master)
+
+## Rust 1.69
+
+Current stable, released 2023-04-20
+
+[7f27e2e7...149392b0](https://github.com/rust-lang/rust-clippy/compare/7f27e2e7...149392b0)
+
+### New Lints
+
+* [`no_mangle_with_rust_abi`]
+ [#10369](https://github.com/rust-lang/rust-clippy/pull/10369)
+* [`significant_drop_tightening`]
+ [#10163](https://github.com/rust-lang/rust-clippy/pull/10163)
+* [`suspicious_command_arg_space`]
+ [#10317](https://github.com/rust-lang/rust-clippy/pull/10317)
+* [`let_underscore_untyped`]
+ [#10356](https://github.com/rust-lang/rust-clippy/pull/10356)
+* [`question_mark_used`]
+ [#10342](https://github.com/rust-lang/rust-clippy/pull/10342)
+* [`extra_unused_type_parameters`]
+ [#10028](https://github.com/rust-lang/rust-clippy/pull/10028)
+* [`impl_trait_in_params`]
+ [10197](https://github.com/rust-lang/rust-clippy/pull/10197)
+* [`transmute_int_to_non_zero`]
+ [#10360](https://github.com/rust-lang/rust-clippy/pull/10360)
+* [`multiple_unsafe_ops_per_block`]
+ [#10206](https://github.com/rust-lang/rust-clippy/pull/10206)
+
+### Moves and Deprecations
+
+* Moved [`uninlined_format_args`] to `pedantic` (Now allow-by-default)
+ [#10265](https://github.com/rust-lang/rust-clippy/pull/10265)
+* Moved [`unchecked_duration_subtraction`] to `pedantic` (Now allow-by-default)
+ [#10194](https://github.com/rust-lang/rust-clippy/pull/10194)
+
+### Enhancements
+
+* [`arithmetic_side_effects`]: No longer lints if safe constant values are used.
+ [#10310](https://github.com/rust-lang/rust-clippy/pull/10310)
+* [`needless_lifetimes`]: Now works in local macros
+ [#10257](https://github.com/rust-lang/rust-clippy/pull/10257)
+* [`unused_io_amount`]: Now detects usages of `is_ok` and `is_err`
+ [#10225](https://github.com/rust-lang/rust-clippy/pull/10225)
+* [`missing_docs_in_private_items`]: Added new configuration `missing-docs-in-crate-items` to lint
+ on items visible within the current crate. For example, `pub(crate)` items.
+ [#10303](https://github.com/rust-lang/rust-clippy/pull/10303)
+* [`almost_swapped`]: Now detects almost swaps using `let` statements
+ [#10177](https://github.com/rust-lang/rust-clippy/pull/10177)
+* [`wildcard_enum_match_arm`]: Now lints missing private variants, for local enums
+ [#10250](https://github.com/rust-lang/rust-clippy/pull/10250)
+
+### False Positive Fixes
+
+* [`explicit_auto_deref`]: Now considers projections when determining if auto deref is applicable
+ [#10386](https://github.com/rust-lang/rust-clippy/pull/10386)
+* [`manual_let_else`]: Now considers side effects of branches before linting
+ [#10336](https://github.com/rust-lang/rust-clippy/pull/10336)
+* [`uninlined_format_args`]: No longer lints for arguments with generic parameters
+ [#10343](https://github.com/rust-lang/rust-clippy/pull/10343)
+* [`needless_lifetimes`]: No longer lints signatures in macros if the lifetime is a metavariable
+ [#10380](https://github.com/rust-lang/rust-clippy/pull/10380)
+* [`len_without_is_empty`]: No longer lints if `len` as a non-default signature
+ [#10255](https://github.com/rust-lang/rust-clippy/pull/10255)
+* [`unusual_byte_groupings`]: Relaxed the required restrictions for specific sizes to reduce false
+ positives
+ [#10353](https://github.com/rust-lang/rust-clippy/pull/10353)
+* [`manual_let_else`]: No longer lints `if-else` blocks if they can divergent
+ [#10332](https://github.com/rust-lang/rust-clippy/pull/10332)
+* [`expect_used`], [`unwrap_used`], [`dbg_macro`], [`print_stdout`], [`print_stderr`]: No longer lint
+ in test functions if `allow-expect-in-tests` is set
+ [#10391](https://github.com/rust-lang/rust-clippy/pull/10391)
+* [`unnecessary_safety_comment`]: No longer lints code inside macros
+ [#10106](https://github.com/rust-lang/rust-clippy/pull/10106)
+* [`never_loop`]: No longer lints statements following break statements for outer blocks.
+ [#10311](https://github.com/rust-lang/rust-clippy/pull/10311)
+
+### Suggestion Fixes/Improvements
+
+* [`box_default`]: The suggestion now includes the type for trait objects when needed
+ [#10382](https://github.com/rust-lang/rust-clippy/pull/10382)
+* [`cast_possible_truncation`]: Now suggests using `try_from` or allowing the lint
+ [#10038](https://github.com/rust-lang/rust-clippy/pull/10038)
+* [`invalid_regex`]: Regex errors for non-literals or regular strings containing escape sequences will
+ now show the complete error
+ [#10231](https://github.com/rust-lang/rust-clippy/pull/10231)
+* [`transmutes_expressible_as_ptr_casts`]: The suggestion now works if the base type is borrowed
+ [#10193](https://github.com/rust-lang/rust-clippy/pull/10193)
+* [`needless_return`]: Now removes all semicolons on the same line
+ [#10187](https://github.com/rust-lang/rust-clippy/pull/10187)
+* [`suspicious_to_owned`]: The suggestion now shows all options clearly
+ [#10295](https://github.com/rust-lang/rust-clippy/pull/10295)
+* [`bytes_nth`]: Now suggests the correct replacement based on the context
+ [#10361](https://github.com/rust-lang/rust-clippy/pull/10361)
+* [`bool_assert_comparison`]: The suggestion is now machine applicable
+ [#10218](https://github.com/rust-lang/rust-clippy/pull/10218)
+* [`cast_possible_truncation`]: Corrected the lint name in the help message
+ [#10330](https://github.com/rust-lang/rust-clippy/pull/10330)
+* [`needless_return`]: The suggestion now works on if sequences
+ [#10345](https://github.com/rust-lang/rust-clippy/pull/10345)
+* [`needless_lifetimes`]: The suggestion is now machine applicable
+ [#10222](https://github.com/rust-lang/rust-clippy/pull/10222)
+* [`map_entry`]: The suggestion no longer expands macros
+ [#10346](https://github.com/rust-lang/rust-clippy/pull/10346)
+
+### ICE Fixes
+
+* [`needless_pass_by_value`]: Fixed an ICE caused by how late bounds were handled
+ [#10328](https://github.com/rust-lang/rust-clippy/pull/10328)
+* [`needless_borrow`]: No longer panics on ambiguous projections
+ [#10403](https://github.com/rust-lang/rust-clippy/pull/10403)
+
+### Documentation Improvements
+
+* All configurations are now documented in the Clippy Book
+ [#10199](https://github.com/rust-lang/rust-clippy/pull/10199)
## Rust 1.68
-Current stable, released 2023-03-09
+Released 2023-03-09
[d822110d...7f27e2e7](https://github.com/rust-lang/rust-clippy/compare/d822110d...7f27e2e7)
@@ -4467,6 +4582,7 @@ Released 2018-09-13
[`debug_assert_with_mut_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#debug_assert_with_mut_call
[`decimal_literal_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#decimal_literal_representation
[`declare_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const
+[`default_constructed_unit_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_constructed_unit_structs
[`default_instead_of_iter_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_instead_of_iter_empty
[`default_numeric_fallback`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_numeric_fallback
[`default_trait_access`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_trait_access
@@ -4504,6 +4620,7 @@ Released 2018-09-13
[`else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else
[`empty_drop`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_drop
[`empty_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_enum
+[`empty_line_after_doc_comments`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments
[`empty_line_after_outer_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_outer_attr
[`empty_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_loop
[`empty_structs_with_brackets`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_structs_with_brackets
@@ -4615,6 +4732,7 @@ Released 2018-09-13
[`invisible_characters`]: https://rust-lang.github.io/rust-clippy/master/index.html#invisible_characters
[`is_digit_ascii_radix`]: https://rust-lang.github.io/rust-clippy/master/index.html#is_digit_ascii_radix
[`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
+[`items_after_test_module`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_test_module
[`iter_cloned_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_cloned_collect
[`iter_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_count
[`iter_kv_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_kv_map
@@ -4668,6 +4786,7 @@ Released 2018-09-13
[`manual_main_separator_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_main_separator_str
[`manual_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_map
[`manual_memcpy`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy
+[`manual_next_back`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_next_back
[`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
[`manual_ok_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_or
[`manual_range_contains`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
@@ -4681,6 +4800,7 @@ Released 2018-09-13
[`manual_strip`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip
[`manual_swap`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap
[`manual_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or
+[`manual_while_let_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_while_let_some
[`many_single_char_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#many_single_char_names
[`map_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
[`map_collect_result_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_collect_result_unit
@@ -4748,6 +4868,7 @@ Released 2018-09-13
[`needless_arbitrary_self_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_arbitrary_self_type
[`needless_bitwise_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_bitwise_bool
[`needless_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_bool
+[`needless_bool_assign`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_bool_assign
[`needless_borrow`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
[`needless_borrowed_reference`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrowed_reference
[`needless_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_collect
@@ -4778,6 +4899,7 @@ Released 2018-09-13
[`no_effect_underscore_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_effect_underscore_binding
[`no_mangle_with_rust_abi`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_mangle_with_rust_abi
[`non_ascii_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_ascii_literal
+[`non_minimal_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_minimal_cfg
[`non_octal_unix_permissions`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_octal_unix_permissions
[`non_send_fields_in_send_ty`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_send_fields_in_send_ty
[`nonminimal_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool
@@ -4859,6 +4981,7 @@ Released 2018-09-13
[`ref_binding_to_reference`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_binding_to_reference
[`ref_in_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_in_deref
[`ref_option_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_option_ref
+[`ref_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_patterns
[`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro
[`repeat_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#repeat_once
[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts
diff --git a/src/tools/clippy/Cargo.toml b/src/tools/clippy/Cargo.toml
index c35dfcbd8..3c72bb62e 100644
--- a/src/tools/clippy/Cargo.toml
+++ b/src/tools/clippy/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "clippy"
-version = "0.1.70"
+version = "0.1.71"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
@@ -22,13 +22,12 @@ path = "src/driver.rs"
[dependencies]
clippy_lints = { path = "clippy_lints" }
-semver = "1.0"
rustc_tools_util = "0.3.0"
tempfile = { version = "3.2", optional = true }
termize = "0.1"
[dev-dependencies]
-compiletest_rs = { version = "0.9", features = ["tmp"] }
+compiletest_rs = { version = "0.10", features = ["tmp"] }
tester = "0.9"
regex = "1.5"
toml = "0.5"
@@ -49,7 +48,7 @@ if_chain = "1.0"
itertools = "0.10.1"
quote = "1.0"
serde = { version = "1.0.125", features = ["derive"] }
-syn = { version = "1.0", features = ["full"] }
+syn = { version = "2.0", features = ["full"] }
futures = "0.3"
parking_lot = "0.12"
tokio = { version = "1", features = ["io-util"] }
diff --git a/src/tools/clippy/README.md b/src/tools/clippy/README.md
index 85798e0e8..d712d3e67 100644
--- a/src/tools/clippy/README.md
+++ b/src/tools/clippy/README.md
@@ -91,7 +91,8 @@ cargo clippy
#### Automatically applying Clippy suggestions
-Clippy can automatically apply some lint suggestions, just like the compiler.
+Clippy can automatically apply some lint suggestions, just like the compiler. Note that `--fix` implies
+`--all-targets`, so it can fix as much code as it can.
```terminal
cargo clippy --fix
@@ -277,7 +278,7 @@ If you want to contribute to Clippy, you can find more information in [CONTRIBUT
<!-- REUSE-IgnoreStart -->
-Copyright 2014-2022 The Rust Project Developers
+Copyright 2014-2023 The Rust Project Developers
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)> or the MIT license
diff --git a/src/tools/clippy/book/src/SUMMARY.md b/src/tools/clippy/book/src/SUMMARY.md
index cbd73376d..22fbdce75 100644
--- a/src/tools/clippy/book/src/SUMMARY.md
+++ b/src/tools/clippy/book/src/SUMMARY.md
@@ -13,7 +13,9 @@
- [Development](development/README.md)
- [Basics](development/basics.md)
- [Adding Lints](development/adding_lints.md)
+ - [Lint Passes](development/lint_passes.md)
- [Type Checking](development/type_checking.md)
+ - [Macro Expansions](development/macro_expansions.md)
- [Common Tools](development/common_tools_writing_lints.md)
- [Infrastructure](development/infrastructure/README.md)
- [Syncing changes between Clippy and rust-lang/rust](development/infrastructure/sync.md)
diff --git a/src/tools/clippy/book/src/development/README.md b/src/tools/clippy/book/src/development/README.md
index 616e6d182..8f09f66f5 100644
--- a/src/tools/clippy/book/src/development/README.md
+++ b/src/tools/clippy/book/src/development/README.md
@@ -13,6 +13,24 @@ If this is your first time contributing to Clippy, you should first read the
[Basics docs](basics.md). This will explain the basics on how to get the source
code and how to compile and test the code.
+## Additional Readings for Beginners
+
+If a dear reader of this documentation has never taken a class on compilers
+and interpreters, it might be confusing as to why AST level deals with only
+the language's syntax. And some readers might not even understand what lexing,
+parsing, and AST mean.
+
+This documentation serves by no means as a crash course on compilers or language design.
+And for details specifically related to Rust, the [Rustc Development Guide][rustc_dev_guide]
+is a far better choice to peruse.
+
+The [Syntax and AST][ast] chapter and the [High-Level IR][hir] chapter are
+great introduction to the concepts mentioned in this chapter.
+
+Some readers might also find the [introductory chapter][map_of_territory] of
+Robert Nystrom's _Crafting Interpreters_ a helpful overview of compiled and
+interpreted languages before jumping back to the Rustc guide.
+
## Writing code
If you have done the basic setup, it's time to start hacking.
@@ -37,6 +55,10 @@ book](../lints.md).
> - Triage procedure
> - Bors and Homu
+[ast]: https://rustc-dev-guide.rust-lang.org/syntax-intro.html
+[hir]: https://rustc-dev-guide.rust-lang.org/hir.html
+[rustc_dev_guide]: https://rustc-dev-guide.rust-lang.org/
+[map_of_territory]: https://craftinginterpreters.com/a-map-of-the-territory.html
[clippy_rfc]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md
[rfc_stability]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#stability-guarantees
[rfc_lint_cats]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories
diff --git a/src/tools/clippy/book/src/development/adding_lints.md b/src/tools/clippy/book/src/development/adding_lints.md
index 9dacaaaae..ccae8d374 100644
--- a/src/tools/clippy/book/src/development/adding_lints.md
+++ b/src/tools/clippy/book/src/development/adding_lints.md
@@ -164,7 +164,7 @@ The process of generating the `.stderr` file is the same, and prepending the
## Rustfix tests
If the lint you are working on is making use of structured suggestions, the test
-file should include a `// run-rustfix` comment at the top. This will
+file should include a `//@run-rustfix` comment at the top. This will
additionally run [rustfix] for that test. Rustfix will apply the suggestions
from the lint to the code of the test file and compare that to the contents of a
`.fixed` file.
diff --git a/src/tools/clippy/book/src/development/lint_passes.md b/src/tools/clippy/book/src/development/lint_passes.md
new file mode 100644
index 000000000..621fc2097
--- /dev/null
+++ b/src/tools/clippy/book/src/development/lint_passes.md
@@ -0,0 +1,114 @@
+# Lint passes
+
+Before working on the logic of a new lint, there is an important decision
+that every Clippy developer must make: to use
+[`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass].
+
+In short, the `LateLintPass` has access to type and symbol information while the
+`EarlyLintPass` doesn't. If you don't need access to type information, use the
+`EarlyLintPass`.
+
+Let us expand on these two traits more below.
+
+## `EarlyLintPass`
+
+If you examine the documentation on [`EarlyLintPass`][early_lint_pass] closely,
+you'll see that every method defined for this trait utilizes a
+[`EarlyContext`][early_context]. In `EarlyContext`'s documentation, it states:
+
+> Context for lint checking of the AST, after expansion, before lowering to HIR.
+
+Voilà. `EarlyLintPass` works only on the Abstract Syntax Tree (AST) level.
+And AST is generated during the [lexing and parsing][lexing_and_parsing] phase
+of code compilation. Therefore, it doesn't know what a symbol means or information about types, and it should
+be our trait choice for a new lint if the lint only deals with syntax-related issues.
+
+While linting speed has not been a concern for Clippy,
+the `EarlyLintPass` is faster, and it should be your choice
+if you know for sure a lint does not need type information.
+
+As a reminder, run the following command to generate boilerplate for lints
+that use `EarlyLintPass`:
+
+```sh
+$ cargo dev new_lint --name=<your_new_lint> --pass=early --category=<your_category_choice>
+```
+
+### Example for `EarlyLintPass`
+
+Take a look at the following code:
+
+```rust
+let x = OurUndefinedType;
+x.non_existing_method();
+```
+
+From the AST perspective, both lines are "grammatically" correct.
+The assignment uses a `let` and ends with a semicolon. The invocation
+of a method looks fine, too. As programmers, we might raise a few
+questions already, but the parser is okay with it. This is what we
+mean when we say `EarlyLintPass` deals with only syntax on the AST level.
+
+Alternatively, think of the `foo_functions` lint we mentioned in
+define new lints <!-- FIXME: add link --> chapter.
+
+We want the `foo_functions` lint to detect functions with `foo` as their name.
+Writing a lint that only checks for the name of a function means that we only
+work with the AST and don't have to access the type system at all (the type system is where
+`LateLintPass` comes into the picture).
+
+## `LateLintPass`
+
+In contrast to `EarlyLintPass`, `LateLintPass` contains type information.
+
+If you examine the documentation on [`LateLintPass`][late_lint_pass] closely,
+you see that every method defined in this trait utilizes a
+[`LateContext`][late_context].
+
+In `LateContext`'s documentation we will find methods that
+deal with type-checking, which do not exist in `EarlyContext`, such as:
+
+- [`maybe_typeck_results`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LateContext.html#method.maybe_typeck_results)
+- [`typeck_results`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LateContext.html#method.typeck_results)
+
+### Example for `LateLintPass`
+
+Let us take a look with the following example:
+
+```rust
+let x = OurUndefinedType;
+x.non_existing_method();
+```
+
+These two lines of code are syntactically correct code from the perspective
+of the AST. We have an assignment and invoke a method on the variable that
+is of a type. Grammatically, everything is in order for the parser.
+
+However, going down a level and looking at the type information,
+the compiler will notice that both `OurUndefinedType` and `non_existing_method()`
+**are undefined**.
+
+As Clippy developers, to access such type information, we must implement
+`LateLintPass` on our lint.
+When you browse through Clippy's lints, you will notice that almost every lint
+is implemented in a `LateLintPass`, specifically because we often need to check
+not only for syntactic issues but also type information.
+
+Another limitation of the `EarlyLintPass` is that the nodes are only identified
+by their position in the AST. This means that you can't just get an `id` and
+request a certain node. For most lints that is fine, but we have some lints
+that require the inspection of other nodes, which is easier at the HIR level.
+In these cases, `LateLintPass` is the better choice.
+
+As a reminder, run the following command to generate boilerplate for lints
+that use `LateLintPass`:
+
+```sh
+$ cargo dev new_lint --name=<your_new_lint> --pass=late --category=<your_category_choice>
+```
+
+[early_context]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.EarlyContext.html
+[early_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.EarlyLintPass.html
+[late_context]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LateContext.html
+[late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html
+[lexing_and_parsing]: https://rustc-dev-guide.rust-lang.org/overview.html#lexing-and-parsing
diff --git a/src/tools/clippy/book/src/development/macro_expansions.md b/src/tools/clippy/book/src/development/macro_expansions.md
new file mode 100644
index 000000000..c5eb00027
--- /dev/null
+++ b/src/tools/clippy/book/src/development/macro_expansions.md
@@ -0,0 +1,158 @@
+# Dealing with macros and expansions
+
+Sometimes we might encounter Rust macro expansions while working with Clippy.
+While macro expansions are not as dramatic and profound as the expansion
+of our universe, they can certainly bring chaos to the orderly world
+of code and logic.
+
+The general rule of thumb is that we should ignore code with macro
+expansions when working with Clippy because the code can be dynamic
+in ways that are difficult or impossible for us to foresee.
+
+## False Positives
+
+What exactly do we mean by _dynamic in ways that are difficult to foresee_?
+
+Macros are [expanded][expansion] in the `EarlyLintPass` level,
+so the Abstract Syntax Tree (AST) is generated in place of macros.
+This means the code which we work with in Clippy is already expanded.
+
+If we wrote a new lint, there is a possibility that the lint is
+triggered in macro-generated code. Since this expanded macro code
+is not written by the macro's user but really by the macro's author,
+the user cannot and should not be responsible for fixing the issue
+that triggers the lint.
+
+Besides, a [Span] in a macro can be changed by the macro author.
+Therefore, any lint check related to lines or columns should be
+avoided since they might be changed at any time and become unreliable
+or incorrect information.
+
+Because of these unforeseeable or unstable behaviors, macro expansion
+should often not be regarded as a part of the stable API.
+This is also why most lints check if they are inside a macro or not
+before emitting suggestions to the end user to avoid false positives.
+
+## How to Work with Macros
+
+Several functions are available for working with macros.
+
+### The `Span.from_expansion` method
+
+We could utilize a `span`'s [`from_expansion`] method, which
+detects if the `span` is from a macro expansion / desugaring.
+This is a very common first step in a lint:
+
+```rust
+if expr.span.from_expansion() {
+ // We most likely want to ignore it.
+ return;
+}
+```
+
+### `Span.ctxt` method
+
+The `span`'s context, given by the method [`ctxt`] and returning [SpanContext],
+represents if the span is from a macro expansion and, if it is, which
+macro call expanded this span.
+
+Sometimes, it is useful to check if the context of two spans are equal.
+For instance, suppose we have the following line of code that would
+expand into `1 + 0`:
+
+```rust
+// The following code expands to `1 + 0` for both `EarlyLintPass` and `LateLintPass`
+1 + mac!()
+```
+
+Assuming that we'd collect the `1` expression as a variable `left` and the
+`0`/`mac!()` expression as a variable `right`, we can simply compare their
+contexts. If the context is different, then we most likely are dealing with a
+macro expansion and should just ignore it:
+
+```rust
+if left.span.ctxt() != right.span.ctxt() {
+ // The code author most likely cannot modify this expression
+ return;
+}
+```
+
+> **Note**: Code that is not from expansion is in the "root" context.
+> So any spans whose `from_expansion` returns `false` can be assumed
+> to have the same context. Because of this, using `span.from_expansion()`
+> is often sufficient.
+
+Going a bit deeper, in a simple expression such as `a == b`,
+`a` and `b` have the same context.
+However, in a `macro_rules!` with `a == $b`, `$b` is expanded to
+an expression that contains a different context from `a`.
+
+Take a look at the following macro `m`:
+
+```rust
+macro_rules! m {
+ ($a:expr, $b:expr) => {
+ if $a.is_some() {
+ $b;
+ }
+ }
+}
+
+let x: Option<u32> = Some(42);
+m!(x, x.unwrap());
+```
+
+If the `m!(x, x.unwrapp());` line is expanded, we would get two expanded
+expressions:
+
+- `x.is_some()` (from the `$a.is_some()` line in the `m` macro)
+- `x.unwrap()` (corresponding to `$b` in the `m` macro)
+
+Suppose `x.is_some()` expression's span is associated with the `x_is_some_span` variable
+and `x.unwrap()` expression's span is associated with `x_unwrap_span` variable,
+we could assume that these two spans do not share the same context:
+
+```rust
+// x.is_some() is from inside the macro
+// x.unwrap() is from outside the macro
+assert_ne!(x_is_some_span.ctxt(), x_unwrap_span.ctxt());
+```
+
+### The `in_external_macro` function
+
+`rustc_middle::lint` provides a function ([`in_external_macro`]) that can
+detect if the given span is from a macro defined in a foreign crate.
+
+Therefore, if we really want a new lint to work with macro-generated code,
+this is the next line of defense to avoid macros not defined inside
+the current crate since it is unfair to the user if Clippy lints code
+which the user cannot change.
+
+For example, assume we have the following code that is being examined
+by Clippy:
+
+```rust
+#[macro_use]
+extern crate a_foreign_crate_with_macros;
+
+// `foo` macro is defined in `a_foreign_crate_with_macros`
+foo!("bar");
+```
+
+Also assume that we get the corresponding variable `foo_span` for the
+`foo` macro call, we could decide not to lint if `in_external_macro`
+results in `true` (note that `cx` can be `EarlyContext` or `LateContext`):
+
+```rust
+if in_external_macro(cx.sess(), foo_span) {
+ // We should ignore macro from a foreign crate.
+ return;
+}
+```
+
+[`ctxt`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html#method.ctxt
+[expansion]: https://rustc-dev-guide.rust-lang.org/macro-expansion.html#expansion-and-ast-integration
+[`from_expansion`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html#method.from_expansion
+[`in_external_macro`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/lint/fn.in_external_macro.html
+[Span]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html
+[SpanContext]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/hygiene/struct.SyntaxContext.html
diff --git a/src/tools/clippy/book/src/development/proposals/syntax-tree-patterns.md b/src/tools/clippy/book/src/development/proposals/syntax-tree-patterns.md
index 36d722609..285488cec 100644
--- a/src/tools/clippy/book/src/development/proposals/syntax-tree-patterns.md
+++ b/src/tools/clippy/book/src/development/proposals/syntax-tree-patterns.md
@@ -139,7 +139,7 @@ whether the pattern matched.
## Pattern syntax
-The following examples demonstate the pattern syntax:
+The following examples demonstrate the pattern syntax:
#### Any (`_`)
diff --git a/src/tools/clippy/book/src/development/type_checking.md b/src/tools/clippy/book/src/development/type_checking.md
index 5ce434b99..d7c2775b8 100644
--- a/src/tools/clippy/book/src/development/type_checking.md
+++ b/src/tools/clippy/book/src/development/type_checking.md
@@ -51,7 +51,7 @@ impl LateLintPass<'_> for MyStructLint {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
// Get type of `expr`
let ty = cx.typeck_results().expr_ty(expr);
-
+
// Check if the `Ty` of this expression is of character type
if ty.is_char() {
println!("Our expression is a char!");
@@ -70,18 +70,18 @@ pub fn is_char(self) -> bool {
}
```
-Indeed, we just discovered `Ty`'s [`kind` method][kind], which provides us
+Indeed, we just discovered `Ty`'s [`kind()` method][kind], which provides us
with [`TyKind`][TyKind] of a `Ty`.
## `TyKind`
`TyKind` defines the kinds of types in Rust's type system.
Peeking into [`TyKind` documentation][TyKind], we will see that it is an
-enum of 27 variants, including items such as `Bool`, `Int`, `Ref`, etc.
+enum of over 25 variants, including items such as `Bool`, `Int`, `Ref`, etc.
### `kind` Usage
-The `TyKind` of `Ty` can be returned by calling [`Ty.kind` method][kind].
+The `TyKind` of `Ty` can be returned by calling [`Ty.kind()` method][kind].
We often use this method to perform pattern matching in Clippy.
For instance, if we want to check for a `struct`, we could examine if the
@@ -107,15 +107,21 @@ impl LateLintPass<'_> for MyStructLint {
We've been talking about [`ty::Ty`][middle_ty] this whole time without addressing [`hir::Ty`][hir_ty], but the latter
is also important to understand.
-`hir::Ty` would represent *what* an user wrote, while `ty::Ty` would understand the meaning of it (because it has more
-information).
+`hir::Ty` would represent *what* the user wrote, while `ty::Ty` is how the compiler sees the type and has more
+information. Example:
-**Example: `fn foo(x: u32) -> u32 { x }`**
+```rust
+fn foo(x: u32) -> u32 { x }
+```
Here the HIR sees the types without "thinking" about them, it knows that the function takes an `u32` and returns
-an `u32`. But at the `ty::Ty` level the compiler understands that they're the same type, in-depth lifetimes, etc...
+an `u32`. As far as `hir::Ty` is concerned those might be different types. But at the `ty::Ty` level the compiler
+understands that they're the same type, in-depth lifetimes, etc...
+
+To get from a `hir::Ty` to a `ty::Ty`, you can use the [`hir_ty_to_ty`][hir_ty_to_ty] function outside of bodies or
+outside of bodies the [`TypeckResults::node_type()`][node_type] method.
-you can use the [`hir_ty_to_ty`][hir_ty_to_ty] function to convert from a `hir::Ty` to a `ty::Ty`
+> **Warning**: Don't use `hir_ty_to_ty` inside of bodies, because this can cause ICEs.
## Useful Links
@@ -127,17 +133,18 @@ in this chapter:
- [Type checking](https://rustc-dev-guide.rust-lang.org/type-checking.html)
- [Ty module](https://rustc-dev-guide.rust-lang.org/ty.html)
-[Adt]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html#variant.Adt
+[Adt]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/sty/enum.TyKind.html#variant.Adt
[AdtDef]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/adt/struct.AdtDef.html
[expr_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.expr_ty
+[node_type]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.node_type
[is_char]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#method.is_char
[is_char_source]: https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_middle/ty/sty.rs.html#1831-1834
[kind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#method.kind
[LateContext]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LateContext.html
[LateLintPass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html
-[pat_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TypeckResults.html#method.pat_ty
+[pat_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/typeck_results/struct.TypeckResults.html#method.pat_ty
[Ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html
-[TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html
+[TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/sty/enum.TyKind.html
[TypeckResults]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html
[middle_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_middle/ty/struct.Ty.html
[hir_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/struct.Ty.html
diff --git a/src/tools/clippy/book/src/lint_configuration.md b/src/tools/clippy/book/src/lint_configuration.md
index 78e1a55cf..5646c9b15 100644
--- a/src/tools/clippy/book/src/lint_configuration.md
+++ b/src/tools/clippy/book/src/lint_configuration.md
@@ -13,6 +13,8 @@ Please use that command to update the file and do not edit it by hand.
| [msrv](#msrv) | `None` |
| [cognitive-complexity-threshold](#cognitive-complexity-threshold) | `25` |
| [disallowed-names](#disallowed-names) | `["foo", "baz", "quux"]` |
+| [semicolon-inside-block-ignore-singleline](#semicolon-inside-block-ignore-singleline) | `false` |
+| [semicolon-outside-block-ignore-multiline](#semicolon-outside-block-ignore-multiline) | `false` |
| [doc-valid-idents](#doc-valid-idents) | `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenDNS", "WebGL", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]` |
| [too-many-arguments-threshold](#too-many-arguments-threshold) | `7` |
| [type-complexity-threshold](#type-complexity-threshold) | `250` |
@@ -55,6 +57,7 @@ Please use that command to update the file and do not edit it by hand.
| [suppress-restriction-lint-in-const](#suppress-restriction-lint-in-const) | `false` |
| [missing-docs-in-crate-items](#missing-docs-in-crate-items) | `false` |
| [future-size-threshold](#future-size-threshold) | `16384` |
+| [unnecessary-box-size](#unnecessary-box-size) | `128` |
### arithmetic-side-effects-allowed
Suppress checking of the passed type names in all types of operations.
@@ -202,6 +205,22 @@ default configuration of Clippy. By default, any configuration will replace the
* [disallowed_names](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names)
+### semicolon-inside-block-ignore-singleline
+Whether to lint only if it's multiline.
+
+**Default Value:** `false` (`bool`)
+
+* [semicolon_inside_block](https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_inside_block)
+
+
+### semicolon-outside-block-ignore-multiline
+Whether to lint only if it's singleline.
+
+**Default Value:** `false` (`bool`)
+
+* [semicolon_outside_block](https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_outside_block)
+
+
### doc-valid-idents
The list of words this lint should not consider as identifiers needing ticks. The value
`".."` can be used as part of the list to indicate, that the configured values should be appended to the
@@ -561,4 +580,12 @@ The maximum byte size a `Future` can have, before it triggers the `clippy::large
* [large_futures](https://rust-lang.github.io/rust-clippy/master/index.html#large_futures)
+### unnecessary-box-size
+The byte size a `T` in `Box<T>` can have, below which it triggers the `clippy::unnecessary_box` lint
+
+**Default Value:** `128` (`u64`)
+
+* [unnecessary_box_returns](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_box_returns)
+
+
diff --git a/src/tools/clippy/book/src/usage.md b/src/tools/clippy/book/src/usage.md
index 32084a919..36448e4cc 100644
--- a/src/tools/clippy/book/src/usage.md
+++ b/src/tools/clippy/book/src/usage.md
@@ -111,7 +111,8 @@ fn main() {
### Automatically applying Clippy suggestions
-Clippy can automatically apply some lint suggestions, just like the compiler.
+Clippy can automatically apply some lint suggestions, just like the compiler. Note that `--fix` implies
+`--all-targets`, so it can fix as much code as it can.
```terminal
cargo clippy --fix
diff --git a/src/tools/clippy/clippy_dev/src/dogfood.rs b/src/tools/clippy/clippy_dev/src/dogfood.rs
index b69e9f649..a0d57f5ab 100644
--- a/src/tools/clippy/clippy_dev/src/dogfood.rs
+++ b/src/tools/clippy/clippy_dev/src/dogfood.rs
@@ -1,4 +1,4 @@
-use crate::clippy_project_root;
+use crate::{clippy_project_root, exit_if_err};
use std::process::Command;
/// # Panics
@@ -10,7 +10,7 @@ pub fn dogfood(fix: bool, allow_dirty: bool, allow_staged: bool) {
cmd.current_dir(clippy_project_root())
.args(["test", "--test", "dogfood"])
.args(["--features", "internal"])
- .args(["--", "dogfood_clippy"]);
+ .args(["--", "dogfood_clippy", "--nocapture"]);
let mut dogfood_args = Vec::new();
if fix {
@@ -27,7 +27,5 @@ pub fn dogfood(fix: bool, allow_dirty: bool, allow_staged: bool) {
cmd.env("__CLIPPY_DOGFOOD_ARGS", dogfood_args.join(" "));
- let output = cmd.output().expect("failed to run command");
-
- println!("{}", String::from_utf8_lossy(&output.stdout));
+ exit_if_err(cmd.status());
}
diff --git a/src/tools/clippy/clippy_dev/src/lib.rs b/src/tools/clippy/clippy_dev/src/lib.rs
index 3a8b070d7..56a269288 100644
--- a/src/tools/clippy/clippy_dev/src/lib.rs
+++ b/src/tools/clippy/clippy_dev/src/lib.rs
@@ -10,7 +10,9 @@
extern crate rustc_driver;
extern crate rustc_lexer;
+use std::io;
use std::path::PathBuf;
+use std::process::{self, ExitStatus};
pub mod bless;
pub mod dogfood;
@@ -58,3 +60,14 @@ pub fn clippy_project_root() -> PathBuf {
}
panic!("error: Can't determine root of project. Please run inside a Clippy working dir.");
}
+
+pub fn exit_if_err(status: io::Result<ExitStatus>) {
+ match status.expect("failed to run command").code() {
+ Some(0) => {},
+ Some(n) => process::exit(n),
+ None => {
+ eprintln!("Killed by signal");
+ process::exit(1);
+ },
+ }
+}
diff --git a/src/tools/clippy/clippy_dev/src/lint.rs b/src/tools/clippy/clippy_dev/src/lint.rs
index aafd0f71a..a19be1bca 100644
--- a/src/tools/clippy/clippy_dev/src/lint.rs
+++ b/src/tools/clippy/clippy_dev/src/lint.rs
@@ -1,17 +1,6 @@
-use crate::cargo_clippy_path;
-use std::process::{self, Command, ExitStatus};
-use std::{fs, io};
-
-fn exit_if_err(status: io::Result<ExitStatus>) {
- match status.expect("failed to run command").code() {
- Some(0) => {},
- Some(n) => process::exit(n),
- None => {
- eprintln!("Killed by signal");
- process::exit(1);
- },
- }
-}
+use crate::{cargo_clippy_path, exit_if_err};
+use std::fs;
+use std::process::{self, Command};
pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a String>) {
let is_file = match fs::metadata(path) {
diff --git a/src/tools/clippy/clippy_dev/src/update_lints.rs b/src/tools/clippy/clippy_dev/src/update_lints.rs
index 95222a9ac..7213c9dfe 100644
--- a/src/tools/clippy/clippy_dev/src/update_lints.rs
+++ b/src/tools/clippy/clippy_dev/src/update_lints.rs
@@ -36,60 +36,6 @@ pub enum UpdateMode {
pub fn update(update_mode: UpdateMode) {
let (lints, deprecated_lints, renamed_lints) = gather_all();
generate_lint_files(update_mode, &lints, &deprecated_lints, &renamed_lints);
- remove_old_files(update_mode);
-}
-
-/// Remove files no longer needed after <https://github.com/rust-lang/rust-clippy/pull/9541>
-/// that may be reintroduced unintentionally
-///
-/// FIXME: This is a temporary measure that should be removed when there are no more PRs that
-/// include the stray files
-fn remove_old_files(update_mode: UpdateMode) {
- let mut failed = false;
- let mut remove_file = |path: &Path| match update_mode {
- UpdateMode::Check => {
- if path.exists() {
- failed = true;
- println!("unexpected file: {}", path.display());
- }
- },
- UpdateMode::Change => {
- if fs::remove_file(path).is_ok() {
- println!("removed file: {}", path.display());
- }
- },
- };
-
- let files = [
- "clippy_lints/src/lib.register_all.rs",
- "clippy_lints/src/lib.register_cargo.rs",
- "clippy_lints/src/lib.register_complexity.rs",
- "clippy_lints/src/lib.register_correctness.rs",
- "clippy_lints/src/lib.register_internal.rs",
- "clippy_lints/src/lib.register_lints.rs",
- "clippy_lints/src/lib.register_nursery.rs",
- "clippy_lints/src/lib.register_pedantic.rs",
- "clippy_lints/src/lib.register_perf.rs",
- "clippy_lints/src/lib.register_restriction.rs",
- "clippy_lints/src/lib.register_style.rs",
- "clippy_lints/src/lib.register_suspicious.rs",
- "src/docs.rs",
- ];
-
- for file in files {
- remove_file(Path::new(file));
- }
-
- if let Ok(docs_dir) = fs::read_dir("src/docs") {
- for doc_file in docs_dir {
- let path = doc_file.unwrap().path();
- remove_file(&path);
- }
- }
-
- if failed {
- exit_with_failure();
- }
}
fn generate_lint_files(
@@ -741,7 +687,7 @@ fn gen_deprecated_lints_test(lints: &[DeprecatedLint]) -> String {
fn gen_renamed_lints_test(lints: &[RenamedLint]) -> String {
let mut seen_lints = HashSet::new();
let mut res: String = GENERATED_FILE_COMMENT.into();
- res.push_str("// run-rustfix\n\n");
+ res.push_str("//@run-rustfix\n\n");
for lint in lints {
if seen_lints.insert(&lint.new_name) {
writeln!(res, "#![allow({})]", lint.new_name).unwrap();
diff --git a/src/tools/clippy/clippy_lints/Cargo.toml b/src/tools/clippy/clippy_lints/Cargo.toml
index 18e8bf772..98e69c7fd 100644
--- a/src/tools/clippy/clippy_lints/Cargo.toml
+++ b/src/tools/clippy/clippy_lints/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "clippy_lints"
-version = "0.1.70"
+version = "0.1.71"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
@@ -17,7 +17,7 @@ if_chain = "1.0"
itertools = "0.10.1"
pulldown-cmark = { version = "0.9", default-features = false }
quine-mc_cluskey = "0.2"
-regex-syntax = "0.6"
+regex-syntax = "0.7"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", optional = true }
tempfile = { version = "3.2", optional = true }
diff --git a/src/tools/clippy/clippy_lints/src/allow_attributes.rs b/src/tools/clippy/clippy_lints/src/allow_attributes.rs
index 15d46e954..add73d0ae 100644
--- a/src/tools/clippy/clippy_lints/src/allow_attributes.rs
+++ b/src/tools/clippy/clippy_lints/src/allow_attributes.rs
@@ -2,11 +2,12 @@ use ast::AttrStyle;
use clippy_utils::diagnostics::span_lint_and_sugg;
use rustc_ast as ast;
use rustc_errors::Applicability;
-use rustc_lint::{LateContext, LateLintPass};
+use rustc_lint::{LateContext, LateLintPass, LintContext};
+use rustc_middle::lint::in_external_macro;
use rustc_session::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! {
- /// Detects uses of the `#[allow]` attribute and suggests replacing it with
+ /// Checks for usage of the `#[allow]` attribute and suggests replacing it with
/// the `#[expect]` (See [RFC 2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html))
///
/// The expect attribute is still unstable and requires the `lint_reasons`
@@ -51,6 +52,7 @@ impl LateLintPass<'_> for AllowAttribute {
// Separate each crate's features.
fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &ast::Attribute) {
if_chain! {
+ if !in_external_macro(cx.sess(), attr.span);
if cx.tcx.features().lint_reasons;
if let AttrStyle::Outer = attr.style;
if let Some(ident) = attr.ident();
diff --git a/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs b/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs
index a36df55d0..a8dc0cb3b 100644
--- a/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs
+++ b/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs
@@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
_ => return,
};
let Some((condition, panic_expn)) = find_assert_args(cx, e, macro_call.expn) else { return };
- let Some((Constant::Bool(val), _)) = constant(cx, cx.typeck_results(), condition) else { return };
+ let Some(Constant::Bool(val)) = constant(cx, cx.typeck_results(), condition) else { return };
if val {
span_lint_and_help(
cx,
diff --git a/src/tools/clippy/clippy_lints/src/attrs.rs b/src/tools/clippy/clippy_lints/src/attrs.rs
index 751c26267..897495ba1 100644
--- a/src/tools/clippy/clippy_lints/src/attrs.rs
+++ b/src/tools/clippy/clippy_lints/src/attrs.rs
@@ -178,6 +178,52 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
+ /// Checks for empty lines after documenation comments.
+ ///
+ /// ### Why is this bad?
+ /// The documentation comment was most likely meant to be an inner attribute or regular comment.
+ /// If it was intended to be a documentation comment, then the empty line should be removed to
+ /// be more idiomatic.
+ ///
+ /// ### Known problems
+ /// Only detects empty lines immediately following the documentation. If the doc comment is followed
+ /// by an attribute and then an empty line, this lint will not trigger. Use `empty_line_after_outer_attr`
+ /// in combination with this lint to detect both cases.
+ ///
+ /// Does not detect empty lines after doc attributes (e.g. `#[doc = ""]`).
+ ///
+ /// ### Example
+ /// ```rust
+ /// /// Some doc comment with a blank line after it.
+ ///
+ /// fn not_quite_good_code() { }
+ /// ```
+ ///
+ /// Use instead:
+ /// ```rust
+ /// /// Good (no blank line)
+ /// fn this_is_fine() { }
+ /// ```
+ ///
+ /// ```rust
+ /// // Good (convert to a regular comment)
+ ///
+ /// fn this_is_fine_too() { }
+ /// ```
+ ///
+ /// ```rust
+ /// //! Good (convert to a comment on an inner attribute)
+ ///
+ /// fn this_is_fine_as_well() { }
+ /// ```
+ #[clippy::version = "1.70.0"]
+ pub EMPTY_LINE_AFTER_DOC_COMMENTS,
+ nursery,
+ "empty line after documentation comments"
+}
+
+declare_clippy_lint! {
+ /// ### What it does
/// Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category.
///
/// ### Why is this bad?
@@ -292,6 +338,30 @@ declare_clippy_lint! {
"ensures that all `allow` and `expect` attributes have a reason"
}
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for `any` and `all` combinators in `cfg` with only one condition.
+ ///
+ /// ### Why is this bad?
+ /// If there is only one condition, no need to wrap it into `any` or `all` combinators.
+ ///
+ /// ### Example
+ /// ```rust
+ /// #[cfg(any(unix))]
+ /// pub struct Bar;
+ /// ```
+ ///
+ /// Use instead:
+ /// ```rust
+ /// #[cfg(unix)]
+ /// pub struct Bar;
+ /// ```
+ #[clippy::version = "1.71.0"]
+ pub NON_MINIMAL_CFG,
+ style,
+ "ensure that all `cfg(any())` and `cfg(all())` have more than one condition"
+}
+
declare_lint_pass!(Attributes => [
ALLOW_ATTRIBUTES_WITHOUT_REASON,
INLINE_ALWAYS,
@@ -604,6 +674,8 @@ impl_lint_pass!(EarlyAttributes => [
DEPRECATED_CFG_ATTR,
MISMATCHED_TARGET_OS,
EMPTY_LINE_AFTER_OUTER_ATTR,
+ EMPTY_LINE_AFTER_DOC_COMMENTS,
+ NON_MINIMAL_CFG,
]);
impl EarlyLintPass for EarlyAttributes {
@@ -614,15 +686,22 @@ impl EarlyLintPass for EarlyAttributes {
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
check_deprecated_cfg_attr(cx, attr, &self.msrv);
check_mismatched_target_os(cx, attr);
+ check_minimal_cfg_condition(cx, attr);
}
extract_msrv_attr!(EarlyContext);
}
+/// Check for empty lines after outer attributes.
+///
+/// Attributes and documenation comments are both considered outer attributes
+/// by the AST. However, the average user likely considers them to be different.
+/// Checking for empty lines after each of these attributes is split into two different
+/// lints but can share the same logic.
fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::Item) {
let mut iter = item.attrs.iter().peekable();
while let Some(attr) = iter.next() {
- if matches!(attr.kind, AttrKind::Normal(..))
+ if (matches!(attr.kind, AttrKind::Normal(..)) || matches!(attr.kind, AttrKind::DocComment(..)))
&& attr.style == AttrStyle::Outer
&& is_present_in_source(cx, attr.span)
{
@@ -639,13 +718,20 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::It
let lines = without_block_comments(lines);
if lines.iter().filter(|l| l.trim().is_empty()).count() > 2 {
- span_lint(
- cx,
- EMPTY_LINE_AFTER_OUTER_ATTR,
- begin_of_attr_to_item,
- "found an empty line after an outer attribute. \
- Perhaps you forgot to add a `!` to make it an inner attribute?",
- );
+ let (lint_msg, lint_type) = match attr.kind {
+ AttrKind::DocComment(..) => (
+ "found an empty line after a doc comment. \
+ Perhaps you need to use `//!` to make a comment on a module, remove the empty line, or make a regular comment with `//`?",
+ EMPTY_LINE_AFTER_DOC_COMMENTS,
+ ),
+ AttrKind::Normal(..) => (
+ "found an empty line after an outer attribute. \
+ Perhaps you forgot to add a `!` to make it an inner attribute?",
+ EMPTY_LINE_AFTER_OUTER_ATTR,
+ ),
+ };
+
+ span_lint(cx, lint_type, begin_of_attr_to_item, lint_msg);
}
}
}
@@ -690,6 +776,48 @@ fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &Msr
}
}
+fn check_nested_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) {
+ for item in items.iter() {
+ if let NestedMetaItem::MetaItem(meta) = item {
+ if !meta.has_name(sym::any) && !meta.has_name(sym::all) {
+ continue;
+ }
+ if let MetaItemKind::List(list) = &meta.kind {
+ check_nested_cfg(cx, list);
+ if list.len() == 1 {
+ span_lint_and_then(
+ cx,
+ NON_MINIMAL_CFG,
+ meta.span,
+ "unneeded sub `cfg` when there is only one condition",
+ |diag| {
+ if let Some(snippet) = snippet_opt(cx, list[0].span()) {
+ diag.span_suggestion(meta.span, "try", snippet, Applicability::MaybeIncorrect);
+ }
+ },
+ );
+ } else if list.is_empty() && meta.has_name(sym::all) {
+ span_lint_and_then(
+ cx,
+ NON_MINIMAL_CFG,
+ meta.span,
+ "unneeded sub `cfg` when there is no condition",
+ |_| {},
+ );
+ }
+ }
+ }
+ }
+}
+
+fn check_minimal_cfg_condition(cx: &EarlyContext<'_>, attr: &Attribute) {
+ if attr.has_name(sym::cfg) &&
+ let Some(items) = attr.meta_item_list()
+ {
+ check_nested_cfg(cx, &items);
+ }
+}
+
fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
fn find_os(name: &str) -> Option<&'static str> {
UNIX_SYSTEMS
diff --git a/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs b/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs
index 1d9096ea6..8c3ad24ee 100644
--- a/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs
+++ b/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs
@@ -41,7 +41,7 @@ fn extract_bool_lit(e: &Expr<'_>) -> Option<bool> {
}) = e.kind
&& !e.span.from_expansion()
{
- Some(b)
+ Some(*b)
} else {
None
}
diff --git a/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs b/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs
index c4520d003..814108ed8 100644
--- a/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs
+++ b/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs
@@ -1,5 +1,6 @@
use crate::reference::DEREF_ADDROF;
use clippy_utils::diagnostics::span_lint_and_then;
+use clippy_utils::is_from_proc_macro;
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::implements_trait;
use clippy_utils::{get_parent_expr, is_lint_allowed};
@@ -47,8 +48,8 @@ declare_clippy_lint! {
declare_lint_pass!(BorrowDerefRef => [BORROW_DEREF_REF]);
-impl LateLintPass<'_> for BorrowDerefRef {
- fn check_expr(&mut self, cx: &LateContext<'_>, e: &rustc_hir::Expr<'_>) {
+impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
+ fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &rustc_hir::Expr<'tcx>) {
if_chain! {
if !e.span.from_expansion();
if let ExprKind::AddrOf(_, Mutability::Not, addrof_target) = e.kind;
@@ -58,6 +59,7 @@ impl LateLintPass<'_> for BorrowDerefRef {
if !matches!(deref_target.kind, ExprKind::Unary(UnOp::Deref, ..) );
let ref_ty = cx.typeck_results().expr_ty(deref_target);
if let ty::Ref(_, inner_ty, Mutability::Not) = ref_ty.kind();
+ if !is_from_proc_macro(cx, e);
then{
if let Some(parent_expr) = get_parent_expr(cx, e){
diff --git a/src/tools/clippy/clippy_lints/src/box_default.rs b/src/tools/clippy/clippy_lints/src/box_default.rs
index dfa949d1a..e42c3fe24 100644
--- a/src/tools/clippy/clippy_lints/src/box_default.rs
+++ b/src/tools/clippy/clippy_lints/src/box_default.rs
@@ -8,7 +8,9 @@ use rustc_hir::{
Block, Expr, ExprKind, Local, Node, QPath, TyKind,
};
use rustc_lint::{LateContext, LateLintPass, LintContext};
-use rustc_middle::{lint::in_external_macro, ty::print::with_forced_trimmed_paths};
+use rustc_middle::lint::in_external_macro;
+use rustc_middle::ty::print::with_forced_trimmed_paths;
+use rustc_middle::ty::IsSuggestable;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::sym;
@@ -49,7 +51,6 @@ impl LateLintPass<'_> for BoxDefault {
&& path_def_id(cx, ty).map_or(false, |id| Some(id) == cx.tcx.lang_items().owned_box())
&& is_default_equivalent(cx, arg)
{
- let arg_ty = cx.typeck_results().expr_ty(arg);
span_lint_and_sugg(
cx,
BOX_DEFAULT,
@@ -58,8 +59,10 @@ impl LateLintPass<'_> for BoxDefault {
"try",
if is_plain_default(arg_path) || given_type(cx, expr) {
"Box::default()".into()
- } else {
+ } else if let Some(arg_ty) = cx.typeck_results().expr_ty(arg).make_suggestable(cx.tcx, true) {
with_forced_trimmed_paths!(format!("Box::<{arg_ty}>::default()"))
+ } else {
+ return
},
Applicability::MachineApplicable
);
diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_nan_to_int.rs b/src/tools/clippy/clippy_lints/src/casts/cast_nan_to_int.rs
index 322dc41b3..da756129d 100644
--- a/src/tools/clippy/clippy_lints/src/casts/cast_nan_to_int.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/cast_nan_to_int.rs
@@ -21,8 +21,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
fn is_known_nan(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
match constant(cx, cx.typeck_results(), e) {
- Some((Constant::F64(n), _)) => n.is_nan(),
- Some((Constant::F32(n), _)) => n.is_nan(),
+ Some(Constant::F64(n)) => n.is_nan(),
+ Some(Constant::F32(n)) => n.is_nan(),
_ => false,
}
}
diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs b/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs
index 95c2ecbf7..84b99ad5c 100644
--- a/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs
@@ -15,7 +15,7 @@ use rustc_target::abi::IntegerType;
use super::{utils, CAST_ENUM_TRUNCATION, CAST_POSSIBLE_TRUNCATION};
fn constant_int(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<u128> {
- if let Some((Constant::Int(c), _)) = constant(cx, cx.typeck_results(), expr) {
+ if let Some(Constant::Int(c)) = constant(cx, cx.typeck_results(), expr) {
Some(c)
} else {
None
diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_sign_loss.rs b/src/tools/clippy/clippy_lints/src/casts/cast_sign_loss.rs
index a20a97d4e..a83dfd94d 100644
--- a/src/tools/clippy/clippy_lints/src/casts/cast_sign_loss.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/cast_sign_loss.rs
@@ -29,7 +29,7 @@ fn should_lint(cx: &LateContext<'_>, cast_op: &Expr<'_>, cast_from: Ty<'_>, cast
// Don't lint for positive constants.
let const_val = constant(cx, cx.typeck_results(), cast_op);
if_chain! {
- if let Some((Constant::Int(n), _)) = const_val;
+ if let Some(Constant::Int(n)) = const_val;
if let ty::Int(ity) = *cast_from.kind();
if sext(cx.tcx, n, ity) >= 0;
then {
diff --git a/src/tools/clippy/clippy_lints/src/casts/mod.rs b/src/tools/clippy/clippy_lints/src/casts/mod.rs
index 362f70d12..cfeb75eed 100644
--- a/src/tools/clippy/clippy_lints/src/casts/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/mod.rs
@@ -506,7 +506,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for uses of the `abs()` method that cast the result to unsigned.
+ /// Checks for usage of the `abs()` method that cast the result to unsigned.
///
/// ### Why is this bad?
/// The `unsigned_abs()` method avoids panic when called on the MIN value.
@@ -625,20 +625,20 @@ declare_clippy_lint! {
///
/// ### Example
/// ```rust
- /// let string = String::with_capacity(1);
- /// let ptr = string.as_ptr() as *mut u8;
+ /// let mut vec = Vec::<u8>::with_capacity(1);
+ /// let ptr = vec.as_ptr() as *mut u8;
/// unsafe { ptr.write(4) }; // UNDEFINED BEHAVIOUR
/// ```
/// Use instead:
/// ```rust
- /// let mut string = String::with_capacity(1);
- /// let ptr = string.as_mut_ptr();
+ /// let mut vec = Vec::<u8>::with_capacity(1);
+ /// let ptr = vec.as_mut_ptr();
/// unsafe { ptr.write(4) };
/// ```
#[clippy::version = "1.66.0"]
pub AS_PTR_CAST_MUT,
nursery,
- "casting the result of the `&self`-taking `as_ptr` to a mutabe pointer"
+ "casting the result of the `&self`-taking `as_ptr` to a mutable pointer"
}
declare_clippy_lint! {
diff --git a/src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs b/src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs
index 7e2331807..804ae8411 100644
--- a/src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs
@@ -141,9 +141,9 @@ fn lint_unnecessary_cast(
fn get_numeric_literal<'e>(expr: &'e Expr<'e>) -> Option<&'e Lit> {
match expr.kind {
- ExprKind::Lit(ref lit) => Some(lit),
+ ExprKind::Lit(lit) => Some(lit),
ExprKind::Unary(UnOp::Neg, e) => {
- if let ExprKind::Lit(ref lit) = e.kind {
+ if let ExprKind::Lit(lit) = e.kind {
Some(lit)
} else {
None
diff --git a/src/tools/clippy/clippy_lints/src/copies.rs b/src/tools/clippy/clippy_lints/src/copies.rs
index 970f50049..1c321f46e 100644
--- a/src/tools/clippy/clippy_lints/src/copies.rs
+++ b/src/tools/clippy/clippy_lints/src/copies.rs
@@ -591,7 +591,7 @@ fn lint_same_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>], ignored_ty_ids: &De
conds,
|e| hash_expr(cx, e),
|lhs, rhs| {
- // Ignore eq_expr side effects iff one of the expressin kind is a method call
+ // Ignore eq_expr side effects iff one of the expression kind is a method call
// and the caller is not a mutable, including inner mutable type.
if let ExprKind::MethodCall(_, caller, _, _) = lhs.kind {
if method_caller_is_mutable(cx, caller, ignored_ty_ids) {
diff --git a/src/tools/clippy/clippy_lints/src/crate_in_macro_def.rs b/src/tools/clippy/clippy_lints/src/crate_in_macro_def.rs
index b2fe0386f..7436e9ce8 100644
--- a/src/tools/clippy/clippy_lints/src/crate_in_macro_def.rs
+++ b/src/tools/clippy/clippy_lints/src/crate_in_macro_def.rs
@@ -9,7 +9,7 @@ use rustc_span::{symbol::sym, Span};
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of `crate` as opposed to `$crate` in a macro definition.
+ /// Checks for usage of `crate` as opposed to `$crate` in a macro definition.
///
/// ### Why is this bad?
/// `crate` refers to the macro call's crate, whereas `$crate` refers to the macro definition's
diff --git a/src/tools/clippy/clippy_lints/src/dbg_macro.rs b/src/tools/clippy/clippy_lints/src/dbg_macro.rs
index 799e71e84..ea17e7a60 100644
--- a/src/tools/clippy/clippy_lints/src/dbg_macro.rs
+++ b/src/tools/clippy/clippy_lints/src/dbg_macro.rs
@@ -3,10 +3,10 @@ use clippy_utils::macros::root_macro_call_first_node;
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::{is_in_cfg_test, is_in_test_function};
use rustc_errors::Applicability;
-use rustc_hir::{Expr, ExprKind};
-use rustc_lint::{LateContext, LateLintPass};
+use rustc_hir::{Expr, ExprKind, Node};
+use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_session::{declare_tool_lint, impl_lint_pass};
-use rustc_span::sym;
+use rustc_span::{sym, BytePos, Pos, Span};
declare_clippy_lint! {
/// ### What it does
@@ -31,6 +31,31 @@ declare_clippy_lint! {
"`dbg!` macro is intended as a debugging tool"
}
+/// Gets the span of the statement up to the next semicolon, if and only if the next
+/// non-whitespace character actually is a semicolon.
+/// E.g.
+/// ```rust,ignore
+///
+/// dbg!();
+/// ^^^^^^^ this span is returned
+///
+/// foo!(dbg!());
+/// no span is returned
+/// ```
+fn span_including_semi(cx: &LateContext<'_>, span: Span) -> Option<Span> {
+ let sm = cx.sess().source_map();
+ let sf = sm.lookup_source_file(span.hi());
+ let src = sf.src.as_ref()?.get(span.hi().to_usize()..)?;
+ let first_non_whitespace = src.find(|c: char| !c.is_whitespace())?;
+
+ if src.as_bytes()[first_non_whitespace] == b';' {
+ let hi = span.hi() + BytePos::from_usize(first_non_whitespace + 1);
+ Some(span.with_hi(hi))
+ } else {
+ None
+ }
+}
+
#[derive(Copy, Clone)]
pub struct DbgMacro {
allow_dbg_in_tests: bool,
@@ -55,13 +80,25 @@ impl LateLintPass<'_> for DbgMacro {
return;
}
let mut applicability = Applicability::MachineApplicable;
- let suggestion = match expr.peel_drop_temps().kind {
+
+ let (sugg_span, suggestion) = match expr.peel_drop_temps().kind {
// dbg!()
- ExprKind::Block(_, _) => String::new(),
- // dbg!(1)
- ExprKind::Match(val, ..) => {
- snippet_with_applicability(cx, val.span.source_callsite(), "..", &mut applicability).to_string()
+ ExprKind::Block(..) => {
+ // If the `dbg!` macro is a "free" statement and not contained within other expressions,
+ // remove the whole statement.
+ if let Some(Node::Stmt(stmt)) = cx.tcx.hir().find_parent(expr.hir_id)
+ && let Some(span) = span_including_semi(cx, stmt.span.source_callsite())
+ {
+ (span, String::new())
+ } else {
+ (macro_call.span, String::from("()"))
+ }
},
+ // dbg!(1)
+ ExprKind::Match(val, ..) => (
+ macro_call.span,
+ snippet_with_applicability(cx, val.span.source_callsite(), "..", &mut applicability).to_string(),
+ ),
// dbg!(2, 3)
ExprKind::Tup(
[
@@ -82,7 +119,7 @@ impl LateLintPass<'_> for DbgMacro {
"..",
&mut applicability,
);
- format!("({snippet})")
+ (macro_call.span, format!("({snippet})"))
},
_ => return,
};
@@ -90,7 +127,7 @@ impl LateLintPass<'_> for DbgMacro {
span_lint_and_sugg(
cx,
DBG_MACRO,
- macro_call.span,
+ sugg_span,
"the `dbg!` macro is intended as a debugging tool",
"remove the invocation before committing it to a version control system",
suggestion,
diff --git a/src/tools/clippy/clippy_lints/src/declared_lints.rs b/src/tools/clippy/clippy_lints/src/declared_lints.rs
index f24dab627..423eee477 100644
--- a/src/tools/clippy/clippy_lints/src/declared_lints.rs
+++ b/src/tools/clippy/clippy_lints/src/declared_lints.rs
@@ -48,9 +48,11 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::attrs::BLANKET_CLIPPY_RESTRICTION_LINTS_INFO,
crate::attrs::DEPRECATED_CFG_ATTR_INFO,
crate::attrs::DEPRECATED_SEMVER_INFO,
+ crate::attrs::EMPTY_LINE_AFTER_DOC_COMMENTS_INFO,
crate::attrs::EMPTY_LINE_AFTER_OUTER_ATTR_INFO,
crate::attrs::INLINE_ALWAYS_INFO,
crate::attrs::MISMATCHED_TARGET_OS_INFO,
+ crate::attrs::NON_MINIMAL_CFG_INFO,
crate::attrs::USELESS_ATTRIBUTE_INFO,
crate::await_holding_invalid::AWAIT_HOLDING_INVALID_TYPE_INFO,
crate::await_holding_invalid::AWAIT_HOLDING_LOCK_INFO,
@@ -105,6 +107,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::dbg_macro::DBG_MACRO_INFO,
crate::default::DEFAULT_TRAIT_ACCESS_INFO,
crate::default::FIELD_REASSIGN_WITH_DEFAULT_INFO,
+ crate::default_constructed_unit_structs::DEFAULT_CONSTRUCTED_UNIT_STRUCTS_INFO,
crate::default_instead_of_iter_empty::DEFAULT_INSTEAD_OF_ITER_EMPTY_INFO,
crate::default_numeric_fallback::DEFAULT_NUMERIC_FALLBACK_INFO,
crate::default_union_representation::DEFAULT_UNION_REPRESENTATION_INFO,
@@ -131,12 +134,8 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::doc::NEEDLESS_DOCTEST_MAIN_INFO,
crate::doc::UNNECESSARY_SAFETY_DOC_INFO,
crate::double_parens::DOUBLE_PARENS_INFO,
- crate::drop_forget_ref::DROP_COPY_INFO,
crate::drop_forget_ref::DROP_NON_DROP_INFO,
- crate::drop_forget_ref::DROP_REF_INFO,
- crate::drop_forget_ref::FORGET_COPY_INFO,
crate::drop_forget_ref::FORGET_NON_DROP_INFO,
- crate::drop_forget_ref::FORGET_REF_INFO,
crate::drop_forget_ref::UNDROPPED_MANUALLY_DROPS_INFO,
crate::duplicate_mod::DUPLICATE_MOD_INFO,
crate::else_if_without_else::ELSE_IF_WITHOUT_ELSE_INFO,
@@ -215,6 +214,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::invalid_upcast_comparisons::INVALID_UPCAST_COMPARISONS_INFO,
crate::invalid_utf8_in_unchecked::INVALID_UTF8_IN_UNCHECKED_INFO,
crate::items_after_statements::ITEMS_AFTER_STATEMENTS_INFO,
+ crate::items_after_test_module::ITEMS_AFTER_TEST_MODULE_INFO,
crate::iter_not_returning_iterator::ITER_NOT_RETURNING_ITERATOR_INFO,
crate::large_const_arrays::LARGE_CONST_ARRAYS_INFO,
crate::large_enum_variant::LARGE_ENUM_VARIANT_INFO,
@@ -248,6 +248,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::loops::MANUAL_FIND_INFO,
crate::loops::MANUAL_FLATTEN_INFO,
crate::loops::MANUAL_MEMCPY_INFO,
+ crate::loops::MANUAL_WHILE_LET_SOME_INFO,
crate::loops::MISSING_SPIN_LOOP_INFO,
crate::loops::MUT_RANGE_BOUND_INFO,
crate::loops::NEEDLESS_RANGE_LOOP_INFO,
@@ -312,7 +313,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::methods::CHARS_NEXT_CMP_INFO,
crate::methods::CLEAR_WITH_DRAIN_INFO,
crate::methods::CLONED_INSTEAD_OF_COPIED_INFO,
- crate::methods::CLONE_DOUBLE_REF_INFO,
crate::methods::CLONE_ON_COPY_INFO,
crate::methods::CLONE_ON_REF_PTR_INFO,
crate::methods::COLLAPSIBLE_STR_REPLACE_INFO,
@@ -349,6 +349,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::methods::ITER_WITH_DRAIN_INFO,
crate::methods::MANUAL_FILTER_MAP_INFO,
crate::methods::MANUAL_FIND_MAP_INFO,
+ crate::methods::MANUAL_NEXT_BACK_INFO,
crate::methods::MANUAL_OK_OR_INFO,
crate::methods::MANUAL_SATURATING_ARITHMETIC_INFO,
crate::methods::MANUAL_SPLIT_ONCE_INFO,
@@ -445,6 +446,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::needless_arbitrary_self_type::NEEDLESS_ARBITRARY_SELF_TYPE_INFO,
crate::needless_bool::BOOL_COMPARISON_INFO,
crate::needless_bool::NEEDLESS_BOOL_INFO,
+ crate::needless_bool::NEEDLESS_BOOL_ASSIGN_INFO,
crate::needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE_INFO,
crate::needless_continue::NEEDLESS_CONTINUE_INFO,
crate::needless_for_each::NEEDLESS_FOR_EACH_INFO,
@@ -486,7 +488,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::operators::FLOAT_EQUALITY_WITHOUT_ABS_INFO,
crate::operators::IDENTITY_OP_INFO,
crate::operators::INEFFECTIVE_BIT_MASK_INFO,
- crate::operators::INTEGER_ARITHMETIC_INFO,
crate::operators::INTEGER_DIVISION_INFO,
crate::operators::MISREFACTORED_ASSIGN_OP_INFO,
crate::operators::MODULO_ARITHMETIC_INFO,
@@ -536,6 +537,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::redundant_slicing::REDUNDANT_SLICING_INFO,
crate::redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES_INFO,
crate::ref_option_ref::REF_OPTION_REF_INFO,
+ crate::ref_patterns::REF_PATTERNS_INFO,
crate::reference::DEREF_ADDROF_INFO,
crate::regex::INVALID_REGEX_INFO,
crate::regex::TRIVIAL_REGEX_INFO,
diff --git a/src/tools/clippy/clippy_lints/src/default_constructed_unit_structs.rs b/src/tools/clippy/clippy_lints/src/default_constructed_unit_structs.rs
new file mode 100644
index 000000000..fb037bbcb
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/default_constructed_unit_structs.rs
@@ -0,0 +1,84 @@
+use clippy_utils::{diagnostics::span_lint_and_sugg, is_ty_alias, match_def_path, paths};
+use hir::{def::Res, ExprKind};
+use rustc_errors::Applicability;
+use rustc_hir as hir;
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::ty;
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Check for construction on unit struct using `default`.
+ ///
+ /// ### Why is this bad?
+ /// This adds code complexity and an unnecessary function call.
+ ///
+ /// ### Example
+ /// ```rust
+ /// # use std::marker::PhantomData;
+ /// #[derive(Default)]
+ /// struct S<T> {
+ /// _marker: PhantomData<T>
+ /// }
+ ///
+ /// let _: S<i32> = S {
+ /// _marker: PhantomData::default()
+ /// };
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// # use std::marker::PhantomData;
+ /// struct S<T> {
+ /// _marker: PhantomData<T>
+ /// }
+ ///
+ /// let _: S<i32> = S {
+ /// _marker: PhantomData
+ /// };
+ /// ```
+ #[clippy::version = "1.71.0"]
+ pub DEFAULT_CONSTRUCTED_UNIT_STRUCTS,
+ complexity,
+ "unit structs can be contructed without calling `default`"
+}
+declare_lint_pass!(DefaultConstructedUnitStructs => [DEFAULT_CONSTRUCTED_UNIT_STRUCTS]);
+
+fn is_alias(ty: hir::Ty<'_>) -> bool {
+ if let hir::TyKind::Path(ref qpath) = ty.kind {
+ is_ty_alias(qpath)
+ } else {
+ false
+ }
+}
+
+impl LateLintPass<'_> for DefaultConstructedUnitStructs {
+ fn check_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
+ if_chain!(
+ // make sure we have a call to `Default::default`
+ if let hir::ExprKind::Call(fn_expr, &[]) = expr.kind;
+ if let ExprKind::Path(ref qpath @ hir::QPath::TypeRelative(base, _)) = fn_expr.kind;
+ // make sure this isn't a type alias:
+ // `<Foo as Bar>::Assoc` cannot be used as a constructor
+ if !is_alias(*base);
+ if let Res::Def(_, def_id) = cx.qpath_res(qpath, fn_expr.hir_id);
+ if match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD);
+ // make sure we have a struct with no fields (unit struct)
+ if let ty::Adt(def, ..) = cx.typeck_results().expr_ty(expr).kind();
+ if def.is_struct();
+ if let var @ ty::VariantDef { ctor: Some((hir::def::CtorKind::Const, _)), .. } = def.non_enum_variant();
+ if !var.is_field_list_non_exhaustive();
+ if !expr.span.from_expansion() && !qpath.span().from_expansion();
+ then {
+ span_lint_and_sugg(
+ cx,
+ DEFAULT_CONSTRUCTED_UNIT_STRUCTS,
+ expr.span.with_lo(qpath.qself_span().hi()),
+ "use of `default` to create a unit struct",
+ "remove this call to `default`",
+ String::new(),
+ Applicability::MachineApplicable,
+ )
+ }
+ );
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/default_union_representation.rs b/src/tools/clippy/clippy_lints/src/default_union_representation.rs
index dec357ab7..03b5a2d6d 100644
--- a/src/tools/clippy/clippy_lints/src/default_union_representation.rs
+++ b/src/tools/clippy/clippy_lints/src/default_union_representation.rs
@@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultUnionRepresentation {
None,
&format!(
"consider annotating `{}` with `#[repr(C)]` to explicitly specify memory layout",
- cx.tcx.def_path_str(item.owner_id.to_def_id())
+ cx.tcx.def_path_str(item.owner_id)
),
);
}
diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs
index 7f3f26bed..b27ffe73f 100644
--- a/src/tools/clippy/clippy_lints/src/dereference.rs
+++ b/src/tools/clippy/clippy_lints/src/dereference.rs
@@ -1424,6 +1424,7 @@ fn ty_auto_deref_stability<'tcx>(
continue;
},
ty::Param(_) => TyPosition::new_deref_stable_for_result(precedence, ty),
+ ty::Alias(ty::Inherent, _) => unreachable!("inherent projection should have been normalized away above"),
ty::Alias(ty::Projection, _) if ty.has_non_region_param() => {
TyPosition::new_deref_stable_for_result(precedence, ty)
},
diff --git a/src/tools/clippy/clippy_lints/src/derive.rs b/src/tools/clippy/clippy_lints/src/derive.rs
index f425dd5fb..8f5d319cd 100644
--- a/src/tools/clippy/clippy_lints/src/derive.rs
+++ b/src/tools/clippy/clippy_lints/src/derive.rs
@@ -517,7 +517,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
tcx.mk_predicates_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain(
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate {
- trait_ref: tcx.mk_trait_ref(eq_trait_id, [tcx.mk_param_from_def(param)]),
+ trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]),
constness: BoundConstness::NotConst,
polarity: ImplPolarity::Positive,
}))))
diff --git a/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs b/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs
index 11e1bcdf1..9c60edb17 100644
--- a/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs
+++ b/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs
@@ -9,102 +9,6 @@ use rustc_span::sym;
declare_clippy_lint! {
/// ### What it does
- /// Checks for calls to `std::mem::drop` with a reference
- /// instead of an owned value.
- ///
- /// ### Why is this bad?
- /// Calling `drop` on a reference will only drop the
- /// reference itself, which is a no-op. It will not call the `drop` method (from
- /// the `Drop` trait implementation) on the underlying referenced value, which
- /// is likely what was intended.
- ///
- /// ### Example
- /// ```ignore
- /// let mut lock_guard = mutex.lock();
- /// std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex
- /// // still locked
- /// operation_that_requires_mutex_to_be_unlocked();
- /// ```
- #[clippy::version = "pre 1.29.0"]
- pub DROP_REF,
- correctness,
- "calls to `std::mem::drop` with a reference instead of an owned value"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Checks for calls to `std::mem::forget` with a reference
- /// instead of an owned value.
- ///
- /// ### Why is this bad?
- /// Calling `forget` on a reference will only forget the
- /// reference itself, which is a no-op. It will not forget the underlying
- /// referenced
- /// value, which is likely what was intended.
- ///
- /// ### Example
- /// ```rust
- /// let x = Box::new(1);
- /// std::mem::forget(&x) // Should have been forget(x), x will still be dropped
- /// ```
- #[clippy::version = "pre 1.29.0"]
- pub FORGET_REF,
- correctness,
- "calls to `std::mem::forget` with a reference instead of an owned value"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Checks for calls to `std::mem::drop` with a value
- /// that derives the Copy trait
- ///
- /// ### Why is this bad?
- /// Calling `std::mem::drop` [does nothing for types that
- /// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html), since the
- /// value will be copied and moved into the function on invocation.
- ///
- /// ### Example
- /// ```rust
- /// let x: i32 = 42; // i32 implements Copy
- /// std::mem::drop(x) // A copy of x is passed to the function, leaving the
- /// // original unaffected
- /// ```
- #[clippy::version = "pre 1.29.0"]
- pub DROP_COPY,
- correctness,
- "calls to `std::mem::drop` with a value that implements Copy"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Checks for calls to `std::mem::forget` with a value that
- /// derives the Copy trait
- ///
- /// ### Why is this bad?
- /// Calling `std::mem::forget` [does nothing for types that
- /// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the
- /// value will be copied and moved into the function on invocation.
- ///
- /// An alternative, but also valid, explanation is that Copy types do not
- /// implement
- /// the Drop trait, which means they have no destructors. Without a destructor,
- /// there
- /// is nothing for `std::mem::forget` to ignore.
- ///
- /// ### Example
- /// ```rust
- /// let x: i32 = 42; // i32 implements Copy
- /// std::mem::forget(x) // A copy of x is passed to the function, leaving the
- /// // original unaffected
- /// ```
- #[clippy::version = "pre 1.29.0"]
- pub FORGET_COPY,
- correctness,
- "calls to `std::mem::forget` with a value that implements Copy"
-}
-
-declare_clippy_lint! {
- /// ### What it does
/// Checks for calls to `std::mem::drop` with a value that does not implement `Drop`.
///
/// ### Why is this bad?
@@ -172,24 +76,12 @@ declare_clippy_lint! {
"use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value"
}
-const DROP_REF_SUMMARY: &str = "calls to `std::mem::drop` with a reference instead of an owned value. \
- Dropping a reference does nothing";
-const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \
- Forgetting a reference does nothing";
-const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that implements `Copy`. \
- Dropping a copy leaves the original intact";
-const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements `Copy`. \
- Forgetting a copy leaves the original intact";
const DROP_NON_DROP_SUMMARY: &str = "call to `std::mem::drop` with a value that does not implement `Drop`. \
Dropping such a type only extends its contained lifetimes";
const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value that does not implement `Drop`. \
Forgetting such a type is the same as dropping it";
declare_lint_pass!(DropForgetRef => [
- DROP_REF,
- FORGET_REF,
- DROP_COPY,
- FORGET_COPY,
DROP_NON_DROP,
FORGET_NON_DROP,
UNDROPPED_MANUALLY_DROPS
@@ -206,10 +98,11 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
let is_copy = is_copy(cx, arg_ty);
let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr);
let (lint, msg) = match fn_name {
- sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => (DROP_REF, DROP_REF_SUMMARY),
- sym::mem_forget if arg_ty.is_ref() => (FORGET_REF, FORGET_REF_SUMMARY),
- sym::mem_drop if is_copy && !drop_is_single_call_in_arm => (DROP_COPY, DROP_COPY_SUMMARY),
- sym::mem_forget if is_copy => (FORGET_COPY, FORGET_COPY_SUMMARY),
+ // early return for uplifted lints: dropping_references, dropping_copy_types, forgetting_references, forgetting_copy_types
+ sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return,
+ sym::mem_forget if arg_ty.is_ref() => return,
+ sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return,
+ sym::mem_forget if is_copy => return,
sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => {
span_lint_and_help(
cx,
diff --git a/src/tools/clippy/clippy_lints/src/entry.rs b/src/tools/clippy/clippy_lints/src/entry.rs
index 48a54f602..ee5a875ad 100644
--- a/src/tools/clippy/clippy_lints/src/entry.rs
+++ b/src/tools/clippy/clippy_lints/src/entry.rs
@@ -19,7 +19,7 @@ use rustc_span::{Span, SyntaxContext, DUMMY_SP};
declare_clippy_lint! {
/// ### What it does
- /// Checks for uses of `contains_key` + `insert` on `HashMap`
+ /// Checks for usage of `contains_key` + `insert` on `HashMap`
/// or `BTreeMap`.
///
/// ### Why is this bad?
diff --git a/src/tools/clippy/clippy_lints/src/enum_variants.rs b/src/tools/clippy/clippy_lints/src/enum_variants.rs
index 4c69dacf3..faac63404 100644
--- a/src/tools/clippy/clippy_lints/src/enum_variants.rs
+++ b/src/tools/clippy/clippy_lints/src/enum_variants.rs
@@ -1,6 +1,6 @@
//! lint on enum variants that are prefixed or suffixed by the same characters
-use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
+use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_hir};
use clippy_utils::source::is_present_in_source;
use clippy_utils::str_utils::{camel_case_split, count_match_end, count_match_start};
use rustc_hir::{EnumDef, Item, ItemKind, Variant};
@@ -135,9 +135,10 @@ fn check_enum_start(cx: &LateContext<'_>, item_name: &str, variant: &Variant<'_>
&& name.chars().nth(item_name_chars).map_or(false, |c| !c.is_lowercase())
&& name.chars().nth(item_name_chars + 1).map_or(false, |c| !c.is_numeric())
{
- span_lint(
+ span_lint_hir(
cx,
ENUM_VARIANT_NAMES,
+ variant.hir_id,
variant.span,
"variant name starts with the enum's name",
);
@@ -149,9 +150,10 @@ fn check_enum_end(cx: &LateContext<'_>, item_name: &str, variant: &Variant<'_>)
let item_name_chars = item_name.chars().count();
if count_match_end(item_name, name).char_count == item_name_chars {
- span_lint(
+ span_lint_hir(
cx,
ENUM_VARIANT_NAMES,
+ variant.hir_id,
variant.span,
"variant name ends with the enum's name",
);
diff --git a/src/tools/clippy/clippy_lints/src/escape.rs b/src/tools/clippy/clippy_lints/src/escape.rs
index d6ab4c25e..a51a8ee09 100644
--- a/src/tools/clippy/clippy_lints/src/escape.rs
+++ b/src/tools/clippy/clippy_lints/src/escape.rs
@@ -92,11 +92,8 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
if trait_item.id.owner_id.def_id == fn_def_id {
// be sure we have `self` parameter in this function
if trait_item.kind == (AssocItemKind::Fn { has_self: true }) {
- trait_self_ty = Some(
- TraitRef::identity(cx.tcx, trait_item.id.owner_id.to_def_id())
- .self_ty()
- .skip_binder(),
- );
+ trait_self_ty =
+ Some(TraitRef::identity(cx.tcx, trait_item.id.owner_id.to_def_id()).self_ty());
}
}
}
diff --git a/src/tools/clippy/clippy_lints/src/float_literal.rs b/src/tools/clippy/clippy_lints/src/float_literal.rs
index 6fee7fb30..93bf50fd5 100644
--- a/src/tools/clippy/clippy_lints/src/float_literal.rs
+++ b/src/tools/clippy/clippy_lints/src/float_literal.rs
@@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
let ty = cx.typeck_results().expr_ty(expr);
if_chain! {
if let ty::Float(fty) = *ty.kind();
- if let hir::ExprKind::Lit(ref lit) = expr.kind;
+ if let hir::ExprKind::Lit(lit) = expr.kind;
if let LitKind::Float(sym, lit_float_ty) = lit.node;
then {
let sym_str = sym.as_str();
diff --git a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs
index f95b628e6..3c55a563a 100644
--- a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs
+++ b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs
@@ -2,9 +2,10 @@ use clippy_utils::consts::{
constant, constant_simple, Constant,
Constant::{Int, F32, F64},
};
-use clippy_utils::diagnostics::span_lint_and_sugg;
-use clippy_utils::higher;
-use clippy_utils::{eq_expr_value, get_parent_expr, in_constant, numeric_literal, peel_blocks, sugg};
+use clippy_utils::{
+ diagnostics::span_lint_and_sugg, eq_expr_value, get_parent_expr, higher, in_constant, is_no_std_crate,
+ numeric_literal, peel_blocks, sugg,
+};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment, UnOp};
@@ -113,7 +114,7 @@ declare_lint_pass!(FloatingPointArithmetic => [
// Returns the specialized log method for a given base if base is constant
// and is one of 2, 10 and e
fn get_specialized_log_method(cx: &LateContext<'_>, base: &Expr<'_>) -> Option<&'static str> {
- if let Some((value, _)) = constant(cx, cx.typeck_results(), base) {
+ if let Some(value) = constant(cx, cx.typeck_results(), base) {
if F32(2.0) == value || F64(2.0) == value {
return Some("log2");
} else if F32(10.0) == value || F64(10.0) == value {
@@ -192,8 +193,8 @@ fn check_ln1p(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>) {
constant(cx, cx.typeck_results(), lhs),
constant(cx, cx.typeck_results(), rhs),
) {
- (Some((value, _)), _) if F32(1.0) == value || F64(1.0) == value => rhs,
- (_, Some((value, _))) if F32(1.0) == value || F64(1.0) == value => lhs,
+ (Some(value), _) if F32(1.0) == value || F64(1.0) == value => rhs,
+ (_, Some(value)) if F32(1.0) == value || F64(1.0) == value => lhs,
_ => return,
};
@@ -236,7 +237,7 @@ fn get_integer_from_float_constant(value: &Constant) -> Option<i32> {
fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args: &[Expr<'_>]) {
// Check receiver
- if let Some((value, _)) = constant(cx, cx.typeck_results(), receiver) {
+ if let Some(value) = constant(cx, cx.typeck_results(), receiver) {
if let Some(method) = if F32(f32_consts::E) == value || F64(f64_consts::E) == value {
Some("exp")
} else if F32(2.0) == value || F64(2.0) == value {
@@ -257,7 +258,7 @@ fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args:
}
// Check argument
- if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[0]) {
+ if let Some(value) = constant(cx, cx.typeck_results(), &args[0]) {
let (lint, help, suggestion) = if F32(1.0 / 2.0) == value || F64(1.0 / 2.0) == value {
(
SUBOPTIMAL_FLOPS,
@@ -297,7 +298,7 @@ fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args:
}
fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args: &[Expr<'_>]) {
- if let Some((value, _)) = constant(cx, cx.typeck_results(), &args[0]) {
+ if let Some(value) = constant(cx, cx.typeck_results(), &args[0]) {
if value == Int(2) {
if let Some(parent) = get_parent_expr(cx, expr) {
if let Some(grandparent) = get_parent_expr(cx, parent) {
@@ -383,8 +384,8 @@ fn detect_hypot(cx: &LateContext<'_>, receiver: &Expr<'_>) -> Option<String> {
_
) = &add_rhs.kind;
if lmethod_name.as_str() == "powi" && rmethod_name.as_str() == "powi";
- if let Some((lvalue, _)) = constant(cx, cx.typeck_results(), largs_1);
- if let Some((rvalue, _)) = constant(cx, cx.typeck_results(), rargs_1);
+ if let Some(lvalue) = constant(cx, cx.typeck_results(), largs_1);
+ if let Some(rvalue) = constant(cx, cx.typeck_results(), rargs_1);
if Int(2) == lvalue && Int(2) == rvalue;
then {
return Some(format!("{}.hypot({})", Sugg::hir(cx, largs_0, "..").maybe_par(), Sugg::hir(cx, rargs_0, "..")));
@@ -415,7 +416,7 @@ fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) {
if_chain! {
if let ExprKind::Binary(Spanned { node: BinOpKind::Sub, .. }, lhs, rhs) = expr.kind;
if cx.typeck_results().expr_ty(lhs).is_floating_point();
- if let Some((value, _)) = constant(cx, cx.typeck_results(), rhs);
+ if let Some(value) = constant(cx, cx.typeck_results(), rhs);
if F32(1.0) == value || F64(1.0) == value;
if let ExprKind::MethodCall(path, self_arg, ..) = &lhs.kind;
if cx.typeck_results().expr_ty(self_arg).is_floating_point();
@@ -668,8 +669,8 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) {
mul_lhs,
mul_rhs,
) = &div_lhs.kind;
- if let Some((rvalue, _)) = constant(cx, cx.typeck_results(), div_rhs);
- if let Some((lvalue, _)) = constant(cx, cx.typeck_results(), mul_rhs);
+ if let Some(rvalue) = constant(cx, cx.typeck_results(), div_rhs);
+ if let Some(lvalue) = constant(cx, cx.typeck_results(), mul_rhs);
then {
// TODO: also check for constant values near PI/180 or 180/PI
if (F32(f32_consts::PI) == rvalue || F64(f64_consts::PI) == rvalue) &&
@@ -677,7 +678,7 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) {
{
let mut proposal = format!("{}.to_degrees()", Sugg::hir(cx, mul_lhs, "..").maybe_par());
if_chain! {
- if let ExprKind::Lit(ref literal) = mul_lhs.kind;
+ if let ExprKind::Lit(literal) = mul_lhs.kind;
if let ast::LitKind::Float(ref value, float_type) = literal.node;
if float_type == ast::LitFloatType::Unsuffixed;
then {
@@ -703,7 +704,7 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) {
{
let mut proposal = format!("{}.to_radians()", Sugg::hir(cx, mul_lhs, "..").maybe_par());
if_chain! {
- if let ExprKind::Lit(ref literal) = mul_lhs.kind;
+ if let ExprKind::Lit(literal) = mul_lhs.kind;
if let ast::LitKind::Float(ref value, float_type) = literal.node;
if float_type == ast::LitFloatType::Unsuffixed;
then {
@@ -730,7 +731,7 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
- // All of these operations are currently not const.
+ // All of these operations are currently not const and are in std.
if in_constant(cx, expr.hir_id) {
return;
}
@@ -738,7 +739,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic {
if let ExprKind::MethodCall(path, receiver, args, _) = &expr.kind {
let recv_ty = cx.typeck_results().expr_ty(receiver);
- if recv_ty.is_floating_point() {
+ if recv_ty.is_floating_point() && !is_no_std_crate(cx) {
match path.ident.name.as_str() {
"ln" => check_ln1p(cx, expr, receiver),
"log" => check_log_base(cx, expr, receiver, args),
@@ -749,10 +750,12 @@ impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic {
}
}
} else {
- check_expm1(cx, expr);
- check_mul_add(cx, expr);
- check_custom_abs(cx, expr);
- check_log_division(cx, expr);
+ if !is_no_std_crate(cx) {
+ check_expm1(cx, expr);
+ check_mul_add(cx, expr);
+ check_custom_abs(cx, expr);
+ check_log_division(cx, expr);
+ }
check_radians(cx, expr);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/fn_null_check.rs b/src/tools/clippy/clippy_lints/src/fn_null_check.rs
index d8f4a5fe2..521045a9f 100644
--- a/src/tools/clippy/clippy_lints/src/fn_null_check.rs
+++ b/src/tools/clippy/clippy_lints/src/fn_null_check.rs
@@ -89,11 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for FnNullCheck {
// Catching:
// (fn_ptr as *<const/mut> <ty>) == <const that evaluates to null_ptr>
- _ if matches!(
- constant(cx, cx.typeck_results(), to_check),
- Some((Constant::RawPtr(0), _))
- ) =>
- {
+ _ if matches!(constant(cx, cx.typeck_results(), to_check), Some(Constant::RawPtr(0))) => {
lint_expr(cx, expr);
},
diff --git a/src/tools/clippy/clippy_lints/src/format_impl.rs b/src/tools/clippy/clippy_lints/src/format_impl.rs
index e3ddbfb59..3ddee1842 100644
--- a/src/tools/clippy/clippy_lints/src/format_impl.rs
+++ b/src/tools/clippy/clippy_lints/src/format_impl.rs
@@ -51,7 +51,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of `println`, `print`, `eprintln` or `eprint` in an
+ /// Checks for usage of `println`, `print`, `eprintln` or `eprint` in an
/// implementation of a formatting trait.
///
/// ### Why is this bad?
diff --git a/src/tools/clippy/clippy_lints/src/formatting.rs b/src/tools/clippy/clippy_lints/src/formatting.rs
index a866a6898..4762b3543 100644
--- a/src/tools/clippy/clippy_lints/src/formatting.rs
+++ b/src/tools/clippy/clippy_lints/src/formatting.rs
@@ -10,7 +10,7 @@ use rustc_span::source_map::Span;
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of the non-existent `=*`, `=!` and `=-`
+ /// Checks for usage of the non-existent `=*`, `=!` and `=-`
/// operators.
///
/// ### Why is this bad?
diff --git a/src/tools/clippy/clippy_lints/src/from_over_into.rs b/src/tools/clippy/clippy_lints/src/from_over_into.rs
index bd66ace45..10ce2a0f0 100644
--- a/src/tools/clippy/clippy_lints/src/from_over_into.rs
+++ b/src/tools/clippy/clippy_lints/src/from_over_into.rs
@@ -94,7 +94,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
);
}
- let message = format!("replace the `Into` implentation with `From<{}>`", middle_trait_ref.self_ty());
+ let message = format!("replace the `Into` implementation with `From<{}>`", middle_trait_ref.self_ty());
if let Some(suggestions) = convert_to_from(cx, into_trait_seg, target_ty, self_ty, impl_item_ref) {
diag.multipart_suggestion(message, suggestions, Applicability::MachineApplicable);
} else {
diff --git a/src/tools/clippy/clippy_lints/src/functions/misnamed_getters.rs b/src/tools/clippy/clippy_lints/src/functions/misnamed_getters.rs
index e5945939e..b244b9133 100644
--- a/src/tools/clippy/clippy_lints/src/functions/misnamed_getters.rs
+++ b/src/tools/clippy/clippy_lints/src/functions/misnamed_getters.rs
@@ -40,7 +40,7 @@ pub fn check_fn(cx: &LateContext<'_>, kind: FnKind<'_>, decl: &FnDecl<'_>, body:
};
// Body must be &(mut) <self_data>.name
- // self_data is not neccessarilly self, to also lint sub-getters, etc…
+ // self_data is not necessarily self, to also lint sub-getters, etc…
let block_expr = if_chain! {
if let ExprKind::Block(block,_) = body.value.kind;
diff --git a/src/tools/clippy/clippy_lints/src/functions/mod.rs b/src/tools/clippy/clippy_lints/src/functions/mod.rs
index 7c5e44bb7..ee10334c6 100644
--- a/src/tools/clippy/clippy_lints/src/functions/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/functions/mod.rs
@@ -252,6 +252,11 @@ declare_clippy_lint! {
/// A `Result` is at least as large as the `Err`-variant. While we
/// expect that variant to be seldomly used, the compiler needs to reserve
/// and move that much memory every single time.
+ /// Furthermore, errors are often simply passed up the call-stack, making
+ /// use of the `?`-operator and its type-conversion mechanics. If the
+ /// `Err`-variant further up the call-stack stores the `Err`-variant in
+ /// question (as library code often does), it itself needs to be at least
+ /// as large, propagating the problem.
///
/// ### Known problems
/// The size determined by Clippy is platform-dependent.
@@ -330,7 +335,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Lints when `impl Trait` is being used in a function's paremeters.
+ /// Lints when `impl Trait` is being used in a function's parameters.
/// ### Why is this bad?
/// Turbofish syntax (`::<>`) cannot be used when `impl Trait` is being used, making `impl Trait` less powerful. Readability may also be a factor.
///
@@ -348,7 +353,7 @@ declare_clippy_lint! {
/// // [...]
/// }
/// ```
- #[clippy::version = "1.68.0"]
+ #[clippy::version = "1.69.0"]
pub IMPL_TRAIT_IN_PARAMS,
restriction,
"`impl Trait` is used in the function's parameters"
diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs
index ed0bd58c7..d1314795f 100644
--- a/src/tools/clippy/clippy_lints/src/future_not_send.rs
+++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs
@@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind;
use rustc_hir::{Body, FnDecl};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass};
-use rustc_middle::ty::{self, AliasTy, Clause, EarlyBinder, PredicateKind};
+use rustc_middle::ty::{self, AliasTy, Clause, PredicateKind};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::def_id::LocalDefId;
use rustc_span::{sym, Span};
@@ -66,8 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
if let ty::Alias(ty::Opaque, AliasTy { def_id, substs, .. }) = *ret_ty.kind() {
let preds = cx.tcx.explicit_item_bounds(def_id);
let mut is_future = false;
- for &(p, _span) in preds {
- let p = EarlyBinder(p).subst(cx.tcx, substs);
+ for (p, _span) in preds.subst_iter_copied(cx.tcx, substs) {
if let Some(trait_pred) = p.to_opt_poly_trait_pred() {
if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() {
is_future = true;
@@ -97,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
if let PredicateKind::Clause(Clause::Trait(trait_pred)) =
obligation.predicate.kind().skip_binder()
{
- db.note(&format!(
+ db.note(format!(
"`{}` doesn't implement `{}`",
trait_pred.self_ty(),
trait_pred.trait_ref.print_only_trait_path(),
diff --git a/src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs b/src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs
index 57e6caa87..ee7973b82 100644
--- a/src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs
+++ b/src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs
@@ -60,7 +60,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd {
if expr1.span.ctxt() == ctxt;
if clippy_utils::SpanlessEq::new(cx).eq_expr(l, target);
if BinOpKind::Add == op1.node;
- if let ExprKind::Lit(ref lit) = value.kind;
+ if let ExprKind::Lit(lit) = value.kind;
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node;
if block.expr.is_none();
then {
@@ -101,10 +101,10 @@ fn get_int_max(ty: Ty<'_>) -> Option<u128> {
fn get_const<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> Option<(u128, BinOpKind, &'tcx Expr<'tcx>)> {
if let ExprKind::Binary(op, l, r) = expr.kind {
let tr = cx.typeck_results();
- if let Some((Constant::Int(c), _)) = constant(cx, tr, r) {
+ if let Some(Constant::Int(c)) = constant(cx, tr, r) {
return Some((c, op.node, l));
};
- if let Some((Constant::Int(c), _)) = constant(cx, tr, l) {
+ if let Some(Constant::Int(c)) = constant(cx, tr, l) {
return Some((c, invert_op(op.node)?, r));
}
}
diff --git a/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs b/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs
index 0c7aea6da..1e99b6faa 100644
--- a/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs
+++ b/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs
@@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
// Get the variable name
let var_name = ares_path.segments[0].ident.name.as_str();
match cond_num_val.kind {
- ExprKind::Lit(ref cond_lit) => {
+ ExprKind::Lit(cond_lit) => {
// Check if the constant is zero
if let LitKind::Int(0, _) = cond_lit.node {
if cx.typeck_results().expr_ty(cond_left).is_signed() {
diff --git a/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs b/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs
index bdeddf44d..7a269e98f 100644
--- a/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs
+++ b/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs
@@ -254,7 +254,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> {
let parent_id = map.parent_id(expr.hir_id);
if let Some(hir::Node::Expr(parent_expr)) = map.find(parent_id);
if let hir::ExprKind::Index(_, index_expr) = parent_expr.kind;
- if let Some((Constant::Int(index_value), _)) = constant(cx, cx.typeck_results(), index_expr);
+ if let Some(Constant::Int(index_value)) = constant(cx, cx.typeck_results(), index_expr);
if let Ok(index_value) = index_value.try_into();
if index_value < max_suggested_slice;
diff --git a/src/tools/clippy/clippy_lints/src/indexing_slicing.rs b/src/tools/clippy/clippy_lints/src/indexing_slicing.rs
index c384172fb..22c14d9b0 100644
--- a/src/tools/clippy/clippy_lints/src/indexing_slicing.rs
+++ b/src/tools/clippy/clippy_lints/src/indexing_slicing.rs
@@ -170,7 +170,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
return;
}
// Index is a constant uint.
- if let Some(..) = constant(cx, cx.typeck_results(), index) {
+ if constant(cx, cx.typeck_results(), index).is_some() {
// Let rustc's `const_err` lint handle constant `usize` indexing on arrays.
return;
}
@@ -191,18 +191,14 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
/// Returns a tuple of options with the start and end (exclusive) values of
/// the range. If the start or end is not constant, None is returned.
fn to_const_range(cx: &LateContext<'_>, range: higher::Range<'_>, array_size: u128) -> (Option<u128>, Option<u128>) {
- let s = range
- .start
- .map(|expr| constant(cx, cx.typeck_results(), expr).map(|(c, _)| c));
+ let s = range.start.map(|expr| constant(cx, cx.typeck_results(), expr));
let start = match s {
Some(Some(Constant::Int(x))) => Some(x),
Some(_) => None,
None => Some(0),
};
- let e = range
- .end
- .map(|expr| constant(cx, cx.typeck_results(), expr).map(|(c, _)| c));
+ let e = range.end.map(|expr| constant(cx, cx.typeck_results(), expr));
let end = match e {
Some(Some(Constant::Int(x))) => {
if range.limits == RangeLimits::Closed {
diff --git a/src/tools/clippy/clippy_lints/src/items_after_test_module.rs b/src/tools/clippy/clippy_lints/src/items_after_test_module.rs
new file mode 100644
index 000000000..40378ee82
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/items_after_test_module.rs
@@ -0,0 +1,85 @@
+use clippy_utils::{diagnostics::span_lint_and_help, is_from_proc_macro, is_in_cfg_test};
+use rustc_hir::{HirId, ItemId, ItemKind, Mod};
+use rustc_lint::{LateContext, LateLintPass, LintContext};
+use rustc_middle::lint::in_external_macro;
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::{sym, Span};
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Triggers if an item is declared after the testing module marked with `#[cfg(test)]`.
+ /// ### Why is this bad?
+ /// Having items declared after the testing module is confusing and may lead to bad test coverage.
+ /// ### Example
+ /// ```rust
+ /// #[cfg(test)]
+ /// mod tests {
+ /// // [...]
+ /// }
+ ///
+ /// fn my_function() {
+ /// // [...]
+ /// }
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// fn my_function() {
+ /// // [...]
+ /// }
+ ///
+ /// #[cfg(test)]
+ /// mod tests {
+ /// // [...]
+ /// }
+ /// ```
+ #[clippy::version = "1.70.0"]
+ pub ITEMS_AFTER_TEST_MODULE,
+ style,
+ "An item was found after the testing module `tests`"
+}
+
+declare_lint_pass!(ItemsAfterTestModule => [ITEMS_AFTER_TEST_MODULE]);
+
+impl LateLintPass<'_> for ItemsAfterTestModule {
+ fn check_mod(&mut self, cx: &LateContext<'_>, _: &Mod<'_>, _: HirId) {
+ let mut was_test_mod_visited = false;
+ let mut test_mod_span: Option<Span> = None;
+
+ let hir = cx.tcx.hir();
+ let items = hir.items().collect::<Vec<ItemId>>();
+
+ for (i, itid) in items.iter().enumerate() {
+ let item = hir.item(*itid);
+
+ if_chain! {
+ if was_test_mod_visited;
+ if i == (items.len() - 3 /* Weird magic number (HIR-translation behaviour) */);
+ if cx.sess().source_map().lookup_char_pos(item.span.lo()).file.name_hash
+ == cx.sess().source_map().lookup_char_pos(test_mod_span.unwrap().lo()).file.name_hash; // Will never fail
+ if !matches!(item.kind, ItemKind::Mod(_));
+ if !is_in_cfg_test(cx.tcx, itid.hir_id()); // The item isn't in the testing module itself
+ if !in_external_macro(cx.sess(), item.span);
+ if !is_from_proc_macro(cx, item);
+
+ then {
+ span_lint_and_help(cx, ITEMS_AFTER_TEST_MODULE, test_mod_span.unwrap().with_hi(item.span.hi()), "items were found after the testing module", None, "move the items to before the testing module was defined");
+ }};
+
+ if let ItemKind::Mod(module) = item.kind && item.span.hi() == module.spans.inner_span.hi() {
+ // Check that it works the same way, the only I way I've found for #10713
+ for attr in cx.tcx.get_attrs(item.owner_id.to_def_id(), sym::cfg) {
+ if_chain! {
+ if attr.has_name(sym::cfg);
+ if let Some(mitems) = attr.meta_item_list();
+ if let [mitem] = &*mitems;
+ if mitem.has_name(sym::test);
+ then {
+ was_test_mod_visited = true;
+ test_mod_span = Some(item.span);
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/large_futures.rs b/src/tools/clippy/clippy_lints/src/large_futures.rs
index 1b0544813..0ca31033b 100644
--- a/src/tools/clippy/clippy_lints/src/large_futures.rs
+++ b/src/tools/clippy/clippy_lints/src/large_futures.rs
@@ -11,7 +11,7 @@ declare_clippy_lint! {
/// It checks for the size of a `Future` created by `async fn` or `async {}`.
///
/// ### Why is this bad?
- /// Due to the current [unideal implemention](https://github.com/rust-lang/rust/issues/69826) of `Generator`,
+ /// Due to the current [unideal implementation](https://github.com/rust-lang/rust/issues/69826) of `Generator`,
/// large size of a `Future` may cause stack overflows.
///
/// ### Example
diff --git a/src/tools/clippy/clippy_lints/src/len_zero.rs b/src/tools/clippy/clippy_lints/src/len_zero.rs
index 0805b4b19..17bd89efa 100644
--- a/src/tools/clippy/clippy_lints/src/len_zero.rs
+++ b/src/tools/clippy/clippy_lints/src/len_zero.rs
@@ -168,25 +168,27 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
}
if let ExprKind::Binary(Spanned { node: cmp, .. }, left, right) = expr.kind {
+ // expr.span might contains parenthesis, see issue #10529
+ let actual_span = left.span.with_hi(right.span.hi());
match cmp {
BinOpKind::Eq => {
- check_cmp(cx, expr.span, left, right, "", 0); // len == 0
- check_cmp(cx, expr.span, right, left, "", 0); // 0 == len
+ check_cmp(cx, actual_span, left, right, "", 0); // len == 0
+ check_cmp(cx, actual_span, right, left, "", 0); // 0 == len
},
BinOpKind::Ne => {
- check_cmp(cx, expr.span, left, right, "!", 0); // len != 0
- check_cmp(cx, expr.span, right, left, "!", 0); // 0 != len
+ check_cmp(cx, actual_span, left, right, "!", 0); // len != 0
+ check_cmp(cx, actual_span, right, left, "!", 0); // 0 != len
},
BinOpKind::Gt => {
- check_cmp(cx, expr.span, left, right, "!", 0); // len > 0
- check_cmp(cx, expr.span, right, left, "", 1); // 1 > len
+ check_cmp(cx, actual_span, left, right, "!", 0); // len > 0
+ check_cmp(cx, actual_span, right, left, "", 1); // 1 > len
},
BinOpKind::Lt => {
- check_cmp(cx, expr.span, left, right, "", 1); // len < 1
- check_cmp(cx, expr.span, right, left, "!", 0); // 0 < len
+ check_cmp(cx, actual_span, left, right, "", 1); // len < 1
+ check_cmp(cx, actual_span, right, left, "!", 0); // 0 < len
},
- BinOpKind::Ge => check_cmp(cx, expr.span, left, right, "!", 1), // len >= 1
- BinOpKind::Le => check_cmp(cx, expr.span, right, left, "!", 1), // 1 <= len
+ BinOpKind::Ge => check_cmp(cx, actual_span, left, right, "!", 1), // len >= 1
+ BinOpKind::Le => check_cmp(cx, actual_span, right, left, "!", 1), // 1 <= len
_ => (),
}
}
@@ -530,7 +532,7 @@ fn check_empty_expr(cx: &LateContext<'_>, span: Span, lit1: &Expr<'_>, lit2: &Ex
}
fn is_empty_string(expr: &Expr<'_>) -> bool {
- if let ExprKind::Lit(ref lit) = expr.kind {
+ if let ExprKind::Lit(lit) = expr.kind {
if let LitKind::Str(lit, _) = lit.node {
let lit = lit.as_str();
return lit.is_empty();
diff --git a/src/tools/clippy/clippy_lints/src/let_underscore.rs b/src/tools/clippy/clippy_lints/src/let_underscore.rs
index 51b5de27d..e66141809 100644
--- a/src/tools/clippy/clippy_lints/src/let_underscore.rs
+++ b/src/tools/clippy/clippy_lints/src/let_underscore.rs
@@ -1,11 +1,14 @@
use clippy_utils::diagnostics::span_lint_and_help;
+use clippy_utils::is_from_proc_macro;
use clippy_utils::ty::{implements_trait, is_must_use_ty, match_type};
use clippy_utils::{is_must_use_func_call, paths};
use rustc_hir::{Local, PatKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::subst::GenericArgKind;
+use rustc_middle::ty::IsSuggestable;
use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::{BytePos, Span};
declare_clippy_lint! {
/// ### What it does
@@ -137,7 +140,7 @@ const SYNC_GUARD_PATHS: [&[&str]; 3] = [
];
impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
- fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) {
+ fn check_local(&mut self, cx: &LateContext<'tcx>, local: &Local<'tcx>) {
if !in_external_macro(cx.tcx.sess, local.span)
&& let PatKind::Wild = local.pat.kind
&& let Some(init) = local.init
@@ -189,13 +192,31 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
if local.pat.default_binding_modes && local.ty.is_none() {
// When `default_binding_modes` is true, the `let` keyword is present.
- span_lint_and_help(
+
+ // Ignore unnameable types
+ if let Some(init) = local.init
+ && !cx.typeck_results().expr_ty(init).is_suggestable(cx.tcx, true)
+ {
+ return;
+ }
+
+ // Ignore if it is from a procedural macro...
+ if is_from_proc_macro(cx, init) {
+ return;
+ }
+
+ span_lint_and_help(
cx,
LET_UNDERSCORE_UNTYPED,
local.span,
"non-binding `let` without a type annotation",
- None,
- "consider adding a type annotation or removing the `let` keyword",
+ Some(
+ Span::new(local.pat.span.hi(),
+ local.pat.span.hi() + BytePos(1),
+ local.pat.span.ctxt(),
+ local.pat.span.parent()
+ )),
+ "consider adding a type annotation",
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/let_with_type_underscore.rs b/src/tools/clippy/clippy_lints/src/let_with_type_underscore.rs
index c01e3882d..a677fcc41 100644
--- a/src/tools/clippy/clippy_lints/src/let_with_type_underscore.rs
+++ b/src/tools/clippy/clippy_lints/src/let_with_type_underscore.rs
@@ -1,4 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_help;
+use clippy_utils::source::snippet;
use rustc_hir::{Local, TyKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
@@ -25,14 +26,21 @@ declare_clippy_lint! {
declare_lint_pass!(UnderscoreTyped => [LET_WITH_TYPE_UNDERSCORE]);
impl LateLintPass<'_> for UnderscoreTyped {
- fn check_local<'tcx>(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) {
+ fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) {
if_chain! {
if !in_external_macro(cx.tcx.sess, local.span);
if let Some(ty) = local.ty; // Ensure that it has a type defined
if let TyKind::Infer = &ty.kind; // that type is '_'
if local.span.ctxt() == ty.span.ctxt();
then {
- span_lint_and_help(cx,
+ // NOTE: Using `is_from_proc_macro` on `init` will require that it's initialized,
+ // this doesn't. Alternatively, `WithSearchPat` can be implemented for `Ty`
+ if snippet(cx, ty.span, "_").trim() != "_" {
+ return;
+ }
+
+ span_lint_and_help(
+ cx,
LET_WITH_TYPE_UNDERSCORE,
local.span,
"variable declared with type underscore",
diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs
index b0ec14855..b442a4ac5 100644
--- a/src/tools/clippy/clippy_lints/src/lib.rs
+++ b/src/tools/clippy/clippy_lints/src/lib.rs
@@ -94,6 +94,7 @@ mod crate_in_macro_def;
mod create_dir;
mod dbg_macro;
mod default;
+mod default_constructed_unit_structs;
mod default_instead_of_iter_empty;
mod default_numeric_fallback;
mod default_union_representation;
@@ -158,6 +159,7 @@ mod int_plus_one;
mod invalid_upcast_comparisons;
mod invalid_utf8_in_unchecked;
mod items_after_statements;
+mod items_after_test_module;
mod iter_not_returning_iterator;
mod large_const_arrays;
mod large_enum_variant;
@@ -264,6 +266,7 @@ mod redundant_pub_crate;
mod redundant_slicing;
mod redundant_static_lifetimes;
mod ref_option_ref;
+mod ref_patterns;
mod reference;
mod regex;
mod return_self_not_must_use;
@@ -329,8 +332,11 @@ mod zero_div_zero;
mod zero_sized_map_values;
// end lints modules, do not remove this comment, it’s used in `update_lints`
-use crate::utils::conf::{format_error, TryConf};
pub use crate::utils::conf::{lookup_conf_file, Conf};
+use crate::utils::{
+ conf::{format_error, metadata::get_configuration_metadata, TryConf},
+ FindAll,
+};
/// Register all pre expansion lints
///
@@ -352,7 +358,7 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Se
pub fn read_conf(sess: &Session, path: &io::Result<(Option<PathBuf>, Vec<String>)>) -> Conf {
if let Ok((_, warnings)) = path {
for warning in warnings {
- sess.warn(warning);
+ sess.warn(warning.clone());
}
}
let file_name = match path {
@@ -469,7 +475,22 @@ pub(crate) struct LintInfo {
pub fn explain(name: &str) {
let target = format!("clippy::{}", name.to_ascii_uppercase());
match declared_lints::LINTS.iter().find(|info| info.lint.name == target) {
- Some(info) => print!("{}", info.explanation),
+ Some(info) => {
+ println!("{}", info.explanation);
+ // Check if the lint has configuration
+ let mdconf = get_configuration_metadata();
+ if let Some(config_vec_positions) = mdconf
+ .iter()
+ .find_all(|cconf| cconf.lints.contains(&info.lint.name_lower()[8..].to_owned()))
+ {
+ // If it has, print it
+ println!("### Configuration for {}:\n", info.lint.name_lower());
+ for position in config_vec_positions {
+ let conf = &mdconf[position];
+ println!(" - {}: {} (default: {})", conf.name, conf.doc, conf.default);
+ }
+ }
+ },
None => println!("unknown lint: {name}"),
}
}
@@ -932,7 +953,14 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|_| Box::new(from_raw_with_void_ptr::FromRawWithVoidPtr));
store.register_late_pass(|_| Box::new(suspicious_xor_used_as_pow::ConfusingXorAndPow));
store.register_late_pass(move |_| Box::new(manual_is_ascii_check::ManualIsAsciiCheck::new(msrv())));
- store.register_late_pass(|_| Box::new(semicolon_block::SemicolonBlock));
+ let semicolon_inside_block_ignore_singleline = conf.semicolon_inside_block_ignore_singleline;
+ let semicolon_outside_block_ignore_multiline = conf.semicolon_outside_block_ignore_multiline;
+ store.register_late_pass(move |_| {
+ Box::new(semicolon_block::SemicolonBlock::new(
+ semicolon_inside_block_ignore_singleline,
+ semicolon_outside_block_ignore_multiline,
+ ))
+ });
store.register_late_pass(|_| Box::new(fn_null_check::FnNullCheck));
store.register_late_pass(|_| Box::new(permissions_set_readonly_false::PermissionsSetReadonlyFalse));
store.register_late_pass(|_| Box::new(size_of_ref::SizeOfRef));
@@ -950,15 +978,20 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|_| Box::new(allow_attributes::AllowAttribute));
store.register_late_pass(move |_| Box::new(manual_main_separator_str::ManualMainSeparatorStr::new(msrv())));
store.register_late_pass(|_| Box::new(unnecessary_struct_initialization::UnnecessaryStruct));
+ let unnecessary_box_size = conf.unnecessary_box_size;
store.register_late_pass(move |_| {
Box::new(unnecessary_box_returns::UnnecessaryBoxReturns::new(
avoid_breaking_exported_api,
+ unnecessary_box_size,
))
});
store.register_late_pass(|_| Box::new(lines_filter_map_ok::LinesFilterMapOk));
store.register_late_pass(|_| Box::new(tests_outside_test_module::TestsOutsideTestModule));
store.register_late_pass(|_| Box::new(manual_slice_size_calculation::ManualSliceSizeCalculation));
store.register_early_pass(|| Box::new(suspicious_doc_comments::SuspiciousDocComments));
+ store.register_late_pass(|_| Box::new(items_after_test_module::ItemsAfterTestModule));
+ store.register_early_pass(|| Box::new(ref_patterns::RefPatterns));
+ store.register_late_pass(|_| Box::new(default_constructed_unit_structs::DefaultConstructedUnitStructs));
// add lints here, do not remove this comment, it's used in `new_lint`
}
diff --git a/src/tools/clippy/clippy_lints/src/lines_filter_map_ok.rs b/src/tools/clippy/clippy_lints/src/lines_filter_map_ok.rs
index b0f927647..09b2032e2 100644
--- a/src/tools/clippy/clippy_lints/src/lines_filter_map_ok.rs
+++ b/src/tools/clippy/clippy_lints/src/lines_filter_map_ok.rs
@@ -10,7 +10,7 @@ use rustc_span::sym;
declare_clippy_lint! {
/// ### What it does
- /// Detect uses of `lines.filter_map(Result::ok)` or `lines.flat_map(Result::ok)`
+ /// Checks for usage of `lines.filter_map(Result::ok)` or `lines.flat_map(Result::ok)`
/// when `lines` has type `std::io::Lines`.
///
/// ### Why is this bad?
@@ -25,7 +25,7 @@ declare_clippy_lint! {
///
/// ### Known problems
/// This lint suggests replacing `filter_map()` or `flat_map()` applied to a `Lines`
- /// instance in all cases. There two cases where the suggestion might not be
+ /// instance in all cases. There are two cases where the suggestion might not be
/// appropriate or necessary:
///
/// - If the `Lines` instance can never produce any error, or if an error is produced
diff --git a/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs b/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs
index c87fc4f90..d4c3f76b8 100644
--- a/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs
@@ -15,7 +15,7 @@ use rustc_span::symbol::sym;
use std::fmt::Display;
use std::iter::Iterator;
-/// Checks for for loops that sequentially copy items from one slice-like
+/// Checks for `for` loops that sequentially copy items from one slice-like
/// object to another.
pub(super) fn check<'tcx>(
cx: &LateContext<'tcx>,
diff --git a/src/tools/clippy/clippy_lints/src/loops/manual_while_let_some.rs b/src/tools/clippy/clippy_lints/src/loops/manual_while_let_some.rs
new file mode 100644
index 000000000..cb9c84be4
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/loops/manual_while_let_some.rs
@@ -0,0 +1,110 @@
+use clippy_utils::{
+ diagnostics::{multispan_sugg_with_applicability, span_lint_and_then},
+ match_def_path, paths,
+ source::snippet,
+ SpanlessEq,
+};
+use rustc_errors::Applicability;
+use rustc_hir::{Expr, ExprKind, Pat, Stmt, StmtKind, UnOp};
+use rustc_lint::LateContext;
+use rustc_span::Span;
+use std::borrow::Cow;
+
+use super::MANUAL_WHILE_LET_SOME;
+
+/// The kind of statement that the `pop()` call appeared in.
+///
+/// Depending on whether the value was assigned to a variable or not changes what pattern
+/// we use for the suggestion.
+#[derive(Copy, Clone)]
+enum PopStmt<'hir> {
+ /// `x.pop().unwrap()` was and assigned to a variable.
+ /// The pattern of this local variable will be used and the local statement
+ /// is deleted in the suggestion.
+ Local(&'hir Pat<'hir>),
+ /// `x.pop().unwrap()` appeared in an arbitrary expression and was not assigned to a variable.
+ /// The suggestion will use some placeholder identifier and the `x.pop().unwrap()` expression
+ /// is replaced with that identifier.
+ Anonymous,
+}
+
+fn report_lint(cx: &LateContext<'_>, pop_span: Span, pop_stmt_kind: PopStmt<'_>, loop_span: Span, receiver_span: Span) {
+ span_lint_and_then(
+ cx,
+ MANUAL_WHILE_LET_SOME,
+ pop_span,
+ "you seem to be trying to pop elements from a `Vec` in a loop",
+ |diag| {
+ let (pat, pop_replacement) = match pop_stmt_kind {
+ PopStmt::Local(pat) => (snippet(cx, pat.span, ".."), String::new()),
+ PopStmt::Anonymous => (Cow::Borrowed("element"), "element".into()),
+ };
+
+ let loop_replacement = format!("while let Some({}) = {}.pop()", pat, snippet(cx, receiver_span, ".."));
+ multispan_sugg_with_applicability(
+ diag,
+ "consider using a `while..let` loop",
+ Applicability::MachineApplicable,
+ [(loop_span, loop_replacement), (pop_span, pop_replacement)],
+ );
+ },
+ );
+}
+
+fn match_method_call(cx: &LateContext<'_>, expr: &Expr<'_>, method: &[&str]) -> bool {
+ if let ExprKind::MethodCall(..) = expr.kind
+ && let Some(id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
+ {
+ match_def_path(cx, id, method)
+ } else {
+ false
+ }
+}
+
+fn is_vec_pop_unwrap(cx: &LateContext<'_>, expr: &Expr<'_>, is_empty_recv: &Expr<'_>) -> bool {
+ if (match_method_call(cx, expr, &paths::OPTION_UNWRAP) || match_method_call(cx, expr, &paths::OPTION_EXPECT))
+ && let ExprKind::MethodCall(_, unwrap_recv, ..) = expr.kind
+ && match_method_call(cx, unwrap_recv, &paths::VEC_POP)
+ && let ExprKind::MethodCall(_, pop_recv, ..) = unwrap_recv.kind
+ {
+ // make sure they're the same `Vec`
+ SpanlessEq::new(cx).eq_expr(pop_recv, is_empty_recv)
+ } else {
+ false
+ }
+}
+
+fn check_local(cx: &LateContext<'_>, stmt: &Stmt<'_>, is_empty_recv: &Expr<'_>, loop_span: Span) {
+ if let StmtKind::Local(local) = stmt.kind
+ && let Some(init) = local.init
+ && is_vec_pop_unwrap(cx, init, is_empty_recv)
+ {
+ report_lint(cx, stmt.span, PopStmt::Local(local.pat), loop_span, is_empty_recv.span);
+ }
+}
+
+fn check_call_arguments(cx: &LateContext<'_>, stmt: &Stmt<'_>, is_empty_recv: &Expr<'_>, loop_span: Span) {
+ if let StmtKind::Semi(expr) | StmtKind::Expr(expr) = stmt.kind {
+ if let ExprKind::MethodCall(.., args, _) | ExprKind::Call(_, args) = expr.kind {
+ let offending_arg = args
+ .iter()
+ .find_map(|arg| is_vec_pop_unwrap(cx, arg, is_empty_recv).then_some(arg.span));
+
+ if let Some(offending_arg) = offending_arg {
+ report_lint(cx, offending_arg, PopStmt::Anonymous, loop_span, is_empty_recv.span);
+ }
+ }
+ }
+}
+
+pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, full_cond: &'tcx Expr<'_>, body: &'tcx Expr<'_>, loop_span: Span) {
+ if let ExprKind::Unary(UnOp::Not, cond) = full_cond.kind
+ && let ExprKind::MethodCall(_, is_empty_recv, _, _) = cond.kind
+ && match_method_call(cx, cond, &paths::VEC_IS_EMPTY)
+ && let ExprKind::Block(body, _) = body.kind
+ && let Some(stmt) = body.stmts.first()
+ {
+ check_local(cx, stmt, is_empty_recv, loop_span);
+ check_call_arguments(cx, stmt, is_empty_recv, loop_span);
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/loops/mod.rs b/src/tools/clippy/clippy_lints/src/loops/mod.rs
index 610a0233e..f83ad388a 100644
--- a/src/tools/clippy/clippy_lints/src/loops/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/mod.rs
@@ -7,6 +7,7 @@ mod iter_next_loop;
mod manual_find;
mod manual_flatten;
mod manual_memcpy;
+mod manual_while_let_some;
mod missing_spin_loop;
mod mut_range_bound;
mod needless_range_loop;
@@ -575,6 +576,36 @@ declare_clippy_lint! {
"manual implementation of `Iterator::find`"
}
+declare_clippy_lint! {
+ /// ### What it does
+ /// Looks for loops that check for emptiness of a `Vec` in the condition and pop an element
+ /// in the body as a separate operation.
+ ///
+ /// ### Why is this bad?
+ /// Such loops can be written in a more idiomatic way by using a while-let loop and directly
+ /// pattern matching on the return value of `Vec::pop()`.
+ ///
+ /// ### Example
+ /// ```rust
+ /// let mut numbers = vec![1, 2, 3, 4, 5];
+ /// while !numbers.is_empty() {
+ /// let number = numbers.pop().unwrap();
+ /// // use `number`
+ /// }
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// let mut numbers = vec![1, 2, 3, 4, 5];
+ /// while let Some(number) = numbers.pop() {
+ /// // use `number`
+ /// }
+ /// ```
+ #[clippy::version = "1.70.0"]
+ pub MANUAL_WHILE_LET_SOME,
+ style,
+ "checking for emptiness of a `Vec` in the loop condition and popping an element in the body"
+}
+
declare_lint_pass!(Loops => [
MANUAL_MEMCPY,
MANUAL_FLATTEN,
@@ -594,6 +625,7 @@ declare_lint_pass!(Loops => [
SINGLE_ELEMENT_LOOP,
MISSING_SPIN_LOOP,
MANUAL_FIND,
+ MANUAL_WHILE_LET_SOME
]);
impl<'tcx> LateLintPass<'tcx> for Loops {
@@ -640,9 +672,10 @@ impl<'tcx> LateLintPass<'tcx> for Loops {
while_let_on_iterator::check(cx, expr);
- if let Some(higher::While { condition, body }) = higher::While::hir(expr) {
+ if let Some(higher::While { condition, body, span }) = higher::While::hir(expr) {
while_immutable_condition::check(cx, condition, body);
missing_spin_loop::check(cx, condition, body);
+ manual_while_let_some::check(cx, condition, body, span);
}
}
}
diff --git a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs
index 5c317c2a5..cb4465675 100644
--- a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs
@@ -208,7 +208,7 @@ fn is_end_eq_array_len<'tcx>(
indexed_ty: Ty<'tcx>,
) -> bool {
if_chain! {
- if let ExprKind::Lit(ref lit) = end.kind;
+ if let ExprKind::Lit(lit) = end.kind;
if let ast::LitKind::Int(end_int, _) = lit.node;
if let ty::Array(_, arr_len_const) = indexed_ty.kind();
if let Some(arr_len) = arr_len_const.try_eval_target_usize(cx.tcx, cx.param_env);
diff --git a/src/tools/clippy/clippy_lints/src/loops/never_loop.rs b/src/tools/clippy/clippy_lints/src/loops/never_loop.rs
index f0a1b1dfe..5f1fdf00b 100644
--- a/src/tools/clippy/clippy_lints/src/loops/never_loop.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/never_loop.rs
@@ -226,7 +226,8 @@ fn never_loop_expr(expr: &Expr<'_>, ignore_ids: &mut Vec<HirId>, main_loop_id: H
| InlineAsmOperand::SymStatic { .. } => NeverLoopResult::Otherwise,
})
.fold(NeverLoopResult::Otherwise, combine_seq),
- ExprKind::Yield(_, _)
+ ExprKind::OffsetOf(_, _)
+ | ExprKind::Yield(_, _)
| ExprKind::Closure { .. }
| ExprKind::Path(_)
| ExprKind::ConstBlock(_)
diff --git a/src/tools/clippy/clippy_lints/src/manual_assert.rs b/src/tools/clippy/clippy_lints/src/manual_assert.rs
index ce5d657bc..45ea5aab4 100644
--- a/src/tools/clippy/clippy_lints/src/manual_assert.rs
+++ b/src/tools/clippy/clippy_lints/src/manual_assert.rs
@@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAssert {
};
let cond_sugg = sugg::Sugg::hir_with_applicability(cx, cond, "..", &mut applicability).maybe_par();
let sugg = format!("assert!({not}{cond_sugg}, {format_args_snip});");
- // we show to the user the suggestion without the comments, but when applicating the fix, include the comments in the block
+ // we show to the user the suggestion without the comments, but when applying the fix, include the comments in the block
span_lint_and_then(
cx,
MANUAL_ASSERT,
diff --git a/src/tools/clippy/clippy_lints/src/manual_bits.rs b/src/tools/clippy/clippy_lints/src/manual_bits.rs
index bc815dc4a..4629b22d1 100644
--- a/src/tools/clippy/clippy_lints/src/manual_bits.rs
+++ b/src/tools/clippy/clippy_lints/src/manual_bits.rs
@@ -13,7 +13,7 @@ use rustc_span::sym;
declare_clippy_lint! {
/// ### What it does
- /// Checks for uses of `std::mem::size_of::<T>() * 8` when
+ /// Checks for usage of `std::mem::size_of::<T>() * 8` when
/// `T::BITS` is available.
///
/// ### Why is this bad?
diff --git a/src/tools/clippy/clippy_lints/src/manual_let_else.rs b/src/tools/clippy/clippy_lints/src/manual_let_else.rs
index 98e698c6c..3f8b42ffe 100644
--- a/src/tools/clippy/clippy_lints/src/manual_let_else.rs
+++ b/src/tools/clippy/clippy_lints/src/manual_let_else.rs
@@ -38,7 +38,6 @@ declare_clippy_lint! {
/// Could be written:
///
/// ```rust
- /// # #![feature(let_else)]
/// # fn main () {
/// # let w = Some(0);
/// let Some(v) = w else { return };
@@ -69,29 +68,23 @@ impl_lint_pass!(ManualLetElse => [MANUAL_LET_ELSE]);
impl<'tcx> LateLintPass<'tcx> for ManualLetElse {
fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &'tcx Stmt<'tcx>) {
- let if_let_or_match = if_chain! {
- if self.msrv.meets(msrvs::LET_ELSE);
- if !in_external_macro(cx.sess(), stmt.span);
- if let StmtKind::Local(local) = stmt.kind;
- if let Some(init) = local.init;
- if local.els.is_none();
- if local.ty.is_none();
- if init.span.ctxt() == stmt.span.ctxt();
- if let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init);
- then {
- if_let_or_match
- } else {
- return;
- }
- };
+ if !self.msrv.meets(msrvs::LET_ELSE) || in_external_macro(cx.sess(), stmt.span) {
+ return;
+ }
+ if let StmtKind::Local(local) = stmt.kind &&
+ let Some(init) = local.init &&
+ local.els.is_none() &&
+ local.ty.is_none() &&
+ init.span.ctxt() == stmt.span.ctxt() &&
+ let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init) {
match if_let_or_match {
IfLetOrMatch::IfLet(if_let_expr, let_pat, if_then, if_else) => if_chain! {
if expr_is_simple_identity(let_pat, if_then);
if let Some(if_else) = if_else;
if expr_diverges(cx, if_else);
then {
- emit_manual_let_else(cx, stmt.span, if_let_expr, let_pat, if_else);
+ emit_manual_let_else(cx, stmt.span, if_let_expr, local.pat, let_pat, if_else);
}
},
IfLetOrMatch::Match(match_expr, arms, source) => {
@@ -101,7 +94,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualLetElse {
if source != MatchSource::Normal {
return;
}
- // Any other number than two arms doesn't (neccessarily)
+ // Any other number than two arms doesn't (necessarily)
// have a trivial mapping to let else.
if arms.len() != 2 {
return;
@@ -128,15 +121,23 @@ impl<'tcx> LateLintPass<'tcx> for ManualLetElse {
return;
}
- emit_manual_let_else(cx, stmt.span, match_expr, pat_arm.pat, diverging_arm.body);
+ emit_manual_let_else(cx, stmt.span, match_expr, local.pat, pat_arm.pat, diverging_arm.body);
},
}
+ };
}
extract_msrv_attr!(LateContext);
}
-fn emit_manual_let_else(cx: &LateContext<'_>, span: Span, expr: &Expr<'_>, pat: &Pat<'_>, else_body: &Expr<'_>) {
+fn emit_manual_let_else(
+ cx: &LateContext<'_>,
+ span: Span,
+ expr: &Expr<'_>,
+ local: &Pat<'_>,
+ pat: &Pat<'_>,
+ else_body: &Expr<'_>,
+) {
span_lint_and_then(
cx,
MANUAL_LET_ELSE,
@@ -145,12 +146,11 @@ fn emit_manual_let_else(cx: &LateContext<'_>, span: Span, expr: &Expr<'_>, pat:
|diag| {
// This is far from perfect, for example there needs to be:
// * mut additions for the bindings
- // * renamings of the bindings
+ // * renamings of the bindings for `PatKind::Or`
// * unused binding collision detection with existing ones
// * putting patterns with at the top level | inside ()
// for this to be machine applicable.
let mut app = Applicability::HasPlaceholders;
- let (sn_pat, _) = snippet_with_context(cx, pat.span, span.ctxt(), "", &mut app);
let (sn_expr, _) = snippet_with_context(cx, expr.span, span.ctxt(), "", &mut app);
let (sn_else, _) = snippet_with_context(cx, else_body.span, span.ctxt(), "", &mut app);
@@ -159,10 +159,21 @@ fn emit_manual_let_else(cx: &LateContext<'_>, span: Span, expr: &Expr<'_>, pat:
} else {
format!("{{ {sn_else} }}")
};
- let sn_bl = if matches!(pat.kind, PatKind::Or(..)) {
- format!("({sn_pat})")
- } else {
- sn_pat.into_owned()
+ let sn_bl = match pat.kind {
+ PatKind::Or(..) => {
+ let (sn_pat, _) = snippet_with_context(cx, pat.span, span.ctxt(), "", &mut app);
+ format!("({sn_pat})")
+ },
+ // Replace the variable name iff `TupleStruct` has one argument like `Variant(v)`.
+ PatKind::TupleStruct(ref w, args, ..) if args.len() == 1 => {
+ let sn_wrapper = cx.sess().source_map().span_to_snippet(w.span()).unwrap_or_default();
+ let (sn_inner, _) = snippet_with_context(cx, local.span, span.ctxt(), "", &mut app);
+ format!("{sn_wrapper}({sn_inner})")
+ },
+ _ => {
+ let (sn_pat, _) = snippet_with_context(cx, pat.span, span.ctxt(), "", &mut app);
+ sn_pat.into_owned()
+ },
};
let sugg = format!("let {sn_bl} = {sn_expr} else {else_bl};");
diag.span_suggestion(span, "consider writing", sugg, app);
diff --git a/src/tools/clippy/clippy_lints/src/manual_retain.rs b/src/tools/clippy/clippy_lints/src/manual_retain.rs
index 72cdb9c17..5259066eb 100644
--- a/src/tools/clippy/clippy_lints/src/manual_retain.rs
+++ b/src/tools/clippy/clippy_lints/src/manual_retain.rs
@@ -46,7 +46,7 @@ declare_clippy_lint! {
#[clippy::version = "1.64.0"]
pub MANUAL_RETAIN,
perf,
- "`retain()` is simpler and the same functionalitys"
+ "`retain()` is simpler and the same functionalities"
}
pub struct ManualRetain {
diff --git a/src/tools/clippy/clippy_lints/src/manual_slice_size_calculation.rs b/src/tools/clippy/clippy_lints/src/manual_slice_size_calculation.rs
index 92ee79453..703a6b258 100644
--- a/src/tools/clippy/clippy_lints/src/manual_slice_size_calculation.rs
+++ b/src/tools/clippy/clippy_lints/src/manual_slice_size_calculation.rs
@@ -1,5 +1,7 @@
-use clippy_utils::diagnostics::span_lint_and_help;
-use clippy_utils::{expr_or_init, in_constant};
+use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::source::snippet_with_context;
+use clippy_utils::{expr_or_init, in_constant, std_or_core};
+use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
@@ -38,19 +40,27 @@ declare_lint_pass!(ManualSliceSizeCalculation => [MANUAL_SLICE_SIZE_CALCULATION]
impl<'tcx> LateLintPass<'tcx> for ManualSliceSizeCalculation {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
- // Does not apply inside const because size_of_value is not cost in stable.
+ // Does not apply inside const because size_of_val is not cost in stable.
if !in_constant(cx, expr.hir_id)
&& let ExprKind::Binary(ref op, left, right) = expr.kind
&& BinOpKind::Mul == op.node
- && let Some(_receiver) = simplify(cx, left, right)
+ && !expr.span.from_expansion()
+ && let Some(receiver) = simplify(cx, left, right)
{
- span_lint_and_help(
+ let ctxt = expr.span.ctxt();
+ let mut app = Applicability::MachineApplicable;
+ let val_name = snippet_with_context(cx, receiver.span, ctxt, "slice", &mut app).0;
+ let Some(sugg) = std_or_core(cx) else { return };
+
+ span_lint_and_sugg(
cx,
MANUAL_SLICE_SIZE_CALCULATION,
expr.span,
"manual slice size calculation",
- None,
- "consider using std::mem::size_of_value instead");
+ "try",
+ format!("{sugg}::mem::size_of_val({val_name})"),
+ app,
+ );
}
}
}
@@ -71,9 +81,9 @@ fn simplify_half<'tcx>(
expr1: &'tcx Expr<'tcx>,
expr2: &'tcx Expr<'tcx>,
) -> Option<&'tcx Expr<'tcx>> {
- if
+ if !expr1.span.from_expansion()
// expr1 is `[T1].len()`?
- let ExprKind::MethodCall(method_path, receiver, _, _) = expr1.kind
+ && let ExprKind::MethodCall(method_path, receiver, _, _) = expr1.kind
&& method_path.ident.name == sym::len
&& let receiver_ty = cx.typeck_results().expr_ty(receiver)
&& let ty::Slice(ty1) = receiver_ty.peel_refs().kind()
diff --git a/src/tools/clippy/clippy_lints/src/manual_strip.rs b/src/tools/clippy/clippy_lints/src/manual_strip.rs
index c795c1d9a..93d977a5c 100644
--- a/src/tools/clippy/clippy_lints/src/manual_strip.rs
+++ b/src/tools/clippy/clippy_lints/src/manual_strip.rs
@@ -144,7 +144,7 @@ fn len_arg<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx E
// Returns the length of the `expr` if it's a constant string or char.
fn constant_length(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<u128> {
- let (value, _) = constant(cx, cx.typeck_results(), expr)?;
+ let value = constant(cx, cx.typeck_results(), expr)?;
match value {
Constant::Str(value) => Some(value.len() as u128),
Constant::Char(value) => Some(value.len_utf8() as u128),
@@ -159,7 +159,7 @@ fn eq_pattern_length<'tcx>(cx: &LateContext<'tcx>, pattern: &Expr<'_>, expr: &'t
..
}) = expr.kind
{
- constant_length(cx, pattern).map_or(false, |length| length == n)
+ constant_length(cx, pattern).map_or(false, |length| length == *n)
} else {
len_arg(cx, expr).map_or(false, |arg| eq_expr_value(cx, pattern, arg))
}
diff --git a/src/tools/clippy/clippy_lints/src/matches/match_bool.rs b/src/tools/clippy/clippy_lints/src/matches/match_bool.rs
index df1e585f1..69105ff0d 100644
--- a/src/tools/clippy/clippy_lints/src/matches/match_bool.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/match_bool.rs
@@ -22,7 +22,7 @@ pub(crate) fn check(cx: &LateContext<'_>, scrutinee: &Expr<'_>, arms: &[Arm<'_>]
if arms.len() == 2 {
// no guards
let exprs = if let PatKind::Lit(arm_bool) = arms[0].pat.kind {
- if let ExprKind::Lit(ref lit) = arm_bool.kind {
+ if let ExprKind::Lit(lit) = arm_bool.kind {
match lit.node {
LitKind::Bool(true) => Some((arms[0].body, arms[1].body)),
LitKind::Bool(false) => Some((arms[1].body, arms[0].body)),
diff --git a/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs b/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs
index 107fad323..0064619ef 100644
--- a/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs
@@ -1,10 +1,12 @@
+use super::REDUNDANT_PATTERN_MATCHING;
use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::is_lint_allowed;
use clippy_utils::is_wild;
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::span_contains_comment;
use rustc_ast::{Attribute, LitKind};
use rustc_errors::Applicability;
-use rustc_hir::{Arm, BorrowKind, Expr, ExprKind, Guard, Pat};
+use rustc_hir::{Arm, BorrowKind, Expr, ExprKind, Guard, Pat, PatKind, QPath};
use rustc_lint::{LateContext, LintContext};
use rustc_middle::ty;
use rustc_span::source_map::Spanned;
@@ -99,6 +101,14 @@ where
}
}
+ for arm in iter_without_last.clone() {
+ if let Some(pat) = arm.1 {
+ if !is_lint_allowed(cx, REDUNDANT_PATTERN_MATCHING, pat.hir_id) && is_some(pat.kind) {
+ return false;
+ }
+ }
+ }
+
// The suggestion may be incorrect, because some arms can have `cfg` attributes
// evaluated into `false` and so such arms will be stripped before.
let mut applicability = Applicability::MaybeIncorrect;
@@ -162,7 +172,7 @@ fn find_bool_lit(ex: &ExprKind<'_>) -> Option<bool> {
node: LitKind::Bool(b), ..
}) = exp.kind
{
- Some(b)
+ Some(*b)
} else {
None
}
@@ -170,3 +180,13 @@ fn find_bool_lit(ex: &ExprKind<'_>) -> Option<bool> {
_ => None,
}
}
+
+fn is_some(path_kind: PatKind<'_>) -> bool {
+ match path_kind {
+ PatKind::TupleStruct(QPath::Resolved(_, path), [first, ..], _) if is_wild(first) => {
+ let name = path.segments[0].ident;
+ name.name == rustc_span::sym::Some
+ },
+ _ => false,
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs b/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs
index 158e6caa4..ae8262ace 100644
--- a/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs
@@ -282,7 +282,7 @@ impl<'a> NormalizedPat<'a> {
// TODO: Handle negative integers. They're currently treated as a wild match.
ExprKind::Lit(lit) => match lit.node {
LitKind::Str(sym, _) => Self::LitStr(sym),
- LitKind::ByteStr(ref bytes, _) => Self::LitBytes(bytes),
+ LitKind::ByteStr(ref bytes, _) | LitKind::CStr(ref bytes, _) => Self::LitBytes(bytes),
LitKind::Byte(val) => Self::LitInt(val.into()),
LitKind::Char(val) => Self::LitInt(val.into()),
LitKind::Int(val, _) => Self::LitInt(val),
diff --git a/src/tools/clippy/clippy_lints/src/matches/mod.rs b/src/tools/clippy/clippy_lints/src/matches/mod.rs
index 97ecca450..55ec9d447 100644
--- a/src/tools/clippy/clippy_lints/src/matches/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/mod.rs
@@ -25,9 +25,9 @@ mod wild_in_or_pats;
use clippy_utils::msrvs::{self, Msrv};
use clippy_utils::source::{snippet_opt, walk_span_to_context};
-use clippy_utils::{higher, in_constant, is_span_match};
+use clippy_utils::{higher, in_constant, is_span_match, tokenize_with_text};
use rustc_hir::{Arm, Expr, ExprKind, Local, MatchSource, Pat};
-use rustc_lexer::{tokenize, TokenKind};
+use rustc_lexer::TokenKind;
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -843,7 +843,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for usages of `Err(x)?`.
+ /// Checks for usage of `Err(x)?`.
///
/// ### Why is this bad?
/// The `?` operator is designed to allow calls that
@@ -878,7 +878,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for usages of `match` which could be implemented using `map`
+ /// Checks for usage of `match` which could be implemented using `map`
///
/// ### Why is this bad?
/// Using the `map` method is clearer and more concise.
@@ -902,7 +902,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for usages of `match` which could be implemented using `filter`
+ /// Checks for usage of `match` which could be implemented using `filter`
///
/// ### Why is this bad?
/// Using the `filter` method is clearer and more concise.
@@ -1147,12 +1147,7 @@ fn span_contains_cfg(cx: &LateContext<'_>, s: Span) -> bool {
// Assume true. This would require either an invalid span, or one which crosses file boundaries.
return true;
};
- let mut pos = 0usize;
- let mut iter = tokenize(&snip).map(|t| {
- let start = pos;
- pos += t.len as usize;
- (t.kind, start..pos)
- });
+ let mut iter = tokenize_with_text(&snip);
// Search for the token sequence [`#`, `[`, `cfg`]
while iter.any(|(t, _)| matches!(t, TokenKind::Pound)) {
@@ -1163,7 +1158,7 @@ fn span_contains_cfg(cx: &LateContext<'_>, s: Span) -> bool {
)
});
if matches!(iter.next(), Some((TokenKind::OpenBracket, _)))
- && matches!(iter.next(), Some((TokenKind::Ident, range)) if &snip[range.clone()] == "cfg")
+ && matches!(iter.next(), Some((TokenKind::Ident, "cfg")))
{
return true;
}
diff --git a/src/tools/clippy/clippy_lints/src/matches/overlapping_arms.rs b/src/tools/clippy/clippy_lints/src/matches/overlapping_arms.rs
index ae69ca8a3..abf2525a6 100644
--- a/src/tools/clippy/clippy_lints/src/matches/overlapping_arms.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/overlapping_arms.rs
@@ -34,7 +34,7 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
if let Arm { pat, guard: None, .. } = *arm {
if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind {
let lhs_const = match lhs {
- Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0,
+ Some(lhs) => constant(cx, cx.typeck_results(), lhs)?,
None => {
let min_val_const = ty.numeric_min_val(cx.tcx)?;
let min_constant = mir::ConstantKind::from_value(
@@ -45,7 +45,7 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
},
};
let rhs_const = match rhs {
- Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0,
+ Some(rhs) => constant(cx, cx.typeck_results(), rhs)?,
None => {
let max_val_const = ty.numeric_max_val(cx.tcx)?;
let max_constant = mir::ConstantKind::from_value(
diff --git a/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs b/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs
index 7b609ff3d..e81e09da4 100644
--- a/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs
@@ -63,8 +63,11 @@ fn find_sugg_for_if_let<'tcx>(
// Determine which function should be used, and the type contained by the corresponding
// variant.
let (good_method, inner_ty) = match check_pat.kind {
- PatKind::TupleStruct(ref qpath, [sub_pat], _) => {
- if let PatKind::Wild = sub_pat.kind {
+ PatKind::TupleStruct(ref qpath, args, rest) => {
+ let is_wildcard = matches!(args.first().map(|p| &p.kind), Some(PatKind::Wild));
+ let is_rest = matches!((args, rest.as_opt_usize()), ([], Some(_)));
+
+ if is_wildcard || is_rest {
let res = cx.typeck_results().qpath_res(qpath, check_pat.hir_id);
let Some(id) = res.opt_def_id().map(|ctor_id| cx.tcx.parent(ctor_id)) else { return };
let lang_items = cx.tcx.lang_items();
@@ -186,73 +189,7 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op
if arms.len() == 2 {
let node_pair = (&arms[0].pat.kind, &arms[1].pat.kind);
- let found_good_method = match node_pair {
- (
- PatKind::TupleStruct(ref path_left, patterns_left, _),
- PatKind::TupleStruct(ref path_right, patterns_right, _),
- ) if patterns_left.len() == 1 && patterns_right.len() == 1 => {
- if let (PatKind::Wild, PatKind::Wild) = (&patterns_left[0].kind, &patterns_right[0].kind) {
- find_good_method_for_match(
- cx,
- arms,
- path_left,
- path_right,
- Item::Lang(ResultOk),
- Item::Lang(ResultErr),
- "is_ok()",
- "is_err()",
- )
- .or_else(|| {
- find_good_method_for_match(
- cx,
- arms,
- path_left,
- path_right,
- Item::Diag(sym::IpAddr, sym!(V4)),
- Item::Diag(sym::IpAddr, sym!(V6)),
- "is_ipv4()",
- "is_ipv6()",
- )
- })
- } else {
- None
- }
- },
- (PatKind::TupleStruct(ref path_left, patterns, _), PatKind::Path(ref path_right))
- | (PatKind::Path(ref path_left), PatKind::TupleStruct(ref path_right, patterns, _))
- if patterns.len() == 1 =>
- {
- if let PatKind::Wild = patterns[0].kind {
- find_good_method_for_match(
- cx,
- arms,
- path_left,
- path_right,
- Item::Lang(OptionSome),
- Item::Lang(OptionNone),
- "is_some()",
- "is_none()",
- )
- .or_else(|| {
- find_good_method_for_match(
- cx,
- arms,
- path_left,
- path_right,
- Item::Lang(PollReady),
- Item::Lang(PollPending),
- "is_ready()",
- "is_pending()",
- )
- })
- } else {
- None
- }
- },
- _ => None,
- };
-
- if let Some(good_method) = found_good_method {
+ if let Some(good_method) = found_good_method(cx, arms, node_pair) {
let span = expr.span.to(op.span);
let result_expr = match &op.kind {
ExprKind::AddrOf(_, _, borrowed) => borrowed,
@@ -276,6 +213,127 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op
}
}
+fn found_good_method<'a>(
+ cx: &LateContext<'_>,
+ arms: &[Arm<'_>],
+ node: (&PatKind<'_>, &PatKind<'_>),
+) -> Option<&'a str> {
+ match node {
+ (
+ PatKind::TupleStruct(ref path_left, patterns_left, _),
+ PatKind::TupleStruct(ref path_right, patterns_right, _),
+ ) if patterns_left.len() == 1 && patterns_right.len() == 1 => {
+ if let (PatKind::Wild, PatKind::Wild) = (&patterns_left[0].kind, &patterns_right[0].kind) {
+ find_good_method_for_match(
+ cx,
+ arms,
+ path_left,
+ path_right,
+ Item::Lang(ResultOk),
+ Item::Lang(ResultErr),
+ "is_ok()",
+ "is_err()",
+ )
+ .or_else(|| {
+ find_good_method_for_match(
+ cx,
+ arms,
+ path_left,
+ path_right,
+ Item::Diag(sym::IpAddr, sym!(V4)),
+ Item::Diag(sym::IpAddr, sym!(V6)),
+ "is_ipv4()",
+ "is_ipv6()",
+ )
+ })
+ } else {
+ None
+ }
+ },
+ (PatKind::TupleStruct(ref path_left, patterns, _), PatKind::Path(ref path_right))
+ | (PatKind::Path(ref path_left), PatKind::TupleStruct(ref path_right, patterns, _))
+ if patterns.len() == 1 =>
+ {
+ if let PatKind::Wild = patterns[0].kind {
+ find_good_method_for_match(
+ cx,
+ arms,
+ path_left,
+ path_right,
+ Item::Lang(OptionSome),
+ Item::Lang(OptionNone),
+ "is_some()",
+ "is_none()",
+ )
+ .or_else(|| {
+ find_good_method_for_match(
+ cx,
+ arms,
+ path_left,
+ path_right,
+ Item::Lang(PollReady),
+ Item::Lang(PollPending),
+ "is_ready()",
+ "is_pending()",
+ )
+ })
+ } else {
+ None
+ }
+ },
+ (PatKind::TupleStruct(ref path_left, patterns, _), PatKind::Wild) if patterns.len() == 1 => {
+ if let PatKind::Wild = patterns[0].kind {
+ get_good_method(cx, arms, path_left)
+ } else {
+ None
+ }
+ },
+ (PatKind::Path(ref path_left), PatKind::Wild) => get_good_method(cx, arms, path_left),
+ _ => None,
+ }
+}
+
+fn get_ident(path: &QPath<'_>) -> Option<rustc_span::symbol::Ident> {
+ match path {
+ QPath::Resolved(_, path) => {
+ let name = path.segments[0].ident;
+ Some(name)
+ },
+ _ => None,
+ }
+}
+
+fn get_good_method<'a>(cx: &LateContext<'_>, arms: &[Arm<'_>], path_left: &QPath<'_>) -> Option<&'a str> {
+ if let Some(name) = get_ident(path_left) {
+ return match name.as_str() {
+ "Ok" => {
+ find_good_method_for_matches_macro(cx, arms, path_left, Item::Lang(ResultOk), "is_ok()", "is_err()")
+ },
+ "Err" => {
+ find_good_method_for_matches_macro(cx, arms, path_left, Item::Lang(ResultErr), "is_err()", "is_ok()")
+ },
+ "Some" => find_good_method_for_matches_macro(
+ cx,
+ arms,
+ path_left,
+ Item::Lang(OptionSome),
+ "is_some()",
+ "is_none()",
+ ),
+ "None" => find_good_method_for_matches_macro(
+ cx,
+ arms,
+ path_left,
+ Item::Lang(OptionNone),
+ "is_none()",
+ "is_some()",
+ ),
+ _ => None,
+ };
+ }
+ None
+}
+
#[derive(Clone, Copy)]
enum Item {
Lang(LangItem),
@@ -286,10 +344,11 @@ fn is_pat_variant(cx: &LateContext<'_>, pat: &Pat<'_>, path: &QPath<'_>, expecte
let Some(id) = cx.typeck_results().qpath_res(path, pat.hir_id).opt_def_id() else { return false };
match expected_item {
- Item::Lang(expected_lang_item) => {
- let expected_id = cx.tcx.lang_items().require(expected_lang_item).unwrap();
- cx.tcx.parent(id) == expected_id
- },
+ Item::Lang(expected_lang_item) => cx
+ .tcx
+ .lang_items()
+ .get(expected_lang_item)
+ .map_or(false, |expected_id| cx.tcx.parent(id) == expected_id),
Item::Diag(expected_ty, expected_variant) => {
let ty = cx.typeck_results().pat_ty(pat);
@@ -334,7 +393,33 @@ fn find_good_method_for_match<'a>(
};
match body_node_pair {
- (ExprKind::Lit(ref lit_left), ExprKind::Lit(ref lit_right)) => match (&lit_left.node, &lit_right.node) {
+ (ExprKind::Lit(lit_left), ExprKind::Lit(lit_right)) => match (&lit_left.node, &lit_right.node) {
+ (LitKind::Bool(true), LitKind::Bool(false)) => Some(should_be_left),
+ (LitKind::Bool(false), LitKind::Bool(true)) => Some(should_be_right),
+ _ => None,
+ },
+ _ => None,
+ }
+}
+
+fn find_good_method_for_matches_macro<'a>(
+ cx: &LateContext<'_>,
+ arms: &[Arm<'_>],
+ path_left: &QPath<'_>,
+ expected_item_left: Item,
+ should_be_left: &'a str,
+ should_be_right: &'a str,
+) -> Option<&'a str> {
+ let first_pat = arms[0].pat;
+
+ let body_node_pair = if is_pat_variant(cx, first_pat, path_left, expected_item_left) {
+ (&arms[0].body.kind, &arms[1].body.kind)
+ } else {
+ return None;
+ };
+
+ match body_node_pair {
+ (ExprKind::Lit(lit_left), ExprKind::Lit(lit_right)) => match (&lit_left.node, &lit_right.node) {
(LitKind::Bool(true), LitKind::Bool(false)) => Some(should_be_left),
(LitKind::Bool(false), LitKind::Bool(true)) => Some(should_be_right),
_ => None,
diff --git a/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs
index 04225beeb..794527539 100644
--- a/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs
@@ -342,6 +342,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> {
ExprKind::DropTemps(_) |
ExprKind::Err(_) |
ExprKind::InlineAsm(_) |
+ ExprKind::OffsetOf(_, _) |
ExprKind::Let(_) |
ExprKind::Lit(_) |
ExprKind::Loop(_, _, _, _) |
diff --git a/src/tools/clippy/clippy_lints/src/methods/chars_cmp_with_unwrap.rs b/src/tools/clippy/clippy_lints/src/methods/chars_cmp_with_unwrap.rs
index 27a05337a..8984b2cf8 100644
--- a/src/tools/clippy/clippy_lints/src/methods/chars_cmp_with_unwrap.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/chars_cmp_with_unwrap.rs
@@ -18,7 +18,7 @@ pub(super) fn check(
) -> bool {
if_chain! {
if let Some(args) = method_chain_args(info.chain, chain_methods);
- if let hir::ExprKind::Lit(ref lit) = info.other.kind;
+ if let hir::ExprKind::Lit(lit) = info.other.kind;
if let ast::LitKind::Char(c) = lit.node;
then {
let mut applicability = Applicability::MachineApplicable;
diff --git a/src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs b/src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs
index 3795c0ec2..65fd50dff 100644
--- a/src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs
@@ -1,7 +1,6 @@
-use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
+use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::get_parent_node;
use clippy_utils::source::snippet_with_context;
-use clippy_utils::sugg;
use clippy_utils::ty::is_copy;
use rustc_errors::Applicability;
use rustc_hir::{BindingAnnotation, ByRef, Expr, ExprKind, MatchSource, Node, PatKind, QPath};
@@ -9,7 +8,6 @@ use rustc_lint::LateContext;
use rustc_middle::ty::{self, adjustment::Adjust, print::with_forced_trimmed_paths};
use rustc_span::symbol::{sym, Symbol};
-use super::CLONE_DOUBLE_REF;
use super::CLONE_ON_COPY;
/// Checks for the `CLONE_ON_COPY` lint.
@@ -42,41 +40,7 @@ pub(super) fn check(
let ty = cx.typeck_results().expr_ty(expr);
if let ty::Ref(_, inner, _) = arg_ty.kind() {
- if let ty::Ref(_, innermost, _) = inner.kind() {
- span_lint_and_then(
- cx,
- CLONE_DOUBLE_REF,
- expr.span,
- &with_forced_trimmed_paths!(format!(
- "using `clone` on a double-reference; \
- this will copy the reference of type `{ty}` instead of cloning the inner type"
- )),
- |diag| {
- if let Some(snip) = sugg::Sugg::hir_opt(cx, arg) {
- let mut ty = innermost;
- let mut n = 0;
- while let ty::Ref(_, inner, _) = ty.kind() {
- ty = inner;
- n += 1;
- }
- let refs = "&".repeat(n + 1);
- let derefs = "*".repeat(n);
- let explicit = with_forced_trimmed_paths!(format!("<{refs}{ty}>::clone({snip})"));
- diag.span_suggestion(
- expr.span,
- "try dereferencing it",
- with_forced_trimmed_paths!(format!("{refs}({derefs}{}).clone()", snip.deref())),
- Applicability::MaybeIncorrect,
- );
- diag.span_suggestion(
- expr.span,
- "or try being explicit if you are sure, that you want to clone a reference",
- explicit,
- Applicability::MaybeIncorrect,
- );
- }
- },
- );
+ if let ty::Ref(..) = inner.kind() {
return; // don't report clone_on_copy
}
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_next_slice.rs b/src/tools/clippy/clippy_lints/src/methods/iter_next_slice.rs
index 83c1bf203..e2029da80 100644
--- a/src/tools/clippy/clippy_lints/src/methods/iter_next_slice.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/iter_next_slice.rs
@@ -30,7 +30,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, cal
if let hir::ExprKind::Index(caller_var, index_expr) = &caller_expr.kind;
if let Some(higher::Range { start: Some(start_expr), end: None, limits: ast::RangeLimits::HalfOpen })
= higher::Range::hir(index_expr);
- if let hir::ExprKind::Lit(ref start_lit) = &start_expr.kind;
+ if let hir::ExprKind::Lit(start_lit) = &start_expr.kind;
if let ast::LitKind::Int(start_idx, _) = start_lit.node;
then {
let mut applicability = Applicability::MachineApplicable;
diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_nth_zero.rs b/src/tools/clippy/clippy_lints/src/methods/iter_nth_zero.rs
index c830958d5..d1609eebf 100644
--- a/src/tools/clippy/clippy_lints/src/methods/iter_nth_zero.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/iter_nth_zero.rs
@@ -13,7 +13,7 @@ use super::ITER_NTH_ZERO;
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) {
if_chain! {
if is_trait_method(cx, expr, sym::Iterator);
- if let Some((Constant::Int(0), _)) = constant(cx, cx.typeck_results(), arg);
+ if let Some(Constant::Int(0)) = constant(cx, cx.typeck_results(), arg);
then {
let mut applicability = Applicability::MachineApplicable;
span_lint_and_sugg(
diff --git a/src/tools/clippy/clippy_lints/src/methods/iterator_step_by_zero.rs b/src/tools/clippy/clippy_lints/src/methods/iterator_step_by_zero.rs
index 64c09214a..b631cd00c 100644
--- a/src/tools/clippy/clippy_lints/src/methods/iterator_step_by_zero.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/iterator_step_by_zero.rs
@@ -9,7 +9,7 @@ use super::ITERATOR_STEP_BY_ZERO;
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, arg: &'tcx hir::Expr<'_>) {
if is_trait_method(cx, expr, sym::Iterator) {
- if let Some((Constant::Int(0), _)) = constant(cx, cx.typeck_results(), arg) {
+ if let Some(Constant::Int(0)) = constant(cx, cx.typeck_results(), arg) {
span_lint(
cx,
ITERATOR_STEP_BY_ZERO,
diff --git a/src/tools/clippy/clippy_lints/src/methods/manual_next_back.rs b/src/tools/clippy/clippy_lints/src/methods/manual_next_back.rs
new file mode 100644
index 000000000..5f3fec538
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/methods/manual_next_back.rs
@@ -0,0 +1,38 @@
+use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::is_trait_method;
+use clippy_utils::ty::implements_trait;
+use rustc_errors::Applicability;
+use rustc_hir::Expr;
+use rustc_lint::LateContext;
+use rustc_span::symbol::sym;
+
+pub(super) fn check<'tcx>(
+ cx: &LateContext<'tcx>,
+ expr: &'tcx Expr<'_>,
+ rev_call: &'tcx Expr<'_>,
+ rev_recv: &'tcx Expr<'_>,
+) {
+ let rev_recv_ty = cx.typeck_results().expr_ty(rev_recv);
+
+ // check that the receiver of `rev` implements `DoubleEndedIterator` and
+ // that `rev` and `next` come from `Iterator`
+ if cx
+ .tcx
+ .get_diagnostic_item(sym::DoubleEndedIterator)
+ .map_or(false, |double_ended_iterator| {
+ implements_trait(cx, rev_recv_ty, double_ended_iterator, &[])
+ })
+ && is_trait_method(cx, rev_call, sym::Iterator)
+ && is_trait_method(cx, expr, sym::Iterator)
+ {
+ span_lint_and_sugg(
+ cx,
+ super::MANUAL_NEXT_BACK,
+ expr.span.with_lo(rev_recv.span.hi()),
+ "manual backwards iteration",
+ "use",
+ String::from(".next_back()"),
+ Applicability::MachineApplicable,
+ );
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs
index 64bf55ba2..9a594d964 100644
--- a/src/tools/clippy/clippy_lints/src/methods/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs
@@ -45,6 +45,7 @@ mod iter_overeager_cloned;
mod iter_skip_next;
mod iter_with_drain;
mod iterator_step_by_zero;
+mod manual_next_back;
mod manual_ok_or;
mod manual_saturating_arithmetic;
mod manual_str_repeat;
@@ -121,7 +122,7 @@ use rustc_span::{sym, Span};
declare_clippy_lint! {
/// ### What it does
- /// Checks for usages of `cloned()` on an `Iterator` or `Option` where
+ /// Checks for usage of `cloned()` on an `Iterator` or `Option` where
/// `copied()` could be used instead.
///
/// ### Why is this bad?
@@ -201,7 +202,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for usages of `Iterator::flat_map()` where `filter_map()` could be
+ /// Checks for usage of `Iterator::flat_map()` where `filter_map()` could be
/// used instead.
///
/// ### Why is this bad?
@@ -441,7 +442,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for usages of `_.unwrap_or_else(Default::default)` on `Option` and
+ /// Checks for usage of `_.unwrap_or_else(Default::default)` on `Option` and
/// `Result` values.
///
/// ### Why is this bad?
@@ -986,29 +987,6 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for usage of `.clone()` on an `&&T`.
- ///
- /// ### Why is this bad?
- /// Cloning an `&&T` copies the inner `&T`, instead of
- /// cloning the underlying `T`.
- ///
- /// ### Example
- /// ```rust
- /// fn main() {
- /// let x = vec![1];
- /// let y = &&x;
- /// let z = y.clone();
- /// println!("{:p} {:p}", *y, z); // prints out the same pointer
- /// }
- /// ```
- #[clippy::version = "pre 1.29.0"]
- pub CLONE_DOUBLE_REF,
- correctness,
- "using `clone` on `&&T`"
-}
-
-declare_clippy_lint! {
- /// ### What it does
/// Checks for usage of `.to_string()` on an `&&T` where
/// `T` implements `ToString` directly (like `&&str` or `&&String`).
///
@@ -1194,7 +1172,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of `.iter().nth()` (and the related
+ /// Checks for usage of `.iter().nth()` (and the related
/// `.iter_mut().nth()`) on standard library types with *O*(1) element access.
///
/// ### Why is this bad?
@@ -1221,7 +1199,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of `.skip(x).next()` on iterators.
+ /// Checks for usage of `.skip(x).next()` on iterators.
///
/// ### Why is this bad?
/// `.nth(x)` is cleaner
@@ -1246,7 +1224,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of `.drain(..)` on `Vec` and `VecDeque` for iteration.
+ /// Checks for usage of `.drain(..)` on `Vec` and `VecDeque` for iteration.
///
/// ### Why is this bad?
/// `.into_iter()` is simpler with better performance.
@@ -1271,7 +1249,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for using `x.get(x.len() - 1)` instead of
+ /// Checks for usage of `x.get(x.len() - 1)` instead of
/// `x.last()`.
///
/// ### Why is this bad?
@@ -1304,7 +1282,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of `.get().unwrap()` (or
+ /// Checks for usage of `.get().unwrap()` (or
/// `.get_mut().unwrap`) on a standard library type which implements `Index`
///
/// ### Why is this bad?
@@ -1475,7 +1453,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for using `fold` when a more succinct alternative exists.
+ /// Checks for usage of `fold` when a more succinct alternative exists.
/// Specifically, this checks for `fold`s which could be replaced by `any`, `all`,
/// `sum` or `product`.
///
@@ -2161,7 +2139,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for usages of `str::splitn(2, _)`
+ /// Checks for usage of `str::splitn(2, _)`
///
/// ### Why is this bad?
/// `split_once` is both clearer in intent and slightly more efficient.
@@ -2197,7 +2175,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for usages of `str::splitn` (or `str::rsplitn`) where using `str::split` would be the same.
+ /// Checks for usage of `str::splitn` (or `str::rsplitn`) where using `str::split` would be the same.
/// ### Why is this bad?
/// The function `split` is simpler and there is no performance difference in these cases, considering
/// that both functions return a lazy iterator.
@@ -2251,7 +2229,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of `.collect::<Vec<String>>().join("")` on iterators.
+ /// Checks for usage of `.collect::<Vec<String>>().join("")` on iterators.
///
/// ### Why is this bad?
/// `.collect::<String>()` is more concise and might be more performant
@@ -2377,7 +2355,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for usages of `.then_some(..).unwrap_or(..)`
+ /// Checks for usage of `.then_some(..).unwrap_or(..)`
///
/// ### Why is this bad?
/// This can be written more clearly with `if .. else ..`
@@ -2553,7 +2531,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for using `x.get(0)` instead of
+ /// Checks for usage of `x.get(0)` instead of
/// `x.first()`.
///
/// ### Why is this bad?
@@ -2957,7 +2935,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Detects uses of `Vec::sort_by` passing in a closure
+ /// Checks for usage of `Vec::sort_by` passing in a closure
/// which compares the two arguments, either directly or indirectly.
///
/// ### Why is this bad?
@@ -3013,7 +2991,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of File::read_to_end and File::read_to_string.
+ /// Checks for usage of File::read_to_end and File::read_to_string.
///
/// ### Why is this bad?
/// `fs::{read, read_to_string}` provide the same functionality when `buf` is empty with fewer imports and no intermediate values.
@@ -3155,8 +3133,11 @@ declare_clippy_lint! {
/// ### Example
/// ```rust
/// # let iterator = vec![1].into_iter();
- /// let len = iterator.clone().collect::<Vec<_>>().len();
- /// // should be
+ /// let len = iterator.collect::<Vec<_>>().len();
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// # let iterator = vec![1].into_iter();
/// let len = iterator.count();
/// ```
#[clippy::version = "1.30.0"]
@@ -3185,7 +3166,7 @@ declare_clippy_lint! {
/// ```rust
/// std::process::Command::new("echo").args(["-n", "hello"]).spawn().unwrap();
/// ```
- #[clippy::version = "1.67.0"]
+ #[clippy::version = "1.69.0"]
pub SUSPICIOUS_COMMAND_ARG_SPACE,
suspicious,
"single command line argument that looks like it should be multiple arguments"
@@ -3216,6 +3197,29 @@ declare_clippy_lint! {
"calling `drain` in order to `clear` a container"
}
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for `.rev().next()` on a `DoubleEndedIterator`
+ ///
+ /// ### Why is this bad?
+ /// `.next_back()` is cleaner.
+ ///
+ /// ### Example
+ /// ```rust
+ /// # let foo = [0; 10];
+ /// foo.iter().rev().next();
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// # let foo = [0; 10];
+ /// foo.iter().next_back();
+ /// ```
+ #[clippy::version = "1.71.0"]
+ pub MANUAL_NEXT_BACK,
+ style,
+ "manual reverse iteration of `DoubleEndedIterator`"
+}
+
pub struct Methods {
avoid_breaking_exported_api: bool,
msrv: Msrv,
@@ -3258,7 +3262,6 @@ impl_lint_pass!(Methods => [
CHARS_LAST_CMP,
CLONE_ON_COPY,
CLONE_ON_REF_PTR,
- CLONE_DOUBLE_REF,
COLLAPSIBLE_STR_REPLACE,
ITER_OVEREAGER_CLONED,
CLONED_INSTEAD_OF_COPIED,
@@ -3345,6 +3348,7 @@ impl_lint_pass!(Methods => [
NEEDLESS_COLLECT,
SUSPICIOUS_COMMAND_ARG_SPACE,
CLEAR_WITH_DRAIN,
+ MANUAL_NEXT_BACK,
]);
/// Extracts a method call name, args, and `Span` of the method name.
@@ -3500,8 +3504,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
let first_arg_span = first_arg_ty.span;
let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty);
let self_ty = TraitRef::identity(cx.tcx, item.owner_id.to_def_id())
- .self_ty()
- .skip_binder();
+ .self_ty();
wrong_self_convention::check(
cx,
item.ident.name.as_str(),
@@ -3519,8 +3522,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if let TraitItemKind::Fn(_, _) = item.kind;
let ret_ty = return_ty(cx, item.owner_id);
let self_ty = TraitRef::identity(cx.tcx, item.owner_id.to_def_id())
- .self_ty()
- .skip_binder();
+ .self_ty();
if !ret_ty.contains(self_ty);
then {
@@ -3703,6 +3705,7 @@ impl Methods {
("iter", []) => iter_next_slice::check(cx, expr, recv2),
("skip", [arg]) => iter_skip_next::check(cx, expr, recv2, arg),
("skip_while", [_]) => skip_while_next::check(cx, expr),
+ ("rev", [])=> manual_next_back::check(cx, expr, recv, recv2),
_ => {},
}
}
@@ -3767,13 +3770,13 @@ impl Methods {
unnecessary_sort_by::check(cx, expr, recv, arg, true);
},
("splitn" | "rsplitn", [count_arg, pat_arg]) => {
- if let Some((Constant::Int(count), _)) = constant(cx, cx.typeck_results(), count_arg) {
+ if let Some(Constant::Int(count)) = constant(cx, cx.typeck_results(), count_arg) {
suspicious_splitn::check(cx, name, expr, recv, count);
str_splitn::check(cx, name, expr, recv, pat_arg, count, &self.msrv);
}
},
("splitn_mut" | "rsplitn_mut", [count_arg, _]) => {
- if let Some((Constant::Int(count), _)) = constant(cx, cx.typeck_results(), count_arg) {
+ if let Some(Constant::Int(count)) = constant(cx, cx.typeck_results(), count_arg) {
suspicious_splitn::check(cx, name, expr, recv, count);
}
},
diff --git a/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs b/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs
index 0b0c6adc5..6841aaf62 100644
--- a/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs
@@ -1,6 +1,5 @@
use super::NEEDLESS_COLLECT;
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
-use clippy_utils::higher;
use clippy_utils::source::{snippet, snippet_with_applicability};
use clippy_utils::sugg::Sugg;
use clippy_utils::ty::{is_type_diagnostic_item, make_normalized_projection, make_projection};
@@ -8,6 +7,7 @@ use clippy_utils::{
can_move_expr_to_closure, get_enclosing_block, get_parent_node, is_trait_method, path_to_local, path_to_local_id,
CaptureKind,
};
+use clippy_utils::{fn_def_id, higher};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{Applicability, MultiSpan};
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
@@ -16,7 +16,7 @@ use rustc_hir::{
};
use rustc_lint::LateContext;
use rustc_middle::hir::nested_filter;
-use rustc_middle::ty::{self, AssocKind, EarlyBinder, GenericArg, GenericArgKind, Ty};
+use rustc_middle::ty::{self, AssocKind, Clause, EarlyBinder, GenericArg, GenericArgKind, PredicateKind, Ty};
use rustc_span::symbol::Ident;
use rustc_span::{sym, Span, Symbol};
@@ -32,6 +32,8 @@ pub(super) fn check<'tcx>(
if let Some(parent) = get_parent_node(cx.tcx, collect_expr.hir_id) {
match parent {
Node::Expr(parent) => {
+ check_collect_into_intoiterator(cx, parent, collect_expr, call_span, iter_expr);
+
if let ExprKind::MethodCall(name, _, args @ ([] | [_]), _) = parent.kind {
let mut app = Applicability::MachineApplicable;
let name = name.ident.as_str();
@@ -134,6 +136,68 @@ pub(super) fn check<'tcx>(
}
}
+/// checks for for collecting into a (generic) method or function argument
+/// taking an `IntoIterator`
+fn check_collect_into_intoiterator<'tcx>(
+ cx: &LateContext<'tcx>,
+ parent: &'tcx Expr<'tcx>,
+ collect_expr: &'tcx Expr<'tcx>,
+ call_span: Span,
+ iter_expr: &'tcx Expr<'tcx>,
+) {
+ if let Some(id) = fn_def_id(cx, parent) {
+ let args = match parent.kind {
+ ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args, _) => args,
+ _ => &[],
+ };
+ // find the argument index of the `collect_expr` in the
+ // function / method call
+ if let Some(arg_idx) = args.iter().position(|e| e.hir_id == collect_expr.hir_id).map(|i| {
+ if matches!(parent.kind, ExprKind::MethodCall(_, _, _, _)) {
+ i + 1
+ } else {
+ i
+ }
+ }) {
+ // extract the input types of the function/method call
+ // that contains `collect_expr`
+ let inputs = cx
+ .tcx
+ .liberate_late_bound_regions(id, cx.tcx.fn_sig(id).subst_identity())
+ .inputs();
+
+ // map IntoIterator generic bounds to their signature
+ // types and check whether the argument type is an
+ // `IntoIterator`
+ if cx
+ .tcx
+ .param_env(id)
+ .caller_bounds()
+ .into_iter()
+ .filter_map(|p| {
+ if let PredicateKind::Clause(Clause::Trait(t)) = p.kind().skip_binder()
+ && cx.tcx.is_diagnostic_item(sym::IntoIterator,t.trait_ref.def_id) {
+ Some(t.self_ty())
+ } else {
+ None
+ }
+ })
+ .any(|ty| ty == inputs[arg_idx])
+ {
+ span_lint_and_sugg(
+ cx,
+ NEEDLESS_COLLECT,
+ call_span.with_lo(iter_expr.span.hi()),
+ NEEDLESS_COLLECT_MSG,
+ "remove this call",
+ String::new(),
+ Applicability::MachineApplicable,
+ );
+ }
+ }
+ }
+}
+
/// Checks if the given method call matches the expected signature of `([&[mut]] self) -> bool`
fn is_is_empty_sig(cx: &LateContext<'_>, call_id: HirId) -> bool {
cx.typeck_results().type_dependent_def_id(call_id).map_or(false, |id| {
diff --git a/src/tools/clippy/clippy_lints/src/methods/obfuscated_if_else.rs b/src/tools/clippy/clippy_lints/src/methods/obfuscated_if_else.rs
index 4d7427b26..eada530d6 100644
--- a/src/tools/clippy/clippy_lints/src/methods/obfuscated_if_else.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/obfuscated_if_else.rs
@@ -1,5 +1,3 @@
-// run-rustfix
-
use super::OBFUSCATED_IF_ELSE;
use clippy_utils::{diagnostics::span_lint_and_sugg, source::snippet_with_applicability};
use rustc_errors::Applicability;
diff --git a/src/tools/clippy/clippy_lints/src/methods/open_options.rs b/src/tools/clippy/clippy_lints/src/methods/open_options.rs
index c6a27cdd6..bd625a691 100644
--- a/src/tools/clippy/clippy_lints/src/methods/open_options.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/open_options.rs
@@ -42,13 +42,13 @@ fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec
// Only proceed if this is a call on some object of type std::fs::OpenOptions
if match_type(cx, obj_ty, &paths::OPEN_OPTIONS) && !arguments.is_empty() {
let argument_option = match arguments[0].kind {
- ExprKind::Lit(ref span) => {
+ ExprKind::Lit(span) => {
if let Spanned {
node: LitKind::Bool(lit),
..
- } = *span
+ } = span
{
- if lit { Argument::True } else { Argument::False }
+ if *lit { Argument::True } else { Argument::False }
} else {
// The function is called with a literal which is not a boolean literal.
// This is theoretically possible, but not very likely.
diff --git a/src/tools/clippy/clippy_lints/src/methods/path_buf_push_overwrite.rs b/src/tools/clippy/clippy_lints/src/methods/path_buf_push_overwrite.rs
index e3f2de3cd..0284d9dea 100644
--- a/src/tools/clippy/clippy_lints/src/methods/path_buf_push_overwrite.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/path_buf_push_overwrite.rs
@@ -15,7 +15,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arg: &'t
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
if let Some(impl_id) = cx.tcx.impl_of_method(method_id);
if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id).subst_identity(), sym::PathBuf);
- if let ExprKind::Lit(ref lit) = arg.kind;
+ if let ExprKind::Lit(lit) = arg.kind;
if let LitKind::Str(ref path_lit, _) = lit.node;
if let pushed_path = Path::new(path_lit.as_str());
if let Some(pushed_path_lit) = pushed_path.to_str();
diff --git a/src/tools/clippy/clippy_lints/src/methods/repeat_once.rs b/src/tools/clippy/clippy_lints/src/methods/repeat_once.rs
index a345ec813..bb4cdd2a6 100644
--- a/src/tools/clippy/clippy_lints/src/methods/repeat_once.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/repeat_once.rs
@@ -1,4 +1,4 @@
-use clippy_utils::consts::{constant_context, Constant};
+use clippy_utils::consts::{constant, Constant};
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet;
use clippy_utils::ty::is_type_lang_item;
@@ -14,7 +14,7 @@ pub(super) fn check<'tcx>(
recv: &'tcx Expr<'_>,
repeat_arg: &'tcx Expr<'_>,
) {
- if constant_context(cx, cx.typeck_results()).expr(repeat_arg) == Some(Constant::Int(1)) {
+ if constant(cx, cx.typeck_results(), repeat_arg) == Some(Constant::Int(1)) {
let ty = cx.typeck_results().expr_ty(recv).peel_refs();
if ty.is_str() {
span_lint_and_sugg(
diff --git a/src/tools/clippy/clippy_lints/src/methods/seek_from_current.rs b/src/tools/clippy/clippy_lints/src/methods/seek_from_current.rs
index 361a3082f..c028e9543 100644
--- a/src/tools/clippy/clippy_lints/src/methods/seek_from_current.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/seek_from_current.rs
@@ -38,7 +38,7 @@ fn arg_is_seek_from_current<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>)
match_def_path(cx, def_id, &paths::STD_IO_SEEK_FROM_CURRENT) {
// check if argument of `SeekFrom::Current` is `0`
if args.len() == 1 &&
- let ExprKind::Lit(ref lit) = args[0].kind &&
+ let ExprKind::Lit(lit) = args[0].kind &&
let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node {
return true
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/seek_to_start_instead_of_rewind.rs b/src/tools/clippy/clippy_lints/src/methods/seek_to_start_instead_of_rewind.rs
index 660b7049c..787e9e0eb 100644
--- a/src/tools/clippy/clippy_lints/src/methods/seek_to_start_instead_of_rewind.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/seek_to_start_instead_of_rewind.rs
@@ -30,7 +30,7 @@ pub(super) fn check<'tcx>(
let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id() &&
match_def_path(cx, def_id, &paths::STD_IO_SEEKFROM_START) &&
args1.len() == 1 &&
- let ExprKind::Lit(ref lit) = args1[0].kind &&
+ let ExprKind::Lit(lit) = args1[0].kind &&
let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node
{
let method_call_span = expr.span.with_lo(name_span.lo());
diff --git a/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs b/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs
index d00708e82..5ea12c441 100644
--- a/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs
@@ -175,13 +175,13 @@ fn check_manual_split_once_indirect(
let remove_msg = format!("remove the `{iter_ident}` usages");
diag.span_suggestion(
first.span,
- &remove_msg,
+ remove_msg.clone(),
"",
app,
);
diag.span_suggestion(
second.span,
- &remove_msg,
+ remove_msg,
"",
app,
);
@@ -316,7 +316,7 @@ fn parse_iter_usage<'tcx>(
};
},
("nth" | "skip", [idx_expr]) if cx.tcx.trait_of_item(did) == Some(iter_id) => {
- if let Some((Constant::Int(idx), _)) = constant(cx, cx.typeck_results(), idx_expr) {
+ if let Some(Constant::Int(idx)) = constant(cx, cx.typeck_results(), idx_expr) {
let span = if name.ident.as_str() == "nth" {
e.span
} else {
diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_fold.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_fold.rs
index aa87dead3..5a3d12fd7 100644
--- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_fold.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_fold.rs
@@ -78,7 +78,7 @@ pub(super) fn check(
}
// Check if the first argument to .fold is a suitable literal
- if let hir::ExprKind::Lit(ref lit) = init.kind {
+ if let hir::ExprKind::Lit(lit) = init.kind {
match lit.node {
ast::LitKind::Bool(false) => check_fold_with_op(cx, expr, acc, fold_span, hir::BinOpKind::Or, "any", true),
ast::LitKind::Bool(true) => check_fold_with_op(cx, expr, acc, fold_span, hir::BinOpKind::And, "all", true),
diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs
index 4c4c003ca..67b7d3691 100644
--- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs
@@ -385,6 +385,9 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
Node::Expr(parent_expr) => {
if let Some((callee_def_id, call_substs, recv, call_args)) = get_callee_substs_and_args(cx, parent_expr)
{
+ // FIXME: the `subst_identity()` below seems incorrect, since we eventually
+ // call `tcx.try_subst_and_normalize_erasing_regions` further down
+ // (i.e., we are explicitly not in the identity context).
let fn_sig = cx.tcx.fn_sig(callee_def_id).subst_identity().skip_binder();
if let Some(arg_index) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == expr.hir_id)
&& let Some(param_ty) = fn_sig.inputs().get(arg_index)
@@ -435,7 +438,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
let output_ty = fn_sig.output();
if output_ty.contains(*param_ty) {
if let Ok(new_ty) = cx.tcx.try_subst_and_normalize_erasing_regions(
- new_subst, cx.param_env, output_ty) {
+ new_subst, cx.param_env, EarlyBinder(output_ty)) {
expr = parent_expr;
ty = new_ty;
continue;
diff --git a/src/tools/clippy/clippy_lints/src/misc.rs b/src/tools/clippy/clippy_lints/src/misc.rs
index 3752b9a94..303f01256 100644
--- a/src/tools/clippy/clippy_lints/src/misc.rs
+++ b/src/tools/clippy/clippy_lints/src/misc.rs
@@ -16,9 +16,12 @@ use rustc_span::source_map::{ExpnKind, Span};
use clippy_utils::sugg::Sugg;
use clippy_utils::{
- get_parent_expr, in_constant, is_integer_literal, is_no_std_crate, iter_input_pats, last_path_segment, SpanlessEq,
+ get_parent_expr, in_constant, is_integer_literal, is_lint_allowed, is_no_std_crate, iter_input_pats,
+ last_path_segment, SpanlessEq,
};
+use crate::ref_patterns::REF_PATTERNS;
+
declare_clippy_lint! {
/// ### What it does
/// Checks for function arguments and let bindings denoted as
@@ -162,6 +165,10 @@ impl<'tcx> LateLintPass<'tcx> for LintPass {
return;
}
for arg in iter_input_pats(decl, body) {
+ // Do not emit if clippy::ref_patterns is not allowed to avoid having two lints for the same issue.
+ if !is_lint_allowed(cx, REF_PATTERNS, arg.pat.hir_id) {
+ return;
+ }
if let PatKind::Binding(BindingAnnotation(ByRef::Yes, _), ..) = arg.pat.kind {
span_lint(
cx,
@@ -180,6 +187,8 @@ impl<'tcx> LateLintPass<'tcx> for LintPass {
if let StmtKind::Local(local) = stmt.kind;
if let PatKind::Binding(BindingAnnotation(ByRef::Yes, mutabl), .., name, None) = local.pat.kind;
if let Some(init) = local.init;
+ // Do not emit if clippy::ref_patterns is not allowed to avoid having two lints for the same issue.
+ if is_lint_allowed(cx, REF_PATTERNS, local.pat.hir_id);
then {
let ctxt = local.span.ctxt();
let mut app = Applicability::MachineApplicable;
diff --git a/src/tools/clippy/clippy_lints/src/missing_trait_methods.rs b/src/tools/clippy/clippy_lints/src/missing_trait_methods.rs
index e99081ad0..1adecd2ca 100644
--- a/src/tools/clippy/clippy_lints/src/missing_trait_methods.rs
+++ b/src/tools/clippy/clippy_lints/src/missing_trait_methods.rs
@@ -12,7 +12,7 @@ declare_clippy_lint! {
/// Checks if a provided method is used implicitly by a trait
/// implementation. A usage example would be a wrapper where every method
/// should perform some operation before delegating to the inner type's
- /// implemenation.
+ /// implementation.
///
/// This lint should typically be enabled on a specific trait `impl` item
/// rather than globally.
diff --git a/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs b/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs
index 5418616de..2abdfacd2 100644
--- a/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs
+++ b/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs
@@ -59,7 +59,7 @@ declare_clippy_lint! {
/// unsafe { char::from_u32_unchecked(int_value) }
/// }
/// ```
- #[clippy::version = "1.68.0"]
+ #[clippy::version = "1.69.0"]
pub MULTIPLE_UNSAFE_OPS_PER_BLOCK,
restriction,
"more than one unsafe operation per `unsafe` block"
diff --git a/src/tools/clippy/clippy_lints/src/mutex_atomic.rs b/src/tools/clippy/clippy_lints/src/mutex_atomic.rs
index dc866ab63..99394b9e5 100644
--- a/src/tools/clippy/clippy_lints/src/mutex_atomic.rs
+++ b/src/tools/clippy/clippy_lints/src/mutex_atomic.rs
@@ -1,4 +1,4 @@
-//! Checks for uses of mutex where an atomic value could be used
+//! Checks for usage of mutex where an atomic value could be used
//!
//! This lint is **allow** by default
@@ -12,7 +12,7 @@ use rustc_span::sym;
declare_clippy_lint! {
/// ### What it does
- /// Checks for usages of `Mutex<X>` where an atomic will do.
+ /// Checks for usage of `Mutex<X>` where an atomic will do.
///
/// ### Why is this bad?
/// Using a mutex just to make access to a plain bool or
@@ -49,7 +49,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for usages of `Mutex<X>` where `X` is an integral
+ /// Checks for usage of `Mutex<X>` where `X` is an integral
/// type.
///
/// ### Why is this bad?
diff --git a/src/tools/clippy/clippy_lints/src/needless_bool.rs b/src/tools/clippy/clippy_lints/src/needless_bool.rs
index c87059bf6..62af42a39 100644
--- a/src/tools/clippy/clippy_lints/src/needless_bool.rs
+++ b/src/tools/clippy/clippy_lints/src/needless_bool.rs
@@ -3,10 +3,12 @@
//! This lint is **warn** by default
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
-use clippy_utils::higher;
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::sugg::Sugg;
-use clippy_utils::{get_parent_node, is_else_clause, is_expn_of, peel_blocks, peel_blocks_with_stmt};
+use clippy_utils::{
+ get_parent_node, is_else_clause, is_expn_of, peel_blocks, peel_blocks_with_stmt, span_extract_comment,
+};
+use clippy_utils::{higher, SpanlessEq};
use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, Node, UnOp};
@@ -77,7 +79,39 @@ declare_clippy_lint! {
"comparing a variable to a boolean, e.g., `if x == true` or `if x != true`"
}
-declare_lint_pass!(NeedlessBool => [NEEDLESS_BOOL]);
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for expressions of the form `if c { x = true } else { x = false }`
+ /// (or vice versa) and suggest assigning the variable directly from the
+ /// condition.
+ ///
+ /// ### Why is this bad?
+ /// Redundant code.
+ ///
+ /// ### Example
+ /// ```rust,ignore
+ /// # fn must_keep(x: i32, y: i32) -> bool { x == y }
+ /// # let x = 32; let y = 10;
+ /// # let mut skip: bool;
+ /// if must_keep(x, y) {
+ /// skip = false;
+ /// } else {
+ /// skip = true;
+ /// }
+ /// ```
+ /// Use instead:
+ /// ```rust,ignore
+ /// # fn must_keep(x: i32, y: i32) -> bool { x == y }
+ /// # let x = 32; let y = 10;
+ /// # let mut skip: bool;
+ /// skip = !must_keep(x, y);
+ /// ```
+ #[clippy::version = "1.69.0"]
+ pub NEEDLESS_BOOL_ASSIGN,
+ complexity,
+ "setting the same boolean variable in both branches of an if-statement"
+}
+declare_lint_pass!(NeedlessBool => [NEEDLESS_BOOL, NEEDLESS_BOOL_ASSIGN]);
fn condition_needs_parentheses(e: &Expr<'_>) -> bool {
let mut inner = e;
@@ -112,7 +146,7 @@ fn is_parent_stmt(cx: &LateContext<'_>, id: HirId) -> bool {
impl<'tcx> LateLintPass<'tcx> for NeedlessBool {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
use self::Expression::{Bool, RetBool};
- if e.span.from_expansion() {
+ if e.span.from_expansion() || !span_extract_comment(cx.tcx.sess.source_map(), e.span).is_empty() {
return;
}
if let Some(higher::If {
@@ -173,6 +207,28 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBool {
_ => (),
}
}
+ if let Some((lhs_a, a)) = fetch_assign(then) &&
+ let Some((lhs_b, b)) = fetch_assign(r#else) &&
+ SpanlessEq::new(cx).eq_expr(lhs_a, lhs_b)
+ {
+ let mut applicability = Applicability::MachineApplicable;
+ let cond = Sugg::hir_with_applicability(cx, cond, "..", &mut applicability);
+ let lhs = snippet_with_applicability(cx, lhs_a.span, "..", &mut applicability);
+ let sugg = if a == b {
+ format!("{cond}; {lhs} = {a:?};")
+ } else {
+ format!("{lhs} = {};", if a { cond } else { !cond })
+ };
+ span_lint_and_sugg(
+ cx,
+ NEEDLESS_BOOL_ASSIGN,
+ e.span,
+ "this if-then-else expression assigns a bool literal",
+ "you can reduce it to",
+ sugg,
+ applicability
+ );
+ }
}
}
}
@@ -369,10 +425,18 @@ fn fetch_bool_block(expr: &Expr<'_>) -> Option<Expression> {
}
fn fetch_bool_expr(expr: &Expr<'_>) -> Option<bool> {
- if let ExprKind::Lit(ref lit_ptr) = peel_blocks(expr).kind {
+ if let ExprKind::Lit(lit_ptr) = peel_blocks(expr).kind {
if let LitKind::Bool(value) = lit_ptr.node {
return Some(value);
}
}
None
}
+
+fn fetch_assign<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<(&'tcx Expr<'tcx>, bool)> {
+ if let ExprKind::Assign(lhs, rhs, _) = peel_blocks_with_stmt(expr).kind {
+ fetch_bool_expr(rhs).map(|b| (lhs, b))
+ } else {
+ None
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/needless_parens_on_range_literals.rs b/src/tools/clippy/clippy_lints/src/needless_parens_on_range_literals.rs
index 6e54b243c..da1b9d999 100644
--- a/src/tools/clippy/clippy_lints/src/needless_parens_on_range_literals.rs
+++ b/src/tools/clippy/clippy_lints/src/needless_parens_on_range_literals.rs
@@ -49,14 +49,14 @@ fn snippet_enclosed_in_parenthesis(snippet: &str) -> bool {
fn check_for_parens(cx: &LateContext<'_>, e: &Expr<'_>, is_start: bool) {
if is_start &&
- let ExprKind::Lit(ref literal) = e.kind &&
+ let ExprKind::Lit(literal) = e.kind &&
let ast::LitKind::Float(_sym, ast::LitFloatType::Unsuffixed) = literal.node
{
// don't check floating point literals on the start expression of a range
return;
}
if_chain! {
- if let ExprKind::Lit(ref literal) = e.kind;
+ if let ExprKind::Lit(literal) = e.kind;
// the indicator that parenthesis surround the literal is that the span of the expression and the literal differ
if (literal.span.data().hi - literal.span.data().lo) != (e.span.data().hi - e.span.data().lo);
// inspect the source code of the expression for parenthesis
diff --git a/src/tools/clippy/clippy_lints/src/neg_multiply.rs b/src/tools/clippy/clippy_lints/src/neg_multiply.rs
index ed3e2c6e7..db0e22842 100644
--- a/src/tools/clippy/clippy_lints/src/neg_multiply.rs
+++ b/src/tools/clippy/clippy_lints/src/neg_multiply.rs
@@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for NegMultiply {
fn check_mul(cx: &LateContext<'_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) {
if_chain! {
- if let ExprKind::Lit(ref l) = lit.kind;
+ if let ExprKind::Lit(l) = lit.kind;
if consts::lit_to_mir_constant(&l.node, cx.typeck_results().expr_ty_opt(lit)) == Constant::Int(1);
if cx.typeck_results().expr_ty(exp).is_integral();
diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs
index 0bedab05e..58590df1f 100644
--- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs
+++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs
@@ -1,4 +1,4 @@
-//! Checks for uses of const which the type is not `Freeze` (`Cell`-free).
+//! Checks for usage of const which the type is not `Freeze` (`Cell`-free).
//!
//! This lint is **warn** by default.
@@ -196,11 +196,9 @@ fn is_value_unfrozen_poly<'tcx>(cx: &LateContext<'tcx>, body_id: BodyId, ty: Ty<
fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: DefId, ty: Ty<'tcx>) -> bool {
let substs = cx.typeck_results().node_substs(hir_id);
- let result = cx.tcx.const_eval_resolve(
- cx.param_env,
- mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs),
- None,
- );
+ let result = cx
+ .tcx
+ .const_eval_resolve(cx.param_env, mir::UnevaluatedConst::new(def_id, substs), None);
is_value_unfrozen_raw(cx, result, ty)
}
diff --git a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs
index 839c3a381..7eaa7db78 100644
--- a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs
+++ b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs
@@ -131,13 +131,13 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
for field in non_send_fields {
diag.span_note(
field.def.span,
- &format!("it is not safe to send field `{}` to another thread", field.def.ident.name),
+ format!("it is not safe to send field `{}` to another thread", field.def.ident.name),
);
match field.generic_params.len() {
0 => diag.help("use a thread-safe type that implements `Send`"),
- 1 if is_ty_param(field.ty) => diag.help(&format!("add `{}: Send` bound in `Send` impl", field.ty)),
- _ => diag.help(&format!(
+ 1 if is_ty_param(field.ty) => diag.help(format!("add `{}: Send` bound in `Send` impl", field.ty)),
+ _ => diag.help(format!(
"add bounds on type parameter{} `{}` that satisfy `{}: Send`",
if field.generic_params.len() > 1 { "s" } else { "" },
field.generic_params_string(),
diff --git a/src/tools/clippy/clippy_lints/src/octal_escapes.rs b/src/tools/clippy/clippy_lints/src/octal_escapes.rs
index 7376ab0c8..6d3865080 100644
--- a/src/tools/clippy/clippy_lints/src/octal_escapes.rs
+++ b/src/tools/clippy/clippy_lints/src/octal_escapes.rs
@@ -76,8 +76,8 @@ fn check_lit(cx: &EarlyContext<'_>, lit: &Lit, span: Span, is_string: bool) {
if ch == '\\' {
if let Some((_, '0')) = iter.next() {
// collect up to two further octal digits
- if let Some((mut to, '0'..='7')) = iter.next() {
- if let Some((_, '0'..='7')) = iter.peek() {
+ if let Some((mut to, _)) = iter.next_if(|(_, ch)| matches!(ch, '0'..='7')) {
+ if iter.next_if(|(_, ch)| matches!(ch, '0'..='7')).is_some() {
to += 1;
}
found.push((from, to + 1));
@@ -90,32 +90,6 @@ fn check_lit(cx: &EarlyContext<'_>, lit: &Lit, span: Span, is_string: bool) {
return;
}
- // construct two suggestion strings, one with \x escapes with octal meaning
- // as in C, and one with \x00 for null bytes.
- let mut suggest_1 = if is_string { "\"" } else { "b\"" }.to_string();
- let mut suggest_2 = suggest_1.clone();
- let mut index = 0;
- for (from, to) in found {
- suggest_1.push_str(&contents[index..from]);
- suggest_2.push_str(&contents[index..from]);
-
- // construct a replacement escape
- // the maximum value is \077, or \x3f, so u8 is sufficient here
- if let Ok(n) = u8::from_str_radix(&contents[from + 1..to], 8) {
- write!(suggest_1, "\\x{n:02x}").unwrap();
- }
-
- // append the null byte as \x00 and the following digits literally
- suggest_2.push_str("\\x00");
- suggest_2.push_str(&contents[from + 2..to]);
-
- index = to;
- }
- suggest_1.push_str(&contents[index..]);
- suggest_1.push('"');
- suggest_2.push_str(&contents[index..]);
- suggest_2.push('"');
-
span_lint_and_then(
cx,
OCTAL_ESCAPES,
@@ -129,23 +103,53 @@ fn check_lit(cx: &EarlyContext<'_>, lit: &Lit, span: Span, is_string: bool) {
"octal escapes are not supported, `\\0` is always a null {}",
if is_string { "character" } else { "byte" }
));
- // suggestion 1: equivalent hex escape
- diag.span_suggestion(
- span,
- "if an octal escape was intended, use the hexadecimal representation instead",
- suggest_1,
- Applicability::MaybeIncorrect,
- );
- // suggestion 2: unambiguous null byte
- diag.span_suggestion(
- span,
- format!(
- "if the null {} is intended, disambiguate using",
- if is_string { "character" } else { "byte" }
- ),
- suggest_2,
- Applicability::MaybeIncorrect,
- );
+
+ // Generate suggestions if the string is not too long (~ 5 lines)
+ if contents.len() < 400 {
+ // construct two suggestion strings, one with \x escapes with octal meaning
+ // as in C, and one with \x00 for null bytes.
+ let mut suggest_1 = if is_string { "\"" } else { "b\"" }.to_string();
+ let mut suggest_2 = suggest_1.clone();
+ let mut index = 0;
+ for (from, to) in found {
+ suggest_1.push_str(&contents[index..from]);
+ suggest_2.push_str(&contents[index..from]);
+
+ // construct a replacement escape
+ // the maximum value is \077, or \x3f, so u8 is sufficient here
+ if let Ok(n) = u8::from_str_radix(&contents[from + 1..to], 8) {
+ write!(suggest_1, "\\x{n:02x}").unwrap();
+ }
+
+ // append the null byte as \x00 and the following digits literally
+ suggest_2.push_str("\\x00");
+ suggest_2.push_str(&contents[from + 2..to]);
+
+ index = to;
+ }
+ suggest_1.push_str(&contents[index..]);
+ suggest_2.push_str(&contents[index..]);
+
+ suggest_1.push('"');
+ suggest_2.push('"');
+ // suggestion 1: equivalent hex escape
+ diag.span_suggestion(
+ span,
+ "if an octal escape was intended, use the hexadecimal representation instead",
+ suggest_1,
+ Applicability::MaybeIncorrect,
+ );
+ // suggestion 2: unambiguous null byte
+ diag.span_suggestion(
+ span,
+ format!(
+ "if the null {} is intended, disambiguate using",
+ if is_string { "character" } else { "byte" }
+ ),
+ suggest_2,
+ Applicability::MaybeIncorrect,
+ );
+ }
},
);
}
diff --git a/src/tools/clippy/clippy_lints/src/operators/absurd_extreme_comparisons.rs b/src/tools/clippy/clippy_lints/src/operators/absurd_extreme_comparisons.rs
index d29ca37ea..f4863600c 100644
--- a/src/tools/clippy/clippy_lints/src/operators/absurd_extreme_comparisons.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/absurd_extreme_comparisons.rs
@@ -121,7 +121,7 @@ fn detect_absurd_comparison<'tcx>(
fn detect_extreme_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<ExtremeExpr<'tcx>> {
let ty = cx.typeck_results().expr_ty(expr);
- let cv = constant(cx, cx.typeck_results(), expr)?.0;
+ let cv = constant(cx, cx.typeck_results(), expr)?;
let which = match (ty.kind(), cv) {
(&ty::Bool, Constant::Bool(false)) | (&ty::Uint(_), Constant::Int(0)) => ExtremeType::Minimum,
diff --git a/src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs b/src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs
index e57137356..5c240276b 100644
--- a/src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs
@@ -1,4 +1,5 @@
use super::ARITHMETIC_SIDE_EFFECTS;
+use clippy_utils::is_from_proc_macro;
use clippy_utils::{
consts::{constant, constant_simple, Constant},
diagnostics::span_lint,
@@ -10,16 +11,20 @@ use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::Ty;
use rustc_session::impl_lint_pass;
-use rustc_span::source_map::{Span, Spanned};
+use rustc_span::{
+ source_map::{Span, Spanned},
+ Symbol,
+};
const HARD_CODED_ALLOWED_BINARY: &[[&str; 2]] = &[
["f32", "f32"],
["f64", "f64"],
["std::num::Saturating", "std::num::Saturating"],
["std::num::Wrapping", "std::num::Wrapping"],
- ["std::string::String", "&str"],
+ ["std::string::String", "str"],
];
const HARD_CODED_ALLOWED_UNARY: &[&str] = &["f32", "f64", "std::num::Saturating", "std::num::Wrapping"];
+const INTEGER_METHODS: &[&str] = &["saturating_div", "wrapping_div", "wrapping_rem", "wrapping_rem_euclid"];
#[derive(Debug)]
pub struct ArithmeticSideEffects {
@@ -28,6 +33,7 @@ pub struct ArithmeticSideEffects {
// Used to check whether expressions are constants, such as in enum discriminants and consts
const_span: Option<Span>,
expr_span: Option<Span>,
+ integer_methods: FxHashSet<Symbol>,
}
impl_lint_pass!(ArithmeticSideEffects => [ARITHMETIC_SIDE_EFFECTS]);
@@ -53,6 +59,7 @@ impl ArithmeticSideEffects {
allowed_unary,
const_span: None,
expr_span: None,
+ integer_methods: INTEGER_METHODS.iter().map(|el| Symbol::intern(el)).collect(),
}
}
@@ -103,10 +110,10 @@ impl ArithmeticSideEffects {
/// like `i32::MAX` or constant references like `N` from `const N: i32 = 1;`,
fn literal_integer(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<u128> {
let actual = peel_hir_expr_unary(expr).0;
- if let hir::ExprKind::Lit(ref lit) = actual.kind && let ast::LitKind::Int(n, _) = lit.node {
+ if let hir::ExprKind::Lit(lit) = actual.kind && let ast::LitKind::Int(n, _) = lit.node {
return Some(n)
}
- if let Some((Constant::Int(n), _)) = constant(cx, cx.typeck_results(), expr) {
+ if let Some(Constant::Int(n)) = constant(cx, cx.typeck_results(), expr) {
return Some(n);
}
None
@@ -137,8 +144,10 @@ impl ArithmeticSideEffects {
) {
return;
};
- let lhs_ty = cx.typeck_results().expr_ty(lhs);
- let rhs_ty = cx.typeck_results().expr_ty(rhs);
+ let (actual_lhs, lhs_ref_counter) = peel_hir_expr_refs(lhs);
+ let (actual_rhs, rhs_ref_counter) = peel_hir_expr_refs(rhs);
+ let lhs_ty = cx.typeck_results().expr_ty(actual_lhs).peel_refs();
+ let rhs_ty = cx.typeck_results().expr_ty(actual_rhs).peel_refs();
if self.has_allowed_binary(lhs_ty, rhs_ty) {
return;
}
@@ -147,8 +156,6 @@ impl ArithmeticSideEffects {
// At least for integers, shifts are already handled by the CTFE
return;
}
- let (actual_lhs, lhs_ref_counter) = peel_hir_expr_refs(lhs);
- let (actual_rhs, rhs_ref_counter) = peel_hir_expr_refs(rhs);
match (
Self::literal_integer(cx, actual_lhs),
Self::literal_integer(cx, actual_rhs),
@@ -184,6 +191,33 @@ impl ArithmeticSideEffects {
}
}
+ /// There are some integer methods like `wrapping_div` that will panic depending on the
+ /// provided input.
+ fn manage_method_call<'tcx>(
+ &mut self,
+ args: &[hir::Expr<'tcx>],
+ cx: &LateContext<'tcx>,
+ ps: &hir::PathSegment<'tcx>,
+ receiver: &hir::Expr<'tcx>,
+ ) {
+ let Some(arg) = args.first() else { return; };
+ if constant_simple(cx, cx.typeck_results(), receiver).is_some() {
+ return;
+ }
+ let instance_ty = cx.typeck_results().expr_ty(receiver);
+ if !Self::is_integral(instance_ty) {
+ return;
+ }
+ if !self.integer_methods.contains(&ps.ident.name) {
+ return;
+ }
+ let (actual_arg, _) = peel_hir_expr_refs(arg);
+ match Self::literal_integer(cx, actual_arg) {
+ None | Some(0) => self.issue_lint(cx, arg),
+ Some(_) => {},
+ }
+ }
+
fn manage_unary_ops<'tcx>(
&mut self,
cx: &LateContext<'tcx>,
@@ -206,8 +240,9 @@ impl ArithmeticSideEffects {
self.issue_lint(cx, expr);
}
- fn should_skip_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
+ fn should_skip_expr<'tcx>(&mut self, cx: &LateContext<'tcx>, expr: &hir::Expr<'tcx>) -> bool {
is_lint_allowed(cx, ARITHMETIC_SIDE_EFFECTS, expr.hir_id)
+ || is_from_proc_macro(cx, expr)
|| self.expr_span.is_some()
|| self.const_span.map_or(false, |sp| sp.contains(expr.span))
}
@@ -222,6 +257,9 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
hir::ExprKind::AssignOp(op, lhs, rhs) | hir::ExprKind::Binary(op, lhs, rhs) => {
self.manage_bin_ops(cx, expr, op, lhs, rhs);
},
+ hir::ExprKind::MethodCall(ps, receiver, args, _) => {
+ self.manage_method_call(args, cx, ps, receiver);
+ },
hir::ExprKind::Unary(un_op, un_expr) => {
self.manage_unary_ops(cx, expr, un_expr, *un_op);
},
diff --git a/src/tools/clippy/clippy_lints/src/operators/bit_mask.rs b/src/tools/clippy/clippy_lints/src/operators/bit_mask.rs
index 1369b3e74..1fddf0f50 100644
--- a/src/tools/clippy/clippy_lints/src/operators/bit_mask.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/bit_mask.rs
@@ -166,7 +166,7 @@ fn check_ineffective_gt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op:
}
fn fetch_int_literal(cx: &LateContext<'_>, lit: &Expr<'_>) -> Option<u128> {
- match constant(cx, cx.typeck_results(), lit)?.0 {
+ match constant(cx, cx.typeck_results(), lit)? {
Constant::Int(n) => Some(n),
_ => None,
}
diff --git a/src/tools/clippy/clippy_lints/src/operators/cmp_nan.rs b/src/tools/clippy/clippy_lints/src/operators/cmp_nan.rs
index 786ae1552..e18064b70 100644
--- a/src/tools/clippy/clippy_lints/src/operators/cmp_nan.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/cmp_nan.rs
@@ -18,7 +18,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &Expr<'_>, op: BinOpKind, lhs: &Exp
}
fn is_nan(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
- if let Some((value, _)) = constant(cx, cx.typeck_results(), e) {
+ if let Some(value) = constant(cx, cx.typeck_results(), e) {
match value {
Constant::F32(num) => num.is_nan(),
Constant::F64(num) => num.is_nan(),
diff --git a/src/tools/clippy/clippy_lints/src/operators/duration_subsec.rs b/src/tools/clippy/clippy_lints/src/operators/duration_subsec.rs
index 49e662cac..f120be138 100644
--- a/src/tools/clippy/clippy_lints/src/operators/duration_subsec.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/duration_subsec.rs
@@ -19,7 +19,7 @@ pub(crate) fn check<'tcx>(
if op == BinOpKind::Div
&& let ExprKind::MethodCall(method_path, self_arg, [], _) = left.kind
&& is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(self_arg).peel_refs(), sym::Duration)
- && let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right)
+ && let Some(Constant::Int(divisor)) = constant(cx, cx.typeck_results(), right)
{
let suggested_fn = match (method_path.ident.as_str(), divisor) {
("subsec_micros", 1_000) | ("subsec_nanos", 1_000_000) => "subsec_millis",
diff --git a/src/tools/clippy/clippy_lints/src/operators/float_cmp.rs b/src/tools/clippy/clippy_lints/src/operators/float_cmp.rs
index 97ddcdb24..15dff126b 100644
--- a/src/tools/clippy/clippy_lints/src/operators/float_cmp.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/float_cmp.rs
@@ -1,4 +1,4 @@
-use clippy_utils::consts::{constant, Constant};
+use clippy_utils::consts::{constant_with_source, Constant};
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::get_item_name;
use clippy_utils::sugg::Sugg;
@@ -18,9 +18,16 @@ pub(crate) fn check<'tcx>(
right: &'tcx Expr<'_>,
) {
if (op == BinOpKind::Eq || op == BinOpKind::Ne) && (is_float(cx, left) || is_float(cx, right)) {
- if is_allowed(cx, left) || is_allowed(cx, right) {
- return;
- }
+ let left_is_local = match constant_with_source(cx, cx.typeck_results(), left) {
+ Some((c, s)) if !is_allowed(&c) => s.is_local(),
+ Some(_) => return,
+ None => true,
+ };
+ let right_is_local = match constant_with_source(cx, cx.typeck_results(), right) {
+ Some((c, s)) if !is_allowed(&c) => s.is_local(),
+ Some(_) => return,
+ None => true,
+ };
// Allow comparing the results of signum()
if is_signum(cx, left) && is_signum(cx, right) {
@@ -34,10 +41,7 @@ pub(crate) fn check<'tcx>(
}
}
let is_comparing_arrays = is_array(cx, left) || is_array(cx, right);
- let (lint, msg) = get_lint_and_message(
- is_named_constant(cx, left) || is_named_constant(cx, right),
- is_comparing_arrays,
- );
+ let (lint, msg) = get_lint_and_message(left_is_local && right_is_local, is_comparing_arrays);
span_lint_and_then(cx, lint, expr.span, msg, |diag| {
let lhs = Sugg::hir(cx, left, "..");
let rhs = Sugg::hir(cx, right, "..");
@@ -59,44 +63,33 @@ pub(crate) fn check<'tcx>(
}
}
-fn get_lint_and_message(
- is_comparing_constants: bool,
- is_comparing_arrays: bool,
-) -> (&'static rustc_lint::Lint, &'static str) {
- if is_comparing_constants {
+fn get_lint_and_message(is_local: bool, is_comparing_arrays: bool) -> (&'static rustc_lint::Lint, &'static str) {
+ if is_local {
(
- FLOAT_CMP_CONST,
+ FLOAT_CMP,
if is_comparing_arrays {
- "strict comparison of `f32` or `f64` constant arrays"
+ "strict comparison of `f32` or `f64` arrays"
} else {
- "strict comparison of `f32` or `f64` constant"
+ "strict comparison of `f32` or `f64`"
},
)
} else {
(
- FLOAT_CMP,
+ FLOAT_CMP_CONST,
if is_comparing_arrays {
- "strict comparison of `f32` or `f64` arrays"
+ "strict comparison of `f32` or `f64` constant arrays"
} else {
- "strict comparison of `f32` or `f64`"
+ "strict comparison of `f32` or `f64` constant"
},
)
}
}
-fn is_named_constant<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool {
- if let Some((_, res)) = constant(cx, cx.typeck_results(), expr) {
- res
- } else {
- false
- }
-}
-
-fn is_allowed<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> bool {
- match constant(cx, cx.typeck_results(), expr) {
- Some((Constant::F32(f), _)) => f == 0.0 || f.is_infinite(),
- Some((Constant::F64(f), _)) => f == 0.0 || f.is_infinite(),
- Some((Constant::Vec(vec), _)) => vec.iter().all(|f| match f {
+fn is_allowed(val: &Constant) -> bool {
+ match val {
+ &Constant::F32(f) => f == 0.0 || f.is_infinite(),
+ &Constant::F64(f) => f == 0.0 || f.is_infinite(),
+ Constant::Vec(vec) => vec.iter().all(|f| match f {
Constant::F32(f) => *f == 0.0 || (*f).is_infinite(),
Constant::F64(f) => *f == 0.0 || (*f).is_infinite(),
_ => false,
diff --git a/src/tools/clippy/clippy_lints/src/operators/mod.rs b/src/tools/clippy/clippy_lints/src/operators/mod.rs
index eba230da6..d63a836e7 100644
--- a/src/tools/clippy/clippy_lints/src/operators/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/mod.rs
@@ -98,32 +98,6 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for integer arithmetic operations which could overflow or panic.
- ///
- /// Specifically, checks for any operators (`+`, `-`, `*`, `<<`, etc) which are capable
- /// of overflowing according to the [Rust
- /// Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow),
- /// or which can panic (`/`, `%`). No bounds analysis or sophisticated reasoning is
- /// attempted.
- ///
- /// ### Why is this bad?
- /// Integer overflow will trigger a panic in debug builds or will wrap in
- /// release mode. Division by zero will cause a panic in either mode. In some applications one
- /// wants explicitly checked, wrapping or saturating arithmetic.
- ///
- /// ### Example
- /// ```rust
- /// # let a = 0;
- /// a + 1;
- /// ```
- #[clippy::version = "pre 1.29.0"]
- pub INTEGER_ARITHMETIC,
- restriction,
- "any integer arithmetic expression which could overflow or panic"
-}
-
-declare_clippy_lint! {
- /// ### What it does
/// Checks for float arithmetic.
///
/// ### Why is this bad?
@@ -685,7 +659,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for uses of bitwise and/or operators between booleans, where performance may be improved by using
+ /// Checks for usage of bitwise and/or operators between booleans, where performance may be improved by using
/// a lazy and.
///
/// ### Why is this bad?
@@ -787,7 +761,6 @@ pub struct Operators {
impl_lint_pass!(Operators => [
ABSURD_EXTREME_COMPARISONS,
ARITHMETIC_SIDE_EFFECTS,
- INTEGER_ARITHMETIC,
FLOAT_ARITHMETIC,
ASSIGN_OP_PATTERN,
MISREFACTORED_ASSIGN_OP,
diff --git a/src/tools/clippy/clippy_lints/src/operators/modulo_arithmetic.rs b/src/tools/clippy/clippy_lints/src/operators/modulo_arithmetic.rs
index af4e74947..a2c3a4d8b 100644
--- a/src/tools/clippy/clippy_lints/src/operators/modulo_arithmetic.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/modulo_arithmetic.rs
@@ -40,7 +40,7 @@ struct OperandInfo {
fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<OperandInfo> {
match constant(cx, cx.typeck_results(), operand) {
- Some((Constant::Int(v), _)) => match *cx.typeck_results().expr_ty(expr).kind() {
+ Some(Constant::Int(v)) => match *cx.typeck_results().expr_ty(expr).kind() {
ty::Int(ity) => {
let value = sext(cx.tcx, v, ity);
return Some(OperandInfo {
@@ -58,10 +58,10 @@ fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_>, expr: &Expr<'_>) ->
},
_ => {},
},
- Some((Constant::F32(f), _)) => {
+ Some(Constant::F32(f)) => {
return Some(floating_point_operand_info(&f));
},
- Some((Constant::F64(f), _)) => {
+ Some(Constant::F64(f)) => {
return Some(floating_point_operand_info(&f));
},
_ => {},
diff --git a/src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs b/src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs
index 777395f45..102845cee 100644
--- a/src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs
@@ -1,12 +1,10 @@
+use super::FLOAT_ARITHMETIC;
use clippy_utils::consts::constant_simple;
use clippy_utils::diagnostics::span_lint;
-use clippy_utils::is_integer_literal;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_span::source_map::Span;
-use super::{FLOAT_ARITHMETIC, INTEGER_ARITHMETIC};
-
#[derive(Default)]
pub struct Context {
expr_id: Option<hir::HirId>,
@@ -45,28 +43,8 @@ impl Context {
_ => (),
}
- let (l_ty, r_ty) = (cx.typeck_results().expr_ty(l), cx.typeck_results().expr_ty(r));
- if l_ty.peel_refs().is_integral() && r_ty.peel_refs().is_integral() {
- match op {
- hir::BinOpKind::Div | hir::BinOpKind::Rem => match &r.kind {
- hir::ExprKind::Lit(_lit) => (),
- hir::ExprKind::Unary(hir::UnOp::Neg, expr) => {
- if is_integer_literal(expr, 1) {
- span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
- self.expr_id = Some(expr.hir_id);
- }
- },
- _ => {
- span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
- self.expr_id = Some(expr.hir_id);
- },
- },
- _ => {
- span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
- self.expr_id = Some(expr.hir_id);
- },
- }
- } else if r_ty.peel_refs().is_floating_point() && r_ty.peel_refs().is_floating_point() {
+ let (_, r_ty) = (cx.typeck_results().expr_ty(l), cx.typeck_results().expr_ty(r));
+ if r_ty.peel_refs().is_floating_point() && r_ty.peel_refs().is_floating_point() {
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
self.expr_id = Some(expr.hir_id);
}
@@ -77,14 +55,9 @@ impl Context {
return;
}
let ty = cx.typeck_results().expr_ty(arg);
- if constant_simple(cx, cx.typeck_results(), expr).is_none() {
- if ty.is_integral() {
- span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
- self.expr_id = Some(expr.hir_id);
- } else if ty.is_floating_point() {
- span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
- self.expr_id = Some(expr.hir_id);
- }
+ if constant_simple(cx, cx.typeck_results(), expr).is_none() && ty.is_floating_point() {
+ span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
+ self.expr_id = Some(expr.hir_id);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/option_if_let_else.rs b/src/tools/clippy/clippy_lints/src/option_if_let_else.rs
index bbbcda069..aa6d40042 100644
--- a/src/tools/clippy/clippy_lints/src/option_if_let_else.rs
+++ b/src/tools/clippy/clippy_lints/src/option_if_let_else.rs
@@ -122,7 +122,7 @@ fn try_get_option_occurrence<'tcx>(
ExprKind::Unary(UnOp::Deref, inner_expr) | ExprKind::AddrOf(_, _, inner_expr) => inner_expr,
_ => expr,
};
- let inner_pat = try_get_inner_pat(cx, pat)?;
+ let (inner_pat, is_result) = try_get_inner_pat_and_is_result(cx, pat)?;
if_chain! {
if let PatKind::Binding(bind_annotation, _, id, None) = inner_pat.kind;
if let Some(some_captures) = can_move_expr_to_closure(cx, if_then);
@@ -176,7 +176,7 @@ fn try_get_option_occurrence<'tcx>(
),
none_expr: format!(
"{}{}",
- if method_sugg == "map_or" { "" } else { "|| " },
+ if method_sugg == "map_or" { "" } else if is_result { "|_| " } else { "|| "},
Sugg::hir_with_context(cx, none_body, ctxt, "..", &mut app),
),
});
@@ -186,11 +186,13 @@ fn try_get_option_occurrence<'tcx>(
None
}
-fn try_get_inner_pat<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'tcx>) -> Option<&'tcx Pat<'tcx>> {
+fn try_get_inner_pat_and_is_result<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'tcx>) -> Option<(&'tcx Pat<'tcx>, bool)> {
if let PatKind::TupleStruct(ref qpath, [inner_pat], ..) = pat.kind {
let res = cx.qpath_res(qpath, pat.hir_id);
- if is_res_lang_ctor(cx, res, OptionSome) || is_res_lang_ctor(cx, res, ResultOk) {
- return Some(inner_pat);
+ if is_res_lang_ctor(cx, res, OptionSome) {
+ return Some((inner_pat, false));
+ } else if is_res_lang_ctor(cx, res, ResultOk) {
+ return Some((inner_pat, true));
}
}
None
diff --git a/src/tools/clippy/clippy_lints/src/question_mark_used.rs b/src/tools/clippy/clippy_lints/src/question_mark_used.rs
index 9b678e8d7..ff66b8a00 100644
--- a/src/tools/clippy/clippy_lints/src/question_mark_used.rs
+++ b/src/tools/clippy/clippy_lints/src/question_mark_used.rs
@@ -24,7 +24,7 @@ declare_clippy_lint! {
/// ```ignore
/// utility_macro!(expr);
/// ```
- #[clippy::version = "pre 1.29.0"]
+ #[clippy::version = "1.69.0"]
pub QUESTION_MARK_USED,
restriction,
"complains if the question mark operator is used"
diff --git a/src/tools/clippy/clippy_lints/src/ranges.rs b/src/tools/clippy/clippy_lints/src/ranges.rs
index fc655fe2d..dd7ded491 100644
--- a/src/tools/clippy/clippy_lints/src/ranges.rs
+++ b/src/tools/clippy/clippy_lints/src/ranges.rs
@@ -319,7 +319,7 @@ fn check_range_bounds<'a>(cx: &'a LateContext<'_>, ex: &'a Expr<'_>) -> Option<R
_ => return None,
};
if let Some(id) = path_to_local(l) {
- if let Some((c, _)) = constant(cx, cx.typeck_results(), r) {
+ if let Some(c) = constant(cx, cx.typeck_results(), r) {
return Some(RangeBounds {
val: c,
expr: r,
@@ -331,7 +331,7 @@ fn check_range_bounds<'a>(cx: &'a LateContext<'_>, ex: &'a Expr<'_>) -> Option<R
});
}
} else if let Some(id) = path_to_local(r) {
- if let Some((c, _)) = constant(cx, cx.typeck_results(), l) {
+ if let Some(c) = constant(cx, cx.typeck_results(), l) {
return Some(RangeBounds {
val: c,
expr: l,
@@ -451,8 +451,8 @@ fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>) {
if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::Range::hir(expr);
let ty = cx.typeck_results().expr_ty(start);
if let ty::Int(_) | ty::Uint(_) = ty.kind();
- if let Some((start_idx, _)) = constant(cx, cx.typeck_results(), start);
- if let Some((end_idx, _)) = constant(cx, cx.typeck_results(), end);
+ if let Some(start_idx) = constant(cx, cx.typeck_results(), start);
+ if let Some(end_idx) = constant(cx, cx.typeck_results(), end);
if let Some(ordering) = Constant::partial_cmp(cx.tcx, ty, &start_idx, &end_idx);
if is_empty_range(limits, ordering);
then {
diff --git a/src/tools/clippy/clippy_lints/src/redundant_clone.rs b/src/tools/clippy/clippy_lints/src/redundant_clone.rs
index 944a33cc3..685d738cb 100644
--- a/src/tools/clippy/clippy_lints/src/redundant_clone.rs
+++ b/src/tools/clippy/clippy_lints/src/redundant_clone.rs
@@ -57,7 +57,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.32.0"]
pub REDUNDANT_CLONE,
- perf,
+ nursery,
"`clone()` of an owned value that is going to be dropped immediately"
}
diff --git a/src/tools/clippy/clippy_lints/src/ref_patterns.rs b/src/tools/clippy/clippy_lints/src/ref_patterns.rs
new file mode 100644
index 000000000..b1530eed1
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/ref_patterns.rs
@@ -0,0 +1,44 @@
+use clippy_utils::diagnostics::span_lint_and_help;
+use rustc_ast::ast::{BindingAnnotation, Pat, PatKind};
+use rustc_lint::{EarlyContext, EarlyLintPass};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for usages of the `ref` keyword.
+ /// ### Why is this bad?
+ /// The `ref` keyword can be confusing for people unfamiliar with it, and often
+ /// it is more concise to use `&` instead.
+ /// ### Example
+ /// ```rust
+ /// let opt = Some(5);
+ /// if let Some(ref foo) = opt {}
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// let opt = Some(5);
+ /// if let Some(foo) = &opt {}
+ /// ```
+ #[clippy::version = "1.71.0"]
+ pub REF_PATTERNS,
+ restriction,
+ "use of a ref pattern, e.g. Some(ref value)"
+}
+declare_lint_pass!(RefPatterns => [REF_PATTERNS]);
+
+impl EarlyLintPass for RefPatterns {
+ fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &Pat) {
+ if let PatKind::Ident(BindingAnnotation::REF, _, _) = pat.kind
+ && !pat.span.from_expansion()
+ {
+ span_lint_and_help(
+ cx,
+ REF_PATTERNS,
+ pat.span,
+ "usage of ref pattern",
+ None,
+ "consider using `&` for clarity instead",
+ );
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/regex.rs b/src/tools/clippy/clippy_lints/src/regex.rs
index 9e6c6c73d..ef19c6f46 100644
--- a/src/tools/clippy/clippy_lints/src/regex.rs
+++ b/src/tools/clippy/clippy_lints/src/regex.rs
@@ -122,37 +122,39 @@ fn lint_syntax_error(cx: &LateContext<'_>, error: &regex_syntax::Error, unescape
}
fn const_str<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> Option<String> {
- constant(cx, cx.typeck_results(), e).and_then(|(c, _)| match c {
+ constant(cx, cx.typeck_results(), e).and_then(|c| match c {
Constant::Str(s) => Some(s),
_ => None,
})
}
fn is_trivial_regex(s: &regex_syntax::hir::Hir) -> Option<&'static str> {
- use regex_syntax::hir::Anchor::{EndText, StartText};
- use regex_syntax::hir::HirKind::{Alternation, Anchor, Concat, Empty, Literal};
+ use regex_syntax::hir::HirKind::{Alternation, Concat, Empty, Literal, Look};
+ use regex_syntax::hir::Look as HirLook;
let is_literal = |e: &[regex_syntax::hir::Hir]| e.iter().all(|e| matches!(*e.kind(), Literal(_)));
match *s.kind() {
- Empty | Anchor(_) => Some("the regex is unlikely to be useful as it is"),
+ Empty | Look(_) => Some("the regex is unlikely to be useful as it is"),
Literal(_) => Some("consider using `str::contains`"),
Alternation(ref exprs) => {
- if exprs.iter().all(|e| e.kind().is_empty()) {
+ if exprs.iter().all(|e| matches!(e.kind(), Empty)) {
Some("the regex is unlikely to be useful as it is")
} else {
None
}
},
Concat(ref exprs) => match (exprs[0].kind(), exprs[exprs.len() - 1].kind()) {
- (&Anchor(StartText), &Anchor(EndText)) if exprs[1..(exprs.len() - 1)].is_empty() => {
+ (&Look(HirLook::Start), &Look(HirLook::End)) if exprs[1..(exprs.len() - 1)].is_empty() => {
Some("consider using `str::is_empty`")
},
- (&Anchor(StartText), &Anchor(EndText)) if is_literal(&exprs[1..(exprs.len() - 1)]) => {
+ (&Look(HirLook::Start), &Look(HirLook::End)) if is_literal(&exprs[1..(exprs.len() - 1)]) => {
Some("consider using `==` on `str`s")
},
- (&Anchor(StartText), &Literal(_)) if is_literal(&exprs[1..]) => Some("consider using `str::starts_with`"),
- (&Literal(_), &Anchor(EndText)) if is_literal(&exprs[1..(exprs.len() - 1)]) => {
+ (&Look(HirLook::Start), &Literal(_)) if is_literal(&exprs[1..]) => {
+ Some("consider using `str::starts_with`")
+ },
+ (&Literal(_), &Look(HirLook::End)) if is_literal(&exprs[1..(exprs.len() - 1)]) => {
Some("consider using `str::ends_with`")
},
_ if is_literal(exprs) => Some("consider using `str::contains`"),
@@ -175,12 +177,9 @@ fn check_set<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, utf8: bool) {
}
fn check_regex<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, utf8: bool) {
- let mut parser = regex_syntax::ParserBuilder::new()
- .unicode(true)
- .allow_invalid_utf8(!utf8)
- .build();
+ let mut parser = regex_syntax::ParserBuilder::new().unicode(true).utf8(!utf8).build();
- if let ExprKind::Lit(ref lit) = expr.kind {
+ if let ExprKind::Lit(lit) = expr.kind {
if let LitKind::Str(ref r, style) = lit.node {
let r = r.as_str();
let offset = if let StrStyle::Raw(n) = style { 2 + n } else { 1 };
diff --git a/src/tools/clippy/clippy_lints/src/renamed_lints.rs b/src/tools/clippy/clippy_lints/src/renamed_lints.rs
index 9f487dedb..b0db56bb4 100644
--- a/src/tools/clippy/clippy_lints/src/renamed_lints.rs
+++ b/src/tools/clippy/clippy_lints/src/renamed_lints.rs
@@ -15,6 +15,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
("clippy::eval_order_dependence", "clippy::mixed_read_write_in_expression"),
("clippy::identity_conversion", "clippy::useless_conversion"),
("clippy::if_let_some_result", "clippy::match_result_ok"),
+ ("clippy::integer_arithmetic", "clippy::arithmetic_side_effects"),
("clippy::logic_bug", "clippy::overly_complex_bool_expr"),
("clippy::new_without_default_derive", "clippy::new_without_default"),
("clippy::option_and_then_some", "clippy::bind_instead_of_map"),
@@ -30,10 +31,15 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
("clippy::stutter", "clippy::module_name_repetitions"),
("clippy::to_string_in_display", "clippy::recursive_format_impl"),
("clippy::zero_width_space", "clippy::invisible_characters"),
+ ("clippy::clone_double_ref", "suspicious_double_ref_op"),
("clippy::drop_bounds", "drop_bounds"),
+ ("clippy::drop_copy", "dropping_copy_types"),
+ ("clippy::drop_ref", "dropping_references"),
("clippy::for_loop_over_option", "for_loops_over_fallibles"),
("clippy::for_loop_over_result", "for_loops_over_fallibles"),
("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"),
+ ("clippy::forget_copy", "forgetting_copy_types"),
+ ("clippy::forget_ref", "forgetting_references"),
("clippy::into_iter_on_array", "array_into_iter"),
("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"),
("clippy::invalid_ref", "invalid_value"),
diff --git a/src/tools/clippy/clippy_lints/src/semicolon_block.rs b/src/tools/clippy/clippy_lints/src/semicolon_block.rs
index 34a3e5ddf..419d7991f 100644
--- a/src/tools/clippy/clippy_lints/src/semicolon_block.rs
+++ b/src/tools/clippy/clippy_lints/src/semicolon_block.rs
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{multispan_sugg_with_applicability, span_lint_and
use rustc_errors::Applicability;
use rustc_hir::{Block, Expr, ExprKind, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass, LintContext};
-use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::Span;
declare_clippy_lint! {
@@ -64,7 +64,78 @@ declare_clippy_lint! {
restriction,
"add a semicolon outside the block"
}
-declare_lint_pass!(SemicolonBlock => [SEMICOLON_INSIDE_BLOCK, SEMICOLON_OUTSIDE_BLOCK]);
+impl_lint_pass!(SemicolonBlock => [SEMICOLON_INSIDE_BLOCK, SEMICOLON_OUTSIDE_BLOCK]);
+
+#[derive(Copy, Clone)]
+pub struct SemicolonBlock {
+ semicolon_inside_block_ignore_singleline: bool,
+ semicolon_outside_block_ignore_multiline: bool,
+}
+
+impl SemicolonBlock {
+ pub fn new(semicolon_inside_block_ignore_singleline: bool, semicolon_outside_block_ignore_multiline: bool) -> Self {
+ Self {
+ semicolon_inside_block_ignore_singleline,
+ semicolon_outside_block_ignore_multiline,
+ }
+ }
+
+ fn semicolon_inside_block(self, cx: &LateContext<'_>, block: &Block<'_>, tail: &Expr<'_>, semi_span: Span) {
+ let insert_span = tail.span.source_callsite().shrink_to_hi();
+ let remove_span = semi_span.with_lo(block.span.hi());
+
+ if self.semicolon_inside_block_ignore_singleline && get_line(cx, remove_span) == get_line(cx, insert_span) {
+ return;
+ }
+
+ span_lint_and_then(
+ cx,
+ SEMICOLON_INSIDE_BLOCK,
+ semi_span,
+ "consider moving the `;` inside the block for consistent formatting",
+ |diag| {
+ multispan_sugg_with_applicability(
+ diag,
+ "put the `;` here",
+ Applicability::MachineApplicable,
+ [(remove_span, String::new()), (insert_span, ";".to_owned())],
+ );
+ },
+ );
+ }
+
+ fn semicolon_outside_block(
+ self,
+ cx: &LateContext<'_>,
+ block: &Block<'_>,
+ tail_stmt_expr: &Expr<'_>,
+ semi_span: Span,
+ ) {
+ let insert_span = block.span.with_lo(block.span.hi());
+ // account for macro calls
+ let semi_span = cx.sess().source_map().stmt_span(semi_span, block.span);
+ let remove_span = semi_span.with_lo(tail_stmt_expr.span.source_callsite().hi());
+
+ if self.semicolon_outside_block_ignore_multiline && get_line(cx, remove_span) != get_line(cx, insert_span) {
+ return;
+ }
+
+ span_lint_and_then(
+ cx,
+ SEMICOLON_OUTSIDE_BLOCK,
+ block.span,
+ "consider moving the `;` outside the block for consistent formatting",
+ |diag| {
+ multispan_sugg_with_applicability(
+ diag,
+ "put the `;` here",
+ Applicability::MachineApplicable,
+ [(remove_span, String::new()), (insert_span, ";".to_owned())],
+ );
+ },
+ );
+ }
+}
impl LateLintPass<'_> for SemicolonBlock {
fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) {
@@ -83,55 +154,23 @@ impl LateLintPass<'_> for SemicolonBlock {
span,
..
} = stmt else { return };
- semicolon_outside_block(cx, block, expr, span);
+ self.semicolon_outside_block(cx, block, expr, span);
},
StmtKind::Semi(Expr {
kind: ExprKind::Block(block @ Block { expr: Some(tail), .. }, _),
..
- }) if !block.span.from_expansion() => semicolon_inside_block(cx, block, tail, stmt.span),
+ }) if !block.span.from_expansion() => {
+ self.semicolon_inside_block(cx, block, tail, stmt.span);
+ },
_ => (),
}
}
}
-fn semicolon_inside_block(cx: &LateContext<'_>, block: &Block<'_>, tail: &Expr<'_>, semi_span: Span) {
- let insert_span = tail.span.source_callsite().shrink_to_hi();
- let remove_span = semi_span.with_lo(block.span.hi());
-
- span_lint_and_then(
- cx,
- SEMICOLON_INSIDE_BLOCK,
- semi_span,
- "consider moving the `;` inside the block for consistent formatting",
- |diag| {
- multispan_sugg_with_applicability(
- diag,
- "put the `;` here",
- Applicability::MachineApplicable,
- [(remove_span, String::new()), (insert_span, ";".to_owned())],
- );
- },
- );
-}
-
-fn semicolon_outside_block(cx: &LateContext<'_>, block: &Block<'_>, tail_stmt_expr: &Expr<'_>, semi_span: Span) {
- let insert_span = block.span.with_lo(block.span.hi());
- // account for macro calls
- let semi_span = cx.sess().source_map().stmt_span(semi_span, block.span);
- let remove_span = semi_span.with_lo(tail_stmt_expr.span.source_callsite().hi());
+fn get_line(cx: &LateContext<'_>, span: Span) -> Option<usize> {
+ if let Ok(line) = cx.sess().source_map().lookup_line(span.lo()) {
+ return Some(line.line);
+ }
- span_lint_and_then(
- cx,
- SEMICOLON_OUTSIDE_BLOCK,
- block.span,
- "consider moving the `;` outside the block for consistent formatting",
- |diag| {
- multispan_sugg_with_applicability(
- diag,
- "put the `;` here",
- Applicability::MachineApplicable,
- [(remove_span, String::new()), (insert_span, ";".to_owned())],
- );
- },
- );
+ None
}
diff --git a/src/tools/clippy/clippy_lints/src/shadow.rs b/src/tools/clippy/clippy_lints/src/shadow.rs
index ae7d19624..993f9373d 100644
--- a/src/tools/clippy/clippy_lints/src/shadow.rs
+++ b/src/tools/clippy/clippy_lints/src/shadow.rs
@@ -108,7 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
let PatKind::Binding(_, id, ident, _) = pat.kind else { return };
- if pat.span.desugaring_kind().is_some() {
+ if pat.span.desugaring_kind().is_some() || pat.span.from_expansion() {
return;
}
diff --git a/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs b/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs
index 869358fb1..b930b2c8d 100644
--- a/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs
+++ b/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs
@@ -17,7 +17,7 @@ use rustc_span::{symbol::Ident, Span, DUMMY_SP};
declare_clippy_lint! {
/// ### What it does
///
- /// Searches for elements marked with `#[clippy::significant_drop]` that could be early
+ /// Searches for elements marked with `#[clippy::has_significant_drop]` that could be early
/// dropped but are in fact dropped at the end of their scopes. In other words, enforces the
/// "tightening" of their possible lifetimes.
///
@@ -46,7 +46,7 @@ declare_clippy_lint! {
/// do_heavy_computation_that_takes_time(owned_rslt);
/// }
/// ```
- #[clippy::version = "1.67.0"]
+ #[clippy::version = "1.69.0"]
pub SIGNIFICANT_DROP_TIGHTENING,
nursery,
"Searches for elements marked with `#[clippy::has_significant_drop]` that could be early dropped but are in fact dropped at the end of their scopes"
diff --git a/src/tools/clippy/clippy_lints/src/slow_vector_initialization.rs b/src/tools/clippy/clippy_lints/src/slow_vector_initialization.rs
index a2109038a..858135c8d 100644
--- a/src/tools/clippy/clippy_lints/src/slow_vector_initialization.rs
+++ b/src/tools/clippy/clippy_lints/src/slow_vector_initialization.rs
@@ -74,7 +74,7 @@ enum InitializationType<'tcx> {
impl<'tcx> LateLintPass<'tcx> for SlowVectorInit {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
- // Matches initialization on reassignements. For example: `vec = Vec::with_capacity(100)`
+ // Matches initialization on reassignments. For example: `vec = Vec::with_capacity(100)`
if_chain! {
if let ExprKind::Assign(left, right, _) = expr.kind;
diff --git a/src/tools/clippy/clippy_lints/src/strings.rs b/src/tools/clippy/clippy_lints/src/strings.rs
index b2f4b3109..483f860a8 100644
--- a/src/tools/clippy/clippy_lints/src/strings.rs
+++ b/src/tools/clippy/clippy_lints/src/strings.rs
@@ -132,7 +132,7 @@ declare_clippy_lint! {
/// Probably lots of false positives. If an index comes from a known valid position (e.g.
/// obtained via `char_indices` over the same string), it is totally OK.
///
- /// # Example
+ /// ### Example
/// ```rust,should_panic
/// &"Ölkanne"[1..];
/// ```
@@ -292,6 +292,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes {
}
if_chain! {
+ if !in_external_macro(cx.sess(), e.span);
if let ExprKind::MethodCall(path, receiver, ..) = &e.kind;
if path.ident.name == sym!(as_bytes);
if let ExprKind::Lit(lit) = &receiver.kind;
diff --git a/src/tools/clippy/clippy_lints/src/strlen_on_c_strings.rs b/src/tools/clippy/clippy_lints/src/strlen_on_c_strings.rs
index 03324c66e..2f2e84fa3 100644
--- a/src/tools/clippy/clippy_lints/src/strlen_on_c_strings.rs
+++ b/src/tools/clippy/clippy_lints/src/strlen_on_c_strings.rs
@@ -1,11 +1,11 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_context;
-use clippy_utils::ty::is_type_diagnostic_item;
+use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
use clippy_utils::visitors::is_expr_unsafe;
use clippy_utils::{get_parent_node, match_libc_symbol};
use if_chain::if_chain;
use rustc_errors::Applicability;
-use rustc_hir::{Block, BlockCheckMode, Expr, ExprKind, Node, UnsafeSource};
+use rustc_hir::{Block, BlockCheckMode, Expr, ExprKind, LangItem, Node, UnsafeSource};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::symbol::sym;
@@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for StrlenOnCStrings {
let val_name = snippet_with_context(cx, self_arg.span, ctxt, "..", &mut app).0;
let method_name = if is_type_diagnostic_item(cx, ty, sym::cstring_type) {
"as_bytes"
- } else if is_type_diagnostic_item(cx, ty, sym::CStr) {
+ } else if is_type_lang_item(cx, ty, LangItem::CStr) {
"to_bytes"
} else {
return;
diff --git a/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs b/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs
index fab8e9c2e..e2cdc48b5 100644
--- a/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs
+++ b/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs
@@ -577,7 +577,7 @@ fn ident_difference_expr_with_base_location(
| (AssignOp(_, _, _), AssignOp(_, _, _))
| (Assign(_, _, _), Assign(_, _, _))
| (TryBlock(_), TryBlock(_))
- | (Await(_), Await(_))
+ | (Await(_, _), Await(_, _))
| (Async(_, _), Async(_, _))
| (Block(_, _), Block(_, _))
| (Closure(_), Closure(_))
diff --git a/src/tools/clippy/clippy_lints/src/trailing_empty_array.rs b/src/tools/clippy/clippy_lints/src/trailing_empty_array.rs
index 1382c1a40..bb9da3a20 100644
--- a/src/tools/clippy/clippy_lints/src/trailing_empty_array.rs
+++ b/src/tools/clippy/clippy_lints/src/trailing_empty_array.rs
@@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for TrailingEmptyArray {
None,
&format!(
"consider annotating `{}` with `#[repr(C)]` or another `repr` attribute",
- cx.tcx.def_path_str(item.owner_id.to_def_id())
+ cx.tcx.def_path_str(item.owner_id)
),
);
}
@@ -60,7 +60,7 @@ fn is_struct_with_trailing_zero_sized_array(cx: &LateContext<'_>, item: &Item<'_
if let Some(last_field) = data.fields().last();
if let rustc_hir::TyKind::Array(_, rustc_hir::ArrayLen::Body(length)) = last_field.ty.kind;
- // Then check if that that array zero-sized
+ // Then check if that array is zero-sized
let length = Const::from_anon_const(cx.tcx, length.def_id);
let length = length.try_eval_target_usize(cx.tcx, cx.param_env);
if let Some(length) = length;
diff --git a/src/tools/clippy/clippy_lints/src/trait_bounds.rs b/src/tools/clippy/clippy_lints/src/trait_bounds.rs
index b5f11b4ac..4ccda1506 100644
--- a/src/tools/clippy/clippy_lints/src/trait_bounds.rs
+++ b/src/tools/clippy/clippy_lints/src/trait_bounds.rs
@@ -37,12 +37,12 @@ declare_clippy_lint! {
#[clippy::version = "1.38.0"]
pub TYPE_REPETITION_IN_BOUNDS,
nursery,
- "types are repeated unnecessary in trait bounds use `+` instead of using `T: _, T: _`"
+ "types are repeated unnecessarily in trait bounds, use `+` instead of using `T: _, T: _`"
}
declare_clippy_lint! {
/// ### What it does
- /// Checks for cases where generics are being used and multiple
+ /// Checks for cases where generics or trait objects are being used and multiple
/// syntax specifications for trait bounds are used simultaneously.
///
/// ### Why is this bad?
@@ -167,6 +167,61 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
}
}
}
+
+ fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx Ty<'tcx>) {
+ if_chain! {
+ if let TyKind::Ref(.., mut_ty) = &ty.kind;
+ if let TyKind::TraitObject(bounds, ..) = mut_ty.ty.kind;
+ if bounds.len() > 2;
+ then {
+
+ // Build up a hash of every trait we've seen
+ // When we see a trait for the first time, add it to unique_traits
+ // so we can later use it to build a string of all traits exactly once, without duplicates
+
+ let mut seen_def_ids = FxHashSet::default();
+ let mut unique_traits = Vec::new();
+
+ // Iterate the bounds and add them to our seen hash
+ // If we haven't yet seen it, add it to the fixed traits
+ for bound in bounds.iter() {
+ let Some(def_id) = bound.trait_ref.trait_def_id() else { continue; };
+
+ let new_trait = seen_def_ids.insert(def_id);
+
+ if new_trait {
+ unique_traits.push(bound);
+ }
+ }
+
+ // If the number of unique traits isn't the same as the number of traits in the bounds,
+ // there must be 1 or more duplicates
+ if bounds.len() != unique_traits.len() {
+ let mut bounds_span = bounds[0].span;
+
+ for bound in bounds.iter().skip(1) {
+ bounds_span = bounds_span.to(bound.span);
+ }
+
+ let fixed_trait_snippet = unique_traits
+ .iter()
+ .filter_map(|b| snippet_opt(cx, b.span))
+ .collect::<Vec<_>>()
+ .join(" + ");
+
+ span_lint_and_sugg(
+ cx,
+ TRAIT_DUPLICATION_IN_BOUNDS,
+ bounds_span,
+ "this trait bound is already specified in trait declaration",
+ "try",
+ fixed_trait_snippet,
+ Applicability::MaybeIncorrect,
+ );
+ }
+ }
+ }
+ }
}
impl TraitBounds {
diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmute_null_to_fn.rs b/src/tools/clippy/clippy_lints/src/transmute/transmute_null_to_fn.rs
index e75d7f6bf..4944381da 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/transmute_null_to_fn.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/transmute_null_to_fn.rs
@@ -31,9 +31,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arg: &'t
match arg.kind {
// Catching:
// transmute over constants that resolve to `null`.
- ExprKind::Path(ref _qpath)
- if matches!(constant(cx, cx.typeck_results(), arg), Some((Constant::RawPtr(0), _))) =>
- {
+ ExprKind::Path(ref _qpath) if matches!(constant(cx, cx.typeck_results(), arg), Some(Constant::RawPtr(0))) => {
lint_expr(cx, expr);
true
},
diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmuting_null.rs b/src/tools/clippy/clippy_lints/src/transmute/transmuting_null.rs
index 1e407fc41..770914e99 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/transmuting_null.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/transmuting_null.rs
@@ -1,4 +1,4 @@
-use clippy_utils::consts::{constant_context, Constant};
+use clippy_utils::consts::{constant, Constant};
use clippy_utils::diagnostics::span_lint;
use clippy_utils::{is_integer_literal, is_path_diagnostic_item};
use rustc_hir::{Expr, ExprKind};
@@ -16,9 +16,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arg: &'t
}
// Catching transmute over constants that resolve to `null`.
- let mut const_eval_context = constant_context(cx, cx.typeck_results());
if let ExprKind::Path(ref _qpath) = arg.kind &&
- let Some(Constant::RawPtr(0)) = const_eval_context.expr(arg)
+ let Some(Constant::RawPtr(0)) = constant(cx, cx.typeck_results(), arg)
{
span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG);
return true;
diff --git a/src/tools/clippy/clippy_lints/src/types/mod.rs b/src/tools/clippy/clippy_lints/src/types/mod.rs
index c1f228d5f..3c873a590 100644
--- a/src/tools/clippy/clippy_lints/src/types/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/types/mod.rs
@@ -22,7 +22,7 @@ use rustc_span::source_map::Span;
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of `Box<T>` where T is a collection such as Vec anywhere in the code.
+ /// Checks for usage of `Box<T>` where T is a collection such as Vec anywhere in the code.
/// Check the [Box documentation](https://doc.rust-lang.org/std/boxed/index.html) for more information.
///
/// ### Why is this bad?
@@ -52,7 +52,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of `Vec<Box<T>>` where T: Sized anywhere in the code.
+ /// Checks for usage of `Vec<Box<T>>` where T: Sized anywhere in the code.
/// Check the [Box documentation](https://doc.rust-lang.org/std/boxed/index.html) for more information.
///
/// ### Why is this bad?
@@ -85,13 +85,13 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of `Option<Option<_>>` in function signatures and type
+ /// Checks for usage of `Option<Option<_>>` in function signatures and type
/// definitions
///
/// ### Why is this bad?
/// `Option<_>` represents an optional value. `Option<Option<_>>`
- /// represents an optional optional value which is logically the same thing as an optional
- /// value but has an unneeded extra level of wrapping.
+ /// represents an optional value which itself wraps an optional. This is logically the
+ /// same thing as an optional value but has an unneeded extra level of wrapping.
///
/// If you have a case where `Some(Some(_))`, `Some(None)` and `None` are distinct cases,
/// consider a custom `enum` instead, with clear names for each case.
@@ -164,7 +164,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of `&Box<T>` anywhere in the code.
+ /// Checks for usage of `&Box<T>` anywhere in the code.
/// Check the [Box documentation](https://doc.rust-lang.org/std/boxed/index.html) for more information.
///
/// ### Why is this bad?
@@ -190,7 +190,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of redundant allocations anywhere in the code.
+ /// Checks for usage of redundant allocations anywhere in the code.
///
/// ### Why is this bad?
/// Expressions such as `Rc<&T>`, `Rc<Rc<T>>`, `Rc<Arc<T>>`, `Rc<Box<T>>`, `Arc<&T>`, `Arc<Rc<T>>`,
diff --git a/src/tools/clippy/clippy_lints/src/unicode.rs b/src/tools/clippy/clippy_lints/src/unicode.rs
index 8980283e5..e275bfd37 100644
--- a/src/tools/clippy/clippy_lints/src/unicode.rs
+++ b/src/tools/clippy/clippy_lints/src/unicode.rs
@@ -76,7 +76,7 @@ declare_lint_pass!(Unicode => [INVISIBLE_CHARACTERS, NON_ASCII_LITERAL, UNICODE_
impl LateLintPass<'_> for Unicode {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) {
- if let ExprKind::Lit(ref lit) = expr.kind {
+ if let ExprKind::Lit(lit) = expr.kind {
if let LitKind::Str(_, _) | LitKind::Char(_) = lit.node {
check_str(cx, lit.span, expr.hir_id);
}
diff --git a/src/tools/clippy/clippy_lints/src/unnecessary_box_returns.rs b/src/tools/clippy/clippy_lints/src/unnecessary_box_returns.rs
index 912bcda63..e7449639f 100644
--- a/src/tools/clippy/clippy_lints/src/unnecessary_box_returns.rs
+++ b/src/tools/clippy/clippy_lints/src/unnecessary_box_returns.rs
@@ -1,4 +1,4 @@
-use clippy_utils::diagnostics::span_lint_and_then;
+use clippy_utils::{diagnostics::span_lint_and_then, ty::approx_ty_size};
use rustc_errors::Applicability;
use rustc_hir::{def_id::LocalDefId, FnDecl, FnRetTy, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind};
use rustc_lint::{LateContext, LateLintPass};
@@ -10,6 +10,9 @@ declare_clippy_lint! {
///
/// Checks for a return type containing a `Box<T>` where `T` implements `Sized`
///
+ /// The lint ignores `Box<T>` where `T` is larger than `unnecessary_box_size`,
+ /// as returning a large `T` directly may be detrimental to performance.
+ ///
/// ### Why is this bad?
///
/// It's better to just return `T` in these cases. The caller may not need
@@ -36,14 +39,16 @@ declare_clippy_lint! {
pub struct UnnecessaryBoxReturns {
avoid_breaking_exported_api: bool,
+ maximum_size: u64,
}
impl_lint_pass!(UnnecessaryBoxReturns => [UNNECESSARY_BOX_RETURNS]);
impl UnnecessaryBoxReturns {
- pub fn new(avoid_breaking_exported_api: bool) -> Self {
+ pub fn new(avoid_breaking_exported_api: bool, maximum_size: u64) -> Self {
Self {
avoid_breaking_exported_api,
+ maximum_size,
}
}
@@ -71,8 +76,10 @@ impl UnnecessaryBoxReturns {
let boxed_ty = return_ty.boxed_ty();
- // it's sometimes useful to return Box<T> if T is unsized, so don't lint those
- if boxed_ty.is_sized(cx.tcx, cx.param_env) {
+ // It's sometimes useful to return Box<T> if T is unsized, so don't lint those.
+ // Also, don't lint if we know that T is very large, in which case returning
+ // a Box<T> may be beneficial.
+ if boxed_ty.is_sized(cx.tcx, cx.param_env) && approx_ty_size(cx, boxed_ty) <= self.maximum_size {
span_lint_and_then(
cx,
UNNECESSARY_BOX_RETURNS,
@@ -102,7 +109,7 @@ impl LateLintPass<'_> for UnnecessaryBoxReturns {
fn check_impl_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::ImplItem<'_>) {
// Ignore implementations of traits, because the lint should be on the
- // trait, not on the implmentation of it.
+ // trait, not on the implementation of it.
let Node::Item(parent) = cx.tcx.hir().get_parent(item.hir_id()) else { return };
let ItemKind::Impl(parent) = parent.kind else { return };
if parent.of_trait.is_some() {
diff --git a/src/tools/clippy/clippy_lints/src/useless_conversion.rs b/src/tools/clippy/clippy_lints/src/useless_conversion.rs
index ddbe6b2c7..28c3fc859 100644
--- a/src/tools/clippy/clippy_lints/src/useless_conversion.rs
+++ b/src/tools/clippy/clippy_lints/src/useless_conversion.rs
@@ -1,4 +1,5 @@
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg};
+use clippy_utils::is_ty_alias;
use clippy_utils::source::{snippet, snippet_with_context};
use clippy_utils::sugg::Sugg;
use clippy_utils::ty::{is_copy, is_type_diagnostic_item, same_type_and_consts};
@@ -138,6 +139,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
if_chain! {
if let ExprKind::Path(ref qpath) = path.kind;
if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id();
+ if !is_ty_alias(qpath);
then {
let a = cx.typeck_results().expr_ty(e);
let b = cx.typeck_results().expr_ty(arg);
diff --git a/src/tools/clippy/clippy_lints/src/utils/author.rs b/src/tools/clippy/clippy_lints/src/utils/author.rs
index bc4adf159..3c2bf5aba 100644
--- a/src/tools/clippy/clippy_lints/src/utils/author.rs
+++ b/src/tools/clippy/clippy_lints/src/utils/author.rs
@@ -304,6 +304,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
kind!("ByteStr(ref {vec})");
chain!(self, "let [{:?}] = **{vec}", vec.value);
},
+ LitKind::CStr(ref vec, _) => {
+ bind!(self, vec);
+ kind!("CStr(ref {vec})");
+ chain!(self, "let [{:?}] = **{vec}", vec.value);
+ },
LitKind::Str(s, _) => {
bind!(self, s);
kind!("Str({s}, _)");
@@ -333,7 +338,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
#[allow(clippy::too_many_lines)]
fn expr(&self, expr: &Binding<&hir::Expr<'_>>) {
- if let Some(higher::While { condition, body }) = higher::While::hir(expr.value) {
+ if let Some(higher::While { condition, body, .. }) = higher::While::hir(expr.value) {
bind!(self, condition, body);
chain!(
self,
@@ -430,7 +435,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
kind!("Unary(UnOp::{op:?}, {inner})");
self.expr(inner);
},
- ExprKind::Lit(ref lit) => {
+ ExprKind::Lit(lit) => {
bind!(self, lit);
kind!("Lit(ref {lit})");
self.lit(lit);
@@ -558,6 +563,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
kind!("InlineAsm(_)");
out!("// unimplemented: `ExprKind::InlineAsm` is not further destructured at the moment");
},
+ ExprKind::OffsetOf(container, ref fields) => {
+ bind!(self, container, fields);
+ kind!("OffsetOf({container}, {fields})");
+ },
ExprKind::Struct(qpath, fields, base) => {
bind!(self, qpath, fields);
opt_bind!(self, base);
diff --git a/src/tools/clippy/clippy_lints/src/utils/conf.rs b/src/tools/clippy/clippy_lints/src/utils/conf.rs
index 896a01af3..f6de66bb5 100644
--- a/src/tools/clippy/clippy_lints/src/utils/conf.rs
+++ b/src/tools/clippy/clippy_lints/src/utils/conf.rs
@@ -174,16 +174,15 @@ macro_rules! define_Conf {
}
}
- #[cfg(feature = "internal")]
pub mod metadata {
- use crate::utils::internal_lints::metadata_collector::ClippyConfiguration;
+ use crate::utils::ClippyConfiguration;
macro_rules! wrap_option {
() => (None);
($x:literal) => (Some($x));
}
- pub(crate) fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
+ pub fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
vec![
$(
{
@@ -277,6 +276,14 @@ define_Conf! {
/// `".."` can be used as part of the list to indicate, that the configured values should be appended to the
/// default configuration of Clippy. By default, any configuration will replace the default value.
(disallowed_names: Vec<String> = super::DEFAULT_DISALLOWED_NAMES.iter().map(ToString::to_string).collect()),
+ /// Lint: SEMICOLON_INSIDE_BLOCK.
+ ///
+ /// Whether to lint only if it's multiline.
+ (semicolon_inside_block_ignore_singleline: bool = false),
+ /// Lint: SEMICOLON_OUTSIDE_BLOCK.
+ ///
+ /// Whether to lint only if it's singleline.
+ (semicolon_outside_block_ignore_multiline: bool = false),
/// Lint: DOC_MARKDOWN.
///
/// The list of words this lint should not consider as identifiers needing ticks. The value
@@ -463,6 +470,10 @@ define_Conf! {
///
/// The maximum byte size a `Future` can have, before it triggers the `clippy::large_futures` lint
(future_size_threshold: u64 = 16 * 1024),
+ /// Lint: UNNECESSARY_BOX_RETURNS.
+ ///
+ /// The byte size a `T` in `Box<T>` can have, below which it triggers the `clippy::unnecessary_box` lint
+ (unnecessary_box_size: u64 = 128),
}
/// Search for the configuration file.
diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs
index 3d0d4a525..7a1cd3eff 100644
--- a/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs
@@ -8,7 +8,11 @@
//! a simple mistake)
use crate::renamed_lints::RENAMED_LINTS;
-use crate::utils::internal_lints::lint_without_lint_pass::{extract_clippy_version_value, is_lint_ref_type};
+use crate::utils::{
+ collect_configs,
+ internal_lints::lint_without_lint_pass::{extract_clippy_version_value, is_lint_ref_type},
+ ClippyConfiguration,
+};
use clippy_utils::diagnostics::span_lint;
use clippy_utils::ty::{match_type, walk_ptrs_ty_depth};
@@ -520,111 +524,6 @@ impl Serialize for ApplicabilityInfo {
}
}
-// ==================================================================
-// Configuration
-// ==================================================================
-#[derive(Debug, Clone, Default)]
-pub struct ClippyConfiguration {
- name: String,
- config_type: &'static str,
- default: String,
- lints: Vec<String>,
- doc: String,
- #[allow(dead_code)]
- deprecation_reason: Option<&'static str>,
-}
-
-impl ClippyConfiguration {
- pub fn new(
- name: &'static str,
- config_type: &'static str,
- default: String,
- doc_comment: &'static str,
- deprecation_reason: Option<&'static str>,
- ) -> Self {
- let (lints, doc) = parse_config_field_doc(doc_comment)
- .unwrap_or_else(|| (vec![], "[ERROR] MALFORMED DOC COMMENT".to_string()));
-
- Self {
- name: to_kebab(name),
- lints,
- doc,
- config_type,
- default,
- deprecation_reason,
- }
- }
-
- fn to_markdown_paragraph(&self) -> String {
- format!(
- "### {}\n{}\n\n**Default Value:** `{}` (`{}`)\n\n{}\n\n",
- self.name,
- self.doc
- .lines()
- .map(|line| line.strip_prefix(" ").unwrap_or(line))
- .join("\n"),
- self.default,
- self.config_type,
- self.lints
- .iter()
- .map(|name| name.to_string().split_whitespace().next().unwrap().to_string())
- .map(|name| format!("* [{name}](https://rust-lang.github.io/rust-clippy/master/index.html#{name})"))
- .join("\n"),
- )
- }
-
- fn to_markdown_table_entry(&self) -> String {
- format!("| [{}](#{}) | `{}` |", self.name, self.name, self.default)
- }
-}
-
-fn collect_configs() -> Vec<ClippyConfiguration> {
- crate::utils::conf::metadata::get_configuration_metadata()
-}
-
-/// This parses the field documentation of the config struct.
-///
-/// ```rust, ignore
-/// parse_config_field_doc(cx, "Lint: LINT_NAME_1, LINT_NAME_2. Papa penguin, papa penguin")
-/// ```
-///
-/// Would yield:
-/// ```rust, ignore
-/// Some(["lint_name_1", "lint_name_2"], "Papa penguin, papa penguin")
-/// ```
-fn parse_config_field_doc(doc_comment: &str) -> Option<(Vec<String>, String)> {
- const DOC_START: &str = " Lint: ";
- if_chain! {
- if doc_comment.starts_with(DOC_START);
- if let Some(split_pos) = doc_comment.find('.');
- then {
- let mut doc_comment = doc_comment.to_string();
- let mut documentation = doc_comment.split_off(split_pos);
-
- // Extract lints
- doc_comment.make_ascii_lowercase();
- let lints: Vec<String> = doc_comment
- .split_off(DOC_START.len())
- .split(", ")
- .map(str::to_string)
- .collect();
-
- // Format documentation correctly
- // split off leading `.` from lint name list and indent for correct formatting
- documentation = documentation.trim_start_matches('.').trim().replace("\n ", "\n ");
-
- Some((lints, documentation))
- } else {
- None
- }
- }
-}
-
-/// Transforms a given `snake_case_string` to a tasty `kebab-case-string`
-fn to_kebab(config_name: &str) -> String {
- config_name.replace('_', "-")
-}
-
impl fmt::Display for ClippyConfiguration {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> fmt::Result {
writeln!(
diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs
index 14ed1368e..008423766 100644
--- a/src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs
@@ -20,7 +20,7 @@ use std::str;
declare_clippy_lint! {
/// ### What it does
- /// Checks for usages of def paths when a diagnostic item or a `LangItem` could be used.
+ /// Checks for usage of def paths when a diagnostic item or a `LangItem` could be used.
///
/// ### Why is this bad?
/// The path for an item is subject to change and is less efficient to look up than a
diff --git a/src/tools/clippy/clippy_lints/src/utils/mod.rs b/src/tools/clippy/clippy_lints/src/utils/mod.rs
index dc647af26..d3ea7cafa 100644
--- a/src/tools/clippy/clippy_lints/src/utils/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/utils/mod.rs
@@ -4,3 +4,143 @@ pub mod dump_hir;
pub mod format_args_collector;
#[cfg(feature = "internal")]
pub mod internal_lints;
+#[cfg(feature = "internal")]
+use itertools::Itertools;
+
+/// Transforms a given `snake_case_string` to a tasty `kebab-case-string`
+fn to_kebab(config_name: &str) -> String {
+ config_name.replace('_', "-")
+}
+
+// ==================================================================
+// Configuration
+// ==================================================================
+#[derive(Debug, Clone, Default)] //~ ERROR no such field
+pub struct ClippyConfiguration {
+ pub name: String,
+ #[allow(dead_code)]
+ config_type: &'static str,
+ pub default: String,
+ pub lints: Vec<String>,
+ pub doc: String,
+ #[allow(dead_code)]
+ deprecation_reason: Option<&'static str>,
+}
+
+impl ClippyConfiguration {
+ pub fn new(
+ name: &'static str,
+ config_type: &'static str,
+ default: String,
+ doc_comment: &'static str,
+ deprecation_reason: Option<&'static str>,
+ ) -> Self {
+ let (lints, doc) = parse_config_field_doc(doc_comment)
+ .unwrap_or_else(|| (vec![], "[ERROR] MALFORMED DOC COMMENT".to_string()));
+
+ Self {
+ name: to_kebab(name),
+ lints,
+ doc,
+ config_type,
+ default,
+ deprecation_reason,
+ }
+ }
+
+ #[cfg(feature = "internal")]
+ fn to_markdown_paragraph(&self) -> String {
+ format!(
+ "### {}\n{}\n\n**Default Value:** `{}` (`{}`)\n\n{}\n\n",
+ self.name,
+ self.doc
+ .lines()
+ .map(|line| line.strip_prefix(" ").unwrap_or(line))
+ .join("\n"),
+ self.default,
+ self.config_type,
+ self.lints
+ .iter()
+ .map(|name| name.to_string().split_whitespace().next().unwrap().to_string())
+ .map(|name| format!("* [{name}](https://rust-lang.github.io/rust-clippy/master/index.html#{name})"))
+ .join("\n"),
+ )
+ }
+
+ #[cfg(feature = "internal")]
+ fn to_markdown_table_entry(&self) -> String {
+ format!("| [{}](#{}) | `{}` |", self.name, self.name, self.default)
+ }
+}
+
+#[cfg(feature = "internal")]
+fn collect_configs() -> Vec<ClippyConfiguration> {
+ crate::utils::conf::metadata::get_configuration_metadata()
+}
+
+/// This parses the field documentation of the config struct.
+///
+/// ```rust, ignore
+/// parse_config_field_doc(cx, "Lint: LINT_NAME_1, LINT_NAME_2. Papa penguin, papa penguin")
+/// ```
+///
+/// Would yield:
+/// ```rust, ignore
+/// Some(["lint_name_1", "lint_name_2"], "Papa penguin, papa penguin")
+/// ```
+fn parse_config_field_doc(doc_comment: &str) -> Option<(Vec<String>, String)> {
+ const DOC_START: &str = " Lint: ";
+ if_chain! {
+ if doc_comment.starts_with(DOC_START);
+ if let Some(split_pos) = doc_comment.find('.');
+ then {
+ let mut doc_comment = doc_comment.to_string();
+ let mut documentation = doc_comment.split_off(split_pos);
+
+ // Extract lints
+ doc_comment.make_ascii_lowercase();
+ let lints: Vec<String> = doc_comment
+ .split_off(DOC_START.len())
+ .split(", ")
+ .map(str::to_string)
+ .collect();
+
+ // Format documentation correctly
+ // split off leading `.` from lint name list and indent for correct formatting
+ documentation = documentation.trim_start_matches('.').trim().replace("\n ", "\n ");
+
+ Some((lints, documentation))
+ } else {
+ None
+ }
+ }
+}
+
+// Shamelessly stolen from find_all (https://github.com/nectariner/find_all)
+pub trait FindAll: Iterator + Sized {
+ fn find_all<P>(&mut self, predicate: P) -> Option<Vec<usize>>
+ where
+ P: FnMut(&Self::Item) -> bool;
+}
+
+impl<I> FindAll for I
+where
+ I: Iterator,
+{
+ fn find_all<P>(&mut self, mut predicate: P) -> Option<Vec<usize>>
+ where
+ P: FnMut(&Self::Item) -> bool,
+ {
+ let mut occurences = Vec::<usize>::default();
+ for (index, element) in self.enumerate() {
+ if predicate(&element) {
+ occurences.push(index);
+ }
+ }
+
+ match occurences.len() {
+ 0 => None,
+ _ => Some(occurences),
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/vec.rs b/src/tools/clippy/clippy_lints/src/vec.rs
index 297a80e57..7329e5081 100644
--- a/src/tools/clippy/clippy_lints/src/vec.rs
+++ b/src/tools/clippy/clippy_lints/src/vec.rs
@@ -84,7 +84,7 @@ impl UselessVec {
let mut applicability = Applicability::MachineApplicable;
let snippet = match *vec_args {
higher::VecArgs::Repeat(elem, len) => {
- if let Some((Constant::Int(len_constant), _)) = constant(cx, cx.typeck_results(), len) {
+ if let Some(Constant::Int(len_constant)) = constant(cx, cx.typeck_results(), len) {
#[expect(clippy::cast_possible_truncation)]
if len_constant as u64 * size_of(cx, elem) > self.too_large_for_stack {
return;
diff --git a/src/tools/clippy/clippy_lints/src/wildcard_imports.rs b/src/tools/clippy/clippy_lints/src/wildcard_imports.rs
index 36f910c98..a9089fba3 100644
--- a/src/tools/clippy/clippy_lints/src/wildcard_imports.rs
+++ b/src/tools/clippy/clippy_lints/src/wildcard_imports.rs
@@ -7,7 +7,7 @@ use rustc_hir::{
def::{DefKind, Res},
Item, ItemKind, PathSegment, UseKind,
};
-use rustc_lint::{LateContext, LateLintPass};
+use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::ty;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::symbol::kw;
@@ -117,6 +117,10 @@ impl_lint_pass!(WildcardImports => [ENUM_GLOB_USE, WILDCARD_IMPORTS]);
impl LateLintPass<'_> for WildcardImports {
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
+ if cx.sess().is_test_crate() {
+ return;
+ }
+
if is_test_module_or_function(cx.tcx, item) {
self.test_modules_deep = self.test_modules_deep.saturating_add(1);
}
diff --git a/src/tools/clippy/clippy_lints/src/write.rs b/src/tools/clippy/clippy_lints/src/write.rs
index d7c94b909..f194dc5d4 100644
--- a/src/tools/clippy/clippy_lints/src/write.rs
+++ b/src/tools/clippy/clippy_lints/src/write.rs
@@ -104,7 +104,7 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for use of `Debug` formatting. The purpose of this
+ /// Checks for usage of `Debug` formatting. The purpose of this
/// lint is to catch debugging remnants.
///
/// ### Why is this bad?
diff --git a/src/tools/clippy/clippy_utils/Cargo.toml b/src/tools/clippy/clippy_utils/Cargo.toml
index 124ebd164..66a5079fa 100644
--- a/src/tools/clippy/clippy_utils/Cargo.toml
+++ b/src/tools/clippy/clippy_utils/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "clippy_utils"
-version = "0.1.70"
+version = "0.1.71"
edition = "2021"
publish = false
diff --git a/src/tools/clippy/clippy_utils/src/ast_utils.rs b/src/tools/clippy/clippy_utils/src/ast_utils.rs
index 1f15598db..8cc01f1ef 100644
--- a/src/tools/clippy/clippy_utils/src/ast_utils.rs
+++ b/src/tools/clippy/clippy_utils/src/ast_utils.rs
@@ -143,7 +143,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
(Paren(l), _) => eq_expr(l, r),
(_, Paren(r)) => eq_expr(l, r),
(Err, Err) => true,
- (Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r),
+ (Try(l), Try(r)) | (Await(l, _), Await(r, _)) => eq_expr(l, r),
(Array(l), Array(r)) => over(l, r, |l, r| eq_expr(l, r)),
(Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)),
(Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value),
diff --git a/src/tools/clippy/clippy_utils/src/attrs.rs b/src/tools/clippy/clippy_utils/src/attrs.rs
index b4ad42a50..49cb9718e 100644
--- a/src/tools/clippy/clippy_utils/src/attrs.rs
+++ b/src/tools/clippy/clippy_utils/src/attrs.rs
@@ -133,7 +133,7 @@ pub fn get_unique_attr<'a>(
let mut unique_attr: Option<&ast::Attribute> = None;
for attr in get_attr(sess, attrs, name) {
if let Some(duplicate) = unique_attr {
- sess.struct_span_err(attr.span, &format!("`{name}` is defined multiple times"))
+ sess.struct_span_err(attr.span, format!("`{name}` is defined multiple times"))
.span_note(duplicate.span, "first definition found here")
.emit();
} else {
diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs
index d3a6929f6..9edaae853 100644
--- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs
+++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs
@@ -117,7 +117,7 @@ fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) {
ExprKind::Unary(UnOp::Deref, e) => (Pat::Str("*"), expr_search_pat(tcx, e).1),
ExprKind::Unary(UnOp::Not, e) => (Pat::Str("!"), expr_search_pat(tcx, e).1),
ExprKind::Unary(UnOp::Neg, e) => (Pat::Str("-"), expr_search_pat(tcx, e).1),
- ExprKind::Lit(ref lit) => lit_search_pat(&lit.node),
+ ExprKind::Lit(lit) => lit_search_pat(&lit.node),
ExprKind::Array(_) | ExprKind::Repeat(..) => (Pat::Str("["), Pat::Str("]")),
ExprKind::Call(e, []) | ExprKind::MethodCall(_, e, [], _) => (expr_search_pat(tcx, e).0, Pat::Str("(")),
ExprKind::Call(first, [.., last])
diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs
index bb8890dca..fb772644c 100644
--- a/src/tools/clippy/clippy_utils/src/consts.rs
+++ b/src/tools/clippy/clippy_utils/src/consts.rs
@@ -1,18 +1,21 @@
#![allow(clippy::float_cmp)]
+use crate::source::{get_source_text, walk_span_to_context};
use crate::{clip, is_direct_expn_of, sext, unsext};
use if_chain::if_chain;
use rustc_ast::ast::{self, LitFloatType, LitKind};
use rustc_data_structures::sync::Lrc;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp};
+use rustc_lexer::tokenize;
use rustc_lint::LateContext;
use rustc_middle::mir;
use rustc_middle::mir::interpret::Scalar;
-use rustc_middle::ty::SubstsRef;
use rustc_middle::ty::{self, EarlyBinder, FloatTy, ScalarInt, Ty, TyCtxt};
+use rustc_middle::ty::{List, SubstsRef};
use rustc_middle::{bug, span_bug};
use rustc_span::symbol::Symbol;
+use rustc_span::SyntaxContext;
use std::cmp::Ordering::{self, Equal};
use std::hash::{Hash, Hasher};
use std::iter;
@@ -210,7 +213,7 @@ pub fn lit_to_mir_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
match *lit {
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
LitKind::Byte(b) => Constant::Int(u128::from(b)),
- LitKind::ByteStr(ref s, _) => Constant::Binary(Lrc::clone(s)),
+ LitKind::ByteStr(ref s, _) | LitKind::CStr(ref s, _) => Constant::Binary(Lrc::clone(s)),
LitKind::Char(c) => Constant::Char(c),
LitKind::Int(n, _) => Constant::Int(n),
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {
@@ -227,27 +230,46 @@ pub fn lit_to_mir_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
}
}
+/// The source of a constant value.
+pub enum ConstantSource {
+ /// The value is determined solely from the expression.
+ Local,
+ /// The value is dependent on a defined constant.
+ Constant,
+}
+impl ConstantSource {
+ pub fn is_local(&self) -> bool {
+ matches!(self, Self::Local)
+ }
+}
+
+/// Attempts to evaluate the expression as a constant.
pub fn constant<'tcx>(
lcx: &LateContext<'tcx>,
typeck_results: &ty::TypeckResults<'tcx>,
e: &Expr<'_>,
-) -> Option<(Constant, bool)> {
- let mut cx = ConstEvalLateContext {
- lcx,
- typeck_results,
- param_env: lcx.param_env,
- needed_resolution: false,
- substs: ty::List::empty(),
- };
- cx.expr(e).map(|cst| (cst, cx.needed_resolution))
+) -> Option<Constant> {
+ ConstEvalLateContext::new(lcx, typeck_results).expr(e)
+}
+
+/// Attempts to evaluate the expression as a constant.
+pub fn constant_with_source<'tcx>(
+ lcx: &LateContext<'tcx>,
+ typeck_results: &ty::TypeckResults<'tcx>,
+ e: &Expr<'_>,
+) -> Option<(Constant, ConstantSource)> {
+ let mut ctxt = ConstEvalLateContext::new(lcx, typeck_results);
+ let res = ctxt.expr(e);
+ res.map(|x| (x, ctxt.source))
}
+/// Attempts to evaluate an expression only if it's value is not dependent on other items.
pub fn constant_simple<'tcx>(
lcx: &LateContext<'tcx>,
typeck_results: &ty::TypeckResults<'tcx>,
e: &Expr<'_>,
) -> Option<Constant> {
- constant(lcx, typeck_results, e).and_then(|(cst, res)| if res { None } else { Some(cst) })
+ constant_with_source(lcx, typeck_results, e).and_then(|(c, s)| s.is_local().then_some(c))
}
pub fn constant_full_int<'tcx>(
@@ -296,35 +318,31 @@ impl Ord for FullInt {
}
}
-/// Creates a `ConstEvalLateContext` from the given `LateContext` and `TypeckResults`.
-pub fn constant_context<'a, 'tcx>(
- lcx: &'a LateContext<'tcx>,
- typeck_results: &'a ty::TypeckResults<'tcx>,
-) -> ConstEvalLateContext<'a, 'tcx> {
- ConstEvalLateContext {
- lcx,
- typeck_results,
- param_env: lcx.param_env,
- needed_resolution: false,
- substs: ty::List::empty(),
- }
-}
-
pub struct ConstEvalLateContext<'a, 'tcx> {
lcx: &'a LateContext<'tcx>,
typeck_results: &'a ty::TypeckResults<'tcx>,
param_env: ty::ParamEnv<'tcx>,
- needed_resolution: bool,
+ source: ConstantSource,
substs: SubstsRef<'tcx>,
}
impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
+ fn new(lcx: &'a LateContext<'tcx>, typeck_results: &'a ty::TypeckResults<'tcx>) -> Self {
+ Self {
+ lcx,
+ typeck_results,
+ param_env: lcx.param_env,
+ source: ConstantSource::Local,
+ substs: List::empty(),
+ }
+ }
+
/// Simple constant folding: Insert an expression, get a constant or none.
pub fn expr(&mut self, e: &Expr<'_>) -> Option<Constant> {
match e.kind {
ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id, self.typeck_results.expr_ty(e)),
ExprKind::Block(block, _) => self.block(block),
- ExprKind::Lit(ref lit) => {
+ ExprKind::Lit(lit) => {
if is_direct_expn_of(e.span, "cfg").is_some() {
None
} else {
@@ -450,18 +468,12 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
let result = self
.lcx
.tcx
- .const_eval_resolve(
- self.param_env,
- mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs),
- None,
- )
+ .const_eval_resolve(self.param_env, mir::UnevaluatedConst::new(def_id, substs), None)
.ok()
.map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty))?;
- let result = miri_to_const(self.lcx.tcx, result);
- if result.is_some() {
- self.needed_resolution = true;
- }
- result
+ let result = miri_to_const(self.lcx.tcx, result)?;
+ self.source = ConstantSource::Constant;
+ Some(result)
},
// FIXME: cover all usable cases.
_ => None,
@@ -495,8 +507,33 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
/// A block can only yield a constant if it only has one constant expression.
fn block(&mut self, block: &Block<'_>) -> Option<Constant> {
- if block.stmts.is_empty() {
- block.expr.as_ref().and_then(|b| self.expr(b))
+ if block.stmts.is_empty()
+ && let Some(expr) = block.expr
+ {
+ // Try to detect any `cfg`ed statements or empty macro expansions.
+ let span = block.span.data();
+ if span.ctxt == SyntaxContext::root() {
+ if let Some(expr_span) = walk_span_to_context(expr.span, span.ctxt)
+ && let expr_lo = expr_span.lo()
+ && expr_lo >= span.lo
+ && let Some(src) = get_source_text(self.lcx, span.lo..expr_lo)
+ && let Some(src) = src.as_str()
+ {
+ use rustc_lexer::TokenKind::{Whitespace, LineComment, BlockComment, Semi, OpenBrace};
+ if !tokenize(src)
+ .map(|t| t.kind)
+ .filter(|t| !matches!(t, Whitespace | LineComment { .. } | BlockComment { .. } | Semi))
+ .eq([OpenBrace])
+ {
+ self.source = ConstantSource::Constant;
+ }
+ } else {
+ // Unable to access the source. Assume a non-local dependency.
+ self.source = ConstantSource::Constant;
+ }
+ }
+
+ self.expr(expr)
} else {
None
}
diff --git a/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs b/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs
index 28c857170..3df40942e 100644
--- a/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs
+++ b/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs
@@ -218,7 +218,8 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
| ExprKind::AddrOf(..)
| ExprKind::Struct(..)
| ExprKind::Repeat(..)
- | ExprKind::Block(Block { stmts: [], .. }, _) => (),
+ | ExprKind::Block(Block { stmts: [], .. }, _)
+ | ExprKind::OffsetOf(..) => (),
// Assignment might be to a local defined earlier, so don't eagerly evaluate.
// Blocks with multiple statements might be expensive, so don't eagerly evaluate.
diff --git a/src/tools/clippy/clippy_utils/src/higher.rs b/src/tools/clippy/clippy_utils/src/higher.rs
index 50bef3709..a61e4c380 100644
--- a/src/tools/clippy/clippy_utils/src/higher.rs
+++ b/src/tools/clippy/clippy_utils/src/higher.rs
@@ -311,6 +311,8 @@ pub struct While<'hir> {
pub condition: &'hir Expr<'hir>,
/// `while` loop body
pub body: &'hir Expr<'hir>,
+ /// Span of the loop header
+ pub span: Span,
}
impl<'hir> While<'hir> {
@@ -336,10 +338,10 @@ impl<'hir> While<'hir> {
},
_,
LoopSource::While,
- _,
+ span,
) = expr.kind
{
- return Some(Self { condition, body });
+ return Some(Self { condition, body, span });
}
None
}
diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs
index 3ee714782..a49246a78 100644
--- a/src/tools/clippy/clippy_utils/src/hir_utils.rs
+++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs
@@ -1,6 +1,7 @@
use crate::consts::constant_simple;
use crate::macros::macro_backtrace;
-use crate::source::snippet_opt;
+use crate::source::{get_source_text, snippet_opt, walk_span_to_context, SpanRange};
+use crate::tokenize_with_text;
use rustc_ast::ast::InlineAsmTemplatePiece;
use rustc_data_structures::fx::FxHasher;
use rustc_hir::def::Res;
@@ -13,8 +14,9 @@ use rustc_hir::{
use rustc_lexer::{tokenize, TokenKind};
use rustc_lint::LateContext;
use rustc_middle::ty::TypeckResults;
-use rustc_span::{sym, Symbol};
+use rustc_span::{sym, BytePos, ExpnKind, MacroKind, Symbol, SyntaxContext};
use std::hash::{Hash, Hasher};
+use std::ops::Range;
/// Callback that is called when two expressions are not equal in the sense of `SpanlessEq`, but
/// other conditions would make them equal.
@@ -65,6 +67,8 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
pub fn inter_expr(&mut self) -> HirEqInterExpr<'_, 'a, 'tcx> {
HirEqInterExpr {
inner: self,
+ left_ctxt: SyntaxContext::root(),
+ right_ctxt: SyntaxContext::root(),
locals: HirIdMap::default(),
}
}
@@ -92,6 +96,8 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
pub struct HirEqInterExpr<'a, 'b, 'tcx> {
inner: &'a mut SpanlessEq<'b, 'tcx>,
+ left_ctxt: SyntaxContext,
+ right_ctxt: SyntaxContext,
// When binding are declared, the binding ID in the left expression is mapped to the one on the
// right. For example, when comparing `{ let x = 1; x + 2 }` and `{ let y = 1; y + 2 }`,
@@ -126,52 +132,88 @@ impl HirEqInterExpr<'_, '_, '_> {
}
/// Checks whether two blocks are the same.
+ #[expect(clippy::similar_names)]
fn eq_block(&mut self, left: &Block<'_>, right: &Block<'_>) -> bool {
- match (left.stmts, left.expr, right.stmts, right.expr) {
- ([], None, [], None) => {
- // For empty blocks, check to see if the tokens are equal. This will catch the case where a macro
- // expanded to nothing, or the cfg attribute was used.
- let (Some(left), Some(right)) = (
- snippet_opt(self.inner.cx, left.span),
- snippet_opt(self.inner.cx, right.span),
- ) else { return true };
- let mut left_pos = 0;
- let left = tokenize(&left)
- .map(|t| {
- let end = left_pos + t.len as usize;
- let s = &left[left_pos..end];
- left_pos = end;
- (t, s)
- })
- .filter(|(t, _)| {
- !matches!(
- t.kind,
- TokenKind::LineComment { .. } | TokenKind::BlockComment { .. } | TokenKind::Whitespace
- )
- })
- .map(|(_, s)| s);
- let mut right_pos = 0;
- let right = tokenize(&right)
- .map(|t| {
- let end = right_pos + t.len as usize;
- let s = &right[right_pos..end];
- right_pos = end;
- (t, s)
- })
- .filter(|(t, _)| {
- !matches!(
- t.kind,
- TokenKind::LineComment { .. } | TokenKind::BlockComment { .. } | TokenKind::Whitespace
- )
- })
- .map(|(_, s)| s);
- left.eq(right)
- },
- _ => {
- over(left.stmts, right.stmts, |l, r| self.eq_stmt(l, r))
- && both(&left.expr, &right.expr, |l, r| self.eq_expr(l, r))
- },
+ use TokenKind::{BlockComment, LineComment, Semi, Whitespace};
+ if left.stmts.len() != right.stmts.len() {
+ return false;
+ }
+ let lspan = left.span.data();
+ let rspan = right.span.data();
+ if lspan.ctxt != SyntaxContext::root() && rspan.ctxt != SyntaxContext::root() {
+ // Don't try to check in between statements inside macros.
+ return over(left.stmts, right.stmts, |left, right| self.eq_stmt(left, right))
+ && both(&left.expr, &right.expr, |left, right| self.eq_expr(left, right));
+ }
+ if lspan.ctxt != rspan.ctxt {
+ return false;
+ }
+
+ let mut lstart = lspan.lo;
+ let mut rstart = rspan.lo;
+
+ for (left, right) in left.stmts.iter().zip(right.stmts) {
+ if !self.eq_stmt(left, right) {
+ return false;
+ }
+
+ // Try to detect any `cfg`ed statements or empty macro expansions.
+ let Some(lstmt_span) = walk_span_to_context(left.span, lspan.ctxt) else {
+ return false;
+ };
+ let Some(rstmt_span) = walk_span_to_context(right.span, rspan.ctxt) else {
+ return false;
+ };
+ let lstmt_span = lstmt_span.data();
+ let rstmt_span = rstmt_span.data();
+
+ if lstmt_span.lo < lstart && rstmt_span.lo < rstart {
+ // Can happen when macros expand to multiple statements, or rearrange statements.
+ // Nothing in between the statements to check in this case.
+ continue;
+ }
+ if lstmt_span.lo < lstart || rstmt_span.lo < rstart {
+ // Only one of the blocks had a weird macro.
+ return false;
+ }
+ if !eq_span_tokens(self.inner.cx, lstart..lstmt_span.lo, rstart..rstmt_span.lo, |t| {
+ !matches!(t, Whitespace | LineComment { .. } | BlockComment { .. } | Semi)
+ }) {
+ return false;
+ }
+
+ lstart = lstmt_span.hi;
+ rstart = rstmt_span.hi;
+ }
+
+ let (lend, rend) = match (left.expr, right.expr) {
+ (Some(left), Some(right)) => {
+ if !self.eq_expr(left, right) {
+ return false;
+ }
+ let Some(lexpr_span) = walk_span_to_context(left.span, lspan.ctxt) else {
+ return false;
+ };
+ let Some(rexpr_span) = walk_span_to_context(right.span, rspan.ctxt) else {
+ return false;
+ };
+ (lexpr_span.lo(), rexpr_span.lo())
+ },
+ (None, None) => (lspan.hi, rspan.hi),
+ (Some(_), None) | (None, Some(_)) => return false,
+ };
+
+ if lend < lstart && rend < rstart {
+ // Can happen when macros rearrange the input.
+ // Nothing in between the statements to check in this case.
+ return true;
+ } else if lend < lstart || rend < rstart {
+ // Only one of the blocks had a weird macro
+ return false;
}
+ eq_span_tokens(self.inner.cx, lstart..lend, rstart..rend, |t| {
+ !matches!(t, Whitespace | LineComment { .. } | BlockComment { .. } | Semi)
+ })
}
fn should_ignore(&mut self, expr: &Expr<'_>) -> bool {
@@ -207,7 +249,7 @@ impl HirEqInterExpr<'_, '_, '_> {
#[expect(clippy::similar_names)]
pub fn eq_expr(&mut self, left: &Expr<'_>, right: &Expr<'_>) -> bool {
- if !self.inner.allow_side_effects && left.span.ctxt() != right.span.ctxt() {
+ if !self.check_ctxt(left.span.ctxt(), right.span.ctxt()) {
return false;
}
@@ -301,6 +343,9 @@ impl HirEqInterExpr<'_, '_, '_> {
(&ExprKind::Unary(l_op, le), &ExprKind::Unary(r_op, re)) => l_op == r_op && self.eq_expr(le, re),
(&ExprKind::Array(l), &ExprKind::Array(r)) => self.eq_exprs(l, r),
(&ExprKind::DropTemps(le), &ExprKind::DropTemps(re)) => self.eq_expr(le, re),
+ (&ExprKind::OffsetOf(l_container, l_fields), &ExprKind::OffsetOf(r_container, r_fields)) => {
+ self.eq_ty(l_container, r_container) && over(l_fields, r_fields, |l, r| l.name == r.name)
+ },
_ => false,
};
(is_eq && (!self.should_ignore(left) || !self.should_ignore(right)))
@@ -437,6 +482,45 @@ impl HirEqInterExpr<'_, '_, '_> {
fn eq_type_binding(&mut self, left: &TypeBinding<'_>, right: &TypeBinding<'_>) -> bool {
left.ident.name == right.ident.name && self.eq_ty(left.ty(), right.ty())
}
+
+ fn check_ctxt(&mut self, left: SyntaxContext, right: SyntaxContext) -> bool {
+ if self.left_ctxt == left && self.right_ctxt == right {
+ return true;
+ } else if self.left_ctxt == left || self.right_ctxt == right {
+ // Only one context has changed. This can only happen if the two nodes are written differently.
+ return false;
+ } else if left != SyntaxContext::root() {
+ let mut left_data = left.outer_expn_data();
+ let mut right_data = right.outer_expn_data();
+ loop {
+ use TokenKind::{BlockComment, LineComment, Whitespace};
+ if left_data.macro_def_id != right_data.macro_def_id
+ || (matches!(left_data.kind, ExpnKind::Macro(MacroKind::Bang, name) if name == sym::cfg)
+ && !eq_span_tokens(self.inner.cx, left_data.call_site, right_data.call_site, |t| {
+ !matches!(t, Whitespace | LineComment { .. } | BlockComment { .. })
+ }))
+ {
+ // Either a different chain of macro calls, or different arguments to the `cfg` macro.
+ return false;
+ }
+ let left_ctxt = left_data.call_site.ctxt();
+ let right_ctxt = right_data.call_site.ctxt();
+ if left_ctxt == SyntaxContext::root() && right_ctxt == SyntaxContext::root() {
+ break;
+ }
+ if left_ctxt == SyntaxContext::root() || right_ctxt == SyntaxContext::root() {
+ // Different lengths for the expansion stack. This can only happen if nodes are written differently,
+ // or shouldn't be compared to start with.
+ return false;
+ }
+ left_data = left_ctxt.outer_expn_data();
+ right_data = right_ctxt.outer_expn_data();
+ }
+ }
+ self.left_ctxt = left;
+ self.right_ctxt = right;
+ true
+ }
}
/// Some simple reductions like `{ return }` => `return`
@@ -701,6 +785,12 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
}
}
},
+ ExprKind::OffsetOf(container, fields) => {
+ self.hash_ty(container);
+ for field in fields {
+ self.hash_name(field.name);
+ }
+ },
ExprKind::Let(Let { pat, init, ty, .. }) => {
self.hash_expr(init);
if let Some(ty) = ty {
@@ -709,7 +799,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
self.hash_pat(pat);
},
ExprKind::Err(_) => {},
- ExprKind::Lit(ref l) => {
+ ExprKind::Lit(l) => {
l.node.hash(&mut self.s);
},
ExprKind::Loop(b, ref i, ..) => {
@@ -1029,3 +1119,34 @@ pub fn hash_expr(cx: &LateContext<'_>, e: &Expr<'_>) -> u64 {
h.hash_expr(e);
h.finish()
}
+
+#[expect(clippy::similar_names)]
+fn eq_span_tokens(
+ cx: &LateContext<'_>,
+ left: impl SpanRange,
+ right: impl SpanRange,
+ pred: impl Fn(TokenKind) -> bool,
+) -> bool {
+ fn f(cx: &LateContext<'_>, left: Range<BytePos>, right: Range<BytePos>, pred: impl Fn(TokenKind) -> bool) -> bool {
+ if let Some(lsrc) = get_source_text(cx, left)
+ && let Some(lsrc) = lsrc.as_str()
+ && let Some(rsrc) = get_source_text(cx, right)
+ && let Some(rsrc) = rsrc.as_str()
+ {
+ let pred = |t: &(_, _)| pred(t.0);
+ let map = |(_, x)| x;
+
+ let ltok = tokenize_with_text(lsrc)
+ .filter(pred)
+ .map(map);
+ let rtok = tokenize_with_text(rsrc)
+ .filter(pred)
+ .map(map);
+ ltok.eq(rtok)
+ } else {
+ // Unable to access the source. Conservatively assume the blocks aren't equal.
+ false
+ }
+ }
+ f(cx, left.into_range(), right.into_range(), pred)
+}
diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs
index 6b677df46..8c883445a 100644
--- a/src/tools/clippy/clippy_utils/src/lib.rs
+++ b/src/tools/clippy/clippy_utils/src/lib.rs
@@ -1,5 +1,6 @@
#![feature(array_chunks)]
#![feature(box_patterns)]
+#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(lint_reasons)]
#![feature(never_type)]
@@ -76,6 +77,7 @@ use std::sync::OnceLock;
use std::sync::{Mutex, MutexGuard};
use if_chain::if_chain;
+use itertools::Itertools;
use rustc_ast::ast::{self, LitKind, RangeLimits};
use rustc_ast::Attribute;
use rustc_data_structures::fx::FxHashMap;
@@ -86,10 +88,10 @@ use rustc_hir::hir_id::{HirIdMap, HirIdSet};
use rustc_hir::intravisit::{walk_expr, FnKind, Visitor};
use rustc_hir::LangItem::{OptionNone, ResultErr, ResultOk};
use rustc_hir::{
- self as hir, def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Closure, Constness, Destination,
- Expr, ExprKind, FnDecl, HirId, Impl, ImplItem, ImplItemKind, ImplItemRef, IsAsync, Item, ItemKind, LangItem, Local,
+ self as hir, def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Closure, Destination, Expr,
+ ExprKind, FnDecl, HirId, Impl, ImplItem, ImplItemKind, ImplItemRef, IsAsync, Item, ItemKind, LangItem, Local,
MatchSource, Mutability, Node, OwnerId, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind,
- TraitItem, TraitItemKind, TraitItemRef, TraitRef, TyKind, UnOp,
+ TraitItem, TraitItemRef, TraitRef, TyKind, UnOp,
};
use rustc_lexer::{tokenize, TokenKind};
use rustc_lint::{LateContext, Level, Lint, LintContext};
@@ -197,31 +199,7 @@ pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<
/// }
/// ```
pub fn in_constant(cx: &LateContext<'_>, id: HirId) -> bool {
- let parent_id = cx.tcx.hir().get_parent_item(id).def_id;
- match cx.tcx.hir().get_by_def_id(parent_id) {
- Node::Item(&Item {
- kind: ItemKind::Const(..) | ItemKind::Static(..) | ItemKind::Enum(..),
- ..
- })
- | Node::TraitItem(&TraitItem {
- kind: TraitItemKind::Const(..),
- ..
- })
- | Node::ImplItem(&ImplItem {
- kind: ImplItemKind::Const(..),
- ..
- })
- | Node::AnonConst(_) => true,
- Node::Item(&Item {
- kind: ItemKind::Fn(ref sig, ..),
- ..
- })
- | Node::ImplItem(&ImplItem {
- kind: ImplItemKind::Fn(ref sig, _),
- ..
- }) => sig.header.constness == Constness::Const,
- _ => false,
- }
+ cx.tcx.hir().is_inside_const_context(id)
}
/// Checks if a `Res` refers to a constructor of a `LangItem`
@@ -306,6 +284,15 @@ pub fn is_wild(pat: &Pat<'_>) -> bool {
matches!(pat.kind, PatKind::Wild)
}
+/// Checks if the given `QPath` belongs to a type alias.
+pub fn is_ty_alias(qpath: &QPath<'_>) -> bool {
+ match *qpath {
+ QPath::Resolved(_, path) => matches!(path.res, Res::Def(DefKind::TyAlias | DefKind::AssocTy, ..)),
+ QPath::TypeRelative(ty, _) if let TyKind::Path(qpath) = ty.kind => { is_ty_alias(&qpath) },
+ _ => false,
+ }
+}
+
/// Checks if the method call given in `expr` belongs to the given trait.
/// This is a deprecated function, consider using [`is_trait_method`].
pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) -> bool {
@@ -846,7 +833,7 @@ pub fn is_default_equivalent(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
},
ExprKind::Tup(items) | ExprKind::Array(items) => items.iter().all(|x| is_default_equivalent(cx, x)),
ExprKind::Repeat(x, ArrayLen::Body(len)) => if_chain! {
- if let ExprKind::Lit(ref const_lit) = cx.tcx.hir().body(len.body).value.kind;
+ if let ExprKind::Lit(const_lit) = cx.tcx.hir().body(len.body).value.kind;
if let LitKind::Int(v, _) = const_lit.node;
if v <= 32 && is_default_equivalent(cx, x);
then {
@@ -875,7 +862,7 @@ fn is_default_equivalent_from(cx: &LateContext<'_>, from_func: &Expr<'_>, arg: &
}) => return sym.is_empty() && is_path_lang_item(cx, ty, LangItem::String),
ExprKind::Array([]) => return is_path_diagnostic_item(cx, ty, sym::Vec),
ExprKind::Repeat(_, ArrayLen::Body(len)) => {
- if let ExprKind::Lit(ref const_lit) = cx.tcx.hir().body(len.body).value.kind &&
+ if let ExprKind::Lit(const_lit) = cx.tcx.hir().body(len.body).value.kind &&
let LitKind::Int(v, _) = const_lit.node
{
return v == 0 && is_path_diagnostic_item(cx, ty, sym::Vec);
@@ -1512,7 +1499,7 @@ pub fn is_range_full(cx: &LateContext<'_>, expr: &Expr<'_>, container_path: Opti
&& let const_val = cx.tcx.valtree_to_const_val((bnd_ty, min_val.to_valtree()))
&& let min_const_kind = ConstantKind::from_value(const_val, bnd_ty)
&& let Some(min_const) = miri_to_const(cx.tcx, min_const_kind)
- && let Some((start_const, _)) = constant(cx, cx.typeck_results(), start)
+ && let Some(start_const) = constant(cx, cx.typeck_results(), start)
{
start_const == min_const
} else {
@@ -1528,7 +1515,7 @@ pub fn is_range_full(cx: &LateContext<'_>, expr: &Expr<'_>, container_path: Opti
&& let const_val = cx.tcx.valtree_to_const_val((bnd_ty, max_val.to_valtree()))
&& let max_const_kind = ConstantKind::from_value(const_val, bnd_ty)
&& let Some(max_const) = miri_to_const(cx.tcx, max_const_kind)
- && let Some((end_const, _)) = constant(cx, cx.typeck_results(), end)
+ && let Some(end_const) = constant(cx, cx.typeck_results(), end)
{
end_const == max_const
} else {
@@ -1560,7 +1547,7 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool
return true;
}
let enclosing_body = cx.tcx.hir().enclosing_body_owner(e.hir_id);
- if let Some((Constant::Int(v), _)) = constant(cx, cx.tcx.typeck(enclosing_body), e) {
+ if let Some(Constant::Int(v)) = constant(cx, cx.tcx.typeck(enclosing_body), e) {
return value == v;
}
false
@@ -1569,7 +1556,7 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool
/// Checks whether the given expression is a constant literal of the given value.
pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool {
// FIXME: use constant folding
- if let ExprKind::Lit(ref spanned) = expr.kind {
+ if let ExprKind::Lit(spanned) = expr.kind {
if let LitKind::Int(v, _) = spanned.node {
return v == value;
}
@@ -2165,10 +2152,7 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool {
.predicates
.iter()
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
- traits::impossible_predicates(
- cx.tcx,
- traits::elaborate(cx.tcx, predicates).collect::<Vec<_>>(),
- )
+ traits::impossible_predicates(cx.tcx, traits::elaborate(cx.tcx, predicates).collect::<Vec<_>>())
}
/// Returns the `DefId` of the callee if the given expression is a function or method call.
@@ -2233,8 +2217,12 @@ pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<S
None
}
-/// returns list of all pairs (a, b) from `exprs` such that `eq(a, b)`
-/// `hash` must be comformed with `eq`
+/// Returns list of all pairs `(a, b)` where `eq(a, b) == true`
+/// and `a` is before `b` in `exprs` for all `a` and `b` in
+/// `exprs`
+///
+/// Given functions `eq` and `hash` such that `eq(a, b) == true`
+/// implies `hash(a) == hash(b)`
pub fn search_same<T, Hash, Eq>(exprs: &[T], hash: Hash, eq: Eq) -> Vec<(&T, &T)>
where
Hash: Fn(&T) -> u64,
@@ -2503,6 +2491,17 @@ pub fn walk_to_expr_usage<'tcx, T>(
None
}
+/// Tokenizes the input while keeping the text associated with each token.
+pub fn tokenize_with_text(s: &str) -> impl Iterator<Item = (TokenKind, &str)> {
+ let mut pos = 0;
+ tokenize(s).map(move |t| {
+ let end = pos + t.len;
+ let range = pos as usize..end as usize;
+ pos = end;
+ (t.kind, s.get(range).unwrap_or_default())
+ })
+}
+
/// Checks whether a given span has any comment token
/// This checks for all types of comment: line "//", block "/**", doc "///" "//!"
pub fn span_contains_comment(sm: &SourceMap, span: Span) -> bool {
@@ -2519,23 +2518,11 @@ pub fn span_contains_comment(sm: &SourceMap, span: Span) -> bool {
/// Comments are returned wrapped with their relevant delimiters
pub fn span_extract_comment(sm: &SourceMap, span: Span) -> String {
let snippet = sm.span_to_snippet(span).unwrap_or_default();
- let mut comments_buf: Vec<String> = Vec::new();
- let mut index: usize = 0;
-
- for token in tokenize(&snippet) {
- let token_range = index..(index + token.len as usize);
- index += token.len as usize;
- match token.kind {
- TokenKind::BlockComment { .. } | TokenKind::LineComment { .. } => {
- if let Some(comment) = snippet.get(token_range) {
- comments_buf.push(comment.to_string());
- }
- },
- _ => (),
- }
- }
-
- comments_buf.join("\n")
+ let res = tokenize_with_text(&snippet)
+ .filter(|(t, _)| matches!(t, TokenKind::BlockComment { .. } | TokenKind::LineComment { .. }))
+ .map(|(_, s)| s)
+ .join("\n");
+ res
}
pub fn span_find_starting_semi(sm: &SourceMap, span: Span) -> Span {
diff --git a/src/tools/clippy/clippy_utils/src/macros.rs b/src/tools/clippy/clippy_utils/src/macros.rs
index 62d388a5e..e4a4936ff 100644
--- a/src/tools/clippy/clippy_utils/src/macros.rs
+++ b/src/tools/clippy/clippy_utils/src/macros.rs
@@ -362,7 +362,7 @@ thread_local! {
/// able to access the many features of a [`LateContext`].
///
/// A thread local is used because [`FormatArgs`] is `!Send` and `!Sync`, we are making an
- /// assumption that the early pass the populates the map and the later late passes will all be
+ /// assumption that the early pass that populates the map and the later late passes will all be
/// running on the same thread.
static AST_FORMAT_ARGS: RefCell<FxHashMap<Span, FormatArgs>> = {
static CALLED: AtomicBool = AtomicBool::new(false);
diff --git a/src/tools/clippy/clippy_utils/src/paths.rs b/src/tools/clippy/clippy_utils/src/paths.rs
index 9be2d0eae..0f0792fda 100644
--- a/src/tools/clippy/clippy_utils/src/paths.rs
+++ b/src/tools/clippy/clippy_utils/src/paths.rs
@@ -159,3 +159,7 @@ pub const WEAK_RC: [&str; 3] = ["alloc", "rc", "Weak"];
pub const PTR_NON_NULL: [&str; 4] = ["core", "ptr", "non_null", "NonNull"];
pub const INSTANT_NOW: [&str; 4] = ["std", "time", "Instant", "now"];
pub const INSTANT: [&str; 3] = ["std", "time", "Instant"];
+pub const VEC_IS_EMPTY: [&str; 4] = ["alloc", "vec", "Vec", "is_empty"];
+pub const VEC_POP: [&str; 4] = ["alloc", "vec", "Vec", "pop"];
+pub const OPTION_UNWRAP: [&str; 4] = ["core", "option", "Option", "unwrap"];
+pub const OPTION_EXPECT: [&str; 4] = ["core", "option", "Option", "expect"];
diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
index 354b6d71a..c0d2c835d 100644
--- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
+++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
@@ -194,7 +194,9 @@ fn check_rvalue<'tcx>(
))
}
},
- Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) | Rvalue::ShallowInitBox(_, _) => Ok(()),
+ Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(_), _) | Rvalue::ShallowInitBox(_, _) => {
+ Ok(())
+ },
Rvalue::UnaryOp(_, operand) => {
let ty = operand.ty(body, tcx);
if ty.is_integral() || ty.is_bool() {
diff --git a/src/tools/clippy/clippy_utils/src/source.rs b/src/tools/clippy/clippy_utils/src/source.rs
index 62fa37660..0f6029064 100644
--- a/src/tools/clippy/clippy_utils/src/source.rs
+++ b/src/tools/clippy/clippy_utils/src/source.rs
@@ -2,14 +2,64 @@
#![allow(clippy::module_name_repetitions)]
+use rustc_data_structures::sync::Lrc;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LintContext};
use rustc_session::Session;
-use rustc_span::hygiene;
use rustc_span::source_map::{original_sp, SourceMap};
+use rustc_span::{hygiene, SourceFile};
use rustc_span::{BytePos, Pos, Span, SpanData, SyntaxContext, DUMMY_SP};
use std::borrow::Cow;
+use std::ops::Range;
+
+/// A type which can be converted to the range portion of a `Span`.
+pub trait SpanRange {
+ fn into_range(self) -> Range<BytePos>;
+}
+impl SpanRange for Span {
+ fn into_range(self) -> Range<BytePos> {
+ let data = self.data();
+ data.lo..data.hi
+ }
+}
+impl SpanRange for SpanData {
+ fn into_range(self) -> Range<BytePos> {
+ self.lo..self.hi
+ }
+}
+impl SpanRange for Range<BytePos> {
+ fn into_range(self) -> Range<BytePos> {
+ self
+ }
+}
+
+pub struct SourceFileRange {
+ pub sf: Lrc<SourceFile>,
+ pub range: Range<usize>,
+}
+impl SourceFileRange {
+ /// Attempts to get the text from the source file. This can fail if the source text isn't
+ /// loaded.
+ pub fn as_str(&self) -> Option<&str> {
+ self.sf.src.as_ref().and_then(|x| x.get(self.range.clone()))
+ }
+}
+
+/// Gets the source file, and range in the file, of the given span. Returns `None` if the span
+/// extends through multiple files, or is malformed.
+pub fn get_source_text(cx: &impl LintContext, sp: impl SpanRange) -> Option<SourceFileRange> {
+ fn f(sm: &SourceMap, sp: Range<BytePos>) -> Option<SourceFileRange> {
+ let start = sm.lookup_byte_offset(sp.start);
+ let end = sm.lookup_byte_offset(sp.end);
+ if !Lrc::ptr_eq(&start.sf, &end.sf) || start.pos > end.pos {
+ return None;
+ }
+ let range = start.pos.to_usize()..end.pos.to_usize();
+ Some(SourceFileRange { sf: start.sf, range })
+ }
+ f(cx.sess().source_map(), sp.into_range())
+}
/// Like `snippet_block`, but add braces if the expr is not an `ExprKind::Block`.
pub fn expr_block<T: LintContext>(
diff --git a/src/tools/clippy/clippy_utils/src/sugg.rs b/src/tools/clippy/clippy_utils/src/sugg.rs
index a5a4a921d..14f7f0301 100644
--- a/src/tools/clippy/clippy_utils/src/sugg.rs
+++ b/src/tools/clippy/clippy_utils/src/sugg.rs
@@ -139,6 +139,7 @@ impl<'a> Sugg<'a> {
| hir::ExprKind::Field(..)
| hir::ExprKind::Index(..)
| hir::ExprKind::InlineAsm(..)
+ | hir::ExprKind::OffsetOf(..)
| hir::ExprKind::ConstBlock(..)
| hir::ExprKind::Lit(..)
| hir::ExprKind::Loop(..)
@@ -161,8 +162,9 @@ impl<'a> Sugg<'a> {
get_snippet(lhs.span),
get_snippet(rhs.span),
),
- hir::ExprKind::Cast(lhs, ty) => Sugg::BinOp(AssocOp::As, get_snippet(lhs.span), get_snippet(ty.span)),
- hir::ExprKind::Type(lhs, ty) => Sugg::BinOp(AssocOp::Colon, get_snippet(lhs.span), get_snippet(ty.span)),
+ hir::ExprKind::Cast(lhs, ty) |
+ //FIXME(chenyukang), remove this after type ascription is removed from AST
+ hir::ExprKind::Type(lhs, ty) => Sugg::BinOp(AssocOp::As, get_snippet(lhs.span), get_snippet(ty.span)),
}
}
@@ -197,6 +199,7 @@ impl<'a> Sugg<'a> {
| ast::ExprKind::ForLoop(..)
| ast::ExprKind::Index(..)
| ast::ExprKind::InlineAsm(..)
+ | ast::ExprKind::OffsetOf(..)
| ast::ExprKind::ConstBlock(..)
| ast::ExprKind::Lit(..)
| ast::ExprKind::IncludedBytes(..)
@@ -251,13 +254,10 @@ impl<'a> Sugg<'a> {
snippet_with_context(cx, lhs.span, ctxt, default, app).0,
snippet_with_context(cx, rhs.span, ctxt, default, app).0,
),
- ast::ExprKind::Cast(ref lhs, ref ty) => Sugg::BinOp(
- AssocOp::As,
- snippet_with_context(cx, lhs.span, ctxt, default, app).0,
- snippet_with_context(cx, ty.span, ctxt, default, app).0,
- ),
+ ast::ExprKind::Cast(ref lhs, ref ty) |
+ //FIXME(chenyukang), remove this after type ascription is removed from AST
ast::ExprKind::Type(ref lhs, ref ty) => Sugg::BinOp(
- AssocOp::Colon,
+ AssocOp::As,
snippet_with_context(cx, lhs.span, ctxt, default, app).0,
snippet_with_context(cx, ty.span, ctxt, default, app).0,
),
@@ -390,7 +390,6 @@ fn binop_to_string(op: AssocOp, lhs: &str, rhs: &str) -> String {
AssocOp::As => format!("{lhs} as {rhs}"),
AssocOp::DotDot => format!("{lhs}..{rhs}"),
AssocOp::DotDotEq => format!("{lhs}..={rhs}"),
- AssocOp::Colon => format!("{lhs}: {rhs}"),
}
}
@@ -600,13 +599,13 @@ enum Associativity {
#[must_use]
fn associativity(op: AssocOp) -> Associativity {
use rustc_ast::util::parser::AssocOp::{
- Add, As, Assign, AssignOp, BitAnd, BitOr, BitXor, Colon, Divide, DotDot, DotDotEq, Equal, Greater,
- GreaterEqual, LAnd, LOr, Less, LessEqual, Modulus, Multiply, NotEqual, ShiftLeft, ShiftRight, Subtract,
+ Add, As, Assign, AssignOp, BitAnd, BitOr, BitXor, Divide, DotDot, DotDotEq, Equal, Greater, GreaterEqual, LAnd,
+ LOr, Less, LessEqual, Modulus, Multiply, NotEqual, ShiftLeft, ShiftRight, Subtract,
};
match op {
Assign | AssignOp(_) => Associativity::Right,
- Add | BitAnd | BitOr | BitXor | LAnd | LOr | Multiply | As | Colon => Associativity::Both,
+ Add | BitAnd | BitOr | BitXor | LAnd | LOr | Multiply | As => Associativity::Both,
Divide | Equal | Greater | GreaterEqual | Less | LessEqual | Modulus | NotEqual | ShiftLeft | ShiftRight
| Subtract => Associativity::Left,
DotDot | DotDotEq => Associativity::None,
diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs
index 9449f0b55..7b4ed77e8 100644
--- a/src/tools/clippy/clippy_utils/src/ty.rs
+++ b/src/tools/clippy/clippy_utils/src/ty.rs
@@ -90,10 +90,10 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
return false;
}
- for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) {
+ for (predicate, _span) in cx.tcx.explicit_item_bounds(def_id).subst_identity_iter_copied() {
match predicate.kind().skip_binder() {
// For `impl Trait<U>`, it will register a predicate of `T: Trait<U>`, so we go through
- // and check substituions to find `U`.
+ // and check substitutions to find `U`.
ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) => {
if trait_predicate
.trait_ref
@@ -226,7 +226,7 @@ pub fn implements_trait_with_env<'tcx>(
ty_params: impl IntoIterator<Item = Option<GenericArg<'tcx>>>,
) -> bool {
// Clippy shouldn't have infer types
- assert!(!ty.needs_infer());
+ assert!(!ty.has_infer());
let ty = tcx.erase_regions(ty);
if ty.has_escaping_bound_vars() {
@@ -267,7 +267,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
},
ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)),
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
- for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
+ for (predicate, _) in cx.tcx.explicit_item_bounds(def_id).skip_binder() {
if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() {
if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) {
return true;
@@ -743,7 +743,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option
for (pred, _) in cx
.tcx
- .bound_explicit_item_bounds(ty.def_id)
+ .explicit_item_bounds(ty.def_id)
.subst_iter_copied(cx.tcx, ty.substs)
{
match pred.kind().skip_binder() {
@@ -837,7 +837,7 @@ pub fn is_c_void(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
if let ty::Adt(adt, _) = ty.kind()
&& let &[krate, .., name] = &*cx.get_def_path(adt.did())
&& let sym::libc | sym::core | sym::std = krate
- && name.as_str() == "c_void"
+ && name == rustc_span::sym::c_void
{
true
} else {
@@ -975,7 +975,7 @@ pub fn approx_ty_size<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> u64 {
}
match (cx.layout_of(ty).map(|layout| layout.size.bytes()), ty.kind()) {
(Ok(size), _) => size,
- (Err(_), ty::Tuple(list)) => list.as_substs().types().map(|t| approx_ty_size(cx, t)).sum(),
+ (Err(_), ty::Tuple(list)) => list.iter().map(|t| approx_ty_size(cx, t)).sum(),
(Err(_), ty::Array(t, n)) => {
n.try_eval_target_usize(cx.tcx, cx.param_env).unwrap_or_default() * approx_ty_size(cx, *t)
},
@@ -1101,7 +1101,7 @@ pub fn make_projection<'tcx>(
///
/// This function is for associated types which are "known" to be valid with the given
/// substitutions, and as such, will only return `None` when debug assertions are disabled in order
-/// to prevent ICE's. With debug assertions enabled this will check that that type normalization
+/// to prevent ICE's. With debug assertions enabled this will check that type normalization
/// succeeds as well as everything checked by `make_projection`.
pub fn make_normalized_projection<'tcx>(
tcx: TyCtxt<'tcx>,
diff --git a/src/tools/clippy/clippy_utils/src/visitors.rs b/src/tools/clippy/clippy_utils/src/visitors.rs
index 1dc19bac9..5dcd71cef 100644
--- a/src/tools/clippy/clippy_utils/src/visitors.rs
+++ b/src/tools/clippy/clippy_utils/src/visitors.rs
@@ -662,6 +662,7 @@ pub fn for_each_unconsumed_temporary<'tcx, B>(
| ExprKind::Path(_)
| ExprKind::Continue(_)
| ExprKind::InlineAsm(_)
+ | ExprKind::OffsetOf(..)
| ExprKind::Err(_) => (),
}
ControlFlow::Continue(())
diff --git a/src/tools/clippy/declare_clippy_lint/Cargo.toml b/src/tools/clippy/declare_clippy_lint/Cargo.toml
index 5c9f76dbb..139102798 100644
--- a/src/tools/clippy/declare_clippy_lint/Cargo.toml
+++ b/src/tools/clippy/declare_clippy_lint/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "declare_clippy_lint"
-version = "0.1.70"
+version = "0.1.71"
edition = "2021"
publish = false
@@ -10,7 +10,7 @@ proc-macro = true
[dependencies]
itertools = "0.10.1"
quote = "1.0.21"
-syn = "1.0.100"
+syn = "2.0"
[features]
deny-warnings = []
diff --git a/src/tools/clippy/declare_clippy_lint/src/lib.rs b/src/tools/clippy/declare_clippy_lint/src/lib.rs
index 26210556d..5232e4ab7 100644
--- a/src/tools/clippy/declare_clippy_lint/src/lib.rs
+++ b/src/tools/clippy/declare_clippy_lint/src/lib.rs
@@ -6,16 +6,16 @@
use proc_macro::TokenStream;
use quote::{format_ident, quote};
use syn::parse::{Parse, ParseStream};
-use syn::{parse_macro_input, Attribute, Error, Ident, Lit, LitStr, Meta, Result, Token};
+use syn::{parse_macro_input, Attribute, Error, Expr, ExprLit, Ident, Lit, LitStr, Meta, Result, Token};
fn parse_attr<const LEN: usize>(path: [&'static str; LEN], attr: &Attribute) -> Option<LitStr> {
- if let Meta::NameValue(name_value) = attr.parse_meta().ok()? {
+ if let Meta::NameValue(name_value) = &attr.meta {
let path_idents = name_value.path.segments.iter().map(|segment| &segment.ident);
if itertools::equal(path_idents, path)
- && let Lit::Str(lit) = name_value.lit
+ && let Expr::Lit(ExprLit { lit: Lit::Str(s), .. }) = &name_value.value
{
- return Some(lit);
+ return Some(s.clone());
}
}
diff --git a/src/tools/clippy/lintcheck/README.md b/src/tools/clippy/lintcheck/README.md
index faf3ce909..37cc04538 100644
--- a/src/tools/clippy/lintcheck/README.md
+++ b/src/tools/clippy/lintcheck/README.md
@@ -79,9 +79,11 @@ is explicitly specified in the options.
### Fix mode
You can run `cargo lintcheck --fix` which will run Clippy with `--fix` and
-print a warning if Clippy's suggestions fail to apply (if the resulting code does not build).
+print a warning if Clippy's suggestions fail to apply (if the resulting code does not build).
This lets us spot bad suggestions or false positives automatically in some cases.
+> Note: Fix mode implies `--all-targets`, so it can fix as much code as it can.
+
Please note that the target dir should be cleaned afterwards since clippy will modify
the downloaded sources which can lead to unexpected results when running lintcheck again afterwards.
diff --git a/src/tools/clippy/lintcheck/src/main.rs b/src/tools/clippy/lintcheck/src/main.rs
index 23c852980..03d1877d6 100644
--- a/src/tools/clippy/lintcheck/src/main.rs
+++ b/src/tools/clippy/lintcheck/src/main.rs
@@ -421,7 +421,7 @@ impl Crate {
{
let subcrate = &stderr[63..];
println!(
- "ERROR: failed to apply some suggetion to {} / to (sub)crate {subcrate}",
+ "ERROR: failed to apply some suggestion to {} / to (sub)crate {subcrate}",
self.name
);
}
diff --git a/src/tools/clippy/rust-toolchain b/src/tools/clippy/rust-toolchain
index 91e8ccea1..bc7fb711e 100644
--- a/src/tools/clippy/rust-toolchain
+++ b/src/tools/clippy/rust-toolchain
@@ -1,3 +1,3 @@
[toolchain]
-channel = "nightly-2023-04-06"
+channel = "nightly-2023-05-20"
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]
diff --git a/src/tools/clippy/src/driver.rs b/src/tools/clippy/src/driver.rs
index 718bc41fb..59bf447a7 100644
--- a/src/tools/clippy/src/driver.rs
+++ b/src/tools/clippy/src/driver.rs
@@ -11,7 +11,6 @@
// FIXME: switch to something more ergonomic here, once available.
// (Currently there is no way to opt into sysroot crates without `extern crate`.)
extern crate rustc_driver;
-extern crate rustc_errors;
extern crate rustc_interface;
extern crate rustc_session;
extern crate rustc_span;
@@ -20,13 +19,10 @@ use rustc_interface::interface;
use rustc_session::parse::ParseSess;
use rustc_span::symbol::Symbol;
-use std::borrow::Cow;
use std::env;
use std::ops::Deref;
-use std::panic;
use std::path::Path;
use std::process::exit;
-use std::sync::LazyLock;
/// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If
/// true, then return it. The parameter is assumed to be either `--arg=value` or `--arg value`.
@@ -160,6 +156,9 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
// MIR passes can be enabled / disabled separately, we should figure out, what passes to
// use for Clippy.
config.opts.unstable_opts.mir_opt_level = Some(0);
+
+ // Disable flattening and inlining of format_args!(), so the HIR matches with the AST.
+ config.opts.unstable_opts.flatten_format_args = false;
}
}
@@ -195,66 +194,18 @@ You can use tool lints to allow or deny lints from your code, eg.:
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/new";
-type PanicCallback = dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static;
-static ICE_HOOK: LazyLock<Box<PanicCallback>> = LazyLock::new(|| {
- let hook = panic::take_hook();
- panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL)));
- hook
-});
-
-fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
- // Invoke our ICE handler, which prints the actual panic message and optionally a backtrace
- (*ICE_HOOK)(info);
-
- // Separate the output with an empty line
- eprintln!();
-
- let fallback_bundle = rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
- let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr(
- rustc_errors::ColorConfig::Auto,
- None,
- None,
- fallback_bundle,
- false,
- false,
- None,
- false,
- false,
- rustc_errors::TerminalUrl::No,
- ));
- let handler = rustc_errors::Handler::with_emitter(true, None, emitter);
-
- // a .span_bug or .bug call has already printed what
- // it wants to print.
- if !info.payload().is::<rustc_errors::ExplicitBug>() {
- let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
- handler.emit_diagnostic(&mut d);
- }
-
- let version_info = rustc_tools_util::get_version_info!();
-
- let xs: Vec<Cow<'static, str>> = vec![
- "the compiler unexpectedly panicked. this is a bug.".into(),
- format!("we would appreciate a bug report: {bug_report_url}").into(),
- format!("Clippy version: {version_info}").into(),
- ];
-
- for note in &xs {
- handler.note_without_error(note.as_ref());
- }
-
- // If backtraces are enabled, also print the query stack
- let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0");
-
- let num_frames = if backtrace { None } else { Some(2) };
-
- interface::try_print_query_stack(&handler, num_frames);
-}
-
#[allow(clippy::too_many_lines)]
pub fn main() {
rustc_driver::init_rustc_env_logger();
- LazyLock::force(&ICE_HOOK);
+
+ rustc_driver::install_ice_hook(BUG_REPORT_URL, |handler| {
+ // FIXME: this macro calls unwrap internally but is called in a panicking context! It's not
+ // as simple as moving the call from the hook to main, because `install_ice_hook` doesn't
+ // accept a generic closure.
+ let version_info = rustc_tools_util::get_version_info!();
+ handler.note_without_error(format!("Clippy version: {version_info}"));
+ });
+
exit(rustc_driver::catch_with_exit_code(move || {
let mut orig_args: Vec<String> = env::args().collect();
let has_sysroot_arg = arg_value(&orig_args, "--sysroot", |_| true).is_some();
diff --git a/src/tools/clippy/src/main.rs b/src/tools/clippy/src/main.rs
index c5e9b96cf..188ff87ab 100644
--- a/src/tools/clippy/src/main.rs
+++ b/src/tools/clippy/src/main.rs
@@ -13,7 +13,7 @@ Usage:
Common options:
--no-deps Run Clippy only on the given crate, without linting the dependencies
- --fix Automatically apply lint suggestions. This flag implies `--no-deps`
+ --fix Automatically apply lint suggestions. This flag implies `--no-deps` and `--all-targets`
-h, --help Print this message
-V, --version Print version info and exit
--explain LINT Print the documentation for a given lint
diff --git a/src/tools/clippy/tests/compile-test.rs b/src/tools/clippy/tests/compile-test.rs
index 57890ff31..35d75cc51 100644
--- a/src/tools/clippy/tests/compile-test.rs
+++ b/src/tools/clippy/tests/compile-test.rs
@@ -126,6 +126,7 @@ fn base_config(test_dir: &str) -> compiletest::Config {
let mut config = compiletest::Config {
edition: Some("2021".into()),
mode: TestMode::Ui,
+ strict_headers: true,
..Default::default()
};
@@ -424,7 +425,7 @@ fn check_rustfix_coverage() {
.binary_search_by_key(&filename, Path::new)
.is_ok(),
"`{rs_file}` runs `MachineApplicable` diagnostics but is missing a `run-rustfix` annotation. \
- Please either add `// run-rustfix` at the top of the file or add the file to \
+ Please either add `//@run-rustfix` at the top of the file or add the file to \
`RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS` in `tests/compile-test.rs`.",
);
}
diff --git a/src/tools/clippy/tests/dogfood.rs b/src/tools/clippy/tests/dogfood.rs
index 68a878e9a..afde31fac 100644
--- a/src/tools/clippy/tests/dogfood.rs
+++ b/src/tools/clippy/tests/dogfood.rs
@@ -39,7 +39,7 @@ fn dogfood_clippy() {
assert!(
failed_packages.is_empty(),
"Dogfood failed for packages `{}`",
- failed_packages.iter().format(", "),
+ failed_packages.iter().join(", "),
);
}
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 27841e18a..1a69bb241 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,4 @@
-// compile-flags: --crate-name=cargo_common_metadata
+//@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 27841e18a..1a69bb241 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,4 @@
-// compile-flags: --crate-name=cargo_common_metadata
+//@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 27841e18a..1a69bb241 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,4 @@
-// compile-flags: --crate-name=cargo_common_metadata
+//@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 27841e18a..1a69bb241 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,4 @@
-// compile-flags: --crate-name=cargo_common_metadata
+//@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 27841e18a..1a69bb241 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,4 @@
-// compile-flags: --crate-name=cargo_common_metadata
+//@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 27841e18a..1a69bb241 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,4 @@
-// compile-flags: --crate-name=cargo_common_metadata
+//@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 64f01a98c..4dd9582af 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,4 @@
-// compile-flags: --crate-name=feature_name
+//@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 64f01a98c..4dd9582af 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,4 @@
-// compile-flags: --crate-name=feature_name
+//@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 ba4c8c873..c70d92e35 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,4 +1,4 @@
-// compile-flags: --remap-path-prefix {{src-base}}=/remapped
+//@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 1b2d3ec94..ece260b74 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,4 @@
-// compile-flags: --crate-name=multiple_crate_versions
+//@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 1b2d3ec94..ece260b74 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,4 @@
-// compile-flags: --crate-name=multiple_crate_versions
+//@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 1b2d3ec94..ece260b74 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,4 @@
-// compile-flags: --crate-name=multiple_crate_versions
+//@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 581babfea..bb3a39d07 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,4 @@
-// compile-flags: --crate-name=wildcard_dependencies
+//@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 581babfea..bb3a39d07 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,4 @@
-// compile-flags: --crate-name=wildcard_dependencies
+//@compile-flags: --crate-name=wildcard_dependencies
#![warn(clippy::wildcard_dependencies)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.fixed b/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.fixed
index 9f299d7de..72c04bf80 100644
--- a/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.fixed
+++ b/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
#![feature(rustc_private)]
diff --git a/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.rs b/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.rs
index 2b113f555..76f7c3ce9 100644
--- a/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.rs
+++ b/src/tools/clippy/tests/ui-internal/collapsible_span_lint_calls.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
#![feature(rustc_private)]
diff --git a/src/tools/clippy/tests/ui-internal/custom_ice_message.rs b/src/tools/clippy/tests/ui-internal/custom_ice_message.rs
index 837811bdf..99ce70283 100644
--- a/src/tools/clippy/tests/ui-internal/custom_ice_message.rs
+++ b/src/tools/clippy/tests/ui-internal/custom_ice_message.rs
@@ -1,9 +1,10 @@
-// rustc-env:RUST_BACKTRACE=0
-// normalize-stderr-test: "Clippy version: .*" -> "Clippy version: foo"
-// normalize-stderr-test: "produce_ice.rs:\d*:\d*" -> "produce_ice.rs"
-// normalize-stderr-test: "', .*clippy_lints" -> "', clippy_lints"
-// normalize-stderr-test: "'rustc'" -> "'<unnamed>'"
-// normalize-stderr-test: "(?ms)query stack during panic:\n.*end of query stack\n" -> ""
+//@rustc-env:RUST_BACKTRACE=0
+//@normalize-stderr-test: "Clippy version: .*" -> "Clippy version: foo"
+//@normalize-stderr-test: "produce_ice.rs:\d*:\d*" -> "produce_ice.rs"
+//@normalize-stderr-test: "', .*clippy_lints" -> "', clippy_lints"
+//@normalize-stderr-test: "'rustc'" -> "'<unnamed>'"
+//@normalize-stderr-test: "running on .*" -> "running on <target>"
+//@normalize-stderr-test: "(?ms)query stack during panic:\n.*end of query stack\n" -> ""
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
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 b4619e980..0fc385cd6 100644
--- a/src/tools/clippy/tests/ui-internal/custom_ice_message.stderr
+++ b/src/tools/clippy/tests/ui-internal/custom_ice_message.stderr
@@ -1,12 +1,14 @@
thread '<unnamed>' panicked at 'Would you like some help with that?', clippy_lints/src/utils/internal_lints/produce_ice.rs
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
-error: internal compiler error: unexpected panic
-
-note: the compiler unexpectedly panicked. this is a bug.
+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: rustc 1.71.0-nightly (521f4dae1 2023-05-19) running on <target>
+
+note: compiler flags: -C prefer-dynamic -Z ui-testing
+
note: Clippy version: foo
thread panicked while panicking. aborting.
diff --git a/src/tools/clippy/tests/ui-internal/interning_defined_symbol.fixed b/src/tools/clippy/tests/ui-internal/interning_defined_symbol.fixed
index eaea218e1..a1a10c079 100644
--- a/src/tools/clippy/tests/ui-internal/interning_defined_symbol.fixed
+++ b/src/tools/clippy/tests/ui-internal/interning_defined_symbol.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute, clippy::let_unit_value)]
#![feature(rustc_private)]
diff --git a/src/tools/clippy/tests/ui-internal/interning_defined_symbol.rs b/src/tools/clippy/tests/ui-internal/interning_defined_symbol.rs
index 7efebb8fa..32dbfe5dc 100644
--- a/src/tools/clippy/tests/ui-internal/interning_defined_symbol.rs
+++ b/src/tools/clippy/tests/ui-internal/interning_defined_symbol.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute, clippy::let_unit_value)]
#![feature(rustc_private)]
diff --git a/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.fixed b/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.fixed
index 08634063a..ac0752774 100644
--- a/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.fixed
+++ b/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
diff --git a/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.rs b/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.rs
index f8af77e6d..56f778621 100644
--- a/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.rs
+++ b/src/tools/clippy/tests/ui-internal/invalid_msrv_attr_impl.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
diff --git a/src/tools/clippy/tests/ui-internal/outer_expn_data.fixed b/src/tools/clippy/tests/ui-internal/outer_expn_data.fixed
index bb82faf0c..d8a08bc99 100644
--- a/src/tools/clippy/tests/ui-internal/outer_expn_data.fixed
+++ b/src/tools/clippy/tests/ui-internal/outer_expn_data.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
diff --git a/src/tools/clippy/tests/ui-internal/outer_expn_data.rs b/src/tools/clippy/tests/ui-internal/outer_expn_data.rs
index 187d468b3..f7af0e9d8 100644
--- a/src/tools/clippy/tests/ui-internal/outer_expn_data.rs
+++ b/src/tools/clippy/tests/ui-internal/outer_expn_data.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::internal)]
#![allow(clippy::missing_clippy_version_attribute)]
diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed
index e474f370a..fce24412f 100644
--- a/src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed
+++ b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:paths.rs
+//@run-rustfix
+//@aux-build:paths.rs
#![deny(clippy::internal)]
#![feature(rustc_private)]
diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_def_path.rs b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.rs
index f17fed6c6..b10bc9e46 100644
--- a/src/tools/clippy/tests/ui-internal/unnecessary_def_path.rs
+++ b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:paths.rs
+//@run-rustfix
+//@aux-build:paths.rs
#![deny(clippy::internal)]
#![feature(rustc_private)]
diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.fixed b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.fixed
index 6033d06e4..b802de1cb 100644
--- a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.fixed
+++ b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(rustc_private)]
#![deny(clippy::internal)]
#![allow(
diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.rs b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.rs
index 1bb5d55f0..c1bead5bd 100644
--- a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.rs
+++ b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(rustc_private)]
#![deny(clippy::internal)]
#![allow(
diff --git a/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed b/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed
index aa8b45b5f..23e7bc16d 100644
--- a/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed
+++ b/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::uninlined_format_args)]
fn main() {
diff --git a/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs b/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs
index ad2e4863e..d66b2b8ff 100644
--- a/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs
+++ b/src/tools/clippy/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::uninlined_format_args)]
fn main() {
diff --git a/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.rs b/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.rs
index 5d9ce18f6..21e4fce26 100644
--- a/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.rs
+++ b/src/tools/clippy/tests/ui-toml/dbg_macro/dbg_macro.rs
@@ -1,4 +1,4 @@
-// compile-flags: --test
+//@compile-flags: --test
#![warn(clippy::dbg_macro)]
fn foo(n: u32) -> u32 {
diff --git a/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.rs b/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.rs
index 2bb537607..ba919b487 100644
--- a/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.rs
+++ b/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.rs
@@ -1,4 +1,4 @@
-// aux-build:macros.rs
+//@aux-build:macros.rs
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui-toml/expect_used/expect_used.rs b/src/tools/clippy/tests/ui-toml/expect_used/expect_used.rs
index 89f142a15..9e267c893 100644
--- a/src/tools/clippy/tests/ui-toml/expect_used/expect_used.rs
+++ b/src/tools/clippy/tests/ui-toml/expect_used/expect_used.rs
@@ -1,4 +1,4 @@
-// compile-flags: --test
+//@compile-flags: --test
#![warn(clippy::expect_used)]
fn expect_option() {
diff --git a/src/tools/clippy/tests/ui-toml/mut_key/mut_key.rs b/src/tools/clippy/tests/ui-toml/mut_key/mut_key.rs
index 667c51cb4..095e0d154 100644
--- a/src/tools/clippy/tests/ui-toml/mut_key/mut_key.rs
+++ b/src/tools/clippy/tests/ui-toml/mut_key/mut_key.rs
@@ -1,4 +1,4 @@
-// compile-flags: --crate-name mut_key
+//@compile-flags: --crate-name mut_key
#![warn(clippy::mutable_key_type)]
diff --git a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/auxiliary/proc_macro_derive.rs b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/auxiliary/proc_macro_derive.rs
index 6452189a4..f5761c6af 100644
--- a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/auxiliary/proc_macro_derive.rs
+++ b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/auxiliary/proc_macro_derive.rs
@@ -1,5 +1,5 @@
-// compile-flags: --emit=link
-// no-prefer-dynamic
+//@compile-flags: --emit=link
+//@no-prefer-dynamic
#![crate_type = "proc-macro"]
diff --git a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed
index 01d135764..e4747bedd 100644
--- a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed
+++ b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed
@@ -1,5 +1,5 @@
-// aux-build:proc_macro_derive.rs
-// run-rustfix
+//@aux-build:proc_macro_derive.rs
+//@run-rustfix
#![warn(clippy::nonstandard_macro_braces)]
diff --git a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs
index 72883e827..54edded99 100644
--- a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs
+++ b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs
@@ -1,5 +1,5 @@
-// aux-build:proc_macro_derive.rs
-// run-rustfix
+//@aux-build:proc_macro_derive.rs
+//@run-rustfix
#![warn(clippy::nonstandard_macro_braces)]
diff --git a/src/tools/clippy/tests/ui-toml/print_macro/print_macro.rs b/src/tools/clippy/tests/ui-toml/print_macro/print_macro.rs
index 5aefb6a6b..3a8b30cca 100644
--- a/src/tools/clippy/tests/ui-toml/print_macro/print_macro.rs
+++ b/src/tools/clippy/tests/ui-toml/print_macro/print_macro.rs
@@ -1,4 +1,4 @@
-// compile-flags: --test
+//@compile-flags: --test
#![warn(clippy::print_stdout)]
#![warn(clippy::print_stderr)]
diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/both.fixed b/src/tools/clippy/tests/ui-toml/semicolon_block/both.fixed
new file mode 100644
index 000000000..fc8038a09
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/semicolon_block/both.fixed
@@ -0,0 +1,86 @@
+//@run-rustfix
+#![allow(
+ unused,
+ clippy::unused_unit,
+ clippy::unnecessary_operation,
+ clippy::no_effect,
+ clippy::single_element_loop
+)]
+#![warn(clippy::semicolon_inside_block)]
+#![warn(clippy::semicolon_outside_block)]
+
+macro_rules! m {
+ (()) => {
+ ()
+ };
+ (0) => {{
+ 0
+ };};
+ (1) => {{
+ 1;
+ }};
+ (2) => {{
+ 2;
+ }};
+}
+
+fn unit_fn_block() {
+ ()
+}
+
+#[rustfmt::skip]
+fn main() {
+ { unit_fn_block() }
+ unsafe { unit_fn_block() }
+
+ {
+ unit_fn_block()
+ }
+
+ { unit_fn_block() };
+ unsafe { unit_fn_block() };
+
+ { unit_fn_block() };
+ unsafe { unit_fn_block() };
+
+ { unit_fn_block(); };
+ unsafe { unit_fn_block(); };
+
+ {
+ unit_fn_block();
+ unit_fn_block();
+ }
+ {
+ unit_fn_block();
+ unit_fn_block();
+ }
+ {
+ unit_fn_block();
+ unit_fn_block();
+ };
+
+ { m!(()) };
+ { m!(()) };
+ { m!(()); };
+ m!(0);
+ m!(1);
+ m!(2);
+
+ for _ in [()] {
+ unit_fn_block();
+ }
+ for _ in [()] {
+ unit_fn_block()
+ }
+
+ let _d = || {
+ unit_fn_block();
+ };
+ let _d = || {
+ unit_fn_block()
+ };
+
+ { unit_fn_block(); };
+
+ unit_fn_block()
+}
diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/both.rs b/src/tools/clippy/tests/ui-toml/semicolon_block/both.rs
new file mode 100644
index 000000000..52ce1f038
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/semicolon_block/both.rs
@@ -0,0 +1,86 @@
+//@run-rustfix
+#![allow(
+ unused,
+ clippy::unused_unit,
+ clippy::unnecessary_operation,
+ clippy::no_effect,
+ clippy::single_element_loop
+)]
+#![warn(clippy::semicolon_inside_block)]
+#![warn(clippy::semicolon_outside_block)]
+
+macro_rules! m {
+ (()) => {
+ ()
+ };
+ (0) => {{
+ 0
+ };};
+ (1) => {{
+ 1;
+ }};
+ (2) => {{
+ 2;
+ }};
+}
+
+fn unit_fn_block() {
+ ()
+}
+
+#[rustfmt::skip]
+fn main() {
+ { unit_fn_block() }
+ unsafe { unit_fn_block() }
+
+ {
+ unit_fn_block()
+ }
+
+ { unit_fn_block() };
+ unsafe { unit_fn_block() };
+
+ { unit_fn_block(); }
+ unsafe { unit_fn_block(); }
+
+ { unit_fn_block(); };
+ unsafe { unit_fn_block(); };
+
+ {
+ unit_fn_block();
+ unit_fn_block()
+ };
+ {
+ unit_fn_block();
+ unit_fn_block();
+ }
+ {
+ unit_fn_block();
+ unit_fn_block();
+ };
+
+ { m!(()) };
+ { m!(()); }
+ { m!(()); };
+ m!(0);
+ m!(1);
+ m!(2);
+
+ for _ in [()] {
+ unit_fn_block();
+ }
+ for _ in [()] {
+ unit_fn_block()
+ }
+
+ let _d = || {
+ unit_fn_block();
+ };
+ let _d = || {
+ unit_fn_block()
+ };
+
+ { unit_fn_block(); };
+
+ unit_fn_block()
+}
diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/both.stderr b/src/tools/clippy/tests/ui-toml/semicolon_block/both.stderr
new file mode 100644
index 000000000..2f58842ea
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/semicolon_block/both.stderr
@@ -0,0 +1,55 @@
+error: consider moving the `;` outside the block for consistent formatting
+ --> $DIR/both.rs:43:5
+ |
+LL | { unit_fn_block(); }
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::semicolon-outside-block` implied by `-D warnings`
+help: put the `;` here
+ |
+LL - { unit_fn_block(); }
+LL + { unit_fn_block() };
+ |
+
+error: consider moving the `;` outside the block for consistent formatting
+ --> $DIR/both.rs:44:5
+ |
+LL | unsafe { unit_fn_block(); }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: put the `;` here
+ |
+LL - unsafe { unit_fn_block(); }
+LL + unsafe { unit_fn_block() };
+ |
+
+error: consider moving the `;` inside the block for consistent formatting
+ --> $DIR/both.rs:49:5
+ |
+LL | / {
+LL | | unit_fn_block();
+LL | | unit_fn_block()
+LL | | };
+ | |______^
+ |
+ = note: `-D clippy::semicolon-inside-block` implied by `-D warnings`
+help: put the `;` here
+ |
+LL ~ unit_fn_block();
+LL ~ }
+ |
+
+error: consider moving the `;` outside the block for consistent formatting
+ --> $DIR/both.rs:63:5
+ |
+LL | { m!(()); }
+ | ^^^^^^^^^^^
+ |
+help: put the `;` here
+ |
+LL - { m!(()); }
+LL + { m!(()) };
+ |
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/clippy.toml b/src/tools/clippy/tests/ui-toml/semicolon_block/clippy.toml
new file mode 100644
index 000000000..4d03e88de
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/semicolon_block/clippy.toml
@@ -0,0 +1,2 @@
+semicolon-inside-block-ignore-singleline = true
+semicolon-outside-block-ignore-multiline = true
diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed
new file mode 100644
index 000000000..23df98301
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.fixed
@@ -0,0 +1,85 @@
+//@run-rustfix
+#![allow(
+ unused,
+ clippy::unused_unit,
+ clippy::unnecessary_operation,
+ clippy::no_effect,
+ clippy::single_element_loop
+)]
+#![warn(clippy::semicolon_inside_block)]
+
+macro_rules! m {
+ (()) => {
+ ()
+ };
+ (0) => {{
+ 0
+ };};
+ (1) => {{
+ 1;
+ }};
+ (2) => {{
+ 2;
+ }};
+}
+
+fn unit_fn_block() {
+ ()
+}
+
+#[rustfmt::skip]
+fn main() {
+ { unit_fn_block() }
+ unsafe { unit_fn_block() }
+
+ {
+ unit_fn_block()
+ }
+
+ { unit_fn_block() };
+ unsafe { unit_fn_block() };
+
+ { unit_fn_block(); }
+ unsafe { unit_fn_block(); }
+
+ { unit_fn_block(); };
+ unsafe { unit_fn_block(); };
+
+ {
+ unit_fn_block();
+ unit_fn_block();
+ }
+ {
+ unit_fn_block();
+ unit_fn_block();
+ }
+ {
+ unit_fn_block();
+ unit_fn_block();
+ };
+
+ { m!(()) };
+ { m!(()); }
+ { m!(()); };
+ m!(0);
+ m!(1);
+ m!(2);
+
+ for _ in [()] {
+ unit_fn_block();
+ }
+ for _ in [()] {
+ unit_fn_block()
+ }
+
+ let _d = || {
+ unit_fn_block();
+ };
+ let _d = || {
+ unit_fn_block()
+ };
+
+ { unit_fn_block(); };
+
+ unit_fn_block()
+}
diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.rs b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.rs
new file mode 100644
index 000000000..e8516f79b
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.rs
@@ -0,0 +1,85 @@
+//@run-rustfix
+#![allow(
+ unused,
+ clippy::unused_unit,
+ clippy::unnecessary_operation,
+ clippy::no_effect,
+ clippy::single_element_loop
+)]
+#![warn(clippy::semicolon_inside_block)]
+
+macro_rules! m {
+ (()) => {
+ ()
+ };
+ (0) => {{
+ 0
+ };};
+ (1) => {{
+ 1;
+ }};
+ (2) => {{
+ 2;
+ }};
+}
+
+fn unit_fn_block() {
+ ()
+}
+
+#[rustfmt::skip]
+fn main() {
+ { unit_fn_block() }
+ unsafe { unit_fn_block() }
+
+ {
+ unit_fn_block()
+ }
+
+ { unit_fn_block() };
+ unsafe { unit_fn_block() };
+
+ { unit_fn_block(); }
+ unsafe { unit_fn_block(); }
+
+ { unit_fn_block(); };
+ unsafe { unit_fn_block(); };
+
+ {
+ unit_fn_block();
+ unit_fn_block()
+ };
+ {
+ unit_fn_block();
+ unit_fn_block();
+ }
+ {
+ unit_fn_block();
+ unit_fn_block();
+ };
+
+ { m!(()) };
+ { m!(()); }
+ { m!(()); };
+ m!(0);
+ m!(1);
+ m!(2);
+
+ for _ in [()] {
+ unit_fn_block();
+ }
+ for _ in [()] {
+ unit_fn_block()
+ }
+
+ let _d = || {
+ unit_fn_block();
+ };
+ let _d = || {
+ unit_fn_block()
+ };
+
+ { unit_fn_block(); };
+
+ unit_fn_block()
+}
diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr
new file mode 100644
index 000000000..2569dc4b4
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_inside_block.stderr
@@ -0,0 +1,18 @@
+error: consider moving the `;` inside the block for consistent formatting
+ --> $DIR/semicolon_inside_block.rs:48:5
+ |
+LL | / {
+LL | | unit_fn_block();
+LL | | unit_fn_block()
+LL | | };
+ | |______^
+ |
+ = note: `-D clippy::semicolon-inside-block` implied by `-D warnings`
+help: put the `;` here
+ |
+LL ~ unit_fn_block();
+LL ~ }
+ |
+
+error: aborting due to previous error
+
diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed
new file mode 100644
index 000000000..7e9055e71
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.fixed
@@ -0,0 +1,85 @@
+//@run-rustfix
+#![allow(
+ unused,
+ clippy::unused_unit,
+ clippy::unnecessary_operation,
+ clippy::no_effect,
+ clippy::single_element_loop
+)]
+#![warn(clippy::semicolon_outside_block)]
+
+macro_rules! m {
+ (()) => {
+ ()
+ };
+ (0) => {{
+ 0
+ };};
+ (1) => {{
+ 1;
+ }};
+ (2) => {{
+ 2;
+ }};
+}
+
+fn unit_fn_block() {
+ ()
+}
+
+#[rustfmt::skip]
+fn main() {
+ { unit_fn_block() }
+ unsafe { unit_fn_block() }
+
+ {
+ unit_fn_block()
+ }
+
+ { unit_fn_block() };
+ unsafe { unit_fn_block() };
+
+ { unit_fn_block() };
+ unsafe { unit_fn_block() };
+
+ { unit_fn_block(); };
+ unsafe { unit_fn_block(); };
+
+ {
+ unit_fn_block();
+ unit_fn_block()
+ };
+ {
+ unit_fn_block();
+ unit_fn_block();
+ }
+ {
+ unit_fn_block();
+ unit_fn_block();
+ };
+
+ { m!(()) };
+ { m!(()) };
+ { m!(()); };
+ m!(0);
+ m!(1);
+ m!(2);
+
+ for _ in [()] {
+ unit_fn_block();
+ }
+ for _ in [()] {
+ unit_fn_block()
+ }
+
+ let _d = || {
+ unit_fn_block();
+ };
+ let _d = || {
+ unit_fn_block()
+ };
+
+ { unit_fn_block(); };
+
+ unit_fn_block()
+}
diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.rs b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.rs
new file mode 100644
index 000000000..4dc956d8a
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.rs
@@ -0,0 +1,85 @@
+//@run-rustfix
+#![allow(
+ unused,
+ clippy::unused_unit,
+ clippy::unnecessary_operation,
+ clippy::no_effect,
+ clippy::single_element_loop
+)]
+#![warn(clippy::semicolon_outside_block)]
+
+macro_rules! m {
+ (()) => {
+ ()
+ };
+ (0) => {{
+ 0
+ };};
+ (1) => {{
+ 1;
+ }};
+ (2) => {{
+ 2;
+ }};
+}
+
+fn unit_fn_block() {
+ ()
+}
+
+#[rustfmt::skip]
+fn main() {
+ { unit_fn_block() }
+ unsafe { unit_fn_block() }
+
+ {
+ unit_fn_block()
+ }
+
+ { unit_fn_block() };
+ unsafe { unit_fn_block() };
+
+ { unit_fn_block(); }
+ unsafe { unit_fn_block(); }
+
+ { unit_fn_block(); };
+ unsafe { unit_fn_block(); };
+
+ {
+ unit_fn_block();
+ unit_fn_block()
+ };
+ {
+ unit_fn_block();
+ unit_fn_block();
+ }
+ {
+ unit_fn_block();
+ unit_fn_block();
+ };
+
+ { m!(()) };
+ { m!(()); }
+ { m!(()); };
+ m!(0);
+ m!(1);
+ m!(2);
+
+ for _ in [()] {
+ unit_fn_block();
+ }
+ for _ in [()] {
+ unit_fn_block()
+ }
+
+ let _d = || {
+ unit_fn_block();
+ };
+ let _d = || {
+ unit_fn_block()
+ };
+
+ { unit_fn_block(); };
+
+ unit_fn_block()
+}
diff --git a/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr
new file mode 100644
index 000000000..6dd3577dd
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/semicolon_block/semicolon_outside_block.stderr
@@ -0,0 +1,39 @@
+error: consider moving the `;` outside the block for consistent formatting
+ --> $DIR/semicolon_outside_block.rs:42:5
+ |
+LL | { unit_fn_block(); }
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::semicolon-outside-block` implied by `-D warnings`
+help: put the `;` here
+ |
+LL - { unit_fn_block(); }
+LL + { unit_fn_block() };
+ |
+
+error: consider moving the `;` outside the block for consistent formatting
+ --> $DIR/semicolon_outside_block.rs:43:5
+ |
+LL | unsafe { unit_fn_block(); }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: put the `;` here
+ |
+LL - unsafe { unit_fn_block(); }
+LL + unsafe { unit_fn_block() };
+ |
+
+error: consider moving the `;` outside the block for consistent formatting
+ --> $DIR/semicolon_outside_block.rs:62:5
+ |
+LL | { m!(()); }
+ | ^^^^^^^^^^^
+ |
+help: put the `;` here
+ |
+LL - { m!(()); }
+LL + { m!(()) };
+ |
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs
index 2f3160c83..8e1a1710a 100644
--- a/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs
+++ b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs
@@ -1,4 +1,4 @@
-// compile-flags: --crate-name conf_disallowed_methods
+//@compile-flags: --crate-name conf_disallowed_methods
#![warn(clippy::disallowed_methods)]
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 fb0e226f3..179b12661 100644
--- a/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.rs
+++ b/src/tools/clippy/tests/ui-toml/toml_trivially_copy/test.rs
@@ -1,5 +1,5 @@
-// normalize-stderr-test "\(\d+ byte\)" -> "(N byte)"
-// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)"
+//@normalize-stderr-test: "\(\d+ byte\)" -> "(N byte)"
+//@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)"
#![deny(clippy::trivially_copy_pass_by_ref)]
diff --git a/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.rs b/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.rs
index f328e4d9d..569fd2c35 100644
--- a/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.rs
+++ b/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.rs
@@ -1 +1,3 @@
+//@error-pattern: unknown field `foobar`, expected one of
+
fn main() {}
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 8447c3172..44710b096 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
@@ -37,6 +37,8 @@ error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown fie
missing-docs-in-crate-items
msrv
pass-by-value-size-limit
+ semicolon-inside-block-ignore-singleline
+ semicolon-outside-block-ignore-multiline
single-char-binding-names-threshold
standard-macro-braces
suppress-restriction-lint-in-const
@@ -46,6 +48,7 @@ error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown fie
too-many-lines-threshold
trivial-copy-size-limit
type-complexity-threshold
+ unnecessary-box-size
unreadable-literal-lint-fractions
upper-case-acronyms-aggressive
vec-box-size-threshold
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 6525ea5bf..5d3e800ca 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
@@ -1,4 +1,4 @@
-// compile-flags: --test
+//@compile-flags: --test
#![allow(unused_mut, clippy::get_first, clippy::from_iter_instead_of_collect)]
#![warn(clippy::unwrap_used)]
diff --git a/src/tools/clippy/tests/ui/allow_attributes.fixed b/src/tools/clippy/tests/ui/allow_attributes.fixed
index b8dd0619e..f0936b260 100644
--- a/src/tools/clippy/tests/ui/allow_attributes.fixed
+++ b/src/tools/clippy/tests/ui/allow_attributes.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::allow_attributes)]
#![feature(lint_reasons)]
diff --git a/src/tools/clippy/tests/ui/allow_attributes.rs b/src/tools/clippy/tests/ui/allow_attributes.rs
index 295f56090..2fb9e8612 100644
--- a/src/tools/clippy/tests/ui/allow_attributes.rs
+++ b/src/tools/clippy/tests/ui/allow_attributes.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::allow_attributes)]
#![feature(lint_reasons)]
diff --git a/src/tools/clippy/tests/ui/allow_attributes_false_positive.rs b/src/tools/clippy/tests/ui/allow_attributes_false_positive.rs
new file mode 100644
index 000000000..5c3407628
--- /dev/null
+++ b/src/tools/clippy/tests/ui/allow_attributes_false_positive.rs
@@ -0,0 +1,5 @@
+#![warn(clippy::allow_attributes)]
+#![feature(lint_reasons)]
+#![crate_type = "proc-macro"]
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/almost_complete_range.fixed b/src/tools/clippy/tests/ui/almost_complete_range.fixed
index a4bf7fe18..5cd0dcce6 100644
--- a/src/tools/clippy/tests/ui/almost_complete_range.fixed
+++ b/src/tools/clippy/tests/ui/almost_complete_range.fixed
@@ -1,6 +1,6 @@
-// run-rustfix
-// edition:2018
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@edition:2018
+//@aux-build:proc_macros.rs
#![feature(exclusive_range_pattern)]
#![feature(stmt_expr_attributes)]
diff --git a/src/tools/clippy/tests/ui/almost_complete_range.rs b/src/tools/clippy/tests/ui/almost_complete_range.rs
index 8237c3a13..db0bfc8af 100644
--- a/src/tools/clippy/tests/ui/almost_complete_range.rs
+++ b/src/tools/clippy/tests/ui/almost_complete_range.rs
@@ -1,6 +1,6 @@
-// run-rustfix
-// edition:2018
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@edition:2018
+//@aux-build:proc_macros.rs
#![feature(exclusive_range_pattern)]
#![feature(stmt_expr_attributes)]
diff --git a/src/tools/clippy/tests/ui/arithmetic_side_effects.rs b/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
index 3c06676d7..f95af1017 100644
--- a/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
+++ b/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
@@ -1,3 +1,5 @@
+//@aux-build:proc_macro_derive.rs
+
#![allow(
clippy::assign_op_pattern,
clippy::erasing_op,
@@ -11,6 +13,8 @@
#![feature(const_mut_refs, inline_const, saturating_int_impl)]
#![warn(clippy::arithmetic_side_effects)]
+extern crate proc_macro_derive;
+
use core::num::{Saturating, Wrapping};
const ONE: i32 = 1;
@@ -19,6 +23,9 @@ const ZERO: i32 = 0;
#[derive(Clone, Copy)]
pub struct Custom;
+#[derive(proc_macro_derive::ShadowDerive)]
+pub struct Nothing;
+
macro_rules! impl_arith {
( $( $_trait:ident, $lhs:ty, $rhs:ty, $method:ident; )* ) => {
$(
@@ -269,6 +276,17 @@ pub fn non_overflowing_ops_or_ops_already_handled_by_the_compiler_should_not_tri
_n = &1 * _n;
_n = 23 + 85;
+ // Method
+ _n.saturating_div(1);
+ _n.wrapping_div(1);
+ _n.wrapping_rem(1);
+ _n.wrapping_rem_euclid(1);
+
+ _n.saturating_div(1);
+ _n.checked_div(1);
+ _n.checked_rem(1);
+ _n.checked_rem_euclid(1);
+
// Unary
_n = -2147483647;
_n = -i32::MAX;
@@ -376,6 +394,17 @@ pub fn unknown_ops_or_runtime_ops_that_can_overflow() {
_custom = Custom << _custom;
_custom = &Custom << _custom;
+ // Method
+ _n.saturating_div(0);
+ _n.wrapping_div(0);
+ _n.wrapping_rem(0);
+ _n.wrapping_rem_euclid(0);
+
+ _n.saturating_div(_n);
+ _n.wrapping_div(_n);
+ _n.wrapping_rem(_n);
+ _n.wrapping_rem_euclid(_n);
+
// Unary
_n = -_n;
_n = -&_n;
@@ -429,4 +458,12 @@ pub fn issue_10583(a: u16) -> u16 {
10 / a
}
+pub fn issue_10767() {
+ let n = &1.0;
+ n + n;
+ 3.1_f32 + &1.2_f32;
+ &3.4_f32 + 1.5_f32;
+ &3.5_f32 + &1.3_f32;
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr b/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr
index 2c8ee2884..e9a626643 100644
--- a/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr
+++ b/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr
@@ -1,5 +1,5 @@
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:286:5
+ --> $DIR/arithmetic_side_effects.rs:304:5
|
LL | _n += 1;
| ^^^^^^^
@@ -7,652 +7,700 @@ LL | _n += 1;
= note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:287:5
+ --> $DIR/arithmetic_side_effects.rs:305:5
|
LL | _n += &1;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:288:5
+ --> $DIR/arithmetic_side_effects.rs:306:5
|
LL | _n -= 1;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:289:5
+ --> $DIR/arithmetic_side_effects.rs:307:5
|
LL | _n -= &1;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:290:5
+ --> $DIR/arithmetic_side_effects.rs:308:5
|
LL | _n /= 0;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:291:5
+ --> $DIR/arithmetic_side_effects.rs:309:5
|
LL | _n /= &0;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:292:5
+ --> $DIR/arithmetic_side_effects.rs:310:5
|
LL | _n %= 0;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:293:5
+ --> $DIR/arithmetic_side_effects.rs:311:5
|
LL | _n %= &0;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:294:5
+ --> $DIR/arithmetic_side_effects.rs:312:5
|
LL | _n *= 2;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:295:5
+ --> $DIR/arithmetic_side_effects.rs:313:5
|
LL | _n *= &2;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:296:5
+ --> $DIR/arithmetic_side_effects.rs:314:5
|
LL | _n += -1;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:297:5
+ --> $DIR/arithmetic_side_effects.rs:315:5
|
LL | _n += &-1;
| ^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:298:5
+ --> $DIR/arithmetic_side_effects.rs:316:5
|
LL | _n -= -1;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:299:5
+ --> $DIR/arithmetic_side_effects.rs:317:5
|
LL | _n -= &-1;
| ^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:300:5
+ --> $DIR/arithmetic_side_effects.rs:318:5
|
LL | _n /= -0;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:301:5
+ --> $DIR/arithmetic_side_effects.rs:319:5
|
LL | _n /= &-0;
| ^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:302:5
+ --> $DIR/arithmetic_side_effects.rs:320:5
|
LL | _n %= -0;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:303:5
+ --> $DIR/arithmetic_side_effects.rs:321:5
|
LL | _n %= &-0;
| ^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:304:5
+ --> $DIR/arithmetic_side_effects.rs:322:5
|
LL | _n *= -2;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:305:5
+ --> $DIR/arithmetic_side_effects.rs:323:5
|
LL | _n *= &-2;
| ^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:306:5
+ --> $DIR/arithmetic_side_effects.rs:324:5
|
LL | _custom += Custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:307:5
+ --> $DIR/arithmetic_side_effects.rs:325:5
|
LL | _custom += &Custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:308:5
+ --> $DIR/arithmetic_side_effects.rs:326:5
|
LL | _custom -= Custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:309:5
+ --> $DIR/arithmetic_side_effects.rs:327:5
|
LL | _custom -= &Custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:310:5
+ --> $DIR/arithmetic_side_effects.rs:328:5
|
LL | _custom /= Custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:311:5
+ --> $DIR/arithmetic_side_effects.rs:329:5
|
LL | _custom /= &Custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:312:5
+ --> $DIR/arithmetic_side_effects.rs:330:5
|
LL | _custom %= Custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:313:5
+ --> $DIR/arithmetic_side_effects.rs:331:5
|
LL | _custom %= &Custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:314:5
+ --> $DIR/arithmetic_side_effects.rs:332:5
|
LL | _custom *= Custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:315:5
+ --> $DIR/arithmetic_side_effects.rs:333:5
|
LL | _custom *= &Custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:316:5
+ --> $DIR/arithmetic_side_effects.rs:334:5
|
LL | _custom >>= Custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:317:5
+ --> $DIR/arithmetic_side_effects.rs:335:5
|
LL | _custom >>= &Custom;
| ^^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:318:5
+ --> $DIR/arithmetic_side_effects.rs:336:5
|
LL | _custom <<= Custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:319:5
+ --> $DIR/arithmetic_side_effects.rs:337:5
|
LL | _custom <<= &Custom;
| ^^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:320:5
+ --> $DIR/arithmetic_side_effects.rs:338:5
|
LL | _custom += -Custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:321:5
+ --> $DIR/arithmetic_side_effects.rs:339:5
|
LL | _custom += &-Custom;
| ^^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:322:5
+ --> $DIR/arithmetic_side_effects.rs:340:5
|
LL | _custom -= -Custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:323:5
+ --> $DIR/arithmetic_side_effects.rs:341:5
|
LL | _custom -= &-Custom;
| ^^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:324:5
+ --> $DIR/arithmetic_side_effects.rs:342:5
|
LL | _custom /= -Custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:325:5
+ --> $DIR/arithmetic_side_effects.rs:343:5
|
LL | _custom /= &-Custom;
| ^^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:326:5
+ --> $DIR/arithmetic_side_effects.rs:344:5
|
LL | _custom %= -Custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:327:5
+ --> $DIR/arithmetic_side_effects.rs:345:5
|
LL | _custom %= &-Custom;
| ^^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:328:5
+ --> $DIR/arithmetic_side_effects.rs:346:5
|
LL | _custom *= -Custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:329:5
+ --> $DIR/arithmetic_side_effects.rs:347:5
|
LL | _custom *= &-Custom;
| ^^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:330:5
+ --> $DIR/arithmetic_side_effects.rs:348:5
|
LL | _custom >>= -Custom;
| ^^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:331:5
+ --> $DIR/arithmetic_side_effects.rs:349:5
|
LL | _custom >>= &-Custom;
| ^^^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:332:5
+ --> $DIR/arithmetic_side_effects.rs:350:5
|
LL | _custom <<= -Custom;
| ^^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:333:5
+ --> $DIR/arithmetic_side_effects.rs:351:5
|
LL | _custom <<= &-Custom;
| ^^^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:336:10
+ --> $DIR/arithmetic_side_effects.rs:354:10
|
LL | _n = _n + 1;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:337:10
+ --> $DIR/arithmetic_side_effects.rs:355:10
|
LL | _n = _n + &1;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:338:10
+ --> $DIR/arithmetic_side_effects.rs:356:10
|
LL | _n = 1 + _n;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:339:10
+ --> $DIR/arithmetic_side_effects.rs:357:10
|
LL | _n = &1 + _n;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:340:10
+ --> $DIR/arithmetic_side_effects.rs:358:10
|
LL | _n = _n - 1;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:341:10
+ --> $DIR/arithmetic_side_effects.rs:359:10
|
LL | _n = _n - &1;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:342:10
+ --> $DIR/arithmetic_side_effects.rs:360:10
|
LL | _n = 1 - _n;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:343:10
+ --> $DIR/arithmetic_side_effects.rs:361:10
|
LL | _n = &1 - _n;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:344:10
+ --> $DIR/arithmetic_side_effects.rs:362:10
|
LL | _n = _n / 0;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:345:10
+ --> $DIR/arithmetic_side_effects.rs:363:10
|
LL | _n = _n / &0;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:346:10
+ --> $DIR/arithmetic_side_effects.rs:364:10
|
LL | _n = _n % 0;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:347:10
+ --> $DIR/arithmetic_side_effects.rs:365:10
|
LL | _n = _n % &0;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:348:10
+ --> $DIR/arithmetic_side_effects.rs:366:10
|
LL | _n = _n * 2;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:349:10
+ --> $DIR/arithmetic_side_effects.rs:367:10
|
LL | _n = _n * &2;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:350:10
+ --> $DIR/arithmetic_side_effects.rs:368:10
|
LL | _n = 2 * _n;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:351:10
+ --> $DIR/arithmetic_side_effects.rs:369:10
|
LL | _n = &2 * _n;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:352:10
+ --> $DIR/arithmetic_side_effects.rs:370:10
|
LL | _n = 23 + &85;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:353:10
+ --> $DIR/arithmetic_side_effects.rs:371:10
|
LL | _n = &23 + 85;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:354:10
+ --> $DIR/arithmetic_side_effects.rs:372:10
|
LL | _n = &23 + &85;
| ^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:355:15
+ --> $DIR/arithmetic_side_effects.rs:373:15
|
LL | _custom = _custom + _custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:356:15
+ --> $DIR/arithmetic_side_effects.rs:374:15
|
LL | _custom = _custom + &_custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:357:15
+ --> $DIR/arithmetic_side_effects.rs:375:15
|
LL | _custom = Custom + _custom;
| ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:358:15
+ --> $DIR/arithmetic_side_effects.rs:376:15
|
LL | _custom = &Custom + _custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:359:15
+ --> $DIR/arithmetic_side_effects.rs:377:15
|
LL | _custom = _custom - Custom;
| ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:360:15
+ --> $DIR/arithmetic_side_effects.rs:378:15
|
LL | _custom = _custom - &Custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:361:15
+ --> $DIR/arithmetic_side_effects.rs:379:15
|
LL | _custom = Custom - _custom;
| ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:362:15
+ --> $DIR/arithmetic_side_effects.rs:380:15
|
LL | _custom = &Custom - _custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:363:15
+ --> $DIR/arithmetic_side_effects.rs:381:15
|
LL | _custom = _custom / Custom;
| ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:364:15
+ --> $DIR/arithmetic_side_effects.rs:382:15
|
LL | _custom = _custom / &Custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:365:15
+ --> $DIR/arithmetic_side_effects.rs:383:15
|
LL | _custom = _custom % Custom;
| ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:366:15
+ --> $DIR/arithmetic_side_effects.rs:384:15
|
LL | _custom = _custom % &Custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:367:15
+ --> $DIR/arithmetic_side_effects.rs:385:15
|
LL | _custom = _custom * Custom;
| ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:368:15
+ --> $DIR/arithmetic_side_effects.rs:386:15
|
LL | _custom = _custom * &Custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:369:15
+ --> $DIR/arithmetic_side_effects.rs:387:15
|
LL | _custom = Custom * _custom;
| ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:370:15
+ --> $DIR/arithmetic_side_effects.rs:388:15
|
LL | _custom = &Custom * _custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:371:15
+ --> $DIR/arithmetic_side_effects.rs:389:15
|
LL | _custom = Custom + &Custom;
| ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:372:15
+ --> $DIR/arithmetic_side_effects.rs:390:15
|
LL | _custom = &Custom + Custom;
| ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:373:15
+ --> $DIR/arithmetic_side_effects.rs:391:15
|
LL | _custom = &Custom + &Custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:374:15
+ --> $DIR/arithmetic_side_effects.rs:392:15
|
LL | _custom = _custom >> _custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:375:15
+ --> $DIR/arithmetic_side_effects.rs:393:15
|
LL | _custom = _custom >> &_custom;
| ^^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:376:15
+ --> $DIR/arithmetic_side_effects.rs:394:15
|
LL | _custom = Custom << _custom;
| ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:377:15
+ --> $DIR/arithmetic_side_effects.rs:395:15
|
LL | _custom = &Custom << _custom;
| ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:380:10
+ --> $DIR/arithmetic_side_effects.rs:398:23
+ |
+LL | _n.saturating_div(0);
+ | ^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:399:21
+ |
+LL | _n.wrapping_div(0);
+ | ^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:400:21
+ |
+LL | _n.wrapping_rem(0);
+ | ^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:401:28
+ |
+LL | _n.wrapping_rem_euclid(0);
+ | ^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:403:23
+ |
+LL | _n.saturating_div(_n);
+ | ^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:404:21
+ |
+LL | _n.wrapping_div(_n);
+ | ^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:405:21
+ |
+LL | _n.wrapping_rem(_n);
+ | ^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:406:28
+ |
+LL | _n.wrapping_rem_euclid(_n);
+ | ^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:409:10
|
LL | _n = -_n;
| ^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:381:10
+ --> $DIR/arithmetic_side_effects.rs:410:10
|
LL | _n = -&_n;
| ^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:382:15
+ --> $DIR/arithmetic_side_effects.rs:411:15
|
LL | _custom = -_custom;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:383:15
+ --> $DIR/arithmetic_side_effects.rs:412:15
|
LL | _custom = -&_custom;
| ^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:392:5
+ --> $DIR/arithmetic_side_effects.rs:421:5
|
LL | 1 + i;
| ^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:393:5
+ --> $DIR/arithmetic_side_effects.rs:422:5
|
LL | i * 2;
| ^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:394:5
+ --> $DIR/arithmetic_side_effects.rs:423:5
|
LL | 1 % i / 2;
| ^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:395:5
+ --> $DIR/arithmetic_side_effects.rs:424:5
|
LL | i - 2 + 2 - i;
| ^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:396:5
+ --> $DIR/arithmetic_side_effects.rs:425:5
|
LL | -i;
| ^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:407:5
+ --> $DIR/arithmetic_side_effects.rs:436:5
|
LL | i += 1;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:408:5
+ --> $DIR/arithmetic_side_effects.rs:437:5
|
LL | i -= 1;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:409:5
+ --> $DIR/arithmetic_side_effects.rs:438:5
|
LL | i *= 2;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:411:5
+ --> $DIR/arithmetic_side_effects.rs:440:5
|
LL | i /= 0;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:413:5
+ --> $DIR/arithmetic_side_effects.rs:442:5
|
LL | i /= var1;
| ^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:414:5
+ --> $DIR/arithmetic_side_effects.rs:443:5
|
LL | i /= var2;
| ^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:416:5
+ --> $DIR/arithmetic_side_effects.rs:445:5
|
LL | i %= 0;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:418:5
+ --> $DIR/arithmetic_side_effects.rs:447:5
|
LL | i %= var1;
| ^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:419:5
+ --> $DIR/arithmetic_side_effects.rs:448:5
|
LL | i %= var2;
| ^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:429:5
+ --> $DIR/arithmetic_side_effects.rs:458:5
|
LL | 10 / a
| ^^^^^^
-error: aborting due to 109 previous errors
+error: aborting due to 117 previous errors
diff --git a/src/tools/clippy/tests/ui/as_conversions.rs b/src/tools/clippy/tests/ui/as_conversions.rs
index c50d4088b..890bf0b0a 100644
--- a/src/tools/clippy/tests/ui/as_conversions.rs
+++ b/src/tools/clippy/tests/ui/as_conversions.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs
#![warn(clippy::as_conversions)]
#![allow(clippy::borrow_as_ptr)]
diff --git a/src/tools/clippy/tests/ui/as_underscore.fixed b/src/tools/clippy/tests/ui/as_underscore.fixed
index 948f6d8e6..69af84a0e 100644
--- a/src/tools/clippy/tests/ui/as_underscore.fixed
+++ b/src/tools/clippy/tests/ui/as_underscore.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::as_underscore)]
diff --git a/src/tools/clippy/tests/ui/as_underscore.rs b/src/tools/clippy/tests/ui/as_underscore.rs
index 97785ed08..a8cfb81d9 100644
--- a/src/tools/clippy/tests/ui/as_underscore.rs
+++ b/src/tools/clippy/tests/ui/as_underscore.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::as_underscore)]
diff --git a/src/tools/clippy/tests/ui/asm_syntax.rs b/src/tools/clippy/tests/ui/asm_syntax.rs
index 0220bf333..c93995f93 100644
--- a/src/tools/clippy/tests/ui/asm_syntax.rs
+++ b/src/tools/clippy/tests/ui/asm_syntax.rs
@@ -1,5 +1,5 @@
-// only-x86_64
-// ignore-aarch64
+//@only-x86_64
+//@ignore-aarch64
#[warn(clippy::inline_asm_x86_intel_syntax)]
mod warn_intel {
diff --git a/src/tools/clippy/tests/ui/assertions_on_result_states.fixed b/src/tools/clippy/tests/ui/assertions_on_result_states.fixed
index 2bb755290..ea8b89566 100644
--- a/src/tools/clippy/tests/ui/assertions_on_result_states.fixed
+++ b/src/tools/clippy/tests/ui/assertions_on_result_states.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::assertions_on_result_states)]
use std::result::Result;
diff --git a/src/tools/clippy/tests/ui/assertions_on_result_states.rs b/src/tools/clippy/tests/ui/assertions_on_result_states.rs
index d8a9bd2f1..6fc20f859 100644
--- a/src/tools/clippy/tests/ui/assertions_on_result_states.rs
+++ b/src/tools/clippy/tests/ui/assertions_on_result_states.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::assertions_on_result_states)]
use std::result::Result;
diff --git a/src/tools/clippy/tests/ui/assign_ops.fixed b/src/tools/clippy/tests/ui/assign_ops.fixed
index da034b51c..b50682ea0 100644
--- a/src/tools/clippy/tests/ui/assign_ops.fixed
+++ b/src/tools/clippy/tests/ui/assign_ops.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
use core::num::Wrapping;
diff --git a/src/tools/clippy/tests/ui/assign_ops.rs b/src/tools/clippy/tests/ui/assign_ops.rs
index 337bb02c8..780d2d040 100644
--- a/src/tools/clippy/tests/ui/assign_ops.rs
+++ b/src/tools/clippy/tests/ui/assign_ops.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
use core::num::Wrapping;
diff --git a/src/tools/clippy/tests/ui/async_yields_async.fixed b/src/tools/clippy/tests/ui/async_yields_async.fixed
index 579a63ea4..8d9b02389 100644
--- a/src/tools/clippy/tests/ui/async_yields_async.fixed
+++ b/src/tools/clippy/tests/ui/async_yields_async.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(lint_reasons)]
#![feature(async_closure)]
#![warn(clippy::async_yields_async)]
diff --git a/src/tools/clippy/tests/ui/async_yields_async.rs b/src/tools/clippy/tests/ui/async_yields_async.rs
index 5aec2fb50..bed79062f 100644
--- a/src/tools/clippy/tests/ui/async_yields_async.rs
+++ b/src/tools/clippy/tests/ui/async_yields_async.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(lint_reasons)]
#![feature(async_closure)]
#![warn(clippy::async_yields_async)]
diff --git a/src/tools/clippy/tests/ui/author/blocks.rs b/src/tools/clippy/tests/ui/author/blocks.rs
index a7335c01b..164f7d0d9 100644
--- a/src/tools/clippy/tests/ui/author/blocks.rs
+++ b/src/tools/clippy/tests/ui/author/blocks.rs
@@ -1,4 +1,4 @@
-// edition:2018
+//@edition:2018
#![allow(redundant_semicolons, clippy::no_effect)]
#![feature(stmt_expr_attributes)]
diff --git a/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs b/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs
index a9bb61451..e5bb90666 100644
--- a/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs
@@ -22,6 +22,13 @@ macro_rules! string_add {
}
#[macro_export]
+macro_rules! string_lit_as_bytes {
+ ($s:literal) => {
+ const C: &[u8] = $s.as_bytes();
+ };
+}
+
+#[macro_export]
macro_rules! mut_mut {
() => {
let mut_mut_ty: &mut &mut u32 = &mut &mut 1u32;
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 4914f14b5..d164dd0e5 100644
--- a/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs
@@ -1,5 +1,5 @@
-// compile-flags: --emit=link
-// no-prefer-dynamic
+//@compile-flags: --emit=link
+//@no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(repr128, proc_macro_hygiene, proc_macro_quote, box_patterns)]
@@ -28,7 +28,7 @@ pub fn dummy(_args: TokenStream, input: TokenStream) -> TokenStream {
pub fn fake_async_trait(_args: TokenStream, input: TokenStream) -> TokenStream {
let mut item = parse_macro_input!(input as ItemTrait);
for inner in &mut item.items {
- if let TraitItem::Method(method) = inner {
+ if let TraitItem::Fn(method) = inner {
let sig = &method.sig;
let block = &mut method.default;
if let Some(block) = block {
@@ -70,7 +70,7 @@ pub fn rename_my_lifetimes(_args: TokenStream, input: TokenStream) -> TokenStrea
// Look for methods having arbitrary self type taken by &mut ref
for inner in &mut item.items {
- if let ImplItem::Method(method) = inner {
+ if let ImplItem::Fn(method) = inner {
if let Some(FnArg::Typed(pat_type)) = mut_receiver_of(&mut method.sig) {
if let box Type::Reference(reference) = &mut pat_type.ty {
// Target only unnamed lifetimes
@@ -82,7 +82,7 @@ pub fn rename_my_lifetimes(_args: TokenStream, input: TokenStream) -> TokenStrea
elided += 1;
// HACK: Syn uses `Span` from the proc_macro2 crate, and does not seem to reexport it.
- // In order to avoid adding the dependency, get a default span from a non-existent token.
+ // In order to avoid adding the dependency, get a default span from a nonexistent token.
// A default span is needed to mark the code as coming from expansion.
let span = Star::default().span();
diff --git a/src/tools/clippy/tests/ui/auxiliary/proc_macro_derive.rs b/src/tools/clippy/tests/ui/auxiliary/proc_macro_derive.rs
index a89a06308..5a924ca18 100644
--- a/src/tools/clippy/tests/ui/auxiliary/proc_macro_derive.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/proc_macro_derive.rs
@@ -1,5 +1,5 @@
-// compile-flags: --emit=link
-// no-prefer-dynamic
+//@compile-flags: --emit=link
+//@no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(repr128, proc_macro_quote)]
@@ -9,7 +9,7 @@
extern crate proc_macro;
-use proc_macro::{quote, TokenStream};
+use proc_macro::{quote, Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
#[proc_macro_derive(DeriveSomething)]
pub fn derive(_: TokenStream) -> TokenStream {
@@ -86,3 +86,74 @@ pub fn extra_lifetime(_input: TokenStream) -> TokenStream {
}
)
}
+
+#[allow(unused)]
+#[proc_macro_derive(ArithmeticDerive)]
+pub fn arithmetic_derive(_: TokenStream) -> TokenStream {
+ <TokenStream as FromIterator<TokenTree>>::from_iter(
+ [
+ Ident::new("fn", Span::call_site()).into(),
+ Ident::new("_foo", Span::call_site()).into(),
+ Group::new(Delimiter::Parenthesis, TokenStream::new()).into(),
+ Group::new(
+ Delimiter::Brace,
+ <TokenStream as FromIterator<TokenTree>>::from_iter(
+ [
+ Ident::new("let", Span::call_site()).into(),
+ Ident::new("mut", Span::call_site()).into(),
+ Ident::new("_n", Span::call_site()).into(),
+ Punct::new('=', Spacing::Alone).into(),
+ Literal::i32_unsuffixed(9).into(),
+ Punct::new(';', Spacing::Alone).into(),
+ Ident::new("_n", Span::call_site()).into(),
+ Punct::new('=', Spacing::Alone).into(),
+ Literal::i32_unsuffixed(9).into(),
+ Punct::new('/', Spacing::Alone).into(),
+ Literal::i32_unsuffixed(2).into(),
+ Punct::new(';', Spacing::Alone).into(),
+ Ident::new("_n", Span::call_site()).into(),
+ Punct::new('=', Spacing::Alone).into(),
+ Punct::new('-', Spacing::Alone).into(),
+ Ident::new("_n", Span::call_site()).into(),
+ Punct::new(';', Spacing::Alone).into(),
+ ]
+ .into_iter(),
+ ),
+ )
+ .into(),
+ ]
+ .into_iter(),
+ )
+}
+
+#[allow(unused)]
+#[proc_macro_derive(ShadowDerive)]
+pub fn shadow_derive(_: TokenStream) -> TokenStream {
+ <TokenStream as FromIterator<TokenTree>>::from_iter(
+ [
+ Ident::new("fn", Span::call_site()).into(),
+ Ident::new("_foo", Span::call_site()).into(),
+ Group::new(Delimiter::Parenthesis, TokenStream::new()).into(),
+ Group::new(
+ Delimiter::Brace,
+ <TokenStream as FromIterator<TokenTree>>::from_iter(
+ [
+ Ident::new("let", Span::call_site()).into(),
+ Ident::new("_x", Span::call_site()).into(),
+ Punct::new('=', Spacing::Alone).into(),
+ Literal::i32_unsuffixed(2).into(),
+ Punct::new(';', Spacing::Alone).into(),
+ Ident::new("let", Span::call_site()).into(),
+ Ident::new("_x", Span::call_site()).into(),
+ Punct::new('=', Spacing::Alone).into(),
+ Ident::new("_x", Span::call_site()).into(),
+ Punct::new(';', Spacing::Alone).into(),
+ ]
+ .into_iter(),
+ ),
+ )
+ .into(),
+ ]
+ .into_iter(),
+ )
+}
diff --git a/src/tools/clippy/tests/ui/auxiliary/proc_macro_suspicious_else_formatting.rs b/src/tools/clippy/tests/ui/auxiliary/proc_macro_suspicious_else_formatting.rs
index a2ef0fe82..f13b76e44 100644
--- a/src/tools/clippy/tests/ui/auxiliary/proc_macro_suspicious_else_formatting.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/proc_macro_suspicious_else_formatting.rs
@@ -1,5 +1,5 @@
-// compile-flags: --emit=link
-// no-prefer-dynamic
+//@compile-flags: --emit=link
+//@no-prefer-dynamic
#![crate_type = "proc-macro"]
diff --git a/src/tools/clippy/tests/ui/auxiliary/proc_macro_unsafe.rs b/src/tools/clippy/tests/ui/auxiliary/proc_macro_unsafe.rs
index 3c40f7746..c2326678d 100644
--- a/src/tools/clippy/tests/ui/auxiliary/proc_macro_unsafe.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/proc_macro_unsafe.rs
@@ -1,5 +1,5 @@
-// compile-flags: --emit=link
-// no-prefer-dynamic
+//@compile-flags: --emit=link
+//@no-prefer-dynamic
#![crate_type = "proc-macro"]
diff --git a/src/tools/clippy/tests/ui/auxiliary/proc_macros.rs b/src/tools/clippy/tests/ui/auxiliary/proc_macros.rs
index 3d5beab1e..94f075ed0 100644
--- a/src/tools/clippy/tests/ui/auxiliary/proc_macros.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/proc_macros.rs
@@ -1,5 +1,5 @@
-// compile-flags: --emit=link
-// no-prefer-dynamic
+//@compile-flags: --emit=link
+//@no-prefer-dynamic
#![crate_type = "proc-macro"]
#![feature(let_chains)]
diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map.fixed b/src/tools/clippy/tests/ui/bind_instead_of_map.fixed
index d94e2ac60..ea2dc2e22 100644
--- a/src/tools/clippy/tests/ui/bind_instead_of_map.fixed
+++ b/src/tools/clippy/tests/ui/bind_instead_of_map.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::bind_instead_of_map)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map.rs b/src/tools/clippy/tests/ui/bind_instead_of_map.rs
index 86f31f582..1db58dae5 100644
--- a/src/tools/clippy/tests/ui/bind_instead_of_map.rs
+++ b/src/tools/clippy/tests/ui/bind_instead_of_map.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::bind_instead_of_map)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.fixed b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.fixed
index e15898432..63c7aafcd 100644
--- a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.fixed
+++ b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::bind_instead_of_map)]
#![allow(clippy::blocks_in_if_conditions)]
diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.rs b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.rs
index 49944403f..69b982fa8 100644
--- a/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.rs
+++ b/src/tools/clippy/tests/ui/bind_instead_of_map_multipart.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::bind_instead_of_map)]
#![allow(clippy::blocks_in_if_conditions)]
diff --git a/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.rs b/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.rs
index 554745368..e1ff25c54 100644
--- a/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.rs
+++ b/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.rs
@@ -1,4 +1,4 @@
-// compile-flags: -W clippy::restriction
+//@compile-flags: -W clippy::restriction
#![warn(clippy::blanket_clippy_restriction_lints)]
diff --git a/src/tools/clippy/tests/ui/blocks_in_if_conditions.fixed b/src/tools/clippy/tests/ui/blocks_in_if_conditions.fixed
index e6e40a994..a9f18782e 100644
--- a/src/tools/clippy/tests/ui/blocks_in_if_conditions.fixed
+++ b/src/tools/clippy/tests/ui/blocks_in_if_conditions.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::blocks_in_if_conditions)]
#![allow(unused, clippy::let_and_return)]
#![warn(clippy::nonminimal_bool)]
diff --git a/src/tools/clippy/tests/ui/blocks_in_if_conditions.rs b/src/tools/clippy/tests/ui/blocks_in_if_conditions.rs
index 69387ff57..0a70317c4 100644
--- a/src/tools/clippy/tests/ui/blocks_in_if_conditions.rs
+++ b/src/tools/clippy/tests/ui/blocks_in_if_conditions.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::blocks_in_if_conditions)]
#![allow(unused, clippy::let_and_return)]
#![warn(clippy::nonminimal_bool)]
diff --git a/src/tools/clippy/tests/ui/bool_assert_comparison.fixed b/src/tools/clippy/tests/ui/bool_assert_comparison.fixed
index b8dd92906..53f63444a 100644
--- a/src/tools/clippy/tests/ui/bool_assert_comparison.fixed
+++ b/src/tools/clippy/tests/ui/bool_assert_comparison.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::assertions_on_constants)]
#![warn(clippy::bool_assert_comparison)]
diff --git a/src/tools/clippy/tests/ui/bool_assert_comparison.rs b/src/tools/clippy/tests/ui/bool_assert_comparison.rs
index 0a8ad34fd..151d93a92 100644
--- a/src/tools/clippy/tests/ui/bool_assert_comparison.rs
+++ b/src/tools/clippy/tests/ui/bool_assert_comparison.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::assertions_on_constants)]
#![warn(clippy::bool_assert_comparison)]
diff --git a/src/tools/clippy/tests/ui/bool_comparison.fixed b/src/tools/clippy/tests/ui/bool_comparison.fixed
index 5a012ff4d..670eef6a2 100644
--- a/src/tools/clippy/tests/ui/bool_comparison.fixed
+++ b/src/tools/clippy/tests/ui/bool_comparison.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::bool_comparison)]
diff --git a/src/tools/clippy/tests/ui/bool_comparison.rs b/src/tools/clippy/tests/ui/bool_comparison.rs
index c534bc25c..72851be63 100644
--- a/src/tools/clippy/tests/ui/bool_comparison.rs
+++ b/src/tools/clippy/tests/ui/bool_comparison.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::bool_comparison)]
diff --git a/src/tools/clippy/tests/ui/bool_to_int_with_if.fixed b/src/tools/clippy/tests/ui/bool_to_int_with_if.fixed
index 37d3e3286..fbb10a133 100644
--- a/src/tools/clippy/tests/ui/bool_to_int_with_if.fixed
+++ b/src/tools/clippy/tests/ui/bool_to_int_with_if.fixed
@@ -1,6 +1,6 @@
-// run-rustfix
+//@run-rustfix
-#![feature(let_chains)]
+#![feature(let_chains, inline_const)]
#![warn(clippy::bool_to_int_with_if)]
#![allow(unused, dead_code, clippy::unnecessary_operation, clippy::no_effect)]
@@ -79,6 +79,13 @@ fn main() {
pub const SHOULD_NOT_LINT: usize = if true { 1 } else { 0 };
+ // https://github.com/rust-lang/rust-clippy/issues/10452
+ let should_not_lint = [(); if true { 1 } else { 0 }];
+
+ let should_not_lint = const {
+ if true { 1 } else { 0 }
+ };
+
some_fn(a);
}
diff --git a/src/tools/clippy/tests/ui/bool_to_int_with_if.rs b/src/tools/clippy/tests/ui/bool_to_int_with_if.rs
index ebdf86fd1..709a18d63 100644
--- a/src/tools/clippy/tests/ui/bool_to_int_with_if.rs
+++ b/src/tools/clippy/tests/ui/bool_to_int_with_if.rs
@@ -1,6 +1,6 @@
-// run-rustfix
+//@run-rustfix
-#![feature(let_chains)]
+#![feature(let_chains, inline_const)]
#![warn(clippy::bool_to_int_with_if)]
#![allow(unused, dead_code, clippy::unnecessary_operation, clippy::no_effect)]
@@ -111,6 +111,13 @@ fn main() {
pub const SHOULD_NOT_LINT: usize = if true { 1 } else { 0 };
+ // https://github.com/rust-lang/rust-clippy/issues/10452
+ let should_not_lint = [(); if true { 1 } else { 0 }];
+
+ let should_not_lint = const {
+ if true { 1 } else { 0 }
+ };
+
some_fn(a);
}
diff --git a/src/tools/clippy/tests/ui/bool_to_int_with_if.stderr b/src/tools/clippy/tests/ui/bool_to_int_with_if.stderr
index 5cfb75cc0..3bdae75ca 100644
--- a/src/tools/clippy/tests/ui/bool_to_int_with_if.stderr
+++ b/src/tools/clippy/tests/ui/bool_to_int_with_if.stderr
@@ -98,7 +98,7 @@ LL | | };
= note: `!b as i32` or `(!b).into()` can also be valid options
error: boolean to int conversion using if
- --> $DIR/bool_to_int_with_if.rs:119:5
+ --> $DIR/bool_to_int_with_if.rs:126:5
|
LL | if a { 1 } else { 0 }
| ^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `u8::from(a)`
diff --git a/src/tools/clippy/tests/ui/borrow_as_ptr.fixed b/src/tools/clippy/tests/ui/borrow_as_ptr.fixed
index ff5c6a8c3..3f440ce00 100644
--- a/src/tools/clippy/tests/ui/borrow_as_ptr.fixed
+++ b/src/tools/clippy/tests/ui/borrow_as_ptr.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::borrow_as_ptr)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/borrow_as_ptr.rs b/src/tools/clippy/tests/ui/borrow_as_ptr.rs
index 0f62ec6ee..c1ca9180e 100644
--- a/src/tools/clippy/tests/ui/borrow_as_ptr.rs
+++ b/src/tools/clippy/tests/ui/borrow_as_ptr.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::borrow_as_ptr)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.fixed b/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.fixed
index eaba3b1c2..10f2727c7 100644
--- a/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.fixed
+++ b/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::borrow_as_ptr)]
#![feature(lang_items, start, libc)]
#![no_std]
diff --git a/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.rs b/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.rs
index d83f9d1f8..311e9341a 100644
--- a/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.rs
+++ b/src/tools/clippy/tests/ui/borrow_as_ptr_no_std.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::borrow_as_ptr)]
#![feature(lang_items, start, libc)]
#![no_std]
diff --git a/src/tools/clippy/tests/ui/borrow_deref_ref.fixed b/src/tools/clippy/tests/ui/borrow_deref_ref.fixed
index bf4691c5b..755264617 100644
--- a/src/tools/clippy/tests/ui/borrow_deref_ref.fixed
+++ b/src/tools/clippy/tests/ui/borrow_deref_ref.fixed
@@ -1,7 +1,11 @@
-// run-rustfix
+//@run-rustfix
+//@aux-build: proc_macros.rs
#![allow(dead_code, unused_variables)]
+extern crate proc_macros;
+use proc_macros::with_span;
+
fn main() {}
mod should_lint {
@@ -47,6 +51,17 @@ mod should_not_lint2 {
}
}
+with_span!(
+ span
+
+ fn just_returning(x: &u32) -> &u32 {
+ x
+ }
+
+ fn dont_lint_proc_macro() {
+ let a = &mut &*just_returning(&12);
+ }
+);
// this mod explains why we should not lint `& &* (&T)`
mod false_negative {
fn foo() {
diff --git a/src/tools/clippy/tests/ui/borrow_deref_ref.rs b/src/tools/clippy/tests/ui/borrow_deref_ref.rs
index 28c005fdb..e319d365f 100644
--- a/src/tools/clippy/tests/ui/borrow_deref_ref.rs
+++ b/src/tools/clippy/tests/ui/borrow_deref_ref.rs
@@ -1,7 +1,11 @@
-// run-rustfix
+//@run-rustfix
+//@aux-build: proc_macros.rs
#![allow(dead_code, unused_variables)]
+extern crate proc_macros;
+use proc_macros::with_span;
+
fn main() {}
mod should_lint {
@@ -47,6 +51,17 @@ mod should_not_lint2 {
}
}
+with_span!(
+ span
+
+ fn just_returning(x: &u32) -> &u32 {
+ x
+ }
+
+ fn dont_lint_proc_macro() {
+ let a = &mut &*just_returning(&12);
+ }
+);
// this mod explains why we should not lint `& &* (&T)`
mod false_negative {
fn foo() {
diff --git a/src/tools/clippy/tests/ui/borrow_deref_ref.stderr b/src/tools/clippy/tests/ui/borrow_deref_ref.stderr
index d72de37c6..1e47cda67 100644
--- a/src/tools/clippy/tests/ui/borrow_deref_ref.stderr
+++ b/src/tools/clippy/tests/ui/borrow_deref_ref.stderr
@@ -1,5 +1,5 @@
error: deref on an immutable reference
- --> $DIR/borrow_deref_ref.rs:10:17
+ --> $DIR/borrow_deref_ref.rs:14:17
|
LL | let b = &*a;
| ^^^ help: if you would like to reborrow, try removing `&*`: `a`
@@ -7,13 +7,13 @@ LL | let b = &*a;
= note: `-D clippy::borrow-deref-ref` implied by `-D warnings`
error: deref on an immutable reference
- --> $DIR/borrow_deref_ref.rs:12:22
+ --> $DIR/borrow_deref_ref.rs:16:22
|
LL | let b = &mut &*bar(&12);
| ^^^^^^^^^^ help: if you would like to reborrow, try removing `&*`: `bar(&12)`
error: deref on an immutable reference
- --> $DIR/borrow_deref_ref.rs:55:23
+ --> $DIR/borrow_deref_ref.rs:70:23
|
LL | let addr_y = &&*x as *const _ as usize; // assert ok
| ^^^ help: if you would like to reborrow, try removing `&*`: `x`
diff --git a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.rs b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.rs
index 5027db445..29b08ab36 100644
--- a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.rs
+++ b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.rs
@@ -1,4 +1,4 @@
-// aux-build:helper.rs
+//@aux-build:helper.rs
#![warn(clippy::borrow_interior_mutable_const)]
#![allow(clippy::declare_interior_mutable_const)]
diff --git a/src/tools/clippy/tests/ui/box_default.fixed b/src/tools/clippy/tests/ui/box_default.fixed
index 59c0baf87..840902b53 100644
--- a/src/tools/clippy/tests/ui/box_default.fixed
+++ b/src/tools/clippy/tests/ui/box_default.fixed
@@ -1,5 +1,6 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::box_default)]
+#![allow(clippy::default_constructed_unit_structs)]
#[derive(Default)]
struct ImplementsDefault;
@@ -34,6 +35,13 @@ fn main() {
let _more = ret_ty_fn();
call_ty_fn(Box::default());
issue_10381();
+
+ // `Box::<Option<_>>::default()` would be valid here, but not `Box::default()` or
+ // `Box::<Option<[closure@...]>::default()`
+ //
+ // Would have a suggestion after https://github.com/rust-lang/rust/blob/fdd030127cc68afec44a8d3f6341525dd34e50ae/compiler/rustc_middle/src/ty/diagnostics.rs#L554-L563
+ let mut unnameable = Box::new(Option::default());
+ let _ = unnameable.insert(|| {});
}
fn ret_ty_fn() -> Box<bool> {
diff --git a/src/tools/clippy/tests/ui/box_default.rs b/src/tools/clippy/tests/ui/box_default.rs
index f7d832193..3618486a4 100644
--- a/src/tools/clippy/tests/ui/box_default.rs
+++ b/src/tools/clippy/tests/ui/box_default.rs
@@ -1,5 +1,6 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::box_default)]
+#![allow(clippy::default_constructed_unit_structs)]
#[derive(Default)]
struct ImplementsDefault;
@@ -34,6 +35,13 @@ fn main() {
let _more = ret_ty_fn();
call_ty_fn(Box::new(u8::default()));
issue_10381();
+
+ // `Box::<Option<_>>::default()` would be valid here, but not `Box::default()` or
+ // `Box::<Option<[closure@...]>::default()`
+ //
+ // Would have a suggestion after https://github.com/rust-lang/rust/blob/fdd030127cc68afec44a8d3f6341525dd34e50ae/compiler/rustc_middle/src/ty/diagnostics.rs#L554-L563
+ let mut unnameable = Box::new(Option::default());
+ let _ = unnameable.insert(|| {});
}
fn ret_ty_fn() -> Box<bool> {
diff --git a/src/tools/clippy/tests/ui/box_default.stderr b/src/tools/clippy/tests/ui/box_default.stderr
index 78e17b9f0..13dfc5ae4 100644
--- a/src/tools/clippy/tests/ui/box_default.stderr
+++ b/src/tools/clippy/tests/ui/box_default.stderr
@@ -1,5 +1,5 @@
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:22:32
+ --> $DIR/box_default.rs:23:32
|
LL | let _string: Box<String> = Box::new(Default::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()`
@@ -7,91 +7,91 @@ LL | let _string: Box<String> = Box::new(Default::default());
= note: `-D clippy::box-default` implied by `-D warnings`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:23:17
+ --> $DIR/box_default.rs:24:17
|
LL | let _byte = Box::new(u8::default());
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<u8>::default()`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:24:16
+ --> $DIR/box_default.rs:25:16
|
LL | let _vec = Box::new(Vec::<u8>::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<Vec<u8>>::default()`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:25:17
+ --> $DIR/box_default.rs:26:17
|
LL | let _impl = Box::new(ImplementsDefault::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<ImplementsDefault>::default()`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:26:18
+ --> $DIR/box_default.rs:27:18
|
LL | let _impl2 = Box::new(<ImplementsDefault as Default>::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<ImplementsDefault>::default()`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:27:42
+ --> $DIR/box_default.rs:28:42
|
LL | let _impl3: Box<ImplementsDefault> = Box::new(Default::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:29:28
+ --> $DIR/box_default.rs:30:28
|
LL | let _in_macro = outer!(Box::new(String::new()));
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<String>::default()`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:30:34
+ --> $DIR/box_default.rs:31:34
|
LL | let _string_default = outer!(Box::new(String::from("")));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<String>::default()`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:31:46
+ --> $DIR/box_default.rs:32:46
|
LL | let _vec2: Box<Vec<ImplementsDefault>> = Box::new(vec![]);
| ^^^^^^^^^^^^^^^^ help: try: `Box::default()`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:32:33
+ --> $DIR/box_default.rs:33:33
|
LL | let _vec3: Box<Vec<bool>> = Box::new(Vec::from([]));
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:33:25
+ --> $DIR/box_default.rs:34:25
|
LL | let _vec4: Box<_> = Box::new(Vec::from([false; 0]));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<Vec<bool>>::default()`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:35:16
+ --> $DIR/box_default.rs:36:16
|
LL | call_ty_fn(Box::new(u8::default()));
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:40:5
+ --> $DIR/box_default.rs:48:5
|
LL | Box::new(bool::default())
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<bool>::default()`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:57:28
+ --> $DIR/box_default.rs:65:28
|
LL | let _: Box<dyn Read> = Box::new(ImplementsDefault::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<ImplementsDefault>::default()`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:66:17
+ --> $DIR/box_default.rs:74:17
|
LL | let _ = Box::new(WeirdPathed::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<WeirdPathed>::default()`
error: `Box::new(_)` of default value
- --> $DIR/box_default.rs:78:18
+ --> $DIR/box_default.rs:86:18
|
LL | Some(Box::new(Foo::default()))
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<Foo>::default()`
diff --git a/src/tools/clippy/tests/ui/bytes_count_to_len.fixed b/src/tools/clippy/tests/ui/bytes_count_to_len.fixed
index 860642363..fb3d521ba 100644
--- a/src/tools/clippy/tests/ui/bytes_count_to_len.fixed
+++ b/src/tools/clippy/tests/ui/bytes_count_to_len.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::bytes_count_to_len)]
use std::fs::File;
use std::io::Read;
diff --git a/src/tools/clippy/tests/ui/bytes_count_to_len.rs b/src/tools/clippy/tests/ui/bytes_count_to_len.rs
index 162730c28..8e256b8f0 100644
--- a/src/tools/clippy/tests/ui/bytes_count_to_len.rs
+++ b/src/tools/clippy/tests/ui/bytes_count_to_len.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::bytes_count_to_len)]
use std::fs::File;
use std::io::Read;
diff --git a/src/tools/clippy/tests/ui/bytes_nth.fixed b/src/tools/clippy/tests/ui/bytes_nth.fixed
index a35c679af..d3e0f676b 100644
--- a/src/tools/clippy/tests/ui/bytes_nth.fixed
+++ b/src/tools/clippy/tests/ui/bytes_nth.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::unnecessary_operation)]
#![warn(clippy::bytes_nth)]
diff --git a/src/tools/clippy/tests/ui/bytes_nth.rs b/src/tools/clippy/tests/ui/bytes_nth.rs
index 1ecffea53..b7d813fe2 100644
--- a/src/tools/clippy/tests/ui/bytes_nth.rs
+++ b/src/tools/clippy/tests/ui/bytes_nth.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::unnecessary_operation)]
#![warn(clippy::bytes_nth)]
diff --git a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed
index 5fbaa64db..d5af22aef 100644
--- a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed
+++ b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::case_sensitive_file_extension_comparisons)]
use std::string::String;
diff --git a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs
index 3c0d4821f..f5f0a0022 100644
--- a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs
+++ b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::case_sensitive_file_extension_comparisons)]
use std::string::String;
diff --git a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed
index 8676b562b..ef0a93b01 100644
--- a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed
+++ b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::cast_abs_to_unsigned)]
#![allow(clippy::uninlined_format_args, unused)]
diff --git a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs
index 5775af874..96ced670a 100644
--- a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs
+++ b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::cast_abs_to_unsigned)]
#![allow(clippy::uninlined_format_args, unused)]
diff --git a/src/tools/clippy/tests/ui/cast_lossless_bool.fixed b/src/tools/clippy/tests/ui/cast_lossless_bool.fixed
index 13b3cf838..c321cc644 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_bool.fixed
+++ b/src/tools/clippy/tests/ui/cast_lossless_bool.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
#![warn(clippy::cast_lossless)]
diff --git a/src/tools/clippy/tests/ui/cast_lossless_bool.rs b/src/tools/clippy/tests/ui/cast_lossless_bool.rs
index 3eed21355..632a71892 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_bool.rs
+++ b/src/tools/clippy/tests/ui/cast_lossless_bool.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
#![warn(clippy::cast_lossless)]
diff --git a/src/tools/clippy/tests/ui/cast_lossless_float.fixed b/src/tools/clippy/tests/ui/cast_lossless_float.fixed
index 32a9c1c4a..e72a0096a 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_float.fixed
+++ b/src/tools/clippy/tests/ui/cast_lossless_float.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)]
#![warn(clippy::cast_lossless)]
diff --git a/src/tools/clippy/tests/ui/cast_lossless_float.rs b/src/tools/clippy/tests/ui/cast_lossless_float.rs
index 6f5ddcfe0..dbcbaa9b8 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_float.rs
+++ b/src/tools/clippy/tests/ui/cast_lossless_float.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)]
#![warn(clippy::cast_lossless)]
diff --git a/src/tools/clippy/tests/ui/cast_lossless_integer.fixed b/src/tools/clippy/tests/ui/cast_lossless_integer.fixed
index 925cbf253..7dab02084 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_integer.fixed
+++ b/src/tools/clippy/tests/ui/cast_lossless_integer.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)]
#![warn(clippy::cast_lossless)]
diff --git a/src/tools/clippy/tests/ui/cast_lossless_integer.rs b/src/tools/clippy/tests/ui/cast_lossless_integer.rs
index c82bd9108..c24f73960 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_integer.rs
+++ b/src/tools/clippy/tests/ui/cast_lossless_integer.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::no_effect, clippy::unnecessary_operation, dead_code)]
#![warn(clippy::cast_lossless)]
diff --git a/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.fixed b/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.fixed
index b70c19129..9b6fee270 100644
--- a/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.fixed
+++ b/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::cast_slice_from_raw_parts)]
#[allow(unused_imports, unused_unsafe)]
diff --git a/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs b/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs
index c1b316765..c0bb81379 100644
--- a/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs
+++ b/src/tools/clippy/tests/ui/cast_raw_slice_pointer_cast.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::cast_slice_from_raw_parts)]
#[allow(unused_imports, unused_unsafe)]
diff --git a/src/tools/clippy/tests/ui/cast_size.rs b/src/tools/clippy/tests/ui/cast_size.rs
index 595109be4..cd2184aea 100644
--- a/src/tools/clippy/tests/ui/cast_size.rs
+++ b/src/tools/clippy/tests/ui/cast_size.rs
@@ -1,4 +1,4 @@
-// ignore-32bit
+//@ignore-32bit
#[warn(
clippy::cast_precision_loss,
clippy::cast_possible_truncation,
diff --git a/src/tools/clippy/tests/ui/cast_size_32bit.rs b/src/tools/clippy/tests/ui/cast_size_32bit.rs
index 99aac6dec..7ca20d3ca 100644
--- a/src/tools/clippy/tests/ui/cast_size_32bit.rs
+++ b/src/tools/clippy/tests/ui/cast_size_32bit.rs
@@ -1,4 +1,4 @@
-// ignore-64bit
+//@ignore-64bit
#[warn(
clippy::cast_precision_loss,
clippy::cast_possible_truncation,
diff --git a/src/tools/clippy/tests/ui/cast_size_32bit.stderr b/src/tools/clippy/tests/ui/cast_size_32bit.stderr
index 8990c3ba7..fb51783a4 100644
--- a/src/tools/clippy/tests/ui/cast_size_32bit.stderr
+++ b/src/tools/clippy/tests/ui/cast_size_32bit.stderr
@@ -4,7 +4,12 @@ error: casting `isize` to `i8` may truncate the value
LL | 1isize as i8;
| ^^^^^^^^^^^^
|
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
+help: ... or use `try_from` and handle the error accordingly
+ |
+LL | i8::try_from(1isize);
+ | ~~~~~~~~~~~~~~~~~~~~
error: casting `isize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`isize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
--> $DIR/cast_size_32bit.rs:15:5
@@ -37,24 +42,48 @@ error: casting `isize` to `i32` may truncate the value on targets with 64-bit wi
|
LL | 1isize as i32;
| ^^^^^^^^^^^^^
+ |
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
+help: ... or use `try_from` and handle the error accordingly
+ |
+LL | i32::try_from(1isize);
+ | ~~~~~~~~~~~~~~~~~~~~~
error: casting `isize` to `u32` may truncate the value on targets with 64-bit wide pointers
--> $DIR/cast_size_32bit.rs:20:5
|
LL | 1isize as u32;
| ^^^^^^^^^^^^^
+ |
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
+help: ... or use `try_from` and handle the error accordingly
+ |
+LL | u32::try_from(1isize);
+ | ~~~~~~~~~~~~~~~~~~~~~
error: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers
--> $DIR/cast_size_32bit.rs:21:5
|
LL | 1usize as u32;
| ^^^^^^^^^^^^^
+ |
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
+help: ... or use `try_from` and handle the error accordingly
+ |
+LL | u32::try_from(1usize);
+ | ~~~~~~~~~~~~~~~~~~~~~
error: casting `usize` to `i32` may truncate the value on targets with 64-bit wide pointers
--> $DIR/cast_size_32bit.rs:22:5
|
LL | 1usize as i32;
| ^^^^^^^^^^^^^
+ |
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
+help: ... or use `try_from` and handle the error accordingly
+ |
+LL | i32::try_from(1usize);
+ | ~~~~~~~~~~~~~~~~~~~~~
error: casting `usize` to `i32` may wrap around the value on targets with 32-bit wide pointers
--> $DIR/cast_size_32bit.rs:22:5
@@ -69,18 +98,36 @@ error: casting `i64` to `isize` may truncate the value on targets with 32-bit wi
|
LL | 1i64 as isize;
| ^^^^^^^^^^^^^
+ |
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
+help: ... or use `try_from` and handle the error accordingly
+ |
+LL | isize::try_from(1i64);
+ | ~~~~~~~~~~~~~~~~~~~~~
error: casting `i64` to `usize` may truncate the value on targets with 32-bit wide pointers
--> $DIR/cast_size_32bit.rs:25:5
|
LL | 1i64 as usize;
| ^^^^^^^^^^^^^
+ |
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
+help: ... or use `try_from` and handle the error accordingly
+ |
+LL | usize::try_from(1i64);
+ | ~~~~~~~~~~~~~~~~~~~~~
error: casting `u64` to `isize` may truncate the value on targets with 32-bit wide pointers
--> $DIR/cast_size_32bit.rs:26:5
|
LL | 1u64 as isize;
| ^^^^^^^^^^^^^
+ |
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
+help: ... or use `try_from` and handle the error accordingly
+ |
+LL | isize::try_from(1u64);
+ | ~~~~~~~~~~~~~~~~~~~~~
error: casting `u64` to `isize` may wrap around the value on targets with 64-bit wide pointers
--> $DIR/cast_size_32bit.rs:26:5
@@ -93,6 +140,12 @@ error: casting `u64` to `usize` may truncate the value on targets with 32-bit wi
|
LL | 1u64 as usize;
| ^^^^^^^^^^^^^
+ |
+ = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...
+help: ... or use `try_from` and handle the error accordingly
+ |
+LL | usize::try_from(1u64);
+ | ~~~~~~~~~~~~~~~~~~~~~
error: casting `u32` to `isize` may wrap around the value on targets with 32-bit wide pointers
--> $DIR/cast_size_32bit.rs:28:5
diff --git a/src/tools/clippy/tests/ui/cast_slice_different_sizes.rs b/src/tools/clippy/tests/ui/cast_slice_different_sizes.rs
index 24d7eb28a..b77f01883 100644
--- a/src/tools/clippy/tests/ui/cast_slice_different_sizes.rs
+++ b/src/tools/clippy/tests/ui/cast_slice_different_sizes.rs
@@ -23,7 +23,7 @@ fn main() {
r_x as *const [i32]
} as *const [u8];
- // Check that resores of the same size are detected through blocks
+ // Check that resources of the same size are detected through blocks
let restore_block_1 = { r_x as *const [i32] } as *const [u8] as *const [u32];
let restore_block_2 = { ({ r_x as *const [i32] }) as *const [u8] } as *const [u32];
let restore_block_3 = {
diff --git a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed
index b970b1209..13aadb7d3 100644
--- a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed
+++ b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(stmt_expr_attributes)]
#![allow(unused, clippy::no_effect, clippy::unnecessary_operation)]
diff --git a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs
index 0a8e6a89d..769c5d22b 100644
--- a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs
+++ b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(stmt_expr_attributes)]
#![allow(unused, clippy::no_effect, clippy::unnecessary_operation)]
diff --git a/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.fixed b/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.fixed
index 3dc3cb4e7..ce2f149dc 100644
--- a/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.fixed
+++ b/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::char_lit_as_u8)]
diff --git a/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.rs b/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.rs
index d379a0234..ffad12fc6 100644
--- a/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.rs
+++ b/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::char_lit_as_u8)]
diff --git a/src/tools/clippy/tests/ui/checked_conversions.fixed b/src/tools/clippy/tests/ui/checked_conversions.fixed
index e279ba314..188e6d975 100644
--- a/src/tools/clippy/tests/ui/checked_conversions.fixed
+++ b/src/tools/clippy/tests/ui/checked_conversions.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(
clippy::cast_lossless,
diff --git a/src/tools/clippy/tests/ui/checked_conversions.rs b/src/tools/clippy/tests/ui/checked_conversions.rs
index 9d7a40995..70f0f0975 100644
--- a/src/tools/clippy/tests/ui/checked_conversions.rs
+++ b/src/tools/clippy/tests/ui/checked_conversions.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(
clippy::cast_lossless,
diff --git a/src/tools/clippy/tests/ui/clear_with_drain.fixed b/src/tools/clippy/tests/ui/clear_with_drain.fixed
index 2d9545eee..b68c7d867 100644
--- a/src/tools/clippy/tests/ui/clear_with_drain.fixed
+++ b/src/tools/clippy/tests/ui/clear_with_drain.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::clear_with_drain)]
diff --git a/src/tools/clippy/tests/ui/clear_with_drain.rs b/src/tools/clippy/tests/ui/clear_with_drain.rs
index 4d60ee46e..0f6562eca 100644
--- a/src/tools/clippy/tests/ui/clear_with_drain.rs
+++ b/src/tools/clippy/tests/ui/clear_with_drain.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::clear_with_drain)]
diff --git a/src/tools/clippy/tests/ui/clone_on_copy.fixed b/src/tools/clippy/tests/ui/clone_on_copy.fixed
index 72b122270..a72071158 100644
--- a/src/tools/clippy/tests/ui/clone_on_copy.fixed
+++ b/src/tools/clippy/tests/ui/clone_on_copy.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(
unused,
diff --git a/src/tools/clippy/tests/ui/clone_on_copy.rs b/src/tools/clippy/tests/ui/clone_on_copy.rs
index 03e210eba..2c5fac8fa 100644
--- a/src/tools/clippy/tests/ui/clone_on_copy.rs
+++ b/src/tools/clippy/tests/ui/clone_on_copy.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(
unused,
diff --git a/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed b/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed
index ecbfc1fee..b6e09ab31 100644
--- a/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed
+++ b/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::cloned_instead_of_copied)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs b/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs
index 163dc3ddd..fa9e1a996 100644
--- a/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs
+++ b/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::cloned_instead_of_copied)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.fixed b/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.fixed
index abd059c23..3bf3deb9b 100644
--- a/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.fixed
+++ b/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::redundant_clone, clippy::derive_partial_eq_without_eq)] // See #5700
// Define the types in each module to avoid trait impls leaking between modules.
diff --git a/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.rs b/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.rs
index 020ef5f84..10107dc8f 100644
--- a/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.rs
+++ b/src/tools/clippy/tests/ui/cmp_owned/asymmetric_partial_eq.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::redundant_clone, clippy::derive_partial_eq_without_eq)] // See #5700
// Define the types in each module to avoid trait impls leaking between modules.
diff --git a/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.fixed b/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.fixed
index 44e41bdd1..b1133f2a5 100644
--- a/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.fixed
+++ b/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
use std::fmt::{self, Display};
diff --git a/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.rs b/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.rs
index 662673abb..091a9aa65 100644
--- a/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.rs
+++ b/src/tools/clippy/tests/ui/cmp_owned/comparison_flip.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
use std::fmt::{self, Display};
diff --git a/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.fixed b/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.fixed
index b28c4378e..76f90ab2a 100644
--- a/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.fixed
+++ b/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#[warn(clippy::cmp_owned)]
#[allow(clippy::unnecessary_operation, clippy::no_effect, unused_must_use, clippy::eq_op)]
diff --git a/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.rs b/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.rs
index c1089010f..f3f663670 100644
--- a/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.rs
+++ b/src/tools/clippy/tests/ui/cmp_owned/with_suggestion.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#[warn(clippy::cmp_owned)]
#[allow(clippy::unnecessary_operation, clippy::no_effect, unused_must_use, clippy::eq_op)]
diff --git a/src/tools/clippy/tests/ui/collapsible_else_if.fixed b/src/tools/clippy/tests/ui/collapsible_else_if.fixed
index d6a5a7850..8302cec45 100644
--- a/src/tools/clippy/tests/ui/collapsible_else_if.fixed
+++ b/src/tools/clippy/tests/ui/collapsible_else_if.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::assertions_on_constants, clippy::equatable_if_let)]
#[rustfmt::skip]
diff --git a/src/tools/clippy/tests/ui/collapsible_else_if.rs b/src/tools/clippy/tests/ui/collapsible_else_if.rs
index 4399fc8b2..5913dcf41 100644
--- a/src/tools/clippy/tests/ui/collapsible_else_if.rs
+++ b/src/tools/clippy/tests/ui/collapsible_else_if.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::assertions_on_constants, clippy::equatable_if_let)]
#[rustfmt::skip]
diff --git a/src/tools/clippy/tests/ui/collapsible_if.fixed b/src/tools/clippy/tests/ui/collapsible_if.fixed
index 6bb7682ba..c6514a559 100644
--- a/src/tools/clippy/tests/ui/collapsible_if.fixed
+++ b/src/tools/clippy/tests/ui/collapsible_if.fixed
@@ -1,5 +1,10 @@
-// run-rustfix
-#![allow(clippy::assertions_on_constants, clippy::equatable_if_let)]
+//@run-rustfix
+#![allow(
+ clippy::assertions_on_constants,
+ clippy::equatable_if_let,
+ clippy::nonminimal_bool,
+ clippy::eq_op
+)]
#[rustfmt::skip]
#[warn(clippy::collapsible_if)]
diff --git a/src/tools/clippy/tests/ui/collapsible_if.rs b/src/tools/clippy/tests/ui/collapsible_if.rs
index e216a9ee5..2c85b68df 100644
--- a/src/tools/clippy/tests/ui/collapsible_if.rs
+++ b/src/tools/clippy/tests/ui/collapsible_if.rs
@@ -1,5 +1,10 @@
-// run-rustfix
-#![allow(clippy::assertions_on_constants, clippy::equatable_if_let)]
+//@run-rustfix
+#![allow(
+ clippy::assertions_on_constants,
+ clippy::equatable_if_let,
+ clippy::nonminimal_bool,
+ clippy::eq_op
+)]
#[rustfmt::skip]
#[warn(clippy::collapsible_if)]
diff --git a/src/tools/clippy/tests/ui/collapsible_if.stderr b/src/tools/clippy/tests/ui/collapsible_if.stderr
index 6327444df..c687bae1a 100644
--- a/src/tools/clippy/tests/ui/collapsible_if.stderr
+++ b/src/tools/clippy/tests/ui/collapsible_if.stderr
@@ -1,5 +1,5 @@
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:9:5
+ --> $DIR/collapsible_if.rs:14:5
|
LL | / if x == "hello" {
LL | | if y == "world" {
@@ -17,7 +17,7 @@ LL + }
|
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:15:5
+ --> $DIR/collapsible_if.rs:20:5
|
LL | / if x == "hello" || x == "world" {
LL | | if y == "world" || y == "hello" {
@@ -34,7 +34,7 @@ LL + }
|
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:21:5
+ --> $DIR/collapsible_if.rs:26:5
|
LL | / if x == "hello" && x == "world" {
LL | | if y == "world" || y == "hello" {
@@ -51,7 +51,7 @@ LL + }
|
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:27:5
+ --> $DIR/collapsible_if.rs:32:5
|
LL | / if x == "hello" || x == "world" {
LL | | if y == "world" && y == "hello" {
@@ -68,7 +68,7 @@ LL + }
|
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:33:5
+ --> $DIR/collapsible_if.rs:38:5
|
LL | / if x == "hello" && x == "world" {
LL | | if y == "world" && y == "hello" {
@@ -85,7 +85,7 @@ LL + }
|
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:39:5
+ --> $DIR/collapsible_if.rs:44:5
|
LL | / if 42 == 1337 {
LL | | if 'a' != 'A' {
@@ -102,7 +102,7 @@ LL + }
|
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:95:5
+ --> $DIR/collapsible_if.rs:100:5
|
LL | / if x == "hello" {
LL | | if y == "world" { // Collapsible
@@ -119,7 +119,7 @@ LL + }
|
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:154:5
+ --> $DIR/collapsible_if.rs:159:5
|
LL | / if matches!(true, true) {
LL | | if matches!(true, true) {}
@@ -127,7 +127,7 @@ LL | | }
| |_____^ help: collapse nested if block: `if matches!(true, true) && matches!(true, true) {}`
error: this `if` statement can be collapsed
- --> $DIR/collapsible_if.rs:159:5
+ --> $DIR/collapsible_if.rs:164:5
|
LL | / if matches!(true, true) && truth() {
LL | | if matches!(true, true) {}
diff --git a/src/tools/clippy/tests/ui/collapsible_str_replace.fixed b/src/tools/clippy/tests/ui/collapsible_str_replace.fixed
index 9792ae9ed..ba6c1769a 100644
--- a/src/tools/clippy/tests/ui/collapsible_str_replace.fixed
+++ b/src/tools/clippy/tests/ui/collapsible_str_replace.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::collapsible_str_replace)]
diff --git a/src/tools/clippy/tests/ui/collapsible_str_replace.rs b/src/tools/clippy/tests/ui/collapsible_str_replace.rs
index baee185b7..f5871be65 100644
--- a/src/tools/clippy/tests/ui/collapsible_str_replace.rs
+++ b/src/tools/clippy/tests/ui/collapsible_str_replace.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::collapsible_str_replace)]
diff --git a/src/tools/clippy/tests/ui/collection_is_never_read.rs b/src/tools/clippy/tests/ui/collection_is_never_read.rs
index 01259a983..2c1a42a72 100644
--- a/src/tools/clippy/tests/ui/collection_is_never_read.rs
+++ b/src/tools/clippy/tests/ui/collection_is_never_read.rs
@@ -169,22 +169,35 @@ fn function_argument() {
foo(&x);
}
-fn string() {
- // Do lint (write without read)
- let mut s = String::new();
- s.push_str("Hello, World!");
-
- // Do not lint (read without write)
- let mut s = String::from("Hello, World!");
- let _ = s.len();
-
- // Do not lint (write and read)
- let mut s = String::from("Hello, World!");
- s.push_str("foo, bar");
- let _ = s.len();
-
- // Do lint the first line, but not the second
- let mut s = String::from("Hello, World!");
- let t = String::from("foo, bar");
- s = t;
+fn supported_types() {
+ let mut x = std::collections::BTreeMap::new(); // WARNING
+ x.insert(true, 1);
+
+ let mut x = std::collections::BTreeSet::new(); // WARNING
+ x.insert(1);
+
+ let mut x = std::collections::BinaryHeap::new(); // WARNING
+ x.push(1);
+
+ let mut x = std::collections::HashMap::new(); // WARNING
+ x.insert(1, 2);
+
+ let mut x = std::collections::HashSet::new(); // WARNING
+ x.insert(1);
+
+ let mut x = std::collections::LinkedList::new(); // WARNING
+ x.push_front(1);
+
+ let mut x = Some(true); // WARNING
+ x.insert(false);
+
+ let mut x = String::from("hello"); // WARNING
+ x.push('!');
+
+ let mut x = Vec::new(); // WARNING
+ x.clear();
+ x.push(1);
+
+ let mut x = std::collections::VecDeque::new(); // WARNING
+ x.push_front(1);
}
diff --git a/src/tools/clippy/tests/ui/collection_is_never_read.stderr b/src/tools/clippy/tests/ui/collection_is_never_read.stderr
index cf51a5368..982cb4455 100644
--- a/src/tools/clippy/tests/ui/collection_is_never_read.stderr
+++ b/src/tools/clippy/tests/ui/collection_is_never_read.stderr
@@ -61,16 +61,64 @@ LL | let x = vec![1, 2, 3]; // WARNING
| ^^^^^^^^^^^^^^^^^^^^^^
error: collection is never read
- --> $DIR/collection_is_never_read.rs:174:5
+ --> $DIR/collection_is_never_read.rs:173:5
|
-LL | let mut s = String::new();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let mut x = std::collections::BTreeMap::new(); // WARNING
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+ --> $DIR/collection_is_never_read.rs:176:5
+ |
+LL | let mut x = std::collections::BTreeSet::new(); // WARNING
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+ --> $DIR/collection_is_never_read.rs:179:5
+ |
+LL | let mut x = std::collections::BinaryHeap::new(); // WARNING
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+ --> $DIR/collection_is_never_read.rs:182:5
+ |
+LL | let mut x = std::collections::HashMap::new(); // WARNING
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+ --> $DIR/collection_is_never_read.rs:185:5
+ |
+LL | let mut x = std::collections::HashSet::new(); // WARNING
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+ --> $DIR/collection_is_never_read.rs:188:5
+ |
+LL | let mut x = std::collections::LinkedList::new(); // WARNING
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+ --> $DIR/collection_is_never_read.rs:191:5
+ |
+LL | let mut x = Some(true); // WARNING
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+ --> $DIR/collection_is_never_read.rs:194:5
+ |
+LL | let mut x = String::from("hello"); // WARNING
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: collection is never read
+ --> $DIR/collection_is_never_read.rs:197:5
+ |
+LL | let mut x = Vec::new(); // WARNING
+ | ^^^^^^^^^^^^^^^^^^^^^^^
error: collection is never read
- --> $DIR/collection_is_never_read.rs:187:5
+ --> $DIR/collection_is_never_read.rs:201:5
|
-LL | let mut s = String::from("Hello, World!");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let mut x = std::collections::VecDeque::new(); // WARNING
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 12 previous errors
+error: aborting due to 20 previous errors
diff --git a/src/tools/clippy/tests/ui/comparison_to_empty.fixed b/src/tools/clippy/tests/ui/comparison_to_empty.fixed
index 261024cac..dd2615ab2 100644
--- a/src/tools/clippy/tests/ui/comparison_to_empty.fixed
+++ b/src/tools/clippy/tests/ui/comparison_to_empty.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::comparison_to_empty)]
diff --git a/src/tools/clippy/tests/ui/comparison_to_empty.rs b/src/tools/clippy/tests/ui/comparison_to_empty.rs
index 98ddd9749..5462784c6 100644
--- a/src/tools/clippy/tests/ui/comparison_to_empty.rs
+++ b/src/tools/clippy/tests/ui/comparison_to_empty.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::comparison_to_empty)]
diff --git a/src/tools/clippy/tests/ui/crashes/auxiliary/proc_macro_crash.rs b/src/tools/clippy/tests/ui/crashes/auxiliary/proc_macro_crash.rs
index 5ff2af7cd..66419656a 100644
--- a/src/tools/clippy/tests/ui/crashes/auxiliary/proc_macro_crash.rs
+++ b/src/tools/clippy/tests/ui/crashes/auxiliary/proc_macro_crash.rs
@@ -1,5 +1,5 @@
-// compile-flags: --emit=link
-// no-prefer-dynamic
+//@compile-flags: --emit=link
+//@no-prefer-dynamic
// ^ compiletest by default builds all aux files as dylibs, but we don't want that for proc-macro
// crates. If we don't set this, compiletest will override the `crate_type` attribute below and
// compile this as dylib. Removing this then causes the test to fail because a `dylib` crate can't
diff --git a/src/tools/clippy/tests/ui/crashes/ice-10148.rs b/src/tools/clippy/tests/ui/crashes/ice-10148.rs
index 1ab3570c9..c7f022482 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-10148.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-10148.rs
@@ -1,4 +1,4 @@
-// aux-build:../../auxiliary/proc_macros.rs
+//@aux-build:../../auxiliary/proc_macros.rs
extern crate proc_macros;
diff --git a/src/tools/clippy/tests/ui/crashes/ice-10645.rs b/src/tools/clippy/tests/ui/crashes/ice-10645.rs
new file mode 100644
index 000000000..4d8698d38
--- /dev/null
+++ b/src/tools/clippy/tests/ui/crashes/ice-10645.rs
@@ -0,0 +1,7 @@
+// compile-flags: --cap-lints=warn
+// https://github.com/rust-lang/rust-clippy/issues/10645
+
+#![warn(clippy::future_not_send)]
+pub async fn bar<'a, T: 'a>(_: T) {}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/crashes/ice-10645.stderr b/src/tools/clippy/tests/ui/crashes/ice-10645.stderr
new file mode 100644
index 000000000..fc084e30d
--- /dev/null
+++ b/src/tools/clippy/tests/ui/crashes/ice-10645.stderr
@@ -0,0 +1,16 @@
+error: future cannot be sent between threads safely
+ --> $DIR/ice-10645.rs:5:35
+ |
+LL | pub async fn bar<'a, T: 'a>(_: T) {}
+ | ^ future returned by `bar` is not `Send`
+ |
+note: captured value is not `Send`
+ --> $DIR/ice-10645.rs:5:29
+ |
+LL | pub async fn bar<'a, T: 'a>(_: T) {}
+ | ^ has type `T` which is not `Send`
+ = note: `T` doesn't implement `std::marker::Send`
+ = note: `-D clippy::future-not-send` implied by `-D warnings`
+
+error: aborting due to previous error
+
diff --git a/src/tools/clippy/tests/ui/crashes/ice-3741.rs b/src/tools/clippy/tests/ui/crashes/ice-3741.rs
index 1253ddcfa..3106a2e72 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-3741.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-3741.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macro_crash.rs
+//@aux-build:proc_macro_crash.rs
#![warn(clippy::suspicious_else_formatting)]
diff --git a/src/tools/clippy/tests/ui/crashes/ice-4968.rs b/src/tools/clippy/tests/ui/crashes/ice-4968.rs
index e0510d942..ac724ac93 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-4968.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-4968.rs
@@ -1,4 +1,4 @@
-// check-pass
+//@check-pass
// Test for https://github.com/rust-lang/rust-clippy/issues/4968
diff --git a/src/tools/clippy/tests/ui/crashes/ice-5207.rs b/src/tools/clippy/tests/ui/crashes/ice-5207.rs
index f463f78a9..0df8b88fe 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-5207.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-5207.rs
@@ -1,5 +1,4 @@
// Regression test for https://github.com/rust-lang/rust-clippy/issues/5207
-
pub async fn bar<'a, T: 'a>(_: T) {}
fn main() {}
diff --git a/src/tools/clippy/tests/ui/crashes/ice-7272.rs b/src/tools/clippy/tests/ui/crashes/ice-7272.rs
index 57ab6ca14..e949038c8 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-7272.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-7272.rs
@@ -1,4 +1,4 @@
-// aux-build:ice-7272-aux.rs
+//@aux-build:ice-7272-aux.rs
#![allow(clippy::no_effect)]
diff --git a/src/tools/clippy/tests/ui/crashes/ice-7410.rs b/src/tools/clippy/tests/ui/crashes/ice-7410.rs
index 85fa42103..ffe20ab1c 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-7410.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-7410.rs
@@ -1,6 +1,6 @@
-// compile-flags: -Clink-arg=-nostartfiles
-// ignore-macos
-// ignore-windows
+//@compile-flags: -Clink-arg=-nostartfiles
+//@ignore-macos
+//@ignore-windows
#![feature(lang_items, start, libc)]
#![no_std]
diff --git a/src/tools/clippy/tests/ui/crashes/ice-8681.rs b/src/tools/clippy/tests/ui/crashes/ice-8681.rs
index ee14f011f..607b9caa3 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-8681.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-8681.rs
@@ -1,4 +1,4 @@
-// aux-build: ice-8681-aux.rs
+//@aux-build: ice-8681-aux.rs
#![warn(clippy::undocumented_unsafe_blocks)]
diff --git a/src/tools/clippy/tests/ui/crashes/ice_exacte_size.rs b/src/tools/clippy/tests/ui/crashes/ice_exact_size.rs
index 30e4b11ec..30e4b11ec 100644
--- a/src/tools/clippy/tests/ui/crashes/ice_exacte_size.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice_exact_size.rs
diff --git a/src/tools/clippy/tests/ui/crate_in_macro_def.fixed b/src/tools/clippy/tests/ui/crate_in_macro_def.fixed
index 9fc594be3..12a7b9470 100644
--- a/src/tools/clippy/tests/ui/crate_in_macro_def.fixed
+++ b/src/tools/clippy/tests/ui/crate_in_macro_def.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::crate_in_macro_def)]
mod hygienic {
diff --git a/src/tools/clippy/tests/ui/crate_in_macro_def.rs b/src/tools/clippy/tests/ui/crate_in_macro_def.rs
index ac456108e..a1a9eabf6 100644
--- a/src/tools/clippy/tests/ui/crate_in_macro_def.rs
+++ b/src/tools/clippy/tests/ui/crate_in_macro_def.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::crate_in_macro_def)]
mod hygienic {
diff --git a/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.rs b/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.rs
index 1b3bcece6..d6cd594d7 100644
--- a/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.rs
+++ b/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.rs
@@ -1,4 +1,4 @@
-// ignore-macos
+//@ignore-macos
#![feature(rustc_attrs)]
diff --git a/src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs b/src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs
index e1c9fe30a..a382135bb 100644
--- a/src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs
+++ b/src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs
@@ -1,5 +1,5 @@
-// compile-flags: -Clink-arg=-nostartfiles
-// ignore-macos
+//@compile-flags: -Clink-arg=-nostartfiles
+//@ignore-macos
#![feature(lang_items, start, libc)]
#![no_std]
diff --git a/src/tools/clippy/tests/ui/create_dir.fixed b/src/tools/clippy/tests/ui/create_dir.fixed
index 8ed53a56a..5de3e9fea 100644
--- a/src/tools/clippy/tests/ui/create_dir.fixed
+++ b/src/tools/clippy/tests/ui/create_dir.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_must_use)]
#![warn(clippy::create_dir)]
diff --git a/src/tools/clippy/tests/ui/create_dir.rs b/src/tools/clippy/tests/ui/create_dir.rs
index 19c8fc24b..d375bfb4a 100644
--- a/src/tools/clippy/tests/ui/create_dir.rs
+++ b/src/tools/clippy/tests/ui/create_dir.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_must_use)]
#![warn(clippy::create_dir)]
diff --git a/src/tools/clippy/tests/ui/dbg_macro.rs b/src/tools/clippy/tests/ui/dbg_macro.rs
index 25294e8c7..10788d404 100644
--- a/src/tools/clippy/tests/ui/dbg_macro.rs
+++ b/src/tools/clippy/tests/ui/dbg_macro.rs
@@ -1,9 +1,10 @@
-// compile-flags: --test
+//@compile-flags: --test
#![warn(clippy::dbg_macro)]
fn foo(n: u32) -> u32 {
if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n }
}
+fn bar(_: ()) {}
fn factorial(n: u32) -> u32 {
if dbg!(n <= 1) {
@@ -21,6 +22,32 @@ fn main() {
dbg!(1, 2, 3, 4, 5);
}
+fn issue9914() {
+ macro_rules! foo {
+ ($x:expr) => {
+ $x;
+ };
+ }
+ macro_rules! foo2 {
+ ($x:expr) => {
+ $x;
+ };
+ }
+ macro_rules! expand_to_dbg {
+ () => {
+ dbg!();
+ };
+ }
+
+ dbg!();
+ #[allow(clippy::let_unit_value)]
+ let _ = dbg!();
+ bar(dbg!());
+ foo!(dbg!());
+ foo2!(foo!(dbg!()));
+ expand_to_dbg!();
+}
+
mod issue7274 {
trait Thing<'b> {
fn foo(&self);
diff --git a/src/tools/clippy/tests/ui/dbg_macro.stderr b/src/tools/clippy/tests/ui/dbg_macro.stderr
index ddb5f1342..530e76633 100644
--- a/src/tools/clippy/tests/ui/dbg_macro.stderr
+++ b/src/tools/clippy/tests/ui/dbg_macro.stderr
@@ -11,7 +11,7 @@ LL | if let Some(n) = n.checked_sub(4) { n } else { n }
| ~~~~~~~~~~~~~~~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:9:8
+ --> $DIR/dbg_macro.rs:10:8
|
LL | if dbg!(n <= 1) {
| ^^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL | if n <= 1 {
| ~~~~~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:10:9
+ --> $DIR/dbg_macro.rs:11:9
|
LL | dbg!(1)
| ^^^^^^^
@@ -33,7 +33,7 @@ LL | 1
|
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:12:9
+ --> $DIR/dbg_macro.rs:13:9
|
LL | dbg!(n * factorial(n - 1))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -44,7 +44,7 @@ LL | n * factorial(n - 1)
|
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:17:5
+ --> $DIR/dbg_macro.rs:18:5
|
LL | dbg!(42);
| ^^^^^^^^
@@ -55,7 +55,7 @@ LL | 42;
| ~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:18:5
+ --> $DIR/dbg_macro.rs:19:5
|
LL | dbg!(dbg!(dbg!(42)));
| ^^^^^^^^^^^^^^^^^^^^
@@ -66,7 +66,7 @@ LL | dbg!(dbg!(42));
| ~~~~~~~~~~~~~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:19:14
+ --> $DIR/dbg_macro.rs:20:14
|
LL | foo(3) + dbg!(factorial(4));
| ^^^^^^^^^^^^^^^^^^
@@ -77,7 +77,7 @@ LL | foo(3) + factorial(4);
| ~~~~~~~~~~~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:20:5
+ --> $DIR/dbg_macro.rs:21:5
|
LL | dbg!(1, 2, dbg!(3, 4));
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -88,7 +88,7 @@ LL | (1, 2, dbg!(3, 4));
| ~~~~~~~~~~~~~~~~~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:21:5
+ --> $DIR/dbg_macro.rs:22:5
|
LL | dbg!(1, 2, 3, 4, 5);
| ^^^^^^^^^^^^^^^^^^^
@@ -99,7 +99,63 @@ LL | (1, 2, 3, 4, 5);
| ~~~~~~~~~~~~~~~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:41:9
+ --> $DIR/dbg_macro.rs:42:5
+ |
+LL | dbg!();
+ | ^^^^^^^
+ |
+help: remove the invocation before committing it to a version control system
+ |
+LL - dbg!();
+LL +
+ |
+
+error: the `dbg!` macro is intended as a debugging tool
+ --> $DIR/dbg_macro.rs:44:13
+ |
+LL | let _ = dbg!();
+ | ^^^^^^
+ |
+help: remove the invocation before committing it to a version control system
+ |
+LL | let _ = ();
+ | ~~
+
+error: the `dbg!` macro is intended as a debugging tool
+ --> $DIR/dbg_macro.rs:45:9
+ |
+LL | bar(dbg!());
+ | ^^^^^^
+ |
+help: remove the invocation before committing it to a version control system
+ |
+LL | bar(());
+ | ~~
+
+error: the `dbg!` macro is intended as a debugging tool
+ --> $DIR/dbg_macro.rs:46:10
+ |
+LL | foo!(dbg!());
+ | ^^^^^^
+ |
+help: remove the invocation before committing it to a version control system
+ |
+LL | foo!(());
+ | ~~
+
+error: the `dbg!` macro is intended as a debugging tool
+ --> $DIR/dbg_macro.rs:47:16
+ |
+LL | foo2!(foo!(dbg!()));
+ | ^^^^^^
+ |
+help: remove the invocation before committing it to a version control system
+ |
+LL | foo2!(foo!(()));
+ | ~~
+
+error: the `dbg!` macro is intended as a debugging tool
+ --> $DIR/dbg_macro.rs:68:9
|
LL | dbg!(2);
| ^^^^^^^
@@ -110,7 +166,7 @@ LL | 2;
| ~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:47:5
+ --> $DIR/dbg_macro.rs:74:5
|
LL | dbg!(1);
| ^^^^^^^
@@ -121,7 +177,7 @@ LL | 1;
| ~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:52:5
+ --> $DIR/dbg_macro.rs:79:5
|
LL | dbg!(1);
| ^^^^^^^
@@ -132,7 +188,7 @@ LL | 1;
| ~
error: the `dbg!` macro is intended as a debugging tool
- --> $DIR/dbg_macro.rs:58:9
+ --> $DIR/dbg_macro.rs:85:9
|
LL | dbg!(1);
| ^^^^^^^
@@ -142,5 +198,5 @@ help: remove the invocation before committing it to a version control system
LL | 1;
| ~
-error: aborting due to 13 previous errors
+error: aborting due to 18 previous errors
diff --git a/src/tools/clippy/tests/ui/decimal_literal_representation.fixed b/src/tools/clippy/tests/ui/decimal_literal_representation.fixed
index de3914651..a6eb8c214 100644
--- a/src/tools/clippy/tests/ui/decimal_literal_representation.fixed
+++ b/src/tools/clippy/tests/ui/decimal_literal_representation.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#[warn(clippy::decimal_literal_representation)]
#[allow(unused_variables)]
diff --git a/src/tools/clippy/tests/ui/decimal_literal_representation.rs b/src/tools/clippy/tests/ui/decimal_literal_representation.rs
index 55d07698e..7c666d6d7 100644
--- a/src/tools/clippy/tests/ui/decimal_literal_representation.rs
+++ b/src/tools/clippy/tests/ui/decimal_literal_representation.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#[warn(clippy::decimal_literal_representation)]
#[allow(unused_variables)]
diff --git a/src/tools/clippy/tests/ui/def_id_nocore.rs b/src/tools/clippy/tests/ui/def_id_nocore.rs
index 1af77d1a2..f7819068a 100644
--- a/src/tools/clippy/tests/ui/def_id_nocore.rs
+++ b/src/tools/clippy/tests/ui/def_id_nocore.rs
@@ -1,4 +1,4 @@
-// ignore-macos
+//@ignore-macos
#![feature(no_core, lang_items, start)]
#![no_core]
diff --git a/src/tools/clippy/tests/ui/default_constructed_unit_structs.fixed b/src/tools/clippy/tests/ui/default_constructed_unit_structs.fixed
new file mode 100644
index 000000000..ac5fe38ff
--- /dev/null
+++ b/src/tools/clippy/tests/ui/default_constructed_unit_structs.fixed
@@ -0,0 +1,159 @@
+//@run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::default_constructed_unit_structs)]
+use std::marker::PhantomData;
+
+#[derive(Default)]
+struct UnitStruct;
+
+impl UnitStruct {
+ fn new() -> Self {
+ //should lint
+ Self
+ }
+}
+
+#[derive(Default)]
+struct TupleStruct(usize);
+
+impl TupleStruct {
+ fn new() -> Self {
+ // should not lint
+ Self(Default::default())
+ }
+}
+
+// no lint for derived impl
+#[derive(Default)]
+struct NormalStruct {
+ inner: PhantomData<usize>,
+}
+
+struct NonDefaultStruct;
+
+impl NonDefaultStruct {
+ fn default() -> Self {
+ Self
+ }
+}
+
+#[derive(Default)]
+enum SomeEnum {
+ #[default]
+ Unit,
+ Tuple(UnitStruct),
+ Struct {
+ inner: usize,
+ },
+}
+
+impl NormalStruct {
+ fn new() -> Self {
+ // should lint
+ Self {
+ inner: PhantomData,
+ }
+ }
+
+ fn new2() -> Self {
+ // should not lint
+ Self {
+ inner: Default::default(),
+ }
+ }
+}
+
+#[derive(Default)]
+struct GenericStruct<T> {
+ t: T,
+}
+
+impl<T: Default> GenericStruct<T> {
+ fn new() -> Self {
+ // should not lint
+ Self { t: T::default() }
+ }
+
+ fn new2() -> Self {
+ // should not lint
+ Self { t: Default::default() }
+ }
+}
+
+struct FakeDefault;
+impl FakeDefault {
+ fn default() -> Self {
+ Self
+ }
+}
+
+impl Default for FakeDefault {
+ fn default() -> Self {
+ Self
+ }
+}
+
+#[derive(Default)]
+struct EmptyStruct {}
+
+#[derive(Default)]
+#[non_exhaustive]
+struct NonExhaustiveStruct;
+
+mod issue_10755 {
+ struct Sqlite {}
+
+ trait HasArguments<'q> {
+ type Arguments;
+ }
+
+ impl<'q> HasArguments<'q> for Sqlite {
+ type Arguments = std::marker::PhantomData<&'q ()>;
+ }
+
+ type SqliteArguments<'q> = <Sqlite as HasArguments<'q>>::Arguments;
+
+ fn foo() {
+ // should not lint
+ // type alias cannot be used as a constructor
+ let _ = <Sqlite as HasArguments>::Arguments::default();
+
+ let _ = SqliteArguments::default();
+ }
+}
+
+fn main() {
+ // should lint
+ let _ = PhantomData::<usize>;
+ let _: PhantomData<i32> = PhantomData;
+ let _: PhantomData<i32> = std::marker::PhantomData;
+ let _ = UnitStruct;
+
+ // should not lint
+ let _ = TupleStruct::default();
+ let _ = NormalStruct::default();
+ let _ = NonExhaustiveStruct::default();
+ let _ = SomeEnum::default();
+ let _ = NonDefaultStruct::default();
+ let _ = EmptyStruct::default();
+ let _ = FakeDefault::default();
+ let _ = <FakeDefault as Default>::default();
+
+ macro_rules! in_macro {
+ ($i:ident) => {{
+ let _ = UnitStruct::default();
+ let _ = $i::default();
+ }};
+ }
+
+ in_macro!(UnitStruct);
+
+ macro_rules! struct_from_macro {
+ () => {
+ UnitStruct
+ };
+ }
+
+ let _ = <struct_from_macro!()>::default();
+}
diff --git a/src/tools/clippy/tests/ui/default_constructed_unit_structs.rs b/src/tools/clippy/tests/ui/default_constructed_unit_structs.rs
new file mode 100644
index 000000000..de7f14ffb
--- /dev/null
+++ b/src/tools/clippy/tests/ui/default_constructed_unit_structs.rs
@@ -0,0 +1,159 @@
+//@run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::default_constructed_unit_structs)]
+use std::marker::PhantomData;
+
+#[derive(Default)]
+struct UnitStruct;
+
+impl UnitStruct {
+ fn new() -> Self {
+ //should lint
+ Self::default()
+ }
+}
+
+#[derive(Default)]
+struct TupleStruct(usize);
+
+impl TupleStruct {
+ fn new() -> Self {
+ // should not lint
+ Self(Default::default())
+ }
+}
+
+// no lint for derived impl
+#[derive(Default)]
+struct NormalStruct {
+ inner: PhantomData<usize>,
+}
+
+struct NonDefaultStruct;
+
+impl NonDefaultStruct {
+ fn default() -> Self {
+ Self
+ }
+}
+
+#[derive(Default)]
+enum SomeEnum {
+ #[default]
+ Unit,
+ Tuple(UnitStruct),
+ Struct {
+ inner: usize,
+ },
+}
+
+impl NormalStruct {
+ fn new() -> Self {
+ // should lint
+ Self {
+ inner: PhantomData::default(),
+ }
+ }
+
+ fn new2() -> Self {
+ // should not lint
+ Self {
+ inner: Default::default(),
+ }
+ }
+}
+
+#[derive(Default)]
+struct GenericStruct<T> {
+ t: T,
+}
+
+impl<T: Default> GenericStruct<T> {
+ fn new() -> Self {
+ // should not lint
+ Self { t: T::default() }
+ }
+
+ fn new2() -> Self {
+ // should not lint
+ Self { t: Default::default() }
+ }
+}
+
+struct FakeDefault;
+impl FakeDefault {
+ fn default() -> Self {
+ Self
+ }
+}
+
+impl Default for FakeDefault {
+ fn default() -> Self {
+ Self
+ }
+}
+
+#[derive(Default)]
+struct EmptyStruct {}
+
+#[derive(Default)]
+#[non_exhaustive]
+struct NonExhaustiveStruct;
+
+mod issue_10755 {
+ struct Sqlite {}
+
+ trait HasArguments<'q> {
+ type Arguments;
+ }
+
+ impl<'q> HasArguments<'q> for Sqlite {
+ type Arguments = std::marker::PhantomData<&'q ()>;
+ }
+
+ type SqliteArguments<'q> = <Sqlite as HasArguments<'q>>::Arguments;
+
+ fn foo() {
+ // should not lint
+ // type alias cannot be used as a constructor
+ let _ = <Sqlite as HasArguments>::Arguments::default();
+
+ let _ = SqliteArguments::default();
+ }
+}
+
+fn main() {
+ // should lint
+ let _ = PhantomData::<usize>::default();
+ let _: PhantomData<i32> = PhantomData::default();
+ let _: PhantomData<i32> = std::marker::PhantomData::default();
+ let _ = UnitStruct::default();
+
+ // should not lint
+ let _ = TupleStruct::default();
+ let _ = NormalStruct::default();
+ let _ = NonExhaustiveStruct::default();
+ let _ = SomeEnum::default();
+ let _ = NonDefaultStruct::default();
+ let _ = EmptyStruct::default();
+ let _ = FakeDefault::default();
+ let _ = <FakeDefault as Default>::default();
+
+ macro_rules! in_macro {
+ ($i:ident) => {{
+ let _ = UnitStruct::default();
+ let _ = $i::default();
+ }};
+ }
+
+ in_macro!(UnitStruct);
+
+ macro_rules! struct_from_macro {
+ () => {
+ UnitStruct
+ };
+ }
+
+ let _ = <struct_from_macro!()>::default();
+}
diff --git a/src/tools/clippy/tests/ui/default_constructed_unit_structs.stderr b/src/tools/clippy/tests/ui/default_constructed_unit_structs.stderr
new file mode 100644
index 000000000..13abb9149
--- /dev/null
+++ b/src/tools/clippy/tests/ui/default_constructed_unit_structs.stderr
@@ -0,0 +1,40 @@
+error: use of `default` to create a unit struct
+ --> $DIR/default_constructed_unit_structs.rs:13:13
+ |
+LL | Self::default()
+ | ^^^^^^^^^^^ help: remove this call to `default`
+ |
+ = note: `-D clippy::default-constructed-unit-structs` implied by `-D warnings`
+
+error: use of `default` to create a unit struct
+ --> $DIR/default_constructed_unit_structs.rs:55:31
+ |
+LL | inner: PhantomData::default(),
+ | ^^^^^^^^^^^ help: remove this call to `default`
+
+error: use of `default` to create a unit struct
+ --> $DIR/default_constructed_unit_structs.rs:128:33
+ |
+LL | let _ = PhantomData::<usize>::default();
+ | ^^^^^^^^^^^ help: remove this call to `default`
+
+error: use of `default` to create a unit struct
+ --> $DIR/default_constructed_unit_structs.rs:129:42
+ |
+LL | let _: PhantomData<i32> = PhantomData::default();
+ | ^^^^^^^^^^^ help: remove this call to `default`
+
+error: use of `default` to create a unit struct
+ --> $DIR/default_constructed_unit_structs.rs:130:55
+ |
+LL | let _: PhantomData<i32> = std::marker::PhantomData::default();
+ | ^^^^^^^^^^^ help: remove this call to `default`
+
+error: use of `default` to create a unit struct
+ --> $DIR/default_constructed_unit_structs.rs:131:23
+ |
+LL | let _ = UnitStruct::default();
+ | ^^^^^^^^^^^ help: remove this call to `default`
+
+error: aborting due to 6 previous errors
+
diff --git a/src/tools/clippy/tests/ui/default_instead_of_iter_empty.fixed b/src/tools/clippy/tests/ui/default_instead_of_iter_empty.fixed
index f1abfdcd6..f44d34576 100644
--- a/src/tools/clippy/tests/ui/default_instead_of_iter_empty.fixed
+++ b/src/tools/clippy/tests/ui/default_instead_of_iter_empty.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::default_instead_of_iter_empty)]
#![allow(dead_code)]
use std::collections::HashMap;
diff --git a/src/tools/clippy/tests/ui/default_instead_of_iter_empty.rs b/src/tools/clippy/tests/ui/default_instead_of_iter_empty.rs
index 2630519c4..1c649df25 100644
--- a/src/tools/clippy/tests/ui/default_instead_of_iter_empty.rs
+++ b/src/tools/clippy/tests/ui/default_instead_of_iter_empty.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::default_instead_of_iter_empty)]
#![allow(dead_code)]
use std::collections::HashMap;
diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed
index 42c15d6a7..9520efe63 100644
--- a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed
+++ b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![warn(clippy::default_numeric_fallback)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs
index 7da7ea254..cacbdb4a9 100644
--- a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs
+++ b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![warn(clippy::default_numeric_fallback)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed
index b7485b73d..fbabb8bcf 100644
--- a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed
+++ b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![feature(lint_reasons)]
#![warn(clippy::default_numeric_fallback)]
diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs
index 7307d3135..7bfc390e4 100644
--- a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs
+++ b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![feature(lint_reasons)]
#![warn(clippy::default_numeric_fallback)]
diff --git a/src/tools/clippy/tests/ui/default_trait_access.fixed b/src/tools/clippy/tests/ui/default_trait_access.fixed
index 7842ef3ec..bf5dca976 100644
--- a/src/tools/clippy/tests/ui/default_trait_access.fixed
+++ b/src/tools/clippy/tests/ui/default_trait_access.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build: proc_macros.rs
+//@run-rustfix
+//@aux-build: proc_macros.rs
#![deny(clippy::default_trait_access)]
#![allow(dead_code, unused_imports)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/default_trait_access.rs b/src/tools/clippy/tests/ui/default_trait_access.rs
index cbb3e59c9..5e8e9ce85 100644
--- a/src/tools/clippy/tests/ui/default_trait_access.rs
+++ b/src/tools/clippy/tests/ui/default_trait_access.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build: proc_macros.rs
+//@run-rustfix
+//@aux-build: proc_macros.rs
#![deny(clippy::default_trait_access)]
#![allow(dead_code, unused_imports)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/deref_addrof.fixed b/src/tools/clippy/tests/ui/deref_addrof.fixed
index ca5c03304..b27d3bc10 100644
--- a/src/tools/clippy/tests/ui/deref_addrof.fixed
+++ b/src/tools/clippy/tests/ui/deref_addrof.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![allow(clippy::return_self_not_must_use)]
#![warn(clippy::deref_addrof)]
diff --git a/src/tools/clippy/tests/ui/deref_addrof.rs b/src/tools/clippy/tests/ui/deref_addrof.rs
index 3db5fafe9..825090c7c 100644
--- a/src/tools/clippy/tests/ui/deref_addrof.rs
+++ b/src/tools/clippy/tests/ui/deref_addrof.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![allow(clippy::return_self_not_must_use)]
#![warn(clippy::deref_addrof)]
diff --git a/src/tools/clippy/tests/ui/deref_addrof_macro.rs b/src/tools/clippy/tests/ui/deref_addrof_macro.rs
index 57c0be3f5..c7e60f365 100644
--- a/src/tools/clippy/tests/ui/deref_addrof_macro.rs
+++ b/src/tools/clippy/tests/ui/deref_addrof_macro.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs
#![warn(clippy::deref_addrof)]
diff --git a/src/tools/clippy/tests/ui/deref_by_slicing.fixed b/src/tools/clippy/tests/ui/deref_by_slicing.fixed
index 257393e56..f91a425c6 100644
--- a/src/tools/clippy/tests/ui/deref_by_slicing.fixed
+++ b/src/tools/clippy/tests/ui/deref_by_slicing.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::deref_by_slicing)]
#![allow(clippy::borrow_deref_ref)]
diff --git a/src/tools/clippy/tests/ui/deref_by_slicing.rs b/src/tools/clippy/tests/ui/deref_by_slicing.rs
index e288046f9..1bfdd0a98 100644
--- a/src/tools/clippy/tests/ui/deref_by_slicing.rs
+++ b/src/tools/clippy/tests/ui/deref_by_slicing.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::deref_by_slicing)]
#![allow(clippy::borrow_deref_ref)]
diff --git a/src/tools/clippy/tests/ui/derivable_impls.fixed b/src/tools/clippy/tests/ui/derivable_impls.fixed
index 89ec33a0d..aa0efb85c 100644
--- a/src/tools/clippy/tests/ui/derivable_impls.fixed
+++ b/src/tools/clippy/tests/ui/derivable_impls.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/derivable_impls.rs b/src/tools/clippy/tests/ui/derivable_impls.rs
index def6e4116..8dc999ad5 100644
--- a/src/tools/clippy/tests/ui/derivable_impls.rs
+++ b/src/tools/clippy/tests/ui/derivable_impls.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.fixed b/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.fixed
index bbbe46759..a1f29430c 100644
--- a/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.fixed
+++ b/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::derive_partial_eq_without_eq)]
diff --git a/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.rs b/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.rs
index 88d6fbd1a..ff4d88855 100644
--- a/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.rs
+++ b/src/tools/clippy/tests/ui/derive_partial_eq_without_eq.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::derive_partial_eq_without_eq)]
diff --git a/src/tools/clippy/tests/ui/diverging_sub_expression.stderr b/src/tools/clippy/tests/ui/diverging_sub_expression.stderr
index 9c91d9357..51a3b0d97 100644
--- a/src/tools/clippy/tests/ui/diverging_sub_expression.stderr
+++ b/src/tools/clippy/tests/ui/diverging_sub_expression.stderr
@@ -31,18 +31,10 @@ LL | 3 => true || diverge(),
| ^^^^^^^^^
error: sub-expression diverges
- --> $DIR/diverging_sub_expression.rs:36:30
- |
-LL | _ => true || panic!("boo"),
- | ^^^^^^^^^^^^^
- |
- = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:38:26
|
LL | _ => true || break,
| ^^^^^
-error: aborting due to 7 previous errors
+error: aborting due to 6 previous errors
diff --git a/src/tools/clippy/tests/ui/doc/doc-fixable.fixed b/src/tools/clippy/tests/ui/doc/doc-fixable.fixed
index ecb0bf364..d3aa2816c 100644
--- a/src/tools/clippy/tests/ui/doc/doc-fixable.fixed
+++ b/src/tools/clippy/tests/ui/doc/doc-fixable.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
//! This file tests for the `DOC_MARKDOWN` lint.
#![allow(dead_code, incomplete_features)]
diff --git a/src/tools/clippy/tests/ui/doc/doc-fixable.rs b/src/tools/clippy/tests/ui/doc/doc-fixable.rs
index 11c48dd10..d1e7d8017 100644
--- a/src/tools/clippy/tests/ui/doc/doc-fixable.rs
+++ b/src/tools/clippy/tests/ui/doc/doc-fixable.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
//! This file tests for the `DOC_MARKDOWN` lint.
#![allow(dead_code, incomplete_features)]
diff --git a/src/tools/clippy/tests/ui/doc_unsafe.rs b/src/tools/clippy/tests/ui/doc_unsafe.rs
index 30674ce37..0c8eac5cc 100644
--- a/src/tools/clippy/tests/ui/doc_unsafe.rs
+++ b/src/tools/clippy/tests/ui/doc_unsafe.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs
#![allow(clippy::let_unit_value)]
diff --git a/src/tools/clippy/tests/ui/double_comparison.fixed b/src/tools/clippy/tests/ui/double_comparison.fixed
index bb6cdaa66..c80ff671a 100644
--- a/src/tools/clippy/tests/ui/double_comparison.fixed
+++ b/src/tools/clippy/tests/ui/double_comparison.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
fn main() {
let x = 1;
diff --git a/src/tools/clippy/tests/ui/double_comparison.rs b/src/tools/clippy/tests/ui/double_comparison.rs
index 9a2a9068a..bc78694aa 100644
--- a/src/tools/clippy/tests/ui/double_comparison.rs
+++ b/src/tools/clippy/tests/ui/double_comparison.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
fn main() {
let x = 1;
diff --git a/src/tools/clippy/tests/ui/drop_forget_copy.rs b/src/tools/clippy/tests/ui/drop_forget_copy.rs
deleted file mode 100644
index a7276dd59..000000000
--- a/src/tools/clippy/tests/ui/drop_forget_copy.rs
+++ /dev/null
@@ -1,86 +0,0 @@
-#![warn(clippy::drop_copy, clippy::forget_copy)]
-#![allow(clippy::toplevel_ref_arg, clippy::drop_ref, clippy::forget_ref, unused_mut)]
-
-use std::mem::{drop, forget};
-use std::vec::Vec;
-
-#[derive(Copy, Clone)]
-struct SomeStruct;
-
-struct AnotherStruct {
- x: u8,
- y: u8,
- z: Vec<u8>,
-}
-
-impl Clone for AnotherStruct {
- fn clone(&self) -> AnotherStruct {
- AnotherStruct {
- x: self.x,
- y: self.y,
- z: self.z.clone(),
- }
- }
-}
-
-fn main() {
- let s1 = SomeStruct {};
- let s2 = s1;
- let s3 = &s1;
- let mut s4 = s1;
- let ref s5 = s1;
-
- drop(s1);
- drop(s2);
- drop(s3);
- drop(s4);
- drop(s5);
-
- forget(s1);
- forget(s2);
- forget(s3);
- forget(s4);
- forget(s5);
-
- let a1 = AnotherStruct {
- x: 255,
- y: 0,
- z: vec![1, 2, 3],
- };
- let a2 = &a1;
- let mut a3 = a1.clone();
- let ref a4 = a1;
- let a5 = a1.clone();
-
- drop(a2);
- drop(a3);
- drop(a4);
- drop(a5);
-
- forget(a2);
- let a3 = &a1;
- forget(a3);
- forget(a4);
- let a5 = a1.clone();
- forget(a5);
-}
-
-#[allow(unused)]
-#[allow(clippy::unit_cmp)]
-fn issue9482(x: u8) {
- fn println_and<T>(t: T) -> T {
- println!("foo");
- t
- }
-
- match x {
- 0 => drop(println_and(12)), // Don't lint (copy type), we only care about side-effects
- 1 => drop(println_and(String::new())), // Don't lint (no copy type), we only care about side-effects
- 2 => {
- drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block
- },
- 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
- 4 => drop(2), // Lint, not a fn/method call
- _ => (),
- }
-}
diff --git a/src/tools/clippy/tests/ui/drop_forget_copy.stderr b/src/tools/clippy/tests/ui/drop_forget_copy.stderr
deleted file mode 100644
index 90bef1c3c..000000000
--- a/src/tools/clippy/tests/ui/drop_forget_copy.stderr
+++ /dev/null
@@ -1,112 +0,0 @@
-error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
- --> $DIR/drop_forget_copy.rs:33:5
- |
-LL | drop(s1);
- | ^^^^^^^^
- |
-note: argument has type `SomeStruct`
- --> $DIR/drop_forget_copy.rs:33:10
- |
-LL | drop(s1);
- | ^^
- = note: `-D clippy::drop-copy` implied by `-D warnings`
-
-error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
- --> $DIR/drop_forget_copy.rs:34:5
- |
-LL | drop(s2);
- | ^^^^^^^^
- |
-note: argument has type `SomeStruct`
- --> $DIR/drop_forget_copy.rs:34:10
- |
-LL | drop(s2);
- | ^^
-
-error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
- --> $DIR/drop_forget_copy.rs:36:5
- |
-LL | drop(s4);
- | ^^^^^^^^
- |
-note: argument has type `SomeStruct`
- --> $DIR/drop_forget_copy.rs:36:10
- |
-LL | drop(s4);
- | ^^
-
-error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact
- --> $DIR/drop_forget_copy.rs:39:5
- |
-LL | forget(s1);
- | ^^^^^^^^^^
- |
-note: argument has type `SomeStruct`
- --> $DIR/drop_forget_copy.rs:39:12
- |
-LL | forget(s1);
- | ^^
- = note: `-D clippy::forget-copy` implied by `-D warnings`
-
-error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact
- --> $DIR/drop_forget_copy.rs:40:5
- |
-LL | forget(s2);
- | ^^^^^^^^^^
- |
-note: argument has type `SomeStruct`
- --> $DIR/drop_forget_copy.rs:40:12
- |
-LL | forget(s2);
- | ^^
-
-error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact
- --> $DIR/drop_forget_copy.rs:42:5
- |
-LL | forget(s4);
- | ^^^^^^^^^^
- |
-note: argument has type `SomeStruct`
- --> $DIR/drop_forget_copy.rs:42:12
- |
-LL | forget(s4);
- | ^^
-
-error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
- --> $DIR/drop_forget_copy.rs:80:13
- |
-LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block
- | ^^^^^^^^^^^^^^^^^^^^^
- |
-note: argument has type `i32`
- --> $DIR/drop_forget_copy.rs:80:18
- |
-LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block
- | ^^^^^^^^^^^^^^^
-
-error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
- --> $DIR/drop_forget_copy.rs:82:14
- |
-LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
- | ^^^^^^^^^^^^^^^^^^^^^
- |
-note: argument has type `i32`
- --> $DIR/drop_forget_copy.rs:82:19
- |
-LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
- | ^^^^^^^^^^^^^^^
-
-error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
- --> $DIR/drop_forget_copy.rs:83:14
- |
-LL | 4 => drop(2), // Lint, not a fn/method call
- | ^^^^^^^
- |
-note: argument has type `i32`
- --> $DIR/drop_forget_copy.rs:83:19
- |
-LL | 4 => drop(2), // Lint, not a fn/method call
- | ^
-
-error: aborting due to 9 previous errors
-
diff --git a/src/tools/clippy/tests/ui/drop_ref.rs b/src/tools/clippy/tests/ui/drop_ref.rs
deleted file mode 100644
index 10044e65f..000000000
--- a/src/tools/clippy/tests/ui/drop_ref.rs
+++ /dev/null
@@ -1,97 +0,0 @@
-#![warn(clippy::drop_ref)]
-#![allow(clippy::toplevel_ref_arg)]
-#![allow(clippy::map_err_ignore)]
-#![allow(clippy::unnecessary_wraps, clippy::drop_non_drop)]
-
-use std::mem::drop;
-
-struct SomeStruct;
-
-fn main() {
- drop(&SomeStruct);
-
- let mut owned1 = SomeStruct;
- drop(&owned1);
- drop(&&owned1);
- drop(&mut owned1);
- drop(owned1); //OK
-
- let reference1 = &SomeStruct;
- drop(reference1);
-
- let reference2 = &mut SomeStruct;
- drop(reference2);
-
- let ref reference3 = SomeStruct;
- drop(reference3);
-}
-
-#[allow(dead_code)]
-fn test_generic_fn_drop<T>(val: T) {
- drop(&val);
- drop(val); //OK
-}
-
-#[allow(dead_code)]
-fn test_similarly_named_function() {
- fn drop<T>(_val: T) {}
- drop(&SomeStruct); //OK; call to unrelated function which happens to have the same name
- std::mem::drop(&SomeStruct);
-}
-
-#[derive(Copy, Clone)]
-pub struct Error;
-fn produce_half_owl_error() -> Result<(), Error> {
- Ok(())
-}
-
-fn produce_half_owl_ok() -> Result<bool, ()> {
- Ok(true)
-}
-
-#[allow(dead_code)]
-fn test_owl_result() -> Result<(), ()> {
- produce_half_owl_error().map_err(|_| ())?;
- produce_half_owl_ok().map(|_| ())?;
- // the following should not be linted,
- // we should not force users to use toilet closures
- // to produce owl results when drop is more convenient
- produce_half_owl_error().map_err(drop)?;
- produce_half_owl_ok().map_err(drop)?;
- Ok(())
-}
-
-#[allow(dead_code)]
-fn test_owl_result_2() -> Result<u8, ()> {
- produce_half_owl_error().map_err(|_| ())?;
- produce_half_owl_ok().map(|_| ())?;
- // the following should not be linted,
- // we should not force users to use toilet closures
- // to produce owl results when drop is more convenient
- produce_half_owl_error().map_err(drop)?;
- produce_half_owl_ok().map(drop)?;
- Ok(1)
-}
-
-#[allow(unused)]
-#[allow(clippy::unit_cmp)]
-fn issue10122(x: u8) {
- // This is a function which returns a reference and has a side-effect, which means
- // that calling drop() on the function is considered an idiomatic way of achieving the side-effect
- // in a match arm.
- fn println_and<T>(t: &T) -> &T {
- println!("foo");
- t
- }
-
- match x {
- 0 => drop(println_and(&12)), // Don't lint (copy type), we only care about side-effects
- 1 => drop(println_and(&String::new())), // Don't lint (no copy type), we only care about side-effects
- 2 => {
- drop(println_and(&13)); // Lint, even if we only care about the side-effect, it's already in a block
- },
- 3 if drop(println_and(&14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
- 4 => drop(&2), // Lint, not a fn/method call
- _ => (),
- }
-}
diff --git a/src/tools/clippy/tests/ui/drop_ref.stderr b/src/tools/clippy/tests/ui/drop_ref.stderr
deleted file mode 100644
index 293b9f6de..000000000
--- a/src/tools/clippy/tests/ui/drop_ref.stderr
+++ /dev/null
@@ -1,147 +0,0 @@
-error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
- --> $DIR/drop_ref.rs:11:5
- |
-LL | drop(&SomeStruct);
- | ^^^^^^^^^^^^^^^^^
- |
-note: argument has type `&SomeStruct`
- --> $DIR/drop_ref.rs:11:10
- |
-LL | drop(&SomeStruct);
- | ^^^^^^^^^^^
- = note: `-D clippy::drop-ref` implied by `-D warnings`
-
-error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
- --> $DIR/drop_ref.rs:14:5
- |
-LL | drop(&owned1);
- | ^^^^^^^^^^^^^
- |
-note: argument has type `&SomeStruct`
- --> $DIR/drop_ref.rs:14:10
- |
-LL | drop(&owned1);
- | ^^^^^^^
-
-error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
- --> $DIR/drop_ref.rs:15:5
- |
-LL | drop(&&owned1);
- | ^^^^^^^^^^^^^^
- |
-note: argument has type `&&SomeStruct`
- --> $DIR/drop_ref.rs:15:10
- |
-LL | drop(&&owned1);
- | ^^^^^^^^
-
-error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
- --> $DIR/drop_ref.rs:16:5
- |
-LL | drop(&mut owned1);
- | ^^^^^^^^^^^^^^^^^
- |
-note: argument has type `&mut SomeStruct`
- --> $DIR/drop_ref.rs:16:10
- |
-LL | drop(&mut owned1);
- | ^^^^^^^^^^^
-
-error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
- --> $DIR/drop_ref.rs:20:5
- |
-LL | drop(reference1);
- | ^^^^^^^^^^^^^^^^
- |
-note: argument has type `&SomeStruct`
- --> $DIR/drop_ref.rs:20:10
- |
-LL | drop(reference1);
- | ^^^^^^^^^^
-
-error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
- --> $DIR/drop_ref.rs:23:5
- |
-LL | drop(reference2);
- | ^^^^^^^^^^^^^^^^
- |
-note: argument has type `&mut SomeStruct`
- --> $DIR/drop_ref.rs:23:10
- |
-LL | drop(reference2);
- | ^^^^^^^^^^
-
-error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
- --> $DIR/drop_ref.rs:26:5
- |
-LL | drop(reference3);
- | ^^^^^^^^^^^^^^^^
- |
-note: argument has type `&SomeStruct`
- --> $DIR/drop_ref.rs:26:10
- |
-LL | drop(reference3);
- | ^^^^^^^^^^
-
-error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
- --> $DIR/drop_ref.rs:31:5
- |
-LL | drop(&val);
- | ^^^^^^^^^^
- |
-note: argument has type `&T`
- --> $DIR/drop_ref.rs:31:10
- |
-LL | drop(&val);
- | ^^^^
-
-error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
- --> $DIR/drop_ref.rs:39:5
- |
-LL | std::mem::drop(&SomeStruct);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
-note: argument has type `&SomeStruct`
- --> $DIR/drop_ref.rs:39:20
- |
-LL | std::mem::drop(&SomeStruct);
- | ^^^^^^^^^^^
-
-error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
- --> $DIR/drop_ref.rs:91:13
- |
-LL | drop(println_and(&13)); // Lint, even if we only care about the side-effect, it's already in a block
- | ^^^^^^^^^^^^^^^^^^^^^^
- |
-note: argument has type `&i32`
- --> $DIR/drop_ref.rs:91:18
- |
-LL | drop(println_and(&13)); // Lint, even if we only care about the side-effect, it's already in a block
- | ^^^^^^^^^^^^^^^^
-
-error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
- --> $DIR/drop_ref.rs:93:14
- |
-LL | 3 if drop(println_and(&14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
- | ^^^^^^^^^^^^^^^^^^^^^^
- |
-note: argument has type `&i32`
- --> $DIR/drop_ref.rs:93:19
- |
-LL | 3 if drop(println_and(&14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
- | ^^^^^^^^^^^^^^^^
-
-error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
- --> $DIR/drop_ref.rs:94:14
- |
-LL | 4 => drop(&2), // Lint, not a fn/method call
- | ^^^^^^^^
- |
-note: argument has type `&i32`
- --> $DIR/drop_ref.rs:94:19
- |
-LL | 4 => drop(&2), // Lint, not a fn/method call
- | ^^
-
-error: aborting due to 12 previous errors
-
diff --git a/src/tools/clippy/tests/ui/duration_subsec.fixed b/src/tools/clippy/tests/ui/duration_subsec.fixed
index d92b8998e..bfd30f004 100644
--- a/src/tools/clippy/tests/ui/duration_subsec.fixed
+++ b/src/tools/clippy/tests/ui/duration_subsec.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, clippy::needless_borrow)]
#![warn(clippy::duration_subsec)]
diff --git a/src/tools/clippy/tests/ui/duration_subsec.rs b/src/tools/clippy/tests/ui/duration_subsec.rs
index 08da80499..860233f08 100644
--- a/src/tools/clippy/tests/ui/duration_subsec.rs
+++ b/src/tools/clippy/tests/ui/duration_subsec.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, clippy::needless_borrow)]
#![warn(clippy::duration_subsec)]
diff --git a/src/tools/clippy/tests/ui/empty_drop.fixed b/src/tools/clippy/tests/ui/empty_drop.fixed
index 2e1b76846..fd0a9a708 100644
--- a/src/tools/clippy/tests/ui/empty_drop.fixed
+++ b/src/tools/clippy/tests/ui/empty_drop.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::empty_drop)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/empty_drop.rs b/src/tools/clippy/tests/ui/empty_drop.rs
index 75232b033..6c15cb933 100644
--- a/src/tools/clippy/tests/ui/empty_drop.rs
+++ b/src/tools/clippy/tests/ui/empty_drop.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::empty_drop)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/empty_line_after_doc_comments.rs b/src/tools/clippy/tests/ui/empty_line_after_doc_comments.rs
new file mode 100644
index 000000000..e843770f5
--- /dev/null
+++ b/src/tools/clippy/tests/ui/empty_line_after_doc_comments.rs
@@ -0,0 +1,132 @@
+//@aux-build:proc_macro_attr.rs
+#![warn(clippy::empty_line_after_doc_comments)]
+#![allow(clippy::assertions_on_constants)]
+#![feature(custom_inner_attributes)]
+#![rustfmt::skip]
+
+#[macro_use]
+extern crate proc_macro_attr;
+
+mod some_mod {
+ //! This doc comment should *NOT* produce a warning
+
+ mod some_inner_mod {
+ fn some_noop() {}
+ }
+}
+
+/// This should produce a warning
+
+fn with_doc_and_newline() { assert!(true)}
+
+// This should *NOT* produce a warning
+#[crate_type = "lib"]
+
+/// some comment
+fn with_one_newline_and_comment() { assert!(true) }
+
+// This should *NOT* produce a warning
+#[crate_type = "lib"]
+/// some comment
+fn with_no_newline_and_comment() { assert!(true) }
+
+
+// This should *NOT* produce a warning
+#[crate_type = "lib"]
+
+fn with_one_newline() { assert!(true) }
+
+// This should *NOT* produce a warning
+#[crate_type = "lib"]
+
+
+fn with_two_newlines() { assert!(true) }
+
+
+// This should *NOT* produce a warning
+#[crate_type = "lib"]
+
+enum Baz {
+ One,
+ Two
+}
+
+// This should *NOT* produce a warning
+#[crate_type = "lib"]
+
+struct Foo {
+ one: isize,
+ two: isize
+}
+
+// This should *NOT* produce a warning
+#[crate_type = "lib"]
+
+mod foo {
+}
+
+/// This doc comment should produce a warning
+
+/** This is also a doc comment and should produce a warning
+ */
+
+// This should *NOT* produce a warning
+#[allow(non_camel_case_types)]
+#[allow(missing_docs)]
+#[allow(missing_docs)]
+fn three_attributes() { assert!(true) }
+
+// This should *NOT* produce a warning
+#[doc = "
+Returns the escaped value of the textual representation of
+
+"]
+pub fn function() -> bool {
+ true
+}
+
+// This should *NOT* produce a warning
+#[derive(Clone, Copy)]
+pub enum FooFighter {
+ Bar1,
+
+ Bar2,
+
+ Bar3,
+
+ Bar4
+}
+
+// This should *NOT* produce a warning because the empty line is inside a block comment
+#[crate_type = "lib"]
+/*
+
+*/
+pub struct S;
+
+// This should *NOT* produce a warning
+#[crate_type = "lib"]
+/* test */
+pub struct T;
+
+// This should *NOT* produce a warning
+// See https://github.com/rust-lang/rust-clippy/issues/5567
+#[fake_async_trait]
+pub trait Bazz {
+ fn foo() -> Vec<u8> {
+ let _i = "";
+
+
+
+ vec![]
+ }
+}
+
+#[derive(Clone, Copy)]
+#[dummy(string = "first line
+
+second line
+")]
+pub struct Args;
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/empty_line_after_doc_comments.stderr b/src/tools/clippy/tests/ui/empty_line_after_doc_comments.stderr
new file mode 100644
index 000000000..2ca1b5167
--- /dev/null
+++ b/src/tools/clippy/tests/ui/empty_line_after_doc_comments.stderr
@@ -0,0 +1,36 @@
+error: found an empty line after a doc comment. Perhaps you need to use `//!` to make a comment on a module, remove the empty line, or make a regular comment with `//`?
+ --> $DIR/empty_line_after_doc_comments.rs:18:1
+ |
+LL | / /// This should produce a warning
+LL | |
+LL | | fn with_doc_and_newline() { assert!(true)}
+ | |_
+ |
+ = note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings`
+
+error: found an empty line after a doc comment. Perhaps you need to use `//!` to make a comment on a module, remove the empty line, or make a regular comment with `//`?
+ --> $DIR/empty_line_after_doc_comments.rs:68:1
+ |
+LL | / /// This doc comment should produce a warning
+LL | |
+LL | | /** This is also a doc comment and should produce a warning
+LL | | */
+... |
+LL | | #[allow(missing_docs)]
+LL | | fn three_attributes() { assert!(true) }
+ | |_
+
+error: found an empty line after a doc comment. Perhaps you need to use `//!` to make a comment on a module, remove the empty line, or make a regular comment with `//`?
+ --> $DIR/empty_line_after_doc_comments.rs:70:1
+ |
+LL | / /** This is also a doc comment and should produce a warning
+LL | | */
+LL | |
+LL | | // This should *NOT* produce a warning
+... |
+LL | | #[allow(missing_docs)]
+LL | | fn three_attributes() { assert!(true) }
+ | |_
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs b/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs
index 697412c00..269e66ea0 100644
--- a/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs
+++ b/src/tools/clippy/tests/ui/empty_line_after_outer_attribute.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macro_attr.rs
+//@aux-build:proc_macro_attr.rs
#![warn(clippy::empty_line_after_outer_attr)]
#![allow(clippy::assertions_on_constants)]
#![feature(custom_inner_attributes)]
diff --git a/src/tools/clippy/tests/ui/empty_loop.rs b/src/tools/clippy/tests/ui/empty_loop.rs
index 6a8e6b550..54e8fb490 100644
--- a/src/tools/clippy/tests/ui/empty_loop.rs
+++ b/src/tools/clippy/tests/ui/empty_loop.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs
#![warn(clippy::empty_loop)]
diff --git a/src/tools/clippy/tests/ui/empty_loop_no_std.rs b/src/tools/clippy/tests/ui/empty_loop_no_std.rs
index e742b396f..d564b2d24 100644
--- a/src/tools/clippy/tests/ui/empty_loop_no_std.rs
+++ b/src/tools/clippy/tests/ui/empty_loop_no_std.rs
@@ -1,5 +1,5 @@
-// compile-flags: -Clink-arg=-nostartfiles
-// ignore-macos
+//@compile-flags: -Clink-arg=-nostartfiles
+//@ignore-macos
#![warn(clippy::empty_loop)]
#![feature(lang_items, start, libc)]
diff --git a/src/tools/clippy/tests/ui/empty_structs_with_brackets.fixed b/src/tools/clippy/tests/ui/empty_structs_with_brackets.fixed
index 80f07603b..6fab30208 100644
--- a/src/tools/clippy/tests/ui/empty_structs_with_brackets.fixed
+++ b/src/tools/clippy/tests/ui/empty_structs_with_brackets.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::empty_structs_with_brackets)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/empty_structs_with_brackets.rs b/src/tools/clippy/tests/ui/empty_structs_with_brackets.rs
index 1d1ed4c76..0caa3c49c 100644
--- a/src/tools/clippy/tests/ui/empty_structs_with_brackets.rs
+++ b/src/tools/clippy/tests/ui/empty_structs_with_brackets.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::empty_structs_with_brackets)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/entry.fixed b/src/tools/clippy/tests/ui/entry.fixed
index dbe09e0ff..7e8239060 100644
--- a/src/tools/clippy/tests/ui/entry.fixed
+++ b/src/tools/clippy/tests/ui/entry.fixed
@@ -1,5 +1,5 @@
-// needs-asm-support
-// run-rustfix
+//@needs-asm-support
+//@run-rustfix
#![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)]
#![warn(clippy::map_entry)]
diff --git a/src/tools/clippy/tests/ui/entry.rs b/src/tools/clippy/tests/ui/entry.rs
index 30fed34fc..742c93225 100644
--- a/src/tools/clippy/tests/ui/entry.rs
+++ b/src/tools/clippy/tests/ui/entry.rs
@@ -1,5 +1,5 @@
-// needs-asm-support
-// run-rustfix
+//@needs-asm-support
+//@run-rustfix
#![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)]
#![warn(clippy::map_entry)]
diff --git a/src/tools/clippy/tests/ui/entry_btree.fixed b/src/tools/clippy/tests/ui/entry_btree.fixed
index 949791045..3baaacffd 100644
--- a/src/tools/clippy/tests/ui/entry_btree.fixed
+++ b/src/tools/clippy/tests/ui/entry_btree.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::map_entry)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/entry_btree.rs b/src/tools/clippy/tests/ui/entry_btree.rs
index 080c1d959..770e8e91d 100644
--- a/src/tools/clippy/tests/ui/entry_btree.rs
+++ b/src/tools/clippy/tests/ui/entry_btree.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::map_entry)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/entry_with_else.fixed b/src/tools/clippy/tests/ui/entry_with_else.fixed
index 2332fa631..71fe04fd6 100644
--- a/src/tools/clippy/tests/ui/entry_with_else.fixed
+++ b/src/tools/clippy/tests/ui/entry_with_else.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)]
#![warn(clippy::map_entry)]
diff --git a/src/tools/clippy/tests/ui/entry_with_else.rs b/src/tools/clippy/tests/ui/entry_with_else.rs
index 2ff0c038e..80f74649a 100644
--- a/src/tools/clippy/tests/ui/entry_with_else.rs
+++ b/src/tools/clippy/tests/ui/entry_with_else.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)]
#![warn(clippy::map_entry)]
diff --git a/src/tools/clippy/tests/ui/enum_clike_unportable_variant.rs b/src/tools/clippy/tests/ui/enum_clike_unportable_variant.rs
index 7d6842f5b..f17556ea9 100644
--- a/src/tools/clippy/tests/ui/enum_clike_unportable_variant.rs
+++ b/src/tools/clippy/tests/ui/enum_clike_unportable_variant.rs
@@ -1,4 +1,4 @@
-// ignore-x86
+//@ignore-x86
#![warn(clippy::enum_clike_unportable_variant)]
#![allow(unused, non_upper_case_globals)]
diff --git a/src/tools/clippy/tests/ui/enum_glob_use.fixed b/src/tools/clippy/tests/ui/enum_glob_use.fixed
index a98216758..419370ffb 100644
--- a/src/tools/clippy/tests/ui/enum_glob_use.fixed
+++ b/src/tools/clippy/tests/ui/enum_glob_use.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::enum_glob_use)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/enum_glob_use.rs b/src/tools/clippy/tests/ui/enum_glob_use.rs
index 5d929c973..645ed9832 100644
--- a/src/tools/clippy/tests/ui/enum_glob_use.rs
+++ b/src/tools/clippy/tests/ui/enum_glob_use.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::enum_glob_use)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/enum_variants.rs b/src/tools/clippy/tests/ui/enum_variants.rs
index efed12ee2..531652a0e 100644
--- a/src/tools/clippy/tests/ui/enum_variants.rs
+++ b/src/tools/clippy/tests/ui/enum_variants.rs
@@ -179,4 +179,14 @@ mod issue9018 {
}
}
+mod allow_attributes_on_variants {
+ enum Enum {
+ #[allow(clippy::enum_variant_names)]
+ EnumStartsWith,
+ #[allow(clippy::enum_variant_names)]
+ EndsWithEnum,
+ Foo,
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/eq_op.rs b/src/tools/clippy/tests/ui/eq_op.rs
index e73795502..cdd33ebe5 100644
--- a/src/tools/clippy/tests/ui/eq_op.rs
+++ b/src/tools/clippy/tests/ui/eq_op.rs
@@ -1,4 +1,4 @@
-// compile-flags: --test
+//@compile-flags: --test
#![warn(clippy::eq_op)]
#![allow(clippy::double_parens, clippy::identity_op, clippy::nonminimal_bool)]
diff --git a/src/tools/clippy/tests/ui/equatable_if_let.fixed b/src/tools/clippy/tests/ui/equatable_if_let.fixed
index 007702ab5..53e62760b 100644
--- a/src/tools/clippy/tests/ui/equatable_if_let.fixed
+++ b/src/tools/clippy/tests/ui/equatable_if_let.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![allow(unused_variables, dead_code, clippy::derive_partial_eq_without_eq)]
#![warn(clippy::equatable_if_let)]
diff --git a/src/tools/clippy/tests/ui/equatable_if_let.rs b/src/tools/clippy/tests/ui/equatable_if_let.rs
index 3bda79776..55918a5bb 100644
--- a/src/tools/clippy/tests/ui/equatable_if_let.rs
+++ b/src/tools/clippy/tests/ui/equatable_if_let.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![allow(unused_variables, dead_code, clippy::derive_partial_eq_without_eq)]
#![warn(clippy::equatable_if_let)]
diff --git a/src/tools/clippy/tests/ui/err_expect.fixed b/src/tools/clippy/tests/ui/err_expect.fixed
index b63cbd8a8..6ade6f546 100644
--- a/src/tools/clippy/tests/ui/err_expect.fixed
+++ b/src/tools/clippy/tests/ui/err_expect.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/err_expect.rs b/src/tools/clippy/tests/ui/err_expect.rs
index c081a745f..a93fb5949 100644
--- a/src/tools/clippy/tests/ui/err_expect.rs
+++ b/src/tools/clippy/tests/ui/err_expect.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/eta.fixed b/src/tools/clippy/tests/ui/eta.fixed
index dc129591e..b1baf462c 100644
--- a/src/tools/clippy/tests/ui/eta.fixed
+++ b/src/tools/clippy/tests/ui/eta.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::redundant_closure, clippy::redundant_closure_for_method_calls)]
#![allow(unused)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/eta.rs b/src/tools/clippy/tests/ui/eta.rs
index 025fd6a0b..e113c3d6c 100644
--- a/src/tools/clippy/tests/ui/eta.rs
+++ b/src/tools/clippy/tests/ui/eta.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::redundant_closure, clippy::redundant_closure_for_method_calls)]
#![allow(unused)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/excessive_precision.fixed b/src/tools/clippy/tests/ui/excessive_precision.fixed
index b74bda182..0a0795738 100644
--- a/src/tools/clippy/tests/ui/excessive_precision.fixed
+++ b/src/tools/clippy/tests/ui/excessive_precision.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::excessive_precision)]
#![allow(dead_code, unused_variables, clippy::print_literal)]
diff --git a/src/tools/clippy/tests/ui/excessive_precision.rs b/src/tools/clippy/tests/ui/excessive_precision.rs
index 6e84a71f2..62a832caa 100644
--- a/src/tools/clippy/tests/ui/excessive_precision.rs
+++ b/src/tools/clippy/tests/ui/excessive_precision.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::excessive_precision)]
#![allow(dead_code, unused_variables, clippy::print_literal)]
diff --git a/src/tools/clippy/tests/ui/exhaustive_items.fixed b/src/tools/clippy/tests/ui/exhaustive_items.fixed
index c209f5b4b..6c7b1cab6 100644
--- a/src/tools/clippy/tests/ui/exhaustive_items.fixed
+++ b/src/tools/clippy/tests/ui/exhaustive_items.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/exhaustive_items.rs b/src/tools/clippy/tests/ui/exhaustive_items.rs
index 6f59dbf2d..d205bac2d 100644
--- a/src/tools/clippy/tests/ui/exhaustive_items.rs
+++ b/src/tools/clippy/tests/ui/exhaustive_items.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/expect_fun_call.fixed b/src/tools/clippy/tests/ui/expect_fun_call.fixed
index 15172ae34..8e97054fb 100644
--- a/src/tools/clippy/tests/ui/expect_fun_call.fixed
+++ b/src/tools/clippy/tests/ui/expect_fun_call.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::expect_fun_call)]
#![allow(clippy::to_string_in_format_args, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/expect_fun_call.rs b/src/tools/clippy/tests/ui/expect_fun_call.rs
index 0f448d004..31e6bcc7f 100644
--- a/src/tools/clippy/tests/ui/expect_fun_call.rs
+++ b/src/tools/clippy/tests/ui/expect_fun_call.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::expect_fun_call)]
#![allow(clippy::to_string_in_format_args, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/explicit_auto_deref.fixed b/src/tools/clippy/tests/ui/explicit_auto_deref.fixed
index 5d40c8504..71a5ed96d 100644
--- a/src/tools/clippy/tests/ui/explicit_auto_deref.fixed
+++ b/src/tools/clippy/tests/ui/explicit_auto_deref.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(closure_lifetime_binder)]
#![warn(clippy::explicit_auto_deref)]
diff --git a/src/tools/clippy/tests/ui/explicit_auto_deref.rs b/src/tools/clippy/tests/ui/explicit_auto_deref.rs
index 79e03f4d7..9d0cafa15 100644
--- a/src/tools/clippy/tests/ui/explicit_auto_deref.rs
+++ b/src/tools/clippy/tests/ui/explicit_auto_deref.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(closure_lifetime_binder)]
#![warn(clippy::explicit_auto_deref)]
diff --git a/src/tools/clippy/tests/ui/explicit_deref_methods.fixed b/src/tools/clippy/tests/ui/explicit_deref_methods.fixed
index 6d32bbece..60482c66d 100644
--- a/src/tools/clippy/tests/ui/explicit_deref_methods.fixed
+++ b/src/tools/clippy/tests/ui/explicit_deref_methods.fixed
@@ -1,9 +1,9 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::explicit_deref_methods)]
#![allow(unused_variables)]
#![allow(
clippy::borrow_deref_ref,
- clippy::clone_double_ref,
+ suspicious_double_ref_op,
clippy::explicit_auto_deref,
clippy::needless_borrow,
clippy::uninlined_format_args
diff --git a/src/tools/clippy/tests/ui/explicit_deref_methods.rs b/src/tools/clippy/tests/ui/explicit_deref_methods.rs
index 779909e42..e3613e216 100644
--- a/src/tools/clippy/tests/ui/explicit_deref_methods.rs
+++ b/src/tools/clippy/tests/ui/explicit_deref_methods.rs
@@ -1,9 +1,9 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::explicit_deref_methods)]
#![allow(unused_variables)]
#![allow(
clippy::borrow_deref_ref,
- clippy::clone_double_ref,
+ suspicious_double_ref_op,
clippy::explicit_auto_deref,
clippy::needless_borrow,
clippy::uninlined_format_args
diff --git a/src/tools/clippy/tests/ui/explicit_write.fixed b/src/tools/clippy/tests/ui/explicit_write.fixed
index 862c3fea9..213485bc2 100644
--- a/src/tools/clippy/tests/ui/explicit_write.fixed
+++ b/src/tools/clippy/tests/ui/explicit_write.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::explicit_write)]
#![allow(unused_imports)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/explicit_write.rs b/src/tools/clippy/tests/ui/explicit_write.rs
index 41d7c2255..64acd7108 100644
--- a/src/tools/clippy/tests/ui/explicit_write.rs
+++ b/src/tools/clippy/tests/ui/explicit_write.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::explicit_write)]
#![allow(unused_imports)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/extend_with_drain.fixed b/src/tools/clippy/tests/ui/extend_with_drain.fixed
index 71ebad24c..594f2f6d4 100644
--- a/src/tools/clippy/tests/ui/extend_with_drain.fixed
+++ b/src/tools/clippy/tests/ui/extend_with_drain.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::extend_with_drain)]
#![allow(clippy::iter_with_drain)]
use std::collections::BinaryHeap;
diff --git a/src/tools/clippy/tests/ui/extend_with_drain.rs b/src/tools/clippy/tests/ui/extend_with_drain.rs
index e9f011abb..3e2ad0205 100644
--- a/src/tools/clippy/tests/ui/extend_with_drain.rs
+++ b/src/tools/clippy/tests/ui/extend_with_drain.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::extend_with_drain)]
#![allow(clippy::iter_with_drain)]
use std::collections::BinaryHeap;
diff --git a/src/tools/clippy/tests/ui/extra_unused_lifetimes.rs b/src/tools/clippy/tests/ui/extra_unused_lifetimes.rs
index d6631e012..cdfaf8d3a 100644
--- a/src/tools/clippy/tests/ui/extra_unused_lifetimes.rs
+++ b/src/tools/clippy/tests/ui/extra_unused_lifetimes.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macro_derive.rs
+//@aux-build:proc_macro_derive.rs
#![allow(
unused,
diff --git a/src/tools/clippy/tests/ui/extra_unused_type_parameters.fixed b/src/tools/clippy/tests/ui/extra_unused_type_parameters.fixed
index 19e718625..adcd1f6d4 100644
--- a/src/tools/clippy/tests/ui/extra_unused_type_parameters.fixed
+++ b/src/tools/clippy/tests/ui/extra_unused_type_parameters.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::needless_lifetimes)]
#![warn(clippy::extra_unused_type_parameters)]
diff --git a/src/tools/clippy/tests/ui/extra_unused_type_parameters.rs b/src/tools/clippy/tests/ui/extra_unused_type_parameters.rs
index e53bb587e..c4c5227ac 100644
--- a/src/tools/clippy/tests/ui/extra_unused_type_parameters.rs
+++ b/src/tools/clippy/tests/ui/extra_unused_type_parameters.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::needless_lifetimes)]
#![warn(clippy::extra_unused_type_parameters)]
diff --git a/src/tools/clippy/tests/ui/field_reassign_with_default.rs b/src/tools/clippy/tests/ui/field_reassign_with_default.rs
index 0e208b3ed..2045b1eeb 100644
--- a/src/tools/clippy/tests/ui/field_reassign_with_default.rs
+++ b/src/tools/clippy/tests/ui/field_reassign_with_default.rs
@@ -1,5 +1,5 @@
-// aux-build:proc_macro_derive.rs
-// aux-build:proc_macros.rs
+//@aux-build:proc_macro_derive.rs
+//@aux-build:proc_macros.rs
#![warn(clippy::field_reassign_with_default)]
diff --git a/src/tools/clippy/tests/ui/filter_map_identity.fixed b/src/tools/clippy/tests/ui/filter_map_identity.fixed
index a5860aa49..44665b451 100644
--- a/src/tools/clippy/tests/ui/filter_map_identity.fixed
+++ b/src/tools/clippy/tests/ui/filter_map_identity.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_imports, clippy::needless_return)]
#![warn(clippy::filter_map_identity)]
diff --git a/src/tools/clippy/tests/ui/filter_map_identity.rs b/src/tools/clippy/tests/ui/filter_map_identity.rs
index 7e998b9cd..9832acb01 100644
--- a/src/tools/clippy/tests/ui/filter_map_identity.rs
+++ b/src/tools/clippy/tests/ui/filter_map_identity.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_imports, clippy::needless_return)]
#![warn(clippy::filter_map_identity)]
diff --git a/src/tools/clippy/tests/ui/filter_map_next_fixable.fixed b/src/tools/clippy/tests/ui/filter_map_next_fixable.fixed
index 462d46169..efb37f8b1 100644
--- a/src/tools/clippy/tests/ui/filter_map_next_fixable.fixed
+++ b/src/tools/clippy/tests/ui/filter_map_next_fixable.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all, clippy::pedantic)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/filter_map_next_fixable.rs b/src/tools/clippy/tests/ui/filter_map_next_fixable.rs
index 2ea00cf73..b10e20d35 100644
--- a/src/tools/clippy/tests/ui/filter_map_next_fixable.rs
+++ b/src/tools/clippy/tests/ui/filter_map_next_fixable.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all, clippy::pedantic)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/flat_map_identity.fixed b/src/tools/clippy/tests/ui/flat_map_identity.fixed
index 1f4b880ef..97091d6f1 100644
--- a/src/tools/clippy/tests/ui/flat_map_identity.fixed
+++ b/src/tools/clippy/tests/ui/flat_map_identity.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_imports, clippy::needless_return)]
#![warn(clippy::flat_map_identity)]
diff --git a/src/tools/clippy/tests/ui/flat_map_identity.rs b/src/tools/clippy/tests/ui/flat_map_identity.rs
index de14a06d4..5607683a5 100644
--- a/src/tools/clippy/tests/ui/flat_map_identity.rs
+++ b/src/tools/clippy/tests/ui/flat_map_identity.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_imports, clippy::needless_return)]
#![warn(clippy::flat_map_identity)]
diff --git a/src/tools/clippy/tests/ui/flat_map_option.fixed b/src/tools/clippy/tests/ui/flat_map_option.fixed
index 6a34f0089..eeab864c4 100644
--- a/src/tools/clippy/tests/ui/flat_map_option.fixed
+++ b/src/tools/clippy/tests/ui/flat_map_option.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::flat_map_option)]
#![allow(clippy::redundant_closure, clippy::unnecessary_filter_map)]
diff --git a/src/tools/clippy/tests/ui/flat_map_option.rs b/src/tools/clippy/tests/ui/flat_map_option.rs
index 2479abddb..ebc389f7f 100644
--- a/src/tools/clippy/tests/ui/flat_map_option.rs
+++ b/src/tools/clippy/tests/ui/flat_map_option.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::flat_map_option)]
#![allow(clippy::redundant_closure, clippy::unnecessary_filter_map)]
diff --git a/src/tools/clippy/tests/ui/float_arithmetic.rs b/src/tools/clippy/tests/ui/float_arithmetic.rs
index 60fa7569e..a928c35e8 100644
--- a/src/tools/clippy/tests/ui/float_arithmetic.rs
+++ b/src/tools/clippy/tests/ui/float_arithmetic.rs
@@ -1,4 +1,4 @@
-#![warn(clippy::integer_arithmetic, clippy::float_arithmetic)]
+#![warn(clippy::arithmetic_side_effects, clippy::float_arithmetic)]
#![allow(
unused,
clippy::shadow_reuse,
diff --git a/src/tools/clippy/tests/ui/floating_point_abs.fixed b/src/tools/clippy/tests/ui/floating_point_abs.fixed
index ca747fefc..0cc572822 100644
--- a/src/tools/clippy/tests/ui/floating_point_abs.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_abs.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]
diff --git a/src/tools/clippy/tests/ui/floating_point_abs.rs b/src/tools/clippy/tests/ui/floating_point_abs.rs
index e4b606574..6c732d398 100644
--- a/src/tools/clippy/tests/ui/floating_point_abs.rs
+++ b/src/tools/clippy/tests/ui/floating_point_abs.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]
diff --git a/src/tools/clippy/tests/ui/floating_point_arithmetic_nostd.rs b/src/tools/clippy/tests/ui/floating_point_arithmetic_nostd.rs
new file mode 100644
index 000000000..a42c6383c
--- /dev/null
+++ b/src/tools/clippy/tests/ui/floating_point_arithmetic_nostd.rs
@@ -0,0 +1,31 @@
+#![feature(lang_items, start)]
+#![warn(clippy::imprecise_flops)]
+#![warn(clippy::suboptimal_flops)]
+#![no_std]
+
+// The following should not lint, as the suggested methods {f32,f64}.mul_add()
+// and {f32,f64}::abs() are not available in no_std
+
+pub fn mul_add() {
+ let a: f64 = 1234.567;
+ let b: f64 = 45.67834;
+ let c: f64 = 0.0004;
+ let _ = a * b + c;
+}
+
+fn fake_abs1(num: f64) -> f64 {
+ if num >= 0.0 { num } else { -num }
+}
+
+#[start]
+fn main(_argc: isize, _argv: *const *const u8) -> isize {
+ 0
+}
+
+#[panic_handler]
+fn panic(_info: &core::panic::PanicInfo) -> ! {
+ loop {}
+}
+
+#[lang = "eh_personality"]
+extern "C" fn eh_personality() {}
diff --git a/src/tools/clippy/tests/ui/floating_point_exp.fixed b/src/tools/clippy/tests/ui/floating_point_exp.fixed
index b9e3d89c2..1a33b8153 100644
--- a/src/tools/clippy/tests/ui/floating_point_exp.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_exp.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::imprecise_flops)]
#![allow(clippy::unnecessary_cast)]
diff --git a/src/tools/clippy/tests/ui/floating_point_exp.rs b/src/tools/clippy/tests/ui/floating_point_exp.rs
index ef008dd9b..4f4a5ec81 100644
--- a/src/tools/clippy/tests/ui/floating_point_exp.rs
+++ b/src/tools/clippy/tests/ui/floating_point_exp.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::imprecise_flops)]
#![allow(clippy::unnecessary_cast)]
diff --git a/src/tools/clippy/tests/ui/floating_point_hypot.fixed b/src/tools/clippy/tests/ui/floating_point_hypot.fixed
index bbe411b3f..431cb2709 100644
--- a/src/tools/clippy/tests/ui/floating_point_hypot.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_hypot.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::imprecise_flops)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/floating_point_hypot.rs b/src/tools/clippy/tests/ui/floating_point_hypot.rs
index 586fd170e..e5506ed39 100644
--- a/src/tools/clippy/tests/ui/floating_point_hypot.rs
+++ b/src/tools/clippy/tests/ui/floating_point_hypot.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::imprecise_flops)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/floating_point_log.fixed b/src/tools/clippy/tests/ui/floating_point_log.fixed
index ee5406461..6582c0a0f 100644
--- a/src/tools/clippy/tests/ui/floating_point_log.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_log.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, clippy::double_parens, clippy::unnecessary_cast)]
#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)]
diff --git a/src/tools/clippy/tests/ui/floating_point_log.rs b/src/tools/clippy/tests/ui/floating_point_log.rs
index 0590670a5..854d269ff 100644
--- a/src/tools/clippy/tests/ui/floating_point_log.rs
+++ b/src/tools/clippy/tests/ui/floating_point_log.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, clippy::double_parens, clippy::unnecessary_cast)]
#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)]
diff --git a/src/tools/clippy/tests/ui/floating_point_logbase.fixed b/src/tools/clippy/tests/ui/floating_point_logbase.fixed
index 7347bf72c..0783ecee1 100644
--- a/src/tools/clippy/tests/ui/floating_point_logbase.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_logbase.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::suboptimal_flops)]
#![allow(clippy::unnecessary_cast)]
diff --git a/src/tools/clippy/tests/ui/floating_point_logbase.rs b/src/tools/clippy/tests/ui/floating_point_logbase.rs
index ba5b8d406..80fcfab68 100644
--- a/src/tools/clippy/tests/ui/floating_point_logbase.rs
+++ b/src/tools/clippy/tests/ui/floating_point_logbase.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::suboptimal_flops)]
#![allow(clippy::unnecessary_cast)]
diff --git a/src/tools/clippy/tests/ui/floating_point_mul_add.fixed b/src/tools/clippy/tests/ui/floating_point_mul_add.fixed
index d3e536ba3..8848981a1 100644
--- a/src/tools/clippy/tests/ui/floating_point_mul_add.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_mul_add.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]
diff --git a/src/tools/clippy/tests/ui/floating_point_mul_add.rs b/src/tools/clippy/tests/ui/floating_point_mul_add.rs
index 5d4a9e35c..b0edf5cb2 100644
--- a/src/tools/clippy/tests/ui/floating_point_mul_add.rs
+++ b/src/tools/clippy/tests/ui/floating_point_mul_add.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]
diff --git a/src/tools/clippy/tests/ui/floating_point_powf.fixed b/src/tools/clippy/tests/ui/floating_point_powf.fixed
index f7f93de29..1e660b140 100644
--- a/src/tools/clippy/tests/ui/floating_point_powf.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_powf.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)]
#![allow(clippy::unnecessary_cast)]
diff --git a/src/tools/clippy/tests/ui/floating_point_powf.rs b/src/tools/clippy/tests/ui/floating_point_powf.rs
index 499fc0e15..71c2f5292 100644
--- a/src/tools/clippy/tests/ui/floating_point_powf.rs
+++ b/src/tools/clippy/tests/ui/floating_point_powf.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)]
#![allow(clippy::unnecessary_cast)]
diff --git a/src/tools/clippy/tests/ui/floating_point_powi.fixed b/src/tools/clippy/tests/ui/floating_point_powi.fixed
index 8ffd4cc51..41d5288d6 100644
--- a/src/tools/clippy/tests/ui/floating_point_powi.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_powi.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::suboptimal_flops)]
#![allow(clippy::unnecessary_cast)]
diff --git a/src/tools/clippy/tests/ui/floating_point_powi.rs b/src/tools/clippy/tests/ui/floating_point_powi.rs
index 9ae3455a1..7951aab31 100644
--- a/src/tools/clippy/tests/ui/floating_point_powi.rs
+++ b/src/tools/clippy/tests/ui/floating_point_powi.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::suboptimal_flops)]
#![allow(clippy::unnecessary_cast)]
diff --git a/src/tools/clippy/tests/ui/floating_point_rad.fixed b/src/tools/clippy/tests/ui/floating_point_rad.fixed
index 27674b8a4..af2364527 100644
--- a/src/tools/clippy/tests/ui/floating_point_rad.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_rad.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]
diff --git a/src/tools/clippy/tests/ui/floating_point_rad.rs b/src/tools/clippy/tests/ui/floating_point_rad.rs
index f1ea73df3..d7612c56a 100644
--- a/src/tools/clippy/tests/ui/floating_point_rad.rs
+++ b/src/tools/clippy/tests/ui/floating_point_rad.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]
diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs b/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs
index a456c085c..4f6af8708 100644
--- a/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs
+++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast.rs
@@ -1,4 +1,4 @@
-// ignore-32bit
+//@ignore-32bit
#![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)]
diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs b/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs
index 04ee985c0..62ce97f09 100644
--- a/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs
+++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.rs
@@ -1,4 +1,4 @@
-// ignore-64bit
+//@ignore-64bit
#![warn(clippy::fn_to_numeric_cast, clippy::fn_to_numeric_cast_with_truncation)]
diff --git a/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.stderr b/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.stderr
index 08dd611d6..671347d2b 100644
--- a/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.stderr
+++ b/src/tools/clippy/tests/ui/fn_to_numeric_cast_32bit.stderr
@@ -12,19 +12,19 @@ error: casting function pointer `foo` to `i16`, which truncates the value
LL | let _ = foo as i16;
| ^^^^^^^^^^ help: try: `foo as usize`
-error: casting function pointer `foo` to `i32`
+error: casting function pointer `foo` to `i32`, which truncates the value
--> $DIR/fn_to_numeric_cast_32bit.rs:12:13
|
LL | let _ = foo as i32;
| ^^^^^^^^^^ help: try: `foo as usize`
- |
- = note: `-D clippy::fn-to-numeric-cast` implied by `-D warnings`
error: casting function pointer `foo` to `i64`
--> $DIR/fn_to_numeric_cast_32bit.rs:13:13
|
LL | let _ = foo as i64;
| ^^^^^^^^^^ help: try: `foo as usize`
+ |
+ = note: `-D clippy::fn-to-numeric-cast` implied by `-D warnings`
error: casting function pointer `foo` to `i128`
--> $DIR/fn_to_numeric_cast_32bit.rs:14:13
@@ -50,7 +50,7 @@ error: casting function pointer `foo` to `u16`, which truncates the value
LL | let _ = foo as u16;
| ^^^^^^^^^^ help: try: `foo as usize`
-error: casting function pointer `foo` to `u32`
+error: casting function pointer `foo` to `u32`, which truncates the value
--> $DIR/fn_to_numeric_cast_32bit.rs:19:13
|
LL | let _ = foo as u32;
@@ -80,7 +80,7 @@ error: casting function pointer `abc` to `i16`, which truncates the value
LL | let _ = abc as i16;
| ^^^^^^^^^^ help: try: `abc as usize`
-error: casting function pointer `abc` to `i32`
+error: casting function pointer `abc` to `i32`, which truncates the value
--> $DIR/fn_to_numeric_cast_32bit.rs:36:13
|
LL | let _ = abc as i32;
@@ -116,7 +116,7 @@ error: casting function pointer `abc` to `u16`, which truncates the value
LL | let _ = abc as u16;
| ^^^^^^^^^^ help: try: `abc as usize`
-error: casting function pointer `abc` to `u32`
+error: casting function pointer `abc` to `u32`, which truncates the value
--> $DIR/fn_to_numeric_cast_32bit.rs:43:13
|
LL | let _ = abc as u32;
@@ -134,7 +134,7 @@ error: casting function pointer `abc` to `u128`
LL | let _ = abc as u128;
| ^^^^^^^^^^^ help: try: `abc as usize`
-error: casting function pointer `f` to `i32`
+error: casting function pointer `f` to `i32`, which truncates the value
--> $DIR/fn_to_numeric_cast_32bit.rs:52:5
|
LL | f as i32
diff --git a/src/tools/clippy/tests/ui/for_loop_fixable.fixed b/src/tools/clippy/tests/ui/for_loop_fixable.fixed
index e9dd38fe4..f578c98da 100644
--- a/src/tools/clippy/tests/ui/for_loop_fixable.fixed
+++ b/src/tools/clippy/tests/ui/for_loop_fixable.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, unused)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/for_loop_fixable.rs b/src/tools/clippy/tests/ui/for_loop_fixable.rs
index 534fb4dd4..42bc6de0c 100644
--- a/src/tools/clippy/tests/ui/for_loop_fixable.rs
+++ b/src/tools/clippy/tests/ui/for_loop_fixable.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, unused)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/forget_ref.rs b/src/tools/clippy/tests/ui/forget_ref.rs
deleted file mode 100644
index 031b415f5..000000000
--- a/src/tools/clippy/tests/ui/forget_ref.rs
+++ /dev/null
@@ -1,50 +0,0 @@
-#![warn(clippy::forget_ref)]
-#![allow(clippy::toplevel_ref_arg)]
-#![allow(clippy::unnecessary_wraps, clippy::forget_non_drop)]
-#![allow(clippy::borrow_deref_ref)]
-
-use std::mem::forget;
-
-struct SomeStruct;
-
-fn main() {
- forget(&SomeStruct);
-
- let mut owned = SomeStruct;
- forget(&owned);
- forget(&&owned);
- forget(&mut owned);
- forget(owned); //OK
-
- let reference1 = &SomeStruct;
- forget(&*reference1);
-
- let reference2 = &mut SomeStruct;
- forget(reference2);
-
- let ref reference3 = SomeStruct;
- forget(reference3);
-}
-
-#[allow(dead_code)]
-fn test_generic_fn_forget<T>(val: T) {
- forget(&val);
- forget(val); //OK
-}
-
-#[allow(dead_code)]
-fn test_similarly_named_function() {
- fn forget<T>(_val: T) {}
- forget(&SomeStruct); //OK; call to unrelated function which happens to have the same name
- std::mem::forget(&SomeStruct);
-}
-
-#[derive(Copy, Clone)]
-pub struct Error;
-fn produce_half_owl_error() -> Result<(), Error> {
- Ok(())
-}
-
-fn produce_half_owl_ok() -> Result<bool, ()> {
- Ok(true)
-}
diff --git a/src/tools/clippy/tests/ui/forget_ref.stderr b/src/tools/clippy/tests/ui/forget_ref.stderr
deleted file mode 100644
index 011cdefc6..000000000
--- a/src/tools/clippy/tests/ui/forget_ref.stderr
+++ /dev/null
@@ -1,111 +0,0 @@
-error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
- --> $DIR/forget_ref.rs:11:5
- |
-LL | forget(&SomeStruct);
- | ^^^^^^^^^^^^^^^^^^^
- |
-note: argument has type `&SomeStruct`
- --> $DIR/forget_ref.rs:11:12
- |
-LL | forget(&SomeStruct);
- | ^^^^^^^^^^^
- = note: `-D clippy::forget-ref` implied by `-D warnings`
-
-error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
- --> $DIR/forget_ref.rs:14:5
- |
-LL | forget(&owned);
- | ^^^^^^^^^^^^^^
- |
-note: argument has type `&SomeStruct`
- --> $DIR/forget_ref.rs:14:12
- |
-LL | forget(&owned);
- | ^^^^^^
-
-error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
- --> $DIR/forget_ref.rs:15:5
- |
-LL | forget(&&owned);
- | ^^^^^^^^^^^^^^^
- |
-note: argument has type `&&SomeStruct`
- --> $DIR/forget_ref.rs:15:12
- |
-LL | forget(&&owned);
- | ^^^^^^^
-
-error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
- --> $DIR/forget_ref.rs:16:5
- |
-LL | forget(&mut owned);
- | ^^^^^^^^^^^^^^^^^^
- |
-note: argument has type `&mut SomeStruct`
- --> $DIR/forget_ref.rs:16:12
- |
-LL | forget(&mut owned);
- | ^^^^^^^^^^
-
-error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
- --> $DIR/forget_ref.rs:20:5
- |
-LL | forget(&*reference1);
- | ^^^^^^^^^^^^^^^^^^^^
- |
-note: argument has type `&SomeStruct`
- --> $DIR/forget_ref.rs:20:12
- |
-LL | forget(&*reference1);
- | ^^^^^^^^^^^^
-
-error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
- --> $DIR/forget_ref.rs:23:5
- |
-LL | forget(reference2);
- | ^^^^^^^^^^^^^^^^^^
- |
-note: argument has type `&mut SomeStruct`
- --> $DIR/forget_ref.rs:23:12
- |
-LL | forget(reference2);
- | ^^^^^^^^^^
-
-error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
- --> $DIR/forget_ref.rs:26:5
- |
-LL | forget(reference3);
- | ^^^^^^^^^^^^^^^^^^
- |
-note: argument has type `&SomeStruct`
- --> $DIR/forget_ref.rs:26:12
- |
-LL | forget(reference3);
- | ^^^^^^^^^^
-
-error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
- --> $DIR/forget_ref.rs:31:5
- |
-LL | forget(&val);
- | ^^^^^^^^^^^^
- |
-note: argument has type `&T`
- --> $DIR/forget_ref.rs:31:12
- |
-LL | forget(&val);
- | ^^^^
-
-error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
- --> $DIR/forget_ref.rs:39:5
- |
-LL | std::mem::forget(&SomeStruct);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
-note: argument has type `&SomeStruct`
- --> $DIR/forget_ref.rs:39:22
- |
-LL | std::mem::forget(&SomeStruct);
- | ^^^^^^^^^^^
-
-error: aborting due to 9 previous errors
-
diff --git a/src/tools/clippy/tests/ui/format.fixed b/src/tools/clippy/tests/ui/format.fixed
index beedf2c1d..9288956f5 100644
--- a/src/tools/clippy/tests/ui/format.fixed
+++ b/src/tools/clippy/tests/ui/format.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::useless_format)]
#![allow(
unused_tuple_struct_fields,
diff --git a/src/tools/clippy/tests/ui/format.rs b/src/tools/clippy/tests/ui/format.rs
index e805f1818..b2b817e0f 100644
--- a/src/tools/clippy/tests/ui/format.rs
+++ b/src/tools/clippy/tests/ui/format.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::useless_format)]
#![allow(
unused_tuple_struct_fields,
diff --git a/src/tools/clippy/tests/ui/format_args.fixed b/src/tools/clippy/tests/ui/format_args.fixed
index 825e122be..ea3836861 100644
--- a/src/tools/clippy/tests/ui/format_args.fixed
+++ b/src/tools/clippy/tests/ui/format_args.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::to_string_in_format_args)]
#![allow(unused)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/format_args.rs b/src/tools/clippy/tests/ui/format_args.rs
index a41e53389..bfb324492 100644
--- a/src/tools/clippy/tests/ui/format_args.rs
+++ b/src/tools/clippy/tests/ui/format_args.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::to_string_in_format_args)]
#![allow(unused)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed b/src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed
index 48f809331..915ff4fb0 100644
--- a/src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed
+++ b/src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::from_iter_instead_of_collect)]
#![allow(unused_imports, unused_tuple_struct_fields)]
diff --git a/src/tools/clippy/tests/ui/from_iter_instead_of_collect.rs b/src/tools/clippy/tests/ui/from_iter_instead_of_collect.rs
index ebe0ad278..e926f8c52 100644
--- a/src/tools/clippy/tests/ui/from_iter_instead_of_collect.rs
+++ b/src/tools/clippy/tests/ui/from_iter_instead_of_collect.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::from_iter_instead_of_collect)]
#![allow(unused_imports, unused_tuple_struct_fields)]
diff --git a/src/tools/clippy/tests/ui/from_over_into.fixed b/src/tools/clippy/tests/ui/from_over_into.fixed
index 72d635c2c..d18f93875 100644
--- a/src/tools/clippy/tests/ui/from_over_into.fixed
+++ b/src/tools/clippy/tests/ui/from_over_into.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(type_alias_impl_trait)]
#![warn(clippy::from_over_into)]
@@ -32,7 +32,7 @@ struct SelfKeywords;
impl From<X> for SelfKeywords {
fn from(val: X) -> Self {
- let _ = X::default();
+ let _ = X;
let _ = X::FOO;
let _: X = val;
diff --git a/src/tools/clippy/tests/ui/from_over_into.rs b/src/tools/clippy/tests/ui/from_over_into.rs
index 965f4d5d7..de8ff0b06 100644
--- a/src/tools/clippy/tests/ui/from_over_into.rs
+++ b/src/tools/clippy/tests/ui/from_over_into.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(type_alias_impl_trait)]
#![warn(clippy::from_over_into)]
@@ -32,7 +32,7 @@ struct SelfKeywords;
impl Into<SelfKeywords> for X {
fn into(self) -> SelfKeywords {
- let _ = Self::default();
+ let _ = Self;
let _ = Self::FOO;
let _: Self = self;
diff --git a/src/tools/clippy/tests/ui/from_over_into.stderr b/src/tools/clippy/tests/ui/from_over_into.stderr
index 3c4d011d6..6039f86fe 100644
--- a/src/tools/clippy/tests/ui/from_over_into.stderr
+++ b/src/tools/clippy/tests/ui/from_over_into.stderr
@@ -5,7 +5,7 @@ LL | impl Into<StringWrapper> for String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::from-over-into` implied by `-D warnings`
-help: replace the `Into` implentation with `From<std::string::String>`
+help: replace the `Into` implementation with `From<std::string::String>`
|
LL ~ impl From<String> for StringWrapper {
LL ~ fn from(val: String) -> Self {
@@ -18,7 +18,7 @@ error: an implementation of `From` is preferred since it gives you `Into<_>` for
LL | impl Into<SelfType> for String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-help: replace the `Into` implentation with `From<std::string::String>`
+help: replace the `Into` implementation with `From<std::string::String>`
|
LL ~ impl From<String> for SelfType {
LL ~ fn from(val: String) -> Self {
@@ -31,11 +31,11 @@ error: an implementation of `From` is preferred since it gives you `Into<_>` for
LL | impl Into<SelfKeywords> for X {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-help: replace the `Into` implentation with `From<X>`
+help: replace the `Into` implementation with `From<X>`
|
LL ~ impl From<X> for SelfKeywords {
LL ~ fn from(val: X) -> Self {
-LL ~ let _ = X::default();
+LL ~ let _ = X;
LL ~ let _ = X::FOO;
LL ~ let _: X = val;
|
@@ -48,7 +48,7 @@ LL | impl core::convert::Into<bool> for crate::ExplicitPaths {
|
= help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
-help: replace the `Into` implentation with `From<ExplicitPaths>`
+help: replace the `Into` implementation with `From<ExplicitPaths>`
|
LL ~ impl core::convert::From<crate::ExplicitPaths> for bool {
LL ~ fn from(mut val: crate::ExplicitPaths) -> Self {
@@ -64,7 +64,7 @@ error: an implementation of `From` is preferred since it gives you `Into<_>` for
LL | impl<T> Into<FromOverInto<T>> for Vec<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-help: replace the `Into` implentation with `From<std::vec::Vec<T>>`
+help: replace the `Into` implementation with `From<std::vec::Vec<T>>`
|
LL ~ impl<T> From<Vec<T>> for FromOverInto<T> {
LL ~ fn from(val: Vec<T>) -> Self {
diff --git a/src/tools/clippy/tests/ui/from_over_into_unfixable.stderr b/src/tools/clippy/tests/ui/from_over_into_unfixable.stderr
index 6f6ce3519..251f1d84e 100644
--- a/src/tools/clippy/tests/ui/from_over_into_unfixable.stderr
+++ b/src/tools/clippy/tests/ui/from_over_into_unfixable.stderr
@@ -4,7 +4,7 @@ error: an implementation of `From` is preferred since it gives you `Into<_>` for
LL | impl Into<InMacro> for String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: replace the `Into` implentation with `From<std::string::String>`
+ = help: replace the `Into` implementation with `From<std::string::String>`
= note: `-D clippy::from-over-into` implied by `-D warnings`
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
@@ -13,7 +13,7 @@ error: an implementation of `From` is preferred since it gives you `Into<_>` for
LL | impl Into<WeirdUpperSelf> for &'static [u8] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: replace the `Into` implentation with `From<&'static [u8]>`
+ = help: replace the `Into` implementation with `From<&'static [u8]>`
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
--> $DIR/from_over_into_unfixable.rs:28:1
@@ -23,7 +23,7 @@ LL | impl Into<u8> for ContainsVal {
|
= help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
- = help: replace the `Into` implentation with `From<ContainsVal>`
+ = help: replace the `Into` implementation with `From<ContainsVal>`
error: aborting due to 3 previous errors
diff --git a/src/tools/clippy/tests/ui/future_not_send.stderr b/src/tools/clippy/tests/ui/future_not_send.stderr
index 5b6858e45..5c6348962 100644
--- a/src/tools/clippy/tests/ui/future_not_send.stderr
+++ b/src/tools/clippy/tests/ui/future_not_send.stderr
@@ -5,22 +5,22 @@ LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
| ^^^^ future returned by `private_future` is not `Send`
|
note: future is not `Send` as this value is used across an await
- --> $DIR/future_not_send.rs:8:19
+ --> $DIR/future_not_send.rs:8:20
|
LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
| -- has type `std::rc::Rc<[u8]>` which is not `Send`
LL | async { true }.await
- | ^^^^^^ await occurs here, with `rc` maybe used later
+ | ^^^^^ await occurs here, with `rc` maybe used later
LL | }
| - `rc` is later dropped here
= note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send`
note: future is not `Send` as this value is used across an await
- --> $DIR/future_not_send.rs:8:19
+ --> $DIR/future_not_send.rs:8:20
|
LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
| ---- has type `&std::cell::Cell<usize>` which is not `Send`
LL | async { true }.await
- | ^^^^^^ await occurs here, with `cell` maybe used later
+ | ^^^^^ await occurs here, with `cell` maybe used later
LL | }
| - `cell` is later dropped here
= note: `std::cell::Cell<usize>` doesn't implement `std::marker::Sync`
@@ -33,12 +33,12 @@ LL | pub async fn public_future(rc: Rc<[u8]>) {
| ^ future returned by `public_future` is not `Send`
|
note: future is not `Send` as this value is used across an await
- --> $DIR/future_not_send.rs:12:19
+ --> $DIR/future_not_send.rs:12:20
|
LL | pub async fn public_future(rc: Rc<[u8]>) {
| -- has type `std::rc::Rc<[u8]>` which is not `Send`
LL | async { true }.await;
- | ^^^^^^ await occurs here, with `rc` maybe used later
+ | ^^^^^ await occurs here, with `rc` maybe used later
LL | }
| - `rc` is later dropped here
= note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Send`
@@ -82,12 +82,12 @@ LL | async fn private_future(&self) -> usize {
| ^^^^^ future returned by `private_future` is not `Send`
|
note: future is not `Send` as this value is used across an await
- --> $DIR/future_not_send.rs:35:23
+ --> $DIR/future_not_send.rs:35:24
|
LL | async fn private_future(&self) -> usize {
| ----- has type `&Dummy` which is not `Send`
LL | async { true }.await;
- | ^^^^^^ await occurs here, with `&self` maybe used later
+ | ^^^^^ await occurs here, with `&self` maybe used later
LL | self.rc.len()
LL | }
| - `&self` is later dropped here
@@ -100,12 +100,12 @@ LL | pub async fn public_future(&self) {
| ^ future returned by `public_future` is not `Send`
|
note: future is not `Send` as this value is used across an await
- --> $DIR/future_not_send.rs:40:30
+ --> $DIR/future_not_send.rs:40:31
|
LL | pub async fn public_future(&self) {
| ----- has type `&Dummy` which is not `Send`
LL | self.private_future().await;
- | ^^^^^^ await occurs here, with `&self` maybe used later
+ | ^^^^^ await occurs here, with `&self` maybe used later
LL | }
| - `&self` is later dropped here
= note: `std::rc::Rc<[u8]>` doesn't implement `std::marker::Sync`
@@ -117,12 +117,12 @@ LL | async fn generic_future<T>(t: T) -> T
| ^ future returned by `generic_future` is not `Send`
|
note: future is not `Send` as this value is used across an await
- --> $DIR/future_not_send.rs:54:19
+ --> $DIR/future_not_send.rs:54:20
|
LL | let rt = &t;
| -- has type `&T` which is not `Send`
LL | async { true }.await;
- | ^^^^^^ await occurs here, with `rt` maybe used later
+ | ^^^^^ await occurs here, with `rt` maybe used later
LL | t
LL | }
| - `rt` is later dropped here
diff --git a/src/tools/clippy/tests/ui/get_first.fixed b/src/tools/clippy/tests/ui/get_first.fixed
index def58afa4..ef132b796 100644
--- a/src/tools/clippy/tests/ui/get_first.fixed
+++ b/src/tools/clippy/tests/ui/get_first.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::get_first)]
use std::collections::BTreeMap;
use std::collections::HashMap;
diff --git a/src/tools/clippy/tests/ui/get_first.rs b/src/tools/clippy/tests/ui/get_first.rs
index 85a381854..4d8722356 100644
--- a/src/tools/clippy/tests/ui/get_first.rs
+++ b/src/tools/clippy/tests/ui/get_first.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::get_first)]
use std::collections::BTreeMap;
use std::collections::HashMap;
diff --git a/src/tools/clippy/tests/ui/get_last_with_len.fixed b/src/tools/clippy/tests/ui/get_last_with_len.fixed
index 1e90b3768..a58dfda79 100644
--- a/src/tools/clippy/tests/ui/get_last_with_len.fixed
+++ b/src/tools/clippy/tests/ui/get_last_with_len.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::get_last_with_len)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/get_last_with_len.rs b/src/tools/clippy/tests/ui/get_last_with_len.rs
index d63a731bd..d626656c7 100644
--- a/src/tools/clippy/tests/ui/get_last_with_len.rs
+++ b/src/tools/clippy/tests/ui/get_last_with_len.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::get_last_with_len)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/get_unwrap.fixed b/src/tools/clippy/tests/ui/get_unwrap.fixed
index 5827fc7d7..4950c47dd 100644
--- a/src/tools/clippy/tests/ui/get_unwrap.fixed
+++ b/src/tools/clippy/tests/ui/get_unwrap.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_mut, clippy::from_iter_instead_of_collect, clippy::get_first)]
#![warn(clippy::unwrap_used)]
diff --git a/src/tools/clippy/tests/ui/get_unwrap.rs b/src/tools/clippy/tests/ui/get_unwrap.rs
index a2a323c14..6b1e8edb7 100644
--- a/src/tools/clippy/tests/ui/get_unwrap.rs
+++ b/src/tools/clippy/tests/ui/get_unwrap.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_mut, clippy::from_iter_instead_of_collect, clippy::get_first)]
#![warn(clippy::unwrap_used)]
diff --git a/src/tools/clippy/tests/ui/identity_op.fixed b/src/tools/clippy/tests/ui/identity_op.fixed
index cac69ef42..beb16000e 100644
--- a/src/tools/clippy/tests/ui/identity_op.fixed
+++ b/src/tools/clippy/tests/ui/identity_op.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::identity_op)]
#![allow(unused)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/identity_op.rs b/src/tools/clippy/tests/ui/identity_op.rs
index 33201aad4..072e00c00 100644
--- a/src/tools/clippy/tests/ui/identity_op.rs
+++ b/src/tools/clippy/tests/ui/identity_op.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::identity_op)]
#![allow(unused)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/implicit_clone.fixed b/src/tools/clippy/tests/ui/implicit_clone.fixed
index 8ccc3da7b..e62db8b40 100644
--- a/src/tools/clippy/tests/ui/implicit_clone.fixed
+++ b/src/tools/clippy/tests/ui/implicit_clone.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::implicit_clone)]
#![allow(clippy::clone_on_copy, clippy::redundant_clone)]
use std::borrow::Borrow;
diff --git a/src/tools/clippy/tests/ui/implicit_clone.rs b/src/tools/clippy/tests/ui/implicit_clone.rs
index 593333126..88352b06a 100644
--- a/src/tools/clippy/tests/ui/implicit_clone.rs
+++ b/src/tools/clippy/tests/ui/implicit_clone.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::implicit_clone)]
#![allow(clippy::clone_on_copy, clippy::redundant_clone)]
use std::borrow::Borrow;
diff --git a/src/tools/clippy/tests/ui/implicit_hasher.rs b/src/tools/clippy/tests/ui/implicit_hasher.rs
index 35d08a07b..ca7c12213 100644
--- a/src/tools/clippy/tests/ui/implicit_hasher.rs
+++ b/src/tools/clippy/tests/ui/implicit_hasher.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs
#![deny(clippy::implicit_hasher)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/implicit_return.fixed b/src/tools/clippy/tests/ui/implicit_return.fixed
index 5e55b8b67..64813eafd 100644
--- a/src/tools/clippy/tests/ui/implicit_return.fixed
+++ b/src/tools/clippy/tests/ui/implicit_return.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(lint_reasons)]
#![warn(clippy::implicit_return)]
#![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)]
diff --git a/src/tools/clippy/tests/ui/implicit_return.rs b/src/tools/clippy/tests/ui/implicit_return.rs
index 76f0a9803..39d47b110 100644
--- a/src/tools/clippy/tests/ui/implicit_return.rs
+++ b/src/tools/clippy/tests/ui/implicit_return.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(lint_reasons)]
#![warn(clippy::implicit_return)]
#![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)]
diff --git a/src/tools/clippy/tests/ui/implicit_saturating_add.fixed b/src/tools/clippy/tests/ui/implicit_saturating_add.fixed
index 7d363d59a..7fc510d6b 100644
--- a/src/tools/clippy/tests/ui/implicit_saturating_add.fixed
+++ b/src/tools/clippy/tests/ui/implicit_saturating_add.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::implicit_saturating_add)]
diff --git a/src/tools/clippy/tests/ui/implicit_saturating_add.rs b/src/tools/clippy/tests/ui/implicit_saturating_add.rs
index 31a591627..3dcd91f42 100644
--- a/src/tools/clippy/tests/ui/implicit_saturating_add.rs
+++ b/src/tools/clippy/tests/ui/implicit_saturating_add.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::implicit_saturating_add)]
diff --git a/src/tools/clippy/tests/ui/implicit_saturating_sub.fixed b/src/tools/clippy/tests/ui/implicit_saturating_sub.fixed
index 93df81b1a..1a11db098 100644
--- a/src/tools/clippy/tests/ui/implicit_saturating_sub.fixed
+++ b/src/tools/clippy/tests/ui/implicit_saturating_sub.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_assignments, unused_mut, clippy::assign_op_pattern)]
#![warn(clippy::implicit_saturating_sub)]
diff --git a/src/tools/clippy/tests/ui/implicit_saturating_sub.rs b/src/tools/clippy/tests/ui/implicit_saturating_sub.rs
index 8340bc826..9369df674 100644
--- a/src/tools/clippy/tests/ui/implicit_saturating_sub.rs
+++ b/src/tools/clippy/tests/ui/implicit_saturating_sub.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_assignments, unused_mut, clippy::assign_op_pattern)]
#![warn(clippy::implicit_saturating_sub)]
diff --git a/src/tools/clippy/tests/ui/inconsistent_digit_grouping.fixed b/src/tools/clippy/tests/ui/inconsistent_digit_grouping.fixed
index dd683e7f7..06919809e 100644
--- a/src/tools/clippy/tests/ui/inconsistent_digit_grouping.fixed
+++ b/src/tools/clippy/tests/ui/inconsistent_digit_grouping.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#[warn(clippy::inconsistent_digit_grouping)]
#[deny(clippy::unreadable_literal)]
#[allow(unused_variables, clippy::excessive_precision)]
diff --git a/src/tools/clippy/tests/ui/inconsistent_digit_grouping.rs b/src/tools/clippy/tests/ui/inconsistent_digit_grouping.rs
index d5d27c853..04d9125f2 100644
--- a/src/tools/clippy/tests/ui/inconsistent_digit_grouping.rs
+++ b/src/tools/clippy/tests/ui/inconsistent_digit_grouping.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#[warn(clippy::inconsistent_digit_grouping)]
#[deny(clippy::unreadable_literal)]
#[allow(unused_variables, clippy::excessive_precision)]
diff --git a/src/tools/clippy/tests/ui/inconsistent_struct_constructor.fixed b/src/tools/clippy/tests/ui/inconsistent_struct_constructor.fixed
index 5aaa00f85..620d45e68 100644
--- a/src/tools/clippy/tests/ui/inconsistent_struct_constructor.fixed
+++ b/src/tools/clippy/tests/ui/inconsistent_struct_constructor.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![warn(clippy::inconsistent_struct_constructor)]
#![allow(clippy::redundant_field_names)]
diff --git a/src/tools/clippy/tests/ui/inconsistent_struct_constructor.rs b/src/tools/clippy/tests/ui/inconsistent_struct_constructor.rs
index 2b2dd7f59..10ffadcb2 100644
--- a/src/tools/clippy/tests/ui/inconsistent_struct_constructor.rs
+++ b/src/tools/clippy/tests/ui/inconsistent_struct_constructor.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![warn(clippy::inconsistent_struct_constructor)]
#![allow(clippy::redundant_field_names)]
diff --git a/src/tools/clippy/tests/ui/inefficient_to_string.fixed b/src/tools/clippy/tests/ui/inefficient_to_string.fixed
index c972b9419..557f7fb73 100644
--- a/src/tools/clippy/tests/ui/inefficient_to_string.fixed
+++ b/src/tools/clippy/tests/ui/inefficient_to_string.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::inefficient_to_string)]
use std::borrow::Cow;
diff --git a/src/tools/clippy/tests/ui/inefficient_to_string.rs b/src/tools/clippy/tests/ui/inefficient_to_string.rs
index acdc55aa0..6503001e3 100644
--- a/src/tools/clippy/tests/ui/inefficient_to_string.rs
+++ b/src/tools/clippy/tests/ui/inefficient_to_string.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::inefficient_to_string)]
use std::borrow::Cow;
diff --git a/src/tools/clippy/tests/ui/infallible_destructuring_match.fixed b/src/tools/clippy/tests/ui/infallible_destructuring_match.fixed
index 61985e56b..e396ae94a 100644
--- a/src/tools/clippy/tests/ui/infallible_destructuring_match.fixed
+++ b/src/tools/clippy/tests/ui/infallible_destructuring_match.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(exhaustive_patterns, never_type)]
#![allow(dead_code, unreachable_code, unused_variables)]
#![allow(clippy::let_and_return)]
diff --git a/src/tools/clippy/tests/ui/infallible_destructuring_match.rs b/src/tools/clippy/tests/ui/infallible_destructuring_match.rs
index f2768245b..3fce7bbb6 100644
--- a/src/tools/clippy/tests/ui/infallible_destructuring_match.rs
+++ b/src/tools/clippy/tests/ui/infallible_destructuring_match.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(exhaustive_patterns, never_type)]
#![allow(dead_code, unreachable_code, unused_variables)]
#![allow(clippy::let_and_return)]
diff --git a/src/tools/clippy/tests/ui/inline_fn_without_body.fixed b/src/tools/clippy/tests/ui/inline_fn_without_body.fixed
index fe21a71a4..9c5819558 100644
--- a/src/tools/clippy/tests/ui/inline_fn_without_body.fixed
+++ b/src/tools/clippy/tests/ui/inline_fn_without_body.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::inline_fn_without_body)]
#![allow(clippy::inline_always)]
diff --git a/src/tools/clippy/tests/ui/inline_fn_without_body.rs b/src/tools/clippy/tests/ui/inline_fn_without_body.rs
index 507469894..43ffaf812 100644
--- a/src/tools/clippy/tests/ui/inline_fn_without_body.rs
+++ b/src/tools/clippy/tests/ui/inline_fn_without_body.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::inline_fn_without_body)]
#![allow(clippy::inline_always)]
diff --git a/src/tools/clippy/tests/ui/int_plus_one.fixed b/src/tools/clippy/tests/ui/int_plus_one.fixed
index 642830f24..5a36ec462 100644
--- a/src/tools/clippy/tests/ui/int_plus_one.fixed
+++ b/src/tools/clippy/tests/ui/int_plus_one.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
#[warn(clippy::int_plus_one)]
diff --git a/src/tools/clippy/tests/ui/int_plus_one.rs b/src/tools/clippy/tests/ui/int_plus_one.rs
index 0755a0c79..bffa4afd6 100644
--- a/src/tools/clippy/tests/ui/int_plus_one.rs
+++ b/src/tools/clippy/tests/ui/int_plus_one.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
#[warn(clippy::int_plus_one)]
diff --git a/src/tools/clippy/tests/ui/integer_arithmetic.rs b/src/tools/clippy/tests/ui/integer_arithmetic.rs
deleted file mode 100644
index 8dfdee662..000000000
--- a/src/tools/clippy/tests/ui/integer_arithmetic.rs
+++ /dev/null
@@ -1,102 +0,0 @@
-#![warn(clippy::integer_arithmetic, clippy::float_arithmetic)]
-#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::op_ref)]
-
-#[rustfmt::skip]
-fn main() {
- let mut i = 1i32;
- let mut var1 = 13i32;
- let mut var2 = -1i32;
- 1 + i;
- i * 2;
- 1 %
- i / 2; // no error, this is part of the expression in the preceding line
- i - 2 + 2 - i;
- -i;
- i >> 1;
- i << 1;
-
- // no error, overflows are checked by `overflowing_literals`
- -1;
- -(-1);
-
- i & 1; // no wrapping
- i | 1;
- i ^ 1;
-
- i += 1;
- i -= 1;
- i *= 2;
- i /= 2;
- i /= 0;
- i /= -1;
- i /= var1;
- i /= var2;
- i %= 2;
- i %= 0;
- i %= -1;
- i %= var1;
- i %= var2;
- i <<= 3;
- i >>= 2;
-
- // no errors
- i |= 1;
- i &= 1;
- i ^= i;
-
- // No errors for the following items because they are constant expressions
- enum Foo {
- Bar = -2,
- }
- struct Baz([i32; 1 + 1]);
- union Qux {
- field: [i32; 1 + 1],
- }
- type Alias = [i32; 1 + 1];
-
- const FOO: i32 = -2;
- static BAR: i32 = -2;
-
- let _: [i32; 1 + 1] = [0, 0];
-
- let _: [i32; 1 + 1] = {
- let a: [i32; 1 + 1] = [0, 0];
- a
- };
-
- trait Trait {
- const ASSOC: i32 = 1 + 1;
- }
-
- impl Trait for Foo {
- const ASSOC: i32 = {
- let _: [i32; 1 + 1];
- fn foo() {}
- 1 + 1
- };
- }
-}
-
-// warn on references as well! (#5328)
-pub fn int_arith_ref() {
- 3 + &1;
- &3 + 1;
- &3 + &1;
-}
-
-pub fn foo(x: &i32) -> i32 {
- let a = 5;
- a + x
-}
-
-pub fn bar(x: &i32, y: &i32) -> i32 {
- x + y
-}
-
-pub fn baz(x: i32, y: &i32) -> i32 {
- x + y
-}
-
-pub fn qux(x: i32, y: i32) -> i32 {
- (&x + &y)
-}
diff --git a/src/tools/clippy/tests/ui/integer_arithmetic.stderr b/src/tools/clippy/tests/ui/integer_arithmetic.stderr
deleted file mode 100644
index 9a795b1f2..000000000
--- a/src/tools/clippy/tests/ui/integer_arithmetic.stderr
+++ /dev/null
@@ -1,169 +0,0 @@
-error: this operation will panic at runtime
- --> $DIR/integer_arithmetic.rs:30:5
- |
-LL | i /= 0;
- | ^^^^^^ attempt to divide `_` by zero
- |
- = note: `#[deny(unconditional_panic)]` on by default
-
-error: this operation will panic at runtime
- --> $DIR/integer_arithmetic.rs:35:5
- |
-LL | i %= 0;
- | ^^^^^^ attempt to calculate the remainder of `_` with a divisor of zero
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:9:5
- |
-LL | 1 + i;
- | ^^^^^
- |
- = note: `-D clippy::integer-arithmetic` implied by `-D warnings`
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:10:5
- |
-LL | i * 2;
- | ^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:11:5
- |
-LL | / 1 %
-LL | | i / 2; // no error, this is part of the expression in the preceding line
- | |_____^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:13:5
- |
-LL | i - 2 + 2 - i;
- | ^^^^^^^^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:14:5
- |
-LL | -i;
- | ^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:15:5
- |
-LL | i >> 1;
- | ^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:16:5
- |
-LL | i << 1;
- | ^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:26:5
- |
-LL | i += 1;
- | ^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:27:5
- |
-LL | i -= 1;
- | ^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:28:5
- |
-LL | i *= 2;
- | ^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:31:11
- |
-LL | i /= -1;
- | ^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:32:5
- |
-LL | i /= var1;
- | ^^^^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:33:5
- |
-LL | i /= var2;
- | ^^^^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:36:11
- |
-LL | i %= -1;
- | ^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:37:5
- |
-LL | i %= var1;
- | ^^^^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:38:5
- |
-LL | i %= var2;
- | ^^^^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:39:5
- |
-LL | i <<= 3;
- | ^^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:40:5
- |
-LL | i >>= 2;
- | ^^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:82:5
- |
-LL | 3 + &1;
- | ^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:83:5
- |
-LL | &3 + 1;
- | ^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:84:5
- |
-LL | &3 + &1;
- | ^^^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:89:5
- |
-LL | a + x
- | ^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:93:5
- |
-LL | x + y
- | ^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:97:5
- |
-LL | x + y
- | ^^^^^
-
-error: integer arithmetic detected
- --> $DIR/integer_arithmetic.rs:101:5
- |
-LL | (&x + &y)
- | ^^^^^^^^^
-
-error: aborting due to 27 previous errors
-
diff --git a/src/tools/clippy/tests/ui/into_iter_on_ref.fixed b/src/tools/clippy/tests/ui/into_iter_on_ref.fixed
index b77f17944..9f550acb1 100644
--- a/src/tools/clippy/tests/ui/into_iter_on_ref.fixed
+++ b/src/tools/clippy/tests/ui/into_iter_on_ref.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::useless_vec, clippy::needless_borrow)]
#![warn(clippy::into_iter_on_ref)]
diff --git a/src/tools/clippy/tests/ui/into_iter_on_ref.rs b/src/tools/clippy/tests/ui/into_iter_on_ref.rs
index 3854bb05a..3381ae04d 100644
--- a/src/tools/clippy/tests/ui/into_iter_on_ref.rs
+++ b/src/tools/clippy/tests/ui/into_iter_on_ref.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::useless_vec, clippy::needless_borrow)]
#![warn(clippy::into_iter_on_ref)]
diff --git a/src/tools/clippy/tests/ui/invalid_null_ptr_usage.fixed b/src/tools/clippy/tests/ui/invalid_null_ptr_usage.fixed
index 4f5322ebf..9264fb7e9 100644
--- a/src/tools/clippy/tests/ui/invalid_null_ptr_usage.fixed
+++ b/src/tools/clippy/tests/ui/invalid_null_ptr_usage.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
fn main() {
unsafe {
diff --git a/src/tools/clippy/tests/ui/invalid_null_ptr_usage.rs b/src/tools/clippy/tests/ui/invalid_null_ptr_usage.rs
index ae51c52d8..80c942d77 100644
--- a/src/tools/clippy/tests/ui/invalid_null_ptr_usage.rs
+++ b/src/tools/clippy/tests/ui/invalid_null_ptr_usage.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
fn main() {
unsafe {
diff --git a/src/tools/clippy/tests/ui/is_digit_ascii_radix.fixed b/src/tools/clippy/tests/ui/is_digit_ascii_radix.fixed
index c0ba647d7..bc43303a6 100644
--- a/src/tools/clippy/tests/ui/is_digit_ascii_radix.fixed
+++ b/src/tools/clippy/tests/ui/is_digit_ascii_radix.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::is_digit_ascii_radix)]
diff --git a/src/tools/clippy/tests/ui/is_digit_ascii_radix.rs b/src/tools/clippy/tests/ui/is_digit_ascii_radix.rs
index 68e3f3243..93cba5c8e 100644
--- a/src/tools/clippy/tests/ui/is_digit_ascii_radix.rs
+++ b/src/tools/clippy/tests/ui/is_digit_ascii_radix.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::is_digit_ascii_radix)]
diff --git a/src/tools/clippy/tests/ui/issue-111399.rs b/src/tools/clippy/tests/ui/issue-111399.rs
new file mode 100644
index 000000000..b65e6c726
--- /dev/null
+++ b/src/tools/clippy/tests/ui/issue-111399.rs
@@ -0,0 +1,13 @@
+#![feature(inherent_associated_types)]
+#![allow(incomplete_features)]
+
+// Check that rustc doesn't crash on the trait bound `Self::Ty: std::marker::Freeze`.
+
+pub struct Struct;
+
+impl Struct {
+ pub type Ty = usize;
+ pub const CT: Self::Ty = 42;
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/issue_2356.fixed b/src/tools/clippy/tests/ui/issue_2356.fixed
index a73ee0fb2..a69f5ebdc 100644
--- a/src/tools/clippy/tests/ui/issue_2356.fixed
+++ b/src/tools/clippy/tests/ui/issue_2356.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::while_let_on_iterator)]
#![allow(unused_mut)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/issue_2356.rs b/src/tools/clippy/tests/ui/issue_2356.rs
index 9dd906960..50e1bce1f 100644
--- a/src/tools/clippy/tests/ui/issue_2356.rs
+++ b/src/tools/clippy/tests/ui/issue_2356.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::while_let_on_iterator)]
#![allow(unused_mut)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/items_after_test_module/auxiliary/tests.rs b/src/tools/clippy/tests/ui/items_after_test_module/auxiliary/tests.rs
new file mode 100644
index 000000000..f328e4d9d
--- /dev/null
+++ b/src/tools/clippy/tests/ui/items_after_test_module/auxiliary/tests.rs
@@ -0,0 +1 @@
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/items_after_test_module/block_module.rs b/src/tools/clippy/tests/ui/items_after_test_module/block_module.rs
new file mode 100644
index 000000000..5136b2557
--- /dev/null
+++ b/src/tools/clippy/tests/ui/items_after_test_module/block_module.rs
@@ -0,0 +1,23 @@
+//@compile-flags: --test
+#![allow(unused)]
+#![warn(clippy::items_after_test_module)]
+
+fn main() {}
+
+fn should_not_lint() {}
+
+#[allow(dead_code)]
+#[allow(unused)] // Some attributes to check that span replacement is good enough
+#[allow(clippy::allow_attributes)]
+#[cfg(test)]
+mod tests {
+ #[test]
+ fn hi() {}
+}
+
+fn should_lint() {}
+
+const SHOULD_ALSO_LINT: usize = 1;
+macro_rules! should_not_lint {
+ () => {};
+}
diff --git a/src/tools/clippy/tests/ui/items_after_test_module/block_module.stderr b/src/tools/clippy/tests/ui/items_after_test_module/block_module.stderr
new file mode 100644
index 000000000..597f1b951
--- /dev/null
+++ b/src/tools/clippy/tests/ui/items_after_test_module/block_module.stderr
@@ -0,0 +1,17 @@
+error: items were found after the testing module
+ --> $DIR/block_module.rs:13:1
+ |
+LL | / mod tests {
+LL | | #[test]
+LL | | fn hi() {}
+LL | | }
+... |
+LL | | () => {};
+LL | | }
+ | |_^
+ |
+ = help: move the items to before the testing module was defined
+ = note: `-D clippy::items-after-test-module` implied by `-D warnings`
+
+error: aborting due to previous error
+
diff --git a/src/tools/clippy/tests/ui/items_after_test_module/imported_module.rs b/src/tools/clippy/tests/ui/items_after_test_module/imported_module.rs
new file mode 100644
index 000000000..6a757aef4
--- /dev/null
+++ b/src/tools/clippy/tests/ui/items_after_test_module/imported_module.rs
@@ -0,0 +1,20 @@
+//@compile-flags: --test
+#![allow(unused)]
+#![warn(clippy::items_after_test_module)]
+
+// Nothing here should lint, as `tests` is an imported module (that has no body).
+
+fn main() {}
+
+fn should_not_lint() {}
+
+#[path = "auxiliary/tests.rs"]
+#[cfg(test)]
+mod tests; // Should not lint
+
+fn should_not_lint2() {}
+
+const SHOULD_ALSO_NOT_LINT: usize = 1;
+macro_rules! should_not_lint {
+ () => {};
+}
diff --git a/src/tools/clippy/tests/ui/iter_cloned_collect.fixed b/src/tools/clippy/tests/ui/iter_cloned_collect.fixed
index 9b8621335..88f08bb99 100644
--- a/src/tools/clippy/tests/ui/iter_cloned_collect.fixed
+++ b/src/tools/clippy/tests/ui/iter_cloned_collect.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/iter_cloned_collect.rs b/src/tools/clippy/tests/ui/iter_cloned_collect.rs
index 639f50665..d3438b7f5 100644
--- a/src/tools/clippy/tests/ui/iter_cloned_collect.rs
+++ b/src/tools/clippy/tests/ui/iter_cloned_collect.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/iter_count.fixed b/src/tools/clippy/tests/ui/iter_count.fixed
index 90a6eef75..4367a12f8 100644
--- a/src/tools/clippy/tests/ui/iter_count.fixed
+++ b/src/tools/clippy/tests/ui/iter_count.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:option_helpers.rs
+//@run-rustfix
+//@aux-build:option_helpers.rs
#![warn(clippy::iter_count)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/iter_count.rs b/src/tools/clippy/tests/ui/iter_count.rs
index 6681a480a..8c7543cf0 100644
--- a/src/tools/clippy/tests/ui/iter_count.rs
+++ b/src/tools/clippy/tests/ui/iter_count.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:option_helpers.rs
+//@run-rustfix
+//@aux-build:option_helpers.rs
#![warn(clippy::iter_count)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/iter_kv_map.fixed b/src/tools/clippy/tests/ui/iter_kv_map.fixed
index f2a4c284c..64201b553 100644
--- a/src/tools/clippy/tests/ui/iter_kv_map.fixed
+++ b/src/tools/clippy/tests/ui/iter_kv_map.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::iter_kv_map)]
#![allow(unused_mut, clippy::redundant_clone, clippy::suspicious_map, clippy::map_identity)]
diff --git a/src/tools/clippy/tests/ui/iter_kv_map.rs b/src/tools/clippy/tests/ui/iter_kv_map.rs
index ad6564df4..ec0231ba5 100644
--- a/src/tools/clippy/tests/ui/iter_kv_map.rs
+++ b/src/tools/clippy/tests/ui/iter_kv_map.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::iter_kv_map)]
#![allow(unused_mut, clippy::redundant_clone, clippy::suspicious_map, clippy::map_identity)]
diff --git a/src/tools/clippy/tests/ui/iter_next_slice.fixed b/src/tools/clippy/tests/ui/iter_next_slice.fixed
index f612d26aa..d862abc34 100644
--- a/src/tools/clippy/tests/ui/iter_next_slice.fixed
+++ b/src/tools/clippy/tests/ui/iter_next_slice.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::iter_next_slice)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/iter_next_slice.rs b/src/tools/clippy/tests/ui/iter_next_slice.rs
index 5195f1c86..da6fc46e4 100644
--- a/src/tools/clippy/tests/ui/iter_next_slice.rs
+++ b/src/tools/clippy/tests/ui/iter_next_slice.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::iter_next_slice)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/iter_nth.rs b/src/tools/clippy/tests/ui/iter_nth.rs
index 9c21dd82e..e7fb97d4f 100644
--- a/src/tools/clippy/tests/ui/iter_nth.rs
+++ b/src/tools/clippy/tests/ui/iter_nth.rs
@@ -1,4 +1,4 @@
-// aux-build:option_helpers.rs
+//@aux-build:option_helpers.rs
#![warn(clippy::iter_nth)]
diff --git a/src/tools/clippy/tests/ui/iter_nth_zero.fixed b/src/tools/clippy/tests/ui/iter_nth_zero.fixed
index f23671c26..587b0d1d3 100644
--- a/src/tools/clippy/tests/ui/iter_nth_zero.fixed
+++ b/src/tools/clippy/tests/ui/iter_nth_zero.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::iter_nth_zero)]
use std::collections::HashSet;
diff --git a/src/tools/clippy/tests/ui/iter_nth_zero.rs b/src/tools/clippy/tests/ui/iter_nth_zero.rs
index 7c968d498..93b576ec5 100644
--- a/src/tools/clippy/tests/ui/iter_nth_zero.rs
+++ b/src/tools/clippy/tests/ui/iter_nth_zero.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::iter_nth_zero)]
use std::collections::HashSet;
diff --git a/src/tools/clippy/tests/ui/iter_on_empty_collections.fixed b/src/tools/clippy/tests/ui/iter_on_empty_collections.fixed
index bd9b07aef..4616f0cdc 100644
--- a/src/tools/clippy/tests/ui/iter_on_empty_collections.fixed
+++ b/src/tools/clippy/tests/ui/iter_on_empty_collections.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::iter_on_empty_collections)]
#![allow(clippy::iter_next_slice, clippy::redundant_clone)]
diff --git a/src/tools/clippy/tests/ui/iter_on_empty_collections.rs b/src/tools/clippy/tests/ui/iter_on_empty_collections.rs
index e15ba94bd..81cc7265e 100644
--- a/src/tools/clippy/tests/ui/iter_on_empty_collections.rs
+++ b/src/tools/clippy/tests/ui/iter_on_empty_collections.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::iter_on_empty_collections)]
#![allow(clippy::iter_next_slice, clippy::redundant_clone)]
diff --git a/src/tools/clippy/tests/ui/iter_on_single_items.fixed b/src/tools/clippy/tests/ui/iter_on_single_items.fixed
index 1fa4b0364..80dbe454b 100644
--- a/src/tools/clippy/tests/ui/iter_on_single_items.fixed
+++ b/src/tools/clippy/tests/ui/iter_on_single_items.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::iter_on_single_items)]
#![allow(clippy::iter_next_slice, clippy::redundant_clone)]
diff --git a/src/tools/clippy/tests/ui/iter_on_single_items.rs b/src/tools/clippy/tests/ui/iter_on_single_items.rs
index ea96d8066..71c8c7a3f 100644
--- a/src/tools/clippy/tests/ui/iter_on_single_items.rs
+++ b/src/tools/clippy/tests/ui/iter_on_single_items.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::iter_on_single_items)]
#![allow(clippy::iter_next_slice, clippy::redundant_clone)]
diff --git a/src/tools/clippy/tests/ui/iter_overeager_cloned.fixed b/src/tools/clippy/tests/ui/iter_overeager_cloned.fixed
index c100705d0..bf576e9cb 100644
--- a/src/tools/clippy/tests/ui/iter_overeager_cloned.fixed
+++ b/src/tools/clippy/tests/ui/iter_overeager_cloned.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::iter_overeager_cloned, clippy::redundant_clone, clippy::filter_next)]
#![allow(dead_code, clippy::let_unit_value)]
diff --git a/src/tools/clippy/tests/ui/iter_overeager_cloned.rs b/src/tools/clippy/tests/ui/iter_overeager_cloned.rs
index 2caa88020..df42d88ef 100644
--- a/src/tools/clippy/tests/ui/iter_overeager_cloned.rs
+++ b/src/tools/clippy/tests/ui/iter_overeager_cloned.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::iter_overeager_cloned, clippy::redundant_clone, clippy::filter_next)]
#![allow(dead_code, clippy::let_unit_value)]
diff --git a/src/tools/clippy/tests/ui/iter_skip_next.fixed b/src/tools/clippy/tests/ui/iter_skip_next.fixed
index d56d623b5..8f2cefc43 100644
--- a/src/tools/clippy/tests/ui/iter_skip_next.fixed
+++ b/src/tools/clippy/tests/ui/iter_skip_next.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:option_helpers.rs
+//@run-rustfix
+//@aux-build:option_helpers.rs
#![warn(clippy::iter_skip_next)]
#![allow(clippy::disallowed_names)]
diff --git a/src/tools/clippy/tests/ui/iter_skip_next.rs b/src/tools/clippy/tests/ui/iter_skip_next.rs
index 3ec5d1b82..71d83384f 100644
--- a/src/tools/clippy/tests/ui/iter_skip_next.rs
+++ b/src/tools/clippy/tests/ui/iter_skip_next.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:option_helpers.rs
+//@run-rustfix
+//@aux-build:option_helpers.rs
#![warn(clippy::iter_skip_next)]
#![allow(clippy::disallowed_names)]
diff --git a/src/tools/clippy/tests/ui/iter_with_drain.fixed b/src/tools/clippy/tests/ui/iter_with_drain.fixed
index 0330d5549..24a95c4d0 100644
--- a/src/tools/clippy/tests/ui/iter_with_drain.fixed
+++ b/src/tools/clippy/tests/ui/iter_with_drain.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
// will emits unused mut warnings after fixing
#![allow(unused_mut)]
// will emits needless collect warnings after fixing
diff --git a/src/tools/clippy/tests/ui/iter_with_drain.rs b/src/tools/clippy/tests/ui/iter_with_drain.rs
index 993936fb8..a118c981e 100644
--- a/src/tools/clippy/tests/ui/iter_with_drain.rs
+++ b/src/tools/clippy/tests/ui/iter_with_drain.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
// will emits unused mut warnings after fixing
#![allow(unused_mut)]
// will emits needless collect warnings after fixing
diff --git a/src/tools/clippy/tests/ui/large_const_arrays.fixed b/src/tools/clippy/tests/ui/large_const_arrays.fixed
index c5af07c8a..f7ce6fbe6 100644
--- a/src/tools/clippy/tests/ui/large_const_arrays.fixed
+++ b/src/tools/clippy/tests/ui/large_const_arrays.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::large_const_arrays)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/large_const_arrays.rs b/src/tools/clippy/tests/ui/large_const_arrays.rs
index a160b9f8a..002ac77dd 100644
--- a/src/tools/clippy/tests/ui/large_const_arrays.rs
+++ b/src/tools/clippy/tests/ui/large_const_arrays.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::large_const_arrays)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/large_digit_groups.fixed b/src/tools/clippy/tests/ui/large_digit_groups.fixed
index ea18dac06..f42fcd96d 100644
--- a/src/tools/clippy/tests/ui/large_digit_groups.fixed
+++ b/src/tools/clippy/tests/ui/large_digit_groups.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::large_digit_groups)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/large_digit_groups.rs b/src/tools/clippy/tests/ui/large_digit_groups.rs
index ac116d5db..3db9da6a3 100644
--- a/src/tools/clippy/tests/ui/large_digit_groups.rs
+++ b/src/tools/clippy/tests/ui/large_digit_groups.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::large_digit_groups)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/large_enum_variant.rs b/src/tools/clippy/tests/ui/large_enum_variant.rs
index f09f8ae0c..ea8bc5b4a 100644
--- a/src/tools/clippy/tests/ui/large_enum_variant.rs
+++ b/src/tools/clippy/tests/ui/large_enum_variant.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs
#![allow(dead_code)]
#![allow(unused_variables)]
diff --git a/src/tools/clippy/tests/ui/large_types_passed_by_value.rs b/src/tools/clippy/tests/ui/large_types_passed_by_value.rs
index 7601b5c66..f9e3c7192 100644
--- a/src/tools/clippy/tests/ui/large_types_passed_by_value.rs
+++ b/src/tools/clippy/tests/ui/large_types_passed_by_value.rs
@@ -1,5 +1,5 @@
-// normalize-stderr-test "\(\d+ byte\)" -> "(N byte)"
-// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)"
+//@normalize-stderr-test: "\(\d+ byte\)" -> "(N byte)"
+//@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)"
#![warn(clippy::large_types_passed_by_value)]
diff --git a/src/tools/clippy/tests/ui/len_zero.fixed b/src/tools/clippy/tests/ui/len_zero.fixed
index c1c0b5ae4..2c22abd7e 100644
--- a/src/tools/clippy/tests/ui/len_zero.fixed
+++ b/src/tools/clippy/tests/ui/len_zero.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::len_zero)]
#![allow(dead_code, unused, clippy::len_without_is_empty)]
@@ -176,6 +176,10 @@ fn main() {
// No error; `HasWrongIsEmpty` does not have `.is_empty()`.
println!("Or this!");
}
+
+ // issue #10529
+ (!has_is_empty.is_empty()).then(|| println!("This can happen."));
+ (has_is_empty.is_empty()).then(|| println!("Or this!"));
}
fn test_slice(b: &[u8]) {
diff --git a/src/tools/clippy/tests/ui/len_zero.rs b/src/tools/clippy/tests/ui/len_zero.rs
index cc2eb05b6..a011ff976 100644
--- a/src/tools/clippy/tests/ui/len_zero.rs
+++ b/src/tools/clippy/tests/ui/len_zero.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::len_zero)]
#![allow(dead_code, unused, clippy::len_without_is_empty)]
@@ -176,6 +176,10 @@ fn main() {
// No error; `HasWrongIsEmpty` does not have `.is_empty()`.
println!("Or this!");
}
+
+ // issue #10529
+ (has_is_empty.len() > 0).then(|| println!("This can happen."));
+ (has_is_empty.len() == 0).then(|| println!("Or this!"));
}
fn test_slice(b: &[u8]) {
diff --git a/src/tools/clippy/tests/ui/len_zero.stderr b/src/tools/clippy/tests/ui/len_zero.stderr
index b6f137802..396cfb75f 100644
--- a/src/tools/clippy/tests/ui/len_zero.stderr
+++ b/src/tools/clippy/tests/ui/len_zero.stderr
@@ -123,10 +123,22 @@ LL | if with_is_empty.len() == 0 {
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `with_is_empty.is_empty()`
error: length comparison to zero
- --> $DIR/len_zero.rs:182:8
+ --> $DIR/len_zero.rs:181:6
+ |
+LL | (has_is_empty.len() > 0).then(|| println!("This can happen."));
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
+
+error: length comparison to zero
+ --> $DIR/len_zero.rs:182:6
+ |
+LL | (has_is_empty.len() == 0).then(|| println!("Or this!"));
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()`
+
+error: length comparison to zero
+ --> $DIR/len_zero.rs:186:8
|
LL | if b.len() != 0 {}
| ^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!b.is_empty()`
-error: aborting due to 21 previous errors
+error: aborting due to 23 previous errors
diff --git a/src/tools/clippy/tests/ui/len_zero_ranges.fixed b/src/tools/clippy/tests/ui/len_zero_ranges.fixed
index 797817662..4b1241ec8 100644
--- a/src/tools/clippy/tests/ui/len_zero_ranges.fixed
+++ b/src/tools/clippy/tests/ui/len_zero_ranges.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::len_zero)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/len_zero_ranges.rs b/src/tools/clippy/tests/ui/len_zero_ranges.rs
index a0eb51cc9..4b47132c7 100644
--- a/src/tools/clippy/tests/ui/len_zero_ranges.rs
+++ b/src/tools/clippy/tests/ui/len_zero_ranges.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::len_zero)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/let_underscore_untyped.rs b/src/tools/clippy/tests/ui/let_underscore_untyped.rs
index bcb33c5c7..2c313ff35 100644
--- a/src/tools/clippy/tests/ui/let_underscore_untyped.rs
+++ b/src/tools/clippy/tests/ui/let_underscore_untyped.rs
@@ -1,6 +1,12 @@
+//@aux-build: proc_macros.rs
+
#![allow(unused)]
#![warn(clippy::let_underscore_untyped)]
+extern crate proc_macros;
+use proc_macros::with_span;
+
+use clippy_utils::is_from_proc_macro;
use std::future::Future;
use std::{boxed::Box, fmt::Display};
@@ -28,6 +34,18 @@ fn f() -> Box<dyn Display> {
Box::new(1)
}
+fn g() -> impl Fn() {
+ || {}
+}
+
+with_span!(
+ span
+
+ fn dont_lint_proc_macro() {
+ let _ = a();
+ }
+);
+
fn main() {
let _ = a();
let _ = b(1);
@@ -35,6 +53,8 @@ fn main() {
let _ = d(&1);
let _ = e();
let _ = f();
+ let _ = g();
+ let closure = || {};
_ = a();
_ = b(1);
diff --git a/src/tools/clippy/tests/ui/let_underscore_untyped.stderr b/src/tools/clippy/tests/ui/let_underscore_untyped.stderr
index 36c3d1214..bbf2508af 100644
--- a/src/tools/clippy/tests/ui/let_underscore_untyped.stderr
+++ b/src/tools/clippy/tests/ui/let_underscore_untyped.stderr
@@ -1,51 +1,63 @@
error: non-binding `let` without a type annotation
- --> $DIR/let_underscore_untyped.rs:32:5
+ --> $DIR/let_underscore_untyped.rs:50:5
|
LL | let _ = a();
| ^^^^^^^^^^^^
|
- = help: consider adding a type annotation or removing the `let` keyword
+help: consider adding a type annotation
+ --> $DIR/let_underscore_untyped.rs:50: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:33:5
+ --> $DIR/let_underscore_untyped.rs:51:5
|
LL | let _ = b(1);
| ^^^^^^^^^^^^^
|
- = help: consider adding a type annotation or removing the `let` keyword
-
-error: non-binding `let` without a type annotation
- --> $DIR/let_underscore_untyped.rs:34:5
+help: consider adding a type annotation
+ --> $DIR/let_underscore_untyped.rs:51:10
|
-LL | let _ = c();
- | ^^^^^^^^^^^^
- |
- = help: consider adding a type annotation or removing the `let` keyword
+LL | let _ = b(1);
+ | ^
error: non-binding `let` without a type annotation
- --> $DIR/let_underscore_untyped.rs:35:5
+ --> $DIR/let_underscore_untyped.rs:53:5
|
LL | let _ = d(&1);
| ^^^^^^^^^^^^^^
|
- = help: consider adding a type annotation or removing the `let` keyword
+help: consider adding a type annotation
+ --> $DIR/let_underscore_untyped.rs:53:10
+ |
+LL | let _ = d(&1);
+ | ^
error: non-binding `let` without a type annotation
- --> $DIR/let_underscore_untyped.rs:36:5
+ --> $DIR/let_underscore_untyped.rs:54:5
|
LL | let _ = e();
| ^^^^^^^^^^^^
|
- = help: consider adding a type annotation or removing the `let` keyword
+help: consider adding a type annotation
+ --> $DIR/let_underscore_untyped.rs:54:10
+ |
+LL | let _ = e();
+ | ^
error: non-binding `let` without a type annotation
- --> $DIR/let_underscore_untyped.rs:37:5
+ --> $DIR/let_underscore_untyped.rs:55:5
|
LL | let _ = f();
| ^^^^^^^^^^^^
|
- = help: consider adding a type annotation or removing the `let` keyword
+help: consider adding a type annotation
+ --> $DIR/let_underscore_untyped.rs:55:10
+ |
+LL | let _ = f();
+ | ^
-error: aborting due to 6 previous errors
+error: aborting due to 5 previous errors
diff --git a/src/tools/clippy/tests/ui/let_unit.fixed b/src/tools/clippy/tests/ui/let_unit.fixed
index 76ff0645f..8ba89ec78 100644
--- a/src/tools/clippy/tests/ui/let_unit.fixed
+++ b/src/tools/clippy/tests/ui/let_unit.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(lint_reasons)]
#![warn(clippy::let_unit_value)]
diff --git a/src/tools/clippy/tests/ui/let_unit.rs b/src/tools/clippy/tests/ui/let_unit.rs
index 895ccfe36..7e8764a48 100644
--- a/src/tools/clippy/tests/ui/let_unit.rs
+++ b/src/tools/clippy/tests/ui/let_unit.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(lint_reasons)]
#![warn(clippy::let_unit_value)]
diff --git a/src/tools/clippy/tests/ui/let_with_type_underscore.rs b/src/tools/clippy/tests/ui/let_with_type_underscore.rs
index 175718b94..ae1a480bc 100644
--- a/src/tools/clippy/tests/ui/let_with_type_underscore.rs
+++ b/src/tools/clippy/tests/ui/let_with_type_underscore.rs
@@ -1,19 +1,42 @@
+//@aux-build: proc_macros.rs
#![allow(unused)]
#![warn(clippy::let_with_type_underscore)]
-#![allow(clippy::let_unit_value)]
+#![allow(clippy::let_unit_value, clippy::needless_late_init)]
+
+extern crate proc_macros;
fn func() -> &'static str {
""
}
+#[rustfmt::skip]
fn main() {
// Will lint
let x: _ = 1;
let _: _ = 2;
let x: _ = func();
+ let x: _;
+ x = ();
- let x = 1; // Will not lint, Rust inferres this to an integer before Clippy
+ let x = 1; // Will not lint, Rust infers this to an integer before Clippy
let x = func();
let x: Vec<_> = Vec::<u32>::new();
let x: [_; 1] = [1];
+ let x : _ = 1;
+
+ // Do not lint from procedural macros
+ proc_macros::with_span! {
+ span
+ let x: _ = ();
+ // Late initialization
+ let x: _;
+ x = ();
+ // Ensure weird formatting will not break it (hopefully)
+ let x : _ = 1;
+ let x
+: _ = 1;
+ let x :
+ _;
+ x = ();
+ };
}
diff --git a/src/tools/clippy/tests/ui/let_with_type_underscore.stderr b/src/tools/clippy/tests/ui/let_with_type_underscore.stderr
index 16bf83c70..a749552c7 100644
--- a/src/tools/clippy/tests/ui/let_with_type_underscore.stderr
+++ b/src/tools/clippy/tests/ui/let_with_type_underscore.stderr
@@ -1,39 +1,63 @@
error: variable declared with type underscore
- --> $DIR/let_with_type_underscore.rs:11:5
+ --> $DIR/let_with_type_underscore.rs:15:5
|
LL | let x: _ = 1;
| ^^^^^^^^^^^^^
|
help: remove the explicit type `_` declaration
- --> $DIR/let_with_type_underscore.rs:11:10
+ --> $DIR/let_with_type_underscore.rs:15:10
|
LL | let x: _ = 1;
| ^^^
= note: `-D clippy::let-with-type-underscore` implied by `-D warnings`
error: variable declared with type underscore
- --> $DIR/let_with_type_underscore.rs:12:5
+ --> $DIR/let_with_type_underscore.rs:16:5
|
LL | let _: _ = 2;
| ^^^^^^^^^^^^^
|
help: remove the explicit type `_` declaration
- --> $DIR/let_with_type_underscore.rs:12:10
+ --> $DIR/let_with_type_underscore.rs:16:10
|
LL | let _: _ = 2;
| ^^^
error: variable declared with type underscore
- --> $DIR/let_with_type_underscore.rs:13:5
+ --> $DIR/let_with_type_underscore.rs:17:5
|
LL | let x: _ = func();
| ^^^^^^^^^^^^^^^^^^
|
help: remove the explicit type `_` declaration
- --> $DIR/let_with_type_underscore.rs:13:10
+ --> $DIR/let_with_type_underscore.rs:17:10
|
LL | let x: _ = func();
| ^^^
-error: aborting due to 3 previous errors
+error: variable declared with type underscore
+ --> $DIR/let_with_type_underscore.rs:18:5
+ |
+LL | let x: _;
+ | ^^^^^^^^^
+ |
+help: remove the explicit type `_` declaration
+ --> $DIR/let_with_type_underscore.rs:18:10
+ |
+LL | let x: _;
+ | ^^^
+
+error: variable declared with type underscore
+ --> $DIR/let_with_type_underscore.rs:25:5
+ |
+LL | let x : _ = 1;
+ | ^^^^^^^^^^^^^^
+ |
+help: remove the explicit type `_` declaration
+ --> $DIR/let_with_type_underscore.rs:25:10
+ |
+LL | let x : _ = 1;
+ | ^^^^
+
+error: aborting due to 5 previous errors
diff --git a/src/tools/clippy/tests/ui/lines_filter_map_ok.fixed b/src/tools/clippy/tests/ui/lines_filter_map_ok.fixed
index f4033cd8e..64114f658 100644
--- a/src/tools/clippy/tests/ui/lines_filter_map_ok.fixed
+++ b/src/tools/clippy/tests/ui/lines_filter_map_ok.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::map_identity)]
#![warn(clippy::lines_filter_map_ok)]
diff --git a/src/tools/clippy/tests/ui/lines_filter_map_ok.rs b/src/tools/clippy/tests/ui/lines_filter_map_ok.rs
index 7e11816b2..5aedc6863 100644
--- a/src/tools/clippy/tests/ui/lines_filter_map_ok.rs
+++ b/src/tools/clippy/tests/ui/lines_filter_map_ok.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::map_identity)]
#![warn(clippy::lines_filter_map_ok)]
diff --git a/src/tools/clippy/tests/ui/lossy_float_literal.fixed b/src/tools/clippy/tests/ui/lossy_float_literal.fixed
index 24e372354..a20885756 100644
--- a/src/tools/clippy/tests/ui/lossy_float_literal.fixed
+++ b/src/tools/clippy/tests/ui/lossy_float_literal.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::lossy_float_literal)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/lossy_float_literal.rs b/src/tools/clippy/tests/ui/lossy_float_literal.rs
index 3dcf98fa0..1a75f214c 100644
--- a/src/tools/clippy/tests/ui/lossy_float_literal.rs
+++ b/src/tools/clippy/tests/ui/lossy_float_literal.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::lossy_float_literal)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/macro_use_imports.fixed b/src/tools/clippy/tests/ui/macro_use_imports.fixed
index a395e4f56..b4dabe3ca 100644
--- a/src/tools/clippy/tests/ui/macro_use_imports.fixed
+++ b/src/tools/clippy/tests/ui/macro_use_imports.fixed
@@ -1,8 +1,8 @@
-// aux-build:macro_rules.rs
-// aux-build:macro_use_helper.rs
-// aux-build:proc_macro_derive.rs
-// run-rustfix
-// ignore-32bit
+//@aux-build:macro_rules.rs
+//@aux-build:macro_use_helper.rs
+//@aux-build:proc_macro_derive.rs
+//@run-rustfix
+//@ignore-32bit
#![feature(lint_reasons)]
#![allow(unused_imports, unreachable_code, unused_variables, dead_code, unused_attributes)]
diff --git a/src/tools/clippy/tests/ui/macro_use_imports.rs b/src/tools/clippy/tests/ui/macro_use_imports.rs
index b1a287332..925a2c61f 100644
--- a/src/tools/clippy/tests/ui/macro_use_imports.rs
+++ b/src/tools/clippy/tests/ui/macro_use_imports.rs
@@ -1,8 +1,8 @@
-// aux-build:macro_rules.rs
-// aux-build:macro_use_helper.rs
-// aux-build:proc_macro_derive.rs
-// run-rustfix
-// ignore-32bit
+//@aux-build:macro_rules.rs
+//@aux-build:macro_use_helper.rs
+//@aux-build:proc_macro_derive.rs
+//@run-rustfix
+//@ignore-32bit
#![feature(lint_reasons)]
#![allow(unused_imports, unreachable_code, unused_variables, dead_code, unused_attributes)]
diff --git a/src/tools/clippy/tests/ui/macro_use_imports_expect.rs b/src/tools/clippy/tests/ui/macro_use_imports_expect.rs
index 5aac5af26..b9677851b 100644
--- a/src/tools/clippy/tests/ui/macro_use_imports_expect.rs
+++ b/src/tools/clippy/tests/ui/macro_use_imports_expect.rs
@@ -1,7 +1,7 @@
-// aux-build:macro_rules.rs
-// aux-build:macro_use_helper.rs
-// aux-build:proc_macro_derive.rs
-// ignore-32bit
+//@aux-build:macro_rules.rs
+//@aux-build:macro_use_helper.rs
+//@aux-build:proc_macro_derive.rs
+//@ignore-32bit
#![feature(lint_reasons)]
#![allow(unused_imports, unreachable_code, unused_variables, dead_code, unused_attributes)]
diff --git a/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed b/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed
index 8c7e919bf..ab9b375dc 100644
--- a/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed
+++ b/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed
@@ -1,7 +1,7 @@
-// revisions: edition2018 edition2021
-//[edition2018] edition:2018
-//[edition2021] edition:2021
-// run-rustfix
+//@revisions: edition2018 edition2021
+//@[edition2018] edition:2018
+//@[edition2021] edition:2021
+//@run-rustfix
#![warn(clippy::manual_assert)]
#![allow(dead_code, unused_doc_comments)]
diff --git a/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed b/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed
index 8c7e919bf..ab9b375dc 100644
--- a/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed
+++ b/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed
@@ -1,7 +1,7 @@
-// revisions: edition2018 edition2021
-//[edition2018] edition:2018
-//[edition2021] edition:2021
-// run-rustfix
+//@revisions: edition2018 edition2021
+//@[edition2018] edition:2018
+//@[edition2021] edition:2021
+//@run-rustfix
#![warn(clippy::manual_assert)]
#![allow(dead_code, unused_doc_comments)]
diff --git a/src/tools/clippy/tests/ui/manual_assert.rs b/src/tools/clippy/tests/ui/manual_assert.rs
index f037c5b84..eac52d1b5 100644
--- a/src/tools/clippy/tests/ui/manual_assert.rs
+++ b/src/tools/clippy/tests/ui/manual_assert.rs
@@ -1,7 +1,7 @@
-// revisions: edition2018 edition2021
-//[edition2018] edition:2018
-//[edition2021] edition:2021
-// run-rustfix
+//@revisions: edition2018 edition2021
+//@[edition2018] edition:2018
+//@[edition2021] edition:2021
+//@run-rustfix
#![warn(clippy::manual_assert)]
#![allow(dead_code, unused_doc_comments)]
diff --git a/src/tools/clippy/tests/ui/manual_async_fn.fixed b/src/tools/clippy/tests/ui/manual_async_fn.fixed
index 5cc4a43af..e458f0d25 100644
--- a/src/tools/clippy/tests/ui/manual_async_fn.fixed
+++ b/src/tools/clippy/tests/ui/manual_async_fn.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_async_fn)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/manual_async_fn.rs b/src/tools/clippy/tests/ui/manual_async_fn.rs
index ba504b8a8..dd5ca1c9b 100644
--- a/src/tools/clippy/tests/ui/manual_async_fn.rs
+++ b/src/tools/clippy/tests/ui/manual_async_fn.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_async_fn)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/manual_bits.fixed b/src/tools/clippy/tests/ui/manual_bits.fixed
index e7f8cd878..037de0262 100644
--- a/src/tools/clippy/tests/ui/manual_bits.fixed
+++ b/src/tools/clippy/tests/ui/manual_bits.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_bits)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/manual_bits.rs b/src/tools/clippy/tests/ui/manual_bits.rs
index 7b1d15495..b15a531ec 100644
--- a/src/tools/clippy/tests/ui/manual_bits.rs
+++ b/src/tools/clippy/tests/ui/manual_bits.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_bits)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/manual_filter.fixed b/src/tools/clippy/tests/ui/manual_filter.fixed
index ef6780dc9..755caa664 100644
--- a/src/tools/clippy/tests/ui/manual_filter.fixed
+++ b/src/tools/clippy/tests/ui/manual_filter.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_filter)]
#![allow(unused_variables, dead_code)]
diff --git a/src/tools/clippy/tests/ui/manual_filter.rs b/src/tools/clippy/tests/ui/manual_filter.rs
index ea0ce8317..faccfe9db 100644
--- a/src/tools/clippy/tests/ui/manual_filter.rs
+++ b/src/tools/clippy/tests/ui/manual_filter.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_filter)]
#![allow(unused_variables, dead_code)]
diff --git a/src/tools/clippy/tests/ui/manual_filter_map.fixed b/src/tools/clippy/tests/ui/manual_filter_map.fixed
index 4936dc9b2..831323089 100644
--- a/src/tools/clippy/tests/ui/manual_filter_map.fixed
+++ b/src/tools/clippy/tests/ui/manual_filter_map.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
#![warn(clippy::manual_filter_map)]
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure
diff --git a/src/tools/clippy/tests/ui/manual_filter_map.rs b/src/tools/clippy/tests/ui/manual_filter_map.rs
index 8c67e827b..2692303d3 100644
--- a/src/tools/clippy/tests/ui/manual_filter_map.rs
+++ b/src/tools/clippy/tests/ui/manual_filter_map.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
#![warn(clippy::manual_filter_map)]
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure
diff --git a/src/tools/clippy/tests/ui/manual_find_fixable.fixed b/src/tools/clippy/tests/ui/manual_find_fixable.fixed
index 2bce6e624..9c5eb20c8 100644
--- a/src/tools/clippy/tests/ui/manual_find_fixable.fixed
+++ b/src/tools/clippy/tests/ui/manual_find_fixable.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_find)]
#![allow(unused)]
#![allow(clippy::needless_return, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/manual_find_fixable.rs b/src/tools/clippy/tests/ui/manual_find_fixable.rs
index f5c6de37a..7b670320e 100644
--- a/src/tools/clippy/tests/ui/manual_find_fixable.rs
+++ b/src/tools/clippy/tests/ui/manual_find_fixable.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_find)]
#![allow(unused)]
#![allow(clippy::needless_return, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/manual_find_map.fixed b/src/tools/clippy/tests/ui/manual_find_map.fixed
index 54302bece..554613a30 100644
--- a/src/tools/clippy/tests/ui/manual_find_map.fixed
+++ b/src/tools/clippy/tests/ui/manual_find_map.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
#![warn(clippy::manual_find_map)]
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure
diff --git a/src/tools/clippy/tests/ui/manual_find_map.rs b/src/tools/clippy/tests/ui/manual_find_map.rs
index afcc1825a..d6245758f 100644
--- a/src/tools/clippy/tests/ui/manual_find_map.rs
+++ b/src/tools/clippy/tests/ui/manual_find_map.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
#![warn(clippy::manual_find_map)]
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure
diff --git a/src/tools/clippy/tests/ui/manual_instant_elapsed.fixed b/src/tools/clippy/tests/ui/manual_instant_elapsed.fixed
index 85a91543c..55073c3b5 100644
--- a/src/tools/clippy/tests/ui/manual_instant_elapsed.fixed
+++ b/src/tools/clippy/tests/ui/manual_instant_elapsed.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_instant_elapsed)]
#![allow(clippy::unnecessary_operation)]
#![allow(clippy::unchecked_duration_subtraction)]
diff --git a/src/tools/clippy/tests/ui/manual_instant_elapsed.rs b/src/tools/clippy/tests/ui/manual_instant_elapsed.rs
index c98cb15b9..c9029a049 100644
--- a/src/tools/clippy/tests/ui/manual_instant_elapsed.rs
+++ b/src/tools/clippy/tests/ui/manual_instant_elapsed.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_instant_elapsed)]
#![allow(clippy::unnecessary_operation)]
#![allow(clippy::unchecked_duration_subtraction)]
diff --git a/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed b/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed
index 5b2b44c2f..87e866586 100644
--- a/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed
+++ b/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, dead_code)]
#![warn(clippy::manual_is_ascii_check)]
diff --git a/src/tools/clippy/tests/ui/manual_is_ascii_check.rs b/src/tools/clippy/tests/ui/manual_is_ascii_check.rs
index c9433f33a..931f0f202 100644
--- a/src/tools/clippy/tests/ui/manual_is_ascii_check.rs
+++ b/src/tools/clippy/tests/ui/manual_is_ascii_check.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, dead_code)]
#![warn(clippy::manual_is_ascii_check)]
diff --git a/src/tools/clippy/tests/ui/manual_let_else.rs b/src/tools/clippy/tests/ui/manual_let_else.rs
index d175597a4..3996d775f 100644
--- a/src/tools/clippy/tests/ui/manual_let_else.rs
+++ b/src/tools/clippy/tests/ui/manual_let_else.rs
@@ -8,6 +8,12 @@
)]
#![warn(clippy::manual_let_else)]
+enum Variant {
+ A(usize, usize),
+ B(usize),
+ C,
+}
+
fn g() -> Option<()> {
None
}
@@ -135,6 +141,15 @@ fn fire() {
};
}
create_binding_if_some!(w, g());
+
+ fn e() -> Variant {
+ Variant::A(0, 0)
+ }
+
+ // Should not be renamed
+ let v = if let Variant::A(a, 0) = e() { a } else { return };
+ // Should be renamed
+ let v = if let Variant::B(b) = e() { b } else { return };
}
fn not_fire() {
diff --git a/src/tools/clippy/tests/ui/manual_let_else.stderr b/src/tools/clippy/tests/ui/manual_let_else.stderr
index 52aac6bc6..f6f56f7b0 100644
--- a/src/tools/clippy/tests/ui/manual_let_else.stderr
+++ b/src/tools/clippy/tests/ui/manual_let_else.stderr
@@ -1,13 +1,13 @@
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:18:5
+ --> $DIR/manual_let_else.rs:24:5
|
LL | let v = if let Some(v_some) = g() { v_some } else { return };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v_some) = g() else { return };`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { return };`
|
= note: `-D clippy::manual-let-else` implied by `-D warnings`
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:19:5
+ --> $DIR/manual_let_else.rs:25:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -18,13 +18,13 @@ LL | | };
|
help: consider writing
|
-LL ~ let Some(v_some) = g() else {
+LL ~ let Some(v) = g() else {
LL + return;
LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:25:5
+ --> $DIR/manual_let_else.rs:31:5
|
LL | / let v = if let Some(v) = g() {
LL | | // Blocks around the identity should have no impact
@@ -45,25 +45,25 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:38:9
+ --> $DIR/manual_let_else.rs:44:9
|
LL | let v = if let Some(v_some) = g() { v_some } else { continue };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v_some) = g() else { continue };`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { continue };`
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:39:9
+ --> $DIR/manual_let_else.rs:45:9
|
LL | let v = if let Some(v_some) = g() { v_some } else { break };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v_some) = g() else { break };`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { break };`
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:43:5
+ --> $DIR/manual_let_else.rs:49:5
|
LL | let v = if let Some(v_some) = g() { v_some } else { panic!() };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v_some) = g() else { panic!() };`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { panic!() };`
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:46:5
+ --> $DIR/manual_let_else.rs:52:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -74,13 +74,13 @@ LL | | };
|
help: consider writing
|
-LL ~ let Some(v_some) = g() else {
+LL ~ let Some(v) = g() else {
LL + std::process::abort()
LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:53:5
+ --> $DIR/manual_let_else.rs:59:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -91,13 +91,13 @@ LL | | };
|
help: consider writing
|
-LL ~ let Some(v_some) = g() else {
+LL ~ let Some(v) = g() else {
LL + if true { return } else { panic!() }
LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:60:5
+ --> $DIR/manual_let_else.rs:66:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -109,14 +109,14 @@ LL | | };
|
help: consider writing
|
-LL ~ let Some(v_some) = g() else {
+LL ~ let Some(v) = g() else {
LL + if true {}
LL + panic!();
LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:70:5
+ --> $DIR/manual_let_else.rs:76:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -129,7 +129,7 @@ LL | | };
|
help: consider writing
|
-LL ~ let Some(v_some) = g() else {
+LL ~ let Some(v) = g() else {
LL + match () {
LL + _ if panic!() => {},
LL + _ => panic!(),
@@ -138,13 +138,13 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:80:5
+ --> $DIR/manual_let_else.rs:86:5
|
LL | let v = if let Some(v_some) = g() { v_some } else { if panic!() {} };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v_some) = g() else { if panic!() {} };`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { if panic!() {} };`
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:83:5
+ --> $DIR/manual_let_else.rs:89:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -157,7 +157,7 @@ LL | | };
|
help: consider writing
|
-LL ~ let Some(v_some) = g() else {
+LL ~ let Some(v) = g() else {
LL + match panic!() {
LL + _ => {},
LL + }
@@ -165,7 +165,7 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:92:5
+ --> $DIR/manual_let_else.rs:98:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -178,7 +178,7 @@ LL | | };
|
help: consider writing
|
-LL ~ let Some(v_some) = g() else { if true {
+LL ~ let Some(v) = g() else { if true {
LL + return;
LL + } else {
LL + panic!("diverge");
@@ -186,7 +186,7 @@ LL + } };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:101:5
+ --> $DIR/manual_let_else.rs:107:5
|
LL | / let v = if let Some(v_some) = g() {
LL | | v_some
@@ -199,7 +199,7 @@ LL | | };
|
help: consider writing
|
-LL ~ let Some(v_some) = g() else {
+LL ~ let Some(v) = g() else {
LL + match (g(), g()) {
LL + (Some(_), None) => return,
LL + (None, Some(_)) => {
@@ -215,7 +215,7 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:118:5
+ --> $DIR/manual_let_else.rs:124:5
|
LL | / let (v, w) = if let Some(v_some) = g().map(|v| (v, 42)) {
LL | | v_some
@@ -226,13 +226,13 @@ LL | | };
|
help: consider writing
|
-LL ~ let Some(v_some) = g().map(|v| (v, 42)) else {
+LL ~ let Some((v, w)) = g().map(|v| (v, 42)) else {
LL + return;
LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:125:5
+ --> $DIR/manual_let_else.rs:131:5
|
LL | / let v = if let (Some(v_some), w_some) = (g(), 0) {
LL | | (w_some, v_some)
@@ -249,10 +249,10 @@ LL + };
|
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:134:13
+ --> $DIR/manual_let_else.rs:140:13
|
LL | let $n = if let Some(v) = $e { v } else { return };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { return };`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some($n) = g() else { return };`
...
LL | create_binding_if_some!(w, g());
| ------------------------------- in this macro invocation
@@ -260,13 +260,25 @@ LL | create_binding_if_some!(w, g());
= note: this error originates in the macro `create_binding_if_some` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this could be rewritten as `let...else`
- --> $DIR/manual_let_else.rs:247:5
+ --> $DIR/manual_let_else.rs:150:5
+ |
+LL | let v = if let Variant::A(a, 0) = e() { a } else { return };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::A(a, 0) = e() else { return };`
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:152:5
+ |
+LL | let v = if let Variant::B(b) = e() { b } else { return };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Variant::B(v) = e() else { return };`
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:262:5
|
LL | / let _ = match ff {
LL | | Some(value) => value,
LL | | _ => macro_call!(),
LL | | };
- | |______^ help: consider writing: `let Some(value) = ff else { macro_call!() };`
+ | |______^ help: consider writing: `let Some(_) = ff else { macro_call!() };`
-error: aborting due to 18 previous errors
+error: aborting due to 20 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_let_else_match.stderr b/src/tools/clippy/tests/ui/manual_let_else_match.stderr
index 7abaa0b85..bacc14dc9 100644
--- a/src/tools/clippy/tests/ui/manual_let_else_match.stderr
+++ b/src/tools/clippy/tests/ui/manual_let_else_match.stderr
@@ -5,7 +5,7 @@ LL | / let v = match g() {
LL | | Some(v_some) => v_some,
LL | | None => return,
LL | | };
- | |______^ help: consider writing: `let Some(v_some) = g() else { return };`
+ | |______^ help: consider writing: `let Some(v) = g() else { return };`
|
= note: `-D clippy::manual-let-else` implied by `-D warnings`
@@ -16,7 +16,7 @@ LL | / let v = match g() {
LL | | Some(v_some) => v_some,
LL | | _ => return,
LL | | };
- | |______^ help: consider writing: `let Some(v_some) = g() else { return };`
+ | |______^ help: consider writing: `let Some(v) = g() else { return };`
error: this could be rewritten as `let...else`
--> $DIR/manual_let_else_match.rs:44:9
diff --git a/src/tools/clippy/tests/ui/manual_main_separator_str.fixed b/src/tools/clippy/tests/ui/manual_main_separator_str.fixed
index 50f46d6b3..7e7da8f20 100644
--- a/src/tools/clippy/tests/ui/manual_main_separator_str.fixed
+++ b/src/tools/clippy/tests/ui/manual_main_separator_str.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::manual_main_separator_str)]
diff --git a/src/tools/clippy/tests/ui/manual_main_separator_str.rs b/src/tools/clippy/tests/ui/manual_main_separator_str.rs
index 2dbb9e661..cf90e12ef 100644
--- a/src/tools/clippy/tests/ui/manual_main_separator_str.rs
+++ b/src/tools/clippy/tests/ui/manual_main_separator_str.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::manual_main_separator_str)]
diff --git a/src/tools/clippy/tests/ui/manual_map_option.fixed b/src/tools/clippy/tests/ui/manual_map_option.fixed
index e12ea7ec1..e8ff65cad 100644
--- a/src/tools/clippy/tests/ui/manual_map_option.fixed
+++ b/src/tools/clippy/tests/ui/manual_map_option.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_map)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/manual_map_option.rs b/src/tools/clippy/tests/ui/manual_map_option.rs
index 325a6db06..b06a96451 100644
--- a/src/tools/clippy/tests/ui/manual_map_option.rs
+++ b/src/tools/clippy/tests/ui/manual_map_option.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_map)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/manual_map_option_2.fixed b/src/tools/clippy/tests/ui/manual_map_option_2.fixed
index ebf3f8cab..dc7228782 100644
--- a/src/tools/clippy/tests/ui/manual_map_option_2.fixed
+++ b/src/tools/clippy/tests/ui/manual_map_option_2.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_map)]
#![allow(clippy::toplevel_ref_arg)]
diff --git a/src/tools/clippy/tests/ui/manual_map_option_2.rs b/src/tools/clippy/tests/ui/manual_map_option_2.rs
index 1382d9af0..c495ab0fa 100644
--- a/src/tools/clippy/tests/ui/manual_map_option_2.rs
+++ b/src/tools/clippy/tests/ui/manual_map_option_2.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_map)]
#![allow(clippy::toplevel_ref_arg)]
diff --git a/src/tools/clippy/tests/ui/manual_next_back.fixed b/src/tools/clippy/tests/ui/manual_next_back.fixed
new file mode 100644
index 000000000..e8a47063a
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_next_back.fixed
@@ -0,0 +1,36 @@
+//@run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::manual_next_back)]
+
+struct FakeIter(std::ops::Range<i32>);
+
+impl FakeIter {
+ fn rev(self) -> Self {
+ self
+ }
+
+ fn next(&self) {}
+}
+
+impl DoubleEndedIterator for FakeIter {
+ fn next_back(&mut self) -> Option<Self::Item> {
+ self.0.next_back()
+ }
+}
+
+impl Iterator for FakeIter {
+ type Item = i32;
+ fn next(&mut self) -> Option<Self::Item> {
+ self.0.next()
+ }
+}
+
+fn main() {
+ // should not lint
+ FakeIter(0..10).rev().next();
+
+ // should lint
+ let _ = (0..10).next_back().unwrap();
+ let _ = "something".bytes().next_back();
+}
diff --git a/src/tools/clippy/tests/ui/manual_next_back.rs b/src/tools/clippy/tests/ui/manual_next_back.rs
new file mode 100644
index 000000000..9ec892422
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_next_back.rs
@@ -0,0 +1,36 @@
+//@run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::manual_next_back)]
+
+struct FakeIter(std::ops::Range<i32>);
+
+impl FakeIter {
+ fn rev(self) -> Self {
+ self
+ }
+
+ fn next(&self) {}
+}
+
+impl DoubleEndedIterator for FakeIter {
+ fn next_back(&mut self) -> Option<Self::Item> {
+ self.0.next_back()
+ }
+}
+
+impl Iterator for FakeIter {
+ type Item = i32;
+ fn next(&mut self) -> Option<Self::Item> {
+ self.0.next()
+ }
+}
+
+fn main() {
+ // should not lint
+ FakeIter(0..10).rev().next();
+
+ // should lint
+ let _ = (0..10).rev().next().unwrap();
+ let _ = "something".bytes().rev().next();
+}
diff --git a/src/tools/clippy/tests/ui/manual_next_back.stderr b/src/tools/clippy/tests/ui/manual_next_back.stderr
new file mode 100644
index 000000000..94ccaa9e4
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_next_back.stderr
@@ -0,0 +1,16 @@
+error: manual backwards iteration
+ --> $DIR/manual_next_back.rs:34:20
+ |
+LL | let _ = (0..10).rev().next().unwrap();
+ | ^^^^^^^^^^^^^ help: use: `.next_back()`
+ |
+ = note: `-D clippy::manual-next-back` implied by `-D warnings`
+
+error: manual backwards iteration
+ --> $DIR/manual_next_back.rs:35:32
+ |
+LL | let _ = "something".bytes().rev().next();
+ | ^^^^^^^^^^^^^ help: use: `.next_back()`
+
+error: aborting due to 2 previous errors
+
diff --git a/src/tools/clippy/tests/ui/manual_ok_or.fixed b/src/tools/clippy/tests/ui/manual_ok_or.fixed
index fc8511626..d8901dc3b 100644
--- a/src/tools/clippy/tests/ui/manual_ok_or.fixed
+++ b/src/tools/clippy/tests/ui/manual_ok_or.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_ok_or)]
#![allow(clippy::or_fun_call)]
#![allow(clippy::disallowed_names)]
diff --git a/src/tools/clippy/tests/ui/manual_ok_or.rs b/src/tools/clippy/tests/ui/manual_ok_or.rs
index b5303d33f..7188a5213 100644
--- a/src/tools/clippy/tests/ui/manual_ok_or.rs
+++ b/src/tools/clippy/tests/ui/manual_ok_or.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_ok_or)]
#![allow(clippy::or_fun_call)]
#![allow(clippy::disallowed_names)]
diff --git a/src/tools/clippy/tests/ui/manual_rem_euclid.fixed b/src/tools/clippy/tests/ui/manual_rem_euclid.fixed
index 1f6df1b0a..f2e44e56f 100644
--- a/src/tools/clippy/tests/ui/manual_rem_euclid.fixed
+++ b/src/tools/clippy/tests/ui/manual_rem_euclid.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![warn(clippy::manual_rem_euclid)]
#![allow(clippy::let_with_type_underscore)]
diff --git a/src/tools/clippy/tests/ui/manual_rem_euclid.rs b/src/tools/clippy/tests/ui/manual_rem_euclid.rs
index b275e8a38..b2329c33a 100644
--- a/src/tools/clippy/tests/ui/manual_rem_euclid.rs
+++ b/src/tools/clippy/tests/ui/manual_rem_euclid.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![warn(clippy::manual_rem_euclid)]
#![allow(clippy::let_with_type_underscore)]
diff --git a/src/tools/clippy/tests/ui/manual_retain.fixed b/src/tools/clippy/tests/ui/manual_retain.fixed
index 8f25fea67..09fb0d758 100644
--- a/src/tools/clippy/tests/ui/manual_retain.fixed
+++ b/src/tools/clippy/tests/ui/manual_retain.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_retain)]
#![allow(unused, clippy::redundant_clone)]
use std::collections::BTreeMap;
@@ -23,8 +23,8 @@ fn main() {
}
fn binary_heap_retain() {
- // NOTE: Do not lint now, because binary_heap_retain is nighyly API.
- // And we need to add a test case for msrv if we update this implmention.
+ // NOTE: Do not lint now, because binary_heap_retain is nightly API.
+ // And we need to add a test case for msrv if we update this implementation.
// https://github.com/rust-lang/rust/issues/71503
let mut heap = BinaryHeap::from([1, 2, 3]);
heap = heap.into_iter().filter(|x| x % 2 == 0).collect();
diff --git a/src/tools/clippy/tests/ui/manual_retain.rs b/src/tools/clippy/tests/ui/manual_retain.rs
index e6b3995a6..7fee4c95c 100644
--- a/src/tools/clippy/tests/ui/manual_retain.rs
+++ b/src/tools/clippy/tests/ui/manual_retain.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_retain)]
#![allow(unused, clippy::redundant_clone)]
use std::collections::BTreeMap;
@@ -23,8 +23,8 @@ fn main() {
}
fn binary_heap_retain() {
- // NOTE: Do not lint now, because binary_heap_retain is nighyly API.
- // And we need to add a test case for msrv if we update this implmention.
+ // NOTE: Do not lint now, because binary_heap_retain is nightly API.
+ // And we need to add a test case for msrv if we update this implementation.
// https://github.com/rust-lang/rust/issues/71503
let mut heap = BinaryHeap::from([1, 2, 3]);
heap = heap.into_iter().filter(|x| x % 2 == 0).collect();
diff --git a/src/tools/clippy/tests/ui/manual_saturating_arithmetic.fixed b/src/tools/clippy/tests/ui/manual_saturating_arithmetic.fixed
index c4f53c446..7dd4521fa 100644
--- a/src/tools/clippy/tests/ui/manual_saturating_arithmetic.fixed
+++ b/src/tools/clippy/tests/ui/manual_saturating_arithmetic.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_imports)]
diff --git a/src/tools/clippy/tests/ui/manual_saturating_arithmetic.rs b/src/tools/clippy/tests/ui/manual_saturating_arithmetic.rs
index cd83cf6e6..463ee0692 100644
--- a/src/tools/clippy/tests/ui/manual_saturating_arithmetic.rs
+++ b/src/tools/clippy/tests/ui/manual_saturating_arithmetic.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_imports)]
diff --git a/src/tools/clippy/tests/ui/manual_slice_size_calculation.fixed b/src/tools/clippy/tests/ui/manual_slice_size_calculation.fixed
new file mode 100644
index 000000000..ac85bd8d3
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_slice_size_calculation.fixed
@@ -0,0 +1,46 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs
+#![allow(unused)]
+#![warn(clippy::manual_slice_size_calculation)]
+
+extern crate proc_macros;
+
+use core::mem::{align_of, size_of};
+use proc_macros::external;
+
+fn main() {
+ let v_i32 = Vec::<i32>::new();
+ let s_i32 = v_i32.as_slice();
+
+ // True positives:
+ let _ = std::mem::size_of_val(s_i32); // WARNING
+ let _ = std::mem::size_of_val(s_i32); // WARNING
+ let _ = std::mem::size_of_val(s_i32) * 5; // WARNING
+
+ let len = s_i32.len();
+ let size = size_of::<i32>();
+ let _ = std::mem::size_of_val(s_i32); // WARNING
+ let _ = std::mem::size_of_val(s_i32); // WARNING
+ let _ = std::mem::size_of_val(s_i32); // WARNING
+
+ let _ = std::mem::size_of_val(external!(&[1u64][..]));
+
+ // True negatives:
+ let _ = size_of::<i32>() + s_i32.len(); // Ok, not a multiplication
+ let _ = size_of::<i32>() * s_i32.partition_point(|_| true); // Ok, not len()
+ let _ = size_of::<i32>() * v_i32.len(); // Ok, not a slice
+ let _ = align_of::<i32>() * s_i32.len(); // Ok, not size_of()
+ let _ = size_of::<u32>() * s_i32.len(); // Ok, different types
+
+ let _ = external!($s_i32.len() * size_of::<i32>());
+ let _ = external!($s_i32.len()) * size_of::<i32>();
+
+ // False negatives:
+ let _ = 5 * size_of::<i32>() * s_i32.len(); // Ok (MISSED OPPORTUNITY)
+ let _ = size_of::<i32>() * 5 * s_i32.len(); // Ok (MISSED OPPORTUNITY)
+}
+
+const fn _const(s_i32: &[i32]) {
+ // True negative:
+ let _ = s_i32.len() * size_of::<i32>(); // Ok, can't use size_of_val in const
+}
diff --git a/src/tools/clippy/tests/ui/manual_slice_size_calculation.rs b/src/tools/clippy/tests/ui/manual_slice_size_calculation.rs
index 5082f931f..1f824b12b 100644
--- a/src/tools/clippy/tests/ui/manual_slice_size_calculation.rs
+++ b/src/tools/clippy/tests/ui/manual_slice_size_calculation.rs
@@ -1,7 +1,12 @@
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![allow(unused)]
#![warn(clippy::manual_slice_size_calculation)]
+extern crate proc_macros;
+
use core::mem::{align_of, size_of};
+use proc_macros::external;
fn main() {
let v_i32 = Vec::<i32>::new();
@@ -18,6 +23,8 @@ fn main() {
let _ = s_i32.len() * size; // WARNING
let _ = len * size; // WARNING
+ let _ = external!(&[1u64][..]).len() * size_of::<u64>();
+
// True negatives:
let _ = size_of::<i32>() + s_i32.len(); // Ok, not a multiplication
let _ = size_of::<i32>() * s_i32.partition_point(|_| true); // Ok, not len()
@@ -25,6 +32,9 @@ fn main() {
let _ = align_of::<i32>() * s_i32.len(); // Ok, not size_of()
let _ = size_of::<u32>() * s_i32.len(); // Ok, different types
+ let _ = external!($s_i32.len() * size_of::<i32>());
+ let _ = external!($s_i32.len()) * size_of::<i32>();
+
// False negatives:
let _ = 5 * size_of::<i32>() * s_i32.len(); // Ok (MISSED OPPORTUNITY)
let _ = size_of::<i32>() * 5 * s_i32.len(); // Ok (MISSED OPPORTUNITY)
diff --git a/src/tools/clippy/tests/ui/manual_slice_size_calculation.stderr b/src/tools/clippy/tests/ui/manual_slice_size_calculation.stderr
index 4a24fc60a..e09d8057a 100644
--- a/src/tools/clippy/tests/ui/manual_slice_size_calculation.stderr
+++ b/src/tools/clippy/tests/ui/manual_slice_size_calculation.stderr
@@ -1,51 +1,46 @@
error: manual slice size calculation
- --> $DIR/manual_slice_size_calculation.rs:11:13
+ --> $DIR/manual_slice_size_calculation.rs:16:13
|
LL | let _ = s_i32.len() * size_of::<i32>(); // WARNING
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)`
|
- = help: consider using std::mem::size_of_value instead
= note: `-D clippy::manual-slice-size-calculation` implied by `-D warnings`
error: manual slice size calculation
- --> $DIR/manual_slice_size_calculation.rs:12:13
+ --> $DIR/manual_slice_size_calculation.rs:17:13
|
LL | let _ = size_of::<i32>() * s_i32.len(); // WARNING
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = help: consider using std::mem::size_of_value instead
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)`
error: manual slice size calculation
- --> $DIR/manual_slice_size_calculation.rs:13:13
+ --> $DIR/manual_slice_size_calculation.rs:18:13
|
LL | let _ = size_of::<i32>() * s_i32.len() * 5; // WARNING
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = help: consider using std::mem::size_of_value instead
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)`
error: manual slice size calculation
- --> $DIR/manual_slice_size_calculation.rs:17:13
+ --> $DIR/manual_slice_size_calculation.rs:22:13
|
LL | let _ = len * size_of::<i32>(); // WARNING
- | ^^^^^^^^^^^^^^^^^^^^^^
- |
- = help: consider using std::mem::size_of_value instead
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)`
error: manual slice size calculation
- --> $DIR/manual_slice_size_calculation.rs:18:13
+ --> $DIR/manual_slice_size_calculation.rs:23:13
|
LL | let _ = s_i32.len() * size; // WARNING
- | ^^^^^^^^^^^^^^^^^^
- |
- = help: consider using std::mem::size_of_value instead
+ | ^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)`
error: manual slice size calculation
- --> $DIR/manual_slice_size_calculation.rs:19:13
+ --> $DIR/manual_slice_size_calculation.rs:24:13
|
LL | let _ = len * size; // WARNING
- | ^^^^^^^^^^
+ | ^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)`
+
+error: manual slice size calculation
+ --> $DIR/manual_slice_size_calculation.rs:26:13
|
- = help: consider using std::mem::size_of_value instead
+LL | let _ = external!(&[1u64][..]).len() * size_of::<u64>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(external!(&[1u64][..]))`
-error: aborting due to 6 previous errors
+error: aborting due to 7 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_split_once.fixed b/src/tools/clippy/tests/ui/manual_split_once.fixed
index 50b02019c..e317c5971 100644
--- a/src/tools/clippy/tests/ui/manual_split_once.fixed
+++ b/src/tools/clippy/tests/ui/manual_split_once.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_split_once)]
#![allow(unused, clippy::iter_skip_next, clippy::iter_nth_zero)]
diff --git a/src/tools/clippy/tests/ui/manual_split_once.rs b/src/tools/clippy/tests/ui/manual_split_once.rs
index e1e8b71a9..7e2dc22bc 100644
--- a/src/tools/clippy/tests/ui/manual_split_once.rs
+++ b/src/tools/clippy/tests/ui/manual_split_once.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_split_once)]
#![allow(unused, clippy::iter_skip_next, clippy::iter_nth_zero)]
diff --git a/src/tools/clippy/tests/ui/manual_str_repeat.fixed b/src/tools/clippy/tests/ui/manual_str_repeat.fixed
index 3d56f2a0d..9468c3df9 100644
--- a/src/tools/clippy/tests/ui/manual_str_repeat.fixed
+++ b/src/tools/clippy/tests/ui/manual_str_repeat.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_str_repeat)]
diff --git a/src/tools/clippy/tests/ui/manual_str_repeat.rs b/src/tools/clippy/tests/ui/manual_str_repeat.rs
index e8240a949..baa0a1026 100644
--- a/src/tools/clippy/tests/ui/manual_str_repeat.rs
+++ b/src/tools/clippy/tests/ui/manual_str_repeat.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_str_repeat)]
diff --git a/src/tools/clippy/tests/ui/manual_string_new.fixed b/src/tools/clippy/tests/ui/manual_string_new.fixed
index a376411bf..0d1bab233 100644
--- a/src/tools/clippy/tests/ui/manual_string_new.fixed
+++ b/src/tools/clippy/tests/ui/manual_string_new.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_string_new)]
diff --git a/src/tools/clippy/tests/ui/manual_string_new.rs b/src/tools/clippy/tests/ui/manual_string_new.rs
index 6bfc52fb1..2392ebfc3 100644
--- a/src/tools/clippy/tests/ui/manual_string_new.rs
+++ b/src/tools/clippy/tests/ui/manual_string_new.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_string_new)]
diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or.fixed b/src/tools/clippy/tests/ui/manual_unwrap_or.fixed
index 7d6897821..c17634bff 100644
--- a/src/tools/clippy/tests/ui/manual_unwrap_or.fixed
+++ b/src/tools/clippy/tests/ui/manual_unwrap_or.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
#![allow(unused_variables, clippy::unnecessary_wraps)]
diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or.rs b/src/tools/clippy/tests/ui/manual_unwrap_or.rs
index b937fe6f9..6d49a6949 100644
--- a/src/tools/clippy/tests/ui/manual_unwrap_or.rs
+++ b/src/tools/clippy/tests/ui/manual_unwrap_or.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
#![allow(unused_variables, clippy::unnecessary_wraps)]
diff --git a/src/tools/clippy/tests/ui/manual_while_let_some.fixed b/src/tools/clippy/tests/ui/manual_while_let_some.fixed
new file mode 100644
index 000000000..8b6109195
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_while_let_some.fixed
@@ -0,0 +1,93 @@
+//@run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::manual_while_let_some)]
+
+struct VecInStruct {
+ numbers: Vec<i32>,
+ unrelated: String,
+}
+
+struct Foo {
+ a: i32,
+ b: i32,
+}
+
+fn accept_i32(_: i32) {}
+fn accept_optional_i32(_: Option<i32>) {}
+fn accept_i32_tuple(_: (i32, i32)) {}
+
+fn main() {
+ let mut numbers = vec![1, 2, 3, 4, 5];
+ while let Some(number) = numbers.pop() {
+
+ }
+
+ let mut val = VecInStruct {
+ numbers: vec![1, 2, 3, 4, 5],
+ unrelated: String::new(),
+ };
+ while let Some(number) = val.numbers.pop() {
+
+ }
+
+ while let Some(element) = numbers.pop() {
+ accept_i32(element);
+ }
+
+ while let Some(element) = numbers.pop() {
+ accept_i32(element);
+ }
+
+ // This should not warn. It "conditionally" pops elements.
+ while !numbers.is_empty() {
+ if true {
+ accept_i32(numbers.pop().unwrap());
+ }
+ }
+
+ // This should also not warn. It conditionally pops elements.
+ while !numbers.is_empty() {
+ if false {
+ continue;
+ }
+ accept_i32(numbers.pop().unwrap());
+ }
+
+ // This should not warn. It pops elements, but does not unwrap it.
+ // Might handle the Option in some other arbitrary way.
+ while !numbers.is_empty() {
+ accept_optional_i32(numbers.pop());
+ }
+
+ let unrelated_vec: Vec<String> = Vec::new();
+ // This should not warn. It pops elements from a different vector.
+ while !unrelated_vec.is_empty() {
+ accept_i32(numbers.pop().unwrap());
+ }
+
+ macro_rules! generate_loop {
+ () => {
+ while !numbers.is_empty() {
+ accept_i32(numbers.pop().unwrap());
+ }
+ };
+ }
+ // Do not warn if the loop comes from a macro.
+ generate_loop!();
+
+ // Try other kinds of patterns
+ let mut numbers = vec![(0, 0), (1, 1), (2, 2)];
+ while let Some((a, b)) = numbers.pop() {
+
+ }
+
+ while let Some(element) = numbers.pop() {
+ accept_i32_tuple(element);
+ }
+
+ let mut results = vec![Foo { a: 1, b: 2 }, Foo { a: 3, b: 4 }];
+ while let Some(Foo { a, b }) = results.pop() {
+
+ }
+}
diff --git a/src/tools/clippy/tests/ui/manual_while_let_some.rs b/src/tools/clippy/tests/ui/manual_while_let_some.rs
new file mode 100644
index 000000000..85a0a084a
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_while_let_some.rs
@@ -0,0 +1,93 @@
+//@run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::manual_while_let_some)]
+
+struct VecInStruct {
+ numbers: Vec<i32>,
+ unrelated: String,
+}
+
+struct Foo {
+ a: i32,
+ b: i32,
+}
+
+fn accept_i32(_: i32) {}
+fn accept_optional_i32(_: Option<i32>) {}
+fn accept_i32_tuple(_: (i32, i32)) {}
+
+fn main() {
+ let mut numbers = vec![1, 2, 3, 4, 5];
+ while !numbers.is_empty() {
+ let number = numbers.pop().unwrap();
+ }
+
+ let mut val = VecInStruct {
+ numbers: vec![1, 2, 3, 4, 5],
+ unrelated: String::new(),
+ };
+ while !val.numbers.is_empty() {
+ let number = val.numbers.pop().unwrap();
+ }
+
+ while !numbers.is_empty() {
+ accept_i32(numbers.pop().unwrap());
+ }
+
+ while !numbers.is_empty() {
+ accept_i32(numbers.pop().expect(""));
+ }
+
+ // This should not warn. It "conditionally" pops elements.
+ while !numbers.is_empty() {
+ if true {
+ accept_i32(numbers.pop().unwrap());
+ }
+ }
+
+ // This should also not warn. It conditionally pops elements.
+ while !numbers.is_empty() {
+ if false {
+ continue;
+ }
+ accept_i32(numbers.pop().unwrap());
+ }
+
+ // This should not warn. It pops elements, but does not unwrap it.
+ // Might handle the Option in some other arbitrary way.
+ while !numbers.is_empty() {
+ accept_optional_i32(numbers.pop());
+ }
+
+ let unrelated_vec: Vec<String> = Vec::new();
+ // This should not warn. It pops elements from a different vector.
+ while !unrelated_vec.is_empty() {
+ accept_i32(numbers.pop().unwrap());
+ }
+
+ macro_rules! generate_loop {
+ () => {
+ while !numbers.is_empty() {
+ accept_i32(numbers.pop().unwrap());
+ }
+ };
+ }
+ // Do not warn if the loop comes from a macro.
+ generate_loop!();
+
+ // Try other kinds of patterns
+ let mut numbers = vec![(0, 0), (1, 1), (2, 2)];
+ while !numbers.is_empty() {
+ let (a, b) = numbers.pop().unwrap();
+ }
+
+ while !numbers.is_empty() {
+ accept_i32_tuple(numbers.pop().unwrap());
+ }
+
+ let mut results = vec![Foo { a: 1, b: 2 }, Foo { a: 3, b: 4 }];
+ while !results.is_empty() {
+ let Foo { a, b } = results.pop().unwrap();
+ }
+}
diff --git a/src/tools/clippy/tests/ui/manual_while_let_some.stderr b/src/tools/clippy/tests/ui/manual_while_let_some.stderr
new file mode 100644
index 000000000..633fe05c4
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_while_let_some.stderr
@@ -0,0 +1,87 @@
+error: you seem to be trying to pop elements from a `Vec` in a loop
+ --> $DIR/manual_while_let_some.rs:23:9
+ |
+LL | let number = numbers.pop().unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::manual-while-let-some` implied by `-D warnings`
+help: consider using a `while..let` loop
+ |
+LL ~ while let Some(number) = numbers.pop() {
+LL ~
+ |
+
+error: you seem to be trying to pop elements from a `Vec` in a loop
+ --> $DIR/manual_while_let_some.rs:31:9
+ |
+LL | let number = val.numbers.pop().unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: consider using a `while..let` loop
+ |
+LL ~ while let Some(number) = val.numbers.pop() {
+LL ~
+ |
+
+error: you seem to be trying to pop elements from a `Vec` in a loop
+ --> $DIR/manual_while_let_some.rs:35:20
+ |
+LL | accept_i32(numbers.pop().unwrap());
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: consider using a `while..let` loop
+ |
+LL ~ while let Some(element) = numbers.pop() {
+LL ~ accept_i32(element);
+ |
+
+error: you seem to be trying to pop elements from a `Vec` in a loop
+ --> $DIR/manual_while_let_some.rs:39:20
+ |
+LL | accept_i32(numbers.pop().expect(""));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: consider using a `while..let` loop
+ |
+LL ~ while let Some(element) = numbers.pop() {
+LL ~ accept_i32(element);
+ |
+
+error: you seem to be trying to pop elements from a `Vec` in a loop
+ --> $DIR/manual_while_let_some.rs:82:9
+ |
+LL | let (a, b) = numbers.pop().unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: consider using a `while..let` loop
+ |
+LL ~ while let Some((a, b)) = numbers.pop() {
+LL ~
+ |
+
+error: you seem to be trying to pop elements from a `Vec` in a loop
+ --> $DIR/manual_while_let_some.rs:86:26
+ |
+LL | accept_i32_tuple(numbers.pop().unwrap());
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: consider using a `while..let` loop
+ |
+LL ~ while let Some(element) = numbers.pop() {
+LL ~ accept_i32_tuple(element);
+ |
+
+error: you seem to be trying to pop elements from a `Vec` in a loop
+ --> $DIR/manual_while_let_some.rs:91:9
+ |
+LL | let Foo { a, b } = results.pop().unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: consider using a `while..let` loop
+ |
+LL ~ while let Some(Foo { a, b }) = results.pop() {
+LL ~
+ |
+
+error: aborting due to 7 previous errors
+
diff --git a/src/tools/clippy/tests/ui/map_clone.fixed b/src/tools/clippy/tests/ui/map_clone.fixed
index 0860dcf8e..d7474f357 100644
--- a/src/tools/clippy/tests/ui/map_clone.fixed
+++ b/src/tools/clippy/tests/ui/map_clone.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::map_clone)]
#![allow(
clippy::clone_on_copy,
diff --git a/src/tools/clippy/tests/ui/map_clone.rs b/src/tools/clippy/tests/ui/map_clone.rs
index b69873368..74978ae80 100644
--- a/src/tools/clippy/tests/ui/map_clone.rs
+++ b/src/tools/clippy/tests/ui/map_clone.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::map_clone)]
#![allow(
clippy::clone_on_copy,
diff --git a/src/tools/clippy/tests/ui/map_collect_result_unit.fixed b/src/tools/clippy/tests/ui/map_collect_result_unit.fixed
index e66c9cc24..b00c2cf28 100644
--- a/src/tools/clippy/tests/ui/map_collect_result_unit.fixed
+++ b/src/tools/clippy/tests/ui/map_collect_result_unit.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::map_collect_result_unit)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/map_collect_result_unit.rs b/src/tools/clippy/tests/ui/map_collect_result_unit.rs
index 6f08f4c3c..ad2198ec1 100644
--- a/src/tools/clippy/tests/ui/map_collect_result_unit.rs
+++ b/src/tools/clippy/tests/ui/map_collect_result_unit.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::map_collect_result_unit)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/map_flatten_fixable.fixed b/src/tools/clippy/tests/ui/map_flatten_fixable.fixed
index 8e2f11389..14816de1a 100644
--- a/src/tools/clippy/tests/ui/map_flatten_fixable.fixed
+++ b/src/tools/clippy/tests/ui/map_flatten_fixable.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all, clippy::pedantic)]
#![allow(clippy::let_underscore_untyped)]
diff --git a/src/tools/clippy/tests/ui/map_flatten_fixable.rs b/src/tools/clippy/tests/ui/map_flatten_fixable.rs
index a783a99c4..f38a00a59 100644
--- a/src/tools/clippy/tests/ui/map_flatten_fixable.rs
+++ b/src/tools/clippy/tests/ui/map_flatten_fixable.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all, clippy::pedantic)]
#![allow(clippy::let_underscore_untyped)]
diff --git a/src/tools/clippy/tests/ui/map_identity.fixed b/src/tools/clippy/tests/ui/map_identity.fixed
index 2256e51f2..7fb7d8c12 100644
--- a/src/tools/clippy/tests/ui/map_identity.fixed
+++ b/src/tools/clippy/tests/ui/map_identity.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::map_identity)]
#![allow(clippy::needless_return)]
diff --git a/src/tools/clippy/tests/ui/map_identity.rs b/src/tools/clippy/tests/ui/map_identity.rs
index ccfdc9ea7..7891c2426 100644
--- a/src/tools/clippy/tests/ui/map_identity.rs
+++ b/src/tools/clippy/tests/ui/map_identity.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::map_identity)]
#![allow(clippy::needless_return)]
diff --git a/src/tools/clippy/tests/ui/map_unwrap_or.rs b/src/tools/clippy/tests/ui/map_unwrap_or.rs
index 32631024c..cb25d8567 100644
--- a/src/tools/clippy/tests/ui/map_unwrap_or.rs
+++ b/src/tools/clippy/tests/ui/map_unwrap_or.rs
@@ -1,4 +1,4 @@
-// aux-build:option_helpers.rs
+//@aux-build:option_helpers.rs
#![warn(clippy::map_unwrap_or)]
#![allow(clippy::uninlined_format_args, clippy::unnecessary_lazy_evaluations)]
diff --git a/src/tools/clippy/tests/ui/map_unwrap_or_fixable.fixed b/src/tools/clippy/tests/ui/map_unwrap_or_fixable.fixed
index bd5b4f716..ea5b6a669 100644
--- a/src/tools/clippy/tests/ui/map_unwrap_or_fixable.fixed
+++ b/src/tools/clippy/tests/ui/map_unwrap_or_fixable.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:option_helpers.rs
+//@run-rustfix
+//@aux-build:option_helpers.rs
#![warn(clippy::map_unwrap_or)]
diff --git a/src/tools/clippy/tests/ui/map_unwrap_or_fixable.rs b/src/tools/clippy/tests/ui/map_unwrap_or_fixable.rs
index 0b892caf2..f8bb9d8ca 100644
--- a/src/tools/clippy/tests/ui/map_unwrap_or_fixable.rs
+++ b/src/tools/clippy/tests/ui/map_unwrap_or_fixable.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:option_helpers.rs
+//@run-rustfix
+//@aux-build:option_helpers.rs
#![warn(clippy::map_unwrap_or)]
diff --git a/src/tools/clippy/tests/ui/match_as_ref.fixed b/src/tools/clippy/tests/ui/match_as_ref.fixed
index ddfa1e741..8fa3f5325 100644
--- a/src/tools/clippy/tests/ui/match_as_ref.fixed
+++ b/src/tools/clippy/tests/ui/match_as_ref.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::match_as_ref)]
diff --git a/src/tools/clippy/tests/ui/match_as_ref.rs b/src/tools/clippy/tests/ui/match_as_ref.rs
index 025d475ae..02a177914 100644
--- a/src/tools/clippy/tests/ui/match_as_ref.rs
+++ b/src/tools/clippy/tests/ui/match_as_ref.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::match_as_ref)]
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 55cd15bd5..60f590661 100644
--- a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed
+++ b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::match_like_matches_macro)]
#![allow(
@@ -15,7 +15,7 @@ fn main() {
let _y = matches!(x, Some(0));
// Lint
- let _w = matches!(x, Some(_));
+ let _w = x.is_some();
// Turn into is_none
let _z = x.is_none();
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 5d645e108..afdf1069f 100644
--- a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs
+++ b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::match_like_matches_macro)]
#![allow(
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 46f67ef49..b72fe10b7 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
@@ -10,7 +10,7 @@ LL | | };
|
= note: `-D clippy::match-like-matches-macro` implied by `-D warnings`
-error: match expression looks like `matches!` macro
+error: redundant pattern matching, consider using `is_some()`
--> $DIR/match_expr_like_matches_macro.rs:21:14
|
LL | let _w = match x {
@@ -18,7 +18,9 @@ LL | let _w = match x {
LL | | Some(_) => true,
LL | | _ => false,
LL | | };
- | |_____^ help: try this: `matches!(x, Some(_))`
+ | |_____^ help: try this: `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
@@ -29,8 +31,6 @@ LL | | Some(_) => false,
LL | | None => true,
LL | | };
| |_____^ help: try this: `x.is_none()`
- |
- = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: match expression looks like `matches!` macro
--> $DIR/match_expr_like_matches_macro.rs:33:15
diff --git a/src/tools/clippy/tests/ui/match_ref_pats.fixed b/src/tools/clippy/tests/ui/match_ref_pats.fixed
index cf37fc6dc..50c3dcc1e 100644
--- a/src/tools/clippy/tests/ui/match_ref_pats.fixed
+++ b/src/tools/clippy/tests/ui/match_ref_pats.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::match_ref_pats)]
#![allow(dead_code, unused_variables)]
#![allow(clippy::enum_variant_names, clippy::equatable_if_let, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/match_ref_pats.rs b/src/tools/clippy/tests/ui/match_ref_pats.rs
index 3220b97d1..d29ddacc0 100644
--- a/src/tools/clippy/tests/ui/match_ref_pats.rs
+++ b/src/tools/clippy/tests/ui/match_ref_pats.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::match_ref_pats)]
#![allow(dead_code, unused_variables)]
#![allow(clippy::enum_variant_names, clippy::equatable_if_let, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/match_result_ok.fixed b/src/tools/clippy/tests/ui/match_result_ok.fixed
index 10ae1ee52..fe67b225f 100644
--- a/src/tools/clippy/tests/ui/match_result_ok.fixed
+++ b/src/tools/clippy/tests/ui/match_result_ok.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::match_result_ok)]
#![allow(dead_code)]
#![allow(clippy::boxed_local, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/match_result_ok.rs b/src/tools/clippy/tests/ui/match_result_ok.rs
index bc2c4b50e..eac382e1f 100644
--- a/src/tools/clippy/tests/ui/match_result_ok.rs
+++ b/src/tools/clippy/tests/ui/match_result_ok.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::match_result_ok)]
#![allow(dead_code)]
#![allow(clippy::boxed_local, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/match_same_arms.rs b/src/tools/clippy/tests/ui/match_same_arms.rs
index 0b9342c9c..3914b4546 100644
--- a/src/tools/clippy/tests/ui/match_same_arms.rs
+++ b/src/tools/clippy/tests/ui/match_same_arms.rs
@@ -53,4 +53,84 @@ mod issue4244 {
}
}
-fn main() {}
+macro_rules! m {
+ (foo) => {};
+ (bar) => {};
+}
+macro_rules! foo {
+ () => {
+ 1
+ };
+}
+macro_rules! bar {
+ () => {
+ 1
+ };
+}
+
+fn main() {
+ let x = 0;
+ let _ = match 0 {
+ 0 => {
+ m!(foo);
+ x
+ },
+ 1 => {
+ m!(bar);
+ x
+ },
+ _ => 1,
+ };
+
+ let _ = match 0 {
+ 0 => {
+ m!(foo);
+ 0
+ },
+ 1 => {
+ m!(bar);
+ 0
+ },
+ _ => 1,
+ };
+
+ let _ = match 0 {
+ 0 => {
+ let mut x = 0;
+ #[cfg(not_enabled)]
+ {
+ x = 5;
+ }
+ #[cfg(not(not_enabled))]
+ {
+ x = 6;
+ }
+ x
+ },
+ 1 => {
+ let mut x = 0;
+ #[cfg(also_not_enabled)]
+ {
+ x = 5;
+ }
+ #[cfg(not(also_not_enabled))]
+ {
+ x = 6;
+ }
+ x
+ },
+ _ => 0,
+ };
+
+ let _ = match 0 {
+ 0 => foo!(),
+ 1 => bar!(),
+ _ => 1,
+ };
+
+ let _ = match 0 {
+ 0 => cfg!(not_enabled),
+ 1 => cfg!(also_not_enabled),
+ _ => false,
+ };
+}
diff --git a/src/tools/clippy/tests/ui/match_same_arms2.rs b/src/tools/clippy/tests/ui/match_same_arms2.rs
index 82b2c433d..60b2975be 100644
--- a/src/tools/clippy/tests/ui/match_same_arms2.rs
+++ b/src/tools/clippy/tests/ui/match_same_arms2.rs
@@ -239,4 +239,10 @@ fn main() {
3 => core::convert::identity::<u32>(todo!()),
_ => 5,
};
+
+ let _ = match 0 {
+ 0 => cfg!(not_enable),
+ 1 => cfg!(not_enable),
+ _ => false,
+ };
}
diff --git a/src/tools/clippy/tests/ui/match_same_arms2.stderr b/src/tools/clippy/tests/ui/match_same_arms2.stderr
index 06cd43000..8fb461bd2 100644
--- a/src/tools/clippy/tests/ui/match_same_arms2.stderr
+++ b/src/tools/clippy/tests/ui/match_same_arms2.stderr
@@ -192,5 +192,20 @@ note: other arm here
LL | Some(Bar { x: 0, y: 5, .. }) => 1,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 12 previous errors
+error: this match arm has an identical body to another arm
+ --> $DIR/match_same_arms2.rs:245:9
+ |
+LL | 1 => cfg!(not_enable),
+ | -^^^^^^^^^^^^^^^^^^^^
+ | |
+ | help: try merging the arm patterns: `1 | 0`
+ |
+ = help: or try changing either arm body
+note: other arm here
+ --> $DIR/match_same_arms2.rs:244:9
+ |
+LL | 0 => cfg!(not_enable),
+ | ^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 13 previous errors
diff --git a/src/tools/clippy/tests/ui/match_single_binding.fixed b/src/tools/clippy/tests/ui/match_single_binding.fixed
index 201301cc9..7c29bb08e 100644
--- a/src/tools/clippy/tests/ui/match_single_binding.fixed
+++ b/src/tools/clippy/tests/ui/match_single_binding.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::match_single_binding)]
#![allow(
unused,
diff --git a/src/tools/clippy/tests/ui/match_single_binding.rs b/src/tools/clippy/tests/ui/match_single_binding.rs
index 8b047b19c..c068d5e17 100644
--- a/src/tools/clippy/tests/ui/match_single_binding.rs
+++ b/src/tools/clippy/tests/ui/match_single_binding.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::match_single_binding)]
#![allow(
unused,
diff --git a/src/tools/clippy/tests/ui/match_single_binding2.fixed b/src/tools/clippy/tests/ui/match_single_binding2.fixed
index e3cf56a42..adfb4ba91 100644
--- a/src/tools/clippy/tests/ui/match_single_binding2.fixed
+++ b/src/tools/clippy/tests/ui/match_single_binding2.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::match_single_binding)]
#![allow(unused_variables)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/match_single_binding2.rs b/src/tools/clippy/tests/ui/match_single_binding2.rs
index 5a4bb8441..b5cfe3654 100644
--- a/src/tools/clippy/tests/ui/match_single_binding2.rs
+++ b/src/tools/clippy/tests/ui/match_single_binding2.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::match_single_binding)]
#![allow(unused_variables)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/match_str_case_mismatch.fixed b/src/tools/clippy/tests/ui/match_str_case_mismatch.fixed
index e436bcf49..cd53b1f06 100644
--- a/src/tools/clippy/tests/ui/match_str_case_mismatch.fixed
+++ b/src/tools/clippy/tests/ui/match_str_case_mismatch.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::match_str_case_mismatch)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/match_str_case_mismatch.rs b/src/tools/clippy/tests/ui/match_str_case_mismatch.rs
index 92e2a000a..688530566 100644
--- a/src/tools/clippy/tests/ui/match_str_case_mismatch.rs
+++ b/src/tools/clippy/tests/ui/match_str_case_mismatch.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::match_str_case_mismatch)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.fixed b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.fixed
index 9fd3739b6..d2e6fef07 100644
--- a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.fixed
+++ b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::match_wildcard_for_single_variants)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.rs b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.rs
index 9a5c849e6..cff0c8960 100644
--- a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.rs
+++ b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::match_wildcard_for_single_variants)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/mem_forget.rs b/src/tools/clippy/tests/ui/mem_forget.rs
index e5b35c098..edb9d87d0 100644
--- a/src/tools/clippy/tests/ui/mem_forget.rs
+++ b/src/tools/clippy/tests/ui/mem_forget.rs
@@ -5,7 +5,7 @@ use std::mem as memstuff;
use std::mem::forget as forgetSomething;
#[warn(clippy::mem_forget)]
-#[allow(clippy::forget_copy)]
+#[allow(forgetting_copy_types)]
fn main() {
let five: i32 = 5;
forgetSomething(five);
diff --git a/src/tools/clippy/tests/ui/mem_replace.fixed b/src/tools/clippy/tests/ui/mem_replace.fixed
index 7fd340173..d37e97b0a 100644
--- a/src/tools/clippy/tests/ui/mem_replace.fixed
+++ b/src/tools/clippy/tests/ui/mem_replace.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(
diff --git a/src/tools/clippy/tests/ui/mem_replace.rs b/src/tools/clippy/tests/ui/mem_replace.rs
index fa2903add..34e37f3db 100644
--- a/src/tools/clippy/tests/ui/mem_replace.rs
+++ b/src/tools/clippy/tests/ui/mem_replace.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(
diff --git a/src/tools/clippy/tests/ui/mem_replace_macro.rs b/src/tools/clippy/tests/ui/mem_replace_macro.rs
index 3932e7d00..132873858 100644
--- a/src/tools/clippy/tests/ui/mem_replace_macro.rs
+++ b/src/tools/clippy/tests/ui/mem_replace_macro.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs
#![warn(clippy::mem_replace_with_default)]
extern crate proc_macros;
diff --git a/src/tools/clippy/tests/ui/methods.rs b/src/tools/clippy/tests/ui/methods.rs
index 1519e4da9..e0e2cac30 100644
--- a/src/tools/clippy/tests/ui/methods.rs
+++ b/src/tools/clippy/tests/ui/methods.rs
@@ -1,4 +1,4 @@
-// aux-build:option_helpers.rs
+//@aux-build:option_helpers.rs
#![warn(clippy::all, clippy::pedantic)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/methods_fixable.fixed b/src/tools/clippy/tests/ui/methods_fixable.fixed
index ee7c1b0da..dcbed5a4d 100644
--- a/src/tools/clippy/tests/ui/methods_fixable.fixed
+++ b/src/tools/clippy/tests/ui/methods_fixable.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::filter_next)]
diff --git a/src/tools/clippy/tests/ui/methods_fixable.rs b/src/tools/clippy/tests/ui/methods_fixable.rs
index 6d0f1b7bd..3a976d235 100644
--- a/src/tools/clippy/tests/ui/methods_fixable.rs
+++ b/src/tools/clippy/tests/ui/methods_fixable.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::filter_next)]
diff --git a/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.fixed b/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.fixed
index f219a570e..f58e9a429 100644
--- a/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.fixed
+++ b/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::mismatched_target_os)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.rs b/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.rs
index 8a8ae756a..e00224f5c 100644
--- a/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.rs
+++ b/src/tools/clippy/tests/ui/mismatched_target_os_non_unix.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::mismatched_target_os)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/mismatched_target_os_unix.fixed b/src/tools/clippy/tests/ui/mismatched_target_os_unix.fixed
index 7d9d406d9..330587a3c 100644
--- a/src/tools/clippy/tests/ui/mismatched_target_os_unix.fixed
+++ b/src/tools/clippy/tests/ui/mismatched_target_os_unix.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::mismatched_target_os)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/mismatched_target_os_unix.rs b/src/tools/clippy/tests/ui/mismatched_target_os_unix.rs
index c1177f1ee..5a90019a2 100644
--- a/src/tools/clippy/tests/ui/mismatched_target_os_unix.rs
+++ b/src/tools/clippy/tests/ui/mismatched_target_os_unix.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::mismatched_target_os)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs b/src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs
index e6f88c6e6..5db73a7b8 100644
--- a/src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs
+++ b/src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs
@@ -2,8 +2,8 @@
//! compilation error.
//! The .stderr output of this test should be empty. Otherwise it's a bug somewhere.
-// aux-build:helper.rs
-// aux-build:../../auxiliary/proc_macros.rs
+//@aux-build:helper.rs
+//@aux-build:../../auxiliary/proc_macros.rs
#![warn(clippy::missing_const_for_fn)]
#![feature(start)]
diff --git a/src/tools/clippy/tests/ui/missing_doc.rs b/src/tools/clippy/tests/ui/missing_doc.rs
index 575204894..bf587e774 100644
--- a/src/tools/clippy/tests/ui/missing_doc.rs
+++ b/src/tools/clippy/tests/ui/missing_doc.rs
@@ -1,5 +1,5 @@
-// needs-asm-support
-// aux-build: proc_macros.rs
+//@needs-asm-support
+//@aux-build: proc_macros.rs
#![warn(clippy::missing_docs_in_private_items)]
// When denying at the crate level, be sure to not get random warnings from the
diff --git a/src/tools/clippy/tests/ui/missing_doc_impl.rs b/src/tools/clippy/tests/ui/missing_doc_impl.rs
index e2d49b090..520ddbe16 100644
--- a/src/tools/clippy/tests/ui/missing_doc_impl.rs
+++ b/src/tools/clippy/tests/ui/missing_doc_impl.rs
@@ -1,4 +1,4 @@
-// aux-build: proc_macros.rs
+//@aux-build: proc_macros.rs
#![warn(clippy::missing_docs_in_private_items)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/missing_spin_loop.fixed b/src/tools/clippy/tests/ui/missing_spin_loop.fixed
index aa89e04d2..a15298dc3 100644
--- a/src/tools/clippy/tests/ui/missing_spin_loop.fixed
+++ b/src/tools/clippy/tests/ui/missing_spin_loop.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::missing_spin_loop)]
#![allow(clippy::bool_comparison)]
#![allow(unused_braces)]
diff --git a/src/tools/clippy/tests/ui/missing_spin_loop.rs b/src/tools/clippy/tests/ui/missing_spin_loop.rs
index 88745e477..be74581ec 100644
--- a/src/tools/clippy/tests/ui/missing_spin_loop.rs
+++ b/src/tools/clippy/tests/ui/missing_spin_loop.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::missing_spin_loop)]
#![allow(clippy::bool_comparison)]
#![allow(unused_braces)]
diff --git a/src/tools/clippy/tests/ui/missing_spin_loop_no_std.fixed b/src/tools/clippy/tests/ui/missing_spin_loop_no_std.fixed
index bb4b47955..960e5c05f 100644
--- a/src/tools/clippy/tests/ui/missing_spin_loop_no_std.fixed
+++ b/src/tools/clippy/tests/ui/missing_spin_loop_no_std.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::missing_spin_loop)]
#![feature(lang_items, start, libc)]
#![no_std]
diff --git a/src/tools/clippy/tests/ui/missing_spin_loop_no_std.rs b/src/tools/clippy/tests/ui/missing_spin_loop_no_std.rs
index a19bc72ba..e532ca62d 100644
--- a/src/tools/clippy/tests/ui/missing_spin_loop_no_std.rs
+++ b/src/tools/clippy/tests/ui/missing_spin_loop_no_std.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::missing_spin_loop)]
#![feature(lang_items, start, libc)]
#![no_std]
diff --git a/src/tools/clippy/tests/ui/mistyped_literal_suffix.fixed b/src/tools/clippy/tests/ui/mistyped_literal_suffix.fixed
index 9a47d7c56..62cfeafdc 100644
--- a/src/tools/clippy/tests/ui/mistyped_literal_suffix.fixed
+++ b/src/tools/clippy/tests/ui/mistyped_literal_suffix.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build: proc_macros.rs
+//@run-rustfix
+//@aux-build: proc_macros.rs
#![allow(
dead_code,
diff --git a/src/tools/clippy/tests/ui/mistyped_literal_suffix.rs b/src/tools/clippy/tests/ui/mistyped_literal_suffix.rs
index 04261cba5..f83b7c3db 100644
--- a/src/tools/clippy/tests/ui/mistyped_literal_suffix.rs
+++ b/src/tools/clippy/tests/ui/mistyped_literal_suffix.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build: proc_macros.rs
+//@run-rustfix
+//@aux-build: proc_macros.rs
#![allow(
dead_code,
diff --git a/src/tools/clippy/tests/ui/module_name_repetitions.rs b/src/tools/clippy/tests/ui/module_name_repetitions.rs
index ebaa77cc2..fb2c76123 100644
--- a/src/tools/clippy/tests/ui/module_name_repetitions.rs
+++ b/src/tools/clippy/tests/ui/module_name_repetitions.rs
@@ -1,4 +1,4 @@
-// compile-flags: --test
+//@compile-flags: --test
#![warn(clippy::module_name_repetitions)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs b/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs
index 9082f1675..4ef6f0ca9 100644
--- a/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs
+++ b/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs
@@ -1,8 +1,8 @@
-// aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs
#![allow(unused)]
#![allow(deref_nullptr)]
#![allow(clippy::unnecessary_operation)]
-#![allow(clippy::drop_copy)]
+#![allow(dropping_copy_types)]
#![warn(clippy::multiple_unsafe_ops_per_block)]
extern crate proc_macros;
diff --git a/src/tools/clippy/tests/ui/must_use_candidates.fixed b/src/tools/clippy/tests/ui/must_use_candidates.fixed
index bbbb3cf62..0c275504d 100644
--- a/src/tools/clippy/tests/ui/must_use_candidates.fixed
+++ b/src/tools/clippy/tests/ui/must_use_candidates.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(never_type)]
#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
#![warn(clippy::must_use_candidate)]
diff --git a/src/tools/clippy/tests/ui/must_use_candidates.rs b/src/tools/clippy/tests/ui/must_use_candidates.rs
index 94d3c83bd..d1c926773 100644
--- a/src/tools/clippy/tests/ui/must_use_candidates.rs
+++ b/src/tools/clippy/tests/ui/must_use_candidates.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(never_type)]
#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
#![warn(clippy::must_use_candidate)]
diff --git a/src/tools/clippy/tests/ui/must_use_unit.fixed b/src/tools/clippy/tests/ui/must_use_unit.fixed
index b7d375ff8..4f7cf4e56 100644
--- a/src/tools/clippy/tests/ui/must_use_unit.fixed
+++ b/src/tools/clippy/tests/ui/must_use_unit.fixed
@@ -1,5 +1,5 @@
-//run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![warn(clippy::must_use_unit)]
#![allow(clippy::unused_unit)]
diff --git a/src/tools/clippy/tests/ui/must_use_unit.rs b/src/tools/clippy/tests/ui/must_use_unit.rs
index 74d6b4ca8..3a814ce16 100644
--- a/src/tools/clippy/tests/ui/must_use_unit.rs
+++ b/src/tools/clippy/tests/ui/must_use_unit.rs
@@ -1,5 +1,5 @@
-//run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![warn(clippy::must_use_unit)]
#![allow(clippy::unused_unit)]
diff --git a/src/tools/clippy/tests/ui/mut_mut.rs b/src/tools/clippy/tests/ui/mut_mut.rs
index 06bb08544..d838098de 100644
--- a/src/tools/clippy/tests/ui/mut_mut.rs
+++ b/src/tools/clippy/tests/ui/mut_mut.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs
#![warn(clippy::mut_mut)]
#![allow(unused)]
#![allow(clippy::no_effect, clippy::uninlined_format_args, clippy::unnecessary_operation)]
diff --git a/src/tools/clippy/tests/ui/mut_mutex_lock.fixed b/src/tools/clippy/tests/ui/mut_mutex_lock.fixed
index ecad10a82..433817a4e 100644
--- a/src/tools/clippy/tests/ui/mut_mutex_lock.fixed
+++ b/src/tools/clippy/tests/ui/mut_mutex_lock.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, unused_mut)]
#![warn(clippy::mut_mutex_lock)]
diff --git a/src/tools/clippy/tests/ui/mut_mutex_lock.rs b/src/tools/clippy/tests/ui/mut_mutex_lock.rs
index f2b1d6fbf..567a0b59e 100644
--- a/src/tools/clippy/tests/ui/mut_mutex_lock.rs
+++ b/src/tools/clippy/tests/ui/mut_mutex_lock.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, unused_mut)]
#![warn(clippy::mut_mutex_lock)]
diff --git a/src/tools/clippy/tests/ui/needless_arbitrary_self_type.fixed b/src/tools/clippy/tests/ui/needless_arbitrary_self_type.fixed
index 9da21eb6b..d7eb1a047 100644
--- a/src/tools/clippy/tests/ui/needless_arbitrary_self_type.fixed
+++ b/src/tools/clippy/tests/ui/needless_arbitrary_self_type.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::needless_arbitrary_self_type)]
#![allow(unused_mut, clippy::needless_lifetimes)]
diff --git a/src/tools/clippy/tests/ui/needless_arbitrary_self_type.rs b/src/tools/clippy/tests/ui/needless_arbitrary_self_type.rs
index 17aeaaf97..85a2a957f 100644
--- a/src/tools/clippy/tests/ui/needless_arbitrary_self_type.rs
+++ b/src/tools/clippy/tests/ui/needless_arbitrary_self_type.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::needless_arbitrary_self_type)]
#![allow(unused_mut, clippy::needless_lifetimes)]
diff --git a/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.rs b/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.rs
index 02b43cce2..00871f9f4 100644
--- a/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.rs
+++ b/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macro_attr.rs
+//@aux-build:proc_macro_attr.rs
#![warn(clippy::needless_arbitrary_self_type)]
diff --git a/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.stderr b/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.stderr
index b2edbfe43..c7df5936d 100644
--- a/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.stderr
+++ b/src/tools/clippy/tests/ui/needless_arbitrary_self_type_unfixable.stderr
@@ -2,7 +2,7 @@ error: the type of the `self` parameter does not need to be arbitrary
--> $DIR/needless_arbitrary_self_type_unfixable.rs:42:31
|
LL | fn call_with_mut_self(self: &mut Self) {}
- | ^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&'_ mut self`
+ | ^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&mut self`
|
= note: `-D clippy::needless-arbitrary-self-type` implied by `-D warnings`
diff --git a/src/tools/clippy/tests/ui/needless_bitwise_bool.fixed b/src/tools/clippy/tests/ui/needless_bitwise_bool.fixed
index 5e1ea663a..7543ab72c 100644
--- a/src/tools/clippy/tests/ui/needless_bitwise_bool.fixed
+++ b/src/tools/clippy/tests/ui/needless_bitwise_bool.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::needless_bitwise_bool)]
diff --git a/src/tools/clippy/tests/ui/needless_bitwise_bool.rs b/src/tools/clippy/tests/ui/needless_bitwise_bool.rs
index f3075fba0..2cea701dc 100644
--- a/src/tools/clippy/tests/ui/needless_bitwise_bool.rs
+++ b/src/tools/clippy/tests/ui/needless_bitwise_bool.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::needless_bitwise_bool)]
diff --git a/src/tools/clippy/tests/ui/needless_bool/fixable.fixed b/src/tools/clippy/tests/ui/needless_bool/fixable.fixed
index 89dc13fd5..bf1911881 100644
--- a/src/tools/clippy/tests/ui/needless_bool/fixable.fixed
+++ b/src/tools/clippy/tests/ui/needless_bool/fixable.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::needless_bool)]
#![allow(
@@ -63,6 +63,13 @@ fn main() {
needless_bool2(x);
needless_bool3(x);
needless_bool_condition();
+
+ if a == b {
+ true
+ } else {
+ // Do not lint as this comment might be important
+ false
+ };
}
fn bool_ret3(x: bool) -> bool {
diff --git a/src/tools/clippy/tests/ui/needless_bool/fixable.rs b/src/tools/clippy/tests/ui/needless_bool/fixable.rs
index c11d9472e..a6c465d4f 100644
--- a/src/tools/clippy/tests/ui/needless_bool/fixable.rs
+++ b/src/tools/clippy/tests/ui/needless_bool/fixable.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::needless_bool)]
#![allow(
@@ -99,6 +99,13 @@ fn main() {
needless_bool2(x);
needless_bool3(x);
needless_bool_condition();
+
+ if a == b {
+ true
+ } else {
+ // Do not lint as this comment might be important
+ false
+ };
}
fn bool_ret3(x: bool) -> bool {
diff --git a/src/tools/clippy/tests/ui/needless_bool/fixable.stderr b/src/tools/clippy/tests/ui/needless_bool/fixable.stderr
index d2c48376f..fa906374f 100644
--- a/src/tools/clippy/tests/ui/needless_bool/fixable.stderr
+++ b/src/tools/clippy/tests/ui/needless_bool/fixable.stderr
@@ -91,7 +91,7 @@ LL | | };
| |_____^ help: you can reduce it to: `a < b`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:105:5
+ --> $DIR/fixable.rs:112:5
|
LL | / if x {
LL | | return true;
@@ -101,7 +101,7 @@ LL | | };
| |_____^ help: you can reduce it to: `return x`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:113:5
+ --> $DIR/fixable.rs:120:5
|
LL | / if x {
LL | | return false;
@@ -111,7 +111,7 @@ LL | | };
| |_____^ help: you can reduce it to: `return !x`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:121:5
+ --> $DIR/fixable.rs:128:5
|
LL | / if x && y {
LL | | return true;
@@ -121,7 +121,7 @@ LL | | };
| |_____^ help: you can reduce it to: `return x && y`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:129:5
+ --> $DIR/fixable.rs:136:5
|
LL | / if x && y {
LL | | return false;
@@ -131,7 +131,7 @@ LL | | };
| |_____^ help: you can reduce it to: `return !(x && y)`
error: equality checks against true are unnecessary
- --> $DIR/fixable.rs:137:8
+ --> $DIR/fixable.rs:144:8
|
LL | if x == true {};
| ^^^^^^^^^ help: try simplifying it as shown: `x`
@@ -139,25 +139,25 @@ LL | if x == true {};
= note: `-D clippy::bool-comparison` implied by `-D warnings`
error: equality checks against false can be replaced by a negation
- --> $DIR/fixable.rs:141:8
+ --> $DIR/fixable.rs:148:8
|
LL | if x == false {};
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
error: equality checks against true are unnecessary
- --> $DIR/fixable.rs:151:8
+ --> $DIR/fixable.rs:158:8
|
LL | if x == true {};
| ^^^^^^^^^ help: try simplifying it as shown: `x`
error: equality checks against false can be replaced by a negation
- --> $DIR/fixable.rs:152:8
+ --> $DIR/fixable.rs:159:8
|
LL | if x == false {};
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:161:12
+ --> $DIR/fixable.rs:168:12
|
LL | } else if returns_bool() {
| ____________^
@@ -168,7 +168,7 @@ LL | | };
| |_____^ help: you can reduce it to: `{ !returns_bool() }`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:174:5
+ --> $DIR/fixable.rs:181:5
|
LL | / if unsafe { no(4) } & 1 != 0 {
LL | | true
@@ -178,13 +178,13 @@ LL | | };
| |_____^ help: you can reduce it to: `(unsafe { no(4) } & 1 != 0)`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:179:30
+ --> $DIR/fixable.rs:186:30
|
LL | let _brackets_unneeded = if unsafe { no(4) } & 1 != 0 { true } else { false };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `unsafe { no(4) } & 1 != 0`
error: this if-then-else expression returns a bool literal
- --> $DIR/fixable.rs:182:9
+ --> $DIR/fixable.rs:189:9
|
LL | if unsafe { no(4) } & 1 != 0 { true } else { false }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `(unsafe { no(4) } & 1 != 0)`
diff --git a/src/tools/clippy/tests/ui/needless_bool_assign.fixed b/src/tools/clippy/tests/ui/needless_bool_assign.fixed
new file mode 100644
index 000000000..3ed31d4d7
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_bool_assign.fixed
@@ -0,0 +1,33 @@
+//@run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::needless_bool_assign)]
+
+fn random() -> bool {
+ true
+}
+
+fn main() {
+ struct Data {
+ field: bool,
+ };
+ let mut a = Data { field: false };
+ a.field = random() && random();
+ a.field = !(random() && random());
+ // Do not lint…
+ if random() {
+ a.field = false;
+ } else {
+ // …to avoid losing this comment
+ a.field = true
+ }
+ // This one also triggers lint `clippy::if_same_then_else`
+ // which does not suggest a rewrite.
+ random(); a.field = true;
+ let mut b = false;
+ if random() {
+ a.field = false;
+ } else {
+ b = true;
+ }
+}
diff --git a/src/tools/clippy/tests/ui/needless_bool_assign.rs b/src/tools/clippy/tests/ui/needless_bool_assign.rs
new file mode 100644
index 000000000..efaeb67fa
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_bool_assign.rs
@@ -0,0 +1,45 @@
+//@run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::needless_bool_assign)]
+
+fn random() -> bool {
+ true
+}
+
+fn main() {
+ struct Data {
+ field: bool,
+ };
+ let mut a = Data { field: false };
+ if random() && random() {
+ a.field = true;
+ } else {
+ a.field = false
+ }
+ if random() && random() {
+ a.field = false;
+ } else {
+ a.field = true
+ }
+ // Do not lint…
+ if random() {
+ a.field = false;
+ } else {
+ // …to avoid losing this comment
+ a.field = true
+ }
+ // This one also triggers lint `clippy::if_same_then_else`
+ // which does not suggest a rewrite.
+ if random() {
+ a.field = true;
+ } else {
+ a.field = true;
+ }
+ let mut b = false;
+ if random() {
+ a.field = false;
+ } else {
+ b = true;
+ }
+}
diff --git a/src/tools/clippy/tests/ui/needless_bool_assign.stderr b/src/tools/clippy/tests/ui/needless_bool_assign.stderr
new file mode 100644
index 000000000..601bbed54
--- /dev/null
+++ b/src/tools/clippy/tests/ui/needless_bool_assign.stderr
@@ -0,0 +1,53 @@
+error: this if-then-else expression assigns a bool literal
+ --> $DIR/needless_bool_assign.rs:15:5
+ |
+LL | / if random() && random() {
+LL | | a.field = true;
+LL | | } else {
+LL | | a.field = false
+LL | | }
+ | |_____^ help: you can reduce it to: `a.field = random() && random();`
+ |
+ = note: `-D clippy::needless-bool-assign` implied by `-D warnings`
+
+error: this if-then-else expression assigns a bool literal
+ --> $DIR/needless_bool_assign.rs:20:5
+ |
+LL | / if random() && random() {
+LL | | a.field = false;
+LL | | } else {
+LL | | a.field = true
+LL | | }
+ | |_____^ help: you can reduce it to: `a.field = !(random() && random());`
+
+error: this if-then-else expression assigns a bool literal
+ --> $DIR/needless_bool_assign.rs:34:5
+ |
+LL | / if random() {
+LL | | a.field = true;
+LL | | } else {
+LL | | a.field = true;
+LL | | }
+ | |_____^ help: you can reduce it to: `random(); a.field = true;`
+
+error: this `if` has identical blocks
+ --> $DIR/needless_bool_assign.rs:34:17
+ |
+LL | if random() {
+ | _________________^
+LL | | a.field = true;
+LL | | } else {
+ | |_____^
+ |
+note: same as this
+ --> $DIR/needless_bool_assign.rs:36:12
+ |
+LL | } else {
+ | ____________^
+LL | | a.field = true;
+LL | | }
+ | |_____^
+ = note: `#[deny(clippy::if_same_then_else)]` on by default
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui/needless_borrow.fixed b/src/tools/clippy/tests/ui/needless_borrow.fixed
index 4cb7f6b68..425e6eb62 100644
--- a/src/tools/clippy/tests/ui/needless_borrow.fixed
+++ b/src/tools/clippy/tests/ui/needless_borrow.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(lint_reasons)]
#![allow(
unused,
diff --git a/src/tools/clippy/tests/ui/needless_borrow.rs b/src/tools/clippy/tests/ui/needless_borrow.rs
index 9a01190ed..3f7fa4a9d 100644
--- a/src/tools/clippy/tests/ui/needless_borrow.rs
+++ b/src/tools/clippy/tests/ui/needless_borrow.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(lint_reasons)]
#![allow(
unused,
diff --git a/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed b/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed
index 0c47ceb7b..6663520da 100644
--- a/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed
+++ b/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::needless_borrowed_reference)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/needless_borrowed_ref.rs b/src/tools/clippy/tests/ui/needless_borrowed_ref.rs
index f883bb0c8..6c8efd2ce 100644
--- a/src/tools/clippy/tests/ui/needless_borrowed_ref.rs
+++ b/src/tools/clippy/tests/ui/needless_borrowed_ref.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::needless_borrowed_reference)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/needless_collect.fixed b/src/tools/clippy/tests/ui/needless_collect.fixed
index 2659ad384..b7e80af50 100644
--- a/src/tools/clippy/tests/ui/needless_collect.fixed
+++ b/src/tools/clippy/tests/ui/needless_collect.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::suspicious_map, clippy::iter_count)]
@@ -62,4 +62,16 @@ fn main() {
let _ = sample.iter().next().is_none();
let _ = sample.iter().any(|x| x == &0);
+
+ #[allow(clippy::double_parens)]
+ {
+ Vec::<u8>::new().extend((0..10));
+ foo((0..10));
+ bar((0..10).collect::<Vec<_>>(), (0..10));
+ baz((0..10), (), ('a'..='z'))
+ }
}
+
+fn foo(_: impl IntoIterator<Item = usize>) {}
+fn bar<I: IntoIterator<Item = usize>>(_: Vec<usize>, _: I) {}
+fn baz<I: IntoIterator<Item = usize>>(_: I, _: (), _: impl IntoIterator<Item = char>) {}
diff --git a/src/tools/clippy/tests/ui/needless_collect.rs b/src/tools/clippy/tests/ui/needless_collect.rs
index 535ec8298..680b6fa5b 100644
--- a/src/tools/clippy/tests/ui/needless_collect.rs
+++ b/src/tools/clippy/tests/ui/needless_collect.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::suspicious_map, clippy::iter_count)]
@@ -62,4 +62,16 @@ fn main() {
let _ = sample.iter().collect::<VecWrapper<_>>().is_empty();
let _ = sample.iter().collect::<VecWrapper<_>>().contains(&&0);
+
+ #[allow(clippy::double_parens)]
+ {
+ Vec::<u8>::new().extend((0..10).collect::<Vec<_>>());
+ foo((0..10).collect::<Vec<_>>());
+ bar((0..10).collect::<Vec<_>>(), (0..10).collect::<Vec<_>>());
+ baz((0..10), (), ('a'..='z').collect::<Vec<_>>())
+ }
}
+
+fn foo(_: impl IntoIterator<Item = usize>) {}
+fn bar<I: IntoIterator<Item = usize>>(_: Vec<usize>, _: I) {}
+fn baz<I: IntoIterator<Item = usize>>(_: I, _: (), _: impl IntoIterator<Item = char>) {}
diff --git a/src/tools/clippy/tests/ui/needless_collect.stderr b/src/tools/clippy/tests/ui/needless_collect.stderr
index 584d2a1d8..ad22a7b05 100644
--- a/src/tools/clippy/tests/ui/needless_collect.stderr
+++ b/src/tools/clippy/tests/ui/needless_collect.stderr
@@ -90,5 +90,29 @@ error: avoid using `collect()` when not needed
LL | let _ = sample.iter().collect::<VecWrapper<_>>().contains(&&0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &0)`
-error: aborting due to 15 previous errors
+error: avoid using `collect()` when not needed
+ --> $DIR/needless_collect.rs:68:40
+ |
+LL | Vec::<u8>::new().extend((0..10).collect::<Vec<_>>());
+ | ^^^^^^^^^^^^^^^^^^^^ help: remove this call
+
+error: avoid using `collect()` when not needed
+ --> $DIR/needless_collect.rs:69:20
+ |
+LL | foo((0..10).collect::<Vec<_>>());
+ | ^^^^^^^^^^^^^^^^^^^^ help: remove this call
+
+error: avoid using `collect()` when not needed
+ --> $DIR/needless_collect.rs:70:49
+ |
+LL | bar((0..10).collect::<Vec<_>>(), (0..10).collect::<Vec<_>>());
+ | ^^^^^^^^^^^^^^^^^^^^ help: remove this call
+
+error: avoid using `collect()` when not needed
+ --> $DIR/needless_collect.rs:71:37
+ |
+LL | baz((0..10), (), ('a'..='z').collect::<Vec<_>>())
+ | ^^^^^^^^^^^^^^^^^^^^ help: remove this call
+
+error: aborting due to 19 previous errors
diff --git a/src/tools/clippy/tests/ui/needless_for_each_fixable.fixed b/src/tools/clippy/tests/ui/needless_for_each_fixable.fixed
index 09e671b88..92572942b 100644
--- a/src/tools/clippy/tests/ui/needless_for_each_fixable.fixed
+++ b/src/tools/clippy/tests/ui/needless_for_each_fixable.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::needless_for_each)]
#![allow(unused)]
#![allow(
@@ -110,7 +110,7 @@ fn should_not_lint() {
}),
}
- // `for_each` is in a let bingind.
+ // `for_each` is in a let binding.
let _ = v.iter().for_each(|elem| {
acc += elem;
});
diff --git a/src/tools/clippy/tests/ui/needless_for_each_fixable.rs b/src/tools/clippy/tests/ui/needless_for_each_fixable.rs
index abb4045b9..95acbdff8 100644
--- a/src/tools/clippy/tests/ui/needless_for_each_fixable.rs
+++ b/src/tools/clippy/tests/ui/needless_for_each_fixable.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::needless_for_each)]
#![allow(unused)]
#![allow(
@@ -110,7 +110,7 @@ fn should_not_lint() {
}),
}
- // `for_each` is in a let bingind.
+ // `for_each` is in a let binding.
let _ = v.iter().for_each(|elem| {
acc += elem;
});
diff --git a/src/tools/clippy/tests/ui/needless_late_init.fixed b/src/tools/clippy/tests/ui/needless_late_init.fixed
index 86d899bb4..92f7b3f77 100644
--- a/src/tools/clippy/tests/ui/needless_late_init.fixed
+++ b/src/tools/clippy/tests/ui/needless_late_init.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![feature(let_chains)]
#![allow(unused)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/needless_late_init.rs b/src/tools/clippy/tests/ui/needless_late_init.rs
index 969afb38e..be378c42f 100644
--- a/src/tools/clippy/tests/ui/needless_late_init.rs
+++ b/src/tools/clippy/tests/ui/needless_late_init.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![feature(let_chains)]
#![allow(unused)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/needless_lifetimes.fixed b/src/tools/clippy/tests/ui/needless_lifetimes.fixed
index e6ead69d1..7b99042f7 100644
--- a/src/tools/clippy/tests/ui/needless_lifetimes.fixed
+++ b/src/tools/clippy/tests/ui/needless_lifetimes.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![warn(clippy::needless_lifetimes)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/needless_lifetimes.rs b/src/tools/clippy/tests/ui/needless_lifetimes.rs
index 06eb43050..6fcf1efc2 100644
--- a/src/tools/clippy/tests/ui/needless_lifetimes.rs
+++ b/src/tools/clippy/tests/ui/needless_lifetimes.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![warn(clippy::needless_lifetimes)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/needless_match.fixed b/src/tools/clippy/tests/ui/needless_match.fixed
index 7e4740679..d8a0400a4 100644
--- a/src/tools/clippy/tests/ui/needless_match.fixed
+++ b/src/tools/clippy/tests/ui/needless_match.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::needless_match)]
#![allow(clippy::manual_map)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/needless_match.rs b/src/tools/clippy/tests/ui/needless_match.rs
index 809c694bf..3de9bd6d7 100644
--- a/src/tools/clippy/tests/ui/needless_match.rs
+++ b/src/tools/clippy/tests/ui/needless_match.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::needless_match)]
#![allow(clippy::manual_map)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/needless_option_as_deref.fixed b/src/tools/clippy/tests/ui/needless_option_as_deref.fixed
index acd22c6bb..70015fccf 100644
--- a/src/tools/clippy/tests/ui/needless_option_as_deref.fixed
+++ b/src/tools/clippy/tests/ui/needless_option_as_deref.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::needless_option_as_deref)]
diff --git a/src/tools/clippy/tests/ui/needless_option_as_deref.rs b/src/tools/clippy/tests/ui/needless_option_as_deref.rs
index 61eda5052..e2e35360c 100644
--- a/src/tools/clippy/tests/ui/needless_option_as_deref.rs
+++ b/src/tools/clippy/tests/ui/needless_option_as_deref.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::needless_option_as_deref)]
diff --git a/src/tools/clippy/tests/ui/needless_option_take.fixed b/src/tools/clippy/tests/ui/needless_option_take.fixed
index 29691e816..bfc6d20d5 100644
--- a/src/tools/clippy/tests/ui/needless_option_take.fixed
+++ b/src/tools/clippy/tests/ui/needless_option_take.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
fn main() {
println!("Testing non erroneous option_take_on_temporary");
diff --git a/src/tools/clippy/tests/ui/needless_option_take.rs b/src/tools/clippy/tests/ui/needless_option_take.rs
index 9f4109eb4..697eeab42 100644
--- a/src/tools/clippy/tests/ui/needless_option_take.rs
+++ b/src/tools/clippy/tests/ui/needless_option_take.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
fn main() {
println!("Testing non erroneous option_take_on_temporary");
diff --git a/src/tools/clippy/tests/ui/needless_parens_on_range_literals.fixed b/src/tools/clippy/tests/ui/needless_parens_on_range_literals.fixed
index f11330a89..9b98f6ea7 100644
--- a/src/tools/clippy/tests/ui/needless_parens_on_range_literals.fixed
+++ b/src/tools/clippy/tests/ui/needless_parens_on_range_literals.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// edition:2018
+//@run-rustfix
+//@edition:2018
#![warn(clippy::needless_parens_on_range_literals)]
#![allow(clippy::almost_complete_range)]
diff --git a/src/tools/clippy/tests/ui/needless_parens_on_range_literals.rs b/src/tools/clippy/tests/ui/needless_parens_on_range_literals.rs
index 671c0009e..088e7b2b9 100644
--- a/src/tools/clippy/tests/ui/needless_parens_on_range_literals.rs
+++ b/src/tools/clippy/tests/ui/needless_parens_on_range_literals.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// edition:2018
+//@run-rustfix
+//@edition:2018
#![warn(clippy::needless_parens_on_range_literals)]
#![allow(clippy::almost_complete_range)]
diff --git a/src/tools/clippy/tests/ui/needless_question_mark.fixed b/src/tools/clippy/tests/ui/needless_question_mark.fixed
index 7eaca5719..679b73d40 100644
--- a/src/tools/clippy/tests/ui/needless_question_mark.fixed
+++ b/src/tools/clippy/tests/ui/needless_question_mark.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::needless_question_mark)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/needless_question_mark.rs b/src/tools/clippy/tests/ui/needless_question_mark.rs
index 960bc7b78..a993d3ec3 100644
--- a/src/tools/clippy/tests/ui/needless_question_mark.rs
+++ b/src/tools/clippy/tests/ui/needless_question_mark.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::needless_question_mark)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/needless_return.fixed b/src/tools/clippy/tests/ui/needless_return.fixed
index 57c08996c..d49ae5d86 100644
--- a/src/tools/clippy/tests/ui/needless_return.fixed
+++ b/src/tools/clippy/tests/ui/needless_return.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(lint_reasons)]
#![feature(yeet_expr)]
@@ -231,8 +231,9 @@ fn needless_return_macro() -> String {
}
fn issue_9361() -> i32 {
- #[allow(clippy::integer_arithmetic)]
- return 1 + 2;
+ let n = 1;
+ #[allow(clippy::arithmetic_side_effects)]
+ return n + n;
}
fn issue8336(x: i32) -> bool {
diff --git a/src/tools/clippy/tests/ui/needless_return.rs b/src/tools/clippy/tests/ui/needless_return.rs
index 7c1feefbe..367638261 100644
--- a/src/tools/clippy/tests/ui/needless_return.rs
+++ b/src/tools/clippy/tests/ui/needless_return.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(lint_reasons)]
#![feature(yeet_expr)]
@@ -239,8 +239,9 @@ fn needless_return_macro() -> String {
}
fn issue_9361() -> i32 {
- #[allow(clippy::integer_arithmetic)]
- return 1 + 2;
+ let n = 1;
+ #[allow(clippy::arithmetic_side_effects)]
+ return n + n;
}
fn issue8336(x: i32) -> bool {
diff --git a/src/tools/clippy/tests/ui/needless_return.stderr b/src/tools/clippy/tests/ui/needless_return.stderr
index 87d0cd3e1..05f6038cd 100644
--- a/src/tools/clippy/tests/ui/needless_return.stderr
+++ b/src/tools/clippy/tests/ui/needless_return.stderr
@@ -328,7 +328,7 @@ LL | return format!("Hello {}", "world!");
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:249:9
+ --> $DIR/needless_return.rs:250:9
|
LL | return true;
| ^^^^^^^^^^^
@@ -336,7 +336,7 @@ LL | return true;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:251:9
+ --> $DIR/needless_return.rs:252:9
|
LL | return false;
| ^^^^^^^^^^^^
@@ -344,7 +344,7 @@ LL | return false;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:258:13
+ --> $DIR/needless_return.rs:259:13
|
LL | return 10;
| ^^^^^^^^^
@@ -352,7 +352,7 @@ LL | return 10;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:261:13
+ --> $DIR/needless_return.rs:262:13
|
LL | return 100;
| ^^^^^^^^^^
@@ -360,7 +360,7 @@ LL | return 100;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:269:9
+ --> $DIR/needless_return.rs:270:9
|
LL | return 0;
| ^^^^^^^^
@@ -368,7 +368,7 @@ LL | return 0;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:276:13
+ --> $DIR/needless_return.rs:277:13
|
LL | return *(x as *const isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -376,7 +376,7 @@ LL | return *(x as *const isize);
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:278:13
+ --> $DIR/needless_return.rs:279:13
|
LL | return !*(x as *const isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -384,7 +384,7 @@ LL | return !*(x as *const isize);
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:285:20
+ --> $DIR/needless_return.rs:286:20
|
LL | let _ = 42;
| ____________________^
@@ -395,7 +395,7 @@ LL | | return;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:292:20
+ --> $DIR/needless_return.rs:293:20
|
LL | let _ = 42; return;
| ^^^^^^^
@@ -403,7 +403,7 @@ LL | let _ = 42; return;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:304:9
+ --> $DIR/needless_return.rs:305:9
|
LL | return Ok(format!("ok!"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -411,7 +411,7 @@ LL | return Ok(format!("ok!"));
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:306:9
+ --> $DIR/needless_return.rs:307:9
|
LL | return Err(format!("err!"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -419,7 +419,7 @@ LL | return Err(format!("err!"));
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:312:9
+ --> $DIR/needless_return.rs:313:9
|
LL | return if true { 1 } else { 2 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -427,7 +427,7 @@ LL | return if true { 1 } else { 2 };
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:316:9
+ --> $DIR/needless_return.rs:317:9
|
LL | return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/needless_splitn.fixed b/src/tools/clippy/tests/ui/needless_splitn.fixed
index 5496031fe..30a038312 100644
--- a/src/tools/clippy/tests/ui/needless_splitn.fixed
+++ b/src/tools/clippy/tests/ui/needless_splitn.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// edition:2018
+//@run-rustfix
+//@edition:2018
#![warn(clippy::needless_splitn)]
#![allow(clippy::iter_skip_next, clippy::iter_nth_zero, clippy::manual_split_once)]
diff --git a/src/tools/clippy/tests/ui/needless_splitn.rs b/src/tools/clippy/tests/ui/needless_splitn.rs
index 35c2465ba..1b0b9a598 100644
--- a/src/tools/clippy/tests/ui/needless_splitn.rs
+++ b/src/tools/clippy/tests/ui/needless_splitn.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// edition:2018
+//@run-rustfix
+//@edition:2018
#![warn(clippy::needless_splitn)]
#![allow(clippy::iter_skip_next, clippy::iter_nth_zero, clippy::manual_split_once)]
diff --git a/src/tools/clippy/tests/ui/neg_multiply.fixed b/src/tools/clippy/tests/ui/neg_multiply.fixed
index 58ab9e856..e07e7c88d 100644
--- a/src/tools/clippy/tests/ui/neg_multiply.fixed
+++ b/src/tools/clippy/tests/ui/neg_multiply.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::neg_multiply)]
#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::precedence)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/neg_multiply.rs b/src/tools/clippy/tests/ui/neg_multiply.rs
index 581290dc7..2887af7b4 100644
--- a/src/tools/clippy/tests/ui/neg_multiply.rs
+++ b/src/tools/clippy/tests/ui/neg_multiply.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::neg_multiply)]
#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::precedence)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/no_mangle_with_rust_abi.rs b/src/tools/clippy/tests/ui/no_mangle_with_rust_abi.rs
index b32e72111..818119f7b 100644
--- a/src/tools/clippy/tests/ui/no_mangle_with_rust_abi.rs
+++ b/src/tools/clippy/tests/ui/no_mangle_with_rust_abi.rs
@@ -25,7 +25,7 @@ fn rust_abi_multiline_function_really_long_name_to_overflow_args_to_multiple_lin
0
}
-// Must not run on functions that explicitly opt in to Rust ABI with `extern "Rust"`
+// Must not run on functions that explicitly opt in to using the Rust ABI with `extern "Rust"`
#[no_mangle]
#[rustfmt::skip]
extern "Rust" fn rust_abi_fn_explicit_opt_in(arg_one: u32, arg_two: usize) {}
diff --git a/src/tools/clippy/tests/ui/non_minimal_cfg.fixed b/src/tools/clippy/tests/ui/non_minimal_cfg.fixed
new file mode 100644
index 000000000..430caafb3
--- /dev/null
+++ b/src/tools/clippy/tests/ui/non_minimal_cfg.fixed
@@ -0,0 +1,17 @@
+//@run-rustfix
+
+#![allow(unused)]
+
+#[cfg(windows)]
+fn hermit() {}
+
+#[cfg(windows)]
+fn wasi() {}
+
+#[cfg(all(unix, not(windows)))]
+fn the_end() {}
+
+#[cfg(any())]
+fn any() {}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/non_minimal_cfg.rs b/src/tools/clippy/tests/ui/non_minimal_cfg.rs
new file mode 100644
index 000000000..a38ce1c21
--- /dev/null
+++ b/src/tools/clippy/tests/ui/non_minimal_cfg.rs
@@ -0,0 +1,17 @@
+//@run-rustfix
+
+#![allow(unused)]
+
+#[cfg(all(windows))]
+fn hermit() {}
+
+#[cfg(any(windows))]
+fn wasi() {}
+
+#[cfg(all(any(unix), all(not(windows))))]
+fn the_end() {}
+
+#[cfg(any())]
+fn any() {}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/non_minimal_cfg.stderr b/src/tools/clippy/tests/ui/non_minimal_cfg.stderr
new file mode 100644
index 000000000..cdfd728aa
--- /dev/null
+++ b/src/tools/clippy/tests/ui/non_minimal_cfg.stderr
@@ -0,0 +1,28 @@
+error: unneeded sub `cfg` when there is only one condition
+ --> $DIR/non_minimal_cfg.rs:5:7
+ |
+LL | #[cfg(all(windows))]
+ | ^^^^^^^^^^^^ help: try: `windows`
+ |
+ = note: `-D clippy::non-minimal-cfg` implied by `-D warnings`
+
+error: unneeded sub `cfg` when there is only one condition
+ --> $DIR/non_minimal_cfg.rs:8:7
+ |
+LL | #[cfg(any(windows))]
+ | ^^^^^^^^^^^^ help: try: `windows`
+
+error: unneeded sub `cfg` when there is only one condition
+ --> $DIR/non_minimal_cfg.rs:11:11
+ |
+LL | #[cfg(all(any(unix), all(not(windows))))]
+ | ^^^^^^^^^ help: try: `unix`
+
+error: unneeded sub `cfg` when there is only one condition
+ --> $DIR/non_minimal_cfg.rs:11:22
+ |
+LL | #[cfg(all(any(unix), all(not(windows))))]
+ | ^^^^^^^^^^^^^^^^^ help: try: `not(windows)`
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui/non_minimal_cfg2.rs b/src/tools/clippy/tests/ui/non_minimal_cfg2.rs
new file mode 100644
index 000000000..a4c6abce3
--- /dev/null
+++ b/src/tools/clippy/tests/ui/non_minimal_cfg2.rs
@@ -0,0 +1,6 @@
+#![allow(unused)]
+
+#[cfg(all())]
+fn all() {}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/non_minimal_cfg2.stderr b/src/tools/clippy/tests/ui/non_minimal_cfg2.stderr
new file mode 100644
index 000000000..2a9a36fbc
--- /dev/null
+++ b/src/tools/clippy/tests/ui/non_minimal_cfg2.stderr
@@ -0,0 +1,10 @@
+error: unneeded sub `cfg` when there is no condition
+ --> $DIR/non_minimal_cfg2.rs:3:7
+ |
+LL | #[cfg(all())]
+ | ^^^^^
+ |
+ = note: `-D clippy::non-minimal-cfg` implied by `-D warnings`
+
+error: aborting due to previous error
+
diff --git a/src/tools/clippy/tests/ui/non_octal_unix_permissions.fixed b/src/tools/clippy/tests/ui/non_octal_unix_permissions.fixed
index a9b2dcfb0..89d127528 100644
--- a/src/tools/clippy/tests/ui/non_octal_unix_permissions.fixed
+++ b/src/tools/clippy/tests/ui/non_octal_unix_permissions.fixed
@@ -1,5 +1,5 @@
-// ignore-windows
-// run-rustfix
+//@ignore-windows
+//@run-rustfix
#![warn(clippy::non_octal_unix_permissions)]
use std::fs::{DirBuilder, File, OpenOptions, Permissions};
use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt, PermissionsExt};
diff --git a/src/tools/clippy/tests/ui/non_octal_unix_permissions.rs b/src/tools/clippy/tests/ui/non_octal_unix_permissions.rs
index 7d2922f49..1b3a322d7 100644
--- a/src/tools/clippy/tests/ui/non_octal_unix_permissions.rs
+++ b/src/tools/clippy/tests/ui/non_octal_unix_permissions.rs
@@ -1,5 +1,5 @@
-// ignore-windows
-// run-rustfix
+//@ignore-windows
+//@run-rustfix
#![warn(clippy::non_octal_unix_permissions)]
use std::fs::{DirBuilder, File, OpenOptions, Permissions};
use std::os::unix::fs::{DirBuilderExt, OpenOptionsExt, PermissionsExt};
diff --git a/src/tools/clippy/tests/ui/nonminimal_bool_methods.fixed b/src/tools/clippy/tests/ui/nonminimal_bool_methods.fixed
index aad44089d..05802a2c8 100644
--- a/src/tools/clippy/tests/ui/nonminimal_bool_methods.fixed
+++ b/src/tools/clippy/tests/ui/nonminimal_bool_methods.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::diverging_sub_expression)]
#![warn(clippy::nonminimal_bool)]
diff --git a/src/tools/clippy/tests/ui/nonminimal_bool_methods.rs b/src/tools/clippy/tests/ui/nonminimal_bool_methods.rs
index b9074da84..cd5b576fa 100644
--- a/src/tools/clippy/tests/ui/nonminimal_bool_methods.rs
+++ b/src/tools/clippy/tests/ui/nonminimal_bool_methods.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::diverging_sub_expression)]
#![warn(clippy::nonminimal_bool)]
diff --git a/src/tools/clippy/tests/ui/numbered_fields.fixed b/src/tools/clippy/tests/ui/numbered_fields.fixed
index 68c987eb4..a52845e53 100644
--- a/src/tools/clippy/tests/ui/numbered_fields.fixed
+++ b/src/tools/clippy/tests/ui/numbered_fields.fixed
@@ -1,4 +1,4 @@
-//run-rustfix
+//@run-rustfix
#![warn(clippy::init_numbered_fields)]
#![allow(unused_tuple_struct_fields)]
diff --git a/src/tools/clippy/tests/ui/numbered_fields.rs b/src/tools/clippy/tests/ui/numbered_fields.rs
index 2ef4fb4de..ca93f7dce 100644
--- a/src/tools/clippy/tests/ui/numbered_fields.rs
+++ b/src/tools/clippy/tests/ui/numbered_fields.rs
@@ -1,4 +1,4 @@
-//run-rustfix
+//@run-rustfix
#![warn(clippy::init_numbered_fields)]
#![allow(unused_tuple_struct_fields)]
diff --git a/src/tools/clippy/tests/ui/obfuscated_if_else.fixed b/src/tools/clippy/tests/ui/obfuscated_if_else.fixed
index 62d932c2c..9e4f97253 100644
--- a/src/tools/clippy/tests/ui/obfuscated_if_else.fixed
+++ b/src/tools/clippy/tests/ui/obfuscated_if_else.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::obfuscated_if_else)]
diff --git a/src/tools/clippy/tests/ui/obfuscated_if_else.rs b/src/tools/clippy/tests/ui/obfuscated_if_else.rs
index 273be9092..c2351d64c 100644
--- a/src/tools/clippy/tests/ui/obfuscated_if_else.rs
+++ b/src/tools/clippy/tests/ui/obfuscated_if_else.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::obfuscated_if_else)]
diff --git a/src/tools/clippy/tests/ui/octal_escapes.rs b/src/tools/clippy/tests/ui/octal_escapes.rs
index 53145ef0f..61ea96604 100644
--- a/src/tools/clippy/tests/ui/octal_escapes.rs
+++ b/src/tools/clippy/tests/ui/octal_escapes.rs
@@ -17,4 +17,5 @@ fn main() {
let _good3 = "\0\0";
let _good4 = "X\0\0X";
let _good5 = "锈\0锈";
+ let _good6 = "\0\\01";
}
diff --git a/src/tools/clippy/tests/ui/octal_escapes.stderr b/src/tools/clippy/tests/ui/octal_escapes.stderr
index 295dc1798..aa362e963 100644
--- a/src/tools/clippy/tests/ui/octal_escapes.stderr
+++ b/src/tools/clippy/tests/ui/octal_escapes.stderr
@@ -64,6 +64,22 @@ LL | let _bad4 = "/x001234567";
| ~~~~~~~~~~~~~
error: octal-looking escape in string literal
+ --> $DIR/octal_escapes.rs:9:17
+ |
+LL | let _bad5 = "/0/03";
+ | ^^^^^^^
+ |
+ = help: octal escapes are not supported, `/0` is always a null character
+help: if an octal escape was intended, use the hexadecimal representation instead
+ |
+LL | let _bad5 = "/0/x03";
+ | ~~~~~~~~
+help: if the null character is intended, disambiguate using
+ |
+LL | let _bad5 = "/0/x003";
+ | ~~~~~~~~~
+
+error: octal-looking escape in string literal
--> $DIR/octal_escapes.rs:10:17
|
LL | let _bad6 = "Text-/055/077-MoreText";
@@ -127,5 +143,5 @@ help: if the null character is intended, disambiguate using
LL | let _bad9 = "锈/x0011锈";
| ~~~~~~~~~~~~
-error: aborting due to 8 previous errors
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/option_as_ref_deref.fixed b/src/tools/clippy/tests/ui/option_as_ref_deref.fixed
index d124d133f..e1c0fa3f7 100644
--- a/src/tools/clippy/tests/ui/option_as_ref_deref.fixed
+++ b/src/tools/clippy/tests/ui/option_as_ref_deref.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::redundant_clone)]
#![warn(clippy::option_as_ref_deref)]
diff --git a/src/tools/clippy/tests/ui/option_as_ref_deref.rs b/src/tools/clippy/tests/ui/option_as_ref_deref.rs
index 86e354c67..6f4917fd1 100644
--- a/src/tools/clippy/tests/ui/option_as_ref_deref.rs
+++ b/src/tools/clippy/tests/ui/option_as_ref_deref.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::redundant_clone)]
#![warn(clippy::option_as_ref_deref)]
diff --git a/src/tools/clippy/tests/ui/option_env_unwrap.rs b/src/tools/clippy/tests/ui/option_env_unwrap.rs
index 9a56cf40d..ee1fe3f1f 100644
--- a/src/tools/clippy/tests/ui/option_env_unwrap.rs
+++ b/src/tools/clippy/tests/ui/option_env_unwrap.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs
#![warn(clippy::option_env_unwrap)]
#![allow(clippy::map_flatten)]
diff --git a/src/tools/clippy/tests/ui/option_filter_map.fixed b/src/tools/clippy/tests/ui/option_filter_map.fixed
index b20f73f31..93c250cfa 100644
--- a/src/tools/clippy/tests/ui/option_filter_map.fixed
+++ b/src/tools/clippy/tests/ui/option_filter_map.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::option_filter_map)]
#![allow(clippy::map_flatten)]
diff --git a/src/tools/clippy/tests/ui/option_filter_map.rs b/src/tools/clippy/tests/ui/option_filter_map.rs
index 7abaaa0fb..2c5f03250 100644
--- a/src/tools/clippy/tests/ui/option_filter_map.rs
+++ b/src/tools/clippy/tests/ui/option_filter_map.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::option_filter_map)]
#![allow(clippy::map_flatten)]
diff --git a/src/tools/clippy/tests/ui/option_if_let_else.fixed b/src/tools/clippy/tests/ui/option_if_let_else.fixed
index 0456005dc..2b8ce5477 100644
--- a/src/tools/clippy/tests/ui/option_if_let_else.fixed
+++ b/src/tools/clippy/tests/ui/option_if_let_else.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::option_if_let_else)]
#![allow(
unused_tuple_struct_fields,
@@ -25,7 +25,7 @@ fn else_if_option(string: Option<&str>) -> Option<(bool, &str)> {
fn unop_bad(string: &Option<&str>, mut num: Option<i32>) {
let _ = string.map_or(0, |s| s.len());
let _ = num.as_ref().map_or(&0, |s| s);
- let _ = num.as_mut().map_or(&mut 0, |s| {
+ let _ = num.as_mut().map_or(&0, |s| {
*s += 1;
s
});
@@ -34,7 +34,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option<i32>) {
s += 1;
s
});
- let _ = num.as_mut().map_or(&mut 0, |s| {
+ let _ = num.as_mut().map_or(&0, |s| {
*s += 1;
s
});
@@ -92,12 +92,21 @@ fn pattern_to_vec(pattern: &str) -> Vec<String> {
.collect::<Vec<_>>()
}
+// #10335
+fn test_result_impure_else(variable: Result<u32, &str>) {
+ variable.map_or_else(|_| {
+ println!("Err");
+ }, |binding| {
+ println!("Ok {binding}");
+ })
+}
+
enum DummyEnum {
One(u8),
Two,
}
-// should not warn since there is a compled complex subpat
+// should not warn since there is a complex subpat
// see #7991
fn complex_subpat() -> DummyEnum {
let x = Some(DummyEnum::One(1));
@@ -113,6 +122,7 @@ fn main() {
unop_bad(&None, None);
let _ = longer_body(None);
test_map_or_else(None);
+ test_result_impure_else(Ok(42));
let _ = negative_tests(None);
let _ = impure_else(None);
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 23b148752..cfbec8cb2 100644
--- a/src/tools/clippy/tests/ui/option_if_let_else.rs
+++ b/src/tools/clippy/tests/ui/option_if_let_else.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::option_if_let_else)]
#![allow(
unused_tuple_struct_fields,
@@ -33,7 +33,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option<i32>) {
*s += 1;
s
} else {
- &mut 0
+ &0
};
let _ = if let Some(ref s) = num { s } else { &0 };
let _ = if let Some(mut s) = num {
@@ -46,7 +46,7 @@ fn unop_bad(string: &Option<&str>, mut num: Option<i32>) {
*s += 1;
s
} else {
- &mut 0
+ &0
};
}
@@ -115,12 +115,21 @@ fn pattern_to_vec(pattern: &str) -> Vec<String> {
.collect::<Vec<_>>()
}
+// #10335
+fn test_result_impure_else(variable: Result<u32, &str>) {
+ if let Ok(binding) = variable {
+ println!("Ok {binding}");
+ } else {
+ println!("Err");
+ }
+}
+
enum DummyEnum {
One(u8),
Two,
}
-// should not warn since there is a compled complex subpat
+// should not warn since there is a complex subpat
// see #7991
fn complex_subpat() -> DummyEnum {
let x = Some(DummyEnum::One(1));
@@ -136,6 +145,7 @@ fn main() {
unop_bad(&None, None);
let _ = longer_body(None);
test_map_or_else(None);
+ test_result_impure_else(Ok(42));
let _ = negative_tests(None);
let _ = impure_else(None);
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 a5dbf6e1f..91d52fc79 100644
--- a/src/tools/clippy/tests/ui/option_if_let_else.stderr
+++ b/src/tools/clippy/tests/ui/option_if_let_else.stderr
@@ -30,13 +30,13 @@ LL | let _ = if let Some(s) = &mut num {
LL | | *s += 1;
LL | | s
LL | | } else {
-LL | | &mut 0
+LL | | &0
LL | | };
| |_____^
|
help: try
|
-LL ~ let _ = num.as_mut().map_or(&mut 0, |s| {
+LL ~ let _ = num.as_mut().map_or(&0, |s| {
LL + *s += 1;
LL + s
LL ~ });
@@ -76,13 +76,13 @@ LL | let _ = if let Some(ref mut s) = num {
LL | | *s += 1;
LL | | s
LL | | } else {
-LL | | &mut 0
+LL | | &0
LL | | };
| |_____^
|
help: try
|
-LL ~ let _ = num.as_mut().map_or(&mut 0, |s| {
+LL ~ let _ = num.as_mut().map_or(&0, |s| {
LL + *s += 1;
LL + s
LL ~ });
@@ -152,14 +152,33 @@ LL | | vec![s.to_string()]
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
+ |
+LL | / if let Ok(binding) = variable {
+LL | | println!("Ok {binding}");
+LL | | } else {
+LL | | println!("Err");
+LL | | }
+ | |_____^
+ |
+help: try
+ |
+LL ~ variable.map_or_else(|_| {
+LL + println!("Err");
+LL + }, |binding| {
+LL + println!("Ok {binding}");
+LL + })
+ |
+
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:133:13
+ --> $DIR/option_if_let_else.rs:142:13
|
LL | let _ = if let Some(x) = optional { x + 2 } else { 5 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)`
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:142:13
+ --> $DIR/option_if_let_else.rs:152:13
|
LL | let _ = if let Some(x) = Some(0) {
| _____________^
@@ -181,13 +200,13 @@ LL ~ });
|
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:170:13
+ --> $DIR/option_if_let_else.rs:180:13
|
LL | let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(0).map_or(s.len(), |x| s.len() + x)`
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:174:13
+ --> $DIR/option_if_let_else.rs:184:13
|
LL | let _ = if let Some(x) = Some(0) {
| _____________^
@@ -207,7 +226,7 @@ LL ~ });
|
error: use Option::map_or instead of an if let/else
- --> $DIR/option_if_let_else.rs:213:13
+ --> $DIR/option_if_let_else.rs:223:13
|
LL | let _ = match s {
| _____________^
@@ -217,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:217:13
+ --> $DIR/option_if_let_else.rs:227:13
|
LL | let _ = match Some(10) {
| _____________^
@@ -227,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:223:13
+ --> $DIR/option_if_let_else.rs:233:13
|
LL | let _ = match res {
| _____________^
@@ -237,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:227:13
+ --> $DIR/option_if_let_else.rs:237:13
|
LL | let _ = match res {
| _____________^
@@ -247,10 +266,10 @@ 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:231:13
+ --> $DIR/option_if_let_else.rs:241:13
|
LL | let _ = if let Ok(a) = res { a + 1 } else { 5 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or(5, |a| a + 1)`
-error: aborting due to 20 previous errors
+error: aborting due to 21 previous errors
diff --git a/src/tools/clippy/tests/ui/option_map_or_none.fixed b/src/tools/clippy/tests/ui/option_map_or_none.fixed
index 04bfac773..501757647 100644
--- a/src/tools/clippy/tests/ui/option_map_or_none.fixed
+++ b/src/tools/clippy/tests/ui/option_map_or_none.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::bind_instead_of_map)]
diff --git a/src/tools/clippy/tests/ui/option_map_or_none.rs b/src/tools/clippy/tests/ui/option_map_or_none.rs
index bb84f8a48..4d8704e73 100644
--- a/src/tools/clippy/tests/ui/option_map_or_none.rs
+++ b/src/tools/clippy/tests/ui/option_map_or_none.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::bind_instead_of_map)]
diff --git a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.fixed b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.fixed
index 00264dcce..8f64451ed 100644
--- a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.fixed
+++ b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::option_map_unit_fn)]
#![allow(unused)]
#![allow(clippy::uninlined_format_args, clippy::unnecessary_wraps)]
diff --git a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.rs b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.rs
index f3363ebce..2bf7a8e0f 100644
--- a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.rs
+++ b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::option_map_unit_fn)]
#![allow(unused)]
#![allow(clippy::uninlined_format_args, clippy::unnecessary_wraps)]
diff --git a/src/tools/clippy/tests/ui/or_fun_call.fixed b/src/tools/clippy/tests/ui/or_fun_call.fixed
index be9a65506..f723a55f7 100644
--- a/src/tools/clippy/tests/ui/or_fun_call.fixed
+++ b/src/tools/clippy/tests/ui/or_fun_call.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::or_fun_call)]
#![allow(dead_code)]
#![allow(clippy::borrow_as_ptr, clippy::uninlined_format_args, clippy::unnecessary_wraps)]
diff --git a/src/tools/clippy/tests/ui/or_fun_call.rs b/src/tools/clippy/tests/ui/or_fun_call.rs
index 628c97046..61ef6e27f 100644
--- a/src/tools/clippy/tests/ui/or_fun_call.rs
+++ b/src/tools/clippy/tests/ui/or_fun_call.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::or_fun_call)]
#![allow(dead_code)]
#![allow(clippy::borrow_as_ptr, clippy::uninlined_format_args, clippy::unnecessary_wraps)]
diff --git a/src/tools/clippy/tests/ui/or_then_unwrap.fixed b/src/tools/clippy/tests/ui/or_then_unwrap.fixed
index 844cc4b7a..40badac44 100644
--- a/src/tools/clippy/tests/ui/or_then_unwrap.fixed
+++ b/src/tools/clippy/tests/ui/or_then_unwrap.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::or_then_unwrap)]
#![allow(clippy::map_identity, clippy::let_unit_value)]
diff --git a/src/tools/clippy/tests/ui/or_then_unwrap.rs b/src/tools/clippy/tests/ui/or_then_unwrap.rs
index 1528ef9be..76c9942fe 100644
--- a/src/tools/clippy/tests/ui/or_then_unwrap.rs
+++ b/src/tools/clippy/tests/ui/or_then_unwrap.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::or_then_unwrap)]
#![allow(clippy::map_identity, clippy::let_unit_value)]
diff --git a/src/tools/clippy/tests/ui/partialeq_to_none.fixed b/src/tools/clippy/tests/ui/partialeq_to_none.fixed
index 4644ea8f5..2df87a26d 100644
--- a/src/tools/clippy/tests/ui/partialeq_to_none.fixed
+++ b/src/tools/clippy/tests/ui/partialeq_to_none.fixed
@@ -1,5 +1,6 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::partialeq_to_none)]
+#![allow(clippy::eq_op)]
struct Foobar;
diff --git a/src/tools/clippy/tests/ui/partialeq_to_none.rs b/src/tools/clippy/tests/ui/partialeq_to_none.rs
index 61011b3a8..df6233b9a 100644
--- a/src/tools/clippy/tests/ui/partialeq_to_none.rs
+++ b/src/tools/clippy/tests/ui/partialeq_to_none.rs
@@ -1,5 +1,6 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::partialeq_to_none)]
+#![allow(clippy::eq_op)]
struct Foobar;
diff --git a/src/tools/clippy/tests/ui/partialeq_to_none.stderr b/src/tools/clippy/tests/ui/partialeq_to_none.stderr
index d06ab7aee..4f84862a2 100644
--- a/src/tools/clippy/tests/ui/partialeq_to_none.stderr
+++ b/src/tools/clippy/tests/ui/partialeq_to_none.stderr
@@ -1,5 +1,5 @@
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:14:8
+ --> $DIR/partialeq_to_none.rs:15:8
|
LL | if f != None { "yay" } else { "nay" }
| ^^^^^^^^^ help: use `Option::is_some()` instead: `f.is_some()`
@@ -7,55 +7,55 @@ LL | if f != None { "yay" } else { "nay" }
= note: `-D clippy::partialeq-to-none` implied by `-D warnings`
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:44:13
+ --> $DIR/partialeq_to_none.rs:45:13
|
LL | let _ = x == None;
| ^^^^^^^^^ help: use `Option::is_none()` instead: `x.is_none()`
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:45:13
+ --> $DIR/partialeq_to_none.rs:46:13
|
LL | let _ = x != None;
| ^^^^^^^^^ help: use `Option::is_some()` instead: `x.is_some()`
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:46:13
+ --> $DIR/partialeq_to_none.rs:47:13
|
LL | let _ = None == x;
| ^^^^^^^^^ help: use `Option::is_none()` instead: `x.is_none()`
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:47:13
+ --> $DIR/partialeq_to_none.rs:48:13
|
LL | let _ = None != x;
| ^^^^^^^^^ help: use `Option::is_some()` instead: `x.is_some()`
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:49:8
+ --> $DIR/partialeq_to_none.rs:50:8
|
LL | if foobar() == None {}
| ^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `foobar().is_none()`
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:51:8
+ --> $DIR/partialeq_to_none.rs:52:8
|
LL | if bar().ok() != None {}
| ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `bar().ok().is_some()`
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:53:13
+ --> $DIR/partialeq_to_none.rs:54:13
|
LL | let _ = Some(1 + 2) != None;
| ^^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `Some(1 + 2).is_some()`
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:55:13
+ --> $DIR/partialeq_to_none.rs:56:13
|
LL | let _ = { Some(0) } == None;
| ^^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `{ Some(0) }.is_none()`
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:57:13
+ --> $DIR/partialeq_to_none.rs:58:13
|
LL | let _ = {
| _____________^
@@ -77,31 +77,31 @@ LL ~ }.is_some();
|
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:67:13
+ --> $DIR/partialeq_to_none.rs:68:13
|
LL | let _ = optref() == &&None;
| ^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `optref().is_none()`
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:68:13
+ --> $DIR/partialeq_to_none.rs:69:13
|
LL | let _ = &&None != optref();
| ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `optref().is_some()`
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:69:13
+ --> $DIR/partialeq_to_none.rs:70:13
|
LL | let _ = **optref() == None;
| ^^^^^^^^^^^^^^^^^^ help: use `Option::is_none()` instead: `optref().is_none()`
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:70:13
+ --> $DIR/partialeq_to_none.rs:71:13
|
LL | let _ = &None != *optref();
| ^^^^^^^^^^^^^^^^^^ help: use `Option::is_some()` instead: `optref().is_some()`
error: binary comparison to literal `Option::None`
- --> $DIR/partialeq_to_none.rs:73:13
+ --> $DIR/partialeq_to_none.rs:74:13
|
LL | let _ = None != *x;
| ^^^^^^^^^^ help: use `Option::is_some()` instead: `(*x).is_some()`
diff --git a/src/tools/clippy/tests/ui/path_buf_push_overwrite.fixed b/src/tools/clippy/tests/ui/path_buf_push_overwrite.fixed
index ef8856830..393fc6e1c 100644
--- a/src/tools/clippy/tests/ui/path_buf_push_overwrite.fixed
+++ b/src/tools/clippy/tests/ui/path_buf_push_overwrite.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
use std::path::PathBuf;
#[warn(clippy::all, clippy::path_buf_push_overwrite)]
diff --git a/src/tools/clippy/tests/ui/path_buf_push_overwrite.rs b/src/tools/clippy/tests/ui/path_buf_push_overwrite.rs
index 6e2d483f4..18de6e064 100644
--- a/src/tools/clippy/tests/ui/path_buf_push_overwrite.rs
+++ b/src/tools/clippy/tests/ui/path_buf_push_overwrite.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
use std::path::PathBuf;
#[warn(clippy::all, clippy::path_buf_push_overwrite)]
diff --git a/src/tools/clippy/tests/ui/patterns.fixed b/src/tools/clippy/tests/ui/patterns.fixed
index cd6901432..a1da47d84 100644
--- a/src/tools/clippy/tests/ui/patterns.fixed
+++ b/src/tools/clippy/tests/ui/patterns.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all)]
#![allow(unused)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/patterns.rs b/src/tools/clippy/tests/ui/patterns.rs
index 9128da420..399066b81 100644
--- a/src/tools/clippy/tests/ui/patterns.rs
+++ b/src/tools/clippy/tests/ui/patterns.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all)]
#![allow(unused)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/precedence.fixed b/src/tools/clippy/tests/ui/precedence.fixed
index 163bd044c..af4d5636b 100644
--- a/src/tools/clippy/tests/ui/precedence.fixed
+++ b/src/tools/clippy/tests/ui/precedence.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::precedence)]
#![allow(unused_must_use, clippy::no_effect, clippy::unnecessary_operation)]
#![allow(clippy::identity_op)]
diff --git a/src/tools/clippy/tests/ui/precedence.rs b/src/tools/clippy/tests/ui/precedence.rs
index 8c849e320..e23ae9127 100644
--- a/src/tools/clippy/tests/ui/precedence.rs
+++ b/src/tools/clippy/tests/ui/precedence.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::precedence)]
#![allow(unused_must_use, clippy::no_effect, clippy::unnecessary_operation)]
#![allow(clippy::identity_op)]
diff --git a/src/tools/clippy/tests/ui/print_stdout_build_script.rs b/src/tools/clippy/tests/ui/print_stdout_build_script.rs
index 997ebef8a..91448cb0f 100644
--- a/src/tools/clippy/tests/ui/print_stdout_build_script.rs
+++ b/src/tools/clippy/tests/ui/print_stdout_build_script.rs
@@ -1,4 +1,4 @@
-// compile-flags: --crate-name=build_script_build
+//@compile-flags: --crate-name=build_script_build
#![warn(clippy::print_stdout)]
diff --git a/src/tools/clippy/tests/ui/print_with_newline.rs b/src/tools/clippy/tests/ui/print_with_newline.rs
index b8c29d207..ff79ca75f 100644
--- a/src/tools/clippy/tests/ui/print_with_newline.rs
+++ b/src/tools/clippy/tests/ui/print_with_newline.rs
@@ -1,5 +1,5 @@
// FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934
-// // run-rustfix
+//
#![allow(clippy::print_literal)]
#![warn(clippy::print_with_newline)]
diff --git a/src/tools/clippy/tests/ui/println_empty_string.fixed b/src/tools/clippy/tests/ui/println_empty_string.fixed
index 976068092..abf951ae2 100644
--- a/src/tools/clippy/tests/ui/println_empty_string.fixed
+++ b/src/tools/clippy/tests/ui/println_empty_string.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::match_single_binding)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/println_empty_string.rs b/src/tools/clippy/tests/ui/println_empty_string.rs
index 80fdb3e6e..fd86e2543 100644
--- a/src/tools/clippy/tests/ui/println_empty_string.rs
+++ b/src/tools/clippy/tests/ui/println_empty_string.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::match_single_binding)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/ptr_as_ptr.fixed b/src/tools/clippy/tests/ui/ptr_as_ptr.fixed
index ee7b998a0..2c2567d67 100644
--- a/src/tools/clippy/tests/ui/ptr_as_ptr.fixed
+++ b/src/tools/clippy/tests/ui/ptr_as_ptr.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![warn(clippy::ptr_as_ptr)]
diff --git a/src/tools/clippy/tests/ui/ptr_as_ptr.rs b/src/tools/clippy/tests/ui/ptr_as_ptr.rs
index c88329ce4..6000e5c08 100644
--- a/src/tools/clippy/tests/ui/ptr_as_ptr.rs
+++ b/src/tools/clippy/tests/ui/ptr_as_ptr.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![warn(clippy::ptr_as_ptr)]
diff --git a/src/tools/clippy/tests/ui/ptr_eq.fixed b/src/tools/clippy/tests/ui/ptr_eq.fixed
index 209081e6e..d5fa273d4 100644
--- a/src/tools/clippy/tests/ui/ptr_eq.fixed
+++ b/src/tools/clippy/tests/ui/ptr_eq.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::ptr_eq)]
macro_rules! mac {
diff --git a/src/tools/clippy/tests/ui/ptr_eq.rs b/src/tools/clippy/tests/ui/ptr_eq.rs
index 691628708..e033366a4 100644
--- a/src/tools/clippy/tests/ui/ptr_eq.rs
+++ b/src/tools/clippy/tests/ui/ptr_eq.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::ptr_eq)]
macro_rules! mac {
diff --git a/src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed b/src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed
index c57e2990f..f69bc1318 100644
--- a/src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed
+++ b/src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::unnecessary_cast)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/ptr_offset_with_cast.rs b/src/tools/clippy/tests/ui/ptr_offset_with_cast.rs
index 3de7997ac..eae36c277 100644
--- a/src/tools/clippy/tests/ui/ptr_offset_with_cast.rs
+++ b/src/tools/clippy/tests/ui/ptr_offset_with_cast.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::unnecessary_cast)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/question_mark.fixed b/src/tools/clippy/tests/ui/question_mark.fixed
index 5c49d46da..7f1660f31 100644
--- a/src/tools/clippy/tests/ui/question_mark.fixed
+++ b/src/tools/clippy/tests/ui/question_mark.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unreachable_code)]
#![allow(dead_code)]
#![allow(clippy::unnecessary_wraps)]
diff --git a/src/tools/clippy/tests/ui/question_mark.rs b/src/tools/clippy/tests/ui/question_mark.rs
index d057df6a9..a90eae50e 100644
--- a/src/tools/clippy/tests/ui/question_mark.rs
+++ b/src/tools/clippy/tests/ui/question_mark.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unreachable_code)]
#![allow(dead_code)]
#![allow(clippy::unnecessary_wraps)]
diff --git a/src/tools/clippy/tests/ui/range_contains.fixed b/src/tools/clippy/tests/ui/range_contains.fixed
index 4923731fe..0a92ee7c8 100644
--- a/src/tools/clippy/tests/ui/range_contains.fixed
+++ b/src/tools/clippy/tests/ui/range_contains.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_range_contains)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/range_contains.rs b/src/tools/clippy/tests/ui/range_contains.rs
index d623ccb5d..7a83be609 100644
--- a/src/tools/clippy/tests/ui/range_contains.rs
+++ b/src/tools/clippy/tests/ui/range_contains.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::manual_range_contains)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/range_plus_minus_one.fixed b/src/tools/clippy/tests/ui/range_plus_minus_one.fixed
index a16a3e54d..79c133cb5 100644
--- a/src/tools/clippy/tests/ui/range_plus_minus_one.fixed
+++ b/src/tools/clippy/tests/ui/range_plus_minus_one.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_parens)]
#![allow(clippy::iter_with_drain)]
diff --git a/src/tools/clippy/tests/ui/range_plus_minus_one.rs b/src/tools/clippy/tests/ui/range_plus_minus_one.rs
index bd6cb4d21..689a6b7a1 100644
--- a/src/tools/clippy/tests/ui/range_plus_minus_one.rs
+++ b/src/tools/clippy/tests/ui/range_plus_minus_one.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_parens)]
#![allow(clippy::iter_with_drain)]
diff --git a/src/tools/clippy/tests/ui/rc_buffer.fixed b/src/tools/clippy/tests/ui/rc_buffer.fixed
index 8910c01b1..4cba292c1 100644
--- a/src/tools/clippy/tests/ui/rc_buffer.fixed
+++ b/src/tools/clippy/tests/ui/rc_buffer.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::rc_buffer)]
#![allow(dead_code, unused_imports)]
diff --git a/src/tools/clippy/tests/ui/rc_buffer.rs b/src/tools/clippy/tests/ui/rc_buffer.rs
index 1e63a4326..d8a9aa278 100644
--- a/src/tools/clippy/tests/ui/rc_buffer.rs
+++ b/src/tools/clippy/tests/ui/rc_buffer.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::rc_buffer)]
#![allow(dead_code, unused_imports)]
diff --git a/src/tools/clippy/tests/ui/rc_buffer_arc.fixed b/src/tools/clippy/tests/ui/rc_buffer_arc.fixed
index 13dd6f5fc..ac51ac9e4 100644
--- a/src/tools/clippy/tests/ui/rc_buffer_arc.fixed
+++ b/src/tools/clippy/tests/ui/rc_buffer_arc.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::rc_buffer)]
#![allow(dead_code, unused_imports)]
diff --git a/src/tools/clippy/tests/ui/rc_buffer_arc.rs b/src/tools/clippy/tests/ui/rc_buffer_arc.rs
index 1a521bfeb..21dc27bc5 100644
--- a/src/tools/clippy/tests/ui/rc_buffer_arc.rs
+++ b/src/tools/clippy/tests/ui/rc_buffer_arc.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::rc_buffer)]
#![allow(dead_code, unused_imports)]
diff --git a/src/tools/clippy/tests/ui/redundant_allocation_fixable.fixed b/src/tools/clippy/tests/ui/redundant_allocation_fixable.fixed
index 6db02718c..edb7715f4 100644
--- a/src/tools/clippy/tests/ui/redundant_allocation_fixable.fixed
+++ b/src/tools/clippy/tests/ui/redundant_allocation_fixable.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all)]
#![allow(clippy::boxed_local, clippy::needless_pass_by_value)]
#![allow(clippy::disallowed_names, unused_variables, dead_code)]
diff --git a/src/tools/clippy/tests/ui/redundant_allocation_fixable.rs b/src/tools/clippy/tests/ui/redundant_allocation_fixable.rs
index c15806f30..c59422dd9 100644
--- a/src/tools/clippy/tests/ui/redundant_allocation_fixable.rs
+++ b/src/tools/clippy/tests/ui/redundant_allocation_fixable.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all)]
#![allow(clippy::boxed_local, clippy::needless_pass_by_value)]
#![allow(clippy::disallowed_names, unused_variables, dead_code)]
diff --git a/src/tools/clippy/tests/ui/redundant_async_block.fixed b/src/tools/clippy/tests/ui/redundant_async_block.fixed
index ad96993c4..328958491 100644
--- a/src/tools/clippy/tests/ui/redundant_async_block.fixed
+++ b/src/tools/clippy/tests/ui/redundant_async_block.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::manual_async_fn)]
#![warn(clippy::redundant_async_block)]
diff --git a/src/tools/clippy/tests/ui/redundant_async_block.rs b/src/tools/clippy/tests/ui/redundant_async_block.rs
index 7ae235583..cd189b315 100644
--- a/src/tools/clippy/tests/ui/redundant_async_block.rs
+++ b/src/tools/clippy/tests/ui/redundant_async_block.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::manual_async_fn)]
#![warn(clippy::redundant_async_block)]
diff --git a/src/tools/clippy/tests/ui/redundant_clone.fixed b/src/tools/clippy/tests/ui/redundant_clone.fixed
index 00b427450..cb9583aa6 100644
--- a/src/tools/clippy/tests/ui/redundant_clone.fixed
+++ b/src/tools/clippy/tests/ui/redundant_clone.fixed
@@ -1,6 +1,7 @@
-// run-rustfix
+//@run-rustfix
// rustfix-only-machine-applicable
#![feature(lint_reasons)]
+#![warn(clippy::redundant_clone)]
#![allow(clippy::drop_non_drop, clippy::implicit_clone, clippy::uninlined_format_args)]
use std::ffi::OsString;
diff --git a/src/tools/clippy/tests/ui/redundant_clone.rs b/src/tools/clippy/tests/ui/redundant_clone.rs
index f899127db..e5aeacbb5 100644
--- a/src/tools/clippy/tests/ui/redundant_clone.rs
+++ b/src/tools/clippy/tests/ui/redundant_clone.rs
@@ -1,6 +1,7 @@
-// run-rustfix
+//@run-rustfix
// rustfix-only-machine-applicable
#![feature(lint_reasons)]
+#![warn(clippy::redundant_clone)]
#![allow(clippy::drop_non_drop, clippy::implicit_clone, clippy::uninlined_format_args)]
use std::ffi::OsString;
diff --git a/src/tools/clippy/tests/ui/redundant_clone.stderr b/src/tools/clippy/tests/ui/redundant_clone.stderr
index 782590034..bb5c602d6 100644
--- a/src/tools/clippy/tests/ui/redundant_clone.stderr
+++ b/src/tools/clippy/tests/ui/redundant_clone.stderr
@@ -1,180 +1,180 @@
error: redundant clone
- --> $DIR/redundant_clone.rs:10:42
+ --> $DIR/redundant_clone.rs:11:42
|
LL | let _s = ["lorem", "ipsum"].join(" ").to_string();
| ^^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:10:14
+ --> $DIR/redundant_clone.rs:11:14
|
LL | let _s = ["lorem", "ipsum"].join(" ").to_string();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `-D clippy::redundant-clone` implied by `-D warnings`
error: redundant clone
- --> $DIR/redundant_clone.rs:13:15
+ --> $DIR/redundant_clone.rs:14:15
|
LL | let _s = s.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:13:14
+ --> $DIR/redundant_clone.rs:14:14
|
LL | let _s = s.clone();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:16:15
+ --> $DIR/redundant_clone.rs:17:15
|
LL | let _s = s.to_string();
| ^^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:16:14
+ --> $DIR/redundant_clone.rs:17:14
|
LL | let _s = s.to_string();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:19:15
+ --> $DIR/redundant_clone.rs:20:15
|
LL | let _s = s.to_owned();
| ^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:19:14
+ --> $DIR/redundant_clone.rs:20:14
|
LL | let _s = s.to_owned();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:21:42
+ --> $DIR/redundant_clone.rs:22:42
|
LL | let _s = Path::new("/a/b/").join("c").to_owned();
| ^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:21:14
+ --> $DIR/redundant_clone.rs:22:14
|
LL | let _s = Path::new("/a/b/").join("c").to_owned();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:23:42
+ --> $DIR/redundant_clone.rs:24:42
|
LL | let _s = Path::new("/a/b/").join("c").to_path_buf();
| ^^^^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:23:14
+ --> $DIR/redundant_clone.rs:24:14
|
LL | let _s = Path::new("/a/b/").join("c").to_path_buf();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:25:29
+ --> $DIR/redundant_clone.rs:26:29
|
LL | let _s = OsString::new().to_owned();
| ^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:25:14
+ --> $DIR/redundant_clone.rs:26:14
|
LL | let _s = OsString::new().to_owned();
| ^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:27:29
+ --> $DIR/redundant_clone.rs:28:29
|
LL | let _s = OsString::new().to_os_string();
| ^^^^^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:27:14
+ --> $DIR/redundant_clone.rs:28:14
|
LL | let _s = OsString::new().to_os_string();
| ^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:38:19
+ --> $DIR/redundant_clone.rs:39:19
|
LL | let _t = tup.0.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:38:14
+ --> $DIR/redundant_clone.rs:39:14
|
LL | let _t = tup.0.clone();
| ^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:70:25
+ --> $DIR/redundant_clone.rs:71:25
|
LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) }
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:70:24
+ --> $DIR/redundant_clone.rs:71:24
|
LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) }
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:127:15
+ --> $DIR/redundant_clone.rs:128:15
|
LL | let _s = s.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:127:14
+ --> $DIR/redundant_clone.rs:128:14
|
LL | let _s = s.clone();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:128:15
+ --> $DIR/redundant_clone.rs:129:15
|
LL | let _t = t.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:128:14
+ --> $DIR/redundant_clone.rs:129:14
|
LL | let _t = t.clone();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:138:19
+ --> $DIR/redundant_clone.rs:139:19
|
LL | let _f = f.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:138:18
+ --> $DIR/redundant_clone.rs:139:18
|
LL | let _f = f.clone();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:150:14
+ --> $DIR/redundant_clone.rs:151:14
|
LL | let y = x.clone().join("matthias");
| ^^^^^^^^ help: remove this
|
note: cloned value is neither consumed nor mutated
- --> $DIR/redundant_clone.rs:150:13
+ --> $DIR/redundant_clone.rs:151:13
|
LL | let y = x.clone().join("matthias");
| ^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:204:11
+ --> $DIR/redundant_clone.rs:205:11
|
LL | foo(&x.clone(), move || {
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:204:10
+ --> $DIR/redundant_clone.rs:205:10
|
LL | foo(&x.clone(), move || {
| ^
diff --git a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed
index b987fd2ce..61aed2733 100644
--- a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed
+++ b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(async_closure)]
#![warn(clippy::redundant_closure_call)]
diff --git a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs
index 633a2979d..56b286635 100644
--- a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs
+++ b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(async_closure)]
#![warn(clippy::redundant_closure_call)]
diff --git a/src/tools/clippy/tests/ui/redundant_field_names.fixed b/src/tools/clippy/tests/ui/redundant_field_names.fixed
index 276266a2d..d2a65399d 100644
--- a/src/tools/clippy/tests/ui/redundant_field_names.fixed
+++ b/src/tools/clippy/tests/ui/redundant_field_names.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::redundant_field_names)]
#![allow(clippy::extra_unused_type_parameters, clippy::no_effect, dead_code, unused_variables)]
diff --git a/src/tools/clippy/tests/ui/redundant_field_names.rs b/src/tools/clippy/tests/ui/redundant_field_names.rs
index f674141c1..605ffd21e 100644
--- a/src/tools/clippy/tests/ui/redundant_field_names.rs
+++ b/src/tools/clippy/tests/ui/redundant_field_names.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::redundant_field_names)]
#![allow(clippy::extra_unused_type_parameters, clippy::no_effect, dead_code, unused_variables)]
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.fixed
index ce3229f17..bebdf8971 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
// Issue #5746
#![warn(clippy::redundant_pattern_matching)]
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.rs
index 29b8543cf..8fb6ed5f7 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.rs
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
// Issue #5746
#![warn(clippy::redundant_pattern_matching)]
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 21bae9095..a9faf12cd 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all, clippy::redundant_pattern_matching)]
#![allow(unused_must_use)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs
index 4dd917167..574671d03 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all, clippy::redundant_pattern_matching)]
#![allow(unused_must_use)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed
index a89845c1d..accdf1da9 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all)]
#![warn(clippy::redundant_pattern_matching)]
@@ -46,6 +46,7 @@ fn main() {
let _ = if opt.is_some() { true } else { false };
issue6067();
+ issue10726();
let _ = if gen_opt().is_some() {
1
@@ -54,6 +55,8 @@ fn main() {
} else {
3
};
+
+ if gen_opt().is_some() {}
}
fn gen_opt() -> Option<()> {
@@ -86,3 +89,21 @@ fn issue7921() {
if (&None::<()>).is_none() {}
if (&None::<()>).is_none() {}
}
+
+fn issue10726() {
+ let x = Some(42);
+
+ x.is_some();
+
+ x.is_none();
+
+ x.is_none();
+
+ x.is_some();
+
+ // Don't lint
+ match x {
+ Some(21) => true,
+ _ => false,
+ };
+}
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 d6f444034..ec684bdf7 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.rs
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all)]
#![warn(clippy::redundant_pattern_matching)]
@@ -55,6 +55,7 @@ fn main() {
let _ = if let Some(_) = opt { true } else { false };
issue6067();
+ issue10726();
let _ = if let Some(_) = gen_opt() {
1
@@ -63,6 +64,8 @@ fn main() {
} else {
3
};
+
+ if let Some(..) = gen_opt() {}
}
fn gen_opt() -> Option<()> {
@@ -101,3 +104,33 @@ fn issue7921() {
if let None = *(&None::<()>) {}
if let None = *&None::<()> {}
}
+
+fn issue10726() {
+ let x = Some(42);
+
+ match x {
+ Some(_) => true,
+ _ => false,
+ };
+
+ match x {
+ None => true,
+ _ => false,
+ };
+
+ match x {
+ Some(_) => false,
+ _ => true,
+ };
+
+ match x {
+ None => false,
+ _ => true,
+ };
+
+ // Don't lint
+ match x {
+ Some(21) => true,
+ _ => false,
+ };
+}
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 27ff812ba..a69eb3905 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_option.stderr
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_option.stderr
@@ -77,43 +77,49 @@ LL | let _ = if let Some(_) = opt { true } else { false };
| -------^^^^^^^------ help: try this: `if opt.is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:59:20
+ --> $DIR/redundant_pattern_matching_option.rs:60:20
|
LL | let _ = if let Some(_) = gen_opt() {
| -------^^^^^^^------------ help: try this: `if gen_opt().is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:61:19
+ --> $DIR/redundant_pattern_matching_option.rs:62:19
|
LL | } else if let None = gen_opt() {
| -------^^^^------------ help: try this: `if gen_opt().is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:80:12
+ --> $DIR/redundant_pattern_matching_option.rs:68:12
+ |
+LL | if let Some(..) = gen_opt() {}
+ | -------^^^^^^^^------------ help: try this: `if gen_opt().is_some()`
+
+error: redundant pattern matching, consider using `is_some()`
+ --> $DIR/redundant_pattern_matching_option.rs:83:12
|
LL | if let Some(_) = Some(42) {}
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:82:12
+ --> $DIR/redundant_pattern_matching_option.rs:85:12
|
LL | if let None = None::<()> {}
| -------^^^^------------- help: try this: `if None::<()>.is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:84:15
+ --> $DIR/redundant_pattern_matching_option.rs:87:15
|
LL | while let Some(_) = Some(42) {}
| ----------^^^^^^^----------- help: try this: `while Some(42).is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:86:15
+ --> $DIR/redundant_pattern_matching_option.rs:89:15
|
LL | while let None = None::<()> {}
| ----------^^^^------------- help: try this: `while None::<()>.is_none()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_option.rs:88:5
+ --> $DIR/redundant_pattern_matching_option.rs:91:5
|
LL | / match Some(42) {
LL | | Some(_) => true,
@@ -122,7 +128,7 @@ LL | | };
| |_____^ help: try this: `Some(42).is_some()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:93:5
+ --> $DIR/redundant_pattern_matching_option.rs:96:5
|
LL | / match None::<()> {
LL | | Some(_) => false,
@@ -131,16 +137,52 @@ LL | | };
| |_____^ help: try this: `None::<()>.is_none()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:101:12
+ --> $DIR/redundant_pattern_matching_option.rs:104:12
|
LL | if let None = *(&None::<()>) {}
| -------^^^^----------------- help: try this: `if (&None::<()>).is_none()`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/redundant_pattern_matching_option.rs:102:12
+ --> $DIR/redundant_pattern_matching_option.rs:105:12
|
LL | if let None = *&None::<()> {}
| -------^^^^--------------- help: try this: `if (&None::<()>).is_none()`
-error: aborting due to 21 previous errors
+error: redundant pattern matching, consider using `is_some()`
+ --> $DIR/redundant_pattern_matching_option.rs:111:5
+ |
+LL | / match x {
+LL | | Some(_) => true,
+LL | | _ => false,
+LL | | };
+ | |_____^ help: try this: `x.is_some()`
+
+error: redundant pattern matching, consider using `is_none()`
+ --> $DIR/redundant_pattern_matching_option.rs:116:5
+ |
+LL | / match x {
+LL | | None => true,
+LL | | _ => false,
+LL | | };
+ | |_____^ help: try this: `x.is_none()`
+
+error: redundant pattern matching, consider using `is_none()`
+ --> $DIR/redundant_pattern_matching_option.rs:121:5
+ |
+LL | / match x {
+LL | | Some(_) => false,
+LL | | _ => true,
+LL | | };
+ | |_____^ help: try this: `x.is_none()`
+
+error: redundant pattern matching, consider using `is_some()`
+ --> $DIR/redundant_pattern_matching_option.rs:126:5
+ |
+LL | / match x {
+LL | | None => false,
+LL | | _ => true,
+LL | | };
+ | |_____^ help: try this: `x.is_some()`
+
+error: aborting due to 26 previous errors
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.fixed
index 3645f2c4b..bf3e69220 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all)]
#![warn(clippy::redundant_pattern_matching)]
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.rs
index 866c71b7c..892a21d9d 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.rs
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_poll.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all)]
#![warn(clippy::redundant_pattern_matching)]
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed
index 42348df44..e4032ae44 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all)]
#![warn(clippy::redundant_pattern_matching)]
#![allow(deprecated, unused_must_use)]
@@ -43,6 +43,7 @@ fn main() {
issue5504();
issue6067();
issue6065();
+ issue10726();
let _ = if gen_res().is_ok() {
1
@@ -107,3 +108,28 @@ const fn issue6067() {
Err::<i32, i32>(42).is_err();
}
+
+fn issue10726() {
+ // This is optional, but it makes the examples easier
+ let x: Result<i32, i32> = Ok(42);
+
+ x.is_ok();
+
+ x.is_err();
+
+ x.is_err();
+
+ x.is_ok();
+
+ // Don't lint
+ match x {
+ Err(16) => false,
+ _ => true,
+ };
+
+ // Don't lint
+ match x {
+ Ok(16) => false,
+ _ => true,
+ };
+}
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs
index 5949cb227..39eb10df8 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::all)]
#![warn(clippy::redundant_pattern_matching)]
#![allow(deprecated, unused_must_use)]
@@ -55,6 +55,7 @@ fn main() {
issue5504();
issue6067();
issue6065();
+ issue10726();
let _ = if let Ok(_) = gen_res() {
1
@@ -125,3 +126,40 @@ const fn issue6067() {
Err(_) => true,
};
}
+
+fn issue10726() {
+ // This is optional, but it makes the examples easier
+ let x: Result<i32, i32> = Ok(42);
+
+ match x {
+ Ok(_) => true,
+ _ => false,
+ };
+
+ match x {
+ Ok(_) => false,
+ _ => true,
+ };
+
+ match x {
+ Err(_) => true,
+ _ => false,
+ };
+
+ match x {
+ Err(_) => false,
+ _ => true,
+ };
+
+ // Don't lint
+ match x {
+ Err(16) => false,
+ _ => true,
+ };
+
+ // Don't lint
+ match x {
+ Ok(16) => false,
+ _ => true,
+ };
+}
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 d6a46babb..5893ae4dc 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr
@@ -73,67 +73,67 @@ LL | let _ = if let Ok(_) = Ok::<usize, ()>(4) { true } else { false };
| -------^^^^^--------------------- help: try this: `if Ok::<usize, ()>(4).is_ok()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:59:20
+ --> $DIR/redundant_pattern_matching_result.rs:60:20
|
LL | let _ = if let Ok(_) = gen_res() {
| -------^^^^^------------ help: try this: `if gen_res().is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:61:19
+ --> $DIR/redundant_pattern_matching_result.rs:62:19
|
LL | } else if let Err(_) = gen_res() {
| -------^^^^^^------------ help: try this: `if gen_res().is_err()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_result.rs:84:19
+ --> $DIR/redundant_pattern_matching_result.rs:85:19
|
LL | while let Some(_) = r#try!(result_opt()) {}
| ----------^^^^^^^----------------------- help: try this: `while r#try!(result_opt()).is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_result.rs:85:16
+ --> $DIR/redundant_pattern_matching_result.rs:86:16
|
LL | if let Some(_) = r#try!(result_opt()) {}
| -------^^^^^^^----------------------- help: try this: `if r#try!(result_opt()).is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_result.rs:91:12
+ --> $DIR/redundant_pattern_matching_result.rs:92:12
|
LL | if let Some(_) = m!() {}
| -------^^^^^^^------- help: try this: `if m!().is_some()`
error: redundant pattern matching, consider using `is_some()`
- --> $DIR/redundant_pattern_matching_result.rs:92:15
+ --> $DIR/redundant_pattern_matching_result.rs:93:15
|
LL | while let Some(_) = m!() {}
| ----------^^^^^^^------- help: try this: `while m!().is_some()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:110:12
+ --> $DIR/redundant_pattern_matching_result.rs:111:12
|
LL | if let Ok(_) = Ok::<i32, i32>(42) {}
| -------^^^^^--------------------- help: try this: `if Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:112:12
+ --> $DIR/redundant_pattern_matching_result.rs:113:12
|
LL | if let Err(_) = Err::<i32, i32>(42) {}
| -------^^^^^^---------------------- help: try this: `if Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:114:15
+ --> $DIR/redundant_pattern_matching_result.rs:115:15
|
LL | while let Ok(_) = Ok::<i32, i32>(10) {}
| ----------^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:116:15
+ --> $DIR/redundant_pattern_matching_result.rs:117:15
|
LL | while let Err(_) = Ok::<i32, i32>(10) {}
| ----------^^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:118:5
+ --> $DIR/redundant_pattern_matching_result.rs:119:5
|
LL | / match Ok::<i32, i32>(42) {
LL | | Ok(_) => true,
@@ -142,7 +142,7 @@ LL | | };
| |_____^ help: try this: `Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:123:5
+ --> $DIR/redundant_pattern_matching_result.rs:124:5
|
LL | / match Err::<i32, i32>(42) {
LL | | Ok(_) => false,
@@ -150,5 +150,41 @@ LL | | Err(_) => true,
LL | | };
| |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
-error: aborting due to 22 previous errors
+error: redundant pattern matching, consider using `is_ok()`
+ --> $DIR/redundant_pattern_matching_result.rs:134:5
+ |
+LL | / match x {
+LL | | Ok(_) => true,
+LL | | _ => false,
+LL | | };
+ | |_____^ help: try this: `x.is_ok()`
+
+error: redundant pattern matching, consider using `is_err()`
+ --> $DIR/redundant_pattern_matching_result.rs:139:5
+ |
+LL | / match x {
+LL | | Ok(_) => false,
+LL | | _ => true,
+LL | | };
+ | |_____^ help: try this: `x.is_err()`
+
+error: redundant pattern matching, consider using `is_err()`
+ --> $DIR/redundant_pattern_matching_result.rs:144:5
+ |
+LL | / match x {
+LL | | Err(_) => true,
+LL | | _ => false,
+LL | | };
+ | |_____^ help: try this: `x.is_err()`
+
+error: redundant pattern matching, consider using `is_ok()`
+ --> $DIR/redundant_pattern_matching_result.rs:149:5
+ |
+LL | / match x {
+LL | | Err(_) => false,
+LL | | _ => true,
+LL | | };
+ | |_____^ help: try this: `x.is_ok()`
+
+error: aborting due to 26 previous errors
diff --git a/src/tools/clippy/tests/ui/redundant_pub_crate.fixed b/src/tools/clippy/tests/ui/redundant_pub_crate.fixed
index 106947de6..f65c0fdd3 100644
--- a/src/tools/clippy/tests/ui/redundant_pub_crate.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pub_crate.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
#![warn(clippy::redundant_pub_crate)]
diff --git a/src/tools/clippy/tests/ui/redundant_pub_crate.rs b/src/tools/clippy/tests/ui/redundant_pub_crate.rs
index f96cfd318..fb07fed98 100644
--- a/src/tools/clippy/tests/ui/redundant_pub_crate.rs
+++ b/src/tools/clippy/tests/ui/redundant_pub_crate.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
#![warn(clippy::redundant_pub_crate)]
diff --git a/src/tools/clippy/tests/ui/redundant_slicing.fixed b/src/tools/clippy/tests/ui/redundant_slicing.fixed
index 8dd8d3092..56ddca719 100644
--- a/src/tools/clippy/tests/ui/redundant_slicing.fixed
+++ b/src/tools/clippy/tests/ui/redundant_slicing.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::deref_by_slicing)]
#![warn(clippy::redundant_slicing)]
diff --git a/src/tools/clippy/tests/ui/redundant_slicing.rs b/src/tools/clippy/tests/ui/redundant_slicing.rs
index 51c16dd8d..d67b6665e 100644
--- a/src/tools/clippy/tests/ui/redundant_slicing.rs
+++ b/src/tools/clippy/tests/ui/redundant_slicing.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused, clippy::deref_by_slicing)]
#![warn(clippy::redundant_slicing)]
diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed b/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
index bca777a89..2651735d1 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs b/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
index afe764481..728665289 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/ref_patterns.rs b/src/tools/clippy/tests/ui/ref_patterns.rs
new file mode 100644
index 000000000..c51e0bc76
--- /dev/null
+++ b/src/tools/clippy/tests/ui/ref_patterns.rs
@@ -0,0 +1,19 @@
+#![allow(unused)]
+#![warn(clippy::ref_patterns)]
+
+fn use_in_pattern() {
+ let opt = Some(5);
+ match opt {
+ None => {},
+ Some(ref opt) => {},
+ }
+}
+
+fn use_in_binding() {
+ let x = 5;
+ let ref y = x;
+}
+
+fn use_in_parameter(ref x: i32) {}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/ref_patterns.stderr b/src/tools/clippy/tests/ui/ref_patterns.stderr
new file mode 100644
index 000000000..aa0077826
--- /dev/null
+++ b/src/tools/clippy/tests/ui/ref_patterns.stderr
@@ -0,0 +1,27 @@
+error: usage of ref pattern
+ --> $DIR/ref_patterns.rs:8:14
+ |
+LL | Some(ref opt) => {},
+ | ^^^^^^^
+ |
+ = help: consider using `&` for clarity instead
+ = note: `-D clippy::ref-patterns` implied by `-D warnings`
+
+error: usage of ref pattern
+ --> $DIR/ref_patterns.rs:14:9
+ |
+LL | let ref y = x;
+ | ^^^^^
+ |
+ = help: consider using `&` for clarity instead
+
+error: usage of ref pattern
+ --> $DIR/ref_patterns.rs:17:21
+ |
+LL | fn use_in_parameter(ref x: i32) {}
+ | ^^^^^
+ |
+ = help: consider using `&` for clarity instead
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/regex.rs b/src/tools/clippy/tests/ui/regex.rs
index ab8ac97a0..a5f79b139 100644
--- a/src/tools/clippy/tests/ui/regex.rs
+++ b/src/tools/clippy/tests/ui/regex.rs
@@ -34,8 +34,10 @@ fn syntax_error() {
let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]);
let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]);
+ // These following three cases are considering valid since regex-1.8.0
let raw_string_error = Regex::new(r"[...\/...]");
let raw_string_error = Regex::new(r#"[...\/...]"#);
+ let _ = Regex::new(r"(?<hi>hi)").unwrap();
let escaped_string_span = Regex::new("\\b\\c");
diff --git a/src/tools/clippy/tests/ui/regex.stderr b/src/tools/clippy/tests/ui/regex.stderr
index c2440f39e..6b8a772e7 100644
--- a/src/tools/clippy/tests/ui/regex.stderr
+++ b/src/tools/clippy/tests/ui/regex.stderr
@@ -82,23 +82,11 @@ error: regex parse error:
LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+/.(com|org|net)"]);
| ^^^^^^^^^^^^^
-error: regex syntax error: unrecognized escape sequence
- --> $DIR/regex.rs:37:45
- |
-LL | let raw_string_error = Regex::new(r"[...//...]");
- | ^^
-
-error: regex syntax error: unrecognized escape sequence
- --> $DIR/regex.rs:38:46
- |
-LL | let raw_string_error = Regex::new(r#"[...//...]"#);
- | ^^
-
error: regex parse error:
/b/c
^^
error: unrecognized escape sequence
- --> $DIR/regex.rs:40:42
+ --> $DIR/regex.rs:42:42
|
LL | let escaped_string_span = Regex::new("/b/c");
| ^^^^^^^^
@@ -106,13 +94,13 @@ LL | let escaped_string_span = Regex::new("/b/c");
= help: consider using a raw string literal: `r".."`
error: regex syntax error: duplicate flag
- --> $DIR/regex.rs:42:34
+ --> $DIR/regex.rs:44:34
|
LL | let aux_span = Regex::new("(?ixi)");
| ^ ^
error: trivial regex
- --> $DIR/regex.rs:46:33
+ --> $DIR/regex.rs:48:33
|
LL | let trivial_eq = Regex::new("^foobar$");
| ^^^^^^^^^^
@@ -120,7 +108,7 @@ LL | let trivial_eq = Regex::new("^foobar$");
= help: consider using `==` on `str`s
error: trivial regex
- --> $DIR/regex.rs:48:48
+ --> $DIR/regex.rs:50:48
|
LL | let trivial_eq_builder = RegexBuilder::new("^foobar$");
| ^^^^^^^^^^
@@ -128,7 +116,7 @@ LL | let trivial_eq_builder = RegexBuilder::new("^foobar$");
= help: consider using `==` on `str`s
error: trivial regex
- --> $DIR/regex.rs:50:42
+ --> $DIR/regex.rs:52:42
|
LL | let trivial_starts_with = Regex::new("^foobar");
| ^^^^^^^^^
@@ -136,7 +124,7 @@ LL | let trivial_starts_with = Regex::new("^foobar");
= help: consider using `str::starts_with`
error: trivial regex
- --> $DIR/regex.rs:52:40
+ --> $DIR/regex.rs:54:40
|
LL | let trivial_ends_with = Regex::new("foobar$");
| ^^^^^^^^^
@@ -144,7 +132,7 @@ LL | let trivial_ends_with = Regex::new("foobar$");
= help: consider using `str::ends_with`
error: trivial regex
- --> $DIR/regex.rs:54:39
+ --> $DIR/regex.rs:56:39
|
LL | let trivial_contains = Regex::new("foobar");
| ^^^^^^^^
@@ -152,7 +140,7 @@ LL | let trivial_contains = Regex::new("foobar");
= help: consider using `str::contains`
error: trivial regex
- --> $DIR/regex.rs:56:39
+ --> $DIR/regex.rs:58:39
|
LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX);
| ^^^^^^^^^^^^^^^^
@@ -160,7 +148,7 @@ LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX);
= help: consider using `str::contains`
error: trivial regex
- --> $DIR/regex.rs:58:40
+ --> $DIR/regex.rs:60:40
|
LL | let trivial_backslash = Regex::new("a/.b");
| ^^^^^^^
@@ -168,7 +156,7 @@ LL | let trivial_backslash = Regex::new("a/.b");
= help: consider using `str::contains`
error: trivial regex
- --> $DIR/regex.rs:61:36
+ --> $DIR/regex.rs:63:36
|
LL | let trivial_empty = Regex::new("");
| ^^
@@ -176,7 +164,7 @@ LL | let trivial_empty = Regex::new("");
= help: the regex is unlikely to be useful as it is
error: trivial regex
- --> $DIR/regex.rs:63:36
+ --> $DIR/regex.rs:65:36
|
LL | let trivial_empty = Regex::new("^");
| ^^^
@@ -184,7 +172,7 @@ LL | let trivial_empty = Regex::new("^");
= help: the regex is unlikely to be useful as it is
error: trivial regex
- --> $DIR/regex.rs:65:36
+ --> $DIR/regex.rs:67:36
|
LL | let trivial_empty = Regex::new("^$");
| ^^^^
@@ -192,12 +180,12 @@ LL | let trivial_empty = Regex::new("^$");
= help: consider using `str::is_empty`
error: trivial regex
- --> $DIR/regex.rs:67:44
+ --> $DIR/regex.rs:69:44
|
LL | let binary_trivial_empty = BRegex::new("^$");
| ^^^^
|
= help: consider using `str::is_empty`
-error: aborting due to 25 previous errors
+error: aborting due to 23 previous errors
diff --git a/src/tools/clippy/tests/ui/rename.fixed b/src/tools/clippy/tests/ui/rename.fixed
index 5076f6133..dfe45dec8 100644
--- a/src/tools/clippy/tests/ui/rename.fixed
+++ b/src/tools/clippy/tests/ui/rename.fixed
@@ -2,7 +2,7 @@
// Use that command to update this file and do not edit by hand.
// Manual edits will be overwritten.
-// run-rustfix
+//@run-rustfix
#![allow(clippy::almost_complete_range)]
#![allow(clippy::disallowed_names)]
@@ -16,6 +16,7 @@
#![allow(clippy::mixed_read_write_in_expression)]
#![allow(clippy::useless_conversion)]
#![allow(clippy::match_result_ok)]
+#![allow(clippy::arithmetic_side_effects)]
#![allow(clippy::overly_complex_bool_expr)]
#![allow(clippy::new_without_default)]
#![allow(clippy::bind_instead_of_map)]
@@ -27,8 +28,13 @@
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::recursive_format_impl)]
#![allow(clippy::invisible_characters)]
+#![allow(suspicious_double_ref_op)]
#![allow(drop_bounds)]
+#![allow(dropping_copy_types)]
+#![allow(dropping_references)]
#![allow(for_loops_over_fallibles)]
+#![allow(forgetting_copy_types)]
+#![allow(forgetting_references)]
#![allow(array_into_iter)]
#![allow(invalid_atomic_ordering)]
#![allow(invalid_value)]
@@ -36,6 +42,7 @@
#![allow(enum_intrinsics_non_enums)]
#![allow(non_fmt_panics)]
#![allow(named_arguments_used_positionally)]
+#![allow(suspicious_double_ref_op)]
#![allow(temporary_cstring_as_ptr)]
#![allow(unknown_lints)]
#![allow(unused_labels)]
@@ -52,6 +59,7 @@
#![warn(clippy::mixed_read_write_in_expression)]
#![warn(clippy::useless_conversion)]
#![warn(clippy::match_result_ok)]
+#![warn(clippy::arithmetic_side_effects)]
#![warn(clippy::overly_complex_bool_expr)]
#![warn(clippy::new_without_default)]
#![warn(clippy::bind_instead_of_map)]
@@ -67,10 +75,15 @@
#![warn(clippy::module_name_repetitions)]
#![warn(clippy::recursive_format_impl)]
#![warn(clippy::invisible_characters)]
+#![warn(suspicious_double_ref_op)]
#![warn(drop_bounds)]
+#![warn(dropping_copy_types)]
+#![warn(dropping_references)]
#![warn(for_loops_over_fallibles)]
#![warn(for_loops_over_fallibles)]
#![warn(for_loops_over_fallibles)]
+#![warn(forgetting_copy_types)]
+#![warn(forgetting_references)]
#![warn(array_into_iter)]
#![warn(invalid_atomic_ordering)]
#![warn(invalid_value)]
diff --git a/src/tools/clippy/tests/ui/rename.rs b/src/tools/clippy/tests/ui/rename.rs
index 64bc1ca71..ce8eca5a3 100644
--- a/src/tools/clippy/tests/ui/rename.rs
+++ b/src/tools/clippy/tests/ui/rename.rs
@@ -2,7 +2,7 @@
// Use that command to update this file and do not edit by hand.
// Manual edits will be overwritten.
-// run-rustfix
+//@run-rustfix
#![allow(clippy::almost_complete_range)]
#![allow(clippy::disallowed_names)]
@@ -16,6 +16,7 @@
#![allow(clippy::mixed_read_write_in_expression)]
#![allow(clippy::useless_conversion)]
#![allow(clippy::match_result_ok)]
+#![allow(clippy::arithmetic_side_effects)]
#![allow(clippy::overly_complex_bool_expr)]
#![allow(clippy::new_without_default)]
#![allow(clippy::bind_instead_of_map)]
@@ -27,8 +28,13 @@
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::recursive_format_impl)]
#![allow(clippy::invisible_characters)]
+#![allow(suspicious_double_ref_op)]
#![allow(drop_bounds)]
+#![allow(dropping_copy_types)]
+#![allow(dropping_references)]
#![allow(for_loops_over_fallibles)]
+#![allow(forgetting_copy_types)]
+#![allow(forgetting_references)]
#![allow(array_into_iter)]
#![allow(invalid_atomic_ordering)]
#![allow(invalid_value)]
@@ -36,6 +42,7 @@
#![allow(enum_intrinsics_non_enums)]
#![allow(non_fmt_panics)]
#![allow(named_arguments_used_positionally)]
+#![allow(suspicious_double_ref_op)]
#![allow(temporary_cstring_as_ptr)]
#![allow(unknown_lints)]
#![allow(unused_labels)]
@@ -52,6 +59,7 @@
#![warn(clippy::eval_order_dependence)]
#![warn(clippy::identity_conversion)]
#![warn(clippy::if_let_some_result)]
+#![warn(clippy::integer_arithmetic)]
#![warn(clippy::logic_bug)]
#![warn(clippy::new_without_default_derive)]
#![warn(clippy::option_and_then_some)]
@@ -67,10 +75,15 @@
#![warn(clippy::stutter)]
#![warn(clippy::to_string_in_display)]
#![warn(clippy::zero_width_space)]
+#![warn(clippy::clone_double_ref)]
#![warn(clippy::drop_bounds)]
+#![warn(clippy::drop_copy)]
+#![warn(clippy::drop_ref)]
#![warn(clippy::for_loop_over_option)]
#![warn(clippy::for_loop_over_result)]
#![warn(clippy::for_loops_over_fallibles)]
+#![warn(clippy::forget_copy)]
+#![warn(clippy::forget_ref)]
#![warn(clippy::into_iter_on_array)]
#![warn(clippy::invalid_atomic_ordering)]
#![warn(clippy::invalid_ref)]
diff --git a/src/tools/clippy/tests/ui/rename.stderr b/src/tools/clippy/tests/ui/rename.stderr
index 27a026329..3fca60aa2 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:42:9
+ --> $DIR/rename.rs:49:9
|
LL | #![warn(clippy::almost_complete_letter_range)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range`
@@ -7,250 +7,286 @@ 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:43:9
+ --> $DIR/rename.rs:50: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:44:9
+ --> $DIR/rename.rs:51: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:45:9
+ --> $DIR/rename.rs:52: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:46:9
+ --> $DIR/rename.rs:53: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:47:9
+ --> $DIR/rename.rs:54: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:48:9
+ --> $DIR/rename.rs:55: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:49:9
+ --> $DIR/rename.rs:56: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:50:9
+ --> $DIR/rename.rs:57: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:51:9
+ --> $DIR/rename.rs:58: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:52:9
+ --> $DIR/rename.rs:59: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:53:9
+ --> $DIR/rename.rs:60: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:54:9
+ --> $DIR/rename.rs:61:9
|
LL | #![warn(clippy::if_let_some_result)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok`
+error: lint `clippy::integer_arithmetic` has been renamed to `clippy::arithmetic_side_effects`
+ --> $DIR/rename.rs:62:9
+ |
+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:55:9
+ --> $DIR/rename.rs:63: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:56:9
+ --> $DIR/rename.rs:64: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:57:9
+ --> $DIR/rename.rs:65: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:58:9
+ --> $DIR/rename.rs:66: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:59:9
+ --> $DIR/rename.rs:67: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:60:9
+ --> $DIR/rename.rs:68: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:61:9
+ --> $DIR/rename.rs:69: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:62:9
+ --> $DIR/rename.rs:70: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:63:9
+ --> $DIR/rename.rs:71: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:64:9
+ --> $DIR/rename.rs:72: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:65:9
+ --> $DIR/rename.rs:73: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:66:9
+ --> $DIR/rename.rs:74: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:67:9
+ --> $DIR/rename.rs:75: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:68:9
+ --> $DIR/rename.rs:76:9
|
LL | #![warn(clippy::to_string_in_display)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl`
error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters`
- --> $DIR/rename.rs:69:9
+ --> $DIR/rename.rs:77:9
|
LL | #![warn(clippy::zero_width_space)]
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters`
+error: lint `clippy::clone_double_ref` has been renamed to `suspicious_double_ref_op`
+ --> $DIR/rename.rs:78:9
+ |
+LL | #![warn(clippy::clone_double_ref)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `suspicious_double_ref_op`
+
error: lint `clippy::drop_bounds` has been renamed to `drop_bounds`
- --> $DIR/rename.rs:70:9
+ --> $DIR/rename.rs:79:9
|
LL | #![warn(clippy::drop_bounds)]
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds`
+error: lint `clippy::drop_copy` has been renamed to `dropping_copy_types`
+ --> $DIR/rename.rs:80:9
+ |
+LL | #![warn(clippy::drop_copy)]
+ | ^^^^^^^^^^^^^^^^^ help: use the new name: `dropping_copy_types`
+
+error: lint `clippy::drop_ref` has been renamed to `dropping_references`
+ --> $DIR/rename.rs:81:9
+ |
+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:71:9
+ --> $DIR/rename.rs:82: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:72:9
+ --> $DIR/rename.rs:83: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:73:9
+ --> $DIR/rename.rs:84:9
|
LL | #![warn(clippy::for_loops_over_fallibles)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles`
+error: lint `clippy::forget_copy` has been renamed to `forgetting_copy_types`
+ --> $DIR/rename.rs:85:9
+ |
+LL | #![warn(clippy::forget_copy)]
+ | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_copy_types`
+
+error: lint `clippy::forget_ref` has been renamed to `forgetting_references`
+ --> $DIR/rename.rs:86:9
+ |
+LL | #![warn(clippy::forget_ref)]
+ | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forgetting_references`
+
error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter`
- --> $DIR/rename.rs:74:9
+ --> $DIR/rename.rs:87: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:75:9
+ --> $DIR/rename.rs:88: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:76:9
+ --> $DIR/rename.rs:89:9
|
LL | #![warn(clippy::invalid_ref)]
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value`
error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop`
- --> $DIR/rename.rs:77:9
+ --> $DIR/rename.rs:90: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:78:9
+ --> $DIR/rename.rs:91: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:79:9
+ --> $DIR/rename.rs:92: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:80:9
+ --> $DIR/rename.rs:93: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:81:9
+ --> $DIR/rename.rs:94:9
|
LL | #![warn(clippy::temporary_cstring_as_ptr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr`
error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints`
- --> $DIR/rename.rs:82:9
+ --> $DIR/rename.rs:95: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:83:9
+ --> $DIR/rename.rs:96:9
|
LL | #![warn(clippy::unused_label)]
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels`
-error: aborting due to 42 previous errors
+error: aborting due to 48 previous errors
diff --git a/src/tools/clippy/tests/ui/renamed_builtin_attr.fixed b/src/tools/clippy/tests/ui/renamed_builtin_attr.fixed
index cb91b841d..0334c1e1a 100644
--- a/src/tools/clippy/tests/ui/renamed_builtin_attr.fixed
+++ b/src/tools/clippy/tests/ui/renamed_builtin_attr.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#[clippy::cognitive_complexity = "1"]
fn main() {}
diff --git a/src/tools/clippy/tests/ui/renamed_builtin_attr.rs b/src/tools/clippy/tests/ui/renamed_builtin_attr.rs
index b3ce27580..d350370c2 100644
--- a/src/tools/clippy/tests/ui/renamed_builtin_attr.rs
+++ b/src/tools/clippy/tests/ui/renamed_builtin_attr.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#[clippy::cyclomatic_complexity = "1"]
fn main() {}
diff --git a/src/tools/clippy/tests/ui/repeat_once.fixed b/src/tools/clippy/tests/ui/repeat_once.fixed
index dc197e503..c517bfcc6 100644
--- a/src/tools/clippy/tests/ui/repeat_once.fixed
+++ b/src/tools/clippy/tests/ui/repeat_once.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::repeat_once)]
#[allow(unused, clippy::redundant_clone)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/repeat_once.rs b/src/tools/clippy/tests/ui/repeat_once.rs
index 0ec512711..9a30b4741 100644
--- a/src/tools/clippy/tests/ui/repeat_once.rs
+++ b/src/tools/clippy/tests/ui/repeat_once.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::repeat_once)]
#[allow(unused, clippy::redundant_clone)]
fn main() {
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 331531b51..119ff2591 100644
--- a/src/tools/clippy/tests/ui/result_map_or_into_option.fixed
+++ b/src/tools/clippy/tests/ui/result_map_or_into_option.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::result_map_or_into_option)]
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 3058480e2..eeeef830a 100644
--- a/src/tools/clippy/tests/ui/result_map_or_into_option.rs
+++ b/src/tools/clippy/tests/ui/result_map_or_into_option.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::result_map_or_into_option)]
diff --git a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.fixed b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.fixed
index d8b56237e..0583d2927 100644
--- a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.fixed
+++ b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::result_map_unit_fn)]
#![allow(unused)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.rs b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.rs
index 44f50d211..7ad3bdd04 100644
--- a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.rs
+++ b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::result_map_unit_fn)]
#![allow(unused)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed
index c67edb36c..30dfc9776 100644
--- a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed
+++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::reversed_empty_ranges)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs
index 0a4fef5bf..1837249ea 100644
--- a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs
+++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::reversed_empty_ranges)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed
index 78401e463..a74569599 100644
--- a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed
+++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::reversed_empty_ranges)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs
index f9e0f7fcd..42f9957df 100644
--- a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs
+++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::reversed_empty_ranges)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/same_functions_in_if_condition.rs b/src/tools/clippy/tests/ui/same_functions_in_if_condition.rs
index e6198a1bc..aea1507cc 100644
--- a/src/tools/clippy/tests/ui/same_functions_in_if_condition.rs
+++ b/src/tools/clippy/tests/ui/same_functions_in_if_condition.rs
@@ -1,5 +1,5 @@
#![feature(adt_const_params)]
-#![warn(clippy::same_functions_in_if_condition)]
+#![deny(clippy::same_functions_in_if_condition)]
// ifs_same_cond warning is different from `ifs_same_cond`.
// clippy::if_same_then_else, clippy::comparison_chain -- all empty blocks
#![allow(incomplete_features)]
diff --git a/src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr b/src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr
index f352ade15..aade3b1fa 100644
--- a/src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr
+++ b/src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr
@@ -9,7 +9,11 @@ note: same as this
|
LL | if function() {
| ^^^^^^^^^^
- = note: `-D clippy::same-functions-in-if-condition` implied by `-D warnings`
+note: the lint level is defined here
+ --> $DIR/same_functions_in_if_condition.rs:2:9
+ |
+LL | #![deny(clippy::same_functions_in_if_condition)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this `if` has the same function call as a previous `if`
--> $DIR/same_functions_in_if_condition.rs:42:15
diff --git a/src/tools/clippy/tests/ui/same_name_method.rs b/src/tools/clippy/tests/ui/same_name_method.rs
index daef95a42..f31a7e33c 100644
--- a/src/tools/clippy/tests/ui/same_name_method.rs
+++ b/src/tools/clippy/tests/ui/same_name_method.rs
@@ -62,7 +62,7 @@ mod should_lint {
impl T1 for S {}
}
- mod multiply_conflicit_trait {
+ mod multiple_conflicting_traits {
use crate::{T1, T2};
struct S;
diff --git a/src/tools/clippy/tests/ui/search_is_some.rs b/src/tools/clippy/tests/ui/search_is_some.rs
index 72f335153..670599b0d 100644
--- a/src/tools/clippy/tests/ui/search_is_some.rs
+++ b/src/tools/clippy/tests/ui/search_is_some.rs
@@ -1,4 +1,4 @@
-// aux-build:option_helpers.rs
+//@aux-build:option_helpers.rs
#![warn(clippy::search_is_some)]
#![allow(dead_code)]
extern crate option_helpers;
diff --git a/src/tools/clippy/tests/ui/search_is_some_fixable_none.fixed b/src/tools/clippy/tests/ui/search_is_some_fixable_none.fixed
index 5190c5304..9386618c1 100644
--- a/src/tools/clippy/tests/ui/search_is_some_fixable_none.fixed
+++ b/src/tools/clippy/tests/ui/search_is_some_fixable_none.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, clippy::explicit_auto_deref)]
#![warn(clippy::search_is_some)]
diff --git a/src/tools/clippy/tests/ui/search_is_some_fixable_none.rs b/src/tools/clippy/tests/ui/search_is_some_fixable_none.rs
index 310d87333..6b2537a96 100644
--- a/src/tools/clippy/tests/ui/search_is_some_fixable_none.rs
+++ b/src/tools/clippy/tests/ui/search_is_some_fixable_none.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, clippy::explicit_auto_deref)]
#![warn(clippy::search_is_some)]
diff --git a/src/tools/clippy/tests/ui/search_is_some_fixable_some.fixed b/src/tools/clippy/tests/ui/search_is_some_fixable_some.fixed
index 385a9986a..e9116fc59 100644
--- a/src/tools/clippy/tests/ui/search_is_some_fixable_some.fixed
+++ b/src/tools/clippy/tests/ui/search_is_some_fixable_some.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, clippy::explicit_auto_deref)]
#![warn(clippy::search_is_some)]
diff --git a/src/tools/clippy/tests/ui/search_is_some_fixable_some.rs b/src/tools/clippy/tests/ui/search_is_some_fixable_some.rs
index 67e190ee3..b15283994 100644
--- a/src/tools/clippy/tests/ui/search_is_some_fixable_some.rs
+++ b/src/tools/clippy/tests/ui/search_is_some_fixable_some.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, clippy::explicit_auto_deref)]
#![warn(clippy::search_is_some)]
diff --git a/src/tools/clippy/tests/ui/seek_from_current.fixed b/src/tools/clippy/tests/ui/seek_from_current.fixed
index 1309c91b8..34c33baf6 100644
--- a/src/tools/clippy/tests/ui/seek_from_current.fixed
+++ b/src/tools/clippy/tests/ui/seek_from_current.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::seek_from_current)]
use std::fs::File;
diff --git a/src/tools/clippy/tests/ui/seek_from_current.rs b/src/tools/clippy/tests/ui/seek_from_current.rs
index 5d9b1424c..22bcff1bc 100644
--- a/src/tools/clippy/tests/ui/seek_from_current.rs
+++ b/src/tools/clippy/tests/ui/seek_from_current.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::seek_from_current)]
use std::fs::File;
diff --git a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed
index dc24d447c..d8a6e6985 100644
--- a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed
+++ b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::seek_to_start_instead_of_rewind)]
diff --git a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs
index 4adde2c40..fc6a6433c 100644
--- a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs
+++ b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::seek_to_start_instead_of_rewind)]
diff --git a/src/tools/clippy/tests/ui/semicolon_inside_block.fixed b/src/tools/clippy/tests/ui/semicolon_inside_block.fixed
index 42e97e1ca..ee359f60c 100644
--- a/src/tools/clippy/tests/ui/semicolon_inside_block.fixed
+++ b/src/tools/clippy/tests/ui/semicolon_inside_block.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(
unused,
clippy::unused_unit,
diff --git a/src/tools/clippy/tests/ui/semicolon_inside_block.rs b/src/tools/clippy/tests/ui/semicolon_inside_block.rs
index f40848f70..e8516f79b 100644
--- a/src/tools/clippy/tests/ui/semicolon_inside_block.rs
+++ b/src/tools/clippy/tests/ui/semicolon_inside_block.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(
unused,
clippy::unused_unit,
diff --git a/src/tools/clippy/tests/ui/semicolon_outside_block.fixed b/src/tools/clippy/tests/ui/semicolon_outside_block.fixed
index 091eaa751..034c7f8c7 100644
--- a/src/tools/clippy/tests/ui/semicolon_outside_block.fixed
+++ b/src/tools/clippy/tests/ui/semicolon_outside_block.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(
unused,
clippy::unused_unit,
diff --git a/src/tools/clippy/tests/ui/semicolon_outside_block.rs b/src/tools/clippy/tests/ui/semicolon_outside_block.rs
index 7ce46431f..4dc956d8a 100644
--- a/src/tools/clippy/tests/ui/semicolon_outside_block.rs
+++ b/src/tools/clippy/tests/ui/semicolon_outside_block.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(
unused,
clippy::unused_unit,
diff --git a/src/tools/clippy/tests/ui/shadow.rs b/src/tools/clippy/tests/ui/shadow.rs
index 1fa9fc749..2c0fc3e3f 100644
--- a/src/tools/clippy/tests/ui/shadow.rs
+++ b/src/tools/clippy/tests/ui/shadow.rs
@@ -1,6 +1,19 @@
+//@aux-build:proc_macro_derive.rs
+
#![warn(clippy::shadow_same, clippy::shadow_reuse, clippy::shadow_unrelated)]
#![allow(clippy::let_unit_value)]
+extern crate proc_macro_derive;
+
+#[derive(proc_macro_derive::ShadowDerive)]
+pub struct Nothing;
+
+macro_rules! reuse {
+ ($v:ident) => {
+ let $v = $v + 1;
+ };
+}
+
fn shadow_same() {
let x = 1;
let x = x;
@@ -26,6 +39,12 @@ fn shadow_reuse() -> Option<()> {
None
}
+fn shadow_reuse_macro() {
+ let x = 1;
+ // this should not warn
+ reuse!(x);
+}
+
fn shadow_unrelated() {
let x = 1;
let x = 2;
diff --git a/src/tools/clippy/tests/ui/shadow.stderr b/src/tools/clippy/tests/ui/shadow.stderr
index c3d7bc2a5..8321f6df2 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:6:9
+ --> $DIR/shadow.rs:19:9
|
LL | let x = x;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:5:9
+ --> $DIR/shadow.rs:18: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:7:13
+ --> $DIR/shadow.rs:20:13
|
LL | let mut x = &x;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:6:9
+ --> $DIR/shadow.rs:19:9
|
LL | let x = x;
| ^
error: `x` is shadowed by itself in `&mut x`
- --> $DIR/shadow.rs:8:9
+ --> $DIR/shadow.rs:21:9
|
LL | let x = &mut x;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:7:9
+ --> $DIR/shadow.rs:20:9
|
LL | let mut x = &x;
| ^^^^^
error: `x` is shadowed by itself in `*x`
- --> $DIR/shadow.rs:9:9
+ --> $DIR/shadow.rs:22:9
|
LL | let x = *x;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:8:9
+ --> $DIR/shadow.rs:21:9
|
LL | let x = &mut x;
| ^
error: `x` is shadowed
- --> $DIR/shadow.rs:14:9
+ --> $DIR/shadow.rs:27:9
|
LL | let x = x.0;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:13:9
+ --> $DIR/shadow.rs:26:9
|
LL | let x = ([[0]], ());
| ^
= note: `-D clippy::shadow-reuse` implied by `-D warnings`
error: `x` is shadowed
- --> $DIR/shadow.rs:15:9
+ --> $DIR/shadow.rs:28:9
|
LL | let x = x[0];
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:14:9
+ --> $DIR/shadow.rs:27:9
|
LL | let x = x.0;
| ^
error: `x` is shadowed
- --> $DIR/shadow.rs:16:10
+ --> $DIR/shadow.rs:29:10
|
LL | let [x] = x;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:15:9
+ --> $DIR/shadow.rs:28:9
|
LL | let x = x[0];
| ^
error: `x` is shadowed
- --> $DIR/shadow.rs:17:9
+ --> $DIR/shadow.rs:30:9
|
LL | let x = Some(x);
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:16:10
+ --> $DIR/shadow.rs:29:10
|
LL | let [x] = x;
| ^
error: `x` is shadowed
- --> $DIR/shadow.rs:18:9
+ --> $DIR/shadow.rs:31:9
|
LL | let x = foo(x);
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:17:9
+ --> $DIR/shadow.rs:30:9
|
LL | let x = Some(x);
| ^
error: `x` is shadowed
- --> $DIR/shadow.rs:19:9
+ --> $DIR/shadow.rs:32:9
|
LL | let x = || x;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:18:9
+ --> $DIR/shadow.rs:31:9
|
LL | let x = foo(x);
| ^
error: `x` is shadowed
- --> $DIR/shadow.rs:20:9
+ --> $DIR/shadow.rs:33:9
|
LL | let x = Some(1).map(|_| x)?;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:19:9
+ --> $DIR/shadow.rs:32:9
|
LL | let x = || x;
| ^
error: `y` is shadowed
- --> $DIR/shadow.rs:22:9
+ --> $DIR/shadow.rs:35:9
|
LL | let y = match y {
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:21:9
+ --> $DIR/shadow.rs:34:9
|
LL | let y = 1;
| ^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:31:9
+ --> $DIR/shadow.rs:50:9
|
LL | let x = 2;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:30:9
+ --> $DIR/shadow.rs:49:9
|
LL | let x = 1;
| ^
= note: `-D clippy::shadow-unrelated` implied by `-D warnings`
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:36:13
+ --> $DIR/shadow.rs:55:13
|
LL | let x = 1;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:35:10
+ --> $DIR/shadow.rs:54:10
|
LL | fn f(x: u32) {
| ^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:41:14
+ --> $DIR/shadow.rs:60:14
|
LL | Some(x) => {
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:38:9
+ --> $DIR/shadow.rs:57:9
|
LL | let x = 1;
| ^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:42:17
+ --> $DIR/shadow.rs:61:17
|
LL | let x = 1;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:41:14
+ --> $DIR/shadow.rs:60:14
|
LL | Some(x) => {
| ^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:46:17
+ --> $DIR/shadow.rs:65:17
|
LL | if let Some(x) = Some(1) {}
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:38:9
+ --> $DIR/shadow.rs:57:9
|
LL | let x = 1;
| ^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:47:20
+ --> $DIR/shadow.rs:66:20
|
LL | while let Some(x) = Some(1) {}
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:38:9
+ --> $DIR/shadow.rs:57:9
|
LL | let x = 1;
| ^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:48:15
+ --> $DIR/shadow.rs:67:15
|
LL | let _ = |[x]: [u32; 1]| {
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:38:9
+ --> $DIR/shadow.rs:57:9
|
LL | let x = 1;
| ^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:49:13
+ --> $DIR/shadow.rs:68:13
|
LL | let x = 1;
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:48:15
+ --> $DIR/shadow.rs:67:15
|
LL | let _ = |[x]: [u32; 1]| {
| ^
error: `y` is shadowed
- --> $DIR/shadow.rs:52:17
+ --> $DIR/shadow.rs:71:17
|
LL | if let Some(y) = y {}
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:51:9
+ --> $DIR/shadow.rs:70:9
|
LL | let y = Some(1);
| ^
error: `_b` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:88:9
+ --> $DIR/shadow.rs:107:9
|
LL | let _b = _a;
| ^^
|
note: previous binding is here
- --> $DIR/shadow.rs:87:28
+ --> $DIR/shadow.rs:106:28
|
LL | pub async fn foo2(_a: i32, _b: i64) {
| ^^
error: `x` shadows a previous, unrelated binding
- --> $DIR/shadow.rs:94:21
+ --> $DIR/shadow.rs:113:21
|
LL | if let Some(x) = Some(1) { x } else { 1 }
| ^
|
note: previous binding is here
- --> $DIR/shadow.rs:93:13
+ --> $DIR/shadow.rs:112:13
|
LL | let x = 1;
| ^
diff --git a/src/tools/clippy/tests/ui/short_circuit_statement.fixed b/src/tools/clippy/tests/ui/short_circuit_statement.fixed
index dd22ecab0..1737d5014 100644
--- a/src/tools/clippy/tests/ui/short_circuit_statement.fixed
+++ b/src/tools/clippy/tests/ui/short_circuit_statement.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::short_circuit_statement)]
#![allow(clippy::nonminimal_bool)]
diff --git a/src/tools/clippy/tests/ui/short_circuit_statement.rs b/src/tools/clippy/tests/ui/short_circuit_statement.rs
index 73a55bf1f..ab93aa1ca 100644
--- a/src/tools/clippy/tests/ui/short_circuit_statement.rs
+++ b/src/tools/clippy/tests/ui/short_circuit_statement.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::short_circuit_statement)]
#![allow(clippy::nonminimal_bool)]
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 c65df9ece..8c48b21f1 100644
--- a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs
+++ b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs
@@ -1,5 +1,5 @@
// FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934
-// // run-rustfix
+//
#![warn(clippy::significant_drop_in_scrutinee)]
#![allow(dead_code, unused_assignments)]
#![allow(clippy::match_single_binding, clippy::single_match, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/significant_drop_tightening.fixed b/src/tools/clippy/tests/ui/significant_drop_tightening.fixed
index da998c610..ee7f2b063 100644
--- a/src/tools/clippy/tests/ui/significant_drop_tightening.fixed
+++ b/src/tools/clippy/tests/ui/significant_drop_tightening.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::significant_drop_tightening)]
diff --git a/src/tools/clippy/tests/ui/significant_drop_tightening.rs b/src/tools/clippy/tests/ui/significant_drop_tightening.rs
index 83823f95f..9c139deb9 100644
--- a/src/tools/clippy/tests/ui/significant_drop_tightening.rs
+++ b/src/tools/clippy/tests/ui/significant_drop_tightening.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::significant_drop_tightening)]
diff --git a/src/tools/clippy/tests/ui/single_char_add_str.fixed b/src/tools/clippy/tests/ui/single_char_add_str.fixed
index 63a6d37a9..cbcf1ab21 100644
--- a/src/tools/clippy/tests/ui/single_char_add_str.fixed
+++ b/src/tools/clippy/tests/ui/single_char_add_str.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::single_char_add_str)]
macro_rules! get_string {
diff --git a/src/tools/clippy/tests/ui/single_char_add_str.rs b/src/tools/clippy/tests/ui/single_char_add_str.rs
index a799ea7d8..a1f005cc8 100644
--- a/src/tools/clippy/tests/ui/single_char_add_str.rs
+++ b/src/tools/clippy/tests/ui/single_char_add_str.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::single_char_add_str)]
macro_rules! get_string {
diff --git a/src/tools/clippy/tests/ui/single_char_pattern.fixed b/src/tools/clippy/tests/ui/single_char_pattern.fixed
index 68e267267..dba898720 100644
--- a/src/tools/clippy/tests/ui/single_char_pattern.fixed
+++ b/src/tools/clippy/tests/ui/single_char_pattern.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_must_use)]
diff --git a/src/tools/clippy/tests/ui/single_char_pattern.rs b/src/tools/clippy/tests/ui/single_char_pattern.rs
index 186202d78..6a145a14b 100644
--- a/src/tools/clippy/tests/ui/single_char_pattern.rs
+++ b/src/tools/clippy/tests/ui/single_char_pattern.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_must_use)]
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 8c96c4715..d4d2cbbe5 100644
--- a/src/tools/clippy/tests/ui/single_component_path_imports.fixed
+++ b/src/tools/clippy/tests/ui/single_component_path_imports.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::single_component_path_imports)]
#![allow(unused_imports)]
diff --git a/src/tools/clippy/tests/ui/single_component_path_imports.rs b/src/tools/clippy/tests/ui/single_component_path_imports.rs
index 8434bf7ea..80d72115f 100644
--- a/src/tools/clippy/tests/ui/single_component_path_imports.rs
+++ b/src/tools/clippy/tests/ui/single_component_path_imports.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::single_component_path_imports)]
#![allow(unused_imports)]
diff --git a/src/tools/clippy/tests/ui/single_element_loop.fixed b/src/tools/clippy/tests/ui/single_element_loop.fixed
index a0dcc0172..1697a0cf2 100644
--- a/src/tools/clippy/tests/ui/single_element_loop.fixed
+++ b/src/tools/clippy/tests/ui/single_element_loop.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
// Tests from for_loop.rs that don't have suggestions
#[warn(clippy::single_element_loop)]
diff --git a/src/tools/clippy/tests/ui/single_element_loop.rs b/src/tools/clippy/tests/ui/single_element_loop.rs
index bc014035c..860424f42 100644
--- a/src/tools/clippy/tests/ui/single_element_loop.rs
+++ b/src/tools/clippy/tests/ui/single_element_loop.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
// Tests from for_loop.rs that don't have suggestions
#[warn(clippy::single_element_loop)]
diff --git a/src/tools/clippy/tests/ui/single_match_else.rs b/src/tools/clippy/tests/ui/single_match_else.rs
index 3c86f41f3..c8ac768b6 100644
--- a/src/tools/clippy/tests/ui/single_match_else.rs
+++ b/src/tools/clippy/tests/ui/single_match_else.rs
@@ -1,4 +1,4 @@
-// aux-build: proc_macros.rs
+//@aux-build: proc_macros.rs
#![warn(clippy::single_match_else)]
#![allow(clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/skip_while_next.rs b/src/tools/clippy/tests/ui/skip_while_next.rs
index a551c19d9..62574e2c8 100644
--- a/src/tools/clippy/tests/ui/skip_while_next.rs
+++ b/src/tools/clippy/tests/ui/skip_while_next.rs
@@ -1,4 +1,4 @@
-// aux-build:option_helpers.rs
+//@aux-build:option_helpers.rs
#![warn(clippy::skip_while_next)]
#![allow(clippy::disallowed_names)]
diff --git a/src/tools/clippy/tests/ui/stable_sort_primitive.fixed b/src/tools/clippy/tests/ui/stable_sort_primitive.fixed
index f5f18169d..1370dd2df 100644
--- a/src/tools/clippy/tests/ui/stable_sort_primitive.fixed
+++ b/src/tools/clippy/tests/ui/stable_sort_primitive.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::stable_sort_primitive)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/stable_sort_primitive.rs b/src/tools/clippy/tests/ui/stable_sort_primitive.rs
index 8149c5638..cd344dd12 100644
--- a/src/tools/clippy/tests/ui/stable_sort_primitive.rs
+++ b/src/tools/clippy/tests/ui/stable_sort_primitive.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::stable_sort_primitive)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/starts_ends_with.fixed b/src/tools/clippy/tests/ui/starts_ends_with.fixed
index 983fac7af..29d56f852 100644
--- a/src/tools/clippy/tests/ui/starts_ends_with.fixed
+++ b/src/tools/clippy/tests/ui/starts_ends_with.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, unused_must_use)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui/starts_ends_with.rs b/src/tools/clippy/tests/ui/starts_ends_with.rs
index e3335dd2e..56bbe2574 100644
--- a/src/tools/clippy/tests/ui/starts_ends_with.rs
+++ b/src/tools/clippy/tests/ui/starts_ends_with.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, unused_must_use)]
fn main() {}
diff --git a/src/tools/clippy/tests/ui/string_add.rs b/src/tools/clippy/tests/ui/string_add.rs
index 20edbe31f..de78dfe4d 100644
--- a/src/tools/clippy/tests/ui/string_add.rs
+++ b/src/tools/clippy/tests/ui/string_add.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs
extern crate proc_macros;
use proc_macros::external;
diff --git a/src/tools/clippy/tests/ui/string_add_assign.fixed b/src/tools/clippy/tests/ui/string_add_assign.fixed
index b687f43b2..616c6daaf 100644
--- a/src/tools/clippy/tests/ui/string_add_assign.fixed
+++ b/src/tools/clippy/tests/ui/string_add_assign.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#[allow(clippy::string_add, unused)]
#[warn(clippy::string_add_assign)]
diff --git a/src/tools/clippy/tests/ui/string_add_assign.rs b/src/tools/clippy/tests/ui/string_add_assign.rs
index e5dbde108..e1f885975 100644
--- a/src/tools/clippy/tests/ui/string_add_assign.rs
+++ b/src/tools/clippy/tests/ui/string_add_assign.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#[allow(clippy::string_add, unused)]
#[warn(clippy::string_add_assign)]
diff --git a/src/tools/clippy/tests/ui/string_extend.fixed b/src/tools/clippy/tests/ui/string_extend.fixed
index d200d7310..65c9abff3 100644
--- a/src/tools/clippy/tests/ui/string_extend.fixed
+++ b/src/tools/clippy/tests/ui/string_extend.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#[derive(Copy, Clone)]
struct HasChars;
diff --git a/src/tools/clippy/tests/ui/string_extend.rs b/src/tools/clippy/tests/ui/string_extend.rs
index 0dd96a3b2..5f72ffe2f 100644
--- a/src/tools/clippy/tests/ui/string_extend.rs
+++ b/src/tools/clippy/tests/ui/string_extend.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#[derive(Copy, Clone)]
struct HasChars;
diff --git a/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.fixed b/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.fixed
index 6e665cdd5..9b315ae2b 100644
--- a/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.fixed
+++ b/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::string_from_utf8_as_bytes)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.rs b/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.rs
index 670d206d3..043dd2350 100644
--- a/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.rs
+++ b/src/tools/clippy/tests/ui/string_from_utf8_as_bytes.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::string_from_utf8_as_bytes)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/string_lit_as_bytes.fixed b/src/tools/clippy/tests/ui/string_lit_as_bytes.fixed
index 506187fc1..3fc11b8b0 100644
--- a/src/tools/clippy/tests/ui/string_lit_as_bytes.fixed
+++ b/src/tools/clippy/tests/ui/string_lit_as_bytes.fixed
@@ -1,8 +1,18 @@
-// run-rustfix
+//@run-rustfix
+//@aux-build:macro_rules.rs
#![allow(dead_code, unused_variables)]
#![warn(clippy::string_lit_as_bytes)]
+#[macro_use]
+extern crate macro_rules;
+
+macro_rules! b {
+ ($b:literal) => {
+ const B: &[u8] = b"warning";
+ };
+}
+
fn str_lit_as_bytes() {
let bs = b"hello there";
@@ -11,6 +21,10 @@ fn str_lit_as_bytes() {
let bs = b"lit to string".to_vec();
let bs = b"lit to owned".to_vec();
+ b!("warning");
+
+ string_lit_as_bytes!("no warning");
+
// no warning, because these cannot be written as byte string literals:
let ubs = "☃".as_bytes();
let ubs = "hello there! this is a very long string".as_bytes();
diff --git a/src/tools/clippy/tests/ui/string_lit_as_bytes.rs b/src/tools/clippy/tests/ui/string_lit_as_bytes.rs
index 2c339f1dd..7d54acf63 100644
--- a/src/tools/clippy/tests/ui/string_lit_as_bytes.rs
+++ b/src/tools/clippy/tests/ui/string_lit_as_bytes.rs
@@ -1,8 +1,18 @@
-// run-rustfix
+//@run-rustfix
+//@aux-build:macro_rules.rs
#![allow(dead_code, unused_variables)]
#![warn(clippy::string_lit_as_bytes)]
+#[macro_use]
+extern crate macro_rules;
+
+macro_rules! b {
+ ($b:literal) => {
+ const B: &[u8] = $b.as_bytes();
+ };
+}
+
fn str_lit_as_bytes() {
let bs = "hello there".as_bytes();
@@ -11,6 +21,10 @@ fn str_lit_as_bytes() {
let bs = "lit to string".to_string().into_bytes();
let bs = "lit to owned".to_owned().into_bytes();
+ b!("warning");
+
+ string_lit_as_bytes!("no warning");
+
// no warning, because these cannot be written as byte string literals:
let ubs = "☃".as_bytes();
let ubs = "hello there! this is a very long string".as_bytes();
diff --git a/src/tools/clippy/tests/ui/string_lit_as_bytes.stderr b/src/tools/clippy/tests/ui/string_lit_as_bytes.stderr
index f47d6161c..61b4e210e 100644
--- a/src/tools/clippy/tests/ui/string_lit_as_bytes.stderr
+++ b/src/tools/clippy/tests/ui/string_lit_as_bytes.stderr
@@ -1,5 +1,5 @@
error: calling `as_bytes()` on a string literal
- --> $DIR/string_lit_as_bytes.rs:7:14
+ --> $DIR/string_lit_as_bytes.rs:17:14
|
LL | let bs = "hello there".as_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"hello there"`
@@ -7,34 +7,45 @@ LL | let bs = "hello there".as_bytes();
= note: `-D clippy::string-lit-as-bytes` implied by `-D warnings`
error: calling `as_bytes()` on a string literal
- --> $DIR/string_lit_as_bytes.rs:9:14
+ --> $DIR/string_lit_as_bytes.rs:19:14
|
LL | let bs = r###"raw string with 3# plus " ""###.as_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `br###"raw string with 3# plus " ""###`
error: calling `into_bytes()` on a string literal
- --> $DIR/string_lit_as_bytes.rs:11:14
+ --> $DIR/string_lit_as_bytes.rs:21:14
|
LL | let bs = "lit to string".to_string().into_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"lit to string".to_vec()`
error: calling `into_bytes()` on a string literal
- --> $DIR/string_lit_as_bytes.rs:12:14
+ --> $DIR/string_lit_as_bytes.rs:22:14
|
LL | let bs = "lit to owned".to_owned().into_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"lit to owned".to_vec()`
+error: calling `as_bytes()` on a string literal
+ --> $DIR/string_lit_as_bytes.rs:12:26
+ |
+LL | const B: &[u8] = $b.as_bytes();
+ | ^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"warning"`
+...
+LL | b!("warning");
+ | ------------- in this macro invocation
+ |
+ = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info)
+
error: calling `as_bytes()` on `include_str!(..)`
- --> $DIR/string_lit_as_bytes.rs:25:22
+ --> $DIR/string_lit_as_bytes.rs:39:22
|
LL | let includestr = include_str!("string_lit_as_bytes.rs").as_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `include_bytes!(..)` instead: `include_bytes!("string_lit_as_bytes.rs")`
error: calling `as_bytes()` on a string literal
- --> $DIR/string_lit_as_bytes.rs:27:13
+ --> $DIR/string_lit_as_bytes.rs:41:13
|
LL | let _ = "string with newline/t/n".as_bytes();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using a byte string literal instead: `b"string with newline/t/n"`
-error: aborting due to 6 previous errors
+error: aborting due to 7 previous errors
diff --git a/src/tools/clippy/tests/ui/strlen_on_c_strings.fixed b/src/tools/clippy/tests/ui/strlen_on_c_strings.fixed
index 947a59bcc..ef207e28c 100644
--- a/src/tools/clippy/tests/ui/strlen_on_c_strings.fixed
+++ b/src/tools/clippy/tests/ui/strlen_on_c_strings.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::strlen_on_c_strings)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/strlen_on_c_strings.rs b/src/tools/clippy/tests/ui/strlen_on_c_strings.rs
index 1237f1ab0..03ec5f79d 100644
--- a/src/tools/clippy/tests/ui/strlen_on_c_strings.rs
+++ b/src/tools/clippy/tests/ui/strlen_on_c_strings.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::strlen_on_c_strings)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/suspicious_doc_comments.fixed b/src/tools/clippy/tests/ui/suspicious_doc_comments.fixed
index b404df94d..bffda1cc4 100644
--- a/src/tools/clippy/tests/ui/suspicious_doc_comments.fixed
+++ b/src/tools/clippy/tests/ui/suspicious_doc_comments.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::suspicious_doc_comments)]
diff --git a/src/tools/clippy/tests/ui/suspicious_doc_comments.rs b/src/tools/clippy/tests/ui/suspicious_doc_comments.rs
index 46eff51e2..cdd972ee3 100644
--- a/src/tools/clippy/tests/ui/suspicious_doc_comments.rs
+++ b/src/tools/clippy/tests/ui/suspicious_doc_comments.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::suspicious_doc_comments)]
diff --git a/src/tools/clippy/tests/ui/suspicious_else_formatting.rs b/src/tools/clippy/tests/ui/suspicious_else_formatting.rs
index 21753e5dc..e0153cdd8 100644
--- a/src/tools/clippy/tests/ui/suspicious_else_formatting.rs
+++ b/src/tools/clippy/tests/ui/suspicious_else_formatting.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macro_suspicious_else_formatting.rs
+//@aux-build:proc_macro_suspicious_else_formatting.rs
#![warn(clippy::suspicious_else_formatting)]
#![allow(clippy::if_same_then_else, clippy::let_unit_value)]
diff --git a/src/tools/clippy/tests/ui/suspicious_operation_groupings.fixed b/src/tools/clippy/tests/ui/suspicious_operation_groupings.fixed
index ede8a39fe..0e37701ec 100644
--- a/src/tools/clippy/tests/ui/suspicious_operation_groupings.fixed
+++ b/src/tools/clippy/tests/ui/suspicious_operation_groupings.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::suspicious_operation_groupings)]
#![allow(dead_code, unused_parens, clippy::eq_op)]
diff --git a/src/tools/clippy/tests/ui/suspicious_operation_groupings.rs b/src/tools/clippy/tests/ui/suspicious_operation_groupings.rs
index 26ce97bb3..dd4f3b71c 100644
--- a/src/tools/clippy/tests/ui/suspicious_operation_groupings.rs
+++ b/src/tools/clippy/tests/ui/suspicious_operation_groupings.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::suspicious_operation_groupings)]
#![allow(dead_code, unused_parens, clippy::eq_op)]
diff --git a/src/tools/clippy/tests/ui/swap.fixed b/src/tools/clippy/tests/ui/swap.fixed
index 9703674d1..fd3569cf3 100644
--- a/src/tools/clippy/tests/ui/swap.fixed
+++ b/src/tools/clippy/tests/ui/swap.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build: macro_rules.rs
+//@run-rustfix
+//@aux-build: macro_rules.rs
#![warn(clippy::all)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/swap.rs b/src/tools/clippy/tests/ui/swap.rs
index a0228065e..34fbce052 100644
--- a/src/tools/clippy/tests/ui/swap.rs
+++ b/src/tools/clippy/tests/ui/swap.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build: macro_rules.rs
+//@run-rustfix
+//@aux-build: macro_rules.rs
#![warn(clippy::all)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/swap_ptr_to_ref.fixed b/src/tools/clippy/tests/ui/swap_ptr_to_ref.fixed
index 596b6ee91..3bede3017 100644
--- a/src/tools/clippy/tests/ui/swap_ptr_to_ref.fixed
+++ b/src/tools/clippy/tests/ui/swap_ptr_to_ref.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::swap_ptr_to_ref)]
diff --git a/src/tools/clippy/tests/ui/swap_ptr_to_ref.rs b/src/tools/clippy/tests/ui/swap_ptr_to_ref.rs
index 282f57121..726b09d37 100644
--- a/src/tools/clippy/tests/ui/swap_ptr_to_ref.rs
+++ b/src/tools/clippy/tests/ui/swap_ptr_to_ref.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::swap_ptr_to_ref)]
diff --git a/src/tools/clippy/tests/ui/tabs_in_doc_comments.fixed b/src/tools/clippy/tests/ui/tabs_in_doc_comments.fixed
index 4bc4bc86c..21020182c 100644
--- a/src/tools/clippy/tests/ui/tabs_in_doc_comments.fixed
+++ b/src/tools/clippy/tests/ui/tabs_in_doc_comments.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::tabs_in_doc_comments)]
#[allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/tabs_in_doc_comments.rs b/src/tools/clippy/tests/ui/tabs_in_doc_comments.rs
index 9db3416e6..df704267d 100644
--- a/src/tools/clippy/tests/ui/tabs_in_doc_comments.rs
+++ b/src/tools/clippy/tests/ui/tabs_in_doc_comments.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::tabs_in_doc_comments)]
#[allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/tests_outside_test_module.rs b/src/tools/clippy/tests/ui/tests_outside_test_module.rs
index 1982b1d01..21fdfdf90 100644
--- a/src/tools/clippy/tests/ui/tests_outside_test_module.rs
+++ b/src/tools/clippy/tests/ui/tests_outside_test_module.rs
@@ -1,4 +1,4 @@
-// compile-flags: --test
+//@compile-flags: --test
#![allow(unused)]
#![warn(clippy::tests_outside_test_module)]
diff --git a/src/tools/clippy/tests/ui/to_digit_is_some.fixed b/src/tools/clippy/tests/ui/to_digit_is_some.fixed
index 3c5e96427..dc9be66d4 100644
--- a/src/tools/clippy/tests/ui/to_digit_is_some.fixed
+++ b/src/tools/clippy/tests/ui/to_digit_is_some.fixed
@@ -1,4 +1,4 @@
-//run-rustfix
+//@run-rustfix
#![warn(clippy::to_digit_is_some)]
diff --git a/src/tools/clippy/tests/ui/to_digit_is_some.rs b/src/tools/clippy/tests/ui/to_digit_is_some.rs
index 4f247c06c..d2a09ac30 100644
--- a/src/tools/clippy/tests/ui/to_digit_is_some.rs
+++ b/src/tools/clippy/tests/ui/to_digit_is_some.rs
@@ -1,4 +1,4 @@
-//run-rustfix
+//@run-rustfix
#![warn(clippy::to_digit_is_some)]
diff --git a/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed b/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed
index 174c858a4..ea30c1fda 100644
--- a/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed
+++ b/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![warn(clippy::toplevel_ref_arg)]
#![allow(clippy::uninlined_format_args, unused)]
diff --git a/src/tools/clippy/tests/ui/toplevel_ref_arg.rs b/src/tools/clippy/tests/ui/toplevel_ref_arg.rs
index 4b81a0611..7a3d33e5b 100644
--- a/src/tools/clippy/tests/ui/toplevel_ref_arg.rs
+++ b/src/tools/clippy/tests/ui/toplevel_ref_arg.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![warn(clippy::toplevel_ref_arg)]
#![allow(clippy::uninlined_format_args, unused)]
diff --git a/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.rs b/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.rs
index 2047593e7..8aaf47b1b 100644
--- a/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.rs
+++ b/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs
#![warn(clippy::toplevel_ref_arg)]
#![allow(unused)]
diff --git a/src/tools/clippy/tests/ui/track-diagnostics.rs b/src/tools/clippy/tests/ui/track-diagnostics.rs
index fa9221ed0..6ab0bce77 100644
--- a/src/tools/clippy/tests/ui/track-diagnostics.rs
+++ b/src/tools/clippy/tests/ui/track-diagnostics.rs
@@ -1,9 +1,8 @@
-// compile-flags: -Z track-diagnostics
-// error-pattern: created at
+//@compile-flags: -Z track-diagnostics
// Normalize the emitted location so this doesn't need
// updating everytime someone adds or removes a line.
-// normalize-stderr-test ".rs:\d+:\d+" -> ".rs:LL:CC"
+//@normalize-stderr-test: ".rs:\d+:\d+" -> ".rs:LL:CC"
struct A;
struct B;
diff --git a/src/tools/clippy/tests/ui/trailing_empty_array.rs b/src/tools/clippy/tests/ui/trailing_empty_array.rs
index 8e3749eef..928475b5f 100644
--- a/src/tools/clippy/tests/ui/trailing_empty_array.rs
+++ b/src/tools/clippy/tests/ui/trailing_empty_array.rs
@@ -144,7 +144,7 @@ struct ReprCAlign {
// NOTE: because of https://doc.rust-lang.org/stable/reference/type-layout.html#primitive-representation-of-enums-with-fields and I'm not sure when in the compilation pipeline that would happen
#[repr(C)]
-enum DontLintAnonymousStructsFromDesuraging {
+enum DontLintAnonymousStructsFromDesugaring {
A(u32),
B(f32, [u64; 0]),
C { x: u32, y: [u64; 0] },
diff --git a/src/tools/clippy/tests/ui/trait_duplication_in_bounds.fixed b/src/tools/clippy/tests/ui/trait_duplication_in_bounds.fixed
index 4ce5d4217..fdac0e4cb 100644
--- a/src/tools/clippy/tests/ui/trait_duplication_in_bounds.fixed
+++ b/src/tools/clippy/tests/ui/trait_duplication_in_bounds.fixed
@@ -1,7 +1,9 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::trait_duplication_in_bounds)]
#![allow(unused)]
+use std::any::Any;
+
fn bad_foo<T: Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) {
unimplemented!();
}
@@ -109,4 +111,12 @@ fn qualified_path<T: std::clone::Clone + foo::Clone>(arg0: T) {
unimplemented!();
}
+fn good_trait_object(arg0: &(dyn Any + Send)) {
+ unimplemented!();
+}
+
+fn bad_trait_object(arg0: &(dyn Any + Send)) {
+ unimplemented!();
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/trait_duplication_in_bounds.rs b/src/tools/clippy/tests/ui/trait_duplication_in_bounds.rs
index 7f2e96a22..a0300da55 100644
--- a/src/tools/clippy/tests/ui/trait_duplication_in_bounds.rs
+++ b/src/tools/clippy/tests/ui/trait_duplication_in_bounds.rs
@@ -1,7 +1,9 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::trait_duplication_in_bounds)]
#![allow(unused)]
+use std::any::Any;
+
fn bad_foo<T: Clone + Clone + Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) {
unimplemented!();
}
@@ -109,4 +111,12 @@ fn qualified_path<T: std::clone::Clone + Clone + foo::Clone>(arg0: T) {
unimplemented!();
}
+fn good_trait_object(arg0: &(dyn Any + Send)) {
+ unimplemented!();
+}
+
+fn bad_trait_object(arg0: &(dyn Any + Send + Send)) {
+ unimplemented!();
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/trait_duplication_in_bounds.stderr b/src/tools/clippy/tests/ui/trait_duplication_in_bounds.stderr
index af800ba78..539b6114c 100644
--- a/src/tools/clippy/tests/ui/trait_duplication_in_bounds.stderr
+++ b/src/tools/clippy/tests/ui/trait_duplication_in_bounds.stderr
@@ -1,5 +1,5 @@
error: these bounds contain repeated elements
- --> $DIR/trait_duplication_in_bounds.rs:5:15
+ --> $DIR/trait_duplication_in_bounds.rs:7:15
|
LL | fn bad_foo<T: Clone + Clone + Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy`
@@ -11,46 +11,52 @@ LL | #![deny(clippy::trait_duplication_in_bounds)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: these where clauses contain repeated elements
- --> $DIR/trait_duplication_in_bounds.rs:11:8
+ --> $DIR/trait_duplication_in_bounds.rs:13:8
|
LL | T: Clone + Clone + Clone + Copy,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy`
error: these bounds contain repeated elements
- --> $DIR/trait_duplication_in_bounds.rs:39:26
+ --> $DIR/trait_duplication_in_bounds.rs:41:26
|
LL | trait BadSelfTraitBound: Clone + Clone + Clone {
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone`
error: these where clauses contain repeated elements
- --> $DIR/trait_duplication_in_bounds.rs:46:15
+ --> $DIR/trait_duplication_in_bounds.rs:48:15
|
LL | Self: Clone + Clone + Clone;
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone`
error: these bounds contain repeated elements
- --> $DIR/trait_duplication_in_bounds.rs:60:24
+ --> $DIR/trait_duplication_in_bounds.rs:62:24
|
LL | trait BadTraitBound<T: Clone + Clone + Clone + Copy, U: Clone + Copy> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy`
error: these where clauses contain repeated elements
- --> $DIR/trait_duplication_in_bounds.rs:67:12
+ --> $DIR/trait_duplication_in_bounds.rs:69:12
|
LL | T: Clone + Clone + Clone + Copy,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy`
error: these bounds contain repeated elements
- --> $DIR/trait_duplication_in_bounds.rs:100:19
+ --> $DIR/trait_duplication_in_bounds.rs:102:19
|
LL | fn bad_generic<T: GenericTrait<u64> + GenericTrait<u32> + GenericTrait<u64>>(arg0: T) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `GenericTrait<u64> + GenericTrait<u32>`
error: these bounds contain repeated elements
- --> $DIR/trait_duplication_in_bounds.rs:108:22
+ --> $DIR/trait_duplication_in_bounds.rs:110:22
|
LL | fn qualified_path<T: std::clone::Clone + Clone + foo::Clone>(arg0: T) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::clone::Clone + foo::Clone`
-error: aborting due to 8 previous errors
+error: this trait bound is already specified in trait declaration
+ --> $DIR/trait_duplication_in_bounds.rs:118:33
+ |
+LL | fn bad_trait_object(arg0: &(dyn Any + Send + Send)) {
+ | ^^^^^^^^^^^^^^^^^ help: try: `Any + Send`
+
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/transmute_32bit.rs b/src/tools/clippy/tests/ui/transmute_32bit.rs
index ffe22b12f..8e1316ca3 100644
--- a/src/tools/clippy/tests/ui/transmute_32bit.rs
+++ b/src/tools/clippy/tests/ui/transmute_32bit.rs
@@ -1,4 +1,4 @@
-// ignore-64bit
+//@ignore-64bit
#[warn(clippy::wrong_transmute)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/transmute_32bit.stderr b/src/tools/clippy/tests/ui/transmute_32bit.stderr
index 040519564..75ddca60d 100644
--- a/src/tools/clippy/tests/ui/transmute_32bit.stderr
+++ b/src/tools/clippy/tests/ui/transmute_32bit.stderr
@@ -1,28 +1,39 @@
-error: transmute from a `f32` to a pointer
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute_32bit.rs:6:31
|
LL | let _: *const usize = std::mem::transmute(6.0f32);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::wrong-transmute` implied by `-D warnings`
+ = note: source type: `f32` (32 bits)
+ = note: target type: `*const usize` (64 bits)
-error: transmute from a `f32` to a pointer
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute_32bit.rs:8:29
|
LL | let _: *mut usize = std::mem::transmute(6.0f32);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `f32` (32 bits)
+ = note: target type: `*mut usize` (64 bits)
-error: transmute from a `char` to a pointer
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute_32bit.rs:10:31
|
LL | let _: *const usize = std::mem::transmute('x');
- | ^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `char` (32 bits)
+ = note: target type: `*const usize` (64 bits)
-error: transmute from a `char` to a pointer
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute_32bit.rs:12:29
|
LL | let _: *mut usize = std::mem::transmute('x');
- | ^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `char` (32 bits)
+ = note: target type: `*mut usize` (64 bits)
error: aborting due to 4 previous errors
+For more information about this error, try `rustc --explain E0512`.
diff --git a/src/tools/clippy/tests/ui/transmute_64bit.rs b/src/tools/clippy/tests/ui/transmute_64bit.rs
index 00dc0b2c3..ceecf9b27 100644
--- a/src/tools/clippy/tests/ui/transmute_64bit.rs
+++ b/src/tools/clippy/tests/ui/transmute_64bit.rs
@@ -1,4 +1,4 @@
-// ignore-32bit
+//@ignore-32bit
#[warn(clippy::wrong_transmute)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed
index 074dae5fb..575dadde9 100644
--- a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed
+++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::transmute_ptr_to_ref)]
#![allow(clippy::match_single_binding)]
diff --git a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs
index 2edc122cf..4238ff804 100644
--- a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs
+++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::transmute_ptr_to_ref)]
#![allow(clippy::match_single_binding)]
diff --git a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed
index cc84ba25b..05aa86c47 100644
--- a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed
+++ b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::transmutes_expressible_as_ptr_casts)]
// These two warnings currently cover the cases transmutes_expressible_as_ptr_casts
// would otherwise be responsible for
diff --git a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs
index aa65ab4dd..29fa6914c 100644
--- a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs
+++ b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::transmutes_expressible_as_ptr_casts)]
// These two warnings currently cover the cases transmutes_expressible_as_ptr_casts
// would otherwise be responsible for
diff --git a/src/tools/clippy/tests/ui/trim_split_whitespace.fixed b/src/tools/clippy/tests/ui/trim_split_whitespace.fixed
index e4d352f73..7909b319d 100644
--- a/src/tools/clippy/tests/ui/trim_split_whitespace.fixed
+++ b/src/tools/clippy/tests/ui/trim_split_whitespace.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::trim_split_whitespace)]
#![allow(clippy::let_unit_value)]
diff --git a/src/tools/clippy/tests/ui/trim_split_whitespace.rs b/src/tools/clippy/tests/ui/trim_split_whitespace.rs
index f98451a98..0cf58979f 100644
--- a/src/tools/clippy/tests/ui/trim_split_whitespace.rs
+++ b/src/tools/clippy/tests/ui/trim_split_whitespace.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::trim_split_whitespace)]
#![allow(clippy::let_unit_value)]
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 c0af011d3..486155831 100644
--- a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs
+++ b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs
@@ -1,5 +1,5 @@
-// normalize-stderr-test "\(\d+ byte\)" -> "(N byte)"
-// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)"
+//@normalize-stderr-test: "\(\d+ byte\)" -> "(N byte)"
+//@normalize-stderr-test: "\(limit: \d+ byte\)" -> "(limit: N byte)"
#![deny(clippy::trivially_copy_pass_by_ref)]
#![allow(
clippy::disallowed_names,
diff --git a/src/tools/clippy/tests/ui/try_err.fixed b/src/tools/clippy/tests/ui/try_err.fixed
index dc497b169..dc773ad4b 100644
--- a/src/tools/clippy/tests/ui/try_err.fixed
+++ b/src/tools/clippy/tests/ui/try_err.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![deny(clippy::try_err)]
#![allow(clippy::unnecessary_wraps, clippy::needless_question_mark)]
diff --git a/src/tools/clippy/tests/ui/try_err.rs b/src/tools/clippy/tests/ui/try_err.rs
index 86aeb75cd..7a7433a7e 100644
--- a/src/tools/clippy/tests/ui/try_err.rs
+++ b/src/tools/clippy/tests/ui/try_err.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macros.rs
+//@run-rustfix
+//@aux-build:proc_macros.rs
#![deny(clippy::try_err)]
#![allow(clippy::unnecessary_wraps, clippy::needless_question_mark)]
diff --git a/src/tools/clippy/tests/ui/types.fixed b/src/tools/clippy/tests/ui/types.fixed
index 417da42ed..4a2616a7a 100644
--- a/src/tools/clippy/tests/ui/types.fixed
+++ b/src/tools/clippy/tests/ui/types.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, unused_variables)]
#![warn(clippy::cast_lossless)]
diff --git a/src/tools/clippy/tests/ui/types.rs b/src/tools/clippy/tests/ui/types.rs
index b16e9e538..5e0917907 100644
--- a/src/tools/clippy/tests/ui/types.rs
+++ b/src/tools/clippy/tests/ui/types.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code, unused_variables)]
#![warn(clippy::cast_lossless)]
diff --git a/src/tools/clippy/tests/ui/unchecked_duration_subtraction.fixed b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.fixed
index a0e49a8be..757d15921 100644
--- a/src/tools/clippy/tests/ui/unchecked_duration_subtraction.fixed
+++ b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unchecked_duration_subtraction)]
use std::time::{Duration, Instant};
diff --git a/src/tools/clippy/tests/ui/unchecked_duration_subtraction.rs b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.rs
index a14a7ea57..da7faab67 100644
--- a/src/tools/clippy/tests/ui/unchecked_duration_subtraction.rs
+++ b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unchecked_duration_subtraction)]
use std::time::{Duration, Instant};
diff --git a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs b/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs
index c05eb447b..229d15085 100644
--- a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs
+++ b/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macro_unsafe.rs
+//@aux-build:proc_macro_unsafe.rs
#![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)]
#![allow(clippy::let_unit_value, clippy::missing_safety_doc)]
diff --git a/src/tools/clippy/tests/ui/unicode.fixed b/src/tools/clippy/tests/ui/unicode.fixed
index 94b472345..910968afa 100644
--- a/src/tools/clippy/tests/ui/unicode.fixed
+++ b/src/tools/clippy/tests/ui/unicode.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// compile-flags: --test
+//@run-rustfix
+//@compile-flags: --test
#![allow(dead_code)]
#[warn(clippy::invisible_characters)]
diff --git a/src/tools/clippy/tests/ui/unicode.rs b/src/tools/clippy/tests/ui/unicode.rs
index 6ad0b255b..bc4b84d34 100644
--- a/src/tools/clippy/tests/ui/unicode.rs
+++ b/src/tools/clippy/tests/ui/unicode.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// compile-flags: --test
+//@run-rustfix
+//@compile-flags: --test
#![allow(dead_code)]
#[warn(clippy::invisible_characters)]
diff --git a/src/tools/clippy/tests/ui/uninit.rs b/src/tools/clippy/tests/ui/uninit.rs
index c996de894..2d567630e 100644
--- a/src/tools/clippy/tests/ui/uninit.rs
+++ b/src/tools/clippy/tests/ui/uninit.rs
@@ -17,10 +17,10 @@ fn main() {
// This is OK, because `MaybeUninit` allows uninitialized data.
let _: MaybeUninit<usize> = unsafe { MaybeUninit::uninit().assume_init() };
- // This is OK, because all constitutent types are uninit-compatible.
+ // This is OK, because all constituent types are uninit-compatible.
let _: (MaybeUninit<usize>, MaybeUninit<bool>) = unsafe { MaybeUninit::uninit().assume_init() };
- // This is OK, because all constitutent types are uninit-compatible.
+ // This is OK, because all constituent types are uninit-compatible.
let _: (MaybeUninit<usize>, [MaybeUninit<bool>; 2]) = unsafe { MaybeUninit::uninit().assume_init() };
// This is OK, because our own MaybeUninit is just as fine as the one from core.
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.fixed b/src/tools/clippy/tests/ui/uninlined_format_args.fixed
index 3122081a4..e25d123dd 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args.fixed
+++ b/src/tools/clippy/tests/ui/uninlined_format_args.fixed
@@ -1,5 +1,5 @@
-// aux-build:proc_macros.rs
-// run-rustfix
+//@aux-build:proc_macros.rs
+//@run-rustfix
#![warn(clippy::uninlined_format_args)]
#![allow(named_arguments_used_positionally, unused)]
#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.rs b/src/tools/clippy/tests/ui/uninlined_format_args.rs
index b153ef256..6793ec244 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args.rs
+++ b/src/tools/clippy/tests/ui/uninlined_format_args.rs
@@ -1,5 +1,5 @@
-// aux-build:proc_macros.rs
-// run-rustfix
+//@aux-build:proc_macros.rs
+//@run-rustfix
#![warn(clippy::uninlined_format_args)]
#![allow(named_arguments_used_positionally, unused)]
#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed
index 52b5343c3..559050b3d 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed
+++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed
@@ -1,7 +1,7 @@
-// revisions: edition2018 edition2021
-//[edition2018] edition:2018
-//[edition2021] edition:2021
-// run-rustfix
+//@revisions: edition2018 edition2021
+//@[edition2018] edition:2018
+//@[edition2021] edition:2021
+//@run-rustfix
#![warn(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed
index ee72065e2..3a753b49c 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed
+++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed
@@ -1,7 +1,7 @@
-// revisions: edition2018 edition2021
-//[edition2018] edition:2018
-//[edition2021] edition:2021
-// run-rustfix
+//@revisions: edition2018 edition2021
+//@[edition2018] edition:2018
+//@[edition2021] edition:2021
+//@run-rustfix
#![warn(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs b/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs
index b4a0a0f49..83fbb9afd 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs
+++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs
@@ -1,7 +1,7 @@
-// revisions: edition2018 edition2021
-//[edition2018] edition:2018
-//[edition2021] edition:2021
-// run-rustfix
+//@revisions: edition2018 edition2021
+//@[edition2018] edition:2018
+//@[edition2021] edition:2021
+//@run-rustfix
#![warn(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/unit_arg.rs b/src/tools/clippy/tests/ui/unit_arg.rs
index 674ae4f1d..d082063c8 100644
--- a/src/tools/clippy/tests/ui/unit_arg.rs
+++ b/src/tools/clippy/tests/ui/unit_arg.rs
@@ -1,4 +1,4 @@
-// aux-build: proc_macros.rs
+//@aux-build: proc_macros.rs
#![warn(clippy::unit_arg)]
#![allow(unused_must_use, unused_variables)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.fixed b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.fixed
index 5787471a3..8c065115a 100644
--- a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.fixed
+++ b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unit_arg)]
#![allow(unused_must_use, unused_variables)]
#![allow(clippy::no_effect, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs
index 6a42c2ccf..af166b56f 100644
--- a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs
+++ b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unit_arg)]
#![allow(unused_must_use, unused_variables)]
#![allow(clippy::no_effect, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed b/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed
index 4249ff8a9..49c0e4dc7 100644
--- a/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed
+++ b/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::pedantic)]
// Should suggest lowercase
@@ -10,7 +10,7 @@
#[warn(clippy::unnecessary_cast)]
#[warn(clippy::useless_transmute)]
// Shouldn't suggest rustc lint name(`dead_code`)
-#[warn(clippy::drop_copy)]
+#[warn(clippy::eq_op)]
// Shouldn't suggest removed/deprecated clippy lint name(`unused_collect`)
#[warn(clippy::unused_self)]
// Shouldn't suggest renamed clippy lint name(`const_static_lifetime`)
diff --git a/src/tools/clippy/tests/ui/unknown_clippy_lints.rs b/src/tools/clippy/tests/ui/unknown_clippy_lints.rs
index 5db345f54..b60042923 100644
--- a/src/tools/clippy/tests/ui/unknown_clippy_lints.rs
+++ b/src/tools/clippy/tests/ui/unknown_clippy_lints.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::pedantic)]
// Should suggest lowercase
diff --git a/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr b/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr
index 421bf5ffa..584c42893 100644
--- a/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr
+++ b/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr
@@ -34,7 +34,7 @@ error: unknown lint: `clippy::dead_cod`
--> $DIR/unknown_clippy_lints.rs:13:8
|
LL | #[warn(clippy::dead_cod)]
- | ^^^^^^^^^^^^^^^^ help: did you mean: `clippy::drop_copy`
+ | ^^^^^^^^^^^^^^^^ help: did you mean: `clippy::eq_op`
error: unknown lint: `clippy::unused_colle`
--> $DIR/unknown_clippy_lints.rs:15:8
diff --git a/src/tools/clippy/tests/ui/unnecessary_box_returns.rs b/src/tools/clippy/tests/ui/unnecessary_box_returns.rs
index fe60d9297..ce7cc2e97 100644
--- a/src/tools/clippy/tests/ui/unnecessary_box_returns.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_box_returns.rs
@@ -54,6 +54,16 @@ fn string() -> String {
String::from("Hello, world")
}
+struct Huge([u8; 500]);
+struct HasHuge(Box<Huge>);
+
+impl HasHuge {
+ // don't lint: The size of `Huge` is very large
+ fn into_huge(self) -> Box<Huge> {
+ self.0
+ }
+}
+
fn main() {
// don't lint: this is a closure
let a = || -> Box<usize> { Box::new(5) };
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.fixed b/src/tools/clippy/tests/ui/unnecessary_cast.fixed
index 2f7e2997e..bcc231ea7 100644
--- a/src/tools/clippy/tests/ui/unnecessary_cast.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_cast.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unnecessary_cast)]
#![allow(
unused_must_use,
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.rs b/src/tools/clippy/tests/ui/unnecessary_cast.rs
index 54dd46ba5..282b2f128 100644
--- a/src/tools/clippy/tests/ui/unnecessary_cast.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_cast.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unnecessary_cast)]
#![allow(
unused_must_use,
diff --git a/src/tools/clippy/tests/ui/unnecessary_clone.rs b/src/tools/clippy/tests/ui/unnecessary_clone.rs
index 8b1629b19..7ceed3c75 100644
--- a/src/tools/clippy/tests/ui/unnecessary_clone.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_clone.rs
@@ -42,14 +42,6 @@ fn clone_on_copy_generic<T: Copy>(t: T) {
Some(t).clone();
}
-fn clone_on_double_ref() {
- let x = vec![1];
- let y = &&x;
- let z: &Vec<_> = y.clone();
-
- println!("{:p} {:p}", *y, z);
-}
-
mod many_derefs {
struct A;
struct B;
@@ -84,11 +76,6 @@ mod many_derefs {
let _: E = a.clone();
let _: E = *****a;
}
-
- fn check(mut encoded: &[u8]) {
- let _ = &mut encoded.clone();
- let _ = &encoded.clone();
- }
}
mod issue2076 {
diff --git a/src/tools/clippy/tests/ui/unnecessary_clone.stderr b/src/tools/clippy/tests/ui/unnecessary_clone.stderr
index 6022d9fa4..5686ab6b4 100644
--- a/src/tools/clippy/tests/ui/unnecessary_clone.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_clone.stderr
@@ -44,63 +44,17 @@ error: using `clone` on type `Option<T>` which implements the `Copy` trait
LL | Some(t).clone();
| ^^^^^^^^^^^^^^^ help: try removing the `clone` call: `Some(t)`
-error: using `clone` on a double-reference; this will copy the reference of type `&Vec<i32>` instead of cloning the inner type
- --> $DIR/unnecessary_clone.rs:48:22
- |
-LL | let z: &Vec<_> = y.clone();
- | ^^^^^^^^^
- |
- = note: `#[deny(clippy::clone_double_ref)]` on by default
-help: try dereferencing it
- |
-LL | let z: &Vec<_> = &(*y).clone();
- | ~~~~~~~~~~~~~
-help: or try being explicit if you are sure, that you want to clone a reference
- |
-LL | let z: &Vec<_> = <&Vec<i32>>::clone(y);
- | ~~~~~~~~~~~~~~~~~~~~~
-
error: using `clone` on type `E` which implements the `Copy` trait
- --> $DIR/unnecessary_clone.rs:84:20
+ --> $DIR/unnecessary_clone.rs:76:20
|
LL | let _: E = a.clone();
| ^^^^^^^^^ help: try dereferencing it: `*****a`
-error: using `clone` on a double-reference; this will copy the reference of type `&[u8]` instead of cloning the inner type
- --> $DIR/unnecessary_clone.rs:89:22
- |
-LL | let _ = &mut encoded.clone();
- | ^^^^^^^^^^^^^^^
- |
-help: try dereferencing it
- |
-LL | let _ = &mut &(*encoded).clone();
- | ~~~~~~~~~~~~~~~~~~~
-help: or try being explicit if you are sure, that you want to clone a reference
- |
-LL | let _ = &mut <&[u8]>::clone(encoded);
- | ~~~~~~~~~~~~~~~~~~~~~~~
-
-error: using `clone` on a double-reference; this will copy the reference of type `&[u8]` instead of cloning the inner type
- --> $DIR/unnecessary_clone.rs:90:18
- |
-LL | let _ = &encoded.clone();
- | ^^^^^^^^^^^^^^^
- |
-help: try dereferencing it
- |
-LL | let _ = &&(*encoded).clone();
- | ~~~~~~~~~~~~~~~~~~~
-help: or try being explicit if you are sure, that you want to clone a reference
- |
-LL | let _ = &<&[u8]>::clone(encoded);
- | ~~~~~~~~~~~~~~~~~~~~~~~
-
error: using `.clone()` on a ref-counted pointer
- --> $DIR/unnecessary_clone.rs:108:14
+ --> $DIR/unnecessary_clone.rs:95:14
|
LL | Some(try_opt!(Some(rc)).clone())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `Rc::<u8>::clone(&try_opt!(Some(rc)))`
-error: aborting due to 12 previous errors
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/unnecessary_fold.fixed b/src/tools/clippy/tests/ui/unnecessary_fold.fixed
index 52300a3b6..2bed14973 100644
--- a/src/tools/clippy/tests/ui/unnecessary_fold.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_fold.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_fold.rs b/src/tools/clippy/tests/ui/unnecessary_fold.rs
index 4028d80c0..a3cec8ea3 100644
--- a/src/tools/clippy/tests/ui/unnecessary_fold.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_fold.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_iter_cloned.fixed b/src/tools/clippy/tests/ui/unnecessary_iter_cloned.fixed
index e01e9f07b..a0f8dd1a2 100644
--- a/src/tools/clippy/tests/ui/unnecessary_iter_cloned.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_iter_cloned.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_assignments)]
#![warn(clippy::unnecessary_to_owned)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_iter_cloned.rs b/src/tools/clippy/tests/ui/unnecessary_iter_cloned.rs
index 6ef2966c8..98f2dfe75 100644
--- a/src/tools/clippy/tests/ui/unnecessary_iter_cloned.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_iter_cloned.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_assignments)]
#![warn(clippy::unnecessary_to_owned)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_join.fixed b/src/tools/clippy/tests/ui/unnecessary_join.fixed
index 347953960..e102df625 100644
--- a/src/tools/clippy/tests/ui/unnecessary_join.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_join.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unnecessary_join)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_join.rs b/src/tools/clippy/tests/ui/unnecessary_join.rs
index 344918cd2..b87c15bc1 100644
--- a/src/tools/clippy/tests/ui/unnecessary_join.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_join.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unnecessary_join)]
#![allow(clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
index 3b93800f8..c3728886e 100644
--- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build: proc_macros.rs
+//@run-rustfix
+//@aux-build: proc_macros.rs
#![warn(clippy::unnecessary_lazy_evaluations)]
#![allow(clippy::redundant_closure)]
#![allow(clippy::bind_instead_of_map)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs
index 2851c0c51..76e50fa5b 100644
--- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build: proc_macros.rs
+//@run-rustfix
+//@aux-build: proc_macros.rs
#![warn(clippy::unnecessary_lazy_evaluations)]
#![allow(clippy::redundant_closure)]
#![allow(clippy::bind_instead_of_map)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_operation.fixed b/src/tools/clippy/tests/ui/unnecessary_operation.fixed
index b046694f8..fbd2d3459 100644
--- a/src/tools/clippy/tests/ui/unnecessary_operation.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_operation.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(
clippy::deref_addrof,
diff --git a/src/tools/clippy/tests/ui/unnecessary_operation.rs b/src/tools/clippy/tests/ui/unnecessary_operation.rs
index 9ed9679e9..b45298a6d 100644
--- a/src/tools/clippy/tests/ui/unnecessary_operation.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_operation.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(
clippy::deref_addrof,
diff --git a/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.fixed b/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.fixed
index 40052c410..af12fd1d6 100644
--- a/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unnecessary_owned_empty_strings)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.rs b/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.rs
index 2304dff51..a460b21af 100644
--- a/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_owned_empty_strings.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unnecessary_owned_empty_strings)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_self_imports.fixed b/src/tools/clippy/tests/ui/unnecessary_self_imports.fixed
index 1185eaa1d..7fc978d3e 100644
--- a/src/tools/clippy/tests/ui/unnecessary_self_imports.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_self_imports.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unnecessary_self_imports)]
#![allow(unused_imports, dead_code)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_self_imports.rs b/src/tools/clippy/tests/ui/unnecessary_self_imports.rs
index 56bfbc094..02424bc12 100644
--- a/src/tools/clippy/tests/ui/unnecessary_self_imports.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_self_imports.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unnecessary_self_imports)]
#![allow(unused_imports, dead_code)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_sort_by.fixed b/src/tools/clippy/tests/ui/unnecessary_sort_by.fixed
index 21e2da474..165cabd82 100644
--- a/src/tools/clippy/tests/ui/unnecessary_sort_by.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_sort_by.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::stable_sort_primitive)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_sort_by.rs b/src/tools/clippy/tests/ui/unnecessary_sort_by.rs
index 3365bf6e1..8a2158d5a 100644
--- a/src/tools/clippy/tests/ui/unnecessary_sort_by.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_sort_by.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::stable_sort_primitive)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_struct_initialization.fixed b/src/tools/clippy/tests/ui/unnecessary_struct_initialization.fixed
index b47129e4a..bdf746cf2 100644
--- a/src/tools/clippy/tests/ui/unnecessary_struct_initialization.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_struct_initialization.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::unnecessary_struct_initialization)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_struct_initialization.rs b/src/tools/clippy/tests/ui/unnecessary_struct_initialization.rs
index 63b11c626..7271e2f95 100644
--- a/src/tools/clippy/tests/ui/unnecessary_struct_initialization.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_struct_initialization.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused)]
#![warn(clippy::unnecessary_struct_initialization)]
diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
index 345f6d604..08733906b 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
@@ -1,7 +1,7 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::needless_borrow, clippy::ptr_arg)]
-#![warn(clippy::unnecessary_to_owned)]
+#![warn(clippy::unnecessary_to_owned, clippy::redundant_clone)]
use std::borrow::Cow;
use std::ffi::{CStr, CString, OsStr, OsString};
diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
index 7eb53df39..e3589ea0d 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
@@ -1,7 +1,7 @@
-// run-rustfix
+//@run-rustfix
#![allow(clippy::needless_borrow, clippy::ptr_arg)]
-#![warn(clippy::unnecessary_to_owned)]
+#![warn(clippy::unnecessary_to_owned, clippy::redundant_clone)]
use std::borrow::Cow;
use std::ffi::{CStr, CString, OsStr, OsString};
diff --git a/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs b/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs
index 431093ab3..373b18470 100644
--- a/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macros.rs
+//@aux-build:proc_macros.rs
#![allow(clippy::let_unit_value)]
#![warn(clippy::unnecessary_safety_doc)]
diff --git a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.fixed b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.fixed
index 12c3461c9..16c2de760 100644
--- a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.fixed
+++ b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(stmt_expr_attributes)]
#![deny(clippy::unneeded_wildcard_pattern)]
diff --git a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.rs b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.rs
index 4ac01d5d2..9d9eae1d9 100644
--- a/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.rs
+++ b/src/tools/clippy/tests/ui/unneeded_wildcard_pattern.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(stmt_expr_attributes)]
#![deny(clippy::unneeded_wildcard_pattern)]
diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns.fixed b/src/tools/clippy/tests/ui/unnested_or_patterns.fixed
index 0a8e7b34d..8ec35ba4e 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns.fixed
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns.rs b/src/tools/clippy/tests/ui/unnested_or_patterns.rs
index 2c454adfe..efdb91b24 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns.rs
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns2.fixed b/src/tools/clippy/tests/ui/unnested_or_patterns2.fixed
index d3539d798..de40e9367 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns2.fixed
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns2.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns2.rs b/src/tools/clippy/tests/ui/unnested_or_patterns2.rs
index 9cea5cdea..87f66d26c 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns2.rs
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns2.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
diff --git a/src/tools/clippy/tests/ui/unreadable_literal.fixed b/src/tools/clippy/tests/ui/unreadable_literal.fixed
index 13e5feb19..f5e87648a 100644
--- a/src/tools/clippy/tests/ui/unreadable_literal.fixed
+++ b/src/tools/clippy/tests/ui/unreadable_literal.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unreadable_literal)]
#![allow(unused_tuple_struct_fields)]
diff --git a/src/tools/clippy/tests/ui/unreadable_literal.rs b/src/tools/clippy/tests/ui/unreadable_literal.rs
index 82f04e7ce..426bdf7d7 100644
--- a/src/tools/clippy/tests/ui/unreadable_literal.rs
+++ b/src/tools/clippy/tests/ui/unreadable_literal.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unreadable_literal)]
#![allow(unused_tuple_struct_fields)]
diff --git a/src/tools/clippy/tests/ui/unseparated_prefix_literals.fixed b/src/tools/clippy/tests/ui/unseparated_prefix_literals.fixed
index f0c2ba7cc..b6241612d 100644
--- a/src/tools/clippy/tests/ui/unseparated_prefix_literals.fixed
+++ b/src/tools/clippy/tests/ui/unseparated_prefix_literals.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macro_derive.rs
+//@run-rustfix
+//@aux-build:proc_macro_derive.rs
#![warn(clippy::unseparated_literal_suffix)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/unseparated_prefix_literals.rs b/src/tools/clippy/tests/ui/unseparated_prefix_literals.rs
index f44880b41..ae583f4bd 100644
--- a/src/tools/clippy/tests/ui/unseparated_prefix_literals.rs
+++ b/src/tools/clippy/tests/ui/unseparated_prefix_literals.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macro_derive.rs
+//@run-rustfix
+//@aux-build:proc_macro_derive.rs
#![warn(clippy::unseparated_literal_suffix)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/unused_rounding.fixed b/src/tools/clippy/tests/ui/unused_rounding.fixed
index f6f734c05..f02b55502 100644
--- a/src/tools/clippy/tests/ui/unused_rounding.fixed
+++ b/src/tools/clippy/tests/ui/unused_rounding.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unused_rounding)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/unused_rounding.rs b/src/tools/clippy/tests/ui/unused_rounding.rs
index a0267d814..c7bd4906d 100644
--- a/src/tools/clippy/tests/ui/unused_rounding.rs
+++ b/src/tools/clippy/tests/ui/unused_rounding.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unused_rounding)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/unused_unit.fixed b/src/tools/clippy/tests/ui/unused_unit.fixed
index 3dd640b86..7b8f7847d 100644
--- a/src/tools/clippy/tests/ui/unused_unit.fixed
+++ b/src/tools/clippy/tests/ui/unused_unit.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
// The output for humans should just highlight the whole span without showing
// the suggested replacement, but we also want to test that suggested
diff --git a/src/tools/clippy/tests/ui/unused_unit.rs b/src/tools/clippy/tests/ui/unused_unit.rs
index bddecf06f..fdde1ecad 100644
--- a/src/tools/clippy/tests/ui/unused_unit.rs
+++ b/src/tools/clippy/tests/ui/unused_unit.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
// The output for humans should just highlight the whole span without showing
// the suggested replacement, but we also want to test that suggested
diff --git a/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed b/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed
index 84f779569..59a0ca3f1 100644
--- a/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed
+++ b/src/tools/clippy/tests/ui/unwrap_or_else_default.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unwrap_or_else_default)]
#![allow(dead_code)]
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 1735bd580..97cafa336 100644
--- a/src/tools/clippy/tests/ui/unwrap_or_else_default.rs
+++ b/src/tools/clippy/tests/ui/unwrap_or_else_default.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::unwrap_or_else_default)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/use_self.fixed b/src/tools/clippy/tests/ui/use_self.fixed
index 3ac621731..89ea14759 100644
--- a/src/tools/clippy/tests/ui/use_self.fixed
+++ b/src/tools/clippy/tests/ui/use_self.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macro_derive.rs
+//@run-rustfix
+//@aux-build:proc_macro_derive.rs
#![warn(clippy::use_self)]
#![allow(dead_code, unreachable_code)]
diff --git a/src/tools/clippy/tests/ui/use_self.rs b/src/tools/clippy/tests/ui/use_self.rs
index 9dc5d1e3f..49e5bcb7e 100644
--- a/src/tools/clippy/tests/ui/use_self.rs
+++ b/src/tools/clippy/tests/ui/use_self.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macro_derive.rs
+//@run-rustfix
+//@aux-build:proc_macro_derive.rs
#![warn(clippy::use_self)]
#![allow(dead_code, unreachable_code)]
diff --git a/src/tools/clippy/tests/ui/use_self_trait.fixed b/src/tools/clippy/tests/ui/use_self_trait.fixed
index 4e779308d..20138a29f 100644
--- a/src/tools/clippy/tests/ui/use_self_trait.fixed
+++ b/src/tools/clippy/tests/ui/use_self_trait.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::use_self)]
#![allow(dead_code)]
@@ -33,7 +33,7 @@ impl SelfTrait for Bad {
fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
fn vals(_: Self) -> Self {
- Self::default()
+ Self
}
}
@@ -70,7 +70,7 @@ impl SelfTrait for Good {
fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
fn vals(_: Self) -> Self {
- Self::default()
+ Self
}
}
diff --git a/src/tools/clippy/tests/ui/use_self_trait.rs b/src/tools/clippy/tests/ui/use_self_trait.rs
index 325dc73b2..bf697b01a 100644
--- a/src/tools/clippy/tests/ui/use_self_trait.rs
+++ b/src/tools/clippy/tests/ui/use_self_trait.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::use_self)]
#![allow(dead_code)]
@@ -33,7 +33,7 @@ impl SelfTrait for Bad {
fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {}
fn vals(_: Bad) -> Bad {
- Bad::default()
+ Bad
}
}
@@ -70,7 +70,7 @@ impl SelfTrait for Good {
fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
fn vals(_: Self) -> Self {
- Self::default()
+ Self
}
}
diff --git a/src/tools/clippy/tests/ui/use_self_trait.stderr b/src/tools/clippy/tests/ui/use_self_trait.stderr
index 090729b9c..6257f802d 100644
--- a/src/tools/clippy/tests/ui/use_self_trait.stderr
+++ b/src/tools/clippy/tests/ui/use_self_trait.stderr
@@ -63,7 +63,7 @@ LL | fn vals(_: Bad) -> Bad {
error: unnecessary structure name repetition
--> $DIR/use_self_trait.rs:36:9
|
-LL | Bad::default()
+LL | Bad
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
diff --git a/src/tools/clippy/tests/ui/used_underscore_binding.rs b/src/tools/clippy/tests/ui/used_underscore_binding.rs
index 8c29e15b1..c672eff1c 100644
--- a/src/tools/clippy/tests/ui/used_underscore_binding.rs
+++ b/src/tools/clippy/tests/ui/used_underscore_binding.rs
@@ -1,4 +1,4 @@
-// aux-build:proc_macro_derive.rs
+//@aux-build:proc_macro_derive.rs
#![feature(rustc_private)]
#![warn(clippy::all)]
#![warn(clippy::used_underscore_binding)]
diff --git a/src/tools/clippy/tests/ui/useless_asref.fixed b/src/tools/clippy/tests/ui/useless_asref.fixed
index 38e4b9201..490d36ae6 100644
--- a/src/tools/clippy/tests/ui/useless_asref.fixed
+++ b/src/tools/clippy/tests/ui/useless_asref.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::useless_asref)]
#![allow(clippy::explicit_auto_deref, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/useless_asref.rs b/src/tools/clippy/tests/ui/useless_asref.rs
index f1e83f9d3..f2681af92 100644
--- a/src/tools/clippy/tests/ui/useless_asref.rs
+++ b/src/tools/clippy/tests/ui/useless_asref.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::useless_asref)]
#![allow(clippy::explicit_auto_deref, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/useless_attribute.fixed b/src/tools/clippy/tests/ui/useless_attribute.fixed
index 871e4fb5c..de6660c95 100644
--- a/src/tools/clippy/tests/ui/useless_attribute.fixed
+++ b/src/tools/clippy/tests/ui/useless_attribute.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macro_derive.rs
+//@run-rustfix
+//@aux-build:proc_macro_derive.rs
#![allow(unused)]
#![warn(clippy::useless_attribute)]
diff --git a/src/tools/clippy/tests/ui/useless_attribute.rs b/src/tools/clippy/tests/ui/useless_attribute.rs
index cb50736ba..8de4331e8 100644
--- a/src/tools/clippy/tests/ui/useless_attribute.rs
+++ b/src/tools/clippy/tests/ui/useless_attribute.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:proc_macro_derive.rs
+//@run-rustfix
+//@aux-build:proc_macro_derive.rs
#![allow(unused)]
#![warn(clippy::useless_attribute)]
diff --git a/src/tools/clippy/tests/ui/useless_conversion.fixed b/src/tools/clippy/tests/ui/useless_conversion.fixed
index 94b206d8e..c16caa38f 100644
--- a/src/tools/clippy/tests/ui/useless_conversion.fixed
+++ b/src/tools/clippy/tests/ui/useless_conversion.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::useless_conversion)]
#![allow(clippy::unnecessary_wraps)]
@@ -33,6 +33,11 @@ fn test_issue_3913() -> Result<(), std::io::Error> {
Ok(())
}
+fn dont_lint_on_type_alias() {
+ type A = i32;
+ _ = A::from(0i32);
+}
+
fn dont_lint_into_iter_on_immutable_local_implementing_iterator_in_expr() {
let text = "foo\r\nbar\n\nbaz\n";
let lines = text.lines();
@@ -106,6 +111,7 @@ fn main() {
test_questionmark().unwrap();
test_issue_3913().unwrap();
+ dont_lint_on_type_alias();
dont_lint_into_iter_on_immutable_local_implementing_iterator_in_expr();
lint_into_iter_on_mutable_local_implementing_iterator_in_expr();
lint_into_iter_on_expr_implementing_iterator();
diff --git a/src/tools/clippy/tests/ui/useless_conversion.rs b/src/tools/clippy/tests/ui/useless_conversion.rs
index c7ae92794..c75a2bce4 100644
--- a/src/tools/clippy/tests/ui/useless_conversion.rs
+++ b/src/tools/clippy/tests/ui/useless_conversion.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![deny(clippy::useless_conversion)]
#![allow(clippy::unnecessary_wraps)]
@@ -33,6 +33,11 @@ fn test_issue_3913() -> Result<(), std::io::Error> {
Ok(())
}
+fn dont_lint_on_type_alias() {
+ type A = i32;
+ _ = A::from(0i32);
+}
+
fn dont_lint_into_iter_on_immutable_local_implementing_iterator_in_expr() {
let text = "foo\r\nbar\n\nbaz\n";
let lines = text.lines();
@@ -106,6 +111,7 @@ fn main() {
test_questionmark().unwrap();
test_issue_3913().unwrap();
+ dont_lint_on_type_alias();
dont_lint_into_iter_on_immutable_local_implementing_iterator_in_expr();
lint_into_iter_on_mutable_local_implementing_iterator_in_expr();
lint_into_iter_on_expr_implementing_iterator();
diff --git a/src/tools/clippy/tests/ui/useless_conversion.stderr b/src/tools/clippy/tests/ui/useless_conversion.stderr
index be067c684..4dca3aac5 100644
--- a/src/tools/clippy/tests/ui/useless_conversion.stderr
+++ b/src/tools/clippy/tests/ui/useless_conversion.stderr
@@ -23,97 +23,97 @@ LL | let _: i32 = 0i32.into();
| ^^^^^^^^^^^ help: consider removing `.into()`: `0i32`
error: useless conversion to the same type: `std::str::Lines<'_>`
- --> $DIR/useless_conversion.rs:45:22
+ --> $DIR/useless_conversion.rs:50:22
|
LL | if Some("ok") == lines.into_iter().next() {}
| ^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `lines`
error: useless conversion to the same type: `std::str::Lines<'_>`
- --> $DIR/useless_conversion.rs:50:21
+ --> $DIR/useless_conversion.rs:55:21
|
LL | let mut lines = text.lines().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `text.lines()`
error: useless conversion to the same type: `std::str::Lines<'_>`
- --> $DIR/useless_conversion.rs:56:22
+ --> $DIR/useless_conversion.rs:61:22
|
LL | if Some("ok") == text.lines().into_iter().next() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `text.lines()`
error: useless conversion to the same type: `std::ops::Range<i32>`
- --> $DIR/useless_conversion.rs:62:13
+ --> $DIR/useless_conversion.rs:67:13
|
LL | let _ = NUMBERS.into_iter().next();
| ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `NUMBERS`
error: useless conversion to the same type: `std::ops::Range<i32>`
- --> $DIR/useless_conversion.rs:67:17
+ --> $DIR/useless_conversion.rs:72:17
|
LL | let mut n = NUMBERS.into_iter();
| ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `NUMBERS`
error: useless conversion to the same type: `std::string::String`
- --> $DIR/useless_conversion.rs:128:21
+ --> $DIR/useless_conversion.rs:134:21
|
LL | let _: String = "foo".to_string().into();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `"foo".to_string()`
error: useless conversion to the same type: `std::string::String`
- --> $DIR/useless_conversion.rs:129:21
+ --> $DIR/useless_conversion.rs:135:21
|
LL | let _: String = From::from("foo".to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `From::from()`: `"foo".to_string()`
error: useless conversion to the same type: `std::string::String`
- --> $DIR/useless_conversion.rs:130:13
+ --> $DIR/useless_conversion.rs:136:13
|
LL | let _ = String::from("foo".to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `"foo".to_string()`
error: useless conversion to the same type: `std::string::String`
- --> $DIR/useless_conversion.rs:131:13
+ --> $DIR/useless_conversion.rs:137:13
|
LL | let _ = String::from(format!("A: {:04}", 123));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `format!("A: {:04}", 123)`
error: useless conversion to the same type: `std::str::Lines<'_>`
- --> $DIR/useless_conversion.rs:132:13
+ --> $DIR/useless_conversion.rs:138:13
|
LL | let _ = "".lines().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()`
error: useless conversion to the same type: `std::vec::IntoIter<i32>`
- --> $DIR/useless_conversion.rs:133:13
+ --> $DIR/useless_conversion.rs:139:13
|
LL | let _ = vec![1, 2, 3].into_iter().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![1, 2, 3].into_iter()`
error: useless conversion to the same type: `std::string::String`
- --> $DIR/useless_conversion.rs:134:21
+ --> $DIR/useless_conversion.rs:140:21
|
LL | let _: String = format!("Hello {}", "world").into();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `format!("Hello {}", "world")`
error: useless conversion to the same type: `i32`
- --> $DIR/useless_conversion.rs:139:13
+ --> $DIR/useless_conversion.rs:145:13
|
LL | let _ = i32::from(a + b) * 3;
| ^^^^^^^^^^^^^^^^ help: consider removing `i32::from()`: `(a + b)`
error: useless conversion to the same type: `Foo<'a'>`
- --> $DIR/useless_conversion.rs:145:23
+ --> $DIR/useless_conversion.rs:151:23
|
LL | let _: Foo<'a'> = s2.into();
| ^^^^^^^^^ help: consider removing `.into()`: `s2`
error: useless conversion to the same type: `Foo<'a'>`
- --> $DIR/useless_conversion.rs:147:13
+ --> $DIR/useless_conversion.rs:153:13
|
LL | let _ = Foo::<'a'>::from(s3);
| ^^^^^^^^^^^^^^^^^^^^ help: consider removing `Foo::<'a'>::from()`: `s3`
error: useless conversion to the same type: `std::vec::IntoIter<Foo<'a'>>`
- --> $DIR/useless_conversion.rs:149:13
+ --> $DIR/useless_conversion.rs:155:13
|
LL | let _ = vec![s4, s4, s4].into_iter().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![s4, s4, s4].into_iter()`
diff --git a/src/tools/clippy/tests/ui/vec.fixed b/src/tools/clippy/tests/ui/vec.fixed
index 2518d8049..d77a4dd8e 100644
--- a/src/tools/clippy/tests/ui/vec.fixed
+++ b/src/tools/clippy/tests/ui/vec.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::useless_vec)]
#![allow(clippy::nonstandard_macro_braces, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/vec.rs b/src/tools/clippy/tests/ui/vec.rs
index e1492e2f3..dfed3a29a 100644
--- a/src/tools/clippy/tests/ui/vec.rs
+++ b/src/tools/clippy/tests/ui/vec.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::useless_vec)]
#![allow(clippy::nonstandard_macro_braces, clippy::uninlined_format_args)]
diff --git a/src/tools/clippy/tests/ui/vec_box_sized.fixed b/src/tools/clippy/tests/ui/vec_box_sized.fixed
index a40d91fdb..0d0f710b5 100644
--- a/src/tools/clippy/tests/ui/vec_box_sized.fixed
+++ b/src/tools/clippy/tests/ui/vec_box_sized.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/vec_box_sized.rs b/src/tools/clippy/tests/ui/vec_box_sized.rs
index 843bbb64e..fd3a7543e 100644
--- a/src/tools/clippy/tests/ui/vec_box_sized.rs
+++ b/src/tools/clippy/tests/ui/vec_box_sized.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/while_let_on_iterator.fixed b/src/tools/clippy/tests/ui/while_let_on_iterator.fixed
index 5afa0a89f..c2f216a89 100644
--- a/src/tools/clippy/tests/ui/while_let_on_iterator.fixed
+++ b/src/tools/clippy/tests/ui/while_let_on_iterator.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::while_let_on_iterator)]
#![allow(dead_code, unreachable_code, unused_mut)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/while_let_on_iterator.rs b/src/tools/clippy/tests/ui/while_let_on_iterator.rs
index 3de586c9d..971bd5f0c 100644
--- a/src/tools/clippy/tests/ui/while_let_on_iterator.rs
+++ b/src/tools/clippy/tests/ui/while_let_on_iterator.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![warn(clippy::while_let_on_iterator)]
#![allow(dead_code, unreachable_code, unused_mut)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed
index 293bf75a7..ccb40acfb 100644
--- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed
+++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:non-exhaustive-enum.rs
+//@run-rustfix
+//@aux-build:non-exhaustive-enum.rs
#![deny(clippy::wildcard_enum_match_arm)]
#![allow(dead_code, unreachable_code, unused_variables)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs
index decd86165..3ce00b021 100644
--- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs
+++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs
@@ -1,5 +1,5 @@
-// run-rustfix
-// aux-build:non-exhaustive-enum.rs
+//@run-rustfix
+//@aux-build:non-exhaustive-enum.rs
#![deny(clippy::wildcard_enum_match_arm)]
#![allow(dead_code, unreachable_code, unused_variables)]
#![allow(
diff --git a/src/tools/clippy/tests/ui/wildcard_imports.fixed b/src/tools/clippy/tests/ui/wildcard_imports.fixed
index 0baec6f0b..bd845361f 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports.fixed
+++ b/src/tools/clippy/tests/ui/wildcard_imports.fixed
@@ -1,6 +1,6 @@
-// edition:2015
-// run-rustfix
-// aux-build:wildcard_imports_helper.rs
+//@edition:2015
+//@run-rustfix
+//@aux-build:wildcard_imports_helper.rs
// the 2015 edition here is needed because edition 2018 changed the module system
// (see https://doc.rust-lang.org/edition-guide/rust-2018/path-changes.html) which means the lint
diff --git a/src/tools/clippy/tests/ui/wildcard_imports.rs b/src/tools/clippy/tests/ui/wildcard_imports.rs
index db591d56a..fb51f7bdf 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports.rs
+++ b/src/tools/clippy/tests/ui/wildcard_imports.rs
@@ -1,6 +1,6 @@
-// edition:2015
-// run-rustfix
-// aux-build:wildcard_imports_helper.rs
+//@edition:2015
+//@run-rustfix
+//@aux-build:wildcard_imports_helper.rs
// the 2015 edition here is needed because edition 2018 changed the module system
// (see https://doc.rust-lang.org/edition-guide/rust-2018/path-changes.html) which means the lint
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 6d534a10e..3aea013fb 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed
+++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed
@@ -1,8 +1,8 @@
-// revisions: edition2018 edition2021
-//[edition2018] edition:2018
-//[edition2021] edition:2021
-// run-rustfix
-// aux-build:wildcard_imports_helper.rs
+//@revisions: edition2018 edition2021
+//@[edition2018] edition:2018
+//@[edition2021] edition:2021
+//@run-rustfix
+//@aux-build:wildcard_imports_helper.rs
#![warn(clippy::wildcard_imports)]
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
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 6d534a10e..3aea013fb 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed
+++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed
@@ -1,8 +1,8 @@
-// revisions: edition2018 edition2021
-//[edition2018] edition:2018
-//[edition2021] edition:2021
-// run-rustfix
-// aux-build:wildcard_imports_helper.rs
+//@revisions: edition2018 edition2021
+//@[edition2018] edition:2018
+//@[edition2021] edition:2021
+//@run-rustfix
+//@aux-build:wildcard_imports_helper.rs
#![warn(clippy::wildcard_imports)]
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.rs b/src/tools/clippy/tests/ui/wildcard_imports_2021.rs
index b5ed58e68..40c2d0752 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports_2021.rs
+++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.rs
@@ -1,8 +1,8 @@
-// revisions: edition2018 edition2021
-//[edition2018] edition:2018
-//[edition2021] edition:2021
-// run-rustfix
-// aux-build:wildcard_imports_helper.rs
+//@revisions: edition2018 edition2021
+//@[edition2018] edition:2018
+//@[edition2021] edition:2021
+//@run-rustfix
+//@aux-build:wildcard_imports_helper.rs
#![warn(clippy::wildcard_imports)]
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.stderr b/src/tools/clippy/tests/ui/wildcard_imports_2021.stderr
deleted file mode 100644
index 92f6d3153..000000000
--- a/src/tools/clippy/tests/ui/wildcard_imports_2021.stderr
+++ /dev/null
@@ -1,132 +0,0 @@
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:9:5
- |
-LL | use crate::fn_mod::*;
- | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
- |
- = note: `-D clippy::wildcard-imports` implied by `-D warnings`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:10:5
- |
-LL | use crate::mod_mod::*;
- | ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:11:5
- |
-LL | use crate::multi_fn_mod::*;
- | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:12:5
- |
-LL | use crate::struct_mod::*;
- | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:15:5
- |
-LL | use wildcard_imports_helper::inner::inner_for_self_import::*;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:17:5
- |
-LL | use wildcard_imports_helper::*;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:87:13
- |
-LL | use crate::fn_mod::*;
- | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:93:75
- |
-LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
- | ^ help: try: `inner_extern_foo`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:94:13
- |
-LL | use wildcard_imports_helper::*;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:105:20
- |
-LL | use self::{inner::*, inner2::*};
- | ^^^^^^^^ help: try: `inner::inner_foo`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:105:30
- |
-LL | use self::{inner::*, inner2::*};
- | ^^^^^^^^^ help: try: `inner2::inner_bar`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:112: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:141: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:150:9
- |
-LL | use crate:: in_fn_test:: * ;
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:151:9
- |
-LL | use crate:: fn_mod::
- | _________^
-LL | | *;
- | |_________^ help: try: `crate:: fn_mod::foo`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:162:13
- |
-LL | use super::*;
- | ^^^^^^^^ help: try: `super::foofoo`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:197:17
- |
-LL | use super::*;
- | ^^^^^^^^ help: try: `super::insidefoo`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:205:13
- |
-LL | use crate::super_imports::*;
- | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:214:17
- |
-LL | use super::super::*;
- | ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:223:13
- |
-LL | use super::super::super_imports::*;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
-
-error: usage of wildcard import
- --> $DIR/wildcard_imports_2021.rs:231:13
- |
-LL | use super::*;
- | ^^^^^^^^ help: try: `super::foofoo`
-
-error: aborting due to 21 previous errors
-
diff --git a/src/tools/clippy/tests/ui/wildcard_imports_cfgtest.rs b/src/tools/clippy/tests/ui/wildcard_imports_cfgtest.rs
new file mode 100644
index 000000000..203c4e15b
--- /dev/null
+++ b/src/tools/clippy/tests/ui/wildcard_imports_cfgtest.rs
@@ -0,0 +1,19 @@
+//@compile-flags: --test
+
+#![warn(clippy::wildcard_imports)]
+#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
+
+// Test for #10580, the lint should ignore it because of the crate's cfg test flag.
+
+fn foofoo() {}
+
+mod outer {
+ mod inner {
+ use super::super::*;
+ fn barbar() {
+ let _ = foofoo();
+ }
+ }
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/write_with_newline.rs b/src/tools/clippy/tests/ui/write_with_newline.rs
index b79364c87..35bd9e7f3 100644
--- a/src/tools/clippy/tests/ui/write_with_newline.rs
+++ b/src/tools/clippy/tests/ui/write_with_newline.rs
@@ -1,5 +1,5 @@
// FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934
-// // run-rustfix
+//
#![allow(clippy::write_literal)]
#![warn(clippy::write_with_newline)]
@@ -54,7 +54,7 @@ fn main() {
// Don't warn on CRLF (#4208)
write!(v, "\r\n");
write!(v, "foo\r\n");
- write!(v, "\\r\n"); //~ ERROR
+ write!(v, "\\r\n");
write!(v, "foo\rbar\n");
// Ignore expanded format strings
diff --git a/src/tools/clippy/tests/ui/write_with_newline.stderr b/src/tools/clippy/tests/ui/write_with_newline.stderr
index 2baaea166..9035275b2 100644
--- a/src/tools/clippy/tests/ui/write_with_newline.stderr
+++ b/src/tools/clippy/tests/ui/write_with_newline.stderr
@@ -106,13 +106,13 @@ LL ~ v
error: using `write!()` with a format string that ends in a single newline
--> $DIR/write_with_newline.rs:57:5
|
-LL | write!(v, "/r/n"); //~ ERROR
+LL | write!(v, "/r/n");
| ^^^^^^^^^^^^^^^^^^
|
help: use `writeln!` instead
|
-LL - write!(v, "/r/n"); //~ ERROR
-LL + writeln!(v, "/r"); //~ ERROR
+LL - write!(v, "/r/n");
+LL + writeln!(v, "/r");
|
error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/writeln_empty_string.fixed b/src/tools/clippy/tests/ui/writeln_empty_string.fixed
index e7d94acd1..45dedd9ea 100644
--- a/src/tools/clippy/tests/ui/writeln_empty_string.fixed
+++ b/src/tools/clippy/tests/ui/writeln_empty_string.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_must_use)]
#![warn(clippy::writeln_empty_string)]
diff --git a/src/tools/clippy/tests/ui/writeln_empty_string.rs b/src/tools/clippy/tests/ui/writeln_empty_string.rs
index 662c62f02..3b9f51a15 100644
--- a/src/tools/clippy/tests/ui/writeln_empty_string.rs
+++ b/src/tools/clippy/tests/ui/writeln_empty_string.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![allow(unused_must_use)]
#![warn(clippy::writeln_empty_string)]
diff --git a/src/tools/clippy/tests/ui/zero_ptr.fixed b/src/tools/clippy/tests/ui/zero_ptr.fixed
index 489aa4121..bed38ecaf 100644
--- a/src/tools/clippy/tests/ui/zero_ptr.fixed
+++ b/src/tools/clippy/tests/ui/zero_ptr.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
pub fn foo(_const: *const f32, _mut: *mut i64) {}
fn main() {
diff --git a/src/tools/clippy/tests/ui/zero_ptr.rs b/src/tools/clippy/tests/ui/zero_ptr.rs
index c3b55ef9e..b7b778915 100644
--- a/src/tools/clippy/tests/ui/zero_ptr.rs
+++ b/src/tools/clippy/tests/ui/zero_ptr.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
pub fn foo(_const: *const f32, _mut: *mut i64) {}
fn main() {
diff --git a/src/tools/clippy/tests/ui/zero_ptr_no_std.fixed b/src/tools/clippy/tests/ui/zero_ptr_no_std.fixed
index 8906c7769..7afd80cca 100644
--- a/src/tools/clippy/tests/ui/zero_ptr_no_std.fixed
+++ b/src/tools/clippy/tests/ui/zero_ptr_no_std.fixed
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(lang_items, start, libc)]
#![no_std]
diff --git a/src/tools/clippy/tests/ui/zero_ptr_no_std.rs b/src/tools/clippy/tests/ui/zero_ptr_no_std.rs
index 379c1b18d..05a0587d2 100644
--- a/src/tools/clippy/tests/ui/zero_ptr_no_std.rs
+++ b/src/tools/clippy/tests/ui/zero_ptr_no_std.rs
@@ -1,4 +1,4 @@
-// run-rustfix
+//@run-rustfix
#![feature(lang_items, start, libc)]
#![no_std]
diff --git a/src/tools/clippy/triagebot.toml b/src/tools/clippy/triagebot.toml
index 3f8f6a7b9..c40b71f6c 100644
--- a/src/tools/clippy/triagebot.toml
+++ b/src/tools/clippy/triagebot.toml
@@ -17,9 +17,9 @@ contributing_url = "https://github.com/rust-lang/rust-clippy/blob/master/CONTRIB
[assign.owners]
"/.github" = ["@flip1995"]
+"/book" = ["@flip1995"]
"/util/gh-pages" = ["@xFrednet"]
"*" = [
- "@flip1995",
"@Manishearth",
"@llogiq",
"@giraffate",