Rewrite target checking for #[sanitize]#157332
Conversation
|
Some changes occurred in compiler/rustc_attr_parsing Some changes occurred in compiler/rustc_passes/src/check_attr.rs |
| Allow(Target::Impl { of_trait: true }), | ||
| Allow(Target::Mod), | ||
| Allow(Target::Crate), | ||
| Allow(Target::Static), |
There was a problem hiding this comment.
Note that attribute parsing has slightly better/different target information than check_attr.rs does
- We allow
Target::Cratehere, which falls underTarget::Modin check_attr.rs - We allow
Target::Method(MethodKind::TraitImpl)here, which falls underTarget::Impl { of_trait: true }in check_attr.rs
There was a problem hiding this comment.
Okay, I raised some concerns on the tracking issue. #39699 (comment)
This pr won't change the behavior and sanitize is still unstable so I don't mind proceeding.
| LL | #[sanitize(address = "off")] | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: sanitize attribute can be applied to a function (with body), impl block, or module |
There was a problem hiding this comment.
function (with body) would be nice to keep. Can we update allowed_targets_applied to do this?
| Allow(Target::Impl { of_trait: true }), | ||
| Allow(Target::Mod), | ||
| Allow(Target::Crate), | ||
| Allow(Target::Static), |
There was a problem hiding this comment.
Okay, I raised some concerns on the tracking issue. #39699 (comment)
This pr won't change the behavior and sanitize is still unstable so I don't mind proceeding.
| #[derive(Diagnostic)] | ||
| #[diag("`#[sanitize({$field} = ...)]` attribute cannot be used on statics")] | ||
| #[help("`#[sanitize]` can be used on statics if only the address is sanitized")] | ||
| pub(crate) struct SanitizeInvalidStatic { | ||
| #[primary_span] | ||
| pub span: Span, | ||
| pub field: &'static str, | ||
| } |
There was a problem hiding this comment.
You can have multiple fields in this attribute, how does this error display in that case?
There was a problem hiding this comment.
It currently only complains about the first one it finds
|
Reminder, once the PR becomes ready for a review, use |
r? @mejrs