22
33extern crate env_logger;
44extern crate syntax;
5- extern crate serialize as rustc_serialize;
65
76use std:: collections:: BTreeMap ;
87use std:: env;
98use std:: error:: Error ;
10- use std:: fs:: { self , read_dir , File } ;
9+ use std:: fs:: File ;
1110use std:: io:: Write ;
1211use std:: path:: Path ;
1312use std:: path:: PathBuf ;
1413use std:: cell:: RefCell ;
1514
1615use syntax:: edition:: DEFAULT_EDITION ;
17- use syntax:: diagnostics:: metadata:: { get_metadata_dir, ErrorMetadataMap , ErrorMetadata } ;
1816
1917use rustdoc:: html:: markdown:: { Markdown , IdMap , ErrorCodes , Playground } ;
20- use rustc_serialize:: json;
18+
19+ pub struct ErrorMetadata {
20+ pub description : Option < String > ,
21+ }
22+
23+ /// Mapping from error codes to metadata that can be (de)serialized.
24+ pub type ErrorMetadataMap = BTreeMap < String , ErrorMetadata > ;
2125
2226enum OutputFormat {
2327 HTML ( HTMLFormatter ) ,
@@ -80,11 +84,7 @@ impl Formatter for HTMLFormatter {
8084 Some ( _) => "error-described" ,
8185 None => "error-undescribed" ,
8286 } ;
83- let use_desc = match info. use_site {
84- Some ( _) => "error-used" ,
85- None => "error-unused" ,
86- } ;
87- write ! ( output, "<div class=\" {} {}\" >" , desc_desc, use_desc) ?;
87+ write ! ( output, "<div class=\" {}\" >" , desc_desc) ?;
8888
8989 // Error title (with self-link).
9090 write ! ( output,
@@ -199,25 +199,6 @@ impl Formatter for MarkdownFormatter {
199199 }
200200}
201201
202- /// Loads all the metadata files from `metadata_dir` into an in-memory map.
203- fn load_all_errors ( metadata_dir : & Path ) -> Result < ErrorMetadataMap , Box < dyn Error > > {
204- let mut all_errors = BTreeMap :: new ( ) ;
205-
206- for entry in read_dir ( metadata_dir) ? {
207- let path = entry?. path ( ) ;
208-
209- let metadata_str = fs:: read_to_string ( & path) ?;
210-
211- let some_errors: ErrorMetadataMap = json:: decode ( & metadata_str) ?;
212-
213- for ( err_code, info) in some_errors {
214- all_errors. insert ( err_code, info) ;
215- }
216- }
217-
218- Ok ( all_errors)
219- }
220-
221202/// Output an HTML page for the errors in `err_map` to `output_path`.
222203fn render_error_page < T : Formatter > ( err_map : & ErrorMetadataMap , output_path : & Path ,
223204 formatter : T ) -> Result < ( ) , Box < dyn Error > > {
@@ -234,9 +215,13 @@ fn render_error_page<T: Formatter>(err_map: &ErrorMetadataMap, output_path: &Pat
234215}
235216
236217fn main_with_result ( format : OutputFormat , dst : & Path ) -> Result < ( ) , Box < dyn Error > > {
237- let build_arch = env:: var ( "CFG_BUILD" ) ?;
238- let metadata_dir = get_metadata_dir ( & build_arch) ;
239- let err_map = load_all_errors ( & metadata_dir) ?;
218+ let long_codes = register_all ( ) ;
219+ let mut err_map = BTreeMap :: new ( ) ;
220+ for ( code, desc) in long_codes {
221+ err_map. insert ( code. to_string ( ) , ErrorMetadata {
222+ description : desc. map ( String :: from) ,
223+ } ) ;
224+ }
240225 match format {
241226 OutputFormat :: Unknown ( s) => panic ! ( "Unknown output format: {}" , s) ,
242227 OutputFormat :: HTML ( h) => render_error_page ( & err_map, dst, h) ?,
@@ -272,3 +257,5 @@ fn main() {
272257 panic ! ( "{}" , e. description( ) ) ;
273258 }
274259}
260+
261+ include ! ( concat!( env!( "OUT_DIR" ) , "/error_codes.rs" ) ) ;
0 commit comments