Commit Graph

16 Commits

Author SHA1 Message Date
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
Esteban Küber
692bc344d5 Make parse error suggestions verbose and fix spans
Go over all structured parser suggestions and make them verbose style.

When suggesting to add or remove delimiters, turn them into multiple suggestion parts.
2024-07-12 03:02:57 +00:00
León Orell Valerian Liehr
0ad3c5da72
Fix parse error message for meta items 2024-05-10 09:16:27 +02:00
Urgau
d4e26fbb53 compiletest: add enable-by-default check-cfg 2024-05-04 11:30:38 +02:00
Urgau
0c3f5cce89 Further cleanup cfgs in the UI test suite
This commit does three things:
 1. replaces (the last remaining) never true cfgs by the FALSE cfg
 2. fix derive-helper-configured.rs (typo in directive)
 3. and comment some current unused #[cfg_attr] (missing revisions)
2024-04-09 23:58:18 +02:00
Urgau
c4a97d9407 Unify all the always-false cfgs under the FALSE cfg 2024-04-07 01:16:45 +02:00
许杰友 Jieyou Xu (Joe)
ec2cc761bc
[AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
George-lewis
d56cdd48cb Bless tests
Update tests
2024-01-13 12:46:58 -05:00
Nilstrieb
41e8d152dc Show number in error message even for one error
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
Alex Macleod
5453a9f34d Add a note to duplicate diagnostics 2023-10-05 01:04:41 +00:00
许杰友 Jieyou Xu (Joe)
1faa95d289
Update UI tests which relied on old behavior of constructing a default error handler every time
`early_warn` is called

Skip `colored-session-opt-error.rs` on Windows hosts

This is very cursed as to why it fails on Windows CI specifically:

- The test emits a *warning*.
- *Warnings*, and only warnings *specifically*, have a different
  256-color between Windows and non-Windows hosts (other levels
  `set_intense(true)` unconditionally):

  e69c7306e2/compiler/rustc_errors/src/lib.rs (L1792-L1794)

Therefore, I added `// ignore-windows` test header to skip this test on
Windows (it's sufficient to test color is enabled on at least one
non-Windows host).
2023-06-29 23:31:25 +08:00
Eric Huss
a4e851cf62 Add some reasons why tests are ignored. 2023-04-15 16:11:42 -07:00
Ezra Shaw
35103fe8ab
error-msg: expand suggestion for unused lint 2023-03-15 23:30:12 +13:00
Michael Goulet
fded2e95ab Adjust tracking issue for non_lifetime_binders 2023-02-18 02:42:43 +00:00
Michael Goulet
262a344d72 Add feature gate for non_lifetime_binders 2023-02-16 03:39:58 +00:00
Albert Larsan
cf2dff2b1e
Move /src/test to /tests 2023-01-11 09:32:08 +00:00