Skip to content

Commit

Permalink
Add explanation for #[must_use] on string replace methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed May 7, 2018
1 parent f8b774f commit a72a080
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ impl str {
/// let s = "this is old";
/// assert_eq!(s, s.replace("cookie monster", "little lamb"));
/// ```
#[must_use]
#[must_use = "this returns the replaced string as a new allocation, \
without modifying the original"]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn replace<'a, P: Pattern<'a>>(&'a self, from: P, to: &str) -> String {
Expand Down Expand Up @@ -247,7 +248,8 @@ impl str {
/// let s = "this is old";
/// assert_eq!(s, s.replacen("cookie monster", "little lamb", 10));
/// ```
#[must_use]
#[must_use = "this returns the replaced string as a new allocation, \
without modifying the original"]
#[stable(feature = "str_replacen", since = "1.16.0")]
pub fn replacen<'a, P: Pattern<'a>>(&'a self, pat: P, to: &str, count: usize) -> String {
// Hope to reduce the times of re-allocation
Expand Down

0 comments on commit a72a080

Please sign in to comment.