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

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

Closed
silvanshade opened this issue Dec 22, 2019 · 2 comments
Closed

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

silvanshade opened this issue Dec 22, 2019 · 2 comments

Comments

@silvanshade
Copy link

silvanshade commented Dec 22, 2019

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?

@ghost
Copy link

ghost commented Dec 22, 2019

Why not just apply #[must_use] to js_sys::Promise?

@silvanshade
Copy link
Author

Oh I didn’t realize you could apply #[must_use] directly to types. If that works it would be a better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant