-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Attribute to annotate functions that implement the for loop protocol #2505
Comments
If it becomes a problem that functions are being used inappropriately, I would prefer to use types to enforce this constraint (for example, by returning a newtype'd boolean). |
I agree with @nikomatsakis fwiw. I'm going to be bold and close this, since we don't have enough data yet to know whether functions not-intended-to-be-used-with-a-for-loop getting accidentally used with a for loop is a problem. We can revisit this later if necessary. |
I'm fine with closing this, but to be clear, I wasn't concerned with people using the wrong functions with for loops. I was more concerned with the documented discoverability of functions that were written with the for loop protocol in mind. For example, someone coming from another language might expect |
@bstrie Ah, ok. I think an external tool that's not part of the compiler could do this, since it's deducible just based on type signatures. |
cope with rustc aborting due to a signal `status.code().unwrap()` will panic when the process is aborted due to a signal. Let's not do that.
It would be nice to be able to quickly determine which functions in a crate are intended to be used with
for
. Name could be something like#[for_protocol]
or#[iterator]
. I suppose this is something that could be detected automatically, but not every function that has the signature to be used with a for loop may be intended to be used with a for loop (if that makes any difference). This attribute could also automatically imply#[inline(always)]
, if that seems desirable.The text was updated successfully, but these errors were encountered: