@@ -8,21 +8,26 @@ fn main() {
88 // directory.
99 let out_dir = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
1010 let dest = out_dir. join ( "error_codes.rs" ) ;
11- let mut idx = 0 ;
12- for entry in WalkDir :: new ( "../../../src" ) {
13- let entry = entry. unwrap ( ) ;
14- if entry. file_name ( ) == "error_codes.rs" {
15- println ! ( "cargo:rerun-if-changed={}" , entry. path( ) . to_str( ) . unwrap( ) ) ;
16- let file = fs:: read_to_string ( entry. path ( ) ) . unwrap ( )
17- . replace ( "crate::register_diagnostics!" , "register_diagnostics!" )
18- . replace ( ": include_str!(\" ./" ,
19- ": include_str!(\" ../../../../../../../../src/librustc_error_codes/" ) ;
20- let contents = format ! ( "(|| {{\n {}\n }})()" , file) ;
2111
22- fs:: write ( & out_dir. join ( & format ! ( "error_{}.rs" , idx) ) , & contents) . unwrap ( ) ;
12+ let error_codes_path = "../../../src/librustc_error_codes/error_codes.rs" ;
13+
14+ println ! ( "cargo:rerun-if-changed={}" , error_codes_path) ;
15+ let file = fs:: read_to_string ( error_codes_path) . unwrap ( )
16+ . replace ( "crate::register_diagnostics!" , "register_diagnostics!" )
17+ . replace ( ": include_str!(\" ./error_codes/" , ": include_str!(\" ./" ) ;
18+ let contents = format ! ( "(|| {{\n {}\n }})()" , file) ;
19+ fs:: write ( & out_dir. join ( "all_error_codes.rs" ) , & contents) . unwrap ( ) ;
2320
24- idx += 1 ;
21+ // We copy the md files as well to the target directory.
22+ for entry in WalkDir :: new ( "../../../src/librustc_error_codes/error_codes" ) {
23+ let entry = entry. unwrap ( ) ;
24+ match entry. path ( ) . extension ( ) {
25+ Some ( s) if s == "md" => { }
26+ _ => continue ,
2527 }
28+ println ! ( "cargo:rerun-if-changed={}" , entry. path( ) . to_str( ) . unwrap( ) ) ;
29+ let md_content = fs:: read_to_string ( entry. path ( ) ) . unwrap ( ) ;
30+ fs:: write ( & out_dir. join ( entry. file_name ( ) ) , & md_content) . unwrap ( ) ;
2631 }
2732
2833 let mut all = String :: new ( ) ;
@@ -48,10 +53,7 @@ fn register_all() -> Vec<(&'static str, Option<&'static str>)> {
4853 )
4954 }
5055"### ) ;
51- for idx in 0 ..idx {
52- all. push_str ( & format ! ( r#"include!(concat!(env!("OUT_DIR"), "/error_{}.rs"));"# , idx) ) ;
53- all. push_str ( "\n " ) ;
54- }
56+ all. push_str ( r#"include!(concat!(env!("OUT_DIR"), "/all_error_codes.rs"));"# ) ;
5557 all. push_str ( "\n long_codes\n " ) ;
5658 all. push_str ( "}\n " ) ;
5759
0 commit comments