I'm trying to use a rustc
crate in my program.
#[macro_use]
extern crate rustc;
extern crate rustc_typeck;
extern crate syntax;
extern crate syntax_pos;
use rustc::hir;
fn main() {
println!("Hello, World!");
}
I also added an extra dependency in the Cargo.toml file:
[dependencies]
log = "0.4.1"
cargo run
emits a bunch of errors that it's private and nightly only:
error: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? (see issue #27812)
--> src/main.rs:2:1
|
2 | extern crate rustc;
| ^^^^^^^^^^^^^^^^^^^
It seems Cargo want a stable crate from crates.io
, but I don't know which crate I should use. There's no crate named rustc
on crates.io
.
Here's my Rust installation version.
I installed it using rustup
.
How can I use a rustc
crate for my program?
I tried to add rustc = "1.23.0"
to Cargo.toml
, but it still doesn't work with this error:
error: no matching package named `rustc` found (required by `rust-swift-serde-gen`)
rustc
is indeed not published on crates.io.
Because the API for the rustc
crate is not stable, you must switch to the nightly compiler and opt in by adding this line at the beginning of your crate root (main.rs
or lib.rs
):
#![feature(rustc_private)]
Naturally, since the API is not stable, every time you update your nightly compiler, things may break without warning!
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