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

must_use attribute not used properly #345

Closed
de-sh opened this issue Feb 7, 2022 · 1 comment
Closed

must_use attribute not used properly #345

de-sh opened this issue Feb 7, 2022 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@de-sh
Copy link
Contributor

de-sh commented Feb 7, 2022

Currently, the following warning is shown by the compiler, as the must_use attribute is being applied to a Future and not the actual function that is supposed to be called. A solution had been trialed in #342 but has been deemed not right.

warning: `must_use` attribute on `async` functions applies to the anonymous `Future` returned by the function, not the value within
Warning:    --> rumqttc/src/eventloop.rs:124:5
    |
124 |       #[must_use = "Eventloop should be iterated over a loop to make progress"]
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
125 | /     pub async fn poll(&mut self) -> Result<Event, ConnectionError> {
126 | |         if self.network.is_none() {
127 | |             let (network, connack) = connect_or_cancel(&self.options, &self.cancel_rx).await?;
128 | |             self.network = Some(network);
...   |
143 | |         }
144 | |     }
    | |_____- this attribute does nothing, the `Future`s returned by async functions are already `must_use`
    |
    = note: `#[warn(unused_attributes)]` on by default
@de-sh de-sh added bug Something isn't working help wanted Extra attention is needed labels Feb 7, 2022
@jplatte
Copy link
Contributor

jplatte commented Feb 7, 2022

Both Futures and Results are already #[must_use]. This attribute should simply be removed, there's (unfortunately) no way to show this custom error instead of the ones for Future / Result when the user ignores the future, or its yielded value.

I suppose you could consider making the Event type #[must_use], with a somewhat different message.

@de-sh de-sh closed this as completed Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants