Skip to content

Commit 9bfa201

Browse files
authored
Bump proc-macro-crate to v1.0.0 (#127)
Signed-off-by: koushiro <koushiro.cqx@gmail.com>
1 parent 6da8334 commit 9bfa201

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ jobs:
5454
command: test
5555
args: --all-features --workspace
5656

57-
ensure_no_std:
58-
name: Ensure no_std
57+
build-no-std:
58+
name: Build no_std
5959
runs-on: ubuntu-latest
6060
steps:
6161
- name: Checkout Sources

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
target
22
Cargo.lock
3-
*.bk
3+
*.bk
4+
.idea

derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ proc-macro = true
1212

1313
[dependencies]
1414
proc-macro2 = { version = "1.0.24", features = ["span-locations"] }
15-
proc-macro-crate = "0.1.5"
15+
proc-macro-crate = "1.0.0"
1616
proc-macro-error = "1.0.4"
1717
quote = "1.0.7"
1818
syn = "1.0.42"

derive/src/multihash.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashSet;
22

33
use crate::utils;
4-
use proc_macro2::TokenStream;
4+
use proc_macro2::{Span, TokenStream};
55
use quote::quote;
66
#[cfg(not(test))]
77
use quote::ToTokens;
@@ -152,8 +152,8 @@ impl<'a> From<&'a VariantInfo<'a>> for Hash {
152152
Self {
153153
ident,
154154
code,
155-
digest,
156155
hasher,
156+
digest,
157157
}
158158
}
159159
}
@@ -224,7 +224,7 @@ fn error_code_duplicates(hashes: &[Hash]) {
224224

225225
/// An error that contains a span in order to produce nice error messages.
226226
#[derive(Debug)]
227-
struct ParseError(proc_macro2::Span);
227+
struct ParseError(Span);
228228

229229
/// Parse a path containing a `typenum` unsigned integer (e.g. `U64`) into a u64
230230
fn parse_unsigned_typenum(typenum_path: &syn::Type) -> Result<u64, ParseError> {
@@ -314,7 +314,13 @@ fn error_alloc_size(hashes: &[Hash], expected_alloc_size_type: &syn::Type) {
314314
}
315315

316316
pub fn multihash(s: Structure) -> TokenStream {
317-
let mh_crate = utils::use_crate("multihash");
317+
let mh_crate = match utils::use_crate("multihash") {
318+
Ok(ident) => ident,
319+
Err(e) => {
320+
let err = syn::Error::new(Span::call_site(), e).to_compile_error();
321+
return quote!(#err);
322+
}
323+
};
318324
let code_enum = &s.ast().ident;
319325
let (alloc_size, no_alloc_size_errors) = parse_code_enum_attrs(&s.ast());
320326
let hashes: Vec<_> = s.variants().iter().map(Hash::from).collect();

derive/src/utils.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
use proc_macro2::Span;
2+
use proc_macro_crate::{crate_name, FoundCrate};
23
use syn::parse::{Parse, ParseStream};
34
use syn::punctuated::Punctuated;
5+
use syn::Error;
46

5-
pub fn use_crate(name: &str) -> syn::Ident {
6-
let krate = proc_macro_crate::crate_name(name).unwrap_or_else(|_| "crate".into());
7-
syn::Ident::new(&krate, Span::call_site())
7+
pub fn use_crate(name: &str) -> Result<syn::Ident, Error> {
8+
match crate_name(name) {
9+
Ok(FoundCrate::Name(krate)) => Ok(syn::Ident::new(&krate, Span::call_site())),
10+
Ok(FoundCrate::Itself) => Ok(syn::Ident::new("crate", Span::call_site())),
11+
Err(err) => Err(Error::new(Span::call_site(), err)),
12+
}
813
}
914

1015
#[derive(Debug)]

0 commit comments

Comments
 (0)