[naga] Use TypeContext::write_type_resolution where appropriate.

Simplify the implementation of `Display` for
`DiagnosticDisplay<(TypeResolution, GlobalCtx)>` by calling
`GlobalCtx`'s implementation of `write_type_resolution` directly,
rather than duplicating its code. Provide a fallback for non-wgsl
builds.
This commit is contained in:
Jim Blandy 2025-04-09 12:56:52 -07:00 committed by Erich Gubler
parent 7f08498069
commit 6150576a77

View File

@ -53,10 +53,16 @@ impl fmt::Display for DiagnosticDisplay<(&TypeResolution, GlobalCtx<'_>)> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (resolution, ctx) = self.0;
match *resolution {
TypeResolution::Handle(handle) => DiagnosticDisplay((handle, ctx)).fmt(f),
TypeResolution::Value(ref inner) => DiagnosticDisplay((inner, ctx)).fmt(f),
#[cfg(any(feature = "wgsl-in", feature = "wgsl-out"))]
ctx.write_type_resolution(resolution, f)?;
#[cfg(not(any(feature = "wgsl-in", feature = "wgsl-out")))]
{
let _ = ctx;
write!(f, "{resolution:?}")?;
}
Ok(())
}
}