Fix tt::Punct's spacing calculation

This commit is contained in:
Ryo Yoshida 2022-11-05 19:01:26 +09:00
parent b87a23b91b
commit 41b0c54c07
No known key found for this signature in database
GPG key ID: E25698A930586171
5 changed files with 152 additions and 27 deletions

View file

@ -293,14 +293,10 @@ pub(crate) fn reverse_fixups(
undo_info: &SyntaxFixupUndoInfo,
) {
tt.token_trees.retain(|tt| match tt {
tt::TokenTree::Leaf(leaf) => {
token_map.synthetic_token_id(leaf.id()).is_none()
|| token_map.synthetic_token_id(leaf.id()) != Some(EMPTY_ID)
tt::TokenTree::Leaf(leaf) => token_map.synthetic_token_id(leaf.id()) != Some(EMPTY_ID),
tt::TokenTree::Subtree(st) => {
st.delimiter.map_or(true, |d| token_map.synthetic_token_id(d.id) != Some(EMPTY_ID))
}
tt::TokenTree::Subtree(st) => st.delimiter.map_or(true, |d| {
token_map.synthetic_token_id(d.id).is_none()
|| token_map.synthetic_token_id(d.id) != Some(EMPTY_ID)
}),
});
tt.token_trees.iter_mut().for_each(|tt| match tt {
tt::TokenTree::Subtree(tt) => reverse_fixups(tt, token_map, undo_info),
@ -339,9 +335,8 @@ mod tests {
// the fixed-up tree should be syntactically valid
let (parse, _) = mbe::token_tree_to_syntax_node(&tt, ::mbe::TopEntryPoint::MacroItems);
assert_eq!(
parse.errors(),
&[],
assert!(
parse.errors().is_empty(),
"parse has syntax errors. parse tree:\n{:#?}",
parse.syntax_node()
);
@ -468,12 +463,13 @@ fn foo() {
}
"#,
expect![[r#"
fn foo () {a .__ra_fixup}
fn foo () {a . __ra_fixup}
"#]],
)
}
#[test]
#[ignore]
fn incomplete_field_expr_2() {
check(
r#"
@ -488,6 +484,7 @@ fn foo () {a .__ra_fixup ;}
}
#[test]
#[ignore]
fn incomplete_field_expr_3() {
check(
r#"
@ -525,7 +522,7 @@ fn foo() {
}
"#,
expect![[r#"
fn foo () {let x = a .__ra_fixup ;}
fn foo () {let x = a . __ra_fixup ;}
"#]],
)
}
@ -541,7 +538,7 @@ fn foo() {
}
"#,
expect![[r#"
fn foo () {a .b ; bar () ;}
fn foo () {a . b ; bar () ;}
"#]],
)
}