Skip to content

Commit

Permalink
Strip invisible delimiters from type name (#156)
Browse files Browse the repository at this point in the history
* Strip invisible delimiters from type name

* Bump to 2.1.2 and add to CHANGELOG

* Move comment to code
  • Loading branch information
ascjones committed May 18, 2022
1 parent 7140f90 commit e4de349
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.1.2] - 2022-05-18

### Fixed
- Strip invisible delimiters from type name [(#156)](https://github.com/paritytech/scale-info/pull/156)

## [2.1.1] - 2022-04-11

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scale-info"
version = "2.1.1"
version = "2.1.2"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
rust-version = "1.56.1"
Expand All @@ -17,7 +17,7 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
[dependencies]
bitvec = { version = "1", default-features = false, features = ["alloc"], optional = true }
cfg-if = "1.0"
scale-info-derive = { version = "2.1.1", path = "derive", default-features = false, optional = true }
scale-info-derive = { version = "2.1.2", path = "derive", default-features = false, optional = true }
serde = { version = "1", default-features = false, optional = true, features = ["derive", "alloc"] }
derive_more = { version = "0.99.1", default-features = false, features = ["from"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scale-info-derive"
version = "2.1.1"
version = "2.1.2"
authors = [
"Parity Technologies <[email protected]>",
"Centrality Developers <[email protected]>",
Expand Down
9 changes: 8 additions & 1 deletion derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,14 @@ impl TypeInfoImpl {
*lifetime = parse_quote!('static)
}
}
let mut ty = ty.clone();
let mut ty = match ty {
// When a type is specified as part of a `macro_rules!`, the tokens passed to
// the `TypeInfo` derive macro are a type `Group`, which is pretty printed with
// invisible delimiters e.g. /*«*/ bool /*»*/. To avoid printing the delimiters
// the inner type element is extracted.
syn::Type::Group(group) => (*group.elem).clone(),
_ => ty.clone(),
};
StaticLifetimesReplace.visit_type_mut(&mut ty);

let type_name = clean_type_string(&quote!(#ty).to_string());
Expand Down
19 changes: 19 additions & 0 deletions test_suite/tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,3 +867,22 @@ fn ranges() {

assert_type!(Rangey, ty);
}

#[test]
fn strips_invisible_delimiters_from_type_name() {
macro_rules! gen_struct {
( $ty:ty ) => {
#[allow(unused)]
#[derive(TypeInfo)]
struct S($ty);
};
}

gen_struct!(bool);

let expected = Type::builder()
.path(Path::new("S", "derive"))
.composite(Fields::unnamed().field(|f| f.ty::<bool>().type_name("bool")));

assert_type!(S, expected);
}

0 comments on commit e4de349

Please sign in to comment.