1
Fork 0
rust/compiler/rustc_passes/src
许杰友 Jieyou Xu (Joe) 9d0eaa2ad7 check_attr: cover multi-segment attributes on specific check arms
PR #128581 introduced an assertion that all builtin attributes are
actually checked via `CheckAttrVisitor` and aren't accidentally usable
on completely unrelated HIR nodes. Unfortunately, the check had
correctness problems.

The match on attribute path segments looked like

```rust,ignore
[sym::should_panic] => /* check is implemented */
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 builtin attribute such as
   `should_panic`
2. which does not start with `rustc_`, and
3. is also an `AttributeType::Normal` attribute 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]`).

See <https://github.com/rust-lang/rust/issues/128622>.
2024-08-04 01:50:55 +00:00
..
liveness Reformat use declarations. 2024-07-29 08:26:52 +10:00
abi_test.rs Instance::resolve -> Instance::try_resolve, and other nits 2024-07-02 17:28:03 -04:00
check_attr.rs check_attr: cover multi-segment attributes on specific check arms 2024-08-04 01:50:55 +00:00
check_const.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
dead.rs Revert "Rollup merge of #125572 - mu001999-contrib:dead/enhance, r=pnkfelix" 2024-08-03 07:57:31 -04:00
debugger_visualizer.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
diagnostic_items.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
entry.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
errors.rs Assert that all attributes are actually checked via CheckAttrVisitor and aren't accidentally usable on completely unrelated HIR nodes 2024-08-03 02:26:21 +00:00
hir_id_validator.rs Actually create ranged int types in the type system. 2024-04-08 12:02:19 +00:00
hir_stats.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
lang_items.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
layout_test.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
lib.rs Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
lib_features.rs Remove Session methods that duplicate DiagCtxt methods. 2023-12-24 08:05:28 +11:00
liveness.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
loops.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
naked_functions.rs Rollup merge of #127853 - folkertdev:naked-function-error-messages, r=bjorn3 2024-07-28 08:57:16 +02:00
reachable.rs Miri function identity hack: account for possible inlining 2024-07-02 21:05:30 +02:00
stability.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
upvars.rs Make body_owned_by return the body directly. 2024-05-29 10:04:08 +00:00
weak_lang_items.rs Revert "Rollup merge of #124976 - petrochenkov:usedcrates, r=oli-obk" 2024-06-06 10:06:28 +00:00