-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Make borrow_as_ptr
flag implicit casts as well
#14408
base: master
Are you sure you want to change the base?
Conversation
Note: I really dislike the reborrow suggestions, I'll remove them, and I'm not even sure this should be covered by this lint according to the description. Edit: done, especially given the hundreds of hits in lintcheck |
61600ab
to
185235c
Compare
Can you give a self-contained example of the reborrow case you asked about?
|
185235c
to
6ea7982
Compare
fn main() {
let p = &0i32;
let r: *const i32 = p;
} Initially I had this suggest |
13b6772
to
2857cca
Compare
Incidentally, the lintcheck output without regard to MSRV made me notice some suspicious code in |
The lintcheck seems reasonable. |
Agreed. Ideally this code would be changed so |
Does this cover all coercion sites, including e.g. function calls? I guess the fact that this triggered on that tracing-core code means the answer is "yes". |
Yes. It looks for all explicit references which are auto-reborrowed by the compiler as raw pointers, except for references in explicit casts, as those are linted separately. Interestingly, this discussion brought me to think about one problematic case: Edit: I've changed not to lint references to temporaries, as was done in the |
96dedba
to
e1bc192
Compare
Can't this be just one joint check? The diagnostics can then be different, but ideally the logic for "do we lint" is unified.
Good point. This should not lint. |
The only part to share is the temporary expression check, and this is done. Otherwise, entry points are different (cast expression vs. any pointer expression whose parent is not a cast).
Yes, this is what I ended up doing. |
e1bc192
to
a9aff03
Compare
a9aff03
to
78d456a
Compare
While I like replacing
&x
by&raw const x
and&mut x
by&raw mut x
, I'm less sure I like the suggested reborrows such as&raw const *p
. There was one in Clippy sources, see the PR diff.@RalfJung, any opinion on this?
Fix #14406
changelog: [
borrow_as_ptr
]: lint implicit casts as well