Skip to content

Commit a8cf3be

Browse files
committed
span: allow ambiguous_negative_literals
This was bad timing. The lang team just stabilized (in nightly) a new deny-by-default lint, named `ambiguous_negative_literals`, which triggers an error for things like `-1.hour()`. While such things can be confusingly ambiguous in some cases, in Jiff, `-1.hour()`, `(-1).hour()` and `-(1.hour())` are all, very intentionally, precisely equivalent. For now we just `allow` the lint. If the lint stays, we'll likely want to recommend allowing it in the Jiff docs. See: rust-lang/rust#121364
1 parent e300355 commit a8cf3be

File tree

9 files changed

+130
-0
lines changed

9 files changed

+130
-0
lines changed

src/civil/date.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,8 @@ impl Date {
13671367
/// # Example: negative spans are supported
13681368
///
13691369
/// ```
1370+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1371+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
13701372
/// use jiff::{civil::Date, ToSpan};
13711373
///
13721374
/// let d = Date::constant(2024, 3, 31);
@@ -1380,6 +1382,8 @@ impl Date {
13801382
/// # Example: error on overflow
13811383
///
13821384
/// ```
1385+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1386+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
13831387
/// use jiff::{civil::Date, ToSpan};
13841388
///
13851389
/// let d = Date::constant(2024, 3, 31);
@@ -1471,6 +1475,8 @@ impl Date {
14711475
/// # Example: negative spans are supported
14721476
///
14731477
/// ```
1478+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1479+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
14741480
/// use jiff::{civil::Date, ToSpan};
14751481
///
14761482
/// let d = Date::constant(2024, 3, 31);
@@ -1484,6 +1490,8 @@ impl Date {
14841490
/// # Example: error on overflow
14851491
///
14861492
/// ```
1493+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1494+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
14871495
/// use jiff::{civil::Date, ToSpan};
14881496
///
14891497
/// let d = Date::constant(2024, 3, 31);
@@ -1535,6 +1543,8 @@ impl Date {
15351543
/// # Example: negative spans are supported
15361544
///
15371545
/// ```
1546+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1547+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
15381548
/// use jiff::{civil::Date, ToSpan};
15391549
///
15401550
/// let d = Date::constant(2024, 3, 31);
@@ -1547,6 +1557,8 @@ impl Date {
15471557
/// # Example: saturation on overflow
15481558
///
15491559
/// ```
1560+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1561+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
15501562
/// use jiff::{civil::Date, ToSpan};
15511563
///
15521564
/// let d = Date::constant(2024, 3, 31);
@@ -1604,6 +1616,8 @@ impl Date {
16041616
/// # Example: negative spans are supported
16051617
///
16061618
/// ```
1619+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1620+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
16071621
/// use jiff::{civil::Date, ToSpan};
16081622
///
16091623
/// let d = Date::constant(2024, 3, 31);
@@ -1616,6 +1630,8 @@ impl Date {
16161630
/// # Example: saturation on overflow
16171631
///
16181632
/// ```
1633+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1634+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
16191635
/// use jiff::{civil::Date, ToSpan};
16201636
///
16211637
/// let d = Date::constant(2024, 3, 31);
@@ -1669,6 +1685,8 @@ impl Date {
16691685
/// # Examples
16701686
///
16711687
/// ```
1688+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1689+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
16721690
/// use jiff::{civil::Date, ToSpan};
16731691
///
16741692
/// let earlier = Date::constant(2006, 8, 24);
@@ -1839,6 +1857,8 @@ impl Date {
18391857
/// # Examples
18401858
///
18411859
/// ```
1860+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1861+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
18421862
/// use jiff::{civil::Date, ToSpan};
18431863
///
18441864
/// let earlier = Date::constant(2006, 8, 24);
@@ -2035,6 +2055,8 @@ impl Date {
20352055
/// When did the most recent Friday the 13th occur?
20362056
///
20372057
/// ```
2058+
/// # // See: https://github.com/rust-lang/rust/pull/121364
2059+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
20382060
/// use jiff::{civil::{Date, Weekday}, ToSpan};
20392061
///
20402062
/// let start = Date::constant(2024, 3, 13);
@@ -2689,6 +2711,8 @@ impl DateDifference {
26892711
/// This shows how to always round "up" towards positive infinity.
26902712
///
26912713
/// ```
2714+
/// # // See: https://github.com/rust-lang/rust/pull/121364
2715+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
26922716
/// use jiff::{civil::{Date, DateDifference}, RoundMode, ToSpan, Unit};
26932717
///
26942718
/// let d1 = "2024-01-15".parse::<Date>()?;

src/civil/datetime.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,8 @@ impl DateTime {
14821482
/// # Example: negative spans are supported
14831483
///
14841484
/// ```
1485+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1486+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
14851487
/// use jiff::{civil::date, ToSpan};
14861488
///
14871489
/// let dt = date(2024, 3, 31).at(19, 5, 59, 999_999_999);
@@ -1496,6 +1498,8 @@ impl DateTime {
14961498
/// # Example: error on overflow
14971499
///
14981500
/// ```
1501+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1502+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
14991503
/// use jiff::{civil::date, ToSpan};
15001504
///
15011505
/// let dt = date(2024, 3, 31).at(13, 13, 13, 13);
@@ -1581,6 +1585,8 @@ impl DateTime {
15811585
/// # Example: negative spans are supported
15821586
///
15831587
/// ```
1588+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1589+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
15841590
/// use jiff::{civil::date, ToSpan};
15851591
///
15861592
/// let dt = date(2024, 3, 31).at(19, 5, 59, 999_999_999);
@@ -1595,6 +1601,8 @@ impl DateTime {
15951601
/// # Example: error on overflow
15961602
///
15971603
/// ```
1604+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1605+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
15981606
/// use jiff::{civil::date, ToSpan};
15991607
///
16001608
/// let dt = date(2024, 3, 31).at(13, 13, 13, 13);
@@ -1642,6 +1650,8 @@ impl DateTime {
16421650
/// # Example: negative spans are supported
16431651
///
16441652
/// ```
1653+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1654+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
16451655
/// use jiff::{civil::date, ToSpan};
16461656
///
16471657
/// let dt = date(2024, 3, 31).at(19, 5, 59, 999_999_999);
@@ -1654,6 +1664,8 @@ impl DateTime {
16541664
/// # Example: saturation on overflow
16551665
///
16561666
/// ```
1667+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1668+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
16571669
/// use jiff::{civil::{DateTime, date}, ToSpan};
16581670
///
16591671
/// let dt = date(2024, 3, 31).at(13, 13, 13, 13);
@@ -1708,6 +1720,8 @@ impl DateTime {
17081720
/// # Example: negative spans are supported
17091721
///
17101722
/// ```
1723+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1724+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
17111725
/// use jiff::{civil::date, ToSpan};
17121726
///
17131727
/// let dt = date(2024, 3, 31).at(19, 5, 59, 999_999_999);
@@ -1720,6 +1734,8 @@ impl DateTime {
17201734
/// # Example: saturation on overflow
17211735
///
17221736
/// ```
1737+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1738+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
17231739
/// use jiff::{civil::{DateTime, date}, ToSpan};
17241740
///
17251741
/// let dt = date(2024, 3, 31).at(13, 13, 13, 13);
@@ -1780,6 +1796,8 @@ impl DateTime {
17801796
/// # Example
17811797
///
17821798
/// ```
1799+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1800+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
17831801
/// use jiff::{civil::date, ToSpan};
17841802
///
17851803
/// let earlier = date(2006, 8, 24).at(22, 30, 0, 0);
@@ -1950,6 +1968,8 @@ impl DateTime {
19501968
/// # Example
19511969
///
19521970
/// ```
1971+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1972+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
19531973
/// use jiff::{civil::date, ToSpan};
19541974
///
19551975
/// let earlier = date(2006, 8, 24).at(22, 30, 0, 0);

src/civil/time.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,8 @@ impl Time {
11801180
/// # Examples
11811181
///
11821182
/// ```
1183+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1184+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
11831185
/// use jiff::{civil::Time, ToSpan};
11841186
///
11851187
/// let t1 = Time::constant(22, 35, 1, 0);
@@ -1267,6 +1269,8 @@ impl Time {
12671269
/// # Examples
12681270
///
12691271
/// ```
1272+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1273+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
12701274
/// use jiff::{civil::Time, ToSpan};
12711275
///
12721276
/// let t1 = Time::constant(22, 35, 1, 0);
@@ -1468,6 +1472,8 @@ impl Time {
14681472
/// Or go backwards every 6.5 hours:
14691473
///
14701474
/// ```
1475+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1476+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
14711477
/// use jiff::{civil::Time, ToSpan};
14721478
///
14731479
/// let start = Time::constant(23, 0, 0, 0);

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ specifiers and other APIs.
575575
#![warn(missing_debug_implementations)]
576576
// Document ALL THE THINGS!
577577
#![deny(missing_docs)]
578+
// See: https://github.com/rust-lang/rust/pull/121364
579+
#![allow(unknown_lints, ambiguous_negative_literals)]
578580

579581
// It should be possible to support other pointer widths, but this library
580582
// hasn't been tested nor thought about much in contexts with pointers less

src/span.rs

+31
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,16 @@ use crate::{
8787
///
8888
/// # Negative spans
8989
///
90+
/// **WARNING:** As of nightly Rust 2024-07-26, negating spans like
91+
/// `-2.hours()` triggers a deny-by-default lint due to an ambiguous negative
92+
/// literal. However, in Jiff's case, this is a false positive. Feel free to
93+
/// `allow` the lint or write the span as `(-2).hours()` or `-(2.hours())`.
94+
///
9095
/// A span may be negative. All of these are equivalent:
9196
///
9297
/// ```
98+
/// # // See: https://github.com/rust-lang/rust/pull/121364
99+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
93100
/// use jiff::{Span, ToSpan};
94101
///
95102
/// let span = -Span::new().days(5);
@@ -118,6 +125,8 @@ use crate::{
118125
/// then all of its units are negative:
119126
///
120127
/// ```
128+
/// # // See: https://github.com/rust-lang/rust/pull/121364
129+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
121130
/// use jiff::ToSpan;
122131
///
123132
/// let span = -5.days().hours(10).minutes(1);
@@ -130,6 +139,8 @@ use crate::{
130139
/// as negative:
131140
///
132141
/// ```
142+
/// # // See: https://github.com/rust-lang/rust/pull/121364
143+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
133144
/// use jiff::ToSpan;
134145
///
135146
/// // It's the same thing.
@@ -541,6 +552,8 @@ use crate::{
541552
/// span positive before converting it to a `Duration`:
542553
///
543554
/// ```
555+
/// # // See: https://github.com/rust-lang/rust/pull/121364
556+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
544557
/// use std::time::Duration;
545558
///
546559
/// use jiff::{Span, ToSpan};
@@ -990,6 +1003,8 @@ impl Span {
9901003
/// # Example
9911004
///
9921005
/// ```
1006+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1007+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
9931008
/// use jiff::ToSpan;
9941009
///
9951010
/// let span = -100.seconds();
@@ -1055,6 +1070,8 @@ impl Span {
10551070
/// # Example
10561071
///
10571072
/// ```
1073+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1074+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
10581075
/// use jiff::ToSpan;
10591076
///
10601077
/// assert!(!2.months().is_negative());
@@ -1072,6 +1089,8 @@ impl Span {
10721089
/// # Example
10731090
///
10741091
/// ```
1092+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1093+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
10751094
/// use jiff::ToSpan;
10761095
///
10771096
/// assert!(!2.months().is_negative());
@@ -1108,6 +1127,8 @@ impl Span {
11081127
/// # Example
11091128
///
11101129
/// ```
1130+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1131+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
11111132
/// use jiff::ToSpan;
11121133
///
11131134
/// let span = 4.days().seconds(8);
@@ -1129,6 +1150,8 @@ impl Span {
11291150
/// happens on overflow.
11301151
///
11311152
/// ```
1153+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1154+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
11321155
/// use jiff::ToSpan;
11331156
///
11341157
/// let span = 4.days().seconds(8);
@@ -1493,6 +1516,8 @@ impl Span {
14931516
/// # Example: negative spans are less than zero
14941517
///
14951518
/// ```
1519+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1520+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
14961521
/// use jiff::ToSpan;
14971522
///
14981523
/// let span1 = -1.second();
@@ -1893,6 +1918,8 @@ impl Span {
18931918
/// the span positive before converting it to a `Duration`:
18941919
///
18951920
/// ```
1921+
/// # // See: https://github.com/rust-lang/rust/pull/121364
1922+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
18961923
/// use std::time::Duration;
18971924
///
18981925
/// use jiff::{civil::date, Span, ToSpan};
@@ -2790,6 +2817,8 @@ impl core::ops::Mul<Span> for i64 {
27902817
/// span positive before converting it to a `Duration`:
27912818
///
27922819
/// ```
2820+
/// # // See: https://github.com/rust-lang/rust/pull/121364
2821+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
27932822
/// use std::time::Duration;
27942823
///
27952824
/// use jiff::{Span, ToSpan};
@@ -3039,6 +3068,8 @@ impl quickcheck::Arbitrary for Span {
30393068
/// # Example
30403069
///
30413070
/// ```
3071+
/// # // See: https://github.com/rust-lang/rust/pull/121364
3072+
/// # #![allow(unknown_lints, ambiguous_negative_literals)]
30423073
/// use jiff::ToSpan;
30433074
///
30443075
/// assert_eq!(5.days().to_string(), "P5d");

0 commit comments

Comments
 (0)