44use std:: ffi:: OsStr ;
55use std:: path:: Path ;
66use std:: process:: Command ;
7+ use std:: str:: FromStr ;
78
89use build_helper:: ci:: CiEnv ;
910use build_helper:: git:: { GitConfig , get_closest_upstream_commit} ;
@@ -71,9 +72,22 @@ pub fn check(src_path: &Path, bad: &mut bool) {
7172 Some ( output) => {
7273 let mut format_version_updated = false ;
7374 let mut latest_feature_comment_updated = false ;
75+ let mut new_version = None ;
76+ let mut old_version = None ;
7477 for line in output. lines ( ) {
7578 if line. starts_with ( "+pub const FORMAT_VERSION: u32 =" ) {
7679 format_version_updated = true ;
80+ new_version = line
81+ . split ( '=' )
82+ . nth ( 1 )
83+ . and_then ( |s| s. trim ( ) . split ( ';' ) . next ( ) )
84+ . and_then ( |s| u32:: from_str ( s. trim ( ) ) . ok ( ) ) ;
85+ } else if line. starts_with ( "-pub const FORMAT_VERSION: u32 =" ) {
86+ old_version = line
87+ . split ( '=' )
88+ . nth ( 1 )
89+ . and_then ( |s| s. trim ( ) . split ( ';' ) . next ( ) )
90+ . and_then ( |s| u32:: from_str ( s. trim ( ) ) . ok ( ) ) ;
7791 } else if line. starts_with ( "+// Latest feature:" ) {
7892 latest_feature_comment_updated = true ;
7993 }
@@ -92,6 +106,17 @@ pub fn check(src_path: &Path, bad: &mut bool) {
92106 ) ;
93107 }
94108 }
109+ match ( new_version, old_version) {
110+ ( Some ( new_version) , Some ( old_version) ) if new_version != old_version + 1 => {
111+ * bad = true ;
112+ eprintln ! (
113+ "error in `rustdoc_json` tidy check: invalid `FORMAT_VERSION` increase in \
114+ `{RUSTDOC_JSON_TYPES}/lib.rs`, should be `{}`, found `{new_version}`",
115+ old_version + 1 ,
116+ ) ;
117+ }
118+ _ => { }
119+ }
95120 }
96121 None => {
97122 * bad = true ;
0 commit comments