@@ -48,12 +48,10 @@ use std::fs;
48
48
use std:: io:: { self , Write } ;
49
49
use std:: path:: { Path , PathBuf } ;
50
50
use syntax:: ast:: { self , NodeIdAssigner } ;
51
- use syntax:: attr;
52
- use syntax:: attr:: AttrMetaMethods ;
51
+ use syntax:: attr:: { self , AttrMetaMethods } ;
53
52
use syntax:: diagnostics;
54
53
use syntax:: fold:: Folder ;
55
- use syntax:: parse;
56
- use syntax:: parse:: token;
54
+ use syntax:: parse:: { self , PResult , token} ;
57
55
use syntax:: util:: node_count:: NodeCounter ;
58
56
use syntax:: visit;
59
57
use syntax;
@@ -86,7 +84,13 @@ pub fn compile_input(sess: &Session,
86
84
// possible to keep the peak memory usage low
87
85
let ( outputs, trans) = {
88
86
let ( outputs, expanded_crate, id) = {
89
- let krate = phase_1_parse_input ( sess, cfg, input) ;
87
+ let krate = match phase_1_parse_input ( sess, cfg, input) {
88
+ Ok ( krate) => krate,
89
+ Err ( mut parse_error) => {
90
+ parse_error. emit ( ) ;
91
+ return Err ( 1 ) ;
92
+ }
93
+ } ;
90
94
91
95
controller_entry_point ! ( after_parse,
92
96
sess,
@@ -415,17 +419,20 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
415
419
}
416
420
}
417
421
418
- pub fn phase_1_parse_input ( sess : & Session , cfg : ast:: CrateConfig , input : & Input ) -> ast:: Crate {
422
+ pub fn phase_1_parse_input < ' a > ( sess : & ' a Session ,
423
+ cfg : ast:: CrateConfig ,
424
+ input : & Input )
425
+ -> PResult < ' a , ast:: Crate > {
419
426
// These may be left in an incoherent state after a previous compile.
420
427
// `clear_tables` and `get_ident_interner().clear()` can be used to free
421
428
// memory, but they do not restore the initial state.
422
429
syntax:: ext:: mtwt:: reset_tables ( ) ;
423
430
token:: reset_ident_interner ( ) ;
424
431
425
- let krate = time ( sess. time_passes ( ) , "parsing" , || {
432
+ let krate = try! ( time ( sess. time_passes ( ) , "parsing" , || {
426
433
match * input {
427
434
Input :: File ( ref file) => {
428
- parse:: parse_crate_from_file ( & ( * file) , cfg. clone ( ) , & sess. parse_sess )
435
+ parse:: parse_crate_from_file ( file, cfg. clone ( ) , & sess. parse_sess )
429
436
}
430
437
Input :: Str ( ref src) => {
431
438
parse:: parse_crate_from_source_str ( anon_src ( ) . to_string ( ) ,
@@ -434,7 +441,7 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
434
441
& sess. parse_sess )
435
442
}
436
443
}
437
- } ) ;
444
+ } ) ) ;
438
445
439
446
if sess. opts . debugging_opts . ast_json_noexpand {
440
447
println ! ( "{}" , json:: as_json( & krate) ) ;
@@ -449,7 +456,7 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
449
456
syntax:: show_span:: run ( sess. diagnostic ( ) , s, & krate) ;
450
457
}
451
458
452
- krate
459
+ Ok ( krate)
453
460
}
454
461
455
462
fn count_nodes ( krate : & ast:: Crate ) -> usize {
0 commit comments