diff options
| author | bors <bors@rust-lang.org> | 2018-04-28 04:14:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-04-28 04:14:12 +0000 |
| commit | 1eb0cef62b3e83bf7ce6bc7d1b99e130648a55e8 (patch) | |
| tree | a421589312b46f56be896405fea3f3b01c3ed228 /src/libcore | |
| parent | ede7f94794213187b7d8984fdd24be6eb6106b96 (diff) | |
| parent | 91aa267eda21be36d7cae43b6809eba63f1aac4c (diff) | |
Auto merge of #50149 - aaronaaeng:master, r=estebank
Added warning for unused arithmetic expressions The compiler now displays a warning when a binary arithmetic operation is evaluated but not used. This resolves #50124 by following the instructions outlined in the issue. The changes are as follows: - Added new pattern matching for unused arithmetic expressions in `src/librustc_lint/unused.rs` - Added `#[must_use]` attributes to the binary operation methods in `src/libcore/internal_macros.rs` - Added `#[must_use]` attributes to the non-assigning binary operators in `src/libcore/ops/arith.rs`
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/ops/arith.rs | 6 | ||||
| -rw-r--r-- | src/libcore/ops/bit.rs | 6 | ||||
| -rw-r--r-- | src/libcore/ops/deref.rs | 1 |
3 files changed, 13 insertions, 0 deletions
diff --git a/src/libcore/ops/arith.rs b/src/libcore/ops/arith.rs index a1f6030428f..a1bc5463f73 100644 --- a/src/libcore/ops/arith.rs +++ b/src/libcore/ops/arith.rs @@ -94,6 +94,7 @@ pub trait Add<RHS=Self> { type Output; /// Performs the `+` operation. + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn add(self, rhs: RHS) -> Self::Output; } @@ -191,6 +192,7 @@ pub trait Sub<RHS=Self> { type Output; /// Performs the `-` operation. + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn sub(self, rhs: RHS) -> Self::Output; } @@ -310,6 +312,7 @@ pub trait Mul<RHS=Self> { type Output; /// Performs the `*` operation. + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn mul(self, rhs: RHS) -> Self::Output; } @@ -433,6 +436,7 @@ pub trait Div<RHS=Self> { type Output; /// Performs the `/` operation. + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn div(self, rhs: RHS) -> Self::Output; } @@ -517,6 +521,7 @@ pub trait Rem<RHS=Self> { type Output = Self; /// Performs the `%` operation. + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn rem(self, rhs: RHS) -> Self::Output; } @@ -601,6 +606,7 @@ pub trait Neg { type Output; /// Performs the unary `-` operation. + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn neg(self) -> Self::Output; } diff --git a/src/libcore/ops/bit.rs b/src/libcore/ops/bit.rs index 02b6f62db6e..3900f365b0a 100644 --- a/src/libcore/ops/bit.rs +++ b/src/libcore/ops/bit.rs @@ -46,6 +46,7 @@ pub trait Not { type Output; /// Performs the unary `!` operation. + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn not(self) -> Self::Output; } @@ -129,6 +130,7 @@ pub trait BitAnd<RHS=Self> { type Output; /// Performs the `&` operation. + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn bitand(self, rhs: RHS) -> Self::Output; } @@ -212,6 +214,7 @@ pub trait BitOr<RHS=Self> { type Output; /// Performs the `|` operation. + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn bitor(self, rhs: RHS) -> Self::Output; } @@ -298,6 +301,7 @@ pub trait BitXor<RHS=Self> { type Output; /// Performs the `^` operation. + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn bitxor(self, rhs: RHS) -> Self::Output; } @@ -385,6 +389,7 @@ pub trait Shl<RHS=Self> { type Output; /// Performs the `<<` operation. + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn shl(self, rhs: RHS) -> Self::Output; } @@ -493,6 +498,7 @@ pub trait Shr<RHS=Self> { type Output; /// Performs the `>>` operation. + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn shr(self, rhs: RHS) -> Self::Output; } diff --git a/src/libcore/ops/deref.rs b/src/libcore/ops/deref.rs index 332d154170f..54eecc82e19 100644 --- a/src/libcore/ops/deref.rs +++ b/src/libcore/ops/deref.rs @@ -77,6 +77,7 @@ pub trait Deref { type Target: ?Sized; /// Dereferences the value. + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] fn deref(&self) -> &Self::Target; } |
