rust/compiler/rustc_passes/src
bors 11d96b5930 Auto merge of #107257 - inquisitivecrystal:ffi-attr, r=davidtwco
Strengthen validation of FFI attributes

Previously, `codegen_attrs` validated the attributes `#[ffi_pure]`, `#[ffi_const]`, and `#[ffi_returns_twice]` to make sure that they were only used on foreign functions. However, this validation was insufficient in two ways:

1. `codegen_attrs` only sees items for which code must be generated, so it was unable to raise errors when the attribute was incorrectly applied to macros and the like.
2. the validation code only checked that the item with the attr was foreign, but not that it was a foreign function, allowing these attributes to be applied to foreign statics as well.

This PR moves the validation to `check_attr`, which sees all items. It additionally changes the validation to ensure that the attribute's target is `Target::ForeignFunction`, only allowing the attributes on foreign functions and not foreign statics. Because these attributes are unstable, there is no risk for backwards compatibility. The changes also ending up making the code much easier to read.

This PR is best reviewed commit by commit. Additionally, I was considering moving the tests to the `attribute` subdirectory, to get them out of the general UI directory. I could do that as part of this PR or a follow-up, as the reviewer prefers.

CC: #58328, #58329
2023-02-01 11:37:24 +00:00
..
liveness Use iter::zip in compiler/ 2021-03-26 09:32:31 -07:00
check_attr.rs Auto merge of #107257 - inquisitivecrystal:ffi-attr, r=davidtwco 2023-02-01 11:37:24 +00:00
check_const.rs session: diagnostic migration lint on more fns 2023-01-30 17:11:35 +00:00
dead.rs Consider #[allow(dead_code)] before lang items 2023-01-30 10:54:33 +00:00
debugger_visualizer.rs rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00
diagnostic_items.rs rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00
entry.rs Move compiler input and ouput paths into session 2023-01-16 14:46:44 +00:00
errors.rs Auto merge of #107257 - inquisitivecrystal:ffi-attr, r=davidtwco 2023-02-01 11:37:24 +00:00
hir_id_validator.rs Verify that HIR parenting and Def parenting match. 2022-11-26 17:28:59 +00:00
hir_stats.rs Take a LocalDefId in hir::Visitor::visit_fn. 2023-01-28 09:51:50 +00:00
lang_items.rs Remove HirId -> LocalDefId map from HIR. 2023-01-28 09:55:26 +00:00
layout_test.rs rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00
lib.rs Lint against usages of struct_span_lint_hir. 2022-10-29 18:03:47 +08:00
lib_features.rs fix: don't emit E0711 if staged_api not enabled 2023-01-14 22:04:42 +13:00
liveness.rs Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
loops.rs Specify that break cannot be used outside of loop *or* labeled block 2022-11-05 01:12:58 +00:00
naked_functions.rs migrate naked_functions.rs to translateable diagnostics 2022-10-07 13:19:27 -06:00
reachable.rs rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00
stability.rs Replace some _ == _ || _ == _s with matches!(_, _ | _)s 2023-01-30 12:26:26 +00:00
upvars.rs rustc_hir: Relax lifetime requirements on Visitor::visit_path 2022-12-01 17:04:02 +03:00
weak_lang_items.rs rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00