-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement Termination for Option<()> #61360
Implement Termination for Option<()> #61360
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
This seems like more of a libs/lang issue than compiler, no? |
The fact that that is even a question suggests that we shouldn't add this impl. See also rust-lang/rfcs#1937 (comment). |
IMO it's non-obvious what |
This seems like a matter primarily for the language team. |
Oh yes it is, sorry! @cramertj: Absolutely. I first thought than in any case, we should just return |
@cramertj we have |
I'm not confused by |
src/libstd/process.rs
Outdated
@@ -1625,6 +1625,17 @@ impl<E: fmt::Debug> Termination for Result<(), E> { | |||
} | |||
} | |||
|
|||
#[unstable(feature = "termination_trait_lib", issue = "43301")] | |||
impl Termination for Option<()> { |
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.
why only ()
rather than anything implementing Termination
?
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.
Would that flatten the Option
? I'm afraid this could lead to too clever code like fn main -> Option<Option<Result<(), _>>> { .. }
.
I'd expect |
63a8cd1
to
24c1b73
Compare
@llogiq So the current code (with the update) is how you would do it? That's convenient. :) What the others are thinking about it? |
We had a conversation about specific impls and such in the first stabilization issue, #48453, and the RFC (https://github.com/rust-lang/rfcs/blob/master/text/1937-ques-in-main.md) had I, of course, agree with @ollie27's comment 😄 Additionally, I don't want
I consider that a good reason to not implement Termination here. |
We discussed this in the @rust-lang/lang team meeting today, though notably @scottmcm was not present. The consensus was that we were "not opposed" (some mildly in favor, some neutral, some mildly opposed but not enough to block). Speaking personally, I found the idea of returning Ultimately, we decided we'd rather defer the final details to the @rust-lang/libs team. If someone from that team wants to move to FCP, it would be approved by the lang team (modulo the fact that not everyone was present). But if they have doubts and would prefer to wait, that seems ok. |
I would prefer not to do this. I agree with Niko that in
Nope, just use unwrap in tests. Then you even get to find out which step failed. Writing The main justifiable use case I see for this impl is in doc tests with a hidden function signature. These allow the doc test to be rendered by rustdoc with /// ```
/// # fn main() -> Option<()> {
/// let x = f()?;
/// let y = g(x)?;
/// # Some(())
/// # }
/// ```
But for these it seems fine to recommend something like: /// ```
/// # try {
/// let x = f()?;
/// let y = g(x)?;
/// # }.unwrap()
/// ```
|
@dtolnay in current nightly, you can just add |
I'm late to the party, but if the libs team decides to close this, i would prefer #61279 be reverted. I left a longer comment over there: #61279 (comment) |
👍 |
@QuietMisdreavus @GuillaumeGomez Should we revert #61279 until such time that an affirmative decision to support |
Fine by me. |
Closing this based on #61360 (comment). Let's terminate the termination |
My comment was more of an "if this gets closed" - i was not calling for its closure myself, just deferring to libs team, which was pinged up-thread as the responsible party. |
After a question about this here, I decided to open this PR. However, is this how we should implement it? Should we consider
None
as a failure (because that's how I implemented it)?Anyway, I think having this PR open is a good place to discuss about it (and closing it if we don't want it of course).
cc @ollie27 @rust-lang/compiler