rust/compiler/rustc_builtin_macros/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
..
assert Remove TreeAndSpacing. 2022-07-29 15:52:15 +10:00
deriving Don't add attribute to allow unused-qualifications to derive impl's 2022-07-18 22:28:17 -04:00
format_foreign update tests 2021-12-31 12:51:27 -05:00
asm.rs Generate correct suggestion with named arguments used positionally 2022-07-25 00:00:27 -06:00
assert.rs remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
cfg_accessible.rs Remove crate visibility usage in compiler 2022-05-20 20:04:54 -04:00
cfg_eval.rs rustc_parse: Move AST -> TokenStream conversion logic to rustc_ast 2022-05-22 12:01:07 +03:00
cfg.rs macros: use typed identifiers in diag derive 2022-06-24 09:08:25 +01:00
cmdline_attrs.rs Unconditionally capture tokens for attributes. 2020-10-21 18:57:29 -04:00
compile_error.rs check_doc_keyword: don't alloc string for emptiness check 2022-04-08 11:45:57 +03:00
concat_bytes.rs Adopt let else in more places 2022-02-19 17:27:43 +01:00
concat_idents.rs Remove TreeAndSpacing. 2022-07-29 15:52:15 +10:00
concat.rs Adopt let else in more places 2022-02-19 17:27:43 +01:00
derive.rs remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
edition_panic.rs Spellchecking some comments 2022-03-30 01:39:38 -04:00
env.rs check_doc_keyword: don't alloc string for emptiness check 2022-04-08 11:45:57 +03:00
format_foreign.rs [rustc_builtin_macros] add indices to format_foreign::printf::Substitution::Escape 2021-12-31 12:42:15 -05:00
format.rs Use more idiomatic rust, comment for lint logic 2022-07-28 00:10:19 -06:00
global_allocator.rs Point at type when a static #[global_allocator] doesn't impl GlobalAlloc 2021-12-15 01:40:08 +00:00
lib.rs Stabilize let_chains 2022-07-16 20:17:58 -03:00
log_syntax.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
proc_macro_harness.rs Rename some ExtCtxt methods. 2022-06-23 11:10:43 +10:00
source_util.rs Add support for a new attribute #[debugger_visualizer] to support embedding debugger visualizers into a generated PDB. 2022-05-03 10:53:54 -07:00
standard_library_imports.rs Create 2024 edition 2022-04-02 02:45:49 -04:00
test_harness.rs Rename debugging_opts to unstable_opts 2022-07-13 17:47:06 -05:00
test.rs remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
trace_macros.rs Remove TreeAndSpacing. 2022-07-29 15:52:15 +10:00
util.rs Add a lint for duplicated attributes. 2021-12-15 23:43:13 +01:00