2023-07-27 08:23:04 -05:00
|
|
|
//@aux-build:proc_macros.rs
|
2022-06-21 13:13:15 -05:00
|
|
|
|
|
|
|
#![warn(clippy::manual_rem_euclid)]
|
2023-03-08 10:31:00 -06:00
|
|
|
#![allow(clippy::let_with_type_underscore)]
|
2022-06-21 13:13:15 -05:00
|
|
|
|
2023-03-07 08:40:55 -06:00
|
|
|
extern crate proc_macros;
|
|
|
|
use proc_macros::{external, inline_macros};
|
2022-06-23 15:34:52 -05:00
|
|
|
|
2023-03-07 08:40:55 -06:00
|
|
|
#[inline_macros]
|
2022-06-21 13:13:15 -05:00
|
|
|
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;
|
2022-06-21 15:41:36 -05:00
|
|
|
|
|
|
|
// 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;
|
2022-06-22 12:26:13 -05:00
|
|
|
|
|
|
|
// 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;
|
2022-06-23 15:34:52 -05:00
|
|
|
|
|
|
|
// Lint in internal macros
|
2023-03-07 08:40:55 -06:00
|
|
|
inline!(
|
|
|
|
let value: i32 = 5;
|
|
|
|
let _: i32 = value.rem_euclid(4);
|
|
|
|
);
|
2022-06-23 15:34:52 -05:00
|
|
|
|
|
|
|
// Do not lint in external macros
|
2023-03-07 08:40:55 -06:00
|
|
|
external!(
|
|
|
|
let value: i32 = 5;
|
|
|
|
let _: i32 = ((value % 4) + 4) % 4;
|
|
|
|
);
|
2022-06-21 13:13:15 -05:00
|
|
|
}
|
2022-06-22 13:08:47 -05:00
|
|
|
|
|
|
|
// Should lint for params too
|
|
|
|
pub fn rem_euclid_4(num: i32) -> i32 {
|
|
|
|
num.rem_euclid(4)
|
|
|
|
}
|
2022-06-22 13:17:52 -05:00
|
|
|
|
|
|
|
// Constant version came later, should still lint
|
|
|
|
pub const fn const_rem_euclid_4(num: i32) -> i32 {
|
|
|
|
num.rem_euclid(4)
|
|
|
|
}
|
2022-10-21 16:35:39 -05:00
|
|
|
|
2022-11-19 06:50:02 -06:00
|
|
|
#[clippy::msrv = "1.37"]
|
2022-10-21 16:35:39 -05:00
|
|
|
pub fn msrv_1_37() {
|
|
|
|
let x: i32 = 10;
|
|
|
|
let _: i32 = ((x % 4) + 4) % 4;
|
|
|
|
}
|
|
|
|
|
2022-11-19 06:50:02 -06:00
|
|
|
#[clippy::msrv = "1.38"]
|
2022-10-21 16:35:39 -05:00
|
|
|
pub fn msrv_1_38() {
|
|
|
|
let x: i32 = 10;
|
|
|
|
let _: i32 = x.rem_euclid(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
// For const fns:
|
2022-11-19 06:50:02 -06:00
|
|
|
#[clippy::msrv = "1.51"]
|
2022-10-21 16:35:39 -05:00
|
|
|
pub const fn msrv_1_51() {
|
|
|
|
let x: i32 = 10;
|
|
|
|
let _: i32 = ((x % 4) + 4) % 4;
|
|
|
|
}
|
|
|
|
|
2022-11-19 06:50:02 -06:00
|
|
|
#[clippy::msrv = "1.52"]
|
2022-10-21 16:35:39 -05:00
|
|
|
pub const fn msrv_1_52() {
|
|
|
|
let x: i32 = 10;
|
|
|
|
let _: i32 = x.rem_euclid(4);
|
|
|
|
}
|