Skip to content

Commit c45086b

Browse files
committed
printing ty::Field
1 parent 11f0dc7 commit c45086b

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ fn push_debuginfo_type_name<'tcx>(
119119
push_generic_params_internal(tcx, args, output, visited);
120120
}
121121
}
122+
ty::Field(container, field_path) => {
123+
output.push_str("field_of!(");
124+
push_debuginfo_type_name(tcx, container, qualified, output, visited);
125+
output.push_str(", ");
126+
field_path.walk(tcx, container, |_, name, _, last| {
127+
output.push_str(name.as_str());
128+
if !last {
129+
output.push('.');
130+
}
131+
std::ops::ControlFlow::<()>::Continue(())
132+
});
133+
output.push(')');
134+
}
122135
ty::Tuple(component_types) => {
123136
if cpp_like_debuginfo {
124137
output.push_str("tuple$<");

compiler/rustc_middle/src/ty/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ impl<'tcx> Ty<'tcx> {
180180
| ty::Float(_)
181181
| ty::Str
182182
| ty::Never => "type".into(),
183+
ty::Field(..) => "field representing type".into(),
183184
ty::Tuple(tys) if tys.is_empty() => "unit type".into(),
184185
ty::Adt(def, _) => def.descr().into(),
185186
ty::Foreign(_) => "extern type".into(),

compiler/rustc_middle/src/ty/print/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ fn characteristic_def_id_of_type_cached<'a>(
289289
) -> Option<DefId> {
290290
match *ty.kind() {
291291
ty::Adt(adt_def, _) => Some(adt_def.did()),
292+
ty::Field(ty, _) => characteristic_def_id_of_type_cached(ty, visited),
292293

293294
ty::Dynamic(data, ..) => data.principal_def_id(),
294295

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::cell::Cell;
22
use std::fmt::{self, Write as _};
33
use std::iter;
4-
use std::ops::{Deref, DerefMut};
4+
use std::ops::{ControlFlow, Deref, DerefMut};
55

66
use rustc_abi::{ExternAbi, Size};
77
use rustc_apfloat::Float;
@@ -784,6 +784,28 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
784784
},
785785
},
786786
ty::Adt(def, args) => self.print_def_path(def.did(), args)?,
787+
ty::Field(container, field_path) => {
788+
write!(self, "field_of!(")?;
789+
self.pretty_print_type(container)?;
790+
write!(self, ", ")?;
791+
field_path
792+
.walk(self.tcx(), container, |_, name, _, last| {
793+
match write!(self, "{name}") {
794+
Err(err) => ControlFlow::Break(Err(err)),
795+
Ok(()) => ControlFlow::Continue(()),
796+
}?;
797+
if !last {
798+
match write!(self, ".") {
799+
Err(err) => ControlFlow::Break(Err(err)),
800+
Ok(()) => ControlFlow::Continue(()),
801+
}
802+
} else {
803+
ControlFlow::Continue(())
804+
}
805+
})
806+
.unwrap_or(Ok(()))?;
807+
write!(self, ")")?;
808+
}
787809
ty::Dynamic(data, r, repr) => {
788810
let print_r = self.should_print_optional_region(r);
789811
if print_r {

compiler/rustc_type_ir/src/ty_kind.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ impl<I: Interner> fmt::Debug for TyKind<I> {
360360

361361
write!(f, ">")
362362
}
363+
Field(ty, field_path) => write!(f, "{ty:?}.{field_path:?}"),
363364
Foreign(d) => f.debug_tuple("Foreign").field(d).finish(),
364365
Str => write!(f, "str"),
365366
Array(t, c) => write!(f, "[{t:?}; {c:?}]"),

0 commit comments

Comments
 (0)