Skip to content

Commit b43204a

Browse files
committed
Expand on Reference details
1 parent d3ebf36 commit b43204a

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

text/3493-precise-pre-release-cargo-update.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,49 @@ Since this RFC is concerned with the behaviour of `cargo update --precise` chang
9191
# Reference-level explanation
9292
[reference-level-explanation]: #reference-level-explanation
9393

94-
To determine if a version can be selected with `--precise` for a specification that isn't listed above cosider where pre-releases exist within version ranges.
94+
## Version requirements
9595

96-
For example consider the version `~1.2.3`.
97-
The range for `~1.2.3` is [stated in the cargo book](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#tilde-requirements).
96+
Version requirement operator semantics will change to encompass pre-release versions, compared to before where the presence of pre-release would change matching modes.
97+
This will also better align with the mathematical properties associated with some of the operators (see the closed [RFC 3266](https://github.com/rust-lang/rfcs/pull/3266)).
9898

99+
So before,
99100
```
100-
~1.2.3 := >=1.2.3, <1.3.0
101+
1.2.3 -> ^1.2.3 -> >=1.2.3, <2.0.0 (with implicit holes excluding pre-release versions)
101102
```
103+
would become
104+
```
105+
1.2.3 -> ^1.2.3 -> >=1.2.3, <2.0.0-0
106+
```
107+
Note that the old syntax implicitly excluded `2.0.0-<prelease>` which we have have to explicitly exclude by referencing the smallest possible pre-release version of `-0`.
108+
109+
This change applies to all operators.
110+
111+
## Dependency Resolution
112+
113+
The intent is to mirror the behavior of yanked today.
114+
115+
When parsing a `Cargo.lock`, any pre-release version would be tracked in an allow-list.
116+
When resolving, we would exclude from consideration any pre-release version unless:
117+
- It is in the allow-list
118+
- It matches the version requirement under the old pre-release version requirement semantics.
119+
120+
## `cargo update`
121+
122+
The version passed in via `--precise` would be added to the allow-list.
123+
124+
**Note:** overriding of yanked via this mechanism is not meant to be assumed to be a part of this proposal.
125+
Support for selecting yanked with `--precise` should be decided separately from this RFC, instead see [rust-lang/cargo#4225](https://github.com/rust-lang/cargo/issues/4225)
102126

103-
Intuitively `1.2.4-pre.0` satisfies this inequality, therefore it can be selected with `cargo update --precise`.
104-
Since it is a pre-release and the specification is not, `1.2.4-pre.0` would not be selected by a bare `cargo update`.
105-
`1.3.0-pre.0` also satisfies the inequality but `1.2.3-pre.0` and `1.3.1-pre.0` do not.
127+
## [`semver`](https://crates.io/crates/semver)
106128

107-
Put in simple terms the relationship between a pre-release and its stable release is always `a.b.c-pre.0 < a.b.c`.
129+
`cargo` will need both the old and new behavior exposed.
130+
To reduce risk of tools in the ecosystem unintentionally matching pre-releases (despite them still needing an opt-in),
131+
it might be reasonable for the
132+
`semver`
133+
package to offer this new matching behavior under a different name
134+
(e.g. `VersionReq::matches_prerelease` in contrast to the existing `VersionReq::matches`)
135+
(also avoiding a breaking change).
136+
However, we leave the exact API details to the maintainer of the `semver` package.
108137

109138
# Drawbacks
110139
[drawbacks]: #drawbacks

0 commit comments

Comments
 (0)