-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Take lifetime extension into account in ref_as_ptr
#12260
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
☔ The latest upstream changes (presumably #12306) made this pull request unmergeable. Please resolve the merge conflicts. |
Sorry for the delay, I was quite sick the last two weeks and am still recovering. r=me after a rebase. |
@bors r=llogiq Take the time you need to recover. |
Take lifetime extension into account in `ref_as_ptr` fixes #12255 This should be merged upstream as well. Changing `let x = &temp as *const _` into `let x = from_ref(&temp)` is UB. changelog: `ref_as_ptr`: Take lifetime extension into account
💔 Test failed - checks-action_test |
@bors retry |
Take lifetime extension into account in `ref_as_ptr` fixes #12255 This should be merged upstream as well. Changing `let x = &temp as *const _` into `let x = from_ref(&temp)` is UB. changelog: `ref_as_ptr`: Take lifetime extension into account
💔 Test failed - checks-action_test |
@bors retry |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Third time's the charm. 😄 |
This lint is not in |
@@ -58,27 +64,27 @@ fn _msrv_1_75() { | |||
let mut_val = &mut 42_i32; | |||
|
|||
// `std::ptr::from_{ref, mut}` was stabilized in 1.76. Do not lint this | |||
let _ = val as *const i32; | |||
let _ = mut_val as *mut i32; |
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.
Didn't this change go way too far? let _ = mut_val as *mut i32;
should absolutely trigger the lint, no? The issue isn't the temporariness of the resultant pointer, but whether the expression being cast is a &x
or &mut x
expression, right?
} | ||
|
||
fn foo(val: &[u8]) { | ||
let _ = val as *const _; |
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.
Similarly, let _ = val as *const _
should absolutely trigger the lint, as there is no lifetime extension.
fixes #12255
This should be merged upstream as well. Changing
let x = &temp as *const _
intolet x = from_ref(&temp)
is UB.changelog:
ref_as_ptr
: Take lifetime extension into account