Skip to content

Commit ab7e555

Browse files
committed
Auto merge of rust-lang#99887 - nnethercote:rm-TreeAndSpacing, r=petrochenkov
Remove `TreeAndSpacing`. A `TokenStream` contains a `Lrc<Vec<(TokenTree, Spacing)>>`. But this is not quite right. `Spacing` makes sense for `TokenTree::Token`, but does not make sense for `TokenTree::Delimited`, because a `TokenTree::Delimited` cannot be joined with another `TokenTree`. This commit fixes this problem, by adding `Spacing` to `TokenTree::Token`, changing `TokenStream` to contain a `Lrc<Vec<TokenTree>>`, and removing the `TreeAndSpacing` typedef. The commit removes these two impls: - `impl From<TokenTree> for TokenStream` - `impl From<TokenTree> for TreeAndSpacing` These were useful, but also resulted in code with many `.into()` calls that was hard to read, particularly for anyone not highly familiar with the relevant types. This commit makes some other changes to compensate: - `TokenTree::token()` becomes `TokenTree::token_{alone,joint}()`. - `TokenStream::token_{alone,joint}()` are added. - `TokenStream::delimited` is added. This results in things like this: ```rust TokenTree::token(token::Semi, stmt.span).into() ``` changing to this: ```rust TokenStream::token_alone(token::Semi, stmt.span) ``` This makes the type of the result, and its spacing, clearer. These changes also simplifies `Cursor` and `CursorRef`, because they no longer need to distinguish between `next` and `next_with_spacing`. r? `@petrochenkov`
2 parents 61c6d16 + 1a6f02b commit ab7e555

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

clippy_lints/src/crate_in_macro_def.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ fn contains_unhygienic_crate_reference(tts: &TokenStream) -> Option<Span> {
110110

111111
fn is_crate_keyword(tt: &TokenTree) -> Option<Span> {
112112
if_chain! {
113-
if let TokenTree::Token(Token { kind: TokenKind::Ident(symbol, _), span }) = tt;
113+
if let TokenTree::Token(Token { kind: TokenKind::Ident(symbol, _), span }, _) = tt;
114114
if symbol.as_str() == "crate";
115115
then { Some(*span) } else { None }
116116
}
117117
}
118118

119119
fn is_token(tt: &TokenTree, kind: &TokenKind) -> bool {
120-
if let TokenTree::Token(Token { kind: other, .. }) = tt {
120+
if let TokenTree::Token(Token { kind: other, .. }, _) = tt {
121121
kind == other
122122
} else {
123123
false

0 commit comments

Comments
 (0)