From eb99a89bd7037bb5662ba3d16296a4f7a2adaea6 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 18 Oct 2023 09:51:50 +0000 Subject: [PATCH] Ensure we never accidentally serialize an `ErrorGuaranteed` --- compiler/rustc_span/src/lib.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 49b4042d148..444dc09c11d 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -2244,7 +2244,7 @@ where /// Useful type to use with `Result<>` indicate that an error has already /// been reported to the user, so no need to continue checking. -#[derive(Clone, Copy, Debug, Encodable, Decodable, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] #[derive(HashStable_Generic)] pub struct ErrorGuaranteed(()); @@ -2256,3 +2256,20 @@ impl ErrorGuaranteed { ErrorGuaranteed(()) } } + +impl Encodable for ErrorGuaranteed { + #[inline] + fn encode(&self, _e: &mut E) { + panic!( + "should never serialize an `ErrorGuaranteed`, as we do not write metadata or incremental caches in case errors occurred" + ) + } +} +impl Decodable for ErrorGuaranteed { + #[inline] + fn decode(_d: &mut D) -> ErrorGuaranteed { + panic!( + "`ErrorGuaranteed` should never have been serialized to metadata or incremental caches" + ) + } +}