Warnings for breaking semver

I have looked at API evolution document and think that most of the rules can controlled by a robot better than by human.

Maybe Cargo can include some "semver-check" action that will compare API of the library with API of the previous version of the same library and show warnings (about Minor changes unless minor version got incremented and about Major changes unless major version got incremented)?

Cargo can look to Git or to crates.io. Looking to Git has advantage of helping private projects as well as public. Maybe crates.io itself can check it on upload.

If implemented, I think it would be nice idea of turning this on automatically (e.g. on "publish" action) even for library authors that does not thought (or care) about semver at all. The sudden warning from Cargo can make user actually understand better (or even discover for the first time) why one needs semver, as there will be concrete breakage scenario in the author's own library.

Breaking API every time and bumping major number (to stop Cargo complaning) is better than breaking API every time and not incrementing the number.

4 Likes

I thought about this with an intent to put up an RFC some day...
How I see it could be done, is to get a compiler option to output the public API metadata of the crate into a text file that can be checked into a VCS and used for semver checks in later builds. This, of course, means the metadata format has to be stabilized.

Overall I think this would be a great idea, but I would do the checking earlier than a cargo publish to give people a chance to correct version numbers.

The only thing that would probably be difficult is detecting Minor changes since Rust doesn't have fine grained control over publicity of crate contents (yet?). This means not everything marked pub should qualify as a Minor change.

And we'd have to admit it wouldn't be perfect, it'd be hard to detect new features that don't somehow change the public API. But it'd be a cool step forward :slight_smile: