@@ -76,8 +76,9 @@ use extra::rl;
76
76
77
77
use rustc:: driver:: { driver, session} ;
78
78
use rustc:: back:: link:: jit;
79
- use syntax:: { ast, diagnostic} ;
79
+ use syntax:: { ast, codemap , diagnostic} ;
80
80
use syntax:: ast_util:: * ;
81
+ use syntax:: diagnostic:: Emitter ;
81
82
use syntax:: parse:: token;
82
83
use syntax:: print:: pprust;
83
84
@@ -107,6 +108,28 @@ enum CmdAction {
107
108
action_run_line( ~str ) ,
108
109
}
109
110
111
+ struct EncodableWarningEmitter ;
112
+
113
+ impl diagnostic:: Emitter for EncodableWarningEmitter {
114
+ fn emit ( & self ,
115
+ cm : Option < ( @codemap:: CodeMap , codemap:: Span ) > ,
116
+ msg : & str ,
117
+ lvl : diagnostic:: level ) {
118
+ diagnostic:: DefaultEmitter . emit ( cm, msg, lvl) ;
119
+ if msg. contains ( "failed to find an implementation of trait" ) &&
120
+ msg. contains ( "extra::serialize::Encodable" ) {
121
+ diagnostic:: DefaultEmitter . emit ( cm,
122
+ "Currrently rusti serializes \
123
+ bound locals between different \
124
+ lines of input. This means that \
125
+ all values of local variables \
126
+ need to be encodable, and this \
127
+ type isn't encodable",
128
+ diagnostic:: note) ;
129
+ }
130
+ }
131
+ }
132
+
110
133
/// Run an input string in a Repl, returning the new Repl.
111
134
fn run( mut program : ~Program , binary : ~str , lib_search_paths : ~[ ~str ] ,
112
135
input : ~str ) -> ( ~Program , Option < ~jit:: Engine > )
@@ -124,18 +147,9 @@ fn run(mut program: ~Program, binary: ~str, lib_search_paths: ~[~str],
124
147
// extra helpful information if the error crops up. Otherwise people are
125
148
// bound to be very confused when they find out code is running that they
126
149
// never typed in...
127
- let sess = driver:: build_session ( options, |cm, msg, lvl| {
128
- diagnostic:: emit ( cm, msg, lvl) ;
129
- if msg. contains ( "failed to find an implementation of trait" ) &&
130
- msg. contains ( "extra::serialize::Encodable" ) {
131
- diagnostic:: emit ( cm,
132
- "Currrently rusti serializes bound locals between \
133
- different lines of input. This means that all \
134
- values of local variables need to be encodable, \
135
- and this type isn't encodable",
136
- diagnostic:: note) ;
137
- }
138
- } ) ;
150
+ let sess = driver:: build_session ( options,
151
+ @EncodableWarningEmitter as
152
+ @diagnostic:: Emitter ) ;
139
153
let intr = token:: get_ident_interner ( ) ;
140
154
141
155
//
@@ -243,7 +257,9 @@ fn run(mut program: ~Program, binary: ~str, lib_search_paths: ~[~str],
243
257
let input = driver:: str_input ( code. to_managed ( ) ) ;
244
258
let cfg = driver:: build_configuration ( sess) ;
245
259
let outputs = driver:: build_output_filenames ( & input, & None , & None , [ ] , sess) ;
246
- let sess = driver:: build_session ( options, diagnostic:: emit) ;
260
+ let sess = driver:: build_session ( options,
261
+ @diagnostic:: DefaultEmitter as
262
+ @diagnostic:: Emitter ) ;
247
263
248
264
let crate = driver:: phase_1_parse_input ( sess, cfg. clone ( ) , & input) ;
249
265
let expanded_crate = driver:: phase_2_configure_and_expand ( sess, cfg, crate ) ;
@@ -305,7 +321,9 @@ fn compile_crate(src_filename: ~str, binary: ~str) -> Option<bool> {
305
321
.. ( * session:: basic_options( ) ) . clone( )
306
322
} ;
307
323
let input = driver:: file_input ( src_path. clone ( ) ) ;
308
- let sess = driver:: build_session ( options, diagnostic:: emit) ;
324
+ let sess = driver:: build_session ( options,
325
+ @diagnostic:: DefaultEmitter as
326
+ @diagnostic:: Emitter ) ;
309
327
* sess. building_library = true ;
310
328
let cfg = driver:: build_configuration ( sess) ;
311
329
let outputs = driver:: build_output_filenames (
0 commit comments