1
Fork 0

Rollup merge of #50177 - matthiaskrgr:std_std_replacen__must_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.
This commit is contained in:
Guillaume Gomez 2018-04-26 10:11:11 +02:00 committed by GitHub
commit 3b49b27e0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 0 deletions

View file

@ -96,6 +96,7 @@
#![feature(dropck_eyepatch)] #![feature(dropck_eyepatch)]
#![feature(exact_size_is_empty)] #![feature(exact_size_is_empty)]
#![feature(fmt_internals)] #![feature(fmt_internals)]
#![feature(fn_must_use)]
#![feature(from_ref)] #![feature(from_ref)]
#![feature(fundamental)] #![feature(fundamental)]
#![feature(lang_items)] #![feature(lang_items)]

View file

@ -207,6 +207,7 @@ impl str {
/// let s = "this is old"; /// let s = "this is old";
/// assert_eq!(s, s.replace("cookie monster", "little lamb")); /// assert_eq!(s, s.replace("cookie monster", "little lamb"));
/// ``` /// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[inline] #[inline]
pub fn replace<'a, P: Pattern<'a>>(&'a self, from: P, to: &str) -> String { pub fn replace<'a, P: Pattern<'a>>(&'a self, from: P, to: &str) -> String {
@ -246,6 +247,7 @@ impl str {
/// let s = "this is old"; /// let s = "this is old";
/// assert_eq!(s, s.replacen("cookie monster", "little lamb", 10)); /// assert_eq!(s, s.replacen("cookie monster", "little lamb", 10));
/// ``` /// ```
#[must_use]
#[stable(feature = "str_replacen", since = "1.16.0")] #[stable(feature = "str_replacen", since = "1.16.0")]
pub fn replacen<'a, P: Pattern<'a>>(&'a self, pat: P, to: &str, count: usize) -> String { pub fn replacen<'a, P: Pattern<'a>>(&'a self, pat: P, to: &str, count: usize) -> String {
// Hope to reduce the times of re-allocation // Hope to reduce the times of re-allocation