Take lifetime extension into account in ref_as_ptr#12260
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 |
|
|
||
| // `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.
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.
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