fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1//@aux-build:proc_macros.rs 2 3#![warn(clippy::manual_rem_euclid)] 4#![allow(clippy::let_with_type_underscore)] 5 6extern crate proc_macros; 7use proc_macros::{external, inline_macros}; 8 9#[inline_macros] 10fn main() { 11 let value: i32 = 5; 12 13 let _: i32 = value.rem_euclid(4); 14 let _: i32 = value.rem_euclid(4); 15 let _: i32 = value.rem_euclid(4); 16 let _: i32 = value.rem_euclid(4); 17 let _: i32 = 1 + value.rem_euclid(4); 18 19 let _: i32 = (3 + value % 4) % 4; 20 let _: i32 = (-4 + value % -4) % -4; 21 let _: i32 = ((5 % 4) + 4) % 4; 22 23 // Make sure the lint does not trigger if it would cause an error, like with an ambiguous 24 // integer type 25 let not_annotated = 24; 26 let _ = ((not_annotated % 4) + 4) % 4; 27 let inferred: _ = 24; 28 let _ = ((inferred % 4) + 4) % 4; 29 30 // For lint to apply the constant must always be on the RHS of the previous value for % 31 let _: i32 = 4 % ((value % 4) + 4); 32 let _: i32 = ((4 % value) + 4) % 4; 33 34 // Lint in internal macros 35 inline!( 36 let value: i32 = 5; 37 let _: i32 = value.rem_euclid(4); 38 ); 39 40 // Do not lint in external macros 41 external!( 42 let value: i32 = 5; 43 let _: i32 = ((value % 4) + 4) % 4; 44 ); 45} 46 47// Should lint for params too 48pub fn rem_euclid_4(num: i32) -> i32 { 49 num.rem_euclid(4) 50} 51 52// Constant version came later, should still lint 53pub const fn const_rem_euclid_4(num: i32) -> i32 { 54 num.rem_euclid(4) 55} 56 57#[clippy::msrv = "1.37"] 58pub fn msrv_1_37() { 59 let x: i32 = 10; 60 let _: i32 = ((x % 4) + 4) % 4; 61} 62 63#[clippy::msrv = "1.38"] 64pub fn msrv_1_38() { 65 let x: i32 = 10; 66 let _: i32 = x.rem_euclid(4); 67} 68 69// For const fns: 70#[clippy::msrv = "1.51"] 71pub const fn msrv_1_51() { 72 let x: i32 = 10; 73 let _: i32 = ((x % 4) + 4) % 4; 74} 75 76#[clippy::msrv = "1.52"] 77pub const fn msrv_1_52() { 78 let x: i32 = 10; 79 let _: i32 = x.rem_euclid(4); 80}