hygiene: Update $crate
pretty-printing to account for holes in syntax contexts
This commit is contained in:
parent
6e1effe948
commit
07328d5d40
1 changed files with 15 additions and 14 deletions
|
@ -653,25 +653,26 @@ pub fn walk_chain_collapsed(span: Span, to: Span) -> Span {
|
||||||
|
|
||||||
pub fn update_dollar_crate_names(mut get_name: impl FnMut(SyntaxContext) -> Symbol) {
|
pub fn update_dollar_crate_names(mut get_name: impl FnMut(SyntaxContext) -> Symbol) {
|
||||||
// The new contexts that need updating are at the end of the list and have `$crate` as a name.
|
// The new contexts that need updating are at the end of the list and have `$crate` as a name.
|
||||||
let (len, to_update) = HygieneData::with(|data| {
|
// Also decoding placeholders can be encountered among both old and new contexts.
|
||||||
(
|
let mut to_update = vec![];
|
||||||
data.syntax_context_data.len(),
|
HygieneData::with(|data| {
|
||||||
data.syntax_context_data
|
for (idx, scdata) in data.syntax_context_data.iter().enumerate().rev() {
|
||||||
.iter()
|
if scdata.dollar_crate_name == kw::DollarCrate {
|
||||||
.rev()
|
to_update.push((idx, kw::DollarCrate));
|
||||||
.take_while(|scdata| scdata.dollar_crate_name == kw::DollarCrate)
|
} else if !scdata.is_decode_placeholder() {
|
||||||
.count(),
|
break;
|
||||||
)
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// The callback must be called from outside of the `HygieneData` lock,
|
// The callback must be called from outside of the `HygieneData` lock,
|
||||||
// since it will try to acquire it too.
|
// since it will try to acquire it too.
|
||||||
let range_to_update = len - to_update..len;
|
for (idx, name) in &mut to_update {
|
||||||
let names: Vec<_> =
|
*name = get_name(SyntaxContext::from_usize(*idx));
|
||||||
range_to_update.clone().map(|idx| get_name(SyntaxContext::from_u32(idx as u32))).collect();
|
}
|
||||||
HygieneData::with(|data| {
|
HygieneData::with(|data| {
|
||||||
range_to_update.zip(names).for_each(|(idx, name)| {
|
for (idx, name) in to_update {
|
||||||
data.syntax_context_data[idx].dollar_crate_name = name;
|
data.syntax_context_data[idx].dollar_crate_name = name;
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue