Skip to content

Commit fdff7de

Browse files
committed
Revert "Rollup merge of rust-lang#76285 - matklad:censor-spacing, r=petrochenkov"
This reverts commit 85cee57, reversing changes made to b4d3873.
1 parent 97eb606 commit fdff7de

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

compiler/rustc_ast/src/tokenstream.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ impl Cursor {
403403
self.index = index;
404404
}
405405

406-
pub fn look_ahead(&self, n: usize) -> Option<&TokenTree> {
407-
self.stream.0[self.index..].get(n).map(|(tree, _)| tree)
406+
pub fn look_ahead(&self, n: usize) -> Option<TokenTree> {
407+
self.stream.0[self.index..].get(n).map(|(tree, _)| tree.clone())
408408
}
409409
}
410410

compiler/rustc_expand/src/proc_macro_server.rs

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

50-
impl
51-
FromInternal<(
52-
TreeAndJoint,
53-
Option<&'_ tokenstream::TokenTree>,
54-
&'_ ParseSess,
55-
&'_ mut Vec<Self>,
56-
)> for TokenTree<Group, Punct, Ident, Literal>
50+
impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
51+
for TokenTree<Group, Punct, Ident, Literal>
5752
{
5853
fn from_internal(
59-
((tree, is_joint), look_ahead, sess, stack): (
60-
TreeAndJoint,
61-
Option<&tokenstream::TokenTree>,
62-
&ParseSess,
63-
&mut Vec<Self>,
64-
),
54+
((tree, is_joint), sess, stack): (TreeAndJoint, &ParseSess, &mut Vec<Self>),
6555
) -> Self {
6656
use rustc_ast::token::*;
6757

68-
let joint = is_joint == Joint
69-
&& matches!(look_ahead, Some(tokenstream::TokenTree::Token(t)) if t.is_op());
58+
let joint = is_joint == Joint;
7059
let Token { kind, span } = match tree {
7160
tokenstream::TokenTree::Delimited(span, delim, tts) => {
7261
let delimiter = Delimiter::from_internal(delim);
@@ -456,8 +445,7 @@ impl server::TokenStreamIter for Rustc<'_> {
456445
loop {
457446
let tree = iter.stack.pop().or_else(|| {
458447
let next = iter.cursor.next_with_joint()?;
459-
let lookahead = iter.cursor.look_ahead(0);
460-
Some(TokenTree::from_internal((next, lookahead, self.sess, &mut iter.stack)))
448+
Some(TokenTree::from_internal((next, self.sess, &mut iter.stack)))
461449
})?;
462450
// A hack used to pass AST fragments to attribute and derive macros
463451
// as a single nonterminal token instead of a token stream.

compiler/rustc_parse/src/lexer/tokentrees.rs

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

compiler/rustc_parse/src/parser/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -822,15 +822,15 @@ impl<'a> Parser<'a> {
822822
}
823823

824824
let frame = &self.token_cursor.frame;
825-
match frame.tree_cursor.look_ahead(dist - 1) {
825+
looker(&match frame.tree_cursor.look_ahead(dist - 1) {
826826
Some(tree) => match tree {
827-
TokenTree::Token(token) => looker(token),
827+
TokenTree::Token(token) => token,
828828
TokenTree::Delimited(dspan, delim, _) => {
829-
looker(&Token::new(token::OpenDelim(delim.clone()), dspan.open))
829+
Token::new(token::OpenDelim(delim), dspan.open)
830830
}
831831
},
832-
None => looker(&Token::new(token::CloseDelim(frame.delim), frame.span.close)),
833-
}
832+
None => Token::new(token::CloseDelim(frame.delim), frame.span.close),
833+
})
834834
}
835835

836836
/// Returns whether any of the given keywords are `dist` tokens ahead of the current one.

0 commit comments

Comments
 (0)