From 71a6f5f2b5a05db34cf4b48c958597301797cda4 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Fri, 21 Feb 2025 17:14:10 +0900 Subject: [PATCH] Update Rust edition (#2107) --- Cargo.toml | 2 +- bench/benches/main.rs | 2 +- bench/build.rs | 2 +- build/src/lib.rs | 2 +- cmd/minimal/Cargo.toml | 2 +- cmd/minimal/interpret/src/main.rs | 18 ++++++++++-------- cmd/profile/src/main.rs | 8 ++++---- device/src/device/libc/device.rs | 2 +- device/src/device/libc/stdio.rs | 2 +- device/src/device/stdio.rs | 2 +- dynamic/src/primitive_set.rs | 2 +- engine/build.rs | 2 +- engine/src/engine.rs | 2 +- examples/custom-vm/build.rs | 2 +- examples/embedded-script/build.rs | 2 +- examples/embedded-script/src/main.rs | 2 +- examples/hot-reload/build.rs | 2 +- examples/hot-reload/src/main.rs | 2 +- examples/no-std-no-alloc/build.rs | 2 +- file/src/file_system/libc.rs | 2 +- file/src/file_system/os.rs | 2 +- macro/src/lib.rs | 6 +++--- minifier/src/lib.rs | 2 +- minifier_macro/src/lib.rs | 2 +- profiler/src/record/duration_record.rs | 2 +- profiler/src/record/procedure_record.rs | 2 +- profiler/src/stack_profiler.rs | 2 +- root/build.rs | 2 +- sac/src/lib.rs | 2 +- time/src/clock/libc.rs | 2 +- util/src/mmap.rs | 2 +- vm/src/cons.rs | 2 +- vm/src/lib.rs | 2 +- vm/src/memory.rs | 10 +++------- vm/src/number.rs | 4 ++-- vm/src/primitive_set.rs | 2 +- vm/src/value.rs | 2 +- vm/src/vm.rs | 2 +- wasm/build.rs | 2 +- 39 files changed, 56 insertions(+), 58 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ce95f568b..a4f615de9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ members = [ ] [workspace.package] -edition = "2021" +edition = "2024" keywords = ["interpreter", "language", "scheme"] license-file = "LICENSE" readme = "README.md" diff --git a/bench/benches/main.rs b/bench/benches/main.rs index c4a785a60..d5a86d014 100644 --- a/bench/benches/main.rs +++ b/bench/benches/main.rs @@ -1,6 +1,6 @@ #![allow(missing_docs)] -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{Criterion, black_box, criterion_group, criterion_main}; use stak::{ device::FixedBufferDevice, file::VoidFileSystem, diff --git a/bench/build.rs b/bench/build.rs index 1a797640f..c7d6bb97a 100644 --- a/bench/build.rs +++ b/bench/build.rs @@ -1,6 +1,6 @@ //! A build script. -use stak_build::{build_r7rs, BuildError}; +use stak_build::{BuildError, build_r7rs}; fn main() -> Result<(), BuildError> { build_r7rs() diff --git a/build/src/lib.rs b/build/src/lib.rs index 509b71a92..58547447b 100644 --- a/build/src/lib.rs +++ b/build/src/lib.rs @@ -24,7 +24,7 @@ mod error; use alloc::sync::Arc; pub use error::BuildError; -use glob::{glob, Paths}; +use glob::{Paths, glob}; use stak_compiler::compile_r7rs; use std::{ env, diff --git a/cmd/minimal/Cargo.toml b/cmd/minimal/Cargo.toml index b691a8572..04a60db6a 100644 --- a/cmd/minimal/Cargo.toml +++ b/cmd/minimal/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["interpret", "run"] [workspace.package] -edition = "2021" +edition = "2024" keywords = ["interpreter", "language", "scheme"] license-file = "../../LICENSE" readme = "../../README.md" diff --git a/cmd/minimal/interpret/src/main.rs b/cmd/minimal/interpret/src/main.rs index efd5f6db0..9b8022d70 100644 --- a/cmd/minimal/interpret/src/main.rs +++ b/cmd/minimal/interpret/src/main.rs @@ -26,29 +26,31 @@ fn panic(_info: &core::panic::PanicInfo) -> ! { unsafe { libc::exit(1) } } -#[cfg_attr(not(test), no_mangle)] +#[cfg_attr(not(test), unsafe(no_mangle))] unsafe extern "C" fn main(argc: isize, argv: *const *const i8) -> isize { - let Some(&file) = &slice::from_raw_parts(argv, argc as _).get(1) else { + let Some(&file) = unsafe { slice::from_raw_parts(argv, argc as _) }.get(1) else { return 1; }; - let heap = slice::from_raw_parts_mut( - libc::malloc(size_of::() * HEAP_SIZE) as *mut Value, - HEAP_SIZE, - ); + let heap = unsafe { + slice::from_raw_parts_mut( + libc::malloc(size_of::() * HEAP_SIZE) as *mut Value, + HEAP_SIZE, + ) + }; let mut vm = Vm::new( heap, SmallPrimitiveSet::new( ReadWriteDevice::new(Stdin::new(), Stdout::new(), Stderr::new()), LibcFileSystem::new(), - LibcProcessContext::new(argc, argv), + unsafe { LibcProcessContext::new(argc, argv) }, LibcClock::new(), ), ) .unwrap(); - let mmap = Mmap::new(CStr::from_ptr(file as _)); + let mmap = Mmap::new(unsafe { CStr::from_ptr(file as _) }); vm.initialize(mmap.as_slice().iter().copied()).unwrap(); vm.run().unwrap(); diff --git a/cmd/profile/src/main.rs b/cmd/profile/src/main.rs index c110367e3..c51f5cdba 100644 --- a/cmd/profile/src/main.rs +++ b/cmd/profile/src/main.rs @@ -13,15 +13,15 @@ use stak_device::StdioDevice; use stak_file::OsFileSystem; use stak_process_context::OsProcessContext; use stak_profiler::{ - calculate_durations, calculate_flamegraph, collapse_stacks, read_records, reverse_stacks, - write_records, DurationRecord, ProcedureRecord, StackProfiler, + DurationRecord, ProcedureRecord, StackProfiler, calculate_durations, calculate_flamegraph, + collapse_stacks, read_records, reverse_stacks, write_records, }; use stak_r7rs::SmallPrimitiveSet; use stak_time::OsClock; use stak_vm::Vm; use std::{ - fs::{read, OpenOptions}, - io::{stdin, stdout, BufWriter}, + fs::{OpenOptions, read}, + io::{BufWriter, stdin, stdout}, path::PathBuf, }; diff --git a/device/src/device/libc/device.rs b/device/src/device/libc/device.rs index 2deab084d..e7d41ad17 100644 --- a/device/src/device/libc/device.rs +++ b/device/src/device/libc/device.rs @@ -1,4 +1,4 @@ -use super::{error::LibcError, Read, Write}; +use super::{Read, Write, error::LibcError}; use crate::Device; /// A device composed of objects implementing `Read` and `Write` traits. diff --git a/device/src/device/libc/stdio.rs b/device/src/device/libc/stdio.rs index 4dcb25630..8c4649b09 100644 --- a/device/src/device/libc/stdio.rs +++ b/device/src/device/libc/stdio.rs @@ -1,4 +1,4 @@ -use super::{error::LibcError, Read, Write}; +use super::{Read, Write, error::LibcError}; use rustix::{ fd::BorrowedFd, io, diff --git a/device/src/device/stdio.rs b/device/src/device/stdio.rs index c1a57570f..65f4c5fb5 100644 --- a/device/src/device/stdio.rs +++ b/device/src/device/stdio.rs @@ -1,5 +1,5 @@ use crate::{Device, ReadWriteDevice}; -use std::io::{stderr, stdin, stdout, Error, Stderr, Stdin, Stdout}; +use std::io::{Error, Stderr, Stdin, Stdout, stderr, stdin, stdout}; /// A standard I/O device of a current process. #[derive(Debug)] diff --git a/dynamic/src/primitive_set.rs b/dynamic/src/primitive_set.rs index 6b4875c38..34d562a94 100644 --- a/dynamic/src/primitive_set.rs +++ b/dynamic/src/primitive_set.rs @@ -218,7 +218,7 @@ impl PrimitiveSet for DynamicPrimitiveSet<'_, '_> { #[cfg(test)] mod tests { use super::*; - use any_fn::{r#fn, value, Ref}; + use any_fn::{Ref, r#fn, value}; const HEAP_SIZE: usize = 1 << 8; diff --git a/engine/build.rs b/engine/build.rs index 1a797640f..c7d6bb97a 100644 --- a/engine/build.rs +++ b/engine/build.rs @@ -1,6 +1,6 @@ //! A build script. -use stak_build::{build_r7rs, BuildError}; +use stak_build::{BuildError, build_r7rs}; fn main() -> Result<(), BuildError> { build_r7rs() diff --git a/engine/src/engine.rs b/engine/src/engine.rs index 118b4ef2e..09bcba160 100644 --- a/engine/src/engine.rs +++ b/engine/src/engine.rs @@ -1,4 +1,4 @@ -use crate::{primitive_set::EnginePrimitiveSet, EngineError}; +use crate::{EngineError, primitive_set::EnginePrimitiveSet}; use any_fn::AnyFn; use stak_dynamic::SchemeValue; use stak_module::Module; diff --git a/examples/custom-vm/build.rs b/examples/custom-vm/build.rs index 1a797640f..c7d6bb97a 100644 --- a/examples/custom-vm/build.rs +++ b/examples/custom-vm/build.rs @@ -1,6 +1,6 @@ //! A build script. -use stak_build::{build_r7rs, BuildError}; +use stak_build::{BuildError, build_r7rs}; fn main() -> Result<(), BuildError> { build_r7rs() diff --git a/examples/embedded-script/build.rs b/examples/embedded-script/build.rs index 1a797640f..c7d6bb97a 100644 --- a/examples/embedded-script/build.rs +++ b/examples/embedded-script/build.rs @@ -1,6 +1,6 @@ //! A build script. -use stak_build::{build_r7rs, BuildError}; +use stak_build::{BuildError, build_r7rs}; fn main() -> Result<(), BuildError> { build_r7rs() diff --git a/examples/embedded-script/src/main.rs b/examples/embedded-script/src/main.rs index ac80df1ab..1fab964fc 100644 --- a/examples/embedded-script/src/main.rs +++ b/examples/embedded-script/src/main.rs @@ -1,6 +1,6 @@ //! The pie-throwing duel. -use any_fn::{r#fn, Ref}; +use any_fn::{Ref, r#fn}; use core::error::Error; use rand::random; use stak::{ diff --git a/examples/hot-reload/build.rs b/examples/hot-reload/build.rs index 1a797640f..c7d6bb97a 100644 --- a/examples/hot-reload/build.rs +++ b/examples/hot-reload/build.rs @@ -1,6 +1,6 @@ //! A build script. -use stak_build::{build_r7rs, BuildError}; +use stak_build::{BuildError, build_r7rs}; fn main() -> Result<(), BuildError> { build_r7rs() diff --git a/examples/hot-reload/src/main.rs b/examples/hot-reload/src/main.rs index 7bb51dd2a..9d990dd66 100644 --- a/examples/hot-reload/src/main.rs +++ b/examples/hot-reload/src/main.rs @@ -1,6 +1,6 @@ //! A `stak-build` example. -use axum::{http::StatusCode, response, routing::post, serve, Router}; +use axum::{Router, http::StatusCode, response, routing::post, serve}; use core::error::Error; use stak::{ device::ReadWriteDevice, diff --git a/examples/no-std-no-alloc/build.rs b/examples/no-std-no-alloc/build.rs index 1a797640f..c7d6bb97a 100644 --- a/examples/no-std-no-alloc/build.rs +++ b/examples/no-std-no-alloc/build.rs @@ -1,6 +1,6 @@ //! A build script. -use stak_build::{build_r7rs, BuildError}; +use stak_build::{BuildError, build_r7rs}; fn main() -> Result<(), BuildError> { build_r7rs() diff --git a/file/src/file_system/libc.rs b/file/src/file_system/libc.rs index 1443ec679..2ded96abd 100644 --- a/file/src/file_system/libc.rs +++ b/file/src/file_system/libc.rs @@ -1,4 +1,4 @@ -use super::{utility::decode_path, FileDescriptor, FileError, FileSystem}; +use super::{FileDescriptor, FileError, FileSystem, utility::decode_path}; use core::ffi::CStr; use heapless::{FnvIndexMap, Vec}; use rustix::{ diff --git a/file/src/file_system/os.rs b/file/src/file_system/os.rs index b80abd09e..f500bfc58 100644 --- a/file/src/file_system/os.rs +++ b/file/src/file_system/os.rs @@ -4,7 +4,7 @@ use core::str; use stak_vm::{Memory, Value}; use std::{ collections::HashMap, - fs::{remove_file, File, OpenOptions}, + fs::{File, OpenOptions, remove_file}, io::{self, ErrorKind, Read, Write}, path::{Path, PathBuf}, }; diff --git a/macro/src/lib.rs b/macro/src/lib.rs index b4d6a5840..cad647b8b 100644 --- a/macro/src/lib.rs +++ b/macro/src/lib.rs @@ -4,11 +4,11 @@ use cfg_elif::expr::feature; use core::error::Error; use proc_macro::TokenStream; use proc_macro2::Literal; -use quote::{quote, ToTokens}; +use quote::{ToTokens, quote}; use stak_compiler::CompileError; use stak_macro_util::{convert_result, read_source_file}; -use std::path::{Path, MAIN_SEPARATOR_STR}; -use syn::{parse::Parse, parse_macro_input, Ident, LitStr, Token}; +use std::path::{MAIN_SEPARATOR_STR, Path}; +use syn::{Ident, LitStr, Token, parse::Parse, parse_macro_input}; struct IncludeModuleInput { path: LitStr, diff --git a/minifier/src/lib.rs b/minifier/src/lib.rs index e9391df4d..829f96e76 100644 --- a/minifier/src/lib.rs +++ b/minifier/src/lib.rs @@ -8,7 +8,7 @@ use stak_process_context::VoidProcessContext; use stak_r7rs::{SmallError, SmallPrimitiveSet}; use stak_time::VoidClock; use stak_vm::Vm; -use std::io::{empty, Read, Write}; +use std::io::{Read, Write, empty}; /// Minifies given source codes. pub fn minify(reader: impl Read, writer: impl Write) -> Result<(), SmallError> { diff --git a/minifier_macro/src/lib.rs b/minifier_macro/src/lib.rs index c6f69d5d9..c8fcbdd2a 100644 --- a/minifier_macro/src/lib.rs +++ b/minifier_macro/src/lib.rs @@ -8,7 +8,7 @@ use proc_macro::TokenStream; use proc_macro2::Literal; use quote::quote; use stak_macro_util::{convert_result, read_source_file}; -use syn::{parse_macro_input, LitStr}; +use syn::{LitStr, parse_macro_input}; /// Minifies source codes in Scheme. /// diff --git a/profiler/src/record/duration_record.rs b/profiler/src/record/duration_record.rs index da571ac21..0b7bc14ef 100644 --- a/profiler/src/record/duration_record.rs +++ b/profiler/src/record/duration_record.rs @@ -1,5 +1,5 @@ use super::{Record, StackedRecord}; -use crate::{Error, Stack, COLUMN_SEPARATOR}; +use crate::{COLUMN_SEPARATOR, Error, Stack}; use core::{ fmt::{self, Display, Formatter}, str::FromStr, diff --git a/profiler/src/record/procedure_record.rs b/profiler/src/record/procedure_record.rs index b8009bdbf..a1539f2fa 100644 --- a/profiler/src/record/procedure_record.rs +++ b/profiler/src/record/procedure_record.rs @@ -1,5 +1,5 @@ use super::{Record, StackedRecord}; -use crate::{Error, ProcedureOperation, Stack, COLUMN_SEPARATOR}; +use crate::{COLUMN_SEPARATOR, Error, ProcedureOperation, Stack}; use core::{ fmt::{self, Display, Formatter}, str::FromStr, diff --git a/profiler/src/stack_profiler.rs b/profiler/src/stack_profiler.rs index 40be3e996..9a8655297 100644 --- a/profiler/src/stack_profiler.rs +++ b/profiler/src/stack_profiler.rs @@ -1,4 +1,4 @@ -use crate::{ProcedureOperation, COLUMN_SEPARATOR, FRAME_SEPARATOR}; +use crate::{COLUMN_SEPARATOR, FRAME_SEPARATOR, ProcedureOperation}; use stak_vm::{Cons, Memory, Profiler, StackSlot}; use std::{io::Write, time::Instant}; diff --git a/root/build.rs b/root/build.rs index 1a797640f..c7d6bb97a 100644 --- a/root/build.rs +++ b/root/build.rs @@ -1,6 +1,6 @@ //! A build script. -use stak_build::{build_r7rs, BuildError}; +use stak_build::{BuildError, build_r7rs}; fn main() -> Result<(), BuildError> { build_r7rs() diff --git a/sac/src/lib.rs b/sac/src/lib.rs index a0eb8b8e6..dc64bdbfc 100644 --- a/sac/src/lib.rs +++ b/sac/src/lib.rs @@ -129,7 +129,7 @@ macro_rules! libc_main { unsafe { exit(1) } } - #[cfg_attr(not(test), no_mangle)] + #[cfg_attr(not(test), unsafe(no_mangle))] unsafe extern "C" fn main(argc: isize, argv: *const *const i8) -> isize { let mut heap = Heap::new($heap_size, Default::default); let mut vm = Vm::new( diff --git a/time/src/clock/libc.rs b/time/src/clock/libc.rs index dba35e543..dbaa602dc 100644 --- a/time/src/clock/libc.rs +++ b/time/src/clock/libc.rs @@ -1,6 +1,6 @@ use super::Clock; use core::convert::Infallible; -use rustix::time::{clock_gettime, ClockId}; +use rustix::time::{ClockId, clock_gettime}; use stak_vm::Number; /// A clock based on libc. diff --git a/util/src/mmap.rs b/util/src/mmap.rs index 772728145..9443e64d5 100644 --- a/util/src/mmap.rs +++ b/util/src/mmap.rs @@ -2,7 +2,7 @@ use crate::read_file_size; use core::{ffi::CStr, ptr::null_mut, slice}; use rustix::{ fs::{self, Mode, OFlags}, - mm::{mmap, munmap, MapFlags, ProtFlags}, + mm::{MapFlags, ProtFlags, mmap, munmap}, }; /// A mmap. diff --git a/vm/src/cons.rs b/vm/src/cons.rs index 42b3464c9..af1373fde 100644 --- a/vm/src/cons.rs +++ b/vm/src/cons.rs @@ -1,4 +1,4 @@ -use crate::{value::Value, Error}; +use crate::{Error, value::Value}; use cfg_elif::expr::feature; use core::fmt::{self, Display, Formatter}; diff --git a/vm/src/lib.rs b/vm/src/lib.rs index 0efe56a29..a714134ee 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -68,7 +68,7 @@ pub use memory::Memory; pub use number::{Number, NumberRepresentation}; pub use primitive_set::PrimitiveSet; pub use profiler::Profiler; -pub use r#type::Type; pub use stack_slot::StackSlot; +pub use r#type::Type; pub use value::Value; pub use vm::Vm; diff --git a/vm/src/memory.rs b/vm/src/memory.rs index 856bbb9f0..463302f9a 100644 --- a/vm/src/memory.rs +++ b/vm/src/memory.rs @@ -1,9 +1,9 @@ use crate::{ - cons::{Cons, Tag, NEVER}, + Error, + cons::{Cons, NEVER, Tag}, number::Number, r#type::Type, value::Value, - Error, }; use core::fmt::{self, Display, Formatter}; @@ -239,11 +239,7 @@ impl<'a> Memory<'a> { /// Returns an allocation start index. #[inline] pub const fn allocation_start(&self) -> usize { - if self.space { - self.space_size() - } else { - 0 - } + if self.space { self.space_size() } else { 0 } } /// Returns an allocation end index. diff --git a/vm/src/number.rs b/vm/src/number.rs index 19b58ba3c..1b662d652 100644 --- a/vm/src/number.rs +++ b/vm/src/number.rs @@ -1,4 +1,4 @@ -use crate::{value::Value, Error}; +use crate::{Error, value::Value}; use cfg_elif::{expr::feature, item}; use core::{ fmt::{self, Display, Formatter}, @@ -25,7 +25,7 @@ impl Number { /// Creates a number. #[inline] pub const fn new(number: NumberRepresentation) -> Self { - Self(feature!(if ("float") { number } else { number << 1 | 1 })) + Self(feature!(if ("float") { number } else { (number << 1) | 1 })) } /// Converts a number to a number representation. diff --git a/vm/src/primitive_set.rs b/vm/src/primitive_set.rs index 000944e0d..eadfc9945 100644 --- a/vm/src/primitive_set.rs +++ b/vm/src/primitive_set.rs @@ -1,4 +1,4 @@ -use crate::{memory::Memory, Error}; +use crate::{Error, memory::Memory}; use core::error; /// A primitive set. diff --git a/vm/src/value.rs b/vm/src/value.rs index 7c6caffd1..5eb3d394f 100644 --- a/vm/src/value.rs +++ b/vm/src/value.rs @@ -153,7 +153,7 @@ impl Display for Value { #[cfg(test)] mod tests { use super::*; - use crate::{cons::NEVER, Type}; + use crate::{Type, cons::NEVER}; #[test] fn convert_cons() { diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 801b10ee9..cc9e91c80 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -1,6 +1,7 @@ #[cfg(feature = "profile")] use crate::profiler::Profiler; use crate::{ + Error, StackSlot, code::{INTEGER_BASE, NUMBER_BASE, SHARE_BASE, TAG_BASE}, cons::{Cons, NEVER}, instruction::Instruction, @@ -9,7 +10,6 @@ use crate::{ primitive_set::PrimitiveSet, r#type::Type, value::{TypedValue, Value}, - Error, StackSlot, }; #[cfg(feature = "profile")] use core::cell::RefCell; diff --git a/wasm/build.rs b/wasm/build.rs index 1a797640f..c7d6bb97a 100644 --- a/wasm/build.rs +++ b/wasm/build.rs @@ -1,6 +1,6 @@ //! A build script. -use stak_build::{build_r7rs, BuildError}; +use stak_build::{BuildError, build_r7rs}; fn main() -> Result<(), BuildError> { build_r7rs()