Skip to content

Commit

Permalink
Restore 'must_use' for 'clamp'; fix warning for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Strand committed Sep 5, 2019
1 parent 54cb728 commit 1aa5d0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/libstd/f32.rs
Expand Up @@ -1015,8 +1015,7 @@ impl f32 {
/// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0);
/// assert!((std::f32::NAN).clamp(-2.0, 1.0).is_nan());
/// ```
// The tests below invoke `clamp` without a return value in order to cause a `panic`.
// #[must_use = "method returns a new number and does not mutate the original value"]
#[must_use = "method returns a new number and does not mutate the original value"]
#[unstable(feature = "clamp", issue = "44095")]
#[inline]
pub fn clamp(self, min: f32, max: f32) -> f32 {
Expand Down Expand Up @@ -1631,18 +1630,18 @@ mod tests {
#[test]
#[should_panic]
fn test_clamp_min_greater_than_max() {
1.0f32.clamp(3.0, 1.0);
let _ = 1.0f32.clamp(3.0, 1.0);
}

#[test]
#[should_panic]
fn test_clamp_min_is_nan() {
1.0f32.clamp(NAN, 1.0);
let _ = 1.0f32.clamp(NAN, 1.0);
}

#[test]
#[should_panic]
fn test_clamp_max_is_nan() {
1.0f32.clamp(3.0, NAN);
let _ = 1.0f32.clamp(3.0, NAN);
}
}
9 changes: 4 additions & 5 deletions src/libstd/f64.rs
Expand Up @@ -936,8 +936,7 @@ impl f64 {
/// assert!((2.0f64).clamp(-2.0, 1.0) == 1.0);
/// assert!((std::f64::NAN).clamp(-2.0, 1.0).is_nan());
/// ```
// The tests below invoke `clamp` without a return value in order to cause a `panic`.
// #[must_use = "method returns a new number and does not mutate the original value"]
#[must_use = "method returns a new number and does not mutate the original value"]
#[unstable(feature = "clamp", issue = "44095")]
#[inline]
pub fn clamp(self, min: f64, max: f64) -> f64 {
Expand Down Expand Up @@ -1571,18 +1570,18 @@ mod tests {
#[test]
#[should_panic]
fn test_clamp_min_greater_than_max() {
1.0f64.clamp(3.0, 1.0);
let _ = 1.0f64.clamp(3.0, 1.0);
}

#[test]
#[should_panic]
fn test_clamp_min_is_nan() {
1.0f64.clamp(NAN, 1.0);
let _ = 1.0f64.clamp(NAN, 1.0);
}

#[test]
#[should_panic]
fn test_clamp_max_is_nan() {
1.0f64.clamp(3.0, NAN);
let _ = 1.0f64.clamp(3.0, NAN);
}
}

0 comments on commit 1aa5d0c

Please sign in to comment.