X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_interface%2Fcallbacks.rs;h=eb9c118bb0100d8345ee53b09327d84a2707e94f;hb=0c366cdeaf6cfc2780bae118268eec5c675d6c43;hp=28e687a378646a2754385b30b5ce61361cddb797;hpb=3928aceb49b11f4ae4d360390bed6503fb8109ec;p=rust.git diff --git a/src/librustc_interface/callbacks.rs b/src/librustc_interface/callbacks.rs index 28e687a3786..eb9c118bb01 100644 --- a/src/librustc_interface/callbacks.rs +++ b/src/librustc_interface/callbacks.rs @@ -11,17 +11,17 @@ use rustc::ty::tls; use rustc_errors::{Diagnostic, TRACK_DIAGNOSTICS}; +use rustc_span; use std::fmt; -use syntax_pos; /// This is a callback from libsyntax as it cannot access the implicit state /// in librustc otherwise. -fn span_debug(span: syntax_pos::Span, f: &mut fmt::Formatter<'_>) -> fmt::Result { +fn span_debug(span: rustc_span::Span, f: &mut fmt::Formatter<'_>) -> fmt::Result { tls::with_opt(|tcx| { if let Some(tcx) = tcx { write!(f, "{}", tcx.sess.source_map().span_to_string(span)) } else { - syntax_pos::default_span_debug(span, f) + rustc_span::default_span_debug(span, f) } }) } @@ -40,9 +40,23 @@ fn track_diagnostic(diagnostic: &Diagnostic) { }) } +/// This is a callback from librustc_hir as it cannot access the implicit state +/// in librustc otherwise. +fn def_id_debug(def_id: rustc_hir::def_id::DefId, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "DefId({}:{}", def_id.krate, def_id.index.index())?; + tls::with_opt(|opt_tcx| { + if let Some(tcx) = opt_tcx { + write!(f, " ~ {}", tcx.def_path_debug_str(def_id))?; + } + Ok(()) + })?; + write!(f, ")") +} + /// Sets up the callbacks in prior crates which we want to refer to the /// TyCtxt in. pub fn setup_callbacks() { - syntax_pos::SPAN_DEBUG.swap(&(span_debug as fn(_, &mut fmt::Formatter<'_>) -> _)); + rustc_span::SPAN_DEBUG.swap(&(span_debug as fn(_, &mut fmt::Formatter<'_>) -> _)); + rustc_hir::def_id::DEF_ID_DEBUG.swap(&(def_id_debug as fn(_, &mut fmt::Formatter<'_>) -> _)); TRACK_DIAGNOSTICS.swap(&(track_diagnostic as fn(&_))); }