Hi folks. Based on the feedback and problems with the previous Context Managers RFC, Arnaud and I have a new approach to present:
https://wiki.php.net/rfc/context-managers-v2
It basically swaps the two-method approach in favor of "it's a generator, you're welcome." The result is, I think, both simpler and more flexible, and resolves a number of other issues as well. More details in the RFC.
There is a linked implementation, though Arnaud warns it's only partially complete so go easy on it. :-) But the design in the RFC is all ready for review.
--
Larry Garfield
larry@garfieldtech.com
Quoted text · 7 lines
Hi folks. Based on the feedback and problems with the previous Context Managers RFC, Arnaud and I have a new approach to present:
https://wiki.php.net/rfc/context-managers-v2
It basically swaps the two-method approach in favor of "it's a generator, you're welcome." The result is, I think, both simpler and more flexible, and resolves a number of other issues as well. More details in the RFC.
There is a linked implementation, though Arnaud warns it's only partially complete so go easy on it. :-) But the design in the RFC is all ready for review.
--
Larry Garfield
larry@garfieldtech.com
Hi Larry,
TLDR: why => rather than as?
As a userland developer I like what this is trying to achieve. I'm not knowledgeable enough about the internals to comment on the finer details or their ramifications - I just have a bike shedding suggestion/question which seemed glaring to me so I wonder if it's because of an ambiguous syntax or some other issue?
The => symbol seems odd to me, given how it's used elsewhere (generally as an indicator of a key/value pair, whether in an array or match block) and how generators/iterables are used elsewhere (ie foreach as)
Your example is:
using (file_for_write('file.txt') => $fp) {
Whereas to my eye this seems like a much more obvious choice:
using (file_for_write('file.txt') as $fp) {
Anyway, just a thought.
Cheers
Stephen
Quoted text · 9 lines
Hi Larry,
TLDR: why
=>rather thanas?As a userland developer I like what this is trying to achieve. I'm not knowledgeable enough about the internals to comment on the finer details or their ramifications - I just have a bike shedding suggestion/question which seemed glaring to me so I wonder if it's because of an ambiguous syntax or some other issue?
The
=>symbol seems odd to me, given how it's used elsewhere (generally as an indicator of a key/value pair, whether in an array or match block) and how generators/iterables are used elsewhere (ie foreach as)Your example is:
using (file_for_write('file.txt') => $fp) {
Whereas to my eye this seems like a much more obvious choice:
using (file_for_write('file.txt') as $fp) {
Anyway, just a thought.
The v1 RFC originally used as, which is what Python uses as well. However, a lot of people were concerned that it implied that the left side expression would be "used as" the right side variable. While in some cases it might be, the typical case is that it's not. The context variable is emitted by the context manager, but is not the same thing.
At the time, no one could really agree on a better keyword. But => was right there waiting to be used, and already has an "evaluates to" or "yields" or "produces" meaning, which is roughly accurate to what happens here.
I don't mind as, personally, but the consensus before seemed to not care for it.
--Larry Garfield
Quoted text · 13 lines
Hi Larry,
TLDR: why
=>rather thanas?As a userland developer I like what this is trying to achieve. I'm not knowledgeable enough about the internals to comment on the finer details or their ramifications - I just have a bike shedding suggestion/question which seemed glaring to me so I wonder if it's because of an ambiguous syntax or some other issue?
The
=>symbol seems odd to me, given how it's used elsewhere (generally as an indicator of a key/value pair, whether in an array or match block) and how generators/iterables are used elsewhere (ie foreach as)Your example is:
using (file_for_write('file.txt') => $fp) {
Whereas to my eye this seems like a much more obvious choice:
using (file_for_write('file.txt') as $fp) {
Anyway, just a thought.
The v1 RFC originally used
as, which is what Python uses as well. However, a lot of people were concerned that it implied that the left side expression would be "used as" the right side variable. While in some cases it might be, the typical case is that it's not. The context variable is emitted by the context manager, but is not the same thing.At the time, no one could really agree on a better keyword. But => was right there waiting to be used, and already has an "evaluates to" or "yields" or "produces" meaning, which is roughly accurate to what happens here.
I don't mind
as, personally, but the consensus before seemed to not care for it.--Larry Garfield
Hello Larry,
Using the => operator for this case looks inconsistent to me as well. In my perception, the meaning of => in PHP is that of mapping as a function in the mathematical sense: the domain mapped to the image. For example, we have keys mapped to values in arrays or in yield generators or even in iterations with foreach. Similarly, the usage of => in lambda functions is also consistent as we have a mapping of input to output.
In this new case, however, it looks like it is used more as an assignment. In the statement foreach ($iterable as $key => $value), the assignment operator is as, while => consistently carries the meaning of a map. So, I would argue that using as for assigning is more consistent with the previous syntax choices.
Lazare INEPOLOGLOU
Architecte Logiciel
Hello,
Please remember to bottom post, not top post.
Quoted text · 4 lines
I agree that
asseems more coherent than=>in PHP. The only time I saw=>in PHP was with key => value. And in JS it was with() => {}
functions.I have another question. This mechanism of Context Manager, Is it the same as the Ruby
doblocks? Example with Vagrant Ruby configuration file:Vagrant.configure("2") do |config| config.vm.box = "bento/ubuntu-24.04" config.vm.box_version = "202510.26.0" end
It's not quite the same. I don't have any Ruby experience, so going based on https://zetcode.com/ruby/do-keyword/, it can be used in a similar way but it's not the same mechanism. Ruby (per that page) creates a closure for a do block, and thus variables go out of scope at the end and get closed implicitly. A using block in this RFC creates no closure or scope. The body of the using expression executes in the same function context as the code around it. Also, the context manager generator itself allows more cleanup than just "unset()" on the context variable. That happens automatically, which can trigger some cleanup, but the context manager is able to do a lot more if it wants to.
The model we are building from is Python, basically.
When you set the example as:
using (file_for_write('file.txt') => $fp) { foreach ($someThing as $value) { fwrite($fp, serialize($value)); } }; // At this point, we're guaranteed that $fp has closed, whether there was an error or not.It means that the block inside
usingis aware of variables outside of it's own scope, right?
Correct. There is no "own scope". As implemented currently, it's just materializing some generator read logic around the body of the using block. There is no new function scope created, so the code inside is "in" the function it's already in, as it always has been.
I like the idea. I have to admit that at first I was confused because I thought that the first example in the RFC post was exactly the same as the second example (Error catching included).
You mean in the introduction? They do accomplish the same goal, just with less code in the context manager version.
Quoted text · 4 lines
I have another question: according to PHP documentation ("Freeing resources"
"Thanks to the reference-counting system being part of the Zend Engine, a resource with no more references to it is detected automatically, and it is freed by the garbage collector. For this reason, it is rarely necessary to free the memory manually."
From what I understand by this text,
fclose()is optional (but recommended according to some Stack Overflow posts). In both cases (using or not the usingusing), this acts exactly the same. The only difference is that you declare the variable inside the using instead of the outside the try/catch block, right? Because even inside theusingfunction you would need to invoke thefclose()function, right?
PHP will automatically close() a resource that goes out of scope, just as it will garbage collect an object that goes out of scope. However, that is only true if that is the last reference to that resource/object. If the value had "escaped" (see the section in the RFC), then the file wouldn't be closed at that point. Also, even if PHP will cleanup as it goes, it's still good practice to close a file when you're done with it to minimize race conditions. A using block takes care of both of those for you. The context manager generator function is where the fclose() would live, so you don't have to remember to write it yourself every time.
Apart from easing the expressiveness of the language, I'm curious of what would be other benefits. In the post you express that it provides "a way to abstract out common control-flow and variable-lifetime-management pattern". What are the ways this function may bring such improvements? Are those improvement observed by language like Python not already available in PHP by default? I read somewhere that PHP tends to be more memory efficient than Python due to the processing of the many magic methods and other issues. If so, Is the context manager in Python focused on improving the variable-lifetime-management due to Python internal issues, and are these issues present in PHP?
The examples section includes most of the example cases I could think of off hand, but I'm sure there are more. Basically, any time you have the use case of "I want to stick some setup logic at the start of this code, and some cleanup and error handling logic at the end", a context manager can abstract that away for you, resulting in reusable logic and in your business logic not getting confused with the boilerplate error handling.
Think of opening a connection to some remote service and sending a message to it, but then there's like 10 error cases you need to handle. That's a great example to factor out into a using block, so you don't need to do all that error handling each time.
For use in Python, I recommend this video, which lays out a "Pythonic" way of thinking, and in particular shows how context managers in Python can help vastly simplify code.
https://www.youtube.com/watch?v=wf-BqAjZb8M
(That's the video that really helped me wrap my head around context managers and made me want them in PHP.)
As far as performance, there's a huge number of differences between PHP and Python that impact performance. The engine itself is less efficient, plus yes, Python relies a lot more heavily on magic callbacks that incur extra overhead (just as they do in PHP). You can't really pin it down to any one thing. Context Managers in Python in particular are mainly about managing flow of control and error handling, not performance, which is the same for this RFC.
The way using is implemented here, that impact is minimal. It adds a generator invocation and read, and that's about it. So it's not 100% free, but the overhead is minimal, and comparable to if you were passing a closure to some ordinary function that did the same sort of wrapping.
--Larry Garfield
Am 05.11.2026, 18:33:14 schrieb Larry Garfield larry@garfieldtech.com:
Hi folks. Based on the feedback and problems with the previous Context Managers RFC, Arnaud and I have a new approach to present:
trying to understand, can you implement the file_for_write method in the code sample to its more clear how that creates a generator?
Quoted text · 5 lines
It basically swaps the two-method approach in favor of "it's a generator, you're welcome." The result is, I think, both simpler and more flexible, and resolves a number of other issues as well. More details in the RFC.
There is a linked implementation, though Arnaud warns it's only partially complete so go easy on it. :-) But the design in the RFC is all ready for review.
--
Larry Garfield
larry@garfieldtech.com
Quoted text · 4 lines
Am 05.11.2026, 18:33:14 schrieb Larry Garfield larry@garfieldtech.com:
Hi folks. Based on the feedback and problems with the previous Context Managers RFC, Arnaud and I have a new approach to present:
trying to understand, can you implement the file_for_write method in the code sample to its more clear how that creates a generator?
I added a basic implementation to the intro section. Arguably I'd clean it up further and refine it for a real function, but I kept it parallel to the example to make it clearer what is going on.
--Larry Garfield
Le 05/11/2026 à 18:33, Larry Garfield a écrit :
It basically swaps the two-method approach in favor of "it's a generator, you're welcome." The result is, I think, both simpler and more flexible, and resolves a number of other issues as well. More details in the RFC.
Hello,
I love the simplicity for this RFC. I have one question: what happens if the generator yield more than once, will the using block run more than once ? If so it seems odd and may trigger very hard to debug problems (I can imagine some SQL transaction running more than once because of a generator bug).
Regards,
--
Pierre
Le 06/11/2026 à 12:19, Pierre a écrit :
I love the simplicity for this RFC. I have one question: what happens if the generator yield more than once, will the using block run more than once ? If so it seems odd and may trigger very hard to debug problems (I can imagine some SQL transaction running more than once because of a generator bug).
The implementation details section gave me an answer, the generator can only yield once.
Sorry for the noise.
--
Pierre
Context Managers RFC, Arnaud and I have a new approach to present:
Thanks. It looks promising.
When the using expression ends, VAR is explicitly unset().
What happens when VAR was already defined before the context? Is it masked and restored, or overwritten and unset?
what the return value of a combined using block should be
I would say the return value of the outer-most / left-most context manager. That is equivalent to the nested form. The compact comma separated syntax could also be added later, so if this is a difficult point it is also possible to remove this from the RFC and add it later on.
public function transaction(): self
Should the return type be Generator here?
Regards,
Sjoerd
Quoted text · 5 lines
Context Managers RFC, Arnaud and I have a new approach to present:
Thanks. It looks promising.
When the using expression ends, VAR is explicitly unset().
What happens when VAR was already defined before the context? Is it masked and restored, or overwritten and unset?
At the moment, in v2 it's overwritten and unset. We can bring back the mask/restore logic if there's interest, but we're not entirely convinced it's needed so left it out of this version for now. (Basically, if you're reusing a variable like that, you know that it's not going to be what it was before. If you do so accidentally, then your function is too long for you to keep in your head and you need to refactor anyway.)
what the return value of a combined using block should be
I would say the return value of the outer-most / left-most context manager. That is equivalent to the nested form.
That's my thinking as well, but we wanted to get input from the Crowd(tm).
The compact comma separated syntax could also be added later, so if this is a difficult point it is also possible to remove this from the RFC and add it later on.
True, though it doesn't seem controversial so I'd rather include it if we can.
public function transaction(): self
Should the return type be Generator here?
Yep, it should. Fixed now, thanks.
--Larry Garfield
Hello,
Le jeudi 5 novembre 2026, 18:33:14 heure normale d’Europe centrale Larry Garfield a écrit :
Quoted text · 4 lines
Hi folks. Based on the feedback and problems with the previous Context Managers RFC, Arnaud and I have a new approach to present:
https://wiki.php.net/rfc/context-managers-v2
It basically swaps the two-method approach in favor of "it's a generator, you're welcome." The result is, I think, both simpler and more flexible, and resolves a number of other issues as well. More details in the RFC.
There is a linked implementation, though Arnaud warns it's only partially complete so go easy on it. :-) But the design in the RFC is all ready for review.
I do not understand this sentence: «Additionally, it is legal for a Context Manager object to return $this as the context variable if that is appropriate in the specific use case.» If ContextManager::getContextManager returns $this, which Generator is used 🤔
The whole section «Mixing with try-catch» is also a mystery to me. I do not understand why "using" would need a short syntax for try catch any more than any other keyword we often put in a try/catch, nor what the explanations in there mean.
Is the semi-colon necessary after the closing '}' ? That reads weird, it’s not clear to me why it’s not a single '}' like after an if or foreach or whatever. Also, this semi-colon is missing in at least one example.
In the transaction example, $conn does not exist, I suppose both instances should be $this?
«A return statement inside the BODY will return from the function the code is currently executing in. A finally block in the generator context manager will still be executed, but otherwise control returns to the function's caller.» This is also hard to get for me.
Can you detail what this would output:
function context(): \Generator {
echo "A\n";
yield "B";
echo "C\n";
return "D";
}
var_dump(
using (context() => $c) {
echo "E\n";
return "F";
}
);
Côme
Quoted text · 7 lines
Hello,
Le jeudi 5 novembre 2026, 18:33:14 heure normale d’Europe centrale Larry Garfield a écrit :
Hi folks. Based on the feedback and problems with the previous Context Managers RFC, Arnaud and I have a new approach to present:
https://wiki.php.net/rfc/context-managers-v2
It basically swaps the two-method approach in favor of "it's a generator, you're welcome." The result is, I think, both simpler and more flexible, and resolves a number of other issues as well. More details in the RFC.
There is a linked implementation, though Arnaud warns it's only partially complete so go easy on it. :-) But the design in the RFC is all ready for review.
I do not understand this sentence: «Additionally, it is legal for a Context Manager object to return $this as the context variable if that is appropriate in the specific use case.» If ContextManager::getContextManager returns $this, which Generator is used 🤔
That should read "yield $this". Like so:
class Foo implements ContextManager {
public function getContextManager(): \Generator {
yield $this;
{
}
In which case the context variable will be an instance of Foo. I'll adjust the language.
The whole section «Mixing with try-catch» is also a mystery to me. I do not understand why "using" would need a short syntax for try catch any more than any other keyword we often put in a try/catch, nor what the explanations in there mean.
As stated in the RFC, we expect doing this to be very common:
function something(): \Generator
{
try {
$something = init_something();
yield $something;
} finally {
deinit($something);
}
}
try {
using (something() => $var) {
// Do stuff with $var.
};
} catch (\Exception $e) {
// Additional error handling, but we don't need to clean up $something. That's already handled. }
So the short-hand form just lets us reduce the nesting a bit for a common case. One could make an argument that we could support arbitrary single-expression try statements this way; I'd be open to that myself, but that's out of scope for this RFC.
Is the semi-colon necessary after the closing '}' ? That reads weird, it’s not clear to me why it’s not a single '}' like after an if or foreach or whatever.
Because using() is an expression, like match() or an anonymous function. Those have semicolons after them as well, because they're not a complete statement, just an expression. The same applies here.
Also, this semi-colon is missing in at least one example.
Which one?
In the transaction example, $conn does not exist, I suppose both instances should be $this?
You are correct, fixed. Thanks.
Quoted text · 15 lines
«A return statement inside the BODY will return from the function the code is currently executing in. A finally block in the generator context manager will still be executed, but otherwise control returns to the function's caller.»
This is also hard to get for me.
Can you detail what this would output:
functioncontext(): \Generator {
echo "A\n";
yield "B";
echo "C\n";
return "D";
}
var_dump(
using (context() => $c) {
echo "E\n";
return "F";
}
);
I believe (without actually running it) that would output:
A
E
The return "F" terminates the function that the var_dump()/using() construct is in. The generator is discarded without ever reaching its end, so the generator's return statement is never reached.
That said, you have brought up an interesting question, I have no idea what happens when you var_dump() a compound expression like this that returns. Something for Arnaud to write tests for. 0:-)
--Larry Garfield
Quoted text · 21 lines
«A return statement inside the BODY will return from the function the code is currently executing in. A finally block in the generator context manager will still be executed, but otherwise control returns to the function's caller.»
This is also hard to get for me.
Can you detail what this would output:
functioncontext(): \Generator {
echo "A\n";
yield "B";
echo "C\n";
return "D";
}
var_dump(
using (context() => $c) {
echo "E\n";
return "F";
}
);I believe (without actually running it) that would output:
A
EThe return "F" terminates the function that the
var_dump()/using() construct is in. The generator is discarded without ever reaching its end, so the generator's return statement is never reached.That said, you have brought up an interesting question, I have no idea what happens when you
var_dump()a compound expression like this that returns. Something for Arnaud to write tests for. 0:-)--Larry Garfield
Actually I'm wrong. I checked with Arnaud, and it will print A E C.
When you return from the CM block, the generator is first resumed so that it gets a chance to do its cleanup, in this case printing C. When it completes, then the function return happens. The var_dump() is never called, because the function returned before that happened.
I have reworded the RFC a bit to make that clearer. Thanks for calling it out.
--Larry Garfield
Hi Larry,
On Fri, Nov 13, 2026 at 3:21 PM Larry Garfield larry@garfieldtech.com wrote:
Quoted text · 7 lines
Hi folks. Based on the feedback and problems with the previous Context Managers RFC, Arnaud and I have a new approach to present:
https://wiki.php.net/rfc/context-managers-v2
It basically swaps the two-method approach in favor of "it's a generator, you're welcome." The result is, I think, both simpler and more flexible, and resolves a number of other issues as well. More details in the RFC.
There is a linked implementation, though Arnaud warns it's only partially complete so go easy on it. :-) But the design in the RFC is all ready for review.
--
Larry Garfield
larry@garfieldtech.com
Some feedback on the current RFC draft
- The behavior section says
When a using expression is encountered, the GENERATOR is first evaluated to
ensure it is a Generator object. If it is not, an Error is thrown. (See the
section below regarding resources, however.)
Can you include some mention of ContextManager here, since GENERATOR can be
evaluated to a ContextManager that is then called to get the generator.
- I'm wondering about what happens if the generator throws an exception. Specifically, it could throw after yielding, but before it terminates, i.e. when it resumes execution after the BODY finishes, returns, or throws.
Looking at the "Implementation details" example desugaring, it seems like that
exception would just be silently ignored, but I don't see that anywhere in the
specification.
-
A number of other things trigger errors, but for generators that yield with
keys, the keys are just silently ignored - did you consider throwing an error
for that too? -
I'd prefer to not add special syntax for this in try-catch, it looks like it
just saves 3 characters (opening{, closing};) plus any whitespace that the developer wants, and it looks a bit odd to me. We can always add this later
if it becomes a common pattern. It also means that the returned value from the
using block cannot be stored anywhere. -
Speaking of the returned value from the using block, can you confirm that
NoDiscardwill be handled properly? Consider a modified version of thefile_for_writingfunction given as an example:
/** Returns true if everything succeeded, and false otherwise */
#[\NoDiscard('as failures should be handled')]
function file_for_write(string $file)
{
$fp = fopen($file, 'w');
if ($fp) {
try {
yield $fp;
// If this line is reached, then the `using` didn't throw an
exception
return true;
} catch (\Exception $e) {
log('The file failed.');
} finally {
fclose($fp);
}
}
// Either `fopen()` didn't succeed, or it succeeded but the `using`
block
// had an exception.
return false;
}
for the example
using (file_for_write('file.txt') => $fp) {
foreach ($someThing as $value) {
fwrite($fp, serialize($value));
}
};
the returned value from file_for_write isn't used and should trigger a warning.
- Is there a way for the generator to specify that the yielded value should
not be discarded? The current RFC text says
If no VAR is specified, the yielded value is ignored.
and while NoDiscard would highlight the ignoring for a function return, it doesn't for generator yields.
Thanks,
-Daniel
Quoted text · 4 lines
Some feedback on the current RFC draft
- The behavior section says
When a using expression is encountered, the GENERATOR is first evaluated to ensure it is a Generator object. If it is not, an Error is thrown. (See the section below regarding resources, however.)
Can you include some mention of
ContextManagerhere, since GENERATOR can be evaluated to aContextManagerthat is then called to get the generator.
Adjusted the language.
- I'm wondering about what happens if the generator throws an exception. Specifically, it could throw after yielding, but before it terminates, i.e. when it resumes execution after the BODY finishes, returns, or throws.
Looking at the "Implementation details" example desugaring, it seems like that exception would just be silently ignored, but I don't see that anywhere in the specification.
It wouldn't be ignored. It would be treated like any other exception thrown by a generator. If it's inside a try block inside the generator, it would be catchable by any catch block in the generator. If none catch it, then it would propagate up to higher callers like any other exception, possibly triggering a finally block along the way.
If the generator wants to handle exceptions it throws differently from exceptions thrown by the context block, it's welcome to do so by having its own exception type/interface to catch. All of this is standard exception handling logic, nothing new introduced.
- A number of other things trigger errors, but for generators that yield with keys, the keys are just silently ignored - did you consider throwing an error for that too?
We considered that quite a bit, actually. The issue is that right now, the keys would do nothing. Checking for a key, however, requires checking if that value is non-numeric, even though it should be the default 0 in every case. That's a small but existing performance overhead. Basically, it comes down to two options:
-
We assume that no one is going to try to make the key do something in the future, so save the overhead and ignore it.
-
We assume that someone is going to find a use for the yielded key in the future, so make it an error for now despite the cost, so there's no BC impact in the future.
For the moment, we've gone with the first option. If someone has a compelling idea for what to do with the key, now or in the future, that would justify taking the second option.
- I'd prefer to not add special syntax for this in try-catch, it looks like it just saves 3 characters (opening
{, closing};) plus any whitespace that the developer wants, and it looks a bit odd to me. We can always add this later if it becomes a common pattern. It also means that the returned value from the using block cannot be stored anywhere.
If someone can figure out a good way to still capture the return value in this case, I'm game for including that now. We just didn't want to pull that thread just yet.
Also, in practice, I expect most using blocks won't have a return value. I could only think of 2-3 examples that would, but lots of examples that don't need one.
Quoted text · 5 lines
- Speaking of the returned value from the using block, can you confirm that
NoDiscardwill be handled properly? Consider a modified version of thefile_for_writingfunction given as an example:/** Returns true if everything succeeded, and false otherwise */ #[\NoDiscard('as failures should be handled')] function file_for_write(string $file) { $fp = fopen($file, 'w'); if ($fp) { try { yield $fp; // If this line is reached, then the `using` didn't throw an exception return true; } catch (\Exception $e) { log('The file failed.'); } finally { fclose($fp); } } // Either `fopen()` didn't succeed, or it succeeded but the `using` block // had an exception. return false; }for the example
using (file_for_write('file.txt') => $fp) { foreach ($someThing as $value) { fwrite($fp, serialize($value)); } };the returned value from
file_for_writeisn't used and should trigger a warning.
That seems reasonable; I'll have to confirm with Arnaud that we can implement that.
- Is there a way for the generator to specify that the yielded value should not be discarded? The current RFC text says
If no VAR is specified, the yielded value is ignored.
and while
NoDiscardwould highlight the ignoring for a function return, it doesn't for generator yields.
I don't believe so. The language has no mechanism for that at present. I suppose, maybe NoDiscard could be expanded to mean both the return and the yielded value? I don't know if that's wise...
I don't have strong feelings on it, but if someone thinks this is an important feature please suggest a way it could be done.
--Larry Garfield
Quoted text · 5 lines
the returned value from
file_for_writeisn't used and should trigger a warning.That seems reasonable; I'll have to confirm with Arnaud that we can implement that.
- Is there a way for the generator to specify that the yielded value should not be discarded? The current RFC text says
If no VAR is specified, the yielded value is ignored.
and while
NoDiscardwould highlight the ignoring for a function return, it doesn't for generator yields.
Update here: this is actually not feasible for either the return or yield, because right now, generators don't do that. A #[NoDiscard] on a generator function means "don't discard the generator object," and says nothing about the return or yield. Changing that means changing the behavior of NoDiscard, which is out of scope, and would also impact performance.
I've added a note to Rejected Features on this front.
--Larry Garfield