Function rustc_tools::with_tyctxt

source ·
pub fn with_tyctxt<T: Send, F: FnOnce(TyCtxt<'_>) -> T + Send>(
    rustc_args: &[String],
    callback: F
) -> Result<T, String>
Expand description

If you need more information than what is provided by with_ast_parser, this is the function you will use.

  • rustc_args argument is what will be provided to rustc.
  • callback argument is the callback that will be called once everything has been set up. It provides a TyCtxt instance which will allow to use the rustc query engine.

VERY IMPORTANT TO NOTE: if you want to run this code on a crate with dependencies, you’ll need to pass the according options so that rustc knows where to look for them. otherwise it will simply fail to compile and the callback won’t be called. A good example of the list of the expected arguments can be seen when you run cargo build -v.

Take a look at cargo_integration and at rustc-tools-example to see how to write a cargo integration.

Don’t forget to take a look at the TyCtxt and at the Map documentations.

And to make things much simpler, I strongly recommend to use the HIR visitor. (You can take a look at how to use it with examples/hir.rs.)