@@ -3489,6 +3489,8 @@ impl str {
3489
3489
///
3490
3490
/// assert_eq!("Hello\tworld", s.trim());
3491
3491
/// ```
3492
+ #[ must_use = "this returns the trimmed string as a slice, \
3493
+ without modifying the original"]
3492
3494
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
3493
3495
pub fn trim ( & self ) -> & str {
3494
3496
self . trim_matches ( |c : char | c. is_whitespace ( ) )
@@ -3524,6 +3526,8 @@ impl str {
3524
3526
/// let s = " עברית ";
3525
3527
/// assert!(Some('ע') == s.trim_start().chars().next());
3526
3528
/// ```
3529
+ #[ must_use = "this returns the trimmed string as a new slice, \
3530
+ without modifying the original"]
3527
3531
#[ stable( feature = "trim_direction" , since = "1.30.0" ) ]
3528
3532
pub fn trim_start ( & self ) -> & str {
3529
3533
self . trim_start_matches ( |c : char | c. is_whitespace ( ) )
@@ -3559,6 +3563,8 @@ impl str {
3559
3563
/// let s = " עברית ";
3560
3564
/// assert!(Some('ת') == s.trim_end().chars().rev().next());
3561
3565
/// ```
3566
+ #[ must_use = "this returns the trimmed string as a new slice, \
3567
+ without modifying the original"]
3562
3568
#[ stable( feature = "trim_direction" , since = "1.30.0" ) ]
3563
3569
pub fn trim_end ( & self ) -> & str {
3564
3570
self . trim_end_matches ( |c : char | c. is_whitespace ( ) )
@@ -3661,6 +3667,8 @@ impl str {
3661
3667
/// ```
3662
3668
/// assert_eq!("1foo1barXX".trim_matches(|c| c == '1' || c == 'X'), "foo1bar");
3663
3669
/// ```
3670
+ #[ must_use = "this returns the trimmed string as a new slice, \
3671
+ without modifying the original"]
3664
3672
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
3665
3673
pub fn trim_matches < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> & ' a str
3666
3674
where P :: Searcher : DoubleEndedSearcher < ' a >
@@ -3706,6 +3714,8 @@ impl str {
3706
3714
/// let x: &[_] = &['1', '2'];
3707
3715
/// assert_eq!("12foo1bar12".trim_start_matches(x), "foo1bar12");
3708
3716
/// ```
3717
+ #[ must_use = "this returns the trimmed string as a new slice, \
3718
+ without modifying the original"]
3709
3719
#[ stable( feature = "trim_direction" , since = "1.30.0" ) ]
3710
3720
pub fn trim_start_matches < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> & ' a str {
3711
3721
let mut i = self . len ( ) ;
@@ -3749,6 +3759,8 @@ impl str {
3749
3759
/// ```
3750
3760
/// assert_eq!("1fooX".trim_end_matches(|c| c == '1' || c == 'X'), "1foo");
3751
3761
/// ```
3762
+ #[ must_use = "this returns the trimmed string as a new slice, \
3763
+ without modifying the original"]
3752
3764
#[ stable( feature = "trim_direction" , since = "1.30.0" ) ]
3753
3765
pub fn trim_end_matches < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> & ' a str
3754
3766
where P :: Searcher : ReverseSearcher < ' a >
0 commit comments