Skip to content

Commit d26aefb

Browse files
committed
---
yaml --- r: 170776 b: refs/heads/try c: 98aeac2 h: refs/heads/master v: v3
1 parent 72d3e38 commit d26aefb

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
@@ -2,7 +2,7 @@
22
refs/heads/master: 73a25f55ad748b4d3516417c711b99ce446591af
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 5b3cd3900ceda838f5798c30ab96ceb41f962534
5-
refs/heads/try: d4da75892219ee8fed5fc8801a37ffe82520083d
5+
refs/heads/try: 98aeac2930dfd64ef1cb52c3a20e1f3609feee8e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/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/try/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)