2 This lint warns when a method returning `Self` doesn't have the `#[must_use]` attribute.
5 Methods returning `Self` often create new values, having the `#[must_use]` attribute
6 prevents users from "forgetting" to use the newly created value.
8 The `#[must_use]` attribute can be added to the type itself to ensure that instances
9 are never forgotten. Functions returning a type marked with `#[must_use]` will not be
10 linted, as the usage is already enforced by the type attribute.
13 This lint is only applied on methods taking a `self` argument. It would be mostly noise
14 if it was added on constructors for example.
21 pub fn bar(&self) -> Self {
29 // It's better to have the `#[must_use]` attribute on the method like this:
33 pub fn bar(&self) -> Self {
38 // Or on the type definition like this:
42 pub fn bar(&self) -> Self {