-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
#[must_use = false] #3737
base: master
Are you sure you want to change the base?
#[must_use = false] #3737
Conversation
Maybe it is better to use positive logic. not negative and have Your RFC number is lucky :) |
|
||
Yet another "opt-in/opt-out" dance, similar to `#[non_exhaustive]`. | ||
|
||
The usecase is fairly niche. |
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.
The usecase is fairly niche. | |
The use case is fairly niche. |
I don't really like this approach because, well, error handling exists for a reason. If the error doesn't matter in a large number of cases, then you should just unwrap it or panic instead of returning it, not outright ignore it. This also means that people who do want to be pedantic about errors no longer get notified if they forget to use them. Basically, I think the solution should be to offer methods which don't return an error and then say what they do instead in their name (unchecked, panicking, etc.) rather than returning an error which can be ignored. |
This isn't quite natural English, and honestly, the false flag makes the most sense; any other way of saying "this was marked as must use, but doesn't have to be used" is going to be longer to say and this feels very discoverable. |
I think it's probably a bad idea for things returning It'd help to have an example other than |
This would be especially interesting if Rust supported making every function |
This would mean that we must use I do see where you're coming from, but I do think that it's very important to clarify what you mean by "a small minority of functions" because that's extremely difficult to quantify. I would hesitate to make any sweeping claims about this without actually searching through some kind of dataset. |
Co-authored-by: Josh Triplett <[email protected]>
Co-authored-by: Josh Triplett <[email protected]>
also, this was marked as a future possibility, either via editions or putting |
Generally this is useful for any |
That's fair, although generally, iterator types aren't marked I think that a good example would be one where a type is marked To be clear, I think that the feature is perfectly reasonable and well-defined; I just am not sure that it would actually solve a problem as much as it'd encourage people to ignore return values they really shouldn't. |
That's an exception, if you look at any other iterator, such as
I feel like "it feels wrong" is not very useful feedback.
this is a tool for library authors, not really for applications. If an application author wants to ignore the |
Right, I guess that it's weird that the iterator as marked this way instead of the method, but I wouldn't necessarily say that this is an "exception rather than the rule." If an adapter is only returned by one method, then it kind of doesn't matter whether you mark the type or the method, although it does effect downstream uses of that adapter. Perhaps that's a good reason to not mark the adapters as Like, yes, I acknowledge that this would solve this problem now without a change to the standard library, but considering how we're now proposing a language change, it feels worth considering whether a standard library change and an ecosystem change would be more fitting.
It's not just that it feels wrong: the point of returning a
I mean, this kind of feels like an either/or situation, since within each binary application is a library application too. I can see a lot of users choosing to add this to helper methods for their applications alongside the actual application (generally, you have more than just The reason why I mention that case is because it feels much more likely of a use case: if only one application is using a function, then they can tailor the benefits to that one application. Whereas a library has to assume what all of its users want, which feels like a more difficult call to make. Again, my point is: if a return value is not necessarily useful, why return it at all? If you're expecting users to ignore the entire return value, then it's likely that you have a The point here is that |
my point was that you said most iterators had the annotation on the constructor, while the reality is contrary to this fact. also, it's worth noting that lints are a compiler feature, not a language feature.
it has never been possible to force a The point of returning a
what sort of helper method are you imagining where ignoring the return value is
and if the Ok value of the Result is not ()?
This is your interpretation of the type, but I have seen no evidence that this is the intent. If anything, this semantic seems to be a side effect of the must_use annotation on Result. |
This comment was marked as resolved.
This comment was marked as resolved.
I find the proposal unconvincing because I find the use-case unconvincing, and I just want to pick up on this statement to explain that:
My interpretation of a function returning So, with that in mind, when I read the RFC's motivation:
I don't agree that this motivates That said, if there are example use-cases where it is clear that a |
I did recently have a situation where this could have been useful. pub fn main() {
must_not_use();
}
fn must_not_use() -> impl Future<Output = ()> {
async {
println!("this future does not have to be used");
}
} Some futures do not need to be used, such as various JoinHandle-like types. Implementing those kind of types yourself always requires an explicit wrapper type to be able to get rid of the must_use annotation, even when technically |
and some classes of a error, "do nothing" is a perfectly fine error recovery routine
you misunderstand me, i don't mean "will be correct for almost all calls" i mean "will be most correct in almost all hypothetical call sites"
do you mean "remove it from the types"? this entire proposal is "let functions remove |
Allow annotating functions with
#[must_use = false]
to suppress any warning generated due to its return type being marked as#[must_use]
.Pre-RFC on IRLO
Rendered