Commit 62f0a78
authored
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 #73544 (comment) 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 #73544 (comment) 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```4 files changed
+75
-95
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
120 | 122 | | |
121 | | - | |
122 | | - | |
| 123 | + | |
| 124 | + | |
123 | 125 | | |
124 | 126 | | |
125 | 127 | | |
| |||
166 | 168 | | |
167 | 169 | | |
168 | 170 | | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | 171 | | |
188 | 172 | | |
189 | 173 | | |
| |||
277 | 261 | | |
278 | 262 | | |
279 | 263 | | |
280 | | - | |
| 264 | + | |
281 | 265 | | |
282 | 266 | | |
283 | 267 | | |
| |||
536 | 520 | | |
537 | 521 | | |
538 | 522 | | |
539 | | - | |
| 523 | + | |
540 | 524 | | |
541 | 525 | | |
542 | 526 | | |
543 | 527 | | |
544 | 528 | | |
545 | 529 | | |
546 | | - | |
| 530 | + | |
547 | 531 | | |
548 | 532 | | |
549 | 533 | | |
550 | | - | |
| 534 | + | |
551 | 535 | | |
552 | 536 | | |
553 | 537 | | |
554 | 538 | | |
555 | 539 | | |
556 | 540 | | |
557 | 541 | | |
558 | | - | |
| 542 | + | |
559 | 543 | | |
560 | 544 | | |
561 | 545 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
| 340 | + | |
344 | 341 | | |
345 | 342 | | |
346 | | - | |
347 | | - | |
348 | | - | |
| 343 | + | |
349 | 344 | | |
350 | 345 | | |
351 | 346 | | |
352 | | - | |
| 347 | + | |
353 | 348 | | |
354 | | - | |
| 349 | + | |
355 | 350 | | |
356 | 351 | | |
357 | 352 | | |
358 | | - | |
| 353 | + | |
359 | 354 | | |
360 | | - | |
| 355 | + | |
361 | 356 | | |
362 | 357 | | |
363 | 358 | | |
364 | | - | |
| 359 | + | |
365 | 360 | | |
366 | | - | |
| 361 | + | |
367 | 362 | | |
368 | 363 | | |
369 | 364 | | |
370 | | - | |
| 365 | + | |
371 | 366 | | |
372 | | - | |
| 367 | + | |
373 | 368 | | |
374 | 369 | | |
375 | 370 | | |
376 | | - | |
| 371 | + | |
377 | 372 | | |
378 | | - | |
| 373 | + | |
379 | 374 | | |
380 | 375 | | |
381 | 376 | | |
382 | | - | |
| 377 | + | |
383 | 378 | | |
384 | 379 | | |
385 | 380 | | |
386 | | - | |
| 381 | + | |
387 | 382 | | |
388 | 383 | | |
389 | | - | |
| 384 | + | |
390 | 385 | | |
391 | 386 | | |
392 | | - | |
393 | | - | |
| 387 | + | |
| 388 | + | |
394 | 389 | | |
395 | | - | |
396 | | - | |
| 390 | + | |
| 391 | + | |
397 | 392 | | |
398 | | - | |
399 | | - | |
| 393 | + | |
| 394 | + | |
400 | 395 | | |
401 | | - | |
402 | | - | |
| 396 | + | |
| 397 | + | |
403 | 398 | | |
404 | | - | |
405 | | - | |
| 399 | + | |
| 400 | + | |
406 | 401 | | |
407 | | - | |
408 | | - | |
| 402 | + | |
| 403 | + | |
409 | 404 | | |
410 | | - | |
| 405 | + | |
411 | 406 | | |
412 | 407 | | |
413 | | - | |
| 408 | + | |
414 | 409 | | |
415 | 410 | | |
416 | | - | |
| 411 | + | |
417 | 412 | | |
418 | 413 | | |
419 | | - | |
420 | | - | |
| 414 | + | |
| 415 | + | |
421 | 416 | | |
422 | 417 | | |
423 | 418 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| 260 | + | |
260 | 261 | | |
261 | 262 | | |
262 | 263 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
75 | | - | |
| 74 | + | |
| 75 | + | |
76 | 76 | | |
77 | | - | |
78 | | - | |
| 77 | + | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
85 | | - | |
| 84 | + | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
| 147 | + | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| |||
0 commit comments