1use hir::def::Namespace;
2use rustc_data_structures::fx::FxHashSet;
3use rustc_data_structures::sso::SsoHashSet;
4use rustc_hir as hir;
5use rustc_hir::def_id::{CrateNum, DefId};
6use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
7use tracing::{debug, instrument, trace};
8
9use crate::ty::{self, GenericArg, Ty, TyCtxt};
10
11mod pretty;
13pub use self::pretty::*;
14use super::Lift;
15
16pub type PrintError = std::fmt::Error;
17
18pub trait Print<P> {
19 fn print(&self, p: &mut P) -> Result<(), PrintError>;
20}
21
22pub trait Printer<'tcx>: Sized {
29 fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
30
31 fn print_def_path(
33 &mut self,
34 def_id: DefId,
35 args: ty::GenericArgs<'tcx>,
36 ) -> Result<(), PrintError> {
37 self.default_print_def_path(def_id, args)
38 }
39
40 fn print_impl_path(
42 &mut self,
43 impl_def_id: DefId,
44 args: ty::GenericArgs<'tcx>,
45 ) -> Result<(), PrintError> {
46 let tcx = self.tcx();
47 let self_ty = tcx.type_of(impl_def_id);
48 let impl_trait_ref = tcx.impl_opt_trait_ref(impl_def_id);
49 let (self_ty, impl_trait_ref) = if tcx.generics_of(impl_def_id).count() <= args.len() {
50 (
51 self_ty.instantiate(tcx, args).skip_norm_wip(),
52 impl_trait_ref
53 .map(|impl_trait_ref| impl_trait_ref.instantiate(tcx, args).skip_norm_wip()),
54 )
55 } else {
56 (
59 self_ty.instantiate_identity().skip_norm_wip(),
60 impl_trait_ref
61 .map(|impl_trait_ref| impl_trait_ref.instantiate_identity().skip_norm_wip()),
62 )
63 };
64
65 self.default_print_impl_path(impl_def_id, self_ty, impl_trait_ref)
66 }
67
68 fn print_region(&mut self, region: ty::Region<'tcx>) -> Result<(), PrintError>;
70
71 fn print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError>;
73
74 fn print_dyn_existential(
76 &mut self,
77 predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
78 ) -> Result<(), PrintError>;
79
80 fn print_const(&mut self, ct: ty::Const<'tcx>) -> Result<(), PrintError>;
82
83 fn print_crate_name(&mut self, cnum: CrateNum) -> Result<(), PrintError>;
85
86 fn print_path_with_simple(
93 &mut self,
94 print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
95 disambiguated_data: &DisambiguatedDefPathData,
96 ) -> Result<(), PrintError>;
97
98 fn print_path_with_impl(
103 &mut self,
104 print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
105 self_ty: Ty<'tcx>,
106 trait_ref: Option<ty::TraitRef<'tcx>>,
107 ) -> Result<(), PrintError>;
108
109 fn print_path_with_generic_args(
116 &mut self,
117 print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
118 args: ty::GenericArgs<'tcx>,
119 ) -> Result<(), PrintError>;
120
121 fn print_path_with_qualified(
124 &mut self,
125 self_ty: Ty<'tcx>,
126 trait_ref: Option<ty::TraitRef<'tcx>>,
127 ) -> Result<(), PrintError>;
128
129 fn print_coroutine_with_kind(
130 &mut self,
131 def_id: DefId,
132 parent_args: ty::GenericArgs<'tcx>,
133 kind: Ty<'tcx>,
134 ) -> Result<(), PrintError> {
135 self.print_path_with_generic_args(
136 |p| p.print_def_path(def_id, parent_args),
137 self.tcx().mk_args(&[kind.into()]),
138 )
139 }
140
141 fn reset_path(&mut self) -> Result<(), PrintError> {
142 Ok(())
143 }
144
145 fn should_omit_parent_def_path(&self, _parent_def_id: DefId) -> bool {
146 false
147 }
148
149 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("default_print_def_path",
"rustc_middle::ty::print", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/bbcdfd90a3f81ca2a5f6d69b943a6ff0d8582102/compiler/rustc_middle/src/ty/print/mod.rs"),
::tracing_core::__macro_support::Option::Some(150u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::print"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("args")
}> =
::tracing::__macro_support::FieldName::new("args");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Result<(), PrintError> = loop {};
return __tracing_attr_fake_return;
}
{
let key = self.tcx().def_key(def_id);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/bbcdfd90a3f81ca2a5f6d69b943a6ff0d8582102/compiler/rustc_middle/src/ty/print/mod.rs:157",
"rustc_middle::ty::print", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/bbcdfd90a3f81ca2a5f6d69b943a6ff0d8582102/compiler/rustc_middle/src/ty/print/mod.rs"),
::tracing_core::__macro_support::Option::Some(157u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::print"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("key")
}> =
::tracing::__macro_support::FieldName::new("key");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&key)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
match key.disambiguated_data.data {
DefPathData::CrateRoot => {
if !key.parent.is_none() {
::core::panicking::panic("assertion failed: key.parent.is_none()")
};
self.print_crate_name(def_id.krate)
}
DefPathData::Impl => self.print_impl_path(def_id, args),
_ => {
let parent_def_id =
DefId { index: key.parent.unwrap(), ..def_id };
let mut parent_args = args.as_slice();
let mut trait_qualify_parent = false;
if !args.is_empty() {
let generics = self.tcx().generics_of(def_id);
parent_args =
&args.as_slice()[..generics.parent_count.min(args.len())];
match key.disambiguated_data.data {
DefPathData::Closure => {
if let Some(hir::CoroutineKind::Desugared(_,
hir::CoroutineSource::Closure)) =
self.tcx().coroutine_kind(def_id) &&
args.len() > parent_args.len() {
return self.print_coroutine_with_kind(def_id,
self.tcx().mk_args(parent_args),
args[parent_args.len()].expect_ty());
} else {}
}
DefPathData::SyntheticCoroutineBody => {}
DefPathData::AnonConst => {}
_ => {
if !generics.is_own_empty() &&
args.len() >= generics.count() {
let args =
generics.own_args_no_defaults(self.tcx(), args.as_slice());
let parent_args = self.tcx().mk_args(parent_args);
return self.print_path_with_generic_args(|p|
p.print_def_path(def_id, parent_args),
self.tcx().mk_args(args));
}
}
}
trait_qualify_parent =
generics.has_self && generics.parent == Some(parent_def_id)
&& parent_args.len() == generics.parent_count &&
self.tcx().generics_of(parent_def_id).parent_count == 0;
}
let omit_parent =
#[allow(non_exhaustive_omitted_patterns)] match key.disambiguated_data.data
{
DefPathData::TypeNs(..) => true,
_ => false,
} && self.should_omit_parent_def_path(parent_def_id);
let parent_args = self.tcx().mk_args(parent_args);
self.print_path_with_simple(|p: &mut Self|
{
if omit_parent {
p.reset_path()?;
Ok(())
} else if trait_qualify_parent {
let trait_ref =
ty::TraitRef::new(p.tcx(), parent_def_id,
parent_args.iter());
p.print_path_with_qualified(trait_ref.self_ty(),
Some(trait_ref))
} else { p.print_def_path(parent_def_id, parent_args) }
}, &key.disambiguated_data)
}
}
}
}
}#[instrument(skip(self), level = "debug")]
151 fn default_print_def_path(
152 &mut self,
153 def_id: DefId,
154 args: ty::GenericArgs<'tcx>,
155 ) -> Result<(), PrintError> {
156 let key = self.tcx().def_key(def_id);
157 debug!(?key);
158
159 match key.disambiguated_data.data {
160 DefPathData::CrateRoot => {
161 assert!(key.parent.is_none());
162 self.print_crate_name(def_id.krate)
163 }
164
165 DefPathData::Impl => self.print_impl_path(def_id, args),
166
167 _ => {
168 let parent_def_id = DefId { index: key.parent.unwrap(), ..def_id };
169
170 let mut parent_args = args.as_slice();
171 let mut trait_qualify_parent = false;
172 if !args.is_empty() {
173 let generics = self.tcx().generics_of(def_id);
174 parent_args = &args.as_slice()[..generics.parent_count.min(args.len())];
175
176 match key.disambiguated_data.data {
177 DefPathData::Closure => {
178 if let Some(hir::CoroutineKind::Desugared(
181 _,
182 hir::CoroutineSource::Closure,
183 )) = self.tcx().coroutine_kind(def_id)
184 && args.len() > parent_args.len()
185 {
186 return self.print_coroutine_with_kind(
187 def_id,
188 self.tcx().mk_args(parent_args),
189 args[parent_args.len()].expect_ty(),
190 );
191 } else {
192 }
194 }
195 DefPathData::SyntheticCoroutineBody => {
196 }
199 DefPathData::AnonConst => {}
203
204 _ => {
207 if !generics.is_own_empty() && args.len() >= generics.count() {
208 let args =
209 generics.own_args_no_defaults(self.tcx(), args.as_slice());
210 let parent_args = self.tcx().mk_args(parent_args);
211 return self.print_path_with_generic_args(
212 |p| p.print_def_path(def_id, parent_args),
213 self.tcx().mk_args(args),
214 );
215 }
216 }
217 }
218
219 trait_qualify_parent = generics.has_self
222 && generics.parent == Some(parent_def_id)
223 && parent_args.len() == generics.parent_count
224 && self.tcx().generics_of(parent_def_id).parent_count == 0;
225 }
226
227 let omit_parent = matches!(key.disambiguated_data.data, DefPathData::TypeNs(..))
228 && self.should_omit_parent_def_path(parent_def_id);
229
230 let parent_args = self.tcx().mk_args(parent_args);
231 self.print_path_with_simple(
232 |p: &mut Self| {
233 if omit_parent {
234 p.reset_path()?;
235 Ok(())
236 } else if trait_qualify_parent {
237 let trait_ref =
238 ty::TraitRef::new(p.tcx(), parent_def_id, parent_args.iter());
239 p.print_path_with_qualified(trait_ref.self_ty(), Some(trait_ref))
240 } else {
241 p.print_def_path(parent_def_id, parent_args)
242 }
243 },
244 &key.disambiguated_data,
245 )
246 }
247 }
248 }
249
250 fn default_print_impl_path(
251 &mut self,
252 impl_def_id: DefId,
253 self_ty: Ty<'tcx>,
254 impl_trait_ref: Option<ty::TraitRef<'tcx>>,
255 ) -> Result<(), PrintError> {
256 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/bbcdfd90a3f81ca2a5f6d69b943a6ff0d8582102/compiler/rustc_middle/src/ty/print/mod.rs:256",
"rustc_middle::ty::print", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/bbcdfd90a3f81ca2a5f6d69b943a6ff0d8582102/compiler/rustc_middle/src/ty/print/mod.rs"),
::tracing_core::__macro_support::Option::Some(256u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::print"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("default_print_impl_path: impl_def_id={0:?}, self_ty={1}, impl_trait_ref={2:?}",
impl_def_id, self_ty, impl_trait_ref) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
257 "default_print_impl_path: impl_def_id={:?}, self_ty={}, impl_trait_ref={:?}",
258 impl_def_id, self_ty, impl_trait_ref
259 );
260
261 let key = self.tcx().def_key(impl_def_id);
262 let parent_def_id = DefId { index: key.parent.unwrap(), ..impl_def_id };
263
264 let in_self_mod = match characteristic_def_id_of_type(self_ty) {
270 None => false,
271 Some(ty_def_id) => self.tcx().parent(ty_def_id) == parent_def_id,
272 };
273 let in_trait_mod = match impl_trait_ref {
274 None => false,
275 Some(trait_ref) => self.tcx().parent(trait_ref.def_id) == parent_def_id,
276 };
277
278 if !in_self_mod && !in_trait_mod {
279 self.print_path_with_impl(
283 |p| p.print_def_path(parent_def_id, ty::GenericArgs::empty()),
284 self_ty,
285 impl_trait_ref,
286 )
287 } else {
288 self.print_path_with_qualified(self_ty, impl_trait_ref)
291 }
292 }
293}
294
295fn characteristic_def_id_of_type_cached<'a>(
305 ty: Ty<'a>,
306 visited: &mut SsoHashSet<Ty<'a>>,
307) -> Option<DefId> {
308 match *ty.kind() {
309 ty::Adt(adt_def, _) => Some(adt_def.did()),
310
311 ty::Dynamic(data, ..) => data.principal_def_id(),
312
313 ty::Pat(subty, _) | ty::Array(subty, _) | ty::Slice(subty) => {
314 characteristic_def_id_of_type_cached(subty, visited)
315 }
316
317 ty::RawPtr(ty, _) => characteristic_def_id_of_type_cached(ty, visited),
318
319 ty::Ref(_, ty, _) => characteristic_def_id_of_type_cached(ty, visited),
320
321 ty::Tuple(tys) => tys.iter().find_map(|ty| {
322 if visited.insert(ty) {
323 return characteristic_def_id_of_type_cached(ty, visited);
324 }
325 return None;
326 }),
327
328 ty::FnDef(def_id, _)
329 | ty::Closure(def_id, _)
330 | ty::CoroutineClosure(def_id, _)
331 | ty::Coroutine(def_id, _)
332 | ty::CoroutineWitness(def_id, _)
333 | ty::Foreign(def_id) => Some(def_id),
334
335 ty::Bool
336 | ty::Char
337 | ty::Int(_)
338 | ty::Uint(_)
339 | ty::Str
340 | ty::FnPtr(..)
341 | ty::UnsafeBinder(_)
342 | ty::Alias(..)
343 | ty::Placeholder(..)
344 | ty::Param(_)
345 | ty::Infer(_)
346 | ty::Bound(..)
347 | ty::Error(_)
348 | ty::Never
349 | ty::Float(_) => None,
350 }
351}
352pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {
353 characteristic_def_id_of_type_cached(ty, &mut SsoHashSet::new())
354}
355
356impl<'tcx, P: Printer<'tcx>> Print<P> for ty::Region<'tcx> {
357 fn print(&self, p: &mut P) -> Result<(), PrintError> {
358 p.print_region(*self)
359 }
360}
361
362impl<'tcx, P: Printer<'tcx>> Print<P> for Ty<'tcx> {
363 fn print(&self, p: &mut P) -> Result<(), PrintError> {
364 p.print_type(*self)
365 }
366}
367
368impl<'tcx, P: Printer<'tcx> + std::fmt::Write> Print<P> for ty::Instance<'tcx> {
369 fn print(&self, cx: &mut P) -> Result<(), PrintError> {
370 cx.print_def_path(self.def_id(), self.args)?;
371 match self.def {
372 ty::InstanceKind::Item(_) => {}
373 ty::InstanceKind::Intrinsic(_) => cx.write_str(" - intrinsic")?,
374 ty::InstanceKind::LlvmIntrinsic(_) => cx.write_str(" - LLVM intrinsic")?,
375 ty::InstanceKind::Virtual(_, num) => cx.write_str(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" - virtual#{0}", num))
})format!(" - virtual#{num}"))?,
376 ty::InstanceKind::Shim(shim) => {
377 cx.write_str(" - ")?;
378 shim.print(cx)?;
379 }
380 }
381 Ok(())
382 }
383}
384
385impl<'tcx, P: Printer<'tcx> + std::fmt::Write> Print<P> for ty::ShimKind<'tcx> {
386 fn print(&self, cx: &mut P) -> Result<(), PrintError> {
387 match self {
388 ty::ShimKind::VTable(_) => cx.write_str("shim(vtable)"),
389 ty::ShimKind::Reify(_, None) => cx.write_str("shim(reify)"),
390 ty::ShimKind::Reify(_, Some(ty::ReifyReason::FnPtr)) => {
391 cx.write_str("shim(reify-fnptr)")
392 }
393 ty::ShimKind::Reify(_, Some(ty::ReifyReason::Vtable)) => {
394 cx.write_str("shim(reify-vtable)")
395 }
396 ty::ShimKind::ThreadLocal(_) => cx.write_str("shim(tls)"),
397 ty::ShimKind::FnPtr(_, ty) => cx.write_str(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("shim({0})", ty))
})format!("shim({ty})")),
398 ty::ShimKind::ClosureOnce { .. } => cx.write_str("shim"),
399 ty::ShimKind::ConstructCoroutineInClosure { .. } => cx.write_str("shim"),
400 ty::ShimKind::DropGlue(_, None) => cx.write_str("shim(None)"),
401 ty::ShimKind::DropGlue(_, Some(ty)) => cx.write_str(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("shim(Some({0}))", ty))
})format!("shim(Some({ty}))")),
402 ty::ShimKind::Clone(_, ty) => cx.write_str(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("shim({0})", ty))
})format!("shim({ty})")),
403 ty::ShimKind::FnPtrAsPtr(_, ty) => cx.write_str(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("shim({0})", ty))
})format!("shim({ty})")),
404 ty::ShimKind::FnPtrFromPtr(_, ty) => cx.write_str(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("shim({0})", ty))
})format!("shim({ty})")),
405 ty::ShimKind::FutureDropPoll(_, proxy_ty, impl_ty) => {
406 cx.write_str(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("dropshim({0}-{1})", proxy_ty,
impl_ty))
})format!("dropshim({proxy_ty}-{impl_ty})"))
407 }
408 ty::ShimKind::AsyncDropGlue(_, ty) => cx.write_str(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("shim({0})", ty))
})format!("shim({ty})")),
409 ty::ShimKind::AsyncDropGlueCtor(_, ty) => cx.write_str(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("shim(Some({0}))", ty))
})format!("shim(Some({ty}))")),
410 }
411 }
412}
413
414impl<'tcx, P: Printer<'tcx>> Print<P> for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> {
415 fn print(&self, p: &mut P) -> Result<(), PrintError> {
416 p.print_dyn_existential(self)
417 }
418}
419
420impl<'tcx, P: Printer<'tcx>> Print<P> for ty::Const<'tcx> {
421 fn print(&self, p: &mut P) -> Result<(), PrintError> {
422 p.print_const(*self)
423 }
424}
425
426impl<T> rustc_type_ir::ir_print::IrPrint<T> for TyCtxt<'_>
427where
428 T: Copy + for<'a, 'tcx> Lift<TyCtxt<'tcx>, Lifted: Print<FmtPrinter<'a, 'tcx>>>,
429{
430 fn print(t: &T, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
431 ty::tls::with(|tcx| {
432 let mut p = FmtPrinter::new(tcx, Namespace::TypeNS);
433 tcx.lift(*t).print(&mut p)?;
434 fmt.write_str(&p.into_buffer())?;
435 Ok(())
436 })
437 }
438
439 fn print_debug(t: &T, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
440 { let _guard = NoTrimmedGuard::new(); Self::print(t, fmt) }with_no_trimmed_paths!(Self::print(t, fmt))
441 }
442}