rust - 即使使用“rustc_private”也找不到板条箱“rustc”
问题描述
我从教程中偷了这段代码并将其放入src/lib.rs
#![feature(rustc_private)]
#![feature(plugin_registrar)]
extern crate rustc;
extern crate syntax;
use rustc::plugin::Registry;
use syntax::ast::{Item, MetaItem};
use syntax::codemap::Span;
use syntax::ext::base::ExtCtxt;
use syntax::ext::base::SyntaxExtension::Modifier;
use syntax::parse::token::intern;
use syntax::ptr::P;
#[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;
}
和Cargo.toml
[package]
name = "inductive"
version = "0.1.0"
authors = ["fakedrake"]
[lib]
name = "inductive"
plugin=true
[dependencies]
但
$ rustup component add rustc-dev
info: downloading component 'rustc-dev'
info: installing component 'rustc-dev'
info: using up to 500.0 MiB of RAM to unpack components
102.5 MiB / 102.5 MiB (100 %) 18.9 MiB/s in 5s ETA: 0s
$ cargo --version
cargo 1.52.0-nightly (c68432f1e 2021-03-02)
$ rustc --version
rustc 1.52.0-nightly (caca2121f 2021-03-05)
$ cargo build --verbose
Compiling inductive v0.1.0 (/Users/fakedrake/Projects/Rust/inductive)
Running `rustc --crate-name inductive src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type dylib --emit=dep-info,link -C prefer-dynamic -C embed-bitcode=no -C debuginfo=2 -C metadata=9adf86ab36dcd7bb --out-dir /Users/fakedrake/Projects/Rust/inductive/target/debug/deps -C incremental=/Users/fakedrake/Projects/Rust/inductive/target/debug/incremental -L dependency=/Users/fakedrake/Projects/Rust/inductive/target/debug/deps`
error[E0463]: can't find crate for `rustc`
--> src/lib.rs:4:1
|
4 | extern crate rustc;
| ^^^^^^^^^^^^^^^^^^^ can't find crate
error: aborting due to previous error
For more information about this error, try `rustc --explain E0463`.
error: could not compile `inductive`
Caused by:
process didn't exit successfully: `rustc --crate-name inductive src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type dylib --emit=dep-info,link -C prefer-dynamic -C embed-bitcode=no -C debuginfo=2 -C metadata=9adf86ab36dcd7bb --out-dir /Users/fakedrake/Projects/Rust/inductive/target/debug/deps -C incremental=/Users/fakedrake/Projects/Rust/inductive/target/debug/incremental -L dependency=/Users/fakedrake/Projects/Rust/inductive/target/debug/deps` (exit code: 1)
我究竟做错了什么?
解决方案
rustup component add --toolchain nightly rust-src rustc-dev llvm-tools-preview
推荐阅读
- django-rest-framework - 如何根据 Django Rest Framework 中的 JWT 有效负载覆盖 GET 方法?
- c# - C#元组不保留名称,只使用'itemx'
- javascript - 获取 div 的边界框,按 chromium/puppeteer 中的列数拆分
- r - 如何覆盖R中的html文件
- javascript - 响应式画廊 Vue.js
- sql-server - 恢复几个月前的表记录?
- java - 我怎样才能通过 java.net.Socket.Socket 读/写德语“Umlaute”和特殊字符,如 é?
- firebase - 使用最新版本的 firebase 和 node v10 在 VSCode 中本地调试 firebase 函数
- xpath - 提取两个文本值的正确 xpath 语法
- ansible - ansible 任务无法在 ansible shell 结果的列表输出中搜索字符串