Skip to content

Commit 82dca28

Browse files
committed
Auto merge of #13791 - epage:msrv-unset, r=Eh2406
fix(resolver): Treat unset MSRV as compatible ### What does this PR try to resolve? Have the resolver treat no-MSRV as `rust-version = "*"`, like `cargo add` does for version-requirement selection ### How should we test and review this PR? We last tweaked this logic in #13066. However, we noticed this was inconsistent with `cargo add` in automatically selecting version requirements. It looks like this is a revert of #13066, taking us back to the behavior in #12950. In #12950 there was a concern about the proliferation of no-MSRV and whether we should de-prioritize those to make the chance of success more likely. There are no right answes here, only which wrong answer is ok enough. - Do we treat lack of rust version as `rust-version = "*"` as some people expect or do we try to be smart? - If a user adds or removes `rust-version`, how should that affect the priority? One piece of new information is that the RFC for this has us trying to fill the no-MSRV gap with `rust-version = some-value-representing-the-current-toolchain>`. See also #9930 (comment) r? `@Eh2406` ### Additional information
2 parents e591b0e + 89ead6f commit 82dca28

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

src/cargo/core/resolver/version_prefs.rs

+15-32
Original file line numberDiff line numberDiff line change
@@ -86,36 +86,19 @@ impl VersionPreferences {
8686
}
8787

8888
if let Some(max_rust_version) = &self.max_rust_version {
89-
match (a.rust_version(), b.rust_version()) {
90-
// Fallback
91-
(None, None) => {}
92-
(Some(a), Some(b)) if a == b => {}
93-
// Primary comparison
94-
(Some(a), Some(b)) => {
95-
let a_is_compat = a.is_compatible_with(max_rust_version);
96-
let b_is_compat = b.is_compatible_with(max_rust_version);
97-
match (a_is_compat, b_is_compat) {
98-
(true, true) => {} // fallback
99-
(false, false) => {} // fallback
100-
(true, false) => return Ordering::Less,
101-
(false, true) => return Ordering::Greater,
102-
}
103-
}
104-
// Prioritize `None` over incompatible
105-
(None, Some(b)) => {
106-
if b.is_compatible_with(max_rust_version) {
107-
return Ordering::Greater;
108-
} else {
109-
return Ordering::Less;
110-
}
111-
}
112-
(Some(a), None) => {
113-
if a.is_compatible_with(max_rust_version) {
114-
return Ordering::Less;
115-
} else {
116-
return Ordering::Greater;
117-
}
118-
}
89+
let a_is_compat = a
90+
.rust_version()
91+
.map(|a| a.is_compatible_with(max_rust_version))
92+
.unwrap_or(true);
93+
let b_is_compat = b
94+
.rust_version()
95+
.map(|b| b.is_compatible_with(max_rust_version))
96+
.unwrap_or(true);
97+
match (a_is_compat, b_is_compat) {
98+
(true, true) => {} // fallback
99+
(false, false) => {} // fallback
100+
(true, false) => return Ordering::Less,
101+
(false, true) => return Ordering::Greater,
119102
}
120103
}
121104

@@ -271,15 +254,15 @@ mod test {
271254
vp.sort_summaries(&mut summaries, None);
272255
assert_eq!(
273256
describe(&summaries),
274-
"foo/1.2.1, foo/1.1.0, foo/1.2.4, foo/1.2.2, foo/1.2.0, foo/1.0.9, foo/1.2.3"
257+
"foo/1.2.4, foo/1.2.2, foo/1.2.1, foo/1.2.0, foo/1.1.0, foo/1.0.9, foo/1.2.3"
275258
.to_string()
276259
);
277260

278261
vp.version_ordering(VersionOrdering::MinimumVersionsFirst);
279262
vp.sort_summaries(&mut summaries, None);
280263
assert_eq!(
281264
describe(&summaries),
282-
"foo/1.1.0, foo/1.2.1, foo/1.0.9, foo/1.2.0, foo/1.2.2, foo/1.2.4, foo/1.2.3"
265+
"foo/1.0.9, foo/1.1.0, foo/1.2.0, foo/1.2.1, foo/1.2.2, foo/1.2.4, foo/1.2.3"
283266
.to_string()
284267
);
285268
}

0 commit comments

Comments
 (0)