Rust 1.80.0 breaks existing code such as time crate, exposes compatibility snag with type inference 

Rust 1.80.0 breaks existing code such as time crate, exposes compatibility snag with type inference 

The recent release of Rust 1.80.0 broke the very popular time crate, along with other existing code, causing a developer to declare the release “below the level of stability and reliability that Rust should have.”

The issue was caused by a new impl (implementation) of FromIterator added to Box<str>, which had a knock-on impact on Rust code that infers type. Type inference occurs when the compiler deduces the type of a variable by inspecting the value that is assigned to it, allowing more concise code since the type does not need to be declared explicitly. In Rust, this relies on there being only one matching implementation, so when an additional impl was added there were cases when the compiler could no longer infer the type. If the Rust compiler is installed, rustc –explain E0282 will output a detailed explanation of the issue.

One example of code breakage was the time crate, used for date and time handling. The issue was spotted back in May: “Error with rust-nightly: type annotations needed for Box<_>”. Many projects though have dependencies on older versions of the time crate and suffered build failures when Rust 1.80.0 was released a few weeks ago.

One of the impacted projects is NixOS, a popular package management and system configuration tool. “In NixOS, unstable builds (both local and on CI) now fail because of this, and fixing this will require new versions of each of the affected pakages” said another developer, adding that this is difficult because some packages have little active maintenance.

Developer kornel complained on the Rust internals list that type inference breaking in Rust 1.8.0 has not been handled well. “Even though Rust doesn’t count type inference changes as semver-breaking, this is a poor excuse for releasing a change with a widespread impact without any attempt to soften the blow … even the 1.80 release notes didn’t say a word about the incompatibility with one of the most used Rust crates.” He added that the regression was found in more than 5,000 crates.

SemVer or Semantic Versioning is used by the Cargo package manager to determine compatibility between versions.

The 1.8.0 release notes have now been updated, with the comment that “Type inference will fail in some cases due to a new impl of FromIterator for Box<str>. Notably this breaks versions of the `time` crate before 0.3.55, due to no longer inferring the right impl.”

The regression was discussed before the release of 1.8.0 but David Tolnay from the Rust Library API team said it was discussed and agreed that “there’s nothing to change on Rust’s end. Those repos that have an old version of time in a lockfile will need to update that.”

Another Rust contributor asked how the API team “can look at 5400 regressions and say ‘eh, that’s fine’”, voicing support for a recommendation “for a process change regarding inference regressions to be more cautious,” and adding that “It may be a ‘mere’ inference regression, but this impact has been big enough that people are calling it ‘rust 2′”.

Some developers are calling for an update to the Rust compiler that reverts the change.

It is a tough problem, because restricting the Rust team from adding new implementations between major versions is a significant limitation, but this incident shows how easily this can break existing code.