From b7bfbb0f907a581d9a931889aeb84fd19d1c52b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Wed, 5 May 2021 20:28:47 +0200 Subject: [PATCH] [rust] fix hundreds of clippy warnings --- rust/src/cells/methods.rs | 1 + rust/src/cells/reimplemented.rs | 3 ++ rust/src/cells/test/methods.rs | 2 +- rust/src/channel/methods.rs | 1 + rust/src/channel/reimplemented.rs | 1 + rust/src/channel/test/reimplemented.rs | 16 ++++++----- rust/src/direct/methods.rs | 11 ++++---- rust/src/fade.rs | 2 +- rust/src/file.rs | 36 ++++++++++++++---------- rust/src/input/keycodes.rs | 1 + rust/src/lib.rs | 4 +-- rust/src/macros.rs | 8 +++--- rust/src/notcurses/methods.rs | 17 ++++++----- rust/src/notcurses/mod.rs | 2 +- rust/src/notcurses/reimplemented.rs | 8 +++--- rust/src/pixel.rs | 1 + rust/src/plane/methods.rs | 33 ++++++++-------------- rust/src/plane/reimplemented.rs | 6 ++-- rust/src/resizecb.rs | 4 +-- rust/src/stats.rs | 2 +- rust/src/visual/methods.rs | 19 +++++++------ rust/src/widgets/menu/methods/menu.rs | 7 +++-- rust/src/widgets/menu/methods/options.rs | 8 +++--- rust/src/widgets/progbar/methods.rs | 2 +- rust/src/widgets/tree/methods/mod.rs | 8 +++--- rust/src/widgets/tree/methods/tree.rs | 19 ++++++------- 26 files changed, 113 insertions(+), 109 deletions(-) diff --git a/rust/src/cells/methods.rs b/rust/src/cells/methods.rs index db531f70f..4652e84bf 100644 --- a/rust/src/cells/methods.rs +++ b/rust/src/cells/methods.rs @@ -12,6 +12,7 @@ use crate::NcChannel; impl NcCell { /// New NcCell, expects a 7-bit [char]. #[inline] + #[allow(clippy::unnecessary_cast)] pub const fn with_char7b(ch: char) -> Self { NcCell { gcluster: (ch as u32).to_le(), diff --git a/rust/src/cells/reimplemented.rs b/rust/src/cells/reimplemented.rs index 477a8639e..cee5b34e8 100644 --- a/rust/src/cells/reimplemented.rs +++ b/rust/src/cells/reimplemented.rs @@ -192,6 +192,7 @@ pub fn nccell_bg_palindex_p(cell: &NcCell) -> bool { /// /// *Method: NcCell.[fg_palindex()][NcCell#method.fg_palindex].* #[inline] +#[allow(clippy::unnecessary_cast)] pub const fn nccell_fg_palindex(cell: &NcCell) -> NcPaletteIndex { ((cell.channels & 0xff00000000 as NcChannelPair) >> 32) as NcPaletteIndex } @@ -200,6 +201,7 @@ pub const fn nccell_fg_palindex(cell: &NcCell) -> NcPaletteIndex { /// /// *Method: NcCell.[bg_palindex()][NcCell#method.bg_palindex].* #[inline] +#[allow(clippy::unnecessary_cast)] pub const fn nccell_bg_palindex(cell: &NcCell) -> NcPaletteIndex { (cell.channels & 0xff) as NcPaletteIndex } @@ -213,6 +215,7 @@ pub const fn nccell_bg_palindex(cell: &NcCell) -> NcPaletteIndex { // // NOTE: unlike the original C function, this one can't fail #[inline] +#[allow(clippy::unnecessary_cast)] pub fn nccell_set_fg_palindex(cell: &mut NcCell, index: NcPaletteIndex) { cell.channels |= NCCELL_FGDEFAULT_MASK; cell.channels |= NCCELL_FG_PALETTE; diff --git a/rust/src/cells/test/methods.rs b/rust/src/cells/test/methods.rs index 4107ede8b..71444258b 100644 --- a/rust/src/cells/test/methods.rs +++ b/rust/src/cells/test/methods.rs @@ -1,6 +1,6 @@ //! Test `NcCell` methods and associated functions. -use crate::{Notcurses, NcCell, NcPlane}; +use crate::{NcCell, NcPlane, Notcurses}; use serial_test::serial; diff --git a/rust/src/channel/methods.rs b/rust/src/channel/methods.rs index 0afa73cd1..d0c342d22 100644 --- a/rust/src/channel/methods.rs +++ b/rust/src/channel/methods.rs @@ -1,4 +1,5 @@ //! `NcChannel*` methods and associated functions. +#![allow(clippy::unnecessary_cast)] use crate::{NcAlphaBits, NcChannel, NcChannelPair, NcColor, NcPaletteIndex, NcRgb}; diff --git a/rust/src/channel/reimplemented.rs b/rust/src/channel/reimplemented.rs index cd5888b55..535453a17 100644 --- a/rust/src/channel/reimplemented.rs +++ b/rust/src/channel/reimplemented.rs @@ -487,6 +487,7 @@ pub fn ncchannels_bg_palindex_p(channels: NcChannelPair) -> bool { /// /// *Method: NcChannelPair.[set_fg_palindex()][NcChannelPair#method.set_fg_palindex]* #[inline] +#[allow(clippy::unnecessary_cast)] pub fn ncchannels_set_fg_palindex(channels: &mut NcChannelPair, index: NcPaletteIndex) { *channels |= NCCELL_FGDEFAULT_MASK; *channels |= NCCELL_FG_PALETTE as NcChannelPair; diff --git a/rust/src/channel/test/reimplemented.rs b/rust/src/channel/test/reimplemented.rs index 2774dc4d8..10a58cb89 100644 --- a/rust/src/channel/test/reimplemented.rs +++ b/rust/src/channel/test/reimplemented.rs @@ -84,7 +84,6 @@ fn channel_set() { assert_eq!(false, crate::ncchannel_default_p(c)); } - /// gets the alpha component #[test] #[serial] @@ -128,11 +127,14 @@ fn channel_set_default() { assert_eq!(0x_20_112233, channel_transp); // the transparent bit is now set crate::ncchannel_set_not_default(&mut channel_transp); - // both the "not default" & transparent bits are now set + // both the "not default" & transparent bits are now set assert_eq!(0x_60_112233, channel_transp); // and calling set_default() should make it both default & opaque again - assert_eq!(0x_00_112233, crate::ncchannel_set_default(&mut channel_transp)); + assert_eq!( + 0x_00_112233, + crate::ncchannel_set_default(&mut channel_transp) + ); } /// sets the channel as *not* using the default color @@ -169,7 +171,7 @@ fn channel_default_p() { // NcChannelPair tests --------------------------------------------------------- -/// +/// #[test] #[serial] #[allow(non_snake_case)] @@ -180,7 +182,7 @@ fn channels_set_fchannel__channels_fchannel() { assert_eq!(crate::ncchannels_fchannel(cp), fc); } -/// +/// #[test] #[serial] #[allow(non_snake_case)] @@ -191,7 +193,7 @@ fn channels_set_bchannel__channels_bchannel() { assert_eq!(crate::ncchannels_bchannel(cp), bc); } -/// +/// #[test] #[serial] fn channels_combine() { @@ -205,7 +207,7 @@ fn channels_combine() { assert_eq!(cp1, _cp2); } -/// +/// #[test] #[serial] fn channels_palette() { diff --git a/rust/src/direct/methods.rs b/rust/src/direct/methods.rs index e6c9a03d7..9da3f6a3e 100644 --- a/rust/src/direct/methods.rs +++ b/rust/src/direct/methods.rs @@ -297,14 +297,13 @@ impl NcDirect { /// Must not be called concurrently with either input or rasterization. /// /// *C style function: [ncdirect_check_pixel_support()][crate::ncdirect_check-pixel_support].* + #[allow(clippy::wildcard_in_or_patterns)] pub fn check_pixel_support(&mut self) -> NcResult { let res = unsafe { crate::ncdirect_check_pixel_support(self) }; match res { - 0 => return Ok(false), - 1 => return Ok(true), - NCRESULT_ERR | _ => { - return Err(NcError::with_msg(res, "NcDirect.check_pixel_support()")); - } + 0 => Ok(false), + 1 => Ok(true), + NCRESULT_ERR | _ => Err(NcError::with_msg(res, "NcDirect.check_pixel_support()")), } } @@ -552,7 +551,7 @@ impl NcDirect { /// *C style function: [ncdirect_readline()][crate::ncdirect_readline].* pub fn readline(&mut self, prompt: &str) -> NcResult<&str> { let res = unsafe { crate::ncdirect_readline(self, cstring![prompt]) }; - if res != null_mut() { + if !res.is_null() { return Ok(rstring![res]); } else { Err(NcError::with_msg( diff --git a/rust/src/fade.rs b/rust/src/fade.rs index c79613425..7b595ffbf 100644 --- a/rust/src/fade.rs +++ b/rust/src/fade.rs @@ -32,7 +32,7 @@ impl NcFadeCtx { /// Rather than the simple ncplane_fade{in/out}(), /// ncfadectx_setup() can be paired with a loop over /// ncplane_fade{in/out}_iteration() + ncfadectx_free(). - pub fn setup<'a>(plane: &'a mut NcPlane) -> &'a mut NcFadeCtx { + pub fn setup(plane: &mut NcPlane) -> &mut NcFadeCtx { unsafe { &mut *crate::ncfadectx_setup(plane) } } diff --git a/rust/src/file.rs b/rust/src/file.rs index 3085815e8..d7bbb59f4 100644 --- a/rust/src/file.rs +++ b/rust/src/file.rs @@ -7,13 +7,17 @@ use core::ptr::{null_mut, NonNull}; use std::io::{Error, ErrorKind, Read, Seek, SeekFrom}; -use libc::{c_long, c_void, fclose, feof, fread, fseek, ftell, SEEK_CUR, SEEK_END, SEEK_SET}; +use libc::{ + c_long, c_void, fclose, /* feof, */ fread, fseek, ftell, SEEK_CUR, SEEK_END, SEEK_SET, +}; /// See [NcFile]. Notcurses functions expects this type of `*FILE` (a struct) +#[allow(clippy::upper_case_acronyms)] pub type FILE_NC = crate::ffi::_IO_FILE; /// See [NcFile]. The [`libc`](https://docs.rs/libc/) crate expects this type /// of `*FILE` (an opaque enum) +#[allow(clippy::upper_case_acronyms)] pub type FILE_LIBC = libc::FILE; // TODO: the following static strings aren't made public @@ -22,34 +26,34 @@ pub type FILE_LIBC = libc::FILE; /// It will open the file in a way that will allow reading and writing, /// including overwriting old data. /// It will not create the file if it does not exist. -pub static RANDOM_ACCESS_MODE: &'static str = "rb+"; +pub static RANDOM_ACCESS_MODE: &str = "rb+"; /// Intended to be passed into the CFile::open method. /// It will open the file in a way that will allow reading and writing, /// including overwriting old data -pub static UPDATE: &'static str = "rb+"; +pub static UPDATE: &str = "rb+"; /// Intended to be passed into the CFile::open method. /// It will only allow reading. -pub static READ_ONLY: &'static str = "r"; +pub static READ_ONLY: &str = "r"; /// Intended to be passed into the CFile::open method. /// It will only allow writing. -pub static WRITE_ONLY: &'static str = "w"; +pub static WRITE_ONLY: &str = "w"; /// Intended to be passed into the CFile::open method. /// It will only allow data to be appended to the end of the file. -pub static APPEND_ONLY: &'static str = "a"; +pub static APPEND_ONLY: &str = "a"; /// Intended to be passed into the CFile::open method. /// It will allow data to be appended to the end of the file, and data to be /// read from the file. It will create the file if it doesn't exist. -pub static APPEND_READ: &'static str = "a+"; +pub static APPEND_READ: &str = "a+"; /// Intended to be passed into the CFile::open method. /// It will open the file in a way that will allow reading and writing, /// including overwriting old data. It will create the file if it doesn't exist -pub static TRUNCATE_RANDOM_ACCESS_MODE: &'static str = "wb+"; +pub static TRUNCATE_RANDOM_ACCESS_MODE: &str = "wb+"; /// A utility function to pull the current value of errno and put it into an /// Error::Errno @@ -83,9 +87,9 @@ impl NcFile { } /// `NcFile` constructor from a file produced by the libc crate - pub fn from_libc(file: *mut FILE_LIBC) -> Self { + pub unsafe fn from_libc(file: *mut FILE_LIBC) -> Self { NcFile { - file_ptr: unsafe { NonNull::new_unchecked(file) }, + file_ptr: NonNull::new_unchecked(file), } } @@ -265,11 +269,13 @@ impl Read for NcFile { Ok(()) } else { // Check if we hit the end of the file - if feof(self.as_libc_ptr()) != 0 { - get_error() - } else { - get_error() - } + // FIXME + // if feof(self.as_libc_ptr()) != 0 { + // get_error() + // } else { + // get_error() + // } + get_error() } } } diff --git a/rust/src/input/keycodes.rs b/rust/src/input/keycodes.rs index c43ae68b3..57c8a8ad3 100644 --- a/rust/src/input/keycodes.rs +++ b/rust/src/input/keycodes.rs @@ -1,4 +1,5 @@ //! Special composed key definitions. These values are added to 0x100000. +#![allow(clippy::transmute_int_to_char)] use std::mem::transmute; diff --git a/rust/src/lib.rs b/rust/src/lib.rs index cde914146..fdf1ffbce 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -90,7 +90,7 @@ //! }; //! unsafe { //! let nc = notcurses_init(&options, null_mut()); -//! if nc == null_mut() { +//! if nc.is_null() { //! exit(1); //! } //! let plane = notcurses_stdplane(nc); @@ -117,7 +117,7 @@ //! - [Doxygen Documentation](https://nick-black.com/notcurses/html/index.html) //! #![allow(non_upper_case_globals, non_camel_case_types, non_snake_case)] -#![allow(clippy::too_many_arguments)] +#![allow(clippy::too_many_arguments, clippy::needless_doctest_main)] mod bindings; #[doc(inline)] diff --git a/rust/src/macros.rs b/rust/src/macros.rs index 99a8c8c0f..559645fef 100644 --- a/rust/src/macros.rs +++ b/rust/src/macros.rs @@ -140,7 +140,7 @@ macro_rules! error { /// or an `Err(`[`NcError`]`)` if the pointer is null. /// /// In other words: -/// Returns Ok(&*`$ptr`) if `$ptr` != `null()`, otherwise returns +/// Returns Ok(&*`$ptr`) if `!$ptr.is_null()`, otherwise returns /// Err([NcError]]::[new][NcError#method.new]([NCRESULT_ERR], `$msg`)). /// /// `$msg` is optional. By default it will be an empty `&str` `""`. @@ -169,7 +169,7 @@ macro_rules! error_ref { /// or an `Err(`[`NcError`]`)` if the pointer is null. /// /// In other words: -/// Returns Ok(&mut *`$ptr`) if `$ptr` != `null_mut()`, otherwise returns +/// Returns Ok(&mut *`$ptr`) if `!$ptr._is_null()`, otherwise returns /// Err([NcError]]::[new][NcError#method.new]([NCRESULT_ERR], `$msg`)). /// /// `$msg` is optional. By default it will be an empty `&str` `""`. @@ -198,14 +198,14 @@ macro_rules! error_ref_mut { /// or an `Err(`[`NcError`]`)` if the pointer is null. /// /// In other words: -/// Returns Ok((&*`$str`).to_string()) if `$str` != `null()`, otherwise returns +/// Returns Ok((&*`$str`).to_string()) if `!$str.is_null()`, otherwise returns /// Err([NcError]]::[new][NcError#method.new]([NCRESULT_ERR], `$msg`)). /// /// `$msg` is optional. By default it will be an empty `&str` `""`. #[macro_export] macro_rules! error_str { ($str:expr, $msg:expr) => { - if $str != core::ptr::null_mut() { + if $str.is_null() { #[allow(unused_unsafe)] return Ok(unsafe { (&*$str).to_string() }); } else { diff --git a/rust/src/notcurses/methods.rs b/rust/src/notcurses/methods.rs index 5533a79fe..1e324a238 100644 --- a/rust/src/notcurses/methods.rs +++ b/rust/src/notcurses/methods.rs @@ -156,7 +156,7 @@ impl Notcurses { /// Returns the bottommost [NcPlane], of which there is always at least one. /// /// *C style function: [notcurses_bottom()][crate::notcurses_bottom].* - pub fn bottom<'a>(&'a mut self) -> &'a mut NcPlane { + pub fn bottom(&mut self) -> &mut NcPlane { unsafe { &mut *crate::notcurses_bottom(self) } } @@ -259,14 +259,13 @@ impl Notcurses { /// Must not be called concurrently with either input or rasterization. /// /// *C style function: [notcurses_check_pixel_support()][crate::notcurses_check-pixel_support].* + #[allow(clippy::wildcard_in_or_patterns)] pub fn check_pixel_support(&mut self) -> NcResult { let res = unsafe { crate::notcurses_check_pixel_support(self) }; match res { - 0 => return Ok(false), - 1 => return Ok(true), - NCRESULT_ERR | _ => { - return Err(NcError::with_msg(res, "Notcuses.check_pixel_support()")); - } + 0 => Ok(false), + 1 => Ok(true), + NCRESULT_ERR | _ => Err(NcError::with_msg(res, "Notcuses.check_pixel_support()")), } } @@ -396,7 +395,7 @@ impl Notcurses { // An invalid read is indicated with -1 if res as u32 as i32 != -1 { - return Ok(res); + Ok(res) } else { error![ -1, @@ -586,7 +585,7 @@ impl Notcurses { /// Notcurses might enlarge this structure. /// /// *C style function: [notcurses_stats_alloc()][crate::notcurses_stats_alloc].* - pub fn stats_alloc<'a>(&'a mut self) -> &'a mut NcStats { + pub fn stats_alloc(&mut self) -> &mut NcStats { unsafe { &mut *crate::notcurses_stats_alloc(self) } } @@ -690,7 +689,7 @@ impl Notcurses { /// Returns the topmost [NcPlane], of which there is always at least one. /// /// *C style function: [notcurses_top()][crate::notcurses_top].* - pub fn top<'a>(&'a mut self) -> &'a mut NcPlane { + pub fn top(&mut self) -> &mut NcPlane { unsafe { &mut *crate::notcurses_top(self) } } diff --git a/rust/src/notcurses/mod.rs b/rust/src/notcurses/mod.rs index c085354a7..7f6389710 100644 --- a/rust/src/notcurses/mod.rs +++ b/rust/src/notcurses/mod.rs @@ -1,5 +1,5 @@ //! `Notcurses` - + // total: 51 // --------------------------------------------------- // (X) 1 : wont do diff --git a/rust/src/notcurses/reimplemented.rs b/rust/src/notcurses/reimplemented.rs index b31399d5e..c7afdc91a 100644 --- a/rust/src/notcurses/reimplemented.rs +++ b/rust/src/notcurses/reimplemented.rs @@ -46,7 +46,7 @@ pub fn notcurses_getc_nblock(nc: &mut Notcurses, input: &mut NcInput) -> char { tv_sec: 0, tv_nsec: 0, }; - core::char::from_u32_unchecked(crate::notcurses_getc(nc, &ts, &mut sigmask, input)) + core::char::from_u32_unchecked(crate::notcurses_getc(nc, &ts, &sigmask, input)) } } @@ -68,7 +68,7 @@ pub fn notcurses_getc_blocking(nc: &mut Notcurses, input: Option<&mut NcInput>) unsafe { let mut sigmask = NcSignalSet::new(); sigmask.emptyset(); - core::char::from_u32_unchecked(crate::notcurses_getc(nc, null(), &mut sigmask, input_ptr)) + core::char::from_u32_unchecked(crate::notcurses_getc(nc, null(), &sigmask, input_ptr)) } } @@ -84,7 +84,7 @@ pub fn notcurses_stddim_yx<'a>( ) -> NcResult<&'a mut NcPlane> { unsafe { let sp = crate::notcurses_stdplane(nc); - if sp != null_mut() { + if !sp.is_null() { crate::ncplane_dim_yx(sp, &mut (*y as i32), &mut (*x as i32)); return Ok(&mut *sp); } @@ -104,7 +104,7 @@ pub fn notcurses_stddim_yx_const<'a>( ) -> NcResult<&'a NcPlane> { unsafe { let sp = crate::notcurses_stdplane_const(nc); - if sp != null() { + if !sp.is_null() { crate::ncplane_dim_yx(sp, &mut (*y as i32), &mut (*x as i32)); return Ok(&*sp); } diff --git a/rust/src/pixel.rs b/rust/src/pixel.rs index f18254afa..fbc89104a 100644 --- a/rust/src/pixel.rs +++ b/rust/src/pixel.rs @@ -56,6 +56,7 @@ pub type NcPixel = u32; /// Constructs a libav-compatible ABGR pixel from [NcColor] RGB components. #[inline] +#[allow(clippy::unnecessary_cast)] pub const fn ncpixel(red: NcColor, green: NcColor, blue: NcColor) -> NcPixel { 0xff000000 as NcPixel | red as NcPixel | (blue as NcPixel) << 8 | (green as NcPixel) << 16 } diff --git a/rust/src/plane/methods.rs b/rust/src/plane/methods.rs index b29d40e90..58f87e222 100644 --- a/rust/src/plane/methods.rs +++ b/rust/src/plane/methods.rs @@ -285,12 +285,7 @@ impl NcPlane { #[inline] pub fn fg_rgb8(&self) -> (NcColor, NcColor, NcColor) { let (mut r, mut g, mut b) = (0, 0, 0); - let _ = crate::ncchannels_fg_rgb8( - crate::ncplane_channels(self), - &mut r, - &mut g, - &mut b, - ); + let _ = crate::ncchannels_fg_rgb8(crate::ncplane_channels(self), &mut r, &mut g, &mut b); (r, g, b) } @@ -300,12 +295,7 @@ impl NcPlane { #[inline] pub fn bg_rgb8(&self) -> (NcColor, NcColor, NcColor) { let (mut r, mut g, mut b) = (0, 0, 0); - let _ = crate::ncchannels_bg_rgb8( - crate::ncplane_channels(self), - &mut r, - &mut g, - &mut b, - ); + let _ = crate::ncchannels_bg_rgb8(crate::ncplane_channels(self), &mut r, &mut g, &mut b); (r, g, b) } @@ -831,7 +821,7 @@ impl NcPlane { let cols = self.putstr(string)?; let (y, _x) = self.cursor_yx(); self.cursor_move_yx(y + 1, 0)?; - return Ok(cols); + Ok(cols) } /// Same as [putstr_yx()][NcPlane#method.putstr_yx] but [NcAlign]ed on x. @@ -929,14 +919,14 @@ impl NcPlane { /// *C style function: [ncplane_dup()][crate::ncplane_dup].* // // TODO: deal with the opaque field. - pub fn dup<'a>(&'a mut self) -> &'a mut NcPlane { + pub fn dup(&mut self) -> &mut NcPlane { unsafe { &mut *crate::ncplane_dup(self, null_mut()) } } /// Returns the topmost NcPlane of the current pile. /// /// *C style function: [ncpile_top()][crate::ncpile_top].* - pub fn top<'a>(&mut self) -> &'a mut NcPlane { + pub fn top(&mut self) -> &mut NcPlane { unsafe { &mut *crate::ncpile_top(self) } } @@ -994,14 +984,14 @@ impl NcPlane { /// Returns the NcPlane above this one, or None if already at the top. /// /// *C style function: [ncplane_above()][crate::ncplane_above].* - pub fn above<'a>(&'a mut self) -> NcResult<&'a mut NcPlane> { + pub fn above(&mut self) -> NcResult<&mut NcPlane> { error_ref_mut![unsafe { crate::ncplane_above(self) }, "NcPlane.above()"] } /// Returns the NcPlane below this one, or None if already at the bottom. /// /// *C style function: [ncplane_below()][crate::ncplane_below].* - pub fn below<'a>(&'a mut self) -> NcResult<&'a mut NcPlane> { + pub fn below(&mut self) -> NcResult<&mut NcPlane> { error_ref_mut![unsafe { crate::ncplane_below(self) }, "NcPlane.below()"] } @@ -1098,7 +1088,7 @@ impl NcPlane { /// *C style function: [ncplane_parent()][crate::ncplane_parent].* // // TODO: CHECK: what happens when it's bound to itself. - pub fn parent<'a>(&'a mut self) -> NcResult<&'a mut NcPlane> { + pub fn parent(&mut self) -> NcResult<&mut NcPlane> { error_ref_mut![unsafe { crate::ncplane_parent(self) }, "NcPlane.parent()"] } @@ -1107,7 +1097,7 @@ impl NcPlane { /// *C style function: [ncplane_parent_const()][crate::ncplane_parent_const].* // // CHECK: what happens when it's bound to itself. - pub fn parent_const<'a>(&'a self) -> NcResult<&'a NcPlane> { + pub fn parent_const(&self) -> NcResult<&NcPlane> { error_ref![ unsafe { crate::ncplane_parent_const(self) }, "NcPlane.parent_const()" @@ -1155,7 +1145,7 @@ impl NcPlane { /// rendered (doing so will likely result in a blank screen). /// /// *C style function: [ncpile_rasterize()][crate::ncpile_rasterize].* - pub fn rasterize<'a>(&mut self) -> NcResult<()> { + pub fn rasterize(&mut self) -> NcResult<()> { error![ unsafe { crate::ncpile_rasterize(self) }, "NcPlane.rasterize()" @@ -1167,7 +1157,7 @@ impl NcPlane { /// To actually write out the render, call ncpile_rasterize(). /// /// *C style function: [ncpile_render()][crate::ncpile_render].* - pub fn render<'a>(&mut self) -> NcResult<()> { + pub fn render(&mut self) -> NcResult<()> { error![unsafe { crate::ncpile_render(self) }, "NcPlane.render()"] } @@ -1943,7 +1933,6 @@ impl NcPlane { y_stop: NcDim, x_stop: NcDim, ) -> NcResult { - // https://github.com/dankamongmen/notcurses/issues/1339 #[cfg(any(target_arch = "x86_64", target_arch = "i686"))] let egc_ptr = &(*egc as i8); diff --git a/rust/src/plane/reimplemented.rs b/rust/src/plane/reimplemented.rs index a5cf8f795..cacba4777 100644 --- a/rust/src/plane/reimplemented.rs +++ b/rust/src/plane/reimplemented.rs @@ -4,9 +4,8 @@ use core::ptr::null_mut; use crate::ffi::__va_list_tag; use crate::{ - cstring, nccell_release, NcAlign, NcAlphaBits, NcBoxMask, NcCell, NcChannel, - NcChannelPair, NcColor, NcDim, NcEgc, NcIntResult, NcPlane, NcRgb, NcStyleMask, NCRESULT_ERR, - NCRESULT_OK, + cstring, nccell_release, NcAlign, NcAlphaBits, NcBoxMask, NcCell, NcChannel, NcChannelPair, + NcColor, NcDim, NcEgc, NcIntResult, NcPlane, NcRgb, NcStyleMask, NCRESULT_ERR, NCRESULT_OK, }; // Alpha ----------------------------------------------------------------------- @@ -79,7 +78,6 @@ pub fn ncplane_set_channels(plane: &mut NcPlane, channels: NcChannelPair) { unsafe { crate::ffi::ncplane_set_channels(plane, channels) }; } - // NcColor --------------------------------------------------------------------- /// Gets the foreground [NcColor] RGB components from an [NcPlane]. diff --git a/rust/src/resizecb.rs b/rust/src/resizecb.rs index dc2d0be52..c5ad31f23 100644 --- a/rust/src/resizecb.rs +++ b/rust/src/resizecb.rs @@ -14,7 +14,7 @@ pub type NcResizeCbUnsafe = unsafe extern "C" fn(*mut NcPlane) -> NcIntResult; /// Converts [NcResizeCbUnsafe] to [NcResizeCb]. pub fn ncresizecb_to_rust(resizecb: Option) -> Option { if let Some(cb) = resizecb { - return Some(unsafe { core::mem::transmute(cb) }); + Some(unsafe { core::mem::transmute(cb) }) } else { None } @@ -26,7 +26,7 @@ pub fn ncresizecb_to_rust(resizecb: Option) -> Option) -> Option { if let Some(cb) = resizecb { - return Some(unsafe { core::mem::transmute(cb) }); + Some(unsafe { core::mem::transmute(cb) }) } else { None } diff --git a/rust/src/stats.rs b/rust/src/stats.rs index 23255465e..de19f5e83 100644 --- a/rust/src/stats.rs +++ b/rust/src/stats.rs @@ -8,7 +8,7 @@ pub type NcStats = crate::bindings::ffi::ncstats; /// # `NcStats` Methods. impl NcStats { /// Allocates an NcStats object. - pub fn new<'a>(nc: &'a Notcurses) -> &'a mut Self { + pub fn new(nc: &mut Notcurses) -> &mut Self { unsafe { &mut *crate::notcurses_stats_alloc(nc) } } diff --git a/rust/src/visual/methods.rs b/rust/src/visual/methods.rs index 6b246bbd9..c4f6d2e0a 100644 --- a/rust/src/visual/methods.rs +++ b/rust/src/visual/methods.rs @@ -118,7 +118,7 @@ impl NcVisual { cols as i32, ) }, - &format!("NcVisual::from_bgra()") + "NcVisual::from_bgra()" ] } @@ -129,7 +129,7 @@ impl NcVisual { pub fn from_file<'a>(file: &str) -> NcResult<&'a mut NcVisual> { error_ref_mut![ unsafe { crate::ncvisual_from_file(cstring![file]) }, - &format!("NcVisual::from_file()") + &format!("NcVisual::from_file({})", file) ] } @@ -162,7 +162,10 @@ impl NcVisual { len_x as i32, ) }, - &format!("NcVisual::from_file()") + &format!( + "NcVisual::from_file({}, {}, {}, {}, {})", + blitter, beg_y, beg_x, len_y, len_x + ) ] } @@ -192,7 +195,7 @@ impl NcVisual { cols as i32, ) }, - &format!("NcVisual::from_rgba()") + &format!("NcVisual::from_rgba({}, {}, {})", rows, rowstride, cols) ] } @@ -226,7 +229,7 @@ impl NcVisual { pub fn decode(&mut self) -> NcResult { let res = unsafe { crate::ncvisual_decode(self) }; if res == NCRESULT_ERR { - return Err(NcError::with_msg(res, "NcVisual.decode()")); + Err(NcError::with_msg(res, "NcVisual.decode()")) } else { Ok(res) } @@ -244,7 +247,7 @@ impl NcVisual { pub fn decode_loop(&mut self) -> NcResult { let res = unsafe { crate::ncvisual_decode_loop(self) }; if res == NCRESULT_ERR { - return Err(NcError::with_msg(res, "NcVisual.decode_loop()")); + Err(NcError::with_msg(res, "NcVisual.decode_loop()")) } else { Ok(res) } @@ -449,8 +452,8 @@ impl NcVisual { /// *C style function: [ncvisual_subtitle()][crate::ncvisual_subtitle].* pub fn subtitle(&self) -> NcResult<&str> { let res = unsafe { crate::ncvisual_subtitle(self) }; - if res != null_mut() { - return Ok(rstring![res]); + if !res.is_null() { + Ok(rstring![res]) } else { Err(NcError::with_msg(NCRESULT_ERR, "NcVisual.subtitle()")) } diff --git a/rust/src/widgets/menu/methods/menu.rs b/rust/src/widgets/menu/methods/menu.rs index ee52905d0..a2c1871a5 100644 --- a/rust/src/widgets/menu/methods/menu.rs +++ b/rust/src/widgets/menu/methods/menu.rs @@ -157,10 +157,11 @@ impl NcMenu { ninput = null_mut(); } let res = unsafe { crate::ncmenu_selected(self, ninput) }; - if res != null_mut() { - return Some(unsafe { (&*res).to_string() }); + if !res.is_null() { + Some(unsafe { (&*res).to_string() }) + } else { + None } - None } /// Unrolls the specified [NcMenuSection][crate::NcMenuSection], diff --git a/rust/src/widgets/menu/methods/options.rs b/rust/src/widgets/menu/methods/options.rs index a239047d5..23af37841 100644 --- a/rust/src/widgets/menu/methods/options.rs +++ b/rust/src/widgets/menu/methods/options.rs @@ -18,7 +18,7 @@ impl NcMenuOptions { style_sections: NcChannelPair, flags: u64, ) -> Self { - assert![sections.len() > 0]; + assert![!sections.is_empty()]; Self { // array of 'sectioncount' `MenuSection`s sections: sections.as_mut_ptr(), @@ -33,7 +33,7 @@ impl NcMenuOptions { sectionchannels: style_sections, // flag word of NCMENU_OPTION_* - flags: flags, + flags, } } } @@ -50,7 +50,7 @@ impl NcMenuOptions { /// Returns a mutable reference of the styling for the sections. /// /// *(No equivalent C style function)* - pub fn header_channels_mut<'a>(&'a mut self) -> &'a mut NcChannelPair { + pub fn header_channels_mut(&mut self) -> &mut NcChannelPair { &mut self.headerchannels } @@ -64,7 +64,7 @@ impl NcMenuOptions { /// Returns a mutable reference of the styling for the sections. /// /// *(No equivalent C style function)* - pub fn section_channels_mut<'a>(&'a mut self) -> &'a mut NcChannelPair { + pub fn section_channels_mut(&mut self) -> &mut NcChannelPair { &mut self.sectionchannels } } diff --git a/rust/src/widgets/progbar/methods.rs b/rust/src/widgets/progbar/methods.rs index 54f6a53bf..96d3868ce 100644 --- a/rust/src/widgets/progbar/methods.rs +++ b/rust/src/widgets/progbar/methods.rs @@ -45,7 +45,7 @@ impl NcProgBar { /// Return a reference to the ncprogbar's underlying ncplane. /// /// *C style function: [ncprogbar_plane()][crate::ncprogbar_plane].* - pub fn plane<'a>(&'a mut self) -> &'a mut NcPlane { + pub fn plane(&mut self) -> &mut NcPlane { unsafe { &mut *crate::ncprogbar_plane(self) } } diff --git a/rust/src/widgets/tree/methods/mod.rs b/rust/src/widgets/tree/methods/mod.rs index e2bc74460..009af8001 100644 --- a/rust/src/widgets/tree/methods/mod.rs +++ b/rust/src/widgets/tree/methods/mod.rs @@ -16,17 +16,17 @@ impl NcTreeItem { /// Creates an [NcTreeItem]. pub fn new(curry: &str, subs: Option<&mut [NcTreeItem]>, subcount: usize) -> Self { if let Some(subs) = subs { - return Self { + Self { curry: CString::new(curry).unwrap().into_raw() as *mut _ as *mut c_void, subs: subs.as_mut_ptr(), subcount: subcount as u32, - }; + } } else { - return Self { + Self { curry: CString::new(curry).unwrap().into_raw() as *mut _ as *mut c_void, subs: null_mut(), subcount: subcount as u32, - }; + } } } } diff --git a/rust/src/widgets/tree/methods/tree.rs b/rust/src/widgets/tree/methods/tree.rs index 42cde83e9..f1f359331 100644 --- a/rust/src/widgets/tree/methods/tree.rs +++ b/rust/src/widgets/tree/methods/tree.rs @@ -1,5 +1,3 @@ -use core::ptr::null_mut; - use crate::{ error, error_ref_mut, nctree_create, NcError, NcInput, NcPlane, NcResult, NcTree, NcTreeItem, NcTreeOptions, NCRESULT_ERR, @@ -38,8 +36,8 @@ impl NcTree { // /// *C style function: [nctree_goto()][crate::nctree_goto].* // pub fn goto(&mut self, spec: ... , failspec: ...) -> NcResult<&mut NcTreeItem> { // let res = unsafe { crate::nctree_goto(self) }; - // if res != null_mut() { - // return Ok(unsafe { &mut *(res as *mut NcTreeItem) }); + // if !res.is_null() { + // Ok(unsafe { &mut *(res as *mut NcTreeItem) }) // } else { // Err(NcError::with_msg(NCRESULT_ERR, "NcTree.goto()")) // } @@ -53,8 +51,8 @@ impl NcTree { /// *C style function: [nctree_focused()][crate::nctree_focused].* pub fn focused(&mut self) -> NcResult<&mut NcTreeItem> { let res = unsafe { crate::nctree_focused(self) }; - if res != null_mut() { - return Ok(unsafe { &mut *(res as *mut NcTreeItem) }); + if !res.is_null() { + Ok(unsafe { &mut *(res as *mut NcTreeItem) }) } else { Err(NcError::with_msg(NCRESULT_ERR, "NcTree.focused()")) } @@ -63,10 +61,11 @@ impl NcTree { /// Changes the focus to the next item, and returns it. /// /// *C style function: [nctree_next()][crate::nctree_next].* + #[allow(clippy::should_implement_trait)] pub fn next(&mut self) -> NcResult<&mut NcTreeItem> { let res = unsafe { crate::nctree_next(self) }; - if res != null_mut() { - return Ok(unsafe { &mut *(res as *mut NcTreeItem) }); + if !res.is_null() { + Ok(unsafe { &mut *(res as *mut NcTreeItem) }) } else { Err(NcError::with_msg(NCRESULT_ERR, "NcTree.next()")) } @@ -77,8 +76,8 @@ impl NcTree { /// *C style function: [nctree_prev()][crate::nctree_prev].* pub fn prev(&mut self) -> NcResult<&mut NcTreeItem> { let res = unsafe { crate::nctree_prev(self) }; - if res != null_mut() { - return Ok(unsafe { &mut *(res as *mut NcTreeItem) }); + if !res.is_null() { + Ok(unsafe { &mut *(res as *mut NcTreeItem) }) } else { Err(NcError::with_msg(NCRESULT_ERR, "NcTree.prev()")) }