Skip to content
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

Meeting Proposal: How does match interact with UnsafeCell #5

Closed
chorman0773 opened this issue Apr 18, 2023 · 1 comment
Closed

Meeting Proposal: How does match interact with UnsafeCell #5

chorman0773 opened this issue Apr 18, 2023 · 1 comment
Labels
meeting-proposal Proposal for a discussion topic at a team meeting

Comments

@chorman0773
Copy link

Summary

Currently, both Stacked Borrows and Treed Borrows considers the following code to have defined behaviour:

use std::cell::Cell;

pub fn evil(x: &Result<bool, Cell<u8>>) -> bool {
    unsafe { *(x as *const _ as *const bool as *mut bool).add(1) = false }
    false
}

pub fn main() {
    let x = Ok(true);
    match &x {
        Ok(true) if evil(&x) => unreachable!(),
        Ok(false) => println!("Ok(false) = {x:?}"),
        Ok(true) => println!("Ok(true) = {x:?}"),
        Err(_) => unreachable!(),
    }
}

Under the current match rules, this should evaluate and print Ok(false) = Ok(false). However, on the current lowering by rustc, it prints Ok(true) = Ok(false). If both lowerings (linear, and rustc's current lowering) are correct, this code must have undefined behaviour (or some other rule must allow it). The meeting would be to help address how this code has UB, or if it does/should.

Reading

UCG Issue: unsafe-code-guidelines#399.
Zulip Thread: https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/How.20does.20match.20interact.20with.20.60.26UnsafeCell.60

There will likely be a summary document prepared in time for the meeting, based on the asynchronous discussion that has occured by that time.

Comment policy

These issues are meant to be used as an "announcements channel" regarding the proposal, and not as a
place to discuss the technical details. Feel free to subscribe to updates. We'll post comments when
reviewing the proposal in meetings or making a scheduling decision. In the meantime, if you have
questions or ideas, ping the proposers on Zulip (or elsewhere).

@chorman0773 chorman0773 added the meeting-proposal Proposal for a discussion topic at a team meeting label Apr 18, 2023
@chorman0773
Copy link
Author

This meeting has been held as of 2023-05-09. The question has not been resovled, but the underlying questions can be refined asynchronously prior to holding another Opsem Meeting on this topic. I am therefore closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meeting-proposal Proposal for a discussion topic at a team meeting
Projects
None yet
Development

No branches or pull requests

1 participant