I am trying to build a proc-macro crate with Rust 2018 edition. However, I cannot use the proc_macro
crate.
My Cargo.toml
:
[package]
name = "letrec"
version = "0.1.0"
authors = ["Bruno Zimmermann <brunoczim@gmail.com>"]
edition = "2018"
[lib]
proc-macro = true
crate-type = ["proc-macro"]
[dependencies]
syn = "*"
My src/lib.rs
:
use proc_macro::TokenStream;
#[proc_macro]
pub fn letrec(toks: TokenStream) -> TokenStream {
unimplemented!()
}
And the error:
error[E0432]: unresolved import `proc_macro`
--> src/lib.rs:1:5
|
1 | use proc_macro::TokenStream;
| ^^^^^^^^^^ Could not find `proc_macro` in `{{root}}`
error: aborting due to previous error
The problem seems to be I cannot declare extern crate proc_macro
and I also cannot find another way of declaring it.
EDIT: I have tried also the following, which yields a bizarre error:
use self::proc_macro::TokenStream;
Error:
error[E0432]: unresolved import `self::proc_macro`
--> src/lib.rs:1:11
|
1 | use self::proc_macro::TokenStream;
| ^^^^^^^^^^ Did you mean `crate::registrar::proc_macro`?
error: aborting due to previous error
Then, if I try to change it to
use crate::registrar::proc_macro::TokenStream;
I get:
error[E0433]: failed to resolve. Maybe a missing `extern crate registrar;`?
--> src/lib.rs:1:12
|
1 | use crate::registrar::proc_macro::TokenStream;
| ^^^^^^^^^ Maybe a missing `extern crate registrar;`?
EDIT2: Surprisingly, I can still write extern crate proc_macro;
. If I do this, everything works fine, but I have to import crate::proc_macro::TokenStream
.
NOTE: using 1.30.0-nightly (887690686 2018-09-27)