Skip to content

Commit a72a080

Browse files
committed
Add explanation for #[must_use] on string replace methods
1 parent f8b774f commit a72a080

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/liballoc/str.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ impl str {
207207
/// let s = "this is old";
208208
/// assert_eq!(s, s.replace("cookie monster", "little lamb"));
209209
/// ```
210-
#[must_use]
210+
#[must_use = "this returns the replaced string as a new allocation, \
211+
without modifying the original"]
211212
#[stable(feature = "rust1", since = "1.0.0")]
212213
#[inline]
213214
pub fn replace<'a, P: Pattern<'a>>(&'a self, from: P, to: &str) -> String {
@@ -247,7 +248,8 @@ impl str {
247248
/// let s = "this is old";
248249
/// assert_eq!(s, s.replacen("cookie monster", "little lamb", 10));
249250
/// ```
250-
#[must_use]
251+
#[must_use = "this returns the replaced string as a new allocation, \
252+
without modifying the original"]
251253
#[stable(feature = "str_replacen", since = "1.16.0")]
252254
pub fn replacen<'a, P: Pattern<'a>>(&'a self, pat: P, to: &str, count: usize) -> String {
253255
// Hope to reduce the times of re-allocation

0 commit comments

Comments
 (0)