1
Fork 0

Rollup merge of #62860 - vi:stabilize_checked_duration_since, r=Mark-Simulacrum

Stabilize checked_duration_since for 1.38.0

Looks like it has already found some use in projects.

Resolves #58402.
This commit is contained in:
Mazdak Farrokhzad 2019-09-05 03:59:33 +02:00 committed by GitHub
commit ee437eb5d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 7 deletions

View file

@ -244,7 +244,6 @@
#![feature(cfg_target_has_atomic)] #![feature(cfg_target_has_atomic)]
#![feature(cfg_target_thread_local)] #![feature(cfg_target_thread_local)]
#![feature(char_error_internals)] #![feature(char_error_internals)]
#![feature(checked_duration_since)]
#![feature(clamp)] #![feature(clamp)]
#![feature(compiler_builtins_lib)] #![feature(compiler_builtins_lib)]
#![feature(concat_idents)] #![feature(concat_idents)]

View file

@ -221,7 +221,6 @@ impl Instant {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// #![feature(checked_duration_since)]
/// use std::time::{Duration, Instant}; /// use std::time::{Duration, Instant};
/// use std::thread::sleep; /// use std::thread::sleep;
/// ///
@ -231,7 +230,7 @@ impl Instant {
/// println!("{:?}", new_now.checked_duration_since(now)); /// println!("{:?}", new_now.checked_duration_since(now));
/// println!("{:?}", now.checked_duration_since(new_now)); // None /// println!("{:?}", now.checked_duration_since(new_now)); // None
/// ``` /// ```
#[unstable(feature = "checked_duration_since", issue = "58402")] #[stable(feature = "checked_duration_since", since = "1.39.0")]
pub fn checked_duration_since(&self, earlier: Instant) -> Option<Duration> { pub fn checked_duration_since(&self, earlier: Instant) -> Option<Duration> {
self.0.checked_sub_instant(&earlier.0) self.0.checked_sub_instant(&earlier.0)
} }
@ -242,7 +241,6 @@ impl Instant {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// #![feature(checked_duration_since)]
/// use std::time::{Duration, Instant}; /// use std::time::{Duration, Instant};
/// use std::thread::sleep; /// use std::thread::sleep;
/// ///
@ -252,7 +250,7 @@ impl Instant {
/// println!("{:?}", new_now.saturating_duration_since(now)); /// println!("{:?}", new_now.saturating_duration_since(now));
/// println!("{:?}", now.saturating_duration_since(new_now)); // 0ns /// println!("{:?}", now.saturating_duration_since(new_now)); // 0ns
/// ``` /// ```
#[unstable(feature = "checked_duration_since", issue = "58402")] #[stable(feature = "checked_duration_since", since = "1.39.0")]
pub fn saturating_duration_since(&self, earlier: Instant) -> Duration { pub fn saturating_duration_since(&self, earlier: Instant) -> Duration {
self.checked_duration_since(earlier).unwrap_or(Duration::new(0, 0)) self.checked_duration_since(earlier).unwrap_or(Duration::new(0, 0))
} }

View file

@ -2,8 +2,8 @@ use super::*;
#[test] #[test]
fn test_find_attr_val() { fn test_find_attr_val() {
let s = r#"#[unstable(feature = "checked_duration_since", issue = "58402")]"#; let s = r#"#[unstable(feature = "tidy_test_never_used_anywhere_else", issue = "58402")]"#;
assert_eq!(find_attr_val(s, "feature"), Some("checked_duration_since")); assert_eq!(find_attr_val(s, "feature"), Some("tidy_test_never_used_anywhere_else"));
assert_eq!(find_attr_val(s, "issue"), Some("58402")); assert_eq!(find_attr_val(s, "issue"), Some("58402"));
assert_eq!(find_attr_val(s, "since"), None); assert_eq!(find_attr_val(s, "since"), None);
} }