@@ -18,6 +18,7 @@ use serde_untagged::UntaggedEnumVisitor;
18
18
19
19
use crate :: core:: PackageIdSpec ;
20
20
use crate :: core:: PartialVersion ;
21
+ use crate :: core:: PartialVersionError ;
21
22
use crate :: restricted_names;
22
23
23
24
/// This type is used to deserialize `Cargo.toml` files.
@@ -1334,15 +1335,15 @@ impl std::ops::Deref for RustVersion {
1334
1335
}
1335
1336
1336
1337
impl std:: str:: FromStr for RustVersion {
1337
- type Err = anyhow :: Error ;
1338
+ type Err = RustVersionError ;
1338
1339
1339
1340
fn from_str ( value : & str ) -> Result < Self , Self :: Err > {
1340
1341
let partial = value. parse :: < PartialVersion > ( ) ?;
1341
1342
if partial. pre . is_some ( ) {
1342
- anyhow :: bail! ( "unexpected prerelease field, expected a version like \" 1.32 \" " )
1343
+ return Err ( RustVersionError :: Prerelease ) ;
1343
1344
}
1344
1345
if partial. build . is_some ( ) {
1345
- anyhow :: bail! ( "unexpected prerelease field, expected a version like \" 1.32 \" " )
1346
+ return Err ( RustVersionError :: BuildMetadata ) ;
1346
1347
}
1347
1348
Ok ( Self ( partial) )
1348
1349
}
@@ -1366,6 +1367,20 @@ impl Display for RustVersion {
1366
1367
}
1367
1368
}
1368
1369
1370
+ /// Error parsing a [`PartialVersion`].
1371
+ #[ non_exhaustive]
1372
+ #[ derive( Debug , thiserror:: Error ) ]
1373
+ pub enum RustVersionError {
1374
+ #[ error( "unexpected prerelease field, expected a version like \" 1.32\" " ) ]
1375
+ Prerelease ,
1376
+
1377
+ #[ error( "unexpected build field, expected a version like \" 1.32\" " ) ]
1378
+ BuildMetadata ,
1379
+
1380
+ #[ error( transparent) ]
1381
+ PartialVersion ( #[ from] PartialVersionError ) ,
1382
+ }
1383
+
1369
1384
#[ derive( Copy , Clone , Debug ) ]
1370
1385
pub struct InvalidCargoFeatures { }
1371
1386
0 commit comments