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:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
commita4b7ed7a42c716ab9f05e351f003d589124fd55d (patch)
treeb620cd3f223850b28716e474e80c58059dca5dd4 /src/tools/clippy/tests/ui
parentAdding upstream version 1.67.1+dfsg1. (diff)
downloadrustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz
rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+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.stderr113
-rw-r--r--src/tools/clippy/tests/ui/almost_complete_range.fixed (renamed from src/tools/clippy/tests/ui/almost_complete_letter_range.fixed)49
-rw-r--r--src/tools/clippy/tests/ui/almost_complete_range.rs (renamed from src/tools/clippy/tests/ui/almost_complete_letter_range.rs)49
-rw-r--r--src/tools/clippy/tests/ui/almost_complete_range.stderr235
-rw-r--r--src/tools/clippy/tests/ui/arithmetic_side_effects.rs225
-rw-r--r--src/tools/clippy/tests/ui/arithmetic_side_effects.stderr502
-rw-r--r--src/tools/clippy/tests/ui/async_yields_async.stderr6
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/macro_rules.rs4
-rw-r--r--src/tools/clippy/tests/ui/box_default.fixed18
-rw-r--r--src/tools/clippy/tests/ui/box_default.rs10
-rw-r--r--src/tools/clippy/tests/ui/box_default.stderr16
-rw-r--r--src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed67
-rw-r--r--src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs13
-rw-r--r--src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.stderr66
-rw-r--r--src/tools/clippy/tests/ui/cast_lossless_integer.fixed6
-rw-r--r--src/tools/clippy/tests/ui/cast_lossless_integer.rs6
-rw-r--r--src/tools/clippy/tests/ui/clone_on_copy.stderr2
-rw-r--r--src/tools/clippy/tests/ui/collapsible_str_replace.fixed11
-rw-r--r--src/tools/clippy/tests/ui/collapsible_str_replace.rs11
-rw-r--r--src/tools/clippy/tests/ui/collapsible_str_replace.stderr34
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-6252.stderr9
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-6254.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-6255.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-6256.rs2
-rw-r--r--src/tools/clippy/tests/ui/dbg_macro.stderr52
-rw-r--r--src/tools/clippy/tests/ui/def_id_nocore.rs2
-rw-r--r--src/tools/clippy/tests/ui/default_trait_access.fixed8
-rw-r--r--src/tools/clippy/tests/ui/default_trait_access.stderr16
-rw-r--r--src/tools/clippy/tests/ui/derivable_impls.fixed21
-rw-r--r--src/tools/clippy/tests/ui/derivable_impls.rs23
-rw-r--r--src/tools/clippy/tests/ui/derivable_impls.stderr23
-rw-r--r--src/tools/clippy/tests/ui/derive.rs11
-rw-r--r--src/tools/clippy/tests/ui/derive_hash_xor_eq.stderr59
-rw-r--r--src/tools/clippy/tests/ui/derived_hash_with_manual_eq.rs (renamed from src/tools/clippy/tests/ui/derive_hash_xor_eq.rs)21
-rw-r--r--src/tools/clippy/tests/ui/derived_hash_with_manual_eq.stderr29
-rw-r--r--src/tools/clippy/tests/ui/drop_ref.rs23
-rw-r--r--src/tools/clippy/tests/ui/drop_ref.stderr38
-rw-r--r--src/tools/clippy/tests/ui/explicit_counter_loop.rs30
-rw-r--r--src/tools/clippy/tests/ui/field_reassign_with_default.rs21
-rw-r--r--src/tools/clippy/tests/ui/floating_point_powi.fixed9
-rw-r--r--src/tools/clippy/tests/ui/floating_point_powi.rs9
-rw-r--r--src/tools/clippy/tests/ui/floating_point_powi.stderr44
-rw-r--r--src/tools/clippy/tests/ui/fn_null_check.rs21
-rw-r--r--src/tools/clippy/tests/ui/fn_null_check.stderr43
-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/identity_op.fixed6
-rw-r--r--src/tools/clippy/tests/ui/identity_op.rs4
-rw-r--r--src/tools/clippy/tests/ui/identity_op.stderr12
-rw-r--r--src/tools/clippy/tests/ui/implicit_clone.fixed10
-rw-r--r--src/tools/clippy/tests/ui/implicit_clone.rs10
-rw-r--r--src/tools/clippy/tests/ui/indexing_slicing_index.rs6
-rw-r--r--src/tools/clippy/tests/ui/indexing_slicing_index.stderr44
-rw-r--r--src/tools/clippy/tests/ui/iter_kv_map.fixed35
-rw-r--r--src/tools/clippy/tests/ui/iter_kv_map.rs39
-rw-r--r--src/tools/clippy/tests/ui/iter_kv_map.stderr114
-rw-r--r--src/tools/clippy/tests/ui/large_stack_arrays.rs1
-rw-r--r--src/tools/clippy/tests/ui/large_stack_arrays.stderr10
-rw-r--r--src/tools/clippy/tests/ui/len_zero.fixed40
-rw-r--r--src/tools/clippy/tests/ui/len_zero.rs40
-rw-r--r--src/tools/clippy/tests/ui/len_zero.stderr74
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.edition2018.fixed5
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.edition2021.fixed5
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.edition2021.stderr2
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.rs5
-rw-r--r--src/tools/clippy/tests/ui/manual_filter.fixed41
-rw-r--r--src/tools/clippy/tests/ui/manual_filter.rs41
-rw-r--r--src/tools/clippy/tests/ui/manual_is_ascii_check.fixed13
-rw-r--r--src/tools/clippy/tests/ui/manual_is_ascii_check.rs13
-rw-r--r--src/tools/clippy/tests/ui/manual_is_ascii_check.stderr64
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else_match.rs7
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else_match.stderr15
-rw-r--r--src/tools/clippy/tests/ui/manual_retain.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_retain.rs2
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding.fixed13
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding.rs14
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding.stderr27
-rw-r--r--src/tools/clippy/tests/ui/match_wildcard_for_single_variants.fixed22
-rw-r--r--src/tools/clippy/tests/ui/match_wildcard_for_single_variants.rs22
-rw-r--r--src/tools/clippy/tests/ui/match_wildcard_for_single_variants.stderr8
-rw-r--r--src/tools/clippy/tests/ui/needless_parens_on_range_literals.fixed2
-rw-r--r--src/tools/clippy/tests/ui/needless_parens_on_range_literals.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_return.fixed15
-rw-r--r--src/tools/clippy/tests/ui/needless_return.rs15
-rw-r--r--src/tools/clippy/tests/ui/needless_return.stderr110
-rw-r--r--src/tools/clippy/tests/ui/permissions_set_readonly_false.rs29
-rw-r--r--src/tools/clippy/tests/ui/permissions_set_readonly_false.stderr13
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed6
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes.rs6
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr10
-rw-r--r--src/tools/clippy/tests/ui/rename.fixed4
-rw-r--r--src/tools/clippy/tests/ui/rename.rs4
-rw-r--r--src/tools/clippy/tests/ui/rename.stderr98
-rw-r--r--src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr5
-rw-r--r--src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed6
-rw-r--r--src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs6
-rw-r--r--src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.stderr2
-rw-r--r--src/tools/clippy/tests/ui/semicolon_inside_block.fixed85
-rw-r--r--src/tools/clippy/tests/ui/semicolon_inside_block.rs85
-rw-r--r--src/tools/clippy/tests/ui/semicolon_inside_block.stderr54
-rw-r--r--src/tools/clippy/tests/ui/semicolon_outside_block.fixed85
-rw-r--r--src/tools/clippy/tests/ui/semicolon_outside_block.rs85
-rw-r--r--src/tools/clippy/tests/ui/semicolon_outside_block.stderr54
-rw-r--r--src/tools/clippy/tests/ui/single_element_loop.fixed27
-rw-r--r--src/tools/clippy/tests/ui/single_element_loop.rs26
-rw-r--r--src/tools/clippy/tests/ui/single_element_loop.stderr29
-rw-r--r--src/tools/clippy/tests/ui/size_of_ref.rs27
-rw-r--r--src/tools/clippy/tests/ui/size_of_ref.stderr27
-rw-r--r--src/tools/clippy/tests/ui/string_lit_as_bytes.fixed6
-rw-r--r--src/tools/clippy/tests/ui/string_lit_as_bytes.rs6
-rw-r--r--src/tools/clippy/tests/ui/suspicious_to_owned.stderr8
-rw-r--r--src/tools/clippy/tests/ui/transmute_null_to_fn.rs28
-rw-r--r--src/tools/clippy/tests/ui/transmute_null_to_fn.stderr27
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed3
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed3
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.stderr26
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args_panic.rs3
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_clone.stderr10
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.fixed20
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.rs20
-rw-r--r--src/tools/clippy/tests/ui/unused_self.rs10
-rw-r--r--src/tools/clippy/tests/ui/unused_self.stderr18
-rw-r--r--src/tools/clippy/tests/ui/useless_conversion.fixed73
-rw-r--r--src/tools/clippy/tests/ui/useless_conversion.rs73
-rw-r--r--src/tools/clippy/tests/ui/useless_conversion.stderr54
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports.fixed1
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports.rs1
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports.stderr42
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed240
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.stderr132
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed240
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.stderr132
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.rs241
-rw-r--r--src/tools/clippy/tests/ui/wildcard_imports_2021.stderr132
-rw-r--r--src/tools/clippy/tests/ui/zero_ptr_no_std.fixed21
-rw-r--r--src/tools/clippy/tests/ui/zero_ptr_no_std.rs21
-rw-r--r--src/tools/clippy/tests/ui/zero_ptr_no_std.stderr26
138 files changed, 4583 insertions, 702 deletions
diff --git a/src/tools/clippy/tests/ui/almost_complete_letter_range.stderr b/src/tools/clippy/tests/ui/almost_complete_letter_range.stderr
deleted file mode 100644
index 9abf6d6c5..000000000
--- a/src/tools/clippy/tests/ui/almost_complete_letter_range.stderr
+++ /dev/null
@@ -1,113 +0,0 @@
-error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:29:17
- |
-LL | let _ = ('a') ..'z';
- | ^^^^^^--^^^
- | |
- | help: use an inclusive range: `..=`
- |
- = note: `-D clippy::almost-complete-letter-range` implied by `-D warnings`
-
-error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:30:17
- |
-LL | let _ = 'A' .. ('Z');
- | ^^^^--^^^^^^
- | |
- | help: use an inclusive range: `..=`
-
-error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:36:13
- |
-LL | let _ = (b'a')..(b'z');
- | ^^^^^^--^^^^^^
- | |
- | help: use an inclusive range: `..=`
-
-error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:37:13
- |
-LL | let _ = b'A'..b'Z';
- | ^^^^--^^^^
- | |
- | help: use an inclusive range: `..=`
-
-error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:42:13
- |
-LL | let _ = a!()..'z';
- | ^^^^--^^^
- | |
- | help: use an inclusive range: `..=`
-
-error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:45:9
- |
-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:46:9
- |
-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:53:9
- |
-LL | 'a'..'z' if true => 1,
- | ^^^--^^^
- | |
- | help: use an inclusive range: `..=`
-
-error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:54:9
- |
-LL | 'A'..'Z' if true => 2,
- | ^^^--^^^
- | |
- | help: use an inclusive range: `..=`
-
-error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:22:17
- |
-LL | let _ = 'a'..'z';
- | ^^^--^^^
- | |
- | help: use an inclusive range: `..=`
-...
-LL | b!();
- | ---- in this macro invocation
- |
- = 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:67:9
- |
-LL | 'a'..'z' => 1,
- | ^^^--^^^
- | |
- | help: use an inclusive range: `...`
-
-error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:74:13
- |
-LL | let _ = 'a'..'z';
- | ^^^--^^^
- | |
- | help: use an inclusive range: `..=`
-
-error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:76:9
- |
-LL | 'a'..'z' => 1,
- | ^^^--^^^
- | |
- | help: use an inclusive range: `..=`
-
-error: aborting due to 13 previous errors
-
diff --git a/src/tools/clippy/tests/ui/almost_complete_letter_range.fixed b/src/tools/clippy/tests/ui/almost_complete_range.fixed
index adcbd4d51..6046addf7 100644
--- a/src/tools/clippy/tests/ui/almost_complete_letter_range.fixed
+++ b/src/tools/clippy/tests/ui/almost_complete_range.fixed
@@ -4,9 +4,10 @@
#![feature(exclusive_range_pattern)]
#![feature(stmt_expr_attributes)]
-#![warn(clippy::almost_complete_letter_range)]
+#![warn(clippy::almost_complete_range)]
#![allow(ellipsis_inclusive_range_patterns)]
#![allow(clippy::needless_parens_on_range_literals)]
+#![allow(clippy::double_parens)]
#[macro_use]
extern crate macro_rules;
@@ -16,10 +17,22 @@ macro_rules! a {
'a'
};
}
+macro_rules! A {
+ () => {
+ 'A'
+ };
+}
+macro_rules! zero {
+ () => {
+ '0'
+ };
+}
macro_rules! b {
() => {
let _ = 'a'..='z';
+ let _ = 'A'..='Z';
+ let _ = '0'..='9';
};
}
@@ -28,36 +41,46 @@ fn main() {
{
let _ = ('a') ..='z';
let _ = 'A' ..= ('Z');
+ let _ = ((('0'))) ..= ('9');
}
let _ = 'b'..'z';
let _ = 'B'..'Z';
+ let _ = '1'..'9';
let _ = (b'a')..=(b'z');
let _ = b'A'..=b'Z';
+ let _ = b'0'..=b'9';
let _ = b'b'..b'z';
let _ = b'B'..b'Z';
+ let _ = b'1'..b'9';
let _ = a!()..='z';
+ let _ = A!()..='Z';
+ let _ = zero!()..='9';
let _ = match 0u8 {
b'a'..=b'z' if true => 1,
b'A'..=b'Z' if true => 2,
- b'b'..b'z' => 3,
- b'B'..b'Z' => 4,
- _ => 5,
+ b'0'..=b'9' if true => 3,
+ b'b'..b'z' => 4,
+ b'B'..b'Z' => 5,
+ b'1'..b'9' => 6,
+ _ => 7,
};
let _ = match 'x' {
'a'..='z' if true => 1,
'A'..='Z' if true => 2,
- 'b'..'z' => 3,
- 'B'..'Z' => 4,
- _ => 5,
+ '0'..='9' if true => 3,
+ 'b'..'z' => 4,
+ 'B'..'Z' => 5,
+ '1'..'9' => 6,
+ _ => 7,
};
- almost_complete_letter_range!();
+ almost_complete_range!();
b!();
}
@@ -65,15 +88,21 @@ fn main() {
fn _under_msrv() {
let _ = match 'a' {
'a'...'z' => 1,
- _ => 2,
+ 'A'...'Z' => 2,
+ '0'...'9' => 3,
+ _ => 4,
};
}
#[clippy::msrv = "1.26"]
fn _meets_msrv() {
let _ = 'a'..='z';
+ let _ = 'A'..='Z';
+ let _ = '0'..='9';
let _ = match 'a' {
'a'..='z' => 1,
- _ => 2,
+ 'A'..='Z' => 1,
+ '0'..='9' => 3,
+ _ => 4,
};
}
diff --git a/src/tools/clippy/tests/ui/almost_complete_letter_range.rs b/src/tools/clippy/tests/ui/almost_complete_range.rs
index 9979316ec..ae7e07ab8 100644
--- a/src/tools/clippy/tests/ui/almost_complete_letter_range.rs
+++ b/src/tools/clippy/tests/ui/almost_complete_range.rs
@@ -4,9 +4,10 @@
#![feature(exclusive_range_pattern)]
#![feature(stmt_expr_attributes)]
-#![warn(clippy::almost_complete_letter_range)]
+#![warn(clippy::almost_complete_range)]
#![allow(ellipsis_inclusive_range_patterns)]
#![allow(clippy::needless_parens_on_range_literals)]
+#![allow(clippy::double_parens)]
#[macro_use]
extern crate macro_rules;
@@ -16,10 +17,22 @@ macro_rules! a {
'a'
};
}
+macro_rules! A {
+ () => {
+ 'A'
+ };
+}
+macro_rules! zero {
+ () => {
+ '0'
+ };
+}
macro_rules! b {
() => {
let _ = 'a'..'z';
+ let _ = 'A'..'Z';
+ let _ = '0'..'9';
};
}
@@ -28,36 +41,46 @@ fn main() {
{
let _ = ('a') ..'z';
let _ = 'A' .. ('Z');
+ let _ = ((('0'))) .. ('9');
}
let _ = 'b'..'z';
let _ = 'B'..'Z';
+ let _ = '1'..'9';
let _ = (b'a')..(b'z');
let _ = b'A'..b'Z';
+ let _ = b'0'..b'9';
let _ = b'b'..b'z';
let _ = b'B'..b'Z';
+ let _ = b'1'..b'9';
let _ = a!()..'z';
+ let _ = A!()..'Z';
+ let _ = zero!()..'9';
let _ = match 0u8 {
b'a'..b'z' if true => 1,
b'A'..b'Z' if true => 2,
- b'b'..b'z' => 3,
- b'B'..b'Z' => 4,
- _ => 5,
+ b'0'..b'9' if true => 3,
+ b'b'..b'z' => 4,
+ b'B'..b'Z' => 5,
+ b'1'..b'9' => 6,
+ _ => 7,
};
let _ = match 'x' {
'a'..'z' if true => 1,
'A'..'Z' if true => 2,
- 'b'..'z' => 3,
- 'B'..'Z' => 4,
- _ => 5,
+ '0'..'9' if true => 3,
+ 'b'..'z' => 4,
+ 'B'..'Z' => 5,
+ '1'..'9' => 6,
+ _ => 7,
};
- almost_complete_letter_range!();
+ almost_complete_range!();
b!();
}
@@ -65,15 +88,21 @@ fn main() {
fn _under_msrv() {
let _ = match 'a' {
'a'..'z' => 1,
- _ => 2,
+ 'A'..'Z' => 2,
+ '0'..'9' => 3,
+ _ => 4,
};
}
#[clippy::msrv = "1.26"]
fn _meets_msrv() {
let _ = 'a'..'z';
+ let _ = 'A'..'Z';
+ let _ = '0'..'9';
let _ = match 'a' {
'a'..'z' => 1,
- _ => 2,
+ 'A'..'Z' => 1,
+ '0'..'9' => 3,
+ _ => 4,
};
}
diff --git a/src/tools/clippy/tests/ui/almost_complete_range.stderr b/src/tools/clippy/tests/ui/almost_complete_range.stderr
new file mode 100644
index 000000000..a7a532878
--- /dev/null
+++ b/src/tools/clippy/tests/ui/almost_complete_range.stderr
@@ -0,0 +1,235 @@
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:42:17
+ |
+LL | let _ = ('a') ..'z';
+ | ^^^^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+ |
+ = note: `-D clippy::almost-complete-range` implied by `-D warnings`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:43:17
+ |
+LL | let _ = 'A' .. ('Z');
+ | ^^^^--^^^^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:44:17
+ |
+LL | let _ = ((('0'))) .. ('9');
+ | ^^^^^^^^^^--^^^^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:51:13
+ |
+LL | let _ = (b'a')..(b'z');
+ | ^^^^^^--^^^^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:52:13
+ |
+LL | let _ = b'A'..b'Z';
+ | ^^^^--^^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:53:13
+ |
+LL | let _ = b'0'..b'9';
+ | ^^^^--^^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:59:13
+ |
+LL | let _ = a!()..'z';
+ | ^^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:60:13
+ |
+LL | let _ = A!()..'Z';
+ | ^^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:61:13
+ |
+LL | let _ = zero!()..'9';
+ | ^^^^^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:64:9
+ |
+LL | b'a'..b'z' if true => 1,
+ | ^^^^--^^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:65:9
+ |
+LL | b'A'..b'Z' if true => 2,
+ | ^^^^--^^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:66:9
+ |
+LL | b'0'..b'9' if true => 3,
+ | ^^^^--^^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:74:9
+ |
+LL | 'a'..'z' if true => 1,
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:75:9
+ |
+LL | 'A'..'Z' if true => 2,
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:76:9
+ |
+LL | '0'..'9' if true => 3,
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:33:17
+ |
+LL | let _ = 'a'..'z';
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+...
+LL | b!();
+ | ---- in this macro invocation
+ |
+ = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:34:17
+ |
+LL | let _ = 'A'..'Z';
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+...
+LL | b!();
+ | ---- in this macro invocation
+ |
+ = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:35:17
+ |
+LL | let _ = '0'..'9';
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+...
+LL | b!();
+ | ---- in this macro invocation
+ |
+ = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:90:9
+ |
+LL | 'a'..'z' => 1,
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `...`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:91:9
+ |
+LL | 'A'..'Z' => 2,
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `...`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:92:9
+ |
+LL | '0'..'9' => 3,
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `...`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:99:13
+ |
+LL | let _ = 'a'..'z';
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:100:13
+ |
+LL | let _ = 'A'..'Z';
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:101:13
+ |
+LL | let _ = '0'..'9';
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:103:9
+ |
+LL | 'a'..'z' => 1,
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:104:9
+ |
+LL | 'A'..'Z' => 1,
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: almost complete ascii range
+ --> $DIR/almost_complete_range.rs:105:9
+ |
+LL | '0'..'9' => 3,
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+
+error: aborting due to 27 previous errors
+
diff --git a/src/tools/clippy/tests/ui/arithmetic_side_effects.rs b/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
index b5ed8988a..918cf81c6 100644
--- a/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
+++ b/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
@@ -2,6 +2,7 @@
clippy::assign_op_pattern,
clippy::erasing_op,
clippy::identity_op,
+ clippy::no_effect,
clippy::op_ref,
clippy::unnecessary_owned_empty_strings,
arithmetic_overflow,
@@ -12,31 +13,95 @@
use core::num::{Saturating, Wrapping};
+#[derive(Clone, Copy)]
pub struct Custom;
macro_rules! impl_arith {
- ( $( $_trait:ident, $ty:ty, $method:ident; )* ) => {
+ ( $( $_trait:ident, $lhs:ty, $rhs:ty, $method:ident; )* ) => {
$(
- impl core::ops::$_trait<$ty> for Custom {
- type Output = Self;
- fn $method(self, _: $ty) -> Self::Output { Self }
+ impl core::ops::$_trait<$lhs> for $rhs {
+ type Output = Custom;
+ fn $method(self, _: $lhs) -> Self::Output { todo!() }
+ }
+ )*
+ }
+}
+
+macro_rules! impl_assign_arith {
+ ( $( $_trait:ident, $lhs:ty, $rhs:ty, $method:ident; )* ) => {
+ $(
+ impl core::ops::$_trait<$lhs> for $rhs {
+ fn $method(&mut self, _: $lhs) {}
}
)*
}
}
impl_arith!(
- Add, i32, add;
- Div, i32, div;
- Mul, i32, mul;
- Sub, i32, sub;
-
- Add, f64, add;
- Div, f64, div;
- Mul, f64, mul;
- Sub, f64, sub;
+ Add, Custom, Custom, add;
+ Div, Custom, Custom, div;
+ Mul, Custom, Custom, mul;
+ Rem, Custom, Custom, rem;
+ Sub, Custom, Custom, sub;
+
+ Add, Custom, &Custom, add;
+ Div, Custom, &Custom, div;
+ Mul, Custom, &Custom, mul;
+ Rem, Custom, &Custom, rem;
+ Sub, Custom, &Custom, sub;
+
+ Add, &Custom, Custom, add;
+ Div, &Custom, Custom, div;
+ Mul, &Custom, Custom, mul;
+ Rem, &Custom, Custom, rem;
+ Sub, &Custom, Custom, sub;
+
+ Add, &Custom, &Custom, add;
+ Div, &Custom, &Custom, div;
+ Mul, &Custom, &Custom, mul;
+ Rem, &Custom, &Custom, rem;
+ Sub, &Custom, &Custom, sub;
+);
+
+impl_assign_arith!(
+ AddAssign, Custom, Custom, add_assign;
+ DivAssign, Custom, Custom, div_assign;
+ MulAssign, Custom, Custom, mul_assign;
+ RemAssign, Custom, Custom, rem_assign;
+ SubAssign, Custom, Custom, sub_assign;
+
+ AddAssign, Custom, &Custom, add_assign;
+ DivAssign, Custom, &Custom, div_assign;
+ MulAssign, Custom, &Custom, mul_assign;
+ RemAssign, Custom, &Custom, rem_assign;
+ SubAssign, Custom, &Custom, sub_assign;
+
+ AddAssign, &Custom, Custom, add_assign;
+ DivAssign, &Custom, Custom, div_assign;
+ MulAssign, &Custom, Custom, mul_assign;
+ RemAssign, &Custom, Custom, rem_assign;
+ SubAssign, &Custom, Custom, sub_assign;
+
+ AddAssign, &Custom, &Custom, add_assign;
+ DivAssign, &Custom, &Custom, div_assign;
+ MulAssign, &Custom, &Custom, mul_assign;
+ RemAssign, &Custom, &Custom, rem_assign;
+ SubAssign, &Custom, &Custom, sub_assign;
);
+impl core::ops::Neg for Custom {
+ type Output = Custom;
+ fn neg(self) -> Self::Output {
+ todo!()
+ }
+}
+impl core::ops::Neg for &Custom {
+ type Output = Custom;
+ fn neg(self) -> Self::Output {
+ todo!()
+ }
+}
+
pub fn association_with_structures_should_not_trigger_the_lint() {
enum Foo {
Bar = -2,
@@ -125,6 +190,18 @@ pub fn non_overflowing_ops_or_ops_already_handled_by_the_compiler_should_not_tri
_n *= &0;
_n *= 1;
_n *= &1;
+ _n += -0;
+ _n += &-0;
+ _n -= -0;
+ _n -= &-0;
+ _n /= -99;
+ _n /= &-99;
+ _n %= -99;
+ _n %= &-99;
+ _n *= -0;
+ _n *= &-0;
+ _n *= -1;
+ _n *= &-1;
// Binary
_n = _n + 0;
@@ -158,8 +235,9 @@ pub fn non_overflowing_ops_or_ops_already_handled_by_the_compiler_should_not_tri
_n = -&i32::MIN;
}
-pub fn runtime_ops() {
+pub fn unknown_ops_or_runtime_ops_that_can_overflow() {
let mut _n = i32::MAX;
+ let mut _custom = Custom;
// Assign
_n += 1;
@@ -172,6 +250,36 @@ pub fn runtime_ops() {
_n %= &0;
_n *= 2;
_n *= &2;
+ _n += -1;
+ _n += &-1;
+ _n -= -1;
+ _n -= &-1;
+ _n /= -0;
+ _n /= &-0;
+ _n %= -0;
+ _n %= &-0;
+ _n *= -2;
+ _n *= &-2;
+ _custom += Custom;
+ _custom += &Custom;
+ _custom -= Custom;
+ _custom -= &Custom;
+ _custom /= Custom;
+ _custom /= &Custom;
+ _custom %= Custom;
+ _custom %= &Custom;
+ _custom *= Custom;
+ _custom *= &Custom;
+ _custom += -Custom;
+ _custom += &-Custom;
+ _custom -= -Custom;
+ _custom -= &-Custom;
+ _custom /= -Custom;
+ _custom /= &-Custom;
+ _custom %= -Custom;
+ _custom %= &-Custom;
+ _custom *= -Custom;
+ _custom *= &-Custom;
// Binary
_n = _n + 1;
@@ -193,36 +301,73 @@ pub fn runtime_ops() {
_n = 23 + &85;
_n = &23 + 85;
_n = &23 + &85;
-
- // Custom
- let _ = Custom + 0;
- let _ = Custom + 1;
- let _ = Custom + 2;
- let _ = Custom + 0.0;
- let _ = Custom + 1.0;
- let _ = Custom + 2.0;
- let _ = Custom - 0;
- let _ = Custom - 1;
- let _ = Custom - 2;
- let _ = Custom - 0.0;
- let _ = Custom - 1.0;
- let _ = Custom - 2.0;
- let _ = Custom / 0;
- let _ = Custom / 1;
- let _ = Custom / 2;
- let _ = Custom / 0.0;
- let _ = Custom / 1.0;
- let _ = Custom / 2.0;
- let _ = Custom * 0;
- let _ = Custom * 1;
- let _ = Custom * 2;
- let _ = Custom * 0.0;
- let _ = Custom * 1.0;
- let _ = Custom * 2.0;
+ _custom = _custom + _custom;
+ _custom = _custom + &_custom;
+ _custom = Custom + _custom;
+ _custom = &Custom + _custom;
+ _custom = _custom - Custom;
+ _custom = _custom - &Custom;
+ _custom = Custom - _custom;
+ _custom = &Custom - _custom;
+ _custom = _custom / Custom;
+ _custom = _custom / &Custom;
+ _custom = _custom % Custom;
+ _custom = _custom % &Custom;
+ _custom = _custom * Custom;
+ _custom = _custom * &Custom;
+ _custom = Custom * _custom;
+ _custom = &Custom * _custom;
+ _custom = Custom + &Custom;
+ _custom = &Custom + Custom;
+ _custom = &Custom + &Custom;
// Unary
_n = -_n;
_n = -&_n;
+ _custom = -_custom;
+ _custom = -&_custom;
+}
+
+// Copied and pasted from the `integer_arithmetic` lint for comparison.
+pub fn integer_arithmetic() {
+ let mut i = 1i32;
+ let mut var1 = 0i32;
+ let mut var2 = -1i32;
+
+ 1 + i;
+ i * 2;
+ 1 % i / 2;
+ i - 2 + 2 - i;
+ -i;
+ i >> 1;
+ i << 1;
+
+ -1;
+ -(-1);
+
+ i & 1;
+ i | 1;
+ i ^ 1;
+
+ i += 1;
+ i -= 1;
+ i *= 2;
+ i /= 2;
+ i /= 0;
+ i /= -1;
+ i /= var1;
+ i /= var2;
+ i %= 2;
+ i %= 0;
+ i %= -1;
+ i %= var1;
+ i %= var2;
+ i <<= 3;
+ i >>= 2;
+
+ i |= 1;
+ i &= 1;
+ i ^= i;
}
fn main() {}
diff --git a/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr b/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr
index 0259a0824..5e349f6b4 100644
--- a/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr
+++ b/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr
@@ -1,352 +1,598 @@
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:78:13
- |
-LL | let _ = String::new() + "";
- | ^^^^^^^^^^^^^^^^^^
- |
- = note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`
-
-error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:86:27
- |
-LL | let inferred_string = string + "";
- | ^^^^^^^^^^^
-
-error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:90:13
- |
-LL | let _ = inferred_string + "";
- | ^^^^^^^^^^^^^^^^^^^^
-
-error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:165:5
+ --> $DIR/arithmetic_side_effects.rs:243:5
|
LL | _n += 1;
| ^^^^^^^
+ |
+ = note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:166:5
+ --> $DIR/arithmetic_side_effects.rs:244:5
|
LL | _n += &1;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:167:5
+ --> $DIR/arithmetic_side_effects.rs:245:5
|
LL | _n -= 1;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:168:5
+ --> $DIR/arithmetic_side_effects.rs:246:5
|
LL | _n -= &1;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:169:5
+ --> $DIR/arithmetic_side_effects.rs:247:5
|
LL | _n /= 0;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:170:5
+ --> $DIR/arithmetic_side_effects.rs:248:5
|
LL | _n /= &0;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:171:5
+ --> $DIR/arithmetic_side_effects.rs:249:5
|
LL | _n %= 0;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:172:5
+ --> $DIR/arithmetic_side_effects.rs:250:5
|
LL | _n %= &0;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:173:5
+ --> $DIR/arithmetic_side_effects.rs:251:5
|
LL | _n *= 2;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:174:5
+ --> $DIR/arithmetic_side_effects.rs:252:5
|
LL | _n *= &2;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:177:10
+ --> $DIR/arithmetic_side_effects.rs:253:5
+ |
+LL | _n += -1;
+ | ^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:254:5
+ |
+LL | _n += &-1;
+ | ^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:255:5
+ |
+LL | _n -= -1;
+ | ^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:256:5
+ |
+LL | _n -= &-1;
+ | ^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:257:5
+ |
+LL | _n /= -0;
+ | ^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:258:5
+ |
+LL | _n /= &-0;
+ | ^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:259:5
+ |
+LL | _n %= -0;
+ | ^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:260:5
+ |
+LL | _n %= &-0;
+ | ^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:261:5
+ |
+LL | _n *= -2;
+ | ^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:262:5
+ |
+LL | _n *= &-2;
+ | ^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:263:5
+ |
+LL | _custom += Custom;
+ | ^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:264:5
+ |
+LL | _custom += &Custom;
+ | ^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:265:5
+ |
+LL | _custom -= Custom;
+ | ^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:266:5
+ |
+LL | _custom -= &Custom;
+ | ^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:267:5
+ |
+LL | _custom /= Custom;
+ | ^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:268:5
+ |
+LL | _custom /= &Custom;
+ | ^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:269:5
+ |
+LL | _custom %= Custom;
+ | ^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:270:5
+ |
+LL | _custom %= &Custom;
+ | ^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:271:5
+ |
+LL | _custom *= Custom;
+ | ^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:272:5
+ |
+LL | _custom *= &Custom;
+ | ^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:273:5
+ |
+LL | _custom += -Custom;
+ | ^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:274:5
+ |
+LL | _custom += &-Custom;
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:275:5
+ |
+LL | _custom -= -Custom;
+ | ^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:276:5
+ |
+LL | _custom -= &-Custom;
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:277:5
+ |
+LL | _custom /= -Custom;
+ | ^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:278:5
+ |
+LL | _custom /= &-Custom;
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:279:5
+ |
+LL | _custom %= -Custom;
+ | ^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:280:5
+ |
+LL | _custom %= &-Custom;
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:281:5
+ |
+LL | _custom *= -Custom;
+ | ^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:282:5
+ |
+LL | _custom *= &-Custom;
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:285: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:286: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:287: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:288: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:289:10
|
LL | _n = _n - 1;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:182:10
+ --> $DIR/arithmetic_side_effects.rs:290:10
|
LL | _n = _n - &1;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:183:10
+ --> $DIR/arithmetic_side_effects.rs:291:10
|
LL | _n = 1 - _n;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:184:10
+ --> $DIR/arithmetic_side_effects.rs:292:10
|
LL | _n = &1 - _n;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:185:10
+ --> $DIR/arithmetic_side_effects.rs:293:10
|
LL | _n = _n / 0;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:186:10
+ --> $DIR/arithmetic_side_effects.rs:294:10
|
LL | _n = _n / &0;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:187:10
+ --> $DIR/arithmetic_side_effects.rs:295:10
|
LL | _n = _n % 0;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:188:10
+ --> $DIR/arithmetic_side_effects.rs:296:10
|
LL | _n = _n % &0;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:189:10
+ --> $DIR/arithmetic_side_effects.rs:297:10
|
LL | _n = _n * 2;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:190:10
+ --> $DIR/arithmetic_side_effects.rs:298:10
|
LL | _n = _n * &2;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:191:10
+ --> $DIR/arithmetic_side_effects.rs:299:10
|
LL | _n = 2 * _n;
| ^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:192:10
+ --> $DIR/arithmetic_side_effects.rs:300:10
|
LL | _n = &2 * _n;
| ^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:193:10
+ --> $DIR/arithmetic_side_effects.rs:301:10
|
LL | _n = 23 + &85;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:194:10
+ --> $DIR/arithmetic_side_effects.rs:302:10
|
LL | _n = &23 + 85;
| ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:195:10
+ --> $DIR/arithmetic_side_effects.rs:303:10
|
LL | _n = &23 + &85;
| ^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:198:13
+ --> $DIR/arithmetic_side_effects.rs:304:15
+ |
+LL | _custom = _custom + _custom;
+ | ^^^^^^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:305:15
|
-LL | let _ = Custom + 0;
- | ^^^^^^^^^^
+LL | _custom = _custom + &_custom;
+ | ^^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:199:13
+ --> $DIR/arithmetic_side_effects.rs:306:15
|
-LL | let _ = Custom + 1;
- | ^^^^^^^^^^
+LL | _custom = Custom + _custom;
+ | ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:200:13
+ --> $DIR/arithmetic_side_effects.rs:307:15
|
-LL | let _ = Custom + 2;
- | ^^^^^^^^^^
+LL | _custom = &Custom + _custom;
+ | ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:201:13
+ --> $DIR/arithmetic_side_effects.rs:308:15
|
-LL | let _ = Custom + 0.0;
- | ^^^^^^^^^^^^
+LL | _custom = _custom - Custom;
+ | ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:202:13
+ --> $DIR/arithmetic_side_effects.rs:309:15
|
-LL | let _ = Custom + 1.0;
- | ^^^^^^^^^^^^
+LL | _custom = _custom - &Custom;
+ | ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:203:13
+ --> $DIR/arithmetic_side_effects.rs:310:15
|
-LL | let _ = Custom + 2.0;
- | ^^^^^^^^^^^^
+LL | _custom = Custom - _custom;
+ | ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:204:13
+ --> $DIR/arithmetic_side_effects.rs:311:15
|
-LL | let _ = Custom - 0;
- | ^^^^^^^^^^
+LL | _custom = &Custom - _custom;
+ | ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:205:13
+ --> $DIR/arithmetic_side_effects.rs:312:15
|
-LL | let _ = Custom - 1;
- | ^^^^^^^^^^
+LL | _custom = _custom / Custom;
+ | ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:206:13
+ --> $DIR/arithmetic_side_effects.rs:313:15
|
-LL | let _ = Custom - 2;
- | ^^^^^^^^^^
+LL | _custom = _custom / &Custom;
+ | ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:207:13
+ --> $DIR/arithmetic_side_effects.rs:314:15
|
-LL | let _ = Custom - 0.0;
- | ^^^^^^^^^^^^
+LL | _custom = _custom % Custom;
+ | ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:208:13
+ --> $DIR/arithmetic_side_effects.rs:315:15
|
-LL | let _ = Custom - 1.0;
- | ^^^^^^^^^^^^
+LL | _custom = _custom % &Custom;
+ | ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:209:13
+ --> $DIR/arithmetic_side_effects.rs:316:15
|
-LL | let _ = Custom - 2.0;
- | ^^^^^^^^^^^^
+LL | _custom = _custom * Custom;
+ | ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:210:13
+ --> $DIR/arithmetic_side_effects.rs:317:15
|
-LL | let _ = Custom / 0;
- | ^^^^^^^^^^
+LL | _custom = _custom * &Custom;
+ | ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:211:13
+ --> $DIR/arithmetic_side_effects.rs:318:15
|
-LL | let _ = Custom / 1;
- | ^^^^^^^^^^
+LL | _custom = Custom * _custom;
+ | ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:212:13
+ --> $DIR/arithmetic_side_effects.rs:319:15
|
-LL | let _ = Custom / 2;
- | ^^^^^^^^^^
+LL | _custom = &Custom * _custom;
+ | ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:213:13
+ --> $DIR/arithmetic_side_effects.rs:320:15
|
-LL | let _ = Custom / 0.0;
- | ^^^^^^^^^^^^
+LL | _custom = Custom + &Custom;
+ | ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:214:13
+ --> $DIR/arithmetic_side_effects.rs:321:15
|
-LL | let _ = Custom / 1.0;
- | ^^^^^^^^^^^^
+LL | _custom = &Custom + Custom;
+ | ^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:215:13
+ --> $DIR/arithmetic_side_effects.rs:322:15
|
-LL | let _ = Custom / 2.0;
- | ^^^^^^^^^^^^
+LL | _custom = &Custom + &Custom;
+ | ^^^^^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:216:13
+ --> $DIR/arithmetic_side_effects.rs:325:10
|
-LL | let _ = Custom * 0;
- | ^^^^^^^^^^
+LL | _n = -_n;
+ | ^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:217:13
+ --> $DIR/arithmetic_side_effects.rs:326:10
|
-LL | let _ = Custom * 1;
- | ^^^^^^^^^^
+LL | _n = -&_n;
+ | ^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:218:13
+ --> $DIR/arithmetic_side_effects.rs:327:15
|
-LL | let _ = Custom * 2;
- | ^^^^^^^^^^
+LL | _custom = -_custom;
+ | ^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:219:13
+ --> $DIR/arithmetic_side_effects.rs:328:15
|
-LL | let _ = Custom * 0.0;
- | ^^^^^^^^^^^^
+LL | _custom = -&_custom;
+ | ^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:220:13
+ --> $DIR/arithmetic_side_effects.rs:337:5
|
-LL | let _ = Custom * 1.0;
- | ^^^^^^^^^^^^
+LL | 1 + i;
+ | ^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:221:13
+ --> $DIR/arithmetic_side_effects.rs:338:5
|
-LL | let _ = Custom * 2.0;
- | ^^^^^^^^^^^^
+LL | i * 2;
+ | ^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:224:10
+ --> $DIR/arithmetic_side_effects.rs:340:5
|
-LL | _n = -_n;
- | ^^^
+LL | i - 2 + 2 - i;
+ | ^^^^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects.rs:225:10
+ --> $DIR/arithmetic_side_effects.rs:341:5
|
-LL | _n = -&_n;
- | ^^^^
+LL | -i;
+ | ^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:342:5
+ |
+LL | i >> 1;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:343:5
+ |
+LL | i << 1;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:352:5
+ |
+LL | i += 1;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:353:5
+ |
+LL | i -= 1;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:354:5
+ |
+LL | i *= 2;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:356:5
+ |
+LL | i /= 0;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:358:5
+ |
+LL | i /= var1;
+ | ^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:359:5
+ |
+LL | i /= var2;
+ | ^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:361:5
+ |
+LL | i %= 0;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:363:5
+ |
+LL | i %= var1;
+ | ^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:364:5
+ |
+LL | i %= var2;
+ | ^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:365:5
+ |
+LL | i <<= 3;
+ | ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:366:5
+ |
+LL | i >>= 2;
+ | ^^^^^^^
-error: aborting due to 58 previous errors
+error: aborting due to 99 previous errors
diff --git a/src/tools/clippy/tests/ui/async_yields_async.stderr b/src/tools/clippy/tests/ui/async_yields_async.stderr
index 92ba35929..22ce1c6f6 100644
--- a/src/tools/clippy/tests/ui/async_yields_async.stderr
+++ b/src/tools/clippy/tests/ui/async_yields_async.stderr
@@ -3,8 +3,7 @@ error: an async construct yields a type which is itself awaitable
|
LL | let _h = async {
| _____________________-
-LL | | async {
- | | _________^
+LL | |/ async {
LL | || 3
LL | || }
| ||_________^ awaitable value not awaited
@@ -37,8 +36,7 @@ error: an async construct yields a type which is itself awaitable
|
LL | let _j = async || {
| ________________________-
-LL | | async {
- | | _________^
+LL | |/ async {
LL | || 3
LL | || }
| ||_________^ awaitable value not awaited
diff --git a/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs b/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs
index ef3ca9aea..1e5f20e8c 100644
--- a/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs
@@ -142,8 +142,10 @@ macro_rules! equatable_if_let {
}
#[macro_export]
-macro_rules! almost_complete_letter_range {
+macro_rules! almost_complete_range {
() => {
let _ = 'a'..'z';
+ let _ = 'A'..'Z';
+ let _ = '0'..'9';
};
}
diff --git a/src/tools/clippy/tests/ui/box_default.fixed b/src/tools/clippy/tests/ui/box_default.fixed
index 911fa856a..7e9f074fd 100644
--- a/src/tools/clippy/tests/ui/box_default.fixed
+++ b/src/tools/clippy/tests/ui/box_default.fixed
@@ -21,16 +21,16 @@ macro_rules! outer {
fn main() {
let _string: Box<String> = Box::default();
let _byte = Box::<u8>::default();
- let _vec = Box::<std::vec::Vec<u8>>::default();
+ let _vec = Box::<Vec<u8>>::default();
let _impl = Box::<ImplementsDefault>::default();
let _impl2 = Box::<ImplementsDefault>::default();
let _impl3: Box<ImplementsDefault> = Box::default();
let _own = Box::new(OwnDefault::default()); // should not lint
- let _in_macro = outer!(Box::<std::string::String>::default());
- let _string_default = outer!(Box::<std::string::String>::default());
+ let _in_macro = outer!(Box::<String>::default());
+ let _string_default = outer!(Box::<String>::default());
let _vec2: Box<Vec<ImplementsDefault>> = Box::default();
let _vec3: Box<Vec<bool>> = Box::default();
- let _vec4: Box<_> = Box::<std::vec::Vec<bool>>::default();
+ let _vec4: Box<_> = Box::<Vec<bool>>::default();
let _more = ret_ty_fn();
call_ty_fn(Box::default());
}
@@ -54,4 +54,14 @@ impl Read for ImplementsDefault {
fn issue_9621_dyn_trait() {
let _: Box<dyn Read> = Box::<ImplementsDefault>::default();
+ issue_10089();
+}
+
+fn issue_10089() {
+ let _closure = || {
+ #[derive(Default)]
+ struct WeirdPathed;
+
+ let _ = Box::<WeirdPathed>::default();
+ };
}
diff --git a/src/tools/clippy/tests/ui/box_default.rs b/src/tools/clippy/tests/ui/box_default.rs
index 20019c2ee..5c8d0b835 100644
--- a/src/tools/clippy/tests/ui/box_default.rs
+++ b/src/tools/clippy/tests/ui/box_default.rs
@@ -54,4 +54,14 @@ impl Read for ImplementsDefault {
fn issue_9621_dyn_trait() {
let _: Box<dyn Read> = Box::new(ImplementsDefault::default());
+ issue_10089();
+}
+
+fn issue_10089() {
+ let _closure = || {
+ #[derive(Default)]
+ struct WeirdPathed;
+
+ let _ = Box::new(WeirdPathed::default());
+ };
}
diff --git a/src/tools/clippy/tests/ui/box_default.stderr b/src/tools/clippy/tests/ui/box_default.stderr
index 5ea410331..249eb340f 100644
--- a/src/tools/clippy/tests/ui/box_default.stderr
+++ b/src/tools/clippy/tests/ui/box_default.stderr
@@ -16,7 +16,7 @@ error: `Box::new(_)` of default value
--> $DIR/box_default.rs:24:16
|
LL | let _vec = Box::new(Vec::<u8>::new());
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::vec::Vec<u8>>::default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<Vec<u8>>::default()`
error: `Box::new(_)` of default value
--> $DIR/box_default.rs:25:17
@@ -40,13 +40,13 @@ error: `Box::new(_)` of default value
--> $DIR/box_default.rs:29:28
|
LL | let _in_macro = outer!(Box::new(String::new()));
- | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::string::String>::default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<String>::default()`
error: `Box::new(_)` of default value
--> $DIR/box_default.rs:30:34
|
LL | let _string_default = outer!(Box::new(String::from("")));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::string::String>::default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<String>::default()`
error: `Box::new(_)` of default value
--> $DIR/box_default.rs:31:46
@@ -64,7 +64,7 @@ error: `Box::new(_)` of default value
--> $DIR/box_default.rs:33:25
|
LL | let _vec4: Box<_> = Box::new(Vec::from([false; 0]));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::vec::Vec<bool>>::default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<Vec<bool>>::default()`
error: `Box::new(_)` of default value
--> $DIR/box_default.rs:35:16
@@ -84,5 +84,11 @@ error: `Box::new(_)` of default value
LL | let _: Box<dyn Read> = Box::new(ImplementsDefault::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<ImplementsDefault>::default()`
-error: aborting due to 14 previous errors
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:65:17
+ |
+LL | let _ = Box::new(WeirdPathed::default());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<WeirdPathed>::default()`
+
+error: aborting due to 15 previous errors
diff --git a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed
new file mode 100644
index 000000000..5fbaa64db
--- /dev/null
+++ b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed
@@ -0,0 +1,67 @@
+// run-rustfix
+#![warn(clippy::case_sensitive_file_extension_comparisons)]
+
+use std::string::String;
+
+struct TestStruct;
+
+impl TestStruct {
+ fn ends_with(self, _arg: &str) {}
+}
+
+#[allow(dead_code)]
+fn is_rust_file(filename: &str) -> bool {
+ std::path::Path::new(filename)
+ .extension()
+ .map_or(false, |ext| ext.eq_ignore_ascii_case("rs"))
+}
+
+fn main() {
+ // std::string::String and &str should trigger the lint failure with .ext12
+ let _ = std::path::Path::new(&String::new())
+ .extension()
+ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
+ let _ = std::path::Path::new("str")
+ .extension()
+ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
+
+ // The fixup should preserve the indentation level
+ {
+ let _ = std::path::Path::new("str")
+ .extension()
+ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
+ }
+
+ // The test struct should not trigger the lint failure with .ext12
+ TestStruct {}.ends_with(".ext12");
+
+ // std::string::String and &str should trigger the lint failure with .EXT12
+ let _ = std::path::Path::new(&String::new())
+ .extension()
+ .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12"));
+ let _ = std::path::Path::new("str")
+ .extension()
+ .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12"));
+
+ // Should not trigger the lint failure because of the calls to to_lowercase and to_uppercase
+ let _ = String::new().to_lowercase().ends_with(".EXT12");
+ let _ = String::new().to_uppercase().ends_with(".EXT12");
+
+ // The test struct should not trigger the lint failure with .EXT12
+ TestStruct {}.ends_with(".EXT12");
+
+ // Should not trigger the lint failure with .eXT12
+ let _ = String::new().ends_with(".eXT12");
+ let _ = "str".ends_with(".eXT12");
+ TestStruct {}.ends_with(".eXT12");
+
+ // Should not trigger the lint failure with .EXT123 (too long)
+ let _ = String::new().ends_with(".EXT123");
+ let _ = "str".ends_with(".EXT123");
+ TestStruct {}.ends_with(".EXT123");
+
+ // Shouldn't fail if it doesn't start with a dot
+ let _ = String::new().ends_with("a.ext");
+ let _ = "str".ends_with("a.extA");
+ TestStruct {}.ends_with("a.ext");
+}
diff --git a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs
index 6f0485b52..3c0d4821f 100644
--- a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs
+++ b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs
@@ -1,3 +1,4 @@
+// run-rustfix
#![warn(clippy::case_sensitive_file_extension_comparisons)]
use std::string::String;
@@ -5,9 +6,10 @@ use std::string::String;
struct TestStruct;
impl TestStruct {
- fn ends_with(self, arg: &str) {}
+ fn ends_with(self, _arg: &str) {}
}
+#[allow(dead_code)]
fn is_rust_file(filename: &str) -> bool {
filename.ends_with(".rs")
}
@@ -17,6 +19,11 @@ fn main() {
let _ = String::new().ends_with(".ext12");
let _ = "str".ends_with(".ext12");
+ // The fixup should preserve the indentation level
+ {
+ let _ = "str".ends_with(".ext12");
+ }
+
// The test struct should not trigger the lint failure with .ext12
TestStruct {}.ends_with(".ext12");
@@ -24,6 +31,10 @@ fn main() {
let _ = String::new().ends_with(".EXT12");
let _ = "str".ends_with(".EXT12");
+ // Should not trigger the lint failure because of the calls to to_lowercase and to_uppercase
+ let _ = String::new().to_lowercase().ends_with(".EXT12");
+ let _ = String::new().to_uppercase().ends_with(".EXT12");
+
// The test struct should not trigger the lint failure with .EXT12
TestStruct {}.ends_with(".EXT12");
diff --git a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.stderr b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.stderr
index a28dd8bd5..44c8e3fdf 100644
--- a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.stderr
+++ b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.stderr
@@ -1,43 +1,87 @@
error: case-sensitive file extension comparison
- --> $DIR/case_sensitive_file_extension_comparisons.rs:12:14
+ --> $DIR/case_sensitive_file_extension_comparisons.rs:14:5
|
LL | filename.ends_with(".rs")
- | ^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using a case-insensitive comparison instead
= note: `-D clippy::case-sensitive-file-extension-comparisons` implied by `-D warnings`
+help: use std::path::Path
+ |
+LL ~ std::path::Path::new(filename)
+LL + .extension()
+LL + .map_or(false, |ext| ext.eq_ignore_ascii_case("rs"))
+ |
error: case-sensitive file extension comparison
- --> $DIR/case_sensitive_file_extension_comparisons.rs:17:27
+ --> $DIR/case_sensitive_file_extension_comparisons.rs:19:13
|
LL | let _ = String::new().ends_with(".ext12");
- | ^^^^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using a case-insensitive comparison instead
+help: use std::path::Path
+ |
+LL ~ let _ = std::path::Path::new(&String::new())
+LL + .extension()
+LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
+ |
error: case-sensitive file extension comparison
- --> $DIR/case_sensitive_file_extension_comparisons.rs:18:19
+ --> $DIR/case_sensitive_file_extension_comparisons.rs:20:13
|
LL | let _ = "str".ends_with(".ext12");
- | ^^^^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using a case-insensitive comparison instead
+help: use std::path::Path
+ |
+LL ~ let _ = std::path::Path::new("str")
+LL + .extension()
+LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
+ |
error: case-sensitive file extension comparison
- --> $DIR/case_sensitive_file_extension_comparisons.rs:24:27
+ --> $DIR/case_sensitive_file_extension_comparisons.rs:24:17
+ |
+LL | let _ = "str".ends_with(".ext12");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: consider using a case-insensitive comparison instead
+help: use std::path::Path
+ |
+LL ~ let _ = std::path::Path::new("str")
+LL + .extension()
+LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
+ |
+
+error: case-sensitive file extension comparison
+ --> $DIR/case_sensitive_file_extension_comparisons.rs:31:13
|
LL | let _ = String::new().ends_with(".EXT12");
- | ^^^^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using a case-insensitive comparison instead
+help: use std::path::Path
+ |
+LL ~ let _ = std::path::Path::new(&String::new())
+LL + .extension()
+LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12"));
+ |
error: case-sensitive file extension comparison
- --> $DIR/case_sensitive_file_extension_comparisons.rs:25:19
+ --> $DIR/case_sensitive_file_extension_comparisons.rs:32:13
|
LL | let _ = "str".ends_with(".EXT12");
- | ^^^^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using a case-insensitive comparison instead
+help: use std::path::Path
+ |
+LL ~ let _ = std::path::Path::new("str")
+LL + .extension()
+LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12"));
+ |
-error: aborting due to 5 previous errors
+error: aborting due to 6 previous errors
diff --git a/src/tools/clippy/tests/ui/cast_lossless_integer.fixed b/src/tools/clippy/tests/ui/cast_lossless_integer.fixed
index 72a708b40..925cbf253 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_integer.fixed
+++ b/src/tools/clippy/tests/ui/cast_lossless_integer.fixed
@@ -45,3 +45,9 @@ mod cast_lossless_in_impl {
}
}
}
+
+#[derive(PartialEq, Debug)]
+#[repr(i64)]
+enum Test {
+ A = u32::MAX as i64 + 1,
+}
diff --git a/src/tools/clippy/tests/ui/cast_lossless_integer.rs b/src/tools/clippy/tests/ui/cast_lossless_integer.rs
index 34bb47181..c82bd9108 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_integer.rs
+++ b/src/tools/clippy/tests/ui/cast_lossless_integer.rs
@@ -45,3 +45,9 @@ mod cast_lossless_in_impl {
}
}
}
+
+#[derive(PartialEq, Debug)]
+#[repr(i64)]
+enum Test {
+ A = u32::MAX as i64 + 1,
+}
diff --git a/src/tools/clippy/tests/ui/clone_on_copy.stderr b/src/tools/clippy/tests/ui/clone_on_copy.stderr
index 42ae22777..862234d20 100644
--- a/src/tools/clippy/tests/ui/clone_on_copy.stderr
+++ b/src/tools/clippy/tests/ui/clone_on_copy.stderr
@@ -48,7 +48,7 @@ error: using `clone` on type `i32` which implements the `Copy` trait
LL | vec.push(42.clone());
| ^^^^^^^^^^ help: try removing the `clone` call: `42`
-error: using `clone` on type `std::option::Option<i32>` which implements the `Copy` trait
+error: using `clone` on type `Option<i32>` which implements the `Copy` trait
--> $DIR/clone_on_copy.rs:77:17
|
LL | let value = opt.clone()?; // operator precedence needed (*opt)?
diff --git a/src/tools/clippy/tests/ui/collapsible_str_replace.fixed b/src/tools/clippy/tests/ui/collapsible_str_replace.fixed
index 49fc9a962..9792ae9ed 100644
--- a/src/tools/clippy/tests/ui/collapsible_str_replace.fixed
+++ b/src/tools/clippy/tests/ui/collapsible_str_replace.fixed
@@ -1,5 +1,6 @@
// run-rustfix
+#![allow(unused)]
#![warn(clippy::collapsible_str_replace)]
fn get_filter() -> char {
@@ -71,3 +72,13 @@ fn main() {
.replace('u', iter.next().unwrap())
.replace('s', iter.next().unwrap());
}
+
+#[clippy::msrv = "1.57"]
+fn msrv_1_57() {
+ let _ = "".replace('a', "1.57").replace('b', "1.57");
+}
+
+#[clippy::msrv = "1.58"]
+fn msrv_1_58() {
+ let _ = "".replace(['a', 'b'], "1.58");
+}
diff --git a/src/tools/clippy/tests/ui/collapsible_str_replace.rs b/src/tools/clippy/tests/ui/collapsible_str_replace.rs
index e3e25c414..baee185b7 100644
--- a/src/tools/clippy/tests/ui/collapsible_str_replace.rs
+++ b/src/tools/clippy/tests/ui/collapsible_str_replace.rs
@@ -1,5 +1,6 @@
// run-rustfix
+#![allow(unused)]
#![warn(clippy::collapsible_str_replace)]
fn get_filter() -> char {
@@ -74,3 +75,13 @@ fn main() {
.replace('u', iter.next().unwrap())
.replace('s', iter.next().unwrap());
}
+
+#[clippy::msrv = "1.57"]
+fn msrv_1_57() {
+ let _ = "".replace('a', "1.57").replace('b', "1.57");
+}
+
+#[clippy::msrv = "1.58"]
+fn msrv_1_58() {
+ let _ = "".replace('a', "1.58").replace('b', "1.58");
+}
diff --git a/src/tools/clippy/tests/ui/collapsible_str_replace.stderr b/src/tools/clippy/tests/ui/collapsible_str_replace.stderr
index 8e3daf3b8..223358cf5 100644
--- a/src/tools/clippy/tests/ui/collapsible_str_replace.stderr
+++ b/src/tools/clippy/tests/ui/collapsible_str_replace.stderr
@@ -1,5 +1,5 @@
error: used consecutive `str::replace` call
- --> $DIR/collapsible_str_replace.rs:19:27
+ --> $DIR/collapsible_str_replace.rs:20:27
|
LL | let _ = "hesuo worpd".replace('s', "l").replace('u', "l");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['s', 'u'], "l")`
@@ -7,19 +7,19 @@ LL | let _ = "hesuo worpd".replace('s', "l").replace('u', "l");
= note: `-D clippy::collapsible-str-replace` implied by `-D warnings`
error: used consecutive `str::replace` call
- --> $DIR/collapsible_str_replace.rs:21:27
+ --> $DIR/collapsible_str_replace.rs:22:27
|
LL | let _ = "hesuo worpd".replace('s', l).replace('u', l);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['s', 'u'], l)`
error: used consecutive `str::replace` call
- --> $DIR/collapsible_str_replace.rs:23:27
+ --> $DIR/collapsible_str_replace.rs:24:27
|
LL | let _ = "hesuo worpd".replace('s', "l").replace('u', "l").replace('p', "l");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['s', 'u', 'p'], "l")`
error: used consecutive `str::replace` call
- --> $DIR/collapsible_str_replace.rs:26:10
+ --> $DIR/collapsible_str_replace.rs:27:10
|
LL | .replace('s', "l")
| __________^
@@ -29,58 +29,64 @@ LL | | .replace('d', "l");
| |__________________________^ help: replace with: `replace(['s', 'u', 'p', 'd'], "l")`
error: used consecutive `str::replace` call
- --> $DIR/collapsible_str_replace.rs:31:27
+ --> $DIR/collapsible_str_replace.rs:32:27
|
LL | let _ = "hesuo world".replace(s, "l").replace('u', "l");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([s, 'u'], "l")`
error: used consecutive `str::replace` call
- --> $DIR/collapsible_str_replace.rs:33:27
+ --> $DIR/collapsible_str_replace.rs:34:27
|
LL | let _ = "hesuo worpd".replace(s, "l").replace('u', "l").replace('p', "l");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([s, 'u', 'p'], "l")`
error: used consecutive `str::replace` call
- --> $DIR/collapsible_str_replace.rs:35:27
+ --> $DIR/collapsible_str_replace.rs:36:27
|
LL | let _ = "hesuo worpd".replace(s, "l").replace(u, "l").replace('p', "l");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([s, u, 'p'], "l")`
error: used consecutive `str::replace` call
- --> $DIR/collapsible_str_replace.rs:37:27
+ --> $DIR/collapsible_str_replace.rs:38:27
|
LL | let _ = "hesuo worpd".replace(s, "l").replace(u, "l").replace(p, "l");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([s, u, p], "l")`
error: used consecutive `str::replace` call
- --> $DIR/collapsible_str_replace.rs:39:27
+ --> $DIR/collapsible_str_replace.rs:40:27
|
LL | let _ = "hesuo worlp".replace('s', "l").replace('u', "l").replace('p', "d");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['s', 'u'], "l")`
error: used consecutive `str::replace` call
- --> $DIR/collapsible_str_replace.rs:41:45
+ --> $DIR/collapsible_str_replace.rs:42:45
|
LL | let _ = "hesuo worpd".replace('s', "x").replace('u', "l").replace('p', "l");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['u', 'p'], "l")`
error: used consecutive `str::replace` call
- --> $DIR/collapsible_str_replace.rs:44:47
+ --> $DIR/collapsible_str_replace.rs:45:47
|
LL | let _ = "hesudo worpd".replace("su", "l").replace('d', "l").replace('p', "l");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['d', 'p'], "l")`
error: used consecutive `str::replace` call
- --> $DIR/collapsible_str_replace.rs:46:28
+ --> $DIR/collapsible_str_replace.rs:47:28
|
LL | let _ = "hesudo worpd".replace(d, "l").replace('p', "l").replace("su", "l");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([d, 'p'], "l")`
error: used consecutive `str::replace` call
- --> $DIR/collapsible_str_replace.rs:48:27
+ --> $DIR/collapsible_str_replace.rs:49:27
|
LL | let _ = "hesuo world".replace(get_filter(), "l").replace('s', "l");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace([get_filter(), 's'], "l")`
-error: aborting due to 13 previous errors
+error: used consecutive `str::replace` call
+ --> $DIR/collapsible_str_replace.rs:86:16
+ |
+LL | let _ = "".replace('a', "1.58").replace('b', "1.58");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `replace(['a', 'b'], "1.58")`
+
+error: aborting due to 14 previous errors
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6252.stderr b/src/tools/clippy/tests/ui/crashes/ice-6252.stderr
index 638e4a548..efdd56dd4 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6252.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-6252.stderr
@@ -17,9 +17,12 @@ error[E0412]: cannot find type `VAL` in this scope
--> $DIR/ice-6252.rs:10:63
|
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
- | - ^^^ not found in this scope
- | |
- | help: you might be missing a type parameter: `, VAL`
+ | ^^^ not found in this scope
+ |
+help: you might be missing a type parameter
+ |
+LL | impl<N, M, VAL> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
+ | +++++
error[E0046]: not all trait items implemented, missing: `VAL`
--> $DIR/ice-6252.rs:10:1
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6254.rs b/src/tools/clippy/tests/ui/crashes/ice-6254.rs
index a2a60a169..8af608903 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6254.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-6254.rs
@@ -1,4 +1,4 @@
-// originally from ./src/test/ui/pattern/usefulness/consts-opaque.rs
+// originally from ./tests/ui/pattern/usefulness/consts-opaque.rs
// panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())',
// compiler/rustc_mir_build/src/thir/pattern/_match.rs:2030:5
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6255.rs b/src/tools/clippy/tests/ui/crashes/ice-6255.rs
index bd4a81d98..ccde6aa2b 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6255.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-6255.rs
@@ -1,4 +1,4 @@
-// originally from rustc ./src/test/ui/macros/issue-78325-inconsistent-resolution.rs
+// originally from rustc ./tests/ui/macros/issue-78325-inconsistent-resolution.rs
// inconsistent resolution for a macro
macro_rules! define_other_core {
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6256.rs b/src/tools/clippy/tests/ui/crashes/ice-6256.rs
index 67308263d..f9ee3e058 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6256.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-6256.rs
@@ -1,4 +1,4 @@
-// originally from rustc ./src/test/ui/regions/issue-78262.rs
+// originally from rustc ./tests/ui/regions/issue-78262.rs
// ICE: to get the signature of a closure, use substs.as_closure().sig() not fn_sig()
#![allow(clippy::upper_case_acronyms)]
diff --git a/src/tools/clippy/tests/ui/dbg_macro.stderr b/src/tools/clippy/tests/ui/dbg_macro.stderr
index e6a65b46d..ddb5f1342 100644
--- a/src/tools/clippy/tests/ui/dbg_macro.stderr
+++ b/src/tools/clippy/tests/ui/dbg_macro.stderr
@@ -1,143 +1,143 @@
-error: `dbg!` macro is intended as a debugging tool
+error: the `dbg!` macro is intended as a debugging tool
--> $DIR/dbg_macro.rs:5:22
|
LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n }
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::dbg-macro` implied by `-D warnings`
-help: ensure to avoid having uses of it in version control
+help: remove the invocation before committing it to a version control system
|
LL | if let Some(n) = n.checked_sub(4) { n } else { n }
| ~~~~~~~~~~~~~~~~
-error: `dbg!` macro is intended as a debugging tool
+error: the `dbg!` macro is intended as a debugging tool
--> $DIR/dbg_macro.rs:9:8
|
LL | if dbg!(n <= 1) {
| ^^^^^^^^^^^^
|
-help: ensure to avoid having uses of it in version control
+help: remove the invocation before committing it to a version control system
|
LL | if n <= 1 {
| ~~~~~~
-error: `dbg!` macro is intended as a debugging tool
+error: the `dbg!` macro is intended as a debugging tool
--> $DIR/dbg_macro.rs:10:9
|
LL | dbg!(1)
| ^^^^^^^
|
-help: ensure to avoid having uses of it in version control
+help: remove the invocation before committing it to a version control system
|
LL | 1
|
-error: `dbg!` macro is intended as a debugging tool
+error: the `dbg!` macro is intended as a debugging tool
--> $DIR/dbg_macro.rs:12:9
|
LL | dbg!(n * factorial(n - 1))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-help: ensure to avoid having uses of it in version control
+help: remove the invocation before committing it to a version control system
|
LL | n * factorial(n - 1)
|
-error: `dbg!` macro is intended as a debugging tool
+error: the `dbg!` macro is intended as a debugging tool
--> $DIR/dbg_macro.rs:17:5
|
LL | dbg!(42);
| ^^^^^^^^
|
-help: ensure to avoid having uses of it in version control
+help: remove the invocation before committing it to a version control system
|
LL | 42;
| ~~
-error: `dbg!` macro is intended as a debugging tool
+error: the `dbg!` macro is intended as a debugging tool
--> $DIR/dbg_macro.rs:18:5
|
LL | dbg!(dbg!(dbg!(42)));
| ^^^^^^^^^^^^^^^^^^^^
|
-help: ensure to avoid having uses of it in version control
+help: remove the invocation before committing it to a version control system
|
LL | dbg!(dbg!(42));
| ~~~~~~~~~~~~~~
-error: `dbg!` macro is intended as a debugging tool
+error: the `dbg!` macro is intended as a debugging tool
--> $DIR/dbg_macro.rs:19:14
|
LL | foo(3) + dbg!(factorial(4));
| ^^^^^^^^^^^^^^^^^^
|
-help: ensure to avoid having uses of it in version control
+help: remove the invocation before committing it to a version control system
|
LL | foo(3) + factorial(4);
| ~~~~~~~~~~~~
-error: `dbg!` macro is intended as a debugging tool
+error: the `dbg!` macro is intended as a debugging tool
--> $DIR/dbg_macro.rs:20:5
|
LL | dbg!(1, 2, dbg!(3, 4));
| ^^^^^^^^^^^^^^^^^^^^^^
|
-help: ensure to avoid having uses of it in version control
+help: remove the invocation before committing it to a version control system
|
LL | (1, 2, dbg!(3, 4));
| ~~~~~~~~~~~~~~~~~~
-error: `dbg!` macro is intended as a debugging tool
+error: the `dbg!` macro is intended as a debugging tool
--> $DIR/dbg_macro.rs:21:5
|
LL | dbg!(1, 2, 3, 4, 5);
| ^^^^^^^^^^^^^^^^^^^
|
-help: ensure to avoid having uses of it in version control
+help: remove the invocation before committing it to a version control system
|
LL | (1, 2, 3, 4, 5);
| ~~~~~~~~~~~~~~~
-error: `dbg!` macro is intended as a debugging tool
+error: the `dbg!` macro is intended as a debugging tool
--> $DIR/dbg_macro.rs:41:9
|
LL | dbg!(2);
| ^^^^^^^
|
-help: ensure to avoid having uses of it in version control
+help: remove the invocation before committing it to a version control system
|
LL | 2;
| ~
-error: `dbg!` macro is intended as a debugging tool
+error: the `dbg!` macro is intended as a debugging tool
--> $DIR/dbg_macro.rs:47:5
|
LL | dbg!(1);
| ^^^^^^^
|
-help: ensure to avoid having uses of it in version control
+help: remove the invocation before committing it to a version control system
|
LL | 1;
| ~
-error: `dbg!` macro is intended as a debugging tool
+error: the `dbg!` macro is intended as a debugging tool
--> $DIR/dbg_macro.rs:52:5
|
LL | dbg!(1);
| ^^^^^^^
|
-help: ensure to avoid having uses of it in version control
+help: remove the invocation before committing it to a version control system
|
LL | 1;
| ~
-error: `dbg!` macro is intended as a debugging tool
+error: the `dbg!` macro is intended as a debugging tool
--> $DIR/dbg_macro.rs:58:9
|
LL | dbg!(1);
| ^^^^^^^
|
-help: ensure to avoid having uses of it in version control
+help: remove the invocation before committing it to a version control system
|
LL | 1;
| ~
diff --git a/src/tools/clippy/tests/ui/def_id_nocore.rs b/src/tools/clippy/tests/ui/def_id_nocore.rs
index a7da8f89a..1af77d1a2 100644
--- a/src/tools/clippy/tests/ui/def_id_nocore.rs
+++ b/src/tools/clippy/tests/ui/def_id_nocore.rs
@@ -15,7 +15,7 @@ pub trait Copy {}
pub unsafe trait Freeze {}
#[lang = "start"]
-fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize {
+fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8, _sigpipe: u8) -> isize {
0
}
diff --git a/src/tools/clippy/tests/ui/default_trait_access.fixed b/src/tools/clippy/tests/ui/default_trait_access.fixed
index eedd43619..5640599d4 100644
--- a/src/tools/clippy/tests/ui/default_trait_access.fixed
+++ b/src/tools/clippy/tests/ui/default_trait_access.fixed
@@ -12,17 +12,17 @@ use std::default::Default as D2;
use std::string;
fn main() {
- let s1: String = std::string::String::default();
+ let s1: String = String::default();
let s2 = String::default();
- let s3: String = std::string::String::default();
+ let s3: String = String::default();
- let s4: String = std::string::String::default();
+ let s4: String = String::default();
let s5 = string::String::default();
- let s6: String = std::string::String::default();
+ let s6: String = String::default();
let s7 = std::string::String::default();
diff --git a/src/tools/clippy/tests/ui/default_trait_access.stderr b/src/tools/clippy/tests/ui/default_trait_access.stderr
index 49b2dde3f..e4f73c08d 100644
--- a/src/tools/clippy/tests/ui/default_trait_access.stderr
+++ b/src/tools/clippy/tests/ui/default_trait_access.stderr
@@ -1,8 +1,8 @@
-error: calling `std::string::String::default()` is more clear than this expression
+error: calling `String::default()` is more clear than this expression
--> $DIR/default_trait_access.rs:15:22
|
LL | let s1: String = Default::default();
- | ^^^^^^^^^^^^^^^^^^ help: try: `std::string::String::default()`
+ | ^^^^^^^^^^^^^^^^^^ help: try: `String::default()`
|
note: the lint level is defined here
--> $DIR/default_trait_access.rs:3:9
@@ -10,23 +10,23 @@ note: the lint level is defined here
LL | #![deny(clippy::default_trait_access)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: calling `std::string::String::default()` is more clear than this expression
+error: calling `String::default()` is more clear than this expression
--> $DIR/default_trait_access.rs:19:22
|
LL | let s3: String = D2::default();
- | ^^^^^^^^^^^^^ help: try: `std::string::String::default()`
+ | ^^^^^^^^^^^^^ help: try: `String::default()`
-error: calling `std::string::String::default()` is more clear than this expression
+error: calling `String::default()` is more clear than this expression
--> $DIR/default_trait_access.rs:21:22
|
LL | let s4: String = std::default::Default::default();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::string::String::default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `String::default()`
-error: calling `std::string::String::default()` is more clear than this expression
+error: calling `String::default()` is more clear than this expression
--> $DIR/default_trait_access.rs:25:22
|
LL | let s6: String = default::Default::default();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::string::String::default()`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `String::default()`
error: calling `GenericDerivedDefault::default()` is more clear than this expression
--> $DIR/default_trait_access.rs:35:46
diff --git a/src/tools/clippy/tests/ui/derivable_impls.fixed b/src/tools/clippy/tests/ui/derivable_impls.fixed
index 7dcdfb093..ee8456f5d 100644
--- a/src/tools/clippy/tests/ui/derivable_impls.fixed
+++ b/src/tools/clippy/tests/ui/derivable_impls.fixed
@@ -210,4 +210,25 @@ impl Default for IntOrString {
}
}
+#[derive(Default)]
+pub enum SimpleEnum {
+ Foo,
+ #[default]
+ Bar,
+}
+
+
+
+pub enum NonExhaustiveEnum {
+ Foo,
+ #[non_exhaustive]
+ Bar,
+}
+
+impl Default for NonExhaustiveEnum {
+ fn default() -> Self {
+ NonExhaustiveEnum::Bar
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/derivable_impls.rs b/src/tools/clippy/tests/ui/derivable_impls.rs
index 625cbcdde..14af419bc 100644
--- a/src/tools/clippy/tests/ui/derivable_impls.rs
+++ b/src/tools/clippy/tests/ui/derivable_impls.rs
@@ -244,4 +244,27 @@ impl Default for IntOrString {
}
}
+pub enum SimpleEnum {
+ Foo,
+ Bar,
+}
+
+impl Default for SimpleEnum {
+ fn default() -> Self {
+ SimpleEnum::Bar
+ }
+}
+
+pub enum NonExhaustiveEnum {
+ Foo,
+ #[non_exhaustive]
+ Bar,
+}
+
+impl Default for NonExhaustiveEnum {
+ fn default() -> Self {
+ NonExhaustiveEnum::Bar
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/derivable_impls.stderr b/src/tools/clippy/tests/ui/derivable_impls.stderr
index c1db5a58b..81963c3be 100644
--- a/src/tools/clippy/tests/ui/derivable_impls.stderr
+++ b/src/tools/clippy/tests/ui/derivable_impls.stderr
@@ -113,5 +113,26 @@ help: ...and instead derive it
LL | #[derive(Default)]
|
-error: aborting due to 7 previous errors
+error: this `impl` can be derived
+ --> $DIR/derivable_impls.rs:252:1
+ |
+LL | / impl Default for SimpleEnum {
+LL | | fn default() -> Self {
+LL | | SimpleEnum::Bar
+LL | | }
+LL | | }
+ | |_^
+ |
+ = help: remove the manual implementation...
+help: ...and instead derive it...
+ |
+LL | #[derive(Default)]
+ |
+help: ...and mark the default variant
+ |
+LL ~ #[default]
+LL ~ Bar,
+ |
+
+error: aborting due to 8 previous errors
diff --git a/src/tools/clippy/tests/ui/derive.rs b/src/tools/clippy/tests/ui/derive.rs
index b276c384c..6e0ce55f5 100644
--- a/src/tools/clippy/tests/ui/derive.rs
+++ b/src/tools/clippy/tests/ui/derive.rs
@@ -86,4 +86,15 @@ impl<T: Clone, U> Clone for GenericRef<'_, T, U> {
}
}
+// https://github.com/rust-lang/rust-clippy/issues/10188
+#[repr(packed)]
+#[derive(Copy)]
+struct Packed<T>(T);
+
+impl<T: Copy> Clone for Packed<T> {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/derive_hash_xor_eq.stderr b/src/tools/clippy/tests/ui/derive_hash_xor_eq.stderr
deleted file mode 100644
index 16c923978..000000000
--- a/src/tools/clippy/tests/ui/derive_hash_xor_eq.stderr
+++ /dev/null
@@ -1,59 +0,0 @@
-error: you are deriving `Hash` but have implemented `PartialEq` explicitly
- --> $DIR/derive_hash_xor_eq.rs:12:10
- |
-LL | #[derive(Hash)]
- | ^^^^
- |
-note: `PartialEq` implemented here
- --> $DIR/derive_hash_xor_eq.rs:15:1
- |
-LL | impl PartialEq for Bar {
- | ^^^^^^^^^^^^^^^^^^^^^^
- = note: `#[deny(clippy::derive_hash_xor_eq)]` on by default
- = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: you are deriving `Hash` but have implemented `PartialEq` explicitly
- --> $DIR/derive_hash_xor_eq.rs:21:10
- |
-LL | #[derive(Hash)]
- | ^^^^
- |
-note: `PartialEq` implemented here
- --> $DIR/derive_hash_xor_eq.rs:24:1
- |
-LL | impl PartialEq<Baz> for Baz {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: you are implementing `Hash` explicitly but have derived `PartialEq`
- --> $DIR/derive_hash_xor_eq.rs:33:1
- |
-LL | / impl std::hash::Hash for Bah {
-LL | | fn hash<H: std::hash::Hasher>(&self, _: &mut H) {}
-LL | | }
- | |_^
- |
-note: `PartialEq` implemented here
- --> $DIR/derive_hash_xor_eq.rs:30:10
- |
-LL | #[derive(PartialEq)]
- | ^^^^^^^^^
- = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: you are implementing `Hash` explicitly but have derived `PartialEq`
- --> $DIR/derive_hash_xor_eq.rs:51:5
- |
-LL | / impl Hash for Foo3 {
-LL | | fn hash<H: std::hash::Hasher>(&self, _: &mut H) {}
-LL | | }
- | |_____^
- |
-note: `PartialEq` implemented here
- --> $DIR/derive_hash_xor_eq.rs:48:14
- |
-LL | #[derive(PartialEq)]
- | ^^^^^^^^^
- = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: aborting due to 4 previous errors
-
diff --git a/src/tools/clippy/tests/ui/derive_hash_xor_eq.rs b/src/tools/clippy/tests/ui/derived_hash_with_manual_eq.rs
index 813ddc566..8ad09a8de 100644
--- a/src/tools/clippy/tests/ui/derive_hash_xor_eq.rs
+++ b/src/tools/clippy/tests/ui/derived_hash_with_manual_eq.rs
@@ -27,6 +27,8 @@ impl PartialEq<Baz> for Baz {
}
}
+// Implementing `Hash` with a derived `PartialEq` is fine. See #2627
+
#[derive(PartialEq)]
struct Bah;
@@ -34,23 +36,4 @@ impl std::hash::Hash for Bah {
fn hash<H: std::hash::Hasher>(&self, _: &mut H) {}
}
-#[derive(PartialEq)]
-struct Foo2;
-
-trait Hash {}
-
-// We don't want to lint on user-defined traits called `Hash`
-impl Hash for Foo2 {}
-
-mod use_hash {
- use std::hash::{Hash, Hasher};
-
- #[derive(PartialEq)]
- struct Foo3;
-
- impl Hash for Foo3 {
- fn hash<H: std::hash::Hasher>(&self, _: &mut H) {}
- }
-}
-
fn main() {}
diff --git a/src/tools/clippy/tests/ui/derived_hash_with_manual_eq.stderr b/src/tools/clippy/tests/ui/derived_hash_with_manual_eq.stderr
new file mode 100644
index 000000000..230940f25
--- /dev/null
+++ b/src/tools/clippy/tests/ui/derived_hash_with_manual_eq.stderr
@@ -0,0 +1,29 @@
+error: you are deriving `Hash` but have implemented `PartialEq` explicitly
+ --> $DIR/derived_hash_with_manual_eq.rs:12:10
+ |
+LL | #[derive(Hash)]
+ | ^^^^
+ |
+note: `PartialEq` implemented here
+ --> $DIR/derived_hash_with_manual_eq.rs:15:1
+ |
+LL | impl PartialEq for Bar {
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ = note: `#[deny(clippy::derived_hash_with_manual_eq)]` on by default
+ = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: you are deriving `Hash` but have implemented `PartialEq` explicitly
+ --> $DIR/derived_hash_with_manual_eq.rs:21:10
+ |
+LL | #[derive(Hash)]
+ | ^^^^
+ |
+note: `PartialEq` implemented here
+ --> $DIR/derived_hash_with_manual_eq.rs:24:1
+ |
+LL | impl PartialEq<Baz> for Baz {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 2 previous errors
+
diff --git a/src/tools/clippy/tests/ui/drop_ref.rs b/src/tools/clippy/tests/ui/drop_ref.rs
index 7de0b0bbd..10044e65f 100644
--- a/src/tools/clippy/tests/ui/drop_ref.rs
+++ b/src/tools/clippy/tests/ui/drop_ref.rs
@@ -72,3 +72,26 @@ fn test_owl_result_2() -> Result<u8, ()> {
produce_half_owl_ok().map(drop)?;
Ok(1)
}
+
+#[allow(unused)]
+#[allow(clippy::unit_cmp)]
+fn issue10122(x: u8) {
+ // This is a function which returns a reference and has a side-effect, which means
+ // that calling drop() on the function is considered an idiomatic way of achieving the side-effect
+ // in a match arm.
+ fn println_and<T>(t: &T) -> &T {
+ println!("foo");
+ t
+ }
+
+ match x {
+ 0 => drop(println_and(&12)), // Don't lint (copy type), we only care about side-effects
+ 1 => drop(println_and(&String::new())), // Don't lint (no copy type), we only care about side-effects
+ 2 => {
+ drop(println_and(&13)); // Lint, even if we only care about the side-effect, it's already in a block
+ },
+ 3 if drop(println_and(&14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
+ 4 => drop(&2), // Lint, not a fn/method call
+ _ => (),
+ }
+}
diff --git a/src/tools/clippy/tests/ui/drop_ref.stderr b/src/tools/clippy/tests/ui/drop_ref.stderr
index 4743cf79b..293b9f6de 100644
--- a/src/tools/clippy/tests/ui/drop_ref.stderr
+++ b/src/tools/clippy/tests/ui/drop_ref.stderr
@@ -107,5 +107,41 @@ note: argument has type `&SomeStruct`
LL | std::mem::drop(&SomeStruct);
| ^^^^^^^^^^^
-error: aborting due to 9 previous errors
+error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
+ --> $DIR/drop_ref.rs:91:13
+ |
+LL | drop(println_and(&13)); // Lint, even if we only care about the side-effect, it's already in a block
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: argument has type `&i32`
+ --> $DIR/drop_ref.rs:91:18
+ |
+LL | drop(println_and(&13)); // Lint, even if we only care about the side-effect, it's already in a block
+ | ^^^^^^^^^^^^^^^^
+
+error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
+ --> $DIR/drop_ref.rs:93:14
+ |
+LL | 3 if drop(println_and(&14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: argument has type `&i32`
+ --> $DIR/drop_ref.rs:93:19
+ |
+LL | 3 if drop(println_and(&14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
+ | ^^^^^^^^^^^^^^^^
+
+error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
+ --> $DIR/drop_ref.rs:94:14
+ |
+LL | 4 => drop(&2), // Lint, not a fn/method call
+ | ^^^^^^^^
+ |
+note: argument has type `&i32`
+ --> $DIR/drop_ref.rs:94:19
+ |
+LL | 4 => drop(&2), // Lint, not a fn/method call
+ | ^^
+
+error: aborting due to 12 previous errors
diff --git a/src/tools/clippy/tests/ui/explicit_counter_loop.rs b/src/tools/clippy/tests/ui/explicit_counter_loop.rs
index 6eddc01e2..46565a97f 100644
--- a/src/tools/clippy/tests/ui/explicit_counter_loop.rs
+++ b/src/tools/clippy/tests/ui/explicit_counter_loop.rs
@@ -189,3 +189,33 @@ mod issue_7920 {
}
}
}
+
+mod issue_10058 {
+ pub fn test() {
+ // should not lint since we are increasing counter potentially more than once in the loop
+ let values = [0, 1, 0, 1, 1, 1, 0, 1, 0, 1];
+ let mut counter = 0;
+ for value in values {
+ counter += 1;
+
+ if value == 0 {
+ continue;
+ }
+
+ counter += 1;
+ }
+ }
+
+ pub fn test2() {
+ // should not lint since we are increasing counter potentially more than once in the loop
+ let values = [0, 1, 0, 1, 1, 1, 0, 1, 0, 1];
+ let mut counter = 0;
+ for value in values {
+ counter += 1;
+
+ if value != 0 {
+ counter += 1;
+ }
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/field_reassign_with_default.rs b/src/tools/clippy/tests/ui/field_reassign_with_default.rs
index 7367910ea..1f989bb12 100644
--- a/src/tools/clippy/tests/ui/field_reassign_with_default.rs
+++ b/src/tools/clippy/tests/ui/field_reassign_with_default.rs
@@ -247,3 +247,24 @@ mod issue6312 {
}
}
}
+
+struct Collection {
+ items: Vec<i32>,
+ len: usize,
+}
+
+impl Default for Collection {
+ fn default() -> Self {
+ Self {
+ items: vec![1, 2, 3],
+ len: 0,
+ }
+ }
+}
+
+#[allow(clippy::redundant_closure_call)]
+fn issue10136() {
+ let mut c = Collection::default();
+ // don't lint, since c.items was used to calculate this value
+ c.len = (|| c.items.len())();
+}
diff --git a/src/tools/clippy/tests/ui/floating_point_powi.fixed b/src/tools/clippy/tests/ui/floating_point_powi.fixed
index 884d05fed..8ffd4cc51 100644
--- a/src/tools/clippy/tests/ui/floating_point_powi.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_powi.fixed
@@ -14,6 +14,15 @@ fn main() {
let _ = (y as f32).mul_add(y as f32, x);
let _ = x.mul_add(x, y).sqrt();
let _ = y.mul_add(y, x).sqrt();
+
+ let _ = (x - 1.0).mul_add(x - 1.0, -y);
+ let _ = (x - 1.0).mul_add(x - 1.0, -y) + 3.0;
+ let _ = (x - 1.0).mul_add(x - 1.0, -(y + 3.0));
+ let _ = (y + 1.0).mul_add(-(y + 1.0), x);
+ let _ = (3.0 * y).mul_add(-(3.0 * y), x);
+ let _ = (y + 1.0 + x).mul_add(-(y + 1.0 + x), x);
+ let _ = (y + 1.0 + 2.0).mul_add(-(y + 1.0 + 2.0), x);
+
// Cases where the lint shouldn't be applied
let _ = x.powi(2);
let _ = x.powi(1 + 1);
diff --git a/src/tools/clippy/tests/ui/floating_point_powi.rs b/src/tools/clippy/tests/ui/floating_point_powi.rs
index e6a1c8953..9ae3455a1 100644
--- a/src/tools/clippy/tests/ui/floating_point_powi.rs
+++ b/src/tools/clippy/tests/ui/floating_point_powi.rs
@@ -14,6 +14,15 @@ fn main() {
let _ = x + (y as f32).powi(2);
let _ = (x.powi(2) + y).sqrt();
let _ = (x + y.powi(2)).sqrt();
+
+ let _ = (x - 1.0).powi(2) - y;
+ let _ = (x - 1.0).powi(2) - y + 3.0;
+ let _ = (x - 1.0).powi(2) - (y + 3.0);
+ let _ = x - (y + 1.0).powi(2);
+ let _ = x - (3.0 * y).powi(2);
+ let _ = x - (y + 1.0 + x).powi(2);
+ let _ = x - (y + 1.0 + 2.0).powi(2);
+
// Cases where the lint shouldn't be applied
let _ = x.powi(2);
let _ = x.powi(1 + 1);
diff --git a/src/tools/clippy/tests/ui/floating_point_powi.stderr b/src/tools/clippy/tests/ui/floating_point_powi.stderr
index 5df0de1fe..fdf6d0880 100644
--- a/src/tools/clippy/tests/ui/floating_point_powi.stderr
+++ b/src/tools/clippy/tests/ui/floating_point_powi.stderr
@@ -42,5 +42,47 @@ error: multiply and add expressions can be calculated more efficiently and accur
LL | let _ = (x + y.powi(2)).sqrt();
| ^^^^^^^^^^^^^^^ help: consider using: `y.mul_add(y, x)`
-error: aborting due to 7 previous errors
+error: multiply and add expressions can be calculated more efficiently and accurately
+ --> $DIR/floating_point_powi.rs:18:13
+ |
+LL | let _ = (x - 1.0).powi(2) - y;
+ | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x - 1.0).mul_add(x - 1.0, -y)`
+
+error: multiply and add expressions can be calculated more efficiently and accurately
+ --> $DIR/floating_point_powi.rs:19:13
+ |
+LL | let _ = (x - 1.0).powi(2) - y + 3.0;
+ | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x - 1.0).mul_add(x - 1.0, -y)`
+
+error: multiply and add expressions can be calculated more efficiently and accurately
+ --> $DIR/floating_point_powi.rs:20:13
+ |
+LL | let _ = (x - 1.0).powi(2) - (y + 3.0);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x - 1.0).mul_add(x - 1.0, -(y + 3.0))`
+
+error: multiply and add expressions can be calculated more efficiently and accurately
+ --> $DIR/floating_point_powi.rs:21:13
+ |
+LL | let _ = x - (y + 1.0).powi(2);
+ | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(y + 1.0).mul_add(-(y + 1.0), x)`
+
+error: multiply and add expressions can be calculated more efficiently and accurately
+ --> $DIR/floating_point_powi.rs:22:13
+ |
+LL | let _ = x - (3.0 * y).powi(2);
+ | ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(3.0 * y).mul_add(-(3.0 * y), x)`
+
+error: multiply and add expressions can be calculated more efficiently and accurately
+ --> $DIR/floating_point_powi.rs:23:13
+ |
+LL | let _ = x - (y + 1.0 + x).powi(2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(y + 1.0 + x).mul_add(-(y + 1.0 + x), x)`
+
+error: multiply and add expressions can be calculated more efficiently and accurately
+ --> $DIR/floating_point_powi.rs:24:13
+ |
+LL | let _ = x - (y + 1.0 + 2.0).powi(2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(y + 1.0 + 2.0).mul_add(-(y + 1.0 + 2.0), x)`
+
+error: aborting due to 14 previous errors
diff --git a/src/tools/clippy/tests/ui/fn_null_check.rs b/src/tools/clippy/tests/ui/fn_null_check.rs
new file mode 100644
index 000000000..df5bc8420
--- /dev/null
+++ b/src/tools/clippy/tests/ui/fn_null_check.rs
@@ -0,0 +1,21 @@
+#![allow(unused)]
+#![warn(clippy::fn_null_check)]
+#![allow(clippy::cmp_null)]
+#![allow(clippy::ptr_eq)]
+#![allow(clippy::zero_ptr)]
+
+pub const ZPTR: *const () = 0 as *const _;
+pub const NOT_ZPTR: *const () = 1 as *const _;
+
+fn main() {
+ let fn_ptr = main;
+
+ if (fn_ptr as *mut ()).is_null() {}
+ if (fn_ptr as *const u8).is_null() {}
+ if (fn_ptr as *const ()) == std::ptr::null() {}
+ if (fn_ptr as *const ()) == (0 as *const ()) {}
+ if (fn_ptr as *const ()) == ZPTR {}
+
+ // no lint
+ if (fn_ptr as *const ()) == NOT_ZPTR {}
+}
diff --git a/src/tools/clippy/tests/ui/fn_null_check.stderr b/src/tools/clippy/tests/ui/fn_null_check.stderr
new file mode 100644
index 000000000..660dd3239
--- /dev/null
+++ b/src/tools/clippy/tests/ui/fn_null_check.stderr
@@ -0,0 +1,43 @@
+error: function pointer assumed to be nullable, even though it isn't
+ --> $DIR/fn_null_check.rs:13:8
+ |
+LL | if (fn_ptr as *mut ()).is_null() {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: try wrapping your function pointer type in `Option<T>` instead, and using `is_none` to check for null pointer value
+ = note: `-D clippy::fn-null-check` implied by `-D warnings`
+
+error: function pointer assumed to be nullable, even though it isn't
+ --> $DIR/fn_null_check.rs:14:8
+ |
+LL | if (fn_ptr as *const u8).is_null() {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: try wrapping your function pointer type in `Option<T>` instead, and using `is_none` to check for null pointer value
+
+error: function pointer assumed to be nullable, even though it isn't
+ --> $DIR/fn_null_check.rs:15:8
+ |
+LL | if (fn_ptr as *const ()) == std::ptr::null() {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: try wrapping your function pointer type in `Option<T>` instead, and using `is_none` to check for null pointer value
+
+error: function pointer assumed to be nullable, even though it isn't
+ --> $DIR/fn_null_check.rs:16:8
+ |
+LL | if (fn_ptr as *const ()) == (0 as *const ()) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: try wrapping your function pointer type in `Option<T>` instead, and using `is_none` to check for null pointer value
+
+error: function pointer assumed to be nullable, even though it isn't
+ --> $DIR/fn_null_check.rs:17:8
+ |
+LL | if (fn_ptr as *const ()) == ZPTR {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: try wrapping your function pointer type in `Option<T>` instead, and using `is_none` to check for null pointer value
+
+error: aborting due to 5 previous errors
+
diff --git a/src/tools/clippy/tests/ui/from_over_into.fixed b/src/tools/clippy/tests/ui/from_over_into.fixed
index 125c9a69c..72d635c2c 100644
--- a/src/tools/clippy/tests/ui/from_over_into.fixed
+++ b/src/tools/clippy/tests/ui/from_over_into.fixed
@@ -1,5 +1,6 @@
// run-rustfix
+#![feature(type_alias_impl_trait)]
#![warn(clippy::from_over_into)]
#![allow(unused)]
@@ -81,4 +82,10 @@ fn msrv_1_41() {
}
}
+type Opaque = impl Sized;
+struct IntoOpaque;
+impl Into<Opaque> for IntoOpaque {
+ fn into(self) -> Opaque {}
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/from_over_into.rs b/src/tools/clippy/tests/ui/from_over_into.rs
index 5aa127bfa..965f4d5d7 100644
--- a/src/tools/clippy/tests/ui/from_over_into.rs
+++ b/src/tools/clippy/tests/ui/from_over_into.rs
@@ -1,5 +1,6 @@
// run-rustfix
+#![feature(type_alias_impl_trait)]
#![warn(clippy::from_over_into)]
#![allow(unused)]
@@ -81,4 +82,10 @@ fn msrv_1_41() {
}
}
+type Opaque = impl Sized;
+struct IntoOpaque;
+impl Into<Opaque> for IntoOpaque {
+ fn into(self) -> Opaque {}
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/from_over_into.stderr b/src/tools/clippy/tests/ui/from_over_into.stderr
index a1764a5ea..3c4d011d6 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:9:1
+ --> $DIR/from_over_into.rs:10: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:17:1
+ --> $DIR/from_over_into.rs:18: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:32:1
+ --> $DIR/from_over_into.rs:33: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:44:1
+ --> $DIR/from_over_into.rs:45: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:77:5
+ --> $DIR/from_over_into.rs:78:5
|
LL | impl<T> Into<FromOverInto<T>> for Vec<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/identity_op.fixed b/src/tools/clippy/tests/ui/identity_op.fixed
index e7b9a78c5..cac69ef42 100644
--- a/src/tools/clippy/tests/ui/identity_op.fixed
+++ b/src/tools/clippy/tests/ui/identity_op.fixed
@@ -65,7 +65,7 @@ fn main() {
42;
1;
42;
- &x;
+ x;
x;
let mut a = A(String::new());
@@ -112,6 +112,10 @@ fn main() {
2 * { a };
(({ a } + 4));
1;
+
+ // Issue #9904
+ let x = 0i32;
+ let _: i32 = x;
}
pub fn decide(a: bool, b: bool) -> u32 {
diff --git a/src/tools/clippy/tests/ui/identity_op.rs b/src/tools/clippy/tests/ui/identity_op.rs
index 9a435cdbb..33201aad4 100644
--- a/src/tools/clippy/tests/ui/identity_op.rs
+++ b/src/tools/clippy/tests/ui/identity_op.rs
@@ -112,6 +112,10 @@ fn main() {
2 * (0 + { a });
1 * ({ a } + 4);
1 * 1;
+
+ // Issue #9904
+ let x = 0i32;
+ let _: i32 = &x + 0;
}
pub fn decide(a: bool, b: bool) -> u32 {
diff --git a/src/tools/clippy/tests/ui/identity_op.stderr b/src/tools/clippy/tests/ui/identity_op.stderr
index 1a104a20b..3ba557d18 100644
--- a/src/tools/clippy/tests/ui/identity_op.stderr
+++ b/src/tools/clippy/tests/ui/identity_op.stderr
@@ -70,7 +70,7 @@ error: this operation has no effect
--> $DIR/identity_op.rs:68:5
|
LL | &x >> 0;
- | ^^^^^^^ help: consider reducing it to: `&x`
+ | ^^^^^^^ help: consider reducing it to: `x`
error: this operation has no effect
--> $DIR/identity_op.rs:69:5
@@ -229,10 +229,16 @@ LL | 1 * 1;
| ^^^^^ help: consider reducing it to: `1`
error: this operation has no effect
- --> $DIR/identity_op.rs:118:5
+ --> $DIR/identity_op.rs:118:18
+ |
+LL | let _: i32 = &x + 0;
+ | ^^^^^^ help: consider reducing it to: `x`
+
+error: this operation has no effect
+ --> $DIR/identity_op.rs:122:5
|
LL | 0 + if a { 1 } else { 2 } + if b { 3 } else { 5 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider reducing it to: `(if a { 1 } else { 2 })`
-error: aborting due to 39 previous errors
+error: aborting due to 40 previous errors
diff --git a/src/tools/clippy/tests/ui/implicit_clone.fixed b/src/tools/clippy/tests/ui/implicit_clone.fixed
index 33770fc2a..51b1afbe5 100644
--- a/src/tools/clippy/tests/ui/implicit_clone.fixed
+++ b/src/tools/clippy/tests/ui/implicit_clone.fixed
@@ -115,4 +115,14 @@ fn main() {
let pathbuf_ref = &pathbuf_ref;
let _ = pathbuf_ref.to_owned(); // Don't lint. Returns `&&PathBuf`
let _ = (**pathbuf_ref).clone();
+
+ struct NoClone;
+ impl ToOwned for NoClone {
+ type Owned = Self;
+ fn to_owned(&self) -> Self {
+ NoClone
+ }
+ }
+ let no_clone = &NoClone;
+ let _ = no_clone.to_owned();
}
diff --git a/src/tools/clippy/tests/ui/implicit_clone.rs b/src/tools/clippy/tests/ui/implicit_clone.rs
index fc896525b..8a9027433 100644
--- a/src/tools/clippy/tests/ui/implicit_clone.rs
+++ b/src/tools/clippy/tests/ui/implicit_clone.rs
@@ -115,4 +115,14 @@ fn main() {
let pathbuf_ref = &pathbuf_ref;
let _ = pathbuf_ref.to_owned(); // Don't lint. Returns `&&PathBuf`
let _ = pathbuf_ref.to_path_buf();
+
+ struct NoClone;
+ impl ToOwned for NoClone {
+ type Owned = Self;
+ fn to_owned(&self) -> Self {
+ NoClone
+ }
+ }
+ let no_clone = &NoClone;
+ let _ = no_clone.to_owned();
}
diff --git a/src/tools/clippy/tests/ui/indexing_slicing_index.rs b/src/tools/clippy/tests/ui/indexing_slicing_index.rs
index 4476e0eb9..26abc9edb 100644
--- a/src/tools/clippy/tests/ui/indexing_slicing_index.rs
+++ b/src/tools/clippy/tests/ui/indexing_slicing_index.rs
@@ -6,7 +6,7 @@
#![allow(unconditional_panic, clippy::no_effect, clippy::unnecessary_operation)]
const ARR: [i32; 2] = [1, 2];
-const REF: &i32 = &ARR[idx()]; // Ok, should not produce stderr.
+const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
const fn idx() -> usize {
@@ -27,8 +27,8 @@ fn main() {
x[3]; // Ok, should not produce stderr.
x[const { idx() }]; // Ok, should not produce stderr.
x[const { idx4() }]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays.
- const { &ARR[idx()] }; // Ok, should not produce stderr.
- const { &ARR[idx4()] }; // Ok, let rustc handle const contexts.
+ const { &ARR[idx()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
+ const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
let y = &x;
y[0]; // Ok, referencing shouldn't affect this lint. See the issue 6021
diff --git a/src/tools/clippy/tests/ui/indexing_slicing_index.stderr b/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
index d8b6e3f12..8fd77913a 100644
--- a/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
+++ b/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
@@ -1,13 +1,32 @@
+error: indexing may panic
+ --> $DIR/indexing_slicing_index.rs:9:20
+ |
+LL | const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
+ | ^^^^^^^^^^
+ |
+ = help: consider using `.get(n)` or `.get_mut(n)` instead
+ = note: the suggestion might not be applicable in constant blocks
+ = note: `-D clippy::indexing-slicing` implied by `-D warnings`
+
+error: indexing may panic
+ --> $DIR/indexing_slicing_index.rs:10:24
+ |
+LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
+ | ^^^^^^^^^^^
+ |
+ = help: consider using `.get(n)` or `.get_mut(n)` instead
+ = note: the suggestion might not be applicable in constant blocks
+
error[E0080]: evaluation of `main::{constant#3}` failed
--> $DIR/indexing_slicing_index.rs:31:14
|
-LL | const { &ARR[idx4()] }; // Ok, let rustc handle const contexts.
+LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
| ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
note: erroneous constant used
--> $DIR/indexing_slicing_index.rs:31:5
|
-LL | const { &ARR[idx4()] }; // Ok, let rustc handle const contexts.
+LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
| ^^^^^^^^^^^^^^^^^^^^^^
error: indexing may panic
@@ -17,7 +36,24 @@ LL | x[index];
| ^^^^^^^^
|
= help: consider using `.get(n)` or `.get_mut(n)` instead
- = note: `-D clippy::indexing-slicing` implied by `-D warnings`
+
+error: indexing may panic
+ --> $DIR/indexing_slicing_index.rs:30:14
+ |
+LL | const { &ARR[idx()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
+ | ^^^^^^^^^^
+ |
+ = help: consider using `.get(n)` or `.get_mut(n)` instead
+ = note: the suggestion might not be applicable in constant blocks
+
+error: indexing may panic
+ --> $DIR/indexing_slicing_index.rs:31:14
+ |
+LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
+ | ^^^^^^^^^^^
+ |
+ = help: consider using `.get(n)` or `.get_mut(n)` instead
+ = note: the suggestion might not be applicable in constant blocks
error: indexing may panic
--> $DIR/indexing_slicing_index.rs:38:5
@@ -65,6 +101,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 8 previous errors
+error: aborting due to 12 previous errors
For more information about this error, try `rustc --explain E0080`.
diff --git a/src/tools/clippy/tests/ui/iter_kv_map.fixed b/src/tools/clippy/tests/ui/iter_kv_map.fixed
index 83fee0408..f2a4c284c 100644
--- a/src/tools/clippy/tests/ui/iter_kv_map.fixed
+++ b/src/tools/clippy/tests/ui/iter_kv_map.fixed
@@ -1,14 +1,15 @@
// run-rustfix
#![warn(clippy::iter_kv_map)]
-#![allow(clippy::redundant_clone)]
-#![allow(clippy::suspicious_map)]
-#![allow(clippy::map_identity)]
+#![allow(unused_mut, clippy::redundant_clone, clippy::suspicious_map, clippy::map_identity)]
use std::collections::{BTreeMap, HashMap};
fn main() {
let get_key = |(key, _val)| key;
+ fn ref_acceptor(v: &u32) -> u32 {
+ *v
+ }
let map: HashMap<u32, u32> = HashMap::new();
@@ -36,6 +37,20 @@ fn main() {
let _ = map.keys().map(|key| key * 9).count();
let _ = map.values().map(|value| value * 17).count();
+ // Preserve the ref in the fix.
+ let _ = map.clone().into_values().map(|ref val| ref_acceptor(val)).count();
+
+ // Preserve the mut in the fix.
+ let _ = map
+ .clone().into_values().map(|mut val| {
+ val += 2;
+ val
+ })
+ .count();
+
+ // Don't let a mut interfere.
+ let _ = map.clone().into_values().count();
+
let map: BTreeMap<u32, u32> = BTreeMap::new();
let _ = map.keys().collect::<Vec<_>>();
@@ -61,4 +76,18 @@ fn main() {
// Lint
let _ = map.keys().map(|key| key * 9).count();
let _ = map.values().map(|value| value * 17).count();
+
+ // Preserve the ref in the fix.
+ let _ = map.clone().into_values().map(|ref val| ref_acceptor(val)).count();
+
+ // Preserve the mut in the fix.
+ let _ = map
+ .clone().into_values().map(|mut val| {
+ val += 2;
+ val
+ })
+ .count();
+
+ // Don't let a mut interfere.
+ let _ = map.clone().into_values().count();
}
diff --git a/src/tools/clippy/tests/ui/iter_kv_map.rs b/src/tools/clippy/tests/ui/iter_kv_map.rs
index 7a1f1fb01..ad6564df4 100644
--- a/src/tools/clippy/tests/ui/iter_kv_map.rs
+++ b/src/tools/clippy/tests/ui/iter_kv_map.rs
@@ -1,14 +1,15 @@
// run-rustfix
#![warn(clippy::iter_kv_map)]
-#![allow(clippy::redundant_clone)]
-#![allow(clippy::suspicious_map)]
-#![allow(clippy::map_identity)]
+#![allow(unused_mut, clippy::redundant_clone, clippy::suspicious_map, clippy::map_identity)]
use std::collections::{BTreeMap, HashMap};
fn main() {
let get_key = |(key, _val)| key;
+ fn ref_acceptor(v: &u32) -> u32 {
+ *v
+ }
let map: HashMap<u32, u32> = HashMap::new();
@@ -36,6 +37,22 @@ fn main() {
let _ = map.iter().map(|(key, _value)| key * 9).count();
let _ = map.iter().map(|(_key, value)| value * 17).count();
+ // Preserve the ref in the fix.
+ let _ = map.clone().into_iter().map(|(_, ref val)| ref_acceptor(val)).count();
+
+ // Preserve the mut in the fix.
+ let _ = map
+ .clone()
+ .into_iter()
+ .map(|(_, mut val)| {
+ val += 2;
+ val
+ })
+ .count();
+
+ // Don't let a mut interfere.
+ let _ = map.clone().into_iter().map(|(_, mut val)| val).count();
+
let map: BTreeMap<u32, u32> = BTreeMap::new();
let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
@@ -61,4 +78,20 @@ fn main() {
// Lint
let _ = map.iter().map(|(key, _value)| key * 9).count();
let _ = map.iter().map(|(_key, value)| value * 17).count();
+
+ // Preserve the ref in the fix.
+ let _ = map.clone().into_iter().map(|(_, ref val)| ref_acceptor(val)).count();
+
+ // Preserve the mut in the fix.
+ let _ = map
+ .clone()
+ .into_iter()
+ .map(|(_, mut val)| {
+ val += 2;
+ val
+ })
+ .count();
+
+ // Don't let a mut interfere.
+ let _ = map.clone().into_iter().map(|(_, mut val)| val).count();
}
diff --git a/src/tools/clippy/tests/ui/iter_kv_map.stderr b/src/tools/clippy/tests/ui/iter_kv_map.stderr
index 9b9b04c97..e00da223b 100644
--- a/src/tools/clippy/tests/ui/iter_kv_map.stderr
+++ b/src/tools/clippy/tests/ui/iter_kv_map.stderr
@@ -1,5 +1,5 @@
error: iterating on a map's keys
- --> $DIR/iter_kv_map.rs:15:13
+ --> $DIR/iter_kv_map.rs:16:13
|
LL | let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
@@ -7,130 +7,198 @@ LL | let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
= note: `-D clippy::iter-kv-map` implied by `-D warnings`
error: iterating on a map's values
- --> $DIR/iter_kv_map.rs:16:13
+ --> $DIR/iter_kv_map.rs:17:13
|
LL | let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()`
error: iterating on a map's values
- --> $DIR/iter_kv_map.rs:17:13
+ --> $DIR/iter_kv_map.rs:18:13
|
LL | let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)`
error: iterating on a map's keys
- --> $DIR/iter_kv_map.rs:19:13
+ --> $DIR/iter_kv_map.rs:20:13
|
LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()`
error: iterating on a map's keys
- --> $DIR/iter_kv_map.rs:20:13
+ --> $DIR/iter_kv_map.rs:21:13
|
LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)`
error: iterating on a map's values
- --> $DIR/iter_kv_map.rs:22:13
+ --> $DIR/iter_kv_map.rs:23:13
|
LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()`
error: iterating on a map's values
- --> $DIR/iter_kv_map.rs:23:13
+ --> $DIR/iter_kv_map.rs:24:13
|
LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)`
error: iterating on a map's values
- --> $DIR/iter_kv_map.rs:25:13
+ --> $DIR/iter_kv_map.rs:26:13
|
LL | let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()`
error: iterating on a map's keys
- --> $DIR/iter_kv_map.rs:26:13
+ --> $DIR/iter_kv_map.rs:27:13
|
LL | let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
error: iterating on a map's keys
- --> $DIR/iter_kv_map.rs:36:13
+ --> $DIR/iter_kv_map.rs:37:13
|
LL | let _ = map.iter().map(|(key, _value)| key * 9).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)`
error: iterating on a map's values
- --> $DIR/iter_kv_map.rs:37:13
+ --> $DIR/iter_kv_map.rs:38:13
|
LL | let _ = map.iter().map(|(_key, value)| value * 17).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)`
-error: iterating on a map's keys
+error: iterating on a map's values
--> $DIR/iter_kv_map.rs:41:13
|
+LL | let _ = map.clone().into_iter().map(|(_, ref val)| ref_acceptor(val)).count();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|ref val| ref_acceptor(val))`
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:44:13
+ |
+LL | let _ = map
+ | _____________^
+LL | | .clone()
+LL | | .into_iter()
+LL | | .map(|(_, mut val)| {
+LL | | val += 2;
+LL | | val
+LL | | })
+ | |__________^
+ |
+help: try
+ |
+LL ~ let _ = map
+LL + .clone().into_values().map(|mut val| {
+LL + val += 2;
+LL + val
+LL + })
+ |
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:54:13
+ |
+LL | let _ = map.clone().into_iter().map(|(_, mut val)| val).count();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()`
+
+error: iterating on a map's keys
+ --> $DIR/iter_kv_map.rs:58:13
+ |
LL | let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
error: iterating on a map's values
- --> $DIR/iter_kv_map.rs:42:13
+ --> $DIR/iter_kv_map.rs:59:13
|
LL | let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()`
error: iterating on a map's values
- --> $DIR/iter_kv_map.rs:43:13
+ --> $DIR/iter_kv_map.rs:60:13
|
LL | let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)`
error: iterating on a map's keys
- --> $DIR/iter_kv_map.rs:45:13
+ --> $DIR/iter_kv_map.rs:62:13
|
LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()`
error: iterating on a map's keys
- --> $DIR/iter_kv_map.rs:46:13
+ --> $DIR/iter_kv_map.rs:63:13
|
LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)`
error: iterating on a map's values
- --> $DIR/iter_kv_map.rs:48:13
+ --> $DIR/iter_kv_map.rs:65:13
|
LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()`
error: iterating on a map's values
- --> $DIR/iter_kv_map.rs:49:13
+ --> $DIR/iter_kv_map.rs:66:13
|
LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)`
error: iterating on a map's values
- --> $DIR/iter_kv_map.rs:51:13
+ --> $DIR/iter_kv_map.rs:68:13
|
LL | let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()`
error: iterating on a map's keys
- --> $DIR/iter_kv_map.rs:52:13
+ --> $DIR/iter_kv_map.rs:69:13
|
LL | let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
error: iterating on a map's keys
- --> $DIR/iter_kv_map.rs:62:13
+ --> $DIR/iter_kv_map.rs:79:13
|
LL | let _ = map.iter().map(|(key, _value)| key * 9).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)`
error: iterating on a map's values
- --> $DIR/iter_kv_map.rs:63:13
+ --> $DIR/iter_kv_map.rs:80:13
|
LL | let _ = map.iter().map(|(_key, value)| value * 17).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)`
-error: aborting due to 22 previous errors
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:83:13
+ |
+LL | let _ = map.clone().into_iter().map(|(_, ref val)| ref_acceptor(val)).count();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|ref val| ref_acceptor(val))`
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:86:13
+ |
+LL | let _ = map
+ | _____________^
+LL | | .clone()
+LL | | .into_iter()
+LL | | .map(|(_, mut val)| {
+LL | | val += 2;
+LL | | val
+LL | | })
+ | |__________^
+ |
+help: try
+ |
+LL ~ let _ = map
+LL + .clone().into_values().map(|mut val| {
+LL + val += 2;
+LL + val
+LL + })
+ |
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:96:13
+ |
+LL | let _ = map.clone().into_iter().map(|(_, mut val)| val).count();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()`
+
+error: aborting due to 28 previous errors
diff --git a/src/tools/clippy/tests/ui/large_stack_arrays.rs b/src/tools/clippy/tests/ui/large_stack_arrays.rs
index 6790765f8..99787ffd3 100644
--- a/src/tools/clippy/tests/ui/large_stack_arrays.rs
+++ b/src/tools/clippy/tests/ui/large_stack_arrays.rs
@@ -24,6 +24,7 @@ fn main() {
[S { data: [0; 32] }; 5000],
[Some(""); 20_000_000],
[E::T(0); 5000],
+ [0u8; usize::MAX],
);
let good = (
diff --git a/src/tools/clippy/tests/ui/large_stack_arrays.stderr b/src/tools/clippy/tests/ui/large_stack_arrays.stderr
index c7bf941ad..24e900949 100644
--- a/src/tools/clippy/tests/ui/large_stack_arrays.stderr
+++ b/src/tools/clippy/tests/ui/large_stack_arrays.stderr
@@ -31,5 +31,13 @@ LL | [E::T(0); 5000],
|
= help: consider allocating on the heap with `vec![E::T(0); 5000].into_boxed_slice()`
-error: aborting due to 4 previous errors
+error: allocating a local array larger than 512000 bytes
+ --> $DIR/large_stack_arrays.rs:27:9
+ |
+LL | [0u8; usize::MAX],
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = help: consider allocating on the heap with `vec![0u8; usize::MAX].into_boxed_slice()`
+
+error: aborting due to 5 previous errors
diff --git a/src/tools/clippy/tests/ui/len_zero.fixed b/src/tools/clippy/tests/ui/len_zero.fixed
index 1f3b8ac99..c1c0b5ae4 100644
--- a/src/tools/clippy/tests/ui/len_zero.fixed
+++ b/src/tools/clippy/tests/ui/len_zero.fixed
@@ -3,6 +3,9 @@
#![warn(clippy::len_zero)]
#![allow(dead_code, unused, clippy::len_without_is_empty)]
+extern crate core;
+use core::ops::Deref;
+
pub struct One;
struct Wither;
@@ -56,6 +59,26 @@ impl WithIsEmpty for Wither {
}
}
+struct DerefToDerefToString;
+
+impl Deref for DerefToDerefToString {
+ type Target = DerefToString;
+
+ fn deref(&self) -> &Self::Target {
+ &DerefToString {}
+ }
+}
+
+struct DerefToString;
+
+impl Deref for DerefToString {
+ type Target = str;
+
+ fn deref(&self) -> &Self::Target {
+ "Hello, world!"
+ }
+}
+
fn main() {
let x = [1, 2];
if x.is_empty() {
@@ -64,6 +87,23 @@ fn main() {
if "".is_empty() {}
+ let s = "Hello, world!";
+ let s1 = &s;
+ let s2 = &s1;
+ let s3 = &s2;
+ let s4 = &s3;
+ let s5 = &s4;
+ let s6 = &s5;
+ println!("{}", s1.is_empty());
+ println!("{}", s2.is_empty());
+ println!("{}", s3.is_empty());
+ println!("{}", s4.is_empty());
+ println!("{}", s5.is_empty());
+ println!("{}", (s6).is_empty());
+
+ let d2s = DerefToDerefToString {};
+ println!("{}", (**d2s).is_empty());
+
let y = One;
if y.len() == 0 {
// No error; `One` does not have `.is_empty()`.
diff --git a/src/tools/clippy/tests/ui/len_zero.rs b/src/tools/clippy/tests/ui/len_zero.rs
index dc21de000..cc2eb05b6 100644
--- a/src/tools/clippy/tests/ui/len_zero.rs
+++ b/src/tools/clippy/tests/ui/len_zero.rs
@@ -3,6 +3,9 @@
#![warn(clippy::len_zero)]
#![allow(dead_code, unused, clippy::len_without_is_empty)]
+extern crate core;
+use core::ops::Deref;
+
pub struct One;
struct Wither;
@@ -56,6 +59,26 @@ impl WithIsEmpty for Wither {
}
}
+struct DerefToDerefToString;
+
+impl Deref for DerefToDerefToString {
+ type Target = DerefToString;
+
+ fn deref(&self) -> &Self::Target {
+ &DerefToString {}
+ }
+}
+
+struct DerefToString;
+
+impl Deref for DerefToString {
+ type Target = str;
+
+ fn deref(&self) -> &Self::Target {
+ "Hello, world!"
+ }
+}
+
fn main() {
let x = [1, 2];
if x.len() == 0 {
@@ -64,6 +87,23 @@ fn main() {
if "".len() == 0 {}
+ let s = "Hello, world!";
+ let s1 = &s;
+ let s2 = &s1;
+ let s3 = &s2;
+ let s4 = &s3;
+ let s5 = &s4;
+ let s6 = &s5;
+ println!("{}", *s1 == "");
+ println!("{}", **s2 == "");
+ println!("{}", ***s3 == "");
+ println!("{}", ****s4 == "");
+ println!("{}", *****s5 == "");
+ println!("{}", ******(s6) == "");
+
+ let d2s = DerefToDerefToString {};
+ println!("{}", &**d2s == "");
+
let y = One;
if y.len() == 0 {
// No error; `One` does not have `.is_empty()`.
diff --git a/src/tools/clippy/tests/ui/len_zero.stderr b/src/tools/clippy/tests/ui/len_zero.stderr
index 6c71f1bee..b6f137802 100644
--- a/src/tools/clippy/tests/ui/len_zero.stderr
+++ b/src/tools/clippy/tests/ui/len_zero.stderr
@@ -1,5 +1,5 @@
error: length comparison to zero
- --> $DIR/len_zero.rs:61:8
+ --> $DIR/len_zero.rs:84:8
|
LL | if x.len() == 0 {
| ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `x.is_empty()`
@@ -7,82 +7,126 @@ LL | if x.len() == 0 {
= note: `-D clippy::len-zero` implied by `-D warnings`
error: length comparison to zero
- --> $DIR/len_zero.rs:65:8
+ --> $DIR/len_zero.rs:88:8
|
LL | if "".len() == 0 {}
| ^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `"".is_empty()`
+error: comparison to empty slice
+ --> $DIR/len_zero.rs:97:20
+ |
+LL | println!("{}", *s1 == "");
+ | ^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s1.is_empty()`
+ |
+ = note: `-D clippy::comparison-to-empty` implied by `-D warnings`
+
+error: comparison to empty slice
+ --> $DIR/len_zero.rs:98:20
+ |
+LL | println!("{}", **s2 == "");
+ | ^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s2.is_empty()`
+
+error: comparison to empty slice
+ --> $DIR/len_zero.rs:99:20
+ |
+LL | println!("{}", ***s3 == "");
+ | ^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s3.is_empty()`
+
+error: comparison to empty slice
+ --> $DIR/len_zero.rs:100:20
+ |
+LL | println!("{}", ****s4 == "");
+ | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s4.is_empty()`
+
+error: comparison to empty slice
+ --> $DIR/len_zero.rs:101:20
+ |
+LL | println!("{}", *****s5 == "");
+ | ^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `s5.is_empty()`
+
+error: comparison to empty slice
+ --> $DIR/len_zero.rs:102:20
+ |
+LL | println!("{}", ******(s6) == "");
+ | ^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(s6).is_empty()`
+
+error: comparison to empty slice
+ --> $DIR/len_zero.rs:105:20
+ |
+LL | println!("{}", &**d2s == "");
+ | ^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(**d2s).is_empty()`
+
error: length comparison to zero
- --> $DIR/len_zero.rs:80:8
+ --> $DIR/len_zero.rs:120:8
|
LL | if has_is_empty.len() == 0 {
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()`
error: length comparison to zero
- --> $DIR/len_zero.rs:83:8
+ --> $DIR/len_zero.rs:123:8
|
LL | if has_is_empty.len() != 0 {
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
error: length comparison to zero
- --> $DIR/len_zero.rs:86:8
+ --> $DIR/len_zero.rs:126:8
|
LL | if has_is_empty.len() > 0 {
| ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
error: length comparison to one
- --> $DIR/len_zero.rs:89:8
+ --> $DIR/len_zero.rs:129:8
|
LL | if has_is_empty.len() < 1 {
| ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()`
error: length comparison to one
- --> $DIR/len_zero.rs:92:8
+ --> $DIR/len_zero.rs:132:8
|
LL | if has_is_empty.len() >= 1 {
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
error: length comparison to zero
- --> $DIR/len_zero.rs:103:8
+ --> $DIR/len_zero.rs:143:8
|
LL | if 0 == has_is_empty.len() {
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()`
error: length comparison to zero
- --> $DIR/len_zero.rs:106:8
+ --> $DIR/len_zero.rs:146:8
|
LL | if 0 != has_is_empty.len() {
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
error: length comparison to zero
- --> $DIR/len_zero.rs:109:8
+ --> $DIR/len_zero.rs:149:8
|
LL | if 0 < has_is_empty.len() {
| ^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
error: length comparison to one
- --> $DIR/len_zero.rs:112:8
+ --> $DIR/len_zero.rs:152:8
|
LL | if 1 <= has_is_empty.len() {
| ^^^^^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!has_is_empty.is_empty()`
error: length comparison to one
- --> $DIR/len_zero.rs:115:8
+ --> $DIR/len_zero.rs:155:8
|
LL | if 1 > has_is_empty.len() {
| ^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `has_is_empty.is_empty()`
error: length comparison to zero
- --> $DIR/len_zero.rs:129:8
+ --> $DIR/len_zero.rs:169:8
|
LL | if with_is_empty.len() == 0 {
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `with_is_empty.is_empty()`
error: length comparison to zero
- --> $DIR/len_zero.rs:142:8
+ --> $DIR/len_zero.rs:182:8
|
LL | if b.len() != 0 {}
| ^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!b.is_empty()`
-error: aborting due to 14 previous errors
+error: aborting due to 21 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed b/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed
index c9a819ba5..638320dd6 100644
--- a/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed
+++ b/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed
@@ -62,6 +62,11 @@ fn main() {
panic!("panic5");
}
assert!(!a.is_empty(), "with expansion {}", one!());
+ if a.is_empty() {
+ let _ = 0;
+ } else if a.len() == 1 {
+ panic!("panic6");
+ }
}
fn issue7730(a: u8) {
diff --git a/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed b/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed
index 2f62de51c..8c7e919bf 100644
--- a/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed
+++ b/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed
@@ -50,6 +50,11 @@ fn main() {
assert!(!(b.is_empty() || a.is_empty()), "panic4");
assert!(!(a.is_empty() || !b.is_empty()), "panic5");
assert!(!a.is_empty(), "with expansion {}", one!());
+ if a.is_empty() {
+ let _ = 0;
+ } else if a.len() == 1 {
+ panic!("panic6");
+ }
}
fn issue7730(a: u8) {
diff --git a/src/tools/clippy/tests/ui/manual_assert.edition2021.stderr b/src/tools/clippy/tests/ui/manual_assert.edition2021.stderr
index 237638ee1..3555ac292 100644
--- a/src/tools/clippy/tests/ui/manual_assert.edition2021.stderr
+++ b/src/tools/clippy/tests/ui/manual_assert.edition2021.stderr
@@ -65,7 +65,7 @@ LL | | }
| |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());`
error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:73:5
+ --> $DIR/manual_assert.rs:78:5
|
LL | / if a > 2 {
LL | | // comment
diff --git a/src/tools/clippy/tests/ui/manual_assert.rs b/src/tools/clippy/tests/ui/manual_assert.rs
index 6a4cc2468..f037c5b84 100644
--- a/src/tools/clippy/tests/ui/manual_assert.rs
+++ b/src/tools/clippy/tests/ui/manual_assert.rs
@@ -66,6 +66,11 @@ fn main() {
if a.is_empty() {
panic!("with expansion {}", one!())
}
+ if a.is_empty() {
+ let _ = 0;
+ } else if a.len() == 1 {
+ panic!("panic6");
+ }
}
fn issue7730(a: u8) {
diff --git a/src/tools/clippy/tests/ui/manual_filter.fixed b/src/tools/clippy/tests/ui/manual_filter.fixed
index 3553291b8..ef6780dc9 100644
--- a/src/tools/clippy/tests/ui/manual_filter.fixed
+++ b/src/tools/clippy/tests/ui/manual_filter.fixed
@@ -116,4 +116,45 @@ fn main() {
},
None => None,
};
+
+ match Some(20) {
+ // Don't Lint, because `Some(3*x)` is not `None`
+ None => None,
+ Some(x) => {
+ if x > 0 {
+ Some(3 * x)
+ } else {
+ Some(x)
+ }
+ },
+ };
+
+ // Don't lint: https://github.com/rust-lang/rust-clippy/issues/10088
+ let result = if let Some(a) = maybe_some() {
+ if let Some(b) = maybe_some() {
+ Some(a + b)
+ } else {
+ Some(a)
+ }
+ } else {
+ None
+ };
+
+ let allowed_integers = vec![3, 4, 5, 6];
+ // Don't lint, since there's a side effect in the else branch
+ match Some(21) {
+ Some(x) => {
+ if allowed_integers.contains(&x) {
+ Some(x)
+ } else {
+ println!("Invalid integer: {x:?}");
+ None
+ }
+ },
+ None => None,
+ };
+}
+
+fn maybe_some() -> Option<u32> {
+ Some(0)
}
diff --git a/src/tools/clippy/tests/ui/manual_filter.rs b/src/tools/clippy/tests/ui/manual_filter.rs
index aa9f90f75..ea0ce8317 100644
--- a/src/tools/clippy/tests/ui/manual_filter.rs
+++ b/src/tools/clippy/tests/ui/manual_filter.rs
@@ -240,4 +240,45 @@ fn main() {
},
None => None,
};
+
+ match Some(20) {
+ // Don't Lint, because `Some(3*x)` is not `None`
+ None => None,
+ Some(x) => {
+ if x > 0 {
+ Some(3 * x)
+ } else {
+ Some(x)
+ }
+ },
+ };
+
+ // Don't lint: https://github.com/rust-lang/rust-clippy/issues/10088
+ let result = if let Some(a) = maybe_some() {
+ if let Some(b) = maybe_some() {
+ Some(a + b)
+ } else {
+ Some(a)
+ }
+ } else {
+ None
+ };
+
+ let allowed_integers = vec![3, 4, 5, 6];
+ // Don't lint, since there's a side effect in the else branch
+ match Some(21) {
+ Some(x) => {
+ if allowed_integers.contains(&x) {
+ Some(x)
+ } else {
+ println!("Invalid integer: {x:?}");
+ None
+ }
+ },
+ None => None,
+ };
+}
+
+fn maybe_some() -> Option<u32> {
+ Some(0)
}
diff --git a/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed b/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed
index 231ba83b1..5b2b44c2f 100644
--- a/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed
+++ b/src/tools/clippy/tests/ui/manual_is_ascii_check.fixed
@@ -15,6 +15,19 @@ fn main() {
assert!('x'.is_ascii_alphabetic());
assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_'));
+
+ b'0'.is_ascii_digit();
+ b'a'.is_ascii_lowercase();
+ b'A'.is_ascii_uppercase();
+
+ '0'.is_ascii_digit();
+ 'a'.is_ascii_lowercase();
+ 'A'.is_ascii_uppercase();
+
+ let cool_letter = &'g';
+ cool_letter.is_ascii_digit();
+ cool_letter.is_ascii_lowercase();
+ cool_letter.is_ascii_uppercase();
}
#[clippy::msrv = "1.23"]
diff --git a/src/tools/clippy/tests/ui/manual_is_ascii_check.rs b/src/tools/clippy/tests/ui/manual_is_ascii_check.rs
index 39ee6151c..c9433f33a 100644
--- a/src/tools/clippy/tests/ui/manual_is_ascii_check.rs
+++ b/src/tools/clippy/tests/ui/manual_is_ascii_check.rs
@@ -15,6 +15,19 @@ fn main() {
assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
assert!(matches!('x', 'A'..='Z' | 'a'..='z' | '_'));
+
+ (b'0'..=b'9').contains(&b'0');
+ (b'a'..=b'z').contains(&b'a');
+ (b'A'..=b'Z').contains(&b'A');
+
+ ('0'..='9').contains(&'0');
+ ('a'..='z').contains(&'a');
+ ('A'..='Z').contains(&'A');
+
+ let cool_letter = &'g';
+ ('0'..='9').contains(cool_letter);
+ ('a'..='z').contains(cool_letter);
+ ('A'..='Z').contains(cool_letter);
}
#[clippy::msrv = "1.23"]
diff --git a/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr b/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr
index 397cbe05c..ee6018850 100644
--- a/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr
+++ b/src/tools/clippy/tests/ui/manual_is_ascii_check.stderr
@@ -43,28 +43,82 @@ 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
+ --> $DIR/manual_is_ascii_check.rs:19:5
+ |
+LL | (b'0'..=b'9').contains(&b'0');
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'0'.is_ascii_digit()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:20:5
+ |
+LL | (b'a'..=b'z').contains(&b'a');
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'a'.is_ascii_lowercase()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:21:5
+ |
+LL | (b'A'..=b'Z').contains(&b'A');
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'A'.is_ascii_uppercase()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:23:5
+ |
+LL | ('0'..='9').contains(&'0');
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'0'.is_ascii_digit()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:24:5
+ |
+LL | ('a'..='z').contains(&'a');
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'a'.is_ascii_lowercase()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:25:5
+ |
+LL | ('A'..='Z').contains(&'A');
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'A'.is_ascii_uppercase()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:28:5
+ |
+LL | ('0'..='9').contains(cool_letter);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_digit()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:29:5
+ |
+LL | ('a'..='z').contains(cool_letter);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_lowercase()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:30:5
+ |
+LL | ('A'..='Z').contains(cool_letter);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_uppercase()`
+
+error: manual check for common ascii range
+ --> $DIR/manual_is_ascii_check.rs:42:13
|
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
+ --> $DIR/manual_is_ascii_check.rs:43: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
+ --> $DIR/manual_is_ascii_check.rs:44: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
+ --> $DIR/manual_is_ascii_check.rs:54:23
|
LL | const FOO: bool = matches!('x', '0'..='9');
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_digit()`
-error: aborting due to 11 previous errors
+error: aborting due to 20 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_let_else_match.rs b/src/tools/clippy/tests/ui/manual_let_else_match.rs
index 93c86ca24..28caed9d7 100644
--- a/src/tools/clippy/tests/ui/manual_let_else_match.rs
+++ b/src/tools/clippy/tests/ui/manual_let_else_match.rs
@@ -64,6 +64,13 @@ fn fire() {
Ok(v) => v,
Err(()) => return,
};
+
+ let f = Variant::Bar(1);
+
+ let _value = match f {
+ Variant::Bar(_) | Variant::Baz(_) => (),
+ _ => return,
+ };
}
fn not_fire() {
diff --git a/src/tools/clippy/tests/ui/manual_let_else_match.stderr b/src/tools/clippy/tests/ui/manual_let_else_match.stderr
index 38be5ac54..cd5e9a9ac 100644
--- a/src/tools/clippy/tests/ui/manual_let_else_match.stderr
+++ b/src/tools/clippy/tests/ui/manual_let_else_match.stderr
@@ -25,7 +25,7 @@ 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 };`
+ | |__________^ 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
@@ -34,7 +34,7 @@ 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 };`
+ | |__________^ 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
@@ -54,5 +54,14 @@ LL | | Err(()) => return,
LL | | };
| |______^ help: consider writing: `let Ok(v) = f().map_err(|_| ()) else { return };`
-error: aborting due to 6 previous errors
+error: this could be rewritten as `let...else`
+ --> $DIR/manual_let_else_match.rs:70:5
+ |
+LL | / let _value = match f {
+LL | | Variant::Bar(_) | Variant::Baz(_) => (),
+LL | | _ => return,
+LL | | };
+ | |______^ help: consider writing: `let (Variant::Bar(_) | Variant::Baz(_)) = f else { return };`
+
+error: aborting due to 7 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_retain.fixed b/src/tools/clippy/tests/ui/manual_retain.fixed
index e5ae3cf3e..8f25fea67 100644
--- a/src/tools/clippy/tests/ui/manual_retain.fixed
+++ b/src/tools/clippy/tests/ui/manual_retain.fixed
@@ -1,6 +1,6 @@
// run-rustfix
#![warn(clippy::manual_retain)]
-#![allow(unused)]
+#![allow(unused, clippy::redundant_clone)]
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
diff --git a/src/tools/clippy/tests/ui/manual_retain.rs b/src/tools/clippy/tests/ui/manual_retain.rs
index 1021f15ed..e6b3995a6 100644
--- a/src/tools/clippy/tests/ui/manual_retain.rs
+++ b/src/tools/clippy/tests/ui/manual_retain.rs
@@ -1,6 +1,6 @@
// run-rustfix
#![warn(clippy::manual_retain)]
-#![allow(unused)]
+#![allow(unused, clippy::redundant_clone)]
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
diff --git a/src/tools/clippy/tests/ui/match_single_binding.fixed b/src/tools/clippy/tests/ui/match_single_binding.fixed
index a6e315e47..6cfb6661a 100644
--- a/src/tools/clippy/tests/ui/match_single_binding.fixed
+++ b/src/tools/clippy/tests/ui/match_single_binding.fixed
@@ -133,3 +133,16 @@ fn issue_9575() {
println!("Needs curlies");
};
}
+
+#[allow(dead_code)]
+fn issue_9725(r: Option<u32>) {
+ let x = r;
+ match x {
+ Some(_) => {
+ println!("Some");
+ },
+ None => {
+ println!("None");
+ },
+ };
+}
diff --git a/src/tools/clippy/tests/ui/match_single_binding.rs b/src/tools/clippy/tests/ui/match_single_binding.rs
index cecbd703e..f188aeb5f 100644
--- a/src/tools/clippy/tests/ui/match_single_binding.rs
+++ b/src/tools/clippy/tests/ui/match_single_binding.rs
@@ -148,3 +148,17 @@ fn issue_9575() {
_ => println!("Needs curlies"),
};
}
+
+#[allow(dead_code)]
+fn issue_9725(r: Option<u32>) {
+ match r {
+ x => match x {
+ Some(_) => {
+ println!("Some");
+ },
+ None => {
+ println!("None");
+ },
+ },
+ };
+}
diff --git a/src/tools/clippy/tests/ui/match_single_binding.stderr b/src/tools/clippy/tests/ui/match_single_binding.stderr
index 2b9ec7ee7..e960d64ad 100644
--- a/src/tools/clippy/tests/ui/match_single_binding.stderr
+++ b/src/tools/clippy/tests/ui/match_single_binding.stderr
@@ -213,5 +213,30 @@ LL + println!("Needs curlies");
LL ~ };
|
-error: aborting due to 14 previous errors
+error: this match could be written as a `let` statement
+ --> $DIR/match_single_binding.rs:154:5
+ |
+LL | / match r {
+LL | | x => match x {
+LL | | Some(_) => {
+LL | | println!("Some");
+... |
+LL | | },
+LL | | };
+ | |_____^
+ |
+help: consider using a `let` statement
+ |
+LL ~ let x = r;
+LL + match x {
+LL + Some(_) => {
+LL + println!("Some");
+LL + },
+LL + None => {
+LL + println!("None");
+LL + },
+LL ~ };
+ |
+
+error: aborting due to 15 previous errors
diff --git a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.fixed b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.fixed
index e675c183e..fc252cdd3 100644
--- a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.fixed
+++ b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.fixed
@@ -132,3 +132,25 @@ fn main() {
}
}
}
+
+mod issue9993 {
+ enum Foo {
+ A(bool),
+ B,
+ }
+
+ fn test() {
+ let _ = match Foo::A(true) {
+ _ if false => 0,
+ Foo::A(true) => 1,
+ Foo::A(false) => 2,
+ Foo::B => 3,
+ };
+
+ let _ = match Foo::B {
+ _ if false => 0,
+ Foo::A(_) => 1,
+ Foo::B => 2,
+ };
+ }
+}
diff --git a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.rs b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.rs
index 38c3ffc00..9a5c849e6 100644
--- a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.rs
+++ b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.rs
@@ -132,3 +132,25 @@ fn main() {
}
}
}
+
+mod issue9993 {
+ enum Foo {
+ A(bool),
+ B,
+ }
+
+ fn test() {
+ let _ = match Foo::A(true) {
+ _ if false => 0,
+ Foo::A(true) => 1,
+ Foo::A(false) => 2,
+ Foo::B => 3,
+ };
+
+ let _ = match Foo::B {
+ _ if false => 0,
+ Foo::A(_) => 1,
+ _ => 2,
+ };
+ }
+}
diff --git a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.stderr b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.stderr
index 34538dea8..6fa313dc9 100644
--- a/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.stderr
+++ b/src/tools/clippy/tests/ui/match_wildcard_for_single_variants.stderr
@@ -48,5 +48,11 @@ error: wildcard matches only a single variant and will also match any future add
LL | _ => (),
| ^ help: try this: `Color::Blue`
-error: aborting due to 8 previous errors
+error: wildcard matches only a single variant and will also match any future added variants
+ --> $DIR/match_wildcard_for_single_variants.rs:153:13
+ |
+LL | _ => 2,
+ | ^ help: try this: `Foo::B`
+
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/needless_parens_on_range_literals.fixed b/src/tools/clippy/tests/ui/needless_parens_on_range_literals.fixed
index 1bd75c806..f11330a89 100644
--- a/src/tools/clippy/tests/ui/needless_parens_on_range_literals.fixed
+++ b/src/tools/clippy/tests/ui/needless_parens_on_range_literals.fixed
@@ -2,7 +2,7 @@
// edition:2018
#![warn(clippy::needless_parens_on_range_literals)]
-#![allow(clippy::almost_complete_letter_range)]
+#![allow(clippy::almost_complete_range)]
fn main() {
let _ = 'a'..='z';
diff --git a/src/tools/clippy/tests/ui/needless_parens_on_range_literals.rs b/src/tools/clippy/tests/ui/needless_parens_on_range_literals.rs
index 7abb8a1ad..671c0009e 100644
--- a/src/tools/clippy/tests/ui/needless_parens_on_range_literals.rs
+++ b/src/tools/clippy/tests/ui/needless_parens_on_range_literals.rs
@@ -2,7 +2,7 @@
// edition:2018
#![warn(clippy::needless_parens_on_range_literals)]
-#![allow(clippy::almost_complete_letter_range)]
+#![allow(clippy::almost_complete_range)]
fn main() {
let _ = ('a')..=('z');
diff --git a/src/tools/clippy/tests/ui/needless_return.fixed b/src/tools/clippy/tests/ui/needless_return.fixed
index 4386aaec4..ab1c0e590 100644
--- a/src/tools/clippy/tests/ui/needless_return.fixed
+++ b/src/tools/clippy/tests/ui/needless_return.fixed
@@ -1,6 +1,7 @@
// run-rustfix
#![feature(lint_reasons)]
+#![feature(yeet_expr)]
#![allow(unused)]
#![allow(
clippy::if_same_then_else,
@@ -272,4 +273,18 @@ mod issue9416 {
}
}
+fn issue9947() -> Result<(), String> {
+ do yeet "hello";
+}
+
+// without anyhow, but triggers the same bug I believe
+#[expect(clippy::useless_format)]
+fn issue10051() -> Result<String, String> {
+ if true {
+ Ok(format!("ok!"))
+ } else {
+ Err(format!("err!"))
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/needless_return.rs b/src/tools/clippy/tests/ui/needless_return.rs
index 666dc54b7..abed338bb 100644
--- a/src/tools/clippy/tests/ui/needless_return.rs
+++ b/src/tools/clippy/tests/ui/needless_return.rs
@@ -1,6 +1,7 @@
// run-rustfix
#![feature(lint_reasons)]
+#![feature(yeet_expr)]
#![allow(unused)]
#![allow(
clippy::if_same_then_else,
@@ -282,4 +283,18 @@ mod issue9416 {
}
}
+fn issue9947() -> Result<(), String> {
+ do yeet "hello";
+}
+
+// without anyhow, but triggers the same bug I believe
+#[expect(clippy::useless_format)]
+fn issue10051() -> Result<String, String> {
+ if true {
+ return Ok(format!("ok!"));
+ } else {
+ return Err(format!("err!"));
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/needless_return.stderr b/src/tools/clippy/tests/ui/needless_return.stderr
index a8b5d86cd..52eabf6e1 100644
--- a/src/tools/clippy/tests/ui/needless_return.stderr
+++ b/src/tools/clippy/tests/ui/needless_return.stderr
@@ -1,5 +1,5 @@
error: unneeded `return` statement
- --> $DIR/needless_return.rs:26:5
+ --> $DIR/needless_return.rs:27:5
|
LL | return true;
| ^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | return true;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:30:5
+ --> $DIR/needless_return.rs:31:5
|
LL | return true;
| ^^^^^^^^^^^
@@ -16,7 +16,7 @@ LL | return true;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:35:9
+ --> $DIR/needless_return.rs:36:9
|
LL | return true;
| ^^^^^^^^^^^
@@ -24,7 +24,7 @@ LL | return true;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:37:9
+ --> $DIR/needless_return.rs:38:9
|
LL | return false;
| ^^^^^^^^^^^^
@@ -32,7 +32,7 @@ LL | return false;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:43:17
+ --> $DIR/needless_return.rs:44:17
|
LL | true => return false,
| ^^^^^^^^^^^^
@@ -40,7 +40,7 @@ LL | true => return false,
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:45:13
+ --> $DIR/needless_return.rs:46:13
|
LL | return true;
| ^^^^^^^^^^^
@@ -48,7 +48,7 @@ LL | return true;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:52:9
+ --> $DIR/needless_return.rs:53:9
|
LL | return true;
| ^^^^^^^^^^^
@@ -56,7 +56,7 @@ LL | return true;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:54:16
+ --> $DIR/needless_return.rs:55:16
|
LL | let _ = || return true;
| ^^^^^^^^^^^
@@ -64,7 +64,7 @@ LL | let _ = || return true;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:58:5
+ --> $DIR/needless_return.rs:59:5
|
LL | return the_answer!();
| ^^^^^^^^^^^^^^^^^^^^
@@ -72,7 +72,7 @@ LL | return the_answer!();
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:61:21
+ --> $DIR/needless_return.rs:62:21
|
LL | fn test_void_fun() {
| _____________________^
@@ -82,7 +82,7 @@ LL | | return;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:66:11
+ --> $DIR/needless_return.rs:67:11
|
LL | if b {
| ___________^
@@ -92,7 +92,7 @@ LL | | return;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:68:13
+ --> $DIR/needless_return.rs:69:13
|
LL | } else {
| _____________^
@@ -102,7 +102,7 @@ LL | | return;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:76:14
+ --> $DIR/needless_return.rs:77:14
|
LL | _ => return,
| ^^^^^^
@@ -110,7 +110,7 @@ LL | _ => return,
= help: replace `return` with a unit value
error: unneeded `return` statement
- --> $DIR/needless_return.rs:84:24
+ --> $DIR/needless_return.rs:85:24
|
LL | let _ = 42;
| ________________________^
@@ -120,7 +120,7 @@ LL | | return;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:87:14
+ --> $DIR/needless_return.rs:88:14
|
LL | _ => return,
| ^^^^^^
@@ -128,7 +128,7 @@ LL | _ => return,
= help: replace `return` with a unit value
error: unneeded `return` statement
- --> $DIR/needless_return.rs:100:9
+ --> $DIR/needless_return.rs:101:9
|
LL | return String::from("test");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -136,7 +136,7 @@ LL | return String::from("test");
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:102:9
+ --> $DIR/needless_return.rs:103:9
|
LL | return String::new();
| ^^^^^^^^^^^^^^^^^^^^
@@ -144,7 +144,7 @@ LL | return String::new();
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:124:32
+ --> $DIR/needless_return.rs:125:32
|
LL | bar.unwrap_or_else(|_| return)
| ^^^^^^
@@ -152,7 +152,7 @@ LL | bar.unwrap_or_else(|_| return)
= help: replace `return` with an empty block
error: unneeded `return` statement
- --> $DIR/needless_return.rs:128:21
+ --> $DIR/needless_return.rs:129:21
|
LL | let _ = || {
| _____________________^
@@ -162,7 +162,7 @@ LL | | return;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:131:20
+ --> $DIR/needless_return.rs:132:20
|
LL | let _ = || return;
| ^^^^^^
@@ -170,7 +170,7 @@ LL | let _ = || return;
= help: replace `return` with an empty block
error: unneeded `return` statement
- --> $DIR/needless_return.rs:137:32
+ --> $DIR/needless_return.rs:138:32
|
LL | res.unwrap_or_else(|_| return Foo)
| ^^^^^^^^^^
@@ -178,7 +178,7 @@ LL | res.unwrap_or_else(|_| return Foo)
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:146:5
+ --> $DIR/needless_return.rs:147:5
|
LL | return true;
| ^^^^^^^^^^^
@@ -186,7 +186,7 @@ LL | return true;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:150:5
+ --> $DIR/needless_return.rs:151:5
|
LL | return true;
| ^^^^^^^^^^^
@@ -194,7 +194,7 @@ LL | return true;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:155:9
+ --> $DIR/needless_return.rs:156:9
|
LL | return true;
| ^^^^^^^^^^^
@@ -202,7 +202,7 @@ LL | return true;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:157:9
+ --> $DIR/needless_return.rs:158:9
|
LL | return false;
| ^^^^^^^^^^^^
@@ -210,7 +210,7 @@ LL | return false;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:163:17
+ --> $DIR/needless_return.rs:164:17
|
LL | true => return false,
| ^^^^^^^^^^^^
@@ -218,7 +218,7 @@ LL | true => return false,
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:165:13
+ --> $DIR/needless_return.rs:166:13
|
LL | return true;
| ^^^^^^^^^^^
@@ -226,7 +226,7 @@ LL | return true;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:172:9
+ --> $DIR/needless_return.rs:173:9
|
LL | return true;
| ^^^^^^^^^^^
@@ -234,7 +234,7 @@ LL | return true;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:174:16
+ --> $DIR/needless_return.rs:175:16
|
LL | let _ = || return true;
| ^^^^^^^^^^^
@@ -242,7 +242,7 @@ LL | let _ = || return true;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:178:5
+ --> $DIR/needless_return.rs:179:5
|
LL | return the_answer!();
| ^^^^^^^^^^^^^^^^^^^^
@@ -250,7 +250,7 @@ LL | return the_answer!();
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:181:33
+ --> $DIR/needless_return.rs:182:33
|
LL | async fn async_test_void_fun() {
| _________________________________^
@@ -260,7 +260,7 @@ LL | | return;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:186:11
+ --> $DIR/needless_return.rs:187:11
|
LL | if b {
| ___________^
@@ -270,7 +270,7 @@ LL | | return;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:188:13
+ --> $DIR/needless_return.rs:189:13
|
LL | } else {
| _____________^
@@ -280,7 +280,7 @@ LL | | return;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:196:14
+ --> $DIR/needless_return.rs:197:14
|
LL | _ => return,
| ^^^^^^
@@ -288,7 +288,7 @@ LL | _ => return,
= help: replace `return` with a unit value
error: unneeded `return` statement
- --> $DIR/needless_return.rs:209:9
+ --> $DIR/needless_return.rs:210:9
|
LL | return String::from("test");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -296,7 +296,7 @@ LL | return String::from("test");
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:211:9
+ --> $DIR/needless_return.rs:212:9
|
LL | return String::new();
| ^^^^^^^^^^^^^^^^^^^^
@@ -304,7 +304,7 @@ LL | return String::new();
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:227:5
+ --> $DIR/needless_return.rs:228:5
|
LL | return format!("Hello {}", "world!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -312,7 +312,7 @@ LL | return format!("Hello {}", "world!");
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:238:9
+ --> $DIR/needless_return.rs:239:9
|
LL | return true;
| ^^^^^^^^^^^
@@ -320,7 +320,7 @@ LL | return true;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:240:9
+ --> $DIR/needless_return.rs:241:9
|
LL | return false;
| ^^^^^^^^^^^^
@@ -328,7 +328,7 @@ LL | return false;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:247:13
+ --> $DIR/needless_return.rs:248:13
|
LL | return 10;
| ^^^^^^^^^
@@ -336,7 +336,7 @@ LL | return 10;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:250:13
+ --> $DIR/needless_return.rs:251:13
|
LL | return 100;
| ^^^^^^^^^^
@@ -344,7 +344,7 @@ LL | return 100;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:258:9
+ --> $DIR/needless_return.rs:259:9
|
LL | return 0;
| ^^^^^^^^
@@ -352,7 +352,7 @@ LL | return 0;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:265:13
+ --> $DIR/needless_return.rs:266:13
|
LL | return *(x as *const isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -360,7 +360,7 @@ LL | return *(x as *const isize);
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:267:13
+ --> $DIR/needless_return.rs:268:13
|
LL | return !*(x as *const isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -368,7 +368,7 @@ LL | return !*(x as *const isize);
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:274:20
+ --> $DIR/needless_return.rs:275:20
|
LL | let _ = 42;
| ____________________^
@@ -379,12 +379,28 @@ LL | | return;
= help: remove `return`
error: unneeded `return` statement
- --> $DIR/needless_return.rs:281:20
+ --> $DIR/needless_return.rs:282:20
|
LL | let _ = 42; return;
| ^^^^^^^
|
= help: remove `return`
-error: aborting due to 46 previous errors
+error: unneeded `return` statement
+ --> $DIR/needless_return.rs:294:9
+ |
+LL | return Ok(format!("ok!"));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: remove `return`
+
+error: unneeded `return` statement
+ --> $DIR/needless_return.rs:296:9
+ |
+LL | return Err(format!("err!"));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: remove `return`
+
+error: aborting due to 48 previous errors
diff --git a/src/tools/clippy/tests/ui/permissions_set_readonly_false.rs b/src/tools/clippy/tests/ui/permissions_set_readonly_false.rs
new file mode 100644
index 000000000..28c00d100
--- /dev/null
+++ b/src/tools/clippy/tests/ui/permissions_set_readonly_false.rs
@@ -0,0 +1,29 @@
+#![allow(unused)]
+#![warn(clippy::permissions_set_readonly_false)]
+
+use std::fs::File;
+
+struct A;
+
+impl A {
+ pub fn set_readonly(&mut self, b: bool) {}
+}
+
+fn set_readonly(b: bool) {}
+
+fn main() {
+ let f = File::create("foo.txt").unwrap();
+ let metadata = f.metadata().unwrap();
+ let mut permissions = metadata.permissions();
+ // lint here
+ permissions.set_readonly(false);
+ // no lint
+ permissions.set_readonly(true);
+
+ let mut a = A;
+ // no lint here - a is not of type std::fs::Permissions
+ a.set_readonly(false);
+
+ // no lint here - plain function
+ set_readonly(false);
+}
diff --git a/src/tools/clippy/tests/ui/permissions_set_readonly_false.stderr b/src/tools/clippy/tests/ui/permissions_set_readonly_false.stderr
new file mode 100644
index 000000000..e7a8ee6cb
--- /dev/null
+++ b/src/tools/clippy/tests/ui/permissions_set_readonly_false.stderr
@@ -0,0 +1,13 @@
+error: call to `set_readonly` with argument `false`
+ --> $DIR/permissions_set_readonly_false.rs:19:5
+ |
+LL | permissions.set_readonly(false);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: on Unix platforms this results in the file being world writable
+ = help: you can set the desired permissions using `PermissionsExt`. For more information, see
+ https://doc.rust-lang.org/std/os/unix/fs/trait.PermissionsExt.html
+ = note: `-D clippy::permissions-set-readonly-false` implied by `-D warnings`
+
+error: aborting due to previous error
+
diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed b/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
index 4c5846fe8..bca777a89 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
@@ -39,8 +39,14 @@ static STATIC_VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR Consider removing 'static
static STATIC_VAR_ARRAY: &[u8; 1] = b"T"; // ERROR Consider removing 'static.
+static mut STATIC_MUT_SLICE: &mut [u32] = &mut [0];
+
fn main() {
let false_positive: &'static str = "test";
+
+ unsafe {
+ STATIC_MUT_SLICE[0] = 0;
+ }
}
trait Bar {
diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs b/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
index 64a66be1a..afe764481 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
@@ -39,8 +39,14 @@ static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing
static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
+static mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0];
+
fn main() {
let false_positive: &'static str = "test";
+
+ unsafe {
+ STATIC_MUT_SLICE[0] = 0;
+ }
}
trait Bar {
diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr b/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr
index 0938ebf78..b2cbd2d9d 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr
@@ -97,10 +97,16 @@ LL | static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removin
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:65:16
+ --> $DIR/redundant_static_lifetimes.rs:42:31
+ |
+LL | static mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0];
+ | -^^^^^^^---------- help: consider removing `'static`: `&mut [u32]`
+
+error: statics have by default a `'static` lifetime
+ --> $DIR/redundant_static_lifetimes.rs:71:16
|
LL | static V: &'static u8 = &17;
| -^^^^^^^--- help: consider removing `'static`: `&u8`
-error: aborting due to 17 previous errors
+error: aborting due to 18 previous errors
diff --git a/src/tools/clippy/tests/ui/rename.fixed b/src/tools/clippy/tests/ui/rename.fixed
index 689928f04..5076f6133 100644
--- a/src/tools/clippy/tests/ui/rename.fixed
+++ b/src/tools/clippy/tests/ui/rename.fixed
@@ -4,11 +4,13 @@
// run-rustfix
+#![allow(clippy::almost_complete_range)]
#![allow(clippy::disallowed_names)]
#![allow(clippy::blocks_in_if_conditions)]
#![allow(clippy::box_collection)]
#![allow(clippy::redundant_static_lifetimes)]
#![allow(clippy::cognitive_complexity)]
+#![allow(clippy::derived_hash_with_manual_eq)]
#![allow(clippy::disallowed_methods)]
#![allow(clippy::disallowed_types)]
#![allow(clippy::mixed_read_write_in_expression)]
@@ -37,12 +39,14 @@
#![allow(temporary_cstring_as_ptr)]
#![allow(unknown_lints)]
#![allow(unused_labels)]
+#![warn(clippy::almost_complete_range)]
#![warn(clippy::disallowed_names)]
#![warn(clippy::blocks_in_if_conditions)]
#![warn(clippy::blocks_in_if_conditions)]
#![warn(clippy::box_collection)]
#![warn(clippy::redundant_static_lifetimes)]
#![warn(clippy::cognitive_complexity)]
+#![warn(clippy::derived_hash_with_manual_eq)]
#![warn(clippy::disallowed_methods)]
#![warn(clippy::disallowed_types)]
#![warn(clippy::mixed_read_write_in_expression)]
diff --git a/src/tools/clippy/tests/ui/rename.rs b/src/tools/clippy/tests/ui/rename.rs
index b74aa650f..64bc1ca71 100644
--- a/src/tools/clippy/tests/ui/rename.rs
+++ b/src/tools/clippy/tests/ui/rename.rs
@@ -4,11 +4,13 @@
// run-rustfix
+#![allow(clippy::almost_complete_range)]
#![allow(clippy::disallowed_names)]
#![allow(clippy::blocks_in_if_conditions)]
#![allow(clippy::box_collection)]
#![allow(clippy::redundant_static_lifetimes)]
#![allow(clippy::cognitive_complexity)]
+#![allow(clippy::derived_hash_with_manual_eq)]
#![allow(clippy::disallowed_methods)]
#![allow(clippy::disallowed_types)]
#![allow(clippy::mixed_read_write_in_expression)]
@@ -37,12 +39,14 @@
#![allow(temporary_cstring_as_ptr)]
#![allow(unknown_lints)]
#![allow(unused_labels)]
+#![warn(clippy::almost_complete_letter_range)]
#![warn(clippy::blacklisted_name)]
#![warn(clippy::block_in_if_condition_expr)]
#![warn(clippy::block_in_if_condition_stmt)]
#![warn(clippy::box_vec)]
#![warn(clippy::const_static_lifetime)]
#![warn(clippy::cyclomatic_complexity)]
+#![warn(clippy::derive_hash_xor_eq)]
#![warn(clippy::disallowed_method)]
#![warn(clippy::disallowed_type)]
#![warn(clippy::eval_order_dependence)]
diff --git a/src/tools/clippy/tests/ui/rename.stderr b/src/tools/clippy/tests/ui/rename.stderr
index 622a32c59..27a026329 100644
--- a/src/tools/clippy/tests/ui/rename.stderr
+++ b/src/tools/clippy/tests/ui/rename.stderr
@@ -1,244 +1,256 @@
+error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range`
+ --> $DIR/rename.rs:42:9
+ |
+LL | #![warn(clippy::almost_complete_letter_range)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range`
+ |
+ = note: `-D renamed-and-removed-lints` implied by `-D warnings`
+
error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names`
- --> $DIR/rename.rs:40:9
+ --> $DIR/rename.rs:43:9
|
LL | #![warn(clippy::blacklisted_name)]
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names`
- |
- = 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:41:9
+ --> $DIR/rename.rs:44: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:42:9
+ --> $DIR/rename.rs:45: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:43:9
+ --> $DIR/rename.rs:46: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:44:9
+ --> $DIR/rename.rs:47: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:45:9
+ --> $DIR/rename.rs:48:9
|
LL | #![warn(clippy::cyclomatic_complexity)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity`
+error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq`
+ --> $DIR/rename.rs:49:9
+ |
+LL | #![warn(clippy::derive_hash_xor_eq)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq`
+
error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods`
- --> $DIR/rename.rs:46:9
+ --> $DIR/rename.rs:50: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:47:9
+ --> $DIR/rename.rs:51: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:48:9
+ --> $DIR/rename.rs:52:9
|
LL | #![warn(clippy::eval_order_dependence)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression`
error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion`
- --> $DIR/rename.rs:49:9
+ --> $DIR/rename.rs:53: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:50:9
+ --> $DIR/rename.rs:54: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:51:9
+ --> $DIR/rename.rs:55: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:52:9
+ --> $DIR/rename.rs:56: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:53:9
+ --> $DIR/rename.rs:57: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:54:9
+ --> $DIR/rename.rs:58: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:55:9
+ --> $DIR/rename.rs:59: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:56:9
+ --> $DIR/rename.rs:60: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:57:9
+ --> $DIR/rename.rs:61: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:58:9
+ --> $DIR/rename.rs:62: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:59:9
+ --> $DIR/rename.rs:63: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:60:9
+ --> $DIR/rename.rs:64: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:61:9
+ --> $DIR/rename.rs:65: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:62:9
+ --> $DIR/rename.rs:66: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:63:9
+ --> $DIR/rename.rs:67: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:64:9
+ --> $DIR/rename.rs:68: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:65:9
+ --> $DIR/rename.rs:69: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:66:9
+ --> $DIR/rename.rs:70:9
|
LL | #![warn(clippy::drop_bounds)]
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds`
error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles`
- --> $DIR/rename.rs:67:9
+ --> $DIR/rename.rs:71: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
+ --> $DIR/rename.rs:72: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
+ --> $DIR/rename.rs:73: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:70:9
+ --> $DIR/rename.rs:74: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:71:9
+ --> $DIR/rename.rs:75: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:72:9
+ --> $DIR/rename.rs:76: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
+ --> $DIR/rename.rs:77: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:74:9
+ --> $DIR/rename.rs:78: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:75:9
+ --> $DIR/rename.rs:79: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:76:9
+ --> $DIR/rename.rs:80: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:77:9
+ --> $DIR/rename.rs:81: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:78:9
+ --> $DIR/rename.rs:82: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:79:9
+ --> $DIR/rename.rs:83:9
|
LL | #![warn(clippy::unused_label)]
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels`
-error: aborting due to 40 previous errors
+error: aborting due to 42 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 2e1eb8eb1..d0e534f63 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
@@ -19,10 +19,7 @@ LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value)
error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()`
--> $DIR/result_map_unit_fn_unfixable.rs:29:5
|
-LL | x.field.map(|value| {
- | ______^
- | | _____|
- | ||
+LL | // x.field.map(|value| {
LL | || do_nothing(value);
LL | || do_nothing(value)
LL | || });
diff --git a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed
index 9d0d1124c..713cff604 100644
--- a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed
+++ b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.fixed
@@ -70,6 +70,12 @@ fn seek_to_end<T: Seek>(t: &mut T) {
t.seek(SeekFrom::End(0));
}
+// This should NOT trigger clippy warning because
+// expr is used here
+fn seek_to_start_in_let<T: Seek>(t: &mut T) {
+ let a = t.seek(SeekFrom::Start(0)).unwrap();
+}
+
fn main() {
let mut f = OpenOptions::new()
.write(true)
diff --git a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs
index c5bc57cc3..467003a1a 100644
--- a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs
+++ b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.rs
@@ -70,6 +70,12 @@ fn seek_to_end<T: Seek>(t: &mut T) {
t.seek(SeekFrom::End(0));
}
+// This should NOT trigger clippy warning because
+// expr is used here
+fn seek_to_start_in_let<T: Seek>(t: &mut T) {
+ let a = t.seek(SeekFrom::Start(0)).unwrap();
+}
+
fn main() {
let mut f = OpenOptions::new()
.write(true)
diff --git a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.stderr b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.stderr
index 6cce02535..342ec00fe 100644
--- a/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.stderr
+++ b/src/tools/clippy/tests/ui/seek_to_start_instead_of_rewind.stderr
@@ -13,7 +13,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
+ --> $DIR/seek_to_start_instead_of_rewind.rs:134:7
|
LL | f.seek(SeekFrom::Start(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()`
diff --git a/src/tools/clippy/tests/ui/semicolon_inside_block.fixed b/src/tools/clippy/tests/ui/semicolon_inside_block.fixed
new file mode 100644
index 000000000..42e97e1ca
--- /dev/null
+++ b/src/tools/clippy/tests/ui/semicolon_inside_block.fixed
@@ -0,0 +1,85 @@
+// run-rustfix
+#![allow(
+ unused,
+ clippy::unused_unit,
+ clippy::unnecessary_operation,
+ clippy::no_effect,
+ clippy::single_element_loop
+)]
+#![warn(clippy::semicolon_inside_block)]
+
+macro_rules! m {
+ (()) => {
+ ()
+ };
+ (0) => {{
+ 0
+ };};
+ (1) => {{
+ 1;
+ }};
+ (2) => {{
+ 2;
+ }};
+}
+
+fn unit_fn_block() {
+ ()
+}
+
+#[rustfmt::skip]
+fn main() {
+ { unit_fn_block() }
+ unsafe { unit_fn_block() }
+
+ {
+ unit_fn_block()
+ }
+
+ { unit_fn_block(); }
+ unsafe { unit_fn_block(); }
+
+ { unit_fn_block(); }
+ unsafe { unit_fn_block(); }
+
+ { unit_fn_block(); };
+ unsafe { unit_fn_block(); };
+
+ {
+ unit_fn_block();
+ unit_fn_block();
+ }
+ {
+ unit_fn_block();
+ unit_fn_block();
+ }
+ {
+ unit_fn_block();
+ unit_fn_block();
+ };
+
+ { m!(()); }
+ { m!(()); }
+ { m!(()); };
+ m!(0);
+ m!(1);
+ m!(2);
+
+ for _ in [()] {
+ unit_fn_block();
+ }
+ for _ in [()] {
+ unit_fn_block()
+ }
+
+ let _d = || {
+ unit_fn_block();
+ };
+ let _d = || {
+ unit_fn_block()
+ };
+
+ { unit_fn_block(); };
+
+ unit_fn_block()
+}
diff --git a/src/tools/clippy/tests/ui/semicolon_inside_block.rs b/src/tools/clippy/tests/ui/semicolon_inside_block.rs
new file mode 100644
index 000000000..f40848f70
--- /dev/null
+++ b/src/tools/clippy/tests/ui/semicolon_inside_block.rs
@@ -0,0 +1,85 @@
+// run-rustfix
+#![allow(
+ unused,
+ clippy::unused_unit,
+ clippy::unnecessary_operation,
+ clippy::no_effect,
+ clippy::single_element_loop
+)]
+#![warn(clippy::semicolon_inside_block)]
+
+macro_rules! m {
+ (()) => {
+ ()
+ };
+ (0) => {{
+ 0
+ };};
+ (1) => {{
+ 1;
+ }};
+ (2) => {{
+ 2;
+ }};
+}
+
+fn unit_fn_block() {
+ ()
+}
+
+#[rustfmt::skip]
+fn main() {
+ { unit_fn_block() }
+ unsafe { unit_fn_block() }
+
+ {
+ unit_fn_block()
+ }
+
+ { unit_fn_block() };
+ unsafe { unit_fn_block() };
+
+ { unit_fn_block(); }
+ unsafe { unit_fn_block(); }
+
+ { unit_fn_block(); };
+ unsafe { unit_fn_block(); };
+
+ {
+ unit_fn_block();
+ unit_fn_block()
+ };
+ {
+ unit_fn_block();
+ unit_fn_block();
+ }
+ {
+ unit_fn_block();
+ unit_fn_block();
+ };
+
+ { m!(()) };
+ { m!(()); }
+ { m!(()); };
+ m!(0);
+ m!(1);
+ m!(2);
+
+ for _ in [()] {
+ unit_fn_block();
+ }
+ for _ in [()] {
+ unit_fn_block()
+ }
+
+ let _d = || {
+ unit_fn_block();
+ };
+ let _d = || {
+ unit_fn_block()
+ };
+
+ { unit_fn_block(); };
+
+ unit_fn_block()
+}
diff --git a/src/tools/clippy/tests/ui/semicolon_inside_block.stderr b/src/tools/clippy/tests/ui/semicolon_inside_block.stderr
new file mode 100644
index 000000000..48d3690e2
--- /dev/null
+++ b/src/tools/clippy/tests/ui/semicolon_inside_block.stderr
@@ -0,0 +1,54 @@
+error: consider moving the `;` inside the block for consistent formatting
+ --> $DIR/semicolon_inside_block.rs:39:5
+ |
+LL | { unit_fn_block() };
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::semicolon-inside-block` implied by `-D warnings`
+help: put the `;` here
+ |
+LL - { unit_fn_block() };
+LL + { unit_fn_block(); }
+ |
+
+error: consider moving the `;` inside the block for consistent formatting
+ --> $DIR/semicolon_inside_block.rs:40:5
+ |
+LL | unsafe { unit_fn_block() };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: put the `;` here
+ |
+LL - unsafe { unit_fn_block() };
+LL + unsafe { unit_fn_block(); }
+ |
+
+error: consider moving the `;` inside the block for consistent formatting
+ --> $DIR/semicolon_inside_block.rs:48:5
+ |
+LL | / {
+LL | | unit_fn_block();
+LL | | unit_fn_block()
+LL | | };
+ | |______^
+ |
+help: put the `;` here
+ |
+LL ~ unit_fn_block();
+LL ~ }
+ |
+
+error: consider moving the `;` inside the block for consistent formatting
+ --> $DIR/semicolon_inside_block.rs:61:5
+ |
+LL | { m!(()) };
+ | ^^^^^^^^^^^
+ |
+help: put the `;` here
+ |
+LL - { m!(()) };
+LL + { m!(()); }
+ |
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui/semicolon_outside_block.fixed b/src/tools/clippy/tests/ui/semicolon_outside_block.fixed
new file mode 100644
index 000000000..091eaa751
--- /dev/null
+++ b/src/tools/clippy/tests/ui/semicolon_outside_block.fixed
@@ -0,0 +1,85 @@
+// run-rustfix
+#![allow(
+ unused,
+ clippy::unused_unit,
+ clippy::unnecessary_operation,
+ clippy::no_effect,
+ clippy::single_element_loop
+)]
+#![warn(clippy::semicolon_outside_block)]
+
+macro_rules! m {
+ (()) => {
+ ()
+ };
+ (0) => {{
+ 0
+ };};
+ (1) => {{
+ 1;
+ }};
+ (2) => {{
+ 2;
+ }};
+}
+
+fn unit_fn_block() {
+ ()
+}
+
+#[rustfmt::skip]
+fn main() {
+ { unit_fn_block() }
+ unsafe { unit_fn_block() }
+
+ {
+ unit_fn_block()
+ }
+
+ { unit_fn_block() };
+ unsafe { unit_fn_block() };
+
+ { unit_fn_block() };
+ unsafe { unit_fn_block() };
+
+ { unit_fn_block(); };
+ unsafe { unit_fn_block(); };
+
+ {
+ unit_fn_block();
+ unit_fn_block()
+ };
+ {
+ unit_fn_block();
+ unit_fn_block()
+ };
+ {
+ unit_fn_block();
+ unit_fn_block();
+ };
+
+ { m!(()) };
+ { m!(()) };
+ { m!(()); };
+ m!(0);
+ m!(1);
+ m!(2);
+
+ for _ in [()] {
+ unit_fn_block();
+ }
+ for _ in [()] {
+ unit_fn_block()
+ }
+
+ let _d = || {
+ unit_fn_block();
+ };
+ let _d = || {
+ unit_fn_block()
+ };
+
+ { unit_fn_block(); };
+
+ unit_fn_block()
+}
diff --git a/src/tools/clippy/tests/ui/semicolon_outside_block.rs b/src/tools/clippy/tests/ui/semicolon_outside_block.rs
new file mode 100644
index 000000000..7ce46431f
--- /dev/null
+++ b/src/tools/clippy/tests/ui/semicolon_outside_block.rs
@@ -0,0 +1,85 @@
+// run-rustfix
+#![allow(
+ unused,
+ clippy::unused_unit,
+ clippy::unnecessary_operation,
+ clippy::no_effect,
+ clippy::single_element_loop
+)]
+#![warn(clippy::semicolon_outside_block)]
+
+macro_rules! m {
+ (()) => {
+ ()
+ };
+ (0) => {{
+ 0
+ };};
+ (1) => {{
+ 1;
+ }};
+ (2) => {{
+ 2;
+ }};
+}
+
+fn unit_fn_block() {
+ ()
+}
+
+#[rustfmt::skip]
+fn main() {
+ { unit_fn_block() }
+ unsafe { unit_fn_block() }
+
+ {
+ unit_fn_block()
+ }
+
+ { unit_fn_block() };
+ unsafe { unit_fn_block() };
+
+ { unit_fn_block(); }
+ unsafe { unit_fn_block(); }
+
+ { unit_fn_block(); };
+ unsafe { unit_fn_block(); };
+
+ {
+ unit_fn_block();
+ unit_fn_block()
+ };
+ {
+ unit_fn_block();
+ unit_fn_block();
+ }
+ {
+ unit_fn_block();
+ unit_fn_block();
+ };
+
+ { m!(()) };
+ { m!(()); }
+ { m!(()); };
+ m!(0);
+ m!(1);
+ m!(2);
+
+ for _ in [()] {
+ unit_fn_block();
+ }
+ for _ in [()] {
+ unit_fn_block()
+ }
+
+ let _d = || {
+ unit_fn_block();
+ };
+ let _d = || {
+ unit_fn_block()
+ };
+
+ { unit_fn_block(); };
+
+ unit_fn_block()
+}
diff --git a/src/tools/clippy/tests/ui/semicolon_outside_block.stderr b/src/tools/clippy/tests/ui/semicolon_outside_block.stderr
new file mode 100644
index 000000000..dcc102e60
--- /dev/null
+++ b/src/tools/clippy/tests/ui/semicolon_outside_block.stderr
@@ -0,0 +1,54 @@
+error: consider moving the `;` outside the block for consistent formatting
+ --> $DIR/semicolon_outside_block.rs:42:5
+ |
+LL | { unit_fn_block(); }
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::semicolon-outside-block` implied by `-D warnings`
+help: put the `;` here
+ |
+LL - { unit_fn_block(); }
+LL + { unit_fn_block() };
+ |
+
+error: consider moving the `;` outside the block for consistent formatting
+ --> $DIR/semicolon_outside_block.rs:43:5
+ |
+LL | unsafe { unit_fn_block(); }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: put the `;` here
+ |
+LL - unsafe { unit_fn_block(); }
+LL + unsafe { unit_fn_block() };
+ |
+
+error: consider moving the `;` outside the block for consistent formatting
+ --> $DIR/semicolon_outside_block.rs:52:5
+ |
+LL | / {
+LL | | unit_fn_block();
+LL | | unit_fn_block();
+LL | | }
+ | |_____^
+ |
+help: put the `;` here
+ |
+LL ~ unit_fn_block()
+LL ~ };
+ |
+
+error: consider moving the `;` outside the block for consistent formatting
+ --> $DIR/semicolon_outside_block.rs:62:5
+ |
+LL | { m!(()); }
+ | ^^^^^^^^^^^
+ |
+help: put the `;` here
+ |
+LL - { m!(()); }
+LL + { m!(()) };
+ |
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui/single_element_loop.fixed b/src/tools/clippy/tests/ui/single_element_loop.fixed
index 63d31ff83..a0dcc0172 100644
--- a/src/tools/clippy/tests/ui/single_element_loop.fixed
+++ b/src/tools/clippy/tests/ui/single_element_loop.fixed
@@ -33,4 +33,31 @@ fn main() {
let item = 0..5;
dbg!(item);
}
+
+ // should not lint (issue #10018)
+ for e in [42] {
+ if e > 0 {
+ continue;
+ }
+ }
+
+ // should not lint (issue #10018)
+ for e in [42] {
+ if e > 0 {
+ break;
+ }
+ }
+
+ // should lint (issue #10018)
+ {
+ let _ = 42;
+ let _f = |n: u32| {
+ for i in 0..n {
+ if i > 10 {
+ dbg!(i);
+ break;
+ }
+ }
+ };
+ }
}
diff --git a/src/tools/clippy/tests/ui/single_element_loop.rs b/src/tools/clippy/tests/ui/single_element_loop.rs
index 2cda5a329..bc014035c 100644
--- a/src/tools/clippy/tests/ui/single_element_loop.rs
+++ b/src/tools/clippy/tests/ui/single_element_loop.rs
@@ -27,4 +27,30 @@ fn main() {
for item in [0..5].into_iter() {
dbg!(item);
}
+
+ // should not lint (issue #10018)
+ for e in [42] {
+ if e > 0 {
+ continue;
+ }
+ }
+
+ // should not lint (issue #10018)
+ for e in [42] {
+ if e > 0 {
+ break;
+ }
+ }
+
+ // should lint (issue #10018)
+ for _ in [42] {
+ let _f = |n: u32| {
+ for i in 0..n {
+ if i > 10 {
+ dbg!(i);
+ break;
+ }
+ }
+ };
+ }
}
diff --git a/src/tools/clippy/tests/ui/single_element_loop.stderr b/src/tools/clippy/tests/ui/single_element_loop.stderr
index 0aeb8da1a..14437a597 100644
--- a/src/tools/clippy/tests/ui/single_element_loop.stderr
+++ b/src/tools/clippy/tests/ui/single_element_loop.stderr
@@ -95,5 +95,32 @@ LL + dbg!(item);
LL + }
|
-error: aborting due to 6 previous errors
+error: for loop over a single element
+ --> $DIR/single_element_loop.rs:46:5
+ |
+LL | / for _ in [42] {
+LL | | let _f = |n: u32| {
+LL | | for i in 0..n {
+LL | | if i > 10 {
+... |
+LL | | };
+LL | | }
+ | |_____^
+ |
+help: try
+ |
+LL ~ {
+LL + let _ = 42;
+LL + let _f = |n: u32| {
+LL + for i in 0..n {
+LL + if i > 10 {
+LL + dbg!(i);
+LL + break;
+LL + }
+LL + }
+LL + };
+LL + }
+ |
+
+error: aborting due to 7 previous errors
diff --git a/src/tools/clippy/tests/ui/size_of_ref.rs b/src/tools/clippy/tests/ui/size_of_ref.rs
new file mode 100644
index 000000000..1e83ab829
--- /dev/null
+++ b/src/tools/clippy/tests/ui/size_of_ref.rs
@@ -0,0 +1,27 @@
+#![allow(unused)]
+#![warn(clippy::size_of_ref)]
+
+use std::mem::size_of_val;
+
+fn main() {
+ let x = 5;
+ let y = &x;
+
+ size_of_val(&x); // no lint
+ size_of_val(y); // no lint
+
+ size_of_val(&&x);
+ size_of_val(&y);
+}
+
+struct S {
+ field: u32,
+ data: Vec<u8>,
+}
+
+impl S {
+ /// Get size of object including `self`, in bytes.
+ pub fn size(&self) -> usize {
+ std::mem::size_of_val(&self) + (std::mem::size_of::<u8>() * self.data.capacity())
+ }
+}
diff --git a/src/tools/clippy/tests/ui/size_of_ref.stderr b/src/tools/clippy/tests/ui/size_of_ref.stderr
new file mode 100644
index 000000000..d4c13ac32
--- /dev/null
+++ b/src/tools/clippy/tests/ui/size_of_ref.stderr
@@ -0,0 +1,27 @@
+error: argument to `std::mem::size_of_val()` is a reference to a reference
+ --> $DIR/size_of_ref.rs:13:5
+ |
+LL | size_of_val(&&x);
+ | ^^^^^^^^^^^^^^^^
+ |
+ = help: dereference the argument to `std::mem::size_of_val()` to get the size of the value instead of the size of the reference-type
+ = note: `-D clippy::size-of-ref` implied by `-D warnings`
+
+error: argument to `std::mem::size_of_val()` is a reference to a reference
+ --> $DIR/size_of_ref.rs:14:5
+ |
+LL | size_of_val(&y);
+ | ^^^^^^^^^^^^^^^
+ |
+ = help: dereference the argument to `std::mem::size_of_val()` to get the size of the value instead of the size of the reference-type
+
+error: argument to `std::mem::size_of_val()` is a reference to a reference
+ --> $DIR/size_of_ref.rs:25:9
+ |
+LL | std::mem::size_of_val(&self) + (std::mem::size_of::<u8>() * self.data.capacity())
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: dereference the argument to `std::mem::size_of_val()` to get the size of the value instead of the size of the reference-type
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/string_lit_as_bytes.fixed b/src/tools/clippy/tests/ui/string_lit_as_bytes.fixed
index df2256e4f..506187fc1 100644
--- a/src/tools/clippy/tests/ui/string_lit_as_bytes.fixed
+++ b/src/tools/clippy/tests/ui/string_lit_as_bytes.fixed
@@ -25,6 +25,12 @@ fn str_lit_as_bytes() {
let includestr = include_bytes!("string_lit_as_bytes.rs");
let _ = b"string with newline\t\n";
+
+ let _ = match "x".as_bytes() {
+ b"xx" => 0,
+ [b'x', ..] => 1,
+ _ => 2,
+ };
}
fn main() {}
diff --git a/src/tools/clippy/tests/ui/string_lit_as_bytes.rs b/src/tools/clippy/tests/ui/string_lit_as_bytes.rs
index c6bf8f732..2c339f1dd 100644
--- a/src/tools/clippy/tests/ui/string_lit_as_bytes.rs
+++ b/src/tools/clippy/tests/ui/string_lit_as_bytes.rs
@@ -25,6 +25,12 @@ fn str_lit_as_bytes() {
let includestr = include_str!("string_lit_as_bytes.rs").as_bytes();
let _ = "string with newline\t\n".as_bytes();
+
+ let _ = match "x".as_bytes() {
+ b"xx" => 0,
+ [b'x', ..] => 1,
+ _ => 2,
+ };
}
fn main() {}
diff --git a/src/tools/clippy/tests/ui/suspicious_to_owned.stderr b/src/tools/clippy/tests/ui/suspicious_to_owned.stderr
index ae1aec34d..dec3f50d6 100644
--- a/src/tools/clippy/tests/ui/suspicious_to_owned.stderr
+++ b/src/tools/clippy/tests/ui/suspicious_to_owned.stderr
@@ -1,4 +1,4 @@
-error: this `to_owned` call clones the std::borrow::Cow<'_, str> itself and does not cause the std::borrow::Cow<'_, str> contents to become owned
+error: this `to_owned` call clones the Cow<'_, str> itself and does not cause the Cow<'_, str> contents to become owned
--> $DIR/suspicious_to_owned.rs:16:13
|
LL | let _ = cow.to_owned();
@@ -6,19 +6,19 @@ LL | let _ = cow.to_owned();
|
= note: `-D clippy::suspicious-to-owned` implied by `-D warnings`
-error: this `to_owned` call clones the std::borrow::Cow<'_, [char; 3]> itself and does not cause the std::borrow::Cow<'_, [char; 3]> contents to become owned
+error: this `to_owned` call clones the Cow<'_, [char; 3]> itself and does not cause the Cow<'_, [char; 3]> contents to become owned
--> $DIR/suspicious_to_owned.rs:26:13
|
LL | let _ = cow.to_owned();
| ^^^^^^^^^^^^^^ help: consider using, depending on intent: `cow.clone()` or `cow.into_owned()`
-error: this `to_owned` call clones the std::borrow::Cow<'_, std::vec::Vec<char>> itself and does not cause the std::borrow::Cow<'_, std::vec::Vec<char>> contents to become owned
+error: this `to_owned` call clones the Cow<'_, Vec<char>> itself and does not cause the Cow<'_, Vec<char>> contents to become owned
--> $DIR/suspicious_to_owned.rs:36:13
|
LL | let _ = cow.to_owned();
| ^^^^^^^^^^^^^^ help: consider using, depending on intent: `cow.clone()` or `cow.into_owned()`
-error: this `to_owned` call clones the std::borrow::Cow<'_, str> itself and does not cause the std::borrow::Cow<'_, str> contents to become owned
+error: this `to_owned` call clones the Cow<'_, str> itself and does not cause the Cow<'_, str> contents to become owned
--> $DIR/suspicious_to_owned.rs:46:13
|
LL | let _ = cow.to_owned();
diff --git a/src/tools/clippy/tests/ui/transmute_null_to_fn.rs b/src/tools/clippy/tests/ui/transmute_null_to_fn.rs
new file mode 100644
index 000000000..b3ea3d903
--- /dev/null
+++ b/src/tools/clippy/tests/ui/transmute_null_to_fn.rs
@@ -0,0 +1,28 @@
+#![allow(dead_code)]
+#![warn(clippy::transmute_null_to_fn)]
+#![allow(clippy::zero_ptr)]
+
+// Easy to lint because these only span one line.
+fn one_liners() {
+ unsafe {
+ let _: fn() = std::mem::transmute(0 as *const ());
+ let _: fn() = std::mem::transmute(std::ptr::null::<()>());
+ }
+}
+
+pub const ZPTR: *const usize = 0 as *const _;
+pub const NOT_ZPTR: *const usize = 1 as *const _;
+
+fn transmute_const() {
+ unsafe {
+ // Should raise a lint.
+ let _: fn() = std::mem::transmute(ZPTR);
+ // Should NOT raise a lint.
+ let _: fn() = std::mem::transmute(NOT_ZPTR);
+ }
+}
+
+fn main() {
+ one_liners();
+ transmute_const();
+}
diff --git a/src/tools/clippy/tests/ui/transmute_null_to_fn.stderr b/src/tools/clippy/tests/ui/transmute_null_to_fn.stderr
new file mode 100644
index 000000000..f0c65497d
--- /dev/null
+++ b/src/tools/clippy/tests/ui/transmute_null_to_fn.stderr
@@ -0,0 +1,27 @@
+error: transmuting a known null pointer into a function pointer
+ --> $DIR/transmute_null_to_fn.rs:8:23
+ |
+LL | let _: fn() = std::mem::transmute(0 as *const ());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior
+ |
+ = help: try wrapping your function pointer type in `Option<T>` instead, and using `None` as a null pointer value
+ = note: `-D clippy::transmute-null-to-fn` implied by `-D warnings`
+
+error: transmuting a known null pointer into a function pointer
+ --> $DIR/transmute_null_to_fn.rs:9:23
+ |
+LL | let _: fn() = std::mem::transmute(std::ptr::null::<()>());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior
+ |
+ = help: try wrapping your function pointer type in `Option<T>` instead, and using `None` as a null pointer value
+
+error: transmuting a known null pointer into a function pointer
+ --> $DIR/transmute_null_to_fn.rs:19:23
+ |
+LL | let _: fn() = std::mem::transmute(ZPTR);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior
+ |
+ = help: try wrapping your function pointer type in `Option<T>` instead, and using `None` as a null pointer value
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed
index 96cc08779..52b5343c3 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed
+++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed
@@ -26,4 +26,7 @@ fn main() {
panic!("p4 {var}");
}
}
+
+ assert!(var == 1, "p5 {}", var);
+ debug_assert!(var == 1, "p6 {}", var);
}
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed
index faf8ca4d3..ee72065e2 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed
+++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed
@@ -26,4 +26,7 @@ fn main() {
panic!("p4 {var}");
}
}
+
+ assert!(var == 1, "p5 {var}");
+ debug_assert!(var == 1, "p6 {var}");
}
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.stderr b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.stderr
index 0f09c45f4..fc7b12508 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.stderr
+++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.stderr
@@ -47,5 +47,29 @@ LL - panic!("p3 {var}", var = var);
LL + panic!("p3 {var}");
|
-error: aborting due to 4 previous errors
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args_panic.rs:30:5
+ |
+LL | assert!(var == 1, "p5 {}", var);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - assert!(var == 1, "p5 {}", var);
+LL + assert!(var == 1, "p5 {var}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args_panic.rs:31:5
+ |
+LL | debug_assert!(var == 1, "p6 {}", var);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - debug_assert!(var == 1, "p6 {}", var);
+LL + debug_assert!(var == 1, "p6 {var}");
+ |
+
+error: aborting due to 6 previous errors
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs b/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs
index 6421c5bbe..b4a0a0f49 100644
--- a/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs
+++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs
@@ -26,4 +26,7 @@ fn main() {
panic!("p4 {var}");
}
}
+
+ assert!(var == 1, "p5 {}", var);
+ debug_assert!(var == 1, "p6 {}", var);
}
diff --git a/src/tools/clippy/tests/ui/unnecessary_clone.stderr b/src/tools/clippy/tests/ui/unnecessary_clone.stderr
index 94cc7777a..6022d9fa4 100644
--- a/src/tools/clippy/tests/ui/unnecessary_clone.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_clone.stderr
@@ -38,13 +38,13 @@ LL | t.clone();
|
= note: `-D clippy::clone-on-copy` implied by `-D warnings`
-error: using `clone` on type `std::option::Option<T>` which implements the `Copy` trait
+error: using `clone` on type `Option<T>` which implements the `Copy` trait
--> $DIR/unnecessary_clone.rs:42:5
|
LL | Some(t).clone();
| ^^^^^^^^^^^^^^^ help: try removing the `clone` call: `Some(t)`
-error: using `clone` on a double-reference; this will copy the reference of type `&std::vec::Vec<i32>` instead of cloning the inner type
+error: using `clone` on a double-reference; this will copy the reference of type `&Vec<i32>` instead of cloning the inner type
--> $DIR/unnecessary_clone.rs:48:22
|
LL | let z: &Vec<_> = y.clone();
@@ -57,10 +57,10 @@ LL | let z: &Vec<_> = &(*y).clone();
| ~~~~~~~~~~~~~
help: or try being explicit if you are sure, that you want to clone a reference
|
-LL | let z: &Vec<_> = <&std::vec::Vec<i32>>::clone(y);
- | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+LL | let z: &Vec<_> = <&Vec<i32>>::clone(y);
+ | ~~~~~~~~~~~~~~~~~~~~~
-error: using `clone` on type `many_derefs::E` which implements the `Copy` trait
+error: using `clone` on type `E` which implements the `Copy` trait
--> $DIR/unnecessary_clone.rs:84:20
|
LL | let _: E = a.clone();
diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
index ddeda795f..345f6d604 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
@@ -454,3 +454,23 @@ mod issue_9771b {
Key(v.to_vec())
}
}
+
+// This is a watered down version of the code in: https://github.com/oxigraph/rio
+// The ICE is triggered by the call to `to_owned` on this line:
+// https://github.com/oxigraph/rio/blob/66635b9ff8e5423e58932353fa40d6e64e4820f7/testsuite/src/parser_evaluator.rs#L116
+mod issue_10021 {
+ #![allow(unused)]
+
+ pub struct Iri<T>(T);
+
+ impl<T: AsRef<str>> Iri<T> {
+ pub fn parse(iri: T) -> Result<Self, ()> {
+ unimplemented!()
+ }
+ }
+
+ pub fn parse_w3c_rdf_test_file(url: &str) -> Result<(), ()> {
+ let base_iri = Iri::parse(url.to_owned())?;
+ Ok(())
+ }
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
index 95d257673..7eb53df39 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
@@ -454,3 +454,23 @@ mod issue_9771b {
Key(v.to_vec())
}
}
+
+// This is a watered down version of the code in: https://github.com/oxigraph/rio
+// The ICE is triggered by the call to `to_owned` on this line:
+// https://github.com/oxigraph/rio/blob/66635b9ff8e5423e58932353fa40d6e64e4820f7/testsuite/src/parser_evaluator.rs#L116
+mod issue_10021 {
+ #![allow(unused)]
+
+ pub struct Iri<T>(T);
+
+ impl<T: AsRef<str>> Iri<T> {
+ pub fn parse(iri: T) -> Result<Self, ()> {
+ unimplemented!()
+ }
+ }
+
+ pub fn parse_w3c_rdf_test_file(url: &str) -> Result<(), ()> {
+ let base_iri = Iri::parse(url.to_owned())?;
+ Ok(())
+ }
+}
diff --git a/src/tools/clippy/tests/ui/unused_self.rs b/src/tools/clippy/tests/ui/unused_self.rs
index 92e8e1dba..55bd56071 100644
--- a/src/tools/clippy/tests/ui/unused_self.rs
+++ b/src/tools/clippy/tests/ui/unused_self.rs
@@ -60,6 +60,16 @@ mod unused_self_allow {
// shouldn't trigger for public methods
pub fn unused_self_move(self) {}
}
+
+ pub struct E;
+
+ impl E {
+ // shouldn't trigger if body contains todo!()
+ pub fn unused_self_todo(self) {
+ let x = 42;
+ todo!()
+ }
+ }
}
pub use unused_self_allow::D;
diff --git a/src/tools/clippy/tests/ui/unused_self.stderr b/src/tools/clippy/tests/ui/unused_self.stderr
index 23186122a..919f9b6ef 100644
--- a/src/tools/clippy/tests/ui/unused_self.stderr
+++ b/src/tools/clippy/tests/ui/unused_self.stderr
@@ -4,7 +4,7 @@ error: unused `self` argument
LL | fn unused_self_move(self) {}
| ^^^^
|
- = help: consider refactoring to a associated function
+ = help: consider refactoring to an associated function
= note: `-D clippy::unused-self` implied by `-D warnings`
error: unused `self` argument
@@ -13,7 +13,7 @@ error: unused `self` argument
LL | fn unused_self_ref(&self) {}
| ^^^^^
|
- = help: consider refactoring to a associated function
+ = help: consider refactoring to an associated function
error: unused `self` argument
--> $DIR/unused_self.rs:13:32
@@ -21,7 +21,7 @@ error: unused `self` argument
LL | fn unused_self_mut_ref(&mut self) {}
| ^^^^^^^^^
|
- = help: consider refactoring to a associated function
+ = help: consider refactoring to an associated function
error: unused `self` argument
--> $DIR/unused_self.rs:14:32
@@ -29,7 +29,7 @@ error: unused `self` argument
LL | fn unused_self_pin_ref(self: Pin<&Self>) {}
| ^^^^
|
- = help: consider refactoring to a associated function
+ = help: consider refactoring to an associated function
error: unused `self` argument
--> $DIR/unused_self.rs:15:36
@@ -37,7 +37,7 @@ error: unused `self` argument
LL | fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {}
| ^^^^
|
- = help: consider refactoring to a associated function
+ = help: consider refactoring to an associated function
error: unused `self` argument
--> $DIR/unused_self.rs:16:35
@@ -45,7 +45,7 @@ error: unused `self` argument
LL | fn unused_self_pin_nested(self: Pin<Arc<Self>>) {}
| ^^^^
|
- = help: consider refactoring to a associated function
+ = help: consider refactoring to an associated function
error: unused `self` argument
--> $DIR/unused_self.rs:17:28
@@ -53,7 +53,7 @@ error: unused `self` argument
LL | fn unused_self_box(self: Box<Self>) {}
| ^^^^
|
- = help: consider refactoring to a associated function
+ = help: consider refactoring to an associated function
error: unused `self` argument
--> $DIR/unused_self.rs:18:40
@@ -61,7 +61,7 @@ error: unused `self` argument
LL | fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 {
| ^^^^^
|
- = help: consider refactoring to a associated function
+ = help: consider refactoring to an associated function
error: unused `self` argument
--> $DIR/unused_self.rs:21:37
@@ -69,7 +69,7 @@ error: unused `self` argument
LL | fn unused_self_class_method(&self) {
| ^^^^^
|
- = help: consider refactoring to a associated function
+ = help: consider refactoring to an associated function
error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/useless_conversion.fixed b/src/tools/clippy/tests/ui/useless_conversion.fixed
index 70ff08f36..94b206d8e 100644
--- a/src/tools/clippy/tests/ui/useless_conversion.fixed
+++ b/src/tools/clippy/tests/ui/useless_conversion.fixed
@@ -33,12 +33,71 @@ fn test_issue_3913() -> Result<(), std::io::Error> {
Ok(())
}
-fn test_issue_5833() -> Result<(), ()> {
+fn dont_lint_into_iter_on_immutable_local_implementing_iterator_in_expr() {
let text = "foo\r\nbar\n\nbaz\n";
let lines = text.lines();
if Some("ok") == lines.into_iter().next() {}
+}
- Ok(())
+fn lint_into_iter_on_mutable_local_implementing_iterator_in_expr() {
+ let text = "foo\r\nbar\n\nbaz\n";
+ let mut lines = text.lines();
+ if Some("ok") == lines.next() {}
+}
+
+fn lint_into_iter_on_expr_implementing_iterator() {
+ let text = "foo\r\nbar\n\nbaz\n";
+ let mut lines = text.lines();
+ if Some("ok") == lines.next() {}
+}
+
+fn lint_into_iter_on_expr_implementing_iterator_2() {
+ let text = "foo\r\nbar\n\nbaz\n";
+ if Some("ok") == text.lines().next() {}
+}
+
+#[allow(const_item_mutation)]
+fn lint_into_iter_on_const_implementing_iterator() {
+ const NUMBERS: std::ops::Range<i32> = 0..10;
+ let _ = NUMBERS.next();
+}
+
+fn lint_into_iter_on_const_implementing_iterator_2() {
+ const NUMBERS: std::ops::Range<i32> = 0..10;
+ let mut n = NUMBERS;
+ n.next();
+}
+
+#[derive(Clone, Copy)]
+struct CopiableCounter {
+ counter: u32,
+}
+
+impl Iterator for CopiableCounter {
+ type Item = u32;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ self.counter = self.counter.wrapping_add(1);
+ Some(self.counter)
+ }
+}
+
+fn dont_lint_into_iter_on_copy_iter() {
+ let mut c = CopiableCounter { counter: 0 };
+ assert_eq!(c.into_iter().next(), Some(1));
+ assert_eq!(c.into_iter().next(), Some(1));
+ assert_eq!(c.next(), Some(1));
+ assert_eq!(c.next(), Some(2));
+}
+
+fn dont_lint_into_iter_on_static_copy_iter() {
+ static mut C: CopiableCounter = CopiableCounter { counter: 0 };
+ unsafe {
+ assert_eq!(C.into_iter().next(), Some(1));
+ assert_eq!(C.into_iter().next(), Some(1));
+ assert_eq!(C.next(), Some(1));
+ assert_eq!(C.next(), Some(2));
+ }
}
fn main() {
@@ -46,7 +105,15 @@ fn main() {
test_generic2::<i32, i32>(10i32);
test_questionmark().unwrap();
test_issue_3913().unwrap();
- test_issue_5833().unwrap();
+
+ dont_lint_into_iter_on_immutable_local_implementing_iterator_in_expr();
+ lint_into_iter_on_mutable_local_implementing_iterator_in_expr();
+ lint_into_iter_on_expr_implementing_iterator();
+ lint_into_iter_on_expr_implementing_iterator_2();
+ lint_into_iter_on_const_implementing_iterator();
+ lint_into_iter_on_const_implementing_iterator_2();
+ dont_lint_into_iter_on_copy_iter();
+ dont_lint_into_iter_on_static_copy_iter();
let _: String = "foo".into();
let _: String = From::from("foo");
diff --git a/src/tools/clippy/tests/ui/useless_conversion.rs b/src/tools/clippy/tests/ui/useless_conversion.rs
index f2444a8f4..c7ae92794 100644
--- a/src/tools/clippy/tests/ui/useless_conversion.rs
+++ b/src/tools/clippy/tests/ui/useless_conversion.rs
@@ -33,12 +33,71 @@ fn test_issue_3913() -> Result<(), std::io::Error> {
Ok(())
}
-fn test_issue_5833() -> Result<(), ()> {
+fn dont_lint_into_iter_on_immutable_local_implementing_iterator_in_expr() {
let text = "foo\r\nbar\n\nbaz\n";
let lines = text.lines();
if Some("ok") == lines.into_iter().next() {}
+}
- Ok(())
+fn lint_into_iter_on_mutable_local_implementing_iterator_in_expr() {
+ let text = "foo\r\nbar\n\nbaz\n";
+ let mut lines = text.lines();
+ if Some("ok") == lines.into_iter().next() {}
+}
+
+fn lint_into_iter_on_expr_implementing_iterator() {
+ let text = "foo\r\nbar\n\nbaz\n";
+ let mut lines = text.lines().into_iter();
+ if Some("ok") == lines.next() {}
+}
+
+fn lint_into_iter_on_expr_implementing_iterator_2() {
+ let text = "foo\r\nbar\n\nbaz\n";
+ if Some("ok") == text.lines().into_iter().next() {}
+}
+
+#[allow(const_item_mutation)]
+fn lint_into_iter_on_const_implementing_iterator() {
+ const NUMBERS: std::ops::Range<i32> = 0..10;
+ let _ = NUMBERS.into_iter().next();
+}
+
+fn lint_into_iter_on_const_implementing_iterator_2() {
+ const NUMBERS: std::ops::Range<i32> = 0..10;
+ let mut n = NUMBERS.into_iter();
+ n.next();
+}
+
+#[derive(Clone, Copy)]
+struct CopiableCounter {
+ counter: u32,
+}
+
+impl Iterator for CopiableCounter {
+ type Item = u32;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ self.counter = self.counter.wrapping_add(1);
+ Some(self.counter)
+ }
+}
+
+fn dont_lint_into_iter_on_copy_iter() {
+ let mut c = CopiableCounter { counter: 0 };
+ assert_eq!(c.into_iter().next(), Some(1));
+ assert_eq!(c.into_iter().next(), Some(1));
+ assert_eq!(c.next(), Some(1));
+ assert_eq!(c.next(), Some(2));
+}
+
+fn dont_lint_into_iter_on_static_copy_iter() {
+ static mut C: CopiableCounter = CopiableCounter { counter: 0 };
+ unsafe {
+ assert_eq!(C.into_iter().next(), Some(1));
+ assert_eq!(C.into_iter().next(), Some(1));
+ assert_eq!(C.next(), Some(1));
+ assert_eq!(C.next(), Some(2));
+ }
}
fn main() {
@@ -46,7 +105,15 @@ fn main() {
test_generic2::<i32, i32>(10i32);
test_questionmark().unwrap();
test_issue_3913().unwrap();
- test_issue_5833().unwrap();
+
+ dont_lint_into_iter_on_immutable_local_implementing_iterator_in_expr();
+ lint_into_iter_on_mutable_local_implementing_iterator_in_expr();
+ lint_into_iter_on_expr_implementing_iterator();
+ lint_into_iter_on_expr_implementing_iterator_2();
+ lint_into_iter_on_const_implementing_iterator();
+ lint_into_iter_on_const_implementing_iterator_2();
+ dont_lint_into_iter_on_copy_iter();
+ dont_lint_into_iter_on_static_copy_iter();
let _: String = "foo".into();
let _: String = From::from("foo");
diff --git a/src/tools/clippy/tests/ui/useless_conversion.stderr b/src/tools/clippy/tests/ui/useless_conversion.stderr
index 65ee3807f..be067c684 100644
--- a/src/tools/clippy/tests/ui/useless_conversion.stderr
+++ b/src/tools/clippy/tests/ui/useless_conversion.stderr
@@ -22,71 +22,101 @@ error: useless conversion to the same type: `i32`
LL | let _: i32 = 0i32.into();
| ^^^^^^^^^^^ help: consider removing `.into()`: `0i32`
+error: useless conversion to the same type: `std::str::Lines<'_>`
+ --> $DIR/useless_conversion.rs:45:22
+ |
+LL | if Some("ok") == lines.into_iter().next() {}
+ | ^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `lines`
+
+error: useless conversion to the same type: `std::str::Lines<'_>`
+ --> $DIR/useless_conversion.rs:50:21
+ |
+LL | let mut lines = text.lines().into_iter();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `text.lines()`
+
+error: useless conversion to the same type: `std::str::Lines<'_>`
+ --> $DIR/useless_conversion.rs:56:22
+ |
+LL | if Some("ok") == text.lines().into_iter().next() {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `text.lines()`
+
+error: useless conversion to the same type: `std::ops::Range<i32>`
+ --> $DIR/useless_conversion.rs:62:13
+ |
+LL | let _ = NUMBERS.into_iter().next();
+ | ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `NUMBERS`
+
+error: useless conversion to the same type: `std::ops::Range<i32>`
+ --> $DIR/useless_conversion.rs:67:17
+ |
+LL | let mut n = NUMBERS.into_iter();
+ | ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `NUMBERS`
+
error: useless conversion to the same type: `std::string::String`
- --> $DIR/useless_conversion.rs:61:21
+ --> $DIR/useless_conversion.rs:128:21
|
LL | let _: String = "foo".to_string().into();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `"foo".to_string()`
error: useless conversion to the same type: `std::string::String`
- --> $DIR/useless_conversion.rs:62:21
+ --> $DIR/useless_conversion.rs:129:21
|
LL | let _: String = From::from("foo".to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `From::from()`: `"foo".to_string()`
error: useless conversion to the same type: `std::string::String`
- --> $DIR/useless_conversion.rs:63:13
+ --> $DIR/useless_conversion.rs:130:13
|
LL | let _ = String::from("foo".to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `"foo".to_string()`
error: useless conversion to the same type: `std::string::String`
- --> $DIR/useless_conversion.rs:64:13
+ --> $DIR/useless_conversion.rs:131:13
|
LL | let _ = String::from(format!("A: {:04}", 123));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `format!("A: {:04}", 123)`
error: useless conversion to the same type: `std::str::Lines<'_>`
- --> $DIR/useless_conversion.rs:65:13
+ --> $DIR/useless_conversion.rs:132:13
|
LL | let _ = "".lines().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()`
error: useless conversion to the same type: `std::vec::IntoIter<i32>`
- --> $DIR/useless_conversion.rs:66:13
+ --> $DIR/useless_conversion.rs:133:13
|
LL | let _ = vec![1, 2, 3].into_iter().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![1, 2, 3].into_iter()`
error: useless conversion to the same type: `std::string::String`
- --> $DIR/useless_conversion.rs:67:21
+ --> $DIR/useless_conversion.rs:134:21
|
LL | let _: String = format!("Hello {}", "world").into();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `format!("Hello {}", "world")`
error: useless conversion to the same type: `i32`
- --> $DIR/useless_conversion.rs:72:13
+ --> $DIR/useless_conversion.rs:139:13
|
LL | let _ = i32::from(a + b) * 3;
| ^^^^^^^^^^^^^^^^ help: consider removing `i32::from()`: `(a + b)`
error: useless conversion to the same type: `Foo<'a'>`
- --> $DIR/useless_conversion.rs:78:23
+ --> $DIR/useless_conversion.rs:145:23
|
LL | let _: Foo<'a'> = s2.into();
| ^^^^^^^^^ help: consider removing `.into()`: `s2`
error: useless conversion to the same type: `Foo<'a'>`
- --> $DIR/useless_conversion.rs:80:13
+ --> $DIR/useless_conversion.rs:147:13
|
LL | let _ = Foo::<'a'>::from(s3);
| ^^^^^^^^^^^^^^^^^^^^ help: consider removing `Foo::<'a'>::from()`: `s3`
error: useless conversion to the same type: `std::vec::IntoIter<Foo<'a'>>`
- --> $DIR/useless_conversion.rs:82:13
+ --> $DIR/useless_conversion.rs:149:13
|
LL | let _ = vec![s4, s4, s4].into_iter().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![s4, s4, s4].into_iter()`
-error: aborting due to 14 previous errors
+error: aborting due to 19 previous errors
diff --git a/src/tools/clippy/tests/ui/wildcard_imports.fixed b/src/tools/clippy/tests/ui/wildcard_imports.fixed
index ef55f1c31..0baec6f0b 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports.fixed
+++ b/src/tools/clippy/tests/ui/wildcard_imports.fixed
@@ -5,7 +5,6 @@
// the 2015 edition here is needed because edition 2018 changed the module system
// (see https://doc.rust-lang.org/edition-guide/rust-2018/path-changes.html) which means the lint
// no longer detects some of the cases starting with Rust 2018.
-// FIXME: We should likely add another edition 2021 test case for this lint
#![warn(clippy::wildcard_imports)]
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
diff --git a/src/tools/clippy/tests/ui/wildcard_imports.rs b/src/tools/clippy/tests/ui/wildcard_imports.rs
index b81285142..db591d56a 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports.rs
+++ b/src/tools/clippy/tests/ui/wildcard_imports.rs
@@ -5,7 +5,6 @@
// the 2015 edition here is needed because edition 2018 changed the module system
// (see https://doc.rust-lang.org/edition-guide/rust-2018/path-changes.html) which means the lint
// no longer detects some of the cases starting with Rust 2018.
-// FIXME: We should likely add another edition 2021 test case for this lint
#![warn(clippy::wildcard_imports)]
#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
diff --git a/src/tools/clippy/tests/ui/wildcard_imports.stderr b/src/tools/clippy/tests/ui/wildcard_imports.stderr
index 626c1754f..6b469cdfc 100644
--- a/src/tools/clippy/tests/ui/wildcard_imports.stderr
+++ b/src/tools/clippy/tests/ui/wildcard_imports.stderr
@@ -1,5 +1,5 @@
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:16:5
+ --> $DIR/wildcard_imports.rs:15:5
|
LL | use crate::fn_mod::*;
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
@@ -7,85 +7,85 @@ LL | use crate::fn_mod::*;
= note: `-D clippy::wildcard-imports` implied by `-D warnings`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:17:5
+ --> $DIR/wildcard_imports.rs:16:5
|
LL | use crate::mod_mod::*;
| ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:18:5
+ --> $DIR/wildcard_imports.rs:17:5
|
LL | use crate::multi_fn_mod::*;
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:20:5
+ --> $DIR/wildcard_imports.rs:19:5
|
LL | use crate::struct_mod::*;
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:24:5
+ --> $DIR/wildcard_imports.rs:23:5
|
LL | use wildcard_imports_helper::inner::inner_for_self_import::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:25:5
+ --> $DIR/wildcard_imports.rs:24:5
|
LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:96:13
+ --> $DIR/wildcard_imports.rs:95:13
|
LL | use crate::fn_mod::*;
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:102:75
+ --> $DIR/wildcard_imports.rs:101:75
|
LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
| ^ help: try: `inner_extern_foo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:103:13
+ --> $DIR/wildcard_imports.rs:102:13
|
LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:114:20
+ --> $DIR/wildcard_imports.rs:113:20
|
LL | use self::{inner::*, inner2::*};
| ^^^^^^^^ help: try: `inner::inner_foo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:114:30
+ --> $DIR/wildcard_imports.rs:113:30
|
LL | use self::{inner::*, inner2::*};
| ^^^^^^^^^ help: try: `inner2::inner_bar`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:121:13
+ --> $DIR/wildcard_imports.rs:120:13
|
LL | use wildcard_imports_helper::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:150:9
+ --> $DIR/wildcard_imports.rs:149:9
|
LL | use crate::in_fn_test::*;
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:159:9
+ --> $DIR/wildcard_imports.rs:158:9
|
LL | use crate:: in_fn_test:: * ;
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:160:9
+ --> $DIR/wildcard_imports.rs:159:9
|
LL | use crate:: fn_mod::
| _________^
@@ -93,37 +93,37 @@ LL | | *;
| |_________^ help: try: `crate:: fn_mod::foo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:171:13
+ --> $DIR/wildcard_imports.rs:170:13
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:206:17
+ --> $DIR/wildcard_imports.rs:205:17
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::insidefoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:214:13
+ --> $DIR/wildcard_imports.rs:213:13
|
LL | use super_imports::*;
| ^^^^^^^^^^^^^^^^ help: try: `super_imports::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:223:17
+ --> $DIR/wildcard_imports.rs:222:17
|
LL | use super::super::*;
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:232:13
+ --> $DIR/wildcard_imports.rs:231:13
|
LL | use super::super::super_imports::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
error: usage of wildcard import
- --> $DIR/wildcard_imports.rs:240:13
+ --> $DIR/wildcard_imports.rs:239:13
|
LL | use super::*;
| ^^^^^^^^ help: try: `super::foofoo`
diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed
new file mode 100644
index 000000000..6d534a10e
--- /dev/null
+++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.fixed
@@ -0,0 +1,240 @@
+// revisions: edition2018 edition2021
+//[edition2018] edition:2018
+//[edition2021] edition:2021
+// run-rustfix
+// aux-build:wildcard_imports_helper.rs
+
+#![warn(clippy::wildcard_imports)]
+#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
+#![warn(unused_imports)]
+
+extern crate wildcard_imports_helper;
+
+use crate::fn_mod::foo;
+use crate::mod_mod::inner_mod;
+use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod};
+use crate::struct_mod::{A, inner_struct_mod};
+
+#[allow(unused_imports)]
+use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
+use wildcard_imports_helper::prelude::v1::*;
+use wildcard_imports_helper::{ExternA, extern_foo};
+
+use std::io::prelude::*;
+
+struct ReadFoo;
+
+impl Read for ReadFoo {
+ fn read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
+ Ok(0)
+ }
+}
+
+mod fn_mod {
+ pub fn foo() {}
+}
+
+mod mod_mod {
+ pub mod inner_mod {
+ pub fn foo() {}
+ }
+}
+
+mod multi_fn_mod {
+ pub fn multi_foo() {}
+ pub fn multi_bar() {}
+ pub fn multi_baz() {}
+ pub mod multi_inner_mod {
+ pub fn foo() {}
+ }
+}
+
+mod struct_mod {
+ pub struct A;
+ pub struct B;
+ pub mod inner_struct_mod {
+ pub struct C;
+ }
+
+ #[macro_export]
+ macro_rules! double_struct_import_test {
+ () => {
+ let _ = A;
+ };
+ }
+}
+
+fn main() {
+ foo();
+ multi_foo();
+ multi_bar();
+ multi_inner_mod::foo();
+ inner_mod::foo();
+ extern_foo();
+ inner_extern_bar();
+
+ let _ = A;
+ let _ = inner_struct_mod::C;
+ let _ = ExternA;
+ let _ = PreludeModAnywhere;
+
+ double_struct_import_test!();
+ double_struct_import_test!();
+}
+
+mod in_fn_test {
+ pub use self::inner_exported::*;
+ #[allow(unused_imports)]
+ pub(crate) use self::inner_exported2::*;
+
+ fn test_intern() {
+ use crate::fn_mod::foo;
+
+ foo();
+ }
+
+ fn test_extern() {
+ use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo};
+ use wildcard_imports_helper::{ExternA, extern_foo};
+
+ inner_for_self_import::inner_extern_foo();
+ inner_extern_foo();
+
+ extern_foo();
+
+ let _ = ExternA;
+ }
+
+ fn test_inner_nested() {
+ use self::{inner::inner_foo, inner2::inner_bar};
+
+ inner_foo();
+ inner_bar();
+ }
+
+ fn test_extern_reexported() {
+ use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported};
+
+ extern_exported();
+ let _ = ExternExportedStruct;
+ let _ = ExternExportedEnum::A;
+ }
+
+ mod inner_exported {
+ pub fn exported() {}
+ pub struct ExportedStruct;
+ pub enum ExportedEnum {
+ A,
+ }
+ }
+
+ mod inner_exported2 {
+ pub(crate) fn exported2() {}
+ }
+
+ mod inner {
+ pub fn inner_foo() {}
+ }
+
+ mod inner2 {
+ pub fn inner_bar() {}
+ }
+}
+
+fn test_reexported() {
+ use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported};
+
+ exported();
+ let _ = ExportedStruct;
+ let _ = ExportedEnum::A;
+}
+
+#[rustfmt::skip]
+fn test_weird_formatting() {
+ use crate:: in_fn_test::exported;
+ use crate:: fn_mod::foo;
+
+ exported();
+ foo();
+}
+
+mod super_imports {
+ fn foofoo() {}
+
+ mod should_be_replaced {
+ use super::foofoo;
+
+ fn with_super() {
+ let _ = foofoo();
+ }
+ }
+
+ mod test_should_pass {
+ use super::*;
+
+ fn with_super() {
+ let _ = foofoo();
+ }
+ }
+
+ mod test_should_pass_inside_function {
+ fn with_super_inside_function() {
+ use super::*;
+ let _ = foofoo();
+ }
+ }
+
+ mod test_should_pass_further_inside {
+ fn insidefoo() {}
+ mod inner {
+ use super::*;
+ fn with_super() {
+ let _ = insidefoo();
+ }
+ }
+ }
+
+ mod should_be_replaced_further_inside {
+ fn insidefoo() {}
+ mod inner {
+ use super::insidefoo;
+ fn with_super() {
+ let _ = insidefoo();
+ }
+ }
+ }
+
+ mod use_explicit_should_be_replaced {
+ use crate::super_imports::foofoo;
+
+ fn with_explicit() {
+ let _ = foofoo();
+ }
+ }
+
+ mod use_double_super_should_be_replaced {
+ mod inner {
+ use super::super::foofoo;
+
+ fn with_double_super() {
+ let _ = foofoo();
+ }
+ }
+ }
+
+ mod use_super_explicit_should_be_replaced {
+ use super::super::super_imports::foofoo;
+
+ fn with_super_explicit() {
+ let _ = foofoo();
+ }
+ }
+
+ mod attestation_should_be_replaced {
+ use super::foofoo;
+
+ fn with_explicit() {
+ let _ = foofoo();
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.stderr b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.stderr
new file mode 100644
index 000000000..acca9f651
--- /dev/null
+++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2018.stderr
@@ -0,0 +1,132 @@
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:13:5
+ |
+LL | use crate::fn_mod::*;
+ | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
+ |
+ = note: `-D clippy::wildcard-imports` implied by `-D warnings`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:14:5
+ |
+LL | use crate::mod_mod::*;
+ | ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:15:5
+ |
+LL | use crate::multi_fn_mod::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:16:5
+ |
+LL | use crate::struct_mod::*;
+ | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:19:5
+ |
+LL | use wildcard_imports_helper::inner::inner_for_self_import::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:21:5
+ |
+LL | use wildcard_imports_helper::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:91:13
+ |
+LL | use crate::fn_mod::*;
+ | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:97:75
+ |
+LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
+ | ^ help: try: `inner_extern_foo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:98:13
+ |
+LL | use wildcard_imports_helper::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:109:20
+ |
+LL | use self::{inner::*, inner2::*};
+ | ^^^^^^^^ help: try: `inner::inner_foo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:109:30
+ |
+LL | use self::{inner::*, inner2::*};
+ | ^^^^^^^^^ help: try: `inner2::inner_bar`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:116:13
+ |
+LL | use wildcard_imports_helper::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:145:9
+ |
+LL | use crate::in_fn_test::*;
+ | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:154:9
+ |
+LL | use crate:: in_fn_test:: * ;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:155:9
+ |
+LL | use crate:: fn_mod::
+ | _________^
+LL | | *;
+ | |_________^ help: try: `crate:: fn_mod::foo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:166:13
+ |
+LL | use super::*;
+ | ^^^^^^^^ help: try: `super::foofoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:201:17
+ |
+LL | use super::*;
+ | ^^^^^^^^ help: try: `super::insidefoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:209:13
+ |
+LL | use crate::super_imports::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:218:17
+ |
+LL | use super::super::*;
+ | ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:227:13
+ |
+LL | use super::super::super_imports::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:235:13
+ |
+LL | use super::*;
+ | ^^^^^^^^ help: try: `super::foofoo`
+
+error: aborting due to 21 previous errors
+
diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed
new file mode 100644
index 000000000..6d534a10e
--- /dev/null
+++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.fixed
@@ -0,0 +1,240 @@
+// revisions: edition2018 edition2021
+//[edition2018] edition:2018
+//[edition2021] edition:2021
+// run-rustfix
+// aux-build:wildcard_imports_helper.rs
+
+#![warn(clippy::wildcard_imports)]
+#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
+#![warn(unused_imports)]
+
+extern crate wildcard_imports_helper;
+
+use crate::fn_mod::foo;
+use crate::mod_mod::inner_mod;
+use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod};
+use crate::struct_mod::{A, inner_struct_mod};
+
+#[allow(unused_imports)]
+use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
+use wildcard_imports_helper::prelude::v1::*;
+use wildcard_imports_helper::{ExternA, extern_foo};
+
+use std::io::prelude::*;
+
+struct ReadFoo;
+
+impl Read for ReadFoo {
+ fn read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
+ Ok(0)
+ }
+}
+
+mod fn_mod {
+ pub fn foo() {}
+}
+
+mod mod_mod {
+ pub mod inner_mod {
+ pub fn foo() {}
+ }
+}
+
+mod multi_fn_mod {
+ pub fn multi_foo() {}
+ pub fn multi_bar() {}
+ pub fn multi_baz() {}
+ pub mod multi_inner_mod {
+ pub fn foo() {}
+ }
+}
+
+mod struct_mod {
+ pub struct A;
+ pub struct B;
+ pub mod inner_struct_mod {
+ pub struct C;
+ }
+
+ #[macro_export]
+ macro_rules! double_struct_import_test {
+ () => {
+ let _ = A;
+ };
+ }
+}
+
+fn main() {
+ foo();
+ multi_foo();
+ multi_bar();
+ multi_inner_mod::foo();
+ inner_mod::foo();
+ extern_foo();
+ inner_extern_bar();
+
+ let _ = A;
+ let _ = inner_struct_mod::C;
+ let _ = ExternA;
+ let _ = PreludeModAnywhere;
+
+ double_struct_import_test!();
+ double_struct_import_test!();
+}
+
+mod in_fn_test {
+ pub use self::inner_exported::*;
+ #[allow(unused_imports)]
+ pub(crate) use self::inner_exported2::*;
+
+ fn test_intern() {
+ use crate::fn_mod::foo;
+
+ foo();
+ }
+
+ fn test_extern() {
+ use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo};
+ use wildcard_imports_helper::{ExternA, extern_foo};
+
+ inner_for_self_import::inner_extern_foo();
+ inner_extern_foo();
+
+ extern_foo();
+
+ let _ = ExternA;
+ }
+
+ fn test_inner_nested() {
+ use self::{inner::inner_foo, inner2::inner_bar};
+
+ inner_foo();
+ inner_bar();
+ }
+
+ fn test_extern_reexported() {
+ use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported};
+
+ extern_exported();
+ let _ = ExternExportedStruct;
+ let _ = ExternExportedEnum::A;
+ }
+
+ mod inner_exported {
+ pub fn exported() {}
+ pub struct ExportedStruct;
+ pub enum ExportedEnum {
+ A,
+ }
+ }
+
+ mod inner_exported2 {
+ pub(crate) fn exported2() {}
+ }
+
+ mod inner {
+ pub fn inner_foo() {}
+ }
+
+ mod inner2 {
+ pub fn inner_bar() {}
+ }
+}
+
+fn test_reexported() {
+ use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported};
+
+ exported();
+ let _ = ExportedStruct;
+ let _ = ExportedEnum::A;
+}
+
+#[rustfmt::skip]
+fn test_weird_formatting() {
+ use crate:: in_fn_test::exported;
+ use crate:: fn_mod::foo;
+
+ exported();
+ foo();
+}
+
+mod super_imports {
+ fn foofoo() {}
+
+ mod should_be_replaced {
+ use super::foofoo;
+
+ fn with_super() {
+ let _ = foofoo();
+ }
+ }
+
+ mod test_should_pass {
+ use super::*;
+
+ fn with_super() {
+ let _ = foofoo();
+ }
+ }
+
+ mod test_should_pass_inside_function {
+ fn with_super_inside_function() {
+ use super::*;
+ let _ = foofoo();
+ }
+ }
+
+ mod test_should_pass_further_inside {
+ fn insidefoo() {}
+ mod inner {
+ use super::*;
+ fn with_super() {
+ let _ = insidefoo();
+ }
+ }
+ }
+
+ mod should_be_replaced_further_inside {
+ fn insidefoo() {}
+ mod inner {
+ use super::insidefoo;
+ fn with_super() {
+ let _ = insidefoo();
+ }
+ }
+ }
+
+ mod use_explicit_should_be_replaced {
+ use crate::super_imports::foofoo;
+
+ fn with_explicit() {
+ let _ = foofoo();
+ }
+ }
+
+ mod use_double_super_should_be_replaced {
+ mod inner {
+ use super::super::foofoo;
+
+ fn with_double_super() {
+ let _ = foofoo();
+ }
+ }
+ }
+
+ mod use_super_explicit_should_be_replaced {
+ use super::super::super_imports::foofoo;
+
+ fn with_super_explicit() {
+ let _ = foofoo();
+ }
+ }
+
+ mod attestation_should_be_replaced {
+ use super::foofoo;
+
+ fn with_explicit() {
+ let _ = foofoo();
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.stderr b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.stderr
new file mode 100644
index 000000000..acca9f651
--- /dev/null
+++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.edition2021.stderr
@@ -0,0 +1,132 @@
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:13:5
+ |
+LL | use crate::fn_mod::*;
+ | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
+ |
+ = note: `-D clippy::wildcard-imports` implied by `-D warnings`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:14:5
+ |
+LL | use crate::mod_mod::*;
+ | ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:15:5
+ |
+LL | use crate::multi_fn_mod::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:16:5
+ |
+LL | use crate::struct_mod::*;
+ | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:19:5
+ |
+LL | use wildcard_imports_helper::inner::inner_for_self_import::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:21:5
+ |
+LL | use wildcard_imports_helper::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:91:13
+ |
+LL | use crate::fn_mod::*;
+ | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:97:75
+ |
+LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
+ | ^ help: try: `inner_extern_foo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:98:13
+ |
+LL | use wildcard_imports_helper::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:109:20
+ |
+LL | use self::{inner::*, inner2::*};
+ | ^^^^^^^^ help: try: `inner::inner_foo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:109:30
+ |
+LL | use self::{inner::*, inner2::*};
+ | ^^^^^^^^^ help: try: `inner2::inner_bar`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:116:13
+ |
+LL | use wildcard_imports_helper::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:145:9
+ |
+LL | use crate::in_fn_test::*;
+ | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:154:9
+ |
+LL | use crate:: in_fn_test:: * ;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:155:9
+ |
+LL | use crate:: fn_mod::
+ | _________^
+LL | | *;
+ | |_________^ help: try: `crate:: fn_mod::foo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:166:13
+ |
+LL | use super::*;
+ | ^^^^^^^^ help: try: `super::foofoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:201:17
+ |
+LL | use super::*;
+ | ^^^^^^^^ help: try: `super::insidefoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:209:13
+ |
+LL | use crate::super_imports::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:218:17
+ |
+LL | use super::super::*;
+ | ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:227:13
+ |
+LL | use super::super::super_imports::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:235:13
+ |
+LL | use super::*;
+ | ^^^^^^^^ help: try: `super::foofoo`
+
+error: aborting due to 21 previous errors
+
diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.rs b/src/tools/clippy/tests/ui/wildcard_imports_2021.rs
new file mode 100644
index 000000000..b5ed58e68
--- /dev/null
+++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.rs
@@ -0,0 +1,241 @@
+// revisions: edition2018 edition2021
+//[edition2018] edition:2018
+//[edition2021] edition:2021
+// run-rustfix
+// aux-build:wildcard_imports_helper.rs
+
+#![warn(clippy::wildcard_imports)]
+#![allow(unused, clippy::unnecessary_wraps, clippy::let_unit_value)]
+#![warn(unused_imports)]
+
+extern crate wildcard_imports_helper;
+
+use crate::fn_mod::*;
+use crate::mod_mod::*;
+use crate::multi_fn_mod::*;
+use crate::struct_mod::*;
+
+#[allow(unused_imports)]
+use wildcard_imports_helper::inner::inner_for_self_import::*;
+use wildcard_imports_helper::prelude::v1::*;
+use wildcard_imports_helper::*;
+
+use std::io::prelude::*;
+
+struct ReadFoo;
+
+impl Read for ReadFoo {
+ fn read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
+ Ok(0)
+ }
+}
+
+mod fn_mod {
+ pub fn foo() {}
+}
+
+mod mod_mod {
+ pub mod inner_mod {
+ pub fn foo() {}
+ }
+}
+
+mod multi_fn_mod {
+ pub fn multi_foo() {}
+ pub fn multi_bar() {}
+ pub fn multi_baz() {}
+ pub mod multi_inner_mod {
+ pub fn foo() {}
+ }
+}
+
+mod struct_mod {
+ pub struct A;
+ pub struct B;
+ pub mod inner_struct_mod {
+ pub struct C;
+ }
+
+ #[macro_export]
+ macro_rules! double_struct_import_test {
+ () => {
+ let _ = A;
+ };
+ }
+}
+
+fn main() {
+ foo();
+ multi_foo();
+ multi_bar();
+ multi_inner_mod::foo();
+ inner_mod::foo();
+ extern_foo();
+ inner_extern_bar();
+
+ let _ = A;
+ let _ = inner_struct_mod::C;
+ let _ = ExternA;
+ let _ = PreludeModAnywhere;
+
+ double_struct_import_test!();
+ double_struct_import_test!();
+}
+
+mod in_fn_test {
+ pub use self::inner_exported::*;
+ #[allow(unused_imports)]
+ pub(crate) use self::inner_exported2::*;
+
+ fn test_intern() {
+ use crate::fn_mod::*;
+
+ foo();
+ }
+
+ fn test_extern() {
+ use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
+ use wildcard_imports_helper::*;
+
+ inner_for_self_import::inner_extern_foo();
+ inner_extern_foo();
+
+ extern_foo();
+
+ let _ = ExternA;
+ }
+
+ fn test_inner_nested() {
+ use self::{inner::*, inner2::*};
+
+ inner_foo();
+ inner_bar();
+ }
+
+ fn test_extern_reexported() {
+ use wildcard_imports_helper::*;
+
+ extern_exported();
+ let _ = ExternExportedStruct;
+ let _ = ExternExportedEnum::A;
+ }
+
+ mod inner_exported {
+ pub fn exported() {}
+ pub struct ExportedStruct;
+ pub enum ExportedEnum {
+ A,
+ }
+ }
+
+ mod inner_exported2 {
+ pub(crate) fn exported2() {}
+ }
+
+ mod inner {
+ pub fn inner_foo() {}
+ }
+
+ mod inner2 {
+ pub fn inner_bar() {}
+ }
+}
+
+fn test_reexported() {
+ use crate::in_fn_test::*;
+
+ exported();
+ let _ = ExportedStruct;
+ let _ = ExportedEnum::A;
+}
+
+#[rustfmt::skip]
+fn test_weird_formatting() {
+ use crate:: in_fn_test:: * ;
+ use crate:: fn_mod::
+ *;
+
+ exported();
+ foo();
+}
+
+mod super_imports {
+ fn foofoo() {}
+
+ mod should_be_replaced {
+ use super::*;
+
+ fn with_super() {
+ let _ = foofoo();
+ }
+ }
+
+ mod test_should_pass {
+ use super::*;
+
+ fn with_super() {
+ let _ = foofoo();
+ }
+ }
+
+ mod test_should_pass_inside_function {
+ fn with_super_inside_function() {
+ use super::*;
+ let _ = foofoo();
+ }
+ }
+
+ mod test_should_pass_further_inside {
+ fn insidefoo() {}
+ mod inner {
+ use super::*;
+ fn with_super() {
+ let _ = insidefoo();
+ }
+ }
+ }
+
+ mod should_be_replaced_further_inside {
+ fn insidefoo() {}
+ mod inner {
+ use super::*;
+ fn with_super() {
+ let _ = insidefoo();
+ }
+ }
+ }
+
+ mod use_explicit_should_be_replaced {
+ use crate::super_imports::*;
+
+ fn with_explicit() {
+ let _ = foofoo();
+ }
+ }
+
+ mod use_double_super_should_be_replaced {
+ mod inner {
+ use super::super::*;
+
+ fn with_double_super() {
+ let _ = foofoo();
+ }
+ }
+ }
+
+ mod use_super_explicit_should_be_replaced {
+ use super::super::super_imports::*;
+
+ fn with_super_explicit() {
+ let _ = foofoo();
+ }
+ }
+
+ mod attestation_should_be_replaced {
+ use super::*;
+
+ fn with_explicit() {
+ let _ = foofoo();
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/wildcard_imports_2021.stderr b/src/tools/clippy/tests/ui/wildcard_imports_2021.stderr
new file mode 100644
index 000000000..92f6d3153
--- /dev/null
+++ b/src/tools/clippy/tests/ui/wildcard_imports_2021.stderr
@@ -0,0 +1,132 @@
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:9:5
+ |
+LL | use crate::fn_mod::*;
+ | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
+ |
+ = note: `-D clippy::wildcard-imports` implied by `-D warnings`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:10:5
+ |
+LL | use crate::mod_mod::*;
+ | ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:11:5
+ |
+LL | use crate::multi_fn_mod::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:12:5
+ |
+LL | use crate::struct_mod::*;
+ | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:15:5
+ |
+LL | use wildcard_imports_helper::inner::inner_for_self_import::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:17:5
+ |
+LL | use wildcard_imports_helper::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:87:13
+ |
+LL | use crate::fn_mod::*;
+ | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:93:75
+ |
+LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
+ | ^ help: try: `inner_extern_foo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:94:13
+ |
+LL | use wildcard_imports_helper::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:105:20
+ |
+LL | use self::{inner::*, inner2::*};
+ | ^^^^^^^^ help: try: `inner::inner_foo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:105:30
+ |
+LL | use self::{inner::*, inner2::*};
+ | ^^^^^^^^^ help: try: `inner2::inner_bar`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:112:13
+ |
+LL | use wildcard_imports_helper::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:141:9
+ |
+LL | use crate::in_fn_test::*;
+ | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:150:9
+ |
+LL | use crate:: in_fn_test:: * ;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:151:9
+ |
+LL | use crate:: fn_mod::
+ | _________^
+LL | | *;
+ | |_________^ help: try: `crate:: fn_mod::foo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:162:13
+ |
+LL | use super::*;
+ | ^^^^^^^^ help: try: `super::foofoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:197:17
+ |
+LL | use super::*;
+ | ^^^^^^^^ help: try: `super::insidefoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:205:13
+ |
+LL | use crate::super_imports::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::super_imports::foofoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:214:17
+ |
+LL | use super::super::*;
+ | ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:223:13
+ |
+LL | use super::super::super_imports::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
+
+error: usage of wildcard import
+ --> $DIR/wildcard_imports_2021.rs:231:13
+ |
+LL | use super::*;
+ | ^^^^^^^^ help: try: `super::foofoo`
+
+error: aborting due to 21 previous errors
+
diff --git a/src/tools/clippy/tests/ui/zero_ptr_no_std.fixed b/src/tools/clippy/tests/ui/zero_ptr_no_std.fixed
new file mode 100644
index 000000000..8906c7769
--- /dev/null
+++ b/src/tools/clippy/tests/ui/zero_ptr_no_std.fixed
@@ -0,0 +1,21 @@
+// run-rustfix
+
+#![feature(lang_items, start, libc)]
+#![no_std]
+#![deny(clippy::zero_ptr)]
+
+#[start]
+fn main(_argc: isize, _argv: *const *const u8) -> isize {
+ let _ = core::ptr::null::<usize>();
+ let _ = core::ptr::null_mut::<f64>();
+ let _: *const u8 = core::ptr::null();
+ 0
+}
+
+#[panic_handler]
+fn panic(_info: &core::panic::PanicInfo) -> ! {
+ loop {}
+}
+
+#[lang = "eh_personality"]
+extern "C" fn eh_personality() {}
diff --git a/src/tools/clippy/tests/ui/zero_ptr_no_std.rs b/src/tools/clippy/tests/ui/zero_ptr_no_std.rs
new file mode 100644
index 000000000..379c1b18d
--- /dev/null
+++ b/src/tools/clippy/tests/ui/zero_ptr_no_std.rs
@@ -0,0 +1,21 @@
+// run-rustfix
+
+#![feature(lang_items, start, libc)]
+#![no_std]
+#![deny(clippy::zero_ptr)]
+
+#[start]
+fn main(_argc: isize, _argv: *const *const u8) -> isize {
+ let _ = 0 as *const usize;
+ let _ = 0 as *mut f64;
+ let _: *const u8 = 0 as *const _;
+ 0
+}
+
+#[panic_handler]
+fn panic(_info: &core::panic::PanicInfo) -> ! {
+ loop {}
+}
+
+#[lang = "eh_personality"]
+extern "C" fn eh_personality() {}
diff --git a/src/tools/clippy/tests/ui/zero_ptr_no_std.stderr b/src/tools/clippy/tests/ui/zero_ptr_no_std.stderr
new file mode 100644
index 000000000..d92bb4a65
--- /dev/null
+++ b/src/tools/clippy/tests/ui/zero_ptr_no_std.stderr
@@ -0,0 +1,26 @@
+error: `0 as *const _` detected
+ --> $DIR/zero_ptr_no_std.rs:9:13
+ |
+LL | let _ = 0 as *const usize;
+ | ^^^^^^^^^^^^^^^^^ help: try: `core::ptr::null::<usize>()`
+ |
+note: the lint level is defined here
+ --> $DIR/zero_ptr_no_std.rs:5:9
+ |
+LL | #![deny(clippy::zero_ptr)]
+ | ^^^^^^^^^^^^^^^^
+
+error: `0 as *mut _` detected
+ --> $DIR/zero_ptr_no_std.rs:10:13
+ |
+LL | let _ = 0 as *mut f64;
+ | ^^^^^^^^^^^^^ help: try: `core::ptr::null_mut::<f64>()`
+
+error: `0 as *const _` detected
+ --> $DIR/zero_ptr_no_std.rs:11:24
+ |
+LL | let _: *const u8 = 0 as *const _;
+ | ^^^^^^^^^^^^^ help: try: `core::ptr::null()`
+
+error: aborting due to 3 previous errors
+