Skip to content

Commit 2bb1315

Browse files
committed
Fix clippy warnings
1 parent 7698b1c commit 2bb1315

File tree

11 files changed

+86
-73
lines changed

11 files changed

+86
-73
lines changed

chemfiles-sys/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::os::raw::{c_char, c_double, c_void};
1515
// Manual definitions. Edit the bindgen code to make sure this matches the
1616
// chemfiles.h header
1717
pub type c_bool = u8;
18-
pub type chfl_warning_callback = extern fn(*const c_char);
18+
pub type chfl_warning_callback = extern "C" fn(*const c_char);
1919
pub type chfl_vector3d = [c_double; 3];
2020

2121
#[repr(C)]

src/atom.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct AtomRef<'a> {
3131
marker: PhantomData<&'a Atom>,
3232
}
3333

34-
impl<'a> std::ops::Deref for AtomRef<'a> {
34+
impl std::ops::Deref for AtomRef<'_> {
3535
type Target = Atom;
3636
fn deref(&self) -> &Atom {
3737
&self.inner
@@ -45,14 +45,14 @@ pub struct AtomMut<'a> {
4545
marker: PhantomData<&'a mut Atom>,
4646
}
4747

48-
impl<'a> std::ops::Deref for AtomMut<'a> {
48+
impl std::ops::Deref for AtomMut<'_> {
4949
type Target = Atom;
5050
fn deref(&self) -> &Atom {
5151
&self.inner
5252
}
5353
}
5454

55-
impl<'a> std::ops::DerefMut for AtomMut<'a> {
55+
impl std::ops::DerefMut for AtomMut<'_> {
5656
fn deref_mut(&mut self) -> &mut Atom {
5757
&mut self.inner
5858
}
@@ -142,7 +142,7 @@ impl Atom {
142142
pub fn mass(&self) -> f64 {
143143
let mut mass = 0.0;
144144
unsafe {
145-
check_success(ffi::chfl_atom_mass(self.as_ptr(), &mut mass));
145+
check_success(ffi::chfl_atom_mass(self.as_ptr(), &raw mut mass));
146146
}
147147
return mass;
148148
}
@@ -174,7 +174,7 @@ impl Atom {
174174
pub fn charge(&self) -> f64 {
175175
let mut charge = 0.0;
176176
unsafe {
177-
check_success(ffi::chfl_atom_charge(self.as_ptr(), &mut charge));
177+
check_success(ffi::chfl_atom_charge(self.as_ptr(), &raw mut charge));
178178
}
179179
return charge;
180180
}
@@ -285,7 +285,7 @@ impl Atom {
285285
pub fn vdw_radius(&self) -> f64 {
286286
let mut radius: f64 = 0.0;
287287
unsafe {
288-
check_success(ffi::chfl_atom_vdw_radius(self.as_ptr(), &mut radius));
288+
check_success(ffi::chfl_atom_vdw_radius(self.as_ptr(), &raw mut radius));
289289
}
290290
return radius;
291291
}
@@ -302,7 +302,7 @@ impl Atom {
302302
pub fn covalent_radius(&self) -> f64 {
303303
let mut radius: f64 = 0.0;
304304
unsafe {
305-
check_success(ffi::chfl_atom_covalent_radius(self.as_ptr(), &mut radius));
305+
check_success(ffi::chfl_atom_covalent_radius(self.as_ptr(), &raw mut radius));
306306
}
307307
return radius;
308308
}
@@ -319,7 +319,7 @@ impl Atom {
319319
pub fn atomic_number(&self) -> u64 {
320320
let mut number = 0;
321321
unsafe {
322-
check_success(ffi::chfl_atom_atomic_number(self.as_ptr(), &mut number));
322+
check_success(ffi::chfl_atom_atomic_number(self.as_ptr(), &raw mut number));
323323
}
324324
return number;
325325
}
@@ -393,10 +393,10 @@ impl Atom {
393393
/// }
394394
/// }
395395
/// ```
396-
pub fn properties(&self) -> PropertiesIter {
396+
pub fn properties(&self) -> PropertiesIter<'_> {
397397
let mut count = 0;
398398
unsafe {
399-
check_success(ffi::chfl_atom_properties_count(self.as_ptr(), &mut count));
399+
check_success(ffi::chfl_atom_properties_count(self.as_ptr(), &raw mut count));
400400
}
401401

402402
#[allow(clippy::cast_possible_truncation)]

src/cell.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub struct UnitCellRef<'a> {
6565
marker: PhantomData<&'a UnitCell>,
6666
}
6767

68-
impl<'a> std::ops::Deref for UnitCellRef<'a> {
68+
impl std::ops::Deref for UnitCellRef<'_> {
6969
type Target = UnitCell;
7070
fn deref(&self) -> &UnitCell {
7171
&self.inner
@@ -79,14 +79,14 @@ pub struct UnitCellMut<'a> {
7979
marker: PhantomData<&'a mut UnitCell>,
8080
}
8181

82-
impl<'a> std::ops::Deref for UnitCellMut<'a> {
82+
impl std::ops::Deref for UnitCellMut<'_> {
8383
type Target = UnitCell;
8484
fn deref(&self) -> &UnitCell {
8585
&self.inner
8686
}
8787
}
8888

89-
impl<'a> std::ops::DerefMut for UnitCellMut<'a> {
89+
impl std::ops::DerefMut for UnitCellMut<'_> {
9090
fn deref_mut(&mut self) -> &mut UnitCell {
9191
&mut self.inner
9292
}
@@ -361,7 +361,7 @@ impl UnitCell {
361361
pub fn shape(&self) -> CellShape {
362362
let mut shape = ffi::chfl_cellshape::CHFL_CELL_INFINITE;
363363
unsafe {
364-
check_success(ffi::chfl_cell_shape(self.as_ptr(), &mut shape));
364+
check_success(ffi::chfl_cell_shape(self.as_ptr(), &raw mut shape));
365365
}
366366
return CellShape::from(shape);
367367
}
@@ -397,7 +397,7 @@ impl UnitCell {
397397
pub fn volume(&self) -> f64 {
398398
let mut volume = 0.0;
399399
unsafe {
400-
check_success(ffi::chfl_cell_volume(self.as_ptr(), &mut volume));
400+
check_success(ffi::chfl_cell_volume(self.as_ptr(), &raw mut volume));
401401
}
402402
return volume;
403403
}

src/frame.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl Frame {
9898
/// let atom = frame.atom(0);
9999
/// assert_eq!(atom.name(), "Zn");
100100
/// ```
101-
pub fn atom(&self, index: usize) -> AtomRef {
101+
pub fn atom(&self, index: usize) -> AtomRef<'_> {
102102
unsafe {
103103
let handle = ffi::chfl_atom_from_frame(self.as_mut_ptr_MANUALLY_CHECKING_BORROW(), index as u64);
104104
Atom::ref_from_ptr(handle)
@@ -122,7 +122,7 @@ impl Frame {
122122
/// frame.atom_mut(0).set_name("Fe");
123123
/// assert_eq!(frame.atom(0).name(), "Fe");
124124
/// ```
125-
pub fn atom_mut(&mut self, index: usize) -> AtomMut {
125+
pub fn atom_mut(&mut self, index: usize) -> AtomMut<'_> {
126126
unsafe {
127127
let handle = ffi::chfl_atom_from_frame(self.as_mut_ptr(), index as u64);
128128
Atom::ref_mut_from_ptr(handle)
@@ -143,7 +143,7 @@ impl Frame {
143143
pub fn size(&self) -> usize {
144144
let mut size = 0;
145145
unsafe {
146-
check_success(ffi::chfl_frame_atoms_count(self.as_ptr(), &mut size));
146+
check_success(ffi::chfl_frame_atoms_count(self.as_ptr(), &raw mut size));
147147
}
148148
#[allow(clippy::cast_possible_truncation)]
149149
return size as usize;
@@ -337,7 +337,7 @@ impl Frame {
337337
self.as_ptr(),
338338
i as u64,
339339
j as u64,
340-
&mut distance,
340+
&raw mut distance,
341341
));
342342
}
343343
return distance;
@@ -366,7 +366,7 @@ impl Frame {
366366
i as u64,
367367
j as u64,
368368
k as u64,
369-
&mut angle,
369+
&raw mut angle,
370370
));
371371
}
372372
return angle;
@@ -397,7 +397,7 @@ impl Frame {
397397
j as u64,
398398
k as u64,
399399
m as u64,
400-
&mut dihedral,
400+
&raw mut dihedral,
401401
));
402402
}
403403
return dihedral;
@@ -430,7 +430,7 @@ impl Frame {
430430
j as u64,
431431
k as u64,
432432
m as u64,
433-
&mut distance,
433+
&raw mut distance,
434434
));
435435
}
436436
return distance;
@@ -454,8 +454,8 @@ impl Frame {
454454
unsafe {
455455
check_success(ffi::chfl_frame_positions(
456456
self.as_mut_ptr_MANUALLY_CHECKING_BORROW(),
457-
&mut ptr,
458-
&mut natoms,
457+
&raw mut ptr,
458+
&raw mut natoms,
459459
));
460460
}
461461

@@ -486,7 +486,11 @@ impl Frame {
486486
let mut ptr = std::ptr::null_mut();
487487
let mut natoms = 0;
488488
unsafe {
489-
check_success(ffi::chfl_frame_positions(self.as_mut_ptr(), &mut ptr, &mut natoms));
489+
check_success(ffi::chfl_frame_positions(
490+
self.as_mut_ptr(),
491+
&raw mut ptr,
492+
&raw mut natoms,
493+
));
490494
}
491495
#[allow(clippy::cast_possible_truncation)]
492496
let size = natoms as usize;
@@ -518,8 +522,8 @@ impl Frame {
518522
unsafe {
519523
check_success(ffi::chfl_frame_velocities(
520524
self.as_mut_ptr_MANUALLY_CHECKING_BORROW(),
521-
&mut ptr,
522-
&mut natoms,
525+
&raw mut ptr,
526+
&raw mut natoms,
523527
));
524528
}
525529
#[allow(clippy::cast_possible_truncation)]
@@ -554,7 +558,11 @@ impl Frame {
554558
let mut ptr = std::ptr::null_mut();
555559
let mut natoms = 0;
556560
unsafe {
557-
check_success(ffi::chfl_frame_velocities(self.as_mut_ptr(), &mut ptr, &mut natoms));
561+
check_success(ffi::chfl_frame_velocities(
562+
self.as_mut_ptr(),
563+
&raw mut ptr,
564+
&raw mut natoms,
565+
));
558566
}
559567
#[allow(clippy::cast_possible_truncation)]
560568
let size = natoms as usize;
@@ -577,7 +585,7 @@ impl Frame {
577585
pub fn has_velocities(&self) -> bool {
578586
let mut res = 0;
579587
unsafe {
580-
check_success(ffi::chfl_frame_has_velocities(self.as_ptr(), &mut res));
588+
check_success(ffi::chfl_frame_has_velocities(self.as_ptr(), &raw mut res));
581589
}
582590
return res != 0;
583591
}
@@ -610,7 +618,7 @@ impl Frame {
610618
/// let cell = frame.cell();
611619
/// assert_eq!(cell.shape(), CellShape::Infinite);
612620
/// ```
613-
pub fn cell(&self) -> UnitCellRef {
621+
pub fn cell(&self) -> UnitCellRef<'_> {
614622
unsafe {
615623
let handle = ffi::chfl_cell_from_frame(self.as_mut_ptr_MANUALLY_CHECKING_BORROW());
616624
UnitCell::ref_from_ptr(handle)
@@ -629,7 +637,7 @@ impl Frame {
629637
/// frame.cell_mut().set_shape(CellShape::Triclinic).unwrap();
630638
/// assert_eq!(frame.cell().shape(), CellShape::Triclinic);
631639
/// ```
632-
pub fn cell_mut(&mut self) -> UnitCellMut {
640+
pub fn cell_mut(&mut self) -> UnitCellMut<'_> {
633641
unsafe {
634642
let handle = ffi::chfl_cell_from_frame(self.as_mut_ptr());
635643
UnitCell::ref_mut_from_ptr(handle)
@@ -666,7 +674,7 @@ impl Frame {
666674
/// let topology = frame.topology();
667675
/// assert_eq!(topology.size(), 42);
668676
/// ```
669-
pub fn topology(&self) -> TopologyRef {
677+
pub fn topology(&self) -> TopologyRef<'_> {
670678
unsafe {
671679
let handle = ffi::chfl_topology_from_frame(self.as_ptr());
672680
Topology::ref_from_ptr(handle)
@@ -709,7 +717,7 @@ impl Frame {
709717
pub fn step(&self) -> usize {
710718
let mut step = 0;
711719
unsafe {
712-
check_success(ffi::chfl_frame_step(self.as_ptr(), &mut step));
720+
check_success(ffi::chfl_frame_step(self.as_ptr(), &raw mut step));
713721
}
714722
#[allow(clippy::cast_possible_truncation)]
715723
return step as usize;
@@ -853,10 +861,10 @@ impl Frame {
853861
/// }
854862
/// }
855863
/// ```
856-
pub fn properties(&self) -> PropertiesIter {
864+
pub fn properties(&self) -> PropertiesIter<'_> {
857865
let mut count = 0;
858866
unsafe {
859-
check_success(ffi::chfl_frame_properties_count(self.as_ptr(), &mut count));
867+
check_success(ffi::chfl_frame_properties_count(self.as_ptr(), &raw mut count));
860868
}
861869

862870
#[allow(clippy::cast_possible_truncation)]

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#![warn(clippy::all, clippy::pedantic)]
2929
#![allow(clippy::needless_return, clippy::module_name_repetitions)]
3030
#![allow(clippy::missing_panics_doc, clippy::must_use_candidate)]
31+
#![allow(clippy::new_without_default)]
3132
// Allow a few more clippy lints in test mode
3233
#![cfg_attr(test, allow(clippy::float_cmp, clippy::unreadable_literal, clippy::shadow_unrelated))]
3334
// deny(warnings) in doc tests

src/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn formats_list() -> Vec<FormatMetadata> {
8787
let mut formats = std::ptr::null_mut();
8888
let mut count: u64 = 0;
8989
let formats_slice = unsafe {
90-
check_success(ffi::chfl_formats_list(&mut formats, &mut count));
90+
check_success(ffi::chfl_formats_list(&raw mut formats, &raw mut count));
9191
std::slice::from_raw_parts(formats, count.try_into().expect("failed to convert u64 to usize"))
9292
};
9393
let formats_vec = formats_slice.iter().map(FormatMetadata::from_raw).collect();

src/property.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,23 @@ impl RawProperty {
5757
fn get_kind(&self) -> ffi::chfl_property_kind {
5858
let mut kind = ffi::chfl_property_kind::CHFL_PROPERTY_BOOL;
5959
unsafe {
60-
check_success(ffi::chfl_property_get_kind(self.as_ptr(), &mut kind));
60+
check_success(ffi::chfl_property_get_kind(self.as_ptr(), &raw mut kind));
6161
}
6262
return kind;
6363
}
6464

6565
fn get_bool(&self) -> Result<bool, Error> {
6666
let mut value = 0;
6767
unsafe {
68-
check(ffi::chfl_property_get_bool(self.as_ptr(), &mut value))?;
68+
check(ffi::chfl_property_get_bool(self.as_ptr(), &raw mut value))?;
6969
}
7070
return Ok(value != 0);
7171
}
7272

7373
fn get_double(&self) -> Result<f64, Error> {
7474
let mut value = 0.0;
7575
unsafe {
76-
check(ffi::chfl_property_get_double(self.as_ptr(), &mut value))?;
76+
check(ffi::chfl_property_get_double(self.as_ptr(), &raw mut value))?;
7777
}
7878
return Ok(value);
7979
}
@@ -178,7 +178,7 @@ pub struct PropertiesIter<'a> {
178178
pub(crate) getter: Box<dyn Fn(&str) -> Property + 'a>,
179179
}
180180

181-
impl<'a> Iterator for PropertiesIter<'a> {
181+
impl Iterator for PropertiesIter<'_> {
182182
type Item = (String, Property);
183183
fn next(&mut self) -> Option<Self::Item> {
184184
self.names.next().map(|name| {

0 commit comments

Comments
 (0)