Skip to content

Commit

Permalink
rustfmt: set style_edition = "2024"
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Feb 23, 2025
1 parent d84b946 commit cba8c30
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ error_on_line_overflow = true
# Override the default formatting style.
# See https://internals.rust-lang.org/t/running-rustfmt-on-rust-lang-rust-and-other-rust-lang-repositories/8732/81.
use_small_heuristics = "Max"
# This is the default of 2024 edition https://github.com/rust-lang/rust/pull/114764.
# This is unstable (tracking issue: https://github.com/rust-lang/rustfmt/issues/3370)
overflow_delimited_expr = true
# This is unstable (tracking issue: https://github.com/rust-lang/rustfmt/issues/4991).
Expand All @@ -27,6 +26,7 @@ use_try_shorthand = true
# Set the default settings again to always apply the proper formatting without
# being affected by the editor settings.
edition = "2021"
style_edition = "2024"
hard_tabs = false
newline_style = "Unix"
tab_spaces = 4
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,4 @@ mod version {
}
}
}
use self::version::{rustc_version, Version};
use self::version::{Version, rustc_version};
3 changes: 2 additions & 1 deletion src/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
/// use semihosting::{c, fs};
///
/// fs::write(c!("a.txt"), "abc")?;
/// fs::write(c!(concat!("b", ".txt")), "def")?; // concat! in c! is also supported
/// // concat! in c! is also supported
/// fs::write(c!(concat!("b", ".txt")), "def")?;
/// # Ok::<(), semihosting::io::Error>(())
/// ```
///
Expand Down
8 changes: 4 additions & 4 deletions src/experimental/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<const BUF_SIZE: usize> fmt::Debug for Args<BUF_SIZE> {
}

mod sys {
pub(crate) use self::imp::{args_bytes, ArgsBytes};
pub(crate) use self::imp::{ArgsBytes, args_bytes};

const NUL: u8 = b'\0';

Expand Down Expand Up @@ -87,10 +87,10 @@ mod sys {
mod imp {
use core::cell::Cell;

use super::{next_from_cmdline, NUL};
use super::{NUL, next_from_cmdline};
use crate::{
io,
sys::arm_compat::{sys_get_cmdline, CommandLine},
sys::arm_compat::{CommandLine, sys_get_cmdline},
};

pub(crate) struct ArgsBytes<const BUF_SIZE: usize> {
Expand Down Expand Up @@ -128,7 +128,7 @@ mod sys {

use core::cell::Cell;

use super::{next_from_cmdline, NUL};
use super::{NUL, next_from_cmdline};
use crate::{
io,
sys::mips::{mips_argc, mips_argn, mips_argnlen},
Expand Down
12 changes: 2 additions & 10 deletions src/experimental/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,7 @@ mod sys {
let (res, overflowed) = this.overflowing_add(rhs);
(res, overflowed ^ (rhs < 0))
};
if b {
None
} else {
Some(a)
}
if b { None } else { Some(a) }
}

let mut secs = checked_add_unsigned(self.tv_sec, other.as_secs())?;
Expand All @@ -201,11 +197,7 @@ mod sys {
let (res, overflowed) = this.overflowing_sub(rhs);
(res, overflowed ^ (rhs < 0))
};
if b {
None
} else {
Some(a)
}
if b { None } else { Some(a) }
}

let mut secs = checked_sub_unsigned(self.tv_sec, other.as_secs())?;
Expand Down
6 changes: 4 additions & 2 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
//! ```no_run
//! use semihosting::{c, fs};
//!
//! fs::write(c"a.txt", "abc")?; // with C string literal
//! fs::write(c!("b.txt"), "123")?; // with c! macro
//! // with C string literal
//! fs::write(c"a.txt", "abc")?;
//! // with c! macro
//! fs::write(c!("b.txt"), "123")?;
//! # Ok::<(), semihosting::io::Error>(())
//! ```
//!
Expand Down
6 changes: 1 addition & 5 deletions src/io/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,7 @@ impl Write for &mut [u8] {
// }
#[inline]
fn write_all(&mut self, data: &[u8]) -> io::Result<()> {
if self.write(data)? == data.len() {
Ok(())
} else {
Err(io::Error::WRITE_ALL_EOF)
}
if self.write(data)? == data.len() { Ok(()) } else { Err(io::Error::WRITE_ALL_EOF) }
}
#[inline]
fn flush(&mut self) -> io::Result<()> {
Expand Down
8 changes: 2 additions & 6 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod error;
mod impls;

#[cfg(feature = "stdio")]
pub use self::stdio::{stderr, stdin, stdout, IsTerminal, Stderr, Stdin, Stdout};
pub use self::stdio::{IsTerminal, Stderr, Stdin, Stdout, stderr, stdin, stdout};
#[cfg(feature = "stdio")]
#[cfg_attr(docsrs, doc(cfg(feature = "stdio")))]
mod stdio;
Expand All @@ -43,11 +43,7 @@ pub(crate) fn default_read_exact<R: ?Sized + Read>(this: &mut R, mut buf: &mut [
Err(e) => return Err(e),
}
}
if buf.is_empty() {
Ok(())
} else {
Err(Error::READ_EXACT_EOF)
}
if buf.is_empty() { Ok(()) } else { Err(Error::READ_EXACT_EOF) }
}

/// The `no_std` subset of `std::io::Read`.
Expand Down
2 changes: 1 addition & 1 deletion src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn _panic(_info: &core::panic::PanicInfo<'_>) -> ! {
{
use core::{ffi::c_void, ptr};

use unwinding::abi::{UnwindContext, UnwindReasonCode, _Unwind_Backtrace, _Unwind_GetIP};
use unwinding::abi::{_Unwind_Backtrace, _Unwind_GetIP, UnwindContext, UnwindReasonCode};

extern "C" fn callback(
unwind_ctx: &UnwindContext<'_>,
Expand Down
2 changes: 1 addition & 1 deletion src/sys/arm_compat/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use core::ffi::CStr;

use super::{errno, sys_flen, sys_open, sys_seek, OpenMode};
use super::{OpenMode, errno, sys_flen, sys_open, sys_seek};
pub(crate) use super::{sys_remove as unlink, sys_rename as rename};
use crate::{
fd::{BorrowedFd, OwnedFd},
Expand Down
40 changes: 8 additions & 32 deletions src/sys/arm_compat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ pub(crate) mod fs;
pub mod syscall;

use core::{
ffi::{c_void, CStr},
ffi::{CStr, c_void},
mem::{self, MaybeUninit},
};

use self::syscall::{syscall, syscall0, syscall_readonly, OperationNumber, ParamRegR, ParamRegW};
use self::syscall::{OperationNumber, ParamRegR, ParamRegW, syscall, syscall_readonly, syscall0};
use crate::{
fd::{BorrowedFd, OwnedFd, RawFd},
io::{Error, RawOsError, Result},
Expand Down Expand Up @@ -118,11 +118,7 @@ pub struct CommandLine {
/// [SYS_CLOCK (0x10)](https://github.com/ARM-software/abi-aa/blob/2024Q3/semihosting/semihosting.rst#sys-clock-0x10)
pub fn sys_clock() -> Result<usize> {
let res = unsafe { syscall0(OperationNumber::SYS_CLOCK) };
if res.int() == -1 {
Err(Error::from_raw_os_error(sys_errno()))
} else {
Ok(res.usize())
}
if res.int() == -1 { Err(Error::from_raw_os_error(sys_errno())) } else { Ok(res.usize()) }
}

/// [SYS_CLOSE (0x02)](https://github.com/ARM-software/abi-aa/blob/2024Q3/semihosting/semihosting.rst#sys-close-0x02)
Expand Down Expand Up @@ -200,11 +196,7 @@ pub fn sys_exit_extended(reason: ExitReason, subcode: usize) {
pub fn sys_flen(fd: BorrowedFd<'_>) -> Result<usize> {
let args = [ParamRegR::fd(fd)];
let res = unsafe { syscall_readonly(OperationNumber::SYS_FLEN, ParamRegR::block(&args)) };
if res.int() == -1 {
Err(Error::from_raw_os_error(sys_errno()))
} else {
Ok(res.usize())
}
if res.int() == -1 { Err(Error::from_raw_os_error(sys_errno())) } else { Ok(res.usize()) }
}

/// [SYS_GET_CMDLINE (0x15)](https://github.com/ARM-software/abi-aa/blob/2024Q3/semihosting/semihosting.rst#sys-get-cmdline-0x15)
Expand Down Expand Up @@ -330,11 +322,7 @@ pub fn sys_readc() -> u8 {
pub fn sys_remove(path: &CStr) -> Result<()> {
let args = [ParamRegR::c_str(path), ParamRegR::usize(path.to_bytes().len())];
let res = unsafe { syscall_readonly(OperationNumber::SYS_REMOVE, ParamRegR::block(&args)) };
if res.usize() == 0 {
Ok(())
} else {
Err(Error::from_raw_os_error(sys_errno()))
}
if res.usize() == 0 { Ok(()) } else { Err(Error::from_raw_os_error(sys_errno())) }
}

/// [SYS_RENAME (0x0F)](https://github.com/ARM-software/abi-aa/blob/2024Q3/semihosting/semihosting.rst#sys-rename-0x0f)
Expand All @@ -346,11 +334,7 @@ pub fn sys_rename(from: &CStr, to: &CStr) -> Result<()> {
ParamRegR::usize(to.to_bytes().len()),
];
let res = unsafe { syscall_readonly(OperationNumber::SYS_RENAME, ParamRegR::block(&args)) };
if res.usize() == 0 {
Ok(())
} else {
Err(Error::from_raw_os_error(sys_errno()))
}
if res.usize() == 0 { Ok(()) } else { Err(Error::from_raw_os_error(sys_errno())) }
}

// TODO: resolve safety
Expand All @@ -359,11 +343,7 @@ pub fn sys_rename(from: &CStr, to: &CStr) -> Result<()> {
pub unsafe fn sys_seek(fd: BorrowedFd<'_>, abs_pos: usize) -> Result<()> {
let args = [ParamRegR::fd(fd), ParamRegR::usize(abs_pos)];
let res = unsafe { syscall_readonly(OperationNumber::SYS_SEEK, ParamRegR::block(&args)) };
if res.usize() == 0 {
Ok(())
} else {
Err(Error::from_raw_os_error(sys_errno()))
}
if res.usize() == 0 { Ok(()) } else { Err(Error::from_raw_os_error(sys_errno())) }
}

/// [SYS_SYSTEM (0x12)](https://github.com/ARM-software/abi-aa/blob/2024Q3/semihosting/semihosting.rst#sys-system-0x12)
Expand All @@ -376,11 +356,7 @@ pub fn sys_system(cmd: &CStr) -> usize {
/// [SYS_TICKFREQ (0x31)](https://github.com/ARM-software/abi-aa/blob/2024Q3/semihosting/semihosting.rst#sys-tickfreq-0x31)
pub fn sys_tickfreq() -> Result<usize> {
let res = unsafe { syscall0(OperationNumber::SYS_TICKFREQ) };
if res.int() == -1 {
Err(Error::from_raw_os_error(sys_errno()))
} else {
Ok(res.usize())
}
if res.int() == -1 { Err(Error::from_raw_os_error(sys_errno())) } else { Ok(res.usize()) }
}

/// [SYS_TIME (0x11)](https://github.com/ARM-software/abi-aa/blob/2024Q3/semihosting/semihosting.rst#sys-time-0x11)
Expand Down
4 changes: 2 additions & 2 deletions src/sys/mips/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use core::ffi::CStr;

use super::{
errno, mips_fstat, mips_lseek, mips_open, SeekWhence::SEEK_SET, O_APPEND, O_CREAT, O_EXCL,
O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY,
O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY, SeekWhence::SEEK_SET, errno,
mips_fstat, mips_lseek, mips_open,
};
pub(crate) use super::{mips_fstat as metadata, mips_unlink as unlink, uhi_stat as Metadata};
use crate::{
Expand Down
28 changes: 6 additions & 22 deletions src/sys/mips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use core::{
};

use self::syscall::{
syscall0, syscall1_readonly, syscall2, syscall2_readonly, syscall3, syscall3_readonly,
syscall4, syscall4_readonly, OperationCode, ParamRegR, ParamRegW, RetReg,
OperationCode, ParamRegR, ParamRegW, RetReg, syscall0, syscall1_readonly, syscall2,
syscall2_readonly, syscall3, syscall3_readonly, syscall4, syscall4_readonly,
};
use crate::{
fd::{BorrowedFd, OwnedFd, RawFd},
Expand Down Expand Up @@ -198,32 +198,20 @@ pub unsafe fn mips_lseek(fd: BorrowedFd<'_>, offset: isize, whence: SeekWhence)
ParamRegR::usize(whence as usize),
)
};
if res.int() == -1 {
Err(from_errno(errno))
} else {
Ok(res.usize())
}
if res.int() == -1 { Err(from_errno(errno)) } else { Ok(res.usize()) }
}

pub fn mips_unlink(path: &CStr) -> Result<()> {
let (res, errno) =
unsafe { syscall1_readonly(OperationCode::UHI_UNLINK, ParamRegR::c_str(path)) };
if res.usize() == 0 {
Ok(())
} else {
Err(from_errno(errno))
}
if res.usize() == 0 { Ok(()) } else { Err(from_errno(errno)) }
}

pub fn mips_fstat(fd: BorrowedFd<'_>) -> Result<uhi_stat> {
let mut buf: uhi_stat = unsafe { mem::zeroed() };
let (res, errno) =
unsafe { syscall2(OperationCode::UHI_FSTAT, ParamRegW::fd(fd), ParamRegW::ref_(&mut buf)) };
if res.usize() == 0 {
Ok(buf)
} else {
Err(from_errno(errno))
}
if res.usize() == 0 { Ok(buf) } else { Err(from_errno(errno)) }
}
#[cfg(feature = "stdio")]
pub(crate) fn is_terminal(fd: BorrowedFd<'_>) -> bool {
Expand All @@ -240,11 +228,7 @@ pub fn mips_argc() -> usize {
pub fn mips_argnlen(n: usize) -> Result<usize> {
let (res, errno) =
unsafe { syscall1_readonly(OperationCode::UHI_ARGNLEN, ParamRegR::usize(n)) };
if res.int() == -1 {
Err(from_errno(errno))
} else {
Ok(res.usize())
}
if res.int() == -1 { Err(from_errno(errno)) } else { Ok(res.usize()) }
}

pub unsafe fn mips_argn(n: usize, buf: *mut u8) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ mod reg;
#[cfg(feature = "fs")]
pub(crate) use self::arch::fs;
#[cfg(feature = "stdio")]
pub(crate) use self::arch::{is_terminal, stderr, stdin, stdout, StdioFd};
pub(crate) use self::arch::{StdioFd, is_terminal, stderr, stdin, stdout};
#[cfg(any(feature = "stdio", feature = "fs"))]
pub(crate) use self::arch::{read, write};
pub(crate) use self::{
Expand Down
2 changes: 1 addition & 1 deletion src/sys/reg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use core::{
ffi::{c_int, c_void, CStr},
ffi::{CStr, c_int, c_void},
marker::PhantomData,
};

Expand Down

0 comments on commit cba8c30

Please # to comment.