rust/compiler
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
..
rustc
rustc_abi PointeeInfo is advisory only 2023-01-31 18:49:03 +01:00
rustc_apfloat compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
rustc_arena compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
rustc_ast Replace enum ==s with matches where it makes sense 2023-01-30 12:26:26 +00:00
rustc_ast_lowering Remove HirId -> LocalDefId map from HIR. 2023-01-28 09:55:26 +00:00
rustc_ast_passes Autoderive ExternBlockSuggestion 2023-01-19 13:52:15 +01:00
rustc_ast_pretty Use Edition methods a bit more 2023-01-31 10:09:22 +00:00
rustc_attr Fix uninlined_format_args for some compiler crates 2023-01-05 19:01:12 +01:00
rustc_baked_icu_data Update crate documentation of rustc_baked_icu_data crate 2022-11-18 14:46:36 -08:00
rustc_borrowck Rollup merge of #107467 - WaffleLapkin:uneq, r=oli-obk 2023-01-31 23:38:52 +01:00
rustc_builtin_macros Allow more deriving on packed structs. 2023-01-30 12:00:42 +11:00
rustc_codegen_cranelift Auto merge of #106227 - bryangarza:ctfe-limit, r=oli-obk 2023-01-29 04:11:27 +00:00
rustc_codegen_gcc session: diagnostic migration lint on more fns 2023-01-30 17:11:35 +00:00
rustc_codegen_llvm Rollup merge of #107412 - tshepang:needless-check, r=wesleywiser 2023-01-31 23:38:51 +01:00
rustc_codegen_ssa Auto merge of #107257 - inquisitivecrystal:ffi-attr, r=davidtwco 2023-02-01 11:37:24 +00:00
rustc_const_eval Rollup merge of #107467 - WaffleLapkin:uneq, r=oli-obk 2023-01-31 23:38:52 +01:00
rustc_data_structures Auto merge of #107297 - Mark-Simulacrum:bump-bootstrap, r=pietroalbini 2023-01-31 19:24:29 +00:00
rustc_driver session: diagnostic migration lint on more fns 2023-01-30 17:11:35 +00:00
rustc_error_codes make unaligned_reference a hard error 2023-01-31 20:28:11 +01:00
rustc_error_messages Auto merge of #107257 - inquisitivecrystal:ffi-attr, r=davidtwco 2023-02-01 11:37:24 +00:00
rustc_errors Rollup merge of #107467 - WaffleLapkin:uneq, r=oli-obk 2023-01-31 23:38:52 +01:00
rustc_expand Rollup merge of #107467 - WaffleLapkin:uneq, r=oli-obk 2023-01-31 23:38:52 +01:00
rustc_feature Auto merge of #107297 - Mark-Simulacrum:bump-bootstrap, r=pietroalbini 2023-01-31 19:24:29 +00:00
rustc_fs_util Remove useless borrows and derefs 2022-12-01 17:34:43 +00:00
rustc_graphviz Fix uninlined_format_args for some compiler crates 2023-01-05 19:01:12 +01:00
rustc_hir Rollup merge of #107125 - WaffleLapkin:expect_an_item_in_your_hir_by_the_next_morning, r=Nilstrieb 2023-01-30 17:50:08 +01:00
rustc_hir_analysis Rollup merge of #107486 - compiler-errors:bound-ty-keep-name, r=oli-obk 2023-01-31 23:38:52 +01:00
rustc_hir_pretty Use Mutability::{is_mut, is_not} 2023-01-30 12:26:26 +00:00
rustc_hir_typeck Rollup merge of #107499 - compiler-errors:deduce_sig_from_projection-generator-tweak, r=michaelwoerister 2023-02-01 05:54:39 +01:00
rustc_incremental incremental: migrate diagnostics 2023-01-30 17:11:35 +00:00
rustc_index Fix IndexVec::drain_enumerated 2023-01-19 15:25:33 +00:00
rustc_infer Rollup merge of #107486 - compiler-errors:bound-ty-keep-name, r=oli-obk 2023-01-31 23:38:52 +01:00
rustc_interface session: diagnostic migration lint on more fns 2023-01-30 17:11:35 +00:00
rustc_lexer Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
rustc_lint Auto merge of #107536 - GuillaumeGomez:rollup-xv7dx2h, r=GuillaumeGomez 2023-02-01 01:15:02 +00:00
rustc_lint_defs make unaligned_reference a hard error 2023-01-31 20:28:11 +01:00
rustc_llvm Rollup merge of #106113 - krasimirgg:llvm-16-ext-tyid, r=nikic 2023-01-21 23:20:58 -05:00
rustc_log Add log-backtrace option to show backtraces along with logging 2023-01-12 00:17:48 +09:00
rustc_macros Detect references to non-existant messages in Fluent resources 2023-01-27 11:27:22 +00:00
rustc_metadata Rollup merge of #107467 - WaffleLapkin:uneq, r=oli-obk 2023-01-31 23:38:52 +01:00
rustc_middle Rollup merge of #107486 - compiler-errors:bound-ty-keep-name, r=oli-obk 2023-01-31 23:38:52 +01:00
rustc_mir_build Use Mutability::{is_mut, is_not} 2023-01-30 12:26:26 +00:00
rustc_mir_dataflow Create stable metric to measure long computation in Const Eval 2023-01-23 23:56:22 +00:00
rustc_mir_transform Auto merge of #107536 - GuillaumeGomez:rollup-xv7dx2h, r=GuillaumeGomez 2023-02-01 01:15:02 +00:00
rustc_monomorphize Auto merge of #100754 - davidtwco:translation-incremental, r=compiler-errors 2023-01-31 10:20:58 +00:00
rustc_parse Rollup merge of #107487 - edward-shen:edward-shen/107213-round-2, r=estebank 2023-02-01 05:54:39 +01:00
rustc_parse_format Replace format flags u32 by enums and bools. 2023-01-27 08:53:39 +01:00
rustc_passes Auto merge of #107257 - inquisitivecrystal:ffi-attr, r=davidtwco 2023-02-01 11:37:24 +00:00
rustc_plugin_impl Migrate all diagnostics 2022-10-23 10:09:44 +02:00
rustc_privacy Remove HirId -> LocalDefId map from HIR. 2023-01-28 09:55:26 +00:00
rustc_query_impl Fix uninlined_format_args for some compiler crates 2023-01-05 19:01:12 +01:00
rustc_query_system Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
rustc_resolve Rollup merge of #107508 - WaffleLapkin:uneq'15, r=oli-obk 2023-01-31 23:38:53 +01:00
rustc_save_analysis Review changes 2023-01-31 07:54:01 +00:00
rustc_serialize compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
rustc_session Rollup merge of #107533 - pnkfelix:distinguish-generator-state-in-print-type-sizes, r=compiler-errors 2023-02-01 05:54:40 +01:00
rustc_smir
rustc_span Don't accept Edition by ref 2023-01-31 10:09:23 +00:00
rustc_symbol_mangling Introduce GeneratorWitnessMIR. 2023-01-27 18:58:44 +00:00
rustc_target Rollup merge of #107248 - erikdesjardins:addrspace, r=oli-obk 2023-01-26 06:15:27 +01:00
rustc_trait_selection Rollup merge of #107486 - compiler-errors:bound-ty-keep-name, r=oli-obk 2023-01-31 23:38:52 +01:00
rustc_traits Track bound types like bound regions 2023-01-30 22:18:20 +00:00
rustc_transmute Also remove #![feature(control_flow_enum)] where possible 2023-01-18 10:22:21 -08:00
rustc_ty_utils Extend -Z print-type-sizes to distinguish generator upvars and locals from "normal" ADT fields. 2023-01-31 15:59:29 -05:00
rustc_type_ir Separate witness type computation from the generator transform. 2023-01-27 19:00:26 +00:00