X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_middle%2Fsrc%2Fty%2Fprint%2Fmod.rs;h=667298b9b5b1316ff2738e5c08b1ceab2502be75;hb=ddf055ad07b93d27c826e737b674b65ab760e901;hp=e0a8d58f8a7f62a36aa49bb2988b0320c0f81e21;hpb=c867288d1b05bb7b4e069e3fd6c2d16bdc2bfd4b;p=rust.git diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index e0a8d58f8a7..667298b9b5b 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -3,7 +3,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sso::SsoHashSet; -use rustc_hir::def_id::{CrateNum, DefId}; +use rustc_hir::def_id::{CrateNum, DefId, LocalDefId}; use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData}; // `pretty` is a separate module only for organization. @@ -63,7 +63,7 @@ fn print_impl_path( fn print_dyn_existential( self, - predicates: &'tcx ty::List>>, + predicates: &'tcx ty::List>, ) -> Result; fn print_const(self, ct: ty::Const<'tcx>) -> Result; @@ -308,9 +308,7 @@ fn print(&self, cx: P) -> Result { } } -impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> - for &'tcx ty::List>> -{ +impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for &'tcx ty::List> { type Output = P::DynExistential; type Error = P::Error; fn print(&self, cx: P) -> Result { @@ -325,3 +323,12 @@ fn print(&self, cx: P) -> Result { cx.print_const(*self) } } + +// This is only used by query descriptions +pub fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String { + if def_id.is_top_level_module() { + "top-level module".to_string() + } else { + format!("module `{}`", tcx.def_path_str(def_id.to_def_id())) + } +}