summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:25 +0000
commit5363f350887b1e5b5dd21a86f88c8af9d7fea6da (patch)
tree35ca005eb6e0e9a1ba3bb5dbc033209ad445dc17 /src/tools/clippy/tests/ui
parentAdding debian version 1.66.0+dfsg1-1. (diff)
downloadrustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.tar.xz
rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.zip
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui')
-rw-r--r--src/tools/clippy/tests/ui/almost_complete_letter_range.fixed5
-rw-r--r--src/tools/clippy/tests/ui/almost_complete_letter_range.rs5
-rw-r--r--src/tools/clippy/tests/ui/almost_complete_letter_range.stderr26
-rw-r--r--src/tools/clippy/tests/ui/arithmetic_side_effects.rs8
-rw-r--r--src/tools/clippy/tests/ui/arithmetic_side_effects.stderr110
-rw-r--r--src/tools/clippy/tests/ui/async_yields_async.stderr20
-rw-r--r--src/tools/clippy/tests/ui/author/blocks.stdout2
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/doc_unsafe_macros.rs8
-rw-r--r--src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.rs2
-rw-r--r--src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr27
-rw-r--r--src/tools/clippy/tests/ui/bool_to_int_with_if.fixed22
-rw-r--r--src/tools/clippy/tests/ui/bool_to_int_with_if.rs22
-rw-r--r--src/tools/clippy/tests/ui/bool_to_int_with_if.stderr18
-rw-r--r--src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.rs2
-rw-r--r--src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed7
-rw-r--r--src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs7
-rw-r--r--src/tools/clippy/tests/ui/cast_abs_to_unsigned.stderr36
-rw-r--r--src/tools/clippy/tests/ui/cast_lossless_bool.fixed7
-rw-r--r--src/tools/clippy/tests/ui/cast_lossless_bool.rs7
-rw-r--r--src/tools/clippy/tests/ui/cast_lossless_bool.stderr28
-rw-r--r--src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed8
-rw-r--r--src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs8
-rw-r--r--src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr2
-rw-r--r--src/tools/clippy/tests/ui/checked_conversions.fixed7
-rw-r--r--src/tools/clippy/tests/ui/checked_conversions.rs7
-rw-r--r--src/tools/clippy/tests/ui/checked_conversions.stderr34
-rw-r--r--src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed10
-rw-r--r--src/tools/clippy/tests/ui/cloned_instead_of_copied.rs10
-rw-r--r--src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr16
-rw-r--r--src/tools/clippy/tests/ui/cognitive_complexity.rs16
-rw-r--r--src/tools/clippy/tests/ui/cognitive_complexity.stderr18
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-2774.stderr2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-6250.stderr5
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-9746.rs15
-rw-r--r--src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.stderr2
-rw-r--r--src/tools/clippy/tests/ui/crate_level_checks/no_std_main_recursion.rs1
-rw-r--r--src/tools/clippy/tests/ui/doc_errors.stderr36
-rw-r--r--src/tools/clippy/tests/ui/doc_unsafe.stderr34
-rw-r--r--src/tools/clippy/tests/ui/eq_op.rs1
-rw-r--r--src/tools/clippy/tests/ui/eq_op.stderr56
-rw-r--r--src/tools/clippy/tests/ui/equatable_if_let.fixed11
-rw-r--r--src/tools/clippy/tests/ui/equatable_if_let.rs7
-rw-r--r--src/tools/clippy/tests/ui/equatable_if_let.stderr42
-rw-r--r--src/tools/clippy/tests/ui/err_expect.fixed7
-rw-r--r--src/tools/clippy/tests/ui/err_expect.rs7
-rw-r--r--src/tools/clippy/tests/ui/err_expect.stderr4
-rw-r--r--src/tools/clippy/tests/ui/eta.fixed22
-rw-r--r--src/tools/clippy/tests/ui/eta.rs22
-rw-r--r--src/tools/clippy/tests/ui/eta.stderr26
-rw-r--r--src/tools/clippy/tests/ui/expect.stderr6
-rw-r--r--src/tools/clippy/tests/ui/explicit_auto_deref.fixed15
-rw-r--r--src/tools/clippy/tests/ui/explicit_auto_deref.rs15
-rw-r--r--src/tools/clippy/tests/ui/filter_map_next_fixable.fixed7
-rw-r--r--src/tools/clippy/tests/ui/filter_map_next_fixable.rs7
-rw-r--r--src/tools/clippy/tests/ui/filter_map_next_fixable.stderr4
-rw-r--r--src/tools/clippy/tests/ui/fn_params_excessive_bools.rs8
-rw-r--r--src/tools/clippy/tests/ui/fn_params_excessive_bools.stderr22
-rw-r--r--src/tools/clippy/tests/ui/from_over_into.fixed7
-rw-r--r--src/tools/clippy/tests/ui/from_over_into.rs7
-rw-r--r--src/tools/clippy/tests/ui/from_over_into.stderr10
-rw-r--r--src/tools/clippy/tests/ui/from_raw_with_void_ptr.rs34
-rw-r--r--src/tools/clippy/tests/ui/from_raw_with_void_ptr.stderr63
-rw-r--r--src/tools/clippy/tests/ui/get_unwrap.stderr26
-rw-r--r--src/tools/clippy/tests/ui/if_then_some_else_none.rs5
-rw-r--r--src/tools/clippy/tests/ui/if_then_some_else_none.stderr10
-rw-r--r--src/tools/clippy/tests/ui/indexing_slicing_index.stderr6
-rw-r--r--src/tools/clippy/tests/ui/infallible_destructuring_match.fixed12
-rw-r--r--src/tools/clippy/tests/ui/infallible_destructuring_match.rs14
-rw-r--r--src/tools/clippy/tests/ui/infallible_destructuring_match.stderr16
-rw-r--r--src/tools/clippy/tests/ui/issue_4266.stderr4
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_drop.rs28
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_drop.stderr27
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_future.rs20
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_future.stderr27
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_lock.rs31
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_lock.stderr66
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_must_use.stderr24
-rw-r--r--src/tools/clippy/tests/ui/macro_use_imports.stderr8
-rw-r--r--src/tools/clippy/tests/ui/manual_clamp.rs7
-rw-r--r--src/tools/clippy/tests/ui/manual_clamp.stderr70
-rw-r--r--src/tools/clippy/tests/ui/manual_flatten.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_instant_elapsed.fixed1
-rw-r--r--src/tools/clippy/tests/ui/manual_instant_elapsed.rs1
-rw-r--r--src/tools/clippy/tests/ui/manual_instant_elapsed.stderr4
-rw-r--r--src/tools/clippy/tests/ui/manual_is_ascii_check.fixed42
-rw-r--r--src/tools/clippy/tests/ui/manual_is_ascii_check.rs42
-rw-r--r--src/tools/clippy/tests/ui/manual_is_ascii_check.stderr70
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else.rs251
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else.stderr272
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else_match.rs121
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else_match.stderr58
-rw-r--r--src/tools/clippy/tests/ui/manual_ok_or.fixed1
-rw-r--r--src/tools/clippy/tests/ui/manual_ok_or.rs1
-rw-r--r--src/tools/clippy/tests/ui/manual_ok_or.stderr8
-rw-r--r--src/tools/clippy/tests/ui/manual_rem_euclid.fixed13
-rw-r--r--src/tools/clippy/tests/ui/manual_rem_euclid.rs13
-rw-r--r--src/tools/clippy/tests/ui/manual_rem_euclid.stderr20
-rw-r--r--src/tools/clippy/tests/ui/manual_retain.fixed7
-rw-r--r--src/tools/clippy/tests/ui/manual_retain.rs7
-rw-r--r--src/tools/clippy/tests/ui/manual_retain.stderr38
-rw-r--r--src/tools/clippy/tests/ui/manual_split_once.fixed5
-rw-r--r--src/tools/clippy/tests/ui/manual_split_once.rs5
-rw-r--r--src/tools/clippy/tests/ui/manual_split_once.stderr38
-rw-r--r--src/tools/clippy/tests/ui/manual_str_repeat.fixed5
-rw-r--r--src/tools/clippy/tests/ui/manual_str_repeat.rs5
-rw-r--r--src/tools/clippy/tests/ui/manual_str_repeat.stderr20
-rw-r--r--src/tools/clippy/tests/ui/manual_strip.rs7
-rw-r--r--src/tools/clippy/tests/ui/manual_strip.stderr32
-rw-r--r--src/tools/clippy/tests/ui/map_flatten_fixable.fixed1
-rw-r--r--src/tools/clippy/tests/ui/map_flatten_fixable.rs1
-rw-r--r--src/tools/clippy/tests/ui/map_flatten_fixable.stderr18
-rw-r--r--src/tools/clippy/tests/ui/map_unwrap_or.rs7
-rw-r--r--src/tools/clippy/tests/ui/map_unwrap_or.stderr24
-rw-r--r--src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed14
-rw-r--r--src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs14
-rw-r--r--src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr28
-rw-r--r--src/tools/clippy/tests/ui/mem_replace.fixed7
-rw-r--r--src/tools/clippy/tests/ui/mem_replace.rs7
-rw-r--r--src/tools/clippy/tests/ui/mem_replace.stderr40
-rw-r--r--src/tools/clippy/tests/ui/min_rust_version_attr.rs41
-rw-r--r--src/tools/clippy/tests/ui/min_rust_version_attr.stderr26
-rw-r--r--src/tools/clippy/tests/ui/min_rust_version_invalid_attr.stderr2
-rw-r--r--src/tools/clippy/tests/ui/misnamed_getters.rs124
-rw-r--r--src/tools/clippy/tests/ui/misnamed_getters.stderr166
-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_const_for_fn/could_be_const.rs10
-rw-r--r--src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr24
-rw-r--r--src/tools/clippy/tests/ui/missing_panics_doc.stderr49
-rw-r--r--src/tools/clippy/tests/ui/mut_from_ref.rs2
-rw-r--r--src/tools/clippy/tests/ui/mut_mut.rs17
-rw-r--r--src/tools/clippy/tests/ui/mut_range_bound.rs2
-rw-r--r--src/tools/clippy/tests/ui/mut_range_bound.stderr2
-rw-r--r--src/tools/clippy/tests/ui/needless_borrow.fixed144
-rw-r--r--src/tools/clippy/tests/ui/needless_borrow.rs144
-rw-r--r--src/tools/clippy/tests/ui/needless_borrow.stderr24
-rw-r--r--src/tools/clippy/tests/ui/needless_borrowed_ref.fixed67
-rw-r--r--src/tools/clippy/tests/ui/needless_borrowed_ref.rs67
-rw-r--r--src/tools/clippy/tests/ui/needless_borrowed_ref.stderr113
-rw-r--r--src/tools/clippy/tests/ui/needless_collect.fixed29
-rw-r--r--src/tools/clippy/tests/ui/needless_collect.rs29
-rw-r--r--src/tools/clippy/tests/ui/needless_collect.stderr26
-rw-r--r--src/tools/clippy/tests/ui/needless_collect_indirect.rs1
-rw-r--r--src/tools/clippy/tests/ui/needless_collect_indirect.stderr32
-rw-r--r--src/tools/clippy/tests/ui/needless_lifetimes.rs96
-rw-r--r--src/tools/clippy/tests/ui/needless_lifetimes.stderr246
-rw-r--r--src/tools/clippy/tests/ui/needless_question_mark.fixed1
-rw-r--r--src/tools/clippy/tests/ui/needless_question_mark.rs1
-rw-r--r--src/tools/clippy/tests/ui/needless_question_mark.stderr28
-rw-r--r--src/tools/clippy/tests/ui/needless_return.fixed19
-rw-r--r--src/tools/clippy/tests/ui/needless_return.rs13
-rw-r--r--src/tools/clippy/tests/ui/needless_return.stderr85
-rw-r--r--src/tools/clippy/tests/ui/needless_splitn.fixed3
-rw-r--r--src/tools/clippy/tests/ui/needless_splitn.rs3
-rw-r--r--src/tools/clippy/tests/ui/needless_splitn.stderr26
-rw-r--r--src/tools/clippy/tests/ui/never_loop.rs21
-rw-r--r--src/tools/clippy/tests/ui/never_loop.stderr14
-rw-r--r--src/tools/clippy/tests/ui/new_ret_no_self.rs73
-rw-r--r--src/tools/clippy/tests/ui/new_ret_no_self.stderr54
-rw-r--r--src/tools/clippy/tests/ui/option_as_ref_deref.fixed7
-rw-r--r--src/tools/clippy/tests/ui/option_as_ref_deref.rs7
-rw-r--r--src/tools/clippy/tests/ui/option_as_ref_deref.stderr36
-rw-r--r--src/tools/clippy/tests/ui/option_if_let_else.fixed9
-rw-r--r--src/tools/clippy/tests/ui/option_if_let_else.rs9
-rw-r--r--src/tools/clippy/tests/ui/or_fun_call.fixed16
-rw-r--r--src/tools/clippy/tests/ui/or_fun_call.rs16
-rw-r--r--src/tools/clippy/tests/ui/or_fun_call.stderr14
-rw-r--r--src/tools/clippy/tests/ui/ptr_as_ptr.fixed5
-rw-r--r--src/tools/clippy/tests/ui/ptr_as_ptr.rs5
-rw-r--r--src/tools/clippy/tests/ui/ptr_as_ptr.stderr16
-rw-r--r--src/tools/clippy/tests/ui/question_mark.fixed3
-rw-r--r--src/tools/clippy/tests/ui/question_mark.rs3
-rw-r--r--src/tools/clippy/tests/ui/question_mark.stderr4
-rw-r--r--src/tools/clippy/tests/ui/range_contains.fixed7
-rw-r--r--src/tools/clippy/tests/ui/range_contains.rs7
-rw-r--r--src/tools/clippy/tests/ui/range_contains.stderr42
-rw-r--r--src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed12
-rw-r--r--src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs12
-rw-r--r--src/tools/clippy/tests/ui/redundant_closure_call_fixable.stderr24
-rw-r--r--src/tools/clippy/tests/ui/redundant_field_names.fixed7
-rw-r--r--src/tools/clippy/tests/ui/redundant_field_names.rs7
-rw-r--r--src/tools/clippy/tests/ui/redundant_field_names.stderr16
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed7
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes.rs7
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr34
-rw-r--r--src/tools/clippy/tests/ui/rename.fixed8
-rw-r--r--src/tools/clippy/tests/ui/rename.rs8
-rw-r--r--src/tools/clippy/tests/ui/rename.stderr106
-rw-r--r--src/tools/clippy/tests/ui/result_large_err.rs18
-rw-r--r--src/tools/clippy/tests/ui/result_large_err.stderr30
-rw-r--r--src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr6
-rw-r--r--src/tools/clippy/tests/ui/seek_from_current.fixed25
-rw-r--r--src/tools/clippy/tests/ui/seek_from_current.rs25
-rw-r--r--src/tools/clippy/tests/ui/seek_from_current.stderr10
-rw-r--r--src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed134
-rw-r--r--src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs134
-rw-r--r--src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.stderr22
-rw-r--r--src/tools/clippy/tests/ui/single_component_path_imports.stderr12
-rw-r--r--src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr15
-rw-r--r--src/tools/clippy/tests/ui/string_extend.fixed3
-rw-r--r--src/tools/clippy/tests/ui/string_extend.rs3
-rw-r--r--src/tools/clippy/tests/ui/string_extend.stderr8
-rw-r--r--src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.rs34
-rw-r--r--src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr51
-rw-r--r--src/tools/clippy/tests/ui/swap.fixed9
-rw-r--r--src/tools/clippy/tests/ui/swap.rs9
-rw-r--r--src/tools/clippy/tests/ui/track-diagnostics.rs12
-rw-r--r--src/tools/clippy/tests/ui/track-diagnostics.stderr10
-rw-r--r--src/tools/clippy/tests/ui/transmute.rs2
-rw-r--r--src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed5
-rw-r--r--src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs5
-rw-r--r--src/tools/clippy/tests/ui/transmute_ptr_to_ref.stderr44
-rw-r--r--src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs1
-rw-r--r--src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr36
-rw-r--r--src/tools/clippy/tests/ui/unchecked_duration_subtraction.fixed17
-rw-r--r--src/tools/clippy/tests/ui/unchecked_duration_subtraction.rs17
-rw-r--r--src/tools/clippy/tests/ui/unchecked_duration_subtraction.stderr28
-rw-r--r--src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs21
-rw-r--r--src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr57
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args.fixed24
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args.rs5
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args.stderr213
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast.fixed14
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast.rs14
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast.stderr52
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_join.stderr4
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed23
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs23
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr84
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_operation.fixed9
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_operation.rs9
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_safety_comment.rs51
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_safety_comment.stderr115
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.fixed34
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.rs34
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.stderr168
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs149
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_unsafety_doc.stderr51
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns.fixed8
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns.rs8
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns.stderr2
-rw-r--r--src/tools/clippy/tests/ui/unused_rounding.fixed8
-rw-r--r--src/tools/clippy/tests/ui/unused_rounding.rs8
-rw-r--r--src/tools/clippy/tests/ui/unused_rounding.stderr14
-rw-r--r--src/tools/clippy/tests/ui/unused_unit.fixed7
-rw-r--r--src/tools/clippy/tests/ui/unused_unit.rs7
-rw-r--r--src/tools/clippy/tests/ui/unused_unit.stderr40
-rw-r--r--src/tools/clippy/tests/ui/unwrap.stderr6
-rw-r--r--src/tools/clippy/tests/ui/unwrap_expect_used.stderr12
-rw-r--r--src/tools/clippy/tests/ui/unwrap_or.rs2
-rw-r--r--src/tools/clippy/tests/ui/use_self.fixed7
-rw-r--r--src/tools/clippy/tests/ui/use_self.rs7
-rw-r--r--src/tools/clippy/tests/ui/use_self.stderr84
-rw-r--r--src/tools/clippy/tests/ui/use_self_trait.fixed41
-rw-r--r--src/tools/clippy/tests/ui/use_self_trait.rs39
-rw-r--r--src/tools/clippy/tests/ui/use_self_trait.stderr14
-rw-r--r--src/tools/clippy/tests/ui/useless_attribute.fixed21
-rw-r--r--src/tools/clippy/tests/ui/useless_attribute.rs21
-rw-r--r--src/tools/clippy/tests/ui/useless_attribute.stderr6
258 files changed, 5437 insertions, 1747 deletions
diff --git a/src/tools/clippy/tests/ui/almost_complete_letter_range.fixed b/src/tools/clippy/tests/ui/almost_complete_letter_range.fixed
index 079b7c000..adcbd4d51 100644
--- a/src/tools/clippy/tests/ui/almost_complete_letter_range.fixed
+++ b/src/tools/clippy/tests/ui/almost_complete_letter_range.fixed
@@ -2,7 +2,6 @@
// edition:2018
// aux-build:macro_rules.rs
-#![feature(custom_inner_attributes)]
#![feature(exclusive_range_pattern)]
#![feature(stmt_expr_attributes)]
#![warn(clippy::almost_complete_letter_range)]
@@ -62,16 +61,16 @@ fn main() {
b!();
}
+#[clippy::msrv = "1.25"]
fn _under_msrv() {
- #![clippy::msrv = "1.25"]
let _ = match 'a' {
'a'...'z' => 1,
_ => 2,
};
}
+#[clippy::msrv = "1.26"]
fn _meets_msrv() {
- #![clippy::msrv = "1.26"]
let _ = 'a'..='z';
let _ = match 'a' {
'a'..='z' => 1,
diff --git a/src/tools/clippy/tests/ui/almost_complete_letter_range.rs b/src/tools/clippy/tests/ui/almost_complete_letter_range.rs
index a66900a97..9979316ec 100644
--- a/src/tools/clippy/tests/ui/almost_complete_letter_range.rs
+++ b/src/tools/clippy/tests/ui/almost_complete_letter_range.rs
@@ -2,7 +2,6 @@
// edition:2018
// aux-build:macro_rules.rs
-#![feature(custom_inner_attributes)]
#![feature(exclusive_range_pattern)]
#![feature(stmt_expr_attributes)]
#![warn(clippy::almost_complete_letter_range)]
@@ -62,16 +61,16 @@ fn main() {
b!();
}
+#[clippy::msrv = "1.25"]
fn _under_msrv() {
- #![clippy::msrv = "1.25"]
let _ = match 'a' {
'a'..'z' => 1,
_ => 2,
};
}
+#[clippy::msrv = "1.26"]
fn _meets_msrv() {
- #![clippy::msrv = "1.26"]
let _ = 'a'..'z';
let _ = match 'a' {
'a'..'z' => 1,
diff --git a/src/tools/clippy/tests/ui/almost_complete_letter_range.stderr b/src/tools/clippy/tests/ui/almost_complete_letter_range.stderr
index 3de44c72c..9abf6d6c5 100644
--- a/src/tools/clippy/tests/ui/almost_complete_letter_range.stderr
+++ b/src/tools/clippy/tests/ui/almost_complete_letter_range.stderr
@@ -1,5 +1,5 @@
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:30:17
+ --> $DIR/almost_complete_letter_range.rs:29:17
|
LL | let _ = ('a') ..'z';
| ^^^^^^--^^^
@@ -9,7 +9,7 @@ LL | let _ = ('a') ..'z';
= note: `-D clippy::almost-complete-letter-range` implied by `-D warnings`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:31:17
+ --> $DIR/almost_complete_letter_range.rs:30:17
|
LL | let _ = 'A' .. ('Z');
| ^^^^--^^^^^^
@@ -17,7 +17,7 @@ LL | let _ = 'A' .. ('Z');
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:37:13
+ --> $DIR/almost_complete_letter_range.rs:36:13
|
LL | let _ = (b'a')..(b'z');
| ^^^^^^--^^^^^^
@@ -25,7 +25,7 @@ LL | let _ = (b'a')..(b'z');
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:38:13
+ --> $DIR/almost_complete_letter_range.rs:37:13
|
LL | let _ = b'A'..b'Z';
| ^^^^--^^^^
@@ -33,7 +33,7 @@ LL | let _ = b'A'..b'Z';
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:43:13
+ --> $DIR/almost_complete_letter_range.rs:42:13
|
LL | let _ = a!()..'z';
| ^^^^--^^^
@@ -41,7 +41,7 @@ LL | let _ = a!()..'z';
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:46:9
+ --> $DIR/almost_complete_letter_range.rs:45:9
|
LL | b'a'..b'z' if true => 1,
| ^^^^--^^^^
@@ -49,7 +49,7 @@ LL | b'a'..b'z' if true => 1,
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:47:9
+ --> $DIR/almost_complete_letter_range.rs:46:9
|
LL | b'A'..b'Z' if true => 2,
| ^^^^--^^^^
@@ -57,7 +57,7 @@ LL | b'A'..b'Z' if true => 2,
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:54:9
+ --> $DIR/almost_complete_letter_range.rs:53:9
|
LL | 'a'..'z' if true => 1,
| ^^^--^^^
@@ -65,7 +65,7 @@ LL | 'a'..'z' if true => 1,
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:55:9
+ --> $DIR/almost_complete_letter_range.rs:54:9
|
LL | 'A'..'Z' if true => 2,
| ^^^--^^^
@@ -73,7 +73,7 @@ LL | 'A'..'Z' if true => 2,
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:23:17
+ --> $DIR/almost_complete_letter_range.rs:22:17
|
LL | let _ = 'a'..'z';
| ^^^--^^^
@@ -86,7 +86,7 @@ LL | b!();
= note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info)
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:68:9
+ --> $DIR/almost_complete_letter_range.rs:67:9
|
LL | 'a'..'z' => 1,
| ^^^--^^^
@@ -94,7 +94,7 @@ LL | 'a'..'z' => 1,
| help: use an inclusive range: `...`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:75:13
+ --> $DIR/almost_complete_letter_range.rs:74:13
|
LL | let _ = 'a'..'z';
| ^^^--^^^
@@ -102,7 +102,7 @@ LL | let _ = 'a'..'z';
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:77:9
+ --> $DIR/almost_complete_letter_range.rs:76:9
|
LL | 'a'..'z' => 1,
| ^^^--^^^
diff --git a/src/tools/clippy/tests/ui/arithmetic_side_effects.rs b/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
index b25e68f13..b5ed8988a 100644
--- a/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
+++ b/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
@@ -150,8 +150,12 @@ pub fn non_overflowing_ops_or_ops_already_handled_by_the_compiler_should_not_tri
_n = 23 + 85;
// Unary
- _n = -1;
- _n = -(-1);
+ _n = -2147483647;
+ _n = -i32::MAX;
+ _n = -i32::MIN;
+ _n = -&2147483647;
+ _n = -&i32::MAX;
+ _n = -&i32::MIN;
}
pub fn runtime_ops() {
diff --git a/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr b/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr
index 0f06e22ba..0259a0824 100644
--- a/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr
+++ b/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr
@@ -19,331 +19,331 @@ LL | let _ = inferred_string + "";
| ^^^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:161:5
+ --> $DIR/arithmetic_side_effects.rs:165:5
|
LL | _n += 1;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:162:5
+ --> $DIR/arithmetic_side_effects.rs:166:5
|
LL | _n += &1;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:163:5
+ --> $DIR/arithmetic_side_effects.rs:167:5
|
LL | _n -= 1;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:164:5
+ --> $DIR/arithmetic_side_effects.rs:168:5
|
LL | _n -= &1;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:165:5
+ --> $DIR/arithmetic_side_effects.rs:169:5
|
LL | _n /= 0;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:166:5
+ --> $DIR/arithmetic_side_effects.rs:170:5
|
LL | _n /= &0;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:167:5
+ --> $DIR/arithmetic_side_effects.rs:171:5
|
LL | _n %= 0;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:168:5
+ --> $DIR/arithmetic_side_effects.rs:172:5
|
LL | _n %= &0;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:169:5
+ --> $DIR/arithmetic_side_effects.rs:173:5
|
LL | _n *= 2;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:170:5
+ --> $DIR/arithmetic_side_effects.rs:174:5
|
LL | _n *= &2;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:173:10
+ --> $DIR/arithmetic_side_effects.rs:177:10
|
LL | _n = _n + 1;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:174:10
+ --> $DIR/arithmetic_side_effects.rs:178:10
|
LL | _n = _n + &1;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:175:10
+ --> $DIR/arithmetic_side_effects.rs:179:10
|
LL | _n = 1 + _n;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:176:10
+ --> $DIR/arithmetic_side_effects.rs:180:10
|
LL | _n = &1 + _n;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:177:10
+ --> $DIR/arithmetic_side_effects.rs:181:10
|
LL | _n = _n - 1;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:178:10
+ --> $DIR/arithmetic_side_effects.rs:182:10
|
LL | _n = _n - &1;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:179:10
+ --> $DIR/arithmetic_side_effects.rs:183:10
|
LL | _n = 1 - _n;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:180:10
+ --> $DIR/arithmetic_side_effects.rs:184:10
|
LL | _n = &1 - _n;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:181:10
+ --> $DIR/arithmetic_side_effects.rs:185:10
|
LL | _n = _n / 0;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:182:10
+ --> $DIR/arithmetic_side_effects.rs:186:10
|
LL | _n = _n / &0;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:183:10
+ --> $DIR/arithmetic_side_effects.rs:187:10
|
LL | _n = _n % 0;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:184:10
+ --> $DIR/arithmetic_side_effects.rs:188:10
|
LL | _n = _n % &0;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:185:10
+ --> $DIR/arithmetic_side_effects.rs:189:10
|
LL | _n = _n * 2;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:186:10
+ --> $DIR/arithmetic_side_effects.rs:190:10
|
LL | _n = _n * &2;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:187:10
+ --> $DIR/arithmetic_side_effects.rs:191:10
|
LL | _n = 2 * _n;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:188:10
+ --> $DIR/arithmetic_side_effects.rs:192:10
|
LL | _n = &2 * _n;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:189:10
+ --> $DIR/arithmetic_side_effects.rs:193:10
|
LL | _n = 23 + &85;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:190:10
+ --> $DIR/arithmetic_side_effects.rs:194:10
|
LL | _n = &23 + 85;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:191:10
+ --> $DIR/arithmetic_side_effects.rs:195:10
|
LL | _n = &23 + &85;
| ^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:194:13
+ --> $DIR/arithmetic_side_effects.rs:198:13
|
LL | let _ = Custom + 0;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:195:13
+ --> $DIR/arithmetic_side_effects.rs:199:13
|
LL | let _ = Custom + 1;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:196:13
+ --> $DIR/arithmetic_side_effects.rs:200:13
|
LL | let _ = Custom + 2;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:197:13
+ --> $DIR/arithmetic_side_effects.rs:201:13
|
LL | let _ = Custom + 0.0;
| ^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:198:13
+ --> $DIR/arithmetic_side_effects.rs:202:13
|
LL | let _ = Custom + 1.0;
| ^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:199:13
+ --> $DIR/arithmetic_side_effects.rs:203:13
|
LL | let _ = Custom + 2.0;
| ^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:200:13
+ --> $DIR/arithmetic_side_effects.rs:204:13
|
LL | let _ = Custom - 0;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:201:13
+ --> $DIR/arithmetic_side_effects.rs:205:13
|
LL | let _ = Custom - 1;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:202:13
+ --> $DIR/arithmetic_side_effects.rs:206:13
|
LL | let _ = Custom - 2;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:203:13
+ --> $DIR/arithmetic_side_effects.rs:207:13
|
LL | let _ = Custom - 0.0;
| ^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:204:13
+ --> $DIR/arithmetic_side_effects.rs:208:13
|
LL | let _ = Custom - 1.0;
| ^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:205:13
+ --> $DIR/arithmetic_side_effects.rs:209:13
|
LL | let _ = Custom - 2.0;
| ^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:206:13
+ --> $DIR/arithmetic_side_effects.rs:210:13
|
LL | let _ = Custom / 0;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:207:13
+ --> $DIR/arithmetic_side_effects.rs:211:13
|
LL | let _ = Custom / 1;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:208:13
+ --> $DIR/arithmetic_side_effects.rs:212:13
|
LL | let _ = Custom / 2;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:209:13
+ --> $DIR/arithmetic_side_effects.rs:213:13
|
LL | let _ = Custom / 0.0;
| ^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:210:13
+ --> $DIR/arithmetic_side_effects.rs:214:13
|
LL | let _ = Custom / 1.0;
| ^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:211:13
+ --> $DIR/arithmetic_side_effects.rs:215:13
|
LL | let _ = Custom / 2.0;
| ^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:212:13
+ --> $DIR/arithmetic_side_effects.rs:216:13
|
LL | let _ = Custom * 0;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:213:13
+ --> $DIR/arithmetic_side_effects.rs:217:13
|
LL | let _ = Custom * 1;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:214:13
+ --> $DIR/arithmetic_side_effects.rs:218:13
|
LL | let _ = Custom * 2;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:215:13
+ --> $DIR/arithmetic_side_effects.rs:219:13
|
LL | let _ = Custom * 0.0;
| ^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:216:13
+ --> $DIR/arithmetic_side_effects.rs:220:13
|
LL | let _ = Custom * 1.0;
| ^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:217:13
+ --> $DIR/arithmetic_side_effects.rs:221:13
|
LL | let _ = Custom * 2.0;
| ^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:220:10
+ --> $DIR/arithmetic_side_effects.rs:224:10
|
LL | _n = -_n;
| ^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:221:10
+ --> $DIR/arithmetic_side_effects.rs:225:10
|
LL | _n = -&_n;
| ^^^^
diff --git a/src/tools/clippy/tests/ui/async_yields_async.stderr b/src/tools/clippy/tests/ui/async_yields_async.stderr
index b0c4215e7..92ba35929 100644
--- a/src/tools/clippy/tests/ui/async_yields_async.stderr
+++ b/src/tools/clippy/tests/ui/async_yields_async.stderr
@@ -2,14 +2,14 @@ error: an async construct yields a type which is itself awaitable
--> $DIR/async_yields_async.rs:39:9
|
LL | let _h = async {
- | ____________________-
-LL | | async {
- | |_________^
+ | _____________________-
+LL | | async {
+ | | _________^
LL | || 3
LL | || }
| ||_________^ awaitable value not awaited
-LL | | };
- | |_____- outer async construct
+LL | | };
+ | |______- outer async construct
|
= note: `-D clippy::async-yields-async` implied by `-D warnings`
help: consider awaiting this value
@@ -36,14 +36,14 @@ error: an async construct yields a type which is itself awaitable
--> $DIR/async_yields_async.rs:50:9
|
LL | let _j = async || {
- | _______________________-
-LL | | async {
- | |_________^
+ | ________________________-
+LL | | async {
+ | | _________^
LL | || 3
LL | || }
| ||_________^ awaitable value not awaited
-LL | | };
- | |_____- outer async construct
+LL | | };
+ | |______- outer async construct
|
help: consider awaiting this value
|
diff --git a/src/tools/clippy/tests/ui/author/blocks.stdout b/src/tools/clippy/tests/ui/author/blocks.stdout
index 9de0550d8..c6acf24c2 100644
--- a/src/tools/clippy/tests/ui/author/blocks.stdout
+++ b/src/tools/clippy/tests/ui/author/blocks.stdout
@@ -45,7 +45,7 @@ if let ExprKind::Closure(CaptureBy::Value, fn_decl, body_id, _, None) = expr.kin
&& expr1 = &cx.tcx.hir().body(body_id).value
&& let ExprKind::Call(func, args) = expr1.kind
&& let ExprKind::Path(ref qpath) = func.kind
- && matches!(qpath, QPath::LangItem(LangItem::FromGenerator, _))
+ && matches!(qpath, QPath::LangItem(LangItem::IdentityFuture, _))
&& args.len() == 1
&& let ExprKind::Closure(CaptureBy::Value, fn_decl1, body_id1, _, Some(Movability::Static)) = args[0].kind
&& let FnRetTy::DefaultReturn(_) = fn_decl1.output
diff --git a/src/tools/clippy/tests/ui/auxiliary/doc_unsafe_macros.rs b/src/tools/clippy/tests/ui/auxiliary/doc_unsafe_macros.rs
index 869672d1e..3d917e3dc 100644
--- a/src/tools/clippy/tests/ui/auxiliary/doc_unsafe_macros.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/doc_unsafe_macros.rs
@@ -6,3 +6,11 @@ macro_rules! undocd_unsafe {
}
};
}
+#[macro_export]
+macro_rules! undocd_safe {
+ () => {
+ pub fn vey_oy() {
+ unimplemented!();
+ }
+ };
+}
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 d055f1752..554745368 100644
--- a/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.rs
+++ b/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.rs
@@ -1,3 +1,5 @@
+// compile-flags: -W clippy::restriction
+
#![warn(clippy::blanket_clippy_restriction_lints)]
//! Test that the whole restriction group is not enabled
diff --git a/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr b/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr
index e83eb4d60..2bf89ab69 100644
--- a/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr
+++ b/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr
@@ -1,27 +1,32 @@
-error: restriction lints are not meant to be all enabled
- --> $DIR/blanket_clippy_restriction_lints.rs:4:9
+error: `clippy::restriction` is not meant to be enabled as a group
+ |
+ = note: because of the command line `--warn clippy::restriction`
+ = help: enable the restriction lints you need individually
+ = note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings`
+
+error: `clippy::restriction` is not meant to be enabled as a group
+ --> $DIR/blanket_clippy_restriction_lints.rs:6:9
|
LL | #![warn(clippy::restriction)]
| ^^^^^^^^^^^^^^^^^^^
|
- = help: try enabling only the lints you really need
- = note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings`
+ = help: enable the restriction lints you need individually
-error: restriction lints are not meant to be all enabled
- --> $DIR/blanket_clippy_restriction_lints.rs:5:9
+error: `clippy::restriction` is not meant to be enabled as a group
+ --> $DIR/blanket_clippy_restriction_lints.rs:7:9
|
LL | #![deny(clippy::restriction)]
| ^^^^^^^^^^^^^^^^^^^
|
- = help: try enabling only the lints you really need
+ = help: enable the restriction lints you need individually
-error: restriction lints are not meant to be all enabled
- --> $DIR/blanket_clippy_restriction_lints.rs:6:11
+error: `clippy::restriction` is not meant to be enabled as a group
+ --> $DIR/blanket_clippy_restriction_lints.rs:8:11
|
LL | #![forbid(clippy::restriction)]
| ^^^^^^^^^^^^^^^^^^^
|
- = help: try enabling only the lints you really need
+ = help: enable the restriction lints you need individually
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
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 2c8339cdd..37d3e3286 100644
--- a/src/tools/clippy/tests/ui/bool_to_int_with_if.fixed
+++ b/src/tools/clippy/tests/ui/bool_to_int_with_if.fixed
@@ -1,5 +1,6 @@
// run-rustfix
+#![feature(let_chains)]
#![warn(clippy::bool_to_int_with_if)]
#![allow(unused, dead_code, clippy::unnecessary_operation, clippy::no_effect)]
@@ -76,6 +77,8 @@ fn main() {
123
};
+ pub const SHOULD_NOT_LINT: usize = if true { 1 } else { 0 };
+
some_fn(a);
}
@@ -89,3 +92,22 @@ fn side_effect() {}
fn cond(a: bool, b: bool) -> bool {
a || b
}
+
+enum Enum {
+ A,
+ B,
+}
+
+fn if_let(a: Enum, b: Enum) {
+ if let Enum::A = a {
+ 1
+ } else {
+ 0
+ };
+
+ if let Enum::A = a && let Enum::B = b {
+ 1
+ } else {
+ 0
+ };
+}
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 5d9496f01..ebdf86fd1 100644
--- a/src/tools/clippy/tests/ui/bool_to_int_with_if.rs
+++ b/src/tools/clippy/tests/ui/bool_to_int_with_if.rs
@@ -1,5 +1,6 @@
// run-rustfix
+#![feature(let_chains)]
#![warn(clippy::bool_to_int_with_if)]
#![allow(unused, dead_code, clippy::unnecessary_operation, clippy::no_effect)]
@@ -108,6 +109,8 @@ fn main() {
123
};
+ pub const SHOULD_NOT_LINT: usize = if true { 1 } else { 0 };
+
some_fn(a);
}
@@ -121,3 +124,22 @@ fn side_effect() {}
fn cond(a: bool, b: bool) -> bool {
a || b
}
+
+enum Enum {
+ A,
+ B,
+}
+
+fn if_let(a: Enum, b: Enum) {
+ if let Enum::A = a {
+ 1
+ } else {
+ 0
+ };
+
+ if let Enum::A = a && let Enum::B = b {
+ 1
+ } else {
+ 0
+ };
+}
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 4cb5531be..5cfb75cc0 100644
--- a/src/tools/clippy/tests/ui/bool_to_int_with_if.stderr
+++ b/src/tools/clippy/tests/ui/bool_to_int_with_if.stderr
@@ -1,5 +1,5 @@
error: boolean to int conversion using if
- --> $DIR/bool_to_int_with_if.rs:15:5
+ --> $DIR/bool_to_int_with_if.rs:16:5
|
LL | / if a {
LL | | 1
@@ -12,7 +12,7 @@ LL | | };
= note: `-D clippy::bool-to-int-with-if` implied by `-D warnings`
error: boolean to int conversion using if
- --> $DIR/bool_to_int_with_if.rs:20:5
+ --> $DIR/bool_to_int_with_if.rs:21:5
|
LL | / if a {
LL | | 0
@@ -24,7 +24,7 @@ LL | | };
= note: `!a as i32` or `(!a).into()` can also be valid options
error: boolean to int conversion using if
- --> $DIR/bool_to_int_with_if.rs:25:5
+ --> $DIR/bool_to_int_with_if.rs:26:5
|
LL | / if !a {
LL | | 1
@@ -36,7 +36,7 @@ LL | | };
= note: `!a as i32` or `(!a).into()` can also be valid options
error: boolean to int conversion using if
- --> $DIR/bool_to_int_with_if.rs:30:5
+ --> $DIR/bool_to_int_with_if.rs:31:5
|
LL | / if a || b {
LL | | 1
@@ -48,7 +48,7 @@ LL | | };
= note: `(a || b) as i32` or `(a || b).into()` can also be valid options
error: boolean to int conversion using if
- --> $DIR/bool_to_int_with_if.rs:35:5
+ --> $DIR/bool_to_int_with_if.rs:36:5
|
LL | / if cond(a, b) {
LL | | 1
@@ -60,7 +60,7 @@ LL | | };
= note: `cond(a, b) as i32` or `cond(a, b).into()` can also be valid options
error: boolean to int conversion using if
- --> $DIR/bool_to_int_with_if.rs:40:5
+ --> $DIR/bool_to_int_with_if.rs:41:5
|
LL | / if x + y < 4 {
LL | | 1
@@ -72,7 +72,7 @@ LL | | };
= note: `(x + y < 4) as i32` or `(x + y < 4).into()` can also be valid options
error: boolean to int conversion using if
- --> $DIR/bool_to_int_with_if.rs:49:12
+ --> $DIR/bool_to_int_with_if.rs:50:12
|
LL | } else if b {
| ____________^
@@ -85,7 +85,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:58:12
+ --> $DIR/bool_to_int_with_if.rs:59:12
|
LL | } else if b {
| ____________^
@@ -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:116:5
+ --> $DIR/bool_to_int_with_if.rs:119:5
|
LL | if a { 1 } else { 0 }
| ^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `u8::from(a)`
diff --git a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.rs b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.rs
index eefeb1dec..7c5786424 100644
--- a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.rs
+++ b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.rs
@@ -42,7 +42,7 @@ impl<T> StaticRef<T> {
impl<T> std::ops::Deref for StaticRef<T> {
type Target = T;
- fn deref(&self) -> &'static T {
+ fn deref(&self) -> &T {
unsafe { &*self.ptr }
}
}
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 e6bf944c7..8676b562b 100644
--- a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed
+++ b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::cast_abs_to_unsigned)]
#![allow(clippy::uninlined_format_args, unused)]
@@ -33,16 +32,14 @@ fn main() {
let _ = (x as i64 - y as i64).unsigned_abs() as u32;
}
+#[clippy::msrv = "1.50"]
fn msrv_1_50() {
- #![clippy::msrv = "1.50"]
-
let x: i32 = 10;
assert_eq!(10u32, x.abs() as u32);
}
+#[clippy::msrv = "1.51"]
fn msrv_1_51() {
- #![clippy::msrv = "1.51"]
-
let x: i32 = 10;
assert_eq!(10u32, x.unsigned_abs());
}
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 c87320b52..5775af874 100644
--- a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs
+++ b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::cast_abs_to_unsigned)]
#![allow(clippy::uninlined_format_args, unused)]
@@ -33,16 +32,14 @@ fn main() {
let _ = (x as i64 - y as i64).abs() as u32;
}
+#[clippy::msrv = "1.50"]
fn msrv_1_50() {
- #![clippy::msrv = "1.50"]
-
let x: i32 = 10;
assert_eq!(10u32, x.abs() as u32);
}
+#[clippy::msrv = "1.51"]
fn msrv_1_51() {
- #![clippy::msrv = "1.51"]
-
let x: i32 = 10;
assert_eq!(10u32, x.abs() as u32);
}
diff --git a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.stderr b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.stderr
index 1b39c554b..4668554f4 100644
--- a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.stderr
+++ b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.stderr
@@ -1,5 +1,5 @@
error: casting the result of `i32::abs()` to u32
- --> $DIR/cast_abs_to_unsigned.rs:9:18
+ --> $DIR/cast_abs_to_unsigned.rs:8:18
|
LL | let y: u32 = x.abs() as u32;
| ^^^^^^^^^^^^^^ help: replace with: `x.unsigned_abs()`
@@ -7,103 +7,103 @@ LL | let y: u32 = x.abs() as u32;
= note: `-D clippy::cast-abs-to-unsigned` implied by `-D warnings`
error: casting the result of `i32::abs()` to usize
- --> $DIR/cast_abs_to_unsigned.rs:13:20
+ --> $DIR/cast_abs_to_unsigned.rs:12:20
|
LL | let _: usize = a.abs() as usize;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i32::abs()` to usize
- --> $DIR/cast_abs_to_unsigned.rs:14:20
+ --> $DIR/cast_abs_to_unsigned.rs:13:20
|
LL | let _: usize = a.abs() as _;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i32::abs()` to usize
- --> $DIR/cast_abs_to_unsigned.rs:15:13
+ --> $DIR/cast_abs_to_unsigned.rs:14:13
|
LL | let _ = a.abs() as usize;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i64::abs()` to usize
- --> $DIR/cast_abs_to_unsigned.rs:18:13
+ --> $DIR/cast_abs_to_unsigned.rs:17:13
|
LL | let _ = a.abs() as usize;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i64::abs()` to u8
- --> $DIR/cast_abs_to_unsigned.rs:19:13
+ --> $DIR/cast_abs_to_unsigned.rs:18:13
|
LL | let _ = a.abs() as u8;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i64::abs()` to u16
- --> $DIR/cast_abs_to_unsigned.rs:20:13
+ --> $DIR/cast_abs_to_unsigned.rs:19:13
|
LL | let _ = a.abs() as u16;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i64::abs()` to u32
- --> $DIR/cast_abs_to_unsigned.rs:21:13
+ --> $DIR/cast_abs_to_unsigned.rs:20:13
|
LL | let _ = a.abs() as u32;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i64::abs()` to u64
- --> $DIR/cast_abs_to_unsigned.rs:22:13
+ --> $DIR/cast_abs_to_unsigned.rs:21:13
|
LL | let _ = a.abs() as u64;
| ^^^^^^^^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i64::abs()` to u128
- --> $DIR/cast_abs_to_unsigned.rs:23:13
+ --> $DIR/cast_abs_to_unsigned.rs:22:13
|
LL | let _ = a.abs() as u128;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `isize::abs()` to usize
- --> $DIR/cast_abs_to_unsigned.rs:26:13
+ --> $DIR/cast_abs_to_unsigned.rs:25:13
|
LL | let _ = a.abs() as usize;
| ^^^^^^^^^^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `isize::abs()` to u8
- --> $DIR/cast_abs_to_unsigned.rs:27:13
+ --> $DIR/cast_abs_to_unsigned.rs:26:13
|
LL | let _ = a.abs() as u8;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `isize::abs()` to u16
- --> $DIR/cast_abs_to_unsigned.rs:28:13
+ --> $DIR/cast_abs_to_unsigned.rs:27:13
|
LL | let _ = a.abs() as u16;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `isize::abs()` to u32
- --> $DIR/cast_abs_to_unsigned.rs:29:13
+ --> $DIR/cast_abs_to_unsigned.rs:28:13
|
LL | let _ = a.abs() as u32;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `isize::abs()` to u64
- --> $DIR/cast_abs_to_unsigned.rs:30:13
+ --> $DIR/cast_abs_to_unsigned.rs:29:13
|
LL | let _ = a.abs() as u64;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `isize::abs()` to u128
- --> $DIR/cast_abs_to_unsigned.rs:31:13
+ --> $DIR/cast_abs_to_unsigned.rs:30:13
|
LL | let _ = a.abs() as u128;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i64::abs()` to u32
- --> $DIR/cast_abs_to_unsigned.rs:33:13
+ --> $DIR/cast_abs_to_unsigned.rs:32:13
|
LL | let _ = (x as i64 - y as i64).abs() as u32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `(x as i64 - y as i64).unsigned_abs()`
error: casting the result of `i32::abs()` to u32
- --> $DIR/cast_abs_to_unsigned.rs:47:23
+ --> $DIR/cast_abs_to_unsigned.rs:44:23
|
LL | assert_eq!(10u32, x.abs() as u32);
| ^^^^^^^^^^^^^^ help: replace with: `x.unsigned_abs()`
diff --git a/src/tools/clippy/tests/ui/cast_lossless_bool.fixed b/src/tools/clippy/tests/ui/cast_lossless_bool.fixed
index af13b755e..13b3cf838 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_bool.fixed
+++ b/src/tools/clippy/tests/ui/cast_lossless_bool.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![allow(dead_code)]
#![warn(clippy::cast_lossless)]
@@ -42,14 +41,12 @@ mod cast_lossless_in_impl {
}
}
+#[clippy::msrv = "1.27"]
fn msrv_1_27() {
- #![clippy::msrv = "1.27"]
-
let _ = true as u8;
}
+#[clippy::msrv = "1.28"]
fn msrv_1_28() {
- #![clippy::msrv = "1.28"]
-
let _ = u8::from(true);
}
diff --git a/src/tools/clippy/tests/ui/cast_lossless_bool.rs b/src/tools/clippy/tests/ui/cast_lossless_bool.rs
index 3b06af899..3eed21355 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_bool.rs
+++ b/src/tools/clippy/tests/ui/cast_lossless_bool.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![allow(dead_code)]
#![warn(clippy::cast_lossless)]
@@ -42,14 +41,12 @@ mod cast_lossless_in_impl {
}
}
+#[clippy::msrv = "1.27"]
fn msrv_1_27() {
- #![clippy::msrv = "1.27"]
-
let _ = true as u8;
}
+#[clippy::msrv = "1.28"]
fn msrv_1_28() {
- #![clippy::msrv = "1.28"]
-
let _ = true as u8;
}
diff --git a/src/tools/clippy/tests/ui/cast_lossless_bool.stderr b/src/tools/clippy/tests/ui/cast_lossless_bool.stderr
index 768b033d1..ce240b70f 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_bool.stderr
+++ b/src/tools/clippy/tests/ui/cast_lossless_bool.stderr
@@ -1,5 +1,5 @@
error: casting `bool` to `u8` is more cleanly stated with `u8::from(_)`
- --> $DIR/cast_lossless_bool.rs:9:13
+ --> $DIR/cast_lossless_bool.rs:8:13
|
LL | let _ = true as u8;
| ^^^^^^^^^^ help: try: `u8::from(true)`
@@ -7,79 +7,79 @@ LL | let _ = true as u8;
= note: `-D clippy::cast-lossless` implied by `-D warnings`
error: casting `bool` to `u16` is more cleanly stated with `u16::from(_)`
- --> $DIR/cast_lossless_bool.rs:10:13
+ --> $DIR/cast_lossless_bool.rs:9:13
|
LL | let _ = true as u16;
| ^^^^^^^^^^^ help: try: `u16::from(true)`
error: casting `bool` to `u32` is more cleanly stated with `u32::from(_)`
- --> $DIR/cast_lossless_bool.rs:11:13
+ --> $DIR/cast_lossless_bool.rs:10:13
|
LL | let _ = true as u32;
| ^^^^^^^^^^^ help: try: `u32::from(true)`
error: casting `bool` to `u64` is more cleanly stated with `u64::from(_)`
- --> $DIR/cast_lossless_bool.rs:12:13
+ --> $DIR/cast_lossless_bool.rs:11:13
|
LL | let _ = true as u64;
| ^^^^^^^^^^^ help: try: `u64::from(true)`
error: casting `bool` to `u128` is more cleanly stated with `u128::from(_)`
- --> $DIR/cast_lossless_bool.rs:13:13
+ --> $DIR/cast_lossless_bool.rs:12:13
|
LL | let _ = true as u128;
| ^^^^^^^^^^^^ help: try: `u128::from(true)`
error: casting `bool` to `usize` is more cleanly stated with `usize::from(_)`
- --> $DIR/cast_lossless_bool.rs:14:13
+ --> $DIR/cast_lossless_bool.rs:13:13
|
LL | let _ = true as usize;
| ^^^^^^^^^^^^^ help: try: `usize::from(true)`
error: casting `bool` to `i8` is more cleanly stated with `i8::from(_)`
- --> $DIR/cast_lossless_bool.rs:16:13
+ --> $DIR/cast_lossless_bool.rs:15:13
|
LL | let _ = true as i8;
| ^^^^^^^^^^ help: try: `i8::from(true)`
error: casting `bool` to `i16` is more cleanly stated with `i16::from(_)`
- --> $DIR/cast_lossless_bool.rs:17:13
+ --> $DIR/cast_lossless_bool.rs:16:13
|
LL | let _ = true as i16;
| ^^^^^^^^^^^ help: try: `i16::from(true)`
error: casting `bool` to `i32` is more cleanly stated with `i32::from(_)`
- --> $DIR/cast_lossless_bool.rs:18:13
+ --> $DIR/cast_lossless_bool.rs:17:13
|
LL | let _ = true as i32;
| ^^^^^^^^^^^ help: try: `i32::from(true)`
error: casting `bool` to `i64` is more cleanly stated with `i64::from(_)`
- --> $DIR/cast_lossless_bool.rs:19:13
+ --> $DIR/cast_lossless_bool.rs:18:13
|
LL | let _ = true as i64;
| ^^^^^^^^^^^ help: try: `i64::from(true)`
error: casting `bool` to `i128` is more cleanly stated with `i128::from(_)`
- --> $DIR/cast_lossless_bool.rs:20:13
+ --> $DIR/cast_lossless_bool.rs:19:13
|
LL | let _ = true as i128;
| ^^^^^^^^^^^^ help: try: `i128::from(true)`
error: casting `bool` to `isize` is more cleanly stated with `isize::from(_)`
- --> $DIR/cast_lossless_bool.rs:21:13
+ --> $DIR/cast_lossless_bool.rs:20:13
|
LL | let _ = true as isize;
| ^^^^^^^^^^^^^ help: try: `isize::from(true)`
error: casting `bool` to `u16` is more cleanly stated with `u16::from(_)`
- --> $DIR/cast_lossless_bool.rs:24:13
+ --> $DIR/cast_lossless_bool.rs:23:13
|
LL | let _ = (true | false) as u16;
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::from(true | false)`
error: casting `bool` to `u8` is more cleanly stated with `u8::from(_)`
- --> $DIR/cast_lossless_bool.rs:54:13
+ --> $DIR/cast_lossless_bool.rs:51:13
|
LL | let _ = true as u8;
| ^^^^^^^^^^ help: try: `u8::from(true)`
diff --git a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed
index 8a5645b22..b970b1209 100644
--- a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed
+++ b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed
@@ -1,5 +1,5 @@
// run-rustfix
-#![feature(stmt_expr_attributes, custom_inner_attributes)]
+#![feature(stmt_expr_attributes)]
#![allow(unused, clippy::no_effect, clippy::unnecessary_operation)]
#![warn(clippy::deprecated_cfg_attr)]
@@ -30,16 +30,14 @@ mod foo {
pub fn f() {}
}
+#[clippy::msrv = "1.29"]
fn msrv_1_29() {
- #![clippy::msrv = "1.29"]
-
#[cfg_attr(rustfmt, rustfmt::skip)]
1+29;
}
+#[clippy::msrv = "1.30"]
fn msrv_1_30() {
- #![clippy::msrv = "1.30"]
-
#[rustfmt::skip]
1+30;
}
diff --git a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs
index 2fb140efa..0a8e6a89d 100644
--- a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs
+++ b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs
@@ -1,5 +1,5 @@
// run-rustfix
-#![feature(stmt_expr_attributes, custom_inner_attributes)]
+#![feature(stmt_expr_attributes)]
#![allow(unused, clippy::no_effect, clippy::unnecessary_operation)]
#![warn(clippy::deprecated_cfg_attr)]
@@ -30,16 +30,14 @@ mod foo {
pub fn f() {}
}
+#[clippy::msrv = "1.29"]
fn msrv_1_29() {
- #![clippy::msrv = "1.29"]
-
#[cfg_attr(rustfmt, rustfmt::skip)]
1+29;
}
+#[clippy::msrv = "1.30"]
fn msrv_1_30() {
- #![clippy::msrv = "1.30"]
-
#[cfg_attr(rustfmt, rustfmt::skip)]
1+30;
}
diff --git a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr
index 08df7b2b3..524a2bf72 100644
--- a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr
+++ b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr
@@ -13,7 +13,7 @@ LL | #[cfg_attr(rustfmt, rustfmt_skip)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]`
error: `cfg_attr` is deprecated for rustfmt and got replaced by tool attributes
- --> $DIR/cfg_attr_rustfmt.rs:43:5
+ --> $DIR/cfg_attr_rustfmt.rs:41:5
|
LL | #[cfg_attr(rustfmt, rustfmt::skip)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]`
diff --git a/src/tools/clippy/tests/ui/checked_conversions.fixed b/src/tools/clippy/tests/ui/checked_conversions.fixed
index f936957cb..e279ba314 100644
--- a/src/tools/clippy/tests/ui/checked_conversions.fixed
+++ b/src/tools/clippy/tests/ui/checked_conversions.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![allow(
clippy::cast_lossless,
unused,
@@ -78,16 +77,14 @@ pub const fn issue_8898(i: u32) -> bool {
i <= i32::MAX as u32
}
+#[clippy::msrv = "1.33"]
fn msrv_1_33() {
- #![clippy::msrv = "1.33"]
-
let value: i64 = 33;
let _ = value <= (u32::MAX as i64) && value >= 0;
}
+#[clippy::msrv = "1.34"]
fn msrv_1_34() {
- #![clippy::msrv = "1.34"]
-
let value: i64 = 34;
let _ = u32::try_from(value).is_ok();
}
diff --git a/src/tools/clippy/tests/ui/checked_conversions.rs b/src/tools/clippy/tests/ui/checked_conversions.rs
index 77aec713f..9d7a40995 100644
--- a/src/tools/clippy/tests/ui/checked_conversions.rs
+++ b/src/tools/clippy/tests/ui/checked_conversions.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![allow(
clippy::cast_lossless,
unused,
@@ -78,16 +77,14 @@ pub const fn issue_8898(i: u32) -> bool {
i <= i32::MAX as u32
}
+#[clippy::msrv = "1.33"]
fn msrv_1_33() {
- #![clippy::msrv = "1.33"]
-
let value: i64 = 33;
let _ = value <= (u32::MAX as i64) && value >= 0;
}
+#[clippy::msrv = "1.34"]
fn msrv_1_34() {
- #![clippy::msrv = "1.34"]
-
let value: i64 = 34;
let _ = value <= (u32::MAX as i64) && value >= 0;
}
diff --git a/src/tools/clippy/tests/ui/checked_conversions.stderr b/src/tools/clippy/tests/ui/checked_conversions.stderr
index b2bf7af8d..273ead73b 100644
--- a/src/tools/clippy/tests/ui/checked_conversions.stderr
+++ b/src/tools/clippy/tests/ui/checked_conversions.stderr
@@ -1,5 +1,5 @@
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:17:13
+ --> $DIR/checked_conversions.rs:16:13
|
LL | let _ = value <= (u32::max_value() as i64) && value >= 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()`
@@ -7,97 +7,97 @@ LL | let _ = value <= (u32::max_value() as i64) && value >= 0;
= note: `-D clippy::checked-conversions` implied by `-D warnings`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:18:13
+ --> $DIR/checked_conversions.rs:17:13
|
LL | let _ = value <= (u32::MAX as i64) && value >= 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:22:13
+ --> $DIR/checked_conversions.rs:21:13
|
LL | let _ = value <= i64::from(u16::max_value()) && value >= 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:23:13
+ --> $DIR/checked_conversions.rs:22:13
|
LL | let _ = value <= i64::from(u16::MAX) && value >= 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:27:13
+ --> $DIR/checked_conversions.rs:26:13
|
LL | let _ = value <= (u8::max_value() as isize) && value >= 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u8::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:28:13
+ --> $DIR/checked_conversions.rs:27:13
|
LL | let _ = value <= (u8::MAX as isize) && value >= 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u8::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:34:13
+ --> $DIR/checked_conversions.rs:33:13
|
LL | let _ = value <= (i32::max_value() as i64) && value >= (i32::min_value() as i64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:35:13
+ --> $DIR/checked_conversions.rs:34:13
|
LL | let _ = value <= (i32::MAX as i64) && value >= (i32::MIN as i64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:39:13
+ --> $DIR/checked_conversions.rs:38:13
|
LL | let _ = value <= i64::from(i16::max_value()) && value >= i64::from(i16::min_value());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i16::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:40:13
+ --> $DIR/checked_conversions.rs:39:13
|
LL | let _ = value <= i64::from(i16::MAX) && value >= i64::from(i16::MIN);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i16::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:46:13
+ --> $DIR/checked_conversions.rs:45:13
|
LL | let _ = value <= i32::max_value() as u32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:47:13
+ --> $DIR/checked_conversions.rs:46:13
|
LL | let _ = value <= i32::MAX as u32;
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:51:13
+ --> $DIR/checked_conversions.rs:50:13
|
LL | let _ = value <= isize::max_value() as usize && value as i32 == 5;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `isize::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:52:13
+ --> $DIR/checked_conversions.rs:51:13
|
LL | let _ = value <= isize::MAX as usize && value as i32 == 5;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `isize::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:56:13
+ --> $DIR/checked_conversions.rs:55:13
|
LL | let _ = value <= u16::max_value() as u32 && value as i32 == 5;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:57:13
+ --> $DIR/checked_conversions.rs:56:13
|
LL | let _ = value <= u16::MAX as u32 && value as i32 == 5;
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:92:13
+ --> $DIR/checked_conversions.rs:89:13
|
LL | let _ = value <= (u32::MAX as i64) && value >= 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()`
diff --git a/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed b/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed
index 42ed232d1..ecbfc1fee 100644
--- a/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed
+++ b/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::cloned_instead_of_copied)]
#![allow(unused)]
@@ -17,23 +16,20 @@ fn main() {
let _ = Some(&String::new()).cloned();
}
+#[clippy::msrv = "1.34"]
fn msrv_1_34() {
- #![clippy::msrv = "1.34"]
-
let _ = [1].iter().cloned();
let _ = Some(&1).cloned();
}
+#[clippy::msrv = "1.35"]
fn msrv_1_35() {
- #![clippy::msrv = "1.35"]
-
let _ = [1].iter().cloned();
let _ = Some(&1).copied(); // Option::copied needs 1.35
}
+#[clippy::msrv = "1.36"]
fn msrv_1_36() {
- #![clippy::msrv = "1.36"]
-
let _ = [1].iter().copied(); // Iterator::copied needs 1.36
let _ = Some(&1).copied();
}
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 471bd9654..163dc3ddd 100644
--- a/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs
+++ b/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::cloned_instead_of_copied)]
#![allow(unused)]
@@ -17,23 +16,20 @@ fn main() {
let _ = Some(&String::new()).cloned();
}
+#[clippy::msrv = "1.34"]
fn msrv_1_34() {
- #![clippy::msrv = "1.34"]
-
let _ = [1].iter().cloned();
let _ = Some(&1).cloned();
}
+#[clippy::msrv = "1.35"]
fn msrv_1_35() {
- #![clippy::msrv = "1.35"]
-
let _ = [1].iter().cloned();
let _ = Some(&1).cloned(); // Option::copied needs 1.35
}
+#[clippy::msrv = "1.36"]
fn msrv_1_36() {
- #![clippy::msrv = "1.36"]
-
let _ = [1].iter().cloned(); // Iterator::copied needs 1.36
let _ = Some(&1).cloned();
}
diff --git a/src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr b/src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr
index 914c9a91e..e0361acd9 100644
--- a/src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr
+++ b/src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr
@@ -1,5 +1,5 @@
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:9:24
+ --> $DIR/cloned_instead_of_copied.rs:8:24
|
LL | let _ = [1].iter().cloned();
| ^^^^^^ help: try: `copied`
@@ -7,43 +7,43 @@ LL | let _ = [1].iter().cloned();
= note: `-D clippy::cloned-instead-of-copied` implied by `-D warnings`
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:10:31
+ --> $DIR/cloned_instead_of_copied.rs:9:31
|
LL | let _ = vec!["hi"].iter().cloned();
| ^^^^^^ help: try: `copied`
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:11:22
+ --> $DIR/cloned_instead_of_copied.rs:10:22
|
LL | let _ = Some(&1).cloned();
| ^^^^^^ help: try: `copied`
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:12:34
+ --> $DIR/cloned_instead_of_copied.rs:11:34
|
LL | let _ = Box::new([1].iter()).cloned();
| ^^^^^^ help: try: `copied`
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:13:32
+ --> $DIR/cloned_instead_of_copied.rs:12:32
|
LL | let _ = Box::new(Some(&1)).cloned();
| ^^^^^^ help: try: `copied`
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:31:22
+ --> $DIR/cloned_instead_of_copied.rs:28:22
|
LL | let _ = Some(&1).cloned(); // Option::copied needs 1.35
| ^^^^^^ help: try: `copied`
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:37:24
+ --> $DIR/cloned_instead_of_copied.rs:33:24
|
LL | let _ = [1].iter().cloned(); // Iterator::copied needs 1.36
| ^^^^^^ help: try: `copied`
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:38:22
+ --> $DIR/cloned_instead_of_copied.rs:34:22
|
LL | let _ = Some(&1).cloned();
| ^^^^^^ help: try: `copied`
diff --git a/src/tools/clippy/tests/ui/cognitive_complexity.rs b/src/tools/clippy/tests/ui/cognitive_complexity.rs
index 912e6788a..07bdaff00 100644
--- a/src/tools/clippy/tests/ui/cognitive_complexity.rs
+++ b/src/tools/clippy/tests/ui/cognitive_complexity.rs
@@ -393,3 +393,19 @@ impl Moo {
}
}
}
+
+#[clippy::cognitive_complexity = "1"]
+mod issue9300 {
+ async fn a() {
+ let a = 0;
+ if a == 0 {}
+ }
+
+ pub struct S;
+ impl S {
+ pub async fn async_method() {
+ let a = 0;
+ if a == 0 {}
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/cognitive_complexity.stderr b/src/tools/clippy/tests/ui/cognitive_complexity.stderr
index d7f2f24e5..5824631fa 100644
--- a/src/tools/clippy/tests/ui/cognitive_complexity.stderr
+++ b/src/tools/clippy/tests/ui/cognitive_complexity.stderr
@@ -135,5 +135,21 @@ LL | fn moo(&self) {
|
= help: you could split it up into multiple smaller functions
-error: aborting due to 17 previous errors
+error: the function has a cognitive complexity of (2/1)
+ --> $DIR/cognitive_complexity.rs:399:14
+ |
+LL | async fn a() {
+ | ^
+ |
+ = help: you could split it up into multiple smaller functions
+
+error: the function has a cognitive complexity of (2/1)
+ --> $DIR/cognitive_complexity.rs:406:22
+ |
+LL | pub async fn async_method() {
+ | ^^^^^^^^^^^^
+ |
+ = help: you could split it up into multiple smaller functions
+
+error: aborting due to 19 previous errors
diff --git a/src/tools/clippy/tests/ui/crashes/ice-2774.stderr b/src/tools/clippy/tests/ui/crashes/ice-2774.stderr
index 0c2d48f93..1f26c7f4d 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-2774.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-2774.stderr
@@ -1,4 +1,4 @@
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
+error: the following explicit lifetimes could be elided: 'a
--> $DIR/ice-2774.rs:15:1
|
LL | pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) {
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6250.stderr b/src/tools/clippy/tests/ui/crashes/ice-6250.stderr
index 878897c41..4506d1550 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6250.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-6250.stderr
@@ -23,6 +23,11 @@ error[E0308]: mismatched types
|
LL | Some(reference) = cache.data.get(key) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
+ |
+help: consider adding `let`
+ |
+LL | let Some(reference) = cache.data.get(key) {
+ | +++
error: aborting due to 3 previous errors
diff --git a/src/tools/clippy/tests/ui/crashes/ice-9746.rs b/src/tools/clippy/tests/ui/crashes/ice-9746.rs
new file mode 100644
index 000000000..fbd373c70
--- /dev/null
+++ b/src/tools/clippy/tests/ui/crashes/ice-9746.rs
@@ -0,0 +1,15 @@
+//! <https://github.com/rust-lang/rust-clippy/issues/9746#issuecomment-1297132880>
+
+trait Trait {}
+
+struct Struct<'a> {
+ _inner: &'a Struct<'a>,
+}
+
+impl Trait for Struct<'_> {}
+
+fn example<'a>(s: &'a Struct) -> Box<Box<dyn Trait + 'a>> {
+ Box::new(Box::new(Struct { _inner: s }))
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.stderr b/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.stderr
index d68bbe788..875d5ab4f 100644
--- a/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.stderr
+++ b/src/tools/clippy/tests/ui/crashes/needless_lifetimes_impl_trait.stderr
@@ -1,4 +1,4 @@
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
+error: the following explicit lifetimes could be elided: 'a
--> $DIR/needless_lifetimes_impl_trait.rs:15:5
|
LL | fn baz<'a>(&'a self) -> impl Foo + 'a {
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 4a5c597dd..e1c9fe30a 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,6 +1,5 @@
// compile-flags: -Clink-arg=-nostartfiles
// ignore-macos
-// ignore-windows
#![feature(lang_items, start, libc)]
#![no_std]
diff --git a/src/tools/clippy/tests/ui/doc_errors.stderr b/src/tools/clippy/tests/ui/doc_errors.stderr
index c7b616e28..d74f2dbfe 100644
--- a/src/tools/clippy/tests/ui/doc_errors.stderr
+++ b/src/tools/clippy/tests/ui/doc_errors.stderr
@@ -1,52 +1,40 @@
error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:7:1
|
-LL | / pub fn pub_fn_missing_errors_header() -> Result<(), ()> {
-LL | | unimplemented!();
-LL | | }
- | |_^
+LL | pub fn pub_fn_missing_errors_header() -> Result<(), ()> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::missing-errors-doc` implied by `-D warnings`
error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:11:1
|
-LL | / pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> {
-LL | | unimplemented!();
-LL | | }
- | |_^
+LL | pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:16:1
|
-LL | / pub fn pub_fn_returning_io_result() -> io::Result<()> {
-LL | | unimplemented!();
-LL | | }
- | |_^
+LL | pub fn pub_fn_returning_io_result() -> io::Result<()> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:21:1
|
-LL | / pub async fn async_pub_fn_returning_io_result() -> io::Result<()> {
-LL | | unimplemented!();
-LL | | }
- | |_^
+LL | pub async fn async_pub_fn_returning_io_result() -> io::Result<()> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:51:5
|
-LL | / pub fn pub_method_missing_errors_header() -> Result<(), ()> {
-LL | | unimplemented!();
-LL | | }
- | |_____^
+LL | pub fn pub_method_missing_errors_header() -> Result<(), ()> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:56:5
|
-LL | / pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> {
-LL | | unimplemented!();
-LL | | }
- | |_____^
+LL | pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:85:5
diff --git a/src/tools/clippy/tests/ui/doc_unsafe.stderr b/src/tools/clippy/tests/ui/doc_unsafe.stderr
index 904b88eae..a86e19137 100644
--- a/src/tools/clippy/tests/ui/doc_unsafe.stderr
+++ b/src/tools/clippy/tests/ui/doc_unsafe.stderr
@@ -1,20 +1,16 @@
error: unsafe function's docs miss `# Safety` section
--> $DIR/doc_unsafe.rs:9:1
|
-LL | / pub unsafe fn destroy_the_planet() {
-LL | | unimplemented!();
-LL | | }
- | |_^
+LL | pub unsafe fn destroy_the_planet() {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::missing-safety-doc` implied by `-D warnings`
error: unsafe function's docs miss `# Safety` section
--> $DIR/doc_unsafe.rs:32:5
|
-LL | / pub unsafe fn republished() {
-LL | | unimplemented!();
-LL | | }
- | |_____^
+LL | pub unsafe fn republished() {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: unsafe function's docs miss `# Safety` section
--> $DIR/doc_unsafe.rs:40:5
@@ -25,29 +21,23 @@ LL | unsafe fn woefully_underdocumented(self);
error: docs for unsafe trait missing `# Safety` section
--> $DIR/doc_unsafe.rs:46:1
|
-LL | / pub unsafe trait UnsafeTrait {
-LL | | fn method();
-LL | | }
- | |_^
+LL | pub unsafe trait UnsafeTrait {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: unsafe function's docs miss `# Safety` section
--> $DIR/doc_unsafe.rs:76:5
|
-LL | / pub unsafe fn more_undocumented_unsafe() -> Self {
-LL | | unimplemented!();
-LL | | }
- | |_____^
+LL | pub unsafe fn more_undocumented_unsafe() -> Self {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: unsafe function's docs miss `# Safety` section
--> $DIR/doc_unsafe.rs:92:9
|
-LL | / pub unsafe fn whee() {
-LL | | unimplemented!()
-LL | | }
- | |_________^
+LL | pub unsafe fn whee() {
+ | ^^^^^^^^^^^^^^^^^^^^
...
-LL | very_unsafe!();
- | -------------- in this macro invocation
+LL | very_unsafe!();
+ | -------------- in this macro invocation
|
= note: this error originates in the macro `very_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/src/tools/clippy/tests/ui/eq_op.rs b/src/tools/clippy/tests/ui/eq_op.rs
index 422f94865..e73795502 100644
--- a/src/tools/clippy/tests/ui/eq_op.rs
+++ b/src/tools/clippy/tests/ui/eq_op.rs
@@ -2,6 +2,7 @@
#![warn(clippy::eq_op)]
#![allow(clippy::double_parens, clippy::identity_op, clippy::nonminimal_bool)]
+#![allow(clippy::suspicious_xor_used_as_pow)]
fn main() {
// simple values and comparisons
diff --git a/src/tools/clippy/tests/ui/eq_op.stderr b/src/tools/clippy/tests/ui/eq_op.stderr
index 313ceed2b..d365ab27e 100644
--- a/src/tools/clippy/tests/ui/eq_op.stderr
+++ b/src/tools/clippy/tests/ui/eq_op.stderr
@@ -1,5 +1,5 @@
error: equal expressions as operands to `==`
- --> $DIR/eq_op.rs:8:13
+ --> $DIR/eq_op.rs:9:13
|
LL | let _ = 1 == 1;
| ^^^^^^
@@ -7,163 +7,163 @@ LL | let _ = 1 == 1;
= note: `-D clippy::eq-op` implied by `-D warnings`
error: equal expressions as operands to `==`
- --> $DIR/eq_op.rs:9:13
+ --> $DIR/eq_op.rs:10:13
|
LL | let _ = "no" == "no";
| ^^^^^^^^^^^^
error: equal expressions as operands to `!=`
- --> $DIR/eq_op.rs:11:13
+ --> $DIR/eq_op.rs:12:13
|
LL | let _ = false != false;
| ^^^^^^^^^^^^^^
error: equal expressions as operands to `<`
- --> $DIR/eq_op.rs:12:13
+ --> $DIR/eq_op.rs:13:13
|
LL | let _ = 1.5 < 1.5;
| ^^^^^^^^^
error: equal expressions as operands to `>=`
- --> $DIR/eq_op.rs:13:13
+ --> $DIR/eq_op.rs:14:13
|
LL | let _ = 1u64 >= 1u64;
| ^^^^^^^^^^^^
error: equal expressions as operands to `&`
- --> $DIR/eq_op.rs:16:13
+ --> $DIR/eq_op.rs:17:13
|
LL | let _ = (1u32 as u64) & (1u32 as u64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `^`
- --> $DIR/eq_op.rs:19:17
+ --> $DIR/eq_op.rs:20:17
|
LL | let _ = 1 ^ ((((((1))))));
| ^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `<`
- --> $DIR/eq_op.rs:23:13
+ --> $DIR/eq_op.rs:24:13
|
LL | let _ = (-(2) < -(2));
| ^^^^^^^^^^^^^
error: equal expressions as operands to `==`
- --> $DIR/eq_op.rs:24:13
+ --> $DIR/eq_op.rs:25:13
|
LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `&`
- --> $DIR/eq_op.rs:24:14
+ --> $DIR/eq_op.rs:25:14
|
LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
| ^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `&`
- --> $DIR/eq_op.rs:24:35
+ --> $DIR/eq_op.rs:25:35
|
LL | let _ = ((1 + 1) & (1 + 1) == (1 + 1) & (1 + 1));
| ^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `==`
- --> $DIR/eq_op.rs:25:13
+ --> $DIR/eq_op.rs:26:13
|
LL | let _ = (1 * 2) + (3 * 4) == 1 * 2 + 3 * 4;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `!=`
- --> $DIR/eq_op.rs:28:13
+ --> $DIR/eq_op.rs:29:13
|
LL | let _ = ([1] != [1]);
| ^^^^^^^^^^^^
error: equal expressions as operands to `!=`
- --> $DIR/eq_op.rs:29:13
+ --> $DIR/eq_op.rs:30:13
|
LL | let _ = ((1, 2) != (1, 2));
| ^^^^^^^^^^^^^^^^^^
error: equal expressions as operands to `==`
- --> $DIR/eq_op.rs:33:13
+ --> $DIR/eq_op.rs:34:13
|
LL | let _ = 1 + 1 == 2;
| ^^^^^^^^^^
error: equal expressions as operands to `==`
- --> $DIR/eq_op.rs:34:13
+ --> $DIR/eq_op.rs:35:13
|
LL | let _ = 1 - 1 == 0;
| ^^^^^^^^^^
error: equal expressions as operands to `-`
- --> $DIR/eq_op.rs:34:13
+ --> $DIR/eq_op.rs:35:13
|
LL | let _ = 1 - 1 == 0;
| ^^^^^
error: equal expressions as operands to `-`
- --> $DIR/eq_op.rs:36:13
+ --> $DIR/eq_op.rs:37:13
|
LL | let _ = 1 - 1;
| ^^^^^
error: equal expressions as operands to `/`
- --> $DIR/eq_op.rs:37:13
+ --> $DIR/eq_op.rs:38:13
|
LL | let _ = 1 / 1;
| ^^^^^
error: equal expressions as operands to `&&`
- --> $DIR/eq_op.rs:38:13
+ --> $DIR/eq_op.rs:39:13
|
LL | let _ = true && true;
| ^^^^^^^^^^^^
error: equal expressions as operands to `||`
- --> $DIR/eq_op.rs:40:13
+ --> $DIR/eq_op.rs:41:13
|
LL | let _ = true || true;
| ^^^^^^^^^^^^
error: equal expressions as operands to `&&`
- --> $DIR/eq_op.rs:45:13
+ --> $DIR/eq_op.rs:46:13
|
LL | let _ = a == b && b == a;
| ^^^^^^^^^^^^^^^^
error: equal expressions as operands to `&&`
- --> $DIR/eq_op.rs:46:13
+ --> $DIR/eq_op.rs:47:13
|
LL | let _ = a != b && b != a;
| ^^^^^^^^^^^^^^^^
error: equal expressions as operands to `&&`
- --> $DIR/eq_op.rs:47:13
+ --> $DIR/eq_op.rs:48:13
|
LL | let _ = a < b && b > a;
| ^^^^^^^^^^^^^^
error: equal expressions as operands to `&&`
- --> $DIR/eq_op.rs:48:13
+ --> $DIR/eq_op.rs:49:13
|
LL | let _ = a <= b && b >= a;
| ^^^^^^^^^^^^^^^^
error: equal expressions as operands to `==`
- --> $DIR/eq_op.rs:51:13
+ --> $DIR/eq_op.rs:52:13
|
LL | let _ = a == a;
| ^^^^^^
error: equal expressions as operands to `/`
- --> $DIR/eq_op.rs:61:20
+ --> $DIR/eq_op.rs:62:20
|
LL | const D: u32 = A / A;
| ^^^^^
error: equal expressions as operands to `==`
- --> $DIR/eq_op.rs:92:5
+ --> $DIR/eq_op.rs:93:5
|
LL | (n1.inner.0).0 == (n1.inner.0).0 && (n1.inner.1).0 == (n2.inner.1).0 && (n1.inner.2).0 == (n2.inner.2).0
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/equatable_if_let.fixed b/src/tools/clippy/tests/ui/equatable_if_let.fixed
index 687efdada..9af2ba962 100644
--- a/src/tools/clippy/tests/ui/equatable_if_let.fixed
+++ b/src/tools/clippy/tests/ui/equatable_if_let.fixed
@@ -23,6 +23,11 @@ struct Struct {
b: bool,
}
+struct NoPartialEqStruct {
+ a: i32,
+ b: bool,
+}
+
enum NotPartialEq {
A,
B,
@@ -47,6 +52,7 @@ fn main() {
let e = Enum::UnitVariant;
let f = NotPartialEq::A;
let g = NotStructuralEq::A;
+ let h = NoPartialEqStruct { a: 2, b: false };
// true
@@ -66,10 +72,11 @@ fn main() {
if let Some(3 | 4) = c {}
if let Struct { a, b: false } = d {}
if let Struct { a: 2, b: x } = d {}
- if let NotPartialEq::A = f {}
+ if matches!(f, NotPartialEq::A) {}
if g == NotStructuralEq::A {}
- if let Some(NotPartialEq::A) = Some(f) {}
+ if matches!(Some(f), Some(NotPartialEq::A)) {}
if Some(g) == Some(NotStructuralEq::A) {}
+ if matches!(h, NoPartialEqStruct { a: 2, b: false }) {}
macro_rules! m1 {
(x) => {
diff --git a/src/tools/clippy/tests/ui/equatable_if_let.rs b/src/tools/clippy/tests/ui/equatable_if_let.rs
index 8c467d14d..c3626c081 100644
--- a/src/tools/clippy/tests/ui/equatable_if_let.rs
+++ b/src/tools/clippy/tests/ui/equatable_if_let.rs
@@ -23,6 +23,11 @@ struct Struct {
b: bool,
}
+struct NoPartialEqStruct {
+ a: i32,
+ b: bool,
+}
+
enum NotPartialEq {
A,
B,
@@ -47,6 +52,7 @@ fn main() {
let e = Enum::UnitVariant;
let f = NotPartialEq::A;
let g = NotStructuralEq::A;
+ let h = NoPartialEqStruct { a: 2, b: false };
// true
@@ -70,6 +76,7 @@ fn main() {
if let NotStructuralEq::A = g {}
if let Some(NotPartialEq::A) = Some(f) {}
if let Some(NotStructuralEq::A) = Some(g) {}
+ if let NoPartialEqStruct { a: 2, b: false } = h {}
macro_rules! m1 {
(x) => {
diff --git a/src/tools/clippy/tests/ui/equatable_if_let.stderr b/src/tools/clippy/tests/ui/equatable_if_let.stderr
index 9c4c3cc36..40ca75b8d 100644
--- a/src/tools/clippy/tests/ui/equatable_if_let.stderr
+++ b/src/tools/clippy/tests/ui/equatable_if_let.stderr
@@ -1,5 +1,5 @@
error: this pattern matching can be expressed using equality
- --> $DIR/equatable_if_let.rs:53:8
+ --> $DIR/equatable_if_let.rs:59:8
|
LL | if let 2 = a {}
| ^^^^^^^^^ help: try: `a == 2`
@@ -7,64 +7,82 @@ LL | if let 2 = a {}
= note: `-D clippy::equatable-if-let` implied by `-D warnings`
error: this pattern matching can be expressed using equality
- --> $DIR/equatable_if_let.rs:54:8
+ --> $DIR/equatable_if_let.rs:60:8
|
LL | if let Ordering::Greater = a.cmp(&b) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.cmp(&b) == Ordering::Greater`
error: this pattern matching can be expressed using equality
- --> $DIR/equatable_if_let.rs:55:8
+ --> $DIR/equatable_if_let.rs:61:8
|
LL | if let Some(2) = c {}
| ^^^^^^^^^^^^^^^ help: try: `c == Some(2)`
error: this pattern matching can be expressed using equality
- --> $DIR/equatable_if_let.rs:56:8
+ --> $DIR/equatable_if_let.rs:62:8
|
LL | if let Struct { a: 2, b: false } = d {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `d == (Struct { a: 2, b: false })`
error: this pattern matching can be expressed using equality
- --> $DIR/equatable_if_let.rs:57:8
+ --> $DIR/equatable_if_let.rs:63:8
|
LL | if let Enum::TupleVariant(32, 64) = e {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == Enum::TupleVariant(32, 64)`
error: this pattern matching can be expressed using equality
- --> $DIR/equatable_if_let.rs:58:8
+ --> $DIR/equatable_if_let.rs:64:8
|
LL | if let Enum::RecordVariant { a: 64, b: 32 } = e {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == (Enum::RecordVariant { a: 64, b: 32 })`
error: this pattern matching can be expressed using equality
- --> $DIR/equatable_if_let.rs:59:8
+ --> $DIR/equatable_if_let.rs:65:8
|
LL | if let Enum::UnitVariant = e {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `e == Enum::UnitVariant`
error: this pattern matching can be expressed using equality
- --> $DIR/equatable_if_let.rs:60:8
+ --> $DIR/equatable_if_let.rs:66:8
|
LL | if let (Enum::UnitVariant, &Struct { a: 2, b: false }) = (e, &d) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(e, &d) == (Enum::UnitVariant, &Struct { a: 2, b: false })`
+error: this pattern matching can be expressed using `matches!`
+ --> $DIR/equatable_if_let.rs:75:8
+ |
+LL | if let NotPartialEq::A = f {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(f, NotPartialEq::A)`
+
error: this pattern matching can be expressed using equality
- --> $DIR/equatable_if_let.rs:70:8
+ --> $DIR/equatable_if_let.rs:76:8
|
LL | if let NotStructuralEq::A = g {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `g == NotStructuralEq::A`
+error: this pattern matching can be expressed using `matches!`
+ --> $DIR/equatable_if_let.rs:77:8
+ |
+LL | if let Some(NotPartialEq::A) = Some(f) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(Some(f), Some(NotPartialEq::A))`
+
error: this pattern matching can be expressed using equality
- --> $DIR/equatable_if_let.rs:72:8
+ --> $DIR/equatable_if_let.rs:78:8
|
LL | if let Some(NotStructuralEq::A) = Some(g) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(g) == Some(NotStructuralEq::A)`
-error: this pattern matching can be expressed using equality
+error: this pattern matching can be expressed using `matches!`
--> $DIR/equatable_if_let.rs:79:8
|
+LL | if let NoPartialEqStruct { a: 2, b: false } = h {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(h, NoPartialEqStruct { a: 2, b: false })`
+
+error: this pattern matching can be expressed using equality
+ --> $DIR/equatable_if_let.rs:86:8
+ |
LL | if let m1!(x) = "abc" {
| ^^^^^^^^^^^^^^^^^^ help: try: `"abc" == m1!(x)`
-error: aborting due to 11 previous errors
+error: aborting due to 14 previous errors
diff --git a/src/tools/clippy/tests/ui/err_expect.fixed b/src/tools/clippy/tests/ui/err_expect.fixed
index 3bac738ac..b63cbd8a8 100644
--- a/src/tools/clippy/tests/ui/err_expect.fixed
+++ b/src/tools/clippy/tests/ui/err_expect.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![allow(unused)]
struct MyTypeNonDebug;
@@ -16,16 +15,14 @@ fn main() {
test_non_debug.err().expect("Testing non debug type");
}
+#[clippy::msrv = "1.16"]
fn msrv_1_16() {
- #![clippy::msrv = "1.16"]
-
let x: Result<u32, &str> = Ok(16);
x.err().expect("16");
}
+#[clippy::msrv = "1.17"]
fn msrv_1_17() {
- #![clippy::msrv = "1.17"]
-
let x: Result<u32, &str> = Ok(17);
x.expect_err("17");
}
diff --git a/src/tools/clippy/tests/ui/err_expect.rs b/src/tools/clippy/tests/ui/err_expect.rs
index 6e7c47d9a..c081a745f 100644
--- a/src/tools/clippy/tests/ui/err_expect.rs
+++ b/src/tools/clippy/tests/ui/err_expect.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![allow(unused)]
struct MyTypeNonDebug;
@@ -16,16 +15,14 @@ fn main() {
test_non_debug.err().expect("Testing non debug type");
}
+#[clippy::msrv = "1.16"]
fn msrv_1_16() {
- #![clippy::msrv = "1.16"]
-
let x: Result<u32, &str> = Ok(16);
x.err().expect("16");
}
+#[clippy::msrv = "1.17"]
fn msrv_1_17() {
- #![clippy::msrv = "1.17"]
-
let x: Result<u32, &str> = Ok(17);
x.err().expect("17");
}
diff --git a/src/tools/clippy/tests/ui/err_expect.stderr b/src/tools/clippy/tests/ui/err_expect.stderr
index 91a6cf8de..82c0754cf 100644
--- a/src/tools/clippy/tests/ui/err_expect.stderr
+++ b/src/tools/clippy/tests/ui/err_expect.stderr
@@ -1,5 +1,5 @@
error: called `.err().expect()` on a `Result` value
- --> $DIR/err_expect.rs:13:16
+ --> $DIR/err_expect.rs:12:16
|
LL | test_debug.err().expect("Testing debug type");
| ^^^^^^^^^^^^ help: try: `expect_err`
@@ -7,7 +7,7 @@ LL | test_debug.err().expect("Testing debug type");
= note: `-D clippy::err-expect` implied by `-D warnings`
error: called `.err().expect()` on a `Result` value
- --> $DIR/err_expect.rs:30:7
+ --> $DIR/err_expect.rs:27:7
|
LL | x.err().expect("17");
| ^^^^^^^^^^^^ help: try: `expect_err`
diff --git a/src/tools/clippy/tests/ui/eta.fixed b/src/tools/clippy/tests/ui/eta.fixed
index a9cc80aaa..dc129591e 100644
--- a/src/tools/clippy/tests/ui/eta.fixed
+++ b/src/tools/clippy/tests/ui/eta.fixed
@@ -316,3 +316,25 @@ pub fn mutable_impl_fn_mut(mut f: impl FnMut(), mut f_used_once: impl FnMut()) -
move || takes_fn_mut(&mut f_used_once)
}
+
+impl dyn TestTrait + '_ {
+ fn method_on_dyn(&self) -> bool {
+ false
+ }
+}
+
+// https://github.com/rust-lang/rust-clippy/issues/7746
+fn angle_brackets_and_substs() {
+ let array_opt: Option<&[u8; 3]> = Some(&[4, 8, 7]);
+ array_opt.map(<[u8; 3]>::as_slice);
+
+ let slice_opt: Option<&[u8]> = Some(b"slice");
+ slice_opt.map(<[u8]>::len);
+
+ let ptr_opt: Option<*const usize> = Some(&487);
+ ptr_opt.map(<*const usize>::is_null);
+
+ let test_struct = TestStruct { some_ref: &487 };
+ let dyn_opt: Option<&dyn TestTrait> = Some(&test_struct);
+ dyn_opt.map(<dyn TestTrait>::method_on_dyn);
+}
diff --git a/src/tools/clippy/tests/ui/eta.rs b/src/tools/clippy/tests/ui/eta.rs
index cc99906cc..025fd6a0b 100644
--- a/src/tools/clippy/tests/ui/eta.rs
+++ b/src/tools/clippy/tests/ui/eta.rs
@@ -316,3 +316,25 @@ pub fn mutable_impl_fn_mut(mut f: impl FnMut(), mut f_used_once: impl FnMut()) -
move || takes_fn_mut(|| f_used_once())
}
+
+impl dyn TestTrait + '_ {
+ fn method_on_dyn(&self) -> bool {
+ false
+ }
+}
+
+// https://github.com/rust-lang/rust-clippy/issues/7746
+fn angle_brackets_and_substs() {
+ let array_opt: Option<&[u8; 3]> = Some(&[4, 8, 7]);
+ array_opt.map(|a| a.as_slice());
+
+ let slice_opt: Option<&[u8]> = Some(b"slice");
+ slice_opt.map(|s| s.len());
+
+ let ptr_opt: Option<*const usize> = Some(&487);
+ ptr_opt.map(|p| p.is_null());
+
+ let test_struct = TestStruct { some_ref: &487 };
+ let dyn_opt: Option<&dyn TestTrait> = Some(&test_struct);
+ dyn_opt.map(|d| d.method_on_dyn());
+}
diff --git a/src/tools/clippy/tests/ui/eta.stderr b/src/tools/clippy/tests/ui/eta.stderr
index 434706b7e..a521fb868 100644
--- a/src/tools/clippy/tests/ui/eta.stderr
+++ b/src/tools/clippy/tests/ui/eta.stderr
@@ -134,5 +134,29 @@ error: redundant closure
LL | move || takes_fn_mut(|| f_used_once())
| ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once`
-error: aborting due to 22 previous errors
+error: redundant closure
+ --> $DIR/eta.rs:329:19
+ |
+LL | array_opt.map(|a| a.as_slice());
+ | ^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8; 3]>::as_slice`
+
+error: redundant closure
+ --> $DIR/eta.rs:332:19
+ |
+LL | slice_opt.map(|s| s.len());
+ | ^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8]>::len`
+
+error: redundant closure
+ --> $DIR/eta.rs:335:17
+ |
+LL | ptr_opt.map(|p| p.is_null());
+ | ^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<*const usize>::is_null`
+
+error: redundant closure
+ --> $DIR/eta.rs:339:17
+ |
+LL | dyn_opt.map(|d| d.method_on_dyn());
+ | ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<dyn TestTrait>::method_on_dyn`
+
+error: aborting due to 26 previous errors
diff --git a/src/tools/clippy/tests/ui/expect.stderr b/src/tools/clippy/tests/ui/expect.stderr
index f6738865c..c08e0dbbf 100644
--- a/src/tools/clippy/tests/ui/expect.stderr
+++ b/src/tools/clippy/tests/ui/expect.stderr
@@ -1,4 +1,4 @@
-error: used `expect()` on `an Option` value
+error: used `expect()` on an `Option` value
--> $DIR/expect.rs:5:13
|
LL | let _ = opt.expect("");
@@ -7,7 +7,7 @@ LL | let _ = opt.expect("");
= help: if this value is `None`, it will panic
= note: `-D clippy::expect-used` implied by `-D warnings`
-error: used `expect()` on `a Result` value
+error: used `expect()` on a `Result` value
--> $DIR/expect.rs:10:13
|
LL | let _ = res.expect("");
@@ -15,7 +15,7 @@ LL | let _ = res.expect("");
|
= help: if this value is an `Err`, it will panic
-error: used `expect_err()` on `a Result` value
+error: used `expect_err()` on a `Result` value
--> $DIR/expect.rs:11:13
|
LL | let _ = res.expect_err("");
diff --git a/src/tools/clippy/tests/ui/explicit_auto_deref.fixed b/src/tools/clippy/tests/ui/explicit_auto_deref.fixed
index d1d35e5c0..475fae5e8 100644
--- a/src/tools/clippy/tests/ui/explicit_auto_deref.fixed
+++ b/src/tools/clippy/tests/ui/explicit_auto_deref.fixed
@@ -266,4 +266,19 @@ fn main() {
}
x
};
+
+ trait WithAssoc {
+ type Assoc: ?Sized;
+ }
+ impl WithAssoc for String {
+ type Assoc = str;
+ }
+ fn takes_assoc<T: WithAssoc>(_: &T::Assoc) -> T {
+ unimplemented!()
+ }
+ let _: String = takes_assoc(&*String::new());
+
+ // Issue #9901
+ fn takes_ref(_: &i32) {}
+ takes_ref(*Box::new(&0i32));
}
diff --git a/src/tools/clippy/tests/ui/explicit_auto_deref.rs b/src/tools/clippy/tests/ui/explicit_auto_deref.rs
index deedafad1..c1894258f 100644
--- a/src/tools/clippy/tests/ui/explicit_auto_deref.rs
+++ b/src/tools/clippy/tests/ui/explicit_auto_deref.rs
@@ -266,4 +266,19 @@ fn main() {
}
*x
};
+
+ trait WithAssoc {
+ type Assoc: ?Sized;
+ }
+ impl WithAssoc for String {
+ type Assoc = str;
+ }
+ fn takes_assoc<T: WithAssoc>(_: &T::Assoc) -> T {
+ unimplemented!()
+ }
+ let _: String = takes_assoc(&*String::new());
+
+ // Issue #9901
+ fn takes_ref(_: &i32) {}
+ takes_ref(*Box::new(&0i32));
}
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 41828ddd7..462d46169 100644
--- a/src/tools/clippy/tests/ui/filter_map_next_fixable.fixed
+++ b/src/tools/clippy/tests/ui/filter_map_next_fixable.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::all, clippy::pedantic)]
#![allow(unused)]
@@ -11,16 +10,14 @@ fn main() {
assert_eq!(element, Some(1));
}
+#[clippy::msrv = "1.29"]
fn msrv_1_29() {
- #![clippy::msrv = "1.29"]
-
let a = ["1", "lol", "3", "NaN", "5"];
let _: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
}
+#[clippy::msrv = "1.30"]
fn msrv_1_30() {
- #![clippy::msrv = "1.30"]
-
let a = ["1", "lol", "3", "NaN", "5"];
let _: Option<i32> = a.iter().find_map(|s| s.parse().ok());
}
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 be492a81b..2ea00cf73 100644
--- a/src/tools/clippy/tests/ui/filter_map_next_fixable.rs
+++ b/src/tools/clippy/tests/ui/filter_map_next_fixable.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::all, clippy::pedantic)]
#![allow(unused)]
@@ -11,16 +10,14 @@ fn main() {
assert_eq!(element, Some(1));
}
+#[clippy::msrv = "1.29"]
fn msrv_1_29() {
- #![clippy::msrv = "1.29"]
-
let a = ["1", "lol", "3", "NaN", "5"];
let _: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
}
+#[clippy::msrv = "1.30"]
fn msrv_1_30() {
- #![clippy::msrv = "1.30"]
-
let a = ["1", "lol", "3", "NaN", "5"];
let _: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
}
diff --git a/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr b/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr
index e789efeab..a9fc6abe8 100644
--- a/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr
+++ b/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr
@@ -1,5 +1,5 @@
error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead
- --> $DIR/filter_map_next_fixable.rs:10:32
+ --> $DIR/filter_map_next_fixable.rs:9:32
|
LL | let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `a.iter().find_map(|s| s.parse().ok())`
@@ -7,7 +7,7 @@ LL | let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next
= note: `-D clippy::filter-map-next` implied by `-D warnings`
error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead
- --> $DIR/filter_map_next_fixable.rs:25:26
+ --> $DIR/filter_map_next_fixable.rs:22:26
|
LL | let _: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `a.iter().find_map(|s| s.parse().ok())`
diff --git a/src/tools/clippy/tests/ui/fn_params_excessive_bools.rs b/src/tools/clippy/tests/ui/fn_params_excessive_bools.rs
index f805bcc9b..f53e53162 100644
--- a/src/tools/clippy/tests/ui/fn_params_excessive_bools.rs
+++ b/src/tools/clippy/tests/ui/fn_params_excessive_bools.rs
@@ -2,6 +2,7 @@
#![allow(clippy::too_many_arguments)]
extern "C" {
+ // Should not lint, most of the time users have no control over extern function signatures
fn f(_: bool, _: bool, _: bool, _: bool);
}
@@ -22,8 +23,12 @@ fn t(_: S, _: S, _: Box<S>, _: Vec<u32>, _: bool, _: bool, _: bool, _: bool) {}
struct S;
trait Trait {
+ // should warn for trait functions with and without body
fn f(_: bool, _: bool, _: bool, _: bool);
fn g(_: bool, _: bool, _: bool, _: Vec<u32>);
+ #[allow(clippy::fn_params_excessive_bools)]
+ fn h(_: bool, _: bool, _: bool, _: bool, _: bool, _: bool);
+ fn i(_: bool, _: bool, _: bool, _: bool) {}
}
impl S {
@@ -34,8 +39,11 @@ impl S {
}
impl Trait for S {
+ // Should not lint because the trait might not be changeable by the user
+ // We only lint in the trait definition
fn f(_: bool, _: bool, _: bool, _: bool) {}
fn g(_: bool, _: bool, _: bool, _: Vec<u32>) {}
+ fn h(_: bool, _: bool, _: bool, _: bool, _: bool, _: bool) {}
}
fn main() {
diff --git a/src/tools/clippy/tests/ui/fn_params_excessive_bools.stderr b/src/tools/clippy/tests/ui/fn_params_excessive_bools.stderr
index 116271056..43363b469 100644
--- a/src/tools/clippy/tests/ui/fn_params_excessive_bools.stderr
+++ b/src/tools/clippy/tests/ui/fn_params_excessive_bools.stderr
@@ -1,5 +1,5 @@
error: more than 3 bools in function parameters
- --> $DIR/fn_params_excessive_bools.rs:18:1
+ --> $DIR/fn_params_excessive_bools.rs:19:1
|
LL | fn g(_: bool, _: bool, _: bool, _: bool) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | fn g(_: bool, _: bool, _: bool, _: bool) {}
= note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings`
error: more than 3 bools in function parameters
- --> $DIR/fn_params_excessive_bools.rs:21:1
+ --> $DIR/fn_params_excessive_bools.rs:22:1
|
LL | fn t(_: S, _: S, _: Box<S>, _: Vec<u32>, _: bool, _: bool, _: bool, _: bool) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,7 +16,7 @@ LL | fn t(_: S, _: S, _: Box<S>, _: Vec<u32>, _: bool, _: bool, _: bool, _: bool
= help: consider refactoring bools into two-variant enums
error: more than 3 bools in function parameters
- --> $DIR/fn_params_excessive_bools.rs:25:5
+ --> $DIR/fn_params_excessive_bools.rs:27:5
|
LL | fn f(_: bool, _: bool, _: bool, _: bool);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -24,7 +24,15 @@ LL | fn f(_: bool, _: bool, _: bool, _: bool);
= help: consider refactoring bools into two-variant enums
error: more than 3 bools in function parameters
- --> $DIR/fn_params_excessive_bools.rs:30:5
+ --> $DIR/fn_params_excessive_bools.rs:31:5
+ |
+LL | fn i(_: bool, _: bool, _: bool, _: bool) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: consider refactoring bools into two-variant enums
+
+error: more than 3 bools in function parameters
+ --> $DIR/fn_params_excessive_bools.rs:35:5
|
LL | fn f(&self, _: bool, _: bool, _: bool, _: bool) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -32,7 +40,7 @@ LL | fn f(&self, _: bool, _: bool, _: bool, _: bool) {}
= help: consider refactoring bools into two-variant enums
error: more than 3 bools in function parameters
- --> $DIR/fn_params_excessive_bools.rs:42:5
+ --> $DIR/fn_params_excessive_bools.rs:50:5
|
LL | / fn n(_: bool, _: u32, _: bool, _: Box<u32>, _: bool, _: bool) {
LL | | fn nn(_: bool, _: bool, _: bool, _: bool) {}
@@ -42,12 +50,12 @@ LL | | }
= help: consider refactoring bools into two-variant enums
error: more than 3 bools in function parameters
- --> $DIR/fn_params_excessive_bools.rs:43:9
+ --> $DIR/fn_params_excessive_bools.rs:51:9
|
LL | fn nn(_: bool, _: bool, _: bool, _: bool) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider refactoring bools into two-variant enums
-error: aborting due to 6 previous errors
+error: aborting due to 7 previous errors
diff --git a/src/tools/clippy/tests/ui/from_over_into.fixed b/src/tools/clippy/tests/ui/from_over_into.fixed
index 1cf49ca45..125c9a69c 100644
--- a/src/tools/clippy/tests/ui/from_over_into.fixed
+++ b/src/tools/clippy/tests/ui/from_over_into.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::from_over_into)]
#![allow(unused)]
@@ -60,9 +59,8 @@ impl From<String> for A {
}
}
+#[clippy::msrv = "1.40"]
fn msrv_1_40() {
- #![clippy::msrv = "1.40"]
-
struct FromOverInto<T>(Vec<T>);
impl<T> Into<FromOverInto<T>> for Vec<T> {
@@ -72,9 +70,8 @@ fn msrv_1_40() {
}
}
+#[clippy::msrv = "1.41"]
fn msrv_1_41() {
- #![clippy::msrv = "1.41"]
-
struct FromOverInto<T>(Vec<T>);
impl<T> From<Vec<T>> for FromOverInto<T> {
diff --git a/src/tools/clippy/tests/ui/from_over_into.rs b/src/tools/clippy/tests/ui/from_over_into.rs
index d30f3c3fc..5aa127bfa 100644
--- a/src/tools/clippy/tests/ui/from_over_into.rs
+++ b/src/tools/clippy/tests/ui/from_over_into.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::from_over_into)]
#![allow(unused)]
@@ -60,9 +59,8 @@ impl From<String> for A {
}
}
+#[clippy::msrv = "1.40"]
fn msrv_1_40() {
- #![clippy::msrv = "1.40"]
-
struct FromOverInto<T>(Vec<T>);
impl<T> Into<FromOverInto<T>> for Vec<T> {
@@ -72,9 +70,8 @@ fn msrv_1_40() {
}
}
+#[clippy::msrv = "1.41"]
fn msrv_1_41() {
- #![clippy::msrv = "1.41"]
-
struct FromOverInto<T>(Vec<T>);
impl<T> Into<FromOverInto<T>> for Vec<T> {
diff --git a/src/tools/clippy/tests/ui/from_over_into.stderr b/src/tools/clippy/tests/ui/from_over_into.stderr
index 9c2a7c04c..a1764a5ea 100644
--- a/src/tools/clippy/tests/ui/from_over_into.stderr
+++ b/src/tools/clippy/tests/ui/from_over_into.stderr
@@ -1,5 +1,5 @@
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
- --> $DIR/from_over_into.rs:10:1
+ --> $DIR/from_over_into.rs:9:1
|
LL | impl Into<StringWrapper> for String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -13,7 +13,7 @@ LL ~ StringWrapper(val)
|
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
- --> $DIR/from_over_into.rs:18:1
+ --> $DIR/from_over_into.rs:17:1
|
LL | impl Into<SelfType> for String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -26,7 +26,7 @@ LL ~ SelfType(String::new())
|
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
- --> $DIR/from_over_into.rs:33:1
+ --> $DIR/from_over_into.rs:32:1
|
LL | impl Into<SelfKeywords> for X {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -41,7 +41,7 @@ LL ~ let _: X = val;
|
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
- --> $DIR/from_over_into.rs:45:1
+ --> $DIR/from_over_into.rs:44:1
|
LL | impl core::convert::Into<bool> for crate::ExplicitPaths {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -59,7 +59,7 @@ LL ~ val.0
|
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
- --> $DIR/from_over_into.rs:80:5
+ --> $DIR/from_over_into.rs:77:5
|
LL | impl<T> Into<FromOverInto<T>> for Vec<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/from_raw_with_void_ptr.rs b/src/tools/clippy/tests/ui/from_raw_with_void_ptr.rs
new file mode 100644
index 000000000..8484da241
--- /dev/null
+++ b/src/tools/clippy/tests/ui/from_raw_with_void_ptr.rs
@@ -0,0 +1,34 @@
+#![warn(clippy::from_raw_with_void_ptr)]
+
+use std::ffi::c_void;
+use std::rc::Rc;
+use std::sync::Arc;
+
+fn main() {
+ // must lint
+ let ptr = Box::into_raw(Box::new(42usize)) as *mut c_void;
+ let _ = unsafe { Box::from_raw(ptr) };
+
+ // shouldn't be linted
+ let _ = unsafe { Box::from_raw(ptr as *mut usize) };
+
+ // shouldn't be linted
+ let should_not_lint_ptr = Box::into_raw(Box::new(12u8)) as *mut u8;
+ let _ = unsafe { Box::from_raw(should_not_lint_ptr as *mut u8) };
+
+ // must lint
+ let ptr = Rc::into_raw(Rc::new(42usize)) as *mut c_void;
+ let _ = unsafe { Rc::from_raw(ptr) };
+
+ // must lint
+ let ptr = Arc::into_raw(Arc::new(42usize)) as *mut c_void;
+ let _ = unsafe { Arc::from_raw(ptr) };
+
+ // must lint
+ let ptr = std::rc::Weak::into_raw(Rc::downgrade(&Rc::new(42usize))) as *mut c_void;
+ let _ = unsafe { std::rc::Weak::from_raw(ptr) };
+
+ // must lint
+ let ptr = std::sync::Weak::into_raw(Arc::downgrade(&Arc::new(42usize))) as *mut c_void;
+ let _ = unsafe { std::sync::Weak::from_raw(ptr) };
+}
diff --git a/src/tools/clippy/tests/ui/from_raw_with_void_ptr.stderr b/src/tools/clippy/tests/ui/from_raw_with_void_ptr.stderr
new file mode 100644
index 000000000..96e4af12b
--- /dev/null
+++ b/src/tools/clippy/tests/ui/from_raw_with_void_ptr.stderr
@@ -0,0 +1,63 @@
+error: creating a `Box` from a void raw pointer
+ --> $DIR/from_raw_with_void_ptr.rs:10:22
+ |
+LL | let _ = unsafe { Box::from_raw(ptr) };
+ | ^^^^^^^^^^^^^^^^^^
+ |
+help: cast this to a pointer of the appropriate type
+ --> $DIR/from_raw_with_void_ptr.rs:10:36
+ |
+LL | let _ = unsafe { Box::from_raw(ptr) };
+ | ^^^
+ = note: `-D clippy::from-raw-with-void-ptr` implied by `-D warnings`
+
+error: creating a `Rc` from a void raw pointer
+ --> $DIR/from_raw_with_void_ptr.rs:21:22
+ |
+LL | let _ = unsafe { Rc::from_raw(ptr) };
+ | ^^^^^^^^^^^^^^^^^
+ |
+help: cast this to a pointer of the appropriate type
+ --> $DIR/from_raw_with_void_ptr.rs:21:35
+ |
+LL | let _ = unsafe { Rc::from_raw(ptr) };
+ | ^^^
+
+error: creating a `Arc` from a void raw pointer
+ --> $DIR/from_raw_with_void_ptr.rs:25:22
+ |
+LL | let _ = unsafe { Arc::from_raw(ptr) };
+ | ^^^^^^^^^^^^^^^^^^
+ |
+help: cast this to a pointer of the appropriate type
+ --> $DIR/from_raw_with_void_ptr.rs:25:36
+ |
+LL | let _ = unsafe { Arc::from_raw(ptr) };
+ | ^^^
+
+error: creating a `Weak` from a void raw pointer
+ --> $DIR/from_raw_with_void_ptr.rs:29:22
+ |
+LL | let _ = unsafe { std::rc::Weak::from_raw(ptr) };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: cast this to a pointer of the appropriate type
+ --> $DIR/from_raw_with_void_ptr.rs:29:46
+ |
+LL | let _ = unsafe { std::rc::Weak::from_raw(ptr) };
+ | ^^^
+
+error: creating a `Weak` from a void raw pointer
+ --> $DIR/from_raw_with_void_ptr.rs:33:22
+ |
+LL | let _ = unsafe { std::sync::Weak::from_raw(ptr) };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: cast this to a pointer of the appropriate type
+ --> $DIR/from_raw_with_void_ptr.rs:33:48
+ |
+LL | let _ = unsafe { std::sync::Weak::from_raw(ptr) };
+ | ^^^
+
+error: aborting due to 5 previous errors
+
diff --git a/src/tools/clippy/tests/ui/get_unwrap.stderr b/src/tools/clippy/tests/ui/get_unwrap.stderr
index 937f85904..6dee4d5b4 100644
--- a/src/tools/clippy/tests/ui/get_unwrap.stderr
+++ b/src/tools/clippy/tests/ui/get_unwrap.stderr
@@ -10,7 +10,7 @@ note: the lint level is defined here
LL | #![deny(clippy::get_unwrap)]
| ^^^^^^^^^^^^^^^^^^
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:35:17
|
LL | let _ = boxed_slice.get(1).unwrap();
@@ -25,7 +25,7 @@ error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more co
LL | let _ = some_slice.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_slice[0]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:36:17
|
LL | let _ = some_slice.get(0).unwrap();
@@ -39,7 +39,7 @@ error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more conc
LL | let _ = some_vec.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vec[0]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:37:17
|
LL | let _ = some_vec.get(0).unwrap();
@@ -53,7 +53,7 @@ error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more
LL | let _ = some_vecdeque.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vecdeque[0]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:38:17
|
LL | let _ = some_vecdeque.get(0).unwrap();
@@ -67,7 +67,7 @@ error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more
LL | let _ = some_hashmap.get(&1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_hashmap[&1]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:39:17
|
LL | let _ = some_hashmap.get(&1).unwrap();
@@ -81,7 +81,7 @@ error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more
LL | let _ = some_btreemap.get(&1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_btreemap[&1]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:40:17
|
LL | let _ = some_btreemap.get(&1).unwrap();
@@ -95,7 +95,7 @@ error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more co
LL | let _: u8 = *boxed_slice.get(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[1]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:44:22
|
LL | let _: u8 = *boxed_slice.get(1).unwrap();
@@ -109,7 +109,7 @@ error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and mor
LL | *boxed_slice.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[0]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:49:10
|
LL | *boxed_slice.get_mut(0).unwrap() = 1;
@@ -123,7 +123,7 @@ error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and mor
LL | *some_slice.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_slice[0]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:50:10
|
LL | *some_slice.get_mut(0).unwrap() = 1;
@@ -137,7 +137,7 @@ error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more
LL | *some_vec.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:51:10
|
LL | *some_vec.get_mut(0).unwrap() = 1;
@@ -151,7 +151,7 @@ error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vecdeque[0]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:52:10
|
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
@@ -165,7 +165,7 @@ error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more conc
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:64:17
|
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
@@ -179,7 +179,7 @@ error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/get_unwrap.rs:65:17
|
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
diff --git a/src/tools/clippy/tests/ui/if_then_some_else_none.rs b/src/tools/clippy/tests/ui/if_then_some_else_none.rs
index 3bc3a0395..0e89fdb0d 100644
--- a/src/tools/clippy/tests/ui/if_then_some_else_none.rs
+++ b/src/tools/clippy/tests/ui/if_then_some_else_none.rs
@@ -1,5 +1,4 @@
#![warn(clippy::if_then_some_else_none)]
-#![feature(custom_inner_attributes)]
fn main() {
// Should issue an error.
@@ -66,8 +65,8 @@ fn main() {
let _ = if foo() { into_some("foo") } else { None };
}
+#[clippy::msrv = "1.49"]
fn _msrv_1_49() {
- #![clippy::msrv = "1.49"]
// `bool::then` was stabilized in 1.50. Do not lint this
let _ = if foo() {
println!("true!");
@@ -77,8 +76,8 @@ fn _msrv_1_49() {
};
}
+#[clippy::msrv = "1.50"]
fn _msrv_1_50() {
- #![clippy::msrv = "1.50"]
let _ = if foo() {
println!("true!");
Some(150)
diff --git a/src/tools/clippy/tests/ui/if_then_some_else_none.stderr b/src/tools/clippy/tests/ui/if_then_some_else_none.stderr
index 24e0b5947..d728a3c31 100644
--- a/src/tools/clippy/tests/ui/if_then_some_else_none.stderr
+++ b/src/tools/clippy/tests/ui/if_then_some_else_none.stderr
@@ -1,5 +1,5 @@
error: this could be simplified with `bool::then`
- --> $DIR/if_then_some_else_none.rs:6:13
+ --> $DIR/if_then_some_else_none.rs:5:13
|
LL | let _ = if foo() {
| _____________^
@@ -14,7 +14,7 @@ LL | | };
= note: `-D clippy::if-then-some-else-none` implied by `-D warnings`
error: this could be simplified with `bool::then`
- --> $DIR/if_then_some_else_none.rs:14:13
+ --> $DIR/if_then_some_else_none.rs:13:13
|
LL | let _ = if matches!(true, true) {
| _____________^
@@ -28,7 +28,7 @@ LL | | };
= help: consider using `bool::then` like: `matches!(true, true).then(|| { /* snippet */ matches!(true, false) })`
error: this could be simplified with `bool::then_some`
- --> $DIR/if_then_some_else_none.rs:23:28
+ --> $DIR/if_then_some_else_none.rs:22:28
|
LL | let _ = x.and_then(|o| if o < 32 { Some(o) } else { None });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -36,7 +36,7 @@ LL | let _ = x.and_then(|o| if o < 32 { Some(o) } else { None });
= help: consider using `bool::then_some` like: `(o < 32).then_some(o)`
error: this could be simplified with `bool::then_some`
- --> $DIR/if_then_some_else_none.rs:27:13
+ --> $DIR/if_then_some_else_none.rs:26:13
|
LL | let _ = if !x { Some(0) } else { None };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -44,7 +44,7 @@ LL | let _ = if !x { Some(0) } else { None };
= help: consider using `bool::then_some` like: `(!x).then_some(0)`
error: this could be simplified with `bool::then`
- --> $DIR/if_then_some_else_none.rs:82:13
+ --> $DIR/if_then_some_else_none.rs:81:13
|
LL | let _ = if foo() {
| _____________^
diff --git a/src/tools/clippy/tests/ui/indexing_slicing_index.stderr b/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
index da5bc38b3..d8b6e3f12 100644
--- a/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
+++ b/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
@@ -4,11 +4,11 @@ error[E0080]: evaluation of `main::{constant#3}` failed
LL | const { &ARR[idx4()] }; // Ok, let rustc handle const contexts.
| ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
-error[E0080]: erroneous constant used
+note: erroneous constant used
--> $DIR/indexing_slicing_index.rs:31:5
|
LL | const { &ARR[idx4()] }; // Ok, let rustc handle const contexts.
- | ^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
+ | ^^^^^^^^^^^^^^^^^^^^^^
error: indexing may panic
--> $DIR/indexing_slicing_index.rs:22:5
@@ -65,6 +65,6 @@ error[E0080]: evaluation of constant value failed
LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
| ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
-error: aborting due to 9 previous errors
+error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0080`.
diff --git a/src/tools/clippy/tests/ui/infallible_destructuring_match.fixed b/src/tools/clippy/tests/ui/infallible_destructuring_match.fixed
index b8e40d995..61985e56b 100644
--- a/src/tools/clippy/tests/ui/infallible_destructuring_match.fixed
+++ b/src/tools/clippy/tests/ui/infallible_destructuring_match.fixed
@@ -9,6 +9,9 @@ enum SingleVariantEnum {
struct TupleStruct(i32);
+struct NonCopy;
+struct TupleStructWithNonCopy(NonCopy);
+
enum EmptyEnum {}
macro_rules! match_enum {
@@ -71,6 +74,15 @@ fn infallible_destructuring_match_struct() {
let TupleStruct(data) = wrapper;
}
+fn infallible_destructuring_match_struct_with_noncopy() {
+ let wrapper = TupleStructWithNonCopy(NonCopy);
+
+ // This should lint! (keeping `ref` in the suggestion)
+ let TupleStructWithNonCopy(ref data) = wrapper;
+
+ let TupleStructWithNonCopy(ref data) = wrapper;
+}
+
macro_rules! match_never_enum {
($param:expr) => {
let data = match $param {
diff --git a/src/tools/clippy/tests/ui/infallible_destructuring_match.rs b/src/tools/clippy/tests/ui/infallible_destructuring_match.rs
index 106cd438b..f2768245b 100644
--- a/src/tools/clippy/tests/ui/infallible_destructuring_match.rs
+++ b/src/tools/clippy/tests/ui/infallible_destructuring_match.rs
@@ -9,6 +9,9 @@ enum SingleVariantEnum {
struct TupleStruct(i32);
+struct NonCopy;
+struct TupleStructWithNonCopy(NonCopy);
+
enum EmptyEnum {}
macro_rules! match_enum {
@@ -75,6 +78,17 @@ fn infallible_destructuring_match_struct() {
let TupleStruct(data) = wrapper;
}
+fn infallible_destructuring_match_struct_with_noncopy() {
+ let wrapper = TupleStructWithNonCopy(NonCopy);
+
+ // This should lint! (keeping `ref` in the suggestion)
+ let data = match wrapper {
+ TupleStructWithNonCopy(ref n) => n,
+ };
+
+ let TupleStructWithNonCopy(ref data) = wrapper;
+}
+
macro_rules! match_never_enum {
($param:expr) => {
let data = match $param {
diff --git a/src/tools/clippy/tests/ui/infallible_destructuring_match.stderr b/src/tools/clippy/tests/ui/infallible_destructuring_match.stderr
index 1b78db420..f8a50f022 100644
--- a/src/tools/clippy/tests/ui/infallible_destructuring_match.stderr
+++ b/src/tools/clippy/tests/ui/infallible_destructuring_match.stderr
@@ -1,5 +1,5 @@
error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let`
- --> $DIR/infallible_destructuring_match.rs:26:5
+ --> $DIR/infallible_destructuring_match.rs:29:5
|
LL | / let data = match wrapper {
LL | | SingleVariantEnum::Variant(i) => i,
@@ -9,7 +9,7 @@ LL | | };
= note: `-D clippy::infallible-destructuring-match` implied by `-D warnings`
error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let`
- --> $DIR/infallible_destructuring_match.rs:58:5
+ --> $DIR/infallible_destructuring_match.rs:61:5
|
LL | / let data = match wrapper {
LL | | TupleStruct(i) => i,
@@ -17,12 +17,20 @@ LL | | };
| |______^ help: try this: `let TupleStruct(data) = wrapper;`
error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let`
- --> $DIR/infallible_destructuring_match.rs:90:5
+ --> $DIR/infallible_destructuring_match.rs:85:5
+ |
+LL | / let data = match wrapper {
+LL | | TupleStructWithNonCopy(ref n) => n,
+LL | | };
+ | |______^ help: try this: `let TupleStructWithNonCopy(ref data) = wrapper;`
+
+error: you seem to be trying to use `match` to destructure a single infallible pattern. Consider using `let`
+ --> $DIR/infallible_destructuring_match.rs:104:5
|
LL | / let data = match wrapper {
LL | | Ok(i) => i,
LL | | };
| |______^ help: try this: `let Ok(data) = wrapper;`
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
diff --git a/src/tools/clippy/tests/ui/issue_4266.stderr b/src/tools/clippy/tests/ui/issue_4266.stderr
index fb2a93c95..fd553aa45 100644
--- a/src/tools/clippy/tests/ui/issue_4266.stderr
+++ b/src/tools/clippy/tests/ui/issue_4266.stderr
@@ -1,4 +1,4 @@
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
+error: the following explicit lifetimes could be elided: 'a
--> $DIR/issue_4266.rs:4:1
|
LL | async fn sink1<'a>(_: &'a str) {} // lint
@@ -6,7 +6,7 @@ LL | async fn sink1<'a>(_: &'a str) {} // lint
|
= note: `-D clippy::needless-lifetimes` implied by `-D warnings`
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
+error: the following explicit lifetimes could be elided: 'a
--> $DIR/issue_4266.rs:8:1
|
LL | async fn one_to_one<'a>(s: &'a str) -> &'a str {
diff --git a/src/tools/clippy/tests/ui/let_underscore_drop.rs b/src/tools/clippy/tests/ui/let_underscore_drop.rs
deleted file mode 100644
index 11b50492a..000000000
--- a/src/tools/clippy/tests/ui/let_underscore_drop.rs
+++ /dev/null
@@ -1,28 +0,0 @@
-#![warn(clippy::let_underscore_drop)]
-#![allow(clippy::let_unit_value)]
-
-struct Droppable;
-
-impl Drop for Droppable {
- fn drop(&mut self) {}
-}
-
-fn main() {
- let unit = ();
- let boxed = Box::new(());
- let droppable = Droppable;
- let optional = Some(Droppable);
-
- let _ = ();
- let _ = Box::new(());
- let _ = Droppable;
- let _ = Some(Droppable);
-
- // no lint for reference
- let _ = droppable_ref();
-}
-
-#[must_use]
-fn droppable_ref() -> &'static mut Droppable {
- unimplemented!()
-}
diff --git a/src/tools/clippy/tests/ui/let_underscore_drop.stderr b/src/tools/clippy/tests/ui/let_underscore_drop.stderr
deleted file mode 100644
index 324b7cd43..000000000
--- a/src/tools/clippy/tests/ui/let_underscore_drop.stderr
+++ /dev/null
@@ -1,27 +0,0 @@
-error: non-binding `let` on a type that implements `Drop`
- --> $DIR/let_underscore_drop.rs:17:5
- |
-LL | let _ = Box::new(());
- | ^^^^^^^^^^^^^^^^^^^^^
- |
- = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
- = note: `-D clippy::let-underscore-drop` implied by `-D warnings`
-
-error: non-binding `let` on a type that implements `Drop`
- --> $DIR/let_underscore_drop.rs:18:5
- |
-LL | let _ = Droppable;
- | ^^^^^^^^^^^^^^^^^^
- |
- = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
-
-error: non-binding `let` on a type that implements `Drop`
- --> $DIR/let_underscore_drop.rs:19:5
- |
-LL | let _ = Some(Droppable);
- | ^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
-
-error: aborting due to 3 previous errors
-
diff --git a/src/tools/clippy/tests/ui/let_underscore_future.rs b/src/tools/clippy/tests/ui/let_underscore_future.rs
new file mode 100644
index 000000000..d8f54cdca
--- /dev/null
+++ b/src/tools/clippy/tests/ui/let_underscore_future.rs
@@ -0,0 +1,20 @@
+use std::future::Future;
+
+async fn some_async_fn() {}
+
+fn sync_side_effects() {}
+fn custom() -> impl Future<Output = ()> {
+ sync_side_effects();
+ async {}
+}
+
+fn do_something_to_future(future: &mut impl Future<Output = ()>) {}
+
+fn main() {
+ let _ = some_async_fn();
+ let _ = custom();
+
+ let mut future = some_async_fn();
+ do_something_to_future(&mut future);
+ let _ = future;
+}
diff --git a/src/tools/clippy/tests/ui/let_underscore_future.stderr b/src/tools/clippy/tests/ui/let_underscore_future.stderr
new file mode 100644
index 000000000..33a748736
--- /dev/null
+++ b/src/tools/clippy/tests/ui/let_underscore_future.stderr
@@ -0,0 +1,27 @@
+error: non-binding `let` on a future
+ --> $DIR/let_underscore_future.rs:14:5
+ |
+LL | let _ = some_async_fn();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: consider awaiting the future or dropping explicitly with `std::mem::drop`
+ = note: `-D clippy::let-underscore-future` implied by `-D warnings`
+
+error: non-binding `let` on a future
+ --> $DIR/let_underscore_future.rs:15:5
+ |
+LL | let _ = custom();
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = help: consider awaiting the future or dropping explicitly with `std::mem::drop`
+
+error: non-binding `let` on a future
+ --> $DIR/let_underscore_future.rs:19:5
+ |
+LL | let _ = future;
+ | ^^^^^^^^^^^^^^^
+ |
+ = help: consider awaiting the future or dropping explicitly with `std::mem::drop`
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/let_underscore_lock.rs b/src/tools/clippy/tests/ui/let_underscore_lock.rs
index 7a7c4e924..4dff4d766 100644
--- a/src/tools/clippy/tests/ui/let_underscore_lock.rs
+++ b/src/tools/clippy/tests/ui/let_underscore_lock.rs
@@ -3,20 +3,6 @@
extern crate parking_lot;
fn main() {
- let m = std::sync::Mutex::new(());
- let rw = std::sync::RwLock::new(());
-
- let _ = m.lock();
- let _ = rw.read();
- let _ = rw.write();
- let _ = m.try_lock();
- let _ = rw.try_read();
- let _ = rw.try_write();
-
- // These shouldn't throw an error.
- let _ = m;
- let _ = rw;
-
use parking_lot::{lock_api::RawMutex, Mutex, RwLock};
let p_m: Mutex<()> = Mutex::const_new(RawMutex::INIT, ());
@@ -34,3 +20,20 @@ fn main() {
let _ = p_m1;
let _ = p_rw;
}
+
+fn uplifted() {
+ // shouldn't lint std locks as they were uplifted as rustc's `let_underscore_lock`
+
+ let m = std::sync::Mutex::new(());
+ let rw = std::sync::RwLock::new(());
+
+ let _ = m.lock();
+ let _ = rw.read();
+ let _ = rw.write();
+ let _ = m.try_lock();
+ let _ = rw.try_read();
+ let _ = rw.try_write();
+
+ let _ = m;
+ let _ = rw;
+}
diff --git a/src/tools/clippy/tests/ui/let_underscore_lock.stderr b/src/tools/clippy/tests/ui/let_underscore_lock.stderr
index d7779e7b6..f137d4112 100644
--- a/src/tools/clippy/tests/ui/let_underscore_lock.stderr
+++ b/src/tools/clippy/tests/ui/let_underscore_lock.stderr
@@ -1,83 +1,35 @@
-error: non-binding let on a synchronization lock
+error: non-binding `let` on a synchronization lock
--> $DIR/let_underscore_lock.rs:9:5
|
-LL | let _ = m.lock();
- | ^^^^^^^^^^^^^^^^^
- |
- = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
- = note: `-D clippy::let-underscore-lock` implied by `-D warnings`
-
-error: non-binding let on a synchronization lock
- --> $DIR/let_underscore_lock.rs:10:5
- |
-LL | let _ = rw.read();
- | ^^^^^^^^^^^^^^^^^^
- |
- = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
-
-error: non-binding let on a synchronization lock
- --> $DIR/let_underscore_lock.rs:11:5
- |
-LL | let _ = rw.write();
- | ^^^^^^^^^^^^^^^^^^^
- |
- = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
-
-error: non-binding let on a synchronization lock
- --> $DIR/let_underscore_lock.rs:12:5
- |
-LL | let _ = m.try_lock();
- | ^^^^^^^^^^^^^^^^^^^^^
- |
- = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
-
-error: non-binding let on a synchronization lock
- --> $DIR/let_underscore_lock.rs:13:5
- |
-LL | let _ = rw.try_read();
- | ^^^^^^^^^^^^^^^^^^^^^^
- |
- = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
-
-error: non-binding let on a synchronization lock
- --> $DIR/let_underscore_lock.rs:14:5
- |
-LL | let _ = rw.try_write();
- | ^^^^^^^^^^^^^^^^^^^^^^^
- |
- = help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
-
-error: non-binding let on a synchronization lock
- --> $DIR/let_underscore_lock.rs:23:5
- |
LL | let _ = p_m.lock();
| ^^^^^^^^^^^^^^^^^^^
|
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
+ = note: `-D clippy::let-underscore-lock` implied by `-D warnings`
-error: non-binding let on a synchronization lock
- --> $DIR/let_underscore_lock.rs:26:5
+error: non-binding `let` on a synchronization lock
+ --> $DIR/let_underscore_lock.rs:12:5
|
LL | let _ = p_m1.lock();
| ^^^^^^^^^^^^^^^^^^^^
|
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
-error: non-binding let on a synchronization lock
- --> $DIR/let_underscore_lock.rs:29:5
+error: non-binding `let` on a synchronization lock
+ --> $DIR/let_underscore_lock.rs:15:5
|
LL | let _ = p_rw.read();
| ^^^^^^^^^^^^^^^^^^^^
|
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
-error: non-binding let on a synchronization lock
- --> $DIR/let_underscore_lock.rs:30:5
+error: non-binding `let` on a synchronization lock
+ --> $DIR/let_underscore_lock.rs:16:5
|
LL | let _ = p_rw.write();
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
-error: aborting due to 10 previous errors
+error: aborting due to 4 previous errors
diff --git a/src/tools/clippy/tests/ui/let_underscore_must_use.stderr b/src/tools/clippy/tests/ui/let_underscore_must_use.stderr
index bae60f2ff..28d760eb4 100644
--- a/src/tools/clippy/tests/ui/let_underscore_must_use.stderr
+++ b/src/tools/clippy/tests/ui/let_underscore_must_use.stderr
@@ -1,4 +1,4 @@
-error: non-binding let on a result of a `#[must_use]` function
+error: non-binding `let` on a result of a `#[must_use]` function
--> $DIR/let_underscore_must_use.rs:67:5
|
LL | let _ = f();
@@ -7,7 +7,7 @@ LL | let _ = f();
= help: consider explicitly using function result
= note: `-D clippy::let-underscore-must-use` implied by `-D warnings`
-error: non-binding let on an expression with `#[must_use]` type
+error: non-binding `let` on an expression with `#[must_use]` type
--> $DIR/let_underscore_must_use.rs:68:5
|
LL | let _ = g();
@@ -15,7 +15,7 @@ LL | let _ = g();
|
= help: consider explicitly using expression value
-error: non-binding let on a result of a `#[must_use]` function
+error: non-binding `let` on a result of a `#[must_use]` function
--> $DIR/let_underscore_must_use.rs:70:5
|
LL | let _ = l(0_u32);
@@ -23,7 +23,7 @@ LL | let _ = l(0_u32);
|
= help: consider explicitly using function result
-error: non-binding let on a result of a `#[must_use]` function
+error: non-binding `let` on a result of a `#[must_use]` function
--> $DIR/let_underscore_must_use.rs:74:5
|
LL | let _ = s.f();
@@ -31,7 +31,7 @@ LL | let _ = s.f();
|
= help: consider explicitly using function result
-error: non-binding let on an expression with `#[must_use]` type
+error: non-binding `let` on an expression with `#[must_use]` type
--> $DIR/let_underscore_must_use.rs:75:5
|
LL | let _ = s.g();
@@ -39,7 +39,7 @@ LL | let _ = s.g();
|
= help: consider explicitly using expression value
-error: non-binding let on a result of a `#[must_use]` function
+error: non-binding `let` on a result of a `#[must_use]` function
--> $DIR/let_underscore_must_use.rs:78:5
|
LL | let _ = S::h();
@@ -47,7 +47,7 @@ LL | let _ = S::h();
|
= help: consider explicitly using function result
-error: non-binding let on an expression with `#[must_use]` type
+error: non-binding `let` on an expression with `#[must_use]` type
--> $DIR/let_underscore_must_use.rs:79:5
|
LL | let _ = S::p();
@@ -55,7 +55,7 @@ LL | let _ = S::p();
|
= help: consider explicitly using expression value
-error: non-binding let on a result of a `#[must_use]` function
+error: non-binding `let` on a result of a `#[must_use]` function
--> $DIR/let_underscore_must_use.rs:81:5
|
LL | let _ = S::a();
@@ -63,7 +63,7 @@ LL | let _ = S::a();
|
= help: consider explicitly using function result
-error: non-binding let on an expression with `#[must_use]` type
+error: non-binding `let` on an expression with `#[must_use]` type
--> $DIR/let_underscore_must_use.rs:83:5
|
LL | let _ = if true { Ok(()) } else { Err(()) };
@@ -71,7 +71,7 @@ LL | let _ = if true { Ok(()) } else { Err(()) };
|
= help: consider explicitly using expression value
-error: non-binding let on a result of a `#[must_use]` function
+error: non-binding `let` on a result of a `#[must_use]` function
--> $DIR/let_underscore_must_use.rs:87:5
|
LL | let _ = a.is_ok();
@@ -79,7 +79,7 @@ LL | let _ = a.is_ok();
|
= help: consider explicitly using function result
-error: non-binding let on an expression with `#[must_use]` type
+error: non-binding `let` on an expression with `#[must_use]` type
--> $DIR/let_underscore_must_use.rs:89:5
|
LL | let _ = a.map(|_| ());
@@ -87,7 +87,7 @@ LL | let _ = a.map(|_| ());
|
= help: consider explicitly using expression value
-error: non-binding let on an expression with `#[must_use]` type
+error: non-binding `let` on an expression with `#[must_use]` type
--> $DIR/let_underscore_must_use.rs:91:5
|
LL | let _ = a;
diff --git a/src/tools/clippy/tests/ui/macro_use_imports.stderr b/src/tools/clippy/tests/ui/macro_use_imports.stderr
index bf7b6edd0..61843124c 100644
--- a/src/tools/clippy/tests/ui/macro_use_imports.stderr
+++ b/src/tools/clippy/tests/ui/macro_use_imports.stderr
@@ -1,8 +1,8 @@
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
- --> $DIR/macro_use_imports.rs:23:5
+ --> $DIR/macro_use_imports.rs:25:5
|
LL | #[macro_use]
- | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};`
+ | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;`
|
= note: `-D clippy::macro-use-imports` implied by `-D warnings`
@@ -13,10 +13,10 @@ LL | #[macro_use]
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;`
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
- --> $DIR/macro_use_imports.rs:25:5
+ --> $DIR/macro_use_imports.rs:23:5
|
LL | #[macro_use]
- | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;`
+ | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};`
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
--> $DIR/macro_use_imports.rs:19:5
diff --git a/src/tools/clippy/tests/ui/manual_clamp.rs b/src/tools/clippy/tests/ui/manual_clamp.rs
index 331fd29b7..f7902e6fd 100644
--- a/src/tools/clippy/tests/ui/manual_clamp.rs
+++ b/src/tools/clippy/tests/ui/manual_clamp.rs
@@ -1,4 +1,3 @@
-#![feature(custom_inner_attributes)]
#![warn(clippy::manual_clamp)]
#![allow(
unused,
@@ -304,9 +303,8 @@ fn cmp_min_max(input: i32) -> i32 {
input * 3
}
+#[clippy::msrv = "1.49"]
fn msrv_1_49() {
- #![clippy::msrv = "1.49"]
-
let (input, min, max) = (0, -1, 2);
let _ = if input < min {
min
@@ -317,9 +315,8 @@ fn msrv_1_49() {
};
}
+#[clippy::msrv = "1.50"]
fn msrv_1_50() {
- #![clippy::msrv = "1.50"]
-
let (input, min, max) = (0, -1, 2);
let _ = if input < min {
min
diff --git a/src/tools/clippy/tests/ui/manual_clamp.stderr b/src/tools/clippy/tests/ui/manual_clamp.stderr
index 70abe2809..988ad1527 100644
--- a/src/tools/clippy/tests/ui/manual_clamp.stderr
+++ b/src/tools/clippy/tests/ui/manual_clamp.stderr
@@ -1,5 +1,5 @@
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:77:5
+ --> $DIR/manual_clamp.rs:76:5
|
LL | / if x9 < min {
LL | | x9 = min;
@@ -13,7 +13,7 @@ LL | | }
= note: `-D clippy::manual-clamp` implied by `-D warnings`
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:92:5
+ --> $DIR/manual_clamp.rs:91:5
|
LL | / if x11 > max {
LL | | x11 = max;
@@ -26,7 +26,7 @@ LL | | }
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:100:5
+ --> $DIR/manual_clamp.rs:99:5
|
LL | / if min > x12 {
LL | | x12 = min;
@@ -39,7 +39,7 @@ LL | | }
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:108:5
+ --> $DIR/manual_clamp.rs:107:5
|
LL | / if max < x13 {
LL | | x13 = max;
@@ -52,7 +52,7 @@ LL | | }
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:162:5
+ --> $DIR/manual_clamp.rs:161:5
|
LL | / if max < x33 {
LL | | x33 = max;
@@ -65,7 +65,7 @@ LL | | }
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:22:14
+ --> $DIR/manual_clamp.rs:21:14
|
LL | let x0 = if max < input {
| ______________^
@@ -80,7 +80,7 @@ LL | | };
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:30:14
+ --> $DIR/manual_clamp.rs:29:14
|
LL | let x1 = if input > max {
| ______________^
@@ -95,7 +95,7 @@ LL | | };
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:38:14
+ --> $DIR/manual_clamp.rs:37:14
|
LL | let x2 = if input < min {
| ______________^
@@ -110,7 +110,7 @@ LL | | };
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:46:14
+ --> $DIR/manual_clamp.rs:45:14
|
LL | let x3 = if min > input {
| ______________^
@@ -125,7 +125,7 @@ LL | | };
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:54:14
+ --> $DIR/manual_clamp.rs:53:14
|
LL | let x4 = input.max(min).min(max);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(min, max)`
@@ -133,7 +133,7 @@ LL | let x4 = input.max(min).min(max);
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:56:14
+ --> $DIR/manual_clamp.rs:55:14
|
LL | let x5 = input.min(max).max(min);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(min, max)`
@@ -141,7 +141,7 @@ LL | let x5 = input.min(max).max(min);
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:58:14
+ --> $DIR/manual_clamp.rs:57:14
|
LL | let x6 = match input {
| ______________^
@@ -154,7 +154,7 @@ LL | | };
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:64:14
+ --> $DIR/manual_clamp.rs:63:14
|
LL | let x7 = match input {
| ______________^
@@ -167,7 +167,7 @@ LL | | };
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:70:14
+ --> $DIR/manual_clamp.rs:69:14
|
LL | let x8 = match input {
| ______________^
@@ -180,7 +180,7 @@ LL | | };
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:84:15
+ --> $DIR/manual_clamp.rs:83:15
|
LL | let x10 = match input {
| _______________^
@@ -193,7 +193,7 @@ LL | | };
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:115:15
+ --> $DIR/manual_clamp.rs:114:15
|
LL | let x14 = if input > CONST_MAX {
| _______________^
@@ -208,7 +208,7 @@ LL | | };
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:124:19
+ --> $DIR/manual_clamp.rs:123:19
|
LL | let x15 = if input > max {
| ___________________^
@@ -224,7 +224,7 @@ LL | | };
= note: clamp returns NaN if the input is NaN
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:135:19
+ --> $DIR/manual_clamp.rs:134:19
|
LL | let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
@@ -232,7 +232,7 @@ LL | let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN);
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:136:19
+ --> $DIR/manual_clamp.rs:135:19
|
LL | let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
@@ -240,7 +240,7 @@ LL | let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX);
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:137:19
+ --> $DIR/manual_clamp.rs:136:19
|
LL | let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
@@ -248,7 +248,7 @@ LL | let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX));
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:138:19
+ --> $DIR/manual_clamp.rs:137:19
|
LL | let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
@@ -256,7 +256,7 @@ LL | let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN));
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:139:19
+ --> $DIR/manual_clamp.rs:138:19
|
LL | let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
@@ -264,7 +264,7 @@ LL | let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN);
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:140:19
+ --> $DIR/manual_clamp.rs:139:19
|
LL | let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
@@ -272,7 +272,7 @@ LL | let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX);
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:141:19
+ --> $DIR/manual_clamp.rs:140:19
|
LL | let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
@@ -280,7 +280,7 @@ LL | let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input));
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:142:19
+ --> $DIR/manual_clamp.rs:141:19
|
LL | let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
@@ -288,7 +288,7 @@ LL | let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input));
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:144:19
+ --> $DIR/manual_clamp.rs:143:19
|
LL | let x24 = f64::max(f64::min(input, CONST_F64_MAX), CONST_F64_MIN);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
@@ -297,7 +297,7 @@ LL | let x24 = f64::max(f64::min(input, CONST_F64_MAX), CONST_F64_MIN);
= note: clamp returns NaN if the input is NaN
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:145:19
+ --> $DIR/manual_clamp.rs:144:19
|
LL | let x25 = f64::min(f64::max(input, CONST_F64_MIN), CONST_F64_MAX);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
@@ -306,7 +306,7 @@ LL | let x25 = f64::min(f64::max(input, CONST_F64_MIN), CONST_F64_MAX);
= note: clamp returns NaN if the input is NaN
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:146:19
+ --> $DIR/manual_clamp.rs:145:19
|
LL | let x26 = f64::max(CONST_F64_MIN, f64::min(input, CONST_F64_MAX));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
@@ -315,7 +315,7 @@ LL | let x26 = f64::max(CONST_F64_MIN, f64::min(input, CONST_F64_MAX));
= note: clamp returns NaN if the input is NaN
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:147:19
+ --> $DIR/manual_clamp.rs:146:19
|
LL | let x27 = f64::min(CONST_F64_MAX, f64::max(input, CONST_F64_MIN));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
@@ -324,7 +324,7 @@ LL | let x27 = f64::min(CONST_F64_MAX, f64::max(input, CONST_F64_MIN));
= note: clamp returns NaN if the input is NaN
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:148:19
+ --> $DIR/manual_clamp.rs:147:19
|
LL | let x28 = f64::max(f64::min(CONST_F64_MAX, input), CONST_F64_MIN);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
@@ -333,7 +333,7 @@ LL | let x28 = f64::max(f64::min(CONST_F64_MAX, input), CONST_F64_MIN);
= note: clamp returns NaN if the input is NaN
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:149:19
+ --> $DIR/manual_clamp.rs:148:19
|
LL | let x29 = f64::min(f64::max(CONST_F64_MIN, input), CONST_F64_MAX);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
@@ -342,7 +342,7 @@ LL | let x29 = f64::min(f64::max(CONST_F64_MIN, input), CONST_F64_MAX);
= note: clamp returns NaN if the input is NaN
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:150:19
+ --> $DIR/manual_clamp.rs:149:19
|
LL | let x30 = f64::max(CONST_F64_MIN, f64::min(CONST_F64_MAX, input));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
@@ -351,7 +351,7 @@ LL | let x30 = f64::max(CONST_F64_MIN, f64::min(CONST_F64_MAX, input));
= note: clamp returns NaN if the input is NaN
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:151:19
+ --> $DIR/manual_clamp.rs:150:19
|
LL | let x31 = f64::min(CONST_F64_MAX, f64::max(CONST_F64_MIN, input));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
@@ -360,7 +360,7 @@ LL | let x31 = f64::min(CONST_F64_MAX, f64::max(CONST_F64_MIN, input));
= note: clamp returns NaN if the input is NaN
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:154:5
+ --> $DIR/manual_clamp.rs:153:5
|
LL | / if x32 < min {
LL | | x32 = min;
@@ -372,7 +372,7 @@ LL | | }
= note: clamp will panic if max < min
error: clamp-like pattern without using clamp function
- --> $DIR/manual_clamp.rs:324:13
+ --> $DIR/manual_clamp.rs:321:13
|
LL | let _ = if input < min {
| _____________^
diff --git a/src/tools/clippy/tests/ui/manual_flatten.rs b/src/tools/clippy/tests/ui/manual_flatten.rs
index 96cd87c0e..552213a7f 100644
--- a/src/tools/clippy/tests/ui/manual_flatten.rs
+++ b/src/tools/clippy/tests/ui/manual_flatten.rs
@@ -10,7 +10,7 @@ fn main() {
}
}
- // Test for loop over implicitly implicitly adjusted `Iterator` with `if let` statement
+ // Test for loop over implicitly adjusted `Iterator` with `if let` statement
let y: Vec<Result<i32, i32>> = vec![];
for n in y.clone() {
if let Ok(n) = n {
diff --git a/src/tools/clippy/tests/ui/manual_instant_elapsed.fixed b/src/tools/clippy/tests/ui/manual_instant_elapsed.fixed
index 0fa776b7b..85a91543c 100644
--- a/src/tools/clippy/tests/ui/manual_instant_elapsed.fixed
+++ b/src/tools/clippy/tests/ui/manual_instant_elapsed.fixed
@@ -1,6 +1,7 @@
// run-rustfix
#![warn(clippy::manual_instant_elapsed)]
#![allow(clippy::unnecessary_operation)]
+#![allow(clippy::unchecked_duration_subtraction)]
#![allow(unused_variables)]
#![allow(unused_must_use)]
diff --git a/src/tools/clippy/tests/ui/manual_instant_elapsed.rs b/src/tools/clippy/tests/ui/manual_instant_elapsed.rs
index 5b11b8453..c98cb15b9 100644
--- a/src/tools/clippy/tests/ui/manual_instant_elapsed.rs
+++ b/src/tools/clippy/tests/ui/manual_instant_elapsed.rs
@@ -1,6 +1,7 @@
// run-rustfix
#![warn(clippy::manual_instant_elapsed)]
#![allow(clippy::unnecessary_operation)]
+#![allow(clippy::unchecked_duration_subtraction)]
#![allow(unused_variables)]
#![allow(unused_must_use)]
diff --git a/src/tools/clippy/tests/ui/manual_instant_elapsed.stderr b/src/tools/clippy/tests/ui/manual_instant_elapsed.stderr
index 5537f5642..4ce1f6891 100644
--- a/src/tools/clippy/tests/ui/manual_instant_elapsed.stderr
+++ b/src/tools/clippy/tests/ui/manual_instant_elapsed.stderr
@@ -1,5 +1,5 @@
error: manual implementation of `Instant::elapsed`
- --> $DIR/manual_instant_elapsed.rs:17:20
+ --> $DIR/manual_instant_elapsed.rs:18:20
|
LL | let duration = Instant::now() - prev_instant;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `prev_instant.elapsed()`
@@ -7,7 +7,7 @@ LL | let duration = Instant::now() - prev_instant;
= note: `-D clippy::manual-instant-elapsed` implied by `-D warnings`
error: manual implementation of `Instant::elapsed`
- --> $DIR/manual_instant_elapsed.rs:26:5
+ --> $DIR/manual_instant_elapsed.rs:27:5
|
LL | Instant::now() - *ref_to_instant; // to ensure parens are added correctly
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*ref_to_instant).elapsed()`
diff --git a/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed b/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed
new file mode 100644
index 000000000..231ba83b1
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed
@@ -0,0 +1,42 @@
+// run-rustfix
+
+#![allow(unused, dead_code)]
+#![warn(clippy::manual_is_ascii_check)]
+
+fn main() {
+ assert!('x'.is_ascii_lowercase());
+ assert!('X'.is_ascii_uppercase());
+ assert!(b'x'.is_ascii_lowercase());
+ assert!(b'X'.is_ascii_uppercase());
+
+ let num = '2';
+ assert!(num.is_ascii_digit());
+ assert!(b'1'.is_ascii_digit());
+ assert!('x'.is_ascii_alphabetic());
+
+ assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_'));
+}
+
+#[clippy::msrv = "1.23"]
+fn msrv_1_23() {
+ assert!(matches!(b'1', b'0'..=b'9'));
+ assert!(matches!('X', 'A'..='Z'));
+ assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
+}
+
+#[clippy::msrv = "1.24"]
+fn msrv_1_24() {
+ assert!(b'1'.is_ascii_digit());
+ assert!('X'.is_ascii_uppercase());
+ assert!('x'.is_ascii_alphabetic());
+}
+
+#[clippy::msrv = "1.46"]
+fn msrv_1_46() {
+ const FOO: bool = matches!('x', '0'..='9');
+}
+
+#[clippy::msrv = "1.47"]
+fn msrv_1_47() {
+ const FOO: bool = 'x'.is_ascii_digit();
+}
diff --git a/src/tools/clippy/tests/ui/manual_is_ascii_check.rs b/src/tools/clippy/tests/ui/manual_is_ascii_check.rs
new file mode 100644
index 000000000..39ee6151c
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_is_ascii_check.rs
@@ -0,0 +1,42 @@
+// run-rustfix
+
+#![allow(unused, dead_code)]
+#![warn(clippy::manual_is_ascii_check)]
+
+fn main() {
+ assert!(matches!('x', 'a'..='z'));
+ assert!(matches!('X', 'A'..='Z'));
+ assert!(matches!(b'x', b'a'..=b'z'));
+ assert!(matches!(b'X', b'A'..=b'Z'));
+
+ let num = '2';
+ assert!(matches!(num, '0'..='9'));
+ assert!(matches!(b'1', b'0'..=b'9'));
+ assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
+
+ assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_'));
+}
+
+#[clippy::msrv = "1.23"]
+fn msrv_1_23() {
+ assert!(matches!(b'1', b'0'..=b'9'));
+ assert!(matches!('X', 'A'..='Z'));
+ assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
+}
+
+#[clippy::msrv = "1.24"]
+fn msrv_1_24() {
+ assert!(matches!(b'1', b'0'..=b'9'));
+ assert!(matches!('X', 'A'..='Z'));
+ assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
+}
+
+#[clippy::msrv = "1.46"]
+fn msrv_1_46() {
+ const FOO: bool = matches!('x', '0'..='9');
+}
+
+#[clippy::msrv = "1.47"]
+fn msrv_1_47() {
+ const FOO: bool = matches!('x', '0'..='9');
+}
diff --git a/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr b/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr
new file mode 100644
index 000000000..397cbe05c
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr
@@ -0,0 +1,70 @@
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:7:13
+ |
+LL | assert!(matches!('x', 'a'..='z'));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_lowercase()`
+ |
+ = note: `-D clippy::manual-is-ascii-check` implied by `-D warnings`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:8:13
+ |
+LL | assert!(matches!('X', 'A'..='Z'));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'X'.is_ascii_uppercase()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:9:13
+ |
+LL | assert!(matches!(b'x', b'a'..=b'z'));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'x'.is_ascii_lowercase()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:10:13
+ |
+LL | assert!(matches!(b'X', b'A'..=b'Z'));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'X'.is_ascii_uppercase()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:13:13
+ |
+LL | assert!(matches!(num, '0'..='9'));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.is_ascii_digit()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:14:13
+ |
+LL | assert!(matches!(b'1', b'0'..=b'9'));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'1'.is_ascii_digit()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:15:13
+ |
+LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:29:13
+ |
+LL | assert!(matches!(b'1', b'0'..=b'9'));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'1'.is_ascii_digit()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:30:13
+ |
+LL | assert!(matches!('X', 'A'..='Z'));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'X'.is_ascii_uppercase()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:31:13
+ |
+LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:41:23
+ |
+LL | const FOO: bool = matches!('x', '0'..='9');
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_digit()`
+
+error: aborting due to 11 previous errors
+
diff --git a/src/tools/clippy/tests/ui/manual_let_else.rs b/src/tools/clippy/tests/ui/manual_let_else.rs
new file mode 100644
index 000000000..48a162c13
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_let_else.rs
@@ -0,0 +1,251 @@
+#![allow(unused_braces, unused_variables, dead_code)]
+#![allow(
+ clippy::collapsible_else_if,
+ clippy::unused_unit,
+ clippy::let_unit_value,
+ clippy::match_single_binding,
+ clippy::never_loop
+)]
+#![warn(clippy::manual_let_else)]
+
+fn g() -> Option<()> {
+ None
+}
+
+fn main() {}
+
+fn fire() {
+ let v = if let Some(v_some) = g() { v_some } else { return };
+ let v = if let Some(v_some) = g() {
+ v_some
+ } else {
+ return;
+ };
+
+ let v = if let Some(v) = g() {
+ // Blocks around the identity should have no impact
+ {
+ { v }
+ }
+ } else {
+ // Some computation should still make it fire
+ g();
+ return;
+ };
+
+ // continue and break diverge
+ loop {
+ let v = if let Some(v_some) = g() { v_some } else { continue };
+ let v = if let Some(v_some) = g() { v_some } else { break };
+ }
+
+ // panic also diverges
+ let v = if let Some(v_some) = g() { v_some } else { panic!() };
+
+ // abort also diverges
+ let v = if let Some(v_some) = g() {
+ v_some
+ } else {
+ std::process::abort()
+ };
+
+ // If whose two branches diverge also diverges
+ let v = if let Some(v_some) = g() {
+ v_some
+ } else {
+ if true { return } else { panic!() }
+ };
+
+ // Diverging after an if still makes the block diverge:
+ let v = if let Some(v_some) = g() {
+ v_some
+ } else {
+ if true {}
+ panic!();
+ };
+
+ // A match diverges if all branches diverge:
+ // Note: the corresponding let-else requires a ; at the end of the match
+ // as otherwise the type checker does not turn it into a ! type.
+ let v = if let Some(v_some) = g() {
+ v_some
+ } else {
+ match () {
+ _ if panic!() => {},
+ _ => panic!(),
+ }
+ };
+
+ // An if's expression can cause divergence:
+ let v = if let Some(v_some) = g() { v_some } else { if panic!() {} };
+
+ // An expression of a match can cause divergence:
+ let v = if let Some(v_some) = g() {
+ v_some
+ } else {
+ match panic!() {
+ _ => {},
+ }
+ };
+
+ // Top level else if
+ let v = if let Some(v_some) = g() {
+ v_some
+ } else if true {
+ return;
+ } else {
+ panic!("diverge");
+ };
+
+ // All match arms diverge
+ let v = if let Some(v_some) = g() {
+ v_some
+ } else {
+ match (g(), g()) {
+ (Some(_), None) => return,
+ (None, Some(_)) => {
+ if true {
+ return;
+ } else {
+ panic!();
+ }
+ },
+ _ => return,
+ }
+ };
+
+ // Tuples supported for the declared variables
+ let (v, w) = if let Some(v_some) = g().map(|v| (v, 42)) {
+ v_some
+ } else {
+ return;
+ };
+
+ // Tuples supported for the identity block and pattern
+ let v = if let (Some(v_some), w_some) = (g(), 0) {
+ (w_some, v_some)
+ } else {
+ return;
+ };
+
+ // entirely inside macro lints
+ macro_rules! create_binding_if_some {
+ ($n:ident, $e:expr) => {
+ let $n = if let Some(v) = $e { v } else { return };
+ };
+ }
+ create_binding_if_some!(w, g());
+}
+
+fn not_fire() {
+ let v = if let Some(v_some) = g() {
+ // Nothing returned. Should not fire.
+ } else {
+ return;
+ };
+
+ let w = 0;
+ let v = if let Some(v_some) = g() {
+ // Different variable than v_some. Should not fire.
+ w
+ } else {
+ return;
+ };
+
+ let v = if let Some(v_some) = g() {
+ // Computation in then clause. Should not fire.
+ g();
+ v_some
+ } else {
+ return;
+ };
+
+ let v = if let Some(v_some) = g() {
+ v_some
+ } else {
+ if false {
+ return;
+ }
+ // This doesn't diverge. Should not fire.
+ ()
+ };
+
+ let v = if let Some(v_some) = g() {
+ v_some
+ } else {
+ // There is one match arm that doesn't diverge. Should not fire.
+ match (g(), g()) {
+ (Some(_), None) => return,
+ (None, Some(_)) => return,
+ (Some(_), Some(_)) => (),
+ _ => return,
+ }
+ };
+
+ let v = if let Some(v_some) = g() {
+ v_some
+ } else {
+ // loop with a break statement inside does not diverge.
+ loop {
+ break;
+ }
+ };
+
+ enum Uninhabited {}
+ fn un() -> Uninhabited {
+ panic!()
+ }
+ let v = if let Some(v_some) = None {
+ v_some
+ } else {
+ // Don't lint if the type is uninhabited but not !
+ un()
+ };
+
+ fn question_mark() -> Option<()> {
+ let v = if let Some(v) = g() {
+ v
+ } else {
+ // Question mark does not diverge
+ g()?
+ };
+ Some(v)
+ }
+
+ // Macro boundary inside let
+ macro_rules! some_or_return {
+ ($e:expr) => {
+ if let Some(v) = $e { v } else { return }
+ };
+ }
+ let v = some_or_return!(g());
+
+ // Also macro boundary inside let, but inside a macro
+ macro_rules! create_binding_if_some_nf {
+ ($n:ident, $e:expr) => {
+ let $n = some_or_return!($e);
+ };
+ }
+ create_binding_if_some_nf!(v, g());
+
+ // Already a let-else
+ let Some(a) = (if let Some(b) = Some(Some(())) { b } else { return }) else { panic!() };
+
+ // If a type annotation is present, don't lint as
+ // expressing the type might be too hard
+ let v: () = if let Some(v_some) = g() { v_some } else { panic!() };
+
+ // Issue 9940
+ // Suggestion should not expand macros
+ macro_rules! macro_call {
+ () => {
+ return ()
+ };
+ }
+
+ let ff = Some(1);
+ let _ = match ff {
+ Some(value) => value,
+ _ => macro_call!(),
+ };
+}
diff --git a/src/tools/clippy/tests/ui/manual_let_else.stderr b/src/tools/clippy/tests/ui/manual_let_else.stderr
new file mode 100644
index 000000000..52aac6bc6
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_let_else.stderr
@@ -0,0 +1,272 @@
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:18:5
+ |
+LL | let v = if let Some(v_some) = g() { v_some } else { return };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v_some) = 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
+ |
+LL | / let v = if let Some(v_some) = g() {
+LL | | v_some
+LL | | } else {
+LL | | return;
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let Some(v_some) = g() else {
+LL + return;
+LL + };
+ |
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:25:5
+ |
+LL | / let v = if let Some(v) = g() {
+LL | | // Blocks around the identity should have no impact
+LL | | {
+LL | | { v }
+... |
+LL | | return;
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let Some(v) = g() else {
+LL + // Some computation should still make it fire
+LL + g();
+LL + return;
+LL + };
+ |
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:38:9
+ |
+LL | let v = if let Some(v_some) = g() { v_some } else { continue };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v_some) = g() else { continue };`
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:39:9
+ |
+LL | let v = if let Some(v_some) = g() { v_some } else { break };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v_some) = g() else { break };`
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:43:5
+ |
+LL | let v = if let Some(v_some) = g() { v_some } else { panic!() };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v_some) = g() else { panic!() };`
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:46:5
+ |
+LL | / let v = if let Some(v_some) = g() {
+LL | | v_some
+LL | | } else {
+LL | | std::process::abort()
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let Some(v_some) = g() else {
+LL + std::process::abort()
+LL + };
+ |
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:53:5
+ |
+LL | / let v = if let Some(v_some) = g() {
+LL | | v_some
+LL | | } else {
+LL | | if true { return } else { panic!() }
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let Some(v_some) = g() else {
+LL + if true { return } else { panic!() }
+LL + };
+ |
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:60:5
+ |
+LL | / let v = if let Some(v_some) = g() {
+LL | | v_some
+LL | | } else {
+LL | | if true {}
+LL | | panic!();
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let Some(v_some) = g() else {
+LL + if true {}
+LL + panic!();
+LL + };
+ |
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:70:5
+ |
+LL | / let v = if let Some(v_some) = g() {
+LL | | v_some
+LL | | } else {
+LL | | match () {
+... |
+LL | | }
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let Some(v_some) = g() else {
+LL + match () {
+LL + _ if panic!() => {},
+LL + _ => panic!(),
+LL + }
+LL + };
+ |
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:80: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!() {} };`
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:83:5
+ |
+LL | / let v = if let Some(v_some) = g() {
+LL | | v_some
+LL | | } else {
+LL | | match panic!() {
+LL | | _ => {},
+LL | | }
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let Some(v_some) = g() else {
+LL + match panic!() {
+LL + _ => {},
+LL + }
+LL + };
+ |
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:92:5
+ |
+LL | / let v = if let Some(v_some) = g() {
+LL | | v_some
+LL | | } else if true {
+LL | | return;
+LL | | } else {
+LL | | panic!("diverge");
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let Some(v_some) = g() else { if true {
+LL + return;
+LL + } else {
+LL + panic!("diverge");
+LL + } };
+ |
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:101:5
+ |
+LL | / let v = if let Some(v_some) = g() {
+LL | | v_some
+LL | | } else {
+LL | | match (g(), g()) {
+... |
+LL | | }
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let Some(v_some) = g() else {
+LL + match (g(), g()) {
+LL + (Some(_), None) => return,
+LL + (None, Some(_)) => {
+LL + if true {
+LL + return;
+LL + } else {
+LL + panic!();
+LL + }
+LL + },
+LL + _ => return,
+LL + }
+LL + };
+ |
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:118:5
+ |
+LL | / let (v, w) = if let Some(v_some) = g().map(|v| (v, 42)) {
+LL | | v_some
+LL | | } else {
+LL | | return;
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let Some(v_some) = g().map(|v| (v, 42)) else {
+LL + return;
+LL + };
+ |
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:125:5
+ |
+LL | / let v = if let (Some(v_some), w_some) = (g(), 0) {
+LL | | (w_some, v_some)
+LL | | } else {
+LL | | return;
+LL | | };
+ | |______^
+ |
+help: consider writing
+ |
+LL ~ let (Some(v_some), w_some) = (g(), 0) else {
+LL + return;
+LL + };
+ |
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else.rs:134:13
+ |
+LL | let $n = if let Some(v) = $e { v } else { return };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Some(v) = g() else { return };`
+...
+LL | create_binding_if_some!(w, g());
+ | ------------------------------- in this macro invocation
+ |
+ = 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
+ |
+LL | / let _ = match ff {
+LL | | Some(value) => value,
+LL | | _ => macro_call!(),
+LL | | };
+ | |______^ help: consider writing: `let Some(value) = ff else { macro_call!() };`
+
+error: aborting due to 18 previous errors
+
diff --git a/src/tools/clippy/tests/ui/manual_let_else_match.rs b/src/tools/clippy/tests/ui/manual_let_else_match.rs
new file mode 100644
index 000000000..93c86ca24
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_let_else_match.rs
@@ -0,0 +1,121 @@
+#![allow(unused_braces, unused_variables, dead_code)]
+#![allow(clippy::collapsible_else_if, clippy::let_unit_value)]
+#![warn(clippy::manual_let_else)]
+// Ensure that we don't conflict with match -> if let lints
+#![warn(clippy::single_match_else, clippy::single_match)]
+
+fn f() -> Result<u32, u32> {
+ Ok(0)
+}
+
+fn g() -> Option<()> {
+ None
+}
+
+fn h() -> (Option<()>, Option<()>) {
+ (None, None)
+}
+
+enum Variant {
+ Foo,
+ Bar(u32),
+ Baz(u32),
+}
+
+fn build_enum() -> Variant {
+ Variant::Foo
+}
+
+fn main() {}
+
+fn fire() {
+ let v = match g() {
+ Some(v_some) => v_some,
+ None => return,
+ };
+
+ let v = match g() {
+ Some(v_some) => v_some,
+ _ => return,
+ };
+
+ loop {
+ // More complex pattern for the identity arm and diverging arm
+ let v = match h() {
+ (Some(_), Some(_)) | (None, None) => continue,
+ (Some(v), None) | (None, Some(v)) => v,
+ };
+ // Custom enums are supported as long as the "else" arm is a simple _
+ let v = match build_enum() {
+ _ => continue,
+ Variant::Bar(v) | Variant::Baz(v) => v,
+ };
+ }
+
+ // There is a _ in the diverging arm
+ // TODO also support unused bindings aka _v
+ let v = match f() {
+ Ok(v) => v,
+ Err(_) => return,
+ };
+
+ // Err(()) is an allowed pattern
+ let v = match f().map_err(|_| ()) {
+ Ok(v) => v,
+ Err(()) => return,
+ };
+}
+
+fn not_fire() {
+ // Multiple diverging arms
+ let v = match h() {
+ _ => panic!(),
+ (None, Some(_v)) => return,
+ (Some(v), None) => v,
+ };
+
+ // Multiple identity arms
+ let v = match h() {
+ _ => panic!(),
+ (None, Some(v)) => v,
+ (Some(v), None) => v,
+ };
+
+ // No diverging arm at all, only identity arms.
+ // This is no case for let else, but destructuring assignment.
+ let v = match f() {
+ Ok(v) => v,
+ Err(e) => e,
+ };
+
+ // The identity arm has a guard
+ let v = match g() {
+ Some(v) if g().is_none() => v,
+ _ => return,
+ };
+
+ // The diverging arm has a guard
+ let v = match f() {
+ Err(v) if v > 0 => panic!(),
+ Ok(v) | Err(v) => v,
+ };
+
+ // The diverging arm creates a binding
+ let v = match f() {
+ Ok(v) => v,
+ Err(e) => panic!("error: {e}"),
+ };
+
+ // Custom enum where the diverging arm
+ // explicitly mentions the variant
+ let v = match build_enum() {
+ Variant::Foo => return,
+ Variant::Bar(v) | Variant::Baz(v) => v,
+ };
+
+ // The custom enum is surrounded by an Err()
+ let v = match Err(build_enum()) {
+ Ok(v) | Err(Variant::Bar(v) | Variant::Baz(v)) => v,
+ Err(Variant::Foo) => return,
+ };
+}
diff --git a/src/tools/clippy/tests/ui/manual_let_else_match.stderr b/src/tools/clippy/tests/ui/manual_let_else_match.stderr
new file mode 100644
index 000000000..38be5ac54
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_let_else_match.stderr
@@ -0,0 +1,58 @@
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else_match.rs:32:5
+ |
+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 };`
+ |
+ = note: `-D clippy::manual-let-else` implied by `-D warnings`
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else_match.rs:37:5
+ |
+LL | / let v = match g() {
+LL | | Some(v_some) => v_some,
+LL | | _ => return,
+LL | | };
+ | |______^ help: consider writing: `let Some(v_some) = g() else { return };`
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else_match.rs:44:9
+ |
+LL | / let v = match h() {
+LL | | (Some(_), Some(_)) | (None, None) => continue,
+LL | | (Some(v), None) | (None, Some(v)) => v,
+LL | | };
+ | |__________^ help: consider writing: `let (Some(v), None) | (None, Some(v)) = h() else { continue };`
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else_match.rs:49:9
+ |
+LL | / let v = match build_enum() {
+LL | | _ => continue,
+LL | | Variant::Bar(v) | Variant::Baz(v) => v,
+LL | | };
+ | |__________^ help: consider writing: `let Variant::Bar(v) | Variant::Baz(v) = build_enum() else { continue };`
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else_match.rs:57:5
+ |
+LL | / let v = match f() {
+LL | | Ok(v) => v,
+LL | | Err(_) => return,
+LL | | };
+ | |______^ help: consider writing: `let Ok(v) = f() else { return };`
+
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else_match.rs:63:5
+ |
+LL | / let v = match f().map_err(|_| ()) {
+LL | | Ok(v) => v,
+LL | | Err(()) => return,
+LL | | };
+ | |______^ help: consider writing: `let Ok(v) = f().map_err(|_| ()) else { return };`
+
+error: aborting due to 6 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 d864f8554..fc8511626 100644
--- a/src/tools/clippy/tests/ui/manual_ok_or.fixed
+++ b/src/tools/clippy/tests/ui/manual_ok_or.fixed
@@ -1,5 +1,6 @@
// run-rustfix
#![warn(clippy::manual_ok_or)]
+#![allow(clippy::or_fun_call)]
#![allow(clippy::disallowed_names)]
#![allow(clippy::redundant_closure)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/manual_ok_or.rs b/src/tools/clippy/tests/ui/manual_ok_or.rs
index 626476846..b5303d33f 100644
--- a/src/tools/clippy/tests/ui/manual_ok_or.rs
+++ b/src/tools/clippy/tests/ui/manual_ok_or.rs
@@ -1,5 +1,6 @@
// run-rustfix
#![warn(clippy::manual_ok_or)]
+#![allow(clippy::or_fun_call)]
#![allow(clippy::disallowed_names)]
#![allow(clippy::redundant_closure)]
#![allow(dead_code)]
diff --git a/src/tools/clippy/tests/ui/manual_ok_or.stderr b/src/tools/clippy/tests/ui/manual_ok_or.stderr
index 65459a097..b4a17f143 100644
--- a/src/tools/clippy/tests/ui/manual_ok_or.stderr
+++ b/src/tools/clippy/tests/ui/manual_ok_or.stderr
@@ -1,5 +1,5 @@
error: this pattern reimplements `Option::ok_or`
- --> $DIR/manual_ok_or.rs:11:5
+ --> $DIR/manual_ok_or.rs:12:5
|
LL | foo.map_or(Err("error"), |v| Ok(v));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `foo.ok_or("error")`
@@ -7,19 +7,19 @@ LL | foo.map_or(Err("error"), |v| Ok(v));
= note: `-D clippy::manual-ok-or` implied by `-D warnings`
error: this pattern reimplements `Option::ok_or`
- --> $DIR/manual_ok_or.rs:14:5
+ --> $DIR/manual_ok_or.rs:15:5
|
LL | foo.map_or(Err("error"), Ok);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `foo.ok_or("error")`
error: this pattern reimplements `Option::ok_or`
- --> $DIR/manual_ok_or.rs:17:5
+ --> $DIR/manual_ok_or.rs:18:5
|
LL | None::<i32>.map_or(Err("error"), |v| Ok(v));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `None::<i32>.ok_or("error")`
error: this pattern reimplements `Option::ok_or`
- --> $DIR/manual_ok_or.rs:21:5
+ --> $DIR/manual_ok_or.rs:22:5
|
LL | / foo.map_or(Err::<i32, &str>(
LL | | &format!(
diff --git a/src/tools/clippy/tests/ui/manual_rem_euclid.fixed b/src/tools/clippy/tests/ui/manual_rem_euclid.fixed
index b942fbfe9..4cdc0546a 100644
--- a/src/tools/clippy/tests/ui/manual_rem_euclid.fixed
+++ b/src/tools/clippy/tests/ui/manual_rem_euclid.fixed
@@ -1,7 +1,6 @@
// run-rustfix
// aux-build:macro_rules.rs
-#![feature(custom_inner_attributes)]
#![warn(clippy::manual_rem_euclid)]
#[macro_use]
@@ -55,31 +54,27 @@ pub const fn const_rem_euclid_4(num: i32) -> i32 {
num.rem_euclid(4)
}
+#[clippy::msrv = "1.37"]
pub fn msrv_1_37() {
- #![clippy::msrv = "1.37"]
-
let x: i32 = 10;
let _: i32 = ((x % 4) + 4) % 4;
}
+#[clippy::msrv = "1.38"]
pub fn msrv_1_38() {
- #![clippy::msrv = "1.38"]
-
let x: i32 = 10;
let _: i32 = x.rem_euclid(4);
}
// For const fns:
+#[clippy::msrv = "1.51"]
pub const fn msrv_1_51() {
- #![clippy::msrv = "1.51"]
-
let x: i32 = 10;
let _: i32 = ((x % 4) + 4) % 4;
}
+#[clippy::msrv = "1.52"]
pub const fn msrv_1_52() {
- #![clippy::msrv = "1.52"]
-
let x: i32 = 10;
let _: i32 = x.rem_euclid(4);
}
diff --git a/src/tools/clippy/tests/ui/manual_rem_euclid.rs b/src/tools/clippy/tests/ui/manual_rem_euclid.rs
index 7462d5321..58a9e20f3 100644
--- a/src/tools/clippy/tests/ui/manual_rem_euclid.rs
+++ b/src/tools/clippy/tests/ui/manual_rem_euclid.rs
@@ -1,7 +1,6 @@
// run-rustfix
// aux-build:macro_rules.rs
-#![feature(custom_inner_attributes)]
#![warn(clippy::manual_rem_euclid)]
#[macro_use]
@@ -55,31 +54,27 @@ pub const fn const_rem_euclid_4(num: i32) -> i32 {
((num % 4) + 4) % 4
}
+#[clippy::msrv = "1.37"]
pub fn msrv_1_37() {
- #![clippy::msrv = "1.37"]
-
let x: i32 = 10;
let _: i32 = ((x % 4) + 4) % 4;
}
+#[clippy::msrv = "1.38"]
pub fn msrv_1_38() {
- #![clippy::msrv = "1.38"]
-
let x: i32 = 10;
let _: i32 = ((x % 4) + 4) % 4;
}
// For const fns:
+#[clippy::msrv = "1.51"]
pub const fn msrv_1_51() {
- #![clippy::msrv = "1.51"]
-
let x: i32 = 10;
let _: i32 = ((x % 4) + 4) % 4;
}
+#[clippy::msrv = "1.52"]
pub const fn msrv_1_52() {
- #![clippy::msrv = "1.52"]
-
let x: i32 = 10;
let _: i32 = ((x % 4) + 4) % 4;
}
diff --git a/src/tools/clippy/tests/ui/manual_rem_euclid.stderr b/src/tools/clippy/tests/ui/manual_rem_euclid.stderr
index d51bac03b..e3122a588 100644
--- a/src/tools/clippy/tests/ui/manual_rem_euclid.stderr
+++ b/src/tools/clippy/tests/ui/manual_rem_euclid.stderr
@@ -1,5 +1,5 @@
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:20:18
+ --> $DIR/manual_rem_euclid.rs:19:18
|
LL | let _: i32 = ((value % 4) + 4) % 4;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)`
@@ -7,31 +7,31 @@ LL | let _: i32 = ((value % 4) + 4) % 4;
= note: `-D clippy::manual-rem-euclid` implied by `-D warnings`
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:21:18
+ --> $DIR/manual_rem_euclid.rs:20:18
|
LL | let _: i32 = (4 + (value % 4)) % 4;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)`
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:22:18
+ --> $DIR/manual_rem_euclid.rs:21:18
|
LL | let _: i32 = (value % 4 + 4) % 4;
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)`
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:23:18
+ --> $DIR/manual_rem_euclid.rs:22:18
|
LL | let _: i32 = (4 + value % 4) % 4;
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)`
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:24:22
+ --> $DIR/manual_rem_euclid.rs:23:22
|
LL | let _: i32 = 1 + (4 + value % 4) % 4;
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)`
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:13:22
+ --> $DIR/manual_rem_euclid.rs:12:22
|
LL | let _: i32 = ((value % 4) + 4) % 4;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)`
@@ -42,25 +42,25 @@ LL | internal_rem_euclid!();
= note: this error originates in the macro `internal_rem_euclid` (in Nightly builds, run with -Z macro-backtrace for more info)
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:50:5
+ --> $DIR/manual_rem_euclid.rs:49:5
|
LL | ((num % 4) + 4) % 4
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `num.rem_euclid(4)`
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:55:5
+ --> $DIR/manual_rem_euclid.rs:54:5
|
LL | ((num % 4) + 4) % 4
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `num.rem_euclid(4)`
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:69:18
+ --> $DIR/manual_rem_euclid.rs:66:18
|
LL | let _: i32 = ((x % 4) + 4) % 4;
| ^^^^^^^^^^^^^^^^^ help: consider using: `x.rem_euclid(4)`
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:84:18
+ --> $DIR/manual_rem_euclid.rs:79:18
|
LL | let _: i32 = ((x % 4) + 4) % 4;
| ^^^^^^^^^^^^^^^^^ help: consider using: `x.rem_euclid(4)`
diff --git a/src/tools/clippy/tests/ui/manual_retain.fixed b/src/tools/clippy/tests/ui/manual_retain.fixed
index fba503a20..e5ae3cf3e 100644
--- a/src/tools/clippy/tests/ui/manual_retain.fixed
+++ b/src/tools/clippy/tests/ui/manual_retain.fixed
@@ -1,5 +1,4 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::manual_retain)]
#![allow(unused)]
use std::collections::BTreeMap;
@@ -216,8 +215,8 @@ fn vec_deque_retain() {
bar = foobar.into_iter().filter(|x| x % 2 == 0).collect();
}
+#[clippy::msrv = "1.52"]
fn _msrv_153() {
- #![clippy::msrv = "1.52"]
let mut btree_map: BTreeMap<i8, i8> = (0..8).map(|x| (x, x * 10)).collect();
btree_map = btree_map.into_iter().filter(|(k, _)| k % 2 == 0).collect();
@@ -225,14 +224,14 @@ fn _msrv_153() {
btree_set = btree_set.iter().filter(|&x| x % 2 == 0).copied().collect();
}
+#[clippy::msrv = "1.25"]
fn _msrv_126() {
- #![clippy::msrv = "1.25"]
let mut s = String::from("foobar");
s = s.chars().filter(|&c| c != 'o').to_owned().collect();
}
+#[clippy::msrv = "1.17"]
fn _msrv_118() {
- #![clippy::msrv = "1.17"]
let mut hash_set = HashSet::from([1, 2, 3, 4, 5, 6]);
hash_set = hash_set.into_iter().filter(|x| x % 2 == 0).collect();
let mut hash_map: HashMap<i8, i8> = (0..8).map(|x| (x, x * 10)).collect();
diff --git a/src/tools/clippy/tests/ui/manual_retain.rs b/src/tools/clippy/tests/ui/manual_retain.rs
index 81a849fe7..1021f15ed 100644
--- a/src/tools/clippy/tests/ui/manual_retain.rs
+++ b/src/tools/clippy/tests/ui/manual_retain.rs
@@ -1,5 +1,4 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::manual_retain)]
#![allow(unused)]
use std::collections::BTreeMap;
@@ -222,8 +221,8 @@ fn vec_deque_retain() {
bar = foobar.into_iter().filter(|x| x % 2 == 0).collect();
}
+#[clippy::msrv = "1.52"]
fn _msrv_153() {
- #![clippy::msrv = "1.52"]
let mut btree_map: BTreeMap<i8, i8> = (0..8).map(|x| (x, x * 10)).collect();
btree_map = btree_map.into_iter().filter(|(k, _)| k % 2 == 0).collect();
@@ -231,14 +230,14 @@ fn _msrv_153() {
btree_set = btree_set.iter().filter(|&x| x % 2 == 0).copied().collect();
}
+#[clippy::msrv = "1.25"]
fn _msrv_126() {
- #![clippy::msrv = "1.25"]
let mut s = String::from("foobar");
s = s.chars().filter(|&c| c != 'o').to_owned().collect();
}
+#[clippy::msrv = "1.17"]
fn _msrv_118() {
- #![clippy::msrv = "1.17"]
let mut hash_set = HashSet::from([1, 2, 3, 4, 5, 6]);
hash_set = hash_set.into_iter().filter(|x| x % 2 == 0).collect();
let mut hash_map: HashMap<i8, i8> = (0..8).map(|x| (x, x * 10)).collect();
diff --git a/src/tools/clippy/tests/ui/manual_retain.stderr b/src/tools/clippy/tests/ui/manual_retain.stderr
index ec635919b..89316ce1d 100644
--- a/src/tools/clippy/tests/ui/manual_retain.stderr
+++ b/src/tools/clippy/tests/ui/manual_retain.stderr
@@ -1,5 +1,5 @@
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:52:5
+ --> $DIR/manual_retain.rs:51:5
|
LL | btree_map = btree_map.into_iter().filter(|(k, _)| k % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_map.retain(|k, _| k % 2 == 0)`
@@ -7,13 +7,13 @@ LL | btree_map = btree_map.into_iter().filter(|(k, _)| k % 2 == 0).collect()
= note: `-D clippy::manual-retain` implied by `-D warnings`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:53:5
+ --> $DIR/manual_retain.rs:52:5
|
LL | btree_map = btree_map.into_iter().filter(|(_, v)| v % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_map.retain(|_, &mut v| v % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:54:5
+ --> $DIR/manual_retain.rs:53:5
|
LL | / btree_map = btree_map
LL | | .into_iter()
@@ -22,37 +22,37 @@ LL | | .collect();
| |__________________^ help: consider calling `.retain()` instead: `btree_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0))`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:76:5
+ --> $DIR/manual_retain.rs:75:5
|
LL | btree_set = btree_set.iter().filter(|&x| x % 2 == 0).copied().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:77:5
+ --> $DIR/manual_retain.rs:76:5
|
LL | btree_set = btree_set.iter().filter(|&x| x % 2 == 0).cloned().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:78:5
+ --> $DIR/manual_retain.rs:77:5
|
LL | btree_set = btree_set.into_iter().filter(|x| x % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `btree_set.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:108:5
+ --> $DIR/manual_retain.rs:107:5
|
LL | hash_map = hash_map.into_iter().filter(|(k, _)| k % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_map.retain(|k, _| k % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:109:5
+ --> $DIR/manual_retain.rs:108:5
|
LL | hash_map = hash_map.into_iter().filter(|(_, v)| v % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_map.retain(|_, &mut v| v % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:110:5
+ --> $DIR/manual_retain.rs:109:5
|
LL | / hash_map = hash_map
LL | | .into_iter()
@@ -61,61 +61,61 @@ LL | | .collect();
| |__________________^ help: consider calling `.retain()` instead: `hash_map.retain(|k, &mut v| (k % 2 == 0) && (v % 2 == 0))`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:131:5
+ --> $DIR/manual_retain.rs:130:5
|
LL | hash_set = hash_set.into_iter().filter(|x| x % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:132:5
+ --> $DIR/manual_retain.rs:131:5
|
LL | hash_set = hash_set.iter().filter(|&x| x % 2 == 0).copied().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:133:5
+ --> $DIR/manual_retain.rs:132:5
|
LL | hash_set = hash_set.iter().filter(|&x| x % 2 == 0).cloned().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `hash_set.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:162:5
+ --> $DIR/manual_retain.rs:161:5
|
LL | s = s.chars().filter(|&c| c != 'o').to_owned().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `s.retain(|c| c != 'o')`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:174:5
+ --> $DIR/manual_retain.rs:173:5
|
LL | vec = vec.iter().filter(|&x| x % 2 == 0).copied().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:175:5
+ --> $DIR/manual_retain.rs:174:5
|
LL | vec = vec.iter().filter(|&x| x % 2 == 0).cloned().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:176:5
+ --> $DIR/manual_retain.rs:175:5
|
LL | vec = vec.into_iter().filter(|x| x % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:198:5
+ --> $DIR/manual_retain.rs:197:5
|
LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).copied().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:199:5
+ --> $DIR/manual_retain.rs:198:5
|
LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).cloned().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)`
error: this expression can be written more simply using `.retain()`
- --> $DIR/manual_retain.rs:200:5
+ --> $DIR/manual_retain.rs:199:5
|
LL | vec_deque = vec_deque.into_iter().filter(|x| x % 2 == 0).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)`
diff --git a/src/tools/clippy/tests/ui/manual_split_once.fixed b/src/tools/clippy/tests/ui/manual_split_once.fixed
index c7ca77043..50b02019c 100644
--- a/src/tools/clippy/tests/ui/manual_split_once.fixed
+++ b/src/tools/clippy/tests/ui/manual_split_once.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::manual_split_once)]
#![allow(unused, clippy::iter_skip_next, clippy::iter_nth_zero)]
@@ -127,8 +126,8 @@ fn indirect() -> Option<()> {
None
}
+#[clippy::msrv = "1.51"]
fn _msrv_1_51() {
- #![clippy::msrv = "1.51"]
// `str::split_once` was stabilized in 1.52. Do not lint this
let _ = "key=value".splitn(2, '=').nth(1).unwrap();
@@ -137,8 +136,8 @@ fn _msrv_1_51() {
let b = iter.next().unwrap();
}
+#[clippy::msrv = "1.52"]
fn _msrv_1_52() {
- #![clippy::msrv = "1.52"]
let _ = "key=value".split_once('=').unwrap().1;
let (a, b) = "a.b.c".split_once('.').unwrap();
diff --git a/src/tools/clippy/tests/ui/manual_split_once.rs b/src/tools/clippy/tests/ui/manual_split_once.rs
index ee2848a25..e1e8b71a9 100644
--- a/src/tools/clippy/tests/ui/manual_split_once.rs
+++ b/src/tools/clippy/tests/ui/manual_split_once.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::manual_split_once)]
#![allow(unused, clippy::iter_skip_next, clippy::iter_nth_zero)]
@@ -127,8 +126,8 @@ fn indirect() -> Option<()> {
None
}
+#[clippy::msrv = "1.51"]
fn _msrv_1_51() {
- #![clippy::msrv = "1.51"]
// `str::split_once` was stabilized in 1.52. Do not lint this
let _ = "key=value".splitn(2, '=').nth(1).unwrap();
@@ -137,8 +136,8 @@ fn _msrv_1_51() {
let b = iter.next().unwrap();
}
+#[clippy::msrv = "1.52"]
fn _msrv_1_52() {
- #![clippy::msrv = "1.52"]
let _ = "key=value".splitn(2, '=').nth(1).unwrap();
let mut iter = "a.b.c".splitn(2, '.');
diff --git a/src/tools/clippy/tests/ui/manual_split_once.stderr b/src/tools/clippy/tests/ui/manual_split_once.stderr
index 269669468..78da5a16c 100644
--- a/src/tools/clippy/tests/ui/manual_split_once.stderr
+++ b/src/tools/clippy/tests/ui/manual_split_once.stderr
@@ -1,5 +1,5 @@
error: manual implementation of `split_once`
- --> $DIR/manual_split_once.rs:14:13
+ --> $DIR/manual_split_once.rs:13:13
|
LL | let _ = "key=value".splitn(2, '=').nth(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"key=value".split_once('=').unwrap().1`
@@ -7,79 +7,79 @@ LL | let _ = "key=value".splitn(2, '=').nth(1).unwrap();
= note: `-D clippy::manual-split-once` implied by `-D warnings`
error: manual implementation of `split_once`
- --> $DIR/manual_split_once.rs:15:13
+ --> $DIR/manual_split_once.rs:14:13
|
LL | let _ = "key=value".splitn(2, '=').skip(1).next().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"key=value".split_once('=').unwrap().1`
error: manual implementation of `split_once`
- --> $DIR/manual_split_once.rs:16:18
+ --> $DIR/manual_split_once.rs:15:18
|
LL | let (_, _) = "key=value".splitn(2, '=').next_tuple().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"key=value".split_once('=')`
error: manual implementation of `split_once`
- --> $DIR/manual_split_once.rs:19:13
+ --> $DIR/manual_split_once.rs:18:13
|
LL | let _ = s.splitn(2, '=').nth(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.split_once('=').unwrap().1`
error: manual implementation of `split_once`
- --> $DIR/manual_split_once.rs:22:13
+ --> $DIR/manual_split_once.rs:21:13
|
LL | let _ = s.splitn(2, '=').nth(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.split_once('=').unwrap().1`
error: manual implementation of `split_once`
- --> $DIR/manual_split_once.rs:25:13
+ --> $DIR/manual_split_once.rs:24:13
|
LL | let _ = s.splitn(2, '=').skip(1).next().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.split_once('=').unwrap().1`
error: manual implementation of `split_once`
- --> $DIR/manual_split_once.rs:28:17
+ --> $DIR/manual_split_once.rs:27:17
|
LL | let _ = s.splitn(2, '=').nth(1)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.split_once('=')?.1`
error: manual implementation of `split_once`
- --> $DIR/manual_split_once.rs:29:17
+ --> $DIR/manual_split_once.rs:28:17
|
LL | let _ = s.splitn(2, '=').skip(1).next()?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.split_once('=')?.1`
error: manual implementation of `rsplit_once`
- --> $DIR/manual_split_once.rs:30:17
+ --> $DIR/manual_split_once.rs:29:17
|
LL | let _ = s.rsplitn(2, '=').nth(1)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.rsplit_once('=')?.0`
error: manual implementation of `rsplit_once`
- --> $DIR/manual_split_once.rs:31:17
+ --> $DIR/manual_split_once.rs:30:17
|
LL | let _ = s.rsplitn(2, '=').skip(1).next()?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.rsplit_once('=')?.0`
error: manual implementation of `rsplit_once`
- --> $DIR/manual_split_once.rs:39:13
+ --> $DIR/manual_split_once.rs:38:13
|
LL | let _ = "key=value".rsplitn(2, '=').nth(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"key=value".rsplit_once('=').unwrap().0`
error: manual implementation of `rsplit_once`
- --> $DIR/manual_split_once.rs:40:18
+ --> $DIR/manual_split_once.rs:39:18
|
LL | let (_, _) = "key=value".rsplitn(2, '=').next_tuple().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"key=value".rsplit_once('=').map(|(x, y)| (y, x))`
error: manual implementation of `rsplit_once`
- --> $DIR/manual_split_once.rs:41:13
+ --> $DIR/manual_split_once.rs:40:13
|
LL | let _ = s.rsplitn(2, '=').nth(1);
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.rsplit_once('=').map(|x| x.0)`
error: manual implementation of `split_once`
- --> $DIR/manual_split_once.rs:45:5
+ --> $DIR/manual_split_once.rs:44:5
|
LL | let mut iter = "a.b.c".splitn(2, '.');
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -104,7 +104,7 @@ LL +
|
error: manual implementation of `split_once`
- --> $DIR/manual_split_once.rs:49:5
+ --> $DIR/manual_split_once.rs:48:5
|
LL | let mut iter = "a.b.c".splitn(2, '.');
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -129,7 +129,7 @@ LL +
|
error: manual implementation of `rsplit_once`
- --> $DIR/manual_split_once.rs:53:5
+ --> $DIR/manual_split_once.rs:52:5
|
LL | let mut iter = "a.b.c".rsplitn(2, '.');
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -154,7 +154,7 @@ LL +
|
error: manual implementation of `rsplit_once`
- --> $DIR/manual_split_once.rs:57:5
+ --> $DIR/manual_split_once.rs:56:5
|
LL | let mut iter = "a.b.c".rsplitn(2, '.');
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -179,13 +179,13 @@ LL +
|
error: manual implementation of `split_once`
- --> $DIR/manual_split_once.rs:142:13
+ --> $DIR/manual_split_once.rs:141:13
|
LL | let _ = "key=value".splitn(2, '=').nth(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"key=value".split_once('=').unwrap().1`
error: manual implementation of `split_once`
- --> $DIR/manual_split_once.rs:144:5
+ --> $DIR/manual_split_once.rs:143:5
|
LL | let mut iter = "a.b.c".splitn(2, '.');
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/manual_str_repeat.fixed b/src/tools/clippy/tests/ui/manual_str_repeat.fixed
index 0704ba2f9..3d56f2a0d 100644
--- a/src/tools/clippy/tests/ui/manual_str_repeat.fixed
+++ b/src/tools/clippy/tests/ui/manual_str_repeat.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::manual_str_repeat)]
use std::borrow::Cow;
@@ -54,13 +53,13 @@ fn main() {
let _: String = repeat(x).take(count).collect();
}
+#[clippy::msrv = "1.15"]
fn _msrv_1_15() {
- #![clippy::msrv = "1.15"]
// `str::repeat` was stabilized in 1.16. Do not lint this
let _: String = std::iter::repeat("test").take(10).collect();
}
+#[clippy::msrv = "1.16"]
fn _msrv_1_16() {
- #![clippy::msrv = "1.16"]
let _: String = "test".repeat(10);
}
diff --git a/src/tools/clippy/tests/ui/manual_str_repeat.rs b/src/tools/clippy/tests/ui/manual_str_repeat.rs
index f522be439..e8240a949 100644
--- a/src/tools/clippy/tests/ui/manual_str_repeat.rs
+++ b/src/tools/clippy/tests/ui/manual_str_repeat.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::manual_str_repeat)]
use std::borrow::Cow;
@@ -54,13 +53,13 @@ fn main() {
let _: String = repeat(x).take(count).collect();
}
+#[clippy::msrv = "1.15"]
fn _msrv_1_15() {
- #![clippy::msrv = "1.15"]
// `str::repeat` was stabilized in 1.16. Do not lint this
let _: String = std::iter::repeat("test").take(10).collect();
}
+#[clippy::msrv = "1.16"]
fn _msrv_1_16() {
- #![clippy::msrv = "1.16"]
let _: String = std::iter::repeat("test").take(10).collect();
}
diff --git a/src/tools/clippy/tests/ui/manual_str_repeat.stderr b/src/tools/clippy/tests/ui/manual_str_repeat.stderr
index c65116897..bdfee7cab 100644
--- a/src/tools/clippy/tests/ui/manual_str_repeat.stderr
+++ b/src/tools/clippy/tests/ui/manual_str_repeat.stderr
@@ -1,5 +1,5 @@
error: manual implementation of `str::repeat` using iterators
- --> $DIR/manual_str_repeat.rs:10:21
+ --> $DIR/manual_str_repeat.rs:9:21
|
LL | let _: String = std::iter::repeat("test").take(10).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"test".repeat(10)`
@@ -7,55 +7,55 @@ LL | let _: String = std::iter::repeat("test").take(10).collect();
= note: `-D clippy::manual-str-repeat` implied by `-D warnings`
error: manual implementation of `str::repeat` using iterators
- --> $DIR/manual_str_repeat.rs:11:21
+ --> $DIR/manual_str_repeat.rs:10:21
|
LL | let _: String = std::iter::repeat('x').take(10).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"x".repeat(10)`
error: manual implementation of `str::repeat` using iterators
- --> $DIR/manual_str_repeat.rs:12:21
+ --> $DIR/manual_str_repeat.rs:11:21
|
LL | let _: String = std::iter::repeat('/'').take(10).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"'".repeat(10)`
error: manual implementation of `str::repeat` using iterators
- --> $DIR/manual_str_repeat.rs:13:21
+ --> $DIR/manual_str_repeat.rs:12:21
|
LL | let _: String = std::iter::repeat('"').take(10).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"/"".repeat(10)`
error: manual implementation of `str::repeat` using iterators
- --> $DIR/manual_str_repeat.rs:17:13
+ --> $DIR/manual_str_repeat.rs:16:13
|
LL | let _ = repeat(x).take(count + 2).collect::<String>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `x.repeat(count + 2)`
error: manual implementation of `str::repeat` using iterators
- --> $DIR/manual_str_repeat.rs:26:21
+ --> $DIR/manual_str_repeat.rs:25:21
|
LL | let _: String = repeat(*x).take(count).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `(*x).repeat(count)`
error: manual implementation of `str::repeat` using iterators
- --> $DIR/manual_str_repeat.rs:35:21
+ --> $DIR/manual_str_repeat.rs:34:21
|
LL | let _: String = repeat(x).take(count).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `x.repeat(count)`
error: manual implementation of `str::repeat` using iterators
- --> $DIR/manual_str_repeat.rs:47:21
+ --> $DIR/manual_str_repeat.rs:46:21
|
LL | let _: String = repeat(Cow::Borrowed("test")).take(count).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `Cow::Borrowed("test").repeat(count)`
error: manual implementation of `str::repeat` using iterators
- --> $DIR/manual_str_repeat.rs:50:21
+ --> $DIR/manual_str_repeat.rs:49:21
|
LL | let _: String = repeat(x).take(count).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `x.repeat(count)`
error: manual implementation of `str::repeat` using iterators
- --> $DIR/manual_str_repeat.rs:65:21
+ --> $DIR/manual_str_repeat.rs:64:21
|
LL | let _: String = std::iter::repeat("test").take(10).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"test".repeat(10)`
diff --git a/src/tools/clippy/tests/ui/manual_strip.rs b/src/tools/clippy/tests/ui/manual_strip.rs
index 85009d785..b0b1c262a 100644
--- a/src/tools/clippy/tests/ui/manual_strip.rs
+++ b/src/tools/clippy/tests/ui/manual_strip.rs
@@ -1,4 +1,3 @@
-#![feature(custom_inner_attributes)]
#![warn(clippy::manual_strip)]
fn main() {
@@ -66,18 +65,16 @@ fn main() {
}
}
+#[clippy::msrv = "1.44"]
fn msrv_1_44() {
- #![clippy::msrv = "1.44"]
-
let s = "abc";
if s.starts_with('a') {
s[1..].to_string();
}
}
+#[clippy::msrv = "1.45"]
fn msrv_1_45() {
- #![clippy::msrv = "1.45"]
-
let s = "abc";
if s.starts_with('a') {
s[1..].to_string();
diff --git a/src/tools/clippy/tests/ui/manual_strip.stderr b/src/tools/clippy/tests/ui/manual_strip.stderr
index ad2a362f3..f592e898f 100644
--- a/src/tools/clippy/tests/ui/manual_strip.stderr
+++ b/src/tools/clippy/tests/ui/manual_strip.stderr
@@ -1,11 +1,11 @@
error: stripping a prefix manually
- --> $DIR/manual_strip.rs:8:24
+ --> $DIR/manual_strip.rs:7:24
|
LL | str::to_string(&s["ab".len()..]);
| ^^^^^^^^^^^^^^^^
|
note: the prefix was tested here
- --> $DIR/manual_strip.rs:7:5
+ --> $DIR/manual_strip.rs:6:5
|
LL | if s.starts_with("ab") {
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -21,13 +21,13 @@ LL ~ <stripped>.to_string();
|
error: stripping a suffix manually
- --> $DIR/manual_strip.rs:16:24
+ --> $DIR/manual_strip.rs:15:24
|
LL | str::to_string(&s[..s.len() - "bc".len()]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the suffix was tested here
- --> $DIR/manual_strip.rs:15:5
+ --> $DIR/manual_strip.rs:14:5
|
LL | if s.ends_with("bc") {
| ^^^^^^^^^^^^^^^^^^^^^
@@ -42,13 +42,13 @@ LL ~ <stripped>.to_string();
|
error: stripping a prefix manually
- --> $DIR/manual_strip.rs:25:24
+ --> $DIR/manual_strip.rs:24:24
|
LL | str::to_string(&s[1..]);
| ^^^^^^^
|
note: the prefix was tested here
- --> $DIR/manual_strip.rs:24:5
+ --> $DIR/manual_strip.rs:23:5
|
LL | if s.starts_with('a') {
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -60,13 +60,13 @@ LL ~ <stripped>.to_string();
|
error: stripping a prefix manually
- --> $DIR/manual_strip.rs:32:24
+ --> $DIR/manual_strip.rs:31:24
|
LL | str::to_string(&s[prefix.len()..]);
| ^^^^^^^^^^^^^^^^^^
|
note: the prefix was tested here
- --> $DIR/manual_strip.rs:31:5
+ --> $DIR/manual_strip.rs:30:5
|
LL | if s.starts_with(prefix) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -77,13 +77,13 @@ LL ~ str::to_string(<stripped>);
|
error: stripping a prefix manually
- --> $DIR/manual_strip.rs:38:24
+ --> $DIR/manual_strip.rs:37:24
|
LL | str::to_string(&s[PREFIX.len()..]);
| ^^^^^^^^^^^^^^^^^^
|
note: the prefix was tested here
- --> $DIR/manual_strip.rs:37:5
+ --> $DIR/manual_strip.rs:36:5
|
LL | if s.starts_with(PREFIX) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -95,13 +95,13 @@ LL ~ str::to_string(<stripped>);
|
error: stripping a prefix manually
- --> $DIR/manual_strip.rs:45:24
+ --> $DIR/manual_strip.rs:44:24
|
LL | str::to_string(&TARGET[prefix.len()..]);
| ^^^^^^^^^^^^^^^^^^^^^^^
|
note: the prefix was tested here
- --> $DIR/manual_strip.rs:44:5
+ --> $DIR/manual_strip.rs:43:5
|
LL | if TARGET.starts_with(prefix) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -112,13 +112,13 @@ LL ~ str::to_string(<stripped>);
|
error: stripping a prefix manually
- --> $DIR/manual_strip.rs:51:9
+ --> $DIR/manual_strip.rs:50:9
|
LL | s1[2..].to_uppercase();
| ^^^^^^^
|
note: the prefix was tested here
- --> $DIR/manual_strip.rs:50:5
+ --> $DIR/manual_strip.rs:49:5
|
LL | if s1.starts_with("ab") {
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -129,13 +129,13 @@ LL ~ <stripped>.to_uppercase();
|
error: stripping a prefix manually
- --> $DIR/manual_strip.rs:83:9
+ --> $DIR/manual_strip.rs:80:9
|
LL | s[1..].to_string();
| ^^^^^^
|
note: the prefix was tested here
- --> $DIR/manual_strip.rs:82:5
+ --> $DIR/manual_strip.rs:79:5
|
LL | if s.starts_with('a') {
| ^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/map_flatten_fixable.fixed b/src/tools/clippy/tests/ui/map_flatten_fixable.fixed
index 312819a0a..53628ef65 100644
--- a/src/tools/clippy/tests/ui/map_flatten_fixable.fixed
+++ b/src/tools/clippy/tests/ui/map_flatten_fixable.fixed
@@ -1,7 +1,6 @@
// run-rustfix
#![warn(clippy::all, clippy::pedantic)]
-#![allow(clippy::let_underscore_drop)]
#![allow(clippy::missing_docs_in_private_items)]
#![allow(clippy::map_identity)]
#![allow(clippy::redundant_closure)]
diff --git a/src/tools/clippy/tests/ui/map_flatten_fixable.rs b/src/tools/clippy/tests/ui/map_flatten_fixable.rs
index 3fbf4f9a1..76016c8ed 100644
--- a/src/tools/clippy/tests/ui/map_flatten_fixable.rs
+++ b/src/tools/clippy/tests/ui/map_flatten_fixable.rs
@@ -1,7 +1,6 @@
// run-rustfix
#![warn(clippy::all, clippy::pedantic)]
-#![allow(clippy::let_underscore_drop)]
#![allow(clippy::missing_docs_in_private_items)]
#![allow(clippy::map_identity)]
#![allow(clippy::redundant_closure)]
diff --git a/src/tools/clippy/tests/ui/map_flatten_fixable.stderr b/src/tools/clippy/tests/ui/map_flatten_fixable.stderr
index c91f0b9ae..b6b0c4d09 100644
--- a/src/tools/clippy/tests/ui/map_flatten_fixable.stderr
+++ b/src/tools/clippy/tests/ui/map_flatten_fixable.stderr
@@ -1,5 +1,5 @@
error: called `map(..).flatten()` on `Iterator`
- --> $DIR/map_flatten_fixable.rs:18:47
+ --> $DIR/map_flatten_fixable.rs:17:47
|
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id)`
@@ -7,43 +7,43 @@ LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().coll
= note: `-D clippy::map-flatten` implied by `-D warnings`
error: called `map(..).flatten()` on `Iterator`
- --> $DIR/map_flatten_fixable.rs:19:47
+ --> $DIR/map_flatten_fixable.rs:18:47
|
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_ref).flatten().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id_ref)`
error: called `map(..).flatten()` on `Iterator`
- --> $DIR/map_flatten_fixable.rs:20:47
+ --> $DIR/map_flatten_fixable.rs:19:47
|
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_closure).flatten().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(option_id_closure)`
error: called `map(..).flatten()` on `Iterator`
- --> $DIR/map_flatten_fixable.rs:21:47
+ --> $DIR/map_flatten_fixable.rs:20:47
|
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| x.checked_add(1)).flatten().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `filter_map` and remove the `.flatten()`: `filter_map(|x| x.checked_add(1))`
error: called `map(..).flatten()` on `Iterator`
- --> $DIR/map_flatten_fixable.rs:24:47
+ --> $DIR/map_flatten_fixable.rs:23:47
|
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `flat_map` and remove the `.flatten()`: `flat_map(|x| 0..x)`
error: called `map(..).flatten()` on `Option`
- --> $DIR/map_flatten_fixable.rs:27:40
+ --> $DIR/map_flatten_fixable.rs:26:40
|
LL | let _: Option<_> = (Some(Some(1))).map(|x| x).flatten();
| ^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|x| x)`
error: called `map(..).flatten()` on `Result`
- --> $DIR/map_flatten_fixable.rs:30:42
+ --> $DIR/map_flatten_fixable.rs:29:42
|
LL | let _: Result<_, &str> = (Ok(Ok(1))).map(|x| x).flatten();
| ^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|x| x)`
error: called `map(..).flatten()` on `Iterator`
- --> $DIR/map_flatten_fixable.rs:39:10
+ --> $DIR/map_flatten_fixable.rs:38:10
|
LL | .map(|n| match n {
| __________^
@@ -72,7 +72,7 @@ LL ~ });
|
error: called `map(..).flatten()` on `Option`
- --> $DIR/map_flatten_fixable.rs:59:10
+ --> $DIR/map_flatten_fixable.rs:58:10
|
LL | .map(|_| {
| __________^
diff --git a/src/tools/clippy/tests/ui/map_unwrap_or.rs b/src/tools/clippy/tests/ui/map_unwrap_or.rs
index 396b22a9a..32631024c 100644
--- a/src/tools/clippy/tests/ui/map_unwrap_or.rs
+++ b/src/tools/clippy/tests/ui/map_unwrap_or.rs
@@ -1,6 +1,5 @@
// aux-build:option_helpers.rs
-#![feature(custom_inner_attributes)]
#![warn(clippy::map_unwrap_or)]
#![allow(clippy::uninlined_format_args, clippy::unnecessary_lazy_evaluations)]
@@ -82,17 +81,15 @@ fn main() {
result_methods();
}
+#[clippy::msrv = "1.40"]
fn msrv_1_40() {
- #![clippy::msrv = "1.40"]
-
let res: Result<i32, ()> = Ok(1);
let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
}
+#[clippy::msrv = "1.41"]
fn msrv_1_41() {
- #![clippy::msrv = "1.41"]
-
let res: Result<i32, ()> = Ok(1);
let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
diff --git a/src/tools/clippy/tests/ui/map_unwrap_or.stderr b/src/tools/clippy/tests/ui/map_unwrap_or.stderr
index d17d24a40..41781b050 100644
--- a/src/tools/clippy/tests/ui/map_unwrap_or.stderr
+++ b/src/tools/clippy/tests/ui/map_unwrap_or.stderr
@@ -1,5 +1,5 @@
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:18:13
+ --> $DIR/map_unwrap_or.rs:17:13
|
LL | let _ = opt.map(|x| x + 1)
| _____________^
@@ -15,7 +15,7 @@ LL + let _ = opt.map_or(0, |x| x + 1);
|
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:22:13
+ --> $DIR/map_unwrap_or.rs:21:13
|
LL | let _ = opt.map(|x| {
| _____________^
@@ -33,7 +33,7 @@ LL ~ );
|
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:26:13
+ --> $DIR/map_unwrap_or.rs:25:13
|
LL | let _ = opt.map(|x| x + 1)
| _____________^
@@ -50,7 +50,7 @@ LL ~ }, |x| x + 1);
|
error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
- --> $DIR/map_unwrap_or.rs:31:13
+ --> $DIR/map_unwrap_or.rs:30:13
|
LL | let _ = opt.map(|x| Some(x + 1)).unwrap_or(None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -62,7 +62,7 @@ LL + let _ = opt.and_then(|x| Some(x + 1));
|
error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
- --> $DIR/map_unwrap_or.rs:33:13
+ --> $DIR/map_unwrap_or.rs:32:13
|
LL | let _ = opt.map(|x| {
| _____________^
@@ -80,7 +80,7 @@ LL ~ );
|
error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
- --> $DIR/map_unwrap_or.rs:37:13
+ --> $DIR/map_unwrap_or.rs:36:13
|
LL | let _ = opt
| _____________^
@@ -95,7 +95,7 @@ LL + .and_then(|x| Some(x + 1));
|
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:48:13
+ --> $DIR/map_unwrap_or.rs:47:13
|
LL | let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -107,7 +107,7 @@ LL + let _ = Some("prefix").map_or(id, |p| format!("{}.", p));
|
error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:52:13
+ --> $DIR/map_unwrap_or.rs:51:13
|
LL | let _ = opt.map(|x| {
| _____________^
@@ -117,7 +117,7 @@ LL | | ).unwrap_or_else(|| 0);
| |__________________________^
error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:56:13
+ --> $DIR/map_unwrap_or.rs:55:13
|
LL | let _ = opt.map(|x| x + 1)
| _____________^
@@ -127,7 +127,7 @@ LL | | );
| |_________^
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:68:13
+ --> $DIR/map_unwrap_or.rs:67:13
|
LL | let _ = res.map(|x| {
| _____________^
@@ -137,7 +137,7 @@ LL | | ).unwrap_or_else(|_e| 0);
| |____________________________^
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:72:13
+ --> $DIR/map_unwrap_or.rs:71:13
|
LL | let _ = res.map(|x| x + 1)
| _____________^
@@ -147,7 +147,7 @@ LL | | });
| |__________^
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:98:13
+ --> $DIR/map_unwrap_or.rs:95:13
|
LL | let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `res.map_or_else(|_e| 0, |x| x + 1)`
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 249800769..55cd15bd5 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,8 +1,12 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::match_like_matches_macro)]
-#![allow(unreachable_patterns, dead_code, clippy::equatable_if_let)]
+#![allow(
+ unreachable_patterns,
+ dead_code,
+ clippy::equatable_if_let,
+ clippy::needless_borrowed_reference
+)]
fn main() {
let x = Some(5);
@@ -195,17 +199,15 @@ fn main() {
};
}
+#[clippy::msrv = "1.41"]
fn msrv_1_41() {
- #![clippy::msrv = "1.41"]
-
let _y = match Some(5) {
Some(0) => true,
_ => false,
};
}
+#[clippy::msrv = "1.42"]
fn msrv_1_42() {
- #![clippy::msrv = "1.42"]
-
let _y = matches!(Some(5), Some(0));
}
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 b4e48499b..5d645e108 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,8 +1,12 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::match_like_matches_macro)]
-#![allow(unreachable_patterns, dead_code, clippy::equatable_if_let)]
+#![allow(
+ unreachable_patterns,
+ dead_code,
+ clippy::equatable_if_let,
+ clippy::needless_borrowed_reference
+)]
fn main() {
let x = Some(5);
@@ -236,18 +240,16 @@ fn main() {
};
}
+#[clippy::msrv = "1.41"]
fn msrv_1_41() {
- #![clippy::msrv = "1.41"]
-
let _y = match Some(5) {
Some(0) => true,
_ => false,
};
}
+#[clippy::msrv = "1.42"]
fn msrv_1_42() {
- #![clippy::msrv = "1.42"]
-
let _y = match Some(5) {
Some(0) => true,
_ => false,
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 f1d1c23ae..46f67ef49 100644
--- a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr
+++ b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr
@@ -1,5 +1,5 @@
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:11:14
+ --> $DIR/match_expr_like_matches_macro.rs:15:14
|
LL | let _y = match x {
| ______________^
@@ -11,7 +11,7 @@ LL | | };
= note: `-D clippy::match-like-matches-macro` implied by `-D warnings`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:17:14
+ --> $DIR/match_expr_like_matches_macro.rs:21:14
|
LL | let _w = match x {
| ______________^
@@ -21,7 +21,7 @@ LL | | };
| |_____^ help: try this: `matches!(x, Some(_))`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/match_expr_like_matches_macro.rs:23:14
+ --> $DIR/match_expr_like_matches_macro.rs:27:14
|
LL | let _z = match x {
| ______________^
@@ -33,7 +33,7 @@ LL | | };
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:29:15
+ --> $DIR/match_expr_like_matches_macro.rs:33:15
|
LL | let _zz = match x {
| _______________^
@@ -43,13 +43,13 @@ LL | | };
| |_____^ help: try this: `!matches!(x, Some(r) if r == 0)`
error: if let .. else expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:35:16
+ --> $DIR/match_expr_like_matches_macro.rs:39:16
|
LL | let _zzz = if let Some(5) = x { true } else { false };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `matches!(x, Some(5))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:59:20
+ --> $DIR/match_expr_like_matches_macro.rs:63:20
|
LL | let _ans = match x {
| ____________________^
@@ -60,7 +60,7 @@ LL | | };
| |_________^ help: try this: `matches!(x, E::A(_) | E::B(_))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:69:20
+ --> $DIR/match_expr_like_matches_macro.rs:73:20
|
LL | let _ans = match x {
| ____________________^
@@ -73,7 +73,7 @@ LL | | };
| |_________^ help: try this: `matches!(x, E::A(_) | E::B(_))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:79:20
+ --> $DIR/match_expr_like_matches_macro.rs:83:20
|
LL | let _ans = match x {
| ____________________^
@@ -84,7 +84,7 @@ LL | | };
| |_________^ help: try this: `!matches!(x, E::B(_) | E::C)`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:139:18
+ --> $DIR/match_expr_like_matches_macro.rs:143:18
|
LL | let _z = match &z {
| __________________^
@@ -94,7 +94,7 @@ LL | | };
| |_________^ help: try this: `matches!(z, Some(3))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:148:18
+ --> $DIR/match_expr_like_matches_macro.rs:152:18
|
LL | let _z = match &z {
| __________________^
@@ -104,7 +104,7 @@ LL | | };
| |_________^ help: try this: `matches!(&z, Some(3))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:165:21
+ --> $DIR/match_expr_like_matches_macro.rs:169:21
|
LL | let _ = match &z {
| _____________________^
@@ -114,7 +114,7 @@ LL | | };
| |_____________^ help: try this: `matches!(&z, AnEnum::X)`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:179:20
+ --> $DIR/match_expr_like_matches_macro.rs:183:20
|
LL | let _res = match &val {
| ____________________^
@@ -124,7 +124,7 @@ LL | | };
| |_________^ help: try this: `matches!(&val, &Some(ref _a))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:191:20
+ --> $DIR/match_expr_like_matches_macro.rs:195:20
|
LL | let _res = match &val {
| ____________________^
@@ -134,7 +134,7 @@ LL | | };
| |_________^ help: try this: `matches!(&val, &Some(ref _a))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:251:14
+ --> $DIR/match_expr_like_matches_macro.rs:253:14
|
LL | let _y = match Some(5) {
| ______________^
diff --git a/src/tools/clippy/tests/ui/mem_replace.fixed b/src/tools/clippy/tests/ui/mem_replace.fixed
index ae237395b..874d55843 100644
--- a/src/tools/clippy/tests/ui/mem_replace.fixed
+++ b/src/tools/clippy/tests/ui/mem_replace.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![allow(unused)]
#![warn(
clippy::all,
@@ -80,16 +79,14 @@ fn main() {
dont_lint_primitive();
}
+#[clippy::msrv = "1.39"]
fn msrv_1_39() {
- #![clippy::msrv = "1.39"]
-
let mut s = String::from("foo");
let _ = std::mem::replace(&mut s, String::default());
}
+#[clippy::msrv = "1.40"]
fn msrv_1_40() {
- #![clippy::msrv = "1.40"]
-
let mut s = String::from("foo");
let _ = std::mem::take(&mut s);
}
diff --git a/src/tools/clippy/tests/ui/mem_replace.rs b/src/tools/clippy/tests/ui/mem_replace.rs
index 3202e99e0..f4f3bff51 100644
--- a/src/tools/clippy/tests/ui/mem_replace.rs
+++ b/src/tools/clippy/tests/ui/mem_replace.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![allow(unused)]
#![warn(
clippy::all,
@@ -80,16 +79,14 @@ fn main() {
dont_lint_primitive();
}
+#[clippy::msrv = "1.39"]
fn msrv_1_39() {
- #![clippy::msrv = "1.39"]
-
let mut s = String::from("foo");
let _ = std::mem::replace(&mut s, String::default());
}
+#[clippy::msrv = "1.40"]
fn msrv_1_40() {
- #![clippy::msrv = "1.40"]
-
let mut s = String::from("foo");
let _ = std::mem::replace(&mut s, String::default());
}
diff --git a/src/tools/clippy/tests/ui/mem_replace.stderr b/src/tools/clippy/tests/ui/mem_replace.stderr
index dd8a50dab..caa127f76 100644
--- a/src/tools/clippy/tests/ui/mem_replace.stderr
+++ b/src/tools/clippy/tests/ui/mem_replace.stderr
@@ -1,5 +1,5 @@
error: replacing an `Option` with `None`
- --> $DIR/mem_replace.rs:17:13
+ --> $DIR/mem_replace.rs:16:13
|
LL | let _ = mem::replace(&mut an_option, None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()`
@@ -7,13 +7,13 @@ LL | let _ = mem::replace(&mut an_option, None);
= note: `-D clippy::mem-replace-option-with-none` implied by `-D warnings`
error: replacing an `Option` with `None`
- --> $DIR/mem_replace.rs:19:13
+ --> $DIR/mem_replace.rs:18:13
|
LL | let _ = mem::replace(an_option, None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:24:13
+ --> $DIR/mem_replace.rs:23:13
|
LL | let _ = std::mem::replace(&mut s, String::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)`
@@ -21,103 +21,103 @@ LL | let _ = std::mem::replace(&mut s, String::default());
= note: `-D clippy::mem-replace-with-default` implied by `-D warnings`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:27:13
+ --> $DIR/mem_replace.rs:26:13
|
LL | let _ = std::mem::replace(s, String::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:28:13
+ --> $DIR/mem_replace.rs:27:13
|
LL | let _ = std::mem::replace(s, Default::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:31:13
+ --> $DIR/mem_replace.rs:30:13
|
LL | let _ = std::mem::replace(&mut v, Vec::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:32:13
+ --> $DIR/mem_replace.rs:31:13
|
LL | let _ = std::mem::replace(&mut v, Default::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:33:13
+ --> $DIR/mem_replace.rs:32:13
|
LL | let _ = std::mem::replace(&mut v, Vec::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:34:13
+ --> $DIR/mem_replace.rs:33:13
|
LL | let _ = std::mem::replace(&mut v, vec![]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:37:13
+ --> $DIR/mem_replace.rs:36:13
|
LL | let _ = std::mem::replace(&mut hash_map, HashMap::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut hash_map)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:40:13
+ --> $DIR/mem_replace.rs:39:13
|
LL | let _ = std::mem::replace(&mut btree_map, BTreeMap::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut btree_map)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:43:13
+ --> $DIR/mem_replace.rs:42:13
|
LL | let _ = std::mem::replace(&mut vd, VecDeque::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut vd)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:46:13
+ --> $DIR/mem_replace.rs:45:13
|
LL | let _ = std::mem::replace(&mut hash_set, HashSet::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut hash_set)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:49:13
+ --> $DIR/mem_replace.rs:48:13
|
LL | let _ = std::mem::replace(&mut btree_set, BTreeSet::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut btree_set)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:52:13
+ --> $DIR/mem_replace.rs:51:13
|
LL | let _ = std::mem::replace(&mut list, LinkedList::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut list)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:55:13
+ --> $DIR/mem_replace.rs:54:13
|
LL | let _ = std::mem::replace(&mut binary_heap, BinaryHeap::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut binary_heap)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:58:13
+ --> $DIR/mem_replace.rs:57:13
|
LL | let _ = std::mem::replace(&mut tuple, (vec![], BinaryHeap::new()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut tuple)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:61:13
+ --> $DIR/mem_replace.rs:60:13
|
LL | let _ = std::mem::replace(&mut refstr, "");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut refstr)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:64:13
+ --> $DIR/mem_replace.rs:63:13
|
LL | let _ = std::mem::replace(&mut slice, &[]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut slice)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:94:13
+ --> $DIR/mem_replace.rs:91:13
|
LL | let _ = std::mem::replace(&mut s, String::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)`
diff --git a/src/tools/clippy/tests/ui/min_rust_version_attr.rs b/src/tools/clippy/tests/ui/min_rust_version_attr.rs
index cd148063b..955e7eb72 100644
--- a/src/tools/clippy/tests/ui/min_rust_version_attr.rs
+++ b/src/tools/clippy/tests/ui/min_rust_version_attr.rs
@@ -3,27 +3,60 @@
fn main() {}
+#[clippy::msrv = "1.42.0"]
fn just_under_msrv() {
- #![clippy::msrv = "1.42.0"]
let log2_10 = 3.321928094887362;
}
+#[clippy::msrv = "1.43.0"]
fn meets_msrv() {
- #![clippy::msrv = "1.43.0"]
let log2_10 = 3.321928094887362;
}
+#[clippy::msrv = "1.44.0"]
fn just_above_msrv() {
- #![clippy::msrv = "1.44.0"]
let log2_10 = 3.321928094887362;
}
+#[clippy::msrv = "1.42"]
fn no_patch_under() {
- #![clippy::msrv = "1.42"]
let log2_10 = 3.321928094887362;
}
+#[clippy::msrv = "1.43"]
fn no_patch_meets() {
+ let log2_10 = 3.321928094887362;
+}
+
+fn inner_attr_under() {
+ #![clippy::msrv = "1.42"]
+ let log2_10 = 3.321928094887362;
+}
+
+fn inner_attr_meets() {
#![clippy::msrv = "1.43"]
let log2_10 = 3.321928094887362;
}
+
+// https://github.com/rust-lang/rust-clippy/issues/6920
+fn scoping() {
+ mod m {
+ #![clippy::msrv = "1.42.0"]
+ }
+
+ // Should warn
+ let log2_10 = 3.321928094887362;
+
+ mod a {
+ #![clippy::msrv = "1.42.0"]
+
+ fn should_warn() {
+ #![clippy::msrv = "1.43.0"]
+ let log2_10 = 3.321928094887362;
+ }
+
+ fn should_not_warn() {
+ let log2_10 = 3.321928094887362;
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/min_rust_version_attr.stderr b/src/tools/clippy/tests/ui/min_rust_version_attr.stderr
index 68aa58748..7e2135584 100644
--- a/src/tools/clippy/tests/ui/min_rust_version_attr.stderr
+++ b/src/tools/clippy/tests/ui/min_rust_version_attr.stderr
@@ -23,5 +23,29 @@ LL | let log2_10 = 3.321928094887362;
|
= help: consider using the constant directly
-error: aborting due to 3 previous errors
+error: approximate value of `f{32, 64}::consts::LOG2_10` found
+ --> $DIR/min_rust_version_attr.rs:38:19
+ |
+LL | let log2_10 = 3.321928094887362;
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = help: consider using the constant directly
+
+error: approximate value of `f{32, 64}::consts::LOG2_10` found
+ --> $DIR/min_rust_version_attr.rs:48:19
+ |
+LL | let log2_10 = 3.321928094887362;
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = help: consider using the constant directly
+
+error: approximate value of `f{32, 64}::consts::LOG2_10` found
+ --> $DIR/min_rust_version_attr.rs:55:27
+ |
+LL | let log2_10 = 3.321928094887362;
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = help: consider using the constant directly
+
+error: aborting due to 6 previous errors
diff --git a/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.stderr b/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.stderr
index 93370a0fa..675b78031 100644
--- a/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.stderr
+++ b/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.stderr
@@ -4,7 +4,7 @@ error: `invalid.version` is not a valid Rust version
LL | #![clippy::msrv = "invalid.version"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: `msrv` cannot be an outer attribute
+error: `invalid.version` is not a valid Rust version
--> $DIR/min_rust_version_invalid_attr.rs:6:1
|
LL | #[clippy::msrv = "invalid.version"]
diff --git a/src/tools/clippy/tests/ui/misnamed_getters.rs b/src/tools/clippy/tests/ui/misnamed_getters.rs
new file mode 100644
index 000000000..03e7dac7d
--- /dev/null
+++ b/src/tools/clippy/tests/ui/misnamed_getters.rs
@@ -0,0 +1,124 @@
+#![allow(unused)]
+#![warn(clippy::misnamed_getters)]
+
+struct A {
+ a: u8,
+ b: u8,
+ c: u8,
+}
+
+impl A {
+ fn a(&self) -> &u8 {
+ &self.b
+ }
+ fn a_mut(&mut self) -> &mut u8 {
+ &mut self.b
+ }
+
+ fn b(self) -> u8 {
+ self.a
+ }
+
+ fn b_mut(&mut self) -> &mut u8 {
+ &mut self.a
+ }
+
+ fn c(&self) -> &u8 {
+ &self.b
+ }
+
+ fn c_mut(&mut self) -> &mut u8 {
+ &mut self.a
+ }
+}
+
+union B {
+ a: u8,
+ b: u8,
+}
+
+impl B {
+ unsafe fn a(&self) -> &u8 {
+ &self.b
+ }
+ unsafe fn a_mut(&mut self) -> &mut u8 {
+ &mut self.b
+ }
+
+ unsafe fn b(self) -> u8 {
+ self.a
+ }
+
+ unsafe fn b_mut(&mut self) -> &mut u8 {
+ &mut self.a
+ }
+
+ unsafe fn c(&self) -> &u8 {
+ &self.b
+ }
+
+ unsafe fn c_mut(&mut self) -> &mut u8 {
+ &mut self.a
+ }
+
+ unsafe fn a_unchecked(&self) -> &u8 {
+ &self.b
+ }
+ unsafe fn a_unchecked_mut(&mut self) -> &mut u8 {
+ &mut self.b
+ }
+
+ unsafe fn b_unchecked(self) -> u8 {
+ self.a
+ }
+
+ unsafe fn b_unchecked_mut(&mut self) -> &mut u8 {
+ &mut self.a
+ }
+
+ unsafe fn c_unchecked(&self) -> &u8 {
+ &self.b
+ }
+
+ unsafe fn c_unchecked_mut(&mut self) -> &mut u8 {
+ &mut self.a
+ }
+}
+
+struct D {
+ d: u8,
+ inner: A,
+}
+
+impl core::ops::Deref for D {
+ type Target = A;
+ fn deref(&self) -> &A {
+ &self.inner
+ }
+}
+
+impl core::ops::DerefMut for D {
+ fn deref_mut(&mut self) -> &mut A {
+ &mut self.inner
+ }
+}
+
+impl D {
+ fn a(&self) -> &u8 {
+ &self.b
+ }
+ fn a_mut(&mut self) -> &mut u8 {
+ &mut self.b
+ }
+
+ fn d(&self) -> &u8 {
+ &self.b
+ }
+ fn d_mut(&mut self) -> &mut u8 {
+ &mut self.b
+ }
+}
+
+fn main() {
+ // test code goes here
+}
diff --git a/src/tools/clippy/tests/ui/misnamed_getters.stderr b/src/tools/clippy/tests/ui/misnamed_getters.stderr
new file mode 100644
index 000000000..1e38a83d0
--- /dev/null
+++ b/src/tools/clippy/tests/ui/misnamed_getters.stderr
@@ -0,0 +1,166 @@
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:11:5
+ |
+LL | / fn a(&self) -> &u8 {
+LL | | &self.b
+ | | ------- help: consider using: `&self.a`
+LL | | }
+ | |_____^
+ |
+ = note: `-D clippy::misnamed-getters` implied by `-D warnings`
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:14:5
+ |
+LL | / fn a_mut(&mut self) -> &mut u8 {
+LL | | &mut self.b
+ | | ----------- help: consider using: `&mut self.a`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:18:5
+ |
+LL | / fn b(self) -> u8 {
+LL | | self.a
+ | | ------ help: consider using: `self.b`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:22:5
+ |
+LL | / fn b_mut(&mut self) -> &mut u8 {
+LL | | &mut self.a
+ | | ----------- help: consider using: `&mut self.b`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:26:5
+ |
+LL | / fn c(&self) -> &u8 {
+LL | | &self.b
+ | | ------- help: consider using: `&self.c`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:30:5
+ |
+LL | / fn c_mut(&mut self) -> &mut u8 {
+LL | | &mut self.a
+ | | ----------- help: consider using: `&mut self.c`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:41:5
+ |
+LL | / unsafe fn a(&self) -> &u8 {
+LL | | &self.b
+ | | ------- help: consider using: `&self.a`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:44:5
+ |
+LL | / unsafe fn a_mut(&mut self) -> &mut u8 {
+LL | | &mut self.b
+ | | ----------- help: consider using: `&mut self.a`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:48:5
+ |
+LL | / unsafe fn b(self) -> u8 {
+LL | | self.a
+ | | ------ help: consider using: `self.b`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:52:5
+ |
+LL | / unsafe fn b_mut(&mut self) -> &mut u8 {
+LL | | &mut self.a
+ | | ----------- help: consider using: `&mut self.b`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:64:5
+ |
+LL | / unsafe fn a_unchecked(&self) -> &u8 {
+LL | | &self.b
+ | | ------- help: consider using: `&self.a`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:67:5
+ |
+LL | / unsafe fn a_unchecked_mut(&mut self) -> &mut u8 {
+LL | | &mut self.b
+ | | ----------- help: consider using: `&mut self.a`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:71:5
+ |
+LL | / unsafe fn b_unchecked(self) -> u8 {
+LL | | self.a
+ | | ------ help: consider using: `self.b`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:75:5
+ |
+LL | / unsafe fn b_unchecked_mut(&mut self) -> &mut u8 {
+LL | | &mut self.a
+ | | ----------- help: consider using: `&mut self.b`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:107:5
+ |
+LL | / fn a(&self) -> &u8 {
+LL | | &self.b
+ | | ------- help: consider using: `&self.a`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:110:5
+ |
+LL | / fn a_mut(&mut self) -> &mut u8 {
+LL | | &mut self.b
+ | | ----------- help: consider using: `&mut self.a`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:114:5
+ |
+LL | / fn d(&self) -> &u8 {
+LL | | &self.b
+ | | ------- help: consider using: `&self.d`
+LL | | }
+ | |_____^
+
+error: getter function appears to return the wrong field
+ --> $DIR/misnamed_getters.rs:117:5
+ |
+LL | / fn d_mut(&mut self) -> &mut u8 {
+LL | | &mut self.b
+ | | ----------- help: consider using: `&mut self.d`
+LL | | }
+ | |_____^
+
+error: aborting due to 18 previous errors
+
diff --git a/src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs b/src/tools/clippy/tests/ui/missing_const_for_fn/cant_be_const.rs
index b950248ef..75cace181 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
@@ -7,7 +7,6 @@
#![warn(clippy::missing_const_for_fn)]
#![feature(start)]
-#![feature(custom_inner_attributes)]
extern crate helper;
extern crate proc_macro_with_span;
@@ -115,9 +114,8 @@ fn unstably_const_fn() {
helper::unstably_const_fn()
}
+#[clippy::msrv = "1.46.0"]
mod const_fn_stabilized_after_msrv {
- #![clippy::msrv = "1.46.0"]
-
// Do not lint this because `u8::is_ascii_digit` is stabilized as a const function in 1.47.0.
fn const_fn_stabilized_after_msrv(byte: u8) {
byte.is_ascii_digit();
diff --git a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs
index b85e88784..0246c8622 100644
--- a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs
+++ b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs
@@ -1,6 +1,5 @@
#![warn(clippy::missing_const_for_fn)]
#![allow(incomplete_features, clippy::let_and_return)]
-#![feature(custom_inner_attributes)]
use std::mem::transmute;
@@ -68,24 +67,21 @@ mod with_drop {
}
}
+#[clippy::msrv = "1.47.0"]
mod const_fn_stabilized_before_msrv {
- #![clippy::msrv = "1.47.0"]
-
// This could be const because `u8::is_ascii_digit` is a stable const function in 1.47.
fn const_fn_stabilized_before_msrv(byte: u8) {
byte.is_ascii_digit();
}
}
+#[clippy::msrv = "1.45"]
fn msrv_1_45() -> i32 {
- #![clippy::msrv = "1.45"]
-
45
}
+#[clippy::msrv = "1.46"]
fn msrv_1_46() -> i32 {
- #![clippy::msrv = "1.46"]
-
46
}
diff --git a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr
index f8e221c82..955e1ed26 100644
--- a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr
+++ b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr
@@ -1,5 +1,5 @@
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:13:5
+ --> $DIR/could_be_const.rs:12:5
|
LL | / pub fn new() -> Self {
LL | | Self { guess: 42 }
@@ -9,7 +9,7 @@ LL | | }
= note: `-D clippy::missing-const-for-fn` implied by `-D warnings`
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:17:5
+ --> $DIR/could_be_const.rs:16:5
|
LL | / fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] {
LL | | b
@@ -17,7 +17,7 @@ LL | | }
| |_____^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:23:1
+ --> $DIR/could_be_const.rs:22:1
|
LL | / fn one() -> i32 {
LL | | 1
@@ -25,7 +25,7 @@ LL | | }
| |_^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:28:1
+ --> $DIR/could_be_const.rs:27:1
|
LL | / fn two() -> i32 {
LL | | let abc = 2;
@@ -34,7 +34,7 @@ LL | | }
| |_^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:34:1
+ --> $DIR/could_be_const.rs:33:1
|
LL | / fn string() -> String {
LL | | String::new()
@@ -42,7 +42,7 @@ LL | | }
| |_^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:39:1
+ --> $DIR/could_be_const.rs:38:1
|
LL | / unsafe fn four() -> i32 {
LL | | 4
@@ -50,7 +50,7 @@ LL | | }
| |_^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:44:1
+ --> $DIR/could_be_const.rs:43:1
|
LL | / fn generic<T>(t: T) -> T {
LL | | t
@@ -58,7 +58,7 @@ LL | | }
| |_^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:52:1
+ --> $DIR/could_be_const.rs:51:1
|
LL | / fn generic_arr<T: Copy>(t: [T; 1]) -> T {
LL | | t[0]
@@ -66,7 +66,7 @@ LL | | }
| |_^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:65:9
+ --> $DIR/could_be_const.rs:64:9
|
LL | / pub fn b(self, a: &A) -> B {
LL | | B
@@ -74,7 +74,7 @@ LL | | }
| |_________^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:75:5
+ --> $DIR/could_be_const.rs:73:5
|
LL | / fn const_fn_stabilized_before_msrv(byte: u8) {
LL | | byte.is_ascii_digit();
@@ -82,11 +82,9 @@ LL | | }
| |_____^
error: this could be a `const fn`
- --> $DIR/could_be_const.rs:86:1
+ --> $DIR/could_be_const.rs:84:1
|
LL | / fn msrv_1_46() -> i32 {
-LL | | #![clippy::msrv = "1.46"]
-LL | |
LL | | 46
LL | | }
| |_^
diff --git a/src/tools/clippy/tests/ui/missing_panics_doc.stderr b/src/tools/clippy/tests/ui/missing_panics_doc.stderr
index c9ded7f1a..183c262ce 100644
--- a/src/tools/clippy/tests/ui/missing_panics_doc.stderr
+++ b/src/tools/clippy/tests/ui/missing_panics_doc.stderr
@@ -1,11 +1,8 @@
error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:6:1
|
-LL | / pub fn unwrap() {
-LL | | let result = Err("Hi");
-LL | | result.unwrap()
-LL | | }
- | |_^
+LL | pub fn unwrap() {
+ | ^^^^^^^^^^^^^^^
|
note: first possible panic found here
--> $DIR/missing_panics_doc.rs:8:5
@@ -17,10 +14,8 @@ LL | result.unwrap()
error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:12:1
|
-LL | / pub fn panic() {
-LL | | panic!("This function panics")
-LL | | }
- | |_^
+LL | pub fn panic() {
+ | ^^^^^^^^^^^^^^
|
note: first possible panic found here
--> $DIR/missing_panics_doc.rs:13:5
@@ -31,10 +26,8 @@ LL | panic!("This function panics")
error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:17:1
|
-LL | / pub fn todo() {
-LL | | todo!()
-LL | | }
- | |_^
+LL | pub fn todo() {
+ | ^^^^^^^^^^^^^
|
note: first possible panic found here
--> $DIR/missing_panics_doc.rs:18:5
@@ -45,14 +38,8 @@ LL | todo!()
error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:22:1
|
-LL | / pub fn inner_body(opt: Option<u32>) {
-LL | | opt.map(|x| {
-LL | | if x == 10 {
-LL | | panic!()
-LL | | }
-LL | | });
-LL | | }
- | |_^
+LL | pub fn inner_body(opt: Option<u32>) {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: first possible panic found here
--> $DIR/missing_panics_doc.rs:25:13
@@ -63,10 +50,8 @@ LL | panic!()
error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:31:1
|
-LL | / pub fn unreachable_and_panic() {
-LL | | if true { unreachable!() } else { panic!() }
-LL | | }
- | |_^
+LL | pub fn unreachable_and_panic() {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: first possible panic found here
--> $DIR/missing_panics_doc.rs:32:39
@@ -77,11 +62,8 @@ LL | if true { unreachable!() } else { panic!() }
error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:36:1
|
-LL | / pub fn assert_eq() {
-LL | | let x = 0;
-LL | | assert_eq!(x, 0);
-LL | | }
- | |_^
+LL | pub fn assert_eq() {
+ | ^^^^^^^^^^^^^^^^^^
|
note: first possible panic found here
--> $DIR/missing_panics_doc.rs:38:5
@@ -92,11 +74,8 @@ LL | assert_eq!(x, 0);
error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:42:1
|
-LL | / pub fn assert_ne() {
-LL | | let x = 0;
-LL | | assert_ne!(x, 0);
-LL | | }
- | |_^
+LL | pub fn assert_ne() {
+ | ^^^^^^^^^^^^^^^^^^
|
note: first possible panic found here
--> $DIR/missing_panics_doc.rs:44:5
diff --git a/src/tools/clippy/tests/ui/mut_from_ref.rs b/src/tools/clippy/tests/ui/mut_from_ref.rs
index 370dbd588..7de153305 100644
--- a/src/tools/clippy/tests/ui/mut_from_ref.rs
+++ b/src/tools/clippy/tests/ui/mut_from_ref.rs
@@ -1,4 +1,4 @@
-#![allow(unused)]
+#![allow(unused, clippy::needless_lifetimes)]
#![warn(clippy::mut_from_ref)]
struct Foo;
diff --git a/src/tools/clippy/tests/ui/mut_mut.rs b/src/tools/clippy/tests/ui/mut_mut.rs
index ac8fd9d8f..ee3a85656 100644
--- a/src/tools/clippy/tests/ui/mut_mut.rs
+++ b/src/tools/clippy/tests/ui/mut_mut.rs
@@ -57,3 +57,20 @@ fn issue6922() {
// do not lint from an external macro
mut_mut!();
}
+
+mod issue9035 {
+ use std::fmt::Display;
+
+ struct Foo<'a> {
+ inner: &'a mut dyn Display,
+ }
+
+ impl Foo<'_> {
+ fn foo(&mut self) {
+ let hlp = &mut self.inner;
+ bar(hlp);
+ }
+ }
+
+ fn bar(_: &mut impl Display) {}
+}
diff --git a/src/tools/clippy/tests/ui/mut_range_bound.rs b/src/tools/clippy/tests/ui/mut_range_bound.rs
index e1ae1ef92..7fdeb27ed 100644
--- a/src/tools/clippy/tests/ui/mut_range_bound.rs
+++ b/src/tools/clippy/tests/ui/mut_range_bound.rs
@@ -76,7 +76,7 @@ fn mut_range_bound_no_immediate_break() {
let mut n = 3;
for i in n..10 {
if n == 4 {
- n = 1; // FIXME: warning because is is not immediately followed by break
+ n = 1; // FIXME: warning because it is not immediately followed by break
let _ = 2;
break;
}
diff --git a/src/tools/clippy/tests/ui/mut_range_bound.stderr b/src/tools/clippy/tests/ui/mut_range_bound.stderr
index e0c8dced3..b679b7a0a 100644
--- a/src/tools/clippy/tests/ui/mut_range_bound.stderr
+++ b/src/tools/clippy/tests/ui/mut_range_bound.stderr
@@ -50,7 +50,7 @@ LL | m = 2; // warning because it is not immediately followed by break
error: attempt to mutate range bound within loop
--> $DIR/mut_range_bound.rs:79:13
|
-LL | n = 1; // FIXME: warning because is is not immediately followed by break
+LL | n = 1; // FIXME: warning because it is not immediately followed by break
| ^
|
= note: the range of the loop is unchanged
diff --git a/src/tools/clippy/tests/ui/needless_borrow.fixed b/src/tools/clippy/tests/ui/needless_borrow.fixed
index 340e89d2d..4cb7f6b68 100644
--- a/src/tools/clippy/tests/ui/needless_borrow.fixed
+++ b/src/tools/clippy/tests/ui/needless_borrow.fixed
@@ -1,13 +1,13 @@
// run-rustfix
-#![feature(custom_inner_attributes, lint_reasons)]
-
-#[warn(clippy::all, clippy::needless_borrow)]
-#[allow(unused_variables)]
-#[allow(
+#![feature(lint_reasons)]
+#![allow(
+ unused,
clippy::uninlined_format_args,
clippy::unnecessary_mut_passed,
clippy::unnecessary_to_owned
)]
+#![warn(clippy::needless_borrow)]
+
fn main() {
let a = 5;
let ref_a = &a;
@@ -171,14 +171,12 @@ impl<'a> Trait for &'a str {}
fn h(_: &dyn Trait) {}
-#[allow(dead_code)]
fn check_expect_suppression() {
let a = 5;
#[expect(clippy::needless_borrow)]
let _ = x(&&a);
}
-#[allow(dead_code)]
mod issue9160 {
pub struct S<F> {
f: F,
@@ -267,7 +265,6 @@ where
}
// https://github.com/rust-lang/rust-clippy/pull/9136#pullrequestreview-1037379321
-#[allow(dead_code)]
mod copyable_iterator {
#[derive(Clone, Copy)]
struct Iter;
@@ -287,25 +284,20 @@ mod copyable_iterator {
}
}
+#[clippy::msrv = "1.52.0"]
mod under_msrv {
- #![allow(dead_code)]
- #![clippy::msrv = "1.52.0"]
-
fn foo() {
let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
}
}
+#[clippy::msrv = "1.53.0"]
mod meets_msrv {
- #![allow(dead_code)]
- #![clippy::msrv = "1.53.0"]
-
fn foo() {
let _ = std::process::Command::new("ls").args(["-a", "-l"]).status().unwrap();
}
}
-#[allow(unused)]
fn issue9383() {
// Should not lint because unions need explicit deref when accessing field
use std::mem::ManuallyDrop;
@@ -334,7 +326,6 @@ fn issue9383() {
}
}
-#[allow(dead_code)]
fn closure_test() {
let env = "env".to_owned();
let arg = "arg".to_owned();
@@ -348,7 +339,6 @@ fn closure_test() {
f(arg);
}
-#[allow(dead_code)]
mod significant_drop {
#[derive(Debug)]
struct X;
@@ -368,7 +358,6 @@ mod significant_drop {
fn debug(_: impl std::fmt::Debug) {}
}
-#[allow(dead_code)]
mod used_exactly_once {
fn foo(x: String) {
use_x(x);
@@ -376,7 +365,6 @@ mod used_exactly_once {
fn use_x(_: impl AsRef<str>) {}
}
-#[allow(dead_code)]
mod used_more_than_once {
fn foo(x: String) {
use_x(&x);
@@ -385,3 +373,121 @@ mod used_more_than_once {
fn use_x(_: impl AsRef<str>) {}
fn use_x_again(_: impl AsRef<str>) {}
}
+
+// https://github.com/rust-lang/rust-clippy/issues/9111#issuecomment-1277114280
+mod issue_9111 {
+ struct A;
+
+ impl Extend<u8> for A {
+ fn extend<T: IntoIterator<Item = u8>>(&mut self, _: T) {
+ unimplemented!()
+ }
+ }
+
+ impl<'a> Extend<&'a u8> for A {
+ fn extend<T: IntoIterator<Item = &'a u8>>(&mut self, _: T) {
+ unimplemented!()
+ }
+ }
+
+ fn main() {
+ let mut a = A;
+ a.extend(&[]); // vs a.extend([]);
+ }
+}
+
+mod issue_9710 {
+ fn main() {
+ let string = String::new();
+ for _i in 0..10 {
+ f(&string);
+ }
+ }
+
+ fn f<T: AsRef<str>>(_: T) {}
+}
+
+mod issue_9739 {
+ fn foo<D: std::fmt::Display>(_it: impl IntoIterator<Item = D>) {}
+
+ fn main() {
+ foo(if std::env::var_os("HI").is_some() {
+ &[0]
+ } else {
+ &[] as &[u32]
+ });
+ }
+}
+
+mod issue_9739_method_variant {
+ struct S;
+
+ impl S {
+ fn foo<D: std::fmt::Display>(&self, _it: impl IntoIterator<Item = D>) {}
+ }
+
+ fn main() {
+ S.foo(if std::env::var_os("HI").is_some() {
+ &[0]
+ } else {
+ &[] as &[u32]
+ });
+ }
+}
+
+mod issue_9782 {
+ fn foo<T: AsRef<[u8]>>(t: T) {
+ println!("{}", std::mem::size_of::<T>());
+ let _t: &[u8] = t.as_ref();
+ }
+
+ fn main() {
+ let a: [u8; 100] = [0u8; 100];
+
+ // 100
+ foo::<[u8; 100]>(a);
+ foo(a);
+
+ // 16
+ foo::<&[u8]>(&a);
+ foo(a.as_slice());
+
+ // 8
+ foo::<&[u8; 100]>(&a);
+ foo(a);
+ }
+}
+
+mod issue_9782_type_relative_variant {
+ struct S;
+
+ impl S {
+ fn foo<T: AsRef<[u8]>>(t: T) {
+ println!("{}", std::mem::size_of::<T>());
+ let _t: &[u8] = t.as_ref();
+ }
+ }
+
+ fn main() {
+ let a: [u8; 100] = [0u8; 100];
+
+ S::foo::<&[u8; 100]>(&a);
+ }
+}
+
+mod issue_9782_method_variant {
+ struct S;
+
+ impl S {
+ fn foo<T: AsRef<[u8]>>(&self, t: T) {
+ println!("{}", std::mem::size_of::<T>());
+ let _t: &[u8] = t.as_ref();
+ }
+ }
+
+ fn main() {
+ let a: [u8; 100] = [0u8; 100];
+
+ S.foo::<&[u8; 100]>(&a);
+ }
+}
diff --git a/src/tools/clippy/tests/ui/needless_borrow.rs b/src/tools/clippy/tests/ui/needless_borrow.rs
index c93711ac8..9a01190ed 100644
--- a/src/tools/clippy/tests/ui/needless_borrow.rs
+++ b/src/tools/clippy/tests/ui/needless_borrow.rs
@@ -1,13 +1,13 @@
// run-rustfix
-#![feature(custom_inner_attributes, lint_reasons)]
-
-#[warn(clippy::all, clippy::needless_borrow)]
-#[allow(unused_variables)]
-#[allow(
+#![feature(lint_reasons)]
+#![allow(
+ unused,
clippy::uninlined_format_args,
clippy::unnecessary_mut_passed,
clippy::unnecessary_to_owned
)]
+#![warn(clippy::needless_borrow)]
+
fn main() {
let a = 5;
let ref_a = &a;
@@ -171,14 +171,12 @@ impl<'a> Trait for &'a str {}
fn h(_: &dyn Trait) {}
-#[allow(dead_code)]
fn check_expect_suppression() {
let a = 5;
#[expect(clippy::needless_borrow)]
let _ = x(&&a);
}
-#[allow(dead_code)]
mod issue9160 {
pub struct S<F> {
f: F,
@@ -267,7 +265,6 @@ where
}
// https://github.com/rust-lang/rust-clippy/pull/9136#pullrequestreview-1037379321
-#[allow(dead_code)]
mod copyable_iterator {
#[derive(Clone, Copy)]
struct Iter;
@@ -287,25 +284,20 @@ mod copyable_iterator {
}
}
+#[clippy::msrv = "1.52.0"]
mod under_msrv {
- #![allow(dead_code)]
- #![clippy::msrv = "1.52.0"]
-
fn foo() {
let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
}
}
+#[clippy::msrv = "1.53.0"]
mod meets_msrv {
- #![allow(dead_code)]
- #![clippy::msrv = "1.53.0"]
-
fn foo() {
let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
}
}
-#[allow(unused)]
fn issue9383() {
// Should not lint because unions need explicit deref when accessing field
use std::mem::ManuallyDrop;
@@ -334,7 +326,6 @@ fn issue9383() {
}
}
-#[allow(dead_code)]
fn closure_test() {
let env = "env".to_owned();
let arg = "arg".to_owned();
@@ -348,7 +339,6 @@ fn closure_test() {
f(arg);
}
-#[allow(dead_code)]
mod significant_drop {
#[derive(Debug)]
struct X;
@@ -368,7 +358,6 @@ mod significant_drop {
fn debug(_: impl std::fmt::Debug) {}
}
-#[allow(dead_code)]
mod used_exactly_once {
fn foo(x: String) {
use_x(&x);
@@ -376,7 +365,6 @@ mod used_exactly_once {
fn use_x(_: impl AsRef<str>) {}
}
-#[allow(dead_code)]
mod used_more_than_once {
fn foo(x: String) {
use_x(&x);
@@ -385,3 +373,121 @@ mod used_more_than_once {
fn use_x(_: impl AsRef<str>) {}
fn use_x_again(_: impl AsRef<str>) {}
}
+
+// https://github.com/rust-lang/rust-clippy/issues/9111#issuecomment-1277114280
+mod issue_9111 {
+ struct A;
+
+ impl Extend<u8> for A {
+ fn extend<T: IntoIterator<Item = u8>>(&mut self, _: T) {
+ unimplemented!()
+ }
+ }
+
+ impl<'a> Extend<&'a u8> for A {
+ fn extend<T: IntoIterator<Item = &'a u8>>(&mut self, _: T) {
+ unimplemented!()
+ }
+ }
+
+ fn main() {
+ let mut a = A;
+ a.extend(&[]); // vs a.extend([]);
+ }
+}
+
+mod issue_9710 {
+ fn main() {
+ let string = String::new();
+ for _i in 0..10 {
+ f(&string);
+ }
+ }
+
+ fn f<T: AsRef<str>>(_: T) {}
+}
+
+mod issue_9739 {
+ fn foo<D: std::fmt::Display>(_it: impl IntoIterator<Item = D>) {}
+
+ fn main() {
+ foo(if std::env::var_os("HI").is_some() {
+ &[0]
+ } else {
+ &[] as &[u32]
+ });
+ }
+}
+
+mod issue_9739_method_variant {
+ struct S;
+
+ impl S {
+ fn foo<D: std::fmt::Display>(&self, _it: impl IntoIterator<Item = D>) {}
+ }
+
+ fn main() {
+ S.foo(if std::env::var_os("HI").is_some() {
+ &[0]
+ } else {
+ &[] as &[u32]
+ });
+ }
+}
+
+mod issue_9782 {
+ fn foo<T: AsRef<[u8]>>(t: T) {
+ println!("{}", std::mem::size_of::<T>());
+ let _t: &[u8] = t.as_ref();
+ }
+
+ fn main() {
+ let a: [u8; 100] = [0u8; 100];
+
+ // 100
+ foo::<[u8; 100]>(a);
+ foo(a);
+
+ // 16
+ foo::<&[u8]>(&a);
+ foo(a.as_slice());
+
+ // 8
+ foo::<&[u8; 100]>(&a);
+ foo(&a);
+ }
+}
+
+mod issue_9782_type_relative_variant {
+ struct S;
+
+ impl S {
+ fn foo<T: AsRef<[u8]>>(t: T) {
+ println!("{}", std::mem::size_of::<T>());
+ let _t: &[u8] = t.as_ref();
+ }
+ }
+
+ fn main() {
+ let a: [u8; 100] = [0u8; 100];
+
+ S::foo::<&[u8; 100]>(&a);
+ }
+}
+
+mod issue_9782_method_variant {
+ struct S;
+
+ impl S {
+ fn foo<T: AsRef<[u8]>>(&self, t: T) {
+ println!("{}", std::mem::size_of::<T>());
+ let _t: &[u8] = t.as_ref();
+ }
+ }
+
+ fn main() {
+ let a: [u8; 100] = [0u8; 100];
+
+ S.foo::<&[u8; 100]>(&a);
+ }
+}
diff --git a/src/tools/clippy/tests/ui/needless_borrow.stderr b/src/tools/clippy/tests/ui/needless_borrow.stderr
index 8b593268b..d26c31712 100644
--- a/src/tools/clippy/tests/ui/needless_borrow.stderr
+++ b/src/tools/clippy/tests/ui/needless_borrow.stderr
@@ -163,52 +163,58 @@ LL | let _ = std::fs::write("x", &"".to_string());
| ^^^^^^^^^^^^^^^ help: change this to: `"".to_string()`
error: this expression borrows a value the compiler would automatically borrow
- --> $DIR/needless_borrow.rs:192:13
+ --> $DIR/needless_borrow.rs:190:13
|
LL | (&self.f)()
| ^^^^^^^^^ help: change this to: `(self.f)`
error: this expression borrows a value the compiler would automatically borrow
- --> $DIR/needless_borrow.rs:201:13
+ --> $DIR/needless_borrow.rs:199:13
|
LL | (&mut self.f)()
| ^^^^^^^^^^^^^ help: change this to: `(self.f)`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:286:20
+ --> $DIR/needless_borrow.rs:283:20
|
LL | takes_iter(&mut x)
| ^^^^^^ help: change this to: `x`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:304:55
+ --> $DIR/needless_borrow.rs:297:55
|
LL | let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
| ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:344:37
+ --> $DIR/needless_borrow.rs:335:37
|
LL | let _ = std::fs::write("x", &arg);
| ^^^^ help: change this to: `arg`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:345:37
+ --> $DIR/needless_borrow.rs:336:37
|
LL | let _ = std::fs::write("x", &loc);
| ^^^^ help: change this to: `loc`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:364:15
+ --> $DIR/needless_borrow.rs:354:15
|
LL | debug(&x);
| ^^ help: change this to: `x`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:374:15
+ --> $DIR/needless_borrow.rs:363:15
|
LL | use_x(&x);
| ^^ help: change this to: `x`
-error: aborting due to 35 previous errors
+error: the borrowed expression implements the required traits
+ --> $DIR/needless_borrow.rs:457:13
+ |
+LL | foo(&a);
+ | ^^ help: change this to: `a`
+
+error: aborting due to 36 previous errors
diff --git a/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed b/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed
index bcb4eb2dd..0c47ceb7b 100644
--- a/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed
+++ b/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed
@@ -1,11 +1,32 @@
// run-rustfix
#![warn(clippy::needless_borrowed_reference)]
-#![allow(unused, clippy::needless_borrow)]
+#![allow(
+ unused,
+ irrefutable_let_patterns,
+ non_shorthand_field_patterns,
+ clippy::needless_borrow
+)]
fn main() {}
-fn should_lint(array: [u8; 4], slice: &[u8], slice_of_refs: &[&u8], vec: Vec<u8>) {
+struct Struct {
+ a: usize,
+ b: usize,
+ c: usize,
+}
+
+struct TupleStruct(u8, u8, u8);
+
+fn should_lint(
+ array: [u8; 4],
+ slice: &[u8],
+ slice_of_refs: &[&u8],
+ vec: Vec<u8>,
+ tuple: (u8, u8, u8),
+ tuple_struct: TupleStruct,
+ s: Struct,
+) {
let mut v = Vec::<String>::new();
let _ = v.iter_mut().filter(|a| a.is_empty());
@@ -24,16 +45,54 @@ fn should_lint(array: [u8; 4], slice: &[u8], slice_of_refs: &[&u8], vec: Vec<u8>
if let [a, b, ..] = slice {}
if let [a, .., b] = slice {}
if let [.., a, b] = slice {}
+
+ if let [a, _] = slice {}
+
+ if let (a, b, c) = &tuple {}
+ if let (a, _, c) = &tuple {}
+ if let (a, ..) = &tuple {}
+
+ if let TupleStruct(a, ..) = &tuple_struct {}
+
+ if let Struct {
+ a,
+ b: b,
+ c: renamed,
+ } = &s
+ {}
+
+ if let Struct { a, b: _, .. } = &s {}
}
-fn should_not_lint(array: [u8; 4], slice: &[u8], slice_of_refs: &[&u8], vec: Vec<u8>) {
+fn should_not_lint(
+ array: [u8; 4],
+ slice: &[u8],
+ slice_of_refs: &[&u8],
+ vec: Vec<u8>,
+ tuple: (u8, u8, u8),
+ tuple_struct: TupleStruct,
+ s: Struct,
+) {
if let [ref a] = slice {}
if let &[ref a, b] = slice {}
if let &[ref a, .., b] = slice {}
+ if let &(ref a, b, ..) = &tuple {}
+ if let &TupleStruct(ref a, b, ..) = &tuple_struct {}
+ if let &Struct { ref a, b, .. } = &s {}
+
// must not be removed as variables must be bound consistently across | patterns
if let (&[ref a], _) | ([], ref a) = (slice_of_refs, &1u8) {}
+ // the `&`s here technically could be removed, but it'd be noisy and without a `ref` doesn't match
+ // the lint name
+ if let &[] = slice {}
+ if let &[_] = slice {}
+ if let &[..] = slice {}
+ if let &(..) = &tuple {}
+ if let &TupleStruct(..) = &tuple_struct {}
+ if let &Struct { .. } = &s {}
+
let mut var2 = 5;
let thingy2 = Some(&mut var2);
if let Some(&mut ref mut v) = thingy2 {
@@ -59,6 +118,6 @@ fn foo(a: &Animal, b: &Animal) {
// lifetime mismatch error if there is no '&ref' before `feature(nll)` stabilization in 1.63
(&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (),
// ^ and ^ should **not** be linted
- (&Animal::Dog(ref a), &Animal::Dog(_)) => (), // ^ should **not** be linted
+ (Animal::Dog(a), &Animal::Dog(_)) => (),
}
}
diff --git a/src/tools/clippy/tests/ui/needless_borrowed_ref.rs b/src/tools/clippy/tests/ui/needless_borrowed_ref.rs
index f6de1a6d8..f883bb0c8 100644
--- a/src/tools/clippy/tests/ui/needless_borrowed_ref.rs
+++ b/src/tools/clippy/tests/ui/needless_borrowed_ref.rs
@@ -1,11 +1,32 @@
// run-rustfix
#![warn(clippy::needless_borrowed_reference)]
-#![allow(unused, clippy::needless_borrow)]
+#![allow(
+ unused,
+ irrefutable_let_patterns,
+ non_shorthand_field_patterns,
+ clippy::needless_borrow
+)]
fn main() {}
-fn should_lint(array: [u8; 4], slice: &[u8], slice_of_refs: &[&u8], vec: Vec<u8>) {
+struct Struct {
+ a: usize,
+ b: usize,
+ c: usize,
+}
+
+struct TupleStruct(u8, u8, u8);
+
+fn should_lint(
+ array: [u8; 4],
+ slice: &[u8],
+ slice_of_refs: &[&u8],
+ vec: Vec<u8>,
+ tuple: (u8, u8, u8),
+ tuple_struct: TupleStruct,
+ s: Struct,
+) {
let mut v = Vec::<String>::new();
let _ = v.iter_mut().filter(|&ref a| a.is_empty());
@@ -24,16 +45,54 @@ fn should_lint(array: [u8; 4], slice: &[u8], slice_of_refs: &[&u8], vec: Vec<u8>
if let &[ref a, ref b, ..] = slice {}
if let &[ref a, .., ref b] = slice {}
if let &[.., ref a, ref b] = slice {}
+
+ if let &[ref a, _] = slice {}
+
+ if let &(ref a, ref b, ref c) = &tuple {}
+ if let &(ref a, _, ref c) = &tuple {}
+ if let &(ref a, ..) = &tuple {}
+
+ if let &TupleStruct(ref a, ..) = &tuple_struct {}
+
+ if let &Struct {
+ ref a,
+ b: ref b,
+ c: ref renamed,
+ } = &s
+ {}
+
+ if let &Struct { ref a, b: _, .. } = &s {}
}
-fn should_not_lint(array: [u8; 4], slice: &[u8], slice_of_refs: &[&u8], vec: Vec<u8>) {
+fn should_not_lint(
+ array: [u8; 4],
+ slice: &[u8],
+ slice_of_refs: &[&u8],
+ vec: Vec<u8>,
+ tuple: (u8, u8, u8),
+ tuple_struct: TupleStruct,
+ s: Struct,
+) {
if let [ref a] = slice {}
if let &[ref a, b] = slice {}
if let &[ref a, .., b] = slice {}
+ if let &(ref a, b, ..) = &tuple {}
+ if let &TupleStruct(ref a, b, ..) = &tuple_struct {}
+ if let &Struct { ref a, b, .. } = &s {}
+
// must not be removed as variables must be bound consistently across | patterns
if let (&[ref a], _) | ([], ref a) = (slice_of_refs, &1u8) {}
+ // the `&`s here technically could be removed, but it'd be noisy and without a `ref` doesn't match
+ // the lint name
+ if let &[] = slice {}
+ if let &[_] = slice {}
+ if let &[..] = slice {}
+ if let &(..) = &tuple {}
+ if let &TupleStruct(..) = &tuple_struct {}
+ if let &Struct { .. } = &s {}
+
let mut var2 = 5;
let thingy2 = Some(&mut var2);
if let Some(&mut ref mut v) = thingy2 {
@@ -59,6 +118,6 @@ fn foo(a: &Animal, b: &Animal) {
// lifetime mismatch error if there is no '&ref' before `feature(nll)` stabilization in 1.63
(&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (),
// ^ and ^ should **not** be linted
- (&Animal::Dog(ref a), &Animal::Dog(_)) => (), // ^ should **not** be linted
+ (Animal::Dog(a), &Animal::Dog(_)) => (),
}
}
diff --git a/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr b/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr
index 7453542e6..8d0f0c258 100644
--- a/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr
+++ b/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr
@@ -1,5 +1,5 @@
error: this pattern takes a reference on something that is being dereferenced
- --> $DIR/needless_borrowed_ref.rs:10:34
+ --> $DIR/needless_borrowed_ref.rs:31:34
|
LL | let _ = v.iter_mut().filter(|&ref a| a.is_empty());
| ^^^^^^
@@ -12,7 +12,7 @@ LL + let _ = v.iter_mut().filter(|a| a.is_empty());
|
error: this pattern takes a reference on something that is being dereferenced
- --> $DIR/needless_borrowed_ref.rs:14:17
+ --> $DIR/needless_borrowed_ref.rs:35:17
|
LL | if let Some(&ref v) = thingy {}
| ^^^^^^
@@ -24,7 +24,7 @@ LL + if let Some(v) = thingy {}
|
error: this pattern takes a reference on something that is being dereferenced
- --> $DIR/needless_borrowed_ref.rs:16:14
+ --> $DIR/needless_borrowed_ref.rs:37:14
|
LL | if let &[&ref a, ref b] = slice_of_refs {}
| ^^^^^^
@@ -36,7 +36,7 @@ LL + if let &[a, ref b] = slice_of_refs {}
|
error: dereferencing a slice pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:18:9
+ --> $DIR/needless_borrowed_ref.rs:39:9
|
LL | let &[ref a, ..] = &array;
| ^^^^^^^^^^^^
@@ -48,7 +48,7 @@ LL + let [a, ..] = &array;
|
error: dereferencing a slice pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:19:9
+ --> $DIR/needless_borrowed_ref.rs:40:9
|
LL | let &[ref a, ref b, ..] = &array;
| ^^^^^^^^^^^^^^^^^^^
@@ -60,7 +60,7 @@ LL + let [a, b, ..] = &array;
|
error: dereferencing a slice pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:21:12
+ --> $DIR/needless_borrowed_ref.rs:42:12
|
LL | if let &[ref a, ref b] = slice {}
| ^^^^^^^^^^^^^^^
@@ -72,7 +72,7 @@ LL + if let [a, b] = slice {}
|
error: dereferencing a slice pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:22:12
+ --> $DIR/needless_borrowed_ref.rs:43:12
|
LL | if let &[ref a, ref b] = &vec[..] {}
| ^^^^^^^^^^^^^^^
@@ -84,7 +84,7 @@ LL + if let [a, b] = &vec[..] {}
|
error: dereferencing a slice pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:24:12
+ --> $DIR/needless_borrowed_ref.rs:45:12
|
LL | if let &[ref a, ref b, ..] = slice {}
| ^^^^^^^^^^^^^^^^^^^
@@ -96,7 +96,7 @@ LL + if let [a, b, ..] = slice {}
|
error: dereferencing a slice pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:25:12
+ --> $DIR/needless_borrowed_ref.rs:46:12
|
LL | if let &[ref a, .., ref b] = slice {}
| ^^^^^^^^^^^^^^^^^^^
@@ -108,7 +108,7 @@ LL + if let [a, .., b] = slice {}
|
error: dereferencing a slice pattern where every element takes a reference
- --> $DIR/needless_borrowed_ref.rs:26:12
+ --> $DIR/needless_borrowed_ref.rs:47:12
|
LL | if let &[.., ref a, ref b] = slice {}
| ^^^^^^^^^^^^^^^^^^^
@@ -119,5 +119,96 @@ LL - if let &[.., ref a, ref b] = slice {}
LL + if let [.., a, b] = slice {}
|
-error: aborting due to 10 previous errors
+error: dereferencing a slice pattern where every element takes a reference
+ --> $DIR/needless_borrowed_ref.rs:49:12
+ |
+LL | if let &[ref a, _] = slice {}
+ | ^^^^^^^^^^^
+ |
+help: try removing the `&` and `ref` parts
+ |
+LL - if let &[ref a, _] = slice {}
+LL + if let [a, _] = slice {}
+ |
+
+error: dereferencing a tuple pattern where every element takes a reference
+ --> $DIR/needless_borrowed_ref.rs:51:12
+ |
+LL | if let &(ref a, ref b, ref c) = &tuple {}
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: try removing the `&` and `ref` parts
+ |
+LL - if let &(ref a, ref b, ref c) = &tuple {}
+LL + if let (a, b, c) = &tuple {}
+ |
+
+error: dereferencing a tuple pattern where every element takes a reference
+ --> $DIR/needless_borrowed_ref.rs:52:12
+ |
+LL | if let &(ref a, _, ref c) = &tuple {}
+ | ^^^^^^^^^^^^^^^^^^
+ |
+help: try removing the `&` and `ref` parts
+ |
+LL - if let &(ref a, _, ref c) = &tuple {}
+LL + if let (a, _, c) = &tuple {}
+ |
+
+error: dereferencing a tuple pattern where every element takes a reference
+ --> $DIR/needless_borrowed_ref.rs:53:12
+ |
+LL | if let &(ref a, ..) = &tuple {}
+ | ^^^^^^^^^^^^
+ |
+help: try removing the `&` and `ref` parts
+ |
+LL - if let &(ref a, ..) = &tuple {}
+LL + if let (a, ..) = &tuple {}
+ |
+
+error: dereferencing a tuple pattern where every element takes a reference
+ --> $DIR/needless_borrowed_ref.rs:55:12
+ |
+LL | if let &TupleStruct(ref a, ..) = &tuple_struct {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: try removing the `&` and `ref` parts
+ |
+LL - if let &TupleStruct(ref a, ..) = &tuple_struct {}
+LL + if let TupleStruct(a, ..) = &tuple_struct {}
+ |
+
+error: dereferencing a struct pattern where every field's pattern takes a reference
+ --> $DIR/needless_borrowed_ref.rs:57:12
+ |
+LL | if let &Struct {
+ | ____________^
+LL | | ref a,
+LL | | b: ref b,
+LL | | c: ref renamed,
+LL | | } = &s
+ | |_____^
+ |
+help: try removing the `&` and `ref` parts
+ |
+LL ~ if let Struct {
+LL ~ a,
+LL ~ b: b,
+LL ~ c: renamed,
+ |
+
+error: dereferencing a struct pattern where every field's pattern takes a reference
+ --> $DIR/needless_borrowed_ref.rs:64:12
+ |
+LL | if let &Struct { ref a, b: _, .. } = &s {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: try removing the `&` and `ref` parts
+ |
+LL - if let &Struct { ref a, b: _, .. } = &s {}
+LL + if let Struct { a, b: _, .. } = &s {}
+ |
+
+error: aborting due to 17 previous errors
diff --git a/src/tools/clippy/tests/ui/needless_collect.fixed b/src/tools/clippy/tests/ui/needless_collect.fixed
index 6ecbbcb62..2659ad384 100644
--- a/src/tools/clippy/tests/ui/needless_collect.fixed
+++ b/src/tools/clippy/tests/ui/needless_collect.fixed
@@ -33,4 +33,33 @@ fn main() {
// `BinaryHeap` doesn't have `contains` method
sample.iter().count();
sample.iter().next().is_none();
+
+ // Don't lint string from str
+ let _ = ["", ""].into_iter().collect::<String>().is_empty();
+
+ let _ = sample.iter().next().is_none();
+ let _ = sample.iter().any(|x| x == &0);
+
+ struct VecWrapper<T>(Vec<T>);
+ impl<T> core::ops::Deref for VecWrapper<T> {
+ type Target = Vec<T>;
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+ }
+ impl<T> IntoIterator for VecWrapper<T> {
+ type IntoIter = <Vec<T> as IntoIterator>::IntoIter;
+ type Item = <Vec<T> as IntoIterator>::Item;
+ fn into_iter(self) -> Self::IntoIter {
+ self.0.into_iter()
+ }
+ }
+ impl<T> FromIterator<T> for VecWrapper<T> {
+ fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
+ Self(Vec::from_iter(iter))
+ }
+ }
+
+ let _ = sample.iter().next().is_none();
+ let _ = sample.iter().any(|x| x == &0);
}
diff --git a/src/tools/clippy/tests/ui/needless_collect.rs b/src/tools/clippy/tests/ui/needless_collect.rs
index 8dc69bcf5..535ec8298 100644
--- a/src/tools/clippy/tests/ui/needless_collect.rs
+++ b/src/tools/clippy/tests/ui/needless_collect.rs
@@ -33,4 +33,33 @@ fn main() {
// `BinaryHeap` doesn't have `contains` method
sample.iter().collect::<BinaryHeap<_>>().len();
sample.iter().collect::<BinaryHeap<_>>().is_empty();
+
+ // Don't lint string from str
+ let _ = ["", ""].into_iter().collect::<String>().is_empty();
+
+ let _ = sample.iter().collect::<HashSet<_>>().is_empty();
+ let _ = sample.iter().collect::<HashSet<_>>().contains(&&0);
+
+ struct VecWrapper<T>(Vec<T>);
+ impl<T> core::ops::Deref for VecWrapper<T> {
+ type Target = Vec<T>;
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+ }
+ impl<T> IntoIterator for VecWrapper<T> {
+ type IntoIter = <Vec<T> as IntoIterator>::IntoIter;
+ type Item = <Vec<T> as IntoIterator>::Item;
+ fn into_iter(self) -> Self::IntoIter {
+ self.0.into_iter()
+ }
+ }
+ impl<T> FromIterator<T> for VecWrapper<T> {
+ fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
+ Self(Vec::from_iter(iter))
+ }
+ }
+
+ let _ = sample.iter().collect::<VecWrapper<_>>().is_empty();
+ let _ = sample.iter().collect::<VecWrapper<_>>().contains(&&0);
}
diff --git a/src/tools/clippy/tests/ui/needless_collect.stderr b/src/tools/clippy/tests/ui/needless_collect.stderr
index 039091627..584d2a1d8 100644
--- a/src/tools/clippy/tests/ui/needless_collect.stderr
+++ b/src/tools/clippy/tests/ui/needless_collect.stderr
@@ -66,5 +66,29 @@ error: avoid using `collect()` when not needed
LL | sample.iter().collect::<BinaryHeap<_>>().is_empty();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()`
-error: aborting due to 11 previous errors
+error: avoid using `collect()` when not needed
+ --> $DIR/needless_collect.rs:40:27
+ |
+LL | let _ = sample.iter().collect::<HashSet<_>>().is_empty();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()`
+
+error: avoid using `collect()` when not needed
+ --> $DIR/needless_collect.rs:41:27
+ |
+LL | let _ = sample.iter().collect::<HashSet<_>>().contains(&&0);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &0)`
+
+error: avoid using `collect()` when not needed
+ --> $DIR/needless_collect.rs:63:27
+ |
+LL | let _ = sample.iter().collect::<VecWrapper<_>>().is_empty();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()`
+
+error: avoid using `collect()` when not needed
+ --> $DIR/needless_collect.rs:64:27
+ |
+LL | let _ = sample.iter().collect::<VecWrapper<_>>().contains(&&0);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `any(|x| x == &0)`
+
+error: aborting due to 15 previous errors
diff --git a/src/tools/clippy/tests/ui/needless_collect_indirect.rs b/src/tools/clippy/tests/ui/needless_collect_indirect.rs
index 6d213b46c..fe4209e99 100644
--- a/src/tools/clippy/tests/ui/needless_collect_indirect.rs
+++ b/src/tools/clippy/tests/ui/needless_collect_indirect.rs
@@ -1,4 +1,5 @@
#![allow(clippy::uninlined_format_args)]
+#![warn(clippy::needless_collect)]
use std::collections::{BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
diff --git a/src/tools/clippy/tests/ui/needless_collect_indirect.stderr b/src/tools/clippy/tests/ui/needless_collect_indirect.stderr
index 99e1b91d8..790d72590 100644
--- a/src/tools/clippy/tests/ui/needless_collect_indirect.stderr
+++ b/src/tools/clippy/tests/ui/needless_collect_indirect.stderr
@@ -1,5 +1,5 @@
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:7:39
+ --> $DIR/needless_collect_indirect.rs:8:39
|
LL | let indirect_iter = sample.iter().collect::<Vec<_>>();
| ^^^^^^^
@@ -14,7 +14,7 @@ LL ~ sample.iter().map(|x| (x, x + 1)).collect::<HashMap<_, _>>();
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:9:38
+ --> $DIR/needless_collect_indirect.rs:10:38
|
LL | let indirect_len = sample.iter().collect::<VecDeque<_>>();
| ^^^^^^^
@@ -28,7 +28,7 @@ LL ~ sample.iter().count();
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:11:40
+ --> $DIR/needless_collect_indirect.rs:12:40
|
LL | let indirect_empty = sample.iter().collect::<VecDeque<_>>();
| ^^^^^^^
@@ -42,7 +42,7 @@ LL ~ sample.iter().next().is_none();
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:13:43
+ --> $DIR/needless_collect_indirect.rs:14:43
|
LL | let indirect_contains = sample.iter().collect::<VecDeque<_>>();
| ^^^^^^^
@@ -56,7 +56,7 @@ LL ~ sample.iter().any(|x| x == &5);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:25:48
+ --> $DIR/needless_collect_indirect.rs:26:48
|
LL | let non_copy_contains = sample.into_iter().collect::<Vec<_>>();
| ^^^^^^^
@@ -70,7 +70,7 @@ LL ~ sample.into_iter().any(|x| x == a);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:54:51
+ --> $DIR/needless_collect_indirect.rs:55:51
|
LL | let buffer: Vec<&str> = string.split('/').collect();
| ^^^^^^^
@@ -84,7 +84,7 @@ LL ~ string.split('/').count()
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:59:55
+ --> $DIR/needless_collect_indirect.rs:60:55
|
LL | let indirect_len: VecDeque<_> = sample.iter().collect();
| ^^^^^^^
@@ -98,7 +98,7 @@ LL ~ sample.iter().count()
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:64:57
+ --> $DIR/needless_collect_indirect.rs:65:57
|
LL | let indirect_len: LinkedList<_> = sample.iter().collect();
| ^^^^^^^
@@ -112,7 +112,7 @@ LL ~ sample.iter().count()
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:69:57
+ --> $DIR/needless_collect_indirect.rs:70:57
|
LL | let indirect_len: BinaryHeap<_> = sample.iter().collect();
| ^^^^^^^
@@ -126,7 +126,7 @@ LL ~ sample.iter().count()
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:129:59
+ --> $DIR/needless_collect_indirect.rs:130:59
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
@@ -143,7 +143,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == i);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:154:59
+ --> $DIR/needless_collect_indirect.rs:155:59
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
@@ -160,7 +160,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:183:63
+ --> $DIR/needless_collect_indirect.rs:184:63
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
@@ -177,7 +177,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:219:59
+ --> $DIR/needless_collect_indirect.rs:220:59
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
@@ -195,7 +195,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:244:26
+ --> $DIR/needless_collect_indirect.rs:245:26
|
LL | let w = v.iter().collect::<Vec<_>>();
| ^^^^^^^
@@ -211,7 +211,7 @@ LL ~ for _ in 0..v.iter().count() {
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:266:30
+ --> $DIR/needless_collect_indirect.rs:267:30
|
LL | let mut w = v.iter().collect::<Vec<_>>();
| ^^^^^^^
@@ -227,7 +227,7 @@ LL ~ while 1 == v.iter().count() {
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:288:30
+ --> $DIR/needless_collect_indirect.rs:289:30
|
LL | let mut w = v.iter().collect::<Vec<_>>();
| ^^^^^^^
diff --git a/src/tools/clippy/tests/ui/needless_lifetimes.rs b/src/tools/clippy/tests/ui/needless_lifetimes.rs
index fc686b1da..2efc93675 100644
--- a/src/tools/clippy/tests/ui/needless_lifetimes.rs
+++ b/src/tools/clippy/tests/ui/needless_lifetimes.rs
@@ -29,11 +29,20 @@ fn multiple_in_and_out_1<'a>(x: &'a u8, _y: &'a u8) -> &'a u8 {
x
}
-// No error; multiple input refs.
-fn multiple_in_and_out_2<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 {
+// Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid:
+// fn multiple_in_and_out_2a<'a>(x: &'a u8, _y: &u8) -> &'a u8
+// ^^^
+fn multiple_in_and_out_2a<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 {
x
}
+// Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid:
+// fn multiple_in_and_out_2b<'b>(_x: &u8, y: &'b u8) -> &'b u8
+// ^^^
+fn multiple_in_and_out_2b<'a, 'b>(_x: &'a u8, y: &'b u8) -> &'b u8 {
+ y
+}
+
// No error; multiple input refs
async fn func<'a>(args: &[&'a str]) -> Option<&'a str> {
args.get(0).cloned()
@@ -44,11 +53,20 @@ fn in_static_and_out<'a>(x: &'a u8, _y: &'static u8) -> &'a u8 {
x
}
-// No error.
-fn deep_reference_1<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> {
+// Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid:
+// fn deep_reference_1a<'a>(x: &'a u8, _y: &u8) -> Result<&'a u8, ()>
+// ^^^
+fn deep_reference_1a<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> {
Ok(x)
}
+// Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid:
+// fn deep_reference_1b<'b>(_x: &u8, y: &'b u8) -> Result<&'b u8, ()>
+// ^^^
+fn deep_reference_1b<'a, 'b>(_x: &'a u8, y: &'b u8) -> Result<&'b u8, ()> {
+ Ok(y)
+}
+
// No error; two input refs.
fn deep_reference_2<'a>(x: Result<&'a u8, &'a u8>) -> &'a u8 {
x.unwrap()
@@ -129,11 +147,20 @@ impl X {
&self.x
}
- // No error; multiple input refs.
- fn self_and_in_out<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 {
+ // Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid:
+ // fn self_and_in_out_1<'s>(&'s self, _x: &u8) -> &'s u8
+ // ^^^
+ fn self_and_in_out_1<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 {
&self.x
}
+ // Error; multiple input refs, but the output lifetime is not elided, i.e., the following is valid:
+ // fn self_and_in_out_2<'t>(&self, x: &'t u8) -> &'t u8
+ // ^^^^^
+ fn self_and_in_out_2<'s, 't>(&'s self, x: &'t u8) -> &'t u8 {
+ x
+ }
+
fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {}
// No error; same lifetimes on two params.
@@ -167,8 +194,19 @@ fn struct_with_lt3<'a>(_foo: &Foo<'a>) -> &'a str {
unimplemented!()
}
-// No warning; two input lifetimes.
-fn struct_with_lt4<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str {
+// Warning; two input lifetimes, but the output lifetime is not elided, i.e., the following is
+// valid:
+// fn struct_with_lt4a<'a>(_foo: &'a Foo<'_>) -> &'a str
+// ^^
+fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str {
+ unimplemented!()
+}
+
+// Warning; two input lifetimes, but the output lifetime is not elided, i.e., the following is
+// valid:
+// fn struct_with_lt4b<'b>(_foo: &Foo<'b>) -> &'b str
+// ^^^^
+fn struct_with_lt4b<'a, 'b>(_foo: &'a Foo<'b>) -> &'b str {
unimplemented!()
}
@@ -203,8 +241,19 @@ fn alias_with_lt3<'a>(_foo: &FooAlias<'a>) -> &'a str {
unimplemented!()
}
-// No warning; two input lifetimes.
-fn alias_with_lt4<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str {
+// Warning; two input lifetimes, but the output lifetime is not elided, i.e., the following is
+// valid:
+// fn alias_with_lt4a<'a>(_foo: &'a FooAlias<'_>) -> &'a str
+// ^^
+fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str {
+ unimplemented!()
+}
+
+// Warning; two input lifetimes, but the output lifetime is not elided, i.e., the following is
+// valid:
+// fn alias_with_lt4b<'b>(_foo: &FooAlias<'b>) -> &'b str
+// ^^^^^^^^^
+fn alias_with_lt4b<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'b str {
unimplemented!()
}
@@ -419,4 +468,31 @@ mod issue7296 {
}
}
+mod pr_9743_false_negative_fix {
+ #![allow(unused)]
+
+ fn foo<'a>(x: &'a u8, y: &'_ u8) {}
+
+ fn bar<'a>(x: &'a u8, y: &'_ u8, z: &'_ u8) {}
+}
+
+mod pr_9743_output_lifetime_checks {
+ #![allow(unused)]
+
+ // lint: only one input
+ fn one_input<'a>(x: &'a u8) -> &'a u8 {
+ unimplemented!()
+ }
+
+ // lint: multiple inputs, output would not be elided
+ fn multiple_inputs_output_not_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'b u8 {
+ unimplemented!()
+ }
+
+ // don't lint: multiple inputs, output would be elided (which would create an ambiguity)
+ fn multiple_inputs_output_would_be_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'a u8 {
+ unimplemented!()
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/needless_lifetimes.stderr b/src/tools/clippy/tests/ui/needless_lifetimes.stderr
index 3c428fd46..5a7cf13c8 100644
--- a/src/tools/clippy/tests/ui/needless_lifetimes.stderr
+++ b/src/tools/clippy/tests/ui/needless_lifetimes.stderr
@@ -1,4 +1,4 @@
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
+error: the following explicit lifetimes could be elided: 'a, 'b
--> $DIR/needless_lifetimes.rs:11:1
|
LL | fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {}
@@ -6,185 +6,311 @@ LL | fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {}
|
= note: `-D clippy::needless-lifetimes` implied by `-D warnings`
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
+error: the following explicit lifetimes could be elided: 'a, 'b
--> $DIR/needless_lifetimes.rs:13:1
|
LL | fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
+error: the following explicit lifetimes could be elided: 'a
--> $DIR/needless_lifetimes.rs:23:1
|
LL | fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:57:1
+error: the following explicit lifetimes could be elided: 'b
+ --> $DIR/needless_lifetimes.rs:35:1
+ |
+LL | fn multiple_in_and_out_2a<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:42:1
+ |
+LL | fn multiple_in_and_out_2b<'a, 'b>(_x: &'a u8, y: &'b u8) -> &'b u8 {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: the following explicit lifetimes could be elided: 'b
+ --> $DIR/needless_lifetimes.rs:59:1
+ |
+LL | fn deep_reference_1a<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:66:1
+ |
+LL | fn deep_reference_1b<'a, 'b>(_x: &'a u8, y: &'b u8) -> Result<&'b u8, ()> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:75:1
|
LL | fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:62:1
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:80:1
|
LL | fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:74:1
+error: the following explicit lifetimes could be elided: 'a, 'b
+ --> $DIR/needless_lifetimes.rs:92:1
|
LL | fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: replace with `'_` in generic arguments such as here
+ --> $DIR/needless_lifetimes.rs:92:37
+ |
+LL | fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {}
+ | ^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:98:1
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:116:1
|
LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: replace with `'_` in generic arguments such as here
+ --> $DIR/needless_lifetimes.rs:116:32
+ |
+LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
+ | ^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:128:5
+error: the following explicit lifetimes could be elided: 's
+ --> $DIR/needless_lifetimes.rs:146:5
|
LL | fn self_and_out<'s>(&'s self) -> &'s u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:137:5
+error: the following explicit lifetimes could be elided: 't
+ --> $DIR/needless_lifetimes.rs:153:5
+ |
+LL | fn self_and_in_out_1<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: the following explicit lifetimes could be elided: 's
+ --> $DIR/needless_lifetimes.rs:160:5
+ |
+LL | fn self_and_in_out_2<'s, 't>(&'s self, x: &'t u8) -> &'t u8 {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: the following explicit lifetimes could be elided: 's, 't
+ --> $DIR/needless_lifetimes.rs:164:5
|
LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:156:1
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:183:1
|
LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: replace with `'_` in generic arguments such as here
+ --> $DIR/needless_lifetimes.rs:183:33
+ |
+LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str {
+ | ^^
+
+error: the following explicit lifetimes could be elided: 'b
+ --> $DIR/needless_lifetimes.rs:201:1
+ |
+LL | fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: replace with `'_` in generic arguments such as here
+ --> $DIR/needless_lifetimes.rs:201:43
+ |
+LL | fn struct_with_lt4a<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str {
+ | ^^
+
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:209:1
+ |
+LL | fn struct_with_lt4b<'a, 'b>(_foo: &'a Foo<'b>) -> &'b str {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:186:1
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:224:1
|
LL | fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:192:1
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:230:1
|
LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: replace with `'_` in generic arguments such as here
+ --> $DIR/needless_lifetimes.rs:230:37
+ |
+LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str {
+ | ^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:211:1
+error: the following explicit lifetimes could be elided: 'b
+ --> $DIR/needless_lifetimes.rs:248:1
+ |
+LL | fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: replace with `'_` in generic arguments such as here
+ --> $DIR/needless_lifetimes.rs:248:47
+ |
+LL | fn alias_with_lt4a<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'a str {
+ | ^^
+
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:256:1
+ |
+LL | fn alias_with_lt4b<'a, 'b>(_foo: &'a FooAlias<'b>) -> &'b str {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:260:1
|
LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:219:1
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:268:1
|
LL | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:255:1
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:304:1
|
LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: replace with `'_` in generic arguments such as here
+ --> $DIR/needless_lifetimes.rs:304:47
+ |
+LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> {
+ | ^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:262:9
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:311:9
|
LL | fn needless_lt<'a>(x: &'a u8) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:266:9
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:315:9
|
LL | fn needless_lt<'a>(_x: &'a u8) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:279:9
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:328:9
|
LL | fn baz<'a>(&'a self) -> impl Foo + 'a {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:311:5
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:360:5
|
LL | fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:320:5
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:369:5
|
LL | fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:332:5
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:381:5
|
LL | fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:347:5
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:396:5
|
LL | fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:360:5
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:409:5
|
LL | fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:363:5
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:412:5
|
LL | fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:385:9
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:434:9
|
LL | fn implicit<'a>(&'a self) -> &'a () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:388:9
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:437:9
|
LL | fn implicit_mut<'a>(&'a mut self) -> &'a () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:399:9
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:448:9
|
LL | fn lifetime_elsewhere<'a>(self: Box<Self>, here: &'a ()) -> &'a () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:405:9
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:454:9
|
LL | fn implicit<'a>(&'a self) -> &'a ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:406:9
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:455:9
|
LL | fn implicit_provided<'a>(&'a self) -> &'a () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:415:9
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:464:9
|
LL | fn lifetime_elsewhere<'a>(self: Box<Self>, here: &'a ()) -> &'a ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/needless_lifetimes.rs:416:9
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:465:9
|
LL | fn lifetime_elsewhere_provided<'a>(self: Box<Self>, here: &'a ()) -> &'a () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 31 previous errors
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:474:5
+ |
+LL | fn foo<'a>(x: &'a u8, y: &'_ u8) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:476:5
+ |
+LL | fn bar<'a>(x: &'a u8, y: &'_ u8, z: &'_ u8) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:483:5
+ |
+LL | fn one_input<'a>(x: &'a u8) -> &'a u8 {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: the following explicit lifetimes could be elided: 'a
+ --> $DIR/needless_lifetimes.rs:488:5
+ |
+LL | fn multiple_inputs_output_not_elided<'a, 'b>(x: &'a u8, y: &'b u8, z: &'b u8) -> &'b u8 {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 45 previous errors
diff --git a/src/tools/clippy/tests/ui/needless_question_mark.fixed b/src/tools/clippy/tests/ui/needless_question_mark.fixed
index ba9d15e59..7eaca5719 100644
--- a/src/tools/clippy/tests/ui/needless_question_mark.fixed
+++ b/src/tools/clippy/tests/ui/needless_question_mark.fixed
@@ -8,7 +8,6 @@
dead_code,
unused_must_use
)]
-#![feature(custom_inner_attributes)]
struct TO {
magic: Option<usize>,
diff --git a/src/tools/clippy/tests/ui/needless_question_mark.rs b/src/tools/clippy/tests/ui/needless_question_mark.rs
index 3a6523e8f..960bc7b78 100644
--- a/src/tools/clippy/tests/ui/needless_question_mark.rs
+++ b/src/tools/clippy/tests/ui/needless_question_mark.rs
@@ -8,7 +8,6 @@
dead_code,
unused_must_use
)]
-#![feature(custom_inner_attributes)]
struct TO {
magic: Option<usize>,
diff --git a/src/tools/clippy/tests/ui/needless_question_mark.stderr b/src/tools/clippy/tests/ui/needless_question_mark.stderr
index f8308e24e..d1f89e326 100644
--- a/src/tools/clippy/tests/ui/needless_question_mark.stderr
+++ b/src/tools/clippy/tests/ui/needless_question_mark.stderr
@@ -1,5 +1,5 @@
error: question mark operator is useless here
- --> $DIR/needless_question_mark.rs:23:12
+ --> $DIR/needless_question_mark.rs:22:12
|
LL | return Some(to.magic?);
| ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic`
@@ -7,67 +7,67 @@ LL | return Some(to.magic?);
= note: `-D clippy::needless-question-mark` implied by `-D warnings`
error: question mark operator is useless here
- --> $DIR/needless_question_mark.rs:31:12
+ --> $DIR/needless_question_mark.rs:30:12
|
LL | return Some(to.magic?)
| ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic`
error: question mark operator is useless here
- --> $DIR/needless_question_mark.rs:36:5
+ --> $DIR/needless_question_mark.rs:35:5
|
LL | Some(to.magic?)
| ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic`
error: question mark operator is useless here
- --> $DIR/needless_question_mark.rs:41:21
+ --> $DIR/needless_question_mark.rs:40:21
|
LL | to.and_then(|t| Some(t.magic?))
| ^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `t.magic`
error: question mark operator is useless here
- --> $DIR/needless_question_mark.rs:50:9
+ --> $DIR/needless_question_mark.rs:49:9
|
LL | Some(t.magic?)
| ^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `t.magic`
error: question mark operator is useless here
- --> $DIR/needless_question_mark.rs:55:12
+ --> $DIR/needless_question_mark.rs:54:12
|
LL | return Ok(tr.magic?);
| ^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `tr.magic`
error: question mark operator is useless here
- --> $DIR/needless_question_mark.rs:62:12
+ --> $DIR/needless_question_mark.rs:61:12
|
LL | return Ok(tr.magic?)
| ^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `tr.magic`
error: question mark operator is useless here
- --> $DIR/needless_question_mark.rs:66:5
+ --> $DIR/needless_question_mark.rs:65:5
|
LL | Ok(tr.magic?)
| ^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `tr.magic`
error: question mark operator is useless here
- --> $DIR/needless_question_mark.rs:70:21
+ --> $DIR/needless_question_mark.rs:69:21
|
LL | tr.and_then(|t| Ok(t.magic?))
| ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `t.magic`
error: question mark operator is useless here
- --> $DIR/needless_question_mark.rs:78:9
+ --> $DIR/needless_question_mark.rs:77:9
|
LL | Ok(t.magic?)
| ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `t.magic`
error: question mark operator is useless here
- --> $DIR/needless_question_mark.rs:85:16
+ --> $DIR/needless_question_mark.rs:84:16
|
LL | return Ok(t.magic?);
| ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `t.magic`
error: question mark operator is useless here
- --> $DIR/needless_question_mark.rs:120:27
+ --> $DIR/needless_question_mark.rs:119:27
|
LL | || -> Option<_> { Some(Some($expr)?) }()
| ^^^^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `Some($expr)`
@@ -78,13 +78,13 @@ LL | let _x = some_and_qmark_in_macro!(x?);
= note: this error originates in the macro `some_and_qmark_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
error: question mark operator is useless here
- --> $DIR/needless_question_mark.rs:131:5
+ --> $DIR/needless_question_mark.rs:130:5
|
LL | Some(to.magic?)
| ^^^^^^^^^^^^^^^ help: try removing question mark and `Some()`: `to.magic`
error: question mark operator is useless here
- --> $DIR/needless_question_mark.rs:139:5
+ --> $DIR/needless_question_mark.rs:138:5
|
LL | Ok(s.magic?)
| ^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `s.magic`
diff --git a/src/tools/clippy/tests/ui/needless_return.fixed b/src/tools/clippy/tests/ui/needless_return.fixed
index d2163b14f..4386aaec4 100644
--- a/src/tools/clippy/tests/ui/needless_return.fixed
+++ b/src/tools/clippy/tests/ui/needless_return.fixed
@@ -59,14 +59,11 @@ fn test_macro_call() -> i32 {
}
fn test_void_fun() {
-
}
fn test_void_if_fun(b: bool) {
if b {
-
} else {
-
}
}
@@ -82,7 +79,6 @@ fn test_nested_match(x: u32) {
0 => (),
1 => {
let _ = 42;
-
},
_ => (),
}
@@ -126,7 +122,6 @@ mod issue6501 {
fn test_closure() {
let _ = || {
-
};
let _ = || {};
}
@@ -179,14 +174,11 @@ async fn async_test_macro_call() -> i32 {
}
async fn async_test_void_fun() {
-
}
async fn async_test_void_if_fun(b: bool) {
if b {
-
} else {
-
}
}
@@ -269,4 +261,15 @@ fn issue9503(x: usize) -> isize {
}
}
+mod issue9416 {
+ pub fn with_newline() {
+ let _ = 42;
+ }
+
+ #[rustfmt::skip]
+ pub fn oneline() {
+ let _ = 42;
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/needless_return.rs b/src/tools/clippy/tests/ui/needless_return.rs
index 114414b5f..666dc54b7 100644
--- a/src/tools/clippy/tests/ui/needless_return.rs
+++ b/src/tools/clippy/tests/ui/needless_return.rs
@@ -269,4 +269,17 @@ fn issue9503(x: usize) -> isize {
};
}
+mod issue9416 {
+ pub fn with_newline() {
+ let _ = 42;
+
+ return;
+ }
+
+ #[rustfmt::skip]
+ pub fn oneline() {
+ let _ = 42; return;
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/needless_return.stderr b/src/tools/clippy/tests/ui/needless_return.stderr
index 047fb6c23..a8b5d86cd 100644
--- a/src/tools/clippy/tests/ui/needless_return.stderr
+++ b/src/tools/clippy/tests/ui/needless_return.stderr
@@ -72,26 +72,32 @@ LL | return the_answer!();
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:62:5
+ --> $DIR/needless_return.rs:61:21
|
-LL | return;
- | ^^^^^^
+LL | fn test_void_fun() {
+ | _____________________^
+LL | | return;
+ | |__________^
|
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:67:9
+ --> $DIR/needless_return.rs:66:11
|
-LL | return;
- | ^^^^^^
+LL | if b {
+ | ___________^
+LL | | return;
+ | |______________^
|
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:69:9
+ --> $DIR/needless_return.rs:68:13
|
-LL | return;
- | ^^^^^^
+LL | } else {
+ | _____________^
+LL | | return;
+ | |______________^
|
= help: remove `return`
@@ -104,10 +110,12 @@ LL | _ => return,
= help: replace `return` with a unit value
error: unneeded `return` statement
- --> $DIR/needless_return.rs:85:13
+ --> $DIR/needless_return.rs:84:24
|
-LL | return;
- | ^^^^^^
+LL | let _ = 42;
+ | ________________________^
+LL | | return;
+ | |__________________^
|
= help: remove `return`
@@ -144,10 +152,12 @@ LL | bar.unwrap_or_else(|_| return)
= help: replace `return` with an empty block
error: unneeded `return` statement
- --> $DIR/needless_return.rs:129:13
+ --> $DIR/needless_return.rs:128:21
|
-LL | return;
- | ^^^^^^
+LL | let _ = || {
+ | _____________________^
+LL | | return;
+ | |__________________^
|
= help: remove `return`
@@ -240,26 +250,32 @@ LL | return the_answer!();
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:182:5
+ --> $DIR/needless_return.rs:181:33
|
-LL | return;
- | ^^^^^^
+LL | async fn async_test_void_fun() {
+ | _________________________________^
+LL | | return;
+ | |__________^
|
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:187:9
+ --> $DIR/needless_return.rs:186:11
|
-LL | return;
- | ^^^^^^
+LL | if b {
+ | ___________^
+LL | | return;
+ | |______________^
|
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:189:9
+ --> $DIR/needless_return.rs:188:13
|
-LL | return;
- | ^^^^^^
+LL | } else {
+ | _____________^
+LL | | return;
+ | |______________^
|
= help: remove `return`
@@ -351,5 +367,24 @@ LL | return !*(x as *const isize);
|
= help: remove `return`
-error: aborting due to 44 previous errors
+error: unneeded `return` statement
+ --> $DIR/needless_return.rs:274:20
+ |
+LL | let _ = 42;
+ | ____________________^
+LL | |
+LL | | return;
+ | |______________^
+ |
+ = help: remove `return`
+
+error: unneeded `return` statement
+ --> $DIR/needless_return.rs:281:20
+ |
+LL | let _ = 42; return;
+ | ^^^^^^^
+ |
+ = help: remove `return`
+
+error: aborting due to 46 previous errors
diff --git a/src/tools/clippy/tests/ui/needless_splitn.fixed b/src/tools/clippy/tests/ui/needless_splitn.fixed
index 61f5fc4e6..5496031fe 100644
--- a/src/tools/clippy/tests/ui/needless_splitn.fixed
+++ b/src/tools/clippy/tests/ui/needless_splitn.fixed
@@ -1,7 +1,6 @@
// run-rustfix
// edition:2018
-#![feature(custom_inner_attributes)]
#![warn(clippy::needless_splitn)]
#![allow(clippy::iter_skip_next, clippy::iter_nth_zero, clippy::manual_split_once)]
@@ -40,8 +39,8 @@ fn _question_mark(s: &str) -> Option<()> {
Some(())
}
+#[clippy::msrv = "1.51"]
fn _test_msrv() {
- #![clippy::msrv = "1.51"]
// `manual_split_once` MSRV shouldn't apply to `needless_splitn`
let _ = "key=value".split('=').nth(0).unwrap();
}
diff --git a/src/tools/clippy/tests/ui/needless_splitn.rs b/src/tools/clippy/tests/ui/needless_splitn.rs
index 71d9a7077..35c2465ba 100644
--- a/src/tools/clippy/tests/ui/needless_splitn.rs
+++ b/src/tools/clippy/tests/ui/needless_splitn.rs
@@ -1,7 +1,6 @@
// run-rustfix
// edition:2018
-#![feature(custom_inner_attributes)]
#![warn(clippy::needless_splitn)]
#![allow(clippy::iter_skip_next, clippy::iter_nth_zero, clippy::manual_split_once)]
@@ -40,8 +39,8 @@ fn _question_mark(s: &str) -> Option<()> {
Some(())
}
+#[clippy::msrv = "1.51"]
fn _test_msrv() {
- #![clippy::msrv = "1.51"]
// `manual_split_once` MSRV shouldn't apply to `needless_splitn`
let _ = "key=value".splitn(2, '=').nth(0).unwrap();
}
diff --git a/src/tools/clippy/tests/ui/needless_splitn.stderr b/src/tools/clippy/tests/ui/needless_splitn.stderr
index f112b29e7..f607d8e1a 100644
--- a/src/tools/clippy/tests/ui/needless_splitn.stderr
+++ b/src/tools/clippy/tests/ui/needless_splitn.stderr
@@ -1,5 +1,5 @@
error: unnecessary use of `splitn`
- --> $DIR/needless_splitn.rs:15:13
+ --> $DIR/needless_splitn.rs:14:13
|
LL | let _ = str.splitn(2, '=').next();
| ^^^^^^^^^^^^^^^^^^ help: try this: `str.split('=')`
@@ -7,73 +7,73 @@ LL | let _ = str.splitn(2, '=').next();
= note: `-D clippy::needless-splitn` implied by `-D warnings`
error: unnecessary use of `splitn`
- --> $DIR/needless_splitn.rs:16:13
+ --> $DIR/needless_splitn.rs:15:13
|
LL | let _ = str.splitn(2, '=').nth(0);
| ^^^^^^^^^^^^^^^^^^ help: try this: `str.split('=')`
error: unnecessary use of `splitn`
- --> $DIR/needless_splitn.rs:19:18
+ --> $DIR/needless_splitn.rs:18:18
|
LL | let (_, _) = str.splitn(3, '=').next_tuple().unwrap();
| ^^^^^^^^^^^^^^^^^^ help: try this: `str.split('=')`
error: unnecessary use of `rsplitn`
- --> $DIR/needless_splitn.rs:22:13
+ --> $DIR/needless_splitn.rs:21:13
|
LL | let _ = str.rsplitn(2, '=').next();
| ^^^^^^^^^^^^^^^^^^^ help: try this: `str.rsplit('=')`
error: unnecessary use of `rsplitn`
- --> $DIR/needless_splitn.rs:23:13
+ --> $DIR/needless_splitn.rs:22:13
|
LL | let _ = str.rsplitn(2, '=').nth(0);
| ^^^^^^^^^^^^^^^^^^^ help: try this: `str.rsplit('=')`
error: unnecessary use of `rsplitn`
- --> $DIR/needless_splitn.rs:26:18
+ --> $DIR/needless_splitn.rs:25:18
|
LL | let (_, _) = str.rsplitn(3, '=').next_tuple().unwrap();
| ^^^^^^^^^^^^^^^^^^^ help: try this: `str.rsplit('=')`
error: unnecessary use of `splitn`
- --> $DIR/needless_splitn.rs:28:13
+ --> $DIR/needless_splitn.rs:27:13
|
LL | let _ = str.splitn(5, '=').next();
| ^^^^^^^^^^^^^^^^^^ help: try this: `str.split('=')`
error: unnecessary use of `splitn`
- --> $DIR/needless_splitn.rs:29:13
+ --> $DIR/needless_splitn.rs:28:13
|
LL | let _ = str.splitn(5, '=').nth(3);
| ^^^^^^^^^^^^^^^^^^ help: try this: `str.split('=')`
error: unnecessary use of `splitn`
- --> $DIR/needless_splitn.rs:35:13
+ --> $DIR/needless_splitn.rs:34:13
|
LL | let _ = s.splitn(2, '=').next()?;
| ^^^^^^^^^^^^^^^^ help: try this: `s.split('=')`
error: unnecessary use of `splitn`
- --> $DIR/needless_splitn.rs:36:13
+ --> $DIR/needless_splitn.rs:35:13
|
LL | let _ = s.splitn(2, '=').nth(0)?;
| ^^^^^^^^^^^^^^^^ help: try this: `s.split('=')`
error: unnecessary use of `rsplitn`
- --> $DIR/needless_splitn.rs:37:13
+ --> $DIR/needless_splitn.rs:36:13
|
LL | let _ = s.rsplitn(2, '=').next()?;
| ^^^^^^^^^^^^^^^^^ help: try this: `s.rsplit('=')`
error: unnecessary use of `rsplitn`
- --> $DIR/needless_splitn.rs:38:13
+ --> $DIR/needless_splitn.rs:37:13
|
LL | let _ = s.rsplitn(2, '=').nth(0)?;
| ^^^^^^^^^^^^^^^^^ help: try this: `s.rsplit('=')`
error: unnecessary use of `splitn`
- --> $DIR/needless_splitn.rs:46:13
+ --> $DIR/needless_splitn.rs:45:13
|
LL | let _ = "key=value".splitn(2, '=').nth(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `"key=value".split('=')`
diff --git a/src/tools/clippy/tests/ui/never_loop.rs b/src/tools/clippy/tests/ui/never_loop.rs
index 3dbef1989..28e8f459d 100644
--- a/src/tools/clippy/tests/ui/never_loop.rs
+++ b/src/tools/clippy/tests/ui/never_loop.rs
@@ -229,6 +229,27 @@ pub fn test18() {
};
}
+// Issue #9831: unconditional break to internal labeled block
+pub fn test19() {
+ fn thing(iter: impl Iterator) {
+ for _ in iter {
+ 'b: {
+ break 'b;
+ }
+ }
+ }
+}
+
+pub fn test20() {
+ 'a: loop {
+ 'b: {
+ break 'b 'c: {
+ break 'a;
+ };
+ }
+ }
+}
+
fn main() {
test1();
test2();
diff --git a/src/tools/clippy/tests/ui/never_loop.stderr b/src/tools/clippy/tests/ui/never_loop.stderr
index 3033f0192..b7029bf8b 100644
--- a/src/tools/clippy/tests/ui/never_loop.stderr
+++ b/src/tools/clippy/tests/ui/never_loop.stderr
@@ -114,5 +114,17 @@ LL | | break x;
LL | | };
| |_____^
-error: aborting due to 10 previous errors
+error: this loop never actually loops
+ --> $DIR/never_loop.rs:244:5
+ |
+LL | / 'a: loop {
+LL | | 'b: {
+LL | | break 'b 'c: {
+LL | | break 'a;
+LL | | };
+LL | | }
+LL | | }
+ | |_____^
+
+error: aborting due to 11 previous errors
diff --git a/src/tools/clippy/tests/ui/new_ret_no_self.rs b/src/tools/clippy/tests/ui/new_ret_no_self.rs
index 2f315ffe2..beec42f08 100644
--- a/src/tools/clippy/tests/ui/new_ret_no_self.rs
+++ b/src/tools/clippy/tests/ui/new_ret_no_self.rs
@@ -1,3 +1,4 @@
+#![feature(type_alias_impl_trait)]
#![warn(clippy::new_ret_no_self)]
#![allow(dead_code)]
@@ -350,3 +351,75 @@ impl RetOtherSelf<T> {
RetOtherSelf(RetOtherSelfWrapper(t))
}
}
+
+mod issue7344 {
+ struct RetImplTraitSelf<T>(T);
+
+ impl<T> RetImplTraitSelf<T> {
+ // should not trigger lint
+ fn new(t: T) -> impl Into<Self> {
+ Self(t)
+ }
+ }
+
+ struct RetImplTraitNoSelf<T>(T);
+
+ impl<T> RetImplTraitNoSelf<T> {
+ // should trigger lint
+ fn new(t: T) -> impl Into<i32> {
+ 1
+ }
+ }
+
+ trait Trait2<T, U> {}
+ impl<T, U> Trait2<T, U> for () {}
+
+ struct RetImplTraitSelf2<T>(T);
+
+ impl<T> RetImplTraitSelf2<T> {
+ // should not trigger lint
+ fn new(t: T) -> impl Trait2<(), Self> {
+ unimplemented!()
+ }
+ }
+
+ struct RetImplTraitNoSelf2<T>(T);
+
+ impl<T> RetImplTraitNoSelf2<T> {
+ // should trigger lint
+ fn new(t: T) -> impl Trait2<(), i32> {
+ unimplemented!()
+ }
+ }
+
+ struct RetImplTraitSelfAdt<'a>(&'a str);
+
+ impl<'a> RetImplTraitSelfAdt<'a> {
+ // should not trigger lint
+ fn new<'b: 'a>(s: &'b str) -> impl Into<RetImplTraitSelfAdt<'b>> {
+ RetImplTraitSelfAdt(s)
+ }
+ }
+}
+
+mod issue10041 {
+ struct Bomb;
+
+ impl Bomb {
+ // Hidden <Rhs = Self> default generic paramter.
+ pub fn new() -> impl PartialOrd {
+ 0i32
+ }
+ }
+
+ // TAIT with self-referencing bounds
+ type X = impl std::ops::Add<Output = X>;
+
+ struct Bomb2;
+
+ impl Bomb2 {
+ pub fn new() -> X {
+ 0i32
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/new_ret_no_self.stderr b/src/tools/clippy/tests/ui/new_ret_no_self.stderr
index 8217bc618..2eaebfb5c 100644
--- a/src/tools/clippy/tests/ui/new_ret_no_self.stderr
+++ b/src/tools/clippy/tests/ui/new_ret_no_self.stderr
@@ -1,5 +1,5 @@
error: methods called `new` usually return `Self`
- --> $DIR/new_ret_no_self.rs:49:5
+ --> $DIR/new_ret_no_self.rs:50:5
|
LL | / pub fn new(_: String) -> impl R<Item = u32> {
LL | | S3
@@ -9,7 +9,7 @@ LL | | }
= note: `-D clippy::new-ret-no-self` implied by `-D warnings`
error: methods called `new` usually return `Self`
- --> $DIR/new_ret_no_self.rs:81:5
+ --> $DIR/new_ret_no_self.rs:82:5
|
LL | / pub fn new() -> u32 {
LL | | unimplemented!();
@@ -17,7 +17,7 @@ LL | | }
| |_____^
error: methods called `new` usually return `Self`
- --> $DIR/new_ret_no_self.rs:90:5
+ --> $DIR/new_ret_no_self.rs:91:5
|
LL | / pub fn new(_: String) -> u32 {
LL | | unimplemented!();
@@ -25,7 +25,7 @@ LL | | }
| |_____^
error: methods called `new` usually return `Self`
- --> $DIR/new_ret_no_self.rs:126:5
+ --> $DIR/new_ret_no_self.rs:127:5
|
LL | / pub fn new() -> (u32, u32) {
LL | | unimplemented!();
@@ -33,7 +33,7 @@ LL | | }
| |_____^
error: methods called `new` usually return `Self`
- --> $DIR/new_ret_no_self.rs:153:5
+ --> $DIR/new_ret_no_self.rs:154:5
|
LL | / pub fn new() -> *mut V {
LL | | unimplemented!();
@@ -41,7 +41,7 @@ LL | | }
| |_____^
error: methods called `new` usually return `Self`
- --> $DIR/new_ret_no_self.rs:171:5
+ --> $DIR/new_ret_no_self.rs:172:5
|
LL | / pub fn new() -> Option<u32> {
LL | | unimplemented!();
@@ -49,19 +49,19 @@ LL | | }
| |_____^
error: methods called `new` usually return `Self`
- --> $DIR/new_ret_no_self.rs:224:9
+ --> $DIR/new_ret_no_self.rs:225:9
|
LL | fn new() -> String;
| ^^^^^^^^^^^^^^^^^^^
error: methods called `new` usually return `Self`
- --> $DIR/new_ret_no_self.rs:236:9
+ --> $DIR/new_ret_no_self.rs:237:9
|
LL | fn new(_: String) -> String;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: methods called `new` usually return `Self`
- --> $DIR/new_ret_no_self.rs:271:9
+ --> $DIR/new_ret_no_self.rs:272:9
|
LL | / fn new() -> (u32, u32) {
LL | | unimplemented!();
@@ -69,12 +69,44 @@ LL | | }
| |_________^
error: methods called `new` usually return `Self`
- --> $DIR/new_ret_no_self.rs:298:9
+ --> $DIR/new_ret_no_self.rs:299:9
|
LL | / fn new() -> *mut V {
LL | | unimplemented!();
LL | | }
| |_________^
-error: aborting due to 10 previous errors
+error: methods called `new` usually return `Self`
+ --> $DIR/new_ret_no_self.rs:369:9
+ |
+LL | / fn new(t: T) -> impl Into<i32> {
+LL | | 1
+LL | | }
+ | |_________^
+
+error: methods called `new` usually return `Self`
+ --> $DIR/new_ret_no_self.rs:390:9
+ |
+LL | / fn new(t: T) -> impl Trait2<(), i32> {
+LL | | unimplemented!()
+LL | | }
+ | |_________^
+
+error: methods called `new` usually return `Self`
+ --> $DIR/new_ret_no_self.rs:410:9
+ |
+LL | / pub fn new() -> impl PartialOrd {
+LL | | 0i32
+LL | | }
+ | |_________^
+
+error: methods called `new` usually return `Self`
+ --> $DIR/new_ret_no_self.rs:421:9
+ |
+LL | / pub fn new() -> X {
+LL | | 0i32
+LL | | }
+ | |_________^
+
+error: aborting due to 14 previous errors
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 bc376d0d7..d124d133f 100644
--- a/src/tools/clippy/tests/ui/option_as_ref_deref.fixed
+++ b/src/tools/clippy/tests/ui/option_as_ref_deref.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![allow(unused, clippy::redundant_clone)]
#![warn(clippy::option_as_ref_deref)]
@@ -44,16 +43,14 @@ fn main() {
let _ = opt.as_deref();
}
+#[clippy::msrv = "1.39"]
fn msrv_1_39() {
- #![clippy::msrv = "1.39"]
-
let opt = Some(String::from("123"));
let _ = opt.as_ref().map(String::as_str);
}
+#[clippy::msrv = "1.40"]
fn msrv_1_40() {
- #![clippy::msrv = "1.40"]
-
let opt = Some(String::from("123"));
let _ = opt.as_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 ba3a2eedc..86e354c67 100644
--- a/src/tools/clippy/tests/ui/option_as_ref_deref.rs
+++ b/src/tools/clippy/tests/ui/option_as_ref_deref.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![allow(unused, clippy::redundant_clone)]
#![warn(clippy::option_as_ref_deref)]
@@ -47,16 +46,14 @@ fn main() {
let _ = opt.as_ref().map(std::ops::Deref::deref);
}
+#[clippy::msrv = "1.39"]
fn msrv_1_39() {
- #![clippy::msrv = "1.39"]
-
let opt = Some(String::from("123"));
let _ = opt.as_ref().map(String::as_str);
}
+#[clippy::msrv = "1.40"]
fn msrv_1_40() {
- #![clippy::msrv = "1.40"]
-
let opt = Some(String::from("123"));
let _ = opt.as_ref().map(String::as_str);
}
diff --git a/src/tools/clippy/tests/ui/option_as_ref_deref.stderr b/src/tools/clippy/tests/ui/option_as_ref_deref.stderr
index 7de8b3b6b..e471b56ee 100644
--- a/src/tools/clippy/tests/ui/option_as_ref_deref.stderr
+++ b/src/tools/clippy/tests/ui/option_as_ref_deref.stderr
@@ -1,5 +1,5 @@
error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:14:13
+ --> $DIR/option_as_ref_deref.rs:13:13
|
LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.clone().as_deref()`
@@ -7,7 +7,7 @@ LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len);
= note: `-D clippy::option-as-ref-deref` implied by `-D warnings`
error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:17:13
+ --> $DIR/option_as_ref_deref.rs:16:13
|
LL | let _ = opt.clone()
| _____________^
@@ -17,97 +17,97 @@ LL | | )
| |_________^ help: try using as_deref instead: `opt.clone().as_deref()`
error: called `.as_mut().map(DerefMut::deref_mut)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
- --> $DIR/option_as_ref_deref.rs:23:13
+ --> $DIR/option_as_ref_deref.rs:22:13
|
LL | let _ = opt.as_mut().map(DerefMut::deref_mut);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
error: called `.as_ref().map(String::as_str)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:25:13
+ --> $DIR/option_as_ref_deref.rs:24:13
|
LL | let _ = opt.as_ref().map(String::as_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
error: called `.as_ref().map(|x| x.as_str())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:26:13
+ --> $DIR/option_as_ref_deref.rs:25:13
|
LL | let _ = opt.as_ref().map(|x| x.as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
error: called `.as_mut().map(String::as_mut_str)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
- --> $DIR/option_as_ref_deref.rs:27:13
+ --> $DIR/option_as_ref_deref.rs:26:13
|
LL | let _ = opt.as_mut().map(String::as_mut_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
error: called `.as_mut().map(|x| x.as_mut_str())` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
- --> $DIR/option_as_ref_deref.rs:28:13
+ --> $DIR/option_as_ref_deref.rs:27:13
|
LL | let _ = opt.as_mut().map(|x| x.as_mut_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
error: called `.as_ref().map(CString::as_c_str)` on an Option value. This can be done more directly by calling `Some(CString::new(vec![]).unwrap()).as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:29:13
+ --> $DIR/option_as_ref_deref.rs:28:13
|
LL | let _ = Some(CString::new(vec![]).unwrap()).as_ref().map(CString::as_c_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(CString::new(vec![]).unwrap()).as_deref()`
error: called `.as_ref().map(OsString::as_os_str)` on an Option value. This can be done more directly by calling `Some(OsString::new()).as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:30:13
+ --> $DIR/option_as_ref_deref.rs:29:13
|
LL | let _ = Some(OsString::new()).as_ref().map(OsString::as_os_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(OsString::new()).as_deref()`
error: called `.as_ref().map(PathBuf::as_path)` on an Option value. This can be done more directly by calling `Some(PathBuf::new()).as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:31:13
+ --> $DIR/option_as_ref_deref.rs:30:13
|
LL | let _ = Some(PathBuf::new()).as_ref().map(PathBuf::as_path);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(PathBuf::new()).as_deref()`
error: called `.as_ref().map(Vec::as_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:32:13
+ --> $DIR/option_as_ref_deref.rs:31:13
|
LL | let _ = Some(Vec::<()>::new()).as_ref().map(Vec::as_slice);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(Vec::<()>::new()).as_deref()`
error: called `.as_mut().map(Vec::as_mut_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref_mut()` instead
- --> $DIR/option_as_ref_deref.rs:33:13
+ --> $DIR/option_as_ref_deref.rs:32:13
|
LL | let _ = Some(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `Some(Vec::<()>::new()).as_deref_mut()`
error: called `.as_ref().map(|x| x.deref())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:35:13
+ --> $DIR/option_as_ref_deref.rs:34:13
|
LL | let _ = opt.as_ref().map(|x| x.deref());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
error: called `.as_mut().map(|x| x.deref_mut())` on an Option value. This can be done more directly by calling `opt.clone().as_deref_mut()` instead
- --> $DIR/option_as_ref_deref.rs:36:13
+ --> $DIR/option_as_ref_deref.rs:35:13
|
LL | let _ = opt.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.clone().as_deref_mut()`
error: called `.as_ref().map(|x| &**x)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:43:13
+ --> $DIR/option_as_ref_deref.rs:42:13
|
LL | let _ = opt.as_ref().map(|x| &**x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
error: called `.as_mut().map(|x| &mut **x)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
- --> $DIR/option_as_ref_deref.rs:44:13
+ --> $DIR/option_as_ref_deref.rs:43:13
|
LL | let _ = opt.as_mut().map(|x| &mut **x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
error: called `.as_ref().map(std::ops::Deref::deref)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:47:13
+ --> $DIR/option_as_ref_deref.rs:46:13
|
LL | let _ = opt.as_ref().map(std::ops::Deref::deref);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
error: called `.as_ref().map(String::as_str)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:61:13
+ --> $DIR/option_as_ref_deref.rs:58:13
|
LL | let _ = opt.as_ref().map(String::as_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
diff --git a/src/tools/clippy/tests/ui/option_if_let_else.fixed b/src/tools/clippy/tests/ui/option_if_let_else.fixed
index f15ac551b..0456005dc 100644
--- a/src/tools/clippy/tests/ui/option_if_let_else.fixed
+++ b/src/tools/clippy/tests/ui/option_if_let_else.fixed
@@ -189,3 +189,12 @@ fn main() {
let _ = res.map_or(1, |a| a + 1);
let _ = res.map_or(5, |a| a + 1);
}
+
+#[allow(dead_code)]
+fn issue9742() -> Option<&'static str> {
+ // should not lint because of guards
+ match Some("foo ") {
+ Some(name) if name.starts_with("foo") => Some(name.trim()),
+ _ => 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 9eeaea12d..23b148752 100644
--- a/src/tools/clippy/tests/ui/option_if_let_else.rs
+++ b/src/tools/clippy/tests/ui/option_if_let_else.rs
@@ -230,3 +230,12 @@ fn main() {
};
let _ = if let Ok(a) = res { a + 1 } else { 5 };
}
+
+#[allow(dead_code)]
+fn issue9742() -> Option<&'static str> {
+ // should not lint because of guards
+ match Some("foo ") {
+ Some(name) if name.starts_with("foo") => Some(name.trim()),
+ _ => None,
+ }
+}
diff --git a/src/tools/clippy/tests/ui/or_fun_call.fixed b/src/tools/clippy/tests/ui/or_fun_call.fixed
index 23b1aa8be..be9a65506 100644
--- a/src/tools/clippy/tests/ui/or_fun_call.fixed
+++ b/src/tools/clippy/tests/ui/or_fun_call.fixed
@@ -236,4 +236,20 @@ mod issue9608 {
}
}
+mod issue8993 {
+ fn g() -> i32 {
+ 3
+ }
+
+ fn f(n: i32) -> i32 {
+ n
+ }
+
+ fn test_map_or() {
+ let _ = Some(4).map_or_else(g, |v| v);
+ let _ = Some(4).map_or_else(g, f);
+ let _ = Some(4).map_or(0, f);
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/or_fun_call.rs b/src/tools/clippy/tests/ui/or_fun_call.rs
index 039998f22..628c97046 100644
--- a/src/tools/clippy/tests/ui/or_fun_call.rs
+++ b/src/tools/clippy/tests/ui/or_fun_call.rs
@@ -236,4 +236,20 @@ mod issue9608 {
}
}
+mod issue8993 {
+ fn g() -> i32 {
+ 3
+ }
+
+ fn f(n: i32) -> i32 {
+ n
+ }
+
+ fn test_map_or() {
+ let _ = Some(4).map_or(g(), |v| v);
+ let _ = Some(4).map_or(g(), f);
+ let _ = Some(4).map_or(0, f);
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/or_fun_call.stderr b/src/tools/clippy/tests/ui/or_fun_call.stderr
index 113ba150c..ba3001db7 100644
--- a/src/tools/clippy/tests/ui/or_fun_call.stderr
+++ b/src/tools/clippy/tests/ui/or_fun_call.stderr
@@ -156,5 +156,17 @@ error: use of `unwrap_or` followed by a call to `new`
LL | .unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
-error: aborting due to 26 previous errors
+error: use of `map_or` followed by a function call
+ --> $DIR/or_fun_call.rs:249:25
+ |
+LL | let _ = Some(4).map_or(g(), |v| v);
+ | ^^^^^^^^^^^^^^^^^^ help: try this: `map_or_else(g, |v| v)`
+
+error: use of `map_or` followed by a function call
+ --> $DIR/or_fun_call.rs:250:25
+ |
+LL | let _ = Some(4).map_or(g(), f);
+ | ^^^^^^^^^^^^^^ help: try this: `map_or_else(g, f)`
+
+error: aborting due to 28 previous errors
diff --git a/src/tools/clippy/tests/ui/ptr_as_ptr.fixed b/src/tools/clippy/tests/ui/ptr_as_ptr.fixed
index bea6be66a..df36a9b84 100644
--- a/src/tools/clippy/tests/ui/ptr_as_ptr.fixed
+++ b/src/tools/clippy/tests/ui/ptr_as_ptr.fixed
@@ -2,7 +2,6 @@
// aux-build:macro_rules.rs
#![warn(clippy::ptr_as_ptr)]
-#![feature(custom_inner_attributes)]
extern crate macro_rules;
@@ -45,8 +44,8 @@ fn main() {
let _ = macro_rules::ptr_as_ptr_cast!(ptr);
}
+#[clippy::msrv = "1.37"]
fn _msrv_1_37() {
- #![clippy::msrv = "1.37"]
let ptr: *const u32 = &42_u32;
let mut_ptr: *mut u32 = &mut 42_u32;
@@ -55,8 +54,8 @@ fn _msrv_1_37() {
let _ = mut_ptr as *mut i32;
}
+#[clippy::msrv = "1.38"]
fn _msrv_1_38() {
- #![clippy::msrv = "1.38"]
let ptr: *const u32 = &42_u32;
let mut_ptr: *mut u32 = &mut 42_u32;
diff --git a/src/tools/clippy/tests/ui/ptr_as_ptr.rs b/src/tools/clippy/tests/ui/ptr_as_ptr.rs
index ca2616b00..302c66462 100644
--- a/src/tools/clippy/tests/ui/ptr_as_ptr.rs
+++ b/src/tools/clippy/tests/ui/ptr_as_ptr.rs
@@ -2,7 +2,6 @@
// aux-build:macro_rules.rs
#![warn(clippy::ptr_as_ptr)]
-#![feature(custom_inner_attributes)]
extern crate macro_rules;
@@ -45,8 +44,8 @@ fn main() {
let _ = macro_rules::ptr_as_ptr_cast!(ptr);
}
+#[clippy::msrv = "1.37"]
fn _msrv_1_37() {
- #![clippy::msrv = "1.37"]
let ptr: *const u32 = &42_u32;
let mut_ptr: *mut u32 = &mut 42_u32;
@@ -55,8 +54,8 @@ fn _msrv_1_37() {
let _ = mut_ptr as *mut i32;
}
+#[clippy::msrv = "1.38"]
fn _msrv_1_38() {
- #![clippy::msrv = "1.38"]
let ptr: *const u32 = &42_u32;
let mut_ptr: *mut u32 = &mut 42_u32;
diff --git a/src/tools/clippy/tests/ui/ptr_as_ptr.stderr b/src/tools/clippy/tests/ui/ptr_as_ptr.stderr
index c58c55cfd..a68e1cab6 100644
--- a/src/tools/clippy/tests/ui/ptr_as_ptr.stderr
+++ b/src/tools/clippy/tests/ui/ptr_as_ptr.stderr
@@ -1,5 +1,5 @@
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:19:13
+ --> $DIR/ptr_as_ptr.rs:18:13
|
LL | let _ = ptr as *const i32;
| ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::<i32>()`
@@ -7,31 +7,31 @@ LL | let _ = ptr as *const i32;
= note: `-D clippy::ptr-as-ptr` implied by `-D warnings`
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:20:13
+ --> $DIR/ptr_as_ptr.rs:19:13
|
LL | let _ = mut_ptr as *mut i32;
| ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::<i32>()`
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:25:17
+ --> $DIR/ptr_as_ptr.rs:24:17
|
LL | let _ = *ptr_ptr as *const i32;
| ^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `(*ptr_ptr).cast::<i32>()`
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:38:25
+ --> $DIR/ptr_as_ptr.rs:37:25
|
LL | let _: *const i32 = ptr as *const _;
| ^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast()`
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:39:23
+ --> $DIR/ptr_as_ptr.rs:38:23
|
LL | let _: *mut i32 = mut_ptr as _;
| ^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast()`
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:11:9
+ --> $DIR/ptr_as_ptr.rs:10:9
|
LL | $ptr as *const i32
| ^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `$ptr.cast::<i32>()`
@@ -42,13 +42,13 @@ LL | let _ = cast_it!(ptr);
= note: this error originates in the macro `cast_it` (in Nightly builds, run with -Z macro-backtrace for more info)
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:63:13
+ --> $DIR/ptr_as_ptr.rs:62:13
|
LL | let _ = ptr as *const i32;
| ^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `ptr.cast::<i32>()`
error: `as` casting between raw pointers without changing its mutability
- --> $DIR/ptr_as_ptr.rs:64:13
+ --> $DIR/ptr_as_ptr.rs:63:13
|
LL | let _ = mut_ptr as *mut i32;
| ^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `mut_ptr.cast::<i32>()`
diff --git a/src/tools/clippy/tests/ui/question_mark.fixed b/src/tools/clippy/tests/ui/question_mark.fixed
index 993389232..5c49d46da 100644
--- a/src/tools/clippy/tests/ui/question_mark.fixed
+++ b/src/tools/clippy/tests/ui/question_mark.fixed
@@ -134,6 +134,9 @@ fn result_func(x: Result<i32, i32>) -> Result<i32, i32> {
return func_returning_result();
}
+ // no warning
+ let _ = if let Err(e) = x { Err(e) } else { Ok(0) };
+
Ok(y)
}
diff --git a/src/tools/clippy/tests/ui/question_mark.rs b/src/tools/clippy/tests/ui/question_mark.rs
index 9ae0d8882..d057df6a9 100644
--- a/src/tools/clippy/tests/ui/question_mark.rs
+++ b/src/tools/clippy/tests/ui/question_mark.rs
@@ -166,6 +166,9 @@ fn result_func(x: Result<i32, i32>) -> Result<i32, i32> {
return func_returning_result();
}
+ // no warning
+ let _ = if let Err(e) = x { Err(e) } else { Ok(0) };
+
Ok(y)
}
diff --git a/src/tools/clippy/tests/ui/question_mark.stderr b/src/tools/clippy/tests/ui/question_mark.stderr
index 1b6cd524b..23172d7e5 100644
--- a/src/tools/clippy/tests/ui/question_mark.stderr
+++ b/src/tools/clippy/tests/ui/question_mark.stderr
@@ -115,7 +115,7 @@ LL | | }
| |_____^ help: replace it with: `x?;`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:193:5
+ --> $DIR/question_mark.rs:196:5
|
LL | / if let Err(err) = func_returning_result() {
LL | | return Err(err);
@@ -123,7 +123,7 @@ LL | | }
| |_____^ help: replace it with: `func_returning_result()?;`
error: this block may be rewritten with the `?` operator
- --> $DIR/question_mark.rs:200:5
+ --> $DIR/question_mark.rs:203:5
|
LL | / if let Err(err) = func_returning_result() {
LL | | return Err(err);
diff --git a/src/tools/clippy/tests/ui/range_contains.fixed b/src/tools/clippy/tests/ui/range_contains.fixed
index 824f00cb9..4923731fe 100644
--- a/src/tools/clippy/tests/ui/range_contains.fixed
+++ b/src/tools/clippy/tests/ui/range_contains.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::manual_range_contains)]
#![allow(unused)]
#![allow(clippy::no_effect)]
@@ -65,16 +64,14 @@ pub const fn in_range(a: i32) -> bool {
3 <= a && a <= 20
}
+#[clippy::msrv = "1.34"]
fn msrv_1_34() {
- #![clippy::msrv = "1.34"]
-
let x = 5;
x >= 8 && x < 34;
}
+#[clippy::msrv = "1.35"]
fn msrv_1_35() {
- #![clippy::msrv = "1.35"]
-
let x = 5;
(8..35).contains(&x);
}
diff --git a/src/tools/clippy/tests/ui/range_contains.rs b/src/tools/clippy/tests/ui/range_contains.rs
index df925eead..d623ccb5d 100644
--- a/src/tools/clippy/tests/ui/range_contains.rs
+++ b/src/tools/clippy/tests/ui/range_contains.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::manual_range_contains)]
#![allow(unused)]
#![allow(clippy::no_effect)]
@@ -65,16 +64,14 @@ pub const fn in_range(a: i32) -> bool {
3 <= a && a <= 20
}
+#[clippy::msrv = "1.34"]
fn msrv_1_34() {
- #![clippy::msrv = "1.34"]
-
let x = 5;
x >= 8 && x < 34;
}
+#[clippy::msrv = "1.35"]
fn msrv_1_35() {
- #![clippy::msrv = "1.35"]
-
let x = 5;
x >= 8 && x < 35;
}
diff --git a/src/tools/clippy/tests/ui/range_contains.stderr b/src/tools/clippy/tests/ui/range_contains.stderr
index 9689e665b..ea34023a4 100644
--- a/src/tools/clippy/tests/ui/range_contains.stderr
+++ b/src/tools/clippy/tests/ui/range_contains.stderr
@@ -1,5 +1,5 @@
error: manual `Range::contains` implementation
- --> $DIR/range_contains.rs:14:5
+ --> $DIR/range_contains.rs:13:5
|
LL | x >= 8 && x < 12;
| ^^^^^^^^^^^^^^^^ help: use: `(8..12).contains(&x)`
@@ -7,121 +7,121 @@ LL | x >= 8 && x < 12;
= note: `-D clippy::manual-range-contains` implied by `-D warnings`
error: manual `Range::contains` implementation
- --> $DIR/range_contains.rs:15:5
+ --> $DIR/range_contains.rs:14:5
|
LL | x < 42 && x >= 21;
| ^^^^^^^^^^^^^^^^^ help: use: `(21..42).contains(&x)`
error: manual `Range::contains` implementation
- --> $DIR/range_contains.rs:16:5
+ --> $DIR/range_contains.rs:15:5
|
LL | 100 > x && 1 <= x;
| ^^^^^^^^^^^^^^^^^ help: use: `(1..100).contains(&x)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:19:5
+ --> $DIR/range_contains.rs:18:5
|
LL | x >= 9 && x <= 99;
| ^^^^^^^^^^^^^^^^^ help: use: `(9..=99).contains(&x)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:20:5
+ --> $DIR/range_contains.rs:19:5
|
LL | x <= 33 && x >= 1;
| ^^^^^^^^^^^^^^^^^ help: use: `(1..=33).contains(&x)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:21:5
+ --> $DIR/range_contains.rs:20:5
|
LL | 999 >= x && 1 <= x;
| ^^^^^^^^^^^^^^^^^^ help: use: `(1..=999).contains(&x)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:24:5
+ --> $DIR/range_contains.rs:23:5
|
LL | x < 8 || x >= 12;
| ^^^^^^^^^^^^^^^^ help: use: `!(8..12).contains(&x)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:25:5
+ --> $DIR/range_contains.rs:24:5
|
LL | x >= 42 || x < 21;
| ^^^^^^^^^^^^^^^^^ help: use: `!(21..42).contains(&x)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:26:5
+ --> $DIR/range_contains.rs:25:5
|
LL | 100 <= x || 1 > x;
| ^^^^^^^^^^^^^^^^^ help: use: `!(1..100).contains(&x)`
error: manual `!RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:29:5
+ --> $DIR/range_contains.rs:28:5
|
LL | x < 9 || x > 99;
| ^^^^^^^^^^^^^^^ help: use: `!(9..=99).contains(&x)`
error: manual `!RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:30:5
+ --> $DIR/range_contains.rs:29:5
|
LL | x > 33 || x < 1;
| ^^^^^^^^^^^^^^^ help: use: `!(1..=33).contains(&x)`
error: manual `!RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:31:5
+ --> $DIR/range_contains.rs:30:5
|
LL | 999 < x || 1 > x;
| ^^^^^^^^^^^^^^^^ help: use: `!(1..=999).contains(&x)`
error: manual `Range::contains` implementation
- --> $DIR/range_contains.rs:46:5
+ --> $DIR/range_contains.rs:45:5
|
LL | y >= 0. && y < 1.;
| ^^^^^^^^^^^^^^^^^ help: use: `(0. ..1.).contains(&y)`
error: manual `!RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:47:5
+ --> $DIR/range_contains.rs:46:5
|
LL | y < 0. || y > 1.;
| ^^^^^^^^^^^^^^^^ help: use: `!(0. ..=1.).contains(&y)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:50:5
+ --> $DIR/range_contains.rs:49:5
|
LL | x >= -10 && x <= 10;
| ^^^^^^^^^^^^^^^^^^^ help: use: `(-10..=10).contains(&x)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:52:5
+ --> $DIR/range_contains.rs:51:5
|
LL | y >= -3. && y <= 3.;
| ^^^^^^^^^^^^^^^^^^^ help: use: `(-3. ..=3.).contains(&y)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:57:30
+ --> $DIR/range_contains.rs:56:30
|
LL | (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10);
| ^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=10).contains(&z)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:57:5
+ --> $DIR/range_contains.rs:56:5
|
LL | (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10);
| ^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=10).contains(&x)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:58:29
+ --> $DIR/range_contains.rs:57:29
|
LL | (x < 0) || (x >= 10) || (z < 0) || (z >= 10);
| ^^^^^^^^^^^^^^^^^^^^ help: use: `!(0..10).contains(&z)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:58:5
+ --> $DIR/range_contains.rs:57:5
|
LL | (x < 0) || (x >= 10) || (z < 0) || (z >= 10);
| ^^^^^^^^^^^^^^^^^^^^ help: use: `!(0..10).contains(&x)`
error: manual `Range::contains` implementation
- --> $DIR/range_contains.rs:79:5
+ --> $DIR/range_contains.rs:76:5
|
LL | x >= 8 && x < 35;
| ^^^^^^^^^^^^^^^^ help: use: `(8..35).contains(&x)`
diff --git a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed
index 7cd687c95..c0e49ff4c 100644
--- a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed
+++ b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.fixed
@@ -25,4 +25,16 @@ fn main() {
x * y
};
let d = async { something().await };
+
+ macro_rules! m {
+ () => {
+ 0
+ };
+ }
+ macro_rules! m2 {
+ () => {
+ m!()
+ };
+ }
+ m2!();
}
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 37e4d2238..9e6e54348 100644
--- a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs
+++ b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.rs
@@ -25,4 +25,16 @@ fn main() {
x * y
})();
let d = (async || something().await)();
+
+ macro_rules! m {
+ () => {
+ (|| 0)()
+ };
+ }
+ macro_rules! m2 {
+ () => {
+ (|| m!())()
+ };
+ }
+ m2!();
}
diff --git a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.stderr b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.stderr
index 56a8e57c0..d71bcba2a 100644
--- a/src/tools/clippy/tests/ui/redundant_closure_call_fixable.stderr
+++ b/src/tools/clippy/tests/ui/redundant_closure_call_fixable.stderr
@@ -52,5 +52,27 @@ error: try not to call a closure in the expression where it is declared
LL | let d = (async || something().await)();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try doing something like: `async { something().await }`
-error: aborting due to 4 previous errors
+error: try not to call a closure in the expression where it is declared
+ --> $DIR/redundant_closure_call_fixable.rs:36:13
+ |
+LL | (|| m!())()
+ | ^^^^^^^^^^^ help: try doing something like: `m!()`
+...
+LL | m2!();
+ | ----- in this macro invocation
+ |
+ = note: this error originates in the macro `m2` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: try not to call a closure in the expression where it is declared
+ --> $DIR/redundant_closure_call_fixable.rs:31:13
+ |
+LL | (|| 0)()
+ | ^^^^^^^^ help: try doing something like: `0`
+...
+LL | m2!();
+ | ----- in this macro invocation
+ |
+ = note: this error originates in the macro `m` which comes from the expansion of the macro `m2` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 6 previous errors
diff --git a/src/tools/clippy/tests/ui/redundant_field_names.fixed b/src/tools/clippy/tests/ui/redundant_field_names.fixed
index 34ab552cb..ec7f8ae92 100644
--- a/src/tools/clippy/tests/ui/redundant_field_names.fixed
+++ b/src/tools/clippy/tests/ui/redundant_field_names.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::redundant_field_names)]
#![allow(clippy::no_effect, dead_code, unused_variables)]
@@ -72,16 +71,14 @@ fn issue_3476() {
S { foo: foo::<i32> };
}
+#[clippy::msrv = "1.16"]
fn msrv_1_16() {
- #![clippy::msrv = "1.16"]
-
let start = 0;
let _ = RangeFrom { start: start };
}
+#[clippy::msrv = "1.17"]
fn msrv_1_17() {
- #![clippy::msrv = "1.17"]
-
let start = 0;
let _ = RangeFrom { start };
}
diff --git a/src/tools/clippy/tests/ui/redundant_field_names.rs b/src/tools/clippy/tests/ui/redundant_field_names.rs
index a051b1f96..73122016c 100644
--- a/src/tools/clippy/tests/ui/redundant_field_names.rs
+++ b/src/tools/clippy/tests/ui/redundant_field_names.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::redundant_field_names)]
#![allow(clippy::no_effect, dead_code, unused_variables)]
@@ -72,16 +71,14 @@ fn issue_3476() {
S { foo: foo::<i32> };
}
+#[clippy::msrv = "1.16"]
fn msrv_1_16() {
- #![clippy::msrv = "1.16"]
-
let start = 0;
let _ = RangeFrom { start: start };
}
+#[clippy::msrv = "1.17"]
fn msrv_1_17() {
- #![clippy::msrv = "1.17"]
-
let start = 0;
let _ = RangeFrom { start: start };
}
diff --git a/src/tools/clippy/tests/ui/redundant_field_names.stderr b/src/tools/clippy/tests/ui/redundant_field_names.stderr
index 8b82e062b..00a72c50c 100644
--- a/src/tools/clippy/tests/ui/redundant_field_names.stderr
+++ b/src/tools/clippy/tests/ui/redundant_field_names.stderr
@@ -1,5 +1,5 @@
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:36:9
+ --> $DIR/redundant_field_names.rs:35:9
|
LL | gender: gender,
| ^^^^^^^^^^^^^^ help: replace it with: `gender`
@@ -7,43 +7,43 @@ LL | gender: gender,
= note: `-D clippy::redundant-field-names` implied by `-D warnings`
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:37:9
+ --> $DIR/redundant_field_names.rs:36:9
|
LL | age: age,
| ^^^^^^^^ help: replace it with: `age`
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:58:25
+ --> $DIR/redundant_field_names.rs:57:25
|
LL | let _ = RangeFrom { start: start };
| ^^^^^^^^^^^^ help: replace it with: `start`
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:59:23
+ --> $DIR/redundant_field_names.rs:58:23
|
LL | let _ = RangeTo { end: end };
| ^^^^^^^^ help: replace it with: `end`
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:60:21
+ --> $DIR/redundant_field_names.rs:59:21
|
LL | let _ = Range { start: start, end: end };
| ^^^^^^^^^^^^ help: replace it with: `start`
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:60:35
+ --> $DIR/redundant_field_names.rs:59:35
|
LL | let _ = Range { start: start, end: end };
| ^^^^^^^^ help: replace it with: `end`
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:62:32
+ --> $DIR/redundant_field_names.rs:61:32
|
LL | let _ = RangeToInclusive { end: end };
| ^^^^^^^^ help: replace it with: `end`
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:86:25
+ --> $DIR/redundant_field_names.rs:83:25
|
LL | let _ = RangeFrom { start: start };
| ^^^^^^^^^^^^ help: replace it with: `start`
diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed b/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
index 42110dbe8..4c5846fe8 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![allow(unused)]
#[derive(Debug)]
@@ -56,14 +55,12 @@ impl Bar for Foo {
const TRAIT_VAR: &'static str = "foo";
}
+#[clippy::msrv = "1.16"]
fn msrv_1_16() {
- #![clippy::msrv = "1.16"]
-
static V: &'static u8 = &16;
}
+#[clippy::msrv = "1.17"]
fn msrv_1_17() {
- #![clippy::msrv = "1.17"]
-
static V: &u8 = &17;
}
diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs b/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
index bc5200bc8..64a66be1a 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![allow(unused)]
#[derive(Debug)]
@@ -56,14 +55,12 @@ impl Bar for Foo {
const TRAIT_VAR: &'static str = "foo";
}
+#[clippy::msrv = "1.16"]
fn msrv_1_16() {
- #![clippy::msrv = "1.16"]
-
static V: &'static u8 = &16;
}
+#[clippy::msrv = "1.17"]
fn msrv_1_17() {
- #![clippy::msrv = "1.17"]
-
static V: &'static u8 = &17;
}
diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr b/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr
index 735113460..0938ebf78 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr
@@ -1,5 +1,5 @@
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:9:17
+ --> $DIR/redundant_static_lifetimes.rs:8:17
|
LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static.
| -^^^^^^^---- help: consider removing `'static`: `&str`
@@ -7,97 +7,97 @@ LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removin
= note: `-D clippy::redundant-static-lifetimes` implied by `-D warnings`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:13:21
+ --> $DIR/redundant_static_lifetimes.rs:12:21
|
LL | const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
| -^^^^^^^---- help: consider removing `'static`: `&str`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:15:32
+ --> $DIR/redundant_static_lifetimes.rs:14:32
|
LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
| -^^^^^^^---- help: consider removing `'static`: `&str`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:15:47
+ --> $DIR/redundant_static_lifetimes.rs:14:47
|
LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
| -^^^^^^^---- help: consider removing `'static`: `&str`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:17:17
+ --> $DIR/redundant_static_lifetimes.rs:16:17
|
LL | const VAR_SIX: &'static u8 = &5;
| -^^^^^^^--- help: consider removing `'static`: `&u8`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:19:20
+ --> $DIR/redundant_static_lifetimes.rs:18:20
|
LL | const VAR_HEIGHT: &'static Foo = &Foo {};
| -^^^^^^^---- help: consider removing `'static`: `&Foo`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:21:19
+ --> $DIR/redundant_static_lifetimes.rs:20:19
|
LL | const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR Consider removing 'static.
| -^^^^^^^----- help: consider removing `'static`: `&[u8]`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:23:19
+ --> $DIR/redundant_static_lifetimes.rs:22:19
|
LL | const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static.
| -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:25:19
+ --> $DIR/redundant_static_lifetimes.rs:24:19
|
LL | const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:27:25
+ --> $DIR/redundant_static_lifetimes.rs:26:25
|
LL | static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR Consider removing 'static.
| -^^^^^^^---- help: consider removing `'static`: `&str`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:31:29
+ --> $DIR/redundant_static_lifetimes.rs:30:29
|
LL | static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
| -^^^^^^^---- help: consider removing `'static`: `&str`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:33:25
+ --> $DIR/redundant_static_lifetimes.rs:32:25
|
LL | static STATIC_VAR_SIX: &'static u8 = &5;
| -^^^^^^^--- help: consider removing `'static`: `&u8`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:35:28
+ --> $DIR/redundant_static_lifetimes.rs:34:28
|
LL | static STATIC_VAR_HEIGHT: &'static Foo = &Foo {};
| -^^^^^^^---- help: consider removing `'static`: `&Foo`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:37:27
+ --> $DIR/redundant_static_lifetimes.rs:36:27
|
LL | static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR Consider removing 'static.
| -^^^^^^^----- help: consider removing `'static`: `&[u8]`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:39:27
+ --> $DIR/redundant_static_lifetimes.rs:38:27
|
LL | static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static.
| -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:41:27
+ --> $DIR/redundant_static_lifetimes.rs:40:27
|
LL | static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:68:16
+ --> $DIR/redundant_static_lifetimes.rs:65:16
|
LL | static V: &'static u8 = &17;
| -^^^^^^^--- help: consider removing `'static`: `&u8`
diff --git a/src/tools/clippy/tests/ui/rename.fixed b/src/tools/clippy/tests/ui/rename.fixed
index 8beae8dee..689928f04 100644
--- a/src/tools/clippy/tests/ui/rename.fixed
+++ b/src/tools/clippy/tests/ui/rename.fixed
@@ -12,7 +12,6 @@
#![allow(clippy::disallowed_methods)]
#![allow(clippy::disallowed_types)]
#![allow(clippy::mixed_read_write_in_expression)]
-#![allow(for_loops_over_fallibles)]
#![allow(clippy::useless_conversion)]
#![allow(clippy::match_result_ok)]
#![allow(clippy::overly_complex_bool_expr)]
@@ -27,9 +26,11 @@
#![allow(clippy::recursive_format_impl)]
#![allow(clippy::invisible_characters)]
#![allow(drop_bounds)]
+#![allow(for_loops_over_fallibles)]
#![allow(array_into_iter)]
#![allow(invalid_atomic_ordering)]
#![allow(invalid_value)]
+#![allow(let_underscore_drop)]
#![allow(enum_intrinsics_non_enums)]
#![allow(non_fmt_panics)]
#![allow(named_arguments_used_positionally)]
@@ -45,8 +46,6 @@
#![warn(clippy::disallowed_methods)]
#![warn(clippy::disallowed_types)]
#![warn(clippy::mixed_read_write_in_expression)]
-#![warn(for_loops_over_fallibles)]
-#![warn(for_loops_over_fallibles)]
#![warn(clippy::useless_conversion)]
#![warn(clippy::match_result_ok)]
#![warn(clippy::overly_complex_bool_expr)]
@@ -66,9 +65,12 @@
#![warn(clippy::invisible_characters)]
#![warn(drop_bounds)]
#![warn(for_loops_over_fallibles)]
+#![warn(for_loops_over_fallibles)]
+#![warn(for_loops_over_fallibles)]
#![warn(array_into_iter)]
#![warn(invalid_atomic_ordering)]
#![warn(invalid_value)]
+#![warn(let_underscore_drop)]
#![warn(enum_intrinsics_non_enums)]
#![warn(non_fmt_panics)]
#![warn(named_arguments_used_positionally)]
diff --git a/src/tools/clippy/tests/ui/rename.rs b/src/tools/clippy/tests/ui/rename.rs
index 9e665047b..b74aa650f 100644
--- a/src/tools/clippy/tests/ui/rename.rs
+++ b/src/tools/clippy/tests/ui/rename.rs
@@ -12,7 +12,6 @@
#![allow(clippy::disallowed_methods)]
#![allow(clippy::disallowed_types)]
#![allow(clippy::mixed_read_write_in_expression)]
-#![allow(for_loops_over_fallibles)]
#![allow(clippy::useless_conversion)]
#![allow(clippy::match_result_ok)]
#![allow(clippy::overly_complex_bool_expr)]
@@ -27,9 +26,11 @@
#![allow(clippy::recursive_format_impl)]
#![allow(clippy::invisible_characters)]
#![allow(drop_bounds)]
+#![allow(for_loops_over_fallibles)]
#![allow(array_into_iter)]
#![allow(invalid_atomic_ordering)]
#![allow(invalid_value)]
+#![allow(let_underscore_drop)]
#![allow(enum_intrinsics_non_enums)]
#![allow(non_fmt_panics)]
#![allow(named_arguments_used_positionally)]
@@ -45,8 +46,6 @@
#![warn(clippy::disallowed_method)]
#![warn(clippy::disallowed_type)]
#![warn(clippy::eval_order_dependence)]
-#![warn(clippy::for_loop_over_option)]
-#![warn(clippy::for_loop_over_result)]
#![warn(clippy::identity_conversion)]
#![warn(clippy::if_let_some_result)]
#![warn(clippy::logic_bug)]
@@ -65,10 +64,13 @@
#![warn(clippy::to_string_in_display)]
#![warn(clippy::zero_width_space)]
#![warn(clippy::drop_bounds)]
+#![warn(clippy::for_loop_over_option)]
+#![warn(clippy::for_loop_over_result)]
#![warn(clippy::for_loops_over_fallibles)]
#![warn(clippy::into_iter_on_array)]
#![warn(clippy::invalid_atomic_ordering)]
#![warn(clippy::invalid_ref)]
+#![warn(clippy::let_underscore_drop)]
#![warn(clippy::mem_discriminant_non_enum)]
#![warn(clippy::panic_params)]
#![warn(clippy::positional_named_format_parameters)]
diff --git a/src/tools/clippy/tests/ui/rename.stderr b/src/tools/clippy/tests/ui/rename.stderr
index 63eb56518..622a32c59 100644
--- a/src/tools/clippy/tests/ui/rename.stderr
+++ b/src/tools/clippy/tests/ui/rename.stderr
@@ -1,5 +1,5 @@
error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names`
- --> $DIR/rename.rs:39:9
+ --> $DIR/rename.rs:40:9
|
LL | #![warn(clippy::blacklisted_name)]
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names`
@@ -7,232 +7,238 @@ LL | #![warn(clippy::blacklisted_name)]
= note: `-D renamed-and-removed-lints` implied by `-D warnings`
error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions`
- --> $DIR/rename.rs:40:9
+ --> $DIR/rename.rs:41: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:41:9
+ --> $DIR/rename.rs:42: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:42:9
+ --> $DIR/rename.rs:43: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:43:9
+ --> $DIR/rename.rs:44: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:44:9
+ --> $DIR/rename.rs:45:9
|
LL | #![warn(clippy::cyclomatic_complexity)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity`
error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods`
- --> $DIR/rename.rs:45:9
+ --> $DIR/rename.rs:46: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:46:9
+ --> $DIR/rename.rs:47: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:47:9
+ --> $DIR/rename.rs:48:9
|
LL | #![warn(clippy::eval_order_dependence)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression`
-error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles`
- --> $DIR/rename.rs:48: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:49:9
- |
-LL | #![warn(clippy::for_loop_over_result)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles`
-
error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion`
- --> $DIR/rename.rs:50:9
+ --> $DIR/rename.rs:49: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:51:9
+ --> $DIR/rename.rs:50:9
|
LL | #![warn(clippy::if_let_some_result)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok`
error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr`
- --> $DIR/rename.rs:52:9
+ --> $DIR/rename.rs:51: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:53:9
+ --> $DIR/rename.rs:52: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:54:9
+ --> $DIR/rename.rs:53: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:55:9
+ --> $DIR/rename.rs:54: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:56:9
+ --> $DIR/rename.rs:55: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:57:9
+ --> $DIR/rename.rs:56: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:58:9
+ --> $DIR/rename.rs:57: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:59:9
+ --> $DIR/rename.rs:58: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:60:9
+ --> $DIR/rename.rs:59: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:61:9
+ --> $DIR/rename.rs:60: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:62:9
+ --> $DIR/rename.rs:61: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:63:9
+ --> $DIR/rename.rs:62: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:64:9
+ --> $DIR/rename.rs:63: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:65:9
+ --> $DIR/rename.rs:64: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:66:9
+ --> $DIR/rename.rs:65:9
|
LL | #![warn(clippy::zero_width_space)]
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters`
error: lint `clippy::drop_bounds` has been renamed to `drop_bounds`
- --> $DIR/rename.rs:67:9
+ --> $DIR/rename.rs:66:9
|
LL | #![warn(clippy::drop_bounds)]
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds`
-error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles`
+error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles`
+ --> $DIR/rename.rs:67: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:68: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:69:9
+ |
LL | #![warn(clippy::for_loops_over_fallibles)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles`
error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter`
- --> $DIR/rename.rs:69:9
+ --> $DIR/rename.rs:70: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:70:9
+ --> $DIR/rename.rs:71: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:71:9
+ --> $DIR/rename.rs:72: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:73: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:72:9
+ --> $DIR/rename.rs:74: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:73:9
+ --> $DIR/rename.rs:75: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:74:9
+ --> $DIR/rename.rs:76: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:75:9
+ --> $DIR/rename.rs:77: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:76:9
+ --> $DIR/rename.rs:78: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:77:9
+ --> $DIR/rename.rs:79:9
|
LL | #![warn(clippy::unused_label)]
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels`
-error: aborting due to 39 previous errors
+error: aborting due to 40 previous errors
diff --git a/src/tools/clippy/tests/ui/result_large_err.rs b/src/tools/clippy/tests/ui/result_large_err.rs
index f7df3b856..1c12cebfd 100644
--- a/src/tools/clippy/tests/ui/result_large_err.rs
+++ b/src/tools/clippy/tests/ui/result_large_err.rs
@@ -50,6 +50,18 @@ impl LargeErrorVariants<()> {
}
}
+enum MultipleLargeVariants {
+ _Biggest([u8; 1024]),
+ _AlsoBig([u8; 512]),
+ _Ok(usize),
+}
+
+impl MultipleLargeVariants {
+ fn large_enum_error() -> Result<(), Self> {
+ Ok(())
+ }
+}
+
trait TraitForcesLargeError {
fn large_error() -> Result<(), [u8; 512]> {
Ok(())
@@ -96,4 +108,10 @@ pub fn array_error<T, U>() -> Result<(), ArrayError<(i32, T), U>> {
Ok(())
}
+// Issue #10005
+enum Empty {}
+fn _empty_error() -> Result<(), Empty> {
+ Ok(())
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/result_large_err.stderr b/src/tools/clippy/tests/ui/result_large_err.stderr
index bea101fe2..c386edfd2 100644
--- a/src/tools/clippy/tests/ui/result_large_err.stderr
+++ b/src/tools/clippy/tests/ui/result_large_err.stderr
@@ -42,13 +42,29 @@ LL | pub fn param_large_error<R>() -> Result<(), (u128, R, FullyDefinedLargeErro
error: the `Err`-variant returned from this function is very large
--> $DIR/result_large_err.rs:48:34
|
+LL | _Omg([u8; 512]),
+ | --------------- the largest variant contains at least 512 bytes
+...
LL | pub fn large_enum_error() -> Result<(), Self> {
- | ^^^^^^^^^^^^^^^^ the `Err`-variant is at least 513 bytes
+ | ^^^^^^^^^^^^^^^^
|
= help: try reducing the size of `LargeErrorVariants<()>`, for example by boxing large elements or replacing it with `Box<LargeErrorVariants<()>>`
error: the `Err`-variant returned from this function is very large
- --> $DIR/result_large_err.rs:54:25
+ --> $DIR/result_large_err.rs:60:30
+ |
+LL | _Biggest([u8; 1024]),
+ | -------------------- the largest variant contains at least 1024 bytes
+LL | _AlsoBig([u8; 512]),
+ | ------------------- the variant `_AlsoBig` contains at least 512 bytes
+...
+LL | fn large_enum_error() -> Result<(), Self> {
+ | ^^^^^^^^^^^^^^^^
+ |
+ = help: try reducing the size of `MultipleLargeVariants`, for example by boxing large elements or replacing it with `Box<MultipleLargeVariants>`
+
+error: the `Err`-variant returned from this function is very large
+ --> $DIR/result_large_err.rs:66:25
|
LL | fn large_error() -> Result<(), [u8; 512]> {
| ^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes
@@ -56,7 +72,7 @@ LL | fn large_error() -> Result<(), [u8; 512]> {
= help: try reducing the size of `[u8; 512]`, for example by boxing large elements or replacing it with `Box<[u8; 512]>`
error: the `Err`-variant returned from this function is very large
- --> $DIR/result_large_err.rs:73:29
+ --> $DIR/result_large_err.rs:85:29
|
LL | pub fn large_union_err() -> Result<(), FullyDefinedUnionError> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes
@@ -64,7 +80,7 @@ LL | pub fn large_union_err() -> Result<(), FullyDefinedUnionError> {
= help: try reducing the size of `FullyDefinedUnionError`, for example by boxing large elements or replacing it with `Box<FullyDefinedUnionError>`
error: the `Err`-variant returned from this function is very large
- --> $DIR/result_large_err.rs:82:40
+ --> $DIR/result_large_err.rs:94:40
|
LL | pub fn param_large_union<T: Copy>() -> Result<(), UnionError<T>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes
@@ -72,7 +88,7 @@ LL | pub fn param_large_union<T: Copy>() -> Result<(), UnionError<T>> {
= help: try reducing the size of `UnionError<T>`, for example by boxing large elements or replacing it with `Box<UnionError<T>>`
error: the `Err`-variant returned from this function is very large
- --> $DIR/result_large_err.rs:91:34
+ --> $DIR/result_large_err.rs:103:34
|
LL | pub fn array_error_subst<U>() -> Result<(), ArrayError<i32, U>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 128 bytes
@@ -80,12 +96,12 @@ LL | pub fn array_error_subst<U>() -> Result<(), ArrayError<i32, U>> {
= help: try reducing the size of `ArrayError<i32, U>`, for example by boxing large elements or replacing it with `Box<ArrayError<i32, U>>`
error: the `Err`-variant returned from this function is very large
- --> $DIR/result_large_err.rs:95:31
+ --> $DIR/result_large_err.rs:107:31
|
LL | pub fn array_error<T, U>() -> Result<(), ArrayError<(i32, T), U>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 128 bytes
|
= help: try reducing the size of `ArrayError<(i32, T), U>`, for example by boxing large elements or replacing it with `Box<ArrayError<(i32, T), U>>`
-error: aborting due to 11 previous errors
+error: aborting due to 12 previous errors
diff --git a/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr b/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr
index 88e4efdb0..2e1eb8eb1 100644
--- a/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr
+++ b/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr
@@ -20,14 +20,14 @@ error: called `map(f)` on an `Result` value where `f` is a closure that returns
--> $DIR/result_map_unit_fn_unfixable.rs:29:5
|
LL | x.field.map(|value| {
- | _____^
- | |_____|
+ | ______^
+ | | _____|
| ||
LL | || do_nothing(value);
LL | || do_nothing(value)
LL | || });
| ||______^- help: try this: `if let Ok(value) = x.field { ... }`
- | |_______|
+ | |______|
|
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
diff --git a/src/tools/clippy/tests/ui/seek_from_current.fixed b/src/tools/clippy/tests/ui/seek_from_current.fixed
new file mode 100644
index 000000000..1309c91b8
--- /dev/null
+++ b/src/tools/clippy/tests/ui/seek_from_current.fixed
@@ -0,0 +1,25 @@
+// run-rustfix
+#![warn(clippy::seek_from_current)]
+
+use std::fs::File;
+use std::io::{self, Seek, SeekFrom, Write};
+
+#[clippy::msrv = "1.50"]
+fn _msrv_1_50() -> io::Result<()> {
+ let mut f = File::create("foo.txt")?;
+ f.write_all(b"Hi!")?;
+ f.seek(SeekFrom::Current(0))?;
+ f.seek(SeekFrom::Current(1))?;
+ Ok(())
+}
+
+#[clippy::msrv = "1.51"]
+fn _msrv_1_51() -> io::Result<()> {
+ let mut f = File::create("foo.txt")?;
+ f.write_all(b"Hi!")?;
+ f.stream_position()?;
+ f.seek(SeekFrom::Current(1))?;
+ Ok(())
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/seek_from_current.rs b/src/tools/clippy/tests/ui/seek_from_current.rs
new file mode 100644
index 000000000..5d9b1424c
--- /dev/null
+++ b/src/tools/clippy/tests/ui/seek_from_current.rs
@@ -0,0 +1,25 @@
+// run-rustfix
+#![warn(clippy::seek_from_current)]
+
+use std::fs::File;
+use std::io::{self, Seek, SeekFrom, Write};
+
+#[clippy::msrv = "1.50"]
+fn _msrv_1_50() -> io::Result<()> {
+ let mut f = File::create("foo.txt")?;
+ f.write_all(b"Hi!")?;
+ f.seek(SeekFrom::Current(0))?;
+ f.seek(SeekFrom::Current(1))?;
+ Ok(())
+}
+
+#[clippy::msrv = "1.51"]
+fn _msrv_1_51() -> io::Result<()> {
+ let mut f = File::create("foo.txt")?;
+ f.write_all(b"Hi!")?;
+ f.seek(SeekFrom::Current(0))?;
+ f.seek(SeekFrom::Current(1))?;
+ Ok(())
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/seek_from_current.stderr b/src/tools/clippy/tests/ui/seek_from_current.stderr
new file mode 100644
index 000000000..c079f3611
--- /dev/null
+++ b/src/tools/clippy/tests/ui/seek_from_current.stderr
@@ -0,0 +1,10 @@
+error: using `SeekFrom::Current` to start from current position
+ --> $DIR/seek_from_current.rs:20:5
+ |
+LL | f.seek(SeekFrom::Current(0))?;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `f.stream_position()`
+ |
+ = note: `-D clippy::seek-from-current` implied by `-D warnings`
+
+error: aborting due to previous error
+
diff --git a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed
new file mode 100644
index 000000000..9d0d1124c
--- /dev/null
+++ b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed
@@ -0,0 +1,134 @@
+// run-rustfix
+#![allow(unused)]
+#![warn(clippy::seek_to_start_instead_of_rewind)]
+
+use std::fs::OpenOptions;
+use std::io::{Read, Seek, SeekFrom, Write};
+
+struct StructWithSeekMethod {}
+
+impl StructWithSeekMethod {
+ fn seek(&mut self, from: SeekFrom) {}
+}
+
+trait MySeekTrait {
+ fn seek(&mut self, from: SeekFrom) {}
+}
+
+struct StructWithSeekTrait {}
+impl MySeekTrait for StructWithSeekTrait {}
+
+// This should NOT trigger clippy warning because
+// StructWithSeekMethod does not implement std::io::Seek;
+fn seek_to_start_false_method(t: &mut StructWithSeekMethod) {
+ t.seek(SeekFrom::Start(0));
+}
+
+// This should NOT trigger clippy warning because
+// StructWithSeekMethod does not implement std::io::Seek;
+fn seek_to_start_method_owned_false<T>(mut t: StructWithSeekMethod) {
+ t.seek(SeekFrom::Start(0));
+}
+
+// This should NOT trigger clippy warning because
+// StructWithSeekMethod does not implement std::io::Seek;
+fn seek_to_start_false_trait(t: &mut StructWithSeekTrait) {
+ t.seek(SeekFrom::Start(0));
+}
+
+// This should NOT trigger clippy warning because
+// StructWithSeekMethod does not implement std::io::Seek;
+fn seek_to_start_false_trait_owned<T>(mut t: StructWithSeekTrait) {
+ t.seek(SeekFrom::Start(0));
+}
+
+// This should NOT trigger clippy warning because
+// StructWithSeekMethod does not implement std::io::Seek;
+fn seek_to_start_false_trait_bound<T: MySeekTrait>(t: &mut T) {
+ t.seek(SeekFrom::Start(0));
+}
+
+// This should trigger clippy warning
+fn seek_to_start<T: Seek>(t: &mut T) {
+ t.rewind();
+}
+
+// This should trigger clippy warning
+fn owned_seek_to_start<T: Seek>(mut t: T) {
+ t.rewind();
+}
+
+// This should NOT trigger clippy warning because
+// it does not seek to start
+fn seek_to_5<T: Seek>(t: &mut T) {
+ t.seek(SeekFrom::Start(5));
+}
+
+// This should NOT trigger clippy warning because
+// it does not seek to start
+fn seek_to_end<T: Seek>(t: &mut T) {
+ t.seek(SeekFrom::End(0));
+}
+
+fn main() {
+ let mut f = OpenOptions::new()
+ .write(true)
+ .read(true)
+ .create(true)
+ .open("foo.txt")
+ .unwrap();
+
+ let mut my_struct_trait = StructWithSeekTrait {};
+ seek_to_start_false_trait_bound(&mut my_struct_trait);
+
+ let hello = "Hello!\n";
+ write!(f, "{hello}").unwrap();
+ seek_to_5(&mut f);
+ seek_to_end(&mut f);
+ seek_to_start(&mut f);
+
+ let mut buf = String::new();
+ f.read_to_string(&mut buf).unwrap();
+
+ assert_eq!(&buf, hello);
+}
+
+#[clippy::msrv = "1.54"]
+fn msrv_1_54() {
+ let mut f = OpenOptions::new()
+ .write(true)
+ .read(true)
+ .create(true)
+ .open("foo.txt")
+ .unwrap();
+
+ let hello = "Hello!\n";
+ write!(f, "{hello}").unwrap();
+
+ f.seek(SeekFrom::Start(0));
+
+ let mut buf = String::new();
+ f.read_to_string(&mut buf).unwrap();
+
+ assert_eq!(&buf, hello);
+}
+
+#[clippy::msrv = "1.55"]
+fn msrv_1_55() {
+ let mut f = OpenOptions::new()
+ .write(true)
+ .read(true)
+ .create(true)
+ .open("foo.txt")
+ .unwrap();
+
+ let hello = "Hello!\n";
+ write!(f, "{hello}").unwrap();
+
+ f.rewind();
+
+ let mut buf = String::new();
+ f.read_to_string(&mut buf).unwrap();
+
+ assert_eq!(&buf, hello);
+}
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
new file mode 100644
index 000000000..c5bc57cc3
--- /dev/null
+++ b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs
@@ -0,0 +1,134 @@
+// run-rustfix
+#![allow(unused)]
+#![warn(clippy::seek_to_start_instead_of_rewind)]
+
+use std::fs::OpenOptions;
+use std::io::{Read, Seek, SeekFrom, Write};
+
+struct StructWithSeekMethod {}
+
+impl StructWithSeekMethod {
+ fn seek(&mut self, from: SeekFrom) {}
+}
+
+trait MySeekTrait {
+ fn seek(&mut self, from: SeekFrom) {}
+}
+
+struct StructWithSeekTrait {}
+impl MySeekTrait for StructWithSeekTrait {}
+
+// This should NOT trigger clippy warning because
+// StructWithSeekMethod does not implement std::io::Seek;
+fn seek_to_start_false_method(t: &mut StructWithSeekMethod) {
+ t.seek(SeekFrom::Start(0));
+}
+
+// This should NOT trigger clippy warning because
+// StructWithSeekMethod does not implement std::io::Seek;
+fn seek_to_start_method_owned_false<T>(mut t: StructWithSeekMethod) {
+ t.seek(SeekFrom::Start(0));
+}
+
+// This should NOT trigger clippy warning because
+// StructWithSeekMethod does not implement std::io::Seek;
+fn seek_to_start_false_trait(t: &mut StructWithSeekTrait) {
+ t.seek(SeekFrom::Start(0));
+}
+
+// This should NOT trigger clippy warning because
+// StructWithSeekMethod does not implement std::io::Seek;
+fn seek_to_start_false_trait_owned<T>(mut t: StructWithSeekTrait) {
+ t.seek(SeekFrom::Start(0));
+}
+
+// This should NOT trigger clippy warning because
+// StructWithSeekMethod does not implement std::io::Seek;
+fn seek_to_start_false_trait_bound<T: MySeekTrait>(t: &mut T) {
+ t.seek(SeekFrom::Start(0));
+}
+
+// This should trigger clippy warning
+fn seek_to_start<T: Seek>(t: &mut T) {
+ t.seek(SeekFrom::Start(0));
+}
+
+// This should trigger clippy warning
+fn owned_seek_to_start<T: Seek>(mut t: T) {
+ t.seek(SeekFrom::Start(0));
+}
+
+// This should NOT trigger clippy warning because
+// it does not seek to start
+fn seek_to_5<T: Seek>(t: &mut T) {
+ t.seek(SeekFrom::Start(5));
+}
+
+// This should NOT trigger clippy warning because
+// it does not seek to start
+fn seek_to_end<T: Seek>(t: &mut T) {
+ t.seek(SeekFrom::End(0));
+}
+
+fn main() {
+ let mut f = OpenOptions::new()
+ .write(true)
+ .read(true)
+ .create(true)
+ .open("foo.txt")
+ .unwrap();
+
+ let mut my_struct_trait = StructWithSeekTrait {};
+ seek_to_start_false_trait_bound(&mut my_struct_trait);
+
+ let hello = "Hello!\n";
+ write!(f, "{hello}").unwrap();
+ seek_to_5(&mut f);
+ seek_to_end(&mut f);
+ seek_to_start(&mut f);
+
+ let mut buf = String::new();
+ f.read_to_string(&mut buf).unwrap();
+
+ assert_eq!(&buf, hello);
+}
+
+#[clippy::msrv = "1.54"]
+fn msrv_1_54() {
+ let mut f = OpenOptions::new()
+ .write(true)
+ .read(true)
+ .create(true)
+ .open("foo.txt")
+ .unwrap();
+
+ let hello = "Hello!\n";
+ write!(f, "{hello}").unwrap();
+
+ f.seek(SeekFrom::Start(0));
+
+ let mut buf = String::new();
+ f.read_to_string(&mut buf).unwrap();
+
+ assert_eq!(&buf, hello);
+}
+
+#[clippy::msrv = "1.55"]
+fn msrv_1_55() {
+ let mut f = OpenOptions::new()
+ .write(true)
+ .read(true)
+ .create(true)
+ .open("foo.txt")
+ .unwrap();
+
+ let hello = "Hello!\n";
+ write!(f, "{hello}").unwrap();
+
+ f.seek(SeekFrom::Start(0));
+
+ let mut buf = String::new();
+ f.read_to_string(&mut buf).unwrap();
+
+ assert_eq!(&buf, hello);
+}
diff --git a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.stderr b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.stderr
new file mode 100644
index 000000000..6cce02535
--- /dev/null
+++ b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.stderr
@@ -0,0 +1,22 @@
+error: used `seek` to go to the start of the stream
+ --> $DIR/seek_to_start_instead_of_rewind.rs:53:7
+ |
+LL | t.seek(SeekFrom::Start(0));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()`
+ |
+ = note: `-D clippy::seek-to-start-instead-of-rewind` implied by `-D warnings`
+
+error: used `seek` to go to the start of the stream
+ --> $DIR/seek_to_start_instead_of_rewind.rs:58:7
+ |
+LL | t.seek(SeekFrom::Start(0));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()`
+
+error: used `seek` to go to the start of the stream
+ --> $DIR/seek_to_start_instead_of_rewind.rs:128:7
+ |
+LL | f.seek(SeekFrom::Start(0));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()`
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/single_component_path_imports.stderr b/src/tools/clippy/tests/ui/single_component_path_imports.stderr
index 509c88ac2..71dcc25d6 100644
--- a/src/tools/clippy/tests/ui/single_component_path_imports.stderr
+++ b/src/tools/clippy/tests/ui/single_component_path_imports.stderr
@@ -1,16 +1,16 @@
error: this import is redundant
- --> $DIR/single_component_path_imports.rs:23:5
+ --> $DIR/single_component_path_imports.rs:5:1
|
-LL | use regex;
- | ^^^^^^^^^^ help: remove it entirely
+LL | use regex;
+ | ^^^^^^^^^^ help: remove it entirely
|
= note: `-D clippy::single-component-path-imports` implied by `-D warnings`
error: this import is redundant
- --> $DIR/single_component_path_imports.rs:5:1
+ --> $DIR/single_component_path_imports.rs:23:5
|
-LL | use regex;
- | ^^^^^^^^^^ help: remove it entirely
+LL | use regex;
+ | ^^^^^^^^^^ help: remove it entirely
error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr b/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr
index 633546f64..330f28520 100644
--- a/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr
+++ b/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr
@@ -1,11 +1,18 @@
error: this import is redundant
+ --> $DIR/single_component_path_imports_nested_first.rs:4:1
+ |
+LL | use regex;
+ | ^^^^^^^^^^ help: remove it entirely
+ |
+ = note: `-D clippy::single-component-path-imports` implied by `-D warnings`
+
+error: this import is redundant
--> $DIR/single_component_path_imports_nested_first.rs:13:10
|
LL | use {regex, serde};
| ^^^^^
|
= help: remove this import
- = note: `-D clippy::single-component-path-imports` implied by `-D warnings`
error: this import is redundant
--> $DIR/single_component_path_imports_nested_first.rs:13:17
@@ -15,11 +22,5 @@ LL | use {regex, serde};
|
= help: remove this import
-error: this import is redundant
- --> $DIR/single_component_path_imports_nested_first.rs:4:1
- |
-LL | use regex;
- | ^^^^^^^^^^ help: remove it entirely
-
error: aborting due to 3 previous errors
diff --git a/src/tools/clippy/tests/ui/string_extend.fixed b/src/tools/clippy/tests/ui/string_extend.fixed
index 1883a9f83..d200d7310 100644
--- a/src/tools/clippy/tests/ui/string_extend.fixed
+++ b/src/tools/clippy/tests/ui/string_extend.fixed
@@ -29,4 +29,7 @@ fn main() {
let f = HasChars;
s.extend(f.chars());
+
+ // issue #9735
+ s.push_str(&abc[0..2]);
}
diff --git a/src/tools/clippy/tests/ui/string_extend.rs b/src/tools/clippy/tests/ui/string_extend.rs
index 07d0baa1b..0dd96a3b2 100644
--- a/src/tools/clippy/tests/ui/string_extend.rs
+++ b/src/tools/clippy/tests/ui/string_extend.rs
@@ -29,4 +29,7 @@ fn main() {
let f = HasChars;
s.extend(f.chars());
+
+ // issue #9735
+ s.extend(abc[0..2].chars());
}
diff --git a/src/tools/clippy/tests/ui/string_extend.stderr b/src/tools/clippy/tests/ui/string_extend.stderr
index 6af8c9e16..b35c77fd9 100644
--- a/src/tools/clippy/tests/ui/string_extend.stderr
+++ b/src/tools/clippy/tests/ui/string_extend.stderr
@@ -18,5 +18,11 @@ error: calling `.extend(_.chars())`
LL | s.extend(def.chars());
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(&def)`
-error: aborting due to 3 previous errors
+error: calling `.extend(_.chars())`
+ --> $DIR/string_extend.rs:34:5
+ |
+LL | s.extend(abc[0..2].chars());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(&abc[0..2])`
+
+error: aborting due to 4 previous errors
diff --git a/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.rs b/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.rs
new file mode 100644
index 000000000..eb9fc63fb
--- /dev/null
+++ b/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.rs
@@ -0,0 +1,34 @@
+#![allow(unused)]
+#![warn(clippy::suspicious_xor_used_as_pow)]
+#![allow(clippy::eq_op)]
+
+macro_rules! macro_test {
+ () => {
+ 13
+ };
+}
+
+macro_rules! macro_test_inside {
+ () => {
+ 1 ^ 2 // should warn even if inside macro
+ };
+}
+
+fn main() {
+ // Should warn:
+ let _ = 2 ^ 5;
+ let _ = 2i32 ^ 9i32;
+ let _ = 2i32 ^ 2i32;
+ let _ = 50i32 ^ 3i32;
+ let _ = 5i32 ^ 8i32;
+ let _ = 2i32 ^ 32i32;
+ macro_test_inside!();
+
+ // Should not warn:
+ let x = 0x02;
+ let _ = x ^ 2;
+ let _ = 2 ^ x;
+ let _ = x ^ 5;
+ let _ = 10 ^ 0b0101;
+ let _ = 2i32 ^ macro_test!();
+}
diff --git a/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr b/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr
new file mode 100644
index 000000000..8bb3c8fbe
--- /dev/null
+++ b/src/tools/clippy/tests/ui/suspicious_xor_used_as_pow.stderr
@@ -0,0 +1,51 @@
+error: `^` is not the exponentiation operator
+ --> $DIR/suspicious_xor_used_as_pow.rs:19:13
+ |
+LL | let _ = 2 ^ 5;
+ | ^^^^^ help: did you mean to write: `2.pow(5)`
+ |
+ = note: `-D clippy::suspicious-xor-used-as-pow` implied by `-D warnings`
+
+error: `^` is not the exponentiation operator
+ --> $DIR/suspicious_xor_used_as_pow.rs:20:13
+ |
+LL | let _ = 2i32 ^ 9i32;
+ | ^^^^^^^^^^^ help: did you mean to write: `2_i32.pow(9_i32)`
+
+error: `^` is not the exponentiation operator
+ --> $DIR/suspicious_xor_used_as_pow.rs:21:13
+ |
+LL | let _ = 2i32 ^ 2i32;
+ | ^^^^^^^^^^^ help: did you mean to write: `2_i32.pow(2_i32)`
+
+error: `^` is not the exponentiation operator
+ --> $DIR/suspicious_xor_used_as_pow.rs:22:13
+ |
+LL | let _ = 50i32 ^ 3i32;
+ | ^^^^^^^^^^^^ help: did you mean to write: `50_i32.pow(3_i32)`
+
+error: `^` is not the exponentiation operator
+ --> $DIR/suspicious_xor_used_as_pow.rs:23:13
+ |
+LL | let _ = 5i32 ^ 8i32;
+ | ^^^^^^^^^^^ help: did you mean to write: `5_i32.pow(8_i32)`
+
+error: `^` is not the exponentiation operator
+ --> $DIR/suspicious_xor_used_as_pow.rs:24:13
+ |
+LL | let _ = 2i32 ^ 32i32;
+ | ^^^^^^^^^^^^ help: did you mean to write: `2_i32.pow(32_i32)`
+
+error: `^` is not the exponentiation operator
+ --> $DIR/suspicious_xor_used_as_pow.rs:13:9
+ |
+LL | 1 ^ 2 // should warn even if inside macro
+ | ^^^^^ help: did you mean to write: `1.pow(2)`
+...
+LL | macro_test_inside!();
+ | -------------------- in this macro invocation
+ |
+ = note: this error originates in the macro `macro_test_inside` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 7 previous errors
+
diff --git a/src/tools/clippy/tests/ui/swap.fixed b/src/tools/clippy/tests/ui/swap.fixed
index 24b229235..805a2ba5a 100644
--- a/src/tools/clippy/tests/ui/swap.fixed
+++ b/src/tools/clippy/tests/ui/swap.fixed
@@ -155,3 +155,12 @@ fn issue_8154() {
let s = S3(&mut s);
std::mem::swap(&mut s.0.x, &mut s.0.y);
}
+
+const fn issue_9864(mut u: u32) -> u32 {
+ let mut v = 10;
+
+ let temp = u;
+ u = v;
+ v = temp;
+ u + v
+}
diff --git a/src/tools/clippy/tests/ui/swap.rs b/src/tools/clippy/tests/ui/swap.rs
index a318c2791..a8c878479 100644
--- a/src/tools/clippy/tests/ui/swap.rs
+++ b/src/tools/clippy/tests/ui/swap.rs
@@ -179,3 +179,12 @@ fn issue_8154() {
s.0.x = s.0.y;
s.0.y = t;
}
+
+const fn issue_9864(mut u: u32) -> u32 {
+ let mut v = 10;
+
+ let temp = u;
+ u = v;
+ v = temp;
+ u + v
+}
diff --git a/src/tools/clippy/tests/ui/track-diagnostics.rs b/src/tools/clippy/tests/ui/track-diagnostics.rs
new file mode 100644
index 000000000..fa9221ed0
--- /dev/null
+++ b/src/tools/clippy/tests/ui/track-diagnostics.rs
@@ -0,0 +1,12 @@
+// compile-flags: -Z track-diagnostics
+// error-pattern: created at
+
+// 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"
+
+struct A;
+struct B;
+const S: A = B;
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/track-diagnostics.stderr b/src/tools/clippy/tests/ui/track-diagnostics.stderr
new file mode 100644
index 000000000..ec3031862
--- /dev/null
+++ b/src/tools/clippy/tests/ui/track-diagnostics.stderr
@@ -0,0 +1,10 @@
+error[E0308]: mismatched types
+ --> $DIR/track-diagnostics.rs:LL:CC
+ |
+LL | const S: A = B;
+ | ^ expected struct `A`, found struct `B`
+-Ztrack-diagnostics: created at compiler/rustc_infer/src/infer/error_reporting/mod.rs:LL:CC
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/tools/clippy/tests/ui/transmute.rs b/src/tools/clippy/tests/ui/transmute.rs
index 001c91023..1cbacf0fe 100644
--- a/src/tools/clippy/tests/ui/transmute.rs
+++ b/src/tools/clippy/tests/ui/transmute.rs
@@ -1,4 +1,4 @@
-#![allow(dead_code, clippy::borrow_as_ptr)]
+#![allow(dead_code, clippy::borrow_as_ptr, clippy::needless_lifetimes)]
extern crate core;
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 e5fe9133f..074dae5fb 100644
--- a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed
+++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.fixed
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::transmute_ptr_to_ref)]
#![allow(clippy::match_single_binding)]
@@ -51,8 +50,8 @@ unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &'
}
}
+#[clippy::msrv = "1.38"]
unsafe fn _meets_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 {
- #![clippy::msrv = "1.38"]
let a = 0u32;
let a = &a as *const u32;
let _: &u32 = &*a;
@@ -63,8 +62,8 @@ unsafe fn _meets_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 {
}
}
+#[clippy::msrv = "1.37"]
unsafe fn _under_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 {
- #![clippy::msrv = "1.37"]
let a = 0u32;
let a = &a as *const u32;
let _: &u32 = &*a;
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 fe49cdc32..2edc122cf 100644
--- a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs
+++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.rs
@@ -1,6 +1,5 @@
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::transmute_ptr_to_ref)]
#![allow(clippy::match_single_binding)]
@@ -51,8 +50,8 @@ unsafe fn _issue8924<'a, 'b, 'c>(x: *const &'a u32, y: *const &'b u32) -> &'c &'
}
}
+#[clippy::msrv = "1.38"]
unsafe fn _meets_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 {
- #![clippy::msrv = "1.38"]
let a = 0u32;
let a = &a as *const u32;
let _: &u32 = std::mem::transmute(a);
@@ -63,8 +62,8 @@ unsafe fn _meets_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 {
}
}
+#[clippy::msrv = "1.37"]
unsafe fn _under_msrv<'a, 'b, 'c>(x: *const &'a u32) -> &'c &'b u32 {
- #![clippy::msrv = "1.37"]
let a = 0u32;
let a = &a as *const u32;
let _: &u32 = std::mem::transmute(a);
diff --git a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.stderr b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.stderr
index 10117ee91..b3e6c09d2 100644
--- a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.stderr
+++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.stderr
@@ -1,5 +1,5 @@
error: transmute from a pointer type (`*const T`) to a reference type (`&T`)
- --> $DIR/transmute_ptr_to_ref.rs:8:17
+ --> $DIR/transmute_ptr_to_ref.rs:7:17
|
LL | let _: &T = std::mem::transmute(p);
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*p`
@@ -7,127 +7,127 @@ LL | let _: &T = std::mem::transmute(p);
= note: `-D clippy::transmute-ptr-to-ref` implied by `-D warnings`
error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`)
- --> $DIR/transmute_ptr_to_ref.rs:11:21
+ --> $DIR/transmute_ptr_to_ref.rs:10:21
|
LL | let _: &mut T = std::mem::transmute(m);
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *m`
error: transmute from a pointer type (`*mut T`) to a reference type (`&T`)
- --> $DIR/transmute_ptr_to_ref.rs:14:17
+ --> $DIR/transmute_ptr_to_ref.rs:13:17
|
LL | let _: &T = std::mem::transmute(m);
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*m`
error: transmute from a pointer type (`*mut T`) to a reference type (`&mut T`)
- --> $DIR/transmute_ptr_to_ref.rs:17:21
+ --> $DIR/transmute_ptr_to_ref.rs:16:21
|
LL | let _: &mut T = std::mem::transmute(p as *mut T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(p as *mut T)`
error: transmute from a pointer type (`*const U`) to a reference type (`&T`)
- --> $DIR/transmute_ptr_to_ref.rs:20:17
+ --> $DIR/transmute_ptr_to_ref.rs:19:17
|
LL | let _: &T = std::mem::transmute(o);
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(o as *const T)`
error: transmute from a pointer type (`*mut U`) to a reference type (`&mut T`)
- --> $DIR/transmute_ptr_to_ref.rs:23:21
+ --> $DIR/transmute_ptr_to_ref.rs:22:21
|
LL | let _: &mut T = std::mem::transmute(om);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(om as *mut T)`
error: transmute from a pointer type (`*mut U`) to a reference type (`&T`)
- --> $DIR/transmute_ptr_to_ref.rs:26:17
+ --> $DIR/transmute_ptr_to_ref.rs:25:17
|
LL | let _: &T = std::mem::transmute(om);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(om as *const T)`
error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<'_, u8>`)
- --> $DIR/transmute_ptr_to_ref.rs:36:32
+ --> $DIR/transmute_ptr_to_ref.rs:35:32
|
LL | let _: &Foo<u8> = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*raw.cast::<Foo<_>>()`
error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<'_, &u8>`)
- --> $DIR/transmute_ptr_to_ref.rs:38:33
+ --> $DIR/transmute_ptr_to_ref.rs:37:33
|
LL | let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*raw.cast::<Foo<&_>>()`
error: transmute from a pointer type (`*const i32`) to a reference type (`&u8`)
- --> $DIR/transmute_ptr_to_ref.rs:42:14
+ --> $DIR/transmute_ptr_to_ref.rs:41:14
|
LL | unsafe { std::mem::transmute::<_, Bar>(raw) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(raw as *const u8)`
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
- --> $DIR/transmute_ptr_to_ref.rs:47:14
+ --> $DIR/transmute_ptr_to_ref.rs:46:14
|
LL | 0 => std::mem::transmute(x),
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&u32>()`
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
- --> $DIR/transmute_ptr_to_ref.rs:48:14
+ --> $DIR/transmute_ptr_to_ref.rs:47:14
|
LL | 1 => std::mem::transmute(y),
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*y.cast::<&u32>()`
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
- --> $DIR/transmute_ptr_to_ref.rs:49:14
+ --> $DIR/transmute_ptr_to_ref.rs:48:14
|
LL | 2 => std::mem::transmute::<_, &&'b u32>(x),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&'b u32>()`
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
- --> $DIR/transmute_ptr_to_ref.rs:50:14
+ --> $DIR/transmute_ptr_to_ref.rs:49:14
|
LL | _ => std::mem::transmute::<_, &&'b u32>(y),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*y.cast::<&'b u32>()`
error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`)
- --> $DIR/transmute_ptr_to_ref.rs:58:19
+ --> $DIR/transmute_ptr_to_ref.rs:57:19
|
LL | let _: &u32 = std::mem::transmute(a);
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a`
error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`)
- --> $DIR/transmute_ptr_to_ref.rs:59:19
+ --> $DIR/transmute_ptr_to_ref.rs:58:19
|
LL | let _: &u32 = std::mem::transmute::<_, &u32>(a);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a.cast::<u32>()`
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
- --> $DIR/transmute_ptr_to_ref.rs:61:14
+ --> $DIR/transmute_ptr_to_ref.rs:60:14
|
LL | 0 => std::mem::transmute(x),
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&u32>()`
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
- --> $DIR/transmute_ptr_to_ref.rs:62:14
+ --> $DIR/transmute_ptr_to_ref.rs:61:14
|
LL | _ => std::mem::transmute::<_, &&'b u32>(x),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*x.cast::<&'b u32>()`
error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`)
- --> $DIR/transmute_ptr_to_ref.rs:70:19
+ --> $DIR/transmute_ptr_to_ref.rs:69:19
|
LL | let _: &u32 = std::mem::transmute(a);
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*a`
error: transmute from a pointer type (`*const u32`) to a reference type (`&u32`)
- --> $DIR/transmute_ptr_to_ref.rs:71:19
+ --> $DIR/transmute_ptr_to_ref.rs:70:19
|
LL | let _: &u32 = std::mem::transmute::<_, &u32>(a);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(a as *const u32)`
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
- --> $DIR/transmute_ptr_to_ref.rs:73:14
+ --> $DIR/transmute_ptr_to_ref.rs:72:14
|
LL | 0 => std::mem::transmute(x),
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(x as *const () as *const &u32)`
error: transmute from a pointer type (`*const &u32`) to a reference type (`&&u32`)
- --> $DIR/transmute_ptr_to_ref.rs:74:14
+ --> $DIR/transmute_ptr_to_ref.rs:73:14
|
LL | _ => std::mem::transmute::<_, &&'b u32>(x),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(x as *const () as *const &'b u32)`
diff --git a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs
index af4f3b184..c0af011d3 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
@@ -3,6 +3,7 @@
#![deny(clippy::trivially_copy_pass_by_ref)]
#![allow(
clippy::disallowed_names,
+ clippy::needless_lifetimes,
clippy::redundant_field_names,
clippy::uninlined_format_args
)]
diff --git a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr
index 6a8eca965..8c5cfa8a0 100644
--- a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr
+++ b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr
@@ -1,5 +1,5 @@
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:50:11
+ --> $DIR/trivially_copy_pass_by_ref.rs:51:11
|
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
@@ -11,103 +11,103 @@ LL | #![deny(clippy::trivially_copy_pass_by_ref)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:50:20
+ --> $DIR/trivially_copy_pass_by_ref.rs:51:20
|
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:50:29
+ --> $DIR/trivially_copy_pass_by_ref.rs:51:29
|
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:57:12
+ --> $DIR/trivially_copy_pass_by_ref.rs:58:12
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^^ help: consider passing by value instead: `self`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:57:22
+ --> $DIR/trivially_copy_pass_by_ref.rs:58:22
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:57:31
+ --> $DIR/trivially_copy_pass_by_ref.rs:58:31
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:57:40
+ --> $DIR/trivially_copy_pass_by_ref.rs:58:40
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:59:16
+ --> $DIR/trivially_copy_pass_by_ref.rs:60:16
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:59:25
+ --> $DIR/trivially_copy_pass_by_ref.rs:60:25
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:59:34
+ --> $DIR/trivially_copy_pass_by_ref.rs:60:34
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:61:35
+ --> $DIR/trivially_copy_pass_by_ref.rs:62:35
|
LL | fn bad_issue7518(self, other: &Self) {}
| ^^^^^ help: consider passing by value instead: `Self`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:73:16
+ --> $DIR/trivially_copy_pass_by_ref.rs:74:16
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:73:25
+ --> $DIR/trivially_copy_pass_by_ref.rs:74:25
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:73:34
+ --> $DIR/trivially_copy_pass_by_ref.rs:74:34
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:77:34
+ --> $DIR/trivially_copy_pass_by_ref.rs:78:34
|
LL | fn trait_method(&self, _foo: &Foo);
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:109:21
+ --> $DIR/trivially_copy_pass_by_ref.rs:110:21
|
LL | fn foo_never(x: &i32) {
| ^^^^ help: consider passing by value instead: `i32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:114:15
+ --> $DIR/trivially_copy_pass_by_ref.rs:115:15
|
LL | fn foo(x: &i32) {
| ^^^^ help: consider passing by value instead: `i32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:141:37
+ --> $DIR/trivially_copy_pass_by_ref.rs:142:37
|
LL | fn _unrelated_lifetimes<'a, 'b>(_x: &'a u32, y: &'b u32) -> &'b u32 {
| ^^^^^^^ help: consider passing by value instead: `u32`
diff --git a/src/tools/clippy/tests/ui/unchecked_duration_subtraction.fixed b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.fixed
new file mode 100644
index 000000000..a0e49a8be
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.fixed
@@ -0,0 +1,17 @@
+// run-rustfix
+#![warn(clippy::unchecked_duration_subtraction)]
+
+use std::time::{Duration, Instant};
+
+fn main() {
+ let _first = Instant::now();
+ let second = Duration::from_secs(3);
+
+ let _ = _first.checked_sub(second).unwrap();
+
+ let _ = Instant::now().checked_sub(Duration::from_secs(5)).unwrap();
+
+ let _ = _first.checked_sub(Duration::from_secs(5)).unwrap();
+
+ let _ = Instant::now().checked_sub(second).unwrap();
+}
diff --git a/src/tools/clippy/tests/ui/unchecked_duration_subtraction.rs b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.rs
new file mode 100644
index 000000000..a14a7ea57
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.rs
@@ -0,0 +1,17 @@
+// run-rustfix
+#![warn(clippy::unchecked_duration_subtraction)]
+
+use std::time::{Duration, Instant};
+
+fn main() {
+ let _first = Instant::now();
+ let second = Duration::from_secs(3);
+
+ let _ = _first - second;
+
+ let _ = Instant::now() - Duration::from_secs(5);
+
+ let _ = _first - Duration::from_secs(5);
+
+ let _ = Instant::now() - second;
+}
diff --git a/src/tools/clippy/tests/ui/unchecked_duration_subtraction.stderr b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.stderr
new file mode 100644
index 000000000..a2e0aa1d7
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unchecked_duration_subtraction.stderr
@@ -0,0 +1,28 @@
+error: unchecked subtraction of a 'Duration' from an 'Instant'
+ --> $DIR/unchecked_duration_subtraction.rs:10:13
+ |
+LL | let _ = _first - second;
+ | ^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(second).unwrap()`
+ |
+ = note: `-D clippy::unchecked-duration-subtraction` implied by `-D warnings`
+
+error: unchecked subtraction of a 'Duration' from an 'Instant'
+ --> $DIR/unchecked_duration_subtraction.rs:12:13
+ |
+LL | let _ = Instant::now() - Duration::from_secs(5);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(Duration::from_secs(5)).unwrap()`
+
+error: unchecked subtraction of a 'Duration' from an 'Instant'
+ --> $DIR/unchecked_duration_subtraction.rs:14:13
+ |
+LL | let _ = _first - Duration::from_secs(5);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(Duration::from_secs(5)).unwrap()`
+
+error: unchecked subtraction of a 'Duration' from an 'Instant'
+ --> $DIR/unchecked_duration_subtraction.rs:16:13
+ |
+LL | let _ = Instant::now() - second;
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(second).unwrap()`
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs b/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs
index 08aee4332..c05eb447b 100644
--- a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs
+++ b/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.rs
@@ -1,6 +1,6 @@
// aux-build:proc_macro_unsafe.rs
-#![warn(clippy::undocumented_unsafe_blocks)]
+#![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)]
#![allow(clippy::let_unit_value, clippy::missing_safety_doc)]
extern crate proc_macro_unsafe;
@@ -490,4 +490,23 @@ unsafe impl CrateRoot for () {}
// SAFETY: ok
unsafe impl CrateRoot for (i32) {}
+fn issue_9142() {
+ // SAFETY: ok
+ let _ =
+ // we need this comment to avoid rustfmt putting
+ // it all on one line
+ unsafe {};
+
+ // SAFETY: this is more than one level away, so it should warn
+ let _ = {
+ if unsafe { true } {
+ todo!();
+ } else {
+ let bar = unsafe {};
+ todo!();
+ bar
+ }
+ };
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr b/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr
index 2c466ff5c..d1c1bb5ff 100644
--- a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr
+++ b/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr
@@ -239,6 +239,19 @@ LL | unsafe impl TrailingComment for () {} // SAFETY:
|
= help: consider adding a safety comment on the preceding line
+error: constant item has unnecessary safety comment
+ --> $DIR/undocumented_unsafe_blocks.rs:471:5
+ |
+LL | const BIG_NUMBER: i32 = 1000000;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: consider removing the safety comment
+ --> $DIR/undocumented_unsafe_blocks.rs:470:5
+ |
+LL | // SAFETY:
+ | ^^^^^^^^^^
+ = note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings`
+
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:472:5
|
@@ -263,5 +276,47 @@ LL | unsafe impl CrateRoot for () {}
|
= help: consider adding a safety comment on the preceding line
-error: aborting due to 31 previous errors
+error: unsafe block missing a safety comment
+ --> $DIR/undocumented_unsafe_blocks.rs:498:9
+ |
+LL | unsafe {};
+ | ^^^^^^^^^
+ |
+ = help: consider adding a safety comment on the preceding line
+
+error: statement has unnecessary safety comment
+ --> $DIR/undocumented_unsafe_blocks.rs:501:5
+ |
+LL | / let _ = {
+LL | | if unsafe { true } {
+LL | | todo!();
+LL | | } else {
+... |
+LL | | }
+LL | | };
+ | |______^
+ |
+help: consider removing the safety comment
+ --> $DIR/undocumented_unsafe_blocks.rs:500:5
+ |
+LL | // SAFETY: this is more than one level away, so it should warn
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: unsafe block missing a safety comment
+ --> $DIR/undocumented_unsafe_blocks.rs:502:12
+ |
+LL | if unsafe { true } {
+ | ^^^^^^^^^^^^^^^
+ |
+ = help: consider adding a safety comment on the preceding line
+
+error: unsafe block missing a safety comment
+ --> $DIR/undocumented_unsafe_blocks.rs:505:23
+ |
+LL | let bar = unsafe {};
+ | ^^^^^^^^^
+ |
+ = help: consider adding a safety comment on the preceding line
+
+error: aborting due to 36 previous errors
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.fixed b/src/tools/clippy/tests/ui/uninlined_format_args.fixed
index 106274479..9d08e80cf 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args.fixed
+++ b/src/tools/clippy/tests/ui/uninlined_format_args.fixed
@@ -1,6 +1,5 @@
// aux-build:proc_macro_with_span.rs
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::uninlined_format_args)]
#![allow(named_arguments_used_positionally, unused_imports, unused_macros, unused_variables)]
#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
@@ -44,9 +43,7 @@ fn tester(fn_arg: i32) {
println!("val='{local_i32}'"); // space+tab
println!("val='{local_i32}'"); // tab+space
println!(
- "val='{
- }'",
- local_i32
+ "val='{local_i32}'"
);
println!("{local_i32}");
println!("{fn_arg}");
@@ -57,11 +54,11 @@ fn tester(fn_arg: i32) {
println!("{local_i32:<3}");
println!("{local_i32:#010x}");
println!("{local_f64:.1}");
- println!("Hello {} is {local_f64:.local_i32$}", "x");
- println!("Hello {local_i32} is {local_f64:.*}", 5);
- println!("Hello {local_i32} is {local_f64:.*}", 5);
+ println!("Hello {} is {:.*}", "x", local_i32, local_f64);
+ println!("Hello {} is {:.*}", local_i32, 5, local_f64);
+ println!("Hello {} is {2:.*}", local_i32, 5, local_f64);
println!("{local_i32} {local_f64}");
- println!("{local_i32}, {}", local_opt.unwrap());
+ println!("{}, {}", local_i32, local_opt.unwrap());
println!("{val}");
println!("{val}");
println!("{} {1}", local_i32, 42);
@@ -110,8 +107,7 @@ fn tester(fn_arg: i32) {
println!("{local_f64:width$.prec$}");
println!("{local_f64:width$.prec$} {local_f64} {width} {prec}");
println!(
- "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
- local_i32, width, prec,
+ "{local_i32:width$.prec$} {local_i32:prec$.width$} {width:local_i32$.prec$} {width:prec$.local_i32$} {prec:local_i32$.width$} {prec:width$.local_i32$}",
);
println!(
"{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$} {3}",
@@ -142,9 +138,7 @@ fn tester(fn_arg: i32) {
println!(no_param_str!(), local_i32);
println!(
- "{}",
- // comment with a comma , in it
- val,
+ "{val}",
);
println!("{val}");
@@ -169,14 +163,14 @@ fn main() {
tester(42);
}
+#[clippy::msrv = "1.57"]
fn _under_msrv() {
- #![clippy::msrv = "1.57"]
let local_i32 = 1;
println!("don't expand='{}'", local_i32);
}
+#[clippy::msrv = "1.58"]
fn _meets_msrv() {
- #![clippy::msrv = "1.58"]
let local_i32 = 1;
println!("expand='{local_i32}'");
}
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.rs b/src/tools/clippy/tests/ui/uninlined_format_args.rs
index 8e495ebd0..35b3677a8 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args.rs
+++ b/src/tools/clippy/tests/ui/uninlined_format_args.rs
@@ -1,6 +1,5 @@
// aux-build:proc_macro_with_span.rs
// run-rustfix
-#![feature(custom_inner_attributes)]
#![warn(clippy::uninlined_format_args)]
#![allow(named_arguments_used_positionally, unused_imports, unused_macros, unused_variables)]
#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
@@ -169,14 +168,14 @@ fn main() {
tester(42);
}
+#[clippy::msrv = "1.57"]
fn _under_msrv() {
- #![clippy::msrv = "1.57"]
let local_i32 = 1;
println!("don't expand='{}'", local_i32);
}
+#[clippy::msrv = "1.58"]
fn _meets_msrv() {
- #![clippy::msrv = "1.58"]
let local_i32 = 1;
println!("expand='{}'", local_i32);
}
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.stderr b/src/tools/clippy/tests/ui/uninlined_format_args.stderr
index 2ce3b7fa9..a12abf8be 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args.stderr
+++ b/src/tools/clippy/tests/ui/uninlined_format_args.stderr
@@ -1,5 +1,5 @@
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:41:5
+ --> $DIR/uninlined_format_args.rs:40:5
|
LL | println!("val='{}'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -12,7 +12,7 @@ LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:42:5
+ --> $DIR/uninlined_format_args.rs:41:5
|
LL | println!("val='{ }'", local_i32); // 3 spaces
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -24,7 +24,7 @@ LL + println!("val='{local_i32}'"); // 3 spaces
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:43:5
+ --> $DIR/uninlined_format_args.rs:42:5
|
LL | println!("val='{ }'", local_i32); // tab
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -36,7 +36,7 @@ LL + println!("val='{local_i32}'"); // tab
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:44:5
+ --> $DIR/uninlined_format_args.rs:43:5
|
LL | println!("val='{ }'", local_i32); // space+tab
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -48,7 +48,7 @@ LL + println!("val='{local_i32}'"); // space+tab
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:45:5
+ --> $DIR/uninlined_format_args.rs:44:5
|
LL | println!("val='{ }'", local_i32); // tab+space
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -60,7 +60,17 @@ LL + println!("val='{local_i32}'"); // tab+space
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:51:5
+ --> $DIR/uninlined_format_args.rs:45:5
+ |
+LL | / println!(
+LL | | "val='{
+LL | | }'",
+LL | | local_i32
+LL | | );
+ | |_____^
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:50:5
|
LL | println!("{}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -72,7 +82,7 @@ LL + println!("{local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:52:5
+ --> $DIR/uninlined_format_args.rs:51:5
|
LL | println!("{}", fn_arg);
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -84,7 +94,7 @@ LL + println!("{fn_arg}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:53:5
+ --> $DIR/uninlined_format_args.rs:52:5
|
LL | println!("{:?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -96,7 +106,7 @@ LL + println!("{local_i32:?}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:54:5
+ --> $DIR/uninlined_format_args.rs:53:5
|
LL | println!("{:#?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -108,7 +118,7 @@ LL + println!("{local_i32:#?}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:55:5
+ --> $DIR/uninlined_format_args.rs:54:5
|
LL | println!("{:4}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -120,7 +130,7 @@ LL + println!("{local_i32:4}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:56:5
+ --> $DIR/uninlined_format_args.rs:55:5
|
LL | println!("{:04}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -132,7 +142,7 @@ LL + println!("{local_i32:04}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:57:5
+ --> $DIR/uninlined_format_args.rs:56:5
|
LL | println!("{:<3}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -144,7 +154,7 @@ LL + println!("{local_i32:<3}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:58:5
+ --> $DIR/uninlined_format_args.rs:57:5
|
LL | println!("{:#010x}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -156,7 +166,7 @@ LL + println!("{local_i32:#010x}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:59:5
+ --> $DIR/uninlined_format_args.rs:58:5
|
LL | println!("{:.1}", local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -168,44 +178,8 @@ LL + println!("{local_f64:.1}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:60:5
- |
-LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
-help: change this to
- |
-LL - println!("Hello {} is {:.*}", "x", local_i32, local_f64);
-LL + println!("Hello {} is {local_f64:.local_i32$}", "x");
- |
-
-error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:61:5
- |
-LL | println!("Hello {} is {:.*}", local_i32, 5, local_f64);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
-help: change this to
- |
-LL - println!("Hello {} is {:.*}", local_i32, 5, local_f64);
-LL + println!("Hello {local_i32} is {local_f64:.*}", 5);
- |
-
-error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:62:5
|
-LL | println!("Hello {} is {2:.*}", local_i32, 5, local_f64);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
-help: change this to
- |
-LL - println!("Hello {} is {2:.*}", local_i32, 5, local_f64);
-LL + println!("Hello {local_i32} is {local_f64:.*}", 5);
- |
-
-error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:63:5
- |
LL | println!("{} {}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
@@ -218,18 +192,6 @@ LL + println!("{local_i32} {local_f64}");
error: variables can be used directly in the `format!` string
--> $DIR/uninlined_format_args.rs:64:5
|
-LL | println!("{}, {}", local_i32, local_opt.unwrap());
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
-help: change this to
- |
-LL - println!("{}, {}", local_i32, local_opt.unwrap());
-LL + println!("{local_i32}, {}", local_opt.unwrap());
- |
-
-error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:65:5
- |
LL | println!("{}", val);
| ^^^^^^^^^^^^^^^^^^^
|
@@ -240,7 +202,7 @@ LL + println!("{val}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:66:5
+ --> $DIR/uninlined_format_args.rs:65:5
|
LL | println!("{}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -252,7 +214,7 @@ LL + println!("{val}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:68:5
+ --> $DIR/uninlined_format_args.rs:67:5
|
LL | println!("val='{/t }'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -264,7 +226,7 @@ LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:69:5
+ --> $DIR/uninlined_format_args.rs:68:5
|
LL | println!("val='{/n }'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -276,7 +238,7 @@ LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:70:5
+ --> $DIR/uninlined_format_args.rs:69:5
|
LL | println!("val='{local_i32}'", local_i32 = local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -288,7 +250,7 @@ LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:71:5
+ --> $DIR/uninlined_format_args.rs:70:5
|
LL | println!("val='{local_i32}'", local_i32 = fn_arg);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -300,7 +262,7 @@ LL + println!("val='{fn_arg}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:72:5
+ --> $DIR/uninlined_format_args.rs:71:5
|
LL | println!("{0}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -312,7 +274,7 @@ LL + println!("{local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:73:5
+ --> $DIR/uninlined_format_args.rs:72:5
|
LL | println!("{0:?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -324,7 +286,7 @@ LL + println!("{local_i32:?}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:74:5
+ --> $DIR/uninlined_format_args.rs:73:5
|
LL | println!("{0:#?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -336,7 +298,7 @@ LL + println!("{local_i32:#?}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:75:5
+ --> $DIR/uninlined_format_args.rs:74:5
|
LL | println!("{0:04}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -348,7 +310,7 @@ LL + println!("{local_i32:04}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:76:5
+ --> $DIR/uninlined_format_args.rs:75:5
|
LL | println!("{0:<3}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -360,7 +322,7 @@ LL + println!("{local_i32:<3}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:77:5
+ --> $DIR/uninlined_format_args.rs:76:5
|
LL | println!("{0:#010x}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -372,7 +334,7 @@ LL + println!("{local_i32:#010x}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:78:5
+ --> $DIR/uninlined_format_args.rs:77:5
|
LL | println!("{0:.1}", local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -384,7 +346,7 @@ LL + println!("{local_f64:.1}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:79:5
+ --> $DIR/uninlined_format_args.rs:78:5
|
LL | println!("{0} {0}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -396,7 +358,7 @@ LL + println!("{local_i32} {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:80:5
+ --> $DIR/uninlined_format_args.rs:79:5
|
LL | println!("{1} {} {0} {}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -408,7 +370,7 @@ LL + println!("{local_f64} {local_i32} {local_i32} {local_f64}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:81:5
+ --> $DIR/uninlined_format_args.rs:80:5
|
LL | println!("{0} {1}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -420,7 +382,7 @@ LL + println!("{local_i32} {local_f64}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:82:5
+ --> $DIR/uninlined_format_args.rs:81:5
|
LL | println!("{1} {0}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -432,7 +394,7 @@ LL + println!("{local_f64} {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:83:5
+ --> $DIR/uninlined_format_args.rs:82:5
|
LL | println!("{1} {0} {1} {0}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -444,7 +406,7 @@ LL + println!("{local_f64} {local_i32} {local_f64} {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:85:5
+ --> $DIR/uninlined_format_args.rs:84:5
|
LL | println!("{v}", v = local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -456,7 +418,7 @@ LL + println!("{local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:86:5
+ --> $DIR/uninlined_format_args.rs:85:5
|
LL | println!("{local_i32:0$}", width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -468,7 +430,7 @@ LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:87:5
+ --> $DIR/uninlined_format_args.rs:86:5
|
LL | println!("{local_i32:w$}", w = width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -480,7 +442,7 @@ LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:88:5
+ --> $DIR/uninlined_format_args.rs:87:5
|
LL | println!("{local_i32:.0$}", prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -492,7 +454,7 @@ LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:89:5
+ --> $DIR/uninlined_format_args.rs:88:5
|
LL | println!("{local_i32:.p$}", p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -504,7 +466,7 @@ LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:90:5
+ --> $DIR/uninlined_format_args.rs:89:5
|
LL | println!("{:0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -516,7 +478,7 @@ LL + println!("{val:val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:91:5
+ --> $DIR/uninlined_format_args.rs:90:5
|
LL | println!("{0:0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -528,7 +490,7 @@ LL + println!("{val:val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:92:5
+ --> $DIR/uninlined_format_args.rs:91:5
|
LL | println!("{:0$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -540,7 +502,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:93:5
+ --> $DIR/uninlined_format_args.rs:92:5
|
LL | println!("{0:0$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -552,7 +514,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:94:5
+ --> $DIR/uninlined_format_args.rs:93:5
|
LL | println!("{0:0$.v$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -564,7 +526,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:95:5
+ --> $DIR/uninlined_format_args.rs:94:5
|
LL | println!("{0:v$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -576,7 +538,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:96:5
+ --> $DIR/uninlined_format_args.rs:95:5
|
LL | println!("{v:0$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -588,7 +550,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:97:5
+ --> $DIR/uninlined_format_args.rs:96:5
|
LL | println!("{v:v$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -600,7 +562,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:98:5
+ --> $DIR/uninlined_format_args.rs:97:5
|
LL | println!("{v:0$.v$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -612,7 +574,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:99:5
+ --> $DIR/uninlined_format_args.rs:98:5
|
LL | println!("{v:v$.v$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -624,7 +586,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:100:5
+ --> $DIR/uninlined_format_args.rs:99:5
|
LL | println!("{:0$}", width);
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -636,7 +598,7 @@ LL + println!("{width:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:101:5
+ --> $DIR/uninlined_format_args.rs:100:5
|
LL | println!("{:1$}", local_i32, width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -648,7 +610,7 @@ LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:102:5
+ --> $DIR/uninlined_format_args.rs:101:5
|
LL | println!("{:w$}", w = width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -660,7 +622,7 @@ LL + println!("{width:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:103:5
+ --> $DIR/uninlined_format_args.rs:102:5
|
LL | println!("{:w$}", local_i32, w = width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -672,7 +634,7 @@ LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:104:5
+ --> $DIR/uninlined_format_args.rs:103:5
|
LL | println!("{:.0$}", prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -684,7 +646,7 @@ LL + println!("{prec:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:105:5
+ --> $DIR/uninlined_format_args.rs:104:5
|
LL | println!("{:.1$}", local_i32, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -696,7 +658,7 @@ LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:106:5
+ --> $DIR/uninlined_format_args.rs:105:5
|
LL | println!("{:.p$}", p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -708,7 +670,7 @@ LL + println!("{prec:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:107:5
+ --> $DIR/uninlined_format_args.rs:106:5
|
LL | println!("{:.p$}", local_i32, p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -720,7 +682,7 @@ LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:108:5
+ --> $DIR/uninlined_format_args.rs:107:5
|
LL | println!("{:0$.1$}", width, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -732,7 +694,7 @@ LL + println!("{width:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:109:5
+ --> $DIR/uninlined_format_args.rs:108:5
|
LL | println!("{:0$.w$}", width, w = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -744,7 +706,7 @@ LL + println!("{width:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:110:5
+ --> $DIR/uninlined_format_args.rs:109:5
|
LL | println!("{:1$.2$}", local_f64, width, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -756,7 +718,7 @@ LL + println!("{local_f64:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:111:5
+ --> $DIR/uninlined_format_args.rs:110:5
|
LL | println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -768,7 +730,16 @@ LL + println!("{local_f64:width$.prec$} {local_f64} {width} {prec}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:123:5
+ --> $DIR/uninlined_format_args.rs:111:5
+ |
+LL | / println!(
+LL | | "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
+LL | | local_i32, width, prec,
+LL | | );
+ | |_____^
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:122:5
|
LL | println!("Width = {}, value with width = {:0$}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -780,7 +751,7 @@ LL + println!("Width = {local_i32}, value with width = {local_f64:local_i32$
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:124:5
+ --> $DIR/uninlined_format_args.rs:123:5
|
LL | println!("{:w$.p$}", local_i32, w = width, p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -792,7 +763,7 @@ LL + println!("{local_i32:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:125:5
+ --> $DIR/uninlined_format_args.rs:124:5
|
LL | println!("{:w$.p$}", w = width, p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -804,7 +775,7 @@ LL + println!("{width:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:126:20
+ --> $DIR/uninlined_format_args.rs:125:20
|
LL | println!("{}", format!("{}", local_i32));
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -816,7 +787,17 @@ LL + println!("{}", format!("{local_i32}"));
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:149:5
+ --> $DIR/uninlined_format_args.rs:143:5
+ |
+LL | / println!(
+LL | | "{}",
+LL | | // comment with a comma , in it
+LL | | val,
+LL | | );
+ | |_____^
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:148:5
|
LL | println!("{}", /* comment with a comma , in it */ val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -828,7 +809,7 @@ LL + println!("{val}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:155:9
+ --> $DIR/uninlined_format_args.rs:154:9
|
LL | panic!("p1 {}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -840,7 +821,7 @@ LL + panic!("p1 {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:158:9
+ --> $DIR/uninlined_format_args.rs:157:9
|
LL | panic!("p2 {0}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -852,7 +833,7 @@ LL + panic!("p2 {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:161:9
+ --> $DIR/uninlined_format_args.rs:160:9
|
LL | panic!("p3 {local_i32}", local_i32 = local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -864,7 +845,7 @@ LL + panic!("p3 {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:181:5
+ --> $DIR/uninlined_format_args.rs:180:5
|
LL | println!("expand='{}'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -875,5 +856,5 @@ LL - println!("expand='{}'", local_i32);
LL + println!("expand='{local_i32}'");
|
-error: aborting due to 73 previous errors
+error: aborting due to 72 previous errors
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.fixed b/src/tools/clippy/tests/ui/unnecessary_cast.fixed
index ec8c6abfa..2f7e2997e 100644
--- a/src/tools/clippy/tests/ui/unnecessary_cast.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_cast.fixed
@@ -41,6 +41,17 @@ fn main() {
// do not lint cast to alias type
1 as I32Alias;
&1 as &I32Alias;
+
+ // issue #9960
+ macro_rules! bind_var {
+ ($id:ident, $e:expr) => {{
+ let $id = 0usize;
+ let _ = $e != 0usize;
+ let $id = 0isize;
+ let _ = $e != 0usize;
+ }}
+ }
+ bind_var!(x, (x as usize) + 1);
}
type I32Alias = i32;
@@ -85,6 +96,9 @@ mod fixable {
let _ = 1 as I32Alias;
let _ = &1 as &I32Alias;
+
+ let x = 1i32;
+ let _ = &{ x };
}
type I32Alias = i32;
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.rs b/src/tools/clippy/tests/ui/unnecessary_cast.rs
index 5213cdc26..54dd46ba5 100644
--- a/src/tools/clippy/tests/ui/unnecessary_cast.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_cast.rs
@@ -41,6 +41,17 @@ fn main() {
// do not lint cast to alias type
1 as I32Alias;
&1 as &I32Alias;
+
+ // issue #9960
+ macro_rules! bind_var {
+ ($id:ident, $e:expr) => {{
+ let $id = 0usize;
+ let _ = $e != 0usize;
+ let $id = 0isize;
+ let _ = $e != 0usize;
+ }}
+ }
+ bind_var!(x, (x as usize) + 1);
}
type I32Alias = i32;
@@ -85,6 +96,9 @@ mod fixable {
let _ = 1 as I32Alias;
let _ = &1 as &I32Alias;
+
+ let x = 1i32;
+ let _ = &(x as i32);
}
type I32Alias = i32;
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.stderr b/src/tools/clippy/tests/ui/unnecessary_cast.stderr
index e5c3dd5e5..fcee4ee2a 100644
--- a/src/tools/clippy/tests/ui/unnecessary_cast.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_cast.stderr
@@ -49,136 +49,142 @@ LL | 1_f32 as f32;
| ^^^^^^^^^^^^ help: try: `1_f32`
error: casting integer literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:53:9
+ --> $DIR/unnecessary_cast.rs:64:9
|
LL | 100 as f32;
| ^^^^^^^^^^ help: try: `100_f32`
error: casting integer literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:54:9
+ --> $DIR/unnecessary_cast.rs:65:9
|
LL | 100 as f64;
| ^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:55:9
+ --> $DIR/unnecessary_cast.rs:66:9
|
LL | 100_i32 as f64;
| ^^^^^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:56:17
+ --> $DIR/unnecessary_cast.rs:67:17
|
LL | let _ = -100 as f32;
| ^^^^^^^^^^^ help: try: `-100_f32`
error: casting integer literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:57:17
+ --> $DIR/unnecessary_cast.rs:68:17
|
LL | let _ = -100 as f64;
| ^^^^^^^^^^^ help: try: `-100_f64`
error: casting integer literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:58:17
+ --> $DIR/unnecessary_cast.rs:69:17
|
LL | let _ = -100_i32 as f64;
| ^^^^^^^^^^^^^^^ help: try: `-100_f64`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:59:9
+ --> $DIR/unnecessary_cast.rs:70:9
|
LL | 100. as f32;
| ^^^^^^^^^^^ help: try: `100_f32`
error: casting float literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:60:9
+ --> $DIR/unnecessary_cast.rs:71:9
|
LL | 100. as f64;
| ^^^^^^^^^^^ help: try: `100_f64`
error: casting integer literal to `u32` is unnecessary
- --> $DIR/unnecessary_cast.rs:72:9
+ --> $DIR/unnecessary_cast.rs:83:9
|
LL | 1 as u32;
| ^^^^^^^^ help: try: `1_u32`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:73:9
+ --> $DIR/unnecessary_cast.rs:84:9
|
LL | 0x10 as i32;
| ^^^^^^^^^^^ help: try: `0x10_i32`
error: casting integer literal to `usize` is unnecessary
- --> $DIR/unnecessary_cast.rs:74:9
+ --> $DIR/unnecessary_cast.rs:85:9
|
LL | 0b10 as usize;
| ^^^^^^^^^^^^^ help: try: `0b10_usize`
error: casting integer literal to `u16` is unnecessary
- --> $DIR/unnecessary_cast.rs:75:9
+ --> $DIR/unnecessary_cast.rs:86:9
|
LL | 0o73 as u16;
| ^^^^^^^^^^^ help: try: `0o73_u16`
error: casting integer literal to `u32` is unnecessary
- --> $DIR/unnecessary_cast.rs:76:9
+ --> $DIR/unnecessary_cast.rs:87:9
|
LL | 1_000_000_000 as u32;
| ^^^^^^^^^^^^^^^^^^^^ help: try: `1_000_000_000_u32`
error: casting float literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:78:9
+ --> $DIR/unnecessary_cast.rs:89:9
|
LL | 1.0 as f64;
| ^^^^^^^^^^ help: try: `1.0_f64`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:79:9
+ --> $DIR/unnecessary_cast.rs:90:9
|
LL | 0.5 as f32;
| ^^^^^^^^^^ help: try: `0.5_f32`
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:83:17
+ --> $DIR/unnecessary_cast.rs:94:17
|
LL | let _ = -1 as i32;
| ^^^^^^^^^ help: try: `-1_i32`
error: casting float literal to `f32` is unnecessary
- --> $DIR/unnecessary_cast.rs:84:17
+ --> $DIR/unnecessary_cast.rs:95:17
|
LL | let _ = -1.0 as f32;
| ^^^^^^^^^^^ help: try: `-1.0_f32`
+error: casting to the same type is unnecessary (`i32` -> `i32`)
+ --> $DIR/unnecessary_cast.rs:101:18
+ |
+LL | let _ = &(x as i32);
+ | ^^^^^^^^^^ help: try: `{ x }`
+
error: casting integer literal to `i32` is unnecessary
- --> $DIR/unnecessary_cast.rs:93:22
+ --> $DIR/unnecessary_cast.rs:107:22
|
LL | let _: i32 = -(1) as i32;
| ^^^^^^^^^^^ help: try: `-1_i32`
error: casting integer literal to `i64` is unnecessary
- --> $DIR/unnecessary_cast.rs:95:22
+ --> $DIR/unnecessary_cast.rs:109:22
|
LL | let _: i64 = -(1) as i64;
| ^^^^^^^^^^^ help: try: `-1_i64`
error: casting float literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:102:22
+ --> $DIR/unnecessary_cast.rs:116:22
|
LL | let _: f64 = (-8.0 as f64).exp();
| ^^^^^^^^^^^^^ help: try: `(-8.0_f64)`
error: casting float literal to `f64` is unnecessary
- --> $DIR/unnecessary_cast.rs:104:23
+ --> $DIR/unnecessary_cast.rs:118:23
|
LL | let _: f64 = -(8.0 as f64).exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior
| ^^^^^^^^^^^^ help: try: `8.0_f64`
error: casting to the same type is unnecessary (`f32` -> `f32`)
- --> $DIR/unnecessary_cast.rs:112:20
+ --> $DIR/unnecessary_cast.rs:126:20
|
LL | let _num = foo() as f32;
| ^^^^^^^^^^^^ help: try: `foo()`
-error: aborting due to 30 previous errors
+error: aborting due to 31 previous errors
diff --git a/src/tools/clippy/tests/ui/unnecessary_join.stderr b/src/tools/clippy/tests/ui/unnecessary_join.stderr
index 0b14b143a..e919a6d1d 100644
--- a/src/tools/clippy/tests/ui/unnecessary_join.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_join.stderr
@@ -1,4 +1,4 @@
-error: called `.collect<Vec<String>>().join("")` on an iterator
+error: called `.collect::<Vec<String>>().join("")` on an iterator
--> $DIR/unnecessary_join.rs:11:10
|
LL | .collect::<Vec<String>>()
@@ -8,7 +8,7 @@ LL | | .join("");
|
= note: `-D clippy::unnecessary-join` implied by `-D warnings`
-error: called `.collect<Vec<String>>().join("")` on an iterator
+error: called `.collect::<Vec<String>>().join("")` on an iterator
--> $DIR/unnecessary_join.rs:20:10
|
LL | .collect::<Vec<_>>()
diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
index ce4a82e02..22e9bd8bd 100644
--- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
@@ -33,6 +33,14 @@ impl Drop for Issue9427 {
}
}
+struct Issue9427FollowUp;
+
+impl Drop for Issue9427FollowUp {
+ fn drop(&mut self) {
+ panic!("side effect drop");
+ }
+}
+
fn main() {
let astronomers_pi = 10;
let ext_arr: [usize; 1] = [2];
@@ -87,6 +95,7 @@ fn main() {
// Should not lint - bool
let _ = (0 == 1).then(|| Issue9427(0)); // Issue9427 has a significant drop
+ let _ = false.then(|| Issue9427FollowUp); // Issue9427FollowUp has a significant drop
// should not lint, bind_instead_of_map takes priority
let _ = Some(10).and_then(|idx| Some(ext_arr[idx]));
@@ -133,13 +142,13 @@ fn main() {
let _: Result<usize, usize> = res.or(Ok(astronomers_pi));
let _: Result<usize, usize> = res.or(Ok(ext_str.some_field));
let _: Result<usize, usize> = res.
- // some lines
- // some lines
- // some lines
- // some lines
- // some lines
- // some lines
- or(Ok(ext_str.some_field));
+ // some lines
+ // some lines
+ // some lines
+ // some lines
+ // some lines
+ // some lines
+ or(Ok(ext_str.some_field));
// neither bind_instead_of_map nor unnecessary_lazy_eval applies here
let _: Result<usize, usize> = res.and_then(|x| Err(x));
diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs
index 59cdf6628..8726d84a2 100644
--- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs
@@ -33,6 +33,14 @@ impl Drop for Issue9427 {
}
}
+struct Issue9427FollowUp;
+
+impl Drop for Issue9427FollowUp {
+ fn drop(&mut self) {
+ panic!("side effect drop");
+ }
+}
+
fn main() {
let astronomers_pi = 10;
let ext_arr: [usize; 1] = [2];
@@ -87,6 +95,7 @@ fn main() {
// Should not lint - bool
let _ = (0 == 1).then(|| Issue9427(0)); // Issue9427 has a significant drop
+ let _ = false.then(|| Issue9427FollowUp); // Issue9427FollowUp has a significant drop
// should not lint, bind_instead_of_map takes priority
let _ = Some(10).and_then(|idx| Some(ext_arr[idx]));
@@ -133,13 +142,13 @@ fn main() {
let _: Result<usize, usize> = res.or_else(|_| Ok(astronomers_pi));
let _: Result<usize, usize> = res.or_else(|_| Ok(ext_str.some_field));
let _: Result<usize, usize> = res.
- // some lines
- // some lines
- // some lines
- // some lines
- // some lines
- // some lines
- or_else(|_| Ok(ext_str.some_field));
+ // some lines
+ // some lines
+ // some lines
+ // some lines
+ // some lines
+ // some lines
+ or_else(|_| Ok(ext_str.some_field));
// neither bind_instead_of_map nor unnecessary_lazy_eval applies here
let _: Result<usize, usize> = res.and_then(|x| Err(x));
diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr
index 8a9ece4aa..033975544 100644
--- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr
@@ -1,5 +1,5 @@
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:48:13
+ --> $DIR/unnecessary_lazy_eval.rs:56:13
|
LL | let _ = opt.unwrap_or_else(|| 2);
| ^^^^--------------------
@@ -9,7 +9,7 @@ LL | let _ = opt.unwrap_or_else(|| 2);
= note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:49:13
+ --> $DIR/unnecessary_lazy_eval.rs:57:13
|
LL | let _ = opt.unwrap_or_else(|| astronomers_pi);
| ^^^^---------------------------------
@@ -17,7 +17,7 @@ LL | let _ = opt.unwrap_or_else(|| astronomers_pi);
| help: use `unwrap_or(..)` instead: `unwrap_or(astronomers_pi)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:50:13
+ --> $DIR/unnecessary_lazy_eval.rs:58:13
|
LL | let _ = opt.unwrap_or_else(|| ext_str.some_field);
| ^^^^-------------------------------------
@@ -25,7 +25,7 @@ LL | let _ = opt.unwrap_or_else(|| ext_str.some_field);
| help: use `unwrap_or(..)` instead: `unwrap_or(ext_str.some_field)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:52:13
+ --> $DIR/unnecessary_lazy_eval.rs:60:13
|
LL | let _ = opt.and_then(|_| ext_opt);
| ^^^^---------------------
@@ -33,7 +33,7 @@ LL | let _ = opt.and_then(|_| ext_opt);
| help: use `and(..)` instead: `and(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:53:13
+ --> $DIR/unnecessary_lazy_eval.rs:61:13
|
LL | let _ = opt.or_else(|| ext_opt);
| ^^^^-------------------
@@ -41,7 +41,7 @@ LL | let _ = opt.or_else(|| ext_opt);
| help: use `or(..)` instead: `or(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:54:13
+ --> $DIR/unnecessary_lazy_eval.rs:62:13
|
LL | let _ = opt.or_else(|| None);
| ^^^^----------------
@@ -49,7 +49,7 @@ LL | let _ = opt.or_else(|| None);
| help: use `or(..)` instead: `or(None)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:55:13
+ --> $DIR/unnecessary_lazy_eval.rs:63:13
|
LL | let _ = opt.get_or_insert_with(|| 2);
| ^^^^------------------------
@@ -57,7 +57,7 @@ LL | let _ = opt.get_or_insert_with(|| 2);
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:56:13
+ --> $DIR/unnecessary_lazy_eval.rs:64:13
|
LL | let _ = opt.ok_or_else(|| 2);
| ^^^^----------------
@@ -65,7 +65,7 @@ LL | let _ = opt.ok_or_else(|| 2);
| help: use `ok_or(..)` instead: `ok_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:57:13
+ --> $DIR/unnecessary_lazy_eval.rs:65:13
|
LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2)));
| ^^^^^^^^^^^^^^^^^-------------------------------
@@ -73,7 +73,7 @@ LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2)));
| help: use `unwrap_or(..)` instead: `unwrap_or(Some((1, 2)))`
error: unnecessary closure used with `bool::then`
- --> $DIR/unnecessary_lazy_eval.rs:58:13
+ --> $DIR/unnecessary_lazy_eval.rs:66:13
|
LL | let _ = cond.then(|| astronomers_pi);
| ^^^^^-----------------------
@@ -81,7 +81,7 @@ LL | let _ = cond.then(|| astronomers_pi);
| help: use `then_some(..)` instead: `then_some(astronomers_pi)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:61:13
+ --> $DIR/unnecessary_lazy_eval.rs:69:13
|
LL | let _ = Some(10).unwrap_or_else(|| 2);
| ^^^^^^^^^--------------------
@@ -89,7 +89,7 @@ LL | let _ = Some(10).unwrap_or_else(|| 2);
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:62:13
+ --> $DIR/unnecessary_lazy_eval.rs:70:13
|
LL | let _ = Some(10).and_then(|_| ext_opt);
| ^^^^^^^^^---------------------
@@ -97,7 +97,7 @@ LL | let _ = Some(10).and_then(|_| ext_opt);
| help: use `and(..)` instead: `and(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:63:28
+ --> $DIR/unnecessary_lazy_eval.rs:71:28
|
LL | let _: Option<usize> = None.or_else(|| ext_opt);
| ^^^^^-------------------
@@ -105,7 +105,7 @@ LL | let _: Option<usize> = None.or_else(|| ext_opt);
| help: use `or(..)` instead: `or(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:64:13
+ --> $DIR/unnecessary_lazy_eval.rs:72:13
|
LL | let _ = None.get_or_insert_with(|| 2);
| ^^^^^------------------------
@@ -113,7 +113,7 @@ LL | let _ = None.get_or_insert_with(|| 2);
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:65:35
+ --> $DIR/unnecessary_lazy_eval.rs:73:35
|
LL | let _: Result<usize, usize> = None.ok_or_else(|| 2);
| ^^^^^----------------
@@ -121,7 +121,7 @@ LL | let _: Result<usize, usize> = None.ok_or_else(|| 2);
| help: use `ok_or(..)` instead: `ok_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:66:28
+ --> $DIR/unnecessary_lazy_eval.rs:74:28
|
LL | let _: Option<usize> = None.or_else(|| None);
| ^^^^^----------------
@@ -129,7 +129,7 @@ LL | let _: Option<usize> = None.or_else(|| None);
| help: use `or(..)` instead: `or(None)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:69:13
+ --> $DIR/unnecessary_lazy_eval.rs:77:13
|
LL | let _ = deep.0.unwrap_or_else(|| 2);
| ^^^^^^^--------------------
@@ -137,7 +137,7 @@ LL | let _ = deep.0.unwrap_or_else(|| 2);
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:70:13
+ --> $DIR/unnecessary_lazy_eval.rs:78:13
|
LL | let _ = deep.0.and_then(|_| ext_opt);
| ^^^^^^^---------------------
@@ -145,7 +145,7 @@ LL | let _ = deep.0.and_then(|_| ext_opt);
| help: use `and(..)` instead: `and(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:71:13
+ --> $DIR/unnecessary_lazy_eval.rs:79:13
|
LL | let _ = deep.0.or_else(|| None);
| ^^^^^^^----------------
@@ -153,7 +153,7 @@ LL | let _ = deep.0.or_else(|| None);
| help: use `or(..)` instead: `or(None)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:72:13
+ --> $DIR/unnecessary_lazy_eval.rs:80:13
|
LL | let _ = deep.0.get_or_insert_with(|| 2);
| ^^^^^^^------------------------
@@ -161,7 +161,7 @@ LL | let _ = deep.0.get_or_insert_with(|| 2);
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:73:13
+ --> $DIR/unnecessary_lazy_eval.rs:81:13
|
LL | let _ = deep.0.ok_or_else(|| 2);
| ^^^^^^^----------------
@@ -169,7 +169,7 @@ LL | let _ = deep.0.ok_or_else(|| 2);
| help: use `ok_or(..)` instead: `ok_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:96:28
+ --> $DIR/unnecessary_lazy_eval.rs:105:28
|
LL | let _: Option<usize> = None.or_else(|| Some(3));
| ^^^^^-------------------
@@ -177,7 +177,7 @@ LL | let _: Option<usize> = None.or_else(|| Some(3));
| help: use `or(..)` instead: `or(Some(3))`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:97:13
+ --> $DIR/unnecessary_lazy_eval.rs:106:13
|
LL | let _ = deep.0.or_else(|| Some(3));
| ^^^^^^^-------------------
@@ -185,7 +185,7 @@ LL | let _ = deep.0.or_else(|| Some(3));
| help: use `or(..)` instead: `or(Some(3))`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:98:13
+ --> $DIR/unnecessary_lazy_eval.rs:107:13
|
LL | let _ = opt.or_else(|| Some(3));
| ^^^^-------------------
@@ -193,7 +193,7 @@ LL | let _ = opt.or_else(|| Some(3));
| help: use `or(..)` instead: `or(Some(3))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:104:13
+ --> $DIR/unnecessary_lazy_eval.rs:113:13
|
LL | let _ = res2.unwrap_or_else(|_| 2);
| ^^^^^---------------------
@@ -201,7 +201,7 @@ LL | let _ = res2.unwrap_or_else(|_| 2);
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:105:13
+ --> $DIR/unnecessary_lazy_eval.rs:114:13
|
LL | let _ = res2.unwrap_or_else(|_| astronomers_pi);
| ^^^^^----------------------------------
@@ -209,7 +209,7 @@ LL | let _ = res2.unwrap_or_else(|_| astronomers_pi);
| help: use `unwrap_or(..)` instead: `unwrap_or(astronomers_pi)`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:106:13
+ --> $DIR/unnecessary_lazy_eval.rs:115:13
|
LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field);
| ^^^^^--------------------------------------
@@ -217,7 +217,7 @@ LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field);
| help: use `unwrap_or(..)` instead: `unwrap_or(ext_str.some_field)`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:128:35
+ --> $DIR/unnecessary_lazy_eval.rs:137:35
|
LL | let _: Result<usize, usize> = res.and_then(|_| Err(2));
| ^^^^--------------------
@@ -225,7 +225,7 @@ LL | let _: Result<usize, usize> = res.and_then(|_| Err(2));
| help: use `and(..)` instead: `and(Err(2))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:129:35
+ --> $DIR/unnecessary_lazy_eval.rs:138:35
|
LL | let _: Result<usize, usize> = res.and_then(|_| Err(astronomers_pi));
| ^^^^---------------------------------
@@ -233,7 +233,7 @@ LL | let _: Result<usize, usize> = res.and_then(|_| Err(astronomers_pi));
| help: use `and(..)` instead: `and(Err(astronomers_pi))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:130:35
+ --> $DIR/unnecessary_lazy_eval.rs:139:35
|
LL | let _: Result<usize, usize> = res.and_then(|_| Err(ext_str.some_field));
| ^^^^-------------------------------------
@@ -241,7 +241,7 @@ LL | let _: Result<usize, usize> = res.and_then(|_| Err(ext_str.some_field))
| help: use `and(..)` instead: `and(Err(ext_str.some_field))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:132:35
+ --> $DIR/unnecessary_lazy_eval.rs:141:35
|
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(2));
| ^^^^------------------
@@ -249,7 +249,7 @@ LL | let _: Result<usize, usize> = res.or_else(|_| Ok(2));
| help: use `or(..)` instead: `or(Ok(2))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:133:35
+ --> $DIR/unnecessary_lazy_eval.rs:142:35
|
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(astronomers_pi));
| ^^^^-------------------------------
@@ -257,7 +257,7 @@ LL | let _: Result<usize, usize> = res.or_else(|_| Ok(astronomers_pi));
| help: use `or(..)` instead: `or(Ok(astronomers_pi))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:134:35
+ --> $DIR/unnecessary_lazy_eval.rs:143:35
|
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(ext_str.some_field));
| ^^^^-----------------------------------
@@ -265,19 +265,19 @@ LL | let _: Result<usize, usize> = res.or_else(|_| Ok(ext_str.some_field));
| help: use `or(..)` instead: `or(Ok(ext_str.some_field))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:135:35
+ --> $DIR/unnecessary_lazy_eval.rs:144:35
|
LL | let _: Result<usize, usize> = res.
| ___________________________________^
-LL | | // some lines
-LL | | // some lines
-LL | | // some lines
+LL | | // some lines
+LL | | // some lines
+LL | | // some lines
... |
-LL | | // some lines
-LL | | or_else(|_| Ok(ext_str.some_field));
- | |_________----------------------------------^
- | |
- | help: use `or(..)` instead: `or(Ok(ext_str.some_field))`
+LL | | // some lines
+LL | | or_else(|_| Ok(ext_str.some_field));
+ | |_____----------------------------------^
+ | |
+ | help: use `or(..)` instead: `or(Ok(ext_str.some_field))`
error: aborting due to 34 previous errors
diff --git a/src/tools/clippy/tests/ui/unnecessary_operation.fixed b/src/tools/clippy/tests/ui/unnecessary_operation.fixed
index bf0ec8deb..d37163570 100644
--- a/src/tools/clippy/tests/ui/unnecessary_operation.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_operation.fixed
@@ -76,4 +76,13 @@ fn main() {
DropStruct { ..get_drop_struct() };
DropEnum::Tuple(get_number());
DropEnum::Struct { field: get_number() };
+
+ // Issue #9954
+ fn one() -> i8 {
+ 1
+ }
+ macro_rules! use_expr {
+ ($($e:expr),*) => {{ $($e;)* }}
+ }
+ use_expr!(isize::MIN / -(one() as isize), i8::MIN / -one());
}
diff --git a/src/tools/clippy/tests/ui/unnecessary_operation.rs b/src/tools/clippy/tests/ui/unnecessary_operation.rs
index 08cb9ab52..a14fd4bca 100644
--- a/src/tools/clippy/tests/ui/unnecessary_operation.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_operation.rs
@@ -80,4 +80,13 @@ fn main() {
DropStruct { ..get_drop_struct() };
DropEnum::Tuple(get_number());
DropEnum::Struct { field: get_number() };
+
+ // Issue #9954
+ fn one() -> i8 {
+ 1
+ }
+ macro_rules! use_expr {
+ ($($e:expr),*) => {{ $($e;)* }}
+ }
+ use_expr!(isize::MIN / -(one() as isize), i8::MIN / -one());
}
diff --git a/src/tools/clippy/tests/ui/unnecessary_safety_comment.rs b/src/tools/clippy/tests/ui/unnecessary_safety_comment.rs
new file mode 100644
index 000000000..7fefea705
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unnecessary_safety_comment.rs
@@ -0,0 +1,51 @@
+#![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)]
+#![allow(clippy::let_unit_value, clippy::missing_safety_doc)]
+
+mod unsafe_items_invalid_comment {
+ // SAFETY:
+ const CONST: u32 = 0;
+ // SAFETY:
+ static STATIC: u32 = 0;
+ // SAFETY:
+ struct Struct;
+ // SAFETY:
+ enum Enum {}
+ // SAFETY:
+ mod module {}
+}
+
+mod unnecessary_from_macro {
+ trait T {}
+
+ macro_rules! no_safety_comment {
+ ($t:ty) => {
+ impl T for $t {}
+ };
+ }
+
+ // FIXME: This is not caught
+ // Safety: unnecessary
+ no_safety_comment!(());
+
+ macro_rules! with_safety_comment {
+ ($t:ty) => {
+ // Safety: unnecessary
+ impl T for $t {}
+ };
+ }
+
+ with_safety_comment!(i32);
+}
+
+fn unnecessary_on_stmt_and_expr() -> u32 {
+ // SAFETY: unnecessary
+ let num = 42;
+
+ // SAFETY: unnecessary
+ if num > 24 {}
+
+ // SAFETY: unnecessary
+ 24
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/unnecessary_safety_comment.stderr b/src/tools/clippy/tests/ui/unnecessary_safety_comment.stderr
new file mode 100644
index 000000000..7b2af67d6
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unnecessary_safety_comment.stderr
@@ -0,0 +1,115 @@
+error: constant item has unnecessary safety comment
+ --> $DIR/unnecessary_safety_comment.rs:6:5
+ |
+LL | const CONST: u32 = 0;
+ | ^^^^^^^^^^^^^^^^^^^^^
+ |
+help: consider removing the safety comment
+ --> $DIR/unnecessary_safety_comment.rs:5:5
+ |
+LL | // SAFETY:
+ | ^^^^^^^^^^
+ = note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings`
+
+error: static item has unnecessary safety comment
+ --> $DIR/unnecessary_safety_comment.rs:8:5
+ |
+LL | static STATIC: u32 = 0;
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: consider removing the safety comment
+ --> $DIR/unnecessary_safety_comment.rs:7:5
+ |
+LL | // SAFETY:
+ | ^^^^^^^^^^
+
+error: struct has unnecessary safety comment
+ --> $DIR/unnecessary_safety_comment.rs:10:5
+ |
+LL | struct Struct;
+ | ^^^^^^^^^^^^^^
+ |
+help: consider removing the safety comment
+ --> $DIR/unnecessary_safety_comment.rs:9:5
+ |
+LL | // SAFETY:
+ | ^^^^^^^^^^
+
+error: enum has unnecessary safety comment
+ --> $DIR/unnecessary_safety_comment.rs:12:5
+ |
+LL | enum Enum {}
+ | ^^^^^^^^^^^^
+ |
+help: consider removing the safety comment
+ --> $DIR/unnecessary_safety_comment.rs:11:5
+ |
+LL | // SAFETY:
+ | ^^^^^^^^^^
+
+error: module has unnecessary safety comment
+ --> $DIR/unnecessary_safety_comment.rs:14:5
+ |
+LL | mod module {}
+ | ^^^^^^^^^^^^^
+ |
+help: consider removing the safety comment
+ --> $DIR/unnecessary_safety_comment.rs:13:5
+ |
+LL | // SAFETY:
+ | ^^^^^^^^^^
+
+error: impl has unnecessary safety comment
+ --> $DIR/unnecessary_safety_comment.rs:33:13
+ |
+LL | impl T for $t {}
+ | ^^^^^^^^^^^^^^^^
+...
+LL | with_safety_comment!(i32);
+ | ------------------------- in this macro invocation
+ |
+help: consider removing the safety comment
+ --> $DIR/unnecessary_safety_comment.rs:32:13
+ |
+LL | // Safety: unnecessary
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ = note: this error originates in the macro `with_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: expression has unnecessary safety comment
+ --> $DIR/unnecessary_safety_comment.rs:48:5
+ |
+LL | 24
+ | ^^
+ |
+help: consider removing the safety comment
+ --> $DIR/unnecessary_safety_comment.rs:47:5
+ |
+LL | // SAFETY: unnecessary
+ | ^^^^^^^^^^^^^^^^^^^^^^
+
+error: statement has unnecessary safety comment
+ --> $DIR/unnecessary_safety_comment.rs:42:5
+ |
+LL | let num = 42;
+ | ^^^^^^^^^^^^^
+ |
+help: consider removing the safety comment
+ --> $DIR/unnecessary_safety_comment.rs:41:5
+ |
+LL | // SAFETY: unnecessary
+ | ^^^^^^^^^^^^^^^^^^^^^^
+
+error: statement has unnecessary safety comment
+ --> $DIR/unnecessary_safety_comment.rs:45:5
+ |
+LL | if num > 24 {}
+ | ^^^^^^^^^^^^^^
+ |
+help: consider removing the safety comment
+ --> $DIR/unnecessary_safety_comment.rs:44:5
+ |
+LL | // SAFETY: unnecessary
+ | ^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 9 previous errors
+
diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
index fe09aad06..ddeda795f 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
@@ -2,7 +2,6 @@
#![allow(clippy::needless_borrow, clippy::ptr_arg)]
#![warn(clippy::unnecessary_to_owned)]
-#![feature(custom_inner_attributes)]
use std::borrow::Cow;
use std::ffi::{CStr, CString, OsStr, OsString};
@@ -215,14 +214,14 @@ fn get_file_path(_file_type: &FileType) -> Result<std::path::PathBuf, std::io::E
fn require_string(_: &String) {}
+#[clippy::msrv = "1.35"]
fn _msrv_1_35() {
- #![clippy::msrv = "1.35"]
// `copied` was stabilized in 1.36, so clippy should use `cloned`.
let _ = &["x"][..].iter().cloned();
}
+#[clippy::msrv = "1.36"]
fn _msrv_1_36() {
- #![clippy::msrv = "1.36"]
let _ = &["x"][..].iter().copied();
}
@@ -426,3 +425,32 @@ mod issue_9504 {
foo(std::path::PathBuf::new().to_string_lossy().to_string()).await;
}
}
+
+mod issue_9771a {
+ #![allow(dead_code)]
+
+ use std::marker::PhantomData;
+
+ pub struct Key<K: AsRef<[u8]>, V: ?Sized>(K, PhantomData<V>);
+
+ impl<K: AsRef<[u8]>, V: ?Sized> Key<K, V> {
+ pub fn new(key: K) -> Key<K, V> {
+ Key(key, PhantomData)
+ }
+ }
+
+ pub fn pkh(pkh: &[u8]) -> Key<Vec<u8>, String> {
+ Key::new([b"pkh-", pkh].concat().to_vec())
+ }
+}
+
+mod issue_9771b {
+ #![allow(dead_code)]
+
+ pub struct Key<K: AsRef<[u8]>>(K);
+
+ pub fn from(c: &[u8]) -> Key<Vec<u8>> {
+ let v = [c].concat();
+ Key(v.to_vec())
+ }
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
index 3de6d0903..95d257673 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
@@ -2,7 +2,6 @@
#![allow(clippy::needless_borrow, clippy::ptr_arg)]
#![warn(clippy::unnecessary_to_owned)]
-#![feature(custom_inner_attributes)]
use std::borrow::Cow;
use std::ffi::{CStr, CString, OsStr, OsString};
@@ -215,14 +214,14 @@ fn get_file_path(_file_type: &FileType) -> Result<std::path::PathBuf, std::io::E
fn require_string(_: &String) {}
+#[clippy::msrv = "1.35"]
fn _msrv_1_35() {
- #![clippy::msrv = "1.35"]
// `copied` was stabilized in 1.36, so clippy should use `cloned`.
let _ = &["x"][..].to_vec().into_iter();
}
+#[clippy::msrv = "1.36"]
fn _msrv_1_36() {
- #![clippy::msrv = "1.36"]
let _ = &["x"][..].to_vec().into_iter();
}
@@ -426,3 +425,32 @@ mod issue_9504 {
foo(std::path::PathBuf::new().to_string_lossy().to_string()).await;
}
}
+
+mod issue_9771a {
+ #![allow(dead_code)]
+
+ use std::marker::PhantomData;
+
+ pub struct Key<K: AsRef<[u8]>, V: ?Sized>(K, PhantomData<V>);
+
+ impl<K: AsRef<[u8]>, V: ?Sized> Key<K, V> {
+ pub fn new(key: K) -> Key<K, V> {
+ Key(key, PhantomData)
+ }
+ }
+
+ pub fn pkh(pkh: &[u8]) -> Key<Vec<u8>, String> {
+ Key::new([b"pkh-", pkh].concat().to_vec())
+ }
+}
+
+mod issue_9771b {
+ #![allow(dead_code)]
+
+ pub struct Key<K: AsRef<[u8]>>(K);
+
+ pub fn from(c: &[u8]) -> Key<Vec<u8>> {
+ let v = [c].concat();
+ Key(v.to_vec())
+ }
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr b/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr
index 02bf45a33..4918fe355 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr
@@ -1,66 +1,66 @@
error: redundant clone
- --> $DIR/unnecessary_to_owned.rs:151:64
+ --> $DIR/unnecessary_to_owned.rs:150:64
|
LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned());
| ^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/unnecessary_to_owned.rs:151:20
+ --> $DIR/unnecessary_to_owned.rs:150:20
|
LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `-D clippy::redundant-clone` implied by `-D warnings`
error: redundant clone
- --> $DIR/unnecessary_to_owned.rs:152:40
+ --> $DIR/unnecessary_to_owned.rs:151:40
|
LL | require_os_str(&OsString::from("x").to_os_string());
| ^^^^^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/unnecessary_to_owned.rs:152:21
+ --> $DIR/unnecessary_to_owned.rs:151:21
|
LL | require_os_str(&OsString::from("x").to_os_string());
| ^^^^^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/unnecessary_to_owned.rs:153:48
+ --> $DIR/unnecessary_to_owned.rs:152:48
|
LL | require_path(&std::path::PathBuf::from("x").to_path_buf());
| ^^^^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/unnecessary_to_owned.rs:153:19
+ --> $DIR/unnecessary_to_owned.rs:152:19
|
LL | require_path(&std::path::PathBuf::from("x").to_path_buf());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/unnecessary_to_owned.rs:154:35
+ --> $DIR/unnecessary_to_owned.rs:153:35
|
LL | require_str(&String::from("x").to_string());
| ^^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/unnecessary_to_owned.rs:154:18
+ --> $DIR/unnecessary_to_owned.rs:153:18
|
LL | require_str(&String::from("x").to_string());
| ^^^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/unnecessary_to_owned.rs:155:39
+ --> $DIR/unnecessary_to_owned.rs:154:39
|
LL | require_slice(&[String::from("x")].to_owned());
| ^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/unnecessary_to_owned.rs:155:20
+ --> $DIR/unnecessary_to_owned.rs:154:20
|
LL | require_slice(&[String::from("x")].to_owned());
| ^^^^^^^^^^^^^^^^^^^
error: unnecessary use of `into_owned`
- --> $DIR/unnecessary_to_owned.rs:60:36
+ --> $DIR/unnecessary_to_owned.rs:59:36
|
LL | require_c_str(&Cow::from(c_str).into_owned());
| ^^^^^^^^^^^^^ help: remove this
@@ -68,415 +68,415 @@ LL | require_c_str(&Cow::from(c_str).into_owned());
= note: `-D clippy::unnecessary-to-owned` implied by `-D warnings`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:61:19
+ --> $DIR/unnecessary_to_owned.rs:60:19
|
LL | require_c_str(&c_str.to_owned());
| ^^^^^^^^^^^^^^^^^ help: use: `c_str`
error: unnecessary use of `to_os_string`
- --> $DIR/unnecessary_to_owned.rs:63:20
+ --> $DIR/unnecessary_to_owned.rs:62:20
|
LL | require_os_str(&os_str.to_os_string());
| ^^^^^^^^^^^^^^^^^^^^^^ help: use: `os_str`
error: unnecessary use of `into_owned`
- --> $DIR/unnecessary_to_owned.rs:64:38
+ --> $DIR/unnecessary_to_owned.rs:63:38
|
LL | require_os_str(&Cow::from(os_str).into_owned());
| ^^^^^^^^^^^^^ help: remove this
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:65:20
+ --> $DIR/unnecessary_to_owned.rs:64:20
|
LL | require_os_str(&os_str.to_owned());
| ^^^^^^^^^^^^^^^^^^ help: use: `os_str`
error: unnecessary use of `to_path_buf`
- --> $DIR/unnecessary_to_owned.rs:67:18
+ --> $DIR/unnecessary_to_owned.rs:66:18
|
LL | require_path(&path.to_path_buf());
| ^^^^^^^^^^^^^^^^^^^ help: use: `path`
error: unnecessary use of `into_owned`
- --> $DIR/unnecessary_to_owned.rs:68:34
+ --> $DIR/unnecessary_to_owned.rs:67:34
|
LL | require_path(&Cow::from(path).into_owned());
| ^^^^^^^^^^^^^ help: remove this
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:69:18
+ --> $DIR/unnecessary_to_owned.rs:68:18
|
LL | require_path(&path.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `path`
error: unnecessary use of `to_string`
- --> $DIR/unnecessary_to_owned.rs:71:17
+ --> $DIR/unnecessary_to_owned.rs:70:17
|
LL | require_str(&s.to_string());
| ^^^^^^^^^^^^^^ help: use: `s`
error: unnecessary use of `into_owned`
- --> $DIR/unnecessary_to_owned.rs:72:30
+ --> $DIR/unnecessary_to_owned.rs:71:30
|
LL | require_str(&Cow::from(s).into_owned());
| ^^^^^^^^^^^^^ help: remove this
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:73:17
+ --> $DIR/unnecessary_to_owned.rs:72:17
|
LL | require_str(&s.to_owned());
| ^^^^^^^^^^^^^ help: use: `s`
error: unnecessary use of `to_string`
- --> $DIR/unnecessary_to_owned.rs:74:17
+ --> $DIR/unnecessary_to_owned.rs:73:17
|
LL | require_str(&x_ref.to_string());
| ^^^^^^^^^^^^^^^^^^ help: use: `x_ref.as_ref()`
error: unnecessary use of `to_vec`
- --> $DIR/unnecessary_to_owned.rs:76:19
+ --> $DIR/unnecessary_to_owned.rs:75:19
|
LL | require_slice(&slice.to_vec());
| ^^^^^^^^^^^^^^^ help: use: `slice`
error: unnecessary use of `into_owned`
- --> $DIR/unnecessary_to_owned.rs:77:36
+ --> $DIR/unnecessary_to_owned.rs:76:36
|
LL | require_slice(&Cow::from(slice).into_owned());
| ^^^^^^^^^^^^^ help: remove this
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:78:19
+ --> $DIR/unnecessary_to_owned.rs:77:19
|
LL | require_slice(&array.to_owned());
| ^^^^^^^^^^^^^^^^^ help: use: `array.as_ref()`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:79:19
+ --> $DIR/unnecessary_to_owned.rs:78:19
|
LL | require_slice(&array_ref.to_owned());
| ^^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref.as_ref()`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:80:19
+ --> $DIR/unnecessary_to_owned.rs:79:19
|
LL | require_slice(&slice.to_owned());
| ^^^^^^^^^^^^^^^^^ help: use: `slice`
error: unnecessary use of `into_owned`
- --> $DIR/unnecessary_to_owned.rs:83:42
+ --> $DIR/unnecessary_to_owned.rs:82:42
|
LL | require_x(&Cow::<X>::Owned(x.clone()).into_owned());
| ^^^^^^^^^^^^^ help: remove this
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:86:25
+ --> $DIR/unnecessary_to_owned.rs:85:25
|
LL | require_deref_c_str(c_str.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `c_str`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:87:26
+ --> $DIR/unnecessary_to_owned.rs:86:26
|
LL | require_deref_os_str(os_str.to_owned());
| ^^^^^^^^^^^^^^^^^ help: use: `os_str`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:88:24
+ --> $DIR/unnecessary_to_owned.rs:87:24
|
LL | require_deref_path(path.to_owned());
| ^^^^^^^^^^^^^^^ help: use: `path`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:89:23
+ --> $DIR/unnecessary_to_owned.rs:88:23
|
LL | require_deref_str(s.to_owned());
| ^^^^^^^^^^^^ help: use: `s`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:90:25
+ --> $DIR/unnecessary_to_owned.rs:89:25
|
LL | require_deref_slice(slice.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `slice`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:92:30
+ --> $DIR/unnecessary_to_owned.rs:91:30
|
LL | require_impl_deref_c_str(c_str.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `c_str`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:93:31
+ --> $DIR/unnecessary_to_owned.rs:92:31
|
LL | require_impl_deref_os_str(os_str.to_owned());
| ^^^^^^^^^^^^^^^^^ help: use: `os_str`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:94:29
+ --> $DIR/unnecessary_to_owned.rs:93:29
|
LL | require_impl_deref_path(path.to_owned());
| ^^^^^^^^^^^^^^^ help: use: `path`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:95:28
+ --> $DIR/unnecessary_to_owned.rs:94:28
|
LL | require_impl_deref_str(s.to_owned());
| ^^^^^^^^^^^^ help: use: `s`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:96:30
+ --> $DIR/unnecessary_to_owned.rs:95:30
|
LL | require_impl_deref_slice(slice.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `slice`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:98:29
+ --> $DIR/unnecessary_to_owned.rs:97:29
|
LL | require_deref_str_slice(s.to_owned(), slice.to_owned());
| ^^^^^^^^^^^^ help: use: `s`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:98:43
+ --> $DIR/unnecessary_to_owned.rs:97:43
|
LL | require_deref_str_slice(s.to_owned(), slice.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `slice`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:99:29
+ --> $DIR/unnecessary_to_owned.rs:98:29
|
LL | require_deref_slice_str(slice.to_owned(), s.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `slice`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:99:47
+ --> $DIR/unnecessary_to_owned.rs:98:47
|
LL | require_deref_slice_str(slice.to_owned(), s.to_owned());
| ^^^^^^^^^^^^ help: use: `s`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:101:26
+ --> $DIR/unnecessary_to_owned.rs:100:26
|
LL | require_as_ref_c_str(c_str.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `c_str`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:102:27
+ --> $DIR/unnecessary_to_owned.rs:101:27
|
LL | require_as_ref_os_str(os_str.to_owned());
| ^^^^^^^^^^^^^^^^^ help: use: `os_str`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:103:25
+ --> $DIR/unnecessary_to_owned.rs:102:25
|
LL | require_as_ref_path(path.to_owned());
| ^^^^^^^^^^^^^^^ help: use: `path`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:104:24
+ --> $DIR/unnecessary_to_owned.rs:103:24
|
LL | require_as_ref_str(s.to_owned());
| ^^^^^^^^^^^^ help: use: `s`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:105:24
+ --> $DIR/unnecessary_to_owned.rs:104:24
|
LL | require_as_ref_str(x.to_owned());
| ^^^^^^^^^^^^ help: use: `&x`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:106:26
+ --> $DIR/unnecessary_to_owned.rs:105:26
|
LL | require_as_ref_slice(array.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `array`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:107:26
+ --> $DIR/unnecessary_to_owned.rs:106:26
|
LL | require_as_ref_slice(array_ref.to_owned());
| ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:108:26
+ --> $DIR/unnecessary_to_owned.rs:107:26
|
LL | require_as_ref_slice(slice.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `slice`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:110:31
+ --> $DIR/unnecessary_to_owned.rs:109:31
|
LL | require_impl_as_ref_c_str(c_str.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `c_str`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:111:32
+ --> $DIR/unnecessary_to_owned.rs:110:32
|
LL | require_impl_as_ref_os_str(os_str.to_owned());
| ^^^^^^^^^^^^^^^^^ help: use: `os_str`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:112:30
+ --> $DIR/unnecessary_to_owned.rs:111:30
|
LL | require_impl_as_ref_path(path.to_owned());
| ^^^^^^^^^^^^^^^ help: use: `path`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:113:29
+ --> $DIR/unnecessary_to_owned.rs:112:29
|
LL | require_impl_as_ref_str(s.to_owned());
| ^^^^^^^^^^^^ help: use: `s`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:114:29
+ --> $DIR/unnecessary_to_owned.rs:113:29
|
LL | require_impl_as_ref_str(x.to_owned());
| ^^^^^^^^^^^^ help: use: `&x`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:115:31
+ --> $DIR/unnecessary_to_owned.rs:114:31
|
LL | require_impl_as_ref_slice(array.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `array`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:116:31
+ --> $DIR/unnecessary_to_owned.rs:115:31
|
LL | require_impl_as_ref_slice(array_ref.to_owned());
| ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:117:31
+ --> $DIR/unnecessary_to_owned.rs:116:31
|
LL | require_impl_as_ref_slice(slice.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `slice`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:119:30
+ --> $DIR/unnecessary_to_owned.rs:118:30
|
LL | require_as_ref_str_slice(s.to_owned(), array.to_owned());
| ^^^^^^^^^^^^ help: use: `s`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:119:44
+ --> $DIR/unnecessary_to_owned.rs:118:44
|
LL | require_as_ref_str_slice(s.to_owned(), array.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `array`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:120:30
+ --> $DIR/unnecessary_to_owned.rs:119:30
|
LL | require_as_ref_str_slice(s.to_owned(), array_ref.to_owned());
| ^^^^^^^^^^^^ help: use: `s`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:120:44
+ --> $DIR/unnecessary_to_owned.rs:119:44
|
LL | require_as_ref_str_slice(s.to_owned(), array_ref.to_owned());
| ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:121:30
+ --> $DIR/unnecessary_to_owned.rs:120:30
|
LL | require_as_ref_str_slice(s.to_owned(), slice.to_owned());
| ^^^^^^^^^^^^ help: use: `s`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:121:44
+ --> $DIR/unnecessary_to_owned.rs:120:44
|
LL | require_as_ref_str_slice(s.to_owned(), slice.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `slice`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:122:30
+ --> $DIR/unnecessary_to_owned.rs:121:30
|
LL | require_as_ref_slice_str(array.to_owned(), s.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `array`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:122:48
+ --> $DIR/unnecessary_to_owned.rs:121:48
|
LL | require_as_ref_slice_str(array.to_owned(), s.to_owned());
| ^^^^^^^^^^^^ help: use: `s`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:123:30
+ --> $DIR/unnecessary_to_owned.rs:122:30
|
LL | require_as_ref_slice_str(array_ref.to_owned(), s.to_owned());
| ^^^^^^^^^^^^^^^^^^^^ help: use: `array_ref`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:123:52
+ --> $DIR/unnecessary_to_owned.rs:122:52
|
LL | require_as_ref_slice_str(array_ref.to_owned(), s.to_owned());
| ^^^^^^^^^^^^ help: use: `s`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:124:30
+ --> $DIR/unnecessary_to_owned.rs:123:30
|
LL | require_as_ref_slice_str(slice.to_owned(), s.to_owned());
| ^^^^^^^^^^^^^^^^ help: use: `slice`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:124:48
+ --> $DIR/unnecessary_to_owned.rs:123:48
|
LL | require_as_ref_slice_str(slice.to_owned(), s.to_owned());
| ^^^^^^^^^^^^ help: use: `s`
error: unnecessary use of `to_string`
- --> $DIR/unnecessary_to_owned.rs:126:20
+ --> $DIR/unnecessary_to_owned.rs:125:20
|
LL | let _ = x.join(&x_ref.to_string());
| ^^^^^^^^^^^^^^^^^^ help: use: `x_ref`
error: unnecessary use of `to_vec`
- --> $DIR/unnecessary_to_owned.rs:128:13
+ --> $DIR/unnecessary_to_owned.rs:127:13
|
LL | let _ = slice.to_vec().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:129:13
+ --> $DIR/unnecessary_to_owned.rs:128:13
|
LL | let _ = slice.to_owned().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()`
error: unnecessary use of `to_vec`
- --> $DIR/unnecessary_to_owned.rs:130:13
+ --> $DIR/unnecessary_to_owned.rs:129:13
|
LL | let _ = [std::path::PathBuf::new()][..].to_vec().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:131:13
+ --> $DIR/unnecessary_to_owned.rs:130:13
|
LL | let _ = [std::path::PathBuf::new()][..].to_owned().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()`
error: unnecessary use of `to_vec`
- --> $DIR/unnecessary_to_owned.rs:133:13
+ --> $DIR/unnecessary_to_owned.rs:132:13
|
LL | let _ = IntoIterator::into_iter(slice.to_vec());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:134:13
+ --> $DIR/unnecessary_to_owned.rs:133:13
|
LL | let _ = IntoIterator::into_iter(slice.to_owned());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `slice.iter().copied()`
error: unnecessary use of `to_vec`
- --> $DIR/unnecessary_to_owned.rs:135:13
+ --> $DIR/unnecessary_to_owned.rs:134:13
|
LL | let _ = IntoIterator::into_iter([std::path::PathBuf::new()][..].to_vec());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()`
error: unnecessary use of `to_owned`
- --> $DIR/unnecessary_to_owned.rs:136:13
+ --> $DIR/unnecessary_to_owned.rs:135:13
|
LL | let _ = IntoIterator::into_iter([std::path::PathBuf::new()][..].to_owned());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `[std::path::PathBuf::new()][..].iter().cloned()`
error: unnecessary use of `to_vec`
- --> $DIR/unnecessary_to_owned.rs:198:14
+ --> $DIR/unnecessary_to_owned.rs:197:14
|
LL | for t in file_types.to_vec() {
| ^^^^^^^^^^^^^^^^^^^
@@ -492,25 +492,25 @@ LL + let path = match get_file_path(t) {
|
error: unnecessary use of `to_vec`
- --> $DIR/unnecessary_to_owned.rs:221:14
+ --> $DIR/unnecessary_to_owned.rs:220:14
|
LL | let _ = &["x"][..].to_vec().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().cloned()`
error: unnecessary use of `to_vec`
- --> $DIR/unnecessary_to_owned.rs:226:14
+ --> $DIR/unnecessary_to_owned.rs:225:14
|
LL | let _ = &["x"][..].to_vec().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().copied()`
error: unnecessary use of `to_string`
- --> $DIR/unnecessary_to_owned.rs:273:24
+ --> $DIR/unnecessary_to_owned.rs:272:24
|
LL | Box::new(build(y.to_string()))
| ^^^^^^^^^^^^^ help: use: `y`
error: unnecessary use of `to_string`
- --> $DIR/unnecessary_to_owned.rs:381:12
+ --> $DIR/unnecessary_to_owned.rs:380:12
|
LL | id("abc".to_string())
| ^^^^^^^^^^^^^^^^^ help: use: `"abc"`
diff --git a/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs b/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs
new file mode 100644
index 000000000..c160e31af
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs
@@ -0,0 +1,149 @@
+// aux-build:doc_unsafe_macros.rs
+
+#![allow(clippy::let_unit_value)]
+#![warn(clippy::unnecessary_safety_doc)]
+
+#[macro_use]
+extern crate doc_unsafe_macros;
+
+/// This is has no safety section, and does not need one either
+pub fn destroy_the_planet() {
+ unimplemented!();
+}
+
+/// This one does not need a `Safety` section
+///
+/// # Safety
+///
+/// This function shouldn't be called unless the horsemen are ready
+pub fn apocalypse(universe: &mut ()) {
+ unimplemented!();
+}
+
+/// This is a private function, skip to match behavior with `missing_safety_doc`.
+///
+/// # Safety
+///
+/// Boo!
+fn you_dont_see_me() {
+ unimplemented!();
+}
+
+mod private_mod {
+ /// This is public but unexported function, skip to match behavior with `missing_safety_doc`.
+ ///
+ /// # Safety
+ ///
+ /// Very safe!
+ pub fn only_crate_wide_accessible() {
+ unimplemented!();
+ }
+
+ /// # Safety
+ ///
+ /// Unnecessary safety!
+ pub fn republished() {
+ unimplemented!();
+ }
+}
+
+pub use private_mod::republished;
+
+pub trait SafeTraitSafeMethods {
+ fn woefully_underdocumented(self);
+
+ /// # Safety
+ ///
+ /// Unnecessary!
+ fn documented(self);
+}
+
+pub trait SafeTrait {
+ fn method();
+}
+
+/// # Safety
+///
+/// Unnecessary!
+pub trait DocumentedSafeTrait {
+ fn method2();
+}
+
+pub struct Struct;
+
+impl SafeTraitSafeMethods for Struct {
+ fn woefully_underdocumented(self) {
+ // all is well
+ }
+
+ fn documented(self) {
+ // all is still well
+ }
+}
+
+impl SafeTrait for Struct {
+ fn method() {}
+}
+
+impl DocumentedSafeTrait for Struct {
+ fn method2() {}
+}
+
+impl Struct {
+ /// # Safety
+ ///
+ /// Unnecessary!
+ pub fn documented() -> Self {
+ unimplemented!();
+ }
+
+ pub fn undocumented(&self) {
+ unimplemented!();
+ }
+
+ /// Private, fine again to stay consistent with `missing_safety_doc`.
+ ///
+ /// # Safety
+ ///
+ /// Unnecessary!
+ fn private(&self) {
+ unimplemented!();
+ }
+}
+
+macro_rules! very_safe {
+ () => {
+ pub fn whee() {
+ unimplemented!()
+ }
+
+ /// # Safety
+ ///
+ /// Driving is very safe already!
+ pub fn drive() {
+ whee()
+ }
+ };
+}
+
+very_safe!();
+
+// we don't lint code from external macros
+undocd_safe!();
+
+fn main() {}
+
+// do not lint if any parent has `#[doc(hidden)]` attribute
+// see #7347
+#[doc(hidden)]
+pub mod __macro {
+ pub struct T;
+ impl T {
+ pub unsafe fn f() {}
+ }
+}
+
+/// # Implementation safety
+pub trait DocumentedSafeTraitWithImplementationHeader {
+ fn method();
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.stderr b/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.stderr
new file mode 100644
index 000000000..72898c93f
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.stderr
@@ -0,0 +1,51 @@
+error: safe function's docs have unnecessary `# Safety` section
+ --> $DIR/unnecessary_unsafety_doc.rs:19:1
+ |
+LL | pub fn apocalypse(universe: &mut ()) {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::unnecessary-safety-doc` implied by `-D warnings`
+
+error: safe function's docs have unnecessary `# Safety` section
+ --> $DIR/unnecessary_unsafety_doc.rs:45:5
+ |
+LL | pub fn republished() {
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: safe function's docs have unnecessary `# Safety` section
+ --> $DIR/unnecessary_unsafety_doc.rs:58:5
+ |
+LL | fn documented(self);
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: docs for safe trait have unnecessary `# Safety` section
+ --> $DIR/unnecessary_unsafety_doc.rs:68:1
+ |
+LL | pub trait DocumentedSafeTrait {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: safe function's docs have unnecessary `# Safety` section
+ --> $DIR/unnecessary_unsafety_doc.rs:96:5
+ |
+LL | pub fn documented() -> Self {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: safe function's docs have unnecessary `# Safety` section
+ --> $DIR/unnecessary_unsafety_doc.rs:123:9
+ |
+LL | pub fn drive() {
+ | ^^^^^^^^^^^^^^
+...
+LL | very_safe!();
+ | ------------ in this macro invocation
+ |
+ = note: this error originates in the macro `very_safe` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: docs for safe trait have unnecessary `# Safety` section
+ --> $DIR/unnecessary_unsafety_doc.rs:147:1
+ |
+LL | pub trait DocumentedSafeTraitWithImplementationHeader {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 7 previous errors
+
diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns.fixed b/src/tools/clippy/tests/ui/unnested_or_patterns.fixed
index 9786c7b12..0a8e7b34d 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns.fixed
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns.fixed
@@ -1,6 +1,6 @@
// run-rustfix
-#![feature(box_patterns, custom_inner_attributes)]
+#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)]
#![allow(unreachable_patterns, irrefutable_let_patterns, unused)]
@@ -34,14 +34,12 @@ fn main() {
if let S { x: 0, y, .. } | S { y, x: 1 } = (S { x: 0, y: 1 }) {}
}
+#[clippy::msrv = "1.52"]
fn msrv_1_52() {
- #![clippy::msrv = "1.52"]
-
if let [1] | [52] = [0] {}
}
+#[clippy::msrv = "1.53"]
fn msrv_1_53() {
- #![clippy::msrv = "1.53"]
-
if let [1 | 53] = [0] {}
}
diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns.rs b/src/tools/clippy/tests/ui/unnested_or_patterns.rs
index f57322396..2c454adfe 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns.rs
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns.rs
@@ -1,6 +1,6 @@
// run-rustfix
-#![feature(box_patterns, custom_inner_attributes)]
+#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)]
#![allow(unreachable_patterns, irrefutable_let_patterns, unused)]
@@ -34,14 +34,12 @@ fn main() {
if let S { x: 0, y, .. } | S { y, x: 1 } = (S { x: 0, y: 1 }) {}
}
+#[clippy::msrv = "1.52"]
fn msrv_1_52() {
- #![clippy::msrv = "1.52"]
-
if let [1] | [52] = [0] {}
}
+#[clippy::msrv = "1.53"]
fn msrv_1_53() {
- #![clippy::msrv = "1.53"]
-
if let [1] | [53] = [0] {}
}
diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns.stderr b/src/tools/clippy/tests/ui/unnested_or_patterns.stderr
index fbc12fff0..a1f193db5 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns.stderr
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns.stderr
@@ -176,7 +176,7 @@ LL | if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {}
| ~~~~~~~~~~~~~~~~~
error: unnested or-patterns
- --> $DIR/unnested_or_patterns.rs:46:12
+ --> $DIR/unnested_or_patterns.rs:44:12
|
LL | if let [1] | [53] = [0] {}
| ^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/unused_rounding.fixed b/src/tools/clippy/tests/ui/unused_rounding.fixed
index 54f85806a..f6f734c05 100644
--- a/src/tools/clippy/tests/ui/unused_rounding.fixed
+++ b/src/tools/clippy/tests/ui/unused_rounding.fixed
@@ -6,4 +6,12 @@ fn main() {
let _ = 1.0f64;
let _ = 1.00f32;
let _ = 2e-54f64.floor();
+
+ // issue9866
+ let _ = 3.3_f32.round();
+ let _ = 3.3_f64.round();
+ let _ = 3.0_f32;
+
+ let _ = 3_3.0_0_f32;
+ let _ = 3_3.0_1_f64.round();
}
diff --git a/src/tools/clippy/tests/ui/unused_rounding.rs b/src/tools/clippy/tests/ui/unused_rounding.rs
index 8d007bc4a..a0267d814 100644
--- a/src/tools/clippy/tests/ui/unused_rounding.rs
+++ b/src/tools/clippy/tests/ui/unused_rounding.rs
@@ -6,4 +6,12 @@ fn main() {
let _ = 1.0f64.floor();
let _ = 1.00f32.round();
let _ = 2e-54f64.floor();
+
+ // issue9866
+ let _ = 3.3_f32.round();
+ let _ = 3.3_f64.round();
+ let _ = 3.0_f32.round();
+
+ let _ = 3_3.0_0_f32.round();
+ let _ = 3_3.0_1_f64.round();
}
diff --git a/src/tools/clippy/tests/ui/unused_rounding.stderr b/src/tools/clippy/tests/ui/unused_rounding.stderr
index 6cfb02e04..b867996fe 100644
--- a/src/tools/clippy/tests/ui/unused_rounding.stderr
+++ b/src/tools/clippy/tests/ui/unused_rounding.stderr
@@ -18,5 +18,17 @@ error: used the `round` method with a whole number float
LL | let _ = 1.00f32.round();
| ^^^^^^^^^^^^^^^ help: remove the `round` method call: `1.00f32`
-error: aborting due to 3 previous errors
+error: used the `round` method with a whole number float
+ --> $DIR/unused_rounding.rs:13:13
+ |
+LL | let _ = 3.0_f32.round();
+ | ^^^^^^^^^^^^^^^ help: remove the `round` method call: `3.0_f32`
+
+error: used the `round` method with a whole number float
+ --> $DIR/unused_rounding.rs:15:13
+ |
+LL | let _ = 3_3.0_0_f32.round();
+ | ^^^^^^^^^^^^^^^^^^^ help: remove the `round` method call: `3_3.0_0_f32`
+
+error: aborting due to 5 previous errors
diff --git a/src/tools/clippy/tests/ui/unused_unit.fixed b/src/tools/clippy/tests/ui/unused_unit.fixed
index 7bb43cf7a..3dd640b86 100644
--- a/src/tools/clippy/tests/ui/unused_unit.fixed
+++ b/src/tools/clippy/tests/ui/unused_unit.fixed
@@ -7,6 +7,7 @@
// test of the JSON error format.
#![feature(custom_inner_attributes)]
+#![feature(closure_lifetime_binder)]
#![rustfmt::skip]
#![deny(clippy::unused_unit)]
@@ -87,3 +88,9 @@ fn macro_expr() {
}
e!()
}
+
+mod issue9748 {
+ fn main() {
+ let _ = for<'a> |_: &'a u32| -> () {};
+ }
+}
diff --git a/src/tools/clippy/tests/ui/unused_unit.rs b/src/tools/clippy/tests/ui/unused_unit.rs
index 21073fb80..bddecf06f 100644
--- a/src/tools/clippy/tests/ui/unused_unit.rs
+++ b/src/tools/clippy/tests/ui/unused_unit.rs
@@ -7,6 +7,7 @@
// test of the JSON error format.
#![feature(custom_inner_attributes)]
+#![feature(closure_lifetime_binder)]
#![rustfmt::skip]
#![deny(clippy::unused_unit)]
@@ -87,3 +88,9 @@ fn macro_expr() {
}
e!()
}
+
+mod issue9748 {
+ fn main() {
+ let _ = for<'a> |_: &'a u32| -> () {};
+ }
+}
diff --git a/src/tools/clippy/tests/ui/unused_unit.stderr b/src/tools/clippy/tests/ui/unused_unit.stderr
index 0d2cb7785..ce06738cf 100644
--- a/src/tools/clippy/tests/ui/unused_unit.stderr
+++ b/src/tools/clippy/tests/ui/unused_unit.stderr
@@ -1,119 +1,119 @@
error: unneeded unit return type
- --> $DIR/unused_unit.rs:19:58
+ --> $DIR/unused_unit.rs:20:58
|
LL | pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) -> ()
| ^^^^^^ help: remove the `-> ()`
|
note: the lint level is defined here
- --> $DIR/unused_unit.rs:12:9
+ --> $DIR/unused_unit.rs:13:9
|
LL | #![deny(clippy::unused_unit)]
| ^^^^^^^^^^^^^^^^^^^
error: unneeded unit return type
- --> $DIR/unused_unit.rs:19:28
+ --> $DIR/unused_unit.rs:20:28
|
LL | pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) -> ()
| ^^^^^^ help: remove the `-> ()`
error: unneeded unit return type
- --> $DIR/unused_unit.rs:20:18
+ --> $DIR/unused_unit.rs:21:18
|
LL | where G: Fn() -> () {
| ^^^^^^ help: remove the `-> ()`
error: unneeded unit return type
- --> $DIR/unused_unit.rs:21:26
+ --> $DIR/unused_unit.rs:22:26
|
LL | let _y: &dyn Fn() -> () = &f;
| ^^^^^^ help: remove the `-> ()`
error: unneeded unit return type
- --> $DIR/unused_unit.rs:28:18
+ --> $DIR/unused_unit.rs:29:18
|
LL | fn into(self) -> () {
| ^^^^^^ help: remove the `-> ()`
error: unneeded unit expression
- --> $DIR/unused_unit.rs:29:9
+ --> $DIR/unused_unit.rs:30:9
|
LL | ()
| ^^ help: remove the final `()`
error: unneeded unit return type
- --> $DIR/unused_unit.rs:34:29
+ --> $DIR/unused_unit.rs:35:29
|
LL | fn redundant<F: FnOnce() -> (), G, H>(&self, _f: F, _g: G, _h: H)
| ^^^^^^ help: remove the `-> ()`
error: unneeded unit return type
- --> $DIR/unused_unit.rs:36:19
+ --> $DIR/unused_unit.rs:37:19
|
LL | G: FnMut() -> (),
| ^^^^^^ help: remove the `-> ()`
error: unneeded unit return type
- --> $DIR/unused_unit.rs:37:16
+ --> $DIR/unused_unit.rs:38:16
|
LL | H: Fn() -> ();
| ^^^^^^ help: remove the `-> ()`
error: unneeded unit return type
- --> $DIR/unused_unit.rs:41:29
+ --> $DIR/unused_unit.rs:42:29
|
LL | fn redundant<F: FnOnce() -> (), G, H>(&self, _f: F, _g: G, _h: H)
| ^^^^^^ help: remove the `-> ()`
error: unneeded unit return type
- --> $DIR/unused_unit.rs:43:19
+ --> $DIR/unused_unit.rs:44:19
|
LL | G: FnMut() -> (),
| ^^^^^^ help: remove the `-> ()`
error: unneeded unit return type
- --> $DIR/unused_unit.rs:44:16
+ --> $DIR/unused_unit.rs:45:16
|
LL | H: Fn() -> () {}
| ^^^^^^ help: remove the `-> ()`
error: unneeded unit return type
- --> $DIR/unused_unit.rs:47:17
+ --> $DIR/unused_unit.rs:48:17
|
LL | fn return_unit() -> () { () }
| ^^^^^^ help: remove the `-> ()`
error: unneeded unit expression
- --> $DIR/unused_unit.rs:47:26
+ --> $DIR/unused_unit.rs:48:26
|
LL | fn return_unit() -> () { () }
| ^^ help: remove the final `()`
error: unneeded `()`
- --> $DIR/unused_unit.rs:57:14
+ --> $DIR/unused_unit.rs:58:14
|
LL | break();
| ^^ help: remove the `()`
error: unneeded `()`
- --> $DIR/unused_unit.rs:59:11
+ --> $DIR/unused_unit.rs:60:11
|
LL | return();
| ^^ help: remove the `()`
error: unneeded unit return type
- --> $DIR/unused_unit.rs:76:10
+ --> $DIR/unused_unit.rs:77:10
|
LL | fn test()->(){}
| ^^^^ help: remove the `-> ()`
error: unneeded unit return type
- --> $DIR/unused_unit.rs:79:11
+ --> $DIR/unused_unit.rs:80:11
|
LL | fn test2() ->(){}
| ^^^^^ help: remove the `-> ()`
error: unneeded unit return type
- --> $DIR/unused_unit.rs:82:11
+ --> $DIR/unused_unit.rs:83:11
|
LL | fn test3()-> (){}
| ^^^^^ help: remove the `-> ()`
diff --git a/src/tools/clippy/tests/ui/unwrap.stderr b/src/tools/clippy/tests/ui/unwrap.stderr
index e88d580f7..d49bf2b32 100644
--- a/src/tools/clippy/tests/ui/unwrap.stderr
+++ b/src/tools/clippy/tests/ui/unwrap.stderr
@@ -1,4 +1,4 @@
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap.rs:5:13
|
LL | let _ = opt.unwrap();
@@ -7,7 +7,7 @@ LL | let _ = opt.unwrap();
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
= note: `-D clippy::unwrap-used` implied by `-D warnings`
-error: used `unwrap()` on `a Result` value
+error: used `unwrap()` on a `Result` value
--> $DIR/unwrap.rs:10:13
|
LL | let _ = res.unwrap();
@@ -15,7 +15,7 @@ LL | let _ = res.unwrap();
|
= help: if you don't want to handle the `Err` case gracefully, consider using `expect()` to provide a better panic message
-error: used `unwrap_err()` on `a Result` value
+error: used `unwrap_err()` on a `Result` value
--> $DIR/unwrap.rs:11:13
|
LL | let _ = res.unwrap_err();
diff --git a/src/tools/clippy/tests/ui/unwrap_expect_used.stderr b/src/tools/clippy/tests/ui/unwrap_expect_used.stderr
index 211d2be18..fe4ecef11 100644
--- a/src/tools/clippy/tests/ui/unwrap_expect_used.stderr
+++ b/src/tools/clippy/tests/ui/unwrap_expect_used.stderr
@@ -1,4 +1,4 @@
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_expect_used.rs:23:5
|
LL | Some(3).unwrap();
@@ -7,7 +7,7 @@ LL | Some(3).unwrap();
= help: if this value is `None`, it will panic
= note: `-D clippy::unwrap-used` implied by `-D warnings`
-error: used `expect()` on `an Option` value
+error: used `expect()` on an `Option` value
--> $DIR/unwrap_expect_used.rs:24:5
|
LL | Some(3).expect("Hello world!");
@@ -16,7 +16,7 @@ LL | Some(3).expect("Hello world!");
= help: if this value is `None`, it will panic
= note: `-D clippy::expect-used` implied by `-D warnings`
-error: used `unwrap()` on `a Result` value
+error: used `unwrap()` on a `Result` value
--> $DIR/unwrap_expect_used.rs:31:5
|
LL | a.unwrap();
@@ -24,7 +24,7 @@ LL | a.unwrap();
|
= help: if this value is an `Err`, it will panic
-error: used `expect()` on `a Result` value
+error: used `expect()` on a `Result` value
--> $DIR/unwrap_expect_used.rs:32:5
|
LL | a.expect("Hello world!");
@@ -32,7 +32,7 @@ LL | a.expect("Hello world!");
|
= help: if this value is an `Err`, it will panic
-error: used `unwrap_err()` on `a Result` value
+error: used `unwrap_err()` on a `Result` value
--> $DIR/unwrap_expect_used.rs:33:5
|
LL | a.unwrap_err();
@@ -40,7 +40,7 @@ LL | a.unwrap_err();
|
= help: if this value is an `Ok`, it will panic
-error: used `expect_err()` on `a Result` value
+error: used `expect_err()` on a `Result` value
--> $DIR/unwrap_expect_used.rs:34:5
|
LL | a.expect_err("Hello error!");
diff --git a/src/tools/clippy/tests/ui/unwrap_or.rs b/src/tools/clippy/tests/ui/unwrap_or.rs
index bfb41e439..a0c003f5b 100644
--- a/src/tools/clippy/tests/ui/unwrap_or.rs
+++ b/src/tools/clippy/tests/ui/unwrap_or.rs
@@ -1,4 +1,4 @@
-#![warn(clippy::all)]
+#![warn(clippy::all, clippy::or_fun_call)]
fn main() {
let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len();
diff --git a/src/tools/clippy/tests/ui/use_self.fixed b/src/tools/clippy/tests/ui/use_self.fixed
index 3b54fe9d5..0a6166571 100644
--- a/src/tools/clippy/tests/ui/use_self.fixed
+++ b/src/tools/clippy/tests/ui/use_self.fixed
@@ -1,7 +1,6 @@
// run-rustfix
// aux-build:proc_macro_derive.rs
-#![feature(custom_inner_attributes)]
#![warn(clippy::use_self)]
#![allow(dead_code, unreachable_code)]
#![allow(
@@ -619,9 +618,8 @@ mod issue6902 {
}
}
+#[clippy::msrv = "1.36"]
fn msrv_1_36() {
- #![clippy::msrv = "1.36"]
-
enum E {
A,
}
@@ -635,9 +633,8 @@ fn msrv_1_36() {
}
}
+#[clippy::msrv = "1.37"]
fn msrv_1_37() {
- #![clippy::msrv = "1.37"]
-
enum E {
A,
}
diff --git a/src/tools/clippy/tests/ui/use_self.rs b/src/tools/clippy/tests/ui/use_self.rs
index bf87633cd..39c2b431f 100644
--- a/src/tools/clippy/tests/ui/use_self.rs
+++ b/src/tools/clippy/tests/ui/use_self.rs
@@ -1,7 +1,6 @@
// run-rustfix
// aux-build:proc_macro_derive.rs
-#![feature(custom_inner_attributes)]
#![warn(clippy::use_self)]
#![allow(dead_code, unreachable_code)]
#![allow(
@@ -619,9 +618,8 @@ mod issue6902 {
}
}
+#[clippy::msrv = "1.36"]
fn msrv_1_36() {
- #![clippy::msrv = "1.36"]
-
enum E {
A,
}
@@ -635,9 +633,8 @@ fn msrv_1_36() {
}
}
+#[clippy::msrv = "1.37"]
fn msrv_1_37() {
- #![clippy::msrv = "1.37"]
-
enum E {
A,
}
diff --git a/src/tools/clippy/tests/ui/use_self.stderr b/src/tools/clippy/tests/ui/use_self.stderr
index 16fb06092..48364c40c 100644
--- a/src/tools/clippy/tests/ui/use_self.stderr
+++ b/src/tools/clippy/tests/ui/use_self.stderr
@@ -1,5 +1,5 @@
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:23:21
+ --> $DIR/use_self.rs:22:21
|
LL | fn new() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
@@ -7,247 +7,247 @@ LL | fn new() -> Foo {
= note: `-D clippy::use-self` implied by `-D warnings`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:24:13
+ --> $DIR/use_self.rs:23:13
|
LL | Foo {}
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:26:22
+ --> $DIR/use_self.rs:25:22
|
LL | fn test() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:27:13
+ --> $DIR/use_self.rs:26:13
|
LL | Foo::new()
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:32:25
+ --> $DIR/use_self.rs:31:25
|
LL | fn default() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:33:13
+ --> $DIR/use_self.rs:32:13
|
LL | Foo::new()
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:98:24
+ --> $DIR/use_self.rs:97:24
|
LL | fn bad(foos: &[Foo]) -> impl Iterator<Item = &Foo> {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:98:55
+ --> $DIR/use_self.rs:97:55
|
LL | fn bad(foos: &[Foo]) -> impl Iterator<Item = &Foo> {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:113:13
+ --> $DIR/use_self.rs:112:13
|
LL | TS(0)
| ^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:148:29
+ --> $DIR/use_self.rs:147:29
|
LL | fn bar() -> Bar {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:149:21
+ --> $DIR/use_self.rs:148:21
|
LL | Bar { foo: Foo {} }
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:160:21
+ --> $DIR/use_self.rs:159:21
|
LL | fn baz() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:161:13
+ --> $DIR/use_self.rs:160:13
|
LL | Foo {}
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:178:21
+ --> $DIR/use_self.rs:177:21
|
LL | let _ = Enum::B(42);
| ^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:179:21
+ --> $DIR/use_self.rs:178:21
|
LL | let _ = Enum::C { field: true };
| ^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:180:21
+ --> $DIR/use_self.rs:179:21
|
LL | let _ = Enum::A;
| ^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:222:13
+ --> $DIR/use_self.rs:221:13
|
LL | nested::A::fun_1();
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:223:13
+ --> $DIR/use_self.rs:222:13
|
LL | nested::A::A;
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:225:13
+ --> $DIR/use_self.rs:224:13
|
LL | nested::A {};
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:244:13
+ --> $DIR/use_self.rs:243:13
|
LL | TestStruct::from_something()
| ^^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:258:25
+ --> $DIR/use_self.rs:257:25
|
LL | async fn g() -> S {
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:259:13
+ --> $DIR/use_self.rs:258:13
|
LL | S {}
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:263:16
+ --> $DIR/use_self.rs:262:16
|
LL | &p[S::A..S::B]
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:263:22
+ --> $DIR/use_self.rs:262:22
|
LL | &p[S::A..S::B]
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:286:29
+ --> $DIR/use_self.rs:285:29
|
LL | fn foo(value: T) -> Foo<T> {
| ^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:287:13
+ --> $DIR/use_self.rs:286:13
|
LL | Foo::<T> { value }
| ^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:459:13
+ --> $DIR/use_self.rs:458:13
|
LL | A::new::<submod::B>(submod::B {})
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:496:13
+ --> $DIR/use_self.rs:495:13
|
LL | S2::new()
| ^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:533:17
+ --> $DIR/use_self.rs:532:17
|
LL | Foo::Bar => unimplemented!(),
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:534:17
+ --> $DIR/use_self.rs:533:17
|
LL | Foo::Baz => unimplemented!(),
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:540:20
+ --> $DIR/use_self.rs:539:20
|
LL | if let Foo::Bar = self {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:564:17
+ --> $DIR/use_self.rs:563:17
|
LL | Something::Num(n) => *n,
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:565:17
+ --> $DIR/use_self.rs:564:17
|
LL | Something::TupleNums(n, _m) => *n,
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:566:17
+ --> $DIR/use_self.rs:565:17
|
LL | Something::StructNums { one, two: _ } => *one,
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:572:17
+ --> $DIR/use_self.rs:571:17
|
LL | crate::issue8845::Something::Num(n) => *n,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:573:17
+ --> $DIR/use_self.rs:572:17
|
LL | crate::issue8845::Something::TupleNums(n, _m) => *n,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:574:17
+ --> $DIR/use_self.rs:573:17
|
LL | crate::issue8845::Something::StructNums { one, two: _ } => *one,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:590:17
+ --> $DIR/use_self.rs:589:17
|
LL | let Foo(x) = self;
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:595:17
+ --> $DIR/use_self.rs:594:17
|
LL | let crate::issue8845::Foo(x) = self;
| ^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:602:17
+ --> $DIR/use_self.rs:601:17
|
LL | let Bar { x, .. } = self;
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:607:17
+ --> $DIR/use_self.rs:606:17
|
LL | let crate::issue8845::Bar { x, .. } = self;
| ^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:648:17
+ --> $DIR/use_self.rs:645:17
|
LL | E::A => {},
| ^ help: use the applicable keyword: `Self`
diff --git a/src/tools/clippy/tests/ui/use_self_trait.fixed b/src/tools/clippy/tests/ui/use_self_trait.fixed
index 9bcd692fb..4e779308d 100644
--- a/src/tools/clippy/tests/ui/use_self_trait.fixed
+++ b/src/tools/clippy/tests/ui/use_self_trait.fixed
@@ -47,8 +47,7 @@ impl Mul for Bad {
impl Clone for Bad {
fn clone(&self) -> Self {
- // FIXME: applicable here
- Bad
+ Self
}
}
@@ -112,4 +111,42 @@ impl NameTrait for u8 {
}
}
+mod impl_in_macro {
+ macro_rules! parse_ip_impl {
+ // minimized from serde=1.0.118
+ ($ty:ty) => {
+ impl FooTrait for $ty {
+ fn new() -> Self {
+ <$ty>::bar()
+ }
+ }
+ };
+ }
+
+ struct Foo;
+
+ trait FooTrait {
+ fn new() -> Self;
+ }
+
+ impl Foo {
+ fn bar() -> Self {
+ Self
+ }
+ }
+ parse_ip_impl!(Foo); // Should not lint
+}
+
+mod full_path_replacement {
+ trait Error {
+ fn custom<T: std::fmt::Display>(_msg: T) -> Self;
+ }
+
+ impl Error for std::fmt::Error {
+ fn custom<T: std::fmt::Display>(_msg: T) -> Self {
+ Self // Should lint
+ }
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/use_self_trait.rs b/src/tools/clippy/tests/ui/use_self_trait.rs
index de305d40f..325dc73b2 100644
--- a/src/tools/clippy/tests/ui/use_self_trait.rs
+++ b/src/tools/clippy/tests/ui/use_self_trait.rs
@@ -47,7 +47,6 @@ impl Mul for Bad {
impl Clone for Bad {
fn clone(&self) -> Self {
- // FIXME: applicable here
Bad
}
}
@@ -112,4 +111,42 @@ impl NameTrait for u8 {
}
}
+mod impl_in_macro {
+ macro_rules! parse_ip_impl {
+ // minimized from serde=1.0.118
+ ($ty:ty) => {
+ impl FooTrait for $ty {
+ fn new() -> Self {
+ <$ty>::bar()
+ }
+ }
+ };
+ }
+
+ struct Foo;
+
+ trait FooTrait {
+ fn new() -> Self;
+ }
+
+ impl Foo {
+ fn bar() -> Self {
+ Self
+ }
+ }
+ parse_ip_impl!(Foo); // Should not lint
+}
+
+mod full_path_replacement {
+ trait Error {
+ fn custom<T: std::fmt::Display>(_msg: T) -> Self;
+ }
+
+ impl Error for std::fmt::Error {
+ fn custom<T: std::fmt::Display>(_msg: T) -> Self {
+ std::fmt::Error // Should lint
+ }
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/use_self_trait.stderr b/src/tools/clippy/tests/ui/use_self_trait.stderr
index 55af3ff2a..090729b9c 100644
--- a/src/tools/clippy/tests/ui/use_self_trait.stderr
+++ b/src/tools/clippy/tests/ui/use_self_trait.stderr
@@ -84,5 +84,17 @@ error: unnecessary structure name repetition
LL | fn mul(self, rhs: Bad) -> Bad {
| ^^^ help: use the applicable keyword: `Self`
-error: aborting due to 14 previous errors
+error: unnecessary structure name repetition
+ --> $DIR/use_self_trait.rs:50:9
+ |
+LL | Bad
+ | ^^^ help: use the applicable keyword: `Self`
+
+error: unnecessary structure name repetition
+ --> $DIR/use_self_trait.rs:147:13
+ |
+LL | std::fmt::Error // Should lint
+ | ^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
+
+error: aborting due to 16 previous errors
diff --git a/src/tools/clippy/tests/ui/useless_attribute.fixed b/src/tools/clippy/tests/ui/useless_attribute.fixed
index c23231a99..871e4fb5c 100644
--- a/src/tools/clippy/tests/ui/useless_attribute.fixed
+++ b/src/tools/clippy/tests/ui/useless_attribute.fixed
@@ -1,6 +1,7 @@
// run-rustfix
// aux-build:proc_macro_derive.rs
+#![allow(unused)]
#![warn(clippy::useless_attribute)]
#![warn(unreachable_pub)]
#![feature(rustc_private)]
@@ -16,6 +17,13 @@ extern crate rustc_middle;
#[macro_use]
extern crate proc_macro_derive;
+fn test_indented_attr() {
+ #![allow(clippy::almost_swapped)]
+ use std::collections::HashSet;
+
+ let _ = HashSet::<u32>::default();
+}
+
// don't lint on unused_import for `use` items
#[allow(unused_imports)]
use std::collections;
@@ -63,13 +71,16 @@ mod c {
pub(crate) struct S;
}
-fn test_indented_attr() {
- #![allow(clippy::almost_swapped)]
- use std::collections::HashSet;
-
- let _ = HashSet::<u32>::default();
+// https://github.com/rust-lang/rust-clippy/issues/7511
+pub mod split {
+ #[allow(clippy::module_name_repetitions)]
+ pub use regex::SplitN;
}
+// https://github.com/rust-lang/rust-clippy/issues/8768
+#[allow(clippy::single_component_path_imports)]
+use regex;
+
fn main() {
test_indented_attr();
}
diff --git a/src/tools/clippy/tests/ui/useless_attribute.rs b/src/tools/clippy/tests/ui/useless_attribute.rs
index 7a7b198ea..cb50736ba 100644
--- a/src/tools/clippy/tests/ui/useless_attribute.rs
+++ b/src/tools/clippy/tests/ui/useless_attribute.rs
@@ -1,6 +1,7 @@
// run-rustfix
// aux-build:proc_macro_derive.rs
+#![allow(unused)]
#![warn(clippy::useless_attribute)]
#![warn(unreachable_pub)]
#![feature(rustc_private)]
@@ -16,6 +17,13 @@ extern crate rustc_middle;
#[macro_use]
extern crate proc_macro_derive;
+fn test_indented_attr() {
+ #[allow(clippy::almost_swapped)]
+ use std::collections::HashSet;
+
+ let _ = HashSet::<u32>::default();
+}
+
// don't lint on unused_import for `use` items
#[allow(unused_imports)]
use std::collections;
@@ -63,13 +71,16 @@ mod c {
pub(crate) struct S;
}
-fn test_indented_attr() {
- #[allow(clippy::almost_swapped)]
- use std::collections::HashSet;
-
- let _ = HashSet::<u32>::default();
+// https://github.com/rust-lang/rust-clippy/issues/7511
+pub mod split {
+ #[allow(clippy::module_name_repetitions)]
+ pub use regex::SplitN;
}
+// https://github.com/rust-lang/rust-clippy/issues/8768
+#[allow(clippy::single_component_path_imports)]
+use regex;
+
fn main() {
test_indented_attr();
}
diff --git a/src/tools/clippy/tests/ui/useless_attribute.stderr b/src/tools/clippy/tests/ui/useless_attribute.stderr
index 255d28763..a7ea0df22 100644
--- a/src/tools/clippy/tests/ui/useless_attribute.stderr
+++ b/src/tools/clippy/tests/ui/useless_attribute.stderr
@@ -1,5 +1,5 @@
error: useless lint attribute
- --> $DIR/useless_attribute.rs:8:1
+ --> $DIR/useless_attribute.rs:9:1
|
LL | #[allow(dead_code)]
| ^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(dead_code)]`
@@ -7,13 +7,13 @@ LL | #[allow(dead_code)]
= note: `-D clippy::useless-attribute` implied by `-D warnings`
error: useless lint attribute
- --> $DIR/useless_attribute.rs:9:1
+ --> $DIR/useless_attribute.rs:10:1
|
LL | #[cfg_attr(feature = "cargo-clippy", allow(dead_code))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![cfg_attr(feature = "cargo-clippy", allow(dead_code)`
error: useless lint attribute
- --> $DIR/useless_attribute.rs:67:5
+ --> $DIR/useless_attribute.rs:21:5
|
LL | #[allow(clippy::almost_swapped)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(clippy::almost_swapped)]`