From 63f9d90853aac3237973ba19df907fb3a60d8567 Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Sun, 5 May 2024 22:32:41 +0200 Subject: [PATCH 1/6] Fix failing test for new rustc --- Cargo.lock | 28 ---------------------------- compile_tests/Cargo.lock | 6 +++--- savefile-derive/src/lib.rs | 2 +- 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c6c3b0..ac7df37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,27 +11,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "alkahest" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "631a0c0a3e1a64558bb2552a3893102c428d5e88a0e3f0a6979a7a67328c1e1b" -dependencies = [ - "alkahest-proc", - "bytemuck", -] - -[[package]] -name = "alkahest-proc" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8087db15c316edb2432048cfd2f3f848ee22887f9d717d7375bf7b666a59e7e7" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "arrayvec" version = "0.7.4" @@ -80,12 +59,6 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -[[package]] -name = "bytemuck" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" - [[package]] name = "byteorder" version = "1.5.0" @@ -550,7 +523,6 @@ dependencies = [ name = "savefile-min-build" version = "0.1.0" dependencies = [ - "alkahest", "savefile", "savefile-abi", "savefile-derive", diff --git a/compile_tests/Cargo.lock b/compile_tests/Cargo.lock index cfe70f6..e8bfd7b 100644 --- a/compile_tests/Cargo.lock +++ b/compile_tests/Cargo.lock @@ -463,7 +463,7 @@ checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "savefile" -version = "0.17.0-beta.15" +version = "0.17.1" dependencies = [ "arrayvec", "bit-set", @@ -479,7 +479,7 @@ dependencies = [ [[package]] name = "savefile-abi" -version = "0.17.0-beta.15" +version = "0.17.1" dependencies = [ "byteorder", "libloading", @@ -489,7 +489,7 @@ dependencies = [ [[package]] name = "savefile-derive" -version = "0.17.0-beta.15" +version = "0.17.1" dependencies = [ "proc-macro-error", "proc-macro2", diff --git a/savefile-derive/src/lib.rs b/savefile-derive/src/lib.rs index 14a8bf4..af4c0ab 100644 --- a/savefile-derive/src/lib.rs +++ b/savefile-derive/src/lib.rs @@ -585,7 +585,7 @@ pub fn savefile_abi_export(item: proc_macro::TokenStream) -> proc_macro::TokenSt const _:() = { #uses #[automatically_derived] - unsafe impl AbiExportableImplementation for #implementing_type { + unsafe impl AbiExportableImplementation for #implementing_type where #implementing_type: Default + #trait_type { const ABI_ENTRY: unsafe extern "C" fn (AbiProtocol) = #abi_entry; type AbiInterface = dyn #trait_type; From f09b6fba0951d7cb0be01febe5b4a1d3a677a3ae Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Sun, 5 May 2024 22:35:59 +0200 Subject: [PATCH 2/6] chore: release (#54) * chore: release * Update CHANGELOG.md --- Cargo.lock | 6 +++--- savefile-abi/CHANGELOG.md | 5 +++++ savefile-abi/Cargo.toml | 6 +++--- savefile-derive/CHANGELOG.md | 5 +++++ savefile-derive/Cargo.toml | 2 +- savefile-test/Cargo.toml | 2 +- savefile/CHANGELOG.md | 7 ++++++- savefile/Cargo.toml | 6 +++--- 8 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ac7df37..6d75d44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -448,7 +448,7 @@ dependencies = [ [[package]] name = "savefile" -version = "0.17.1" +version = "0.17.2" dependencies = [ "arrayvec", "bit-set", @@ -471,7 +471,7 @@ dependencies = [ [[package]] name = "savefile-abi" -version = "0.17.1" +version = "0.17.2" dependencies = [ "byteorder", "libloading", @@ -511,7 +511,7 @@ dependencies = [ [[package]] name = "savefile-derive" -version = "0.17.1" +version = "0.17.2" dependencies = [ "proc-macro-error", "proc-macro2", diff --git a/savefile-abi/CHANGELOG.md b/savefile-abi/CHANGELOG.md index 9f5a93c..f5b3c42 100644 --- a/savefile-abi/CHANGELOG.md +++ b/savefile-abi/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.17.2](https://github.com/avl/savefile/compare/savefile-abi-v0.17.1...savefile-abi-v0.17.2) - 2024-05-05 + +### Other +- updated the following local packages: savefile, savefile-derive + ## [0.17.1](https://github.com/avl/savefile/compare/savefile-abi-v0.17.0...savefile-abi-v0.17.1) - 2024-05-01 ### Other diff --git a/savefile-abi/Cargo.toml b/savefile-abi/Cargo.toml index 915fda9..1a8d7fc 100644 --- a/savefile-abi/Cargo.toml +++ b/savefile-abi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "savefile-abi" -version = "0.17.1" +version = "0.17.2" edition = "2021" authors = ["Anders Musikka "] documentation = "https://docs.rs/savefile-abi/" @@ -16,7 +16,7 @@ keywords = ["dylib", "dlopen", "ffi"] license = "MIT/Apache-2.0" [dependencies] -savefile = { path="../savefile", version = "=0.17.1" } -savefile-derive = { path="../savefile-derive", version = "=0.17.1" } +savefile = { path="../savefile", version = "=0.17.2" } +savefile-derive = { path="../savefile-derive", version = "=0.17.2" } byteorder = "1.4" libloading = "0.8" diff --git a/savefile-derive/CHANGELOG.md b/savefile-derive/CHANGELOG.md index 649c2bd..73eee14 100644 --- a/savefile-derive/CHANGELOG.md +++ b/savefile-derive/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.17.2](https://github.com/avl/savefile/compare/savefile-derive-v0.17.1...savefile-derive-v0.17.2) - 2024-05-05 + +### Other +- Fix failing test for new rustc + ## [0.17.0-beta.15](https://github.com/avl/savefile/compare/savefile-derive-v0.17.0-beta.14...savefile-derive-v0.17.0-beta.15) - 2024-04-30 ### Fixed diff --git a/savefile-derive/Cargo.toml b/savefile-derive/Cargo.toml index 21c4927..44697d4 100644 --- a/savefile-derive/Cargo.toml +++ b/savefile-derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "savefile-derive" -version = "0.17.1" +version = "0.17.2" authors = ["Anders Musikka "] description = "Custom derive macros for savefile crate - simple, convenient, fast, versioned, binary serialization/deserialization library." diff --git a/savefile-test/Cargo.toml b/savefile-test/Cargo.toml index 7614698..bf64b8a 100644 --- a/savefile-test/Cargo.toml +++ b/savefile-test/Cargo.toml @@ -12,7 +12,7 @@ nightly=["savefile/nightly"] [dependencies] savefile = { path = "../savefile", features = ["size_sanity_checks", "encryption", "compression","bit-set","bit-vec","rustc-hash","serde_derive", "quickcheck"]} -savefile-derive = { path = "../savefile-derive", version = "=0.17.1" } +savefile-derive = { path = "../savefile-derive", version = "=0.17.2" } savefile-abi = { path = "../savefile-abi" } bit-vec = "0.6" arrayvec="0.7" diff --git a/savefile/CHANGELOG.md b/savefile/CHANGELOG.md index bf3fd8a..4fda70d 100644 --- a/savefile/CHANGELOG.md +++ b/savefile/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.17.2](https://github.com/avl/savefile/compare/savefile-v0.17.1...savefile-v0.17.2) - 2024-05-05 + +### Fixed +- Make comment clearer + ## [0.17.1](https://github.com/avl/savefile/compare/savefile-v0.17.0...savefile-v0.17.1) - 2024-05-01 ### Other @@ -34,4 +39,4 @@ These CHANGELOG-files are experimental. ## [0.17.0-beta.12](https://github.com/avl/savefile/compare/savefile-v0.17.0-beta.11...savefile-v0.17.0-beta.12) - 2024-04-27 ### Other -- Unspecified work \ No newline at end of file +- Unspecified work diff --git a/savefile/Cargo.toml b/savefile/Cargo.toml index e35f941..723317c 100644 --- a/savefile/Cargo.toml +++ b/savefile/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "savefile" -version = "0.17.1" +version = "0.17.2" authors = ["Anders Musikka "] documentation = "https://docs.rs/savefile/" homepage = "https://github.com/avl/savefile/" @@ -54,13 +54,13 @@ bit-set = {version = "0.5", optional = true} rustc-hash = {version = "1.1", optional = true} memoffset = "0.9" byteorder = "1.4" -savefile-derive = {path="../savefile-derive", version = "=0.17.1", optional = true } +savefile-derive = {path="../savefile-derive", version = "=0.17.2", optional = true } serde_derive = {version= "1.0", optional = true} serde = {version= "1.0", optional = true} quickcheck = {version= "1.0", optional = true} [dev-dependencies] -savefile-derive = { path="../savefile-derive", version = "=0.17.1" } +savefile-derive = { path="../savefile-derive", version = "=0.17.2" } [build-dependencies] rustc_version="0.2" From 43317e83c70d80316550c3826cf4eb9c4b94606f Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Mon, 6 May 2024 21:26:39 +0200 Subject: [PATCH 3/6] Move to edition 2021. Fix repo-link in repo --- savefile-derive/Cargo.toml | 3 +++ savefile-derive/src/deserialize.rs | 4 ++-- savefile-derive/src/savefile_abi.rs | 2 +- savefile-derive/src/serialize.rs | 6 +++--- savefile/Cargo.toml | 5 ++--- savefile/src/lib.rs | 1 - 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/savefile-derive/Cargo.toml b/savefile-derive/Cargo.toml index 44697d4..ed562a0 100644 --- a/savefile-derive/Cargo.toml +++ b/savefile-derive/Cargo.toml @@ -2,6 +2,7 @@ name = "savefile-derive" version = "0.17.2" authors = ["Anders Musikka "] +repository = "https://github.com/avl/savefile" description = "Custom derive macros for savefile crate - simple, convenient, fast, versioned, binary serialization/deserialization library." @@ -13,6 +14,8 @@ categories = ["encoding"] license = "MIT/Apache-2.0" +edition = "2021" + [features] default = [] nightly = [] diff --git a/savefile-derive/src/deserialize.rs b/savefile-derive/src/deserialize.rs index e6acc23..f2d78ee 100644 --- a/savefile-derive/src/deserialize.rs +++ b/savefile-derive/src/deserialize.rs @@ -1,5 +1,5 @@ -use common::{check_is_remove, get_extra_where_clauses, parse_attr_tag, FieldInfo, RemovedType}; -use get_enum_size; +use crate::common::{check_is_remove, get_extra_where_clauses, parse_attr_tag, FieldInfo, RemovedType}; +use crate::get_enum_size; use proc_macro2::{Literal, TokenStream}; use syn::spanned::Spanned; use syn::DeriveInput; diff --git a/savefile-derive/src/savefile_abi.rs b/savefile-derive/src/savefile_abi.rs index 95cc4b1..a4618ab 100644 --- a/savefile-derive/src/savefile_abi.rs +++ b/savefile-derive/src/savefile_abi.rs @@ -1,4 +1,4 @@ -use common::{compile_time_check_reprc, compile_time_size}; +use crate::common::{compile_time_check_reprc, compile_time_size}; use proc_macro2::{Ident, Literal, Span, TokenStream}; use quote::ToTokens; use std::collections::HashMap; diff --git a/savefile-derive/src/serialize.rs b/savefile-derive/src/serialize.rs index 0071025..701976e 100644 --- a/savefile-derive/src/serialize.rs +++ b/savefile-derive/src/serialize.rs @@ -1,9 +1,9 @@ use proc_macro2::{Span, TokenStream}; use syn::DeriveInput; -use common::{get_extra_where_clauses, parse_attr_tag, FieldInfo}; -use get_enum_size; -use implement_fields_serialize; +use crate::common::{get_extra_where_clauses, parse_attr_tag, FieldInfo}; +use crate::get_enum_size; +use crate::implement_fields_serialize; use syn::spanned::Spanned; pub(super) fn savefile_derive_crate_serialize(input: DeriveInput) -> TokenStream { diff --git a/savefile/Cargo.toml b/savefile/Cargo.toml index 723317c..f83b494 100644 --- a/savefile/Cargo.toml +++ b/savefile/Cargo.toml @@ -20,7 +20,7 @@ categories = ["encoding"] license = "MIT/Apache-2.0" -edition = "2018" +edition = "2021" [features] default = ["indexmap", "arrayvec", "smallvec", "bit-vec", "parking_lot","bit-set"] @@ -31,8 +31,7 @@ serde_derive = ["dep:serde_derive","serde"] # This is mostly to be able to run fuzzers against the deserializers without them being guaranteed to easily find out-of-memory crashes. size_sanity_checks = [] # Use features only available on the nightly rust-compiler. -# Enabling this means serialization of vectors of simple types will be much faster. -# It also enables serialization of arbitrary size arrays (arbitrary size Vec always work, regardless of features) +# Enabling this provides slightly better introspection support. nightly=[] compression = ["bzip2"] diff --git a/savefile/src/lib.rs b/savefile/src/lib.rs index beb8c23..9ec7499 100644 --- a/savefile/src/lib.rs +++ b/savefile/src/lib.rs @@ -1,7 +1,6 @@ #![allow(incomplete_features)] #![recursion_limit = "256"] #![cfg_attr(feature = "nightly", feature(specialization))] -#![cfg_attr(feature = "nightly", feature(trait_alias))] #![deny(missing_docs)] #![deny(warnings)] #![allow(clippy::box_default)] From ddf660afb49d2e278d9501fe926695b36bd97ca9 Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Mon, 6 May 2024 21:33:44 +0200 Subject: [PATCH 4/6] format --- savefile-abi/src/lib.rs | 14 +++++---- savefile-min-build/src/lib.rs | 7 +---- savefile-test/src/enum_variant_versioning.rs | 2 +- savefile-test/src/ext_benchmark.rs | 17 +++++------ savefile-test/src/lib.rs | 6 ++-- .../argument_backward_compatibility.rs | 14 ++++----- .../src/savefile_abi_test/basic_abi_tests.rs | 5 ++-- savefile/src/lib.rs | 29 ++++++++++++------- savefile/src/prelude.rs | 2 +- 9 files changed, 48 insertions(+), 48 deletions(-) diff --git a/savefile-abi/src/lib.rs b/savefile-abi/src/lib.rs index 214bb9c..caca641 100644 --- a/savefile-abi/src/lib.rs +++ b/savefile-abi/src/lib.rs @@ -303,6 +303,7 @@ use savefile::{ diff_schema, load_file_noschema, load_noschema, save_file_noschema, AbiMethodInfo, AbiTraitDefinition, Deserialize, Deserializer, LittleEndian, SavefileError, Schema, Serializer, CURRENT_SAVEFILE_LIB_VERSION, }; +use std::any::TypeId; use std::collections::hash_map::Entry; use std::collections::HashMap; use std::hash::Hash; @@ -314,7 +315,6 @@ use std::path::Path; use std::ptr::null; use std::sync::{Mutex, MutexGuard}; use std::{ptr, slice}; -use std::any::TypeId; use byteorder::ReadBytesExt; use libloading::{Library, Symbol}; @@ -853,7 +853,7 @@ pub fn parse_return_value_impl( /// Parse an RawAbiCallResult instance into a `Result, SavefileError>` . /// This is used on the caller side, and the type T will always be statically known. /// TODO: There's some duplicated code here, compare parse_return_value -pub fn parse_return_boxed_trait(outcome: &RawAbiCallResult) -> Result>, SavefileError> +pub fn parse_return_boxed_trait(outcome: &RawAbiCallResult) -> Result>, SavefileError> where T: AbiExportable + ?Sized, { @@ -875,7 +875,7 @@ static ENTRY_CACHE: Mutex< > = Mutex::new(None); static ABI_CONNECTION_TEMPLATES: Mutex< - Option>, + Option>, > = Mutex::new(None); struct Guard<'a, K: Hash + Eq, V> { @@ -972,8 +972,10 @@ pub unsafe extern "C" fn abi_result_receiver( /// Raw entry point for receiving return values from other shared libraries #[doc(hidden)] -pub unsafe extern "C" fn abi_boxed_trait_receiver(outcome: *const RawAbiCallResult, result_receiver: *mut ()) -where +pub unsafe extern "C" fn abi_boxed_trait_receiver( + outcome: *const RawAbiCallResult, + result_receiver: *mut (), +) where T: AbiExportable + ?Sized, { let outcome = unsafe { &*outcome }; @@ -1402,7 +1404,7 @@ impl AbiConnection { // In principle, it would be enough to key 'templates' based on 'remote_entry'. // However, if we do, and the user ever uses AbiConnection with the _wrong_ entry point, // we risk poisoning the cache with erroneous data. - let template = match templates.entry((typeid,remote_entry)) { + let template = match templates.entry((typeid, remote_entry)) { Entry::Occupied(template) => template.get().clone(), Entry::Vacant(vacant) => { let own_version = T::get_latest_version(); diff --git a/savefile-min-build/src/lib.rs b/savefile-min-build/src/lib.rs index 8b71a03..2b4ca7c 100644 --- a/savefile-min-build/src/lib.rs +++ b/savefile-min-build/src/lib.rs @@ -1,14 +1,9 @@ - use savefile_derive::Savefile; - #[derive(Debug, Savefile, PartialEq)] pub enum TestStructEnum { Variant2 { a: u8, b: u8 }, } #[test] -fn test() { - -} - +fn test() {} diff --git a/savefile-test/src/enum_variant_versioning.rs b/savefile-test/src/enum_variant_versioning.rs index 3b1a87e..bdb50fd 100644 --- a/savefile-test/src/enum_variant_versioning.rs +++ b/savefile-test/src/enum_variant_versioning.rs @@ -1,5 +1,5 @@ use assert_roundtrip_version; -use savefile::{Removed, Packed}; +use savefile::{Packed, Removed}; use {assert_roundtrip, assert_roundtrip_to_new_version}; #[repr(u8)] diff --git a/savefile-test/src/ext_benchmark.rs b/savefile-test/src/ext_benchmark.rs index c1a4c1b..35d6eda 100644 --- a/savefile-test/src/ext_benchmark.rs +++ b/savefile-test/src/ext_benchmark.rs @@ -1,7 +1,7 @@ +use rand::Rng; use std::hint::black_box; #[cfg(feature = "nightly")] use test::Bencher; -use rand::Rng; mod savefile_test_bad_schema { use savefile::prelude::*; @@ -175,13 +175,13 @@ mod savefile_benchmark_no_reprc { } } -#[derive(Savefile,PartialEq,Default)] +#[derive(Savefile, PartialEq, Default)] pub struct Vector3 { pub x: f32, pub y: f32, pub z: f32, } -#[derive(Savefile,PartialEq,Default)] +#[derive(Savefile, PartialEq, Default)] pub struct Triangle { pub v0: Vector3, pub v1: Vector3, @@ -189,16 +189,13 @@ pub struct Triangle { pub normal: Vector3, } -#[derive(Savefile,PartialEq)] +#[derive(Savefile, PartialEq)] pub struct Mesh { pub triangles: Vec, } #[cfg(test)] pub fn generate_mesh() -> Mesh { - - let mut mesh = Mesh { - triangles: vec![] - }; + let mut mesh = Mesh { triangles: vec![] }; const TRIANGLES: usize = 125_000; for _ in 0..TRIANGLES { mesh.triangles.push(Triangle::default()) @@ -219,10 +216,10 @@ fn bench_ext_triangle(b: &mut Bencher) { #[test] fn test_triangle() { use savefile::Packed; - assert!( unsafe { Triangle::repr_c_optimization_safe(0).is_yes() } ); + assert!(unsafe { Triangle::repr_c_optimization_safe(0).is_yes() }); let mesh = generate_mesh(); let mut encoded = Vec::new(); encoded.clear(); savefile::save_noschema(black_box(&mut encoded), 0, black_box(&mesh)).unwrap(); -} \ No newline at end of file +} diff --git a/savefile-test/src/lib.rs b/savefile-test/src/lib.rs index bec40a0..368ebd7 100644 --- a/savefile-test/src/lib.rs +++ b/savefile-test/src/lib.rs @@ -1357,9 +1357,11 @@ pub fn test_verify_cow_deserialize_not_borrowed() { } f.set_position(0); { - let roundtripped:Cow = Deserializer::load(&mut f, 0).unwrap(); + let roundtripped: Cow = Deserializer::load(&mut f, 0).unwrap(); match roundtripped { - Cow::Borrowed(_) => {panic!("Roundtripped Cow should not be borrowed!")} + Cow::Borrowed(_) => { + panic!("Roundtripped Cow should not be borrowed!") + } Cow::Owned(_) => {} } } diff --git a/savefile-test/src/savefile_abi_test/argument_backward_compatibility.rs b/savefile-test/src/savefile_abi_test/argument_backward_compatibility.rs index 02c741c..b104091 100644 --- a/savefile-test/src/savefile_abi_test/argument_backward_compatibility.rs +++ b/savefile-test/src/savefile_abi_test/argument_backward_compatibility.rs @@ -39,8 +39,7 @@ mod v1 { EnumArgument::Variant2 => "Variant2".into(), } } - fn function_existing_in_v1(&self) { - } + fn function_existing_in_v1(&self) {} } } @@ -85,8 +84,7 @@ mod v2 { a.data3 + a.data2 + b.data2 + b.data3 } - fn function_existing_in_v2(&self) { - } + fn function_existing_in_v2(&self) {} } } @@ -200,7 +198,7 @@ pub fn test_caller_has_newer_version_calling_non_existing_function() { iface1, ) } - .unwrap(); + .unwrap(); conn1.function_existing_in_v2(); } @@ -214,18 +212,18 @@ pub fn test_caller_has_older_version_calling_non_existing_function() { iface2, ) } - .unwrap(); + .unwrap(); conn.function_existing_in_v1(); } #[test] fn test_calling_function_that_is_later_removed() { - let boxed: Box = Box::new(Implementation1{}); + let boxed: Box = Box::new(Implementation1 {}); let conn = AbiConnection::from_boxed_trait(boxed).unwrap(); conn.function_existing_in_v1(); } #[test] fn test_calling_function_that_is_added_in_later_version() { - let boxed: Box = Box::new(Implementation2{}); + let boxed: Box = Box::new(Implementation2 {}); let conn = AbiConnection::from_boxed_trait(boxed).unwrap(); conn.function_existing_in_v2(); } diff --git a/savefile-test/src/savefile_abi_test/basic_abi_tests.rs b/savefile-test/src/savefile_abi_test/basic_abi_tests.rs index 5b30573..423b07c 100644 --- a/savefile-test/src/savefile_abi_test/basic_abi_tests.rs +++ b/savefile-test/src/savefile_abi_test/basic_abi_tests.rs @@ -292,7 +292,6 @@ fn test_cow_smuggler() { assert_eq!(conn.smuggle2("hej".into()), "hej"); assert_eq!(conn.smuggle2("hej".to_string().into()), "hej"); - let static_ret : Cow<'static, str> = conn.smuggle2("hej".into()); + let static_ret: Cow<'static, str> = conn.smuggle2("hej".into()); assert_eq!(static_ret, "hej"); - -} \ No newline at end of file +} diff --git a/savefile/src/lib.rs b/savefile/src/lib.rs index 9ec7499..be7c0e9 100644 --- a/savefile/src/lib.rs +++ b/savefile/src/lib.rs @@ -1157,7 +1157,7 @@ impl<'a, TR: Read> Deserializer<'a, TR> { pub struct IsPacked(bool); #[doc(hidden)] -#[deprecated(since="0.17", note="The 'IsReprC' type has been renamed to 'IsPacked'.")] +#[deprecated(since = "0.17", note = "The 'IsReprC' type has been renamed to 'IsPacked'.")] pub type IsReprC = IsPacked; impl std::ops::BitAnd for IsPacked { @@ -1241,20 +1241,21 @@ pub trait Packed { /// This just exists to make sure that no one can actually implement the ReprC-trait placeholder. #[doc(hidden)] -#[deprecated(since="0.17", note="The 'ReprC' trait has been renamed to 'Packed'.")] -pub struct DeliberatelyUnimplementable{ +#[deprecated(since = "0.17", note = "The 'ReprC' trait has been renamed to 'Packed'.")] +pub struct DeliberatelyUnimplementable { #[allow(dead_code)] - private: () + private: (), } -#[deprecated(since="0.17", note="The 'ReprC' trait has been renamed to 'Packed'.")] +#[deprecated(since = "0.17", note = "The 'ReprC' trait has been renamed to 'Packed'.")] #[doc(hidden)] pub trait ReprC { - #[deprecated(since="0.17", note="The 'ReprC' trait has been renamed to 'Packed'.")] + #[deprecated(since = "0.17", note = "The 'ReprC' trait has been renamed to 'Packed'.")] #[doc(hidden)] #[allow(non_snake_case)] #[allow(deprecated)] - fn this_is_a_placeholder__if_you_see_this_it_is_likely_that_you_have_code_that_refers_to_ReprC_trait__this_trait_has_been_renamed_to__Packed() -> DeliberatelyUnimplementable; + fn this_is_a_placeholder__if_you_see_this_it_is_likely_that_you_have_code_that_refers_to_ReprC_trait__this_trait_has_been_renamed_to__Packed( + ) -> DeliberatelyUnimplementable; unsafe fn repr_c_optimization_safe(_version: u32) -> IsPacked { IsPacked::no() } @@ -2400,7 +2401,6 @@ impl<'a> IntrospectItem<'a> for str { } } - impl<'a> IntrospectItem<'a> for String { fn key(&self) -> &str { self @@ -3700,8 +3700,16 @@ impl Deserialize for SchemaStruct { let l = deserializer.read_usize()?; Ok(SchemaStruct { dbg_name, - size: if deserializer.file_version > 0 {<_ as Deserialize>::deserialize(deserializer)?} else {None}, - alignment: if deserializer.file_version > 0 {<_ as Deserialize>::deserialize(deserializer)?} else {None}, + size: if deserializer.file_version > 0 { + <_ as Deserialize>::deserialize(deserializer)? + } else { + None + }, + alignment: if deserializer.file_version > 0 { + <_ as Deserialize>::deserialize(deserializer)? + } else { + None + }, fields: { let mut ret = Vec::new(); for _ in 0..l { @@ -4159,7 +4167,6 @@ impl Packed for String {} impl Packed for str {} - impl Deserialize for String { fn deserialize(deserializer: &mut Deserializer) -> Result { deserializer.read_string() diff --git a/savefile/src/prelude.rs b/savefile/src/prelude.rs index fbba9ba..49443e1 100644 --- a/savefile/src/prelude.rs +++ b/savefile/src/prelude.rs @@ -4,7 +4,7 @@ pub use { super::save_file_noschema, super::save_noschema, super::save_to_mem, super::AbiRemoved, super::Canary1, super::Deserialize, super::Deserializer, super::Field, super::Introspect, super::IntrospectItem, super::IntrospectedElementKey, super::IntrospectionResult, super::Introspector, super::IntrospectorNavCommand, - super::IsPacked, super::Removed, super::Packed, super::SavefileError, super::Schema, super::SchemaEnum, + super::IsPacked, super::Packed, super::Removed, super::SavefileError, super::Schema, super::SchemaEnum, super::SchemaPrimitive, super::SchemaStruct, super::Serialize, super::Serializer, super::Variant, super::WithSchema, super::WithSchemaContext, }; From d141e0b1433c89ec5e5a6203b057b6a99297fe94 Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Mon, 6 May 2024 22:46:30 +0200 Subject: [PATCH 5/6] fix: Better span-info in derive macro error-messages --- compile_tests/Cargo.lock | 6 +-- .../tests/compile-fail/bad_export.rs | 4 +- .../tests/compile-fail/bad_export2.rs | 2 +- compile_tests/tests/tests.rs | 12 ++--- savefile-derive/src/lib.rs | 45 +++++++++++++------ 5 files changed, 41 insertions(+), 28 deletions(-) diff --git a/compile_tests/Cargo.lock b/compile_tests/Cargo.lock index e8bfd7b..921c47c 100644 --- a/compile_tests/Cargo.lock +++ b/compile_tests/Cargo.lock @@ -463,7 +463,7 @@ checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "savefile" -version = "0.17.1" +version = "0.17.2" dependencies = [ "arrayvec", "bit-set", @@ -479,7 +479,7 @@ dependencies = [ [[package]] name = "savefile-abi" -version = "0.17.1" +version = "0.17.2" dependencies = [ "byteorder", "libloading", @@ -489,7 +489,7 @@ dependencies = [ [[package]] name = "savefile-derive" -version = "0.17.1" +version = "0.17.2" dependencies = [ "proc-macro-error", "proc-macro2", diff --git a/compile_tests/tests/compile-fail/bad_export.rs b/compile_tests/tests/compile-fail/bad_export.rs index 0794278..ce62bde 100644 --- a/compile_tests/tests/compile-fail/bad_export.rs +++ b/compile_tests/tests/compile-fail/bad_export.rs @@ -14,6 +14,7 @@ use savefile_derive::savefile_abi_export; pub trait ExampleTrait { fn get(&mut self, x: u32) -> u32; } +#[derive(Default)] struct ExampleImpl { } @@ -24,6 +25,7 @@ impl ExampleTrait for ExampleImpl { } // Test what happens when you mix up the ordering of trait and impl: savefile_abi_export!(ExampleTrait, ExampleImpl); -//~^ 26:1: 26:48: expected trait, found struct `ExampleImpl` [E0404] +//~^ 27:22: 27:34: trait objects must include the `dyn` keyword [E0782] +//~^^ 27:36: 27:47: expected trait, found struct `ExampleImpl` [E0404] fn main() {} \ No newline at end of file diff --git a/compile_tests/tests/compile-fail/bad_export2.rs b/compile_tests/tests/compile-fail/bad_export2.rs index 7be080f..f478f3b 100644 --- a/compile_tests/tests/compile-fail/bad_export2.rs +++ b/compile_tests/tests/compile-fail/bad_export2.rs @@ -21,6 +21,6 @@ struct ExampleImpl { // Forgot to implement trait savefile_abi_export!(ExampleImpl, ExampleTrait); -//~^ 23:1: 23:48: the trait bound `ExampleImpl: ExampleTrait` is not satisfied [E0277] +//~^ 23:22: 23:47: the trait bound `ExampleImpl: ExampleTrait` is not satisfied [E0277] fn main() {} \ No newline at end of file diff --git a/compile_tests/tests/tests.rs b/compile_tests/tests/tests.rs index 0ba7059..ab92c37 100644 --- a/compile_tests/tests/tests.rs +++ b/compile_tests/tests/tests.rs @@ -1,6 +1,5 @@ extern crate compiletest_rs as compiletest; -use std::env; use std::path::PathBuf; fn run_mode(mode: &'static str, custom_dir: Option<&'static str>) { @@ -11,14 +10,9 @@ fn run_mode(mode: &'static str, custom_dir: Option<&'static str>) { let dir = custom_dir.unwrap_or(mode); config.src_base = PathBuf::from(format!("tests/{}", dir)); - config.target_rustcflags = Some("-L target/debug -L target/debug/deps".to_string()); - config.llvm_filecheck = Some( - env::var("FILECHECK") - .unwrap_or("FileCheck".to_string()) - .into(), - ); - //config.clean_rmeta(); - //config.clean_rlib(); + config.target_rustcflags = Some("-L target/debug -L target/debug/deps --edition 2021".to_string()); + config.llvm_filecheck = Some("FileCheck".to_string().into()); + config.strict_headers = true; compiletest::run_tests(&config); diff --git a/savefile-derive/src/lib.rs b/savefile-derive/src/lib.rs index af4c0ab..022bbf6 100644 --- a/savefile-derive/src/lib.rs +++ b/savefile-derive/src/lib.rs @@ -26,7 +26,7 @@ use common::{ check_is_remove, compile_time_check_reprc, compile_time_size, get_extra_where_clauses, parse_attr_tag, path_to_string, FieldInfo, }; -use proc_macro2::Span; +use proc_macro2::{Span, TokenTree}; use proc_macro2::TokenStream; use quote::ToTokens; use std::collections::{HashMap, HashSet}; @@ -34,12 +34,9 @@ use std::collections::{HashMap, HashSet}; use std::iter::IntoIterator; use syn::__private::bool; use syn::spanned::Spanned; -use syn::token::Paren; +use syn::token::{Paren}; use syn::Type::Tuple; -use syn::{ - DeriveInput, FnArg, GenericParam, Generics, Ident, ImplGenerics, Index, ItemTrait, Pat, ReturnType, TraitItem, - Type, TypeGenerics, TypeParamBound, TypeTuple, -}; +use syn::{DeriveInput, FnArg, GenericParam, Generics, Ident, ImplGenerics, Index, ItemTrait, Pat, ReturnType, TraitItem, Type, TypeGenerics, TypeParamBound, TypeTuple}; fn implement_fields_serialize( field_infos: Vec, implicit_self: bool, @@ -564,21 +561,41 @@ pub fn savefile_abi_exportable( } #[proc_macro_error] #[proc_macro] -pub fn savefile_abi_export(item: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input = item.to_string(); - let symbols: Vec<_> = input.split(',').map(|x| x.trim()).collect(); - if symbols.len() != 2 { - abort!(input.span(), "savefile_abi_export requires two parameters. The first parameter is the implementing type, the second is the trait it implements."); + pub fn savefile_abi_export(item: proc_macro::TokenStream) -> proc_macro::TokenStream { + let tokens = proc_macro2::TokenStream::from(item); + + let mut tokens_iter = tokens.into_iter(); + + let Some(implementing_type) = tokens_iter.next() else { + abort!(Span::call_site(), "The macro savefile_abi_export! requires two parameters. The first parameter must be the implementing type, the second is the trait it implements."); + }; + let Some(comma) = tokens_iter.next() else { + abort!(Span::call_site(), "The macro savefile_abi_export! requires two parameters. The first parameter must be the implementing type, the second is the trait it implements."); + }; + if let TokenTree::Punct(p) = comma { + if p.as_char() != ',' { + abort!(p.span(), "Expected a comma (','). The macro savefile_abi_export! requires two parameters. The first parameter must be the implementing type, the second is the trait it implements, and these must be separated by a comma."); + } + } else { + abort!(comma.span(), "Expected a comma (','). The macro savefile_abi_export! requires two parameters. The first parameter must be the implementing type, the second is the trait it implements, and these must be separated by a comma."); + + } + let Some(trait_type) = tokens_iter.next() else { + abort!(Span::call_site(), "The macro savefile_abi_export! requires two parameters. The first parameter must be the implementing type, the second is the trait it implements. Expected trait name."); + }; + + if let Some(extra) = tokens_iter.next() { + abort!(extra.span(), "Unexpected token. The macro savefile_abi_export! requires exactly two parameters. The first parameter must be the implementing type, the second is the trait it implements."); } + + let defspan = Span::call_site(); let uses = quote_spanned! { defspan => extern crate savefile_abi; use savefile_abi::{AbiProtocol, AbiExportableImplementation, abi_entry,parse_return_value_impl}; }; - let implementing_type = Ident::new(symbols[0], Span::call_site()); - let trait_type = Ident::new(symbols[1], Span::call_site()); - let abi_entry = Ident::new(("abi_entry_".to_string() + symbols[1]).as_str(), Span::call_site()); + let abi_entry = Ident::new(("abi_entry_".to_string() + &trait_type.to_string()).as_str(), Span::call_site()); let expanded = quote! { #[allow(clippy::double_comparisons)] From c6b5ad6199635918f0eed9127ec7fe14a6aaaa87 Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Thu, 9 May 2024 23:49:30 +0200 Subject: [PATCH 6/6] chore: release (#57) --- Cargo.lock | 6 +++--- savefile-abi/CHANGELOG.md | 5 +++++ savefile-abi/Cargo.toml | 6 +++--- savefile-derive/CHANGELOG.md | 5 +++++ savefile-derive/Cargo.toml | 2 +- savefile-test/Cargo.toml | 2 +- savefile/CHANGELOG.md | 8 ++++++++ savefile/Cargo.toml | 6 +++--- 8 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6d75d44..bbca116 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -448,7 +448,7 @@ dependencies = [ [[package]] name = "savefile" -version = "0.17.2" +version = "0.17.3" dependencies = [ "arrayvec", "bit-set", @@ -471,7 +471,7 @@ dependencies = [ [[package]] name = "savefile-abi" -version = "0.17.2" +version = "0.17.3" dependencies = [ "byteorder", "libloading", @@ -511,7 +511,7 @@ dependencies = [ [[package]] name = "savefile-derive" -version = "0.17.2" +version = "0.17.3" dependencies = [ "proc-macro-error", "proc-macro2", diff --git a/savefile-abi/CHANGELOG.md b/savefile-abi/CHANGELOG.md index f5b3c42..1c334ad 100644 --- a/savefile-abi/CHANGELOG.md +++ b/savefile-abi/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.17.3](https://github.com/avl/savefile/compare/savefile-abi-v0.17.2...savefile-abi-v0.17.3) - 2024-05-09 + +### Other +- format + ## [0.17.2](https://github.com/avl/savefile/compare/savefile-abi-v0.17.1...savefile-abi-v0.17.2) - 2024-05-05 ### Other diff --git a/savefile-abi/Cargo.toml b/savefile-abi/Cargo.toml index 1a8d7fc..d9d2ea6 100644 --- a/savefile-abi/Cargo.toml +++ b/savefile-abi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "savefile-abi" -version = "0.17.2" +version = "0.17.3" edition = "2021" authors = ["Anders Musikka "] documentation = "https://docs.rs/savefile-abi/" @@ -16,7 +16,7 @@ keywords = ["dylib", "dlopen", "ffi"] license = "MIT/Apache-2.0" [dependencies] -savefile = { path="../savefile", version = "=0.17.2" } -savefile-derive = { path="../savefile-derive", version = "=0.17.2" } +savefile = { path="../savefile", version = "=0.17.3" } +savefile-derive = { path="../savefile-derive", version = "=0.17.3" } byteorder = "1.4" libloading = "0.8" diff --git a/savefile-derive/CHANGELOG.md b/savefile-derive/CHANGELOG.md index 73eee14..87a95f1 100644 --- a/savefile-derive/CHANGELOG.md +++ b/savefile-derive/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.17.3](https://github.com/avl/savefile/compare/savefile-derive-v0.17.2...savefile-derive-v0.17.3) - 2024-05-09 + +### Other +- Merge remote-tracking branch 'origin/master' into minor_v19 + ## [0.17.2](https://github.com/avl/savefile/compare/savefile-derive-v0.17.1...savefile-derive-v0.17.2) - 2024-05-05 ### Other diff --git a/savefile-derive/Cargo.toml b/savefile-derive/Cargo.toml index ed562a0..28a51cc 100644 --- a/savefile-derive/Cargo.toml +++ b/savefile-derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "savefile-derive" -version = "0.17.2" +version = "0.17.3" authors = ["Anders Musikka "] repository = "https://github.com/avl/savefile" diff --git a/savefile-test/Cargo.toml b/savefile-test/Cargo.toml index bf64b8a..a8127a9 100644 --- a/savefile-test/Cargo.toml +++ b/savefile-test/Cargo.toml @@ -12,7 +12,7 @@ nightly=["savefile/nightly"] [dependencies] savefile = { path = "../savefile", features = ["size_sanity_checks", "encryption", "compression","bit-set","bit-vec","rustc-hash","serde_derive", "quickcheck"]} -savefile-derive = { path = "../savefile-derive", version = "=0.17.2" } +savefile-derive = { path = "../savefile-derive", version = "=0.17.3" } savefile-abi = { path = "../savefile-abi" } bit-vec = "0.6" arrayvec="0.7" diff --git a/savefile/CHANGELOG.md b/savefile/CHANGELOG.md index 4fda70d..38d46ce 100644 --- a/savefile/CHANGELOG.md +++ b/savefile/CHANGELOG.md @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.17.3](https://github.com/avl/savefile/compare/savefile-v0.17.2...savefile-v0.17.3) - 2024-05-09 + +### Fixed +- Silence warning on newer rustc, since TryFrom and TryInto are now part of prelude. Use still needed to keep working on old rustc. + +### Other +- Merge remote-tracking branch 'origin/master' into minor_v19 + ## [0.17.2](https://github.com/avl/savefile/compare/savefile-v0.17.1...savefile-v0.17.2) - 2024-05-05 ### Fixed diff --git a/savefile/Cargo.toml b/savefile/Cargo.toml index f83b494..e9b2d17 100644 --- a/savefile/Cargo.toml +++ b/savefile/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "savefile" -version = "0.17.2" +version = "0.17.3" authors = ["Anders Musikka "] documentation = "https://docs.rs/savefile/" homepage = "https://github.com/avl/savefile/" @@ -53,13 +53,13 @@ bit-set = {version = "0.5", optional = true} rustc-hash = {version = "1.1", optional = true} memoffset = "0.9" byteorder = "1.4" -savefile-derive = {path="../savefile-derive", version = "=0.17.2", optional = true } +savefile-derive = {path="../savefile-derive", version = "=0.17.3", optional = true } serde_derive = {version= "1.0", optional = true} serde = {version= "1.0", optional = true} quickcheck = {version= "1.0", optional = true} [dev-dependencies] -savefile-derive = { path="../savefile-derive", version = "=0.17.2" } +savefile-derive = { path="../savefile-derive", version = "=0.17.3" } [build-dependencies] rustc_version="0.2"