Currently, the validation of some attributes is spread across two parts of the code: the
check_attrs pass and the
codegen_fn_attrs query. To me there is no clear principle behind what kind of check goes where. The split also causes other problems: some errors are only emitted if
codegen_fn_attrs is called on the function/method/closure that has an invalid attribute, and
check_attrs tries to call it for that purpose but it's rather incomplete. This leads to bugs such as #70307 and mysterious test failures (now resolved) in #69274.
I feel like there should be a more robust and unified way to perform attribute validation, but I'm not sure what it looks like and would appreciate ideas. Some of the "validation" in
codegen_fn_attrs is clearly appropriate there (in particular, the parsing of the values passed to attributes), but I don't see a principled way to ensure it runs before codegen on every item and expression. OTOH, we can't really move the "does this attribute even make sense on this kind of item/expression" checks out of
codegen_fn_attrs only applies to function-like things.