Skip to content

Commit e6a6c64

Browse files
committed
Added an explanation to slightly tricky decoding logic.
1 parent dad587b commit e6a6c64

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/librustc_metadata/decoder.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ impl<'a, 'tcx> SpecializedDecoder<CrateNum> for DecodeContext<'a, 'tcx> {
241241
impl<'a, 'tcx> SpecializedDecoder<hygiene::Mark> for DecodeContext<'a, 'tcx> {
242242
fn specialized_decode(&mut self) -> Result<hygiene::Mark, Self::Error> {
243243
let mark = u32::decode(self)?;
244+
//
245+
// We only perform translation if hygiene info is already available and if the
246+
// mark actually needs translation. That way we avoid loops (as obtaining hygiene
247+
// info for an external crate involves decoding marks) and avoid incorrectly translated
248+
// default marks.
244249
if self.cdata().hygiene_data_import_info.borrow().is_some() && mark != 0 {
245250
let imported_hygiene = self.cdata().imported_hygiene_data();
246251

@@ -254,6 +259,11 @@ impl<'a, 'tcx> SpecializedDecoder<hygiene::Mark> for DecodeContext<'a, 'tcx> {
254259
impl<'a, 'tcx> SpecializedDecoder<SyntaxContext> for DecodeContext<'a, 'tcx> {
255260
fn specialized_decode(&mut self) -> Result<SyntaxContext, Self::Error> {
256261
let ctxt = u32::decode(self)?;
262+
263+
// We only perform translation if hygiene info is already available and if the
264+
// syntax context actually needs translation. That way we avoid loops (as obtaining
265+
// hygiene info for an external crate involves decoding syntax contexts) and avoid
266+
// incorrectly translated default contexts.
257267
if self.cdata().hygiene_data_import_info.borrow().is_some() && ctxt != 0 {
258268
let imported_hygiene = self.cdata().imported_hygiene_data();
259269

0 commit comments

Comments
 (0)