diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-09-28 10:07:01 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-10-03 11:41:36 +1100 |
| commit | 3be86e6528db24fb055530ef93c93b2a9fc9ce90 (patch) | |
| tree | 4806e344296c430ea7c4c5160a56d14755eea71c | |
| parent | de692f1fae957fcfb0efb46db044a61261169963 (diff) | |
| download | rust-3be86e6528db24fb055530ef93c93b2a9fc9ce90.tar.gz rust-3be86e6528db24fb055530ef93c93b2a9fc9ce90.zip | |
Clarify operator splitting.
I found this code hard to read.
| -rw-r--r-- | compiler/rustc_expand/src/proc_macro_server.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index 59a7b668a83..ff09a9fb87a 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -110,10 +110,14 @@ impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec<TokenTree<TokenStre tokenstream::TokenTree::Token(token, spacing) => (token, spacing == Joint), }; + // Split the operator into one or more `Punct`s, one per character. + // The final one inherits the jointness of the original token. Any + // before that get `joint = true`. let mut op = |s: &str| { assert!(s.is_ascii()); - trees.extend(s.as_bytes().iter().enumerate().map(|(idx, &ch)| { - TokenTree::Punct(Punct { ch, joint: joint || idx != s.len() - 1, span }) + trees.extend(s.bytes().enumerate().map(|(idx, ch)| { + let is_final = idx == s.len() - 1; + TokenTree::Punct(Punct { ch, joint: if is_final { joint } else { true }, span }) })); }; |
