Explicit lifetimes change the function signature and make the function incompatible for the required type signature



extern crate rustc;
extern crate rustc_driver;

use rustc::hir::intravisit as hir_visit;
use rustc::hir;
use rustc_driver::driver::{CompileController, CompileState};

pub struct SomeVisitor<'a, 'tcx: 'a> {
    pub map: &'a hir::map::Map<'tcx>,

impl<'v, 'tcx: 'v> rustc::hir::intravisit::Visitor<'tcx> for SomeVisitor<'v, 'tcx> {
    fn nested_visit_map<'this>(&'this mut self) -> hir_visit::NestedVisitorMap<'this, 'tcx> {

fn hir(s: &mut CompileState) {
    let krate = s.hir_crate.unwrap();
    let map = s.hir_map.unwrap();
    let mut visitor = SomeVisitor { map };
    hir_visit::walk_crate(&mut visitor, krate);

fn main() {
        let mut controller = CompileController::basic();
        controller.after_hir_lowering.callback = box hir;


This lifetime problem drives me crazy. I almost believe that I have to change the signature of the callback.


Here are some notes on why this doesn’t compile. But I’m not sure what to do about that.

TLDR; passing s.hir_crate and indirectly passing s.hir_map into walk_crates knots lifetimes in such a way that parameter s in hir must have type CompileState<'tcx, 'tcx>, but callback requires independent lifetime parameters there.