@@ -76,8 +76,9 @@ use extra::rl;
7676
7777use rustc:: driver:: { driver, session} ;
7878use rustc:: back:: link:: jit;
79- use syntax:: { ast, diagnostic} ;
79+ use syntax:: { ast, codemap , diagnostic} ;
8080use syntax:: ast_util:: * ;
81+ use syntax:: diagnostic:: Emitter ;
8182use syntax:: parse:: token;
8283use syntax:: print:: pprust;
8384
@@ -107,6 +108,28 @@ enum CmdAction {
107108 action_run_line( ~str ) ,
108109}
109110
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+
110133/// Run an input string in a Repl, returning the new Repl.
111134fn run( mut program : ~Program , binary : ~str , lib_search_paths : ~[ ~str ] ,
112135 input : ~str ) -> ( ~Program , Option < ~jit:: Engine > )
@@ -124,18 +147,9 @@ fn run(mut program: ~Program, binary: ~str, lib_search_paths: ~[~str],
124147 // extra helpful information if the error crops up. Otherwise people are
125148 // bound to be very confused when they find out code is running that they
126149 // 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 ) ;
139153 let intr = token:: get_ident_interner ( ) ;
140154
141155 //
@@ -243,7 +257,9 @@ fn run(mut program: ~Program, binary: ~str, lib_search_paths: ~[~str],
243257 let input = driver:: str_input ( code. to_managed ( ) ) ;
244258 let cfg = driver:: build_configuration ( sess) ;
245259 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 ) ;
247263
248264 let crate = driver:: phase_1_parse_input ( sess, cfg. clone ( ) , & input) ;
249265 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> {
305321 .. ( * session:: basic_options( ) ) . clone( )
306322 } ;
307323 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 ) ;
309327 * sess. building_library = true ;
310328 let cfg = driver:: build_configuration ( sess) ;
311329 let outputs = driver:: build_output_filenames (
0 commit comments