Skip to content

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

This comment has been minimized.

@Jarcho
Copy link
Contributor

Jarcho commented Sep 18, 2025

@EFanZh Sorry for the delay. The lint pass has been completely rewritten so you will need to rebase. You still won't be able to use the MIR value, but you can now use is_init_expr_freeze to evaluate the HIR expression used to initialize the static.

@EFanZh EFanZh force-pushed the add-global-variables-lint branch from 75b29dd to 318f6fa Compare October 1, 2025 03:34
@rustbot

This comment has been minimized.

@github-actions
Copy link

github-actions bot commented Oct 1, 2025

Lintcheck changes for b438103

Lint Added Removed Changed
clippy::global_variables 88 0 0

This comment will be updated if you push new changes

@EFanZh EFanZh force-pushed the add-global-variables-lint branch from 318f6fa to 7638b39 Compare October 1, 2025 04:29
@EFanZh EFanZh force-pushed the add-global-variables-lint branch from 7638b39 to 5bcb783 Compare October 16, 2025 14:05
@rustbot

This comment has been minimized.

@EFanZh EFanZh force-pushed the add-global-variables-lint branch from 5bcb783 to b438103 Compare November 20, 2025 00:41
@rustbot
Copy link
Collaborator

rustbot commented Nov 20, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

4 participants