rust/tests
Matthias Krüger 20480075bd
Rollup merge of #128623 - jieyouxu:check-attr-ice, r=nnethercote
Do not fire unhandled attribute assertion on multi-segment `AttributeType::Normal` attributes with builtin attribute as first segment

### The Problem

In #128581 I introduced an assertion to check that all builtin attributes are actually checked via
`CheckAttrVisitor` and aren't accidentally usable on completely unrelated HIR nodes.
Unfortunately, the assertion had correctness problems as revealed in #128622.

The match on attribute path segments looked like

```rs,ignore
// Normal handler
[sym::should_panic] => /* check is implemented */
// Fallback handler
[name, ..] => match BUILTIN_ATTRIBUTE_MAP.get(name) {
    // checked below
    Some(BuiltinAttribute { type_: AttributeType::CrateLevel, .. }) => {}
    Some(_) => {
        if !name.as_str().starts_with("rustc_") {
            span_bug!(
                attr.span,
                "builtin attribute {name:?} not handled by `CheckAttrVisitor`"
            )
        }
    }
    None => (),
}
```

However, it failed to account for edge cases such as an attribute whose:

1. path segments *starts* with a segment matching the name of a builtin attribute such as `should_panic`, and
2. the first segment's symbol does not start with `rustc_`, and
3. the matched builtin attribute is also of `AttributeType::Normal` attribute type upon registration with the builtin attribute map.

These conditions when all satisfied cause the span bug to be issued for e.g.
`#[should_panic::skip]` because the `[sym::should_panic]` arm is not matched (since it's
`[sym::should_panic, sym::skip]`).

### Proposed Solution

This PR tries to remedy that by adjusting all normal/specific handlers to not match exactly on a single segment, but instead match a prefix segment.

i.e.

```rs,ignore
// Normal handler, notice the `, ..` rest pattern
[sym::should_panic, ..] => /* check is implemented */
// Fallback handler
[name, ..] => match BUILTIN_ATTRIBUTE_MAP.get(name) {
    // checked below
    Some(BuiltinAttribute { type_: AttributeType::CrateLevel, .. }) => {}
    Some(_) => {
        if !name.as_str().starts_with("rustc_") {
            span_bug!(
                attr.span,
                "builtin attribute {name:?} not handled by `CheckAttrVisitor`"
            )
        }
    }
    None => (),
}
```

### Review Remarks

This PR contains 2 commits:

1. The first commit adds a regression test. This will ICE without the `CheckAttrVisitor` changes.
2. The second commit adjusts `CheckAttrVisitor` assertion logic. Once this commit is applied, the test should no longer ICE and produce the expected bless stderr.

Fixes #128622.

r? ``@nnethercote`` (since you reviewed #128581)
2024-08-05 05:40:21 +02:00
..
assembly Match LLVM ABI in extern "C" functions for f128 on Windows 2024-07-30 20:23:33 +01:00
auxiliary
codegen Rollup merge of #128500 - clubby789:122600-test, r=Mark-Simulacrum 2024-08-05 05:40:21 +02:00
codegen-units Revert "Rollup merge of #125572 - mu001999-contrib:dead/enhance, r=pnkfelix" 2024-08-03 07:57:31 -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 Auto merge of #127513 - nikic:llvm-19, r=cuviper 2024-07-31 12:56:46 +00:00
debuginfo Add Natvis visualiser and debuginfo tests for f16 2024-07-09 03:47:50 +01:00
incremental Do not normalize constants eagerly. 2024-07-31 00:59:12 +00:00
mir-opt Re-enable SimplifyToExp in match_branches. 2024-08-03 10:55:46 +08:00
pretty Mark format! with must_use hint 2024-07-06 14:24:20 +02:00
run-make Ensure Rustc::print use in rmake tests 2024-08-03 22:36:08 -04:00
run-pass-valgrind
rustdoc Rollup merge of #127921 - spastorino:stabilize-unsafe-extern-blocks, r=compiler-errors 2024-08-03 20:51:51 +02:00
rustdoc-gui Rollup merge of #128339 - GuillaumeGomez:click-code-example, r=notriddle 2024-07-30 04:31:55 +02:00
rustdoc-js rustdoc-search: use lowercase, non-normalized name for type search 2024-06-09 11:56:52 -07:00
rustdoc-js-std Update tests 2024-06-07 11:55:52 +08:00
rustdoc-json rustdoc: Add test for impl_trait_in_accos_type 2024-08-01 15:48:22 +00:00
rustdoc-ui Structured suggestion for extern crate foo when foo isn't resolved in import 2024-07-29 23:49:51 +00:00
ui Rollup merge of #128623 - jieyouxu:check-attr-ice, r=nnethercote 2024-08-05 05:40:21 +02:00
ui-fulldeps Bless test fallout 2024-08-03 07:57:31 -04:00
COMPILER_TESTS.md