rust/library/core/tests
Jonas Schievink 62f0a78056
Rollup merge of #78216 - workingjubilee:duration-zero, r=m-ou-se
Duration::zero() -> Duration::ZERO

In review for #72790, whether or not a constant or a function should be favored for `#![feature(duration_zero)]` was seen as an open question. In https://github.com/rust-lang/rust/issues/73544#issuecomment-691701670 an invitation was opened to either stabilize the methods or propose a switch to the constant value, supplemented with reasoning. Followup comments suggested community preference leans towards the const ZERO, which would be reason enough.

ZERO also "makes sense" beside existing associated consts for Duration. It is ever so slightly awkward to have a series of constants specifying 1 of various units but leave 0 as a method, especially when they are side-by-side in code. It seems unintuitive for the one non-dynamic value (that isn't from Default) to be not-a-const, which could hurt discoverability of the associated constants overall. Elsewhere in `std`, methods for obtaining a constant value were even deprecated, as seen with [std::u32::min_value](https://doc.rust-lang.org/std/primitive.u32.html#method.min_value).

Most importantly, ZERO costs less to use. A match supports a const pattern, but const fn can only be used if evaluated through a const context such as an inline `const { const_fn() }` or a `const NAME: T = const_fn()` declaration elsewhere. Likewise, while https://github.com/rust-lang/rust/issues/73544#issuecomment-691949373 notes `Duration::zero()` can optimize to a constant value, "can" is not "will". Only const contexts have a strong promise of such. Even without that in mind, the comment in question still leans in favor of the constant for simplicity. As it costs less for a developer to use, may cost less to optimize, and seems to have more of a community consensus for it, the associated const seems best.

r? ```@LukasKalbertodt```
2020-11-11 20:58:52 +01:00
..
fmt
hash
num Rollup merge of #77640 - ethanboxx:int_error_matching_attempt_2, r=KodrAus 2020-11-09 01:13:25 +01:00
alloc.rs
any.rs
array.rs Rollup merge of #76454 - poliorcetics:ui-to-unit-test-1, r=matklad 2020-09-28 18:39:39 +02:00
ascii.rs Move various ui const tests to library 2020-09-04 02:35:27 +02:00
atomic.rs
bool.rs
cell.rs Constantify UnsafeCell::into_inner and related 2020-11-04 11:41:57 +01:00
char.rs
clone.rs
cmp.rs Move const tests for Ordering to library\core 2020-09-04 00:40:11 +02:00
intrinsics.rs move test to intergrated test in library/core 2020-09-24 14:46:57 +00:00
iter.rs Test with non-fused iterators 2020-10-06 00:48:34 +02:00
lazy.rs Make OnceCell<T> transparent to dropck 2020-08-18 00:34:54 +02:00
lib.rs Rollup merge of #78728 - a1phyr:const_cell_into_inner, r=dtolnay 2020-11-08 13:36:14 +01:00
manually_drop.rs
mem.rs
nonzero.rs Apply suggested changes 2020-10-26 18:14:12 +00:00
ops.rs Move range in ui test to ops test in library/core 2020-11-05 00:00:44 +09:00
option.rs review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
pattern.rs
pin.rs Make some methods of Pin<&mut T> unstable const 2020-09-18 19:23:50 +02:00
ptr.rs enable align_to tests in Miri 2020-08-19 10:41:51 +02:00
result.rs Auto merge of #76136 - CDirkx:const-result, r=dtolnay 2020-09-20 13:07:11 +00:00
slice.rs Check for exhaustion in SliceIndex for RangeInclusive 2020-10-20 17:18:08 -07:00
str_lossy.rs
str.rs
task.rs Move const tests for Poll to library\core 2020-09-04 01:04:34 +02:00
time.rs Fixup tests: Duration::MIN -> ::ZERO 2020-10-27 13:57:51 -07:00
tuple.rs