Skip to content

Commit 2c6d446

Browse files
committed
Auto merge of #103761 - chenyukang:yukang/fix-103320-must-use, r=compiler-errors
Add explanatory message for [#must_use] in ops Fixes #103320
2 parents 26b2242 + 3b07fa4 commit 2c6d446

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

core/src/ops/arith.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ pub trait Add<Rhs = Self> {
8686
/// ```
8787
/// assert_eq!(12 + 1, 13);
8888
/// ```
89-
#[must_use]
89+
#[must_use = "this returns the result of the operation, without modifying the original"]
90+
#[rustc_diagnostic_item = "add"]
9091
#[stable(feature = "rust1", since = "1.0.0")]
9192
fn add(self, rhs: Rhs) -> Self::Output;
9293
}
@@ -195,7 +196,8 @@ pub trait Sub<Rhs = Self> {
195196
/// ```
196197
/// assert_eq!(12 - 1, 11);
197198
/// ```
198-
#[must_use]
199+
#[must_use = "this returns the result of the operation, without modifying the original"]
200+
#[rustc_diagnostic_item = "sub"]
199201
#[stable(feature = "rust1", since = "1.0.0")]
200202
fn sub(self, rhs: Rhs) -> Self::Output;
201203
}
@@ -325,7 +327,8 @@ pub trait Mul<Rhs = Self> {
325327
/// ```
326328
/// assert_eq!(12 * 2, 24);
327329
/// ```
328-
#[must_use]
330+
#[must_use = "this returns the result of the operation, without modifying the original"]
331+
#[rustc_diagnostic_item = "mul"]
329332
#[stable(feature = "rust1", since = "1.0.0")]
330333
fn mul(self, rhs: Rhs) -> Self::Output;
331334
}
@@ -459,7 +462,8 @@ pub trait Div<Rhs = Self> {
459462
/// ```
460463
/// assert_eq!(12 / 2, 6);
461464
/// ```
462-
#[must_use]
465+
#[must_use = "this returns the result of the operation, without modifying the original"]
466+
#[rustc_diagnostic_item = "div"]
463467
#[stable(feature = "rust1", since = "1.0.0")]
464468
fn div(self, rhs: Rhs) -> Self::Output;
465469
}
@@ -562,7 +566,8 @@ pub trait Rem<Rhs = Self> {
562566
/// ```
563567
/// assert_eq!(12 % 10, 2);
564568
/// ```
565-
#[must_use]
569+
#[must_use = "this returns the result of the operation, without modifying the original"]
570+
#[rustc_diagnostic_item = "rem"]
566571
#[stable(feature = "rust1", since = "1.0.0")]
567572
fn rem(self, rhs: Rhs) -> Self::Output;
568573
}
@@ -678,7 +683,8 @@ pub trait Neg {
678683
/// let x: i32 = 12;
679684
/// assert_eq!(-x, -12);
680685
/// ```
681-
#[must_use]
686+
#[must_use = "this returns the result of the operation, without modifying the original"]
687+
#[rustc_diagnostic_item = "neg"]
682688
#[stable(feature = "rust1", since = "1.0.0")]
683689
fn neg(self) -> Self::Output;
684690
}

0 commit comments

Comments
 (0)