@@ -3,13 +3,9 @@ use std::{process::Command, sync::OnceLock};
3
3
fn rust_version_minor ( ) -> u32 {
4
4
static VERSION_MINOR : OnceLock < u32 > = OnceLock :: new ( ) ;
5
5
* VERSION_MINOR . get_or_init ( || {
6
- crate :: input:: cargo_pkg_rust_version ( )
7
- . split ( '.' )
8
- . nth ( 1 )
6
+ version_minor ( & crate :: input:: cargo_pkg_rust_version ( ) )
9
7
// assume build-rs's MSRV if none specified for the current package
10
- . unwrap_or ( env ! ( "CARGO_PKG_RUST_VERSION" ) . split ( '.' ) . nth ( 1 ) . unwrap ( ) )
11
- . parse ( )
12
- . unwrap ( )
8
+ . unwrap_or_else ( || version_minor ( env ! ( "CARGO_PKG_RUST_VERSION" ) ) . unwrap ( ) )
13
9
} )
14
10
}
15
11
@@ -25,16 +21,18 @@ fn cargo_version_minor() -> u32 {
25
21
// > cargo -V # example output
26
22
// cargo 1.82.0 (8f40fc59f 2024-08-21)
27
23
28
- std:: str:: from_utf8 ( & out. stdout ) . expect ( "`cargo -V` should output valid UTF-8" )
29
- [ "cargo 1." . len ( ) ..]
30
- . split ( '.' )
31
- . next ( )
32
- . expect ( "`cargo -V` format should be stable" )
33
- . parse ( )
34
- . unwrap ( )
24
+ let out = std:: str:: from_utf8 ( & out. stdout ) . expect ( "`cargo -V` should output valid UTF-8" ) ;
25
+ let version = out. split ( ' ' ) . nth ( 1 ) . unwrap ( ) ;
26
+ version_minor ( version) . unwrap ( )
35
27
} )
36
28
}
37
29
30
+ fn version_minor ( version : & str ) -> Option < u32 > {
31
+ let minor = version. split ( '.' ) . nth ( 1 ) ?;
32
+ let minor = minor. parse ( ) . unwrap ( ) ;
33
+ Some ( minor)
34
+ }
35
+
38
36
pub ( crate ) fn double_colon_directives ( ) -> bool {
39
37
// cargo errors on `cargo::` directives with insufficient package.rust-version
40
38
rust_version_minor ( ) >= 77
0 commit comments