xous: fix various clippy warnings

This stylistic cleanup fixes several clippy warnings.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-08-05 16:57:48 +08:00
parent 75fbf173a9
commit 66005b8b6f
4 changed files with 33 additions and 21 deletions

View file

@ -143,8 +143,8 @@ pub fn process_to_args(call: usize, init: &ProcessInit) -> [usize; 8] {
call, call,
u32::from_le_bytes(init.key.0[0..4].try_into().unwrap()) as _, u32::from_le_bytes(init.key.0[0..4].try_into().unwrap()) as _,
u32::from_le_bytes(init.key.0[4..8].try_into().unwrap()) as _, u32::from_le_bytes(init.key.0[4..8].try_into().unwrap()) as _,
u32::from_le_bytes(init.key.0[8..12].try_into().unwrap()) as _, 0,
u32::from_le_bytes(init.key.0[12..16].try_into().unwrap()) as _, 0,
0, 0,
0, 0,
0, 0,
@ -167,7 +167,7 @@ pub fn create_thread_0_pre<U>(f: &fn() -> U) -> core::result::Result<ThreadInit,
where where
U: Send + 'static, U: Send + 'static,
{ {
let start = unsafe { core::mem::transmute(*f) }; let start = *f as usize;
create_thread_n_pre(start, &0, &0, &0, &0) create_thread_n_pre(start, &0, &0, &0, &0)
} }
@ -178,7 +178,7 @@ pub fn create_thread_0_post<U>(
where where
U: Send + 'static, U: Send + 'static,
{ {
let start = unsafe { core::mem::transmute(f) }; let start = f as usize;
create_thread_n_post(start, 0, 0, 0, 0, thread_id) create_thread_n_post(start, 0, 0, 0, 0, thread_id)
} }
@ -189,7 +189,7 @@ pub fn create_thread_1_pre<U>(
where where
U: Send + 'static, U: Send + 'static,
{ {
let start = unsafe { core::mem::transmute(*f) }; let start = *f as usize;
create_thread_n_pre(start, arg1, &0, &0, &0) create_thread_n_pre(start, arg1, &0, &0, &0)
} }
@ -201,7 +201,7 @@ pub fn create_thread_1_post<U>(
where where
U: Send + 'static, U: Send + 'static,
{ {
let start = unsafe { core::mem::transmute(f) }; let start = f as usize;
create_thread_n_post(start, arg1, 0, 0, 0, thread_id) create_thread_n_post(start, arg1, 0, 0, 0, thread_id)
} }
@ -213,7 +213,7 @@ pub fn create_thread_2_pre<U>(
where where
U: Send + 'static, U: Send + 'static,
{ {
let start = unsafe { core::mem::transmute(*f) }; let start = *f as usize;
create_thread_n_pre(start, arg1, arg2, &0, &0) create_thread_n_pre(start, arg1, arg2, &0, &0)
} }
@ -226,7 +226,7 @@ pub fn create_thread_2_post<U>(
where where
U: Send + 'static, U: Send + 'static,
{ {
let start = unsafe { core::mem::transmute(f) }; let start = f as usize;
create_thread_n_post(start, arg1, arg2, 0, 0, thread_id) create_thread_n_post(start, arg1, arg2, 0, 0, thread_id)
} }
@ -239,7 +239,7 @@ pub fn create_thread_3_pre<U>(
where where
U: Send + 'static, U: Send + 'static,
{ {
let start = unsafe { core::mem::transmute(*f) }; let start = *f as usize;
create_thread_n_pre(start, arg1, arg2, arg3, &0) create_thread_n_pre(start, arg1, arg2, arg3, &0)
} }
@ -253,7 +253,7 @@ pub fn create_thread_3_post<U>(
where where
U: Send + 'static, U: Send + 'static,
{ {
let start = unsafe { core::mem::transmute(f) }; let start = f as usize;
create_thread_n_post(start, arg1, arg2, arg3, 0, thread_id) create_thread_n_post(start, arg1, arg2, arg3, 0, thread_id)
} }
@ -267,7 +267,7 @@ pub fn create_thread_4_pre<U>(
where where
U: Send + 'static, U: Send + 'static,
{ {
let start = unsafe { core::mem::transmute(*f) }; let start = *f as usize;
create_thread_n_pre(start, arg1, arg2, arg3, arg4) create_thread_n_pre(start, arg1, arg2, arg3, arg4)
} }
@ -282,7 +282,7 @@ pub fn create_thread_4_post<U>(
where where
U: Send + 'static, U: Send + 'static,
{ {
let start = unsafe { core::mem::transmute(f) }; let start = f as usize;
create_thread_n_post(start, arg1, arg2, arg3, arg4, thread_id) create_thread_n_post(start, arg1, arg2, arg3, arg4, thread_id)
} }
@ -295,7 +295,7 @@ where
U: Send + 'static, U: Send + 'static,
{ {
create_thread_n_pre( create_thread_n_pre(
unsafe { core::mem::transmute(*f) }, *f as usize,
unsafe { core::mem::transmute(arg) }, unsafe { core::mem::transmute(arg) },
&0, &0,
&0, &0,
@ -313,7 +313,7 @@ where
U: Send + 'static, U: Send + 'static,
{ {
create_thread_n_post( create_thread_n_post(
unsafe { core::mem::transmute(f) }, f as usize,
unsafe { core::mem::transmute(&arg) }, unsafe { core::mem::transmute(&arg) },
0, 0,
0, 0,
@ -321,9 +321,9 @@ where
thread_id, thread_id,
) )
// If we succeeded, the variable will be moved into the caller. Drop it from here. // If we succeeded, the variable will be moved into the caller. Drop it from here.
.and_then(|f| { .map(|f| {
core::mem::forget(arg); core::mem::forget(arg);
Ok(f) f
}) })
} }

View file

@ -214,7 +214,7 @@ pub fn pid_from_usize(src: usize) -> core::result::Result<PID, Error> {
if src > u8::MAX as _ { if src > u8::MAX as _ {
return Err(Error::InvalidPID); return Err(Error::InvalidPID);
} }
Ok(PID::new(src as u8).ok_or(Error::InvalidPID)?) PID::new(src as u8).ok_or(Error::InvalidPID)
} }
#[repr(usize)] #[repr(usize)]
@ -504,7 +504,7 @@ impl Message {
pub fn memory_message(&self) -> Option<&MemoryMessage> { pub fn memory_message(&self) -> Option<&MemoryMessage> {
match self { match self {
Message::MutableBorrow(mem) | Message::Borrow(mem) | Message::Move(mem) => Some(&mem), Message::MutableBorrow(mem) | Message::Borrow(mem) | Message::Move(mem) => Some(mem),
Message::BlockingScalar(_) | Message::Scalar(_) => None, Message::BlockingScalar(_) | Message::Scalar(_) => None,
} }
} }
@ -519,7 +519,7 @@ impl Message {
pub fn scalar_message(&self) -> Option<&ScalarMessage> { pub fn scalar_message(&self) -> Option<&ScalarMessage> {
match self { match self {
Message::MutableBorrow(_) | Message::Borrow(_) | Message::Move(_) => None, Message::MutableBorrow(_) | Message::Borrow(_) | Message::Move(_) => None,
Message::BlockingScalar(scalar) | Message::Scalar(scalar) => Some(&scalar), Message::BlockingScalar(scalar) | Message::Scalar(scalar) => Some(scalar),
} }
} }
@ -643,6 +643,11 @@ impl Drop for MessageEnvelope {
} }
impl MemoryRange { impl MemoryRange {
/// # Safety
///
/// This allows for creating a `MemoryRange` from any arbitrary pointer,
/// so it is imperitive that this only be used to point to valid, page-aligned
/// ranges.
pub unsafe fn new(addr: usize, size: usize) -> core::result::Result<MemoryRange, Error> { pub unsafe fn new(addr: usize, size: usize) -> core::result::Result<MemoryRange, Error> {
assert!( assert!(
addr != 0, addr != 0,

View file

@ -65,7 +65,7 @@ impl<const N: usize> String<N> {
/// awful, O(N) implementation because we have to iterate through the entire string /// awful, O(N) implementation because we have to iterate through the entire string
/// and decode variable-length utf8 characters, until we can't. /// and decode variable-length utf8 characters, until we can't.
pub fn pop(&mut self) -> Option<char> { pub fn pop(&mut self) -> Option<char> {
if self.len() < 1 { if self.is_empty() {
return None; return None;
} }
// first, make a copy of the string // first, make a copy of the string

View file

@ -1371,7 +1371,7 @@ pub fn wait_event() {
} }
#[deprecated( #[deprecated(
since = "0.2", since = "0.2.0",
note = "Please use create_thread_n() or create_thread()" note = "Please use create_thread_n() or create_thread()"
)] )]
pub fn create_thread_simple<T, U>( pub fn create_thread_simple<T, U>(
@ -1579,6 +1579,13 @@ pub fn destroy_server(sid: SID) -> core::result::Result<(), Error> {
/// Disconnect the specified connection ID and mark it as free. This /// Disconnect the specified connection ID and mark it as free. This
/// connection ID may be reused by the server in the future, so ensure /// connection ID may be reused by the server in the future, so ensure
/// no other threads are using the connection ID before disposing of it. /// no other threads are using the connection ID before disposing of it.
///
/// # Safety
///
/// This function must only be called when the connection is no longer in
/// use. Calling this function when the connection ID is in use will result
/// in kernel errors or, if the CID is reused, silent failures due to
/// messages going to the wrong server.
pub unsafe fn disconnect(cid: CID) -> core::result::Result<(), Error> { pub unsafe fn disconnect(cid: CID) -> core::result::Result<(), Error> {
rsyscall(SysCall::Disconnect(cid)).and_then(|result| { rsyscall(SysCall::Disconnect(cid)).and_then(|result| {
if let Result::Ok = result { if let Result::Ok = result {