Skip to content
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

It would be nice if JoinHandle<T> were must-use for T != () #52062

Open
scottmcm opened this issue Jul 4, 2018 · 2 comments
Open

It would be nice if JoinHandle<T> were must-use for T != () #52062

scottmcm opened this issue Jul 4, 2018 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@scottmcm
Copy link
Member

scottmcm commented Jul 4, 2018

One IRC today, someone had code not working because they were doing

thread::spawn(|| mylib::my_function);

Which of course returns the function rather than running it.

Arguably it's almost always mistake to not keep the JoinHandle if the thread is going to return a non-unit value, since if you didn't care the closure could just be -> (), so this should lint, but AFAIK #[must_use] on the function or type would warn for JoinHandle<()> too today.

Repro link: https://play.rust-lang.org/?gist=fd8973579bf0bf474a7e2b9e135ff946&version=nightly

@Mark-Simulacrum Mark-Simulacrum added A-diagnostics Area: Messages for errors, warnings, and lints T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Jul 7, 2018
@varkor
Copy link
Member

varkor commented Nov 3, 2018

This looks like #48820, which was closed.

@jscinoz
Copy link

jscinoz commented Jan 14, 2019

I think this is subtly different - #48820 was for JoinHandle to be marked with #[must_use] in general, whereas this issue is for the more narrow scenario where the spawned thread returns value (implying that there's something still to be done with this value?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants