Skip to content

Commit 38bc29a

Browse files
committed
add more lints
1 parent 09cb9ec commit 38bc29a

File tree

8 files changed

+54
-31
lines changed

8 files changed

+54
-31
lines changed

Cargo.toml

+24
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

+17-15
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 {cfg}, but it is not in ALLOWED_CFGS");
256-
}
255+
assert!(
256+
ALLOWED_CFGS.contains(&cfg),
257+
"trying to set cfg {cfg}, but it is not in ALLOWED_CFGS",
258+
);
257259
println!("cargo:rustc-cfg={cfg}");
258260
}

ctest/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2299,10 +2299,7 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> {
22992299
self.assert_no_generics(i.ident, generics);
23002300
for arg in &decl.inputs {
23012301
if let ast::TyKind::Array(_, _) = arg.ty.node {
2302-
panic!(
2303-
"Foreign Function decl `{}` uses array in C FFI",
2304-
i.ident
2305-
);
2302+
panic!("Foreign Function decl `{}` uses array in C FFI", i.ident);
23062303
}
23072304
}
23082305

src/unix/bsd/apple/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ impl siginfo_t {
16531653
si_value: crate::sigval,
16541654
}
16551655

1656-
(*(self as *const siginfo_t as *const siginfo_timer)).si_value
1656+
(*(self as *const siginfo_t).cast::<siginfo_timer>()).si_value
16571657
}
16581658

16591659
pub unsafe fn si_pid(&self) -> crate::pid_t {
@@ -5538,7 +5538,7 @@ f! {
55385538
pub fn CMSG_NXTHDR(mhdr: *const crate::msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
55395539
if cmsg.is_null() {
55405540
return crate::CMSG_FIRSTHDR(mhdr);
5541-
};
5541+
}
55425542
let cmsg_len = (*cmsg).cmsg_len as usize;
55435543
let next = cmsg as usize + __DARWIN_ALIGN32(cmsg_len);
55445544
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;

src/unix/bsd/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ pub const RTAX_BRD: c_int = 7;
596596
f! {
597597
pub fn CMSG_FIRSTHDR(mhdr: *const crate::msghdr) -> *mut cmsghdr {
598598
if (*mhdr).msg_controllen as usize >= mem::size_of::<cmsghdr>() {
599-
(*mhdr).msg_control as *mut cmsghdr
599+
(*mhdr).msg_control.cast::<cmsghdr>()
600600
} else {
601601
core::ptr::null_mut()
602602
}
@@ -623,7 +623,7 @@ f! {
623623
}
624624

625625
pub fn FD_ZERO(set: *mut fd_set) -> () {
626-
for slot in (*set).fds_bits.iter_mut() {
626+
for slot in &mut (*set).fds_bits {
627627
*slot = 0;
628628
}
629629
}

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

+3-3
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

+3-3
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

+2-2
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)