os-rust/tests
Nicholas Nethercote 1ae521e9d5 Return earlier in some cases in collect_token.
This example triggers an assertion failure:
```
fn f() -> u32 {
    #[cfg_eval] #[cfg(not(FALSE))] 0
}
```
The sequence of events:
- `configure_annotatable` calls `parse_expr_force_collect`, which calls
  `collect_tokens`.
- Within that, we end up in `parse_expr_dot_or_call`, which again calls
  `collect_tokens`.
  - The return value of the `f` call is the expression `0`.
  - This inner call collects tokens for `0` (parser range 10..11) and
    creates a replacement covering `#[cfg(not(FALSE))] 0` (parser range
    0..11).
- We return to the outer `collect_tokens` call. The return value of the
  `f` call is *again* the expression `0`, again with the range 10..11,
  but the replacement from earlier covers the range 0..11. The code
  mistakenly assumes that any attributes from an inner `collect_tokens`
  call fit entirely within the body of the result of an outer
  `collect_tokens` call. So it adjusts the replacement parser range
  0..11 to a node range by subtracting 10, resulting in -10..1. This is
  an invalid range and triggers an assertion failure.

It's tricky to follow, but basically things get complicated when an AST
node is returned from an inner `collect_tokens` call and then returned
again from an outer `collect_token` node without being wrapped in any
kind of additional layer.

This commit changes `collect_tokens` to return early in some extra cases,
avoiding the construction of lazy tokens. In the example above, the
outer `collect_tokens` returns earlier because the `0` token already has
tokens and `self.capture_state.capturing` is `Capturing::No`. This early
return avoids the creation of the invalid range and the assertion
failure.

Fixes #129166. Note: these invalid ranges have been happening for a long
time. #128725 looks like it's at fault only because it introduced the
assertion that catches the invalid ranges.
2024-08-23 14:40:08 +10:00
..
assembly Rollup merge of #127905 - BKPepe:powerpc-muslspe, r=wesleywiser 2024-08-15 00:02:24 +02:00
auxiliary
codegen Don't generate functions with the rustc_intrinsic_must_be_overridden attribute 2024-08-19 06:26:52 +08:00
codegen-units Fix and enable disabled codegen-units tests 2024-08-10 14:03:27 -04:00
coverage Finish blessing coverage/mcdc tests after LLVM 19 upgrade 2024-08-01 13:36:50 +10:00
coverage-run-rustdoc coverage: Extract hole spans from HIR instead of MIR 2024-07-08 21:22:56 +10:00
crashes Return earlier in some cases in collect_token. 2024-08-23 14:40:08 +10:00
debuginfo Rollup merge of #128627 - khuey:DUMMY_SP-line-no, r=nnethercote 2024-08-21 18:15:01 +02:00
incremental Do not normalize constants eagerly. 2024-07-31 00:59:12 +00:00
mir-opt Auto merge of #122551 - RayMuir:copy_fmt, r=saethlin 2024-08-19 23:10:46 +00:00
pretty stabilize raw_ref_op 2024-08-18 19:46:53 +02:00
run-make Auto merge of #129227 - jieyouxu:no-dumping, r=Kobzol 2024-08-18 09:47:46 +00:00
run-pass-valgrind rustfmt tests/run-pass-valgrind/. 2024-06-04 09:53:02 +10:00
rustdoc Stabilize opaque type precise capturing 2024-08-17 12:33:29 -04:00
rustdoc-gui Rollup merge of #128394 - GuillaumeGomez:run-button, r=t-rustdoc 2024-08-12 17:09:15 +02:00
rustdoc-js Add test for Self not being a generic in search index 2024-08-04 12:49:28 -07:00
rustdoc-js-std Update tests 2024-06-07 11:55:52 +08:00
rustdoc-json Stabilize opaque type precise capturing 2024-08-17 12:33:29 -04:00
rustdoc-ui Adjust expected errors for a rustdoc test 2024-08-18 22:52:54 -05:00
ui Return earlier in some cases in collect_token. 2024-08-23 14:40:08 +10:00
ui-fulldeps Bless test fallout 2024-08-03 07:57:31 -04:00
COMPILER_TESTS.md