-
Notifications
You must be signed in to change notification settings - Fork 13k
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
std::process::Command::spawn could benefit from [must_use] #91428
Comments
I feel like this may be a bad idea, though I'm not entirely sure. In general, |
Probably, like when you know you just want to spawn the subprocess in the background without waiting for it. Maybe someone can make an argument that that's bad practice, but even still, if you add @rustbot label -T-compiler +T-libs |
It isn't strictly speaking a breaking change. On the other hand, that's not the only factor to be considered. There's the user experience element. We don't want to even warn by default unless we think they're likely to be making a mistake, since overwhelming people with warnings makes the language less pleasant to use. Furthermore, if we start generating too many warnings, people may opt out, either of the specific warning (mildly unfortunate) or of all warnings in general (very unfortunate). Of course, the risks for any specific warning are low. Now, it's worth mentioning that this particular lint has a relatively clean and idiomatic way of ignoring it in a specific case: I'd guess the best thing to do is to nominate this for discussion by |
Sorry for the slow reply here holidays got in the way!
There are cases where you'd want to ignore this entirely however I would say they are reasonably rare and I think that the value of being prompted (by a warning) to consider the outcome of your process is probably a reasonable choice.
Even in these situations I think you usually want to at least know the PID (to log or record it somewhere) but I guess that's not an warning condition.
I strongly agree with this. I wouldn't want to spam people if this is the normal, so I would love others thoughts on more use-cases for fire and forget style spawning situations. I am sure they exist but my guess is they are the exception rather than the norm. From my usages in the past I almost always want either:
Other examples from the existing libsOne thing I did after submitting this is compare to:
which both feel like reasonable examples to compare against. Neither currently have |
Hi, thanks for reporting this issue. This issue was very briefly discussed in the libs-api meeting today. This It's very reasonable to want to spawn a process without waiting for it to complete. We shouldn't force (Also note that Based on this, I'm closing this issue. |
I was writing some code that used
Command::new
for 3 commands that I wanted to run in a row and I accidentally copy/pasted code that usedspawn
instead of sayoutput
so my code silently kicked off all 3 commands at the same time and didn't wait for them to exit.I feel like most cases that you call
spawn
you probably should use the return value for that so havingmust_use
on eitherstd::process::command::spawn
or onstd::process::Child
would be an easy way to make it harder to mess up here.Given the following code: (https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=03f37b71d1c7c82b7f137b83d4800db5)
The current output is:
Ideally the output should look like:
I would be happy to make the PR to make this change myself however I am not sure if:
I also wasn't 100% sure what the right category for this was so feel free to move it around.
The text was updated successfully, but these errors were encountered: