Skip to content

Rewrite target checking for #[sanitize]#157332

Open
JonathanBrouwer wants to merge 1 commit into
rust-lang:mainfrom
JonathanBrouwer:target-sanitize
Open

Rewrite target checking for #[sanitize]#157332
JonathanBrouwer wants to merge 1 commit into
rust-lang:mainfrom
JonathanBrouwer:target-sanitize

Conversation

@JonathanBrouwer
Copy link
Copy Markdown
Contributor

r? @mejrs

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 2, 2026

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 2, 2026
Allow(Target::Impl { of_trait: true }),
Allow(Target::Mod),
Allow(Target::Crate),
Allow(Target::Static),
Copy link
Copy Markdown
Contributor Author

@JonathanBrouwer JonathanBrouwer Jun 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that attribute parsing has slightly better/different target information than check_attr.rs does

  • We allow Target::Crate here, which falls under Target::Mod in check_attr.rs
  • We allow Target::Method(MethodKind::TraitImpl) here, which falls under Target::Impl { of_trait: true } in check_attr.rs

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

@mejrs mejrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a macro call test here as well.

View changes since this review

LL | #[sanitize(address = "off")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: sanitize attribute can be applied to a function (with body), impl block, or module
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1016 to +1023
#[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,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have multiple fields in this attribute, how does this error display in that case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It currently only complains about the first one it finds

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 2, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 2, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants