-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking Issue for experimental yeet
expressions (feature(yeet_expr)
)
#96373
Comments
Add `do yeet` expressions to allow experimentation in nightly Two main goals for this: - Ensure that trait restructuring in rust-lang#84277 (comment) doesn't accidentally close us off from the possibility of doing this in future, as sketched in https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#possibilities-for-yeet - Experiment with the *existence* of syntax for this, to be able to weight the syntax-vs-library tradeoffs better than we can right now. Notably the syntax (with `do`) and name in this PR are not intended as candidates for stabilization, but they make a good v0 PR for adding this with minimal impact to compiler maintenance or priming one possible name choice over another. r? `@oli-obk` The lang `second` for doing this: rust-lang/lang-team#160 (comment) Tracking issues - Lang, rust-lang#96373 - Libs-api, rust-lang#96374
Add `do yeet` expressions to allow experimentation in nightly Two main goals for this: - Ensure that trait restructuring in rust-lang/rust#84277 (comment) doesn't accidentally close us off from the possibility of doing this in future, as sketched in https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#possibilities-for-yeet - Experiment with the *existence* of syntax for this, to be able to weight the syntax-vs-library tradeoffs better than we can right now. Notably the syntax (with `do`) and name in this PR are not intended as candidates for stabilization, but they make a good v0 PR for adding this with minimal impact to compiler maintenance or priming one possible name choice over another. r? `@oli-obk` The lang `second` for doing this: rust-lang/lang-team#160 (comment) Tracking issues - Lang, rust-lang/rust#96373 - Libs-api, rust-lang/rust#96374
What are exactly the added values here? |
@reza-ebrahimi fn main() -> Result<(), Box<dyn std::error::Error>> {
return Err("string message"); // compile error, wrong type
return Err("string message".into()); // works
Err("string message")?; // works
do yeet "string message"; // works
} It also works with I think fn err_semicolon() -> Result<bool, i32> {
Err(1)?; // compile error, wrong type
}
fn err_no_semicolon() -> Result<bool, i32> {
Err(1)? // works
}
fn yeet_semicolon() -> Result<bool, i32> {
do yeet 1; // works
}
fn yeet_no_semicolon() -> Result<bool, i32> {
do yeet 1 // works
} |
feat: Implement yeeting See tracking issue: rust-lang/rust#96373 Before: ![2022-12-29_03-19](https://user-images.githubusercontent.com/38225716/209884634-e34e98fb-615d-4954-9614-7f9ce6291678.png) After: ![2022-12-29_03-21](https://user-images.githubusercontent.com/38225716/209884633-4bba5eba-6dcc-4714-86cb-5c0d1f358364.png)
Hmm, Edit: I filed #106357 to track this discussion. |
@andersk Sorry for the late reply. The thing I'm trying to understand is why we need to add a new keyword to language for these kinds of scenarios? There should be many scenarios of this kind we can find in the Rust language and do we really need to resolve them by adding a new keyword to the language? |
@reza-ebrahimi I've been thinking about why 'yeet' is different than other cases. I've tried to give a response here, but am happy to take this conversation elsewhere :) A Yeet keyword (and functions that support In my experience this is near the top of the ergonomics issues that Rust faces (and it seems many others agree: this keyword has been proposed many times, under multiple names). As one of the most tractable issues that Rust faces (as it's entirely syntactic sugar) I would love to see this get in! Personally I'd prefer it was named |
I think the infix |
That's a solution for a different problem imo, (and is often complained about by new Haskellers). It only reduces the number of parens (while making it harder to parse (as a human) and requiring work arounds when multiple arguments come into play. More importantly though, it doesn't provide a short hand for |
(NOT A CONTRIBUTION) Not mentioned in this thread, but critical for understanding this feature, is that it would be intended to interact with Of course the same thing could be achieved with e.g. try {
// Do some kind of fallible IO operation, and fail if it returns false
if !do_io()? {
do yeet DoIoFalseError;
};
// More code here...
} |
I would argue that while this pattern is somewhat clearer in try {
if !do_io? {
DoIoFalseError.yeet!();
};
} Also for the record, the monadic error handling actually encourages a different approach: try { do_io()?.failing(DoIoFalseError)? }
// Or call it `map_false` if you like. where all one really needs is an extension trait and a tiny library in |
We're all fine with things like reborrowing. I don't see how Rust is complex enough as is, the fewer symbols we need for basic things such as error handling that you learn early on the better. |
Complete newbie to Rust here, but I've done quite my fair share of system programming in C, and am also very tired of the lack of rigorously defined try {
if !do_io? {
DoIoFalseError.yield!();
};
} Or perhaps the "monadic error handling" way as mentioned by @appetrosyan in this case would be?: try { do_io()?.fails_over_to(DoIoFalseError)? }
// Or call it `map_false` if you like. Like @withoutboats said I wouldn't count my 2 cents as an official contribution, just that I personally believe we need to remind ourselves that just like natural languages, the way we name things in programming languages can take advantage of existing "synonyms" based on natural languages. I understand reusing the same keyword from another very popular language (Python) in a different way might cause severe confusion for beginners, but unfortunately I am unable to think of a better alternative at the moment. :/ And to address @dev-ardi 's point: yes adding more keywords will complicate the language, but unfortunately as well the nature of such things like FILE I/O is that so many things could go wrong (lock on file un-acquireable, file is encoded in wrong format, etc. etc.) that having a relatively simple try...catch way of doing structured programming may actually be very beneficial for all in the long term. DO NOT get me started on having to include some random Sources of inspiration: P.S. minutes after creating this comment, just saw this stack-overflow post and I gotta say that it seems to me using "yield" for iterators seems to be a rather terrible idea imho. P.P.S. what if...synonyms for throw...? try {
if !do_io? {
DoIoFalseError.lob!();
};
} |
OK, I have to apologize here as I have clearly overstepped my bounds here a bit, esp. as I realized after some more thinking that having any extra keywords that needs to be memorized for Rust will in fact likely make the language a bit too complicated especially for beginners, and to be fair half the time I just make up stuff that I end up having to retract later. HOWEVER, the only reason why I'm not jumping onto the Rust train right now is that it is still not as mature as, say, C++, especially given how much of the software world is dependent on code written in C++ (e.g. .NET, Qt, JVM, etc. etc.), and I believe as Theo from t3.gg especially rightly said during this twitch stream (I sometimes misremember so please forgive me if I mis-paraphrase), it's not always a wise idea to just jump onto the latest new tech for any given project. Theo's argument for not doing that is more related to the idea of maintaining a flexible software stack, but I'm borrowing his argument here (esp. as someone who's dabbled with the likes of CUDA, ROCm, OpenMP, etc.) especially for software used as infrastructure (e.g. the Linux Kernel, Oracle Virtualbox), since rely on something brand new for something that cannot be changed at a moment's notice is never a good idea. Basically, with software used as infrastructure one has to take a lot of precautions around the idea of "moving fast", as "moving too fast" can cause critical system breakage. NONETHELESS, I don't want to have to dismiss Rust as a viable systems programming candidate, as I really like how its "mutable borrow" philosophy encourages the writing of safe code, but I understand the sentiment behind keeping things as simple as possible. BUT I also hate to see progress on Rust being stalled due to unsettled disagreements about fundamental keywords that may be a necessary part of the programming language. So my question ultimately is: To solve the issue of having a better version of something like setjmp.h in C due to the lack of Unfortunately my very limited experience in designing programming languages doesn't allow me to participate in this discussion in a truly meaningful way, but again I'm just trying to encourage more discussion around this topic in the hopes that this issue won't be a cause for stalling of the development of Rust itself. |
I've read your comments like 3 times and I'm still not sure what point you're trying to raise honestly 😄 |
My point is: do we want to keep discussing this |
The argument that I find Naming-wise a have a concern: why is it |
|
What’s blocking us from using |
Common sense? You wouldn’t call objects |
I assume you’re implying that |
If we're totally honest, the Secondly, |
Just because I can call something |
I don't see the point in arguing. Just give me a lint to catch these expressions, so I can |
That's the thing, you can't not teach it to users. It adds yet another chapter to the Rust book which everyone needs to read and understand to be able to read Rust code. From the perspective of a new user:
Is surprising the first time you see it. But it can be parsed without learning any new concepts. Once you've seen it, it's easy to remember, and isn't even any more typing. So adding |
The advantage is a significant boilerplate reduction. |
Please find another place to have the discussion like https://internals.rust-lang.org or zulip. |
This is a tracking issue for experimenting with the "throw expression" idea from RFC#0243.
The feature gate for the issue is
#![feature(yeet_expr)]
.Per the lang process, this cannot go further than experimenting without an approved RFC -- and will certainly not stabilize under the name
yeet
. Please try this out and give experience reports, but be aware that it may well change drastically or be removed entirely.Currently the primary purpose of the feature is to ensure that redesigns of the
Try
trait (#84277) are compatible with potentially doing this in the future, and secondarily to experiment with whether this is worth having as an expression, or whether it should be removed in favour of a pure-library approach.Because the
do yeet
syntax is explicitly temporary, do not expect various ecosystem tools to support it, especially not those which have stability promises.Lang initiative: rust-lang/lang-team#160
Tracking issue for standard library additions: #96374
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
instructions?)
Unresolved Questions
yeet
is used for now to avoid priming any particular choice.Implementation history
do yeet
expressions to allow experimentation in nightly #96376The text was updated successfully, but these errors were encountered: