Skip to content

Commit 3be86e6

Browse files
committed
Clarify operator splitting.
I found this code hard to read.
1 parent de692f1 commit 3be86e6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

compiler/rustc_expand/src/proc_macro_server.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,14 @@ impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec<TokenTree<TokenStre
110110
tokenstream::TokenTree::Token(token, spacing) => (token, spacing == Joint),
111111
};
112112

113+
// Split the operator into one or more `Punct`s, one per character.
114+
// The final one inherits the jointness of the original token. Any
115+
// before that get `joint = true`.
113116
let mut op = |s: &str| {
114117
assert!(s.is_ascii());
115-
trees.extend(s.as_bytes().iter().enumerate().map(|(idx, &ch)| {
116-
TokenTree::Punct(Punct { ch, joint: joint || idx != s.len() - 1, span })
118+
trees.extend(s.bytes().enumerate().map(|(idx, ch)| {
119+
let is_final = idx == s.len() - 1;
120+
TokenTree::Punct(Punct { ch, joint: if is_final { joint } else { true }, span })
117121
}));
118122
};
119123

0 commit comments

Comments
 (0)