rust/library/core/src
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
..
alloc Deny broken intra-doc links in linkchecker 2020-10-15 20:22:16 -04:00
array Rollup merge of #78716 - est31:array_traits, r=Dylan-DPC 2020-11-05 10:29:46 +01:00
char Use matches! for core::char methods 2020-10-05 22:29:07 +08:00
convert Rollup merge of #77339 - fusion-engineering-forks:tryfrom-nonzero-to-nonzero, r=dtolnay 2020-10-23 18:26:16 +09:00
fmt Convert a bunch of intra-doc links 2020-11-07 12:50:57 -08:00
future Fix even more URLs 2020-11-05 20:11:29 +01:00
hash fix aliasing issues in SipHasher 2020-10-31 16:26:06 +01:00
iter Convert a bunch of intra-doc links 2020-11-07 12:50:57 -08:00
macros Bad grammar 2020-11-09 23:52:33 +08:00
mem fix aliasing issues in u128 formatting code 2020-10-31 16:26:06 +01:00
num Rollup merge of #77640 - ethanboxx:int_error_matching_attempt_2, r=KodrAus 2020-11-09 01:13:25 +01:00
ops documentation examples fixes in rustfmt convention 2020-11-01 18:53:22 +05:30
prelude mv std libs to library/ 2020-07-27 19:51:13 -05:00
ptr Improve wording of core::ptr::drop_in_place docs 2020-10-29 20:09:29 -07:00
slice Fix automatic_links warnings 2020-11-05 10:22:08 +01:00
str Rollup merge of #78606 - autarch:patch-1, r=m-ou-se 2020-11-02 14:14:33 +09:00
sync Rollup merge of #78728 - a1phyr:const_cell_into_inner, r=dtolnay 2020-11-08 13:36:14 +01:00
task Rollup merge of #76227 - CDirkx:const-poll, r=KodrAus 2020-11-08 13:35:58 +01:00
unicode mv std libs to library/ 2020-07-27 19:51:13 -05:00
any.rs update tracking issue for const_type_id 2020-09-24 09:00:04 +10:00
ascii.rs Fixed some intra-docs links in library/core 2020-09-18 07:49:29 +08:00
bool.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
borrow.rs Remove AsRef link as it is in the prelude 2020-08-10 20:29:20 +02:00
cell.rs Rollup merge of #78852 - camelid:intra-doc-bonanza, r=jyn514 2020-11-08 13:36:28 +01:00
clone.rs Improve readability 2020-09-01 19:56:32 +02:00
cmp.rs Convert a bunch of intra-doc links 2020-11-07 12:50:57 -08:00
default.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
ffi.rs Properly define va_arg and va_list for aarch64-apple-darwin 2020-10-25 21:37:01 -04:00
hint.rs Stabilize hint::spin_loop 2020-11-06 23:41:55 +08:00
internal_macros.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
intrinsics.rs Fix links to stabilized versions of some intrinsics 2020-11-09 00:00:00 +00:00
lazy.rs Capitalize safety comments 2020-09-08 22:26:44 -04:00
lib.rs Rollup merge of #77640 - ethanboxx:int_error_matching_attempt_2, r=KodrAus 2020-11-09 01:13:25 +01:00
marker.rs Use Self more in core in doc when possible 2020-09-23 00:16:16 +02:00
option.rs add tracking issue number to option_insert feature gate 2020-10-23 11:44:58 +02:00
panic.rs Auto merge of #76157 - ArekPiekarz:const_caller_location_tracking_issue, r=joshtriplett 2020-09-06 20:27:51 +00:00
panicking.rs Fix const core::panic!(non_literal_str). 2020-10-22 18:41:35 +02:00
pin.rs Add tracking issue number for pin_static_ref. 2020-10-21 16:30:41 +02:00
primitive.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
raw.rs Use intra-doc-links in core::{raw, ffi, pin} 2020-08-22 22:25:27 +02:00
result.rs Use intra-doc links for links to module-level docs 2020-10-12 19:22:47 -07:00
time.rs Remove Duration::MIN entirely 2020-10-27 15:48:58 -07:00
tuple.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
unit.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00