Skip to content

Commit d07ad69

Browse files
committed
add more lints
1 parent 981d5ae commit d07ad69

File tree

5 files changed

+50
-24
lines changed

5 files changed

+50
-24
lines changed

Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,27 @@ missing_safety_doc = "allow" # safety? in libc? seriously?
158158
# FIXME(clippy): all these should probably be fixed
159159
non_minimal_cfg = "allow" # for some reason cfg_if! sometimes trigger this
160160
unnecessary_cast = "allow" # some casts like `as usize` are only needed for some targets
161+
162+
# Enable pedantic lints - use this manually once in a while, but don't enable by default
163+
# pedantic = { level = "warn", priority = -1 }
164+
165+
# These were manually fixed already, and should be enforced
166+
explicit_iter_loop = "warn"
167+
manual_assert = "warn"
168+
map_unwrap_or = "warn"
169+
ptr_as_ptr = "warn"
170+
unnecessary_semicolon = "warn"
171+
172+
# FIXME(clippy): these should eventually be fixed, or listed as OK
173+
cast_possible_truncation = "allow"
174+
cast_possible_wrap = "allow"
175+
cast_sign_loss = "allow"
176+
expl_impl_clone_on_copy = "allow"
177+
must_use_candidate = "allow"
178+
pub_underscore_fields = "allow"
179+
struct_field_names = "allow"
180+
uninlined_format_args = "allow"
181+
unreadable_literal = "allow"
182+
used_underscore_binding = "allow"
183+
used_underscore_items = "allow"
184+
verbose_bit_mask = "allow"

build.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,11 @@ fn rustc_version_cmd(is_clippy_driver: bool) -> Output {
160160

161161
let output = cmd.output().expect("Failed to get rustc version");
162162

163-
if !output.status.success() {
164-
panic!(
165-
"failed to run rustc: {}",
166-
String::from_utf8_lossy(output.stderr.as_slice())
167-
);
168-
}
163+
assert!(
164+
output.status.success(),
165+
"failed to run rustc: {}",
166+
String::from_utf8_lossy(output.stderr.as_slice())
167+
);
169168

170169
output
171170
}
@@ -192,9 +191,11 @@ fn rustc_minor_nightly() -> (u32, bool) {
192191

193192
let mut pieces = version.split('.');
194193

195-
if pieces.next() != Some("rustc 1") {
196-
panic!("Failed to get rustc version");
197-
}
194+
assert_eq!(
195+
pieces.next(),
196+
Some("rustc 1"),
197+
"Failed to get rustc version"
198+
);
198199

199200
let minor = pieces.next();
200201

@@ -204,9 +205,9 @@ fn rustc_minor_nightly() -> (u32, bool) {
204205
// since a nightly build should either come from CI
205206
// or a git checkout
206207
let nightly_raw = otry!(pieces.next()).split('-').nth(1);
207-
let nightly = nightly_raw
208-
.map(|raw| raw.starts_with("dev") || raw.starts_with("nightly"))
209-
.unwrap_or(false);
208+
let nightly = nightly_raw.map_or(false, |raw| {
209+
raw.starts_with("dev") || raw.starts_with("nightly")
210+
});
210211
let minor = otry!(otry!(minor).parse().ok());
211212

212213
(minor, nightly)
@@ -251,8 +252,9 @@ fn emcc_version_code() -> Option<u64> {
251252
}
252253

253254
fn set_cfg(cfg: &str) {
254-
if !ALLOWED_CFGS.contains(&cfg) {
255-
panic!("trying to set cfg {}, but it is not in ALLOWED_CFGS", cfg);
256-
}
257-
println!("cargo:rustc-cfg={}", cfg);
255+
assert!(
256+
ALLOWED_CFGS.contains(&cfg),
257+
"trying to set cfg {cfg}, but it is not in ALLOWED_CFGS",
258+
);
259+
println!("cargo:rustc-cfg={cfg}");
258260
}

src/unix/linux_like/linux/gnu/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl siginfo_t {
425425
_si_code: c_int,
426426
si_addr: *mut c_void,
427427
}
428-
(*(self as *const siginfo_t as *const siginfo_sigfault)).si_addr
428+
(*(self as *const siginfo_t).cast::<siginfo_sigfault>()).si_addr
429429
}
430430

431431
pub unsafe fn si_value(&self) -> crate::sigval {
@@ -438,7 +438,7 @@ impl siginfo_t {
438438
_si_overrun: c_int,
439439
si_sigval: crate::sigval,
440440
}
441-
(*(self as *const siginfo_t as *const siginfo_timer)).si_sigval
441+
(*(self as *const siginfo_t).cast::<siginfo_timer>()).si_sigval
442442
}
443443
}
444444

@@ -502,7 +502,7 @@ struct siginfo_f {
502502

503503
impl siginfo_t {
504504
unsafe fn sifields(&self) -> &sifields {
505-
&(*(self as *const siginfo_t as *const siginfo_f)).sifields
505+
&(*(self as *const siginfo_t).cast::<siginfo_f>()).sifields
506506
}
507507

508508
pub unsafe fn si_pid(&self) -> crate::pid_t {

src/unix/linux_like/linux/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5977,7 +5977,7 @@ f! {
59775977
pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
59785978
if ((*cmsg).cmsg_len as usize) < size_of::<cmsghdr>() {
59795979
return core::ptr::null_mut::<cmsghdr>();
5980-
};
5980+
}
59815981
let next = (cmsg as usize + super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr;
59825982
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
59835983
if (next.wrapping_offset(1)) as usize > max
@@ -5996,7 +5996,7 @@ f! {
59965996
}
59975997

59985998
pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
5999-
for slot in cpuset.bits.iter_mut() {
5999+
for slot in &mut cpuset.bits {
60006000
*slot = 0;
60016001
}
60026002
}
@@ -6022,7 +6022,7 @@ f! {
60226022
pub fn CPU_COUNT_S(size: usize, cpuset: &cpu_set_t) -> c_int {
60236023
let mut s: u32 = 0;
60246024
let size_of_mask = mem::size_of_val(&cpuset.bits[0]);
6025-
for i in cpuset.bits[..(size / size_of_mask)].iter() {
6025+
for i in &cpuset.bits[..(size / size_of_mask)] {
60266026
s += i.count_ones();
60276027
}
60286028
s as c_int

src/unix/linux_like/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@ const_fn! {
17061706
f! {
17071707
pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr {
17081708
if (*mhdr).msg_controllen as usize >= mem::size_of::<cmsghdr>() {
1709-
(*mhdr).msg_control as *mut cmsghdr
1709+
(*mhdr).msg_control.cast::<cmsghdr>()
17101710
} else {
17111711
core::ptr::null_mut::<cmsghdr>()
17121712
}
@@ -1745,7 +1745,7 @@ f! {
17451745
}
17461746

17471747
pub fn FD_ZERO(set: *mut fd_set) -> () {
1748-
for slot in (*set).fds_bits.iter_mut() {
1748+
for slot in &mut (*set).fds_bits {
17491749
*slot = 0;
17501750
}
17511751
}

0 commit comments

Comments
 (0)