14
all 25 comments
sorted by: hot top new old
[-] TehPers@beehaw.org 4 points 2 weeks ago* (last edited 2 weeks ago)

Unless you depend on exactly 0.2.0 and not 0.2.x, it's still not semver compatible. Any patch increments in 0.2.x would be reflected whenever someone who depends on 0.1.1 updates their dependencies.

These numbers aren't super helpful, so suppose you have 1.0.0, then release 2.0.0 and 1.0.1 simultaneously (where MainStruct is identical to before, and 1.0.1 reexports it from 2.0.0). If 2.1.0 comes around and adds a ton to MainStruct then that could be reflected in 1.0.1 if you don't pin the dependency to exactly 2.0.0.

[-] BB_C@programming.dev 2 points 2 weeks ago

If 2.1.0 comes around and adds a ton to MainStruct

then you broke semver even if tricks aren't involved. You could nuke the whole crate in v2.0.1 too. But that's effectively an "If my grandmother had wheels, she would've been a bike" type of argument.

[-] TehPers@beehaw.org 2 points 2 weeks ago* (last edited 2 weeks ago)

Broke semver how, exactly?

To quote semver.org:

Given a version number MAJOR.MINOR.PATCH, increment the:

  1. MAJOR version when you make incompatible API changes
  2. MINOR version when you add functionality in a backward compatible manner
  3. PATCH version when you make backward compatible bug fixes

But that's effectively an "If my grandmother had wheels, she would've been a bike" type of argument.

???

[-] BB_C@programming.dev 2 points 2 weeks ago* (last edited 2 weeks ago)

adds a ton to MainStruct

What did you mean by this?

(I expect people to know this. But for those who don't, cargo differs from semver.org for 0.y.z, where MINOR is effectively treated like MAJOR).

[-] TehPers@beehaw.org 1 points 2 weeks ago* (last edited 2 weeks ago)

What did you mean by this?

Adding some amount of additional functionality, like new methods or struct members (under the assumption the struct previously had nonpublic members of course). Maybe even new trait impls if you don't consider new trait impls to be breaking (most of the ecosystem doesn't even though it technically is).

These changes would all be reflected in 1.0.1 if someone updated the transitive dependency from 2.0.0 to 2.1.0.

One would likely assume user of v1.0.1 doesn't really know or care about the semver "hack" going on and just doesn't expect v1.0.1 of the library to change over time or between environments.

Users upgrading from 1.0.0 to 1.0.1 would also see these non-patch changes.

(I expect people to know this. But for those who don't, cargo differs from semver.org for 0.y.z, where MINOR is effectively treated like MAJOR).

This is why I switched the version numbers in my example, but I think you caught onto that.

[-] BB_C@programming.dev 1 points 2 weeks ago* (last edited 2 weeks ago)

Edit: if this is about MINOR leaking into PATCH, that's not a problem since you can select a dependency version range (e.g. "2.0.0-rc, <2.1.0")

~~Can you explain this part?~~

~~Unless you depend on exactly 0.2.0 and not 0.2.x, it’s still not semver compatible.~~

[-] TehPers@beehaw.org 2 points 2 weeks ago

Responding to the edit:

Edit: if this is about MINOR leaking into PATCH, that's not a problem since you can select a dependency version range (e.g. "2.0.0-rc, <2.1.0")

Correct, this was my point. Pinning the exact version is simpler, but you can constrain the range like this as well to avoid semver issues.

However, by not pinning to an exact version, your reexport may vary between installs despite the user using the same v1.0.1 version of your package, which may be unexpected and arguably violates the purpose of having immutable versions in crates.io. The user can manually install both version 1.0.1 and, for example, version 2.0.0 to avoid it changing unexpectedly (though Cargo.lock will also prevent it from changing once it's been set), but that makes less sense than just copying the struct to 1.0.1 rather than reexporting.

Plus, the whole point (in the article) was to make the transition easier within the ecosystem by avoiding a split between major versions. If v1.0.1 depends only on a subset of v2's versions, then you still get a split between, say, [1.0.1, 2.1.0) and [2.1.0,).

[-] BB_C@programming.dev 1 points 1 week ago

However, by not pinning to an exact version, your reexport may vary between installs despite the user using the same v1.0.1 version of your package, which may be unexpected and arguably violates the purpose of having immutable versions in crates.io.

Re-exports exist outside of trick usage. num re-exports from num-* crates without exact version dependency restrictions, just to provide one major example.

If v1.0.1 depends only on a subset of v2’s versions, then you still get a split between, say, [1.0.1, 2.1.0) and [2.1.0,).

You can still release 1.1.x tracking 2.1.x, 1.2.x tracking 2.2.x, ..etc to satisfy your restrictions 😉

But as the sibling comment pointed out. People don't care about MINOR vs PATCH that much anyway. And the point of the trick is to smooth over a transition period, not keep the split forever.

under the assumption the struct previously had nonpublic members of course

Just for the sake of... exhaustiveness 😉, you can use #[non_exhaustive] on structs too.

[-] TehPers@beehaw.org 1 points 1 week ago* (last edited 1 week ago)

Just for the sake of... exhaustiveness 😉, you can use #[non_exhaustive] on structs too.

I was under the impression that this worked on structs by creating hidden fields, though that might not/no longer be true. Anyway, this is why I felt no need to specify it.

Edit: Also, with regards to reexports, num crates are versioned separately and do different things. A better comparison is serde (which pins an exact serde_core version) or tokio (which uses a ~ specifier for its macros). rand relies on rand_core@^0.10.0, but these are 0.x so it's still technically [0.10.0, 0.11.0) which isn't as bad and hence why I changed the versions in my example.

[-] TehPers@beehaw.org 1 points 2 weeks ago

If you exactly copy 0.1.0 MainStruct to 0.2.0, there are no breaking changes in the struct when you reexport it from 0.1.1.

Even if you make minor changes, it still follows semver from 0.1.0 -> 0.1.1.

If 0.2.1 introduces changes to MainStruct, then 0.1.1 can reexport those changes unless you pin 0.1.1 to exactly version 0.2.0 (which should never change).

It was harder to visualize with 0.y.z versions, so I switched to x.y.z versions to make it easier to explain further down my post.

[-] sgued@programming.dev 1 points 1 week ago

That would indeed be a significant change, but only matter when you run cargo update.

Pretty much no-one in the Rust ecosystem relies on the distinction between minor and patch version releases. Serde (and all of dtolnay's stuff) famously only publish major.0.minor version numbers.

[-] TehPers@beehaw.org 2 points 1 week ago

Serde (and all of dtolnay's stuff) famously only publish major.0.minor version numbers.

Infamously*. It's been the source of more than one argument lol. Not that I'm going to go tell him he's doing it wrong though since serde is great still.

But it's an overstatement to say that "pretty much no-one" relies on major/minor. Most packages make an attempt to follow semver rules around major/minor. Dtolnay is one of the few exceptions.

[-] sgued@programming.dev 1 points 1 week ago

I didn't say people don't make an effort to follow minor vs patch. I said people don't rely on it.

[-] blazebra@programming.dev 4 points 1 week ago* (last edited 1 week ago)

Major.minor.patch, but with if major is 0, it will be ignored, so minor.patch will be threaded as major.minor.0 (removing leading 0) in terms of breaking changes, but it’s still considered less than 1.0.0.

These rules are clearly written in Rust/Python/NodeJS and other descriptions of “semver”, which are older than the website and their contents.

All update tools including renovatebot and dependabot support this as well in almost all languages.

[-] sgued@programming.dev 1 points 1 week ago

The example I give is with 0.1.0 0 .2.0 and 0.1.1, but all the examples I give work with respectively 1.0.0, 2.0.0 and 1.1.0

[-] BB_C@programming.dev 3 points 2 weeks ago

Other than releasing both concurrently, you can release 0.2.0-rc, then 0.1.1 depending on the former, then release 0.2.0 (matching 0.2.0-rc API) at your leisure.

[-] sgued@programming.dev 2 points 1 week ago* (last edited 1 week ago)

That's smart thanks!

Still, you have to think about it just as you publish, and you can't "do the semver trick" sometime later.

[-] CameronDev@programming.dev 2 points 2 weeks ago* (last edited 2 weeks ago)

Maybe just don't fuck around and do semver properly? Is that really so hard?

[-] Ephera@lemmy.ml 3 points 2 weeks ago

As the article kind of hints at, doing semver properly can be really painful for libraries that are widely used across the ecosystem.

For example, when the http library jumped from 0.2 to 1.0, we couldn't upgrade the HTTP stack in our application at $DAYJOB for more than half a year, so the web server, gRPC, OpenTelemetry and an HTTP client.
Because some of our dependencies stayed on http 0.2 for that long. And if we tried to upgrade parts of it, those would then use datatypes from http 1.0, which couldn't be passed into libraries that still used http 0.2.

Which was particularly painful, because libraries that had already upgraded to 1.0, of course didn't provide patches for their previous version using 0.2 anymore, so for months we couldn't get security updates for a number of libraries.

So, yeah, I'm now in favor of doing shenanigans with semver to avoid breaking changes where possible, for libraries that are used across much of the ecosystem.

[-] copacetic@discuss.tchncs.de 4 points 2 weeks ago

The actual point here is not really SemVer but to avoid breaking changes. Most devs still underestimate the value of backwards-compatibility.

[-] sgued@programming.dev 2 points 1 week ago

Why do you have to be so aggressive?

[-] CameronDev@programming.dev 2 points 1 week ago

Not my intent, apologies. But the rusts community general inability to do semver properly really grinds my gears...

[-] sgued@programming.dev 2 points 1 week ago

Why? On the contrary, in my experience cargo update is more reliable than the equivalent in any other language.

[-] CameronDev@programming.dev 1 points 1 week ago

Ive run into quite a few packages that have breaking changes in minor bumps. Which happens everywhere, so not rally rust exclusive.

this post was submitted on 19 Nov 2026
14 points (88.9% liked)

Rust

8392 readers
10 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 3 years ago
MODERATORS