Skip to content

Commit

Permalink
Rollup merge of rust-lang#50177 - matthiaskrgr:std_std_replacen__must…
Browse files Browse the repository at this point in the history
…_use, r=oli-obk

mark std::str::replace(,n) as #[must_use]

let x = "a b c c";
x.replacen("c", "d", 2");
might not do what people might think it does.
  • Loading branch information
GuillaumeGomez authored Apr 26, 2018
2 parents c187787 + 5d37ba1 commit 3b49b27
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
#![feature(dropck_eyepatch)]
#![feature(exact_size_is_empty)]
#![feature(fmt_internals)]
#![feature(fn_must_use)]
#![feature(from_ref)]
#![feature(fundamental)]
#![feature(lang_items)]
Expand Down
2 changes: 2 additions & 0 deletions src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ impl str {
/// let s = "this is old";
/// assert_eq!(s, s.replace("cookie monster", "little lamb"));
/// ```
#[must_use]
#[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 @@ -246,6 +247,7 @@ impl str {
/// let s = "this is old";
/// assert_eq!(s, s.replacen("cookie monster", "little lamb", 10));
/// ```
#[must_use]
#[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 3b49b27

Please sign in to comment.