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

Add unsafe Option::unwrap_unchecked() #24905

Closed
wants to merge 1 commit into from

Conversation

dschatzberg
Copy link
Contributor

This adds a new function to the Option enum which allows for an
unchecked unwrap. In some cases, a developer may be able to statically
determine that an Option must be Some(V) but the compiler cannot. Being
able to forgo a conditional branch is desirable, even if unsafe.

This adds a new function to the Option enum which allows for an
unchecked unwrap. In some cases, a developer may be able to statically
determine that an Option must be Some(V) but the compiler cannot. Being
able to forgo a conditional branch is desirable, even if unsafe.
@rust-highfive
Copy link
Collaborator

r? @huonw

(rust_highfive has picked a reviewer for you, use r? to override)

@ghost
Copy link

ghost commented Apr 28, 2015

This change, as an addition to the standard library, would warrant an RFC, and perhaps a preceding informal discussion.

Personally, I am unsure about the added utility of this method compared to

match x {
    Some(x) => { ... },
    None => intrinsics::unreachable()
}

@dschatzberg
Copy link
Contributor Author

The unreachable macro is not equivalent as it still panics. This would still force the compiler to check the condition. I have submitted an RFC here: rust-lang/rfcs#1095.

@alexcrichton
Copy link
Member

I'm going to close this in favor of the RFC, but we can reopen if it's accepted!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants