1 use crate::hir::def::Namespace;
2 use crate::hir::map::DefPathData;
3 use crate::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
4 use crate::ty::{self, DefIdTree, Ty, TyCtxt, TypeFoldable};
5 use crate::ty::subst::{Kind, Subst, SubstsRef, UnpackedKind};
6 use crate::middle::cstore::{ExternCrate, ExternCrateSource};
7 use syntax::symbol::{keywords, Symbol};
9 use rustc_data_structures::fx::FxHashSet;
10 use syntax::symbol::InternedString;
13 use std::fmt::{self, Write as _};
18 static FORCE_IMPL_FILENAME_LINE: Cell<bool> = Cell::new(false);
19 static SHOULD_PREFIX_WITH_CRATE: Cell<bool> = Cell::new(false);
22 /// Force us to name impls with just the filename/line number. We
23 /// normally try to use types. But at some points, notably while printing
24 /// cycle errors, this can result in extra or suboptimal error output,
25 /// so this variable disables that check.
26 pub fn with_forced_impl_filename_line<F: FnOnce() -> R, R>(f: F) -> R {
27 FORCE_IMPL_FILENAME_LINE.with(|force| {
28 let old = force.get();
36 /// Adds the `crate::` prefix to paths where appropriate.
37 pub fn with_crate_prefix<F: FnOnce() -> R, R>(f: F) -> R {
38 SHOULD_PREFIX_WITH_CRATE.with(|flag| {
47 // FIXME(eddyb) this module uses `pub(crate)` for things used only
48 // from `ppaux` - when that is removed, they can be re-privatized.
50 struct LateBoundRegionNameCollector(FxHashSet<InternedString>);
51 impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector {
52 fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
54 ty::ReLateBound(_, ty::BrNamed(_, name)) => {
59 r.super_visit_with(self)
63 pub struct PrintCx<'a, 'gcx, 'tcx, P> {
64 pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
66 pub(crate) is_debug: bool,
67 pub(crate) is_verbose: bool,
68 pub(crate) identify_regions: bool,
69 pub(crate) used_region_names: Option<FxHashSet<InternedString>>,
70 pub(crate) region_index: usize,
71 pub(crate) binder_depth: usize,
74 // HACK(eddyb) this is solely for `self: &mut PrintCx<Self>`, e.g. to
75 // implement traits on the printer and call the methods on the context.
76 impl<P> Deref for PrintCx<'_, '_, '_, P> {
78 fn deref(&self) -> &P {
83 impl<P> PrintCx<'a, 'gcx, 'tcx, P> {
84 pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>, printer: P) -> Self {
89 is_verbose: tcx.sess.verbose(),
90 identify_regions: tcx.sess.opts.debugging_opts.identify_regions,
91 used_region_names: None,
97 pub(crate) fn with<R>(printer: P, f: impl FnOnce(PrintCx<'_, '_, '_, P>) -> R) -> R {
98 ty::tls::with(|tcx| f(PrintCx::new(tcx, printer)))
100 pub(crate) fn prepare_late_bound_region_info<T>(&mut self, value: &ty::Binder<T>)
101 where T: TypeFoldable<'tcx>
103 let mut collector = LateBoundRegionNameCollector(Default::default());
104 value.visit_with(&mut collector);
105 self.used_region_names = Some(collector.0);
106 self.region_index = 0;
110 pub trait Print<'tcx, P> {
114 fn print(&self, cx: &mut PrintCx<'_, '_, 'tcx, P>) -> Result<Self::Output, Self::Error>;
117 cx: &mut PrintCx<'_, '_, 'tcx, P>,
118 ) -> Result<Self::Output, Self::Error> {
119 let old_debug = cx.is_debug;
121 let result = self.print(cx);
122 cx.is_debug = old_debug;
125 fn print_debug(&self, cx: &mut PrintCx<'_, '_, 'tcx, P>) -> Result<Self::Output, Self::Error> {
126 let old_debug = cx.is_debug;
128 let result = self.print(cx);
129 cx.is_debug = old_debug;
134 pub trait Printer: Sized {
140 self: &mut PrintCx<'_, '_, 'tcx, Self>,
142 substs: Option<SubstsRef<'tcx>>,
144 projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
145 ) -> Result<Self::Path, Self::Error> {
146 self.default_print_def_path(def_id, substs, ns, projections)
149 self: &mut PrintCx<'_, '_, 'tcx, Self>,
151 substs: Option<SubstsRef<'tcx>>,
154 trait_ref: Option<ty::TraitRef<'tcx>>,
155 ) -> Result<Self::Path, Self::Error> {
156 self.default_print_impl_path(impl_def_id, substs, ns, self_ty, trait_ref)
160 self: &mut PrintCx<'_, '_, '_, Self>,
162 ) -> Result<Self::Path, Self::Error>;
164 self: &mut PrintCx<'_, '_, 'tcx, Self>,
165 impl_prefix: Option<Self::Path>,
167 trait_ref: Option<ty::TraitRef<'tcx>>,
169 ) -> Result<Self::Path, Self::Error>;
171 self: &mut PrintCx<'_, '_, '_, Self>,
174 ) -> Result<Self::Path, Self::Error>;
175 fn path_generic_args(
176 self: &mut PrintCx<'_, '_, 'tcx, Self>,
178 params: &[ty::GenericParamDef],
179 substs: SubstsRef<'tcx>,
181 projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
182 ) -> Result<Self::Path, Self::Error>;
186 pub struct PrettyPath {
190 /// Trait for printers that pretty-print using `fmt::Write` to the printer.
191 pub trait PrettyPrinter: Printer<Error = fmt::Error, Path = PrettyPath> + fmt::Write {}
193 impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
194 // HACK(eddyb) get rid of `def_path_str` and/or pass `Namespace` explicitly always
195 // (but also some things just print a `DefId` generally so maybe we need this?)
196 fn guess_def_namespace(self, def_id: DefId) -> Namespace {
197 match self.def_key(def_id).disambiguated_data.data {
198 DefPathData::ValueNs(..) |
199 DefPathData::EnumVariant(..) |
200 DefPathData::Field(..) |
201 DefPathData::AnonConst |
202 DefPathData::ConstParam(..) |
203 DefPathData::ClosureExpr |
204 DefPathData::StructCtor => Namespace::ValueNS,
206 DefPathData::MacroDef(..) => Namespace::MacroNS,
208 _ => Namespace::TypeNS,
212 /// Returns a string identifying this `DefId`. This string is
213 /// suitable for user output.
214 pub fn def_path_str(self, def_id: DefId) -> String {
215 let ns = self.guess_def_namespace(def_id);
216 debug!("def_path_str: def_id={:?}, ns={:?}", def_id, ns);
217 let mut s = String::new();
218 let _ = PrintCx::new(self, FmtPrinter { fmt: &mut s })
219 .print_def_path(def_id, None, ns, iter::empty());
224 impl<P: Printer> PrintCx<'a, 'gcx, 'tcx, P> {
225 pub fn default_print_def_path(
228 substs: Option<SubstsRef<'tcx>>,
230 projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
231 ) -> Result<P::Path, P::Error> {
232 debug!("default_print_def_path: def_id={:?}, substs={:?}, ns={:?}", def_id, substs, ns);
233 let key = self.tcx.def_key(def_id);
234 debug!("default_print_def_path: key={:?}", key);
236 match key.disambiguated_data.data {
237 DefPathData::CrateRoot => {
238 assert!(key.parent.is_none());
239 self.path_crate(def_id.krate)
242 DefPathData::Impl => {
243 let mut self_ty = self.tcx.type_of(def_id);
244 if let Some(substs) = substs {
245 self_ty = self_ty.subst(self.tcx, substs);
248 let mut impl_trait_ref = self.tcx.impl_trait_ref(def_id);
249 if let Some(substs) = substs {
250 impl_trait_ref = impl_trait_ref.subst(self.tcx, substs);
252 self.print_impl_path(def_id, substs, ns, self_ty, impl_trait_ref)
256 let generics = substs.map(|_| self.tcx.generics_of(def_id));
257 let generics_parent = generics.as_ref().and_then(|g| g.parent);
258 let parent_def_id = DefId { index: key.parent.unwrap(), ..def_id };
259 let path = if let Some(generics_parent_def_id) = generics_parent {
260 assert_eq!(parent_def_id, generics_parent_def_id);
262 // FIXME(eddyb) try to move this into the parent's printing
263 // logic, instead of doing it when printing the child.
264 let parent_generics = self.tcx.generics_of(parent_def_id);
265 let parent_has_own_self =
266 parent_generics.has_self && parent_generics.parent_count == 0;
267 if let (Some(substs), true) = (substs, parent_has_own_self) {
268 let trait_ref = ty::TraitRef::new(parent_def_id, substs);
269 self.path_qualified(None, trait_ref.self_ty(), Some(trait_ref), ns)?
271 self.print_def_path(parent_def_id, substs, ns, iter::empty())?
274 self.print_def_path(parent_def_id, None, ns, iter::empty())?
276 let path = match key.disambiguated_data.data {
277 // Skip `::{{constructor}}` on tuple/unit structs.
278 DefPathData::StructCtor => path,
283 &key.disambiguated_data.data.as_interned_str().as_str(),
288 if let (Some(generics), Some(substs)) = (generics, substs) {
289 let has_own_self = generics.has_self && generics.parent_count == 0;
290 let params = &generics.params[has_own_self as usize..];
291 self.path_generic_args(path, params, substs, ns, projections)
299 fn default_print_impl_path(
302 _substs: Option<SubstsRef<'tcx>>,
305 impl_trait_ref: Option<ty::TraitRef<'tcx>>,
306 ) -> Result<P::Path, P::Error> {
307 debug!("default_print_impl_path: impl_def_id={:?}, self_ty={}, impl_trait_ref={:?}",
308 impl_def_id, self_ty, impl_trait_ref);
310 // Decide whether to print the parent path for the impl.
311 // Logically, since impls are global, it's never needed, but
312 // users may find it useful. Currently, we omit the parent if
313 // the impl is either in the same module as the self-type or
315 let parent_def_id = self.tcx.parent(impl_def_id).unwrap();
316 let in_self_mod = match characteristic_def_id_of_type(self_ty) {
318 Some(ty_def_id) => self.tcx.parent(ty_def_id) == Some(parent_def_id),
320 let in_trait_mod = match impl_trait_ref {
322 Some(trait_ref) => self.tcx.parent(trait_ref.def_id) == Some(parent_def_id),
325 let prefix_path = if !in_self_mod && !in_trait_mod {
326 // If the impl is not co-located with either self-type or
327 // trait-type, then fallback to a format that identifies
328 // the module more clearly.
329 Some(self.print_def_path(parent_def_id, None, ns, iter::empty())?)
331 // Otherwise, try to give a good form that would be valid language
332 // syntax. Preferably using associated item notation.
336 self.path_qualified(prefix_path, self_ty, impl_trait_ref, ns)
340 /// As a heuristic, when we see an impl, if we see that the
341 /// 'self type' is a type defined in the same module as the impl,
342 /// we can omit including the path to the impl itself. This
343 /// function tries to find a "characteristic `DefId`" for a
344 /// type. It's just a heuristic so it makes some questionable
345 /// decisions and we may want to adjust it later.
346 pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {
348 ty::Adt(adt_def, _) => Some(adt_def.did),
350 ty::Dynamic(data, ..) => data.principal_def_id(),
352 ty::Array(subty, _) |
353 ty::Slice(subty) => characteristic_def_id_of_type(subty),
355 ty::RawPtr(mt) => characteristic_def_id_of_type(mt.ty),
357 ty::Ref(_, ty, _) => characteristic_def_id_of_type(ty),
359 ty::Tuple(ref tys) => tys.iter()
360 .filter_map(|ty| characteristic_def_id_of_type(ty))
363 ty::FnDef(def_id, _) |
364 ty::Closure(def_id, _) |
365 ty::Generator(def_id, _, _) |
366 ty::Foreign(def_id) => Some(def_id),
375 ty::Placeholder(..) |
376 ty::UnnormalizedProjection(..) |
382 ty::GeneratorWitness(..) |
384 ty::Float(_) => None,
388 pub struct FmtPrinter<F: fmt::Write> {
392 impl<P: PrettyPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
393 /// If possible, this returns a global path resolving to `def_id` that is visible
394 /// from at least one local module and returns true. If the crate defining `def_id` is
395 /// declared with an `extern crate`, the path is guaranteed to use the `extern crate`.
396 fn try_print_visible_def_path(&mut self, def_id: DefId) -> Result<Option<P::Path>, P::Error> {
397 debug!("try_print_visible_def_path: def_id={:?}", def_id);
399 // If `def_id` is a direct or injected extern crate, return the
400 // path to the crate followed by the path to the item within the crate.
401 if def_id.index == CRATE_DEF_INDEX {
402 let cnum = def_id.krate;
404 if cnum == LOCAL_CRATE {
405 return Ok(Some(self.path_crate(cnum)?));
408 // In local mode, when we encounter a crate other than
409 // LOCAL_CRATE, execution proceeds in one of two ways:
411 // 1. for a direct dependency, where user added an
412 // `extern crate` manually, we put the `extern
413 // crate` as the parent. So you wind up with
414 // something relative to the current crate.
415 // 2. for an extern inferred from a path or an indirect crate,
416 // where there is no explicit `extern crate`, we just prepend
418 match *self.tcx.extern_crate(def_id) {
420 src: ExternCrateSource::Extern(def_id),
425 debug!("try_print_visible_def_path: def_id={:?}", def_id);
426 let path = if !span.is_dummy() {
427 self.print_def_path(def_id, None, Namespace::TypeNS, iter::empty())?
429 self.path_crate(cnum)?
431 return Ok(Some(path));
434 return Ok(Some(self.path_crate(cnum)?));
440 if def_id.is_local() {
444 let visible_parent_map = self.tcx.visible_parent_map(LOCAL_CRATE);
446 let mut cur_def_key = self.tcx.def_key(def_id);
447 debug!("try_print_visible_def_path: cur_def_key={:?}", cur_def_key);
449 // For a UnitStruct or TupleStruct we want the name of its parent rather than <unnamed>.
450 if let DefPathData::StructCtor = cur_def_key.disambiguated_data.data {
453 index: cur_def_key.parent.expect("DefPathData::StructCtor missing a parent"),
456 cur_def_key = self.tcx.def_key(parent);
459 let visible_parent = match visible_parent_map.get(&def_id).cloned() {
460 Some(parent) => parent,
461 None => return Ok(None),
463 let path = match self.try_print_visible_def_path(visible_parent)? {
465 None => return Ok(None),
467 let actual_parent = self.tcx.parent(def_id);
469 let data = cur_def_key.disambiguated_data.data;
471 "try_print_visible_def_path: data={:?} visible_parent={:?} actual_parent={:?}",
472 data, visible_parent, actual_parent,
475 let symbol = match data {
476 // In order to output a path that could actually be imported (valid and visible),
477 // we need to handle re-exports correctly.
479 // For example, take `std::os::unix::process::CommandExt`, this trait is actually
480 // defined at `std::sys::unix::ext::process::CommandExt` (at time of writing).
482 // `std::os::unix` rexports the contents of `std::sys::unix::ext`. `std::sys` is
483 // private so the "true" path to `CommandExt` isn't accessible.
485 // In this case, the `visible_parent_map` will look something like this:
487 // (child) -> (parent)
488 // `std::sys::unix::ext::process::CommandExt` -> `std::sys::unix::ext::process`
489 // `std::sys::unix::ext::process` -> `std::sys::unix::ext`
490 // `std::sys::unix::ext` -> `std::os`
492 // This is correct, as the visible parent of `std::sys::unix::ext` is in fact
495 // When printing the path to `CommandExt` and looking at the `cur_def_key` that
496 // corresponds to `std::sys::unix::ext`, we would normally print `ext` and then go
497 // to the parent - resulting in a mangled path like
498 // `std::os::ext::process::CommandExt`.
500 // Instead, we must detect that there was a re-export and instead print `unix`
501 // (which is the name `std::sys::unix::ext` was re-exported as in `std::os`). To
502 // do this, we compare the parent of `std::sys::unix::ext` (`std::sys::unix`) with
503 // the visible parent (`std::os`). If these do not match, then we iterate over
504 // the children of the visible parent (as was done when computing
505 // `visible_parent_map`), looking for the specific child we currently have and then
506 // have access to the re-exported name.
507 DefPathData::Module(actual_name) |
508 DefPathData::TypeNs(actual_name) if Some(visible_parent) != actual_parent => {
509 self.tcx.item_children(visible_parent)
511 .find(|child| child.def.def_id() == def_id)
512 .map(|child| child.ident.as_str())
513 .unwrap_or_else(|| actual_name.as_str())
516 data.get_opt_name().map(|n| n.as_str()).unwrap_or_else(|| {
517 // Re-exported `extern crate` (#43189).
518 if let DefPathData::CrateRoot = data {
519 self.tcx.original_crate_name(def_id.krate).as_str()
521 Symbol::intern("<unnamed>").as_str()
526 debug!("try_print_visible_def_path: symbol={:?}", symbol);
527 Ok(Some(self.path_append(path, &symbol)?))
530 pub fn pretty_path_qualified(
532 impl_prefix: Option<P::Path>,
534 trait_ref: Option<ty::TraitRef<'tcx>>,
536 ) -> Result<P::Path, P::Error> {
537 if let Some(prefix) = impl_prefix {
538 // HACK(eddyb) going through `path_append` means symbol name
539 // computation gets to handle its equivalent of `::` correctly.
540 let _ = self.path_append(prefix, "<impl ")?;
541 if let Some(trait_ref) = trait_ref {
542 trait_ref.print_display(self)?;
543 write!(self.printer, " for ")?;
545 self_ty.print_display(self)?;
546 write!(self.printer, ">")?;
547 return Ok(PrettyPath { empty: false });
550 if trait_ref.is_none() {
551 // Inherent impls. Try to print `Foo::bar` for an inherent
552 // impl on `Foo`, but fallback to `<Foo>::bar` if self-type is
553 // anything other than a simple path.
555 ty::Adt(adt_def, substs) => {
556 return self.print_def_path(adt_def.did, Some(substs), ns, iter::empty());
558 ty::Foreign(did) => {
559 return self.print_def_path(did, None, ns, iter::empty());
562 ty::Bool | ty::Char | ty::Str |
563 ty::Int(_) | ty::Uint(_) | ty::Float(_) => {
564 self_ty.print_display(self)?;
565 return Ok(PrettyPath { empty: false });
572 write!(self.printer, "<")?;
573 self_ty.print_display(self)?;
574 if let Some(trait_ref) = trait_ref {
575 write!(self.printer, " as ")?;
576 let _ = self.print_def_path(
578 Some(trait_ref.substs),
583 write!(self.printer, ">")?;
584 Ok(PrettyPath { empty: false })
587 pub fn pretty_path_generic_args(
590 params: &[ty::GenericParamDef],
591 substs: SubstsRef<'tcx>,
593 projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
594 ) -> Result<P::Path, P::Error> {
595 let mut empty = true;
596 let mut start_or_continue = |cx: &mut Self, start: &str, cont: &str| {
599 write!(cx.printer, "{}", start)
601 write!(cx.printer, "{}", cont)
605 let start = if ns == Namespace::ValueNS { "::<" } else { "<" };
607 // Don't print any regions if they're all erased.
608 let print_regions = params.iter().any(|param| {
609 match substs[param.index as usize].unpack() {
610 UnpackedKind::Lifetime(r) => *r != ty::ReErased,
615 // Don't print args that are the defaults of their respective parameters.
616 let num_supplied_defaults = if self.is_verbose {
619 params.iter().rev().take_while(|param| {
621 ty::GenericParamDefKind::Lifetime => false,
622 ty::GenericParamDefKind::Type { has_default, .. } => {
623 has_default && substs[param.index as usize] == Kind::from(
624 self.tcx.type_of(param.def_id).subst(self.tcx, substs)
627 ty::GenericParamDefKind::Const => false, // FIXME(const_generics:defaults)
632 for param in ¶ms[..params.len() - num_supplied_defaults] {
633 match substs[param.index as usize].unpack() {
634 UnpackedKind::Lifetime(region) => {
638 start_or_continue(self, start, ", ")?;
639 if !region.display_outputs_anything(self) {
640 // This happens when the value of the region
641 // parameter is not easily serialized. This may be
642 // because the user omitted it in the first place,
643 // or because it refers to some block in the code,
644 // etc. I'm not sure how best to serialize this.
645 write!(self.printer, "'_")?;
647 region.print_display(self)?;
650 UnpackedKind::Type(ty) => {
651 start_or_continue(self, start, ", ")?;
652 ty.print_display(self)?;
654 UnpackedKind::Const(ct) => {
655 start_or_continue(self, start, ", ")?;
656 ct.print_display(self)?;
661 for projection in projections {
662 start_or_continue(self, start, ", ")?;
663 write!(self.printer, "{}=",
664 self.tcx.associated_item(projection.item_def_id).ident)?;
665 projection.ty.print_display(self)?;
668 start_or_continue(self, "", ">")?;
674 impl<F: fmt::Write> fmt::Write for FmtPrinter<F> {
675 fn write_str(&mut self, s: &str) -> fmt::Result {
676 self.fmt.write_str(s)
680 impl<F: fmt::Write> Printer for FmtPrinter<F> {
681 type Error = fmt::Error;
683 type Path = PrettyPath;
686 self: &mut PrintCx<'_, '_, 'tcx, Self>,
688 substs: Option<SubstsRef<'tcx>>,
690 projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
691 ) -> Result<Self::Path, Self::Error> {
692 // FIXME(eddyb) avoid querying `tcx.generics_of` and `tcx.def_key`
693 // both here and in `default_print_def_path`.
694 let generics = substs.map(|_| self.tcx.generics_of(def_id));
695 if generics.as_ref().and_then(|g| g.parent).is_none() {
696 if let Some(path) = self.try_print_visible_def_path(def_id)? {
697 let path = if let (Some(generics), Some(substs)) = (generics, substs) {
698 let has_own_self = generics.has_self && generics.parent_count == 0;
699 let params = &generics.params[has_own_self as usize..];
700 self.path_generic_args(path, params, substs, ns, projections)?
708 let key = self.tcx.def_key(def_id);
709 if let DefPathData::Impl = key.disambiguated_data.data {
710 // Always use types for non-local impls, where types are always
711 // available, and filename/line-number is mostly uninteresting.
713 !def_id.is_local() || {
714 // Otherwise, use filename/line-number if forced.
715 let force_no_types = FORCE_IMPL_FILENAME_LINE.with(|f| f.get());
720 // If no type info is available, fall back to
721 // pretty printing some span information. This should
722 // only occur very early in the compiler pipeline.
723 let parent_def_id = DefId { index: key.parent.unwrap(), ..def_id };
724 let path = self.print_def_path(parent_def_id, None, ns, iter::empty())?;
725 let span = self.tcx.def_span(def_id);
726 return self.path_append(path, &format!("<impl at {:?}>", span));
730 self.default_print_def_path(def_id, substs, ns, projections)
734 self: &mut PrintCx<'_, '_, '_, Self>,
736 ) -> Result<Self::Path, Self::Error> {
737 if cnum == LOCAL_CRATE {
738 if self.tcx.sess.rust_2018() {
739 // We add the `crate::` keyword on Rust 2018, only when desired.
740 if SHOULD_PREFIX_WITH_CRATE.with(|flag| flag.get()) {
741 write!(self.printer, "{}", keywords::Crate.name())?;
742 return Ok(PrettyPath { empty: false });
745 Ok(PrettyPath { empty: true })
747 write!(self.printer, "{}", self.tcx.crate_name(cnum))?;
748 Ok(PrettyPath { empty: false })
752 self: &mut PrintCx<'_, '_, 'tcx, Self>,
753 impl_prefix: Option<Self::Path>,
755 trait_ref: Option<ty::TraitRef<'tcx>>,
757 ) -> Result<Self::Path, Self::Error> {
758 self.pretty_path_qualified(impl_prefix, self_ty, trait_ref, ns)
761 self: &mut PrintCx<'_, '_, '_, Self>,
764 ) -> Result<Self::Path, Self::Error> {
765 // FIXME(eddyb) this shouldn't happen, but is currently
766 // the case for `extern { ... }` "foreign modules".
772 write!(self.printer, "::")?;
774 write!(self.printer, "{}", text)?;
775 Ok(PrettyPath { empty: false })
777 fn path_generic_args(
778 self: &mut PrintCx<'_, '_, 'tcx, Self>,
780 params: &[ty::GenericParamDef],
781 substs: SubstsRef<'tcx>,
783 projections: impl Iterator<Item = ty::ExistentialProjection<'tcx>>,
784 ) -> Result<Self::Path, Self::Error> {
785 self.pretty_path_generic_args(path, params, substs, ns, projections)
789 impl<F: fmt::Write> PrettyPrinter for FmtPrinter<F> {}