I'm trying to make a syntax extension, but I got error E0432. I read about it in the error index but could not understand what I should do!
The error text I got is:
/Users/hasan/.cargo/bin/cargo run --color=always --package rust01 --bin rust01
Compiling rust01 v0.1.0 (file:///Users/hasan/PycharmProjects/rust01)
error[E0432]: unresolved import `rustc::plugin` --> src/lib.rs:6:12
| 6
| use rustc::plugin::Registry;
| ^^^^^^ Could not find `plugin` in `rustc`
error[E0432]: unresolved import
`syntax::ext::base::SyntaxExtension::Modifier` --> src/lib.rs:12:5
| 12
| use syntax::ext::base::SyntaxExtension::Modifier;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `Modifier` in `ext::base::SyntaxExtension`
error[E0432]: unresolved import `syntax::parse::token::intern` -->
src/lib.rs:13:5
| 13
| use syntax::parse::token::intern;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `intern` in `parse::token`
This happened with my IDE:
#![feature(plugin_registrar, rustc_private)]
extern crate syntax; extern crate rustc;
use rustc::plugin::Registry;
use syntax::ptr::P; use syntax::ast::{Item, MetaItem}; use syntax::ext::base::ExtCtxt; use syntax::codemap::Span; use syntax::ext::base::SyntaxExtension::Modifier; use syntax::parse::token::intern;
#[plugin_registrar] pub fn registrar(reg: &mut Registry) {
reg.register_syntax_extension(intern("extension"), Modifier(Box::new(expand))); }
fn expand(_: &mut ExtCtxt, _: Span, _: &MetaItem, item: P<Item>) -> P<Item> {
println!("Hello world!");
return item; }
Based on the comments received, I put the extension as a separate crate, the new app structure is in the screenshot below.
The Cargo.toml of bin is:
[package]
name = "hello_world"
version = "0.1.0"
authors = ["hasan"]
[dependencies]
extension = { path = "./extension" }
The Cargo.toml of lib is:
[package]
name = "extension"
version = "0.1.0"
authors = ["hasan"]
[dependencies]
[lib]
plugin = true

This is what happens when you use unstable features: they change! The blog post you link is quite old now (2015 maybe?)... Many things will still apply but things are being moved around.
You can find the latest official documentation here.
A quick skimming through the docs reveal the first problem is that rustc::plugin has been moved to its own crate: rustc_plugin. I didn't follow all the documentation but more issues probably follow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With