Skip to content

Commit

Permalink
Restore leading :: for crate access (#152)
Browse files Browse the repository at this point in the history
* Restore leading `::` for crate access

* Fmt

* Fix it for real

* Fmt

* Restore changes

* Revert test changes

* Add ui test for `#![no_implicit_prelude]`

* Add ui test for `#![no_implicit_prelude]`

* Bump versions

* Update CHANGELOG
  • Loading branch information
ascjones authored Apr 13, 2022
1 parent 7f20fa1 commit 7140f90
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 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.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
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.0"
version = "2.1.1"
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.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"] }
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.0"
version = "2.1.1"
authors = [
"Parity Technologies <[email protected]>",
"Centrality Developers <[email protected]>",
Expand Down
11 changes: 7 additions & 4 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ident> {
fn crate_name_path(name: &str) -> Result<syn::Path> {
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))
Expand All @@ -303,7 +306,7 @@ fn crate_name_ident(name: &str) -> Result<Ident> {
fn crate_path(crate_path_attr: Option<&CratePathAttr>) -> Result<syn::Path> {
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 {
Expand Down
6 changes: 3 additions & 3 deletions derive/src/trait_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
});

Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test_suite/tests/ui/pass_no_implicit_prelude.rs
Original file line number Diff line number Diff line change
@@ -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<T: TypeInfo + 'static>() {}

fn main() {
assert_type_info::<S>();
}

0 comments on commit 7140f90

Please sign in to comment.