// to track which `SyntaxContext`s we have already decoded.
// The provided closure will be invoked to deserialize a `SyntaxContextData`
// if we haven't already seen the id of the `SyntaxContext` we are deserializing.
-pub fn decode_syntax_context<
- D: Decoder,
- F: FnOnce(&mut D, u32) -> Result<SyntaxContextData, D::Error>,
->(
+pub fn decode_syntax_context<D: Decoder, F: FnOnce(&mut D, u32) -> SyntaxContextData>(
d: &mut D,
context: &HygieneDecodeContext,
decode_data: F,
-) -> Result<SyntaxContext, D::Error> {
- let raw_id: u32 = Decodable::decode(d)?;
+) -> SyntaxContext {
+ let raw_id: u32 = Decodable::decode(d);
if raw_id == 0 {
debug!("decode_syntax_context: deserialized root");
// The root is special
- return Ok(SyntaxContext::root());
+ return SyntaxContext::root();
}
let outer_ctxts = &context.remapped_ctxts;
// Ensure that the lock() temporary is dropped early
{
if let Some(ctxt) = outer_ctxts.lock().get(raw_id as usize).copied().flatten() {
- return Ok(ctxt);
+ return ctxt;
}
}
// Don't try to decode data while holding the lock, since we need to
// be able to recursively decode a SyntaxContext
- let mut ctxt_data = decode_data(d, raw_id)?;
+ let mut ctxt_data = decode_data(d, raw_id);
// Reset `dollar_crate_name` so that it will be updated by `update_dollar_crate_names`
// We don't care what the encoding crate set this to - we want to resolve it
// from the perspective of the current compilation session
assert_eq!(dummy.dollar_crate_name, kw::Empty);
});
- Ok(new_ctxt)
+ new_ctxt
}
fn for_all_ctxts_in<E, F: FnMut(u32, SyntaxContext, &SyntaxContextData) -> Result<(), E>>(
}
impl<D: Decoder> Decodable<D> for LocalExpnId {
- fn decode(d: &mut D) -> Result<Self, D::Error> {
- ExpnId::decode(d).map(ExpnId::expect_local)
+ fn decode(d: &mut D) -> Self {
+ ExpnId::expect_local(ExpnId::decode(d))
}
}
impl<D: Decoder> Decodable<D> for ExpnId {
- default fn decode(_: &mut D) -> Result<Self, D::Error> {
+ default fn decode(_: &mut D) -> Self {
panic!("cannot decode `ExpnId` with `{}`", std::any::type_name::<D>());
}
}
}
impl<D: Decoder> Decodable<D> for SyntaxContext {
- default fn decode(_: &mut D) -> Result<Self, D::Error> {
+ default fn decode(_: &mut D) -> Self {
panic!("cannot decode `SyntaxContext` with `{}`", std::any::type_name::<D>());
}
}