Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/librustc_metadata/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ impl<'a, 'tcx> SpecializedEncoder<Span> for EncodeContext<'a, 'tcx> {
// cross-crate inconsistencies (getting one behavior in the same
// crate, and a different behavior in another crate) due to the
// limited surface that proc-macros can expose.
//
// IMPORTANT: If this is ever changed, be sure to update
// `rustc_span::hygiene::raw_encode_expn_id` to handle
// encoding `ExpnData` for proc-macro crates.
if self.is_proc_macro {
SyntaxContext::root().encode(self)?;
} else {
Expand Down
25 changes: 21 additions & 4 deletions src/librustc_span/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,13 +1170,30 @@ pub fn raw_encode_expn_id<E: Encoder>(
mode: ExpnDataEncodeMode,
e: &mut E,
) -> Result<(), E::Error> {
if !context.serialized_expns.lock().contains(&expn) {
context.latest_expns.lock().insert(expn);
}
// Record the fact that we need to serialize the corresponding
// `ExpnData`
let needs_data = || {
if !context.serialized_expns.lock().contains(&expn) {
context.latest_expns.lock().insert(expn);
}
};

match mode {
ExpnDataEncodeMode::IncrComp => expn.0.encode(e),
ExpnDataEncodeMode::IncrComp => {
// Always serialize the `ExpnData` in incr comp mode
needs_data();
expn.0.encode(e)
}
ExpnDataEncodeMode::Metadata => {
let data = expn.expn_data();
// We only need to serialize the ExpnData
// if it comes from this crate.
// We currently don't serialize any hygiene information data for
// proc-macro crates: see the `SpecializedEncoder<Span>` impl
// for crate metadata.
if data.krate == LOCAL_CRATE {
needs_data();
}
data.orig_id.expect("Missing orig_id").encode(e)?;
data.krate.encode(e)
}
Expand Down