Skip to content

Commit 25f0396

Browse files
jimblandyErichDonGubler
authored andcommitted
[naga] Delete DiagnosticDisplay impl for for TypeInner.
Delete the implementation of `core::fmt::Display` for `naga::common::DiagnosticDisplay`, as it is a footgun wherever `Struct` types can arise. Document that it should not be implemented for `TypeInner`. Although it is possible to put a dummy implementation in the way of people adding real implementations, that would also turn attempts to use it into dynamic errors rather than compile-time errors. Make do with a comment for now.
1 parent 6150576 commit 25f0396

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

naga/src/common/diagnostic_display.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Displaying Naga IR terms in diagnostic output.
22
33
use crate::proc::{GlobalCtx, Rule, TypeResolution};
4-
use crate::{Handle, Scalar, Type, TypeInner};
4+
use crate::{Handle, Scalar, Type};
55

66
#[cfg(any(feature = "wgsl-in", feature = "wgsl-out"))]
77
use crate::common::wgsl::TypeContext;
@@ -23,13 +23,16 @@ use core::fmt;
2323
/// for a type like `DiagnosticDisplay<(Handle<Type>, GlobalCtx)>`, where
2424
/// the [`GlobalCtx`] type provides the necessary context.
2525
///
26+
/// Do not implement this type for [`TypeInner`], as that does not
27+
/// have enough information to display struct types correctly.
28+
///
2629
/// If you only need debugging output, [`DiagnosticDebug`] uses
2730
/// easier-to-obtain context types but still does a good enough job
2831
/// for logging or debugging.
2932
///
3033
/// [`Display`]: core::fmt::Display
31-
/// [`Scalar`]: crate::Scalar
3234
/// [`GlobalCtx`]: crate::proc::GlobalCtx
35+
/// [`TypeInner`]: crate::ir::TypeInner
3336
/// [`DiagnosticDebug`]: super::DiagnosticDebug
3437
///
3538
/// ## Language-sensitive diagnostics
@@ -83,23 +86,6 @@ impl fmt::Display for DiagnosticDisplay<(Handle<Type>, GlobalCtx<'_>)> {
8386
}
8487
}
8588

86-
impl fmt::Display for DiagnosticDisplay<(&TypeInner, GlobalCtx<'_>)> {
87-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
88-
let (inner, ref ctx) = self.0;
89-
90-
#[cfg(any(feature = "wgsl-in", feature = "wgsl-out"))]
91-
ctx.write_type_inner(inner, f)?;
92-
93-
#[cfg(not(any(feature = "wgsl-in", feature = "wgsl-out")))]
94-
{
95-
let _ = ctx;
96-
write!(f, "{inner:?}")?;
97-
}
98-
99-
Ok(())
100-
}
101-
}
102-
10389
impl fmt::Display for DiagnosticDisplay<(&str, &Rule, GlobalCtx<'_>)> {
10490
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10591
let (name, rule, ref ctx) = self.0;

0 commit comments

Comments
 (0)