Skip to content

Report the unsafe_attr_outside_unsafe lint at the closest node #140617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2025

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented May 3, 2025

This PR have AstValidation track a linting node id and then uses it when reporting the unsafe_attr_outside_unsafe lint, so that instead of being bound at the crate-root, #[allow] of the lint works at any node.

Fixes #140602
r? @jieyouxu

@rustbot rustbot added 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 May 3, 2025
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Thanks! One nit, but r=me otherwise

@jieyouxu
Copy link
Member

jieyouxu commented May 3, 2025

@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 3, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 3, 2025

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 May 3, 2025
@jieyouxu
Copy link
Member

jieyouxu commented May 3, 2025

Don't know if we want to backport this to beta, it's in stable ever since this lint was implemented I think

@jieyouxu
Copy link
Member

jieyouxu commented May 3, 2025

I'll nominate this for beta-backport discussion at least.


This PR fixes a bug reported in #140602, where it wasn't possible to #[allow(unsafe_attr_outside_unsafe)] in scopes within crate root, e.g. the following will error and not compile

#![deny(unsafe_attr_outside_unsafe)]

#[allow(unsafe_attr_outside_unsafe)]
mod generated {
    #[no_mangle]
    fn _generated_foo() {}
}

This was broken since the unsafe_attr_outside_unsafe lint was introduced (also present on stable since it was stabilized). EDIT: confirmed with a bisection.

@rustbot label: +beta-nominated

@rustbot rustbot added the beta-nominated Nominated for backporting to the compiler in the beta channel. label May 3, 2025
@Urgau
Copy link
Member Author

Urgau commented May 3, 2025

@bors r=@jieyouxu rollup

@bors
Copy link
Collaborator

bors commented May 3, 2025

📌 Commit f4e1ec1 has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 3, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request May 4, 2025
Rollup of 7 pull requests

Successful merges:

 - rust-lang#139675 (Add the AVX10 target features)
 - rust-lang#140286 (Check if format argument is identifier to avoid error err-emit)
 - rust-lang#140456 (Fix test simd/extract-insert-dyn on s390x)
 - rust-lang#140551 (Move some tests out of tests/ui)
 - rust-lang#140588 (Adjust some ui tests re. target-dependent errors)
 - rust-lang#140617 (Report the `unsafe_attr_outside_unsafe` lint at the closest node)
 - rust-lang#140626 (allow `#[rustfmt::skip]` in combination with `#[naked]`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 54821b9 into rust-lang:master May 4, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone May 4, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 4, 2025
Rollup merge of rust-lang#140617 - Urgau:unsafe_attr-lint-allow, r=jieyouxu

Report the `unsafe_attr_outside_unsafe` lint at the closest node

This PR have `AstValidation` track a linting node id and then uses it when reporting the `unsafe_attr_outside_unsafe` lint, so that instead of being bound at the crate-root, `#[allow]` of the lint works at any node.

Fixes rust-lang#140602
r? `@jieyouxu`
tgross35 added a commit to tgross35/rust that referenced this pull request May 4, 2025
…=Urgau

Small adjustments to `check_attribute_safety` to make the logic more obvious

Follow-up to rust-lang#140617.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 5, 2025
Rollup merge of rust-lang#140619 - jieyouxu:validate_attr_cleanups, r=Urgau

Small adjustments to `check_attribute_safety` to make the logic more obvious

Follow-up to rust-lang#140617.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-nominated Nominated for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

Can't allow unsafe_attr_outside_unsafe in Rust 2015-2021
4 participants