summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/manual_rem_euclid.fixed
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui/manual_rem_euclid.fixed
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/manual_rem_euclid.fixed')
-rw-r--r--src/tools/clippy/tests/ui/manual_rem_euclid.fixed55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/manual_rem_euclid.fixed b/src/tools/clippy/tests/ui/manual_rem_euclid.fixed
new file mode 100644
index 000000000..5601c96c1
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_rem_euclid.fixed
@@ -0,0 +1,55 @@
+// run-rustfix
+// aux-build:macro_rules.rs
+
+#![warn(clippy::manual_rem_euclid)]
+
+#[macro_use]
+extern crate macro_rules;
+
+macro_rules! internal_rem_euclid {
+ () => {
+ let value: i32 = 5;
+ let _: i32 = value.rem_euclid(4);
+ };
+}
+
+fn main() {
+ let value: i32 = 5;
+
+ let _: i32 = value.rem_euclid(4);
+ let _: i32 = value.rem_euclid(4);
+ let _: i32 = value.rem_euclid(4);
+ let _: i32 = value.rem_euclid(4);
+ let _: i32 = 1 + value.rem_euclid(4);
+
+ let _: i32 = (3 + value % 4) % 4;
+ let _: i32 = (-4 + value % -4) % -4;
+ let _: i32 = ((5 % 4) + 4) % 4;
+
+ // Make sure the lint does not trigger if it would cause an error, like with an ambiguous
+ // integer type
+ let not_annotated = 24;
+ let _ = ((not_annotated % 4) + 4) % 4;
+ let inferred: _ = 24;
+ let _ = ((inferred % 4) + 4) % 4;
+
+ // For lint to apply the constant must always be on the RHS of the previous value for %
+ let _: i32 = 4 % ((value % 4) + 4);
+ let _: i32 = ((4 % value) + 4) % 4;
+
+ // Lint in internal macros
+ internal_rem_euclid!();
+
+ // Do not lint in external macros
+ manual_rem_euclid!();
+}
+
+// Should lint for params too
+pub fn rem_euclid_4(num: i32) -> i32 {
+ num.rem_euclid(4)
+}
+
+// Constant version came later, should still lint
+pub const fn const_rem_euclid_4(num: i32) -> i32 {
+ num.rem_euclid(4)
+}