-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix fp when [undocumented_unsafe_blocks
] not able to detect comment on globally defined const/static variables
#11375
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
Conversation
r? @Centri3 (rustbot has picked a reviewer for you, use r? to override) |
span = e.span; | ||
// Note: setting this to `false` is to making sure a "in-function defined" | ||
// const/static variable not mistakenly processed as global variable, | ||
// since global var doesn't have an `Expr` parent as its parent??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only 70% sure of this... so, can someone please confirm this for me? 😆
(also please forgive my terrible English...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is because a const
's initializer is a body, and when getting a body's value
's parent it'll get wherever the body's used; see the HIR for const A: u32 = { 0 }
: https://rust.godbolt.org/z/3cY4vaq6T
So this is getting the Expr
every other time, yet here, it's getting the Const
/Static
, then nothing, afaik? So maybe we just need to handle ItemKind::Const
and ItemKind::Static
parents as well.
I think we already do that so maybe the issue is somewhere within that block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait a minute, I think I unintentionally increase the search span for other scenarios (actually not, but the search span for module level const/static was too big because I forgor to add a break), let me see if I can find a better solution
Interestingly, |
it is the the rest of change I've made was mainly refractoring. tbh I had trouble understanding most of its code lol |
and narrow search span when const/static items are in a mod block
This version looks fine to me. I don't particularly like @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
fixes: #11246
changelog: fix detection on global variables for [
undocumented_unsafe_blocks
]