Skip to content

Commit fe10c63

Browse files
committed
syntax::diagnostic: Remove unnecessary traits
This removes trait `handler` and `span_handler`, and renames `HandlerT` to `Handler`, `CodemapT` to `SpanHandler`.
1 parent a52cdfd commit fe10c63

File tree

16 files changed

+74
-103
lines changed

16 files changed

+74
-103
lines changed

src/librustc/driver/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ pub fn build_session(sopts: @session::options, demitter: @diagnostic::Emitter)
883883
pub fn build_session_(sopts: @session::options,
884884
cm: @codemap::CodeMap,
885885
demitter: @diagnostic::Emitter,
886-
span_diagnostic_handler: @mut diagnostic::span_handler)
886+
span_diagnostic_handler: @mut diagnostic::SpanHandler)
887887
-> Session {
888888
let target_cfg = build_target_config(sopts, demitter);
889889
let p_s = parse::new_parse_sess_special_handler(span_diagnostic_handler,

src/librustc/driver/session.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub struct Session_ {
209209
// For a library crate, this is always none
210210
entry_fn: RefCell<Option<(NodeId, codemap::Span)>>,
211211
entry_type: Cell<Option<EntryFnType>>,
212-
span_diagnostic: @mut diagnostic::span_handler,
212+
span_diagnostic: @mut diagnostic::SpanHandler,
213213
filesearch: @filesearch::FileSearch,
214214
building_library: Cell<bool>,
215215
working_dir: Path,
@@ -292,7 +292,7 @@ impl Session_ {
292292

293293
v
294294
}
295-
pub fn diagnostic(&self) -> @mut diagnostic::span_handler {
295+
pub fn diagnostic(&self) -> @mut diagnostic::SpanHandler {
296296
self.span_diagnostic
297297
}
298298
pub fn debugging_opt(&self, opt: uint) -> bool {

src/librustc/metadata/creader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use syntax::abi;
2222
use syntax::attr;
2323
use syntax::attr::AttrMetaMethods;
2424
use syntax::codemap::{Span, dummy_sp};
25-
use syntax::diagnostic::span_handler;
25+
use syntax::diagnostic::SpanHandler;
2626
use syntax::parse::token;
2727
use syntax::parse::token::ident_interner;
2828
use syntax::crateid::CrateId;
@@ -86,7 +86,7 @@ fn dump_crates(crate_cache: &[cache_entry]) {
8686
}
8787

8888
fn warn_if_multiple_versions(e: &mut Env,
89-
diag: @mut span_handler,
89+
diag: @mut SpanHandler,
9090
crate_cache: &[cache_entry]) {
9191
if crate_cache.len() != 0u {
9292
let name = crate_cache[crate_cache.len() - 1].crateid.name.clone();

src/librustc/metadata/encoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use syntax::ast_map;
3939
use syntax::ast_util::*;
4040
use syntax::attr;
4141
use syntax::attr::AttrMetaMethods;
42-
use syntax::diagnostic::span_handler;
42+
use syntax::diagnostic::SpanHandler;
4343
use syntax::parse::token::special_idents;
4444
use syntax::ast_util;
4545
use syntax::visit::Visitor;
@@ -57,7 +57,7 @@ pub type encode_inlined_item<'a> = 'a |ecx: &EncodeContext,
5757
ii: ast::inlined_item|;
5858

5959
pub struct EncodeParams<'a> {
60-
diag: @mut span_handler,
60+
diag: @mut SpanHandler,
6161
tcx: ty::ctxt,
6262
reexports2: middle::resolve::ExportMap2,
6363
item_symbols: &'a RefCell<HashMap<ast::NodeId, ~str>>,
@@ -83,7 +83,7 @@ struct Stats {
8383
}
8484

8585
pub struct EncodeContext<'a> {
86-
diag: @mut span_handler,
86+
diag: @mut SpanHandler,
8787
tcx: ty::ctxt,
8888
stats: @Stats,
8989
reexports2: middle::resolve::ExportMap2,

src/librustc/metadata/loader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use metadata::encoder;
1919
use metadata::filesearch::{FileMatches, FileDoesntMatch};
2020
use metadata::filesearch;
2121
use syntax::codemap::Span;
22-
use syntax::diagnostic::span_handler;
22+
use syntax::diagnostic::SpanHandler;
2323
use syntax::parse::token::ident_interner;
2424
use syntax::crateid::CrateId;
2525
use syntax::attr;
@@ -231,8 +231,8 @@ impl Context {
231231
}
232232
}
233233

234-
pub fn note_crateid_attr(diag: @mut span_handler,
235-
crateid: &CrateId) {
234+
pub fn note_crateid_attr(diag: @mut SpanHandler,
235+
crateid: &CrateId) {
236236
diag.handler().note(format!("crate_id: {}", crateid.to_str()));
237237
}
238238

src/librustc/metadata/tyencode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ use middle::ty;
2424
use syntax::abi::AbiSet;
2525
use syntax::ast;
2626
use syntax::ast::*;
27-
use syntax::diagnostic::span_handler;
27+
use syntax::diagnostic::SpanHandler;
2828
use syntax::print::pprust::*;
2929

3030
macro_rules! mywrite( ($wr:expr, $($arg:tt)*) => (
3131
format_args!(|a| { mywrite($wr, a) }, $($arg)*)
3232
) )
3333

3434
pub struct ctxt {
35-
diag: @mut span_handler,
35+
diag: @mut SpanHandler,
3636
// Def -> str Callback:
3737
ds: extern "Rust" fn(DefId) -> ~str,
3838
// The type context.

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ pub type ctxt = @ctxt_;
267267
/// generates so that so that it can be reused and doesn't have to be redone
268268
/// later on.
269269
struct ctxt_ {
270-
diag: @mut syntax::diagnostic::span_handler,
270+
diag: @mut syntax::diagnostic::SpanHandler,
271271
interner: RefCell<HashMap<intern_key, ~t_box_>>,
272272
next_id: Cell<uint>,
273273
cstore: @metadata::cstore::CStore,

src/libsyntax/ast_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use ast_util::{inlined_item_utils, stmt_id};
1515
use ast_util;
1616
use codemap::Span;
1717
use codemap;
18-
use diagnostic::span_handler;
18+
use diagnostic::SpanHandler;
1919
use parse::token::get_ident_interner;
2020
use parse::token::ident_interner;
2121
use parse::token::special_idents;
@@ -152,7 +152,7 @@ pub type map = @mut HashMap<NodeId, ast_node>;
152152
pub struct Ctx {
153153
map: map,
154154
path: path,
155-
diag: @mut span_handler,
155+
diag: @mut SpanHandler,
156156
}
157157

158158
impl Ctx {
@@ -373,7 +373,7 @@ impl Visitor<()> for Ctx {
373373
}
374374
}
375375

376-
pub fn map_crate(diag: @mut span_handler, c: &Crate) -> map {
376+
pub fn map_crate(diag: @mut SpanHandler, c: &Crate) -> map {
377377
let cx = @mut Ctx {
378378
map: @mut HashMap::new(),
379379
path: ~[],
@@ -386,7 +386,7 @@ pub fn map_crate(diag: @mut span_handler, c: &Crate) -> map {
386386
// Used for items loaded from external crate that are being inlined into this
387387
// crate. The `path` should be the path to the item but should not include
388388
// the item itself.
389-
pub fn map_decoded_item(diag: @mut span_handler,
389+
pub fn map_decoded_item(diag: @mut SpanHandler,
390390
map: map,
391391
path: path,
392392
ii: &inlined_item) {

src/libsyntax/attr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ast;
1414
use ast::{Attribute, Attribute_, MetaItem, MetaWord, MetaNameValue, MetaList};
1515
use codemap::{Span, Spanned, spanned, dummy_spanned};
1616
use codemap::BytePos;
17-
use diagnostic::span_handler;
17+
use diagnostic::SpanHandler;
1818
use parse::comments::{doc_comment_style, strip_doc_comment_decoration};
1919
use crateid::CrateId;
2020

@@ -355,7 +355,7 @@ pub fn find_stability<AM: AttrMetaMethods, It: Iterator<AM>>(mut metas: It) -> O
355355
None
356356
}
357357

358-
pub fn require_unique_names(diagnostic: @mut span_handler,
358+
pub fn require_unique_names(diagnostic: @mut SpanHandler,
359359
metas: &[@MetaItem]) {
360360
let mut set = HashSet::new();
361361
for meta in metas.iter() {
@@ -381,7 +381,7 @@ pub fn require_unique_names(diagnostic: @mut span_handler,
381381
* present (before fields, if any) with that type; reprensentation
382382
* optimizations which would remove it will not be done.
383383
*/
384-
pub fn find_repr_attr(diagnostic: @mut span_handler, attr: @ast::MetaItem, acc: ReprAttr)
384+
pub fn find_repr_attr(diagnostic: @mut SpanHandler, attr: @ast::MetaItem, acc: ReprAttr)
385385
-> ReprAttr {
386386
let mut acc = acc;
387387
match attr.node {

src/libsyntax/diagnostic.rs

Lines changed: 38 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -26,95 +26,67 @@ pub trait Emitter {
2626
lvl: level);
2727
}
2828

29-
// a handler deals with errors; certain errors
30-
// (fatal, bug, unimpl) may cause immediate exit,
31-
// others log errors for later reporting.
32-
pub trait handler {
33-
fn fatal(@mut self, msg: &str) -> !;
34-
fn err(@mut self, msg: &str);
35-
fn bump_err_count(@mut self);
36-
fn err_count(@mut self) -> uint;
37-
fn has_errors(@mut self) -> bool;
38-
fn abort_if_errors(@mut self);
39-
fn warn(@mut self, msg: &str);
40-
fn note(@mut self, msg: &str);
41-
// used to indicate a bug in the compiler:
42-
fn bug(@mut self, msg: &str) -> !;
43-
fn unimpl(@mut self, msg: &str) -> !;
44-
fn emit(@mut self,
45-
cmsp: Option<(@codemap::CodeMap, Span)>,
46-
msg: &str,
47-
lvl: level);
48-
}
49-
5029
// a span-handler is like a handler but also
5130
// accepts span information for source-location
5231
// reporting.
53-
pub trait span_handler {
54-
fn span_fatal(@mut self, sp: Span, msg: &str) -> !;
55-
fn span_err(@mut self, sp: Span, msg: &str);
56-
fn span_warn(@mut self, sp: Span, msg: &str);
57-
fn span_note(@mut self, sp: Span, msg: &str);
58-
fn span_bug(@mut self, sp: Span, msg: &str) -> !;
59-
fn span_unimpl(@mut self, sp: Span, msg: &str) -> !;
60-
fn handler(@mut self) -> @mut handler;
61-
}
62-
63-
struct HandlerT {
64-
err_count: uint,
65-
emit: @Emitter,
66-
}
67-
68-
struct CodemapT {
69-
handler: @mut handler,
32+
pub struct SpanHandler {
33+
handler: @mut Handler,
7034
cm: @codemap::CodeMap,
7135
}
7236

73-
impl span_handler for CodemapT {
74-
fn span_fatal(@mut self, sp: Span, msg: &str) -> ! {
37+
impl SpanHandler {
38+
pub fn span_fatal(@mut self, sp: Span, msg: &str) -> ! {
7539
self.handler.emit(Some((self.cm, sp)), msg, fatal);
7640
fail!();
7741
}
78-
fn span_err(@mut self, sp: Span, msg: &str) {
42+
pub fn span_err(@mut self, sp: Span, msg: &str) {
7943
self.handler.emit(Some((self.cm, sp)), msg, error);
8044
self.handler.bump_err_count();
8145
}
82-
fn span_warn(@mut self, sp: Span, msg: &str) {
46+
pub fn span_warn(@mut self, sp: Span, msg: &str) {
8347
self.handler.emit(Some((self.cm, sp)), msg, warning);
8448
}
85-
fn span_note(@mut self, sp: Span, msg: &str) {
49+
pub fn span_note(@mut self, sp: Span, msg: &str) {
8650
self.handler.emit(Some((self.cm, sp)), msg, note);
8751
}
88-
fn span_bug(@mut self, sp: Span, msg: &str) -> ! {
52+
pub fn span_bug(@mut self, sp: Span, msg: &str) -> ! {
8953
self.span_fatal(sp, ice_msg(msg));
9054
}
91-
fn span_unimpl(@mut self, sp: Span, msg: &str) -> ! {
55+
pub fn span_unimpl(@mut self, sp: Span, msg: &str) -> ! {
9256
self.span_bug(sp, ~"unimplemented " + msg);
9357
}
94-
fn handler(@mut self) -> @mut handler {
58+
pub fn handler(@mut self) -> @mut Handler {
9559
self.handler
9660
}
9761
}
9862
99-
impl handler for HandlerT {
100-
fn fatal(@mut self, msg: &str) -> ! {
63+
// a handler deals with errors; certain errors
64+
// (fatal, bug, unimpl) may cause immediate exit,
65+
// others log errors for later reporting.
66+
pub struct Handler {
67+
err_count: uint,
68+
emit: @Emitter,
69+
}
70+
71+
impl Handler {
72+
pub fn fatal(@mut self, msg: &str) -> ! {
10173
self.emit.emit(None, msg, fatal);
10274
fail!();
10375
}
104-
fn err(@mut self, msg: &str) {
76+
pub fn err(@mut self, msg: &str) {
10577
self.emit.emit(None, msg, error);
10678
self.bump_err_count();
10779
}
108-
fn bump_err_count(@mut self) {
80+
pub fn bump_err_count(@mut self) {
10981
self.err_count += 1u;
11082
}
111-
fn err_count(@mut self) -> uint {
83+
pub fn err_count(@mut self) -> uint {
11284
self.err_count
11385
}
114-
fn has_errors(@mut self) -> bool {
86+
pub fn has_errors(@mut self) -> bool {
11587
self.err_count > 0u
11688
}
117-
fn abort_if_errors(@mut self) {
89+
pub fn abort_if_errors(@mut self) {
11890
let s;
11991
match self.err_count {
12092
0u => return,
@@ -126,19 +98,19 @@ impl handler for HandlerT {
12698
}
12799
self.fatal(s);
128100
}
129-
fn warn(@mut self, msg: &str) {
101+
pub fn warn(@mut self, msg: &str) {
130102
self.emit.emit(None, msg, warning);
131103
}
132-
fn note(@mut self, msg: &str) {
104+
pub fn note(@mut self, msg: &str) {
133105
self.emit.emit(None, msg, note);
134106
}
135-
fn bug(@mut self, msg: &str) -> ! {
107+
pub fn bug(@mut self, msg: &str) -> ! {
136108
self.fatal(ice_msg(msg));
137109
}
138-
fn unimpl(@mut self, msg: &str) -> ! {
110+
pub fn unimpl(@mut self, msg: &str) -> ! {
139111
self.bug(~"unimplemented " + msg);
140112
}
141-
fn emit(@mut self,
113+
pub fn emit(@mut self,
142114
cmsp: Option<(@codemap::CodeMap, Span)>,
143115
msg: &str,
144116
lvl: level) {
@@ -151,24 +123,24 @@ pub fn ice_msg(msg: &str) -> ~str {
151123
\nWe would appreciate a bug report: {}", msg, BUG_REPORT_URL)
152124
}
153125

154-
pub fn mk_span_handler(handler: @mut handler, cm: @codemap::CodeMap)
155-
-> @mut span_handler {
156-
@mut CodemapT {
126+
pub fn mk_span_handler(handler: @mut Handler, cm: @codemap::CodeMap)
127+
-> @mut SpanHandler {
128+
@mut SpanHandler {
157129
handler: handler,
158130
cm: cm,
159-
} as @mut span_handler
131+
}
160132
}
161133

162-
pub fn mk_handler(emitter: Option<@Emitter>) -> @mut handler {
134+
pub fn mk_handler(emitter: Option<@Emitter>) -> @mut Handler {
163135
let emit: @Emitter = match emitter {
164136
Some(e) => e,
165137
None => @DefaultEmitter as @Emitter
166138
};
167139

168-
@mut HandlerT {
140+
@mut Handler {
169141
err_count: 0,
170142
emit: emit,
171-
} as @mut handler
143+
}
172144
}
173145

174146
#[deriving(Eq)]
@@ -356,7 +328,7 @@ fn print_macro_backtrace(cm: @codemap::CodeMap, sp: Span) {
356328
}
357329

358330
pub fn expect<T:Clone>(
359-
diag: @mut span_handler,
331+
diag: @mut SpanHandler,
360332
opt: Option<T>,
361333
msg: || -> ~str)
362334
-> T {

src/libsyntax/ext/base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use ast;
1212
use ast::Name;
1313
use codemap;
1414
use codemap::{CodeMap, Span, ExpnInfo};
15-
use diagnostic::span_handler;
1615
use ext;
1716
use ext::expand;
1817
use parse;

0 commit comments

Comments
 (0)