Skip to content

Commit 850c321

Browse files
committed
Move jointness censoring to proc_macro
Proc-macro API currently exposes jointness in `Punct` tokens. That is, `+` in `+one` is **non** joint. Our lexer produces jointness info for all tokens, so we need to censor it *somewhere* Previously we did this in a lexer, but it makes more sense to do this in a proc-macro server.
1 parent 08deb86 commit 850c321

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

compiler/rustc_expand/src/proc_macro_server.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,21 @@ impl ToInternal<token::DelimToken> for Delimiter {
4747
}
4848
}
4949

50-
impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
50+
impl FromInternal<(TreeAndJoint, Option<tokenstream::TokenTree>, &'_ ParseSess, &'_ mut Vec<Self>)>
5151
for TokenTree<Group, Punct, Ident, Literal>
5252
{
5353
fn from_internal(
54-
((tree, is_joint), sess, stack): (TreeAndJoint, &ParseSess, &mut Vec<Self>),
54+
((tree, is_joint), look_ahead, sess, stack): (
55+
TreeAndJoint,
56+
Option<tokenstream::TokenTree>,
57+
&ParseSess,
58+
&mut Vec<Self>,
59+
),
5560
) -> Self {
5661
use rustc_ast::token::*;
5762

58-
let joint = is_joint == Joint;
63+
let joint = is_joint == Joint
64+
&& matches!(look_ahead, Some(tokenstream::TokenTree::Token(t)) if t.is_op());
5965
let Token { kind, span } = match tree {
6066
tokenstream::TokenTree::Delimited(span, delim, tts) => {
6167
let delimiter = Delimiter::from_internal(delim);
@@ -445,7 +451,8 @@ impl server::TokenStreamIter for Rustc<'_> {
445451
loop {
446452
let tree = iter.stack.pop().or_else(|| {
447453
let next = iter.cursor.next_with_joint()?;
448-
Some(TokenTree::from_internal((next, self.sess, &mut iter.stack)))
454+
let lookahead = iter.cursor.look_ahead(0);
455+
Some(TokenTree::from_internal((next, lookahead, self.sess, &mut iter.stack)))
449456
})?;
450457
// A hack used to pass AST fragments to attribute and derive macros
451458
// as a single nonterminal token instead of a token stream.

compiler/rustc_parse/src/lexer/tokentrees.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,7 @@ impl<'a> TokenTreesReader<'a> {
262262
}
263263
_ => {
264264
let tt = TokenTree::Token(self.token.take());
265-
let mut is_joint = self.bump();
266-
if !self.token.is_op() {
267-
is_joint = NonJoint;
268-
}
265+
let is_joint = self.bump();
269266
Ok((tt, is_joint))
270267
}
271268
}

0 commit comments

Comments
 (0)