@@ -117,9 +117,15 @@ impl OptVersionReq {
117
117
/// and we're not sure if this part of the functionality should be implemented in semver or cargo.
118
118
pub fn matches_prerelease ( & self , version : & Version ) -> bool {
119
119
if version. is_prerelease ( ) {
120
- let mut version = version. clone ( ) ;
121
- version. pre = semver:: Prerelease :: EMPTY ;
122
- return self . matches ( & version) ;
120
+ // Only in the case of "ordinary" version requirements with pre-release
121
+ // versions do we need to help the version matching. In the case of Any,
122
+ // Locked, or Precise, the `matches()` function is already doing the
123
+ // correct handling.
124
+ if let OptVersionReq :: Req ( _) = self {
125
+ let mut version = version. clone ( ) ;
126
+ version. pre = semver:: Prerelease :: EMPTY ;
127
+ return self . matches ( & version) ;
128
+ }
123
129
}
124
130
self . matches ( version)
125
131
}
@@ -247,10 +253,6 @@ mod matches_prerelease {
247
253
let version = Version :: parse ( "1.2.3-pre" ) . unwrap ( ) ;
248
254
let matched =
249
255
OptVersionReq :: Precise ( version. clone ( ) , version_req) . matches_prerelease ( & version) ;
250
-
251
- assert ! ( !matched, "this is wrong" ) ;
252
-
253
- // FIXME: See https://github.com/rust-lang/cargo/issues/12425#issuecomment-2186198258
254
- // assert!(matched, "a version must match its own precise requirement");
256
+ assert ! ( matched, "a version must match its own precise requirement" ) ;
255
257
}
256
258
}
0 commit comments