Skip to content

Add global_variables lint #14657

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

EFanZh
Copy link

@EFanZh EFanZh commented Apr 20, 2025

changelog: [global_variables]: check static variables with interior mutability.

@rustbot
Copy link
Collaborator

rustbot commented Apr 20, 2025

r? @Jarcho

rustbot has assigned @Jarcho.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 20, 2025
@EFanZh EFanZh force-pushed the add-global-variables-lint branch from e1e98ac to 2c457fd Compare April 20, 2025 10:20
@Jarcho
Copy link
Contributor

Jarcho commented Apr 20, 2025

This looks like it's the same lint as declare_interior_mutable_const but for static items. For consistency this should be named declare_interior_mutable_statics (plural, the other one violates the naming guide) and should share the same implementation.

@EFanZh EFanZh force-pushed the add-global-variables-lint branch from 3ce5790 to 75b29dd Compare April 26, 2025 07:11
@EFanZh
Copy link
Author

EFanZh commented Apr 26, 2025

@Jarcho: I have moved the implementation together with declare_interior_mutable_const, but I didn’t change the name because global_variables seems to be easier to understand than declare_interior_mutable_statics. If you still prefer your proposed name, I am OK to change it.

Also, I am not able to exclude statics with interior mutability but with “frozen” initializers. For example: A static using None::<AtomicU32> as the initializer can be excluded. This detection used for consts uses the is_value_unfrozen_poly function, which panics for statics. What should I do from here?

  • Ignore this false positive, since using a interior mutable static that isn’t actually mutable does not make much sense, the impact could be minor, or
  • Continue trying to figure out how to detect the case with non-mutable value case.

@rustbot
Copy link
Collaborator

rustbot commented May 16, 2025

☔ The latest upstream changes (possibly 94cfebb) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants