Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b62bbea

Browse files
committedMar 14, 2025
hygiene: Update $crate pretty-printing to account for holes in syntax contexts
1 parent 3a97e6f commit b62bbea

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed
 

‎compiler/rustc_span/src/hygiene.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -653,25 +653,26 @@ pub fn walk_chain_collapsed(span: Span, to: Span) -> Span {
653653

654654
pub fn update_dollar_crate_names(mut get_name: impl FnMut(SyntaxContext) -> Symbol) {
655655
// The new contexts that need updating are at the end of the list and have `$crate` as a name.
656-
let (len, to_update) = HygieneData::with(|data| {
657-
(
658-
data.syntax_context_data.len(),
659-
data.syntax_context_data
660-
.iter()
661-
.rev()
662-
.take_while(|scdata| scdata.dollar_crate_name == kw::DollarCrate)
663-
.count(),
664-
)
656+
// Also decoding placeholders can be encountered among both old and new contexts.
657+
let mut to_update = vec![];
658+
HygieneData::with(|data| {
659+
for (idx, scdata) in data.syntax_context_data.iter().enumerate().rev() {
660+
if scdata.dollar_crate_name == kw::DollarCrate {
661+
to_update.push((idx, kw::DollarCrate));
662+
} else if !scdata.is_decode_placeholder() {
663+
break;
664+
}
665+
}
665666
});
666667
// The callback must be called from outside of the `HygieneData` lock,
667668
// since it will try to acquire it too.
668-
let range_to_update = len - to_update..len;
669-
let names: Vec<_> =
670-
range_to_update.clone().map(|idx| get_name(SyntaxContext::from_u32(idx as u32))).collect();
669+
for (idx, name) in &mut to_update {
670+
*name = get_name(SyntaxContext::from_usize(*idx));
671+
}
671672
HygieneData::with(|data| {
672-
range_to_update.zip(names).for_each(|(idx, name)| {
673+
for (idx, name) in to_update {
673674
data.syntax_context_data[idx].dollar_crate_name = name;
674-
})
675+
}
675676
})
676677
}
677678

0 commit comments

Comments
 (0)
Failed to load comments.