2
2
3
3
extern crate env_logger;
4
4
extern crate syntax;
5
- extern crate serialize as rustc_serialize;
6
5
7
6
use std:: collections:: BTreeMap ;
8
7
use std:: env;
9
8
use std:: error:: Error ;
10
- use std:: fs:: { self , read_dir , File } ;
9
+ use std:: fs:: File ;
11
10
use std:: io:: Write ;
12
11
use std:: path:: Path ;
13
12
use std:: path:: PathBuf ;
14
13
use std:: cell:: RefCell ;
15
14
16
15
use syntax:: edition:: DEFAULT_EDITION ;
17
- use syntax:: diagnostics:: metadata:: { get_metadata_dir, ErrorMetadataMap , ErrorMetadata } ;
18
16
19
17
use 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 > ;
21
25
22
26
enum OutputFormat {
23
27
HTML ( HTMLFormatter ) ,
@@ -80,11 +84,7 @@ impl Formatter for HTMLFormatter {
80
84
Some ( _) => "error-described" ,
81
85
None => "error-undescribed" ,
82
86
} ;
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) ?;
88
88
89
89
// Error title (with self-link).
90
90
write ! ( output,
@@ -199,25 +199,6 @@ impl Formatter for MarkdownFormatter {
199
199
}
200
200
}
201
201
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
-
221
202
/// Output an HTML page for the errors in `err_map` to `output_path`.
222
203
fn render_error_page < T : Formatter > ( err_map : & ErrorMetadataMap , output_path : & Path ,
223
204
formatter : T ) -> Result < ( ) , Box < dyn Error > > {
@@ -234,9 +215,13 @@ fn render_error_page<T: Formatter>(err_map: &ErrorMetadataMap, output_path: &Pat
234
215
}
235
216
236
217
fn 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
+ }
240
225
match format {
241
226
OutputFormat :: Unknown ( s) => panic ! ( "Unknown output format: {}" , s) ,
242
227
OutputFormat :: HTML ( h) => render_error_page ( & err_map, dst, h) ?,
@@ -272,3 +257,5 @@ fn main() {
272
257
panic ! ( "{}" , e. description( ) ) ;
273
258
}
274
259
}
260
+
261
+ include ! ( concat!( env!( "OUT_DIR" ) , "/error_codes.rs" ) ) ;
0 commit comments