rust/compiler/rustc_ast/src
bors 1202bbaf48 Auto merge of #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`
2022-07-30 14:50:05 +00:00
..
attr Remove TreeAndSpacing. 2022-07-29 15:52:15 +10:00
expand Make allocator_kind a query. 2021-06-20 11:52:51 +02:00
util Add do yeet expressions to allow experimentation in nightly 2022-04-30 17:40:27 -07:00
ast_traits.rs rustc_parse: Move AST -> TokenStream conversion logic to rustc_ast 2022-05-22 12:01:07 +03:00
ast.rs Add back expr size checks 2022-07-12 21:00:13 +04:00
entry.rs Fixup missing renames from #[main] to #[rustc_main] 2022-06-22 18:24:09 +02:00
lib.rs Stabilize let_chains 2022-07-16 20:17:58 -03:00
mut_visit.rs Remove TreeAndSpacing. 2022-07-29 15:52:15 +10:00
node_id.rs Use LocalExpnId where possible. 2021-07-17 19:41:02 +02:00
ptr.rs Use delayed error handling for Encodable and Encoder infallible. 2022-06-08 07:01:26 +10:00
token.rs Revert #96682. 2022-06-02 11:22:16 +10:00
tokenstream.rs Remove TreeAndSpacing. 2022-07-29 15:52:15 +10:00
visit.rs Remove visit_name from the AST visitor. 2022-07-29 15:28:32 +10:00