Skip to content

Commit

Permalink
Ensure we never accidentally serialize an ErrorGuaranteed
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Oct 20, 2023
1 parent fd9ef69 commit eb99a89
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());

Expand All @@ -2256,3 +2256,20 @@ impl ErrorGuaranteed {
ErrorGuaranteed(())
}
}

impl<E: rustc_serialize::Encoder> Encodable<E> 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<D: rustc_serialize::Decoder> Decodable<D> for ErrorGuaranteed {
#[inline]
fn decode(_d: &mut D) -> ErrorGuaranteed {
panic!(
"`ErrorGuaranteed` should never have been serialized to metadata or incremental caches"
)
}
}

0 comments on commit eb99a89

Please sign in to comment.