|
1 | 1 | use std::fmt::Write; |
| 2 | +use std::ops::ControlFlow; |
2 | 3 |
|
3 | 4 | use rustc_data_structures::intern::Interned; |
4 | 5 | use rustc_hir::def_id::{CrateNum, DefId}; |
@@ -58,6 +59,29 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> { |
58 | 59 | | ty::CoroutineClosure(def_id, args) |
59 | 60 | | ty::Coroutine(def_id, args) => self.print_def_path(def_id, args), |
60 | 61 | ty::Foreign(def_id) => self.print_def_path(def_id, &[]), |
| 62 | + ty::Field(container, field_path) => { |
| 63 | + write!(self, "field_of!(")?; |
| 64 | + self.print_type(container)?; |
| 65 | + write!(self, ", ")?; |
| 66 | + field_path |
| 67 | + .walk(self.tcx, container, |_, name, _, last| { |
| 68 | + match write!(self, "{name}") { |
| 69 | + Ok(()) => ControlFlow::Continue(()), |
| 70 | + Err(err) => ControlFlow::Break(Err(err)), |
| 71 | + }?; |
| 72 | + if !last { |
| 73 | + match write!(self, ".") { |
| 74 | + Ok(()) => ControlFlow::Continue(()), |
| 75 | + Err(err) => ControlFlow::Break(Err(err)), |
| 76 | + } |
| 77 | + } else { |
| 78 | + ControlFlow::Continue(()) |
| 79 | + } |
| 80 | + }) |
| 81 | + .unwrap_or(Ok(()))?; |
| 82 | + write!(self, ")")?; |
| 83 | + Ok(()) |
| 84 | + } |
61 | 85 |
|
62 | 86 | ty::Alias(ty::Free, _) => bug!("type_name: unexpected free alias"), |
63 | 87 | ty::Alias(ty::Inherent, _) => bug!("type_name: unexpected inherent projection"), |
|
0 commit comments