Skip to content

Commit 49e6cef

Browse files
committed
---
yaml --- r: 171870 b: refs/heads/beta c: 98aeac2 h: refs/heads/master v: v3
1 parent a89ae7c commit 49e6cef

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3131
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2
3232
refs/heads/batch: b5571ed71a5879c0495a982506258d5d267744ed
3333
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
34-
refs/heads/beta: d4da75892219ee8fed5fc8801a37ffe82520083d
34+
refs/heads/beta: 98aeac2930dfd64ef1cb52c3a20e1f3609feee8e
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928

branches/beta/src/librustc_driver/driver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
138138
krate.encode(&mut json).unwrap();
139139
}
140140

141-
if sess.opts.show_span.is_some() {
142-
syntax::show_span::run(sess.diagnostic(), &krate);
141+
if let Some(ref s) = sess.opts.show_span {
142+
syntax::show_span::run(sess.diagnostic(), s.as_slice(), &krate);
143143
}
144144

145145
krate

branches/beta/src/libsyntax/show_span.rs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,73 @@
1313
//! This module shows spans for all expressions in the crate
1414
//! to help with compiler debugging.
1515
16+
use std::str::FromStr;
17+
1618
use ast;
1719
use diagnostic;
1820
use visit;
1921
use visit::Visitor;
2022

23+
enum Mode {
24+
Expression,
25+
Pattern,
26+
Type,
27+
}
28+
29+
impl FromStr for Mode {
30+
fn from_str(s: &str) -> Option<Mode> {
31+
let mode = match s {
32+
"expr" => Mode::Expression,
33+
"pat" => Mode::Pattern,
34+
"ty" => Mode::Type,
35+
_ => return None
36+
};
37+
Some(mode)
38+
}
39+
}
40+
2141
struct ShowSpanVisitor<'a> {
2242
span_diagnostic: &'a diagnostic::SpanHandler,
43+
mode: Mode,
2344
}
2445

2546
impl<'a, 'v> Visitor<'v> for ShowSpanVisitor<'a> {
2647
fn visit_expr(&mut self, e: &ast::Expr) {
27-
self.span_diagnostic.span_note(e.span, "expression");
48+
if let Mode::Expression = self.mode {
49+
self.span_diagnostic.span_note(e.span, "expression");
50+
}
2851
visit::walk_expr(self, e);
2952
}
3053

54+
fn visit_pat(&mut self, p: &ast::Pat) {
55+
if let Mode::Pattern = self.mode {
56+
self.span_diagnostic.span_note(p.span, "pattern");
57+
}
58+
visit::walk_pat(self, p);
59+
}
60+
61+
fn visit_ty(&mut self, t: &ast::Ty) {
62+
if let Mode::Type = self.mode {
63+
self.span_diagnostic.span_note(t.span, "type");
64+
}
65+
visit::walk_ty(self, t);
66+
}
67+
3168
fn visit_mac(&mut self, macro: &ast::Mac) {
3269
visit::walk_mac(self, macro);
3370
}
3471
}
3572

36-
pub fn run(span_diagnostic: &diagnostic::SpanHandler, krate: &ast::Crate) {
37-
let mut v = ShowSpanVisitor { span_diagnostic: span_diagnostic };
73+
pub fn run(span_diagnostic: &diagnostic::SpanHandler,
74+
mode: &str,
75+
krate: &ast::Crate) {
76+
let mode = match mode.parse() {
77+
Some(mode) => mode,
78+
None => return
79+
};
80+
let mut v = ShowSpanVisitor {
81+
span_diagnostic: span_diagnostic,
82+
mode: mode,
83+
};
3884
visit::walk_crate(&mut v, krate);
3985
}

0 commit comments

Comments
 (0)