1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#![warn(clippy::ip_constant)]
#![allow(dead_code)]
#![allow(clippy::identity_op)]
#![allow(clippy::eq_op)]
fn literal_test1() {
use std::net::Ipv4Addr;
let _ = Ipv4Addr::new(127, 0, 0, 1);
//~^ ip_constant
let _ = Ipv4Addr::new(255, 255, 255, 255);
//~^ ip_constant
let _ = Ipv4Addr::new(0, 0, 0, 0);
//~^ ip_constant
use std::net::Ipv6Addr;
let _ = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1);
//~^ ip_constant
let _ = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0);
//~^ ip_constant
}
fn literal_test2() {
use std::net;
let _ = net::Ipv4Addr::new(127, 0, 0, 1);
//~^ ip_constant
let _ = net::Ipv4Addr::new(255, 255, 255, 255);
//~^ ip_constant
let _ = net::Ipv4Addr::new(0, 0, 0, 0);
//~^ ip_constant
let _ = net::Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1);
//~^ ip_constant
let _ = net::Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0);
//~^ ip_constant
}
fn literal_test3() {
let _ = std::net::Ipv4Addr::new(127, 0, 0, 1);
//~^ ip_constant
let _ = std::net::Ipv4Addr::new(255, 255, 255, 255);
//~^ ip_constant
let _ = std::net::Ipv4Addr::new(0, 0, 0, 0);
//~^ ip_constant
let _ = std::net::Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1);
//~^ ip_constant
let _ = std::net::Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0);
//~^ ip_constant
}
fn wrapped_in_parens() {
let _ = (std::net::Ipv4Addr::new(127, 0, 0, 1));
//~^ ip_constant
let _ = (std::net::Ipv4Addr::new(255, 255, 255, 255));
//~^ ip_constant
let _ = (std::net::Ipv4Addr::new(0, 0, 0, 0));
//~^ ip_constant
let _ = (std::net::Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
//~^ ip_constant
let _ = (std::net::Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0));
//~^ ip_constant
}
const CONST_U8_0: u8 = 0;
const CONST_U8_1: u8 = 1;
const CONST_U8_127: u8 = 127;
const CONST_U8_255: u8 = 255;
const CONST_U16_0: u16 = 0;
const CONST_U16_1: u16 = 1;
fn const_test1() {
use std::net::Ipv4Addr;
let _ = Ipv4Addr::new(CONST_U8_127, CONST_U8_0, CONST_U8_0, CONST_U8_1);
//~^ ip_constant
let _ = Ipv4Addr::new(CONST_U8_255, CONST_U8_255, CONST_U8_255, CONST_U8_255);
//~^ ip_constant
let _ = Ipv4Addr::new(CONST_U8_0, CONST_U8_0, CONST_U8_0, CONST_U8_0);
//~^ ip_constant
use std::net::Ipv6Addr;
let _ = Ipv6Addr::new(
//~^ ip_constant
CONST_U16_0,
CONST_U16_0,
CONST_U16_0,
CONST_U16_0,
CONST_U16_0,
CONST_U16_0,
CONST_U16_0,
CONST_U16_1,
);
let _ = Ipv6Addr::new(
//~^ ip_constant
CONST_U16_0,
CONST_U16_0,
CONST_U16_0,
CONST_U16_0,
CONST_U16_0,
CONST_U16_0,
CONST_U16_0,
CONST_U16_0,
);
}
fn const_test2() {
use std::net::Ipv4Addr;
let _ = Ipv4Addr::new(126 + 1, 0, 0, 1);
//~^ ip_constant
let _ = Ipv4Addr::new(254 + CONST_U8_1, 255, { 255 - CONST_U8_0 }, CONST_U8_255);
//~^ ip_constant
let _ = Ipv4Addr::new(0, CONST_U8_255 - 255, 0, { 1 + 0 - 1 });
//~^ ip_constant
use std::net::Ipv6Addr;
let _ = Ipv6Addr::new(0 + CONST_U16_0, 0, 0, 0, 0, 0, 0, 1);
//~^ ip_constant
let _ = Ipv6Addr::new(0 + 0, 0, 0, 0, 0, { 2 - 1 - CONST_U16_1 }, 0, 1);
//~^ ip_constant
}
macro_rules! ipv4_new {
($a:expr, $b:expr, $c:expr, $d:expr) => {
std::net::Ipv4Addr::new($a, $b, $c, $d)
};
}
fn macro_test() {
let _ = ipv4_new!(127, 0, 0, 1);
// no lint
let _ = ipv4_new!(255, 255, 255, 255);
// no lint
let _ = ipv4_new!(0, 0, 0, 0);
// no lint
}
fn main() {
// UI Test
}
|