Skip to content

Commit c3ccaac

Browse files
committed
auto merge of #12087 : sanxiyn/rust/show-span, r=huonw
2 parents 14cb4be + e5463b9 commit c3ccaac

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

src/librustc/driver/driver.rs

+4
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
518518
let (outputs, trans) = {
519519
let (expanded_crate, ast_map) = {
520520
let crate = phase_1_parse_input(sess, cfg, input);
521+
if sess.show_span() {
522+
front::show_span::run(sess, &crate);
523+
return;
524+
}
521525
if stop_after_phase_1(sess) { return; }
522526
let loader = &mut Loader::new(sess);
523527
phase_2_configure_and_expand(sess, loader, crate)

src/librustc/driver/session.rs

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ debugging_opts!(
6060
BORROWCK_STATS,
6161
NO_LANDING_PADS,
6262
DEBUG_LLVM,
63+
SHOW_SPAN,
6364
COUNT_TYPE_SIZES,
6465
META_STATS,
6566
NO_OPT,
@@ -95,6 +96,7 @@ pub fn debugging_opts_map() -> ~[(&'static str, &'static str, u64)] {
9596
("no-landing-pads", "omit landing pads for unwinding",
9697
NO_LANDING_PADS),
9798
("debug-llvm", "enable debug output from LLVM", DEBUG_LLVM),
99+
("show-span", "show spans for compiler debugging", SHOW_SPAN),
98100
("count-type-sizes", "count the sizes of aggregate types",
99101
COUNT_TYPE_SIZES),
100102
("meta-stats", "gather metadata statistics", META_STATS),
@@ -351,6 +353,9 @@ impl Session_ {
351353
pub fn no_landing_pads(&self) -> bool {
352354
self.debugging_opt(NO_LANDING_PADS)
353355
}
356+
pub fn show_span(&self) -> bool {
357+
self.debugging_opt(SHOW_SPAN)
358+
}
354359

355360
// DEPRECATED. This function results in a lot of allocations when they
356361
// are not necessary.

src/librustc/front/show_span.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Span debugger
12+
//!
13+
//! This module shows spans for all expressions in the crate
14+
//! to help with compiler debugging.
15+
16+
use syntax::ast;
17+
use syntax::visit;
18+
use syntax::visit::Visitor;
19+
20+
use driver::session::Session;
21+
22+
struct ShowSpanVisitor {
23+
sess: Session
24+
}
25+
26+
impl Visitor<()> for ShowSpanVisitor {
27+
fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
28+
self.sess.span_note(e.span, "expression");
29+
visit::walk_expr(self, e, ());
30+
}
31+
}
32+
33+
pub fn run(sess: Session, crate: &ast::Crate) {
34+
let mut v = ShowSpanVisitor { sess: sess };
35+
visit::walk_crate(&mut v, crate, ());
36+
}

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub mod front {
9797
pub mod std_inject;
9898
pub mod assign_node_ids_and_map;
9999
pub mod feature_gate;
100+
pub mod show_span;
100101
}
101102

102103
pub mod back {

src/libsyntax/parse/parser.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ impl Parser {
17711771
self.commit_expr_expecting(*es.last().unwrap(), token::RPAREN);
17721772

17731773
return if es.len() == 1 && !trailing_comma {
1774-
self.mk_expr(lo, self.span.hi, ExprParen(es[0]))
1774+
self.mk_expr(lo, hi, ExprParen(es[0]))
17751775
}
17761776
else {
17771777
self.mk_expr(lo, hi, ExprTup(es))
@@ -1994,7 +1994,7 @@ impl Parser {
19941994
seq_sep_trailing_disallowed(token::COMMA),
19951995
|p| p.parse_expr()
19961996
);
1997-
hi = self.span.hi;
1997+
hi = self.last_span.hi;
19981998

19991999
es.unshift(e);
20002000
let nd = self.mk_method_call(i, tys, es, NoSugar);
@@ -2510,7 +2510,7 @@ impl Parser {
25102510
parse_decl: |&mut Parser| -> P<FnDecl>,
25112511
parse_body: |&mut Parser| -> @Expr)
25122512
-> @Expr {
2513-
let lo = self.last_span.lo;
2513+
let lo = self.span.lo;
25142514
let decl = parse_decl(self);
25152515
let body = parse_body(self);
25162516
let fakeblock = P(ast::Block {

0 commit comments

Comments
 (0)