From 938790b29ba1ddda060eef9f6791bea7247469ef Mon Sep 17 00:00:00 2001 From: Tadeo Hepperle <62739623+tadeohepperle@users.noreply.github.com> Date: Fri, 22 Mar 2024 17:48:16 +0100 Subject: [PATCH] Change type id to new type id in `PortableRegistry::retain()`. (#204) * fix retain * bump version * add test, fix ui tests --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- src/portable.rs | 5 +++++ test_suite/tests/ui/fail_missing_derive.stderr | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80cc4df3..8bee45e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.11.1] - 2024-03-22 + +- Fix a bug in the `PortableRegistry::retain()` method, where a type's id field was not adjusted to the new position of the type in the retained `Vec`. + ## [2.11.0] - 2024-03-12 ### Added diff --git a/Cargo.toml b/Cargo.toml index 5a39def3..92678caf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scale-info" -version = "2.11.0" +version = "2.11.1" authors = ["Parity Technologies "] edition = "2021" rust-version = "1.60.0" diff --git a/src/portable.rs b/src/portable.rs index c19bb7ec..165a7dd6 100644 --- a/src/portable.rs +++ b/src/portable.rs @@ -181,6 +181,7 @@ impl PortableRegistry { // Retain this type, having updated any inner IDs: let new_id = new_types.len() as u32; + ty.id = new_id; new_types.push(ty); retained_mappings.insert(id, new_id); new_id @@ -549,6 +550,10 @@ mod tests { .field_portable(|f| f.name("vec_of_u32".into()).ty(1)), ); assert_eq!(registry.resolve(2).unwrap(), &expected_ty); + + for (idx, ty) in registry.types.iter().enumerate() { + assert_eq!(idx, ty.id as usize); + } } #[test] diff --git a/test_suite/tests/ui/fail_missing_derive.stderr b/test_suite/tests/ui/fail_missing_derive.stderr index 18aa96b8..1a08d56a 100644 --- a/test_suite/tests/ui/fail_missing_derive.stderr +++ b/test_suite/tests/ui/fail_missing_derive.stderr @@ -2,7 +2,7 @@ error[E0277]: the trait bound `PawType: TypeInfo` is not satisfied --> tests/ui/fail_missing_derive.rs:19:24 | 19 | assert_type_info::>(); - | ^^^^^^^^^^^^^^^^^^ the trait `TypeInfo` is not implemented for `PawType` + | ^^^^^^^^^^^^^^^^^^ the trait `TypeInfo` is not implemented for `PawType`, which is required by `Cat: TypeInfo` | = help: the following other types implement trait `TypeInfo`: bool