Commit af72f7a
committed
Remove
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`.TreeAndSpacing.1 parent f026688 commit af72f7a
1 file changed
+61
-37
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
682 | 682 | | |
683 | 683 | | |
684 | 684 | | |
685 | | - | |
| 685 | + | |
686 | 686 | | |
687 | 687 | | |
688 | 688 | | |
| |||
737 | 737 | | |
738 | 738 | | |
739 | 739 | | |
740 | | - | |
741 | | - | |
742 | | - | |
743 | | - | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
744 | 747 | | |
745 | 748 | | |
746 | 749 | | |
| |||
777 | 780 | | |
778 | 781 | | |
779 | 782 | | |
780 | | - | |
781 | | - | |
782 | | - | |
783 | | - | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | | - | |
791 | | - | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
792 | 804 | | |
793 | 805 | | |
794 | | - | |
| 806 | + | |
795 | 807 | | |
796 | 808 | | |
797 | 809 | | |
| |||
859 | 871 | | |
860 | 872 | | |
861 | 873 | | |
862 | | - | |
863 | | - | |
864 | | - | |
865 | | - | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
866 | 881 | | |
867 | 882 | | |
868 | 883 | | |
| |||
875 | 890 | | |
876 | 891 | | |
877 | 892 | | |
878 | | - | |
879 | | - | |
880 | | - | |
881 | | - | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
882 | 900 | | |
883 | 901 | | |
884 | | - | |
| 902 | + | |
885 | 903 | | |
886 | 904 | | |
887 | 905 | | |
| |||
1123 | 1141 | | |
1124 | 1142 | | |
1125 | 1143 | | |
1126 | | - | |
| 1144 | + | |
1127 | 1145 | | |
1128 | | - | |
1129 | | - | |
1130 | | - | |
1131 | | - | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
1132 | 1153 | | |
1133 | 1154 | | |
1134 | 1155 | | |
| |||
1147 | 1168 | | |
1148 | 1169 | | |
1149 | 1170 | | |
1150 | | - | |
1151 | | - | |
1152 | | - | |
1153 | | - | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
1154 | 1178 | | |
1155 | 1179 | | |
1156 | 1180 | | |
| |||
0 commit comments