Skip to content
Playground(another site)

bynk.duration.unit_agreement

Error A Duration literal's unit does not agree with its number: 1 takes the singular unit, every other number the plural.

A Duration literal uses the unit that agrees with its number: the singular unit with 1 (1.hour, 1.second) and the plural unit with every other number, 0 included (2.hours, 0.seconds). 1.hours and 5.hour read wrongly and give a duration two spellings, so they are refused with a fix that rewrites the unit. The rule reads the literal's own number: a negative duration is the negation of a literal (-1.hour).

Example

fn tick() -> Duration { 1.hours } // ✗ `1` takes the singular unit
fn tick() -> Duration { 1.hour } // ✓

See also

  • Every code in its category, Other, on the diagnostic index.
  • bynk explain bynk.duration.unit_agreement shows the same from the installed toolchain, without a network.