Skip to content

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

Open
@scottmcm

Description

@scottmcm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions