rust-lang / rust-lang/rustc-dev-guide

Example of using rustc_interface to generate the HIR for a file referencing dependent crates?

Open
#1,720 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-custom-driver C-discussion E-hard I-terse T-compiler
Dominant language
HTML
Stars
1.9k
Forks
613
Avg merge
17h 24m
Merged PRs (30d)
39

Description

https://github.com/rust-lang/rustc-dev-guide/blob/master/examples/rustc-driver-example.rs is a great example to get me started using rustc_interface, but I am stuck on how to point this query towards a file that references another crate. I want to use rustc to analyze a multi-crate project and build up info across all crates in the project.

I have a repo based directly on rustc-driver-example, showing my problem. See this example which attempts to produce HIR for a file which references another crate. It fails with:

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: failed while formatting fluent string `metadata_cannot_find_crate`: 
message was missing
', compiler/rustc_errors/src/emitter.rs:1402:84

However I can generate a HIR for a file that does not depend on other crates.

What do I need to add to the config to make it aware of other crates?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with examples/rustc-driver-example.rs in the rustc-dev-guide and reproduce the failure in the linked megadep repository, especially examples/alphabeta.rs. Trace the rustc_interface configuration used for the single-crate example and compare it with the multi-crate case. Done means documenting or demonstrating the configuration needed to generate HIR when dependent crates are referenced.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.