diff --git a/CHANGELOG.md b/CHANGELOG.md index e10b5032..bcef26f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.1.1] - 2022-04-11 + +### Fixed +- Restore leading `::` for crate access [(#152)](https://github.com/paritytech/scale-info/pull/152) + ## [2.1.0] - 2022-04-11 ### Added diff --git a/Cargo.toml b/Cargo.toml index 559f5fb4..08864b4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scale-info" -version = "2.1.0" +version = "2.1.1" authors = ["Parity Technologies "] edition = "2021" rust-version = "1.56.1" @@ -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.0", path = "derive", default-features = false, optional = true } +scale-info-derive = { version = "2.1.1", 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"] } diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 95c4efdf..4159b270 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scale-info-derive" -version = "2.1.0" +version = "2.1.1" authors = [ "Parity Technologies ", "Centrality Developers ", diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 59e10c79..f41968b7 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -288,13 +288,16 @@ impl TypeInfoImpl { } /// Get the name of a crate, to be robust against renamed dependencies. -fn crate_name_ident(name: &str) -> Result { +fn crate_name_path(name: &str) -> Result { proc_macro_crate::crate_name(name) .map(|crate_name| { use proc_macro_crate::FoundCrate::*; match crate_name { - Itself => Ident::new("self", Span::call_site()), - Name(name) => Ident::new(&name, Span::call_site()), + Itself => Ident::new("self", Span::call_site()).into(), + Name(name) => { + let crate_ident = Ident::new(&name, Span::call_site()); + parse_quote!( ::#crate_ident ) + } } }) .map_err(|e| syn::Error::new(Span::call_site(), &e)) @@ -303,7 +306,7 @@ fn crate_name_ident(name: &str) -> Result { fn crate_path(crate_path_attr: Option<&CratePathAttr>) -> Result { crate_path_attr .map(|path_attr| Ok(path_attr.path().clone())) - .unwrap_or_else(|| crate_name_ident("scale-info").map(|ident| ident.into())) + .unwrap_or_else(|| crate_name_path("scale-info")) } fn clean_type_string(input: &str) -> String { diff --git a/derive/src/trait_bounds.rs b/derive/src/trait_bounds.rs index 394b9abc..08fb1ec0 100644 --- a/derive/src/trait_bounds.rs +++ b/derive/src/trait_bounds.rs @@ -96,11 +96,11 @@ pub fn make_where_clause<'a>( if is_compact { where_clause .predicates - .push(parse_quote!(#ty : :: #scale_info :: scale::HasCompact)); + .push(parse_quote!(#ty : #scale_info :: scale::HasCompact)); } else { where_clause .predicates - .push(parse_quote!(#ty : :: #scale_info ::TypeInfo + 'static)); + .push(parse_quote!(#ty : #scale_info ::TypeInfo + 'static)); } }); @@ -111,7 +111,7 @@ pub fn make_where_clause<'a>( .skip_type_params() .map_or(true, |skip| !skip.skip(type_param)) { - bounds.push(parse_quote!(:: #scale_info ::TypeInfo)); + bounds.push(parse_quote!(#scale_info ::TypeInfo)); } bounds.push(parse_quote!('static)); where_clause diff --git a/test_suite/tests/ui/pass_no_implicit_prelude.rs b/test_suite/tests/ui/pass_no_implicit_prelude.rs new file mode 100644 index 00000000..40621bc2 --- /dev/null +++ b/test_suite/tests/ui/pass_no_implicit_prelude.rs @@ -0,0 +1,14 @@ +#![no_implicit_prelude] + +use ::info::{self as scale_info}; +use scale_info::TypeInfo; + +#[allow(dead_code)] +#[derive(TypeInfo)] +struct S { a: bool } + +fn assert_type_info() {} + +fn main() { + assert_type_info::(); +}