rust/tests/ui/hygiene
Nicholas Nethercote 925f7fad57 Improve print_tts by changing tokenstream::Spacing.
`tokenstream::Spacing` appears on all `TokenTree::Token` instances,
both punct and non-punct. Its current usage:
- `Joint` means "can join with the next token *and* that token is a
  punct".
- `Alone` means "cannot join with the next token *or* can join with the
  next token but that token is not a punct".

The fact that `Alone` is used for two different cases is awkward.
This commit augments `tokenstream::Spacing` with a new variant
`JointHidden`, resulting in:
- `Joint` means "can join with the next token *and* that token is a
  punct".
- `JointHidden` means "can join with the next token *and* that token is a
  not a punct".
- `Alone` means "cannot join with the next token".

This *drastically* improves the output of `print_tts`. For example,
this:
```
stringify!(let a: Vec<u32> = vec![];)
```
currently produces this string:
```
let a : Vec < u32 > = vec! [] ;
```
With this PR, it now produces this string:
```
let a: Vec<u32> = vec![] ;
```
(The space after the `]` is because `TokenTree::Delimited` currently
doesn't have spacing information. The subsequent commit fixes this.)

The new `print_tts` doesn't replicate original code perfectly. E.g.
multiple space characters will be condensed into a single space
character. But it's much improved.

`print_tts` still produces the old, uglier output for code produced by
proc macros. Because we have to translate the generated code from
`proc_macro::Spacing` to the more expressive `token::Spacing`, which
results in too much `proc_macro::Along` usage and no
`proc_macro::JointHidden` usage. So `space_between` still exists and
is used by `print_tts` in conjunction with the `Spacing` field.

This change will also help with the removal of `Token::Interpolated`.
Currently interpolated tokens are pretty-printed nicely via AST pretty
printing. `Token::Interpolated` removal will mean they get printed with
`print_tts`. Without this change, that would result in much uglier
output for code produced by decl macro expansions. With this change, AST
pretty printing and `print_tts` produce similar results.

The commit also tweaks the comments on `proc_macro::Spacing`. In
particular, it refers to "compound tokens" rather than "multi-char
operators" because lifetimes aren't operators.
2023-12-11 09:19:09 +11:00
..
auxiliary remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
arguments.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
arguments.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
assoc_item_ctxt.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
assoc_item_ctxt.stderr remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
assoc_ty_bindings.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
cross-crate-codegen-attrs.rs
cross-crate-define-and-use.rs
cross-crate-fields.rs
cross-crate-glob-hygiene.rs
cross-crate-glob-hygiene.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
cross-crate-methods.rs
cross-crate-name-collision.rs
cross-crate-name-hiding-2.rs
cross-crate-name-hiding-2.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
cross-crate-name-hiding.rs
cross-crate-name-hiding.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
cross-crate-redefine.rs
cross-crate-redefine.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
cross-crate-variants.rs
dollar-crate-modern.rs
duplicate_lifetimes.rs
duplicate_lifetimes.stderr
eager-from-opaque-2.rs
eager-from-opaque.rs
expansion-info-reset.rs
expansion-info-reset.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
extern-prelude-from-opaque-fail-2018.rs Add filter with next segment while lookup typo for path 2023-07-07 09:00:50 +08:00
extern-prelude-from-opaque-fail-2018.stderr When encountering struct fn call literal with private fields, suggest all builders 2023-11-19 17:47:41 +00:00
extern-prelude-from-opaque-fail.rs Add filter with next segment while lookup typo for path 2023-07-07 09:00:50 +08:00
extern-prelude-from-opaque-fail.stderr adjust smart_resolve_partial_mod_path_errors 2023-07-07 10:19:30 +08:00
fields-definition.rs
fields-definition.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
fields-move.rs
fields-move.stderr
fields-numeric-borrowck.rs
fields-numeric-borrowck.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
fields.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
fields.stderr remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
for-loop.rs
for-loop.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
format-args.rs
generate-mod.rs
generate-mod.stderr
generic_params.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
globs.rs
globs.stderr Special-case item attributes in the suggestion output 2023-04-12 22:50:10 +00:00
hir-res-hygiene.rs
hygiene-dodging-1.rs
hygiene.rs
hygienic-label-1.rs
hygienic-label-1.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
hygienic-label-2.rs
hygienic-label-2.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
hygienic-label-3.rs
hygienic-label-3.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
hygienic-label-4.rs
hygienic-label-4.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
hygienic-labels-in-let.rs
hygienic-labels.rs
impl_items-2.rs
impl_items-2.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
impl_items.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
impl_items.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
intercrate.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
intercrate.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-15221.rs
issue-32922.rs
issue-40847.rs
issue-44128.rs
issue-47311.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
issue-47312.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
issue-61574-const-parameters.rs
issue-77523-def-site-async-await.rs
items.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
lambda-var-hygiene.rs
legacy_interaction.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
lexical.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
local_inner_macros.rs
macro-metavars-legacy.rs
macro-metavars-transparent.rs
missing-self-diag.rs
missing-self-diag.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
nested_macro_privacy.rs
nested_macro_privacy.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
nested-dollar-crate.rs
no_implicit_prelude-2018.rs
no_implicit_prelude-2018.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
no_implicit_prelude-2021.rs
no_implicit_prelude.rs
no_implicit_prelude.stderr Special-case item attributes in the suggestion output 2023-04-12 22:50:10 +00:00
panic-location.rs
panic-location.run.stderr Hint optimizer about reserved capacity 2023-11-02 00:52:06 +00:00
pattern-macro.rs
pattern-macro.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
prelude-import-hygiene.rs
privacy-early.rs
privacy-early.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
privacy.rs
privacy.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
rustc-macro-transparency.rs
rustc-macro-transparency.stderr
specialization.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
stdlib-prelude-from-opaque-early.rs
stdlib-prelude-from-opaque-late.rs Rename drop_copy lint to dropping_copy_types 2023-05-21 13:37:32 +02:00
thread-local-not-in-prelude.rs
trait_items-2.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
trait_items.rs
trait_items.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
traits-in-scope.rs
transparent-basic.rs
unpretty-debug.rs
unpretty-debug.stdout Improve print_tts by changing tokenstream::Spacing. 2023-12-11 09:19:09 +11:00
wrap_unhygienic_example.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
xcrate.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00