Skip to content

Commit f786437

Browse files
committed
syntax: refactor (Span)Handler and ParseSess constructors to be methods.
1 parent 6a045b9 commit f786437

File tree

17 files changed

+62
-65
lines changed

17 files changed

+62
-65
lines changed

src/librustc/middle/astencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ impl FakeExtCtxt for parse::ParseSess {
18661866

18671867
#[cfg(test)]
18681868
fn mk_ctxt() -> parse::ParseSess {
1869-
parse::new_parse_sess()
1869+
parse::ParseSess::new()
18701870
}
18711871

18721872
#[cfg(test)]

src/librustc/session/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
852852
parse::parse_meta_from_source_str("cfgspec".to_string(),
853853
s.to_string(),
854854
Vec::new(),
855-
&parse::new_parse_sess())
855+
&parse::ParseSess::new())
856856
}).collect::<ast::CrateConfig>()
857857
}
858858

src/librustc/session/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,9 @@ pub fn build_session(sopts: config::Options,
368368

369369
let codemap = codemap::CodeMap::new();
370370
let diagnostic_handler =
371-
diagnostic::default_handler(sopts.color, Some(registry), can_print_warnings);
371+
diagnostic::Handler::new(sopts.color, Some(registry), can_print_warnings);
372372
let span_diagnostic_handler =
373-
diagnostic::mk_span_handler(diagnostic_handler, codemap);
373+
diagnostic::SpanHandler::new(diagnostic_handler, codemap);
374374

375375
build_session_(sopts, local_crate_source_file, span_diagnostic_handler)
376376
}
@@ -387,7 +387,7 @@ pub fn build_session_(sopts: config::Options,
387387
}
388388
};
389389
let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
390-
let p_s = parse::new_parse_sess_special_handler(span_diagnostic);
390+
let p_s = parse::ParseSess::with_span_handler(span_diagnostic);
391391
let default_sysroot = match sopts.maybe_sysroot {
392392
Some(_) => None,
393393
None => Some(filesearch::get_or_default_sysroot())

src/librustc_back/target/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl Target {
218218
// this is 1. ugly, 2. error prone.
219219

220220

221-
let handler = diagnostic::default_handler(diagnostic::Auto, None, true);
221+
let handler = diagnostic::Handler::new(diagnostic::Auto, None, true);
222222

223223
let get_req_field = |name: &str| {
224224
match obj.find(name)

src/librustc_driver/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ fn test_env<F>(source_string: &str,
105105
let codemap =
106106
CodeMap::new();
107107
let diagnostic_handler =
108-
diagnostic::mk_handler(true, emitter);
108+
diagnostic::Handler::with_emitter(true, emitter);
109109
let span_diagnostic_handler =
110-
diagnostic::mk_span_handler(diagnostic_handler, codemap);
110+
diagnostic::SpanHandler::new(diagnostic_handler, codemap);
111111

112112
let sess = session::build_session_(options, None, span_diagnostic_handler);
113113
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));

src/librustc_trans/back/write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use util::common::time;
2121
use util::common::path2cstr;
2222
use syntax::codemap;
2323
use syntax::diagnostic;
24-
use syntax::diagnostic::{Emitter, Handler, Level, mk_handler};
24+
use syntax::diagnostic::{Emitter, Handler, Level};
2525

2626
use std::ffi::{CStr, CString};
2727
use std::fs;
@@ -928,7 +928,7 @@ fn run_work_multithreaded(sess: &Session,
928928
futures.push(rx);
929929

930930
thread::Builder::new().name(format!("codegen-{}", i)).spawn(move || {
931-
let diag_handler = mk_handler(true, box diag_emitter);
931+
let diag_handler = Handler::with_emitter(true, box diag_emitter);
932932

933933
// Must construct cgcx inside the proc because it has non-Send
934934
// fields.

src/librustdoc/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
110110
};
111111

112112
let codemap = codemap::CodeMap::new();
113-
let diagnostic_handler = diagnostic::default_handler(diagnostic::Auto, None, true);
113+
let diagnostic_handler = diagnostic::Handler::new(diagnostic::Auto, None, true);
114114
let span_diagnostic_handler =
115-
diagnostic::mk_span_handler(diagnostic_handler, codemap);
115+
diagnostic::SpanHandler::new(diagnostic_handler, codemap);
116116

117117
let sess = session::build_session_(sessopts, cpath,
118118
span_diagnostic_handler);

src/librustdoc/html/highlight.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use syntax::parse;
2424
/// Highlights some source code, returning the HTML output.
2525
pub fn highlight(src: &str, class: Option<&str>, id: Option<&str>) -> String {
2626
debug!("highlighting: ================\n{}\n==============", src);
27-
let sess = parse::new_parse_sess();
27+
let sess = parse::ParseSess::new();
2828
let fm = parse::string_to_filemap(&sess,
2929
src.to_string(),
3030
"<stdin>".to_string());

src/librustdoc/test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ pub fn run(input: &str,
6565
};
6666

6767
let codemap = CodeMap::new();
68-
let diagnostic_handler = diagnostic::default_handler(diagnostic::Auto, None, true);
68+
let diagnostic_handler = diagnostic::Handler::new(diagnostic::Auto, None, true);
6969
let span_diagnostic_handler =
70-
diagnostic::mk_span_handler(diagnostic_handler, codemap);
70+
diagnostic::SpanHandler::new(diagnostic_handler, codemap);
7171

7272
let sess = session::build_session_(sessopts,
7373
Some(input_path.clone()),
@@ -184,7 +184,7 @@ fn runtest(test: &str, cratename: &str, libs: SearchPaths,
184184
// it with a sink that is also passed to rustc itself. When this function
185185
// returns the output of the sink is copied onto the output of our own thread.
186186
//
187-
// The basic idea is to not use a default_handler() for rustc, and then also
187+
// The basic idea is to not use a default Handler for rustc, and then also
188188
// not print things by default to the actual stderr.
189189
struct Sink(Arc<Mutex<Vec<u8>>>);
190190
impl Write for Sink {
@@ -206,9 +206,9 @@ fn runtest(test: &str, cratename: &str, libs: SearchPaths,
206206

207207
// Compile the code
208208
let codemap = CodeMap::new();
209-
let diagnostic_handler = diagnostic::mk_handler(true, box emitter);
209+
let diagnostic_handler = diagnostic::Handler::with_emitter(true, box emitter);
210210
let span_diagnostic_handler =
211-
diagnostic::mk_span_handler(diagnostic_handler, codemap);
211+
diagnostic::SpanHandler::new(diagnostic_handler, codemap);
212212

213213
let sess = session::build_session_(sessopts,
214214
None,

src/libsyntax/diagnostic.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ pub struct SpanHandler {
122122
}
123123

124124
impl SpanHandler {
125+
pub fn new(handler: Handler, cm: codemap::CodeMap) -> SpanHandler {
126+
SpanHandler {
127+
handler: handler,
128+
cm: cm,
129+
}
130+
}
125131
pub fn span_fatal(&self, sp: Span, msg: &str) -> FatalError {
126132
self.handler.emit(Some((&self.cm, sp)), msg, Fatal);
127133
return FatalError;
@@ -187,6 +193,19 @@ pub struct Handler {
187193
}
188194

189195
impl Handler {
196+
pub fn new(color_config: ColorConfig,
197+
registry: Option<diagnostics::registry::Registry>,
198+
can_emit_warnings: bool) -> Handler {
199+
let emitter = Box::new(EmitterWriter::stderr(color_config, registry));
200+
Handler::with_emitter(can_emit_warnings, emitter)
201+
}
202+
pub fn with_emitter(can_emit_warnings: bool, e: Box<Emitter + Send>) -> Handler {
203+
Handler {
204+
err_count: Cell::new(0),
205+
emit: RefCell::new(e),
206+
can_emit_warnings: can_emit_warnings
207+
}
208+
}
190209
pub fn fatal(&self, msg: &str) -> ! {
191210
self.emit.borrow_mut().emit(None, msg, None, Fatal);
192211
panic!(FatalError);
@@ -254,27 +273,6 @@ impl Handler {
254273
}
255274
}
256275

257-
pub fn mk_span_handler(handler: Handler, cm: codemap::CodeMap) -> SpanHandler {
258-
SpanHandler {
259-
handler: handler,
260-
cm: cm,
261-
}
262-
}
263-
264-
pub fn default_handler(color_config: ColorConfig,
265-
registry: Option<diagnostics::registry::Registry>,
266-
can_emit_warnings: bool) -> Handler {
267-
mk_handler(can_emit_warnings, Box::new(EmitterWriter::stderr(color_config, registry)))
268-
}
269-
270-
pub fn mk_handler(can_emit_warnings: bool, e: Box<Emitter + Send>) -> Handler {
271-
Handler {
272-
err_count: Cell::new(0),
273-
emit: RefCell::new(e),
274-
can_emit_warnings: can_emit_warnings
275-
}
276-
}
277-
278276
#[derive(Copy, PartialEq, Clone, Debug)]
279277
pub enum Level {
280278
Bug,

0 commit comments

Comments
 (0)