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 } ;
16
+ use syntax:: diagnostics:: metadata:: { ErrorMetadataMap , ErrorMetadata } ;
18
17
19
18
use rustdoc:: html:: markdown:: { Markdown , IdMap , ErrorCodes , Playground } ;
20
- use rustc_serialize:: json;
21
19
22
20
enum OutputFormat {
23
21
HTML ( HTMLFormatter ) ,
@@ -80,11 +78,7 @@ impl Formatter for HTMLFormatter {
80
78
Some ( _) => "error-described" ,
81
79
None => "error-undescribed" ,
82
80
} ;
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) ?;
81
+ write ! ( output, "<div class=\" {}\" >" , desc_desc) ?;
88
82
89
83
// Error title (with self-link).
90
84
write ! ( output,
@@ -199,25 +193,6 @@ impl Formatter for MarkdownFormatter {
199
193
}
200
194
}
201
195
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
196
/// Output an HTML page for the errors in `err_map` to `output_path`.
222
197
fn render_error_page < T : Formatter > ( err_map : & ErrorMetadataMap , output_path : & Path ,
223
198
formatter : T ) -> Result < ( ) , Box < dyn Error > > {
@@ -234,9 +209,16 @@ fn render_error_page<T: Formatter>(err_map: &ErrorMetadataMap, output_path: &Pat
234
209
}
235
210
236
211
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) ?;
212
+ let long_codes = register_all ( ) ;
213
+ let mut err_map = BTreeMap :: new ( ) ;
214
+ for ( code, desc) in long_codes {
215
+ err_map. insert ( code. to_string ( ) , ErrorMetadata {
216
+ description : desc. map ( String :: from) ,
217
+ // FIXME: this indicates that the error code is not used, which may not be true.
218
+ // We currently do not use this information.
219
+ use_site : None ,
220
+ } ) ;
221
+ }
240
222
match format {
241
223
OutputFormat :: Unknown ( s) => panic ! ( "Unknown output format: {}" , s) ,
242
224
OutputFormat :: HTML ( h) => render_error_page ( & err_map, dst, h) ?,
@@ -272,3 +254,5 @@ fn main() {
272
254
panic ! ( "{}" , e. description( ) ) ;
273
255
}
274
256
}
257
+
258
+ include ! ( concat!( env!( "OUT_DIR" ) , "/error_codes.rs" ) ) ;
0 commit comments