1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 #![warn(unused_must_use)]
15 #[derive(PartialEq, Eq)]
22 fn need_to_use_this_method_value(&self) -> usize {
28 #[must_use = "no side effects"]
29 fn is_even(&self) -> bool;
32 impl EvenNature for MyStruct {
33 fn is_even(&self) -> bool {
39 fn replace(&mut self, substitute: usize) -> usize;
42 impl Replaceable for MyStruct {
43 // ↓ N.b.: `#[must_use]` attribute on a particular trait implementation
44 // method won't work; the attribute should be on the method signature in
45 // the trait's definition.
47 fn replace(&mut self, substitute: usize) -> usize {
48 let previously = self.n;
54 #[must_use = "it's important"]
55 fn need_to_use_this_value() -> bool {
60 need_to_use_this_value(); //~ WARN unused return value
62 let mut m = MyStruct { n: 2 };
63 let n = MyStruct { n: 3 };
65 m.need_to_use_this_method_value(); //~ WARN unused return value
66 m.is_even(); // trait method!
67 //~^ WARN unused return value
69 m.replace(3); // won't warn (annotation needs to be in trait definition)
71 // comparison methods are `must_use`
72 2.eq(&3); //~ WARN unused return value
73 m.eq(&n); //~ WARN unused return value
75 // lint includes comparison operators
76 2 == 3; //~ WARN unused comparison
77 m == n; //~ WARN unused comparison