@@ -16,7 +16,8 @@ use util::nodemap::{NodeMap, FnvHashMap};
16
16
17
17
use syntax:: ast:: { NodeId , NodeIdAssigner , Name } ;
18
18
use syntax:: codemap:: Span ;
19
- use syntax:: diagnostic:: { self , Emitter } ;
19
+ use syntax:: errors;
20
+ use syntax:: errors:: emitter:: { Emitter , BasicEmitter } ;
20
21
use syntax:: diagnostics;
21
22
use syntax:: feature_gate;
22
23
use syntax:: parse;
@@ -99,7 +100,7 @@ impl Session {
99
100
if self . opts . treat_err_as_bug {
100
101
self . bug ( msg) ;
101
102
}
102
- panic ! ( self . diagnostic( ) . handler ( ) . fatal( msg) )
103
+ panic ! ( self . diagnostic( ) . fatal( msg) )
103
104
}
104
105
pub fn span_err_or_warn ( & self , is_warning : bool , sp : Span , msg : & str ) {
105
106
if is_warning {
@@ -137,16 +138,16 @@ impl Session {
137
138
if self . opts . treat_err_as_bug {
138
139
self . bug ( msg) ;
139
140
}
140
- self . diagnostic ( ) . handler ( ) . err ( msg)
141
+ self . diagnostic ( ) . err ( msg)
141
142
}
142
143
pub fn err_count ( & self ) -> usize {
143
- self . diagnostic ( ) . handler ( ) . err_count ( )
144
+ self . diagnostic ( ) . err_count ( )
144
145
}
145
146
pub fn has_errors ( & self ) -> bool {
146
- self . diagnostic ( ) . handler ( ) . has_errors ( )
147
+ self . diagnostic ( ) . has_errors ( )
147
148
}
148
149
pub fn abort_if_errors ( & self ) {
149
- self . diagnostic ( ) . handler ( ) . abort_if_errors ( ) ;
150
+ self . diagnostic ( ) . abort_if_errors ( ) ;
150
151
151
152
let delayed_bug = self . delayed_span_bug . borrow ( ) ;
152
153
match * delayed_bug {
@@ -177,7 +178,7 @@ impl Session {
177
178
}
178
179
pub fn warn ( & self , msg : & str ) {
179
180
if self . can_print_warnings {
180
- self . diagnostic ( ) . handler ( ) . warn ( msg)
181
+ self . diagnostic ( ) . warn ( msg)
181
182
}
182
183
}
183
184
pub fn opt_span_warn ( & self , opt_sp : Option < Span > , msg : & str ) {
@@ -195,7 +196,7 @@ impl Session {
195
196
196
197
/// Prints out a message with a suggested edit of the code.
197
198
///
198
- /// See `diagnostic ::RenderSpan::Suggestion` for more information.
199
+ /// See `errors ::RenderSpan::Suggestion` for more information.
199
200
pub fn span_suggestion ( & self , sp : Span , msg : & str , suggestion : String ) {
200
201
self . diagnostic ( ) . span_suggestion ( sp, msg, suggestion)
201
202
}
@@ -209,10 +210,10 @@ impl Session {
209
210
self . diagnostic ( ) . fileline_help ( sp, msg)
210
211
}
211
212
pub fn note ( & self , msg : & str ) {
212
- self . diagnostic ( ) . handler ( ) . note ( msg)
213
+ self . diagnostic ( ) . note ( msg)
213
214
}
214
215
pub fn help ( & self , msg : & str ) {
215
- self . diagnostic ( ) . handler ( ) . help ( msg)
216
+ self . diagnostic ( ) . help ( msg)
216
217
}
217
218
pub fn opt_span_bug ( & self , opt_sp : Option < Span > , msg : & str ) -> ! {
218
219
match opt_sp {
@@ -229,13 +230,13 @@ impl Session {
229
230
self . diagnostic ( ) . span_bug ( sp, msg)
230
231
}
231
232
pub fn bug ( & self , msg : & str ) -> ! {
232
- self . diagnostic ( ) . handler ( ) . bug ( msg)
233
+ self . diagnostic ( ) . bug ( msg)
233
234
}
234
235
pub fn span_unimpl ( & self , sp : Span , msg : & str ) -> ! {
235
236
self . diagnostic ( ) . span_unimpl ( sp, msg)
236
237
}
237
238
pub fn unimpl ( & self , msg : & str ) -> ! {
238
- self . diagnostic ( ) . handler ( ) . unimpl ( msg)
239
+ self . diagnostic ( ) . unimpl ( msg)
239
240
}
240
241
pub fn add_lint ( & self ,
241
242
lint : & ' static lint:: Lint ,
@@ -260,7 +261,7 @@ impl Session {
260
261
261
262
id
262
263
}
263
- pub fn diagnostic < ' a > ( & ' a self ) -> & ' a diagnostic :: SpanHandler {
264
+ pub fn diagnostic < ' a > ( & ' a self ) -> & ' a errors :: Handler {
264
265
& self . parse_sess . span_diagnostic
265
266
}
266
267
pub fn codemap < ' a > ( & ' a self ) -> & ' a codemap:: CodeMap {
@@ -414,29 +415,27 @@ pub fn build_session(sopts: config::Options,
414
415
. last ( )
415
416
. unwrap_or ( true ) ;
416
417
417
- let codemap = codemap:: CodeMap :: new ( ) ;
418
+ let codemap = Rc :: new ( codemap:: CodeMap :: new ( ) ) ;
418
419
let diagnostic_handler =
419
- diagnostic:: Handler :: new ( sopts. color , Some ( registry) , can_print_warnings) ;
420
- let span_diagnostic_handler =
421
- diagnostic:: SpanHandler :: new ( diagnostic_handler, codemap) ;
420
+ errors:: Handler :: new ( sopts. color , Some ( registry) , can_print_warnings, codemap. clone ( ) ) ;
422
421
423
- build_session_ ( sopts, local_crate_source_file, span_diagnostic_handler , cstore)
422
+ build_session_ ( sopts, local_crate_source_file, diagnostic_handler , codemap , cstore)
424
423
}
425
424
426
425
pub fn build_session_ ( sopts : config:: Options ,
427
426
local_crate_source_file : Option < PathBuf > ,
428
- span_diagnostic : diagnostic:: SpanHandler ,
427
+ span_diagnostic : errors:: Handler ,
428
+ codemap : Rc < codemap:: CodeMap > ,
429
429
cstore : Rc <for <' a > CrateStore < ' a > >)
430
430
-> Session {
431
431
let host = match Target :: search ( config:: host_triple ( ) ) {
432
432
Ok ( t) => t,
433
433
Err ( e) => {
434
- panic ! ( span_diagnostic. handler( )
435
- . fatal( & format!( "Error loading host specification: {}" , e) ) ) ;
434
+ panic ! ( span_diagnostic. fatal( & format!( "Error loading host specification: {}" , e) ) ) ;
436
435
}
437
436
} ;
438
437
let target_cfg = config:: build_target_config ( & sopts, & span_diagnostic) ;
439
- let p_s = parse:: ParseSess :: with_span_handler ( span_diagnostic) ;
438
+ let p_s = parse:: ParseSess :: with_span_handler ( span_diagnostic, codemap ) ;
440
439
let default_sysroot = match sopts. maybe_sysroot {
441
440
Some ( _) => None ,
442
441
None => Some ( filesearch:: get_or_default_sysroot ( ) )
@@ -494,16 +493,16 @@ pub fn build_session_(sopts: config::Options,
494
493
pub fn expect < T , M > ( sess : & Session , opt : Option < T > , msg : M ) -> T where
495
494
M : FnOnce ( ) -> String ,
496
495
{
497
- diagnostic :: expect ( sess. diagnostic ( ) , opt, msg)
496
+ errors :: expect ( sess. diagnostic ( ) , opt, msg)
498
497
}
499
498
500
- pub fn early_error ( color : diagnostic :: ColorConfig , msg : & str ) -> ! {
501
- let mut emitter = diagnostic :: EmitterWriter :: stderr ( color, None ) ;
502
- emitter. emit ( None , msg, None , diagnostic :: Fatal ) ;
503
- panic ! ( diagnostic :: FatalError ) ;
499
+ pub fn early_error ( color : errors :: ColorConfig , msg : & str ) -> ! {
500
+ let mut emitter = BasicEmitter :: stderr ( color) ;
501
+ emitter. emit ( None , msg, None , errors :: Level :: Fatal ) ;
502
+ panic ! ( errors :: FatalError ) ;
504
503
}
505
504
506
- pub fn early_warn ( color : diagnostic :: ColorConfig , msg : & str ) {
507
- let mut emitter = diagnostic :: EmitterWriter :: stderr ( color, None ) ;
508
- emitter. emit ( None , msg, None , diagnostic :: Warning ) ;
505
+ pub fn early_warn ( color : errors :: ColorConfig , msg : & str ) {
506
+ let mut emitter = BasicEmitter :: stderr ( color) ;
507
+ emitter. emit ( None , msg, None , errors :: Level :: Warning ) ;
509
508
}
0 commit comments