Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cargo clippy warning and error #1274

Merged
merged 3 commits into from May 15, 2024

Conversation

rtczza
Copy link
Contributor

@rtczza rtczza commented May 13, 2024

clippy tips:

error[E0308]: mismatched types
   --> src/c_interface.rs:436:14
    |
433 | pub extern "C" fn sysinfo_process_parent_pid(process: CProcess) -> PID {
    |                                                                    --- expected `i32` because of return type
...
436 |     unsafe { (*process).parent().unwrap_or(Pid(0)).0 }
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `usize`
    |
help: you can convert a `usize` to an `i32` and panic if the converted value doesn't fit
    |
436 |     unsafe { (*process).parent().unwrap_or(Pid(0)).0.try_into().unwrap() }
    |                                                     ++++++++++++++++++++

For more information about this error, try `rustc --explain E0308`.

and :

warning: returning the result of a `let` binding from a block
   --> src/c_interface.rs:638:5
    |
633 | /     let c_string = if let Some(c) = System::long_os_version().and_then(|c| CString::new(c).ok()) {
634 | |         c.into_raw() as _
635 | |     } else {
636 | |         std::ptr::null()
637 | |     };
    | |______- unnecessary `let` binding
638 |       c_string
    |       ^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
    = note: `#[warn(clippy::let_and_return)]` on by default
help: return the expression directly
    |
633 ~     
634 ~     if let Some(c) = System::long_os_version().and_then(|c| CString::new(c).ok()) {
635 +         c.into_raw() as _
636 +     } else {
637 +         std::ptr::null()
638 +     }
    |

@@ -108,7 +108,7 @@ pub extern "C" fn sysinfo_refresh_process(system: CSystem, pid: PID) {
let mut system: Box<System> = Box::from_raw(system as *mut System);
{
let system: &mut System = system.borrow_mut();
system.refresh_process(Pid(pid));
system.refresh_process(Pid(pid.try_into().unwrap()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all these cases, as _ should be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, resubmitted.

@@ -586,55 +590,49 @@ pub extern "C" fn sysinfo_cpu_frequency(system: CSystem) -> u64 {
/// Equivalent of [`System::name()`][crate::System#method.name].
#[no_mangle]
pub extern "C" fn sysinfo_system_name() -> RString {
let c_string = if let Some(c) = System::name().and_then(|p| CString::new(p).ok()) {
if let Some(c) = System::name().and_then(|p| CString::new(p).ok()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 👍

@GuillaumeGomez
Copy link
Owner

Please run cargo fmt now to make CI happy then I'll merge.

@GuillaumeGomez GuillaumeGomez merged commit f55e934 into GuillaumeGomez:master May 15, 2024
67 checks passed
@GuillaumeGomez
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants