本文介绍了即使有`rustc_private`也找不到箱子`rustc`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从教程中窃取了此代码,并将其放在 src/lib.rs

I stole this code from a tutorial and put it in 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

https://github.com/rust-lang/rust/issues/72564

这篇关于即使有`rustc_private`也找不到箱子`rustc`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 15:02