Skip to content

Take lifetime extension into account in ref_as_ptr #12260

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Feb 24, 2024

Conversation

Jarcho
Copy link
Contributor

@Jarcho Jarcho commented Feb 10, 2024

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

@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2024

r? @llogiq

rustbot has assigned @llogiq.
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 Feb 10, 2024
@bors
Copy link
Contributor

bors commented Feb 19, 2024

☔ The latest upstream changes (presumably #12306) made this pull request unmergeable. Please resolve the merge conflicts.

@llogiq
Copy link
Contributor

llogiq commented Feb 23, 2024

Sorry for the delay, I was quite sick the last two weeks and am still recovering.

r=me after a rebase.

@Jarcho
Copy link
Contributor Author

Jarcho commented Feb 24, 2024

@bors r=llogiq

Take the time you need to recover.

@bors
Copy link
Contributor

bors commented Feb 24, 2024

📌 Commit 5ab42d8 has been approved by llogiq

It is now in the queue for this repository.

bors added a commit that referenced this pull request Feb 24, 2024
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
@bors
Copy link
Contributor

bors commented Feb 24, 2024

⌛ Testing commit 5ab42d8 with merge 8542041...

@bors
Copy link
Contributor

bors commented Feb 24, 2024

💔 Test failed - checks-action_test

@Jarcho
Copy link
Contributor Author

Jarcho commented Feb 24, 2024

@bors retry

@Jarcho Jarcho added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Feb 24, 2024
@bors
Copy link
Contributor

bors commented Feb 24, 2024

⌛ Testing commit 5ab42d8 with merge 3bdcbeb...

bors added a commit that referenced this pull request Feb 24, 2024
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
@bors
Copy link
Contributor

bors commented Feb 24, 2024

💔 Test failed - checks-action_test

@Jarcho
Copy link
Contributor Author

Jarcho commented Feb 24, 2024

@bors retry

@bors
Copy link
Contributor

bors commented Feb 24, 2024

⌛ Testing commit 5ab42d8 with merge 0597838...

@bors
Copy link
Contributor

bors commented Feb 24, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing 0597838 to master...

@bors bors merged commit 0597838 into rust-lang:master Feb 24, 2024
@llogiq
Copy link
Contributor

llogiq commented Feb 24, 2024

Third time's the charm. 😄

@flip1995
Copy link
Member

This lint is not in beta yet and this fix made it to master in time. No need for a backport. Thanks for nominating it, would have been a good backport, if necessary. 👍

@flip1995 flip1995 removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Mar 14, 2024
@@ -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;

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 _;

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FP ref_as_ptr: things that cannot const drop
6 participants