Skip to content

Commit 10d7e82

Browse files
committed
Update to only block * constraints
Also update to a warning-first rollout
1 parent ddd6341 commit 10d7e82

File tree

1 file changed

+43
-25
lines changed

1 file changed

+43
-25
lines changed

text/0000-no-wildcard-deps.md

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ constraints range from accepting exactly one version (`=1.2.3`), to
1111
accepting a range of versions (`^1.2.3`, `~1.2.3`, `>= 1.2.3, < 3.0.0`), to
1212
accepting any version at all (`*`). This RFC proposes to update crates.io to
1313
reject publishes of crates that have compile or build dependencies with
14-
version constraints that have no upper bound.
14+
a wildcard version constraint.
1515

1616
# Motivation
1717

@@ -40,10 +40,13 @@ guarantees have on consumers of libraries.
4040
As an example, consider the [openssl](https://crates.io/crates/openssl) crate.
4141
It is one of the most popular libraries on crates.io, with several hundred
4242
downloads every day. 50% of the [libraries that depend on it](https://crates.io/crates/openssl/reverse_dependencies)
43-
have a wildcard constraint on the version. Almost all of them them will fail
44-
to compile against version 0.7 of openssl when it is released. When that
45-
happens, users of those libraries will be forced to manually override Cargo's
46-
version selection every time it is recalculated. This is not a fun time.
43+
have a wildcard constraint on the version. None of them can build against every
44+
version that has ever been released. Indeed, no libraries can since many of
45+
those releases can before Rust 1.0 released. In addition, almost all of them
46+
them will fail to compile against version 0.7 of openssl when it is released.
47+
When that happens, users of those libraries will be forced to manually override
48+
Cargo's version selection every time it is recalculated. This is not a fun
49+
time.
4750

4851
Bad version restrictions are also "viral". Even if a developer is careful to
4952
pick dependencies that have reasonable version restrictions, there could be a
@@ -77,37 +80,52 @@ build dependencies, but not to dev dependencies. Dev dependencies are only used
7780
when testing a crate, so it doesn't matter to downstream consumers if they
7881
break.
7982

80-
# Detailed design
81-
82-
Alter crates.io's pre-publish behavior to check the version constraints of all
83-
compile and build dependencies, and reject those that have no upper bound. For
84-
example, these would be rejected:
83+
This RFC is not trying to prohibit *all* constraints that would run into the
84+
issues described above. For example, the constraint `>= 0.0.0` is exactly
85+
equivalent to `*`. This is for a couple of reasons:
86+
87+
* It's not totally clear how to precisely define "reasonable" constraints. For
88+
example, one might want to forbid constraints that allow unreleased major
89+
versions. However, some crates provide strong guarantees that any breaks will
90+
be followed by one full major version of deprecation. If a library author is
91+
sure that their crate doesn't use any deprecated functionality of that kind of
92+
dependency, it's completely safe and reasonable to explicitly extend the
93+
version constraint to include the next unreleased version.
94+
* Cargo and crates.io are missing tools to deal with overly-restrictive
95+
constraints. For example, it's not currently possible to force Cargo to allow
96+
dependency resolution that violates version constraints. Without this kind of
97+
support, it is somewhat risky to push too hard towards tight version
98+
constraints.
99+
* Wildcard constraints are popular, at least in part, because they are the
100+
path of least resistance when writing a crate. Without wildcard constraints,
101+
crate authors will be forced to figure out what kind of constraints make the
102+
most sense in their use cases, which may very well be good enough.
85103

86-
* `*`
87-
* `> 0.3`
88-
* `>= 0.3`
104+
# Detailed design
89105

90-
While these would not:
106+
The prohibition on wildcard constraints will be rolled out in stages to make
107+
sure that crate authors have lead time to figure out their versioning stories.
91108

92-
* `>= 0.3, < 0.5`
93-
* `^0.3`
94-
* `~0.3`
95-
* `=0.3.1`
109+
In the next stable Rust release (1.4), Cargo will issue warnings for all
110+
wildcard constraints on build and compile dependencies when publishing, but
111+
publishes those constraints will still succeed. Along side the next stable
112+
release after that (1.5 on December 11th, 2015), crates.io be updated to reject
113+
publishes of crates with those kinds of dependency constraints. Note that the
114+
check will happen on the crates.io side rather than on the Cargo side since
115+
Cargo can publish to locations other than crates.io which may not worry about
116+
these restrictions.
96117

97118
# Drawbacks
98119

99120
The barrier to entry when publishing a crate will be mildly higher.
100121

101-
In theory, there could be contexts where an unbounded version constraint is
102-
actually appropriate?
122+
Tightening constraints has the potential to cause resolution breakage when no
123+
breakage would occur otherwise.
103124

104125
# Alternatives
105126

106127
We could continue allowing these kinds of constraints, but complain in a
107128
"sufficiently annoying" manner during publishes to discourage their use.
108129

109-
# Unresolved questions
110-
111-
Should crates.io also forbid constraints that reference versions of
112-
dependencies that don't yet exist? For example, a constraint of `>= 0.3, < 0.5`
113-
where the dependency has no published versions in the `0.4` range.
130+
This RFC originally proposed forbidding all constraints that had no upper
131+
version bound but has since been pulled back to just `*` constraints.

0 commit comments

Comments
 (0)