Skip to content

New lint: js_sys::Promise returning functions should be must_use #4936

Closed
@silvanshade

Description

@silvanshade

It seems that functions and methods which return js_sys::Promise (e.g., when creating bindings with wasm-bindgen) should probably always be marked as #[must_use]. If you invoke something which returns a Promise and then just discard it, the computation does nothing.

In order to do something useful you either have to pass the resulting Promise on to some other JS computation or convert it to a JsFuture and .await it in some async context.

There could be a lint which suggests that #[must_use] should be added for these cases to remind the user to consume the Promise.

Does this sound like something that would be appropriate as a clippy lint?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions