Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ pub(crate) struct ConstItemInteriorMutationsDiag<'tcx> {
pub method_name: Ident,
pub const_name: Ident,
pub const_ty: Ty<'tcx>,
#[label("`{$const_name}` is a interior mutable `const` item of type `{$const_ty}`")]
#[label("`{$const_name}` is an interior mutable `const` item of type `{$const_ty}`")]
pub receiver_span: Span,
#[subdiagnostic]
pub sugg_static: Option<ConstItemInteriorMutationsSuggestionStatic>,
Expand Down
93 changes: 93 additions & 0 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,99 @@ impl Duration {
self.secs as u128 * NANOS_PER_SEC as u128 + self.nanos.as_inner() as u128
}

/// Returns the number of _whole_ weeks contained by this `Duration`.
///
/// The returned value does not include any fractional component
/// corresponding to units less than a week of the duration.
///
/// For this method, one week is defined as 7 days, or 604,800 seconds.
///
/// # Examples
///
/// ```
/// #![feature(duration_extractors)]
/// #![feature(duration_constructors)]
/// use std::time::Duration;
///
/// let duration = Duration::from_days(40);
/// assert_eq!(duration.as_weeks(), 5);
/// ```
#[unstable(feature = "duration_extractors", issue = "165786")]
#[must_use]
#[inline]
pub const fn as_weeks(&self) -> u64 {
self.as_secs() / (SECS_PER_MINUTE * MINS_PER_HOUR * HOURS_PER_DAY * DAYS_PER_WEEK)
}

/// Returns the number of _whole_ days contained by this `Duration`.
///
/// The returned value does not include any fractional component
/// corresponding to units less than a day of the duration.
///
/// For this method, one day is defined as 24 hours, or 86,400 seconds.
///
/// # Examples
///
/// ```
/// #![feature(duration_extractors)]
/// use std::time::Duration;
///
/// let duration = Duration::from_hours(130);
/// assert_eq!(duration.as_days(), 5);
/// ```
#[unstable(feature = "duration_extractors", issue = "165786")]
#[must_use]
#[inline]
pub const fn as_days(&self) -> u64 {
self.as_secs() / (SECS_PER_MINUTE * MINS_PER_HOUR * HOURS_PER_DAY)
}

/// Returns the number of _whole_ hours contained by this `Duration`.
///
/// The returned value does not include any fractional component
/// corresponding to units less than an hour of the duration.
///
/// For this method, one hour is defined as 60 minutes, or 3,600 seconds.
///
/// # Examples
///
/// ```
/// #![feature(duration_extractors_lite)]
/// use std::time::Duration;
///
/// let duration = Duration::from_mins(320);
/// assert_eq!(duration.as_hours(), 5);
/// ```
#[unstable(feature = "duration_extractors_lite", issue = "165784")]
#[must_use]
#[inline]
pub const fn as_hours(&self) -> u64 {
self.as_secs() / (SECS_PER_MINUTE * MINS_PER_HOUR)
}

/// Returns the number of _whole_ minutes contained by this `Duration`.
///
/// The returned value does not include any fractional component
/// corresponding to units less than a minute of the duration.
///
/// For this method, one minute is defined as 60 seconds.
///
/// # Examples
///
/// ```
/// #![feature(duration_extractors_lite)]
/// use std::time::Duration;
///
/// let duration = Duration::from_secs(320);
/// assert_eq!(duration.as_mins(), 5);
/// ```
#[unstable(feature = "duration_extractors_lite", issue = "165784")]
#[must_use]
#[inline]
pub const fn as_mins(&self) -> u64 {
self.as_secs() / SECS_PER_MINUTE
}

/// Computes the absolute difference between `self` and `other`.
///
/// # Examples
Expand Down
2 changes: 2 additions & 0 deletions library/coretests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#![feature(duration_constants)]
#![feature(duration_constructors)]
#![feature(duration_display_seconds)]
#![feature(duration_extractors)]
#![feature(duration_extractors_lite)]
#![feature(exact_div)]
#![feature(exact_size_is_empty)]
#![feature(extend_one)]
Expand Down
24 changes: 24 additions & 0 deletions library/coretests/tests/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,30 @@ fn duration_const() {
const FROM_NANOS_U128: Duration = Duration::from_nanos_u128(NANOS);
assert_eq!(FROM_NANOS_U128, Duration::SECOND);

const WEEKS: u64 = Duration::WEEK.as_weeks();
assert_eq!(WEEKS, 1);

const FROM_WEEKS: Duration = Duration::from_weeks(1);
assert_eq!(FROM_WEEKS, 604_800 * Duration::SECOND);

const DAYS: u64 = Duration::DAY.as_days();
assert_eq!(DAYS, 1);

const FROM_DAYS: Duration = Duration::from_days(1);
assert_eq!(FROM_DAYS, 86400 * Duration::SECOND);

const HOURS: u64 = Duration::HOUR.as_hours();
assert_eq!(HOURS, 1);

const FROM_HOURS: Duration = Duration::from_hours(1);
assert_eq!(FROM_HOURS, 3600 * Duration::SECOND);

const MINUTES: u64 = Duration::MINUTE.as_mins();
assert_eq!(MINUTES, 1);

const FROM_MINUTES: Duration = Duration::from_mins(1);
assert_eq!(FROM_MINUTES, 60 * Duration::SECOND);

const MAX: Duration = Duration::new(u64::MAX, 999_999_999);

const CHECKED_ADD: Option<Duration> = MAX.checked_add(Duration::SECOND);
Expand Down
13 changes: 9 additions & 4 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,12 +1071,17 @@ pub struct IntrinsicTest {
host: TargetSelection,
}

impl IntrinsicTest {
const ALIAS: &'static str = "stdarch-intrinsic-test";
}

impl CommandLineStep for IntrinsicTest {
type Output = ();
const IS_HOST: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.alias("intrinsic-test")
// Not using a path since we don't want this to be part of `./x test library`.
run.alias(Self::ALIAS)
}

fn is_default_step(_builder: &Builder<'_>) -> bool {
Expand All @@ -1087,12 +1092,12 @@ impl CommandLineStep for IntrinsicTest {
let target = run.target;
let builder = run.builder;

let is_explicit =
builder.config.paths.iter().any(|p| p.to_string_lossy() == "intrinsic-test");
let is_explicit = builder.config.paths.iter().any(|p| p.to_string_lossy() == Self::ALIAS);

if target.contains("x86_64-unknown-linux") && builder.config.sde.is_none() && is_explicit {
panic!(
"SDE is required to run intrinsic-test. Please configure `build.sde` in config.toml."
"SDE is required to run {}. Please configure `build.sde` in config.toml.",
Self::ALIAS
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,4 @@ expression: test
- Suite(tests/run-make-cargo)
[Test] test::IntrinsicTest
targets: [x86_64-unknown-linux-gnu]
- Set({intrinsic-test})
- Set({stdarch-intrinsic-test})
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,4 @@ expression: test --skip=coverage
- Suite(tests/run-make-cargo)
[Test] test::IntrinsicTest
targets: [x86_64-unknown-linux-gnu]
- Set({intrinsic-test})
- Set({stdarch-intrinsic-test})
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,4 @@ expression: test --skip=coverage-map
- Suite(tests/run-make-cargo)
[Test] test::IntrinsicTest
targets: [x86_64-unknown-linux-gnu]
- Set({intrinsic-test})
- Set({stdarch-intrinsic-test})
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,4 @@ expression: test --skip=coverage-run
- Suite(tests/run-make-cargo)
[Test] test::IntrinsicTest
targets: [x86_64-unknown-linux-gnu]
- Set({intrinsic-test})
- Set({stdarch-intrinsic-test})
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ expression: test --skip=tests
- Set({compiler-builtins})
[Test] test::IntrinsicTest
targets: [x86_64-unknown-linux-gnu]
- Set({intrinsic-test})
- Set({stdarch-intrinsic-test})
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,4 @@ expression: test --skip=tests/coverage
- Suite(tests/run-make-cargo)
[Test] test::IntrinsicTest
targets: [x86_64-unknown-linux-gnu]
- Set({intrinsic-test})
- Set({stdarch-intrinsic-test})
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,4 @@ expression: test --skip=tests --skip=library --skip=tidyselftest
- Set({compiler-builtins})
[Test] test::IntrinsicTest
targets: [x86_64-unknown-linux-gnu]
- Set({intrinsic-test})
- Set({stdarch-intrinsic-test})
26 changes: 26 additions & 0 deletions tests/ui/lifetimes/where-bound-with-lifetime-53156.current.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: lifetime may not live long enough
--> $DIR/where-bound-with-lifetime-53156.rs:35:9
|
LL | impl<'a, B> OwnedWrap<B>
| -- lifetime `'a` defined here
...
LL | pub fn to_arc_aac(&self) -> Arc<B> {
| - let's call the lifetime of this reference `'1`
LL | let OwnedWrap(ref owned) = *self;
LL | owned.borrow().into()
| ^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'a`

error[E0621]: explicit lifetime required in the type of `wrap`
--> $DIR/where-bound-with-lifetime-53156.rs:135:5
|
LL | owned.borrow().into()
| ^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `wrap`
|
LL | fn to_arc_aac<'a, B>(wrap: &'a OwnedWrap<B>) -> Arc<B>
| ++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0621`.
26 changes: 26 additions & 0 deletions tests/ui/lifetimes/where-bound-with-lifetime-53156.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: lifetime may not live long enough
--> $DIR/where-bound-with-lifetime-53156.rs:35:9
|
LL | impl<'a, B> OwnedWrap<B>
| -- lifetime `'a` defined here
...
LL | pub fn to_arc_aac(&self) -> Arc<B> {
| - let's call the lifetime of this reference `'1`
LL | let OwnedWrap(ref owned) = *self;
LL | owned.borrow().into()
| ^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'a`

error[E0621]: explicit lifetime required in the type of `wrap`
--> $DIR/where-bound-with-lifetime-53156.rs:135:5
|
LL | owned.borrow().into()
| ^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
|
help: add explicit lifetime `'a` to the type of `wrap`
|
LL | fn to_arc_aac<'a, B>(wrap: &'a OwnedWrap<B>) -> Arc<B>
| ++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0621`.
Loading
Loading